From 562b815ba3bdda764db4ba71bef6f7c44cec4918 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Tue, 13 Aug 2024 19:19:46 +0200 Subject: [PATCH] Add a regression test related to narrowing in plain JS files (#59611) --- .../reference/narrowingPlainJsNoCrash1.js | 21 ++++++++ .../narrowingPlainJsNoCrash1.symbols | 26 ++++++++++ .../reference/narrowingPlainJsNoCrash1.types | 48 +++++++++++++++++++ .../compiler/narrowingPlainJsNoCrash1.ts | 13 +++++ 4 files changed, 108 insertions(+) create mode 100644 tests/baselines/reference/narrowingPlainJsNoCrash1.js create mode 100644 tests/baselines/reference/narrowingPlainJsNoCrash1.symbols create mode 100644 tests/baselines/reference/narrowingPlainJsNoCrash1.types create mode 100644 tests/cases/compiler/narrowingPlainJsNoCrash1.ts diff --git a/tests/baselines/reference/narrowingPlainJsNoCrash1.js b/tests/baselines/reference/narrowingPlainJsNoCrash1.js new file mode 100644 index 00000000000..f83a5c5c010 --- /dev/null +++ b/tests/baselines/reference/narrowingPlainJsNoCrash1.js @@ -0,0 +1,21 @@ +//// [tests/cases/compiler/narrowingPlainJsNoCrash1.ts] //// + +//// [index.js] +// https://github.com/microsoft/TypeScript/issues/59594 + +var a$b = {}; +var c, d; +d = a$b; +while (d !== a$b); +while ((c = a$b != a$b)) c.e; + + +//// [index.js] +// https://github.com/microsoft/TypeScript/issues/59594 +var a$b = {}; +var c, d; +d = a$b; +while (d !== a$b) + ; +while ((c = a$b != a$b)) + c.e; diff --git a/tests/baselines/reference/narrowingPlainJsNoCrash1.symbols b/tests/baselines/reference/narrowingPlainJsNoCrash1.symbols new file mode 100644 index 00000000000..5fc0fbfa238 --- /dev/null +++ b/tests/baselines/reference/narrowingPlainJsNoCrash1.symbols @@ -0,0 +1,26 @@ +//// [tests/cases/compiler/narrowingPlainJsNoCrash1.ts] //// + +=== index.js === +// https://github.com/microsoft/TypeScript/issues/59594 + +var a$b = {}; +>a$b : Symbol(a$b, Decl(index.js, 2, 3)) + +var c, d; +>c : Symbol(c, Decl(index.js, 3, 3)) +>d : Symbol(d, Decl(index.js, 3, 6)) + +d = a$b; +>d : Symbol(d, Decl(index.js, 3, 6)) +>a$b : Symbol(a$b, Decl(index.js, 2, 3)) + +while (d !== a$b); +>d : Symbol(d, Decl(index.js, 3, 6)) +>a$b : Symbol(a$b, Decl(index.js, 2, 3)) + +while ((c = a$b != a$b)) c.e; +>c : Symbol(c, Decl(index.js, 3, 3)) +>a$b : Symbol(a$b, Decl(index.js, 2, 3)) +>a$b : Symbol(a$b, Decl(index.js, 2, 3)) +>c : Symbol(c, Decl(index.js, 3, 3)) + diff --git a/tests/baselines/reference/narrowingPlainJsNoCrash1.types b/tests/baselines/reference/narrowingPlainJsNoCrash1.types new file mode 100644 index 00000000000..364d7c4f6de --- /dev/null +++ b/tests/baselines/reference/narrowingPlainJsNoCrash1.types @@ -0,0 +1,48 @@ +//// [tests/cases/compiler/narrowingPlainJsNoCrash1.ts] //// + +=== index.js === +// https://github.com/microsoft/TypeScript/issues/59594 + +var a$b = {}; +>a$b : {} +> : ^^ +>{} : {} +> : ^^ + +var c, d; +>c : any +>d : any + +d = a$b; +>d = a$b : {} +> : ^^ +>d : any +>a$b : {} +> : ^^ + +while (d !== a$b); +>d !== a$b : boolean +> : ^^^^^^^ +>d : {} +> : ^^ +>a$b : {} +> : ^^ + +while ((c = a$b != a$b)) c.e; +>(c = a$b != a$b) : boolean +> : ^^^^^^^ +>c = a$b != a$b : boolean +> : ^^^^^^^ +>c : any +>a$b != a$b : boolean +> : ^^^^^^^ +>a$b : {} +> : ^^ +>a$b : {} +> : ^^ +>c.e : error +>c : true +> : ^^^^ +>e : any +> : ^^^ + diff --git a/tests/cases/compiler/narrowingPlainJsNoCrash1.ts b/tests/cases/compiler/narrowingPlainJsNoCrash1.ts new file mode 100644 index 00000000000..260d04188ed --- /dev/null +++ b/tests/cases/compiler/narrowingPlainJsNoCrash1.ts @@ -0,0 +1,13 @@ +// @allowJs: true +// @checkJs: false +// @outDir: true + +// @filename: index.js + +// https://github.com/microsoft/TypeScript/issues/59594 + +var a$b = {}; +var c, d; +d = a$b; +while (d !== a$b); +while ((c = a$b != a$b)) c.e;