Skip to content

Commit eb80799

Browse files
authored
Care about esnext where we look for es2015 (#18331)
* Care about esnext where we look for es2015 * Update diagnostic message to be more agnostic
1 parent dc8d47c commit eb80799

File tree

102 files changed

+1209
-56
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+1209
-56
lines changed

src/compiler/checker.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22149,9 +22149,9 @@ namespace ts {
2214922149
}
2215022150
}
2215122151
else {
22152-
if (modulekind === ModuleKind.ES2015 && !isInAmbientContext(node)) {
22152+
if (modulekind >= ModuleKind.ES2015 && !isInAmbientContext(node)) {
2215322153
// Import equals declaration is deprecated in es6 or above
22154-
grammarErrorOnNode(node, Diagnostics.Import_assignment_cannot_be_used_when_targeting_ECMAScript_2015_modules_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_import_d_from_mod_or_another_module_format_instead);
22154+
grammarErrorOnNode(node, Diagnostics.Import_assignment_cannot_be_used_when_targeting_ECMAScript_modules_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_import_d_from_mod_or_another_module_format_instead);
2215522155
}
2215622156
}
2215722157
}
@@ -22187,7 +22187,7 @@ namespace ts {
2218722187
error(node.moduleSpecifier, Diagnostics.Module_0_uses_export_and_cannot_be_used_with_export_Asterisk, symbolToString(moduleSymbol));
2218822188
}
2218922189

22190-
if (modulekind !== ModuleKind.System && modulekind !== ModuleKind.ES2015) {
22190+
if (modulekind !== ModuleKind.System && modulekind !== ModuleKind.ES2015 && modulekind !== ModuleKind.ESNext) {
2219122191
checkExternalEmitHelpers(node, ExternalEmitHelpers.ExportStar);
2219222192
}
2219322193
}
@@ -22249,9 +22249,9 @@ namespace ts {
2224922249
checkExternalModuleExports(container);
2225022250

2225122251
if (node.isExportEquals && !isInAmbientContext(node)) {
22252-
if (modulekind === ModuleKind.ES2015) {
22252+
if (modulekind >= ModuleKind.ES2015) {
2225322253
// export assignment is not supported in es6 modules
22254-
grammarErrorOnNode(node, Diagnostics.Export_assignment_cannot_be_used_when_targeting_ECMAScript_2015_modules_Consider_using_export_default_or_another_module_format_instead);
22254+
grammarErrorOnNode(node, Diagnostics.Export_assignment_cannot_be_used_when_targeting_ECMAScript_modules_Consider_using_export_default_or_another_module_format_instead);
2225522255
}
2225622256
else if (modulekind === ModuleKind.System) {
2225722257
// system modules does not support export assignment
@@ -24851,7 +24851,7 @@ namespace ts {
2485124851
}
2485224852
}
2485324853

24854-
if (compilerOptions.module !== ModuleKind.ES2015 && compilerOptions.module !== ModuleKind.System && !compilerOptions.noEmit &&
24854+
if (compilerOptions.module !== ModuleKind.ES2015 && compilerOptions.module !== ModuleKind.ESNext && compilerOptions.module !== ModuleKind.System && !compilerOptions.noEmit &&
2485524855
!isInAmbientContext(node.parent.parent) && hasModifier(node.parent.parent, ModifierFlags.Export)) {
2485624856
checkESModuleMarker(node.name);
2485724857
}

src/compiler/diagnosticMessages.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,11 +627,11 @@
627627
"category": "Error",
628628
"code": 1200
629629
},
630-
"Import assignment cannot be used when targeting ECMAScript 2015 modules. Consider using 'import * as ns from \"mod\"', 'import {a} from \"mod\"', 'import d from \"mod\"', or another module format instead.": {
630+
"Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from \"mod\"', 'import {a} from \"mod\"', 'import d from \"mod\"', or another module format instead.": {
631631
"category": "Error",
632632
"code": 1202
633633
},
634-
"Export assignment cannot be used when targeting ECMAScript 2015 modules. Consider using 'export default' or another module format instead.": {
634+
"Export assignment cannot be used when targeting ECMAScript modules. Consider using 'export default' or another module format instead.": {
635635
"category": "Error",
636636
"code": 1203
637637
},

src/compiler/factory.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4158,7 +4158,8 @@ namespace ts {
41584158
const moduleKind = getEmitModuleKind(compilerOptions);
41594159
let create = hasExportStarsToExportValues
41604160
&& moduleKind !== ModuleKind.System
4161-
&& moduleKind !== ModuleKind.ES2015;
4161+
&& moduleKind !== ModuleKind.ES2015
4162+
&& moduleKind !== ModuleKind.ESNext;
41624163
if (!create) {
41634164
const helpers = getEmitHelpers(node);
41644165
if (helpers) {

src/compiler/transformers/ts.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ namespace ts {
521521

522522
function visitSourceFile(node: SourceFile) {
523523
const alwaysStrict = (compilerOptions.alwaysStrict === undefined ? compilerOptions.strict : compilerOptions.alwaysStrict) &&
524-
!(isExternalModule(node) && moduleKind === ModuleKind.ES2015);
524+
!(isExternalModule(node) && moduleKind >= ModuleKind.ES2015);
525525
return updateSourceFileNode(
526526
node,
527527
visitLexicalEnvironment(node.statements, sourceElementVisitor, context, /*start*/ 0, alwaysStrict));
@@ -2665,6 +2665,7 @@ namespace ts {
26652665
return isExportOfNamespace(node)
26662666
|| (isExternalModuleExport(node)
26672667
&& moduleKind !== ModuleKind.ES2015
2668+
&& moduleKind !== ModuleKind.ESNext
26682669
&& moduleKind !== ModuleKind.System);
26692670
}
26702671

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
tests/cases/compiler/es6ExportAssignment.ts(2,1): error TS1203: Export assignment cannot be used when targeting ECMAScript 2015 modules. Consider using 'export default' or another module format instead.
1+
tests/cases/compiler/es6ExportAssignment.ts(2,1): error TS1203: Export assignment cannot be used when targeting ECMAScript modules. Consider using 'export default' or another module format instead.
22

33

44
==== tests/cases/compiler/es6ExportAssignment.ts (1 errors) ====
55
var a = 10;
66
export = a;
77
~~~~~~~~~~~
8-
!!! error TS1203: Export assignment cannot be used when targeting ECMAScript 2015 modules. Consider using 'export default' or another module format instead.
8+
!!! error TS1203: Export assignment cannot be used when targeting ECMAScript modules. Consider using 'export default' or another module format instead.

tests/baselines/reference/es6ExportAssignment2.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
tests/cases/compiler/a.ts(2,1): error TS1203: Export assignment cannot be used when targeting ECMAScript 2015 modules. Consider using 'export default' or another module format instead.
1+
tests/cases/compiler/a.ts(2,1): error TS1203: Export assignment cannot be used when targeting ECMAScript modules. Consider using 'export default' or another module format instead.
22

33

44
==== tests/cases/compiler/a.ts (1 errors) ====
55
var a = 10;
66
export = a; // Error: export = not allowed in ES6
77
~~~~~~~~~~~
8-
!!! error TS1203: Export assignment cannot be used when targeting ECMAScript 2015 modules. Consider using 'export default' or another module format instead.
8+
!!! error TS1203: Export assignment cannot be used when targeting ECMAScript modules. Consider using 'export default' or another module format instead.
99

1010
==== tests/cases/compiler/b.ts (0 errors) ====
1111
import * as a from "a";
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/compiler/es6ExportEquals.ts(3,1): error TS1203: Export assignment cannot be used when targeting ECMAScript 2015 modules. Consider using 'export default' or another module format instead.
1+
tests/cases/compiler/es6ExportEquals.ts(3,1): error TS1203: Export assignment cannot be used when targeting ECMAScript modules. Consider using 'export default' or another module format instead.
22
tests/cases/compiler/es6ExportEquals.ts(3,1): error TS2309: An export assignment cannot be used in a module with other exported elements.
33

44

@@ -7,7 +7,7 @@ tests/cases/compiler/es6ExportEquals.ts(3,1): error TS2309: An export assignment
77

88
export = f;
99
~~~~~~~~~~~
10-
!!! error TS1203: Export assignment cannot be used when targeting ECMAScript 2015 modules. Consider using 'export default' or another module format instead.
10+
!!! error TS1203: Export assignment cannot be used when targeting ECMAScript modules. Consider using 'export default' or another module format instead.
1111
~~~~~~~~~~~
1212
!!! error TS2309: An export assignment cannot be used in a module with other exported elements.
1313

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
tests/cases/compiler/client.ts(1,1): error TS1202: Import assignment cannot be used when targeting ECMAScript 2015 modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.
2-
tests/cases/compiler/server.ts(2,1): error TS1203: Export assignment cannot be used when targeting ECMAScript 2015 modules. Consider using 'export default' or another module format instead.
1+
tests/cases/compiler/client.ts(1,1): error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.
2+
tests/cases/compiler/server.ts(2,1): error TS1203: Export assignment cannot be used when targeting ECMAScript modules. Consider using 'export default' or another module format instead.
33

44

55
==== tests/cases/compiler/client.ts (1 errors) ====
66
import a = require("server");
77
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8-
!!! error TS1202: Import assignment cannot be used when targeting ECMAScript 2015 modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.
8+
!!! error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.
99
==== tests/cases/compiler/server.ts (1 errors) ====
1010
var a = 10;
1111
export = a;
1212
~~~~~~~~~~~
13-
!!! error TS1203: Export assignment cannot be used when targeting ECMAScript 2015 modules. Consider using 'export default' or another module format instead.
13+
!!! error TS1203: Export assignment cannot be used when targeting ECMAScript modules. Consider using 'export default' or another module format instead.
1414

tests/baselines/reference/es6modulekind.symbols

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
=== tests/cases/compiler/es6modulekind.ts ===
1+
=== tests/cases/conformance/externalModules/es6/es6modulekind.ts ===
22
export default class A
33
>A : Symbol(A, Decl(es6modulekind.ts, 0, 0))
44
{

tests/baselines/reference/es6modulekind.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
=== tests/cases/compiler/es6modulekind.ts ===
1+
=== tests/cases/conformance/externalModules/es6/es6modulekind.ts ===
22
export default class A
33
>A : A
44
{

0 commit comments

Comments
 (0)