mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-04-17 01:49:41 -05:00
Fix(49702): LS crash in binder for module in a JS file (#52537)
This commit is contained in:
@@ -3213,7 +3213,9 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
|
||||
declareSymbolAndAddToSymbolTable(node, SymbolFlags.FunctionScopedVariable, SymbolFlags.FunctionScopedVariableExcludes);
|
||||
}
|
||||
break;
|
||||
|
||||
// Namespaces are not allowed in javascript files, so do nothing here
|
||||
case SyntaxKind.ModuleDeclaration:
|
||||
break;
|
||||
default:
|
||||
Debug.failBadSyntaxKind(thisContainer);
|
||||
}
|
||||
|
||||
25
tests/baselines/reference/moduleCrashInJSFile.errors.txt
Normal file
25
tests/baselines/reference/moduleCrashInJSFile.errors.txt
Normal file
@@ -0,0 +1,25 @@
|
||||
tests/cases/compiler/a.js(2,8): error TS2300: Duplicate identifier 'foo'.
|
||||
tests/cases/compiler/a.js(2,8): error TS8006: 'module' declarations can only be used in TypeScript files.
|
||||
tests/cases/compiler/a.js(3,5): error TS2331: 'this' cannot be referenced in a module or namespace body.
|
||||
tests/cases/compiler/a.js(7,5): error TS2300: Duplicate identifier 'foo'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/a.js (4 errors) ====
|
||||
//// [thisKeyword.ts]
|
||||
module foo {
|
||||
~~~
|
||||
!!! error TS2300: Duplicate identifier 'foo'.
|
||||
~~~
|
||||
!!! error TS8006: 'module' declarations can only be used in TypeScript files.
|
||||
this.bar = 4;
|
||||
~~~~
|
||||
!!! error TS2331: 'this' cannot be referenced in a module or namespace body.
|
||||
}
|
||||
|
||||
//// [thisKeyword.js]
|
||||
var foo;
|
||||
~~~
|
||||
!!! error TS2300: Duplicate identifier 'foo'.
|
||||
(function (foo) {
|
||||
this.bar = 4;
|
||||
})(foo || (foo = {}));
|
||||
23
tests/baselines/reference/moduleCrashInJSFile.js
Normal file
23
tests/baselines/reference/moduleCrashInJSFile.js
Normal file
@@ -0,0 +1,23 @@
|
||||
//// [a.js]
|
||||
//// [thisKeyword.ts]
|
||||
module foo {
|
||||
this.bar = 4;
|
||||
}
|
||||
|
||||
//// [thisKeyword.js]
|
||||
var foo;
|
||||
(function (foo) {
|
||||
this.bar = 4;
|
||||
})(foo || (foo = {}));
|
||||
|
||||
//// [a.js]
|
||||
//// [thisKeyword.ts]
|
||||
var foo;
|
||||
(function (foo) {
|
||||
this.bar = 4;
|
||||
})(foo || (foo = {}));
|
||||
//// [thisKeyword.js]
|
||||
var foo;
|
||||
(function (foo) {
|
||||
this.bar = 4;
|
||||
})(foo || (foo = {}));
|
||||
24
tests/baselines/reference/moduleCrashInJSFile.symbols
Normal file
24
tests/baselines/reference/moduleCrashInJSFile.symbols
Normal file
@@ -0,0 +1,24 @@
|
||||
=== tests/cases/compiler/a.js ===
|
||||
//// [thisKeyword.ts]
|
||||
module foo {
|
||||
>foo : Symbol(foo, Decl(a.js, 0, 0))
|
||||
|
||||
this.bar = 4;
|
||||
}
|
||||
|
||||
//// [thisKeyword.js]
|
||||
var foo;
|
||||
>foo : Symbol(foo, Decl(a.js, 6, 3))
|
||||
|
||||
(function (foo) {
|
||||
>foo : Symbol(foo, Decl(a.js, 7, 11))
|
||||
|
||||
this.bar = 4;
|
||||
>this.bar : Symbol((Anonymous function).bar, Decl(a.js, 7, 17))
|
||||
>this : Symbol((Anonymous function), Decl(a.js, 7, 1))
|
||||
>bar : Symbol((Anonymous function).bar, Decl(a.js, 7, 17))
|
||||
|
||||
})(foo || (foo = {}));
|
||||
>foo : Symbol(foo, Decl(a.js, 0, 0))
|
||||
>foo : Symbol(foo, Decl(a.js, 0, 0))
|
||||
|
||||
38
tests/baselines/reference/moduleCrashInJSFile.types
Normal file
38
tests/baselines/reference/moduleCrashInJSFile.types
Normal file
@@ -0,0 +1,38 @@
|
||||
=== tests/cases/compiler/a.js ===
|
||||
//// [thisKeyword.ts]
|
||||
module foo {
|
||||
>foo : typeof foo
|
||||
|
||||
this.bar = 4;
|
||||
>this.bar = 4 : 4
|
||||
>this.bar : any
|
||||
>this : any
|
||||
>bar : any
|
||||
>4 : 4
|
||||
}
|
||||
|
||||
//// [thisKeyword.js]
|
||||
var foo;
|
||||
>foo : any
|
||||
|
||||
(function (foo) {
|
||||
>(function (foo) { this.bar = 4;})(foo || (foo = {})) : void
|
||||
>(function (foo) { this.bar = 4;}) : typeof (Anonymous function)
|
||||
>function (foo) { this.bar = 4;} : typeof (Anonymous function)
|
||||
>foo : typeof globalThis.foo
|
||||
|
||||
this.bar = 4;
|
||||
>this.bar = 4 : 4
|
||||
>this.bar : any
|
||||
>this : this
|
||||
>bar : any
|
||||
>4 : 4
|
||||
|
||||
})(foo || (foo = {}));
|
||||
>foo || (foo = {}) : typeof foo
|
||||
>foo : typeof foo
|
||||
>(foo = {}) : {}
|
||||
>foo = {} : {}
|
||||
>foo : typeof foo
|
||||
>{} : {}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
tests/cases/compiler/a.js(1,8): error TS8006: 'module' declarations can only be used in TypeScript files.
|
||||
tests/cases/compiler/a.js(2,5): error TS2331: 'this' cannot be referenced in a module or namespace body.
|
||||
tests/cases/compiler/b.js(1,11): error TS8006: 'namespace' declarations can only be used in TypeScript files.
|
||||
tests/cases/compiler/b.js(2,5): error TS2331: 'this' cannot be referenced in a module or namespace body.
|
||||
|
||||
|
||||
==== tests/cases/compiler/a.js (2 errors) ====
|
||||
module foo {
|
||||
~~~
|
||||
!!! error TS8006: 'module' declarations can only be used in TypeScript files.
|
||||
this.bar = 4;
|
||||
~~~~
|
||||
!!! error TS2331: 'this' cannot be referenced in a module or namespace body.
|
||||
}
|
||||
|
||||
==== tests/cases/compiler/b.js (2 errors) ====
|
||||
namespace blah {
|
||||
~~~~
|
||||
!!! error TS8006: 'namespace' declarations can only be used in TypeScript files.
|
||||
this.prop = 42;
|
||||
~~~~
|
||||
!!! error TS2331: 'this' cannot be referenced in a module or namespace body.
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
//// [tests/cases/compiler/thisAssignmentInNamespaceDeclaration1.ts] ////
|
||||
|
||||
//// [a.js]
|
||||
module foo {
|
||||
this.bar = 4;
|
||||
}
|
||||
|
||||
//// [b.js]
|
||||
namespace blah {
|
||||
this.prop = 42;
|
||||
}
|
||||
|
||||
|
||||
//// [a.js]
|
||||
var foo;
|
||||
(function (foo) {
|
||||
this.bar = 4;
|
||||
})(foo || (foo = {}));
|
||||
//// [b.js]
|
||||
var blah;
|
||||
(function (blah) {
|
||||
this.prop = 42;
|
||||
})(blah || (blah = {}));
|
||||
@@ -0,0 +1,14 @@
|
||||
=== tests/cases/compiler/a.js ===
|
||||
module foo {
|
||||
>foo : Symbol(foo, Decl(a.js, 0, 0))
|
||||
|
||||
this.bar = 4;
|
||||
}
|
||||
|
||||
=== tests/cases/compiler/b.js ===
|
||||
namespace blah {
|
||||
>blah : Symbol(blah, Decl(b.js, 0, 0))
|
||||
|
||||
this.prop = 42;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
=== tests/cases/compiler/a.js ===
|
||||
module foo {
|
||||
>foo : typeof foo
|
||||
|
||||
this.bar = 4;
|
||||
>this.bar = 4 : 4
|
||||
>this.bar : any
|
||||
>this : any
|
||||
>bar : any
|
||||
>4 : 4
|
||||
}
|
||||
|
||||
=== tests/cases/compiler/b.js ===
|
||||
namespace blah {
|
||||
>blah : typeof blah
|
||||
|
||||
this.prop = 42;
|
||||
>this.prop = 42 : 42
|
||||
>this.prop : any
|
||||
>this : any
|
||||
>prop : any
|
||||
>42 : 42
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
// @checkJs: true
|
||||
// @outDir: out/
|
||||
|
||||
// @filename: a.js
|
||||
module foo {
|
||||
this.bar = 4;
|
||||
}
|
||||
|
||||
// @filename: b.js
|
||||
namespace blah {
|
||||
this.prop = 42;
|
||||
}
|
||||
Reference in New Issue
Block a user