-
Notifications
You must be signed in to change notification settings - Fork 12.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix(49702): LS crash in binder for module in a JS file (#52537)
- Loading branch information
1 parent
0ce5517
commit 74a37f8
Showing
10 changed files
with
210 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 = {})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 = {})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
>{} : {} | ||
|
24 changes: 24 additions & 0 deletions
24
tests/baselines/reference/thisAssignmentInNamespaceDeclaration1.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
} | ||
|
23 changes: 23 additions & 0 deletions
23
tests/baselines/reference/thisAssignmentInNamespaceDeclaration1.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 = {})); |
14 changes: 14 additions & 0 deletions
14
tests/baselines/reference/thisAssignmentInNamespaceDeclaration1.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
24 changes: 24 additions & 0 deletions
24
tests/baselines/reference/thisAssignmentInNamespaceDeclaration1.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
|
12 changes: 12 additions & 0 deletions
12
tests/cases/compiler/thisAssignmentInNamespaceDeclaration1.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// @checkJs: true | ||
// @outDir: out/ | ||
|
||
// @filename: a.js | ||
module foo { | ||
this.bar = 4; | ||
} | ||
|
||
// @filename: b.js | ||
namespace blah { | ||
this.prop = 42; | ||
} |