Skip to content

Commit 9c85b4b

Browse files
committed
Rest of plain JS binder errors
1 parent 0f619db commit 9c85b4b

File tree

7 files changed

+203
-86
lines changed

7 files changed

+203
-86
lines changed

src/compiler/program.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,9 @@ namespace ts {
832832
Diagnostics.Code_contained_in_a_class_is_evaluated_in_JavaScript_s_strict_mode_which_does_not_allow_this_use_of_0_For_more_information_see_https_Colon_Slash_Slashdeveloper_mozilla_org_Slashen_US_Slashdocs_SlashWeb_SlashJavaScript_SlashReference_SlashStrict_mode.code,
833833
Diagnostics.Invalid_use_of_0_Modules_are_automatically_in_strict_mode.code,
834834
Diagnostics.Invalid_use_of_0_in_strict_mode.code,
835+
Diagnostics.A_label_is_not_allowed_here.code,
836+
Diagnostics.Octal_literals_are_not_allowed_in_strict_mode.code,
837+
Diagnostics.with_statements_are_not_allowed_in_strict_mode.code,
835838
]);
836839

837840
/**
@@ -2020,13 +2023,12 @@ namespace ts {
20202023

20212024
Debug.assert(!!sourceFile.bindDiagnostics);
20222025

2023-
const isCheckJs = !!isCheckJsEnabledForFile(sourceFile, options) && (sourceFile.scriptKind === ScriptKind.JS || sourceFile.scriptKind === ScriptKind.JSX);
2026+
const isCheckJs = isCheckJsEnabledForFile(sourceFile, options) && (sourceFile.scriptKind === ScriptKind.JS || sourceFile.scriptKind === ScriptKind.JSX);
20242027
const isPlainJs = !sourceFile.checkJsDirective && options.checkJs === undefined && (sourceFile.scriptKind === ScriptKind.JS || sourceFile.scriptKind === ScriptKind.JSX);
20252028
const isTsNoCheck = !!sourceFile.checkJsDirective && sourceFile.checkJsDirective.enabled === false;
20262029

20272030
// By default, only type-check .ts, .tsx, 'Deferred' and 'External' files (external files are added by plugins)
2028-
const includeBindAndCheckDiagnostics = !isTsNoCheck && (
2029-
sourceFile.scriptKind === ScriptKind.TS || sourceFile.scriptKind === ScriptKind.TSX
2031+
const includeBindAndCheckDiagnostics = !isTsNoCheck && (sourceFile.scriptKind === ScriptKind.TS || sourceFile.scriptKind === ScriptKind.TSX
20302032
|| sourceFile.scriptKind === ScriptKind.External || isPlainJs || isCheckJs || sourceFile.scriptKind === ScriptKind.Deferred);
20312033
let bindDiagnostics: readonly Diagnostic[] = includeBindAndCheckDiagnostics ? sourceFile.bindDiagnostics : emptyArray;
20322034
let checkDiagnostics = includeBindAndCheckDiagnostics ? typeChecker.getDiagnostics(sourceFile, cancellationToken) : emptyArray;

tests/baselines/reference/plainJSReservedWord.errors.txt renamed to tests/baselines/reference/plainJSBinderErrors.errors.txt

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
1-
tests/cases/conformance/salsa/plainJSReservedWord.js(1,1): error TS2528: A module cannot have multiple default exports.
2-
tests/cases/conformance/salsa/plainJSReservedWord.js(2,1): error TS2528: A module cannot have multiple default exports.
3-
tests/cases/conformance/salsa/plainJSReservedWord.js(3,7): error TS1262: Identifier expected. 'await' is a reserved word at the top-level of a module.
4-
tests/cases/conformance/salsa/plainJSReservedWord.js(4,7): error TS1214: Identifier expected. 'yield' is a reserved word in strict mode. Modules are automatically in strict mode.
5-
tests/cases/conformance/salsa/plainJSReservedWord.js(6,11): error TS1359: Identifier expected. 'await' is a reserved word that cannot be used here.
6-
tests/cases/conformance/salsa/plainJSReservedWord.js(9,11): error TS1214: Identifier expected. 'yield' is a reserved word in strict mode. Modules are automatically in strict mode.
7-
tests/cases/conformance/salsa/plainJSReservedWord.js(12,5): error TS18012: '#constructor' is a reserved word.
8-
tests/cases/conformance/salsa/plainJSReservedWord.js(15,20): error TS1102: 'delete' cannot be called on an identifier in strict mode.
9-
tests/cases/conformance/salsa/plainJSReservedWord.js(18,16): error TS1102: 'delete' cannot be called on an identifier in strict mode.
10-
tests/cases/conformance/salsa/plainJSReservedWord.js(19,16): error TS1102: 'delete' cannot be called on an identifier in strict mode.
11-
tests/cases/conformance/salsa/plainJSReservedWord.js(22,15): error TS1210: Code contained in a class is evaluated in JavaScript's strict mode which does not allow this use of 'eval'. For more information, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode.
12-
tests/cases/conformance/salsa/plainJSReservedWord.js(23,15): error TS1210: Code contained in a class is evaluated in JavaScript's strict mode which does not allow this use of 'arguments'. For more information, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode.
13-
tests/cases/conformance/salsa/plainJSReservedWord.js(26,7): error TS1215: Invalid use of 'eval'. Modules are automatically in strict mode.
14-
tests/cases/conformance/salsa/plainJSReservedWord.js(27,7): error TS1215: Invalid use of 'arguments'. Modules are automatically in strict mode.
1+
tests/cases/conformance/salsa/plainJSBinderErrors.js(1,1): error TS2528: A module cannot have multiple default exports.
2+
tests/cases/conformance/salsa/plainJSBinderErrors.js(2,1): error TS2528: A module cannot have multiple default exports.
3+
tests/cases/conformance/salsa/plainJSBinderErrors.js(3,7): error TS1262: Identifier expected. 'await' is a reserved word at the top-level of a module.
4+
tests/cases/conformance/salsa/plainJSBinderErrors.js(4,7): error TS1214: Identifier expected. 'yield' is a reserved word in strict mode. Modules are automatically in strict mode.
5+
tests/cases/conformance/salsa/plainJSBinderErrors.js(6,11): error TS1359: Identifier expected. 'await' is a reserved word that cannot be used here.
6+
tests/cases/conformance/salsa/plainJSBinderErrors.js(9,11): error TS1214: Identifier expected. 'yield' is a reserved word in strict mode. Modules are automatically in strict mode.
7+
tests/cases/conformance/salsa/plainJSBinderErrors.js(12,5): error TS18012: '#constructor' is a reserved word.
8+
tests/cases/conformance/salsa/plainJSBinderErrors.js(15,20): error TS1102: 'delete' cannot be called on an identifier in strict mode.
9+
tests/cases/conformance/salsa/plainJSBinderErrors.js(18,16): error TS1102: 'delete' cannot be called on an identifier in strict mode.
10+
tests/cases/conformance/salsa/plainJSBinderErrors.js(19,16): error TS1102: 'delete' cannot be called on an identifier in strict mode.
11+
tests/cases/conformance/salsa/plainJSBinderErrors.js(22,15): error TS1210: Code contained in a class is evaluated in JavaScript's strict mode which does not allow this use of 'eval'. For more information, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode.
12+
tests/cases/conformance/salsa/plainJSBinderErrors.js(23,15): error TS1210: Code contained in a class is evaluated in JavaScript's strict mode which does not allow this use of 'arguments'. For more information, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode.
13+
tests/cases/conformance/salsa/plainJSBinderErrors.js(26,27): error TS1121: Octal literals are not allowed in strict mode.
14+
tests/cases/conformance/salsa/plainJSBinderErrors.js(27,9): error TS1101: 'with' statements are not allowed in strict mode.
15+
tests/cases/conformance/salsa/plainJSBinderErrors.js(33,13): error TS1344: 'A label is not allowed here.
16+
tests/cases/conformance/salsa/plainJSBinderErrors.js(39,7): error TS1215: Invalid use of 'eval'. Modules are automatically in strict mode.
17+
tests/cases/conformance/salsa/plainJSBinderErrors.js(40,7): error TS1215: Invalid use of 'arguments'. Modules are automatically in strict mode.
1518

1619

17-
==== tests/cases/conformance/salsa/plainJSReservedWord.js (14 errors) ====
20+
==== tests/cases/conformance/salsa/plainJSBinderErrors.js (17 errors) ====
1821
export default 12
1922
~~~~~~~~~~~~~~~~~
2023
!!! error TS2528: A module cannot have multiple default exports.
21-
!!! related TS2753 tests/cases/conformance/salsa/plainJSReservedWord.js:2:1: Another export default is here.
24+
!!! related TS2753 tests/cases/conformance/salsa/plainJSBinderErrors.js:2:1: Another export default is here.
2225
export default 13
2326
~~~~~~~~~~~~~~~~~
2427
!!! error TS2528: A module cannot have multiple default exports.
25-
!!! related TS2752 tests/cases/conformance/salsa/plainJSReservedWord.js:1:1: The first export default is here.
28+
!!! related TS2752 tests/cases/conformance/salsa/plainJSBinderErrors.js:1:1: The first export default is here.
2629
const await = 1
2730
~~~~~
2831
!!! error TS1262: Identifier expected. 'await' is a reserved word at the top-level of a module.
@@ -65,6 +68,25 @@ tests/cases/conformance/salsa/plainJSReservedWord.js(27,7): error TS1215: Invali
6568
~~~~~~~~~
6669
!!! error TS1210: Code contained in a class is evaluated in JavaScript's strict mode which does not allow this use of 'arguments'. For more information, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode.
6770
}
71+
withOctal() {
72+
const redundant = 010
73+
~~~
74+
!!! error TS1121: Octal literals are not allowed in strict mode.
75+
with (redundant) {
76+
~~~~
77+
!!! error TS1101: 'with' statements are not allowed in strict mode.
78+
return toFixed()
79+
}
80+
}
81+
label() {
82+
for(;;) {
83+
label: var x = 1
84+
~~~~~
85+
!!! error TS1344: 'A label is not allowed here.
86+
break label
87+
}
88+
return x
89+
}
6890
}
6991
const eval = 9
7092
~~~~

tests/baselines/reference/plainJSReservedWord.js renamed to tests/baselines/reference/plainJSBinderErrors.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//// [plainJSReservedWord.js]
1+
//// [plainJSBinderErrors.js]
22
export default 12
33
export default 13
44
const await = 1
@@ -23,12 +23,25 @@ class C {
2323
const eval = 7
2424
const arguments = 8
2525
}
26+
withOctal() {
27+
const redundant = 010
28+
with (redundant) {
29+
return toFixed()
30+
}
31+
}
32+
label() {
33+
for(;;) {
34+
label: var x = 1
35+
break label
36+
}
37+
return x
38+
}
2639
}
2740
const eval = 9
2841
const arguments = 10
2942

3043

31-
//// [plainJSReservedWord.js]
44+
//// [plainJSBinderErrors.js]
3245
export default 12;
3346
export default 13;
3447
const await = 1;
@@ -53,6 +66,19 @@ class C {
5366
const eval = 7;
5467
const arguments = 8;
5568
}
69+
withOctal() {
70+
const redundant = 010;
71+
with (redundant) {
72+
return toFixed();
73+
}
74+
}
75+
label() {
76+
for (;;) {
77+
label: var x = 1;
78+
break label;
79+
}
80+
return x;
81+
}
5682
}
5783
const eval = 9;
5884
const arguments = 10;
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
=== tests/cases/conformance/salsa/plainJSBinderErrors.js ===
2+
export default 12
3+
export default 13
4+
const await = 1
5+
>await : Symbol(await, Decl(plainJSBinderErrors.js, 2, 5))
6+
7+
const yield = 2
8+
>yield : Symbol(yield, Decl(plainJSBinderErrors.js, 3, 5))
9+
10+
async function f() {
11+
>f : Symbol(f, Decl(plainJSBinderErrors.js, 3, 15))
12+
13+
const await = 3
14+
>await : Symbol(await, Decl(plainJSBinderErrors.js, 5, 9))
15+
}
16+
function* g() {
17+
>g : Symbol(g, Decl(plainJSBinderErrors.js, 6, 1))
18+
19+
const yield = 4
20+
>yield : Symbol(yield, Decl(plainJSBinderErrors.js, 8, 9))
21+
}
22+
class C {
23+
>C : Symbol(C, Decl(plainJSBinderErrors.js, 9, 1))
24+
25+
#constructor = 5
26+
>#constructor : Symbol(C.#constructor, Decl(plainJSBinderErrors.js, 10, 9))
27+
28+
deleted() {
29+
>deleted : Symbol(C.deleted, Decl(plainJSBinderErrors.js, 11, 20))
30+
31+
function container(f) {
32+
>container : Symbol(container, Decl(plainJSBinderErrors.js, 12, 15))
33+
>f : Symbol(f, Decl(plainJSBinderErrors.js, 13, 27))
34+
35+
delete f
36+
>f : Symbol(f, Decl(plainJSBinderErrors.js, 13, 27))
37+
}
38+
var g = 6
39+
>g : Symbol(g, Decl(plainJSBinderErrors.js, 16, 11))
40+
41+
delete g
42+
>g : Symbol(g, Decl(plainJSBinderErrors.js, 16, 11))
43+
44+
delete container
45+
>container : Symbol(container, Decl(plainJSBinderErrors.js, 12, 15))
46+
}
47+
evalArguments() {
48+
>evalArguments : Symbol(C.evalArguments, Decl(plainJSBinderErrors.js, 19, 5))
49+
50+
const eval = 7
51+
>eval : Symbol(eval, Decl(plainJSBinderErrors.js, 21, 13))
52+
53+
const arguments = 8
54+
>arguments : Symbol(arguments, Decl(plainJSBinderErrors.js, 22, 13))
55+
}
56+
withOctal() {
57+
>withOctal : Symbol(C.withOctal, Decl(plainJSBinderErrors.js, 23, 5))
58+
59+
const redundant = 010
60+
>redundant : Symbol(redundant, Decl(plainJSBinderErrors.js, 25, 13))
61+
62+
with (redundant) {
63+
>redundant : Symbol(redundant, Decl(plainJSBinderErrors.js, 25, 13))
64+
65+
return toFixed()
66+
}
67+
}
68+
label() {
69+
>label : Symbol(C.label, Decl(plainJSBinderErrors.js, 29, 5))
70+
71+
for(;;) {
72+
label: var x = 1
73+
>x : Symbol(x, Decl(plainJSBinderErrors.js, 32, 22))
74+
75+
break label
76+
}
77+
return x
78+
>x : Symbol(x, Decl(plainJSBinderErrors.js, 32, 22))
79+
}
80+
}
81+
const eval = 9
82+
>eval : Symbol(eval, Decl(plainJSBinderErrors.js, 38, 5))
83+
84+
const arguments = 10
85+
>arguments : Symbol(arguments, Decl(plainJSBinderErrors.js, 39, 5))
86+

tests/baselines/reference/plainJSReservedWord.types renamed to tests/baselines/reference/plainJSBinderErrors.types

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
=== tests/cases/conformance/salsa/plainJSReservedWord.js ===
1+
=== tests/cases/conformance/salsa/plainJSBinderErrors.js ===
22
export default 12
33
export default 13
44
const await = 1
@@ -64,6 +64,36 @@ class C {
6464
>arguments : 8
6565
>8 : 8
6666
}
67+
withOctal() {
68+
>withOctal : () => any
69+
70+
const redundant = 010
71+
>redundant : 10
72+
>010 : 10
73+
74+
with (redundant) {
75+
>redundant : 10
76+
77+
return toFixed()
78+
>toFixed() : any
79+
>toFixed : any
80+
}
81+
}
82+
label() {
83+
>label : () => number
84+
85+
for(;;) {
86+
label: var x = 1
87+
>label : any
88+
>x : number
89+
>1 : 1
90+
91+
break label
92+
>label : any
93+
}
94+
return x
95+
>x : number
96+
}
6797
}
6898
const eval = 9
6999
>eval : 9

tests/baselines/reference/plainJSReservedWord.symbols

Lines changed: 0 additions & 62 deletions
This file was deleted.

tests/cases/conformance/salsa/plainJSReservedWord.ts renamed to tests/cases/conformance/salsa/plainJSBinderErrors.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @outdir: out/
22
// @target: esnext
33
// @allowJS: true
4-
// @filename: plainJSReservedWord.js
4+
// @filename: plainJSBinderErrors.js
55
export default 12
66
export default 13
77
const await = 1
@@ -26,6 +26,19 @@ class C {
2626
const eval = 7
2727
const arguments = 8
2828
}
29+
withOctal() {
30+
const redundant = 010
31+
with (redundant) {
32+
return toFixed()
33+
}
34+
}
35+
label() {
36+
for(;;) {
37+
label: var x = 1
38+
break label
39+
}
40+
return x
41+
}
2942
}
3043
const eval = 9
3144
const arguments = 10

0 commit comments

Comments
 (0)