Skip to content

Add module: es2020 #33893

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31437,7 +31437,7 @@ namespace ts {
*/
function checkClassNameCollisionWithObject(name: Identifier): void {
if (languageVersion === ScriptTarget.ES5 && name.escapedText === "Object"
&& moduleKind !== ModuleKind.ES2015 && moduleKind !== ModuleKind.ESNext) {
&& moduleKind < ModuleKind.ES2015) {
error(name, Diagnostics.Class_name_cannot_be_Object_when_targeting_ES5_with_module_0, ModuleKind[moduleKind]); // https://github.com/Microsoft/TypeScript/issues/17494
}
}
Expand Down Expand Up @@ -32597,7 +32597,7 @@ namespace ts {
error(node.moduleSpecifier, Diagnostics.Module_0_uses_export_and_cannot_be_used_with_export_Asterisk, symbolToString(moduleSymbol));
}

if (moduleKind !== ModuleKind.System && moduleKind !== ModuleKind.ES2015 && moduleKind !== ModuleKind.ESNext) {
if (moduleKind !== ModuleKind.System && moduleKind < ModuleKind.ES2015) {
checkExternalEmitHelpers(node, ExternalEmitHelpers.ExportStar);
}
}
Expand Down Expand Up @@ -35805,7 +35805,9 @@ namespace ts {
return grammarErrorOnNode(node.exclamationToken, Diagnostics.Definite_assignment_assertions_can_only_be_used_along_with_a_type_annotation);
}

if (compilerOptions.module !== ModuleKind.ES2015 && compilerOptions.module !== ModuleKind.ESNext && compilerOptions.module !== ModuleKind.System && !compilerOptions.noEmit &&
const moduleKind = getEmitModuleKind(compilerOptions);

if (moduleKind < ModuleKind.ES2015 && moduleKind !== ModuleKind.System && !compilerOptions.noEmit &&
!(node.parent.parent.flags & NodeFlags.Ambient) && hasModifier(node.parent.parent, ModifierFlags.Export)) {
checkESModuleMarker(node.name);
}
Expand Down Expand Up @@ -36151,7 +36153,7 @@ namespace ts {

function checkGrammarImportCallExpression(node: ImportCall): boolean {
if (moduleKind === ModuleKind.ES2015) {
return grammarErrorOnNode(node, Diagnostics.Dynamic_imports_are_only_supported_when_the_module_flag_is_set_to_esnext_commonjs_amd_system_or_umd);
return grammarErrorOnNode(node, Diagnostics.Dynamic_imports_are_only_supported_when_the_module_flag_is_set_to_es2020_esnext_commonjs_amd_system_or_umd);
}

if (node.typeArguments) {
Expand Down
1 change: 1 addition & 0 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ namespace ts {
umd: ModuleKind.UMD,
es6: ModuleKind.ES2015,
es2015: ModuleKind.ES2015,
es2020: ModuleKind.ES2020,
esnext: ModuleKind.ESNext
}),
affectsModuleResolution: true,
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@
"category": "Error",
"code": 1322
},
"Dynamic imports are only supported when the '--module' flag is set to 'esnext', 'commonjs', 'amd', 'system', or 'umd'.": {
"Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'.": {
"category": "Error",
"code": 1323
},
Expand Down
3 changes: 1 addition & 2 deletions src/compiler/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5157,8 +5157,7 @@ namespace ts {
const moduleKind = getEmitModuleKind(compilerOptions);
let create = (hasExportStarsToExportValues || (compilerOptions.esModuleInterop && hasImportStarOrImportDefault))
&& moduleKind !== ModuleKind.System
&& moduleKind !== ModuleKind.ES2015
&& moduleKind !== ModuleKind.ESNext;
&& moduleKind < ModuleKind.ES2015;
if (!create) {
const helpers = getEmitHelpers(node);
if (helpers) {
Expand Down
1 change: 1 addition & 0 deletions src/compiler/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ namespace ts {
function getModuleTransformer(moduleKind: ModuleKind): TransformerFactory<SourceFile | Bundle> {
switch (moduleKind) {
case ModuleKind.ESNext:
case ModuleKind.ES2020:
case ModuleKind.ES2015:
return transformES2015Module;
case ModuleKind.System:
Expand Down
1 change: 1 addition & 0 deletions src/compiler/transformers/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2469,6 +2469,7 @@ namespace ts {
return isExportOfNamespace(node)
|| (isExternalModuleExport(node)
&& moduleKind !== ModuleKind.ES2015
&& moduleKind !== ModuleKind.ES2020
&& moduleKind !== ModuleKind.ESNext
&& moduleKind !== ModuleKind.System);
}
Expand Down
1 change: 1 addition & 0 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5054,6 +5054,7 @@ namespace ts {
// Non-ES module kinds should not come between ES2015 (the earliest ES module kind) and ESNext (the last ES
// module kind).
ES2015 = 5,
ES2020 = 6,
ESNext = 99
}

Expand Down
1 change: 1 addition & 0 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7634,6 +7634,7 @@ namespace ts {
case ModuleKind.CommonJS:
case ModuleKind.AMD:
case ModuleKind.ES2015:
case ModuleKind.ES2020:
case ModuleKind.ESNext:
return true;
default:
Expand Down
1 change: 1 addition & 0 deletions src/services/codefixes/importFixes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ namespace ts.codefix {
return ImportKind.Equals;
case ModuleKind.System:
case ModuleKind.ES2015:
case ModuleKind.ES2020:
case ModuleKind.ESNext:
case ModuleKind.None:
// Fall back to the `import * as ns` style import.
Expand Down
2 changes: 1 addition & 1 deletion src/testRunner/unittests/config/commandLineParsing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ namespace ts {
start: undefined,
length: undefined,
}, {
messageText: "Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'esnext'.",
messageText: "Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'es2020', 'esnext'.",
category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category,
code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code,

Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/api/tsserverlibrary.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2680,6 +2680,7 @@ declare namespace ts {
UMD = 3,
System = 4,
ES2015 = 5,
ES2020 = 6,
ESNext = 99
}
export enum JsxEmit {
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/api/typescript.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2680,6 +2680,7 @@ declare namespace ts {
UMD = 3,
System = 4,
ES2015 = 5,
ES2020 = 6,
ESNext = 99
}
export enum JsxEmit {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//// [tests/cases/conformance/dynamicImport/importCallExpression1ESNext.ts] ////
//// [tests/cases/conformance/dynamicImport/importCallExpression1ES2020.ts] ////

//// [0.ts]
export function foo() { return "foo"; }
Expand All @@ -14,7 +14,8 @@ export var p2 = import("./0");

function foo() {
const p2 = import("./0");
}
}


//// [0.js]
export function foo() { return "foo"; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ function foo() {
>p2 : Symbol(p2, Decl(1.ts, 9, 9))
>"./0" : Symbol("tests/cases/conformance/dynamicImport/0", Decl(0.ts, 0, 0))
}

Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ function foo() {
>import("./0") : Promise<typeof import("tests/cases/conformance/dynamicImport/0")>
>"./0" : "./0"
}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//// [tests/cases/conformance/dynamicImport/importCallExpression2ESNext.ts] ////
//// [tests/cases/conformance/dynamicImport/importCallExpression2ES2020.ts] ////

//// [0.ts]
export class B {
Expand All @@ -13,7 +13,8 @@ function foo(x: Promise<any>) {
})
}

foo(import("./0"));
foo(import("./0"));


//// [0.js]
export class B {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//// [tests/cases/conformance/dynamicImport/importCallExpression3ESNext.ts] ////
//// [tests/cases/conformance/dynamicImport/importCallExpression3ES2020.ts] ////

//// [0.ts]
export class B {
Expand All @@ -11,7 +11,8 @@ async function foo() {
var c = new C();
c.print();
}
foo();
foo();


//// [0.js]
export class B {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//// [tests/cases/conformance/dynamicImport/importCallExpression4ESNext.ts] ////
//// [tests/cases/conformance/dynamicImport/importCallExpression4ES2020.ts] ////

//// [0.ts]
export class B {
Expand All @@ -24,7 +24,8 @@ class C {
console.log(one.backup());
});
}
}
}


//// [0.js]
export class B {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,4 @@ class C {
});
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,4 @@ class C {
});
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ tests/cases/conformance/dynamicImport/2.ts(6,24): error TS7036: Dynamic import's
!!! error TS7036: Dynamic import's specifier must be of type 'string', but here has type '"./1" | null'.
let myModule3 = import(null);
~~~~
!!! error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'null'.
!!! error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'null'.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//// [tests/cases/conformance/dynamicImport/importCallExpression5ESNext.ts] ////
//// [tests/cases/conformance/dynamicImport/importCallExpression5ES2020.ts] ////

//// [0.ts]
export class B {
Expand All @@ -16,7 +16,8 @@ const specify = bar() ? "./0" : undefined;
let myModule = import(specify);
let myModule1 = import(undefined);
let myModule2 = import(bar() ? "./1" : null);
let myModule3 = import(null);
let myModule3 = import(null);


//// [0.js]
export class B {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ tests/cases/conformance/dynamicImport/2.ts(6,24): error TS7036: Dynamic import's
let myModule2 = import(bar() ? "./1" : null);
let myModule3 = import(null);
~~~~
!!! error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'null'.
!!! error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'null'.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//// [tests/cases/conformance/dynamicImport/importCallExpression6ESNext.ts] ////
//// [tests/cases/conformance/dynamicImport/importCallExpression6ES2020.ts] ////

//// [0.ts]
export class B {
Expand All @@ -16,7 +16,8 @@ const specify = bar() ? "./0" : undefined;
let myModule = import(specify);
let myModule1 = import(undefined);
let myModule2 = import(bar() ? "./1" : null);
let myModule3 = import(null);
let myModule3 = import(null);


//// [0.js]
export class B {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
export function foo() { return "foo"; }

//// [1.ts]
var p1 = import("./0");
var p1 = import("./0");


//// [0.js]
export function foo() { return "foo"; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
tests/cases/conformance/dynamicImport/1.ts(1,1): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'esnext', 'commonjs', 'amd', 'system', or 'umd'.
tests/cases/conformance/dynamicImport/1.ts(2,10): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'esnext', 'commonjs', 'amd', 'system', or 'umd'.
tests/cases/conformance/dynamicImport/1.ts(8,16): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'esnext', 'commonjs', 'amd', 'system', or 'umd'.
tests/cases/conformance/dynamicImport/1.ts(1,1): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'.
tests/cases/conformance/dynamicImport/1.ts(2,10): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'.
tests/cases/conformance/dynamicImport/1.ts(8,16): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'.


==== tests/cases/conformance/dynamicImport/0.ts (0 errors) ====
Expand All @@ -9,16 +9,16 @@ tests/cases/conformance/dynamicImport/1.ts(8,16): error TS1323: Dynamic imports
==== tests/cases/conformance/dynamicImport/1.ts (3 errors) ====
import("./0");
~~~~~~~~~~~~~
!!! error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'esnext', 'commonjs', 'amd', 'system', or 'umd'.
!!! error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'.
var p1 = import("./0");
~~~~~~~~~~~~~
!!! error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'esnext', 'commonjs', 'amd', 'system', or 'umd'.
!!! error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'.
p1.then(zero => {
return zero.foo();
})

function foo() {
const p2 = import("./0");
~~~~~~~~~~~~~
!!! error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'esnext', 'commonjs', 'amd', 'system', or 'umd'.
!!! error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'.
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ tests/cases/conformance/dynamicImport/1.ts(2,1): error TS1109: Expression expect
import
import { foo } from './0';
~~~~~~
!!! error TS1109: Expression expected.
!!! error TS1109: Expression expected.

3 changes: 2 additions & 1 deletion tests/baselines/reference/importCallExpressionIncorrect1.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ export function foo() { return "foo"; }

//// [1.ts]
import
import { foo } from './0';
import { foo } from './0';


//// [0.js]
export function foo() { return "foo"; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ tests/cases/conformance/dynamicImport/1.ts(1,9): error TS1109: Expression expect
==== tests/cases/conformance/dynamicImport/1.ts (1 errors) ====
var x = import { foo } from './0';
~~~~~~
!!! error TS1109: Expression expected.
!!! error TS1109: Expression expected.

3 changes: 2 additions & 1 deletion tests/baselines/reference/importCallExpressionIncorrect2.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
export function foo() { return "foo"; }

//// [1.ts]
var x = import { foo } from './0';
var x = import { foo } from './0';


//// [0.js]
export function foo() { return "foo"; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
tests/cases/conformance/dynamicImport/index.ts(2,18): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'esnext', 'commonjs', 'amd', 'system', or 'umd'.
tests/cases/conformance/dynamicImport/index.ts(2,32): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'esnext', 'commonjs', 'amd', 'system', or 'umd'.
tests/cases/conformance/dynamicImport/index.ts(2,18): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'.
tests/cases/conformance/dynamicImport/index.ts(2,32): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'.


==== tests/cases/conformance/dynamicImport/foo.ts (0 errors) ====
Expand All @@ -9,7 +9,7 @@ tests/cases/conformance/dynamicImport/index.ts(2,32): error TS1323: Dynamic impo
async function foo() {
return await import((await import("./foo")).default);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'esnext', 'commonjs', 'amd', 'system', or 'umd'.
!!! error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'.
~~~~~~~~~~~~~~~
!!! error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'esnext', 'commonjs', 'amd', 'system', or 'umd'.
!!! error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'.
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
tests/cases/conformance/dynamicImport/index.ts(2,18): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'esnext', 'commonjs', 'amd', 'system', or 'umd'.
tests/cases/conformance/dynamicImport/index.ts(2,32): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'esnext', 'commonjs', 'amd', 'system', or 'umd'.
tests/cases/conformance/dynamicImport/index.ts(2,18): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'.
tests/cases/conformance/dynamicImport/index.ts(2,32): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'.


==== tests/cases/conformance/dynamicImport/foo.ts (0 errors) ====
Expand All @@ -9,7 +9,7 @@ tests/cases/conformance/dynamicImport/index.ts(2,32): error TS1323: Dynamic impo
async function foo() {
return await import((await import("./foo")).default);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'esnext', 'commonjs', 'amd', 'system', or 'umd'.
!!! error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'.
~~~~~~~~~~~~~~~
!!! error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'esnext', 'commonjs', 'amd', 'system', or 'umd'.
!!! error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'.
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
//// [tests/cases/conformance/dynamicImport/importCallExpressionNestedESNext.ts] ////
//// [tests/cases/conformance/dynamicImport/importCallExpressionNestedES2020.ts] ////

//// [foo.ts]
export default "./foo";

//// [index.ts]
async function foo() {
return await import((await import("./foo")).default);
}
}


//// [foo.js]
export default "./foo";
Expand Down
Loading