From 787ed372fbe7448ffd6b1d449de1885ee6bffdbc Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Wed, 8 Mar 2017 14:57:57 -0800 Subject: [PATCH 01/67] Use term UpdateExpression instead of IncrementExpression to keep it consistent with ECMA spec --- src/compiler/parser.ts | 16 ++++++++-------- src/compiler/types.ts | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 308d3a317f9..ca3f0c25e4d 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3509,10 +3509,10 @@ namespace ts { * 5) --UnaryExpression[?Yield] */ if (isUpdateExpression()) { - const incrementExpression = parseIncrementExpression(); + const UpdateExpression = parseUpdateExpression(); return token() === SyntaxKind.AsteriskAsteriskToken ? - parseBinaryExpressionRest(getBinaryOperatorPrecedence(), incrementExpression) : - incrementExpression; + parseBinaryExpressionRest(getBinaryOperatorPrecedence(), UpdateExpression) : + UpdateExpression; } /** @@ -3577,7 +3577,7 @@ namespace ts { return parseAwaitExpression(); } default: - return parseIncrementExpression(); + return parseUpdateExpression(); } } @@ -3593,7 +3593,7 @@ namespace ts { */ function isUpdateExpression(): boolean { // This function is called inside parseUnaryExpression to decide - // whether to call parseSimpleUnaryExpression or call parseIncrementExpression directly + // whether to call parseSimpleUnaryExpression or call parseUpdateExpression directly switch (token()) { case SyntaxKind.PlusToken: case SyntaxKind.MinusToken: @@ -3617,9 +3617,9 @@ namespace ts { } /** - * Parse ES7 IncrementExpression. IncrementExpression is used instead of ES6's PostFixExpression. + * Parse ES7 UpdateExpression. UpdateExpression is used instead of ES6's PostFixExpression. * - * ES7 IncrementExpression[yield]: + * ES7 UpdateExpression[yield]: * 1) LeftHandSideExpression[?yield] * 2) LeftHandSideExpression[?yield] [[no LineTerminator here]]++ * 3) LeftHandSideExpression[?yield] [[no LineTerminator here]]-- @@ -3627,7 +3627,7 @@ namespace ts { * 5) --LeftHandSideExpression[?yield] * In TypeScript (2), (3) are parsed as PostfixUnaryExpression. (4), (5) are parsed as PrefixUnaryExpression */ - function parseIncrementExpression(): IncrementExpression { + function parseUpdateExpression(): UpdateExpression { if (token() === SyntaxKind.PlusPlusToken || token() === SyntaxKind.MinusMinusToken) { const node = createNode(SyntaxKind.PrefixUnaryExpression); node.operator = token(); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 759d2a98660..f0a26fbf996 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -982,7 +982,7 @@ namespace ts { _unaryExpressionBrand: any; } - export interface IncrementExpression extends UnaryExpression { + export interface UpdateExpression extends UnaryExpression { _incrementExpressionBrand: any; } @@ -997,7 +997,7 @@ namespace ts { | SyntaxKind.ExclamationToken ; - export interface PrefixUnaryExpression extends IncrementExpression { + export interface PrefixUnaryExpression extends UpdateExpression { kind: SyntaxKind.PrefixUnaryExpression; operator: PrefixUnaryOperator; operand: UnaryExpression; @@ -1009,13 +1009,13 @@ namespace ts { | SyntaxKind.MinusMinusToken ; - export interface PostfixUnaryExpression extends IncrementExpression { + export interface PostfixUnaryExpression extends UpdateExpression { kind: SyntaxKind.PostfixUnaryExpression; operand: LeftHandSideExpression; operator: PostfixUnaryOperator; } - export interface LeftHandSideExpression extends IncrementExpression { + export interface LeftHandSideExpression extends UpdateExpression { _leftHandSideExpressionBrand: any; } From ca0816710a1dfa3188a33e7dd91bb15f5a7e7ce2 Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Wed, 8 Mar 2017 15:53:38 -0800 Subject: [PATCH 02/67] Wip-parsing import call expression --- src/compiler/parser.ts | 36 ++++++++++++++++++++++++++---------- src/compiler/types.ts | 13 +++++++++---- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index ca3f0c25e4d..3641912e76e 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3677,17 +3677,25 @@ namespace ts { // CallExpression Arguments // CallExpression[Expression] // CallExpression.IdentifierName - // super ( ArgumentListopt ) + // import (AssignmentExpression) + // super Arguments // super.IdentifierName // - // Because of the recursion in these calls, we need to bottom out first. There are two - // bottom out states we can run into. Either we see 'super' which must start either of - // the last two CallExpression productions. Or we have a MemberExpression which either - // completes the LeftHandSideExpression, or starts the beginning of the first four - // CallExpression productions. - const expression = token() === SyntaxKind.SuperKeyword - ? parseSuperExpression() - : parseMemberExpressionOrHigher(); + // Because of the recursion in these calls, we need to bottom out first. There are three + // bottom out states we can run into: 1) We see 'super' which must start either of + // the last two CallExpression productions. 2) We see 'import' which must start import call. + // 3)we have a MemberExpression which either completes the LeftHandSideExpression, + // or starts the beginning of the first four CallExpression productions. + let expression: MemberExpression; + if (token() === SyntaxKind.SuperKeyword) { + expression = parseSuperExpression(); + } + else if (token() === SyntaxKind.ImportKeyword) { + expression = parseImportExpression(); + } + else { + expression = parseMemberExpressionOrHigher(); + } // Now, we *may* be complete. However, we might have consumed the start of a // CallExpression. As such, we need to consume the rest of it here to be complete. @@ -3695,7 +3703,7 @@ namespace ts { } function parseMemberExpressionOrHigher(): MemberExpression { - // Note: to make our lives simpler, we decompose the the NewExpression productions and + // Note: to make our lives simpler, we decompose the NewExpression productions and // place ObjectCreationExpression and FunctionExpression into PrimaryExpression. // like so: // @@ -3761,6 +3769,14 @@ namespace ts { return finishNode(node); } + function parseImportExpression(): MemberExpression { + const expression = parseTokenNode(); + if (token() === SyntaxKind.OpenParenToken) { + return expression; + } + // (TODO(yuisu): Error Handling here + } + function tagNamesAreEquivalent(lhs: JsxTagNameExpression, rhs: JsxTagNameExpression): boolean { if (lhs.kind !== rhs.kind) { return false; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index f0a26fbf996..335ff99453e 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1043,6 +1043,10 @@ namespace ts { kind: SyntaxKind.SuperKeyword; } + export interface ImportExpression extends PrimaryExpression { + kind: SyntaxKind.ImportKeyword + } + export interface DeleteExpression extends UnaryExpression { kind: SyntaxKind.DeleteExpression; expression: UnaryExpression; @@ -1425,10 +1429,7 @@ namespace ts { } // see: https://tc39.github.io/ecma262/#prod-SuperProperty - export type SuperProperty - = SuperPropertyAccessExpression - | SuperElementAccessExpression - ; + export type SuperProperty = SuperPropertyAccessExpression | SuperElementAccessExpression; export interface CallExpression extends LeftHandSideExpression, Declaration { kind: SyntaxKind.CallExpression; @@ -1442,6 +1443,10 @@ namespace ts { expression: SuperExpression; } + export interface ImportCall extends CallExpression { + expression: ImportExpression; + } + export interface ExpressionWithTypeArguments extends TypeNode { kind: SyntaxKind.ExpressionWithTypeArguments; parent?: HeritageClause; From 330f7bf96cc6020f9c9b0933a6c97aa4e5c16911 Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Thu, 9 Mar 2017 15:55:09 -0800 Subject: [PATCH 03/67] Correctly parse import() --- src/compiler/parser.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 3641912e76e..5a3560d45e6 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3686,11 +3686,15 @@ namespace ts { // the last two CallExpression productions. 2) We see 'import' which must start import call. // 3)we have a MemberExpression which either completes the LeftHandSideExpression, // or starts the beginning of the first four CallExpression productions. - let expression: MemberExpression; + let expression: LeftHandSideExpression; if (token() === SyntaxKind.SuperKeyword) { expression = parseSuperExpression(); } - else if (token() === SyntaxKind.ImportKeyword) { + else if (token() === SyntaxKind.ImportKeyword && lookAhead(nextTokenIsOpenParen)) { + // We don't want to eagerly consume all import keyword as import call expression. + // For example: + // var foo3 = require("subfolder//*require0*/ + // import * as foo1 from "module-from-node//*import_as1*/ -> we want this import to be a statement rather than import call expression expression = parseImportExpression(); } else { @@ -3769,12 +3773,12 @@ namespace ts { return finishNode(node); } - function parseImportExpression(): MemberExpression { + function parseImportExpression(): LeftHandSideExpression { const expression = parseTokenNode(); if (token() === SyntaxKind.OpenParenToken) { return expression; } - // (TODO(yuisu): Error Handling here + Debug.assert(token() === SyntaxKind.OpenParenToken, "Parsing import expression expects open parenthesis after import keyword"); } function tagNamesAreEquivalent(lhs: JsxTagNameExpression, rhs: JsxTagNameExpression): boolean { @@ -4792,11 +4796,11 @@ namespace ts { // however, we say they are here so that we may gracefully parse them and error later. case SyntaxKind.CatchKeyword: case SyntaxKind.FinallyKeyword: + case SyntaxKind.ImportKeyword: return true; case SyntaxKind.ConstKeyword: case SyntaxKind.ExportKeyword: - case SyntaxKind.ImportKeyword: return isStartOfDeclaration(); case SyntaxKind.AsyncKeyword: From 827abb35767fc4da1e8698c740dc075e313bab41 Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 9 Mar 2017 22:30:06 -0800 Subject: [PATCH 04/67] Parse import call and use collect its specifier --- src/compiler/parser.ts | 38 ++++++++++++++++++++------------------ src/compiler/program.ts | 7 ++----- src/compiler/types.ts | 9 +++++++-- src/compiler/utilities.ts | 7 ++++++- 4 files changed, 35 insertions(+), 26 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 5a3560d45e6..c1a8f293418 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -167,6 +167,8 @@ namespace ts { return visitNode(cbNode, (node).expression) || visitNodes(cbNodes, (node).typeArguments) || visitNodes(cbNodes, (node).arguments); + case SyntaxKind.ImportCallExpression: + return visitNode(cbNode, (node).expression); case SyntaxKind.TaggedTemplateExpression: return visitNode(cbNode, (node).tag) || visitNode(cbNode, (node).template); @@ -3686,20 +3688,19 @@ namespace ts { // the last two CallExpression productions. 2) We see 'import' which must start import call. // 3)we have a MemberExpression which either completes the LeftHandSideExpression, // or starts the beginning of the first four CallExpression productions. - let expression: LeftHandSideExpression; - if (token() === SyntaxKind.SuperKeyword) { - expression = parseSuperExpression(); - } - else if (token() === SyntaxKind.ImportKeyword && lookAhead(nextTokenIsOpenParen)) { - // We don't want to eagerly consume all import keyword as import call expression. + + if (token() === SyntaxKind.ImportKeyword && lookAhead(nextTokenIsOpenParen)) { + // We don't want to eagerly consume all import keyword as import call expression so we look a head to find "(" // For example: - // var foo3 = require("subfolder//*require0*/ - // import * as foo1 from "module-from-node//*import_as1*/ -> we want this import to be a statement rather than import call expression - expression = parseImportExpression(); - } - else { - expression = parseMemberExpressionOrHigher(); + // var foo3 = require("subfolder + // import * as foo1 from "module-from-node -> we want this import to be a statement rather than import call expression + const importCall = parseImportCall(); + if (importCall.expression.kind === SyntaxKind.StringLiteral) { + (sourceFile.imports || (sourceFile.imports = [])).push(importCall.expression as StringLiteral); + } + return importCall; } + const expression = token() === SyntaxKind.SuperKeyword ? parseSuperExpression() : parseMemberExpressionOrHigher(); // Now, we *may* be complete. However, we might have consumed the start of a // CallExpression. As such, we need to consume the rest of it here to be complete. @@ -3773,12 +3774,13 @@ namespace ts { return finishNode(node); } - function parseImportExpression(): LeftHandSideExpression { - const expression = parseTokenNode(); - if (token() === SyntaxKind.OpenParenToken) { - return expression; - } - Debug.assert(token() === SyntaxKind.OpenParenToken, "Parsing import expression expects open parenthesis after import keyword"); + function parseImportCall(): ImportCall { + const importCallExpr = createNode(SyntaxKind.ImportCallExpression); + parseExpected(SyntaxKind.ImportKeyword); + parseExpected(SyntaxKind.OpenParenToken); + importCallExpr.expression = parseAssignmentExpressionOrHigher(); + parseExpected(SyntaxKind.CloseParenToken); + return finishNode(importCallExpr); } function tagNamesAreEquivalent(lhs: JsxTagNameExpression, rhs: JsxTagNameExpression): boolean { diff --git a/src/compiler/program.ts b/src/compiler/program.ts index abb8b0b2f09..ec263831cd4 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1178,15 +1178,12 @@ namespace ts { } function collectExternalModuleReferences(file: SourceFile): void { - if (file.imports) { - return; - } - const isJavaScriptFile = isSourceFileJavaScript(file); const isExternalModuleFile = isExternalModule(file); const isDtsFile = isDeclarationFile(file); - let imports: LiteralExpression[]; + // file.imports may not be undefined if there exists dynamic import + let imports = file.imports; let moduleAugmentations: LiteralExpression[]; let ambientModules: string[]; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 28ec1cba955..d3ecdef2799 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -391,8 +391,12 @@ namespace ts { MergeDeclarationMarker, EndOfDeclarationMarker, + // Dynamic import + ImportCallExpression, + // Enum value count Count, + // Markers FirstAssignment = EqualsToken, LastAssignment = CaretEqualsToken, @@ -1443,8 +1447,9 @@ namespace ts { expression: SuperExpression; } - export interface ImportCall extends CallExpression { - expression: ImportExpression; + export interface ImportCall extends LeftHandSideExpression, Declaration { + kind: SyntaxKind.ImportCallExpression; + expression: Expression; } export interface ExpressionWithTypeArguments extends TypeNode { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index a5229b614be..98a95e9e861 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -662,6 +662,10 @@ namespace ts { return n.kind === SyntaxKind.CallExpression && (n).expression.kind === SyntaxKind.SuperKeyword; } + export function isImportCall(n: Node): n is ImportCall { + return n.kind === SyntaxKind.ImportCallExpression; + } + export function isPrologueDirective(node: Node): node is PrologueDirective { return node.kind === SyntaxKind.ExpressionStatement && (node).expression.kind === SyntaxKind.StringLiteral; @@ -3886,7 +3890,8 @@ namespace ts { || kind === SyntaxKind.TrueKeyword || kind === SyntaxKind.SuperKeyword || kind === SyntaxKind.NonNullExpression - || kind === SyntaxKind.MetaProperty; + || kind === SyntaxKind.MetaProperty + || kind === SyntaxKind.ImportCallExpression; } export function isLeftHandSideExpression(node: Node): node is LeftHandSideExpression { From 6933b581c0aa7569a37c21d66964f350a22ceba5 Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Fri, 10 Mar 2017 16:27:22 -0800 Subject: [PATCH 05/67] Wip-type check dynamic import --- src/compiler/binder.ts | 2 +- src/compiler/checker.ts | 10 +++++++++- src/compiler/parser.ts | 12 ++++++------ src/compiler/types.ts | 4 ++-- src/compiler/utilities.ts | 2 +- 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 418905e604c..b3554876c14 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -2317,7 +2317,7 @@ namespace ts { // A common practice in node modules is to set 'export = module.exports = {}', this ensures that 'exports' // is still pointing to 'module.exports'. // We do not want to consider this as 'export=' since a module can have only one of these. - // Similarlly we do not want to treat 'module.exports = exports' as an 'export='. + // Similarly we do not want to treat 'module.exports = exports' as an 'export='. const assignedExpression = getRightMostAssignedExpression(node.right); if (isEmptyObjectLiteral(assignedExpression) || isExportsOrModuleExportsOrAlias(assignedExpression)) { // Mark it as a module in case there are no other exports in the file diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 00498191f28..f9645b0986c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -14862,6 +14862,14 @@ namespace ts { return getReturnTypeOfSignature(signature); } + function checkImportCallExpression(node: ImportCallExpression): Type { + // resolveExternalModuleName will return undefined if the moduleReferenceExpression is not a string literal + const moduleSymbol = resolveExternalModuleName(node, node.specifier); + if (moduleSymbol) { + } + return createPromiseReturnType(node, anyType); + } + function isCommonJsRequire(node: Node) { if (!isRequireCall(node, /*checkArgumentIsStringLiteral*/true)) { return false; @@ -15068,7 +15076,7 @@ namespace ts { return emptyObjectType; } - function createPromiseReturnType(func: FunctionLikeDeclaration, promisedType: Type) { + function createPromiseReturnType(func: FunctionLikeDeclaration | ImportCallExpression, promisedType: Type) { const promiseType = createPromiseType(promisedType); if (promiseType === emptyObjectType) { error(func, Diagnostics.An_async_function_or_method_must_return_a_Promise_Make_sure_you_have_a_declaration_for_Promise_or_include_ES2015_in_your_lib_option); diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index c1a8f293418..5eb0bc60e68 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -168,7 +168,7 @@ namespace ts { visitNodes(cbNodes, (node).typeArguments) || visitNodes(cbNodes, (node).arguments); case SyntaxKind.ImportCallExpression: - return visitNode(cbNode, (node).expression); + return visitNode(cbNode, (node).specifier); case SyntaxKind.TaggedTemplateExpression: return visitNode(cbNode, (node).tag) || visitNode(cbNode, (node).template); @@ -3695,8 +3695,8 @@ namespace ts { // var foo3 = require("subfolder // import * as foo1 from "module-from-node -> we want this import to be a statement rather than import call expression const importCall = parseImportCall(); - if (importCall.expression.kind === SyntaxKind.StringLiteral) { - (sourceFile.imports || (sourceFile.imports = [])).push(importCall.expression as StringLiteral); + if (importCall.specifier.kind === SyntaxKind.StringLiteral) { + (sourceFile.imports || (sourceFile.imports = [])).push(importCall.specifier as StringLiteral); } return importCall; } @@ -3774,11 +3774,11 @@ namespace ts { return finishNode(node); } - function parseImportCall(): ImportCall { - const importCallExpr = createNode(SyntaxKind.ImportCallExpression); + function parseImportCall(): ImportCallExpression { + const importCallExpr = createNode(SyntaxKind.ImportCallExpression); parseExpected(SyntaxKind.ImportKeyword); parseExpected(SyntaxKind.OpenParenToken); - importCallExpr.expression = parseAssignmentExpressionOrHigher(); + importCallExpr.specifier = parseAssignmentExpressionOrHigher(); parseExpected(SyntaxKind.CloseParenToken); return finishNode(importCallExpr); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index d3ecdef2799..8a19e4d62a1 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1447,9 +1447,9 @@ namespace ts { expression: SuperExpression; } - export interface ImportCall extends LeftHandSideExpression, Declaration { + export interface ImportCallExpression extends LeftHandSideExpression, Declaration { kind: SyntaxKind.ImportCallExpression; - expression: Expression; + specifier: Expression; } export interface ExpressionWithTypeArguments extends TypeNode { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 98a95e9e861..db512cfffe7 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -662,7 +662,7 @@ namespace ts { return n.kind === SyntaxKind.CallExpression && (n).expression.kind === SyntaxKind.SuperKeyword; } - export function isImportCall(n: Node): n is ImportCall { + export function isImportCall(n: Node): n is ImportCallExpression { return n.kind === SyntaxKind.ImportCallExpression; } From 126fb640dbe8e9a121502847e45575f93d40f451 Mon Sep 17 00:00:00 2001 From: Yui T Date: Fri, 10 Mar 2017 22:07:08 -0800 Subject: [PATCH 06/67] Wip-type check dynamic import --- src/compiler/binder.ts | 2 +- src/compiler/checker.ts | 24 +++++++++++++++++++++--- src/compiler/diagnosticMessages.json | 8 ++++++++ src/compiler/parser.ts | 12 ++++++------ src/compiler/types.ts | 4 ++-- src/compiler/utilities.ts | 2 +- 6 files changed, 39 insertions(+), 13 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 418905e604c..b3554876c14 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -2317,7 +2317,7 @@ namespace ts { // A common practice in node modules is to set 'export = module.exports = {}', this ensures that 'exports' // is still pointing to 'module.exports'. // We do not want to consider this as 'export=' since a module can have only one of these. - // Similarlly we do not want to treat 'module.exports = exports' as an 'export='. + // Similarly we do not want to treat 'module.exports = exports' as an 'export='. const assignedExpression = getRightMostAssignedExpression(node.right); if (isEmptyObjectLiteral(assignedExpression) || isExportsOrModuleExportsOrAlias(assignedExpression)) { // Mark it as a module in case there are no other exports in the file diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 00498191f28..14b4506baa8 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -14862,6 +14862,18 @@ namespace ts { return getReturnTypeOfSignature(signature); } + function checkImportCallExpression(node: ImportCallExpression): Type { + // resolveExternalModuleName will return undefined if the moduleReferenceExpression is not a string literal + const moduleSymbol = resolveExternalModuleName(node, node.specifier); + if (moduleSymbol) { + const esModuleSymbol = resolveESModuleSymbol(moduleSymbol, node.specifier); + if (esModuleSymbol) { + return createPromiseReturnType(node, getTypeOfSymbol(esModuleSymbol)); + } + } + return createPromiseReturnType(node, anyType); + } + function isCommonJsRequire(node: Node) { if (!isRequireCall(node, /*checkArgumentIsStringLiteral*/true)) { return false; @@ -15068,14 +15080,18 @@ namespace ts { return emptyObjectType; } - function createPromiseReturnType(func: FunctionLikeDeclaration, promisedType: Type) { + function createPromiseReturnType(func: FunctionLikeDeclaration | ImportCallExpression, promisedType: Type) { const promiseType = createPromiseType(promisedType); if (promiseType === emptyObjectType) { - error(func, Diagnostics.An_async_function_or_method_must_return_a_Promise_Make_sure_you_have_a_declaration_for_Promise_or_include_ES2015_in_your_lib_option); + error(func, isImportCallExpression(func) ? + Diagnostics.An_async_function_or_method_must_return_a_Promise_Make_sure_you_have_a_declaration_for_Promise_or_include_ES2015_in_your_lib_option : + Diagnostics.A_dynamic_import_call_must_return_a_Promise_Make_sure_you_have_a_declaration_for_Promise_or_include_ES2015_in_your_lib_option); return unknownType; } else if (!getGlobalPromiseConstructorSymbol(/*reportErrors*/ true)) { - error(func, Diagnostics.An_async_function_or_method_in_ES5_SlashES3_requires_the_Promise_constructor_Make_sure_you_have_a_declaration_for_the_Promise_constructor_or_include_ES2015_in_your_lib_option); + error(func, isImportCallExpression(func) ? + Diagnostics.An_async_function_or_method_in_ES5_SlashES3_requires_the_Promise_constructor_Make_sure_you_have_a_declaration_for_the_Promise_constructor_or_include_ES2015_in_your_lib_option : + Diagnostics.A_dynamic_import_call_in_ES5_SlashES3_requires_the_Promise_constructor_Make_sure_you_have_a_declaration_for_the_Promise_constructor_or_include_ES2015_in_your_lib_option); } return promiseType; @@ -16398,6 +16414,8 @@ namespace ts { case SyntaxKind.CallExpression: case SyntaxKind.NewExpression: return checkCallExpression(node); + case SyntaxKind.ImportCallExpression: + return checkImportCallExpression(node); case SyntaxKind.TaggedTemplateExpression: return checkTaggedTemplateExpression(node); case SyntaxKind.ParenthesizedExpression: diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 318f06ceeaa..5d7f570ef02 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2091,6 +2091,14 @@ "category": "Error", "code": 2707 }, + "A dynamic import call must return a 'Promise'. Make sure you have a declaration for 'Promise' or include 'ES2015' in your `--lib` option.": { + "category": "Error", + "code": 2708 + }, + "A dynamic import call in ES5/ES3 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your `--lib` option.": { + "category": "Error", + "code": 2709 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index c1a8f293418..5eb0bc60e68 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -168,7 +168,7 @@ namespace ts { visitNodes(cbNodes, (node).typeArguments) || visitNodes(cbNodes, (node).arguments); case SyntaxKind.ImportCallExpression: - return visitNode(cbNode, (node).expression); + return visitNode(cbNode, (node).specifier); case SyntaxKind.TaggedTemplateExpression: return visitNode(cbNode, (node).tag) || visitNode(cbNode, (node).template); @@ -3695,8 +3695,8 @@ namespace ts { // var foo3 = require("subfolder // import * as foo1 from "module-from-node -> we want this import to be a statement rather than import call expression const importCall = parseImportCall(); - if (importCall.expression.kind === SyntaxKind.StringLiteral) { - (sourceFile.imports || (sourceFile.imports = [])).push(importCall.expression as StringLiteral); + if (importCall.specifier.kind === SyntaxKind.StringLiteral) { + (sourceFile.imports || (sourceFile.imports = [])).push(importCall.specifier as StringLiteral); } return importCall; } @@ -3774,11 +3774,11 @@ namespace ts { return finishNode(node); } - function parseImportCall(): ImportCall { - const importCallExpr = createNode(SyntaxKind.ImportCallExpression); + function parseImportCall(): ImportCallExpression { + const importCallExpr = createNode(SyntaxKind.ImportCallExpression); parseExpected(SyntaxKind.ImportKeyword); parseExpected(SyntaxKind.OpenParenToken); - importCallExpr.expression = parseAssignmentExpressionOrHigher(); + importCallExpr.specifier = parseAssignmentExpressionOrHigher(); parseExpected(SyntaxKind.CloseParenToken); return finishNode(importCallExpr); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index d3ecdef2799..8a19e4d62a1 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1447,9 +1447,9 @@ namespace ts { expression: SuperExpression; } - export interface ImportCall extends LeftHandSideExpression, Declaration { + export interface ImportCallExpression extends LeftHandSideExpression, Declaration { kind: SyntaxKind.ImportCallExpression; - expression: Expression; + specifier: Expression; } export interface ExpressionWithTypeArguments extends TypeNode { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 98a95e9e861..47c26301d1b 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -662,7 +662,7 @@ namespace ts { return n.kind === SyntaxKind.CallExpression && (n).expression.kind === SyntaxKind.SuperKeyword; } - export function isImportCall(n: Node): n is ImportCall { + export function isImportCallExpression(n: Node): n is ImportCallExpression { return n.kind === SyntaxKind.ImportCallExpression; } From 7340d84a0288b1f89e4167196cd1d62cf101dcc2 Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Mon, 13 Mar 2017 14:47:54 -0700 Subject: [PATCH 07/67] Rename importcall to importCallExpression --- src/compiler/parser.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 5eb0bc60e68..fbcbfae0bdf 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3694,7 +3694,7 @@ namespace ts { // For example: // var foo3 = require("subfolder // import * as foo1 from "module-from-node -> we want this import to be a statement rather than import call expression - const importCall = parseImportCall(); + const importCall = parseImportCallExpression(); if (importCall.specifier.kind === SyntaxKind.StringLiteral) { (sourceFile.imports || (sourceFile.imports = [])).push(importCall.specifier as StringLiteral); } @@ -3774,7 +3774,7 @@ namespace ts { return finishNode(node); } - function parseImportCall(): ImportCallExpression { + function parseImportCallExpression(): ImportCallExpression { const importCallExpr = createNode(SyntaxKind.ImportCallExpression); parseExpected(SyntaxKind.ImportKeyword); parseExpected(SyntaxKind.OpenParenToken); From 18c826b3aa4d82b398ba4ab4ae6d9b825f83ad77 Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Mon, 13 Mar 2017 14:48:40 -0700 Subject: [PATCH 08/67] Add new value "es2018" for module kind --- src/compiler/commandLineParser.ts | 3 ++- src/compiler/diagnosticMessages.json | 2 +- src/compiler/types.ts | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 4b3dc23d565..6c88af845ee 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -109,8 +109,9 @@ namespace ts { "umd": ModuleKind.UMD, "es6": ModuleKind.ES2015, "es2015": ModuleKind.ES2015, + "es2018": ModuleKind.ES2018 }), - description: Diagnostics.Specify_module_code_generation_Colon_commonjs_amd_system_umd_or_es2015, + description: Diagnostics.Specify_module_code_generation_Colon_commonjs_amd_system_umd_es2015_or_es2018, paramType: Diagnostics.KIND, }, { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 5d7f570ef02..7397f278769 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2569,7 +2569,7 @@ "category": "Message", "code": 6015 }, - "Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'.": { + "Specify module code generation: 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'es2018'.": { "category": "Message", "code": 6016 }, diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 8a19e4d62a1..c8b16130f29 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3426,6 +3426,7 @@ namespace ts { UMD = 3, System = 4, ES2015 = 5, + ES2018 = 6 } export const enum JsxEmit { From ddf5ed944be2abac6eb1440cc7cfeea9b862c667 Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Mon, 13 Mar 2017 15:12:10 -0700 Subject: [PATCH 09/67] Emit dynamic import when module kind is es2018 --- src/compiler/emitter.ts | 9 +++++++++ src/compiler/factory.ts | 12 ++++++++++++ src/compiler/transformer.ts | 1 + src/compiler/visitor.ts | 4 ++++ 4 files changed, 26 insertions(+) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index b10f2e7cb17..5f0e1bd5e92 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -671,6 +671,8 @@ namespace ts { return emitCallExpression(node); case SyntaxKind.NewExpression: return emitNewExpression(node); + case SyntaxKind.ImportCallExpression: + return emitImportCallExpression(node); case SyntaxKind.TaggedTemplateExpression: return emitTaggedTemplateExpression(node); case SyntaxKind.TypeAssertionExpression: @@ -1153,6 +1155,13 @@ namespace ts { emitExpressionList(node, node.arguments, ListFormat.NewExpressionArguments); } + function emitImportCallExpression(node: ImportCallExpression) { + write("import"); + write("("); + emitExpression(node.specifier); + write(")"); + } + function emitTaggedTemplateExpression(node: TaggedTemplateExpression) { emitExpression(node.tag); write(" "); diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index 3ff3bc2782f..0bf545f4fe1 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -503,6 +503,18 @@ namespace ts { : node; } + export function createImportCall(specifier: Expression): ImportCallExpression { + const node = createSynthesizedNode(SyntaxKind.ImportCallExpression); + node.specifier = specifier; + return node; + } + + export function updateImportCall(node: ImportCallExpression, specifier: Expression): ImportCallExpression { + return node.specifier !== specifier + ? updateNode(createImportCall(specifier), node) + : node; + } + export function createTaggedTemplate(tag: Expression, template: TemplateLiteral) { const node = createSynthesizedNode(SyntaxKind.TaggedTemplateExpression); node.tag = parenthesizeForAccess(tag); diff --git a/src/compiler/transformer.ts b/src/compiler/transformer.ts index bb1732b57ea..618e626f463 100644 --- a/src/compiler/transformer.ts +++ b/src/compiler/transformer.ts @@ -15,6 +15,7 @@ namespace ts { function getModuleTransformer(moduleKind: ModuleKind): TransformerFactory { switch (moduleKind) { + case ModuleKind.ES2018: case ModuleKind.ES2015: return transformES2015Module; case ModuleKind.System: diff --git a/src/compiler/visitor.ts b/src/compiler/visitor.ts index 0f4a4ed6561..91ae6560c7d 100644 --- a/src/compiler/visitor.ts +++ b/src/compiler/visitor.ts @@ -339,6 +339,10 @@ namespace ts { visitNodes((node).typeArguments, visitor, isTypeNode), visitNodes((node).arguments, visitor, isExpression)); + case SyntaxKind.ImportCallExpression: + return updateImportCall(node, + visitNode((node).specifier, visitor, isExpression)); + case SyntaxKind.NewExpression: return updateNew(node, visitNode((node).expression, visitor, isExpression), From 26f9a52e9252a6c4a1d65df4e2a5a0d187dbab24 Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Mon, 13 Mar 2017 17:07:13 -0700 Subject: [PATCH 10/67] Add initial tests --- .../es2018/dynamicImport/importCallExpression1.ts | 11 +++++++++++ .../es2018/dynamicImport/importCallExpression2.ts | 10 ++++++++++ 2 files changed, 21 insertions(+) create mode 100644 tests/cases/conformance/es2018/dynamicImport/importCallExpression1.ts create mode 100644 tests/cases/conformance/es2018/dynamicImport/importCallExpression2.ts diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpression1.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpression1.ts new file mode 100644 index 00000000000..f0fd00f9c79 --- /dev/null +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpression1.ts @@ -0,0 +1,11 @@ +// @module: es2018 +// @target: esnext +// @filename: 0.ts +export function foo() { return "foo"; } + +// @filename: 1.ts +import("./0"); +var p1 = import("./0"); +p1.then(zero => { + return zero.foo(); +}) \ No newline at end of file diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpression2.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpression2.ts new file mode 100644 index 00000000000..57ea587ce73 --- /dev/null +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpression2.ts @@ -0,0 +1,10 @@ +// @module: es2018 +// @lib: es2015 +// @filename: 0.ts +export function foo(){} + +// @filename: 1.ts +import * as Zero from "./0" // Should preserve ES2015 module syntax +import("./0"); +var p1 = import("./0"); +export default p1; From 20293b0ece3cc5e6b845d7f2530c5a5ad29362b4 Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 14 Mar 2017 09:57:05 -0700 Subject: [PATCH 11/67] Fix up error when we can't find promise type in import call expression --- src/compiler/checker.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 14b4506baa8..94b35a36b4c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -15084,14 +15084,14 @@ namespace ts { const promiseType = createPromiseType(promisedType); if (promiseType === emptyObjectType) { error(func, isImportCallExpression(func) ? - Diagnostics.An_async_function_or_method_must_return_a_Promise_Make_sure_you_have_a_declaration_for_Promise_or_include_ES2015_in_your_lib_option : - Diagnostics.A_dynamic_import_call_must_return_a_Promise_Make_sure_you_have_a_declaration_for_Promise_or_include_ES2015_in_your_lib_option); + Diagnostics.A_dynamic_import_call_must_return_a_Promise_Make_sure_you_have_a_declaration_for_Promise_or_include_ES2015_in_your_lib_option : + Diagnostics.An_async_function_or_method_must_return_a_Promise_Make_sure_you_have_a_declaration_for_Promise_or_include_ES2015_in_your_lib_option); return unknownType; } else if (!getGlobalPromiseConstructorSymbol(/*reportErrors*/ true)) { error(func, isImportCallExpression(func) ? - Diagnostics.An_async_function_or_method_in_ES5_SlashES3_requires_the_Promise_constructor_Make_sure_you_have_a_declaration_for_the_Promise_constructor_or_include_ES2015_in_your_lib_option : - Diagnostics.A_dynamic_import_call_in_ES5_SlashES3_requires_the_Promise_constructor_Make_sure_you_have_a_declaration_for_the_Promise_constructor_or_include_ES2015_in_your_lib_option); + Diagnostics.A_dynamic_import_call_in_ES5_SlashES3_requires_the_Promise_constructor_Make_sure_you_have_a_declaration_for_the_Promise_constructor_or_include_ES2015_in_your_lib_option : + Diagnostics.An_async_function_or_method_in_ES5_SlashES3_requires_the_Promise_constructor_Make_sure_you_have_a_declaration_for_the_Promise_constructor_or_include_ES2015_in_your_lib_option); } return promiseType; From 369af08e27d7b1d2e7ec6d9a3e7073cbf54fb520 Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 14 Mar 2017 10:29:55 -0700 Subject: [PATCH 12/67] Change filename to indicate it uses module kind of es2018 --- src/harness/harness.ts | 1 + .../{importCallExpression1.ts => importCallExpression1ES2018.ts} | 0 .../{importCallExpression2.ts => importCallExpression2ES2018.ts} | 0 3 files changed, 1 insertion(+) rename tests/cases/conformance/es2018/dynamicImport/{importCallExpression1.ts => importCallExpression1ES2018.ts} (100%) rename tests/cases/conformance/es2018/dynamicImport/{importCallExpression2.ts => importCallExpression2ES2018.ts} (100%) diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 23e8106864a..b31a9f8b88a 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -945,6 +945,7 @@ namespace Harness { export function getDefaultLibFileName(options: ts.CompilerOptions): string { switch (options.target) { + case ts.ScriptTarget.ESNext: case ts.ScriptTarget.ES2017: return "lib.es2017.d.ts"; case ts.ScriptTarget.ES2016: diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpression1.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpression1ES2018.ts similarity index 100% rename from tests/cases/conformance/es2018/dynamicImport/importCallExpression1.ts rename to tests/cases/conformance/es2018/dynamicImport/importCallExpression1ES2018.ts diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpression2.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpression2ES2018.ts similarity index 100% rename from tests/cases/conformance/es2018/dynamicImport/importCallExpression2.ts rename to tests/cases/conformance/es2018/dynamicImport/importCallExpression2ES2018.ts From ffbb445148caafbeb9fdfaee7c6a6bce96067c67 Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 14 Mar 2017 10:31:30 -0700 Subject: [PATCH 13/67] wip-Emit import call expression for commonjs --- src/compiler/factory.ts | 1 + src/compiler/parser.ts | 4 +- src/compiler/transformers/module/module.ts | 39 +++++++++++++++---- src/compiler/types.ts | 1 + .../importCallExpressionInCJS1.ts | 11 ++++++ .../importCallExpressionInCJS2.ts | 19 +++++++++ 6 files changed, 66 insertions(+), 9 deletions(-) create mode 100644 tests/cases/conformance/es2018/dynamicImport/importCallExpressionInCJS1.ts create mode 100644 tests/cases/conformance/es2018/dynamicImport/importCallExpressionInCJS2.ts diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index 0bf545f4fe1..0bd7989327b 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -1644,6 +1644,7 @@ namespace ts { if (node.resolvedTypeReferenceDirectiveNames !== undefined) updated.resolvedTypeReferenceDirectiveNames = node.resolvedTypeReferenceDirectiveNames; if (node.imports !== undefined) updated.imports = node.imports; if (node.moduleAugmentations !== undefined) updated.moduleAugmentations = node.moduleAugmentations; + if (node.containsDynamicImport !== undefined) updated.containsDynamicImport = node.containsDynamicImport; return updateNode(updated, node); } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index fbcbfae0bdf..f9abe8be995 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -461,7 +461,7 @@ namespace ts { } export function isExternalModule(file: SourceFile): boolean { - return file.externalModuleIndicator !== undefined; + return file.externalModuleIndicator !== undefined || file.containsDynamicImport; } // Produces a new SourceFile for the 'newText' provided. The 'textChangeRange' parameter @@ -2778,6 +2778,7 @@ namespace ts { case SyntaxKind.SlashToken: case SyntaxKind.SlashEqualsToken: case SyntaxKind.Identifier: + case SyntaxKind.ImportKeyword: return true; default: return isIdentifier(); @@ -3698,6 +3699,7 @@ namespace ts { if (importCall.specifier.kind === SyntaxKind.StringLiteral) { (sourceFile.imports || (sourceFile.imports = [])).push(importCall.specifier as StringLiteral); } + sourceFile.containsDynamicImport = true; return importCall; } const expression = token() === SyntaxKind.SuperKeyword ? parseSuperExpression() : parseMemberExpressionOrHigher(); diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index 80a8c985c56..2aad24af76e 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -482,12 +482,35 @@ namespace ts { return visitEndOfDeclarationMarker(node); default: - // This visitor does not descend into the tree, as export/import statements - // are only transformed at the top level of a file. - return node; + return visitEachChild(node, visitor, context); } } + function visitor(node: Node): VisitResult { + // This visitor does not need to descend into the tree if there is no dynamic import, + // as export/import statements are only transformed at the top level of a file. + if (!currentSourceFile.containsDynamicImport) { + return node; + } + + switch (node.kind) { + case SyntaxKind.ImportCallExpression: + return visitImportCallExpression(node); + default: + return visitEachChild(node, visitor, context); + } + } + + function visitImportCallExpression(node: ImportCallExpression): Expression{ + return createCall( + createPropertyAccess( + createCall(/*expression*/ createPropertyAccess(createIdentifier("Promise"), "resolve"), /*typeArguments*/ undefined, /*argumentsArray*/ []), + "then"), + /*typeArguments*/ undefined, + [ createArrowFunction(/*modifiers*/ undefined, /*typeParameters*/ undefined, /*parameters*/ undefined, /*type*/ undefined, createToken(SyntaxKind.EqualsGreaterThanToken), createCall(createIdentifier("require"), /*typeArguments*/ undefined, [node.specifier]))] + ); + } + /** * Visits an ImportDeclaration node. * @@ -780,7 +803,7 @@ namespace ts { node.asteriskToken, getDeclarationName(node, /*allowComments*/ true, /*allowSourceMaps*/ true), /*typeParameters*/ undefined, - node.parameters, + visitNodes(node.parameters, visitor), /*type*/ undefined, node.body ), @@ -822,7 +845,7 @@ namespace ts { visitNodes(node.modifiers, modifierVisitor, isModifier), getDeclarationName(node, /*allowComments*/ true, /*allowSourceMaps*/ true), /*typeParameters*/ undefined, - node.heritageClauses, + visitNodes(node.heritageClauses, visitor), node.members ), node @@ -884,7 +907,7 @@ namespace ts { } } else { - statements = append(statements, node); + statements = append(statements, visitEachChild(node, visitor, context)); } if (hasAssociatedEndOfDeclarationMarker(node)) { @@ -907,7 +930,7 @@ namespace ts { function transformInitializedVariable(node: VariableDeclaration): Expression { if (isBindingPattern(node.name)) { return flattenDestructuringAssignment( - node, + visitNode(node, visitor), /*visitor*/ undefined, context, FlattenLevel.All, @@ -924,7 +947,7 @@ namespace ts { ), /*location*/ node.name ), - node.initializer + visitNode(node.initializer, visitor) ); } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index c8b16130f29..07a6610f8fd 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2282,6 +2282,7 @@ namespace ts { /* @internal */ moduleAugmentations: LiteralExpression[]; /* @internal */ patternAmbientModules?: PatternAmbientModule[]; /* @internal */ ambientModuleNames: string[]; + /* @internal */ containsDynamicImport?: boolean; } export interface Bundle extends Node { diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInCJS1.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInCJS1.ts new file mode 100644 index 00000000000..9287e8462e9 --- /dev/null +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInCJS1.ts @@ -0,0 +1,11 @@ +// @module: commonjs +// @target: esnext +// @filename: 0.ts +export function foo() { return "foo"; } + +// @filename: 1.ts +import("./0"); +var p1 = import("./0"); +p1.then(zero => { + return zero.foo(); +}); \ No newline at end of file diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInCJS2.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInCJS2.ts new file mode 100644 index 00000000000..e42a58a290c --- /dev/null +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInCJS2.ts @@ -0,0 +1,19 @@ +// @module: commonjs +// @target: esnext +// @filename: 0.ts +export function foo() { return "foo"; } + +// @filename: 1.ts +export function backup() { return "backup"; } + +// @filename: 2.ts +async function compute(promise: Promise) { + let j = await promise; + if (!j) { + j = await import("./1"); + return j.backup(); + } + return j.foo(); +} + +compute(import("./0")); \ No newline at end of file From be375cb786c2f737b2f24872c9ee17e82f8d3121 Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Tue, 14 Mar 2017 12:26:20 -0700 Subject: [PATCH 14/67] Fix missing import call expression in function and class declaration --- src/compiler/transformers/module/module.ts | 22 ++++++++-------- .../importCallExpressionInCJS3.ts | 17 ++++++++++++ .../importCallExpressionInCJS4.ts | 14 ++++++++++ .../importCallExpressionInCJS5.ts | 26 +++++++++++++++++++ 4 files changed, 68 insertions(+), 11 deletions(-) create mode 100644 tests/cases/conformance/es2018/dynamicImport/importCallExpressionInCJS3.ts create mode 100644 tests/cases/conformance/es2018/dynamicImport/importCallExpressionInCJS4.ts create mode 100644 tests/cases/conformance/es2018/dynamicImport/importCallExpressionInCJS5.ts diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index 2aad24af76e..22afc900f49 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -482,11 +482,11 @@ namespace ts { return visitEndOfDeclarationMarker(node); default: - return visitEachChild(node, visitor, context); + return visitEachChild(node, importCallExpressionVisitor, context); } } - function visitor(node: Node): VisitResult { + function importCallExpressionVisitor(node: Node): VisitResult { // This visitor does not need to descend into the tree if there is no dynamic import, // as export/import statements are only transformed at the top level of a file. if (!currentSourceFile.containsDynamicImport) { @@ -497,7 +497,7 @@ namespace ts { case SyntaxKind.ImportCallExpression: return visitImportCallExpression(node); default: - return visitEachChild(node, visitor, context); + return visitEachChild(node, importCallExpressionVisitor, context); } } @@ -803,9 +803,9 @@ namespace ts { node.asteriskToken, getDeclarationName(node, /*allowComments*/ true, /*allowSourceMaps*/ true), /*typeParameters*/ undefined, - visitNodes(node.parameters, visitor), + visitNodes(node.parameters, importCallExpressionVisitor), /*type*/ undefined, - node.body + visitEachChild(node.body, importCallExpressionVisitor, context) ), /*location*/ node ), @@ -814,7 +814,7 @@ namespace ts { ); } else { - statements = append(statements, node); + statements = append(statements, visitEachChild(node, importCallExpressionVisitor, context)); } if (hasAssociatedEndOfDeclarationMarker(node)) { @@ -845,7 +845,7 @@ namespace ts { visitNodes(node.modifiers, modifierVisitor, isModifier), getDeclarationName(node, /*allowComments*/ true, /*allowSourceMaps*/ true), /*typeParameters*/ undefined, - visitNodes(node.heritageClauses, visitor), + visitNodes(node.heritageClauses, importCallExpressionVisitor), node.members ), node @@ -855,7 +855,7 @@ namespace ts { ); } else { - statements = append(statements, node); + statements = append(statements, visitEachChild(node, importCallExpressionVisitor, context)); } if (hasAssociatedEndOfDeclarationMarker(node)) { @@ -907,7 +907,7 @@ namespace ts { } } else { - statements = append(statements, visitEachChild(node, visitor, context)); + statements = append(statements, visitEachChild(node, importCallExpressionVisitor, context)); } if (hasAssociatedEndOfDeclarationMarker(node)) { @@ -930,7 +930,7 @@ namespace ts { function transformInitializedVariable(node: VariableDeclaration): Expression { if (isBindingPattern(node.name)) { return flattenDestructuringAssignment( - visitNode(node, visitor), + visitNode(node, importCallExpressionVisitor), /*visitor*/ undefined, context, FlattenLevel.All, @@ -947,7 +947,7 @@ namespace ts { ), /*location*/ node.name ), - visitNode(node.initializer, visitor) + visitNode(node.initializer, importCallExpressionVisitor) ); } } diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInCJS3.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInCJS3.ts new file mode 100644 index 00000000000..5990eb3a5a2 --- /dev/null +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInCJS3.ts @@ -0,0 +1,17 @@ +// @module: commonjs +// @target: esnext +// @filename: 0.ts +export class B { + print() { return "I am B"} +} + +// @filename: 2.ts +// We use Promise for now as there is no way to specify shape of module object +function foo(x: Promise) { + x.then(value => { + let b = new value.B(); + b.print(); + }) +} + +foo(import("./0")); \ No newline at end of file diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInCJS4.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInCJS4.ts new file mode 100644 index 00000000000..fba246c0b8b --- /dev/null +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInCJS4.ts @@ -0,0 +1,14 @@ +// @module: commonjs +// @target: esnext +// @filename: 0.ts +export class B { + print() { return "I am B"} +} + +// @filename: 2.ts +async function foo() { + class C extends (await import("./0")).B {} + var c = new C(); + c.print(); +} +foo(); \ No newline at end of file diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInCJS5.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInCJS5.ts new file mode 100644 index 00000000000..db86764802b --- /dev/null +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInCJS5.ts @@ -0,0 +1,26 @@ +// @module: commonjs +// @target: esnext +// @filename: 0.ts +export class B { + print() { return "I am B"} +} + +export function foo() { return "foo" } + +// @filename: 1.ts +export function backup() { return "backup"; } + +// @filename: 2.ts +declare var console: any; +class C { + private myModule = import("./0"); + method() { + this.myModule.then(Zero => { + console.log(Zero.foo()); + }, async err => { + console.log(err); + let one = await import("./1"); + console.log(one.backup()); + }); + } +} \ No newline at end of file From a84645c63e8cc19335eb5dd812b13faf4122e36f Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Tue, 14 Mar 2017 14:41:14 -0700 Subject: [PATCH 15/67] Add more tests for emitting of es2018 module-kind --- .../importCallExpression3ES2018.ts | 17 ++++++++++++ .../importCallExpression4ES2018.ts | 14 ++++++++++ .../importCallExpression5ES2018.ts | 26 +++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 tests/cases/conformance/es2018/dynamicImport/importCallExpression3ES2018.ts create mode 100644 tests/cases/conformance/es2018/dynamicImport/importCallExpression4ES2018.ts create mode 100644 tests/cases/conformance/es2018/dynamicImport/importCallExpression5ES2018.ts diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpression3ES2018.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpression3ES2018.ts new file mode 100644 index 00000000000..3cb6fd7bc92 --- /dev/null +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpression3ES2018.ts @@ -0,0 +1,17 @@ +// @module: es2018 +// @target: esnext +// @filename: 0.ts +export class B { + print() { return "I am B"} +} + +// @filename: 2.ts +// We use Promise for now as there is no way to specify shape of module object +function foo(x: Promise) { + x.then(value => { + let b = new value.B(); + b.print(); + }) +} + +foo(import("./0")); \ No newline at end of file diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpression4ES2018.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpression4ES2018.ts new file mode 100644 index 00000000000..6b2fc219d24 --- /dev/null +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpression4ES2018.ts @@ -0,0 +1,14 @@ +// @module: es2018 +// @target: esnext +// @filename: 0.ts +export class B { + print() { return "I am B"} +} + +// @filename: 2.ts +async function foo() { + class C extends (await import("./0")).B {} + var c = new C(); + c.print(); +} +foo(); \ No newline at end of file diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpression5ES2018.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpression5ES2018.ts new file mode 100644 index 00000000000..03e72bb6d4d --- /dev/null +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpression5ES2018.ts @@ -0,0 +1,26 @@ +// @module: es2018 +// @target: esnext +// @filename: 0.ts +export class B { + print() { return "I am B"} +} + +export function foo() { return "foo" } + +// @filename: 1.ts +export function backup() { return "backup"; } + +// @filename: 2.ts +declare var console: any; +class C { + private myModule = import("./0"); + method() { + this.myModule.then(Zero => { + console.log(Zero.foo()); + }, async err => { + console.log(err); + let one = await import("./1"); + console.log(one.backup()); + }); + } +} \ No newline at end of file From 9864b4e1ff6bb0a5b24e2bf631ab64a5acdd8d58 Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Tue, 14 Mar 2017 14:41:49 -0700 Subject: [PATCH 16/67] Emit import callExpression for UMD and AMD --- src/compiler/transformers/module/module.ts | 66 ++++++++++++++++++- .../importCallExpressionInAMD1.ts | 11 ++++ .../importCallExpressionInUMD1.ts | 11 ++++ 3 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 tests/cases/conformance/es2018/dynamicImport/importCallExpressionInAMD1.ts create mode 100644 tests/cases/conformance/es2018/dynamicImport/importCallExpressionInUMD1.ts diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index 22afc900f49..11fb94693cf 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -501,13 +501,73 @@ namespace ts { } } - function visitImportCallExpression(node: ImportCallExpression): Expression{ + function visitImportCallExpression(node: ImportCallExpression): Expression { + switch (compilerOptions.module) { + case ModuleKind.CommonJS: + return transformImportCallExpressionCommonJS(node); + case ModuleKind.AMD: + return transformImportCallExpressionAMD(node); + case ModuleKind.UMD: + return transformImportCallExpressionUMD(node); + } + Debug.assert(false, "All supported module kind in this transformation step should have been handled"); + } + + function transformImportCallExpressionUMD(node: ImportCallExpression): Expression { + // (function (factory) { + // ... (regular UMD) + // } + // })(function (require, exports, useSyncRequire) { + // "use strict"; + // Object.defineProperty(exports, "__esModule", { value: true }); + // require.length === 1 ? + // /*CommonJs Require*/ Promise.resolve().then(() => require('blah')); + // /*Amd Require*/ new Promise(resolve => require(['blah'], resolve)); + // }); + const require = createIdentifier("require"); + return createConditional( + /*condition*/ createBinary(createPropertyAccess(require, /*name*/ "length"), /*operator*/ createToken(SyntaxKind.EqualsEqualsEqualsToken), createNumericLiteral("1")), + /*whenTrue*/ transformImportCallExpressionCommonJS(node), + /*whenFalse*/ transformImportCallExpressionAMD(node) + ); + } + + function transformImportCallExpressionAMD(node: ImportCallExpression): Expression { + // improt("./blah") + // emit as + // define(["require", "exports", "blah"], function (require, exports) { + // ... + // new Promise(resolve => require(['blah'], resolve)); + // }); + const resolve = createIdentifier("resolve"); + return createNew( + createIdentifier("Promise"), + /*typeArguments*/ undefined, + [ + createArrowFunction( + /*modifiers*/undefined, + /*typeParameters*/ undefined, + [createParameter(/*decorator*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, /*name*/ resolve)], + /*type*/ undefined, + createToken(SyntaxKind.EqualsGreaterThanToken), + createCall(createIdentifier("require"), /*typeArguments*/ undefined, [createArrayLiteral([node.specifier]), resolve]) + ) + ] + ); + } + + function transformImportCallExpressionCommonJS(node: ImportCallExpression): Expression { + // import("./blah") + // emit as + // Promise.resolve().then(() => require("./blah")); + // We have to wrap require in then callback so that require is done in asynchronously + // if we simply do require in resolve callback in Promise constructor. We will execute the loading immediately return createCall( createPropertyAccess( - createCall(/*expression*/ createPropertyAccess(createIdentifier("Promise"), "resolve"), /*typeArguments*/ undefined, /*argumentsArray*/ []), + createCall(/*expression*/ createPropertyAccess(createIdentifier("Promise"), "resolve"), /*typeArguments*/ undefined, /*argumentsArray*/[]), "then"), /*typeArguments*/ undefined, - [ createArrowFunction(/*modifiers*/ undefined, /*typeParameters*/ undefined, /*parameters*/ undefined, /*type*/ undefined, createToken(SyntaxKind.EqualsGreaterThanToken), createCall(createIdentifier("require"), /*typeArguments*/ undefined, [node.specifier]))] + [createArrowFunction(/*modifiers*/ undefined, /*typeParameters*/ undefined, /*parameters*/ undefined, /*type*/ undefined, createToken(SyntaxKind.EqualsGreaterThanToken), createCall(createIdentifier("require"), /*typeArguments*/ undefined, [node.specifier]))] ); } diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInAMD1.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInAMD1.ts new file mode 100644 index 00000000000..28d3ca8a044 --- /dev/null +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInAMD1.ts @@ -0,0 +1,11 @@ +// @module: amd +// @target: esnext +// @filename: 0.ts +export function foo() { return "foo"; } + +// @filename: 1.ts +import("./0"); +var p1 = import("./0"); +p1.then(zero => { + return zero.foo(); +}); \ No newline at end of file diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInUMD1.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInUMD1.ts new file mode 100644 index 00000000000..73793673c22 --- /dev/null +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInUMD1.ts @@ -0,0 +1,11 @@ +// @module: umd +// @target: esnext +// @filename: 0.ts +export function foo() { return "foo"; } + +// @filename: 1.ts +import("./0"); +var p1 = import("./0"); +p1.then(zero => { + return zero.foo(); +}); \ No newline at end of file From 86c712902782e9e71460e3238be90368995dc9f0 Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 14 Mar 2017 20:13:32 -0700 Subject: [PATCH 17/67] wip-system emit --- src/compiler/transformers/module/system.ts | 73 ++++++++++++++-------- 1 file changed, 47 insertions(+), 26 deletions(-) diff --git a/src/compiler/transformers/module/system.ts b/src/compiler/transformers/module/system.ts index 1a362c47fd1..45f515cda9b 100644 --- a/src/compiler/transformers/module/system.ts +++ b/src/compiler/transformers/module/system.ts @@ -645,7 +645,7 @@ namespace ts { return undefined; } - const expression = visitNode(node.expression, destructuringVisitor, isExpression); + const expression = visitNode(node.expression, visitor, isExpression); const original = node.original; if (original && hasAssociatedEndOfDeclarationMarker(original)) { // Defer exports until we encounter an EndOfDeclarationMarker node @@ -672,9 +672,9 @@ namespace ts { node.asteriskToken, getDeclarationName(node, /*allowComments*/ true, /*allowSourceMaps*/ true), /*typeParameters*/ undefined, - visitNodes(node.parameters, destructuringVisitor, isParameterDeclaration), + visitNodes(node.parameters, visitor, isParameterDeclaration), /*type*/ undefined, - visitNode(node.body, destructuringVisitor, isBlock))); + visitNode(node.body, visitor, isBlock))); } else { hoistedStatements = append(hoistedStatements, node); @@ -715,8 +715,8 @@ namespace ts { /*modifiers*/ undefined, node.name, /*typeParameters*/ undefined, - visitNodes(node.heritageClauses, destructuringVisitor, isHeritageClause), - visitNodes(node.members, destructuringVisitor, isClassElement) + visitNodes(node.heritageClauses, visitor, isHeritageClause), + visitNodes(node.members, visitor, isClassElement) ), node ) @@ -746,7 +746,7 @@ namespace ts { */ function visitVariableStatement(node: VariableStatement): VisitResult { if (!shouldHoistVariableDeclarationList(node.declarationList)) { - return visitNode(node, destructuringVisitor, isStatement); + return visitNode(node, visitor, isStatement); } let expressions: Expression[]; @@ -819,13 +819,13 @@ namespace ts { return isBindingPattern(node.name) ? flattenDestructuringAssignment( node, - destructuringVisitor, + visitor, context, FlattenLevel.All, /*needsValue*/ false, createAssignment ) - : createAssignment(node.name, visitNode(node.initializer, destructuringVisitor, isExpression)); + : createAssignment(node.name, visitNode(node.initializer, visitor, isExpression)); } /** @@ -1203,7 +1203,7 @@ namespace ts { return visitEndOfDeclarationMarker(node); default: - return destructuringVisitor(node); + return visitor(node); } } @@ -1219,8 +1219,8 @@ namespace ts { node = updateFor( node, visitForInitializer(node.initializer), - visitNode(node.condition, destructuringVisitor, isExpression), - visitNode(node.incrementor, destructuringVisitor, isExpression), + visitNode(node.condition, visitor, isExpression), + visitNode(node.incrementor, visitor, isExpression), visitNode(node.statement, nestedElementVisitor, isStatement) ); @@ -1240,7 +1240,7 @@ namespace ts { node = updateForIn( node, visitForInitializer(node.initializer), - visitNode(node.expression, destructuringVisitor, isExpression), + visitNode(node.expression, visitor, isExpression), visitNode(node.statement, nestedElementVisitor, isStatement, liftToBlock) ); @@ -1261,7 +1261,7 @@ namespace ts { node, node.awaitModifier, visitForInitializer(node.initializer), - visitNode(node.expression, destructuringVisitor, isExpression), + visitNode(node.expression, visitor, isExpression), visitNode(node.statement, nestedElementVisitor, isStatement, liftToBlock) ); @@ -1308,7 +1308,7 @@ namespace ts { return updateDo( node, visitNode(node.statement, nestedElementVisitor, isStatement, liftToBlock), - visitNode(node.expression, destructuringVisitor, isExpression) + visitNode(node.expression, visitor, isExpression) ); } @@ -1320,7 +1320,7 @@ namespace ts { function visitWhileStatement(node: WhileStatement): VisitResult { return updateWhile( node, - visitNode(node.expression, destructuringVisitor, isExpression), + visitNode(node.expression, visitor, isExpression), visitNode(node.statement, nestedElementVisitor, isStatement, liftToBlock) ); } @@ -1346,7 +1346,7 @@ namespace ts { function visitWithStatement(node: WithStatement): VisitResult { return updateWith( node, - visitNode(node.expression, destructuringVisitor, isExpression), + visitNode(node.expression, visitor, isExpression), visitNode(node.statement, nestedElementVisitor, isStatement, liftToBlock) ); } @@ -1359,7 +1359,7 @@ namespace ts { function visitSwitchStatement(node: SwitchStatement): VisitResult { return updateSwitch( node, - visitNode(node.expression, destructuringVisitor, isExpression), + visitNode(node.expression, visitor, isExpression), visitNode(node.caseBlock, nestedElementVisitor, isCaseBlock) ); } @@ -1390,7 +1390,7 @@ namespace ts { function visitCaseClause(node: CaseClause): VisitResult { return updateCaseClause( node, - visitNode(node.expression, destructuringVisitor, isExpression), + visitNode(node.expression, visitor, isExpression), visitNodes(node.statements, nestedElementVisitor, isStatement) ); } @@ -1456,17 +1456,38 @@ namespace ts { * * @param node The node to visit. */ - function destructuringVisitor(node: Node): VisitResult { + function visitor(node: Node): VisitResult { if (node.transformFlags & TransformFlags.DestructuringAssignment && node.kind === SyntaxKind.BinaryExpression) { return visitDestructuringAssignment(node); } - else if (node.transformFlags & TransformFlags.ContainsDestructuringAssignment) { - return visitEachChild(node, destructuringVisitor, context); - } - else { - return node; + + if (isImportCallExpression(node)) { + return visitImportCallExpression(node); } + + return visitEachChild(node, visitor, context); + } + + function visitImportCallExpression(node: ImportCallExpression): Expression { + // import("./blah") + // emit as + // System.register([], function (_export, _context) { + // return { + // setters: [], + // execute: () => { + // _context.import('./blah'); + // } + // }; + // }); + return createCall( + createPropertyAccess( + contextObject, + createIdentifier("import") + ), + /*typeArguments*/ undefined, + [node.specifier] + ); } /** @@ -1478,14 +1499,14 @@ namespace ts { if (hasExportedReferenceInDestructuringTarget(node.left)) { return flattenDestructuringAssignment( node, - destructuringVisitor, + visitor, context, FlattenLevel.All, /*needsValue*/ true ); } - return visitEachChild(node, destructuringVisitor, context); + return visitEachChild(node, visitor, context); } /** From 6db02e74384656bb3bedec3d1c4797c411bac8a9 Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Thu, 16 Mar 2017 14:01:37 -0700 Subject: [PATCH 18/67] Fix up incorrect system emit --- src/compiler/transformers/module/module.ts | 2 +- src/compiler/transformers/module/system.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index 11fb94693cf..9d811243718 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -510,7 +510,7 @@ namespace ts { case ModuleKind.UMD: return transformImportCallExpressionUMD(node); } - Debug.assert(false, "All supported module kind in this transformation step should have been handled"); + Debug.fail("All supported module kind in this transformation step should have been handled"); } function transformImportCallExpressionUMD(node: ImportCallExpression): Expression { diff --git a/src/compiler/transformers/module/system.ts b/src/compiler/transformers/module/system.ts index 45f515cda9b..2798c7ca2cc 100644 --- a/src/compiler/transformers/module/system.ts +++ b/src/compiler/transformers/module/system.ts @@ -677,7 +677,7 @@ namespace ts { visitNode(node.body, visitor, isBlock))); } else { - hoistedStatements = append(hoistedStatements, node); + hoistedStatements = append(hoistedStatements, visitEachChild(node, visitor, context)); } if (hasAssociatedEndOfDeclarationMarker(node)) { From a77f0d2b1a71998f296f69add48f057aaf7911ea Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Thu, 16 Mar 2017 17:47:10 -0700 Subject: [PATCH 19/67] Do not collect imports in parser as it makes it very hard for incremental parsing --- src/compiler/parser.ts | 4 ---- src/compiler/program.ts | 15 ++++++++------- src/harness/unittests/commandLineParsing.ts | 2 +- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index f9abe8be995..a7427e58134 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3696,10 +3696,6 @@ namespace ts { // var foo3 = require("subfolder // import * as foo1 from "module-from-node -> we want this import to be a statement rather than import call expression const importCall = parseImportCallExpression(); - if (importCall.specifier.kind === SyntaxKind.StringLiteral) { - (sourceFile.imports || (sourceFile.imports = [])).push(importCall.specifier as StringLiteral); - } - sourceFile.containsDynamicImport = true; return importCall; } const expression = token() === SyntaxKind.SuperKeyword ? parseSuperExpression() : parseMemberExpressionOrHigher(); diff --git a/src/compiler/program.ts b/src/compiler/program.ts index ec263831cd4..2057bf017dd 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1183,7 +1183,7 @@ namespace ts { const isDtsFile = isDeclarationFile(file); // file.imports may not be undefined if there exists dynamic import - let imports = file.imports; + let imports: LiteralExpression[]; let moduleAugmentations: LiteralExpression[]; let ambientModules: string[]; @@ -1202,9 +1202,7 @@ namespace ts { for (const node of file.statements) { collectModuleReferences(node, /*inAmbientModule*/ false); - if (isJavaScriptFile) { - collectRequireCalls(node); - } + collectImportOrRequireCalls(node); } file.imports = imports || emptyArray; @@ -1266,12 +1264,15 @@ namespace ts { } } - function collectRequireCalls(node: Node): void { - if (isRequireCall(node, /*checkArgumentIsStringLiteral*/true)) { + function collectImportOrRequireCalls(node: Node): void { + if (isJavaScriptFile && isRequireCall(node, /*checkArgumentIsStringLiteral*/true)) { (imports || (imports = [])).push((node).arguments[0]); } + else if (node.kind === SyntaxKind.ImportCallExpression && (node).specifier.kind === SyntaxKind.StringLiteral) { + (imports || (imports = [])).push((node).specifier); + } else { - forEachChild(node, collectRequireCalls); + forEachChild(node, collectImportOrRequireCalls); } } } diff --git a/src/harness/unittests/commandLineParsing.ts b/src/harness/unittests/commandLineParsing.ts index 61b96d89553..6aa105e2c03 100644 --- a/src/harness/unittests/commandLineParsing.ts +++ b/src/harness/unittests/commandLineParsing.ts @@ -113,7 +113,7 @@ namespace ts { start: undefined, length: undefined, }, { - messageText: "Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015'.", + messageText: "Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'es2018'.", category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category, code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code, From dbac66c75686904d4007dfc89abeb22510f7b8a6 Mon Sep 17 00:00:00 2001 From: Yui T Date: Fri, 17 Mar 2017 10:50:32 -0700 Subject: [PATCH 20/67] Update baselines from adding es2018 value into moduleKind --- src/harness/unittests/convertCompilerOptionsFromJson.ts | 2 +- ...en compiler-options module-kind is out-of-range.errors.txt | 4 ++-- ... compiler-options target-script is out-of-range.errors.txt | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/harness/unittests/convertCompilerOptionsFromJson.ts b/src/harness/unittests/convertCompilerOptionsFromJson.ts index 0409ee19e66..cc0077aaa4e 100644 --- a/src/harness/unittests/convertCompilerOptionsFromJson.ts +++ b/src/harness/unittests/convertCompilerOptionsFromJson.ts @@ -122,7 +122,7 @@ namespace ts { file: undefined, start: 0, length: 0, - messageText: "Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015'.", + messageText: "Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'es2018'.", code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code, category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category }] diff --git a/tests/baselines/reference/transpile/Report an error when compiler-options module-kind is out-of-range.errors.txt b/tests/baselines/reference/transpile/Report an error when compiler-options module-kind is out-of-range.errors.txt index d746f35cbe7..16fb5e7b205 100644 --- a/tests/baselines/reference/transpile/Report an error when compiler-options module-kind is out-of-range.errors.txt +++ b/tests/baselines/reference/transpile/Report an error when compiler-options module-kind is out-of-range.errors.txt @@ -1,6 +1,6 @@ -error TS6046: Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015'. +error TS6046: Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'es2018'. -!!! error TS6046: Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015'. +!!! error TS6046: Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'es2018'. ==== file.ts (0 errors) ==== \ No newline at end of file diff --git a/tests/baselines/reference/transpile/Report an error when compiler-options target-script is out-of-range.errors.txt b/tests/baselines/reference/transpile/Report an error when compiler-options target-script is out-of-range.errors.txt index d746f35cbe7..16fb5e7b205 100644 --- a/tests/baselines/reference/transpile/Report an error when compiler-options target-script is out-of-range.errors.txt +++ b/tests/baselines/reference/transpile/Report an error when compiler-options target-script is out-of-range.errors.txt @@ -1,6 +1,6 @@ -error TS6046: Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015'. +error TS6046: Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'es2018'. -!!! error TS6046: Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015'. +!!! error TS6046: Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'es2018'. ==== file.ts (0 errors) ==== \ No newline at end of file From 804ab2c0dfd08dd0734f55c54d30cfe1848dd384 Mon Sep 17 00:00:00 2001 From: Yui T Date: Fri, 17 Mar 2017 10:54:06 -0700 Subject: [PATCH 21/67] Remove duplicat es2018 tests --- .../importCallExpression2ES2018.ts | 21 ++++++++++----- .../importCallExpression3ES2018.ts | 13 ++++------ .../importCallExpression4ES2018.ts | 24 ++++++++++++----- .../importCallExpression5ES2018.ts | 26 ------------------- 4 files changed, 37 insertions(+), 47 deletions(-) delete mode 100644 tests/cases/conformance/es2018/dynamicImport/importCallExpression5ES2018.ts diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpression2ES2018.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpression2ES2018.ts index 57ea587ce73..3cb6fd7bc92 100644 --- a/tests/cases/conformance/es2018/dynamicImport/importCallExpression2ES2018.ts +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpression2ES2018.ts @@ -1,10 +1,17 @@ // @module: es2018 -// @lib: es2015 +// @target: esnext // @filename: 0.ts -export function foo(){} +export class B { + print() { return "I am B"} +} -// @filename: 1.ts -import * as Zero from "./0" // Should preserve ES2015 module syntax -import("./0"); -var p1 = import("./0"); -export default p1; +// @filename: 2.ts +// We use Promise for now as there is no way to specify shape of module object +function foo(x: Promise) { + x.then(value => { + let b = new value.B(); + b.print(); + }) +} + +foo(import("./0")); \ No newline at end of file diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpression3ES2018.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpression3ES2018.ts index 3cb6fd7bc92..6b2fc219d24 100644 --- a/tests/cases/conformance/es2018/dynamicImport/importCallExpression3ES2018.ts +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpression3ES2018.ts @@ -6,12 +6,9 @@ export class B { } // @filename: 2.ts -// We use Promise for now as there is no way to specify shape of module object -function foo(x: Promise) { - x.then(value => { - let b = new value.B(); - b.print(); - }) +async function foo() { + class C extends (await import("./0")).B {} + var c = new C(); + c.print(); } - -foo(import("./0")); \ No newline at end of file +foo(); \ No newline at end of file diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpression4ES2018.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpression4ES2018.ts index 6b2fc219d24..03e72bb6d4d 100644 --- a/tests/cases/conformance/es2018/dynamicImport/importCallExpression4ES2018.ts +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpression4ES2018.ts @@ -5,10 +5,22 @@ export class B { print() { return "I am B"} } +export function foo() { return "foo" } + +// @filename: 1.ts +export function backup() { return "backup"; } + // @filename: 2.ts -async function foo() { - class C extends (await import("./0")).B {} - var c = new C(); - c.print(); -} -foo(); \ No newline at end of file +declare var console: any; +class C { + private myModule = import("./0"); + method() { + this.myModule.then(Zero => { + console.log(Zero.foo()); + }, async err => { + console.log(err); + let one = await import("./1"); + console.log(one.backup()); + }); + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpression5ES2018.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpression5ES2018.ts deleted file mode 100644 index 03e72bb6d4d..00000000000 --- a/tests/cases/conformance/es2018/dynamicImport/importCallExpression5ES2018.ts +++ /dev/null @@ -1,26 +0,0 @@ -// @module: es2018 -// @target: esnext -// @filename: 0.ts -export class B { - print() { return "I am B"} -} - -export function foo() { return "foo" } - -// @filename: 1.ts -export function backup() { return "backup"; } - -// @filename: 2.ts -declare var console: any; -class C { - private myModule = import("./0"); - method() { - this.myModule.then(Zero => { - console.log(Zero.foo()); - }, async err => { - console.log(err); - let one = await import("./1"); - console.log(one.backup()); - }); - } -} \ No newline at end of file From 1af1005636b624c353bf79a542094dcd8b4beea9 Mon Sep 17 00:00:00 2001 From: Yui T Date: Fri, 17 Mar 2017 16:58:51 -0700 Subject: [PATCH 22/67] Correctly bind import call expression --- src/compiler/binder.ts | 11 +++++++++++ src/compiler/factory.ts | 2 +- src/compiler/parser.ts | 6 +++++- src/compiler/transformers/module/module.ts | 2 +- src/compiler/transformers/module/system.ts | 4 +--- src/compiler/types.ts | 2 +- src/services/services.ts | 1 + 7 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index b3554876c14..5f7771d02ea 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -2163,6 +2163,8 @@ namespace ts { return bindJsxAttribute(node, SymbolFlags.Property, SymbolFlags.PropertyExcludes); // Imports and exports + case SyntaxKind.ImportCallExpression: + return bindImportCallExpression(node); case SyntaxKind.ImportEqualsDeclaration: case SyntaxKind.NamespaceImport: case SyntaxKind.ImportSpecifier: @@ -2267,6 +2269,15 @@ namespace ts { } } + function bindImportCallExpression(node: ImportCallExpression) { + if (!file.dynamicImportIndicator) { + file.dynamicImportIndicator = node; + if (!file.externalModuleIndicator) { + bindSourceFileAsExternalModule(); + } + } + } + function bindImportClause(node: ImportClause) { if (node.name) { declareSymbolAndAddToSymbolTable(node, SymbolFlags.Alias, SymbolFlags.AliasExcludes); diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index 0bd7989327b..962bbc7e234 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -1644,7 +1644,7 @@ namespace ts { if (node.resolvedTypeReferenceDirectiveNames !== undefined) updated.resolvedTypeReferenceDirectiveNames = node.resolvedTypeReferenceDirectiveNames; if (node.imports !== undefined) updated.imports = node.imports; if (node.moduleAugmentations !== undefined) updated.moduleAugmentations = node.moduleAugmentations; - if (node.containsDynamicImport !== undefined) updated.containsDynamicImport = node.containsDynamicImport; + if (node.dynamicImportIndicator !== undefined) updated.dynamicImportIndicator = node.dynamicImportIndicator; return updateNode(updated, node); } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index a7427e58134..e4931b09e3c 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -461,7 +461,11 @@ namespace ts { } export function isExternalModule(file: SourceFile): boolean { - return file.externalModuleIndicator !== undefined || file.containsDynamicImport; + return file.externalModuleIndicator !== undefined; + } + + export function containedDynamicImport(file: SourceFile): boolean { + return file.dynamicImportIndicator !== undefined; } // Produces a new SourceFile for the 'newText' provided. The 'textChangeRange' parameter diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index 9d811243718..6614f1a063e 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -55,7 +55,7 @@ namespace ts { * @param node The SourceFile node. */ function transformSourceFile(node: SourceFile) { - if (isDeclarationFile(node) || !(isExternalModule(node) || compilerOptions.isolatedModules)) { + if (isDeclarationFile(node) || !(isExternalModule(node) || compilerOptions.isolatedModules || containedDynamicImport(node))) { return node; } diff --git a/src/compiler/transformers/module/system.ts b/src/compiler/transformers/module/system.ts index 2798c7ca2cc..32005722e63 100644 --- a/src/compiler/transformers/module/system.ts +++ b/src/compiler/transformers/module/system.ts @@ -50,9 +50,7 @@ namespace ts { * @param node The SourceFile node. */ function transformSourceFile(node: SourceFile) { - if (isDeclarationFile(node) - || !(isExternalModule(node) - || compilerOptions.isolatedModules)) { + if (isDeclarationFile(node) || !(isExternalModule(node) || compilerOptions.isolatedModules || containedDynamicImport(node))) { return node; } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 07a6610f8fd..21da99c62ef 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2253,6 +2253,7 @@ namespace ts { /* @internal */ externalModuleIndicator: Node; // The first node that causes this file to be a CommonJS module /* @internal */ commonJsModuleIndicator: Node; + /* @internal */ dynamicImportIndicator: Node; /* @internal */ identifiers: Map; /* @internal */ nodeCount: number; @@ -2282,7 +2283,6 @@ namespace ts { /* @internal */ moduleAugmentations: LiteralExpression[]; /* @internal */ patternAmbientModules?: PatternAmbientModule[]; /* @internal */ ambientModuleNames: string[]; - /* @internal */ containsDynamicImport?: boolean; } export interface Bundle extends Node { diff --git a/src/services/services.ts b/src/services/services.ts index df5330ebaed..b0dd1f2eb1e 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -458,6 +458,7 @@ namespace ts { public hasNoDefaultLib: boolean; public externalModuleIndicator: Node; // The first node that causes this file to be an external module public commonJsModuleIndicator: Node; // The first node that causes this file to be a CommonJS module + public dynamicImportIndicator: Node; // The first dynamic import in this file public nodeCount: number; public identifierCount: number; public symbolCount: number; From e0192168f72266ac97badd40c1adae42ab2771e0 Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Mon, 20 Mar 2017 14:01:50 -0700 Subject: [PATCH 23/67] Use emitFlags to indicate that the subtree contains dynamic import --- src/compiler/binder.ts | 14 ++---- src/compiler/factory.ts | 1 - src/compiler/parser.ts | 4 -- src/compiler/program.ts | 2 +- src/compiler/transformers/module/module.ts | 4 +- src/compiler/transformers/module/system.ts | 57 ++++++++++++---------- src/compiler/types.ts | 5 +- src/services/services.ts | 1 - 8 files changed, 39 insertions(+), 49 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 5f7771d02ea..10bef2c444f 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -2163,8 +2163,6 @@ namespace ts { return bindJsxAttribute(node, SymbolFlags.Property, SymbolFlags.PropertyExcludes); // Imports and exports - case SyntaxKind.ImportCallExpression: - return bindImportCallExpression(node); case SyntaxKind.ImportEqualsDeclaration: case SyntaxKind.NamespaceImport: case SyntaxKind.ImportSpecifier: @@ -2269,15 +2267,6 @@ namespace ts { } } - function bindImportCallExpression(node: ImportCallExpression) { - if (!file.dynamicImportIndicator) { - file.dynamicImportIndicator = node; - if (!file.externalModuleIndicator) { - bindSourceFileAsExternalModule(); - } - } - } - function bindImportClause(node: ImportClause) { if (node.name) { declareSymbolAndAddToSymbolTable(node, SymbolFlags.Alias, SymbolFlags.AliasExcludes); @@ -3506,6 +3495,9 @@ namespace ts { case SyntaxKind.BreakStatement: transformFlags |= TransformFlags.ContainsHoistedDeclarationOrCompletion; break; + + case SyntaxKind.ImportCallExpression: + transformFlags |= TransformFlags.ContainsDynamicImport; } node.transformFlags = transformFlags | TransformFlags.HasComputedFlags; diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index 962bbc7e234..0bf545f4fe1 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -1644,7 +1644,6 @@ namespace ts { if (node.resolvedTypeReferenceDirectiveNames !== undefined) updated.resolvedTypeReferenceDirectiveNames = node.resolvedTypeReferenceDirectiveNames; if (node.imports !== undefined) updated.imports = node.imports; if (node.moduleAugmentations !== undefined) updated.moduleAugmentations = node.moduleAugmentations; - if (node.dynamicImportIndicator !== undefined) updated.dynamicImportIndicator = node.dynamicImportIndicator; return updateNode(updated, node); } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index e4931b09e3c..8d924ff154c 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -464,10 +464,6 @@ namespace ts { return file.externalModuleIndicator !== undefined; } - export function containedDynamicImport(file: SourceFile): boolean { - return file.dynamicImportIndicator !== undefined; - } - // Produces a new SourceFile for the 'newText' provided. The 'textChangeRange' parameter // indicates what changed between the 'text' that this SourceFile has and the 'newText'. // The SourceFile will be created with the compiler attempting to reuse as many nodes from diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 2057bf017dd..39632061c7c 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1268,7 +1268,7 @@ namespace ts { if (isJavaScriptFile && isRequireCall(node, /*checkArgumentIsStringLiteral*/true)) { (imports || (imports = [])).push((node).arguments[0]); } - else if (node.kind === SyntaxKind.ImportCallExpression && (node).specifier.kind === SyntaxKind.StringLiteral) { + else if (isImportCallExpression(node) && node.specifier.kind === SyntaxKind.StringLiteral) { (imports || (imports = [])).push((node).specifier); } else { diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index 6614f1a063e..375c44a312d 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -55,7 +55,7 @@ namespace ts { * @param node The SourceFile node. */ function transformSourceFile(node: SourceFile) { - if (isDeclarationFile(node) || !(isExternalModule(node) || compilerOptions.isolatedModules || containedDynamicImport(node))) { + if (isDeclarationFile(node) || !(isExternalModule(node) || compilerOptions.isolatedModules || node.transformFlags & TransformFlags.ContainsDynamicImport)) { return node; } @@ -489,7 +489,7 @@ namespace ts { function importCallExpressionVisitor(node: Node): VisitResult { // This visitor does not need to descend into the tree if there is no dynamic import, // as export/import statements are only transformed at the top level of a file. - if (!currentSourceFile.containsDynamicImport) { + if (!(node.transformFlags & TransformFlags.ContainsDynamicImport)) { return node; } diff --git a/src/compiler/transformers/module/system.ts b/src/compiler/transformers/module/system.ts index 32005722e63..2c2466f8c82 100644 --- a/src/compiler/transformers/module/system.ts +++ b/src/compiler/transformers/module/system.ts @@ -50,7 +50,7 @@ namespace ts { * @param node The SourceFile node. */ function transformSourceFile(node: SourceFile) { - if (isDeclarationFile(node) || !(isExternalModule(node) || compilerOptions.isolatedModules || containedDynamicImport(node))) { + if (isDeclarationFile(node) || !(isExternalModule(node) || compilerOptions.isolatedModules || node.transformFlags & TransformFlags.ContainsDynamicImport)) { return node; } @@ -643,7 +643,7 @@ namespace ts { return undefined; } - const expression = visitNode(node.expression, visitor, isExpression); + const expression = visitNode(node.expression, destructuringAndImportCallVisitor, isExpression); const original = node.original; if (original && hasAssociatedEndOfDeclarationMarker(original)) { // Defer exports until we encounter an EndOfDeclarationMarker node @@ -670,12 +670,12 @@ namespace ts { node.asteriskToken, getDeclarationName(node, /*allowComments*/ true, /*allowSourceMaps*/ true), /*typeParameters*/ undefined, - visitNodes(node.parameters, visitor, isParameterDeclaration), + visitNodes(node.parameters, destructuringAndImportCallVisitor, isParameterDeclaration), /*type*/ undefined, - visitNode(node.body, visitor, isBlock))); + visitNode(node.body, destructuringAndImportCallVisitor, isBlock))); } else { - hoistedStatements = append(hoistedStatements, visitEachChild(node, visitor, context)); + hoistedStatements = append(hoistedStatements, visitEachChild(node, destructuringAndImportCallVisitor, context)); } if (hasAssociatedEndOfDeclarationMarker(node)) { @@ -713,8 +713,8 @@ namespace ts { /*modifiers*/ undefined, node.name, /*typeParameters*/ undefined, - visitNodes(node.heritageClauses, visitor, isHeritageClause), - visitNodes(node.members, visitor, isClassElement) + visitNodes(node.heritageClauses, destructuringAndImportCallVisitor, isHeritageClause), + visitNodes(node.members, destructuringAndImportCallVisitor, isClassElement) ), node ) @@ -744,7 +744,7 @@ namespace ts { */ function visitVariableStatement(node: VariableStatement): VisitResult { if (!shouldHoistVariableDeclarationList(node.declarationList)) { - return visitNode(node, visitor, isStatement); + return visitNode(node, destructuringAndImportCallVisitor, isStatement); } let expressions: Expression[]; @@ -817,13 +817,13 @@ namespace ts { return isBindingPattern(node.name) ? flattenDestructuringAssignment( node, - visitor, + destructuringAndImportCallVisitor, context, FlattenLevel.All, /*needsValue*/ false, createAssignment ) - : createAssignment(node.name, visitNode(node.initializer, visitor, isExpression)); + : createAssignment(node.name, visitNode(node.initializer, destructuringAndImportCallVisitor, isExpression)); } /** @@ -1201,7 +1201,7 @@ namespace ts { return visitEndOfDeclarationMarker(node); default: - return visitor(node); + return destructuringAndImportCallVisitor(node); } } @@ -1217,8 +1217,8 @@ namespace ts { node = updateFor( node, visitForInitializer(node.initializer), - visitNode(node.condition, visitor, isExpression), - visitNode(node.incrementor, visitor, isExpression), + visitNode(node.condition, destructuringAndImportCallVisitor, isExpression), + visitNode(node.incrementor, destructuringAndImportCallVisitor, isExpression), visitNode(node.statement, nestedElementVisitor, isStatement) ); @@ -1238,7 +1238,7 @@ namespace ts { node = updateForIn( node, visitForInitializer(node.initializer), - visitNode(node.expression, visitor, isExpression), + visitNode(node.expression, destructuringAndImportCallVisitor, isExpression), visitNode(node.statement, nestedElementVisitor, isStatement, liftToBlock) ); @@ -1259,7 +1259,7 @@ namespace ts { node, node.awaitModifier, visitForInitializer(node.initializer), - visitNode(node.expression, visitor, isExpression), + visitNode(node.expression, destructuringAndImportCallVisitor, isExpression), visitNode(node.statement, nestedElementVisitor, isStatement, liftToBlock) ); @@ -1306,7 +1306,7 @@ namespace ts { return updateDo( node, visitNode(node.statement, nestedElementVisitor, isStatement, liftToBlock), - visitNode(node.expression, visitor, isExpression) + visitNode(node.expression, destructuringAndImportCallVisitor, isExpression) ); } @@ -1318,7 +1318,7 @@ namespace ts { function visitWhileStatement(node: WhileStatement): VisitResult { return updateWhile( node, - visitNode(node.expression, visitor, isExpression), + visitNode(node.expression, destructuringAndImportCallVisitor, isExpression), visitNode(node.statement, nestedElementVisitor, isStatement, liftToBlock) ); } @@ -1344,7 +1344,7 @@ namespace ts { function visitWithStatement(node: WithStatement): VisitResult { return updateWith( node, - visitNode(node.expression, visitor, isExpression), + visitNode(node.expression, destructuringAndImportCallVisitor, isExpression), visitNode(node.statement, nestedElementVisitor, isStatement, liftToBlock) ); } @@ -1357,7 +1357,7 @@ namespace ts { function visitSwitchStatement(node: SwitchStatement): VisitResult { return updateSwitch( node, - visitNode(node.expression, visitor, isExpression), + visitNode(node.expression, destructuringAndImportCallVisitor, isExpression), visitNode(node.caseBlock, nestedElementVisitor, isCaseBlock) ); } @@ -1388,7 +1388,7 @@ namespace ts { function visitCaseClause(node: CaseClause): VisitResult { return updateCaseClause( node, - visitNode(node.expression, visitor, isExpression), + visitNode(node.expression, destructuringAndImportCallVisitor, isExpression), visitNodes(node.statements, nestedElementVisitor, isStatement) ); } @@ -1454,17 +1454,20 @@ namespace ts { * * @param node The node to visit. */ - function visitor(node: Node): VisitResult { + function destructuringAndImportCallVisitor(node: Node): VisitResult { if (node.transformFlags & TransformFlags.DestructuringAssignment && node.kind === SyntaxKind.BinaryExpression) { return visitDestructuringAssignment(node); } - - if (isImportCallExpression(node)) { + else if (isImportCallExpression(node)) { return visitImportCallExpression(node); } - - return visitEachChild(node, visitor, context); + else if ((node.transformFlags & TransformFlags.ContainsDestructuringAssignment) || (node.transformFlags & TransformFlags.ContainsDynamicImport)) { + return visitEachChild(node, destructuringAndImportCallVisitor, context); + } + else { + return node; + } } function visitImportCallExpression(node: ImportCallExpression): Expression { @@ -1497,14 +1500,14 @@ namespace ts { if (hasExportedReferenceInDestructuringTarget(node.left)) { return flattenDestructuringAssignment( node, - visitor, + destructuringAndImportCallVisitor, context, FlattenLevel.All, /*needsValue*/ true ); } - return visitEachChild(node, visitor, context); + return visitEachChild(node, destructuringAndImportCallVisitor, context); } /** diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 21da99c62ef..3a08bd45084 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2253,7 +2253,6 @@ namespace ts { /* @internal */ externalModuleIndicator: Node; // The first node that causes this file to be a CommonJS module /* @internal */ commonJsModuleIndicator: Node; - /* @internal */ dynamicImportIndicator: Node; /* @internal */ identifiers: Map; /* @internal */ nodeCount: number; @@ -3810,7 +3809,9 @@ namespace ts { ContainsYield = 1 << 24, ContainsHoistedDeclarationOrCompletion = 1 << 25, - HasComputedFlags = 1 << 29, // Transform flags have been computed. + ContainsDynamicImport = 1 << 26, + + HasComputedFlags = 1 << 27, // Transform flags have been computed. // Assertions // - Bitmasks that are used to assert facts about the syntax of a node and its subtree. diff --git a/src/services/services.ts b/src/services/services.ts index b0dd1f2eb1e..df5330ebaed 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -458,7 +458,6 @@ namespace ts { public hasNoDefaultLib: boolean; public externalModuleIndicator: Node; // The first node that causes this file to be an external module public commonJsModuleIndicator: Node; // The first node that causes this file to be a CommonJS module - public dynamicImportIndicator: Node; // The first dynamic import in this file public nodeCount: number; public identifierCount: number; public symbolCount: number; From 015f71b5fd769c2e038a916fca89e490bdd68bad Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Mon, 20 Mar 2017 15:34:06 -0700 Subject: [PATCH 24/67] Issue error when use with ES2015 --- src/compiler/checker.ts | 4 ++++ src/compiler/diagnosticMessages.json | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 94b35a36b4c..db2452625c3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -14863,6 +14863,10 @@ namespace ts { } function checkImportCallExpression(node: ImportCallExpression): Type { + if (modulekind === ModuleKind.ES2015) { + grammarErrorOnNode(node, Diagnostics.Dynamic_import_cannot_be_used_when_targeting_ECMAScript_2015_modules); + } + // resolveExternalModuleName will return undefined if the moduleReferenceExpression is not a string literal const moduleSymbol = resolveExternalModuleName(node, node.specifier); if (moduleSymbol) { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 7397f278769..402b1c30920 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -867,6 +867,10 @@ "category": "Error", "code": 1319 }, + "Dynamic import cannot be used when targeting ECMAScript 2015 modules.": { + "category": "Error", + "code": 1320 + }, "Duplicate identifier '{0}'.": { "category": "Error", "code": 2300 @@ -1863,10 +1867,6 @@ "category": "Error", "code": 2649 }, - "Cannot emit namespaced JSX elements in React.": { - "category": "Error", - "code": 2650 - }, "A member initializer in a enum declaration cannot reference members declared after it, including members defined in other enums.": { "category": "Error", "code": 2651 From 8fd660bcba3f3ced8b707f67b5a6f88863b73055 Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Tue, 21 Mar 2017 13:11:29 -0700 Subject: [PATCH 25/67] Report no implicit error when we return Promise --- src/compiler/checker.ts | 3 +++ src/compiler/diagnosticMessages.json | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index db2452625c3..86099ae6d0c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -14875,6 +14875,9 @@ namespace ts { return createPromiseReturnType(node, getTypeOfSymbol(esModuleSymbol)); } } + if (noImplicitAny) { + error(node, Diagnostics.Cannot_resolve_dynamic_import_implicitly_has_a_Promise_any_type); + } return createPromiseReturnType(node, anyType); } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 402b1c30920..8e1ee767c55 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -3161,6 +3161,10 @@ "category": "Error", "code": 7034 }, + "Cannot resolve dynamic import, implicitly has a 'Promise' type.": { + "category": "Error", + "code": 7035 + }, "You cannot rename this element.": { "category": "Error", "code": 8000 From f04f7b5afd49ff865820c9f00d7717ee566c4de2 Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Tue, 21 Mar 2017 14:18:12 -0700 Subject: [PATCH 26/67] Add comment for comparable relationship --- src/compiler/checker.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 86099ae6d0c..51593839104 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7434,6 +7434,12 @@ namespace ts { /** * This is *not* a bi-directional relationship. * If one needs to check both directions for comparability, use a second call to this function or 'checkTypeComparableTo'. + * + * A type S is comparable to a type T if some (but not necessarily all) of the possible values of S are also possible values of T. + * It is used to check following cases: + * - the types of the left and right sides of equality/inequality operators (`===`, `!==`, `==`, `!=`). + * - the types of `case` clause expressions and their respective `switch` expressions. + * - the type of an expression in a type assertion with the type being asserted. */ function isTypeComparableTo(source: Type, target: Type): boolean { return isTypeRelatedTo(source, target, comparableRelation); From 871d6095efaf1d90e98a14f6cb1fc4223ad16911 Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Tue, 21 Mar 2017 15:08:00 -0700 Subject: [PATCH 27/67] Report an error if dynamic import specifier is not assigable to type string --- src/compiler/checker.ts | 4 ++++ src/compiler/diagnosticMessages.json | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 51593839104..3b9b9166589 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -14873,6 +14873,10 @@ namespace ts { grammarErrorOnNode(node, Diagnostics.Dynamic_import_cannot_be_used_when_targeting_ECMAScript_2015_modules); } + const specifierType = checkExpression(node.specifier); + if (!isTypeAssignableTo(specifierType, stringType)) { + error(node.specifier, Diagnostics.Dynamic_import_s_specifier_must_be_of_type_string_but_here_has_type_0, typeToString(specifierType)); + } // resolveExternalModuleName will return undefined if the moduleReferenceExpression is not a string literal const moduleSymbol = resolveExternalModuleName(node, node.specifier); if (moduleSymbol) { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 8e1ee767c55..5e200cf4a93 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -3165,6 +3165,10 @@ "category": "Error", "code": 7035 }, + "Dynamic import's specifier must be of type 'string', but here has type '{0}'.": { + "category": "Error", + "code": 7036 + }, "You cannot rename this element.": { "category": "Error", "code": 8000 From 15ca0af646e8273dfae4498f348b19457e37704a Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Tue, 21 Mar 2017 15:08:15 -0700 Subject: [PATCH 28/67] Add tests --- .../importCallExpression1ES2018.ts | 6 ++++- .../importCallExpressionCheckSpecifier1.ts | 12 +++++++++ .../importCallExpressionCheckSpecifier2.ts | 13 ++++++++++ .../importCallExpressionErrorInES2015.ts | 15 +++++++++++ .../importCallExpressionInAMD1.ts | 6 ++++- .../importCallExpressionInAMD2.ts | 17 ++++++++++++ .../importCallExpressionInAMD3.ts | 14 ++++++++++ .../importCallExpressionInAMD4.ts | 26 +++++++++++++++++++ .../importCallExpressionInCJS1.ts | 6 ++++- .../importCallExpressionInSystem1.ts | 15 +++++++++++ .../importCallExpressionInSystem2.ts | 17 ++++++++++++ .../importCallExpressionInSystem3.ts | 14 ++++++++++ .../importCallExpressionInSystem4.ts | 26 +++++++++++++++++++ .../importCallExpressionInUMD1.ts | 6 ++++- .../importCallExpressionReturnAny1.ts | 12 +++++++++ 15 files changed, 201 insertions(+), 4 deletions(-) create mode 100644 tests/cases/conformance/es2018/dynamicImport/importCallExpressionCheckSpecifier1.ts create mode 100644 tests/cases/conformance/es2018/dynamicImport/importCallExpressionCheckSpecifier2.ts create mode 100644 tests/cases/conformance/es2018/dynamicImport/importCallExpressionErrorInES2015.ts create mode 100644 tests/cases/conformance/es2018/dynamicImport/importCallExpressionInAMD2.ts create mode 100644 tests/cases/conformance/es2018/dynamicImport/importCallExpressionInAMD3.ts create mode 100644 tests/cases/conformance/es2018/dynamicImport/importCallExpressionInAMD4.ts create mode 100644 tests/cases/conformance/es2018/dynamicImport/importCallExpressionInSystem1.ts create mode 100644 tests/cases/conformance/es2018/dynamicImport/importCallExpressionInSystem2.ts create mode 100644 tests/cases/conformance/es2018/dynamicImport/importCallExpressionInSystem3.ts create mode 100644 tests/cases/conformance/es2018/dynamicImport/importCallExpressionInSystem4.ts create mode 100644 tests/cases/conformance/es2018/dynamicImport/importCallExpressionReturnAny1.ts diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpression1ES2018.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpression1ES2018.ts index f0fd00f9c79..f7abb325d99 100644 --- a/tests/cases/conformance/es2018/dynamicImport/importCallExpression1ES2018.ts +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpression1ES2018.ts @@ -8,4 +8,8 @@ import("./0"); var p1 = import("./0"); p1.then(zero => { return zero.foo(); -}) \ No newline at end of file +}) + +function foo() { + const p2 = import("./0"); +} \ No newline at end of file diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionCheckSpecifier1.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionCheckSpecifier1.ts new file mode 100644 index 00000000000..e4de1109b1a --- /dev/null +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionCheckSpecifier1.ts @@ -0,0 +1,12 @@ +// @module: commonjs +// @target: es6 +// @noImplicitAny: false + +declare function getSpecifier(): string; +declare var whatToLoad: boolean; +import(getSpecifier()); +var p1 = import(getSpecifier()); +const p2 = import(whatToLoad ? getSpecifier() : "defaulPath") +p1.then(zero => { + return zero.foo(); // ok, zero is any +}); \ No newline at end of file diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionCheckSpecifier2.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionCheckSpecifier2.ts new file mode 100644 index 00000000000..37e3c65be8d --- /dev/null +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionCheckSpecifier2.ts @@ -0,0 +1,13 @@ +// @module: commonjs +// @target: es6 +// @noImplicitAny: false + +declare function getSpecifier(): boolean; +declare var whatToLoad: boolean; +// Error specifier is not assignable to string +import(getSpecifier()); +var p1 = import(getSpecifier()); +const p2 = import(whatToLoad ? getSpecifier() : "defaulPath") +p1.then(zero => { + return zero.foo(); // ok, zero is any +}); \ No newline at end of file diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionErrorInES2015.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionErrorInES2015.ts new file mode 100644 index 00000000000..a7fcd8533a3 --- /dev/null +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionErrorInES2015.ts @@ -0,0 +1,15 @@ +// @module: es2015 +// @target: esnext +// @filename: 0.ts +export function foo() { return "foo"; } + +// @filename: 1.ts +import("./0"); +var p1 = import("./0"); +p1.then(zero => { + return zero.foo(); +}) + +function foo() { + const p2 = import("./0"); +} \ No newline at end of file diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInAMD1.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInAMD1.ts index 28d3ca8a044..63cfc54c732 100644 --- a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInAMD1.ts +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInAMD1.ts @@ -8,4 +8,8 @@ import("./0"); var p1 = import("./0"); p1.then(zero => { return zero.foo(); -}); \ No newline at end of file +}); + +function foo() { + const p2 = import("./0"); +} \ No newline at end of file diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInAMD2.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInAMD2.ts new file mode 100644 index 00000000000..96b2fd4ceff --- /dev/null +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInAMD2.ts @@ -0,0 +1,17 @@ +// @module: amd +// @target: esnext +// @filename: 0.ts +export class B { + print() { return "I am B"} +} + +// @filename: 2.ts +// We use Promise for now as there is no way to specify shape of module object +function foo(x: Promise) { + x.then(value => { + let b = new value.B(); + b.print(); + }) +} + +foo(import("./0")); \ No newline at end of file diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInAMD3.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInAMD3.ts new file mode 100644 index 00000000000..a2b287b4d95 --- /dev/null +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInAMD3.ts @@ -0,0 +1,14 @@ +// @module: amd +// @target: esnext +// @filename: 0.ts +export class B { + print() { return "I am B"} +} + +// @filename: 2.ts +async function foo() { + class C extends (await import("./0")).B {} + var c = new C(); + c.print(); +} +foo(); \ No newline at end of file diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInAMD4.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInAMD4.ts new file mode 100644 index 00000000000..10044ab674c --- /dev/null +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInAMD4.ts @@ -0,0 +1,26 @@ +// @module: amd +// @target: esnext +// @filename: 0.ts +export class B { + print() { return "I am B"} +} + +export function foo() { return "foo" } + +// @filename: 1.ts +export function backup() { return "backup"; } + +// @filename: 2.ts +declare var console: any; +class C { + private myModule = import("./0"); + method() { + this.myModule.then(Zero => { + console.log(Zero.foo()); + }, async err => { + console.log(err); + let one = await import("./1"); + console.log(one.backup()); + }); + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInCJS1.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInCJS1.ts index 9287e8462e9..e1457017552 100644 --- a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInCJS1.ts +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInCJS1.ts @@ -8,4 +8,8 @@ import("./0"); var p1 = import("./0"); p1.then(zero => { return zero.foo(); -}); \ No newline at end of file +}); + +function foo() { + const p2 = import("./0"); +} \ No newline at end of file diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInSystem1.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInSystem1.ts new file mode 100644 index 00000000000..a69e844c7a7 --- /dev/null +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInSystem1.ts @@ -0,0 +1,15 @@ +// @module: system +// @target: esnext +// @filename: 0.ts +export function foo() { return "foo"; } + +// @filename: 1.ts +import("./0"); +var p1 = import("./0"); +p1.then(zero => { + return zero.foo(); +}); + +function foo() { + const p2 = import("./0"); +} \ No newline at end of file diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInSystem2.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInSystem2.ts new file mode 100644 index 00000000000..c6fac3683ee --- /dev/null +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInSystem2.ts @@ -0,0 +1,17 @@ +// @module: system +// @target: esnext +// @filename: 0.ts +export class B { + print() { return "I am B"} +} + +// @filename: 2.ts +// We use Promise for now as there is no way to specify shape of module object +function foo(x: Promise) { + x.then(value => { + let b = new value.B(); + b.print(); + }) +} + +foo(import("./0")); \ No newline at end of file diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInSystem3.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInSystem3.ts new file mode 100644 index 00000000000..7f4485d8962 --- /dev/null +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInSystem3.ts @@ -0,0 +1,14 @@ +// @module: system +// @target: esnext +// @filename: 0.ts +export class B { + print() { return "I am B"} +} + +// @filename: 2.ts +async function foo() { + class C extends (await import("./0")).B {} + var c = new C(); + c.print(); +} +foo(); \ No newline at end of file diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInSystem4.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInSystem4.ts new file mode 100644 index 00000000000..1ab3040862c --- /dev/null +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInSystem4.ts @@ -0,0 +1,26 @@ +// @module: system +// @target: esnext +// @filename: 0.ts +export class B { + print() { return "I am B"} +} + +export function foo() { return "foo" } + +// @filename: 1.ts +export function backup() { return "backup"; } + +// @filename: 2.ts +declare var console: any; +class C { + private myModule = import("./0"); + method() { + this.myModule.then(Zero => { + console.log(Zero.foo()); + }, async err => { + console.log(err); + let one = await import("./1"); + console.log(one.backup()); + }); + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInUMD1.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInUMD1.ts index 73793673c22..05c4d699104 100644 --- a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInUMD1.ts +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInUMD1.ts @@ -8,4 +8,8 @@ import("./0"); var p1 = import("./0"); p1.then(zero => { return zero.foo(); -}); \ No newline at end of file +}); + +function foo() { + const p2 = import("./0"); +} \ No newline at end of file diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionReturnAny1.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionReturnAny1.ts new file mode 100644 index 00000000000..01f3b3c9281 --- /dev/null +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionReturnAny1.ts @@ -0,0 +1,12 @@ +// @module: es2018 +// @target: esnext +// @filename: 0.ts +// @noImplicitAny: true + +// @filename: 1.ts +declare function ValidSomeCondition(): boolean; +import(ValidSomeCondition() ? "./0" : "externalModule"); // implicit any error +var p1 = import(ValidSomeCondition() ? "./0" : "externalModule"); // implicit any error +p1.then(zero => { + return zero.foo(); // ok +}); \ No newline at end of file From 2332ea388e6335fe84eaf94ce37c0858f251f4df Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Tue, 21 Mar 2017 15:11:21 -0700 Subject: [PATCH 29/67] small fix on indentation --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3b9b9166589..d28d6bc48a1 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -14876,7 +14876,7 @@ namespace ts { const specifierType = checkExpression(node.specifier); if (!isTypeAssignableTo(specifierType, stringType)) { error(node.specifier, Diagnostics.Dynamic_import_s_specifier_must_be_of_type_string_but_here_has_type_0, typeToString(specifierType)); - } + } // resolveExternalModuleName will return undefined if the moduleReferenceExpression is not a string literal const moduleSymbol = resolveExternalModuleName(node, node.specifier); if (moduleSymbol) { From 91d9ecf3e21ea9287e6c13de4d95585c29cf8fc5 Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Wed, 22 Mar 2017 11:10:47 -0700 Subject: [PATCH 30/67] Simply parse dynamic import as call-expression.... --- src/compiler/binder.ts | 7 +++-- src/compiler/checker.ts | 24 ++++++++------- src/compiler/diagnosticMessages.json | 8 +++++ src/compiler/emitter.ts | 10 +------ src/compiler/factory.ts | 12 -------- src/compiler/parser.ts | 34 ++++++++++++---------- src/compiler/program.ts | 5 ++-- src/compiler/transformers/module/module.ts | 22 +++++++------- src/compiler/transformers/module/system.ts | 6 ++-- src/compiler/types.ts | 12 ++++---- src/compiler/utilities.ts | 5 ++-- src/compiler/visitor.ts | 4 --- 12 files changed, 71 insertions(+), 78 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 10bef2c444f..e7ba874d3d2 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -2725,6 +2725,10 @@ namespace ts { transformFlags |= TransformFlags.AssertES2015; } + if (expression.kind === SyntaxKind.ImportKeyword) { + transformFlags |= TransformFlags.ContainsDynamicImport; + } + node.transformFlags = transformFlags | TransformFlags.HasComputedFlags; return transformFlags & ~TransformFlags.ArrayLiteralOrCallOrNewExcludes; } @@ -3495,9 +3499,6 @@ namespace ts { case SyntaxKind.BreakStatement: transformFlags |= TransformFlags.ContainsHoistedDeclarationOrCompletion; break; - - case SyntaxKind.ImportCallExpression: - transformFlags |= TransformFlags.ContainsDynamicImport; } node.transformFlags = transformFlags | TransformFlags.HasComputedFlags; diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d28d6bc48a1..6df2efeea83 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -14830,6 +14830,10 @@ namespace ts { return voidType; } + if (node.expression.kind === SyntaxKind.ImportKeyword) { + return checkImportCallExpression(node); + } + if (node.kind === SyntaxKind.NewExpression) { const declaration = signature.declaration; @@ -14868,19 +14872,21 @@ namespace ts { return getReturnTypeOfSignature(signature); } - function checkImportCallExpression(node: ImportCallExpression): Type { + function checkImportCallExpression(node: CallExpression): Type { if (modulekind === ModuleKind.ES2015) { grammarErrorOnNode(node, Diagnostics.Dynamic_import_cannot_be_used_when_targeting_ECMAScript_2015_modules); } - const specifierType = checkExpression(node.specifier); + // We already error in parse if arguments list is not length of 1 + const specifier = node.arguments[0]; + const specifierType = checkExpression(specifier); if (!isTypeAssignableTo(specifierType, stringType)) { - error(node.specifier, Diagnostics.Dynamic_import_s_specifier_must_be_of_type_string_but_here_has_type_0, typeToString(specifierType)); + error(specifier, Diagnostics.Dynamic_import_s_specifier_must_be_of_type_string_but_here_has_type_0, typeToString(specifierType)); } // resolveExternalModuleName will return undefined if the moduleReferenceExpression is not a string literal - const moduleSymbol = resolveExternalModuleName(node, node.specifier); + const moduleSymbol = resolveExternalModuleName(node, specifier); if (moduleSymbol) { - const esModuleSymbol = resolveESModuleSymbol(moduleSymbol, node.specifier); + const esModuleSymbol = resolveESModuleSymbol(moduleSymbol, specifier); if (esModuleSymbol) { return createPromiseReturnType(node, getTypeOfSymbol(esModuleSymbol)); } @@ -15097,16 +15103,16 @@ namespace ts { return emptyObjectType; } - function createPromiseReturnType(func: FunctionLikeDeclaration | ImportCallExpression, promisedType: Type) { + function createPromiseReturnType(func: FunctionLikeDeclaration | CallExpression, promisedType: Type) { const promiseType = createPromiseType(promisedType); if (promiseType === emptyObjectType) { - error(func, isImportCallExpression(func) ? + error(func, isImportCall(func) ? Diagnostics.A_dynamic_import_call_must_return_a_Promise_Make_sure_you_have_a_declaration_for_Promise_or_include_ES2015_in_your_lib_option : Diagnostics.An_async_function_or_method_must_return_a_Promise_Make_sure_you_have_a_declaration_for_Promise_or_include_ES2015_in_your_lib_option); return unknownType; } else if (!getGlobalPromiseConstructorSymbol(/*reportErrors*/ true)) { - error(func, isImportCallExpression(func) ? + error(func, isImportCall(func) ? Diagnostics.A_dynamic_import_call_in_ES5_SlashES3_requires_the_Promise_constructor_Make_sure_you_have_a_declaration_for_the_Promise_constructor_or_include_ES2015_in_your_lib_option : Diagnostics.An_async_function_or_method_in_ES5_SlashES3_requires_the_Promise_constructor_Make_sure_you_have_a_declaration_for_the_Promise_constructor_or_include_ES2015_in_your_lib_option); } @@ -16431,8 +16437,6 @@ namespace ts { case SyntaxKind.CallExpression: case SyntaxKind.NewExpression: return checkCallExpression(node); - case SyntaxKind.ImportCallExpression: - return checkImportCallExpression(node); case SyntaxKind.TaggedTemplateExpression: return checkTaggedTemplateExpression(node); case SyntaxKind.ParenthesizedExpression: diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 5e200cf4a93..4618776af26 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -3297,6 +3297,14 @@ "category": "Error", "code": 17013 }, + "Dynamic import can only have one specifier as an argument.": { + "category": "Error", + "code": 17014 + }, + "Specifier of dynamic import cannot be spread element.": { + "category": "Error", + "code": 17015 + }, "Circularity detected while resolving configuration: {0}": { "category": "Error", diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 5f0e1bd5e92..c9cd941c7fc 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -655,6 +655,7 @@ namespace ts { case SyntaxKind.SuperKeyword: case SyntaxKind.TrueKeyword: case SyntaxKind.ThisKeyword: + case SyntaxKind.ImportKeyword: writeTokenText(kind); return; @@ -671,8 +672,6 @@ namespace ts { return emitCallExpression(node); case SyntaxKind.NewExpression: return emitNewExpression(node); - case SyntaxKind.ImportCallExpression: - return emitImportCallExpression(node); case SyntaxKind.TaggedTemplateExpression: return emitTaggedTemplateExpression(node); case SyntaxKind.TypeAssertionExpression: @@ -1155,13 +1154,6 @@ namespace ts { emitExpressionList(node, node.arguments, ListFormat.NewExpressionArguments); } - function emitImportCallExpression(node: ImportCallExpression) { - write("import"); - write("("); - emitExpression(node.specifier); - write(")"); - } - function emitTaggedTemplateExpression(node: TaggedTemplateExpression) { emitExpression(node.tag); write(" "); diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index 0bf545f4fe1..3ff3bc2782f 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -503,18 +503,6 @@ namespace ts { : node; } - export function createImportCall(specifier: Expression): ImportCallExpression { - const node = createSynthesizedNode(SyntaxKind.ImportCallExpression); - node.specifier = specifier; - return node; - } - - export function updateImportCall(node: ImportCallExpression, specifier: Expression): ImportCallExpression { - return node.specifier !== specifier - ? updateNode(createImportCall(specifier), node) - : node; - } - export function createTaggedTemplate(tag: Expression, template: TemplateLiteral) { const node = createSynthesizedNode(SyntaxKind.TaggedTemplateExpression); node.tag = parenthesizeForAccess(tag); diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 8d924ff154c..f9bb5afd945 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -167,8 +167,6 @@ namespace ts { return visitNode(cbNode, (node).expression) || visitNodes(cbNodes, (node).typeArguments) || visitNodes(cbNodes, (node).arguments); - case SyntaxKind.ImportCallExpression: - return visitNode(cbNode, (node).specifier); case SyntaxKind.TaggedTemplateExpression: return visitNode(cbNode, (node).tag) || visitNode(cbNode, (node).template); @@ -3654,6 +3652,20 @@ namespace ts { return finishNode(node); } + if (isImportCall(expression)) { + // Check that the argument array is strictly of length 1 and the argument is assignment-expression + const arguments = expression.arguments; + if (arguments.length !== 1) { + parseErrorAtPosition(arguments.pos, arguments.end - arguments.pos, Diagnostics.Dynamic_import_can_only_have_one_specifier_as_an_argument); + } + + // see: parseArgumentOrArrayLiteralElement...we use this function which parse arguments of callExpression to parse specifier for dynamic import. + // parseArgumentOrArrayLiteralElement allows spread element to be in an argument list which is not allowed in dynamic import. + if (expression.arguments.length >= 1 && isSpreadExpression(arguments[0])) { + parseErrorAtPosition(arguments.pos, arguments.end - arguments.pos, Diagnostics.Specifier_of_dynamic_import_cannot_be_spread_element); + } + } + return expression; } @@ -3689,16 +3701,17 @@ namespace ts { // the last two CallExpression productions. 2) We see 'import' which must start import call. // 3)we have a MemberExpression which either completes the LeftHandSideExpression, // or starts the beginning of the first four CallExpression productions. - + let expression: MemberExpression; if (token() === SyntaxKind.ImportKeyword && lookAhead(nextTokenIsOpenParen)) { // We don't want to eagerly consume all import keyword as import call expression so we look a head to find "(" // For example: // var foo3 = require("subfolder // import * as foo1 from "module-from-node -> we want this import to be a statement rather than import call expression - const importCall = parseImportCallExpression(); - return importCall; + expression = parseTokenNode(); + } + else { + expression = token() === SyntaxKind.SuperKeyword ? parseSuperExpression() : parseMemberExpressionOrHigher(); } - const expression = token() === SyntaxKind.SuperKeyword ? parseSuperExpression() : parseMemberExpressionOrHigher(); // Now, we *may* be complete. However, we might have consumed the start of a // CallExpression. As such, we need to consume the rest of it here to be complete. @@ -3772,15 +3785,6 @@ namespace ts { return finishNode(node); } - function parseImportCallExpression(): ImportCallExpression { - const importCallExpr = createNode(SyntaxKind.ImportCallExpression); - parseExpected(SyntaxKind.ImportKeyword); - parseExpected(SyntaxKind.OpenParenToken); - importCallExpr.specifier = parseAssignmentExpressionOrHigher(); - parseExpected(SyntaxKind.CloseParenToken); - return finishNode(importCallExpr); - } - function tagNamesAreEquivalent(lhs: JsxTagNameExpression, rhs: JsxTagNameExpression): boolean { if (lhs.kind !== rhs.kind) { return false; diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 39632061c7c..e6581c382ea 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1268,8 +1268,9 @@ namespace ts { if (isJavaScriptFile && isRequireCall(node, /*checkArgumentIsStringLiteral*/true)) { (imports || (imports = [])).push((node).arguments[0]); } - else if (isImportCallExpression(node) && node.specifier.kind === SyntaxKind.StringLiteral) { - (imports || (imports = [])).push((node).specifier); + // we can safely get the first argument in the list here because we already issue parsing error if the length is not 1 + else if (isImportCall(node) && node.arguments[0].kind === SyntaxKind.StringLiteral) { + (imports || (imports = [])).push((node).arguments[0]); } else { forEachChild(node, collectImportOrRequireCalls); diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index 375c44a312d..4524f660ddf 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -493,15 +493,15 @@ namespace ts { return node; } - switch (node.kind) { - case SyntaxKind.ImportCallExpression: - return visitImportCallExpression(node); - default: - return visitEachChild(node, importCallExpressionVisitor, context); + if (isImportCall(node)) { + return visitImportCallExpression(node); + } + else { + return visitEachChild(node, importCallExpressionVisitor, context); } } - function visitImportCallExpression(node: ImportCallExpression): Expression { + function visitImportCallExpression(node: ImportCall): Expression { switch (compilerOptions.module) { case ModuleKind.CommonJS: return transformImportCallExpressionCommonJS(node); @@ -513,7 +513,7 @@ namespace ts { Debug.fail("All supported module kind in this transformation step should have been handled"); } - function transformImportCallExpressionUMD(node: ImportCallExpression): Expression { + function transformImportCallExpressionUMD(node: ImportCall): Expression { // (function (factory) { // ... (regular UMD) // } @@ -532,7 +532,7 @@ namespace ts { ); } - function transformImportCallExpressionAMD(node: ImportCallExpression): Expression { + function transformImportCallExpressionAMD(node: ImportCall): Expression { // improt("./blah") // emit as // define(["require", "exports", "blah"], function (require, exports) { @@ -550,13 +550,13 @@ namespace ts { [createParameter(/*decorator*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, /*name*/ resolve)], /*type*/ undefined, createToken(SyntaxKind.EqualsGreaterThanToken), - createCall(createIdentifier("require"), /*typeArguments*/ undefined, [createArrayLiteral([node.specifier]), resolve]) + createCall(createIdentifier("require"), /*typeArguments*/ undefined, [createArrayLiteral([node.arguments[0]]), resolve]) ) ] ); } - function transformImportCallExpressionCommonJS(node: ImportCallExpression): Expression { + function transformImportCallExpressionCommonJS(node: ImportCall): Expression { // import("./blah") // emit as // Promise.resolve().then(() => require("./blah")); @@ -567,7 +567,7 @@ namespace ts { createCall(/*expression*/ createPropertyAccess(createIdentifier("Promise"), "resolve"), /*typeArguments*/ undefined, /*argumentsArray*/[]), "then"), /*typeArguments*/ undefined, - [createArrowFunction(/*modifiers*/ undefined, /*typeParameters*/ undefined, /*parameters*/ undefined, /*type*/ undefined, createToken(SyntaxKind.EqualsGreaterThanToken), createCall(createIdentifier("require"), /*typeArguments*/ undefined, [node.specifier]))] + [createArrowFunction(/*modifiers*/ undefined, /*typeParameters*/ undefined, /*parameters*/ undefined, /*type*/ undefined, createToken(SyntaxKind.EqualsGreaterThanToken), createCall(createIdentifier("require"), /*typeArguments*/ undefined, [node.arguments[0]]))] ); } diff --git a/src/compiler/transformers/module/system.ts b/src/compiler/transformers/module/system.ts index 2c2466f8c82..03a1c8cb00b 100644 --- a/src/compiler/transformers/module/system.ts +++ b/src/compiler/transformers/module/system.ts @@ -1459,7 +1459,7 @@ namespace ts { && node.kind === SyntaxKind.BinaryExpression) { return visitDestructuringAssignment(node); } - else if (isImportCallExpression(node)) { + else if (isImportCall(node)) { return visitImportCallExpression(node); } else if ((node.transformFlags & TransformFlags.ContainsDestructuringAssignment) || (node.transformFlags & TransformFlags.ContainsDynamicImport)) { @@ -1470,7 +1470,7 @@ namespace ts { } } - function visitImportCallExpression(node: ImportCallExpression): Expression { + function visitImportCallExpression(node: ImportCall): Expression { // import("./blah") // emit as // System.register([], function (_export, _context) { @@ -1487,7 +1487,7 @@ namespace ts { createIdentifier("import") ), /*typeArguments*/ undefined, - [node.specifier] + [node.arguments[0]] ); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 3a08bd45084..762bbef3f82 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -391,9 +391,6 @@ namespace ts { MergeDeclarationMarker, EndOfDeclarationMarker, - // Dynamic import - ImportCallExpression, - // Enum value count Count, @@ -1447,9 +1444,12 @@ namespace ts { expression: SuperExpression; } - export interface ImportCallExpression extends LeftHandSideExpression, Declaration { - kind: SyntaxKind.ImportCallExpression; - specifier: Expression; + export interface ImportExpression extends PrimaryExpression { + kind: SyntaxKind.ImportKeyword; + } + + export interface ImportCall extends CallExpression { + expression: ImportExpression; } export interface ExpressionWithTypeArguments extends TypeNode { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 47c26301d1b..4eb78736e16 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -662,8 +662,8 @@ namespace ts { return n.kind === SyntaxKind.CallExpression && (n).expression.kind === SyntaxKind.SuperKeyword; } - export function isImportCallExpression(n: Node): n is ImportCallExpression { - return n.kind === SyntaxKind.ImportCallExpression; + export function isImportCall(n: Node): n is ImportCall { + return n.kind === SyntaxKind.CallExpression && (n).expression.kind === SyntaxKind.ImportKeyword; } export function isPrologueDirective(node: Node): node is PrologueDirective { @@ -3891,7 +3891,6 @@ namespace ts { || kind === SyntaxKind.SuperKeyword || kind === SyntaxKind.NonNullExpression || kind === SyntaxKind.MetaProperty - || kind === SyntaxKind.ImportCallExpression; } export function isLeftHandSideExpression(node: Node): node is LeftHandSideExpression { diff --git a/src/compiler/visitor.ts b/src/compiler/visitor.ts index 91ae6560c7d..0f4a4ed6561 100644 --- a/src/compiler/visitor.ts +++ b/src/compiler/visitor.ts @@ -339,10 +339,6 @@ namespace ts { visitNodes((node).typeArguments, visitor, isTypeNode), visitNodes((node).arguments, visitor, isExpression)); - case SyntaxKind.ImportCallExpression: - return updateImportCall(node, - visitNode((node).specifier, visitor, isExpression)); - case SyntaxKind.NewExpression: return updateNew(node, visitNode((node).expression, visitor, isExpression), From c798489eb1a66de79864cf178114bf693bef2347 Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Wed, 22 Mar 2017 15:04:17 -0700 Subject: [PATCH 31/67] Move error report of incorrect grammar in dynamic import to checker --- src/compiler/checker.ts | 35 +++++++++++++++++---- src/compiler/diagnosticMessages.json | 17 +++++----- src/compiler/parser.ts | 14 --------- src/compiler/program.ts | 4 +-- src/compiler/transformers/module/module.ts | 36 +++++++++++++--------- src/compiler/transformers/module/system.ts | 2 +- 6 files changed, 62 insertions(+), 46 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6df2efeea83..6f459770912 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -14824,16 +14824,17 @@ namespace ts { // Grammar checking; stop grammar-checking if checkGrammarTypeArguments return true checkGrammarTypeArguments(node, node.typeArguments) || checkGrammarArguments(node, node.arguments); + // Dynamic import is not need to go through regular resolve signature. + if (node.expression.kind === SyntaxKind.ImportKeyword) { + return checkImportCallExpression(node); + } + const signature = getResolvedSignature(node); if (node.expression.kind === SyntaxKind.SuperKeyword) { return voidType; } - if (node.expression.kind === SyntaxKind.ImportKeyword) { - return checkImportCallExpression(node); - } - if (node.kind === SyntaxKind.NewExpression) { const declaration = signature.declaration; @@ -14872,7 +14873,12 @@ namespace ts { return getReturnTypeOfSignature(signature); } - function checkImportCallExpression(node: CallExpression): Type { + function checkImportCallExpression(node: ImportCall): Type { + // Check grammar of dynamic import + if (checkGrammarImportCallExpression(node)) { + return createPromiseReturnType(node, anyType); + } + if (modulekind === ModuleKind.ES2015) { grammarErrorOnNode(node, Diagnostics.Dynamic_import_cannot_be_used_when_targeting_ECMAScript_2015_modules); } @@ -23364,5 +23370,22 @@ namespace ts { }); return result; } + + /** + * + * @param node + */ + function checkGrammarImportCallExpression(node: ImportCall): boolean { + const arguments = node.arguments; + if (arguments.length !== 1) { + return grammarErrorOnNode(node, Diagnostics.Dynamic_import_must_have_one_specifier_as_an_argument); + } + + // see: parseArgumentOrArrayLiteralElement...we use this function which parse arguments of callExpression to parse specifier for dynamic import. + // parseArgumentOrArrayLiteralElement allows spread element to be in an argument list which is not allowed as specifier in dynamic import. + if (isSpreadExpression(arguments[0])) { + return grammarErrorOnNode(arguments[0], Diagnostics.Specifier_of_dynamic_import_cannot_be_spread_element); + } + } } -} +} \ No newline at end of file diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 4618776af26..880dc7750f1 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -871,6 +871,15 @@ "category": "Error", "code": 1320 }, + "Dynamic import must have one specifier as an argument.": { + "category": "Error", + "code": 1321 + }, + "Specifier of dynamic import cannot be spread element.": { + "category": "Error", + "code": 1322 + }, + "Duplicate identifier '{0}'.": { "category": "Error", "code": 2300 @@ -3297,14 +3306,6 @@ "category": "Error", "code": 17013 }, - "Dynamic import can only have one specifier as an argument.": { - "category": "Error", - "code": 17014 - }, - "Specifier of dynamic import cannot be spread element.": { - "category": "Error", - "code": 17015 - }, "Circularity detected while resolving configuration: {0}": { "category": "Error", diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index f9bb5afd945..1575ec0c0f0 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3652,20 +3652,6 @@ namespace ts { return finishNode(node); } - if (isImportCall(expression)) { - // Check that the argument array is strictly of length 1 and the argument is assignment-expression - const arguments = expression.arguments; - if (arguments.length !== 1) { - parseErrorAtPosition(arguments.pos, arguments.end - arguments.pos, Diagnostics.Dynamic_import_can_only_have_one_specifier_as_an_argument); - } - - // see: parseArgumentOrArrayLiteralElement...we use this function which parse arguments of callExpression to parse specifier for dynamic import. - // parseArgumentOrArrayLiteralElement allows spread element to be in an argument list which is not allowed in dynamic import. - if (expression.arguments.length >= 1 && isSpreadExpression(arguments[0])) { - parseErrorAtPosition(arguments.pos, arguments.end - arguments.pos, Diagnostics.Specifier_of_dynamic_import_cannot_be_spread_element); - } - } - return expression; } diff --git a/src/compiler/program.ts b/src/compiler/program.ts index e6581c382ea..b50c96a5f0c 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1268,8 +1268,8 @@ namespace ts { if (isJavaScriptFile && isRequireCall(node, /*checkArgumentIsStringLiteral*/true)) { (imports || (imports = [])).push((node).arguments[0]); } - // we can safely get the first argument in the list here because we already issue parsing error if the length is not 1 - else if (isImportCall(node) && node.arguments[0].kind === SyntaxKind.StringLiteral) { + // we have to check the argument list has length of 1. We will still have to process these even though we have parsing error. + else if (isImportCall(node) && node.arguments.length === 1 && node.arguments[0].kind === SyntaxKind.StringLiteral) { (imports || (imports = [])).push((node).arguments[0]); } else { diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index 4524f660ddf..d7f3a2ad743 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -543,17 +543,14 @@ namespace ts { return createNew( createIdentifier("Promise"), /*typeArguments*/ undefined, - [ - createArrowFunction( - /*modifiers*/undefined, - /*typeParameters*/ undefined, - [createParameter(/*decorator*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, /*name*/ resolve)], - /*type*/ undefined, - createToken(SyntaxKind.EqualsGreaterThanToken), - createCall(createIdentifier("require"), /*typeArguments*/ undefined, [createArrayLiteral([node.arguments[0]]), resolve]) - ) - ] - ); + [createArrowFunction( + /*modifiers*/undefined, + /*typeParameters*/ undefined, + [createParameter(/*decorator*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, /*name*/ resolve)], + /*type*/ undefined, + createToken(SyntaxKind.EqualsGreaterThanToken), + createCall(createIdentifier("require"), /*typeArguments*/ undefined, node.arguments.concat([resolve])) + )]); } function transformImportCallExpressionCommonJS(node: ImportCall): Expression { @@ -564,11 +561,20 @@ namespace ts { // if we simply do require in resolve callback in Promise constructor. We will execute the loading immediately return createCall( createPropertyAccess( - createCall(/*expression*/ createPropertyAccess(createIdentifier("Promise"), "resolve"), /*typeArguments*/ undefined, /*argumentsArray*/[]), - "then"), + createCall( + createPropertyAccess(createIdentifier("Promise"), "resolve"), + /*typeArguments*/ undefined, + /*argumentsArray*/[] + ), "then"), /*typeArguments*/ undefined, - [createArrowFunction(/*modifiers*/ undefined, /*typeParameters*/ undefined, /*parameters*/ undefined, /*type*/ undefined, createToken(SyntaxKind.EqualsGreaterThanToken), createCall(createIdentifier("require"), /*typeArguments*/ undefined, [node.arguments[0]]))] - ); + [createArrowFunction( + /*modifiers*/ undefined, + /*typeParameters*/ undefined, + /*parameters*/ undefined, + /*type*/ undefined, + createToken(SyntaxKind.EqualsGreaterThanToken), + createCall(createIdentifier("require"), /*typeArguments*/ undefined, node.arguments) + )]); } /** diff --git a/src/compiler/transformers/module/system.ts b/src/compiler/transformers/module/system.ts index 03a1c8cb00b..f7395ab0791 100644 --- a/src/compiler/transformers/module/system.ts +++ b/src/compiler/transformers/module/system.ts @@ -1487,7 +1487,7 @@ namespace ts { createIdentifier("import") ), /*typeArguments*/ undefined, - [node.arguments[0]] + node.arguments ); } From c62f4f5888e24b0b9928be8afec54531ed4e3414 Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Wed, 22 Mar 2017 15:10:19 -0700 Subject: [PATCH 32/67] Update tests --- .../importCallExpressionCheckSpecifier1.ts | 12 --------- .../importCallExpressionGrammarError.ts | 14 ++++++++++ .../importCallExpressionInUMD2.ts | 17 ++++++++++++ .../importCallExpressionInUMD3.ts | 14 ++++++++++ .../importCallExpressionInUMD4.ts | 26 +++++++++++++++++++ ...importCallExpressionNoImplicitAnyError.ts} | 0 .../importCallExpressionReturnPromiseOfAny.ts | 26 +++++++++++++++++++ ...lExpressionSpecifierNotStringTypeError.ts} | 6 ++++- 8 files changed, 102 insertions(+), 13 deletions(-) delete mode 100644 tests/cases/conformance/es2018/dynamicImport/importCallExpressionCheckSpecifier1.ts create mode 100644 tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts create mode 100644 tests/cases/conformance/es2018/dynamicImport/importCallExpressionInUMD2.ts create mode 100644 tests/cases/conformance/es2018/dynamicImport/importCallExpressionInUMD3.ts create mode 100644 tests/cases/conformance/es2018/dynamicImport/importCallExpressionInUMD4.ts rename tests/cases/conformance/es2018/dynamicImport/{importCallExpressionReturnAny1.ts => importCallExpressionNoImplicitAnyError.ts} (100%) create mode 100644 tests/cases/conformance/es2018/dynamicImport/importCallExpressionReturnPromiseOfAny.ts rename tests/cases/conformance/es2018/dynamicImport/{importCallExpressionCheckSpecifier2.ts => importCallExpressionSpecifierNotStringTypeError.ts} (79%) diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionCheckSpecifier1.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionCheckSpecifier1.ts deleted file mode 100644 index e4de1109b1a..00000000000 --- a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionCheckSpecifier1.ts +++ /dev/null @@ -1,12 +0,0 @@ -// @module: commonjs -// @target: es6 -// @noImplicitAny: false - -declare function getSpecifier(): string; -declare var whatToLoad: boolean; -import(getSpecifier()); -var p1 = import(getSpecifier()); -const p2 = import(whatToLoad ? getSpecifier() : "defaulPath") -p1.then(zero => { - return zero.foo(); // ok, zero is any -}); \ No newline at end of file diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts new file mode 100644 index 00000000000..38dc47f3207 --- /dev/null +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts @@ -0,0 +1,14 @@ +// @module: commonjs +// @target: es6 +// @noImplicitAny: false + +declare function getSpecifier(): string; +declare var whatToLoad: boolean; + +var a = ["./0"]; +import(...["PathModule"]); + +var p1 = import(...a); +const p2 = import(); +const p3 = import(,); +const p4 = import("pathToModule", "secondModule"); \ No newline at end of file diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInUMD2.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInUMD2.ts new file mode 100644 index 00000000000..2f76d0aa267 --- /dev/null +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInUMD2.ts @@ -0,0 +1,17 @@ +// @module: umd +// @target: esnext +// @filename: 0.ts +export class B { + print() { return "I am B"} +} + +// @filename: 2.ts +// We use Promise for now as there is no way to specify shape of module object +function foo(x: Promise) { + x.then(value => { + let b = new value.B(); + b.print(); + }) +} + +foo(import("./0")); \ No newline at end of file diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInUMD3.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInUMD3.ts new file mode 100644 index 00000000000..58d21ee52d0 --- /dev/null +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInUMD3.ts @@ -0,0 +1,14 @@ +// @module: umd +// @target: esnext +// @filename: 0.ts +export class B { + print() { return "I am B"} +} + +// @filename: 2.ts +async function foo() { + class C extends (await import("./0")).B {} + var c = new C(); + c.print(); +} +foo(); \ No newline at end of file diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInUMD4.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInUMD4.ts new file mode 100644 index 00000000000..ef0f0999407 --- /dev/null +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInUMD4.ts @@ -0,0 +1,26 @@ +// @module: umd +// @target: esnext +// @filename: 0.ts +export class B { + print() { return "I am B"} +} + +export function foo() { return "foo" } + +// @filename: 1.ts +export function backup() { return "backup"; } + +// @filename: 2.ts +declare var console: any; +class C { + private myModule = import("./0"); + method() { + this.myModule.then(Zero => { + console.log(Zero.foo()); + }, async err => { + console.log(err); + let one = await import("./1"); + console.log(one.backup()); + }); + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionReturnAny1.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionNoImplicitAnyError.ts similarity index 100% rename from tests/cases/conformance/es2018/dynamicImport/importCallExpressionReturnAny1.ts rename to tests/cases/conformance/es2018/dynamicImport/importCallExpressionNoImplicitAnyError.ts diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionReturnPromiseOfAny.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionReturnPromiseOfAny.ts new file mode 100644 index 00000000000..737e2ce42f9 --- /dev/null +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionReturnPromiseOfAny.ts @@ -0,0 +1,26 @@ +// @module: commonjs +// @target: es6 +// @noImplicitAny: false + +declare function getSpecifier(): string; +declare var whatToLoad: boolean; +declare const directory: string; +declare const moduleFile: number; + +import(`${directory}\${moduleFile}`); +import(getSpecifier()); +var p1 = import(getSpecifier()); +const p2 = import(whatToLoad ? getSpecifier() : "defaulPath") +p1.then(zero => { + return zero.foo(); // ok, zero is any +}); + +let j: string; +var p3 = import(j=getSpecifier()); + +function * loadModule(directories: string[]) { + for (const directory of directories) { + const path = `${directory}\moduleFile`; + import(yield path); + } +} diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionCheckSpecifier2.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts similarity index 79% rename from tests/cases/conformance/es2018/dynamicImport/importCallExpressionCheckSpecifier2.ts rename to tests/cases/conformance/es2018/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts index 37e3c65be8d..3af0ec89ac2 100644 --- a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionCheckSpecifier2.ts +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts @@ -4,10 +4,14 @@ declare function getSpecifier(): boolean; declare var whatToLoad: boolean; + // Error specifier is not assignable to string import(getSpecifier()); var p1 = import(getSpecifier()); const p2 = import(whatToLoad ? getSpecifier() : "defaulPath") p1.then(zero => { return zero.foo(); // ok, zero is any -}); \ No newline at end of file +}); + +var p3 = import(["path1", "path2"]); +var p4 = import(()=>"PathToModule"); \ No newline at end of file From e1ba8553b6180c0104156c0618289971a7936778 Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Thu, 23 Mar 2017 11:29:45 -0700 Subject: [PATCH 33/67] Add declaration emit test and test to make sure we don't give dynamic import implicit "use strict" --- ...portCallExpressionAllowInScriptContext1.ts | 10 ++++++++++ ...portCallExpressionAllowInScriptContext2.ts | 11 +++++++++++ .../importCallExpressionDeclarationEmit1.ts | 19 +++++++++++++++++++ .../importCallExpressionDeclarationEmit2.ts | 10 ++++++++++ 4 files changed, 50 insertions(+) create mode 100644 tests/cases/conformance/es2018/dynamicImport/importCallExpressionAllowInScriptContext1.ts create mode 100644 tests/cases/conformance/es2018/dynamicImport/importCallExpressionAllowInScriptContext2.ts create mode 100644 tests/cases/conformance/es2018/dynamicImport/importCallExpressionDeclarationEmit1.ts create mode 100644 tests/cases/conformance/es2018/dynamicImport/importCallExpressionDeclarationEmit2.ts diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionAllowInScriptContext1.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionAllowInScriptContext1.ts new file mode 100644 index 00000000000..166513321a3 --- /dev/null +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionAllowInScriptContext1.ts @@ -0,0 +1,10 @@ +// @module: commonjs +// @target: es6 +// @noImplicitAny: false + +// @filename: 0.ts +export function foo() { return "foo"; } + +// @filename: 1.ts +var p1 = import("./0"); +function arguments() { } // this is allow as the file doesn't have implicit "use strict" \ No newline at end of file diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionAllowInScriptContext2.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionAllowInScriptContext2.ts new file mode 100644 index 00000000000..754f7e865bb --- /dev/null +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionAllowInScriptContext2.ts @@ -0,0 +1,11 @@ +// @module: commonjs +// @target: es6 +// @noImplicitAny: false + +// @filename: 0.ts +export function foo() { return "foo"; } + +// @filename: 1.ts +"use strict" +var p1 = import("./0"); +function arguments() { } \ No newline at end of file diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionDeclarationEmit1.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionDeclarationEmit1.ts new file mode 100644 index 00000000000..fb299951148 --- /dev/null +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionDeclarationEmit1.ts @@ -0,0 +1,19 @@ +// @module: commonjs +// @target: es6 +// @noImplicitAny: false +// @declaration: true + +declare function getSpecifier(): string; +declare var whatToLoad: boolean; +declare const directory: string; +declare const moduleFile: number; + +import(getSpecifier()); + +var p0 = import(`${directory}\${moduleFile}`); +var p1 = import(getSpecifier()); +const p2 = import(whatToLoad ? getSpecifier() : "defaulPath") + +function returnDynamicLoad(path: string) { + return import(path); +} \ No newline at end of file diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionDeclarationEmit2.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionDeclarationEmit2.ts new file mode 100644 index 00000000000..d1ee592a98a --- /dev/null +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionDeclarationEmit2.ts @@ -0,0 +1,10 @@ +// @module: es2018 +// @target: esnext +// @declaration: true + +// @filename: 0.ts +export function foo() { return "foo"; } + +// @filename: 1.ts +import("./0"); +var p1 = import("./0"); \ No newline at end of file From 265d0c020b140be4e79a3833b8bfa1e32e5c996c Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Fri, 24 Mar 2017 13:24:50 -0700 Subject: [PATCH 34/67] Fix where we report noImplicitAny error in dynamic import --- src/compiler/checker.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6f459770912..fe471ba7002 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1,4 +1,4 @@ -/// +/// /// /* @internal */ @@ -284,6 +284,7 @@ namespace ts { let deferredGlobalAsyncIterableIteratorType: GenericType; let deferredGlobalTemplateStringsArrayType: ObjectType; let deferredJsxElementClassType: Type; + let deferredGlobalPromiseAnyType: Type; let deferredNodes: Node[]; let deferredUnusedIdentifierNodes: Node[]; @@ -3455,6 +3456,11 @@ namespace ts { // Use the type of the initializer expression if one is present if (declaration.initializer) { const type = checkDeclarationInitializer(declaration); + + if (isImportCall(declaration.initializer)) { + if (noImplicitAny && type === getGlobalPromiseAnyType()) { + error(declaration, Diagnostics.Cannot_resolve_dynamic_import_implicitly_has_a_Promise_any_type); } + } return addOptionality(type, /*optional*/ declaration.questionToken && includeOptionality); } @@ -6083,6 +6089,10 @@ namespace ts { return deferredGlobalPromiseType || (deferredGlobalPromiseType = getGlobalType("Promise", /*arity*/ 1, reportErrors)) || emptyGenericType; } + function getGlobalPromiseAnyType() { + return deferredGlobalPromiseAnyType || (deferredGlobalPromiseAnyType = createPromiseType(anyType)); + } + function getGlobalPromiseConstructorSymbol(reportErrors: boolean): Symbol | undefined { return deferredGlobalPromiseConstructorSymbol || (deferredGlobalPromiseConstructorSymbol = getGlobalValueSymbol("Promise", reportErrors)); } @@ -14897,9 +14907,6 @@ namespace ts { return createPromiseReturnType(node, getTypeOfSymbol(esModuleSymbol)); } } - if (noImplicitAny) { - error(node, Diagnostics.Cannot_resolve_dynamic_import_implicitly_has_a_Promise_any_type); - } return createPromiseReturnType(node, anyType); } From 640f2c7371bf652d8ea31ca0179ac692f4ded586 Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Fri, 24 Mar 2017 15:30:57 -0700 Subject: [PATCH 35/67] Error when dynamic import has type arguments --- src/compiler/checker.ts | 15 ++++++++------- src/compiler/diagnosticMessages.json | 4 ++++ src/compiler/parser.ts | 7 ++++++- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index fe471ba7002..59fcabb9ffa 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -14834,11 +14834,6 @@ namespace ts { // Grammar checking; stop grammar-checking if checkGrammarTypeArguments return true checkGrammarTypeArguments(node, node.typeArguments) || checkGrammarArguments(node, node.arguments); - // Dynamic import is not need to go through regular resolve signature. - if (node.expression.kind === SyntaxKind.ImportKeyword) { - return checkImportCallExpression(node); - } - const signature = getResolvedSignature(node); if (node.expression.kind === SyntaxKind.SuperKeyword) { @@ -14885,7 +14880,7 @@ namespace ts { function checkImportCallExpression(node: ImportCall): Type { // Check grammar of dynamic import - if (checkGrammarImportCallExpression(node)) { + if (checkGrammarArguments(node, node.arguments) || checkGrammarImportCallExpression(node)) { return createPromiseReturnType(node, anyType); } @@ -14893,7 +14888,6 @@ namespace ts { grammarErrorOnNode(node, Diagnostics.Dynamic_import_cannot_be_used_when_targeting_ECMAScript_2015_modules); } - // We already error in parse if arguments list is not length of 1 const specifier = node.arguments[0]; const specifierType = checkExpression(specifier); if (!isTypeAssignableTo(specifierType, stringType)) { @@ -16449,6 +16443,9 @@ namespace ts { return checkIndexedAccess(node); case SyntaxKind.CallExpression: case SyntaxKind.NewExpression: + if ((node).expression.kind === SyntaxKind.ImportKeyword) { + return checkImportCallExpression(node); + } return checkCallExpression(node); case SyntaxKind.TaggedTemplateExpression: return checkTaggedTemplateExpression(node); @@ -23388,6 +23385,10 @@ namespace ts { return grammarErrorOnNode(node, Diagnostics.Dynamic_import_must_have_one_specifier_as_an_argument); } + if (node.typeArguments) { + return grammarErrorOnNode(node, Diagnostics.Dynamic_import_cannot_have_type_arguments); + } + // see: parseArgumentOrArrayLiteralElement...we use this function which parse arguments of callExpression to parse specifier for dynamic import. // parseArgumentOrArrayLiteralElement allows spread element to be in an argument list which is not allowed as specifier in dynamic import. if (isSpreadExpression(arguments[0])) { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 880dc7750f1..deb1ae90524 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -879,6 +879,10 @@ "category": "Error", "code": 1322 }, + "Dynamic import cannot have type arguments": { + "category": "Error", + "code": 1323 + }, "Duplicate identifier '{0}'.": { "category": "Error", diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 1575ec0c0f0..fd9a66151cc 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3688,7 +3688,7 @@ namespace ts { // 3)we have a MemberExpression which either completes the LeftHandSideExpression, // or starts the beginning of the first four CallExpression productions. let expression: MemberExpression; - if (token() === SyntaxKind.ImportKeyword && lookAhead(nextTokenIsOpenParen)) { + if (token() === SyntaxKind.ImportKeyword && lookAhead(nextTokenIsOpenParenOrLessThan)) { // We don't want to eagerly consume all import keyword as import call expression so we look a head to find "(" // For example: // var foo3 = require("subfolder @@ -5602,6 +5602,11 @@ namespace ts { return nextToken() === SyntaxKind.OpenParenToken; } + function nextTokenIsOpenParenOrLessThan() { + const next = nextToken(); + return next === SyntaxKind.OpenParenToken || next === SyntaxKind.LessThanToken; + } + function nextTokenIsSlash() { return nextToken() === SyntaxKind.SlashToken; } From 61f199e5f25b1d443e0c674a9f1eb086f9ebde7e Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Fri, 24 Mar 2017 15:32:16 -0700 Subject: [PATCH 36/67] Update tests --- .../importCallExpressionReturnPromiseOfAny.ts | 13 +++++++++---- .../importCallExpressionWithTypeArgument.ts | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 tests/cases/conformance/es2018/dynamicImport/importCallExpressionWithTypeArgument.ts diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionReturnPromiseOfAny.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionReturnPromiseOfAny.ts index 737e2ce42f9..235a76eb2f9 100644 --- a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionReturnPromiseOfAny.ts +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionReturnPromiseOfAny.ts @@ -1,7 +1,11 @@ // @module: commonjs // @target: es6 -// @noImplicitAny: false +// @noImplicitAny: true +// @filename: defaultPath.ts +export class C {} +// @filename: 1.ts +import * as defaultModule from "./defaultPath"; declare function getSpecifier(): string; declare var whatToLoad: boolean; declare const directory: string; @@ -9,14 +13,15 @@ declare const moduleFile: number; import(`${directory}\${moduleFile}`); import(getSpecifier()); -var p1 = import(getSpecifier()); -const p2 = import(whatToLoad ? getSpecifier() : "defaulPath") +var p1: Promise = import(getSpecifier()); +var p11: Promise = import(getSpecifier()); +const p2 = import(whatToLoad ? getSpecifier() : "defaulPath") as Promise; p1.then(zero => { return zero.foo(); // ok, zero is any }); let j: string; -var p3 = import(j=getSpecifier()); +var p3: Promise = import(j=getSpecifier()); function * loadModule(directories: string[]) { for (const directory of directories) { diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionWithTypeArgument.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionWithTypeArgument.ts new file mode 100644 index 00000000000..895b61af6ff --- /dev/null +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionWithTypeArgument.ts @@ -0,0 +1,14 @@ +// @module: commonjs +// @target: es6 +// @noImplicitAny: false + +// @filename: 0.ts +export function foo() { return "foo"; } + +// @filename: 1.ts +"use strict" +var p1 = import>("./0"); // error +var p2 = import<>("./0"); // error +// p1.then(value => { +// value.anyFunction(); +// }) \ No newline at end of file From 486dc91f7623121b5f7d0c5074a3bc3998c786f0 Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Mon, 27 Mar 2017 09:47:23 -0700 Subject: [PATCH 37/67] Change comment to jsdoc --- src/compiler/parser.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index fd9a66151cc..3379c3fb3b4 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -46,10 +46,16 @@ namespace ts { } } - // Invokes a callback for each child of the given node. The 'cbNode' callback is invoked for all child nodes - // stored in properties. If a 'cbNodes' callback is specified, it is invoked for embedded arrays; otherwise, - // embedded arrays are flattened and the 'cbNode' callback is invoked for each element. If a callback returns - // a truthy value, iteration stops and that value is returned. Otherwise, undefined is returned. + /** + * Invokes a callback for each child of the given node. The 'cbNode' callback is invoked for all child nodes + * stored in properties. If a 'cbNodes' callback is specified, it is invoked for embedded arrays; otherwise, + * embedded arrays are flattened and the 'cbNode' callback is invoked for each element. If a callback returns + * a truthy value, iteration stops and that value is returned. Otherwise, undefined is returned. + * + * @param node a given node to visit its children + * @param cbNode a callback to be invoked for all child nodes + * @param cbNodeArray a callback to be invoked for embedded array + */ export function forEachChild(node: Node, cbNode: (node: Node) => T, cbNodeArray?: (nodes: Node[]) => T): T { if (!node) { return; From 6080c3efd686df9f1e20e19f763a135cf720ecda Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Tue, 28 Mar 2017 12:38:41 -0700 Subject: [PATCH 38/67] Remove error with noImplicitAny --- src/compiler/checker.ts | 10 ---------- src/compiler/diagnosticMessages.json | 11 ++++------- .../importCallExpressionNoImplicitAnyError.ts | 12 ------------ .../importCallExpressionReturnPromiseOfAny.ts | 3 +++ 4 files changed, 7 insertions(+), 29 deletions(-) delete mode 100644 tests/cases/conformance/es2018/dynamicImport/importCallExpressionNoImplicitAnyError.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 59fcabb9ffa..6d10998ffc5 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -284,7 +284,6 @@ namespace ts { let deferredGlobalAsyncIterableIteratorType: GenericType; let deferredGlobalTemplateStringsArrayType: ObjectType; let deferredJsxElementClassType: Type; - let deferredGlobalPromiseAnyType: Type; let deferredNodes: Node[]; let deferredUnusedIdentifierNodes: Node[]; @@ -3456,11 +3455,6 @@ namespace ts { // Use the type of the initializer expression if one is present if (declaration.initializer) { const type = checkDeclarationInitializer(declaration); - - if (isImportCall(declaration.initializer)) { - if (noImplicitAny && type === getGlobalPromiseAnyType()) { - error(declaration, Diagnostics.Cannot_resolve_dynamic_import_implicitly_has_a_Promise_any_type); } - } return addOptionality(type, /*optional*/ declaration.questionToken && includeOptionality); } @@ -6089,10 +6083,6 @@ namespace ts { return deferredGlobalPromiseType || (deferredGlobalPromiseType = getGlobalType("Promise", /*arity*/ 1, reportErrors)) || emptyGenericType; } - function getGlobalPromiseAnyType() { - return deferredGlobalPromiseAnyType || (deferredGlobalPromiseAnyType = createPromiseType(anyType)); - } - function getGlobalPromiseConstructorSymbol(reportErrors: boolean): Symbol | undefined { return deferredGlobalPromiseConstructorSymbol || (deferredGlobalPromiseConstructorSymbol = getGlobalValueSymbol("Promise", reportErrors)); } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index deb1ae90524..66731bfaf88 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1,4 +1,4 @@ -{ +{ "Unterminated string literal.": { "category": "Error", "code": 1002 @@ -3174,14 +3174,11 @@ "category": "Error", "code": 7034 }, - "Cannot resolve dynamic import, implicitly has a 'Promise' type.": { - "category": "Error", - "code": 7035 - }, "Dynamic import's specifier must be of type 'string', but here has type '{0}'.": { - "category": "Error", - "code": 7036 + "category": "Error", + "code": 7035 }, + "You cannot rename this element.": { "category": "Error", "code": 8000 diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionNoImplicitAnyError.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionNoImplicitAnyError.ts deleted file mode 100644 index 01f3b3c9281..00000000000 --- a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionNoImplicitAnyError.ts +++ /dev/null @@ -1,12 +0,0 @@ -// @module: es2018 -// @target: esnext -// @filename: 0.ts -// @noImplicitAny: true - -// @filename: 1.ts -declare function ValidSomeCondition(): boolean; -import(ValidSomeCondition() ? "./0" : "externalModule"); // implicit any error -var p1 = import(ValidSomeCondition() ? "./0" : "externalModule"); // implicit any error -p1.then(zero => { - return zero.foo(); // ok -}); \ No newline at end of file diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionReturnPromiseOfAny.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionReturnPromiseOfAny.ts index 235a76eb2f9..34f0b63be6f 100644 --- a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionReturnPromiseOfAny.ts +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionReturnPromiseOfAny.ts @@ -7,12 +7,15 @@ export class C {} // @filename: 1.ts import * as defaultModule from "./defaultPath"; declare function getSpecifier(): string; +declare function ValidSomeCondition(): boolean; declare var whatToLoad: boolean; declare const directory: string; declare const moduleFile: number; import(`${directory}\${moduleFile}`); import(getSpecifier()); + +var p1 = import(ValidSomeCondition() ? "./0" : "externalModule"); var p1: Promise = import(getSpecifier()); var p11: Promise = import(getSpecifier()); const p2 = import(whatToLoad ? getSpecifier() : "defaulPath") as Promise; From 32e5cf76af9aa34c525c8aafc3fcbe0fd68de270 Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Tue, 28 Mar 2017 13:27:33 -0700 Subject: [PATCH 39/67] Fix AMD emit --- src/compiler/transformers/module/module.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index d7f3a2ad743..7d26b27f0db 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -549,8 +549,8 @@ namespace ts { [createParameter(/*decorator*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, /*name*/ resolve)], /*type*/ undefined, createToken(SyntaxKind.EqualsGreaterThanToken), - createCall(createIdentifier("require"), /*typeArguments*/ undefined, node.arguments.concat([resolve])) - )]); + createCall(createIdentifier("require"), /*typeArguments*/ undefined, [createArrayLiteral(node.arguments), resolve])) + ]); } function transformImportCallExpressionCommonJS(node: ImportCall): Expression { From 249f446212c5fbceb9d0875327e74fd7f753bbcf Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Tue, 28 Mar 2017 13:31:40 -0700 Subject: [PATCH 40/67] Update tests --- .../importCallExpression2ES2018.ts | 1 - .../importCallExpressionCheckReturntype1.ts | 17 +++++++++++++++++ .../importCallExpressionDeclarationEmit2.ts | 1 - .../importCallExpressionDeclarationEmit3.ts | 15 +++++++++++++++ ... => importCallExpressionInScriptContext1.ts} | 0 ... => importCallExpressionInScriptContext2.ts} | 0 6 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 tests/cases/conformance/es2018/dynamicImport/importCallExpressionCheckReturntype1.ts create mode 100644 tests/cases/conformance/es2018/dynamicImport/importCallExpressionDeclarationEmit3.ts rename tests/cases/conformance/es2018/dynamicImport/{importCallExpressionAllowInScriptContext1.ts => importCallExpressionInScriptContext1.ts} (100%) rename tests/cases/conformance/es2018/dynamicImport/{importCallExpressionAllowInScriptContext2.ts => importCallExpressionInScriptContext2.ts} (100%) diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpression2ES2018.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpression2ES2018.ts index 3cb6fd7bc92..994e6f9e776 100644 --- a/tests/cases/conformance/es2018/dynamicImport/importCallExpression2ES2018.ts +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpression2ES2018.ts @@ -6,7 +6,6 @@ export class B { } // @filename: 2.ts -// We use Promise for now as there is no way to specify shape of module object function foo(x: Promise) { x.then(value => { let b = new value.B(); diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionCheckReturntype1.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionCheckReturntype1.ts new file mode 100644 index 00000000000..1218565fa54 --- /dev/null +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionCheckReturntype1.ts @@ -0,0 +1,17 @@ +// @module: commonjs +// @target: es6 +// @noImplicitAny: true + +// @filename: anotherModule.ts +export class D{} + +// @filename: defaultPath.ts +export class C {} + +// @filename: 1.ts +import * as defaultModule from "./defaultPath"; +import * as anotherModule from "./anotherModule"; + +let p1: Promise = import("./defaultPath"); +let p2 = import("./defaultPath") as Promise; +let p3: Promise = import("./defaultPath"); diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionDeclarationEmit2.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionDeclarationEmit2.ts index d1ee592a98a..7d9b5fec1d0 100644 --- a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionDeclarationEmit2.ts +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionDeclarationEmit2.ts @@ -6,5 +6,4 @@ export function foo() { return "foo"; } // @filename: 1.ts -import("./0"); var p1 = import("./0"); \ No newline at end of file diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionDeclarationEmit3.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionDeclarationEmit3.ts new file mode 100644 index 00000000000..cde7ad0a42f --- /dev/null +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionDeclarationEmit3.ts @@ -0,0 +1,15 @@ +// @module: es2018 +// @target: esnext +// @declaration: true + +// @filename: 0.ts +export function foo() { return "foo"; } + +// @filename: 1.ts +declare function getPath(): string; +import * as Zero from "./0"; +import("./0"); + +export var p0: Promise = import(getPath()); +export var p1: Promise = import("./0"); +export var p2: Promise = import("./0"); diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionAllowInScriptContext1.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInScriptContext1.ts similarity index 100% rename from tests/cases/conformance/es2018/dynamicImport/importCallExpressionAllowInScriptContext1.ts rename to tests/cases/conformance/es2018/dynamicImport/importCallExpressionInScriptContext1.ts diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionAllowInScriptContext2.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInScriptContext2.ts similarity index 100% rename from tests/cases/conformance/es2018/dynamicImport/importCallExpressionAllowInScriptContext2.ts rename to tests/cases/conformance/es2018/dynamicImport/importCallExpressionInScriptContext2.ts From f3306db91dd85a7e76ffc04291943857f5cac0ba Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Tue, 28 Mar 2017 13:31:50 -0700 Subject: [PATCH 41/67] Update baselines --- .../reference/importCallExpression1ES2018.js | 27 ++++ .../importCallExpression1ES2018.symbols | 28 +++++ .../importCallExpression1ES2018.types | 39 ++++++ .../reference/importCallExpression2ES2018.js | 29 +++++ .../importCallExpression2ES2018.symbols | 33 +++++ .../importCallExpression2ES2018.types | 45 +++++++ .../reference/importCallExpression4ES2018.js | 49 ++++++++ .../importCallExpression4ES2018.symbols | 61 +++++++++ .../importCallExpression4ES2018.types | 83 ++++++++++++ ...tCallExpressionCheckReturntype1.errors.txt | 31 +++++ .../importCallExpressionCheckReturntype1.js | 36 ++++++ .../importCallExpressionDeclarationEmit1.js | 37 ++++++ ...portCallExpressionDeclarationEmit1.symbols | 37 ++++++ ...importCallExpressionDeclarationEmit1.types | 48 +++++++ ...tCallExpressionDeclarationEmit2.errors.txt | 11 ++ .../importCallExpressionDeclarationEmit2.js | 17 +++ .../importCallExpressionDeclarationEmit3.js | 32 +++++ ...portCallExpressionDeclarationEmit3.symbols | 29 +++++ ...importCallExpressionDeclarationEmit3.types | 38 ++++++ ...portCallExpressionErrorInES2015.errors.txt | 24 ++++ .../importCallExpressionErrorInES2015.js | 27 ++++ ...mportCallExpressionGrammarError.errors.txt | 29 +++++ .../importCallExpressionGrammarError.js | 21 ++++ .../reference/importCallExpressionInAMD1.js | 35 ++++++ .../importCallExpressionInAMD1.symbols | 28 +++++ .../importCallExpressionInAMD1.types | 39 ++++++ .../reference/importCallExpressionInAMD2.js | 39 ++++++ .../importCallExpressionInAMD2.symbols | 34 +++++ .../importCallExpressionInAMD2.types | 46 +++++++ .../reference/importCallExpressionInAMD4.js | 63 ++++++++++ .../importCallExpressionInAMD4.symbols | 61 +++++++++ .../importCallExpressionInAMD4.types | 83 ++++++++++++ .../reference/importCallExpressionInCJS1.js | 31 +++++ .../importCallExpressionInCJS1.symbols | 28 +++++ .../importCallExpressionInCJS1.types | 39 ++++++ .../reference/importCallExpressionInCJS2.js | 41 ++++++ .../importCallExpressionInCJS2.symbols | 34 +++++ .../importCallExpressionInCJS2.types | 51 ++++++++ .../reference/importCallExpressionInCJS3.js | 35 ++++++ .../importCallExpressionInCJS3.symbols | 34 +++++ .../importCallExpressionInCJS3.types | 46 +++++++ .../reference/importCallExpressionInCJS5.js | 57 +++++++++ .../importCallExpressionInCJS5.symbols | 61 +++++++++ .../importCallExpressionInCJS5.types | 83 ++++++++++++ ...tCallExpressionInScriptContext2.errors.txt | 13 ++ .../importCallExpressionInScriptContext2.js | 20 +++ .../importCallExpressionInSystem1.js | 47 +++++++ .../importCallExpressionInSystem1.symbols | 28 +++++ .../importCallExpressionInSystem1.types | 39 ++++++ .../importCallExpressionInSystem2.js | 51 ++++++++ .../importCallExpressionInSystem2.symbols | 34 +++++ .../importCallExpressionInSystem2.types | 46 +++++++ .../importCallExpressionInSystem4.js | 81 ++++++++++++ .../importCallExpressionInSystem4.symbols | 61 +++++++++ .../importCallExpressionInSystem4.types | 83 ++++++++++++ .../reference/importCallExpressionInUMD1.js | 51 ++++++++ .../importCallExpressionInUMD1.symbols | 28 +++++ .../importCallExpressionInUMD1.types | 39 ++++++ .../reference/importCallExpressionInUMD2.js | 55 ++++++++ .../importCallExpressionInUMD2.symbols | 34 +++++ .../importCallExpressionInUMD2.types | 46 +++++++ .../reference/importCallExpressionInUMD4.js | 87 +++++++++++++ .../importCallExpressionInUMD4.symbols | 61 +++++++++ .../importCallExpressionInUMD4.types | 83 ++++++++++++ .../importCallExpressionReturnPromiseOfAny.js | 61 +++++++++ ...rtCallExpressionReturnPromiseOfAny.symbols | 89 +++++++++++++ ...portCallExpressionReturnPromiseOfAny.types | 118 ++++++++++++++++++ ...sionSpecifierNotStringTypeError.errors.txt | 32 +++++ ...llExpressionSpecifierNotStringTypeError.js | 27 ++++ ...tCallExpressionWithTypeArgument.errors.txt | 19 +++ .../importCallExpressionWithTypeArgument.js | 26 ++++ 71 files changed, 3138 insertions(+) create mode 100644 tests/baselines/reference/importCallExpression1ES2018.js create mode 100644 tests/baselines/reference/importCallExpression1ES2018.symbols create mode 100644 tests/baselines/reference/importCallExpression1ES2018.types create mode 100644 tests/baselines/reference/importCallExpression2ES2018.js create mode 100644 tests/baselines/reference/importCallExpression2ES2018.symbols create mode 100644 tests/baselines/reference/importCallExpression2ES2018.types create mode 100644 tests/baselines/reference/importCallExpression4ES2018.js create mode 100644 tests/baselines/reference/importCallExpression4ES2018.symbols create mode 100644 tests/baselines/reference/importCallExpression4ES2018.types create mode 100644 tests/baselines/reference/importCallExpressionCheckReturntype1.errors.txt create mode 100644 tests/baselines/reference/importCallExpressionCheckReturntype1.js create mode 100644 tests/baselines/reference/importCallExpressionDeclarationEmit1.js create mode 100644 tests/baselines/reference/importCallExpressionDeclarationEmit1.symbols create mode 100644 tests/baselines/reference/importCallExpressionDeclarationEmit1.types create mode 100644 tests/baselines/reference/importCallExpressionDeclarationEmit2.errors.txt create mode 100644 tests/baselines/reference/importCallExpressionDeclarationEmit2.js create mode 100644 tests/baselines/reference/importCallExpressionDeclarationEmit3.js create mode 100644 tests/baselines/reference/importCallExpressionDeclarationEmit3.symbols create mode 100644 tests/baselines/reference/importCallExpressionDeclarationEmit3.types create mode 100644 tests/baselines/reference/importCallExpressionErrorInES2015.errors.txt create mode 100644 tests/baselines/reference/importCallExpressionErrorInES2015.js create mode 100644 tests/baselines/reference/importCallExpressionGrammarError.errors.txt create mode 100644 tests/baselines/reference/importCallExpressionGrammarError.js create mode 100644 tests/baselines/reference/importCallExpressionInAMD1.js create mode 100644 tests/baselines/reference/importCallExpressionInAMD1.symbols create mode 100644 tests/baselines/reference/importCallExpressionInAMD1.types create mode 100644 tests/baselines/reference/importCallExpressionInAMD2.js create mode 100644 tests/baselines/reference/importCallExpressionInAMD2.symbols create mode 100644 tests/baselines/reference/importCallExpressionInAMD2.types create mode 100644 tests/baselines/reference/importCallExpressionInAMD4.js create mode 100644 tests/baselines/reference/importCallExpressionInAMD4.symbols create mode 100644 tests/baselines/reference/importCallExpressionInAMD4.types create mode 100644 tests/baselines/reference/importCallExpressionInCJS1.js create mode 100644 tests/baselines/reference/importCallExpressionInCJS1.symbols create mode 100644 tests/baselines/reference/importCallExpressionInCJS1.types create mode 100644 tests/baselines/reference/importCallExpressionInCJS2.js create mode 100644 tests/baselines/reference/importCallExpressionInCJS2.symbols create mode 100644 tests/baselines/reference/importCallExpressionInCJS2.types create mode 100644 tests/baselines/reference/importCallExpressionInCJS3.js create mode 100644 tests/baselines/reference/importCallExpressionInCJS3.symbols create mode 100644 tests/baselines/reference/importCallExpressionInCJS3.types create mode 100644 tests/baselines/reference/importCallExpressionInCJS5.js create mode 100644 tests/baselines/reference/importCallExpressionInCJS5.symbols create mode 100644 tests/baselines/reference/importCallExpressionInCJS5.types create mode 100644 tests/baselines/reference/importCallExpressionInScriptContext2.errors.txt create mode 100644 tests/baselines/reference/importCallExpressionInScriptContext2.js create mode 100644 tests/baselines/reference/importCallExpressionInSystem1.js create mode 100644 tests/baselines/reference/importCallExpressionInSystem1.symbols create mode 100644 tests/baselines/reference/importCallExpressionInSystem1.types create mode 100644 tests/baselines/reference/importCallExpressionInSystem2.js create mode 100644 tests/baselines/reference/importCallExpressionInSystem2.symbols create mode 100644 tests/baselines/reference/importCallExpressionInSystem2.types create mode 100644 tests/baselines/reference/importCallExpressionInSystem4.js create mode 100644 tests/baselines/reference/importCallExpressionInSystem4.symbols create mode 100644 tests/baselines/reference/importCallExpressionInSystem4.types create mode 100644 tests/baselines/reference/importCallExpressionInUMD1.js create mode 100644 tests/baselines/reference/importCallExpressionInUMD1.symbols create mode 100644 tests/baselines/reference/importCallExpressionInUMD1.types create mode 100644 tests/baselines/reference/importCallExpressionInUMD2.js create mode 100644 tests/baselines/reference/importCallExpressionInUMD2.symbols create mode 100644 tests/baselines/reference/importCallExpressionInUMD2.types create mode 100644 tests/baselines/reference/importCallExpressionInUMD4.js create mode 100644 tests/baselines/reference/importCallExpressionInUMD4.symbols create mode 100644 tests/baselines/reference/importCallExpressionInUMD4.types create mode 100644 tests/baselines/reference/importCallExpressionReturnPromiseOfAny.js create mode 100644 tests/baselines/reference/importCallExpressionReturnPromiseOfAny.symbols create mode 100644 tests/baselines/reference/importCallExpressionReturnPromiseOfAny.types create mode 100644 tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.errors.txt create mode 100644 tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.js create mode 100644 tests/baselines/reference/importCallExpressionWithTypeArgument.errors.txt create mode 100644 tests/baselines/reference/importCallExpressionWithTypeArgument.js diff --git a/tests/baselines/reference/importCallExpression1ES2018.js b/tests/baselines/reference/importCallExpression1ES2018.js new file mode 100644 index 00000000000..e98562ba360 --- /dev/null +++ b/tests/baselines/reference/importCallExpression1ES2018.js @@ -0,0 +1,27 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpression1ES2018.ts] //// + +//// [0.ts] +export function foo() { return "foo"; } + +//// [1.ts] +import("./0"); +var p1 = import("./0"); +p1.then(zero => { + return zero.foo(); +}) + +function foo() { + const p2 = import("./0"); +} + +//// [0.js] +export function foo() { return "foo"; } +//// [1.js] +import("./0"); +var p1 = import("./0"); +p1.then(zero => { + return zero.foo(); +}); +function foo() { + const p2 = import("./0"); +} diff --git a/tests/baselines/reference/importCallExpression1ES2018.symbols b/tests/baselines/reference/importCallExpression1ES2018.symbols new file mode 100644 index 00000000000..93f0d8f6deb --- /dev/null +++ b/tests/baselines/reference/importCallExpression1ES2018.symbols @@ -0,0 +1,28 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export function foo() { return "foo"; } +>foo : Symbol(foo, Decl(0.ts, 0, 0)) + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +import("./0"); +var p1 = import("./0"); +>p1 : Symbol(p1, Decl(1.ts, 1, 3)) + +p1.then(zero => { +>p1.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>p1 : Symbol(p1, Decl(1.ts, 1, 3)) +>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>zero : Symbol(zero, Decl(1.ts, 2, 8)) + + return zero.foo(); +>zero.foo : Symbol(foo, Decl(0.ts, 0, 0)) +>zero : Symbol(zero, Decl(1.ts, 2, 8)) +>foo : Symbol(foo, Decl(0.ts, 0, 0)) + +}) + +function foo() { +>foo : Symbol(foo, Decl(1.ts, 4, 2)) + + const p2 = import("./0"); +>p2 : Symbol(p2, Decl(1.ts, 7, 9)) +} diff --git a/tests/baselines/reference/importCallExpression1ES2018.types b/tests/baselines/reference/importCallExpression1ES2018.types new file mode 100644 index 00000000000..6d67b0f20b4 --- /dev/null +++ b/tests/baselines/reference/importCallExpression1ES2018.types @@ -0,0 +1,39 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export function foo() { return "foo"; } +>foo : () => string +>"foo" : "foo" + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +import("./0"); +>import("./0") : Promise +>"./0" : "./0" + +var p1 = import("./0"); +>p1 : Promise +>import("./0") : Promise +>"./0" : "./0" + +p1.then(zero => { +>p1.then(zero => { return zero.foo();}) : Promise +>p1.then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>p1 : Promise +>then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>zero => { return zero.foo();} : (zero: typeof "tests/cases/conformance/es2018/dynamicImport/0") => string +>zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" + + return zero.foo(); +>zero.foo() : string +>zero.foo : () => string +>zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>foo : () => string + +}) + +function foo() { +>foo : () => void + + const p2 = import("./0"); +>p2 : Promise +>import("./0") : Promise +>"./0" : "./0" +} diff --git a/tests/baselines/reference/importCallExpression2ES2018.js b/tests/baselines/reference/importCallExpression2ES2018.js new file mode 100644 index 00000000000..293fa4e49d2 --- /dev/null +++ b/tests/baselines/reference/importCallExpression2ES2018.js @@ -0,0 +1,29 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpression2ES2018.ts] //// + +//// [0.ts] +export class B { + print() { return "I am B"} +} + +//// [2.ts] +function foo(x: Promise) { + x.then(value => { + let b = new value.B(); + b.print(); + }) +} + +foo(import("./0")); + +//// [0.js] +export class B { + print() { return "I am B"; } +} +//// [2.js] +function foo(x) { + x.then(value => { + let b = new value.B(); + b.print(); + }); +} +foo(import("./0")); diff --git a/tests/baselines/reference/importCallExpression2ES2018.symbols b/tests/baselines/reference/importCallExpression2ES2018.symbols new file mode 100644 index 00000000000..4e8931cb729 --- /dev/null +++ b/tests/baselines/reference/importCallExpression2ES2018.symbols @@ -0,0 +1,33 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export class B { +>B : Symbol(B, Decl(0.ts, 0, 0)) + + print() { return "I am B"} +>print : Symbol(B.print, Decl(0.ts, 0, 16)) +} + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +function foo(x: Promise) { +>foo : Symbol(foo, Decl(2.ts, 0, 0)) +>x : Symbol(x, Decl(2.ts, 0, 13)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) + + x.then(value => { +>x.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(2.ts, 0, 13)) +>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>value : Symbol(value, Decl(2.ts, 1, 11)) + + let b = new value.B(); +>b : Symbol(b, Decl(2.ts, 2, 11)) +>value : Symbol(value, Decl(2.ts, 1, 11)) + + b.print(); +>b : Symbol(b, Decl(2.ts, 2, 11)) + + }) +} + +foo(import("./0")); +>foo : Symbol(foo, Decl(2.ts, 0, 0)) + diff --git a/tests/baselines/reference/importCallExpression2ES2018.types b/tests/baselines/reference/importCallExpression2ES2018.types new file mode 100644 index 00000000000..01e3c0d99bd --- /dev/null +++ b/tests/baselines/reference/importCallExpression2ES2018.types @@ -0,0 +1,45 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export class B { +>B : B + + print() { return "I am B"} +>print : () => string +>"I am B" : "I am B" +} + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +function foo(x: Promise) { +>foo : (x: Promise) => void +>x : Promise +>Promise : Promise + + x.then(value => { +>x.then(value => { let b = new value.B(); b.print(); }) : Promise +>x.then : (onfulfilled?: (value: any) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>x : Promise +>then : (onfulfilled?: (value: any) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>value => { let b = new value.B(); b.print(); } : (value: any) => void +>value : any + + let b = new value.B(); +>b : any +>new value.B() : any +>value.B : any +>value : any +>B : any + + b.print(); +>b.print() : any +>b.print : any +>b : any +>print : any + + }) +} + +foo(import("./0")); +>foo(import("./0")) : void +>foo : (x: Promise) => void +>import("./0") : Promise +>"./0" : "./0" + diff --git a/tests/baselines/reference/importCallExpression4ES2018.js b/tests/baselines/reference/importCallExpression4ES2018.js new file mode 100644 index 00000000000..a132bd8ac65 --- /dev/null +++ b/tests/baselines/reference/importCallExpression4ES2018.js @@ -0,0 +1,49 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpression4ES2018.ts] //// + +//// [0.ts] +export class B { + print() { return "I am B"} +} + +export function foo() { return "foo" } + +//// [1.ts] +export function backup() { return "backup"; } + +//// [2.ts] +declare var console: any; +class C { + private myModule = import("./0"); + method() { + this.myModule.then(Zero => { + console.log(Zero.foo()); + }, async err => { + console.log(err); + let one = await import("./1"); + console.log(one.backup()); + }); + } +} + +//// [0.js] +export class B { + print() { return "I am B"; } +} +export function foo() { return "foo"; } +//// [1.js] +export function backup() { return "backup"; } +//// [2.js] +class C { + constructor() { + this.myModule = import("./0"); + } + method() { + this.myModule.then(Zero => { + console.log(Zero.foo()); + }, async (err) => { + console.log(err); + let one = await import("./1"); + console.log(one.backup()); + }); + } +} diff --git a/tests/baselines/reference/importCallExpression4ES2018.symbols b/tests/baselines/reference/importCallExpression4ES2018.symbols new file mode 100644 index 00000000000..1d2a9aec25c --- /dev/null +++ b/tests/baselines/reference/importCallExpression4ES2018.symbols @@ -0,0 +1,61 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export class B { +>B : Symbol(B, Decl(0.ts, 0, 0)) + + print() { return "I am B"} +>print : Symbol(B.print, Decl(0.ts, 0, 16)) +} + +export function foo() { return "foo" } +>foo : Symbol(foo, Decl(0.ts, 2, 1)) + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +export function backup() { return "backup"; } +>backup : Symbol(backup, Decl(1.ts, 0, 0)) + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +declare var console: any; +>console : Symbol(console, Decl(2.ts, 0, 11)) + +class C { +>C : Symbol(C, Decl(2.ts, 0, 25)) + + private myModule = import("./0"); +>myModule : Symbol(C.myModule, Decl(2.ts, 1, 9)) + + method() { +>method : Symbol(C.method, Decl(2.ts, 2, 37)) + + this.myModule.then(Zero => { +>this.myModule.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>this.myModule : Symbol(C.myModule, Decl(2.ts, 1, 9)) +>this : Symbol(C, Decl(2.ts, 0, 25)) +>myModule : Symbol(C.myModule, Decl(2.ts, 1, 9)) +>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>Zero : Symbol(Zero, Decl(2.ts, 4, 27)) + + console.log(Zero.foo()); +>console : Symbol(console, Decl(2.ts, 0, 11)) +>Zero.foo : Symbol(foo, Decl(0.ts, 2, 1)) +>Zero : Symbol(Zero, Decl(2.ts, 4, 27)) +>foo : Symbol(foo, Decl(0.ts, 2, 1)) + + }, async err => { +>err : Symbol(err, Decl(2.ts, 6, 16)) + + console.log(err); +>console : Symbol(console, Decl(2.ts, 0, 11)) +>err : Symbol(err, Decl(2.ts, 6, 16)) + + let one = await import("./1"); +>one : Symbol(one, Decl(2.ts, 8, 15)) + + console.log(one.backup()); +>console : Symbol(console, Decl(2.ts, 0, 11)) +>one.backup : Symbol(backup, Decl(1.ts, 0, 0)) +>one : Symbol(one, Decl(2.ts, 8, 15)) +>backup : Symbol(backup, Decl(1.ts, 0, 0)) + + }); + } +} diff --git a/tests/baselines/reference/importCallExpression4ES2018.types b/tests/baselines/reference/importCallExpression4ES2018.types new file mode 100644 index 00000000000..6da36879f64 --- /dev/null +++ b/tests/baselines/reference/importCallExpression4ES2018.types @@ -0,0 +1,83 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export class B { +>B : B + + print() { return "I am B"} +>print : () => string +>"I am B" : "I am B" +} + +export function foo() { return "foo" } +>foo : () => string +>"foo" : "foo" + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +export function backup() { return "backup"; } +>backup : () => string +>"backup" : "backup" + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +declare var console: any; +>console : any + +class C { +>C : C + + private myModule = import("./0"); +>myModule : Promise +>import("./0") : Promise +>"./0" : "./0" + + method() { +>method : () => void + + this.myModule.then(Zero => { +>this.myModule.then(Zero => { console.log(Zero.foo()); }, async err => { console.log(err); let one = await import("./1"); console.log(one.backup()); }) : Promise +>this.myModule.then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>this.myModule : Promise +>this : this +>myModule : Promise +>then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>Zero => { console.log(Zero.foo()); } : (Zero: typeof "tests/cases/conformance/es2018/dynamicImport/0") => void +>Zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" + + console.log(Zero.foo()); +>console.log(Zero.foo()) : any +>console.log : any +>console : any +>log : any +>Zero.foo() : string +>Zero.foo : () => string +>Zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>foo : () => string + + }, async err => { +>async err => { console.log(err); let one = await import("./1"); console.log(one.backup()); } : (err: any) => Promise +>err : any + + console.log(err); +>console.log(err) : any +>console.log : any +>console : any +>log : any +>err : any + + let one = await import("./1"); +>one : typeof "tests/cases/conformance/es2018/dynamicImport/1" +>await import("./1") : typeof "tests/cases/conformance/es2018/dynamicImport/1" +>import("./1") : Promise +>"./1" : "./1" + + console.log(one.backup()); +>console.log(one.backup()) : any +>console.log : any +>console : any +>log : any +>one.backup() : string +>one.backup : () => string +>one : typeof "tests/cases/conformance/es2018/dynamicImport/1" +>backup : () => string + + }); + } +} diff --git a/tests/baselines/reference/importCallExpressionCheckReturntype1.errors.txt b/tests/baselines/reference/importCallExpressionCheckReturntype1.errors.txt new file mode 100644 index 00000000000..e5ea311f44c --- /dev/null +++ b/tests/baselines/reference/importCallExpressionCheckReturntype1.errors.txt @@ -0,0 +1,31 @@ +tests/cases/conformance/es2018/dynamicImport/1.ts(4,5): error TS2322: Type 'Promise' is not assignable to type 'Promise'. + Type 'typeof "tests/cases/conformance/es2018/dynamicImport/defaultPath"' is not assignable to type 'typeof "tests/cases/conformance/es2018/dynamicImport/anotherModule"'. + Property 'D' is missing in type 'typeof "tests/cases/conformance/es2018/dynamicImport/defaultPath"'. +tests/cases/conformance/es2018/dynamicImport/1.ts(5,10): error TS2352: Type 'Promise' cannot be converted to type 'Promise'. + Type 'typeof "tests/cases/conformance/es2018/dynamicImport/defaultPath"' is not comparable to type 'typeof "tests/cases/conformance/es2018/dynamicImport/anotherModule"'. + Property 'D' is missing in type 'typeof "tests/cases/conformance/es2018/dynamicImport/defaultPath"'. + + +==== tests/cases/conformance/es2018/dynamicImport/anotherModule.ts (0 errors) ==== + + export class D{} + +==== tests/cases/conformance/es2018/dynamicImport/defaultPath.ts (0 errors) ==== + export class C {} + +==== tests/cases/conformance/es2018/dynamicImport/1.ts (2 errors) ==== + import * as defaultModule from "./defaultPath"; + import * as anotherModule from "./anotherModule"; + + let p1: Promise = import("./defaultPath"); + ~~ +!!! error TS2322: Type 'Promise' is not assignable to type 'Promise'. +!!! error TS2322: Type 'typeof "tests/cases/conformance/es2018/dynamicImport/defaultPath"' is not assignable to type 'typeof "tests/cases/conformance/es2018/dynamicImport/anotherModule"'. +!!! error TS2322: Property 'D' is missing in type 'typeof "tests/cases/conformance/es2018/dynamicImport/defaultPath"'. + let p2 = import("./defaultPath") as Promise; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2352: Type 'Promise' cannot be converted to type 'Promise'. +!!! error TS2352: Type 'typeof "tests/cases/conformance/es2018/dynamicImport/defaultPath"' is not comparable to type 'typeof "tests/cases/conformance/es2018/dynamicImport/anotherModule"'. +!!! error TS2352: Property 'D' is missing in type 'typeof "tests/cases/conformance/es2018/dynamicImport/defaultPath"'. + let p3: Promise = import("./defaultPath"); + \ No newline at end of file diff --git a/tests/baselines/reference/importCallExpressionCheckReturntype1.js b/tests/baselines/reference/importCallExpressionCheckReturntype1.js new file mode 100644 index 00000000000..2ef1e729b84 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionCheckReturntype1.js @@ -0,0 +1,36 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionCheckReturntype1.ts] //// + +//// [anotherModule.ts] + +export class D{} + +//// [defaultPath.ts] +export class C {} + +//// [1.ts] +import * as defaultModule from "./defaultPath"; +import * as anotherModule from "./anotherModule"; + +let p1: Promise = import("./defaultPath"); +let p2 = import("./defaultPath") as Promise; +let p3: Promise = import("./defaultPath"); + + +//// [anotherModule.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +class D { +} +exports.D = D; +//// [defaultPath.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +class C { +} +exports.C = C; +//// [1.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +let p1 = Promise.resolve().then(() => require("./defaultPath")); +let p2 = Promise.resolve().then(() => require("./defaultPath")); +let p3 = Promise.resolve().then(() => require("./defaultPath")); diff --git a/tests/baselines/reference/importCallExpressionDeclarationEmit1.js b/tests/baselines/reference/importCallExpressionDeclarationEmit1.js new file mode 100644 index 00000000000..333bc8768be --- /dev/null +++ b/tests/baselines/reference/importCallExpressionDeclarationEmit1.js @@ -0,0 +1,37 @@ +//// [importCallExpressionDeclarationEmit1.ts] + +declare function getSpecifier(): string; +declare var whatToLoad: boolean; +declare const directory: string; +declare const moduleFile: number; + +import(getSpecifier()); + +var p0 = import(`${directory}\${moduleFile}`); +var p1 = import(getSpecifier()); +const p2 = import(whatToLoad ? getSpecifier() : "defaulPath") + +function returnDynamicLoad(path: string) { + return import(path); +} + +//// [importCallExpressionDeclarationEmit1.js] +"use strict"; +Promise.resolve().then(() => require(getSpecifier())); +var p0 = Promise.resolve().then(() => require(`${directory}\${moduleFile}`)); +var p1 = Promise.resolve().then(() => require(getSpecifier())); +const p2 = Promise.resolve().then(() => require(whatToLoad ? getSpecifier() : "defaulPath")); +function returnDynamicLoad(path) { + return Promise.resolve().then(() => require(path)); +} + + +//// [importCallExpressionDeclarationEmit1.d.ts] +declare function getSpecifier(): string; +declare var whatToLoad: boolean; +declare const directory: string; +declare const moduleFile: number; +declare var p0: Promise; +declare var p1: Promise; +declare const p2: Promise; +declare function returnDynamicLoad(path: string): Promise; diff --git a/tests/baselines/reference/importCallExpressionDeclarationEmit1.symbols b/tests/baselines/reference/importCallExpressionDeclarationEmit1.symbols new file mode 100644 index 00000000000..24fa2bc206d --- /dev/null +++ b/tests/baselines/reference/importCallExpressionDeclarationEmit1.symbols @@ -0,0 +1,37 @@ +=== tests/cases/conformance/es2018/dynamicImport/importCallExpressionDeclarationEmit1.ts === + +declare function getSpecifier(): string; +>getSpecifier : Symbol(getSpecifier, Decl(importCallExpressionDeclarationEmit1.ts, 0, 0)) + +declare var whatToLoad: boolean; +>whatToLoad : Symbol(whatToLoad, Decl(importCallExpressionDeclarationEmit1.ts, 2, 11)) + +declare const directory: string; +>directory : Symbol(directory, Decl(importCallExpressionDeclarationEmit1.ts, 3, 13)) + +declare const moduleFile: number; +>moduleFile : Symbol(moduleFile, Decl(importCallExpressionDeclarationEmit1.ts, 4, 13)) + +import(getSpecifier()); +>getSpecifier : Symbol(getSpecifier, Decl(importCallExpressionDeclarationEmit1.ts, 0, 0)) + +var p0 = import(`${directory}\${moduleFile}`); +>p0 : Symbol(p0, Decl(importCallExpressionDeclarationEmit1.ts, 8, 3)) +>directory : Symbol(directory, Decl(importCallExpressionDeclarationEmit1.ts, 3, 13)) + +var p1 = import(getSpecifier()); +>p1 : Symbol(p1, Decl(importCallExpressionDeclarationEmit1.ts, 9, 3)) +>getSpecifier : Symbol(getSpecifier, Decl(importCallExpressionDeclarationEmit1.ts, 0, 0)) + +const p2 = import(whatToLoad ? getSpecifier() : "defaulPath") +>p2 : Symbol(p2, Decl(importCallExpressionDeclarationEmit1.ts, 10, 5)) +>whatToLoad : Symbol(whatToLoad, Decl(importCallExpressionDeclarationEmit1.ts, 2, 11)) +>getSpecifier : Symbol(getSpecifier, Decl(importCallExpressionDeclarationEmit1.ts, 0, 0)) + +function returnDynamicLoad(path: string) { +>returnDynamicLoad : Symbol(returnDynamicLoad, Decl(importCallExpressionDeclarationEmit1.ts, 10, 61)) +>path : Symbol(path, Decl(importCallExpressionDeclarationEmit1.ts, 12, 27)) + + return import(path); +>path : Symbol(path, Decl(importCallExpressionDeclarationEmit1.ts, 12, 27)) +} diff --git a/tests/baselines/reference/importCallExpressionDeclarationEmit1.types b/tests/baselines/reference/importCallExpressionDeclarationEmit1.types new file mode 100644 index 00000000000..9aedf5fcc6a --- /dev/null +++ b/tests/baselines/reference/importCallExpressionDeclarationEmit1.types @@ -0,0 +1,48 @@ +=== tests/cases/conformance/es2018/dynamicImport/importCallExpressionDeclarationEmit1.ts === + +declare function getSpecifier(): string; +>getSpecifier : () => string + +declare var whatToLoad: boolean; +>whatToLoad : boolean + +declare const directory: string; +>directory : string + +declare const moduleFile: number; +>moduleFile : number + +import(getSpecifier()); +>import(getSpecifier()) : Promise +>getSpecifier() : string +>getSpecifier : () => string + +var p0 = import(`${directory}\${moduleFile}`); +>p0 : Promise +>import(`${directory}\${moduleFile}`) : Promise +>`${directory}\${moduleFile}` : string +>directory : string + +var p1 = import(getSpecifier()); +>p1 : Promise +>import(getSpecifier()) : Promise +>getSpecifier() : string +>getSpecifier : () => string + +const p2 = import(whatToLoad ? getSpecifier() : "defaulPath") +>p2 : Promise +>import(whatToLoad ? getSpecifier() : "defaulPath") : Promise +>whatToLoad ? getSpecifier() : "defaulPath" : string +>whatToLoad : boolean +>getSpecifier() : string +>getSpecifier : () => string +>"defaulPath" : "defaulPath" + +function returnDynamicLoad(path: string) { +>returnDynamicLoad : (path: string) => Promise +>path : string + + return import(path); +>import(path) : Promise +>path : string +} diff --git a/tests/baselines/reference/importCallExpressionDeclarationEmit2.errors.txt b/tests/baselines/reference/importCallExpressionDeclarationEmit2.errors.txt new file mode 100644 index 00000000000..908bfb6a409 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionDeclarationEmit2.errors.txt @@ -0,0 +1,11 @@ +tests/cases/conformance/es2018/dynamicImport/1.ts(1,5): error TS4023: Exported variable 'p1' has or is using name '"tests/cases/conformance/es2018/dynamicImport/0"' from external module "tests/cases/conformance/es2018/dynamicImport/0" but cannot be named. + + +==== tests/cases/conformance/es2018/dynamicImport/0.ts (0 errors) ==== + + export function foo() { return "foo"; } + +==== tests/cases/conformance/es2018/dynamicImport/1.ts (1 errors) ==== + var p1 = import("./0"); + ~~ +!!! error TS4023: Exported variable 'p1' has or is using name '"tests/cases/conformance/es2018/dynamicImport/0"' from external module "tests/cases/conformance/es2018/dynamicImport/0" but cannot be named. \ No newline at end of file diff --git a/tests/baselines/reference/importCallExpressionDeclarationEmit2.js b/tests/baselines/reference/importCallExpressionDeclarationEmit2.js new file mode 100644 index 00000000000..b2f2cac8c6d --- /dev/null +++ b/tests/baselines/reference/importCallExpressionDeclarationEmit2.js @@ -0,0 +1,17 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionDeclarationEmit2.ts] //// + +//// [0.ts] + +export function foo() { return "foo"; } + +//// [1.ts] +var p1 = import("./0"); + +//// [0.js] +export function foo() { return "foo"; } +//// [1.js] +var p1 = import("./0"); + + +//// [0.d.ts] +export declare function foo(): string; diff --git a/tests/baselines/reference/importCallExpressionDeclarationEmit3.js b/tests/baselines/reference/importCallExpressionDeclarationEmit3.js new file mode 100644 index 00000000000..42ae75acbb3 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionDeclarationEmit3.js @@ -0,0 +1,32 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionDeclarationEmit3.ts] //// + +//// [0.ts] + +export function foo() { return "foo"; } + +//// [1.ts] +declare function getPath(): string; +import * as Zero from "./0"; +import("./0"); + +export var p0: Promise = import(getPath()); +export var p1: Promise = import("./0"); +export var p2: Promise = import("./0"); + + +//// [0.js] +export function foo() { return "foo"; } +//// [1.js] +import("./0"); +export var p0 = import(getPath()); +export var p1 = import("./0"); +export var p2 = import("./0"); + + +//// [0.d.ts] +export declare function foo(): string; +//// [1.d.ts] +import * as Zero from "./0"; +export declare var p0: Promise; +export declare var p1: Promise; +export declare var p2: Promise; diff --git a/tests/baselines/reference/importCallExpressionDeclarationEmit3.symbols b/tests/baselines/reference/importCallExpressionDeclarationEmit3.symbols new file mode 100644 index 00000000000..6579d08ce34 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionDeclarationEmit3.symbols @@ -0,0 +1,29 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === + +export function foo() { return "foo"; } +>foo : Symbol(foo, Decl(0.ts, 0, 0)) + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +declare function getPath(): string; +>getPath : Symbol(getPath, Decl(1.ts, 0, 0)) + +import * as Zero from "./0"; +>Zero : Symbol(Zero, Decl(1.ts, 1, 6)) + +import("./0"); + +export var p0: Promise = import(getPath()); +>p0 : Symbol(p0, Decl(1.ts, 4, 10)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>Zero : Symbol(Zero, Decl(1.ts, 1, 6)) +>getPath : Symbol(getPath, Decl(1.ts, 0, 0)) + +export var p1: Promise = import("./0"); +>p1 : Symbol(p1, Decl(1.ts, 5, 10)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>Zero : Symbol(Zero, Decl(1.ts, 1, 6)) + +export var p2: Promise = import("./0"); +>p2 : Symbol(p2, Decl(1.ts, 6, 10)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) + diff --git a/tests/baselines/reference/importCallExpressionDeclarationEmit3.types b/tests/baselines/reference/importCallExpressionDeclarationEmit3.types new file mode 100644 index 00000000000..a03628e917a --- /dev/null +++ b/tests/baselines/reference/importCallExpressionDeclarationEmit3.types @@ -0,0 +1,38 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === + +export function foo() { return "foo"; } +>foo : () => string +>"foo" : "foo" + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +declare function getPath(): string; +>getPath : () => string + +import * as Zero from "./0"; +>Zero : typeof Zero + +import("./0"); +>import("./0") : Promise +>"./0" : "./0" + +export var p0: Promise = import(getPath()); +>p0 : Promise +>Promise : Promise +>Zero : typeof Zero +>import(getPath()) : Promise +>getPath() : string +>getPath : () => string + +export var p1: Promise = import("./0"); +>p1 : Promise +>Promise : Promise +>Zero : typeof Zero +>import("./0") : Promise +>"./0" : "./0" + +export var p2: Promise = import("./0"); +>p2 : Promise +>Promise : Promise +>import("./0") : Promise +>"./0" : "./0" + diff --git a/tests/baselines/reference/importCallExpressionErrorInES2015.errors.txt b/tests/baselines/reference/importCallExpressionErrorInES2015.errors.txt new file mode 100644 index 00000000000..ccd867f831c --- /dev/null +++ b/tests/baselines/reference/importCallExpressionErrorInES2015.errors.txt @@ -0,0 +1,24 @@ +tests/cases/conformance/es2018/dynamicImport/1.ts(1,1): error TS1320: Dynamic import cannot be used when targeting ECMAScript 2015 modules. +tests/cases/conformance/es2018/dynamicImport/1.ts(2,10): error TS1320: Dynamic import cannot be used when targeting ECMAScript 2015 modules. +tests/cases/conformance/es2018/dynamicImport/1.ts(8,16): error TS1320: Dynamic import cannot be used when targeting ECMAScript 2015 modules. + + +==== tests/cases/conformance/es2018/dynamicImport/0.ts (0 errors) ==== + export function foo() { return "foo"; } + +==== tests/cases/conformance/es2018/dynamicImport/1.ts (3 errors) ==== + import("./0"); + ~~~~~~~~~~~~~ +!!! error TS1320: Dynamic import cannot be used when targeting ECMAScript 2015 modules. + var p1 = import("./0"); + ~~~~~~~~~~~~~ +!!! error TS1320: Dynamic import cannot be used when targeting ECMAScript 2015 modules. + p1.then(zero => { + return zero.foo(); + }) + + function foo() { + const p2 = import("./0"); + ~~~~~~~~~~~~~ +!!! error TS1320: Dynamic import cannot be used when targeting ECMAScript 2015 modules. + } \ No newline at end of file diff --git a/tests/baselines/reference/importCallExpressionErrorInES2015.js b/tests/baselines/reference/importCallExpressionErrorInES2015.js new file mode 100644 index 00000000000..afe29bbe9ca --- /dev/null +++ b/tests/baselines/reference/importCallExpressionErrorInES2015.js @@ -0,0 +1,27 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionErrorInES2015.ts] //// + +//// [0.ts] +export function foo() { return "foo"; } + +//// [1.ts] +import("./0"); +var p1 = import("./0"); +p1.then(zero => { + return zero.foo(); +}) + +function foo() { + const p2 = import("./0"); +} + +//// [0.js] +export function foo() { return "foo"; } +//// [1.js] +import("./0"); +var p1 = import("./0"); +p1.then(zero => { + return zero.foo(); +}); +function foo() { + const p2 = import("./0"); +} diff --git a/tests/baselines/reference/importCallExpressionGrammarError.errors.txt b/tests/baselines/reference/importCallExpressionGrammarError.errors.txt new file mode 100644 index 00000000000..4d9c6829953 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionGrammarError.errors.txt @@ -0,0 +1,29 @@ +tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts(6,8): error TS1322: Specifier of dynamic import cannot be spread element. +tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts(8,17): error TS1322: Specifier of dynamic import cannot be spread element. +tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts(9,12): error TS1321: Dynamic import must have one specifier as an argument. +tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts(10,19): error TS1135: Argument expression expected. +tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts(11,12): error TS1321: Dynamic import must have one specifier as an argument. + + +==== tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts (5 errors) ==== + + declare function getSpecifier(): string; + declare var whatToLoad: boolean; + + var a = ["./0"]; + import(...["PathModule"]); + ~~~~~~~~~~~~~~~~~ +!!! error TS1322: Specifier of dynamic import cannot be spread element. + + var p1 = import(...a); + ~~~~ +!!! error TS1322: Specifier of dynamic import cannot be spread element. + const p2 = import(); + ~~~~~~~~ +!!! error TS1321: Dynamic import must have one specifier as an argument. + const p3 = import(,); + +!!! error TS1135: Argument expression expected. + const p4 = import("pathToModule", "secondModule"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1321: Dynamic import must have one specifier as an argument. \ No newline at end of file diff --git a/tests/baselines/reference/importCallExpressionGrammarError.js b/tests/baselines/reference/importCallExpressionGrammarError.js new file mode 100644 index 00000000000..6f31587a23d --- /dev/null +++ b/tests/baselines/reference/importCallExpressionGrammarError.js @@ -0,0 +1,21 @@ +//// [importCallExpressionGrammarError.ts] + +declare function getSpecifier(): string; +declare var whatToLoad: boolean; + +var a = ["./0"]; +import(...["PathModule"]); + +var p1 = import(...a); +const p2 = import(); +const p3 = import(,); +const p4 = import("pathToModule", "secondModule"); + +//// [importCallExpressionGrammarError.js] +"use strict"; +var a = ["./0"]; +Promise.resolve().then(() => require(...["PathModule"])); +var p1 = Promise.resolve().then(() => require(...a)); +const p2 = Promise.resolve().then(() => require()); +const p3 = Promise.resolve().then(() => require()); +const p4 = Promise.resolve().then(() => require("pathToModule", "secondModule")); diff --git a/tests/baselines/reference/importCallExpressionInAMD1.js b/tests/baselines/reference/importCallExpressionInAMD1.js new file mode 100644 index 00000000000..ed02c4893c3 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInAMD1.js @@ -0,0 +1,35 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInAMD1.ts] //// + +//// [0.ts] +export function foo() { return "foo"; } + +//// [1.ts] +import("./0"); +var p1 = import("./0"); +p1.then(zero => { + return zero.foo(); +}); + +function foo() { + const p2 = import("./0"); +} + +//// [0.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + function foo() { return "foo"; } + exports.foo = foo; +}); +//// [1.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + new Promise(resolve => require(["./0"], resolve)); + var p1 = new Promise(resolve => require(["./0"], resolve)); + p1.then(zero => { + return zero.foo(); + }); + function foo() { + const p2 = new Promise(resolve => require(["./0"], resolve)); + } +}); diff --git a/tests/baselines/reference/importCallExpressionInAMD1.symbols b/tests/baselines/reference/importCallExpressionInAMD1.symbols new file mode 100644 index 00000000000..15356c694ed --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInAMD1.symbols @@ -0,0 +1,28 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export function foo() { return "foo"; } +>foo : Symbol(foo, Decl(0.ts, 0, 0)) + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +import("./0"); +var p1 = import("./0"); +>p1 : Symbol(p1, Decl(1.ts, 1, 3)) + +p1.then(zero => { +>p1.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>p1 : Symbol(p1, Decl(1.ts, 1, 3)) +>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>zero : Symbol(zero, Decl(1.ts, 2, 8)) + + return zero.foo(); +>zero.foo : Symbol(foo, Decl(0.ts, 0, 0)) +>zero : Symbol(zero, Decl(1.ts, 2, 8)) +>foo : Symbol(foo, Decl(0.ts, 0, 0)) + +}); + +function foo() { +>foo : Symbol(foo, Decl(1.ts, 4, 3)) + + const p2 = import("./0"); +>p2 : Symbol(p2, Decl(1.ts, 7, 9)) +} diff --git a/tests/baselines/reference/importCallExpressionInAMD1.types b/tests/baselines/reference/importCallExpressionInAMD1.types new file mode 100644 index 00000000000..2733f3ff14a --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInAMD1.types @@ -0,0 +1,39 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export function foo() { return "foo"; } +>foo : () => string +>"foo" : "foo" + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +import("./0"); +>import("./0") : Promise +>"./0" : "./0" + +var p1 = import("./0"); +>p1 : Promise +>import("./0") : Promise +>"./0" : "./0" + +p1.then(zero => { +>p1.then(zero => { return zero.foo();}) : Promise +>p1.then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>p1 : Promise +>then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>zero => { return zero.foo();} : (zero: typeof "tests/cases/conformance/es2018/dynamicImport/0") => string +>zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" + + return zero.foo(); +>zero.foo() : string +>zero.foo : () => string +>zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>foo : () => string + +}); + +function foo() { +>foo : () => void + + const p2 = import("./0"); +>p2 : Promise +>import("./0") : Promise +>"./0" : "./0" +} diff --git a/tests/baselines/reference/importCallExpressionInAMD2.js b/tests/baselines/reference/importCallExpressionInAMD2.js new file mode 100644 index 00000000000..8f451643b5a --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInAMD2.js @@ -0,0 +1,39 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInAMD2.ts] //// + +//// [0.ts] +export class B { + print() { return "I am B"} +} + +//// [2.ts] +// We use Promise for now as there is no way to specify shape of module object +function foo(x: Promise) { + x.then(value => { + let b = new value.B(); + b.print(); + }) +} + +foo(import("./0")); + +//// [0.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + class B { + print() { return "I am B"; } + } + exports.B = B; +}); +//// [2.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + // We use Promise for now as there is no way to specify shape of module object + function foo(x) { + x.then(value => { + let b = new value.B(); + b.print(); + }); + } + foo(new Promise(resolve => require(["./0"], resolve))); +}); diff --git a/tests/baselines/reference/importCallExpressionInAMD2.symbols b/tests/baselines/reference/importCallExpressionInAMD2.symbols new file mode 100644 index 00000000000..7db47944520 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInAMD2.symbols @@ -0,0 +1,34 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export class B { +>B : Symbol(B, Decl(0.ts, 0, 0)) + + print() { return "I am B"} +>print : Symbol(B.print, Decl(0.ts, 0, 16)) +} + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +// We use Promise for now as there is no way to specify shape of module object +function foo(x: Promise) { +>foo : Symbol(foo, Decl(2.ts, 0, 0)) +>x : Symbol(x, Decl(2.ts, 1, 13)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) + + x.then(value => { +>x.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(2.ts, 1, 13)) +>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>value : Symbol(value, Decl(2.ts, 2, 11)) + + let b = new value.B(); +>b : Symbol(b, Decl(2.ts, 3, 11)) +>value : Symbol(value, Decl(2.ts, 2, 11)) + + b.print(); +>b : Symbol(b, Decl(2.ts, 3, 11)) + + }) +} + +foo(import("./0")); +>foo : Symbol(foo, Decl(2.ts, 0, 0)) + diff --git a/tests/baselines/reference/importCallExpressionInAMD2.types b/tests/baselines/reference/importCallExpressionInAMD2.types new file mode 100644 index 00000000000..2db06142911 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInAMD2.types @@ -0,0 +1,46 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export class B { +>B : B + + print() { return "I am B"} +>print : () => string +>"I am B" : "I am B" +} + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +// We use Promise for now as there is no way to specify shape of module object +function foo(x: Promise) { +>foo : (x: Promise) => void +>x : Promise +>Promise : Promise + + x.then(value => { +>x.then(value => { let b = new value.B(); b.print(); }) : Promise +>x.then : (onfulfilled?: (value: any) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>x : Promise +>then : (onfulfilled?: (value: any) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>value => { let b = new value.B(); b.print(); } : (value: any) => void +>value : any + + let b = new value.B(); +>b : any +>new value.B() : any +>value.B : any +>value : any +>B : any + + b.print(); +>b.print() : any +>b.print : any +>b : any +>print : any + + }) +} + +foo(import("./0")); +>foo(import("./0")) : void +>foo : (x: Promise) => void +>import("./0") : Promise +>"./0" : "./0" + diff --git a/tests/baselines/reference/importCallExpressionInAMD4.js b/tests/baselines/reference/importCallExpressionInAMD4.js new file mode 100644 index 00000000000..796e1a7996e --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInAMD4.js @@ -0,0 +1,63 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInAMD4.ts] //// + +//// [0.ts] +export class B { + print() { return "I am B"} +} + +export function foo() { return "foo" } + +//// [1.ts] +export function backup() { return "backup"; } + +//// [2.ts] +declare var console: any; +class C { + private myModule = import("./0"); + method() { + this.myModule.then(Zero => { + console.log(Zero.foo()); + }, async err => { + console.log(err); + let one = await import("./1"); + console.log(one.backup()); + }); + } +} + +//// [0.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + class B { + print() { return "I am B"; } + } + exports.B = B; + function foo() { return "foo"; } + exports.foo = foo; +}); +//// [1.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + function backup() { return "backup"; } + exports.backup = backup; +}); +//// [2.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + class C { + constructor() { + this.myModule = new Promise(resolve => require(["./0"], resolve)); + } + method() { + this.myModule.then(Zero => { + console.log(Zero.foo()); + }, async (err) => { + console.log(err); + let one = await new Promise(resolve => require(["./1"], resolve)); + console.log(one.backup()); + }); + } + } +}); diff --git a/tests/baselines/reference/importCallExpressionInAMD4.symbols b/tests/baselines/reference/importCallExpressionInAMD4.symbols new file mode 100644 index 00000000000..1d2a9aec25c --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInAMD4.symbols @@ -0,0 +1,61 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export class B { +>B : Symbol(B, Decl(0.ts, 0, 0)) + + print() { return "I am B"} +>print : Symbol(B.print, Decl(0.ts, 0, 16)) +} + +export function foo() { return "foo" } +>foo : Symbol(foo, Decl(0.ts, 2, 1)) + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +export function backup() { return "backup"; } +>backup : Symbol(backup, Decl(1.ts, 0, 0)) + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +declare var console: any; +>console : Symbol(console, Decl(2.ts, 0, 11)) + +class C { +>C : Symbol(C, Decl(2.ts, 0, 25)) + + private myModule = import("./0"); +>myModule : Symbol(C.myModule, Decl(2.ts, 1, 9)) + + method() { +>method : Symbol(C.method, Decl(2.ts, 2, 37)) + + this.myModule.then(Zero => { +>this.myModule.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>this.myModule : Symbol(C.myModule, Decl(2.ts, 1, 9)) +>this : Symbol(C, Decl(2.ts, 0, 25)) +>myModule : Symbol(C.myModule, Decl(2.ts, 1, 9)) +>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>Zero : Symbol(Zero, Decl(2.ts, 4, 27)) + + console.log(Zero.foo()); +>console : Symbol(console, Decl(2.ts, 0, 11)) +>Zero.foo : Symbol(foo, Decl(0.ts, 2, 1)) +>Zero : Symbol(Zero, Decl(2.ts, 4, 27)) +>foo : Symbol(foo, Decl(0.ts, 2, 1)) + + }, async err => { +>err : Symbol(err, Decl(2.ts, 6, 16)) + + console.log(err); +>console : Symbol(console, Decl(2.ts, 0, 11)) +>err : Symbol(err, Decl(2.ts, 6, 16)) + + let one = await import("./1"); +>one : Symbol(one, Decl(2.ts, 8, 15)) + + console.log(one.backup()); +>console : Symbol(console, Decl(2.ts, 0, 11)) +>one.backup : Symbol(backup, Decl(1.ts, 0, 0)) +>one : Symbol(one, Decl(2.ts, 8, 15)) +>backup : Symbol(backup, Decl(1.ts, 0, 0)) + + }); + } +} diff --git a/tests/baselines/reference/importCallExpressionInAMD4.types b/tests/baselines/reference/importCallExpressionInAMD4.types new file mode 100644 index 00000000000..6da36879f64 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInAMD4.types @@ -0,0 +1,83 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export class B { +>B : B + + print() { return "I am B"} +>print : () => string +>"I am B" : "I am B" +} + +export function foo() { return "foo" } +>foo : () => string +>"foo" : "foo" + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +export function backup() { return "backup"; } +>backup : () => string +>"backup" : "backup" + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +declare var console: any; +>console : any + +class C { +>C : C + + private myModule = import("./0"); +>myModule : Promise +>import("./0") : Promise +>"./0" : "./0" + + method() { +>method : () => void + + this.myModule.then(Zero => { +>this.myModule.then(Zero => { console.log(Zero.foo()); }, async err => { console.log(err); let one = await import("./1"); console.log(one.backup()); }) : Promise +>this.myModule.then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>this.myModule : Promise +>this : this +>myModule : Promise +>then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>Zero => { console.log(Zero.foo()); } : (Zero: typeof "tests/cases/conformance/es2018/dynamicImport/0") => void +>Zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" + + console.log(Zero.foo()); +>console.log(Zero.foo()) : any +>console.log : any +>console : any +>log : any +>Zero.foo() : string +>Zero.foo : () => string +>Zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>foo : () => string + + }, async err => { +>async err => { console.log(err); let one = await import("./1"); console.log(one.backup()); } : (err: any) => Promise +>err : any + + console.log(err); +>console.log(err) : any +>console.log : any +>console : any +>log : any +>err : any + + let one = await import("./1"); +>one : typeof "tests/cases/conformance/es2018/dynamicImport/1" +>await import("./1") : typeof "tests/cases/conformance/es2018/dynamicImport/1" +>import("./1") : Promise +>"./1" : "./1" + + console.log(one.backup()); +>console.log(one.backup()) : any +>console.log : any +>console : any +>log : any +>one.backup() : string +>one.backup : () => string +>one : typeof "tests/cases/conformance/es2018/dynamicImport/1" +>backup : () => string + + }); + } +} diff --git a/tests/baselines/reference/importCallExpressionInCJS1.js b/tests/baselines/reference/importCallExpressionInCJS1.js new file mode 100644 index 00000000000..e9a5ffa3656 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInCJS1.js @@ -0,0 +1,31 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInCJS1.ts] //// + +//// [0.ts] +export function foo() { return "foo"; } + +//// [1.ts] +import("./0"); +var p1 = import("./0"); +p1.then(zero => { + return zero.foo(); +}); + +function foo() { + const p2 = import("./0"); +} + +//// [0.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +function foo() { return "foo"; } +exports.foo = foo; +//// [1.js] +"use strict"; +Promise.resolve().then(() => require("./0")); +var p1 = Promise.resolve().then(() => require("./0")); +p1.then(zero => { + return zero.foo(); +}); +function foo() { + const p2 = Promise.resolve().then(() => require("./0")); +} diff --git a/tests/baselines/reference/importCallExpressionInCJS1.symbols b/tests/baselines/reference/importCallExpressionInCJS1.symbols new file mode 100644 index 00000000000..15356c694ed --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInCJS1.symbols @@ -0,0 +1,28 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export function foo() { return "foo"; } +>foo : Symbol(foo, Decl(0.ts, 0, 0)) + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +import("./0"); +var p1 = import("./0"); +>p1 : Symbol(p1, Decl(1.ts, 1, 3)) + +p1.then(zero => { +>p1.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>p1 : Symbol(p1, Decl(1.ts, 1, 3)) +>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>zero : Symbol(zero, Decl(1.ts, 2, 8)) + + return zero.foo(); +>zero.foo : Symbol(foo, Decl(0.ts, 0, 0)) +>zero : Symbol(zero, Decl(1.ts, 2, 8)) +>foo : Symbol(foo, Decl(0.ts, 0, 0)) + +}); + +function foo() { +>foo : Symbol(foo, Decl(1.ts, 4, 3)) + + const p2 = import("./0"); +>p2 : Symbol(p2, Decl(1.ts, 7, 9)) +} diff --git a/tests/baselines/reference/importCallExpressionInCJS1.types b/tests/baselines/reference/importCallExpressionInCJS1.types new file mode 100644 index 00000000000..2733f3ff14a --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInCJS1.types @@ -0,0 +1,39 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export function foo() { return "foo"; } +>foo : () => string +>"foo" : "foo" + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +import("./0"); +>import("./0") : Promise +>"./0" : "./0" + +var p1 = import("./0"); +>p1 : Promise +>import("./0") : Promise +>"./0" : "./0" + +p1.then(zero => { +>p1.then(zero => { return zero.foo();}) : Promise +>p1.then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>p1 : Promise +>then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>zero => { return zero.foo();} : (zero: typeof "tests/cases/conformance/es2018/dynamicImport/0") => string +>zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" + + return zero.foo(); +>zero.foo() : string +>zero.foo : () => string +>zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>foo : () => string + +}); + +function foo() { +>foo : () => void + + const p2 = import("./0"); +>p2 : Promise +>import("./0") : Promise +>"./0" : "./0" +} diff --git a/tests/baselines/reference/importCallExpressionInCJS2.js b/tests/baselines/reference/importCallExpressionInCJS2.js new file mode 100644 index 00000000000..7430541b51e --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInCJS2.js @@ -0,0 +1,41 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInCJS2.ts] //// + +//// [0.ts] +export function foo() { return "foo"; } + +//// [1.ts] +export function backup() { return "backup"; } + +//// [2.ts] +async function compute(promise: Promise) { + let j = await promise; + if (!j) { + j = await import("./1"); + return j.backup(); + } + return j.foo(); +} + +compute(import("./0")); + +//// [0.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +function foo() { return "foo"; } +exports.foo = foo; +//// [1.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +function backup() { return "backup"; } +exports.backup = backup; +//// [2.js] +"use strict"; +async function compute(promise) { + let j = await promise; + if (!j) { + j = await Promise.resolve().then(() => require("./1")); + return j.backup(); + } + return j.foo(); +} +compute(Promise.resolve().then(() => require("./0"))); diff --git a/tests/baselines/reference/importCallExpressionInCJS2.symbols b/tests/baselines/reference/importCallExpressionInCJS2.symbols new file mode 100644 index 00000000000..8a62908868c --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInCJS2.symbols @@ -0,0 +1,34 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export function foo() { return "foo"; } +>foo : Symbol(foo, Decl(0.ts, 0, 0)) + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +export function backup() { return "backup"; } +>backup : Symbol(backup, Decl(1.ts, 0, 0)) + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +async function compute(promise: Promise) { +>compute : Symbol(compute, Decl(2.ts, 0, 0)) +>promise : Symbol(promise, Decl(2.ts, 0, 23)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) + + let j = await promise; +>j : Symbol(j, Decl(2.ts, 1, 7)) +>promise : Symbol(promise, Decl(2.ts, 0, 23)) + + if (!j) { +>j : Symbol(j, Decl(2.ts, 1, 7)) + + j = await import("./1"); +>j : Symbol(j, Decl(2.ts, 1, 7)) + + return j.backup(); +>j : Symbol(j, Decl(2.ts, 1, 7)) + } + return j.foo(); +>j : Symbol(j, Decl(2.ts, 1, 7)) +} + +compute(import("./0")); +>compute : Symbol(compute, Decl(2.ts, 0, 0)) + diff --git a/tests/baselines/reference/importCallExpressionInCJS2.types b/tests/baselines/reference/importCallExpressionInCJS2.types new file mode 100644 index 00000000000..88317f387fe --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInCJS2.types @@ -0,0 +1,51 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export function foo() { return "foo"; } +>foo : () => string +>"foo" : "foo" + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +export function backup() { return "backup"; } +>backup : () => string +>"backup" : "backup" + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +async function compute(promise: Promise) { +>compute : (promise: Promise) => Promise +>promise : Promise +>Promise : Promise + + let j = await promise; +>j : any +>await promise : any +>promise : Promise + + if (!j) { +>!j : boolean +>j : any + + j = await import("./1"); +>j = await import("./1") : typeof "tests/cases/conformance/es2018/dynamicImport/1" +>j : any +>await import("./1") : typeof "tests/cases/conformance/es2018/dynamicImport/1" +>import("./1") : Promise +>"./1" : "./1" + + return j.backup(); +>j.backup() : any +>j.backup : any +>j : any +>backup : any + } + return j.foo(); +>j.foo() : any +>j.foo : any +>j : any +>foo : any +} + +compute(import("./0")); +>compute(import("./0")) : Promise +>compute : (promise: Promise) => Promise +>import("./0") : Promise +>"./0" : "./0" + diff --git a/tests/baselines/reference/importCallExpressionInCJS3.js b/tests/baselines/reference/importCallExpressionInCJS3.js new file mode 100644 index 00000000000..264888091ab --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInCJS3.js @@ -0,0 +1,35 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInCJS3.ts] //// + +//// [0.ts] +export class B { + print() { return "I am B"} +} + +//// [2.ts] +// We use Promise for now as there is no way to specify shape of module object +function foo(x: Promise) { + x.then(value => { + let b = new value.B(); + b.print(); + }) +} + +foo(import("./0")); + +//// [0.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +class B { + print() { return "I am B"; } +} +exports.B = B; +//// [2.js] +"use strict"; +// We use Promise for now as there is no way to specify shape of module object +function foo(x) { + x.then(value => { + let b = new value.B(); + b.print(); + }); +} +foo(Promise.resolve().then(() => require("./0"))); diff --git a/tests/baselines/reference/importCallExpressionInCJS3.symbols b/tests/baselines/reference/importCallExpressionInCJS3.symbols new file mode 100644 index 00000000000..7db47944520 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInCJS3.symbols @@ -0,0 +1,34 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export class B { +>B : Symbol(B, Decl(0.ts, 0, 0)) + + print() { return "I am B"} +>print : Symbol(B.print, Decl(0.ts, 0, 16)) +} + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +// We use Promise for now as there is no way to specify shape of module object +function foo(x: Promise) { +>foo : Symbol(foo, Decl(2.ts, 0, 0)) +>x : Symbol(x, Decl(2.ts, 1, 13)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) + + x.then(value => { +>x.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(2.ts, 1, 13)) +>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>value : Symbol(value, Decl(2.ts, 2, 11)) + + let b = new value.B(); +>b : Symbol(b, Decl(2.ts, 3, 11)) +>value : Symbol(value, Decl(2.ts, 2, 11)) + + b.print(); +>b : Symbol(b, Decl(2.ts, 3, 11)) + + }) +} + +foo(import("./0")); +>foo : Symbol(foo, Decl(2.ts, 0, 0)) + diff --git a/tests/baselines/reference/importCallExpressionInCJS3.types b/tests/baselines/reference/importCallExpressionInCJS3.types new file mode 100644 index 00000000000..2db06142911 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInCJS3.types @@ -0,0 +1,46 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export class B { +>B : B + + print() { return "I am B"} +>print : () => string +>"I am B" : "I am B" +} + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +// We use Promise for now as there is no way to specify shape of module object +function foo(x: Promise) { +>foo : (x: Promise) => void +>x : Promise +>Promise : Promise + + x.then(value => { +>x.then(value => { let b = new value.B(); b.print(); }) : Promise +>x.then : (onfulfilled?: (value: any) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>x : Promise +>then : (onfulfilled?: (value: any) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>value => { let b = new value.B(); b.print(); } : (value: any) => void +>value : any + + let b = new value.B(); +>b : any +>new value.B() : any +>value.B : any +>value : any +>B : any + + b.print(); +>b.print() : any +>b.print : any +>b : any +>print : any + + }) +} + +foo(import("./0")); +>foo(import("./0")) : void +>foo : (x: Promise) => void +>import("./0") : Promise +>"./0" : "./0" + diff --git a/tests/baselines/reference/importCallExpressionInCJS5.js b/tests/baselines/reference/importCallExpressionInCJS5.js new file mode 100644 index 00000000000..82845416b45 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInCJS5.js @@ -0,0 +1,57 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInCJS5.ts] //// + +//// [0.ts] +export class B { + print() { return "I am B"} +} + +export function foo() { return "foo" } + +//// [1.ts] +export function backup() { return "backup"; } + +//// [2.ts] +declare var console: any; +class C { + private myModule = import("./0"); + method() { + this.myModule.then(Zero => { + console.log(Zero.foo()); + }, async err => { + console.log(err); + let one = await import("./1"); + console.log(one.backup()); + }); + } +} + +//// [0.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +class B { + print() { return "I am B"; } +} +exports.B = B; +function foo() { return "foo"; } +exports.foo = foo; +//// [1.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +function backup() { return "backup"; } +exports.backup = backup; +//// [2.js] +"use strict"; +class C { + constructor() { + this.myModule = Promise.resolve().then(() => require("./0")); + } + method() { + this.myModule.then(Zero => { + console.log(Zero.foo()); + }, async (err) => { + console.log(err); + let one = await Promise.resolve().then(() => require("./1")); + console.log(one.backup()); + }); + } +} diff --git a/tests/baselines/reference/importCallExpressionInCJS5.symbols b/tests/baselines/reference/importCallExpressionInCJS5.symbols new file mode 100644 index 00000000000..1d2a9aec25c --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInCJS5.symbols @@ -0,0 +1,61 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export class B { +>B : Symbol(B, Decl(0.ts, 0, 0)) + + print() { return "I am B"} +>print : Symbol(B.print, Decl(0.ts, 0, 16)) +} + +export function foo() { return "foo" } +>foo : Symbol(foo, Decl(0.ts, 2, 1)) + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +export function backup() { return "backup"; } +>backup : Symbol(backup, Decl(1.ts, 0, 0)) + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +declare var console: any; +>console : Symbol(console, Decl(2.ts, 0, 11)) + +class C { +>C : Symbol(C, Decl(2.ts, 0, 25)) + + private myModule = import("./0"); +>myModule : Symbol(C.myModule, Decl(2.ts, 1, 9)) + + method() { +>method : Symbol(C.method, Decl(2.ts, 2, 37)) + + this.myModule.then(Zero => { +>this.myModule.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>this.myModule : Symbol(C.myModule, Decl(2.ts, 1, 9)) +>this : Symbol(C, Decl(2.ts, 0, 25)) +>myModule : Symbol(C.myModule, Decl(2.ts, 1, 9)) +>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>Zero : Symbol(Zero, Decl(2.ts, 4, 27)) + + console.log(Zero.foo()); +>console : Symbol(console, Decl(2.ts, 0, 11)) +>Zero.foo : Symbol(foo, Decl(0.ts, 2, 1)) +>Zero : Symbol(Zero, Decl(2.ts, 4, 27)) +>foo : Symbol(foo, Decl(0.ts, 2, 1)) + + }, async err => { +>err : Symbol(err, Decl(2.ts, 6, 16)) + + console.log(err); +>console : Symbol(console, Decl(2.ts, 0, 11)) +>err : Symbol(err, Decl(2.ts, 6, 16)) + + let one = await import("./1"); +>one : Symbol(one, Decl(2.ts, 8, 15)) + + console.log(one.backup()); +>console : Symbol(console, Decl(2.ts, 0, 11)) +>one.backup : Symbol(backup, Decl(1.ts, 0, 0)) +>one : Symbol(one, Decl(2.ts, 8, 15)) +>backup : Symbol(backup, Decl(1.ts, 0, 0)) + + }); + } +} diff --git a/tests/baselines/reference/importCallExpressionInCJS5.types b/tests/baselines/reference/importCallExpressionInCJS5.types new file mode 100644 index 00000000000..6da36879f64 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInCJS5.types @@ -0,0 +1,83 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export class B { +>B : B + + print() { return "I am B"} +>print : () => string +>"I am B" : "I am B" +} + +export function foo() { return "foo" } +>foo : () => string +>"foo" : "foo" + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +export function backup() { return "backup"; } +>backup : () => string +>"backup" : "backup" + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +declare var console: any; +>console : any + +class C { +>C : C + + private myModule = import("./0"); +>myModule : Promise +>import("./0") : Promise +>"./0" : "./0" + + method() { +>method : () => void + + this.myModule.then(Zero => { +>this.myModule.then(Zero => { console.log(Zero.foo()); }, async err => { console.log(err); let one = await import("./1"); console.log(one.backup()); }) : Promise +>this.myModule.then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>this.myModule : Promise +>this : this +>myModule : Promise +>then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>Zero => { console.log(Zero.foo()); } : (Zero: typeof "tests/cases/conformance/es2018/dynamicImport/0") => void +>Zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" + + console.log(Zero.foo()); +>console.log(Zero.foo()) : any +>console.log : any +>console : any +>log : any +>Zero.foo() : string +>Zero.foo : () => string +>Zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>foo : () => string + + }, async err => { +>async err => { console.log(err); let one = await import("./1"); console.log(one.backup()); } : (err: any) => Promise +>err : any + + console.log(err); +>console.log(err) : any +>console.log : any +>console : any +>log : any +>err : any + + let one = await import("./1"); +>one : typeof "tests/cases/conformance/es2018/dynamicImport/1" +>await import("./1") : typeof "tests/cases/conformance/es2018/dynamicImport/1" +>import("./1") : Promise +>"./1" : "./1" + + console.log(one.backup()); +>console.log(one.backup()) : any +>console.log : any +>console : any +>log : any +>one.backup() : string +>one.backup : () => string +>one : typeof "tests/cases/conformance/es2018/dynamicImport/1" +>backup : () => string + + }); + } +} diff --git a/tests/baselines/reference/importCallExpressionInScriptContext2.errors.txt b/tests/baselines/reference/importCallExpressionInScriptContext2.errors.txt new file mode 100644 index 00000000000..b7645851b28 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInScriptContext2.errors.txt @@ -0,0 +1,13 @@ +tests/cases/conformance/es2018/dynamicImport/1.ts(3,10): error TS1100: Invalid use of 'arguments' in strict mode. + + +==== tests/cases/conformance/es2018/dynamicImport/0.ts (0 errors) ==== + + export function foo() { return "foo"; } + +==== tests/cases/conformance/es2018/dynamicImport/1.ts (1 errors) ==== + "use strict" + var p1 = import("./0"); + function arguments() { } + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. \ No newline at end of file diff --git a/tests/baselines/reference/importCallExpressionInScriptContext2.js b/tests/baselines/reference/importCallExpressionInScriptContext2.js new file mode 100644 index 00000000000..b278a60b6bb --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInScriptContext2.js @@ -0,0 +1,20 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInScriptContext2.ts] //// + +//// [0.ts] + +export function foo() { return "foo"; } + +//// [1.ts] +"use strict" +var p1 = import("./0"); +function arguments() { } + +//// [0.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +function foo() { return "foo"; } +exports.foo = foo; +//// [1.js] +"use strict"; +var p1 = Promise.resolve().then(() => require("./0")); +function arguments() { } diff --git a/tests/baselines/reference/importCallExpressionInSystem1.js b/tests/baselines/reference/importCallExpressionInSystem1.js new file mode 100644 index 00000000000..1a146b02fcd --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInSystem1.js @@ -0,0 +1,47 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInSystem1.ts] //// + +//// [0.ts] +export function foo() { return "foo"; } + +//// [1.ts] +import("./0"); +var p1 = import("./0"); +p1.then(zero => { + return zero.foo(); +}); + +function foo() { + const p2 = import("./0"); +} + +//// [0.js] +System.register([], function (exports_1, context_1) { + "use strict"; + var __moduleName = context_1 && context_1.id; + function foo() { return "foo"; } + exports_1("foo", foo); + return { + setters: [], + execute: function () { + } + }; +}); +//// [1.js] +System.register([], function (exports_1, context_1) { + "use strict"; + var __moduleName = context_1 && context_1.id; + function foo() { + const p2 = context_1.import("./0"); + } + var p1; + return { + setters: [], + execute: function () { + context_1.import("./0"); + p1 = context_1.import("./0"); + p1.then(zero => { + return zero.foo(); + }); + } + }; +}); diff --git a/tests/baselines/reference/importCallExpressionInSystem1.symbols b/tests/baselines/reference/importCallExpressionInSystem1.symbols new file mode 100644 index 00000000000..15356c694ed --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInSystem1.symbols @@ -0,0 +1,28 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export function foo() { return "foo"; } +>foo : Symbol(foo, Decl(0.ts, 0, 0)) + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +import("./0"); +var p1 = import("./0"); +>p1 : Symbol(p1, Decl(1.ts, 1, 3)) + +p1.then(zero => { +>p1.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>p1 : Symbol(p1, Decl(1.ts, 1, 3)) +>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>zero : Symbol(zero, Decl(1.ts, 2, 8)) + + return zero.foo(); +>zero.foo : Symbol(foo, Decl(0.ts, 0, 0)) +>zero : Symbol(zero, Decl(1.ts, 2, 8)) +>foo : Symbol(foo, Decl(0.ts, 0, 0)) + +}); + +function foo() { +>foo : Symbol(foo, Decl(1.ts, 4, 3)) + + const p2 = import("./0"); +>p2 : Symbol(p2, Decl(1.ts, 7, 9)) +} diff --git a/tests/baselines/reference/importCallExpressionInSystem1.types b/tests/baselines/reference/importCallExpressionInSystem1.types new file mode 100644 index 00000000000..2733f3ff14a --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInSystem1.types @@ -0,0 +1,39 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export function foo() { return "foo"; } +>foo : () => string +>"foo" : "foo" + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +import("./0"); +>import("./0") : Promise +>"./0" : "./0" + +var p1 = import("./0"); +>p1 : Promise +>import("./0") : Promise +>"./0" : "./0" + +p1.then(zero => { +>p1.then(zero => { return zero.foo();}) : Promise +>p1.then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>p1 : Promise +>then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>zero => { return zero.foo();} : (zero: typeof "tests/cases/conformance/es2018/dynamicImport/0") => string +>zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" + + return zero.foo(); +>zero.foo() : string +>zero.foo : () => string +>zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>foo : () => string + +}); + +function foo() { +>foo : () => void + + const p2 = import("./0"); +>p2 : Promise +>import("./0") : Promise +>"./0" : "./0" +} diff --git a/tests/baselines/reference/importCallExpressionInSystem2.js b/tests/baselines/reference/importCallExpressionInSystem2.js new file mode 100644 index 00000000000..198f4c4c7a2 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInSystem2.js @@ -0,0 +1,51 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInSystem2.ts] //// + +//// [0.ts] +export class B { + print() { return "I am B"} +} + +//// [2.ts] +// We use Promise for now as there is no way to specify shape of module object +function foo(x: Promise) { + x.then(value => { + let b = new value.B(); + b.print(); + }) +} + +foo(import("./0")); + +//// [0.js] +System.register([], function (exports_1, context_1) { + "use strict"; + var __moduleName = context_1 && context_1.id; + var B; + return { + setters: [], + execute: function () { + B = class B { + print() { return "I am B"; } + }; + exports_1("B", B); + } + }; +}); +//// [2.js] +System.register([], function (exports_1, context_1) { + "use strict"; + var __moduleName = context_1 && context_1.id; + // We use Promise for now as there is no way to specify shape of module object + function foo(x) { + x.then(value => { + let b = new value.B(); + b.print(); + }); + } + return { + setters: [], + execute: function () { + foo(context_1.import("./0")); + } + }; +}); diff --git a/tests/baselines/reference/importCallExpressionInSystem2.symbols b/tests/baselines/reference/importCallExpressionInSystem2.symbols new file mode 100644 index 00000000000..7db47944520 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInSystem2.symbols @@ -0,0 +1,34 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export class B { +>B : Symbol(B, Decl(0.ts, 0, 0)) + + print() { return "I am B"} +>print : Symbol(B.print, Decl(0.ts, 0, 16)) +} + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +// We use Promise for now as there is no way to specify shape of module object +function foo(x: Promise) { +>foo : Symbol(foo, Decl(2.ts, 0, 0)) +>x : Symbol(x, Decl(2.ts, 1, 13)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) + + x.then(value => { +>x.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(2.ts, 1, 13)) +>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>value : Symbol(value, Decl(2.ts, 2, 11)) + + let b = new value.B(); +>b : Symbol(b, Decl(2.ts, 3, 11)) +>value : Symbol(value, Decl(2.ts, 2, 11)) + + b.print(); +>b : Symbol(b, Decl(2.ts, 3, 11)) + + }) +} + +foo(import("./0")); +>foo : Symbol(foo, Decl(2.ts, 0, 0)) + diff --git a/tests/baselines/reference/importCallExpressionInSystem2.types b/tests/baselines/reference/importCallExpressionInSystem2.types new file mode 100644 index 00000000000..2db06142911 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInSystem2.types @@ -0,0 +1,46 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export class B { +>B : B + + print() { return "I am B"} +>print : () => string +>"I am B" : "I am B" +} + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +// We use Promise for now as there is no way to specify shape of module object +function foo(x: Promise) { +>foo : (x: Promise) => void +>x : Promise +>Promise : Promise + + x.then(value => { +>x.then(value => { let b = new value.B(); b.print(); }) : Promise +>x.then : (onfulfilled?: (value: any) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>x : Promise +>then : (onfulfilled?: (value: any) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>value => { let b = new value.B(); b.print(); } : (value: any) => void +>value : any + + let b = new value.B(); +>b : any +>new value.B() : any +>value.B : any +>value : any +>B : any + + b.print(); +>b.print() : any +>b.print : any +>b : any +>print : any + + }) +} + +foo(import("./0")); +>foo(import("./0")) : void +>foo : (x: Promise) => void +>import("./0") : Promise +>"./0" : "./0" + diff --git a/tests/baselines/reference/importCallExpressionInSystem4.js b/tests/baselines/reference/importCallExpressionInSystem4.js new file mode 100644 index 00000000000..e3a938b826e --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInSystem4.js @@ -0,0 +1,81 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInSystem4.ts] //// + +//// [0.ts] +export class B { + print() { return "I am B"} +} + +export function foo() { return "foo" } + +//// [1.ts] +export function backup() { return "backup"; } + +//// [2.ts] +declare var console: any; +class C { + private myModule = import("./0"); + method() { + this.myModule.then(Zero => { + console.log(Zero.foo()); + }, async err => { + console.log(err); + let one = await import("./1"); + console.log(one.backup()); + }); + } +} + +//// [0.js] +System.register([], function (exports_1, context_1) { + "use strict"; + var __moduleName = context_1 && context_1.id; + function foo() { return "foo"; } + exports_1("foo", foo); + var B; + return { + setters: [], + execute: function () { + B = class B { + print() { return "I am B"; } + }; + exports_1("B", B); + } + }; +}); +//// [1.js] +System.register([], function (exports_1, context_1) { + "use strict"; + var __moduleName = context_1 && context_1.id; + function backup() { return "backup"; } + exports_1("backup", backup); + return { + setters: [], + execute: function () { + } + }; +}); +//// [2.js] +System.register([], function (exports_1, context_1) { + "use strict"; + var __moduleName = context_1 && context_1.id; + var C; + return { + setters: [], + execute: function () { + C = class C { + constructor() { + this.myModule = context_1.import("./0"); + } + method() { + this.myModule.then(Zero => { + console.log(Zero.foo()); + }, async (err) => { + console.log(err); + let one = await context_1.import("./1"); + console.log(one.backup()); + }); + } + }; + } + }; +}); diff --git a/tests/baselines/reference/importCallExpressionInSystem4.symbols b/tests/baselines/reference/importCallExpressionInSystem4.symbols new file mode 100644 index 00000000000..1d2a9aec25c --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInSystem4.symbols @@ -0,0 +1,61 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export class B { +>B : Symbol(B, Decl(0.ts, 0, 0)) + + print() { return "I am B"} +>print : Symbol(B.print, Decl(0.ts, 0, 16)) +} + +export function foo() { return "foo" } +>foo : Symbol(foo, Decl(0.ts, 2, 1)) + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +export function backup() { return "backup"; } +>backup : Symbol(backup, Decl(1.ts, 0, 0)) + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +declare var console: any; +>console : Symbol(console, Decl(2.ts, 0, 11)) + +class C { +>C : Symbol(C, Decl(2.ts, 0, 25)) + + private myModule = import("./0"); +>myModule : Symbol(C.myModule, Decl(2.ts, 1, 9)) + + method() { +>method : Symbol(C.method, Decl(2.ts, 2, 37)) + + this.myModule.then(Zero => { +>this.myModule.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>this.myModule : Symbol(C.myModule, Decl(2.ts, 1, 9)) +>this : Symbol(C, Decl(2.ts, 0, 25)) +>myModule : Symbol(C.myModule, Decl(2.ts, 1, 9)) +>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>Zero : Symbol(Zero, Decl(2.ts, 4, 27)) + + console.log(Zero.foo()); +>console : Symbol(console, Decl(2.ts, 0, 11)) +>Zero.foo : Symbol(foo, Decl(0.ts, 2, 1)) +>Zero : Symbol(Zero, Decl(2.ts, 4, 27)) +>foo : Symbol(foo, Decl(0.ts, 2, 1)) + + }, async err => { +>err : Symbol(err, Decl(2.ts, 6, 16)) + + console.log(err); +>console : Symbol(console, Decl(2.ts, 0, 11)) +>err : Symbol(err, Decl(2.ts, 6, 16)) + + let one = await import("./1"); +>one : Symbol(one, Decl(2.ts, 8, 15)) + + console.log(one.backup()); +>console : Symbol(console, Decl(2.ts, 0, 11)) +>one.backup : Symbol(backup, Decl(1.ts, 0, 0)) +>one : Symbol(one, Decl(2.ts, 8, 15)) +>backup : Symbol(backup, Decl(1.ts, 0, 0)) + + }); + } +} diff --git a/tests/baselines/reference/importCallExpressionInSystem4.types b/tests/baselines/reference/importCallExpressionInSystem4.types new file mode 100644 index 00000000000..6da36879f64 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInSystem4.types @@ -0,0 +1,83 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export class B { +>B : B + + print() { return "I am B"} +>print : () => string +>"I am B" : "I am B" +} + +export function foo() { return "foo" } +>foo : () => string +>"foo" : "foo" + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +export function backup() { return "backup"; } +>backup : () => string +>"backup" : "backup" + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +declare var console: any; +>console : any + +class C { +>C : C + + private myModule = import("./0"); +>myModule : Promise +>import("./0") : Promise +>"./0" : "./0" + + method() { +>method : () => void + + this.myModule.then(Zero => { +>this.myModule.then(Zero => { console.log(Zero.foo()); }, async err => { console.log(err); let one = await import("./1"); console.log(one.backup()); }) : Promise +>this.myModule.then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>this.myModule : Promise +>this : this +>myModule : Promise +>then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>Zero => { console.log(Zero.foo()); } : (Zero: typeof "tests/cases/conformance/es2018/dynamicImport/0") => void +>Zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" + + console.log(Zero.foo()); +>console.log(Zero.foo()) : any +>console.log : any +>console : any +>log : any +>Zero.foo() : string +>Zero.foo : () => string +>Zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>foo : () => string + + }, async err => { +>async err => { console.log(err); let one = await import("./1"); console.log(one.backup()); } : (err: any) => Promise +>err : any + + console.log(err); +>console.log(err) : any +>console.log : any +>console : any +>log : any +>err : any + + let one = await import("./1"); +>one : typeof "tests/cases/conformance/es2018/dynamicImport/1" +>await import("./1") : typeof "tests/cases/conformance/es2018/dynamicImport/1" +>import("./1") : Promise +>"./1" : "./1" + + console.log(one.backup()); +>console.log(one.backup()) : any +>console.log : any +>console : any +>log : any +>one.backup() : string +>one.backup : () => string +>one : typeof "tests/cases/conformance/es2018/dynamicImport/1" +>backup : () => string + + }); + } +} diff --git a/tests/baselines/reference/importCallExpressionInUMD1.js b/tests/baselines/reference/importCallExpressionInUMD1.js new file mode 100644 index 00000000000..16668df030f --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInUMD1.js @@ -0,0 +1,51 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInUMD1.ts] //// + +//// [0.ts] +export function foo() { return "foo"; } + +//// [1.ts] +import("./0"); +var p1 = import("./0"); +p1.then(zero => { + return zero.foo(); +}); + +function foo() { + const p2 = import("./0"); +} + +//// [0.js] +(function (factory) { + if (typeof module === "object" && typeof module.exports === "object") { + var v = factory(require, exports); + if (v !== undefined) module.exports = v; + } + else if (typeof define === "function" && define.amd) { + define(["require", "exports"], factory); + } +})(function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + function foo() { return "foo"; } + exports.foo = foo; +}); +//// [1.js] +(function (factory) { + if (typeof module === "object" && typeof module.exports === "object") { + var v = factory(require, exports); + if (v !== undefined) module.exports = v; + } + else if (typeof define === "function" && define.amd) { + define(["require", "exports"], factory); + } +})(function (require, exports) { + "use strict"; + require.length === 1 ? Promise.resolve().then(() => require("./0")) : new Promise(resolve => require(["./0"], resolve)); + var p1 = require.length === 1 ? Promise.resolve().then(() => require("./0")) : new Promise(resolve => require(["./0"], resolve)); + p1.then(zero => { + return zero.foo(); + }); + function foo() { + const p2 = require.length === 1 ? Promise.resolve().then(() => require("./0")) : new Promise(resolve => require(["./0"], resolve)); + } +}); diff --git a/tests/baselines/reference/importCallExpressionInUMD1.symbols b/tests/baselines/reference/importCallExpressionInUMD1.symbols new file mode 100644 index 00000000000..15356c694ed --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInUMD1.symbols @@ -0,0 +1,28 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export function foo() { return "foo"; } +>foo : Symbol(foo, Decl(0.ts, 0, 0)) + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +import("./0"); +var p1 = import("./0"); +>p1 : Symbol(p1, Decl(1.ts, 1, 3)) + +p1.then(zero => { +>p1.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>p1 : Symbol(p1, Decl(1.ts, 1, 3)) +>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>zero : Symbol(zero, Decl(1.ts, 2, 8)) + + return zero.foo(); +>zero.foo : Symbol(foo, Decl(0.ts, 0, 0)) +>zero : Symbol(zero, Decl(1.ts, 2, 8)) +>foo : Symbol(foo, Decl(0.ts, 0, 0)) + +}); + +function foo() { +>foo : Symbol(foo, Decl(1.ts, 4, 3)) + + const p2 = import("./0"); +>p2 : Symbol(p2, Decl(1.ts, 7, 9)) +} diff --git a/tests/baselines/reference/importCallExpressionInUMD1.types b/tests/baselines/reference/importCallExpressionInUMD1.types new file mode 100644 index 00000000000..2733f3ff14a --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInUMD1.types @@ -0,0 +1,39 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export function foo() { return "foo"; } +>foo : () => string +>"foo" : "foo" + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +import("./0"); +>import("./0") : Promise +>"./0" : "./0" + +var p1 = import("./0"); +>p1 : Promise +>import("./0") : Promise +>"./0" : "./0" + +p1.then(zero => { +>p1.then(zero => { return zero.foo();}) : Promise +>p1.then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>p1 : Promise +>then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>zero => { return zero.foo();} : (zero: typeof "tests/cases/conformance/es2018/dynamicImport/0") => string +>zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" + + return zero.foo(); +>zero.foo() : string +>zero.foo : () => string +>zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>foo : () => string + +}); + +function foo() { +>foo : () => void + + const p2 = import("./0"); +>p2 : Promise +>import("./0") : Promise +>"./0" : "./0" +} diff --git a/tests/baselines/reference/importCallExpressionInUMD2.js b/tests/baselines/reference/importCallExpressionInUMD2.js new file mode 100644 index 00000000000..ebaeca6311a --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInUMD2.js @@ -0,0 +1,55 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInUMD2.ts] //// + +//// [0.ts] +export class B { + print() { return "I am B"} +} + +//// [2.ts] +// We use Promise for now as there is no way to specify shape of module object +function foo(x: Promise) { + x.then(value => { + let b = new value.B(); + b.print(); + }) +} + +foo(import("./0")); + +//// [0.js] +(function (factory) { + if (typeof module === "object" && typeof module.exports === "object") { + var v = factory(require, exports); + if (v !== undefined) module.exports = v; + } + else if (typeof define === "function" && define.amd) { + define(["require", "exports"], factory); + } +})(function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + class B { + print() { return "I am B"; } + } + exports.B = B; +}); +//// [2.js] +(function (factory) { + if (typeof module === "object" && typeof module.exports === "object") { + var v = factory(require, exports); + if (v !== undefined) module.exports = v; + } + else if (typeof define === "function" && define.amd) { + define(["require", "exports"], factory); + } +})(function (require, exports) { + "use strict"; + // We use Promise for now as there is no way to specify shape of module object + function foo(x) { + x.then(value => { + let b = new value.B(); + b.print(); + }); + } + foo(require.length === 1 ? Promise.resolve().then(() => require("./0")) : new Promise(resolve => require(["./0"], resolve))); +}); diff --git a/tests/baselines/reference/importCallExpressionInUMD2.symbols b/tests/baselines/reference/importCallExpressionInUMD2.symbols new file mode 100644 index 00000000000..7db47944520 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInUMD2.symbols @@ -0,0 +1,34 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export class B { +>B : Symbol(B, Decl(0.ts, 0, 0)) + + print() { return "I am B"} +>print : Symbol(B.print, Decl(0.ts, 0, 16)) +} + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +// We use Promise for now as there is no way to specify shape of module object +function foo(x: Promise) { +>foo : Symbol(foo, Decl(2.ts, 0, 0)) +>x : Symbol(x, Decl(2.ts, 1, 13)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) + + x.then(value => { +>x.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(2.ts, 1, 13)) +>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>value : Symbol(value, Decl(2.ts, 2, 11)) + + let b = new value.B(); +>b : Symbol(b, Decl(2.ts, 3, 11)) +>value : Symbol(value, Decl(2.ts, 2, 11)) + + b.print(); +>b : Symbol(b, Decl(2.ts, 3, 11)) + + }) +} + +foo(import("./0")); +>foo : Symbol(foo, Decl(2.ts, 0, 0)) + diff --git a/tests/baselines/reference/importCallExpressionInUMD2.types b/tests/baselines/reference/importCallExpressionInUMD2.types new file mode 100644 index 00000000000..2db06142911 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInUMD2.types @@ -0,0 +1,46 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export class B { +>B : B + + print() { return "I am B"} +>print : () => string +>"I am B" : "I am B" +} + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +// We use Promise for now as there is no way to specify shape of module object +function foo(x: Promise) { +>foo : (x: Promise) => void +>x : Promise +>Promise : Promise + + x.then(value => { +>x.then(value => { let b = new value.B(); b.print(); }) : Promise +>x.then : (onfulfilled?: (value: any) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>x : Promise +>then : (onfulfilled?: (value: any) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>value => { let b = new value.B(); b.print(); } : (value: any) => void +>value : any + + let b = new value.B(); +>b : any +>new value.B() : any +>value.B : any +>value : any +>B : any + + b.print(); +>b.print() : any +>b.print : any +>b : any +>print : any + + }) +} + +foo(import("./0")); +>foo(import("./0")) : void +>foo : (x: Promise) => void +>import("./0") : Promise +>"./0" : "./0" + diff --git a/tests/baselines/reference/importCallExpressionInUMD4.js b/tests/baselines/reference/importCallExpressionInUMD4.js new file mode 100644 index 00000000000..ac36081a536 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInUMD4.js @@ -0,0 +1,87 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInUMD4.ts] //// + +//// [0.ts] +export class B { + print() { return "I am B"} +} + +export function foo() { return "foo" } + +//// [1.ts] +export function backup() { return "backup"; } + +//// [2.ts] +declare var console: any; +class C { + private myModule = import("./0"); + method() { + this.myModule.then(Zero => { + console.log(Zero.foo()); + }, async err => { + console.log(err); + let one = await import("./1"); + console.log(one.backup()); + }); + } +} + +//// [0.js] +(function (factory) { + if (typeof module === "object" && typeof module.exports === "object") { + var v = factory(require, exports); + if (v !== undefined) module.exports = v; + } + else if (typeof define === "function" && define.amd) { + define(["require", "exports"], factory); + } +})(function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + class B { + print() { return "I am B"; } + } + exports.B = B; + function foo() { return "foo"; } + exports.foo = foo; +}); +//// [1.js] +(function (factory) { + if (typeof module === "object" && typeof module.exports === "object") { + var v = factory(require, exports); + if (v !== undefined) module.exports = v; + } + else if (typeof define === "function" && define.amd) { + define(["require", "exports"], factory); + } +})(function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + function backup() { return "backup"; } + exports.backup = backup; +}); +//// [2.js] +(function (factory) { + if (typeof module === "object" && typeof module.exports === "object") { + var v = factory(require, exports); + if (v !== undefined) module.exports = v; + } + else if (typeof define === "function" && define.amd) { + define(["require", "exports"], factory); + } +})(function (require, exports) { + "use strict"; + class C { + constructor() { + this.myModule = require.length === 1 ? Promise.resolve().then(() => require("./0")) : new Promise(resolve => require(["./0"], resolve)); + } + method() { + this.myModule.then(Zero => { + console.log(Zero.foo()); + }, async (err) => { + console.log(err); + let one = await (require.length === 1 ? Promise.resolve().then(() => require("./1")) : new Promise(resolve => require(["./1"], resolve))); + console.log(one.backup()); + }); + } + } +}); diff --git a/tests/baselines/reference/importCallExpressionInUMD4.symbols b/tests/baselines/reference/importCallExpressionInUMD4.symbols new file mode 100644 index 00000000000..1d2a9aec25c --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInUMD4.symbols @@ -0,0 +1,61 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export class B { +>B : Symbol(B, Decl(0.ts, 0, 0)) + + print() { return "I am B"} +>print : Symbol(B.print, Decl(0.ts, 0, 16)) +} + +export function foo() { return "foo" } +>foo : Symbol(foo, Decl(0.ts, 2, 1)) + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +export function backup() { return "backup"; } +>backup : Symbol(backup, Decl(1.ts, 0, 0)) + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +declare var console: any; +>console : Symbol(console, Decl(2.ts, 0, 11)) + +class C { +>C : Symbol(C, Decl(2.ts, 0, 25)) + + private myModule = import("./0"); +>myModule : Symbol(C.myModule, Decl(2.ts, 1, 9)) + + method() { +>method : Symbol(C.method, Decl(2.ts, 2, 37)) + + this.myModule.then(Zero => { +>this.myModule.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>this.myModule : Symbol(C.myModule, Decl(2.ts, 1, 9)) +>this : Symbol(C, Decl(2.ts, 0, 25)) +>myModule : Symbol(C.myModule, Decl(2.ts, 1, 9)) +>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>Zero : Symbol(Zero, Decl(2.ts, 4, 27)) + + console.log(Zero.foo()); +>console : Symbol(console, Decl(2.ts, 0, 11)) +>Zero.foo : Symbol(foo, Decl(0.ts, 2, 1)) +>Zero : Symbol(Zero, Decl(2.ts, 4, 27)) +>foo : Symbol(foo, Decl(0.ts, 2, 1)) + + }, async err => { +>err : Symbol(err, Decl(2.ts, 6, 16)) + + console.log(err); +>console : Symbol(console, Decl(2.ts, 0, 11)) +>err : Symbol(err, Decl(2.ts, 6, 16)) + + let one = await import("./1"); +>one : Symbol(one, Decl(2.ts, 8, 15)) + + console.log(one.backup()); +>console : Symbol(console, Decl(2.ts, 0, 11)) +>one.backup : Symbol(backup, Decl(1.ts, 0, 0)) +>one : Symbol(one, Decl(2.ts, 8, 15)) +>backup : Symbol(backup, Decl(1.ts, 0, 0)) + + }); + } +} diff --git a/tests/baselines/reference/importCallExpressionInUMD4.types b/tests/baselines/reference/importCallExpressionInUMD4.types new file mode 100644 index 00000000000..6da36879f64 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInUMD4.types @@ -0,0 +1,83 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export class B { +>B : B + + print() { return "I am B"} +>print : () => string +>"I am B" : "I am B" +} + +export function foo() { return "foo" } +>foo : () => string +>"foo" : "foo" + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +export function backup() { return "backup"; } +>backup : () => string +>"backup" : "backup" + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +declare var console: any; +>console : any + +class C { +>C : C + + private myModule = import("./0"); +>myModule : Promise +>import("./0") : Promise +>"./0" : "./0" + + method() { +>method : () => void + + this.myModule.then(Zero => { +>this.myModule.then(Zero => { console.log(Zero.foo()); }, async err => { console.log(err); let one = await import("./1"); console.log(one.backup()); }) : Promise +>this.myModule.then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>this.myModule : Promise +>this : this +>myModule : Promise +>then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>Zero => { console.log(Zero.foo()); } : (Zero: typeof "tests/cases/conformance/es2018/dynamicImport/0") => void +>Zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" + + console.log(Zero.foo()); +>console.log(Zero.foo()) : any +>console.log : any +>console : any +>log : any +>Zero.foo() : string +>Zero.foo : () => string +>Zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>foo : () => string + + }, async err => { +>async err => { console.log(err); let one = await import("./1"); console.log(one.backup()); } : (err: any) => Promise +>err : any + + console.log(err); +>console.log(err) : any +>console.log : any +>console : any +>log : any +>err : any + + let one = await import("./1"); +>one : typeof "tests/cases/conformance/es2018/dynamicImport/1" +>await import("./1") : typeof "tests/cases/conformance/es2018/dynamicImport/1" +>import("./1") : Promise +>"./1" : "./1" + + console.log(one.backup()); +>console.log(one.backup()) : any +>console.log : any +>console : any +>log : any +>one.backup() : string +>one.backup : () => string +>one : typeof "tests/cases/conformance/es2018/dynamicImport/1" +>backup : () => string + + }); + } +} diff --git a/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.js b/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.js new file mode 100644 index 00000000000..0ba536b4c39 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.js @@ -0,0 +1,61 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionReturnPromiseOfAny.ts] //// + +//// [defaultPath.ts] +export class C {} + +//// [1.ts] +import * as defaultModule from "./defaultPath"; +declare function getSpecifier(): string; +declare function ValidSomeCondition(): boolean; +declare var whatToLoad: boolean; +declare const directory: string; +declare const moduleFile: number; + +import(`${directory}\${moduleFile}`); +import(getSpecifier()); + +var p1 = import(ValidSomeCondition() ? "./0" : "externalModule"); +var p1: Promise = import(getSpecifier()); +var p11: Promise = import(getSpecifier()); +const p2 = import(whatToLoad ? getSpecifier() : "defaulPath") as Promise; +p1.then(zero => { + return zero.foo(); // ok, zero is any +}); + +let j: string; +var p3: Promise = import(j=getSpecifier()); + +function * loadModule(directories: string[]) { + for (const directory of directories) { + const path = `${directory}\moduleFile`; + import(yield path); + } +} + + +//// [defaultPath.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +class C { +} +exports.C = C; +//// [1.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +Promise.resolve().then(() => require(`${directory}\${moduleFile}`)); +Promise.resolve().then(() => require(getSpecifier())); +var p1 = Promise.resolve().then(() => require(ValidSomeCondition() ? "./0" : "externalModule")); +var p1 = Promise.resolve().then(() => require(getSpecifier())); +var p11 = Promise.resolve().then(() => require(getSpecifier())); +const p2 = Promise.resolve().then(() => require(whatToLoad ? getSpecifier() : "defaulPath")); +p1.then(zero => { + return zero.foo(); // ok, zero is any +}); +let j; +var p3 = Promise.resolve().then(() => require(j = getSpecifier())); +function* loadModule(directories) { + for (const directory of directories) { + const path = `${directory}\moduleFile`; + Promise.resolve().then(() => require(yield path)); + } +} diff --git a/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.symbols b/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.symbols new file mode 100644 index 00000000000..275bedd4c93 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.symbols @@ -0,0 +1,89 @@ +=== tests/cases/conformance/es2018/dynamicImport/defaultPath.ts === +export class C {} +>C : Symbol(C, Decl(defaultPath.ts, 0, 0)) + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +import * as defaultModule from "./defaultPath"; +>defaultModule : Symbol(defaultModule, Decl(1.ts, 0, 6)) + +declare function getSpecifier(): string; +>getSpecifier : Symbol(getSpecifier, Decl(1.ts, 0, 47)) + +declare function ValidSomeCondition(): boolean; +>ValidSomeCondition : Symbol(ValidSomeCondition, Decl(1.ts, 1, 40)) + +declare var whatToLoad: boolean; +>whatToLoad : Symbol(whatToLoad, Decl(1.ts, 3, 11)) + +declare const directory: string; +>directory : Symbol(directory, Decl(1.ts, 4, 13)) + +declare const moduleFile: number; +>moduleFile : Symbol(moduleFile, Decl(1.ts, 5, 13)) + +import(`${directory}\${moduleFile}`); +>directory : Symbol(directory, Decl(1.ts, 4, 13)) + +import(getSpecifier()); +>getSpecifier : Symbol(getSpecifier, Decl(1.ts, 0, 47)) + +var p1 = import(ValidSomeCondition() ? "./0" : "externalModule"); +>p1 : Symbol(p1, Decl(1.ts, 10, 3), Decl(1.ts, 11, 3)) +>ValidSomeCondition : Symbol(ValidSomeCondition, Decl(1.ts, 1, 40)) + +var p1: Promise = import(getSpecifier()); +>p1 : Symbol(p1, Decl(1.ts, 10, 3), Decl(1.ts, 11, 3)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>getSpecifier : Symbol(getSpecifier, Decl(1.ts, 0, 47)) + +var p11: Promise = import(getSpecifier()); +>p11 : Symbol(p11, Decl(1.ts, 12, 3)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>defaultModule : Symbol(defaultModule, Decl(1.ts, 0, 6)) +>getSpecifier : Symbol(getSpecifier, Decl(1.ts, 0, 47)) + +const p2 = import(whatToLoad ? getSpecifier() : "defaulPath") as Promise; +>p2 : Symbol(p2, Decl(1.ts, 13, 5)) +>whatToLoad : Symbol(whatToLoad, Decl(1.ts, 3, 11)) +>getSpecifier : Symbol(getSpecifier, Decl(1.ts, 0, 47)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>defaultModule : Symbol(defaultModule, Decl(1.ts, 0, 6)) + +p1.then(zero => { +>p1.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>p1 : Symbol(p1, Decl(1.ts, 10, 3), Decl(1.ts, 11, 3)) +>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>zero : Symbol(zero, Decl(1.ts, 14, 8)) + + return zero.foo(); // ok, zero is any +>zero : Symbol(zero, Decl(1.ts, 14, 8)) + +}); + +let j: string; +>j : Symbol(j, Decl(1.ts, 18, 3)) + +var p3: Promise = import(j=getSpecifier()); +>p3 : Symbol(p3, Decl(1.ts, 19, 3)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>defaultModule : Symbol(defaultModule, Decl(1.ts, 0, 6)) +>j : Symbol(j, Decl(1.ts, 18, 3)) +>getSpecifier : Symbol(getSpecifier, Decl(1.ts, 0, 47)) + +function * loadModule(directories: string[]) { +>loadModule : Symbol(loadModule, Decl(1.ts, 19, 65)) +>directories : Symbol(directories, Decl(1.ts, 21, 22)) + + for (const directory of directories) { +>directory : Symbol(directory, Decl(1.ts, 22, 14)) +>directories : Symbol(directories, Decl(1.ts, 21, 22)) + + const path = `${directory}\moduleFile`; +>path : Symbol(path, Decl(1.ts, 23, 13)) +>directory : Symbol(directory, Decl(1.ts, 22, 14)) + + import(yield path); +>path : Symbol(path, Decl(1.ts, 23, 13)) + } +} + diff --git a/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.types b/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.types new file mode 100644 index 00000000000..4337e970bd1 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.types @@ -0,0 +1,118 @@ +=== tests/cases/conformance/es2018/dynamicImport/defaultPath.ts === +export class C {} +>C : C + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +import * as defaultModule from "./defaultPath"; +>defaultModule : typeof defaultModule + +declare function getSpecifier(): string; +>getSpecifier : () => string + +declare function ValidSomeCondition(): boolean; +>ValidSomeCondition : () => boolean + +declare var whatToLoad: boolean; +>whatToLoad : boolean + +declare const directory: string; +>directory : string + +declare const moduleFile: number; +>moduleFile : number + +import(`${directory}\${moduleFile}`); +>import(`${directory}\${moduleFile}`) : Promise +>`${directory}\${moduleFile}` : string +>directory : string + +import(getSpecifier()); +>import(getSpecifier()) : Promise +>getSpecifier() : string +>getSpecifier : () => string + +var p1 = import(ValidSomeCondition() ? "./0" : "externalModule"); +>p1 : Promise +>import(ValidSomeCondition() ? "./0" : "externalModule") : Promise +>ValidSomeCondition() ? "./0" : "externalModule" : "./0" | "externalModule" +>ValidSomeCondition() : boolean +>ValidSomeCondition : () => boolean +>"./0" : "./0" +>"externalModule" : "externalModule" + +var p1: Promise = import(getSpecifier()); +>p1 : Promise +>Promise : Promise +>import(getSpecifier()) : Promise +>getSpecifier() : string +>getSpecifier : () => string + +var p11: Promise = import(getSpecifier()); +>p11 : Promise +>Promise : Promise +>defaultModule : typeof defaultModule +>import(getSpecifier()) : Promise +>getSpecifier() : string +>getSpecifier : () => string + +const p2 = import(whatToLoad ? getSpecifier() : "defaulPath") as Promise; +>p2 : Promise +>import(whatToLoad ? getSpecifier() : "defaulPath") as Promise : Promise +>import(whatToLoad ? getSpecifier() : "defaulPath") : Promise +>whatToLoad ? getSpecifier() : "defaulPath" : string +>whatToLoad : boolean +>getSpecifier() : string +>getSpecifier : () => string +>"defaulPath" : "defaulPath" +>Promise : Promise +>defaultModule : typeof defaultModule + +p1.then(zero => { +>p1.then(zero => { return zero.foo(); // ok, zero is any}) : Promise +>p1.then : (onfulfilled?: (value: any) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>p1 : Promise +>then : (onfulfilled?: (value: any) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>zero => { return zero.foo(); // ok, zero is any} : (zero: any) => any +>zero : any + + return zero.foo(); // ok, zero is any +>zero.foo() : any +>zero.foo : any +>zero : any +>foo : any + +}); + +let j: string; +>j : string + +var p3: Promise = import(j=getSpecifier()); +>p3 : Promise +>Promise : Promise +>defaultModule : typeof defaultModule +>import(j=getSpecifier()) : Promise +>j=getSpecifier() : string +>j : string +>getSpecifier() : string +>getSpecifier : () => string + +function * loadModule(directories: string[]) { +>loadModule : (directories: string[]) => IterableIterator +>directories : string[] + + for (const directory of directories) { +>directory : string +>directories : string[] + + const path = `${directory}\moduleFile`; +>path : string +>`${directory}\moduleFile` : string +>directory : string + + import(yield path); +>import(yield path) : Promise +>yield path : any +>path : string + } +} + diff --git a/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.errors.txt b/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.errors.txt new file mode 100644 index 00000000000..8136597ab93 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.errors.txt @@ -0,0 +1,32 @@ +tests/cases/conformance/es2018/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts(6,8): error TS7035: Dynamic import's specifier must be of type 'string', but here has type 'boolean'. +tests/cases/conformance/es2018/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts(7,17): error TS7035: Dynamic import's specifier must be of type 'string', but here has type 'boolean'. +tests/cases/conformance/es2018/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts(8,19): error TS7035: Dynamic import's specifier must be of type 'string', but here has type 'boolean | "defaulPath"'. +tests/cases/conformance/es2018/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts(13,17): error TS7035: Dynamic import's specifier must be of type 'string', but here has type 'string[]'. +tests/cases/conformance/es2018/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts(14,17): error TS7035: Dynamic import's specifier must be of type 'string', but here has type '() => string'. + + +==== tests/cases/conformance/es2018/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts (5 errors) ==== + + declare function getSpecifier(): boolean; + declare var whatToLoad: boolean; + + // Error specifier is not assignable to string + import(getSpecifier()); + ~~~~~~~~~~~~~~ +!!! error TS7035: Dynamic import's specifier must be of type 'string', but here has type 'boolean'. + var p1 = import(getSpecifier()); + ~~~~~~~~~~~~~~ +!!! error TS7035: Dynamic import's specifier must be of type 'string', but here has type 'boolean'. + const p2 = import(whatToLoad ? getSpecifier() : "defaulPath") + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS7035: Dynamic import's specifier must be of type 'string', but here has type 'boolean | "defaulPath"'. + p1.then(zero => { + return zero.foo(); // ok, zero is any + }); + + var p3 = import(["path1", "path2"]); + ~~~~~~~~~~~~~~~~~~ +!!! error TS7035: Dynamic import's specifier must be of type 'string', but here has type 'string[]'. + var p4 = import(()=>"PathToModule"); + ~~~~~~~~~~~~~~~~~~ +!!! error TS7035: Dynamic import's specifier must be of type 'string', but here has type '() => string'. \ No newline at end of file diff --git a/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.js b/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.js new file mode 100644 index 00000000000..23dd3425c45 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.js @@ -0,0 +1,27 @@ +//// [importCallExpressionSpecifierNotStringTypeError.ts] + +declare function getSpecifier(): boolean; +declare var whatToLoad: boolean; + +// Error specifier is not assignable to string +import(getSpecifier()); +var p1 = import(getSpecifier()); +const p2 = import(whatToLoad ? getSpecifier() : "defaulPath") +p1.then(zero => { + return zero.foo(); // ok, zero is any +}); + +var p3 = import(["path1", "path2"]); +var p4 = import(()=>"PathToModule"); + +//// [importCallExpressionSpecifierNotStringTypeError.js] +"use strict"; +// Error specifier is not assignable to string +Promise.resolve().then(() => require(getSpecifier())); +var p1 = Promise.resolve().then(() => require(getSpecifier())); +const p2 = Promise.resolve().then(() => require(whatToLoad ? getSpecifier() : "defaulPath")); +p1.then(zero => { + return zero.foo(); // ok, zero is any +}); +var p3 = Promise.resolve().then(() => require(["path1", "path2"])); +var p4 = Promise.resolve().then(() => require(() => "PathToModule")); diff --git a/tests/baselines/reference/importCallExpressionWithTypeArgument.errors.txt b/tests/baselines/reference/importCallExpressionWithTypeArgument.errors.txt new file mode 100644 index 00000000000..d0b17931e2e --- /dev/null +++ b/tests/baselines/reference/importCallExpressionWithTypeArgument.errors.txt @@ -0,0 +1,19 @@ +tests/cases/conformance/es2018/dynamicImport/1.ts(2,10): error TS1323: Dynamic import cannot have type arguments +tests/cases/conformance/es2018/dynamicImport/1.ts(3,10): error TS1323: Dynamic import cannot have type arguments + + +==== tests/cases/conformance/es2018/dynamicImport/0.ts (0 errors) ==== + + export function foo() { return "foo"; } + +==== tests/cases/conformance/es2018/dynamicImport/1.ts (2 errors) ==== + "use strict" + var p1 = import>("./0"); // error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1323: Dynamic import cannot have type arguments + var p2 = import<>("./0"); // error + ~~~~~~~~~~~~~~~ +!!! error TS1323: Dynamic import cannot have type arguments + // p1.then(value => { + // value.anyFunction(); + // }) \ No newline at end of file diff --git a/tests/baselines/reference/importCallExpressionWithTypeArgument.js b/tests/baselines/reference/importCallExpressionWithTypeArgument.js new file mode 100644 index 00000000000..59ad9b6026c --- /dev/null +++ b/tests/baselines/reference/importCallExpressionWithTypeArgument.js @@ -0,0 +1,26 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionWithTypeArgument.ts] //// + +//// [0.ts] + +export function foo() { return "foo"; } + +//// [1.ts] +"use strict" +var p1 = import>("./0"); // error +var p2 = import<>("./0"); // error +// p1.then(value => { +// value.anyFunction(); +// }) + +//// [0.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +function foo() { return "foo"; } +exports.foo = foo; +//// [1.js] +"use strict"; +var p1 = (import)("./0"); // error +var p2 = (import)("./0"); // error +// p1.then(value => { +// value.anyFunction(); +// }) From d4754db443f64eea7f587fefce79be27ff398ae6 Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Wed, 29 Mar 2017 10:51:18 -0700 Subject: [PATCH 42/67] Update baseline from merging with master --- .../importCallExpressionDeclarationEmit1.js | 1 - .../importCallExpressionGrammarError.js | 1 - .../reference/importCallExpressionInCJS1.js | 1 - .../reference/importCallExpressionInCJS2.js | 1 - .../reference/importCallExpressionInCJS3.js | 1 - .../reference/importCallExpressionInCJS5.js | 1 - .../importCallExpressionInScriptContext1.js | 18 ++++++++++++++++++ ...mportCallExpressionInScriptContext1.symbols | 12 ++++++++++++ .../importCallExpressionInScriptContext1.types | 15 +++++++++++++++ .../reference/importCallExpressionInSystem1.js | 1 - .../reference/importCallExpressionInSystem2.js | 1 - .../reference/importCallExpressionInSystem4.js | 1 - ...allExpressionSpecifierNotStringTypeError.js | 1 - .../Default initialized TSConfig/tsconfig.json | 2 +- .../tsconfig.json | 2 +- .../tsconfig.json | 2 +- .../tsconfig.json | 2 +- .../tsconfig.json | 2 +- .../tsconfig.json | 2 +- .../tsconfig.json | 2 +- .../tsconfig.json | 2 +- 21 files changed, 53 insertions(+), 18 deletions(-) create mode 100644 tests/baselines/reference/importCallExpressionInScriptContext1.js create mode 100644 tests/baselines/reference/importCallExpressionInScriptContext1.symbols create mode 100644 tests/baselines/reference/importCallExpressionInScriptContext1.types diff --git a/tests/baselines/reference/importCallExpressionDeclarationEmit1.js b/tests/baselines/reference/importCallExpressionDeclarationEmit1.js index 333bc8768be..793e52b12ad 100644 --- a/tests/baselines/reference/importCallExpressionDeclarationEmit1.js +++ b/tests/baselines/reference/importCallExpressionDeclarationEmit1.js @@ -16,7 +16,6 @@ function returnDynamicLoad(path: string) { } //// [importCallExpressionDeclarationEmit1.js] -"use strict"; Promise.resolve().then(() => require(getSpecifier())); var p0 = Promise.resolve().then(() => require(`${directory}\${moduleFile}`)); var p1 = Promise.resolve().then(() => require(getSpecifier())); diff --git a/tests/baselines/reference/importCallExpressionGrammarError.js b/tests/baselines/reference/importCallExpressionGrammarError.js index 6f31587a23d..76694dfc60e 100644 --- a/tests/baselines/reference/importCallExpressionGrammarError.js +++ b/tests/baselines/reference/importCallExpressionGrammarError.js @@ -12,7 +12,6 @@ const p3 = import(,); const p4 = import("pathToModule", "secondModule"); //// [importCallExpressionGrammarError.js] -"use strict"; var a = ["./0"]; Promise.resolve().then(() => require(...["PathModule"])); var p1 = Promise.resolve().then(() => require(...a)); diff --git a/tests/baselines/reference/importCallExpressionInCJS1.js b/tests/baselines/reference/importCallExpressionInCJS1.js index e9a5ffa3656..85d99dfa4c3 100644 --- a/tests/baselines/reference/importCallExpressionInCJS1.js +++ b/tests/baselines/reference/importCallExpressionInCJS1.js @@ -20,7 +20,6 @@ Object.defineProperty(exports, "__esModule", { value: true }); function foo() { return "foo"; } exports.foo = foo; //// [1.js] -"use strict"; Promise.resolve().then(() => require("./0")); var p1 = Promise.resolve().then(() => require("./0")); p1.then(zero => { diff --git a/tests/baselines/reference/importCallExpressionInCJS2.js b/tests/baselines/reference/importCallExpressionInCJS2.js index 7430541b51e..a5b96c45ee0 100644 --- a/tests/baselines/reference/importCallExpressionInCJS2.js +++ b/tests/baselines/reference/importCallExpressionInCJS2.js @@ -29,7 +29,6 @@ Object.defineProperty(exports, "__esModule", { value: true }); function backup() { return "backup"; } exports.backup = backup; //// [2.js] -"use strict"; async function compute(promise) { let j = await promise; if (!j) { diff --git a/tests/baselines/reference/importCallExpressionInCJS3.js b/tests/baselines/reference/importCallExpressionInCJS3.js index 264888091ab..499c8f9b496 100644 --- a/tests/baselines/reference/importCallExpressionInCJS3.js +++ b/tests/baselines/reference/importCallExpressionInCJS3.js @@ -24,7 +24,6 @@ class B { } exports.B = B; //// [2.js] -"use strict"; // We use Promise for now as there is no way to specify shape of module object function foo(x) { x.then(value => { diff --git a/tests/baselines/reference/importCallExpressionInCJS5.js b/tests/baselines/reference/importCallExpressionInCJS5.js index 82845416b45..d1158fe48b8 100644 --- a/tests/baselines/reference/importCallExpressionInCJS5.js +++ b/tests/baselines/reference/importCallExpressionInCJS5.js @@ -40,7 +40,6 @@ Object.defineProperty(exports, "__esModule", { value: true }); function backup() { return "backup"; } exports.backup = backup; //// [2.js] -"use strict"; class C { constructor() { this.myModule = Promise.resolve().then(() => require("./0")); diff --git a/tests/baselines/reference/importCallExpressionInScriptContext1.js b/tests/baselines/reference/importCallExpressionInScriptContext1.js new file mode 100644 index 00000000000..18224e195f4 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInScriptContext1.js @@ -0,0 +1,18 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInScriptContext1.ts] //// + +//// [0.ts] + +export function foo() { return "foo"; } + +//// [1.ts] +var p1 = import("./0"); +function arguments() { } // this is allow as the file doesn't have implicit "use strict" + +//// [0.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +function foo() { return "foo"; } +exports.foo = foo; +//// [1.js] +var p1 = Promise.resolve().then(() => require("./0")); +function arguments() { } // this is allow as the file doesn't have implicit "use strict" diff --git a/tests/baselines/reference/importCallExpressionInScriptContext1.symbols b/tests/baselines/reference/importCallExpressionInScriptContext1.symbols new file mode 100644 index 00000000000..50ba482b03b --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInScriptContext1.symbols @@ -0,0 +1,12 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === + +export function foo() { return "foo"; } +>foo : Symbol(foo, Decl(0.ts, 0, 0)) + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +var p1 = import("./0"); +>p1 : Symbol(p1, Decl(1.ts, 0, 3)) + +function arguments() { } // this is allow as the file doesn't have implicit "use strict" +>arguments : Symbol(arguments, Decl(1.ts, 0, 23)) + diff --git a/tests/baselines/reference/importCallExpressionInScriptContext1.types b/tests/baselines/reference/importCallExpressionInScriptContext1.types new file mode 100644 index 00000000000..fe8a94ddf84 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInScriptContext1.types @@ -0,0 +1,15 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === + +export function foo() { return "foo"; } +>foo : () => string +>"foo" : "foo" + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +var p1 = import("./0"); +>p1 : Promise +>import("./0") : Promise +>"./0" : "./0" + +function arguments() { } // this is allow as the file doesn't have implicit "use strict" +>arguments : () => void + diff --git a/tests/baselines/reference/importCallExpressionInSystem1.js b/tests/baselines/reference/importCallExpressionInSystem1.js index 1a146b02fcd..d200111c70c 100644 --- a/tests/baselines/reference/importCallExpressionInSystem1.js +++ b/tests/baselines/reference/importCallExpressionInSystem1.js @@ -28,7 +28,6 @@ System.register([], function (exports_1, context_1) { }); //// [1.js] System.register([], function (exports_1, context_1) { - "use strict"; var __moduleName = context_1 && context_1.id; function foo() { const p2 = context_1.import("./0"); diff --git a/tests/baselines/reference/importCallExpressionInSystem2.js b/tests/baselines/reference/importCallExpressionInSystem2.js index 198f4c4c7a2..704af5822b3 100644 --- a/tests/baselines/reference/importCallExpressionInSystem2.js +++ b/tests/baselines/reference/importCallExpressionInSystem2.js @@ -33,7 +33,6 @@ System.register([], function (exports_1, context_1) { }); //// [2.js] System.register([], function (exports_1, context_1) { - "use strict"; var __moduleName = context_1 && context_1.id; // We use Promise for now as there is no way to specify shape of module object function foo(x) { diff --git a/tests/baselines/reference/importCallExpressionInSystem4.js b/tests/baselines/reference/importCallExpressionInSystem4.js index e3a938b826e..81562b65212 100644 --- a/tests/baselines/reference/importCallExpressionInSystem4.js +++ b/tests/baselines/reference/importCallExpressionInSystem4.js @@ -56,7 +56,6 @@ System.register([], function (exports_1, context_1) { }); //// [2.js] System.register([], function (exports_1, context_1) { - "use strict"; var __moduleName = context_1 && context_1.id; var C; return { diff --git a/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.js b/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.js index 23dd3425c45..57e42692d23 100644 --- a/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.js +++ b/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.js @@ -15,7 +15,6 @@ var p3 = import(["path1", "path2"]); var p4 = import(()=>"PathToModule"); //// [importCallExpressionSpecifierNotStringTypeError.js] -"use strict"; // Error specifier is not assignable to string Promise.resolve().then(() => require(getSpecifier())); var p1 = Promise.resolve().then(() => require(getSpecifier())); diff --git a/tests/baselines/reference/tsConfig/Default initialized TSConfig/tsconfig.json b/tests/baselines/reference/tsConfig/Default initialized TSConfig/tsconfig.json index 97f59dea8ea..2a93230da51 100644 --- a/tests/baselines/reference/tsConfig/Default initialized TSConfig/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Default initialized TSConfig/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { /* Basic Options */ "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */ - "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'. */ + "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'es2018'. */ // "lib": [], /* Specify library files to be included in the compilation: */ // "allowJs": true, /* Allow javascript files to be compiled. */ // "checkJs": true, /* Report errors in .js files. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json index b90e3fc6c58..f839d900336 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { /* Basic Options */ "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */ - "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'. */ + "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'es2018'. */ // "lib": [], /* Specify library files to be included in the compilation: */ // "allowJs": true, /* Allow javascript files to be compiled. */ // "checkJs": true, /* Report errors in .js files. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with enum value compiler options/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with enum value compiler options/tsconfig.json index 482cfa6a9d5..1c5cf4e955b 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with enum value compiler options/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with enum value compiler options/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { /* Basic Options */ "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */ - "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'. */ + "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'es2018'. */ // "lib": [], /* Specify library files to be included in the compilation: */ // "allowJs": true, /* Allow javascript files to be compiled. */ // "checkJs": true, /* Report errors in .js files. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with files options/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with files options/tsconfig.json index c6a26629dab..b9ab2eb2424 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with files options/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with files options/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { /* Basic Options */ "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */ - "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'. */ + "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'es2018'. */ // "lib": [], /* Specify library files to be included in the compilation: */ // "allowJs": true, /* Allow javascript files to be compiled. */ // "checkJs": true, /* Report errors in .js files. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json index 72289dd1787..78b6a1db4d6 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { /* Basic Options */ "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */ - "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'. */ + "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'es2018'. */ "lib": ["es5","es2015.promise"], /* Specify library files to be included in the compilation: */ // "allowJs": true, /* Allow javascript files to be compiled. */ // "checkJs": true, /* Report errors in .js files. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json index 97f59dea8ea..2a93230da51 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { /* Basic Options */ "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */ - "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'. */ + "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'es2018'. */ // "lib": [], /* Specify library files to be included in the compilation: */ // "allowJs": true, /* Allow javascript files to be compiled. */ // "checkJs": true, /* Report errors in .js files. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json index 1ac7c8c54da..4fdf66b54f8 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { /* Basic Options */ "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */ - "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'. */ + "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'es2018'. */ "lib": ["es5","es2015.core"], /* Specify library files to be included in the compilation: */ // "allowJs": true, /* Allow javascript files to be compiled. */ // "checkJs": true, /* Report errors in .js files. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options/tsconfig.json index 33a9ecc5cd4..31a5ff24da5 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { /* Basic Options */ "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */ - "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'. */ + "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'es2018'. */ // "lib": [], /* Specify library files to be included in the compilation: */ // "allowJs": true, /* Allow javascript files to be compiled. */ // "checkJs": true, /* Report errors in .js files. */ From faaa38d93edac3b649e6909ce82e463cd2971587 Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Tue, 4 Apr 2017 14:27:45 -0700 Subject: [PATCH 43/67] Update PR --- .../reference/importCallExpression3ES2018.js | 27 ++++++++++ .../importCallExpression3ES2018.symbols | 29 +++++++++++ .../importCallExpression3ES2018.types | 37 ++++++++++++++ ...tCallExpressionCheckReturntype1.errors.txt | 1 - .../importCallExpressionCheckReturntype1.js | 1 - .../importCallExpressionDeclarationEmit1.js | 1 - ...portCallExpressionDeclarationEmit1.symbols | 23 ++++----- ...importCallExpressionDeclarationEmit1.types | 1 - ...tCallExpressionDeclarationEmit2.errors.txt | 1 - .../importCallExpressionDeclarationEmit2.js | 1 - .../importCallExpressionDeclarationEmit3.js | 1 - ...portCallExpressionDeclarationEmit3.symbols | 1 - ...importCallExpressionDeclarationEmit3.types | 1 - ...mportCallExpressionGrammarError.errors.txt | 11 ++-- .../importCallExpressionGrammarError.js | 1 - .../reference/importCallExpressionInAMD3.js | 35 +++++++++++++ .../importCallExpressionInAMD3.symbols | 29 +++++++++++ .../importCallExpressionInAMD3.types | 37 ++++++++++++++ .../reference/importCallExpressionInCJS4.js | 30 +++++++++++ .../importCallExpressionInCJS4.symbols | 29 +++++++++++ .../importCallExpressionInCJS4.types | 37 ++++++++++++++ .../importCallExpressionInScriptContext1.js | 1 - ...portCallExpressionInScriptContext1.symbols | 1 - ...importCallExpressionInScriptContext1.types | 1 - ...tCallExpressionInScriptContext2.errors.txt | 1 - .../importCallExpressionInScriptContext2.js | 1 - .../importCallExpressionInSystem3.js | 46 +++++++++++++++++ .../importCallExpressionInSystem3.symbols | 29 +++++++++++ .../importCallExpressionInSystem3.types | 37 ++++++++++++++ .../reference/importCallExpressionInUMD3.js | 51 +++++++++++++++++++ .../importCallExpressionInUMD3.symbols | 29 +++++++++++ .../importCallExpressionInUMD3.types | 37 ++++++++++++++ ...sionSpecifierNotStringTypeError.errors.txt | 11 ++-- ...llExpressionSpecifierNotStringTypeError.js | 1 - ...tCallExpressionWithTypeArgument.errors.txt | 1 - .../importCallExpressionWithTypeArgument.js | 4 -- 36 files changed, 540 insertions(+), 45 deletions(-) create mode 100644 tests/baselines/reference/importCallExpression3ES2018.js create mode 100644 tests/baselines/reference/importCallExpression3ES2018.symbols create mode 100644 tests/baselines/reference/importCallExpression3ES2018.types create mode 100644 tests/baselines/reference/importCallExpressionInAMD3.js create mode 100644 tests/baselines/reference/importCallExpressionInAMD3.symbols create mode 100644 tests/baselines/reference/importCallExpressionInAMD3.types create mode 100644 tests/baselines/reference/importCallExpressionInCJS4.js create mode 100644 tests/baselines/reference/importCallExpressionInCJS4.symbols create mode 100644 tests/baselines/reference/importCallExpressionInCJS4.types create mode 100644 tests/baselines/reference/importCallExpressionInSystem3.js create mode 100644 tests/baselines/reference/importCallExpressionInSystem3.symbols create mode 100644 tests/baselines/reference/importCallExpressionInSystem3.types create mode 100644 tests/baselines/reference/importCallExpressionInUMD3.js create mode 100644 tests/baselines/reference/importCallExpressionInUMD3.symbols create mode 100644 tests/baselines/reference/importCallExpressionInUMD3.types diff --git a/tests/baselines/reference/importCallExpression3ES2018.js b/tests/baselines/reference/importCallExpression3ES2018.js new file mode 100644 index 00000000000..247e78bb46c --- /dev/null +++ b/tests/baselines/reference/importCallExpression3ES2018.js @@ -0,0 +1,27 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpression3ES2018.ts] //// + +//// [0.ts] +export class B { + print() { return "I am B"} +} + +//// [2.ts] +async function foo() { + class C extends (await import("./0")).B {} + var c = new C(); + c.print(); +} +foo(); + +//// [0.js] +export class B { + print() { return "I am B"; } +} +//// [2.js] +async function foo() { + class C extends (await import("./0")).B { + } + var c = new C(); + c.print(); +} +foo(); diff --git a/tests/baselines/reference/importCallExpression3ES2018.symbols b/tests/baselines/reference/importCallExpression3ES2018.symbols new file mode 100644 index 00000000000..06b328f5745 --- /dev/null +++ b/tests/baselines/reference/importCallExpression3ES2018.symbols @@ -0,0 +1,29 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export class B { +>B : Symbol(B, Decl(0.ts, 0, 0)) + + print() { return "I am B"} +>print : Symbol(B.print, Decl(0.ts, 0, 16)) +} + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +async function foo() { +>foo : Symbol(foo, Decl(2.ts, 0, 0)) + + class C extends (await import("./0")).B {} +>C : Symbol(C, Decl(2.ts, 0, 22)) +>(await import("./0")).B : Symbol(B, Decl(0.ts, 0, 0)) +>B : Symbol(B, Decl(0.ts, 0, 0)) + + var c = new C(); +>c : Symbol(c, Decl(2.ts, 2, 7)) +>C : Symbol(C, Decl(2.ts, 0, 22)) + + c.print(); +>c.print : Symbol(B.print, Decl(0.ts, 0, 16)) +>c : Symbol(c, Decl(2.ts, 2, 7)) +>print : Symbol(B.print, Decl(0.ts, 0, 16)) +} +foo(); +>foo : Symbol(foo, Decl(2.ts, 0, 0)) + diff --git a/tests/baselines/reference/importCallExpression3ES2018.types b/tests/baselines/reference/importCallExpression3ES2018.types new file mode 100644 index 00000000000..e88ddd04431 --- /dev/null +++ b/tests/baselines/reference/importCallExpression3ES2018.types @@ -0,0 +1,37 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export class B { +>B : B + + print() { return "I am B"} +>print : () => string +>"I am B" : "I am B" +} + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +async function foo() { +>foo : () => Promise + + class C extends (await import("./0")).B {} +>C : C +>(await import("./0")).B : B +>(await import("./0")) : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>await import("./0") : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>import("./0") : Promise +>"./0" : "./0" +>B : typeof B + + var c = new C(); +>c : C +>new C() : C +>C : typeof C + + c.print(); +>c.print() : string +>c.print : () => string +>c : C +>print : () => string +} +foo(); +>foo() : Promise +>foo : () => Promise + diff --git a/tests/baselines/reference/importCallExpressionCheckReturntype1.errors.txt b/tests/baselines/reference/importCallExpressionCheckReturntype1.errors.txt index e5ea311f44c..adb904ce7fa 100644 --- a/tests/baselines/reference/importCallExpressionCheckReturntype1.errors.txt +++ b/tests/baselines/reference/importCallExpressionCheckReturntype1.errors.txt @@ -7,7 +7,6 @@ tests/cases/conformance/es2018/dynamicImport/1.ts(5,10): error TS2352: Type 'Pro ==== tests/cases/conformance/es2018/dynamicImport/anotherModule.ts (0 errors) ==== - export class D{} ==== tests/cases/conformance/es2018/dynamicImport/defaultPath.ts (0 errors) ==== diff --git a/tests/baselines/reference/importCallExpressionCheckReturntype1.js b/tests/baselines/reference/importCallExpressionCheckReturntype1.js index 2ef1e729b84..cddc20d925a 100644 --- a/tests/baselines/reference/importCallExpressionCheckReturntype1.js +++ b/tests/baselines/reference/importCallExpressionCheckReturntype1.js @@ -1,7 +1,6 @@ //// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionCheckReturntype1.ts] //// //// [anotherModule.ts] - export class D{} //// [defaultPath.ts] diff --git a/tests/baselines/reference/importCallExpressionDeclarationEmit1.js b/tests/baselines/reference/importCallExpressionDeclarationEmit1.js index 793e52b12ad..721d85abe71 100644 --- a/tests/baselines/reference/importCallExpressionDeclarationEmit1.js +++ b/tests/baselines/reference/importCallExpressionDeclarationEmit1.js @@ -1,5 +1,4 @@ //// [importCallExpressionDeclarationEmit1.ts] - declare function getSpecifier(): string; declare var whatToLoad: boolean; declare const directory: string; diff --git a/tests/baselines/reference/importCallExpressionDeclarationEmit1.symbols b/tests/baselines/reference/importCallExpressionDeclarationEmit1.symbols index 24fa2bc206d..997911b9481 100644 --- a/tests/baselines/reference/importCallExpressionDeclarationEmit1.symbols +++ b/tests/baselines/reference/importCallExpressionDeclarationEmit1.symbols @@ -1,37 +1,36 @@ === tests/cases/conformance/es2018/dynamicImport/importCallExpressionDeclarationEmit1.ts === - declare function getSpecifier(): string; >getSpecifier : Symbol(getSpecifier, Decl(importCallExpressionDeclarationEmit1.ts, 0, 0)) declare var whatToLoad: boolean; ->whatToLoad : Symbol(whatToLoad, Decl(importCallExpressionDeclarationEmit1.ts, 2, 11)) +>whatToLoad : Symbol(whatToLoad, Decl(importCallExpressionDeclarationEmit1.ts, 1, 11)) declare const directory: string; ->directory : Symbol(directory, Decl(importCallExpressionDeclarationEmit1.ts, 3, 13)) +>directory : Symbol(directory, Decl(importCallExpressionDeclarationEmit1.ts, 2, 13)) declare const moduleFile: number; ->moduleFile : Symbol(moduleFile, Decl(importCallExpressionDeclarationEmit1.ts, 4, 13)) +>moduleFile : Symbol(moduleFile, Decl(importCallExpressionDeclarationEmit1.ts, 3, 13)) import(getSpecifier()); >getSpecifier : Symbol(getSpecifier, Decl(importCallExpressionDeclarationEmit1.ts, 0, 0)) var p0 = import(`${directory}\${moduleFile}`); ->p0 : Symbol(p0, Decl(importCallExpressionDeclarationEmit1.ts, 8, 3)) ->directory : Symbol(directory, Decl(importCallExpressionDeclarationEmit1.ts, 3, 13)) +>p0 : Symbol(p0, Decl(importCallExpressionDeclarationEmit1.ts, 7, 3)) +>directory : Symbol(directory, Decl(importCallExpressionDeclarationEmit1.ts, 2, 13)) var p1 = import(getSpecifier()); ->p1 : Symbol(p1, Decl(importCallExpressionDeclarationEmit1.ts, 9, 3)) +>p1 : Symbol(p1, Decl(importCallExpressionDeclarationEmit1.ts, 8, 3)) >getSpecifier : Symbol(getSpecifier, Decl(importCallExpressionDeclarationEmit1.ts, 0, 0)) const p2 = import(whatToLoad ? getSpecifier() : "defaulPath") ->p2 : Symbol(p2, Decl(importCallExpressionDeclarationEmit1.ts, 10, 5)) ->whatToLoad : Symbol(whatToLoad, Decl(importCallExpressionDeclarationEmit1.ts, 2, 11)) +>p2 : Symbol(p2, Decl(importCallExpressionDeclarationEmit1.ts, 9, 5)) +>whatToLoad : Symbol(whatToLoad, Decl(importCallExpressionDeclarationEmit1.ts, 1, 11)) >getSpecifier : Symbol(getSpecifier, Decl(importCallExpressionDeclarationEmit1.ts, 0, 0)) function returnDynamicLoad(path: string) { ->returnDynamicLoad : Symbol(returnDynamicLoad, Decl(importCallExpressionDeclarationEmit1.ts, 10, 61)) ->path : Symbol(path, Decl(importCallExpressionDeclarationEmit1.ts, 12, 27)) +>returnDynamicLoad : Symbol(returnDynamicLoad, Decl(importCallExpressionDeclarationEmit1.ts, 9, 61)) +>path : Symbol(path, Decl(importCallExpressionDeclarationEmit1.ts, 11, 27)) return import(path); ->path : Symbol(path, Decl(importCallExpressionDeclarationEmit1.ts, 12, 27)) +>path : Symbol(path, Decl(importCallExpressionDeclarationEmit1.ts, 11, 27)) } diff --git a/tests/baselines/reference/importCallExpressionDeclarationEmit1.types b/tests/baselines/reference/importCallExpressionDeclarationEmit1.types index 9aedf5fcc6a..c45d3b3775e 100644 --- a/tests/baselines/reference/importCallExpressionDeclarationEmit1.types +++ b/tests/baselines/reference/importCallExpressionDeclarationEmit1.types @@ -1,5 +1,4 @@ === tests/cases/conformance/es2018/dynamicImport/importCallExpressionDeclarationEmit1.ts === - declare function getSpecifier(): string; >getSpecifier : () => string diff --git a/tests/baselines/reference/importCallExpressionDeclarationEmit2.errors.txt b/tests/baselines/reference/importCallExpressionDeclarationEmit2.errors.txt index 908bfb6a409..f397ee1e95f 100644 --- a/tests/baselines/reference/importCallExpressionDeclarationEmit2.errors.txt +++ b/tests/baselines/reference/importCallExpressionDeclarationEmit2.errors.txt @@ -2,7 +2,6 @@ tests/cases/conformance/es2018/dynamicImport/1.ts(1,5): error TS4023: Exported v ==== tests/cases/conformance/es2018/dynamicImport/0.ts (0 errors) ==== - export function foo() { return "foo"; } ==== tests/cases/conformance/es2018/dynamicImport/1.ts (1 errors) ==== diff --git a/tests/baselines/reference/importCallExpressionDeclarationEmit2.js b/tests/baselines/reference/importCallExpressionDeclarationEmit2.js index b2f2cac8c6d..49dee5c9f99 100644 --- a/tests/baselines/reference/importCallExpressionDeclarationEmit2.js +++ b/tests/baselines/reference/importCallExpressionDeclarationEmit2.js @@ -1,7 +1,6 @@ //// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionDeclarationEmit2.ts] //// //// [0.ts] - export function foo() { return "foo"; } //// [1.ts] diff --git a/tests/baselines/reference/importCallExpressionDeclarationEmit3.js b/tests/baselines/reference/importCallExpressionDeclarationEmit3.js index 42ae75acbb3..32775b00500 100644 --- a/tests/baselines/reference/importCallExpressionDeclarationEmit3.js +++ b/tests/baselines/reference/importCallExpressionDeclarationEmit3.js @@ -1,7 +1,6 @@ //// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionDeclarationEmit3.ts] //// //// [0.ts] - export function foo() { return "foo"; } //// [1.ts] diff --git a/tests/baselines/reference/importCallExpressionDeclarationEmit3.symbols b/tests/baselines/reference/importCallExpressionDeclarationEmit3.symbols index 6579d08ce34..1e9e3ca9184 100644 --- a/tests/baselines/reference/importCallExpressionDeclarationEmit3.symbols +++ b/tests/baselines/reference/importCallExpressionDeclarationEmit3.symbols @@ -1,5 +1,4 @@ === tests/cases/conformance/es2018/dynamicImport/0.ts === - export function foo() { return "foo"; } >foo : Symbol(foo, Decl(0.ts, 0, 0)) diff --git a/tests/baselines/reference/importCallExpressionDeclarationEmit3.types b/tests/baselines/reference/importCallExpressionDeclarationEmit3.types index a03628e917a..a3e2b58157f 100644 --- a/tests/baselines/reference/importCallExpressionDeclarationEmit3.types +++ b/tests/baselines/reference/importCallExpressionDeclarationEmit3.types @@ -1,5 +1,4 @@ === tests/cases/conformance/es2018/dynamicImport/0.ts === - export function foo() { return "foo"; } >foo : () => string >"foo" : "foo" diff --git a/tests/baselines/reference/importCallExpressionGrammarError.errors.txt b/tests/baselines/reference/importCallExpressionGrammarError.errors.txt index 4d9c6829953..c089452be3b 100644 --- a/tests/baselines/reference/importCallExpressionGrammarError.errors.txt +++ b/tests/baselines/reference/importCallExpressionGrammarError.errors.txt @@ -1,12 +1,11 @@ -tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts(6,8): error TS1322: Specifier of dynamic import cannot be spread element. -tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts(8,17): error TS1322: Specifier of dynamic import cannot be spread element. -tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts(9,12): error TS1321: Dynamic import must have one specifier as an argument. -tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts(10,19): error TS1135: Argument expression expected. -tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts(11,12): error TS1321: Dynamic import must have one specifier as an argument. +tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts(5,8): error TS1322: Specifier of dynamic import cannot be spread element. +tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts(7,17): error TS1322: Specifier of dynamic import cannot be spread element. +tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts(8,12): error TS1321: Dynamic import must have one specifier as an argument. +tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts(9,19): error TS1135: Argument expression expected. +tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts(10,12): error TS1321: Dynamic import must have one specifier as an argument. ==== tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts (5 errors) ==== - declare function getSpecifier(): string; declare var whatToLoad: boolean; diff --git a/tests/baselines/reference/importCallExpressionGrammarError.js b/tests/baselines/reference/importCallExpressionGrammarError.js index 76694dfc60e..e2ffc55577d 100644 --- a/tests/baselines/reference/importCallExpressionGrammarError.js +++ b/tests/baselines/reference/importCallExpressionGrammarError.js @@ -1,5 +1,4 @@ //// [importCallExpressionGrammarError.ts] - declare function getSpecifier(): string; declare var whatToLoad: boolean; diff --git a/tests/baselines/reference/importCallExpressionInAMD3.js b/tests/baselines/reference/importCallExpressionInAMD3.js new file mode 100644 index 00000000000..be752805346 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInAMD3.js @@ -0,0 +1,35 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInAMD3.ts] //// + +//// [0.ts] +export class B { + print() { return "I am B"} +} + +//// [2.ts] +async function foo() { + class C extends (await import("./0")).B {} + var c = new C(); + c.print(); +} +foo(); + +//// [0.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + class B { + print() { return "I am B"; } + } + exports.B = B; +}); +//// [2.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + async function foo() { + class C extends (await new Promise(resolve => require(["./0"], resolve))).B { + } + var c = new C(); + c.print(); + } + foo(); +}); diff --git a/tests/baselines/reference/importCallExpressionInAMD3.symbols b/tests/baselines/reference/importCallExpressionInAMD3.symbols new file mode 100644 index 00000000000..06b328f5745 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInAMD3.symbols @@ -0,0 +1,29 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export class B { +>B : Symbol(B, Decl(0.ts, 0, 0)) + + print() { return "I am B"} +>print : Symbol(B.print, Decl(0.ts, 0, 16)) +} + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +async function foo() { +>foo : Symbol(foo, Decl(2.ts, 0, 0)) + + class C extends (await import("./0")).B {} +>C : Symbol(C, Decl(2.ts, 0, 22)) +>(await import("./0")).B : Symbol(B, Decl(0.ts, 0, 0)) +>B : Symbol(B, Decl(0.ts, 0, 0)) + + var c = new C(); +>c : Symbol(c, Decl(2.ts, 2, 7)) +>C : Symbol(C, Decl(2.ts, 0, 22)) + + c.print(); +>c.print : Symbol(B.print, Decl(0.ts, 0, 16)) +>c : Symbol(c, Decl(2.ts, 2, 7)) +>print : Symbol(B.print, Decl(0.ts, 0, 16)) +} +foo(); +>foo : Symbol(foo, Decl(2.ts, 0, 0)) + diff --git a/tests/baselines/reference/importCallExpressionInAMD3.types b/tests/baselines/reference/importCallExpressionInAMD3.types new file mode 100644 index 00000000000..e88ddd04431 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInAMD3.types @@ -0,0 +1,37 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export class B { +>B : B + + print() { return "I am B"} +>print : () => string +>"I am B" : "I am B" +} + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +async function foo() { +>foo : () => Promise + + class C extends (await import("./0")).B {} +>C : C +>(await import("./0")).B : B +>(await import("./0")) : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>await import("./0") : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>import("./0") : Promise +>"./0" : "./0" +>B : typeof B + + var c = new C(); +>c : C +>new C() : C +>C : typeof C + + c.print(); +>c.print() : string +>c.print : () => string +>c : C +>print : () => string +} +foo(); +>foo() : Promise +>foo : () => Promise + diff --git a/tests/baselines/reference/importCallExpressionInCJS4.js b/tests/baselines/reference/importCallExpressionInCJS4.js new file mode 100644 index 00000000000..038e9649bfd --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInCJS4.js @@ -0,0 +1,30 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInCJS4.ts] //// + +//// [0.ts] +export class B { + print() { return "I am B"} +} + +//// [2.ts] +async function foo() { + class C extends (await import("./0")).B {} + var c = new C(); + c.print(); +} +foo(); + +//// [0.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +class B { + print() { return "I am B"; } +} +exports.B = B; +//// [2.js] +async function foo() { + class C extends (await Promise.resolve().then(() => require("./0"))).B { + } + var c = new C(); + c.print(); +} +foo(); diff --git a/tests/baselines/reference/importCallExpressionInCJS4.symbols b/tests/baselines/reference/importCallExpressionInCJS4.symbols new file mode 100644 index 00000000000..06b328f5745 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInCJS4.symbols @@ -0,0 +1,29 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export class B { +>B : Symbol(B, Decl(0.ts, 0, 0)) + + print() { return "I am B"} +>print : Symbol(B.print, Decl(0.ts, 0, 16)) +} + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +async function foo() { +>foo : Symbol(foo, Decl(2.ts, 0, 0)) + + class C extends (await import("./0")).B {} +>C : Symbol(C, Decl(2.ts, 0, 22)) +>(await import("./0")).B : Symbol(B, Decl(0.ts, 0, 0)) +>B : Symbol(B, Decl(0.ts, 0, 0)) + + var c = new C(); +>c : Symbol(c, Decl(2.ts, 2, 7)) +>C : Symbol(C, Decl(2.ts, 0, 22)) + + c.print(); +>c.print : Symbol(B.print, Decl(0.ts, 0, 16)) +>c : Symbol(c, Decl(2.ts, 2, 7)) +>print : Symbol(B.print, Decl(0.ts, 0, 16)) +} +foo(); +>foo : Symbol(foo, Decl(2.ts, 0, 0)) + diff --git a/tests/baselines/reference/importCallExpressionInCJS4.types b/tests/baselines/reference/importCallExpressionInCJS4.types new file mode 100644 index 00000000000..e88ddd04431 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInCJS4.types @@ -0,0 +1,37 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export class B { +>B : B + + print() { return "I am B"} +>print : () => string +>"I am B" : "I am B" +} + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +async function foo() { +>foo : () => Promise + + class C extends (await import("./0")).B {} +>C : C +>(await import("./0")).B : B +>(await import("./0")) : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>await import("./0") : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>import("./0") : Promise +>"./0" : "./0" +>B : typeof B + + var c = new C(); +>c : C +>new C() : C +>C : typeof C + + c.print(); +>c.print() : string +>c.print : () => string +>c : C +>print : () => string +} +foo(); +>foo() : Promise +>foo : () => Promise + diff --git a/tests/baselines/reference/importCallExpressionInScriptContext1.js b/tests/baselines/reference/importCallExpressionInScriptContext1.js index 18224e195f4..20a72ff565d 100644 --- a/tests/baselines/reference/importCallExpressionInScriptContext1.js +++ b/tests/baselines/reference/importCallExpressionInScriptContext1.js @@ -1,7 +1,6 @@ //// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInScriptContext1.ts] //// //// [0.ts] - export function foo() { return "foo"; } //// [1.ts] diff --git a/tests/baselines/reference/importCallExpressionInScriptContext1.symbols b/tests/baselines/reference/importCallExpressionInScriptContext1.symbols index 50ba482b03b..21e63635ed4 100644 --- a/tests/baselines/reference/importCallExpressionInScriptContext1.symbols +++ b/tests/baselines/reference/importCallExpressionInScriptContext1.symbols @@ -1,5 +1,4 @@ === tests/cases/conformance/es2018/dynamicImport/0.ts === - export function foo() { return "foo"; } >foo : Symbol(foo, Decl(0.ts, 0, 0)) diff --git a/tests/baselines/reference/importCallExpressionInScriptContext1.types b/tests/baselines/reference/importCallExpressionInScriptContext1.types index fe8a94ddf84..82e00221e33 100644 --- a/tests/baselines/reference/importCallExpressionInScriptContext1.types +++ b/tests/baselines/reference/importCallExpressionInScriptContext1.types @@ -1,5 +1,4 @@ === tests/cases/conformance/es2018/dynamicImport/0.ts === - export function foo() { return "foo"; } >foo : () => string >"foo" : "foo" diff --git a/tests/baselines/reference/importCallExpressionInScriptContext2.errors.txt b/tests/baselines/reference/importCallExpressionInScriptContext2.errors.txt index b7645851b28..d87798eb0c9 100644 --- a/tests/baselines/reference/importCallExpressionInScriptContext2.errors.txt +++ b/tests/baselines/reference/importCallExpressionInScriptContext2.errors.txt @@ -2,7 +2,6 @@ tests/cases/conformance/es2018/dynamicImport/1.ts(3,10): error TS1100: Invalid u ==== tests/cases/conformance/es2018/dynamicImport/0.ts (0 errors) ==== - export function foo() { return "foo"; } ==== tests/cases/conformance/es2018/dynamicImport/1.ts (1 errors) ==== diff --git a/tests/baselines/reference/importCallExpressionInScriptContext2.js b/tests/baselines/reference/importCallExpressionInScriptContext2.js index b278a60b6bb..3f2510493f0 100644 --- a/tests/baselines/reference/importCallExpressionInScriptContext2.js +++ b/tests/baselines/reference/importCallExpressionInScriptContext2.js @@ -1,7 +1,6 @@ //// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInScriptContext2.ts] //// //// [0.ts] - export function foo() { return "foo"; } //// [1.ts] diff --git a/tests/baselines/reference/importCallExpressionInSystem3.js b/tests/baselines/reference/importCallExpressionInSystem3.js new file mode 100644 index 00000000000..cdc6856d96b --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInSystem3.js @@ -0,0 +1,46 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInSystem3.ts] //// + +//// [0.ts] +export class B { + print() { return "I am B"} +} + +//// [2.ts] +async function foo() { + class C extends (await import("./0")).B {} + var c = new C(); + c.print(); +} +foo(); + +//// [0.js] +System.register([], function (exports_1, context_1) { + "use strict"; + var __moduleName = context_1 && context_1.id; + var B; + return { + setters: [], + execute: function () { + B = class B { + print() { return "I am B"; } + }; + exports_1("B", B); + } + }; +}); +//// [2.js] +System.register([], function (exports_1, context_1) { + var __moduleName = context_1 && context_1.id; + async function foo() { + class C extends (await context_1.import("./0")).B { + } + var c = new C(); + c.print(); + } + return { + setters: [], + execute: function () { + foo(); + } + }; +}); diff --git a/tests/baselines/reference/importCallExpressionInSystem3.symbols b/tests/baselines/reference/importCallExpressionInSystem3.symbols new file mode 100644 index 00000000000..06b328f5745 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInSystem3.symbols @@ -0,0 +1,29 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export class B { +>B : Symbol(B, Decl(0.ts, 0, 0)) + + print() { return "I am B"} +>print : Symbol(B.print, Decl(0.ts, 0, 16)) +} + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +async function foo() { +>foo : Symbol(foo, Decl(2.ts, 0, 0)) + + class C extends (await import("./0")).B {} +>C : Symbol(C, Decl(2.ts, 0, 22)) +>(await import("./0")).B : Symbol(B, Decl(0.ts, 0, 0)) +>B : Symbol(B, Decl(0.ts, 0, 0)) + + var c = new C(); +>c : Symbol(c, Decl(2.ts, 2, 7)) +>C : Symbol(C, Decl(2.ts, 0, 22)) + + c.print(); +>c.print : Symbol(B.print, Decl(0.ts, 0, 16)) +>c : Symbol(c, Decl(2.ts, 2, 7)) +>print : Symbol(B.print, Decl(0.ts, 0, 16)) +} +foo(); +>foo : Symbol(foo, Decl(2.ts, 0, 0)) + diff --git a/tests/baselines/reference/importCallExpressionInSystem3.types b/tests/baselines/reference/importCallExpressionInSystem3.types new file mode 100644 index 00000000000..e88ddd04431 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInSystem3.types @@ -0,0 +1,37 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export class B { +>B : B + + print() { return "I am B"} +>print : () => string +>"I am B" : "I am B" +} + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +async function foo() { +>foo : () => Promise + + class C extends (await import("./0")).B {} +>C : C +>(await import("./0")).B : B +>(await import("./0")) : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>await import("./0") : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>import("./0") : Promise +>"./0" : "./0" +>B : typeof B + + var c = new C(); +>c : C +>new C() : C +>C : typeof C + + c.print(); +>c.print() : string +>c.print : () => string +>c : C +>print : () => string +} +foo(); +>foo() : Promise +>foo : () => Promise + diff --git a/tests/baselines/reference/importCallExpressionInUMD3.js b/tests/baselines/reference/importCallExpressionInUMD3.js new file mode 100644 index 00000000000..5aef0967131 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInUMD3.js @@ -0,0 +1,51 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInUMD3.ts] //// + +//// [0.ts] +export class B { + print() { return "I am B"} +} + +//// [2.ts] +async function foo() { + class C extends (await import("./0")).B {} + var c = new C(); + c.print(); +} +foo(); + +//// [0.js] +(function (factory) { + if (typeof module === "object" && typeof module.exports === "object") { + var v = factory(require, exports); + if (v !== undefined) module.exports = v; + } + else if (typeof define === "function" && define.amd) { + define(["require", "exports"], factory); + } +})(function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + class B { + print() { return "I am B"; } + } + exports.B = B; +}); +//// [2.js] +(function (factory) { + if (typeof module === "object" && typeof module.exports === "object") { + var v = factory(require, exports); + if (v !== undefined) module.exports = v; + } + else if (typeof define === "function" && define.amd) { + define(["require", "exports"], factory); + } +})(function (require, exports) { + "use strict"; + async function foo() { + class C extends (await (require.length === 1 ? Promise.resolve().then(() => require("./0")) : new Promise(resolve => require(["./0"], resolve)))).B { + } + var c = new C(); + c.print(); + } + foo(); +}); diff --git a/tests/baselines/reference/importCallExpressionInUMD3.symbols b/tests/baselines/reference/importCallExpressionInUMD3.symbols new file mode 100644 index 00000000000..06b328f5745 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInUMD3.symbols @@ -0,0 +1,29 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export class B { +>B : Symbol(B, Decl(0.ts, 0, 0)) + + print() { return "I am B"} +>print : Symbol(B.print, Decl(0.ts, 0, 16)) +} + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +async function foo() { +>foo : Symbol(foo, Decl(2.ts, 0, 0)) + + class C extends (await import("./0")).B {} +>C : Symbol(C, Decl(2.ts, 0, 22)) +>(await import("./0")).B : Symbol(B, Decl(0.ts, 0, 0)) +>B : Symbol(B, Decl(0.ts, 0, 0)) + + var c = new C(); +>c : Symbol(c, Decl(2.ts, 2, 7)) +>C : Symbol(C, Decl(2.ts, 0, 22)) + + c.print(); +>c.print : Symbol(B.print, Decl(0.ts, 0, 16)) +>c : Symbol(c, Decl(2.ts, 2, 7)) +>print : Symbol(B.print, Decl(0.ts, 0, 16)) +} +foo(); +>foo : Symbol(foo, Decl(2.ts, 0, 0)) + diff --git a/tests/baselines/reference/importCallExpressionInUMD3.types b/tests/baselines/reference/importCallExpressionInUMD3.types new file mode 100644 index 00000000000..e88ddd04431 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInUMD3.types @@ -0,0 +1,37 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export class B { +>B : B + + print() { return "I am B"} +>print : () => string +>"I am B" : "I am B" +} + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +async function foo() { +>foo : () => Promise + + class C extends (await import("./0")).B {} +>C : C +>(await import("./0")).B : B +>(await import("./0")) : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>await import("./0") : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>import("./0") : Promise +>"./0" : "./0" +>B : typeof B + + var c = new C(); +>c : C +>new C() : C +>C : typeof C + + c.print(); +>c.print() : string +>c.print : () => string +>c : C +>print : () => string +} +foo(); +>foo() : Promise +>foo : () => Promise + diff --git a/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.errors.txt b/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.errors.txt index 8136597ab93..575247b2380 100644 --- a/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.errors.txt +++ b/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.errors.txt @@ -1,12 +1,11 @@ -tests/cases/conformance/es2018/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts(6,8): error TS7035: Dynamic import's specifier must be of type 'string', but here has type 'boolean'. -tests/cases/conformance/es2018/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts(7,17): error TS7035: Dynamic import's specifier must be of type 'string', but here has type 'boolean'. -tests/cases/conformance/es2018/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts(8,19): error TS7035: Dynamic import's specifier must be of type 'string', but here has type 'boolean | "defaulPath"'. -tests/cases/conformance/es2018/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts(13,17): error TS7035: Dynamic import's specifier must be of type 'string', but here has type 'string[]'. -tests/cases/conformance/es2018/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts(14,17): error TS7035: Dynamic import's specifier must be of type 'string', but here has type '() => string'. +tests/cases/conformance/es2018/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts(5,8): error TS7035: Dynamic import's specifier must be of type 'string', but here has type 'boolean'. +tests/cases/conformance/es2018/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts(6,17): error TS7035: Dynamic import's specifier must be of type 'string', but here has type 'boolean'. +tests/cases/conformance/es2018/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts(7,19): error TS7035: Dynamic import's specifier must be of type 'string', but here has type 'boolean | "defaulPath"'. +tests/cases/conformance/es2018/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts(12,17): error TS7035: Dynamic import's specifier must be of type 'string', but here has type 'string[]'. +tests/cases/conformance/es2018/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts(13,17): error TS7035: Dynamic import's specifier must be of type 'string', but here has type '() => string'. ==== tests/cases/conformance/es2018/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts (5 errors) ==== - declare function getSpecifier(): boolean; declare var whatToLoad: boolean; diff --git a/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.js b/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.js index 57e42692d23..5e2ace1c401 100644 --- a/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.js +++ b/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.js @@ -1,5 +1,4 @@ //// [importCallExpressionSpecifierNotStringTypeError.ts] - declare function getSpecifier(): boolean; declare var whatToLoad: boolean; diff --git a/tests/baselines/reference/importCallExpressionWithTypeArgument.errors.txt b/tests/baselines/reference/importCallExpressionWithTypeArgument.errors.txt index d0b17931e2e..f0076f223fd 100644 --- a/tests/baselines/reference/importCallExpressionWithTypeArgument.errors.txt +++ b/tests/baselines/reference/importCallExpressionWithTypeArgument.errors.txt @@ -3,7 +3,6 @@ tests/cases/conformance/es2018/dynamicImport/1.ts(3,10): error TS1323: Dynamic i ==== tests/cases/conformance/es2018/dynamicImport/0.ts (0 errors) ==== - export function foo() { return "foo"; } ==== tests/cases/conformance/es2018/dynamicImport/1.ts (2 errors) ==== diff --git a/tests/baselines/reference/importCallExpressionWithTypeArgument.js b/tests/baselines/reference/importCallExpressionWithTypeArgument.js index 59ad9b6026c..de487bc45cc 100644 --- a/tests/baselines/reference/importCallExpressionWithTypeArgument.js +++ b/tests/baselines/reference/importCallExpressionWithTypeArgument.js @@ -1,7 +1,6 @@ //// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionWithTypeArgument.ts] //// //// [0.ts] - export function foo() { return "foo"; } //// [1.ts] @@ -21,6 +20,3 @@ exports.foo = foo; "use strict"; var p1 = (import)("./0"); // error var p2 = (import)("./0"); // error -// p1.then(value => { -// value.anyFunction(); -// }) From 55430c46e629b40d0dd67e0c07a4e65a61f53443 Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Tue, 4 Apr 2017 15:43:45 -0700 Subject: [PATCH 44/67] Add boolean flag to not walk the tree if there is no dynamic import --- src/compiler/parser.ts | 1 + src/compiler/program.ts | 10 ++++++---- src/compiler/types.ts | 7 +++++++ src/services/services.ts | 1 + 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index c830be85a59..f0d456758a2 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3700,6 +3700,7 @@ namespace ts { // For example: // var foo3 = require("subfolder // import * as foo1 from "module-from-node -> we want this import to be a statement rather than import call expression + sourceFile.possiblyContainDynamicImport = true; expression = parseTokenNode(); } else { diff --git a/src/compiler/program.ts b/src/compiler/program.ts index e69098a21a1..57462cf1947 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1223,7 +1223,9 @@ namespace ts { for (const node of file.statements) { collectModuleReferences(node, /*inAmbientModule*/ false); - collectImportOrRequireCalls(node); + if (file.possiblyContainDynamicImport || isJavaScriptFile) { + collectDynamicImportOrRequireCalls(node); + } } file.imports = imports || emptyArray; @@ -1285,8 +1287,8 @@ namespace ts { } } - function collectImportOrRequireCalls(node: Node): void { - if (isJavaScriptFile && isRequireCall(node, /*checkArgumentIsStringLiteral*/true)) { + function collectDynamicImportOrRequireCalls(node: Node): void { + if (isRequireCall(node, /*checkArgumentIsStringLiteral*/true)) { (imports || (imports = [])).push((node).arguments[0]); } // we have to check the argument list has length of 1. We will still have to process these even though we have parsing error. @@ -1294,7 +1296,7 @@ namespace ts { (imports || (imports = [])).push((node).arguments[0]); } else { - forEachChild(node, collectImportOrRequireCalls); + forEachChild(node, collectDynamicImportOrRequireCalls); } } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index e2006a868bc..2f94510519b 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2309,6 +2309,13 @@ namespace ts { /* @internal */ patternAmbientModules?: PatternAmbientModule[]; /* @internal */ ambientModuleNames: string[]; /* @internal */ checkJsDirective: CheckJsDirective | undefined; + // This flag will be set to true when the parse encounter dynamic import so that post-parsing process of module resolution + // will not walk the tree if the flag is not set. However, this flag is just a approximation because once it is set, the flag never get reset. + // (hence it is named "possiblyContainDynamicImport"). + // During editing, if dynamic import is remove, incremental parsing will *NOT* update this flag. This will then causes walking of the tree during module resolution. + // However, the removal operation should not occur often and in the case of the removal, it is likely that users will add back the import anyway. + // The advantage of this approach is its simplicity. For the case of batch compilation, we garuntee that users won't have to pay the price of walking the tree if dynamic import isn't used. + /* @internal */ possiblyContainDynamicImport: boolean; } export interface Bundle extends Node { diff --git a/src/services/services.ts b/src/services/services.ts index 7086f4471a5..f5e3def6472 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -507,6 +507,7 @@ namespace ts { private namedDeclarations: Map; public ambientModuleNames: string[]; public checkJsDirective: CheckJsDirective | undefined; + public possiblyContainDynamicImport: boolean; constructor(kind: SyntaxKind, pos: number, end: number) { super(kind, pos, end); From 78b8275ab6407c07dbba8a838fea9a64e5fcbd3b Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Tue, 4 Apr 2017 15:43:56 -0700 Subject: [PATCH 45/67] Fix linting error --- src/compiler/checker.ts | 10 +++------- src/compiler/transformers/module/module.ts | 2 +- src/compiler/transformers/module/system.ts | 2 +- src/compiler/types.ts | 2 +- src/compiler/utilities.ts | 2 +- 5 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1205ce278a8..1089e9d2c7d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1,4 +1,4 @@ -/// +/// /// /* @internal */ @@ -15809,7 +15809,7 @@ namespace ts { function createPromiseReturnType(func: FunctionLikeDeclaration | CallExpression, promisedType: Type) { const promiseType = createPromiseType(promisedType); if (promiseType === emptyObjectType) { - error(func, isImportCall(func) ? + error(func, isImportCall(func) ? Diagnostics.A_dynamic_import_call_must_return_a_Promise_Make_sure_you_have_a_declaration_for_Promise_or_include_ES2015_in_your_lib_option : Diagnostics.An_async_function_or_method_must_return_a_Promise_Make_sure_you_have_a_declaration_for_Promise_or_include_ES2015_in_your_lib_option); return unknownType; @@ -15817,7 +15817,7 @@ namespace ts { else if (!getGlobalPromiseConstructorSymbol(/*reportErrors*/ true)) { error(func, isImportCall(func) ? Diagnostics.A_dynamic_import_call_in_ES5_SlashES3_requires_the_Promise_constructor_Make_sure_you_have_a_declaration_for_the_Promise_constructor_or_include_ES2015_in_your_lib_option : - Diagnostics.An_async_function_or_method_in_ES5_SlashES3_requires_the_Promise_constructor_Make_sure_you_have_a_declaration_for_the_Promise_constructor_or_include_ES2015_in_your_lib_option); + Diagnostics.An_async_function_or_method_in_ES5_SlashES3_requires_the_Promise_constructor_Make_sure_you_have_a_declaration_for_the_Promise_constructor_or_include_ES2015_in_your_lib_option); } return promiseType; @@ -24066,10 +24066,6 @@ namespace ts { return result; } - /** - * - * @param node - */ function checkGrammarImportCallExpression(node: ImportCall): boolean { const arguments = node.arguments; if (arguments.length !== 1) { diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index 8ffea8f395c..f9de12f4958 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -558,7 +558,7 @@ namespace ts { createCall(createIdentifier("require"), /*typeArguments*/ undefined, [createArrayLiteral(node.arguments), resolve])) ]); } - + function transformImportCallExpressionCommonJS(node: ImportCall): Expression { // import("./blah") // emit as diff --git a/src/compiler/transformers/module/system.ts b/src/compiler/transformers/module/system.ts index f5505016b9f..1e3b2dd4350 100644 --- a/src/compiler/transformers/module/system.ts +++ b/src/compiler/transformers/module/system.ts @@ -1488,7 +1488,7 @@ namespace ts { // } // }; // }); - return createCall( + return createCall( createPropertyAccess( contextObject, createIdentifier("import") diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 2f94510519b..0b51f7e2173 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1052,7 +1052,7 @@ namespace ts { } export interface ImportExpression extends PrimaryExpression { - kind: SyntaxKind.ImportKeyword + kind: SyntaxKind.ImportKeyword; } export interface DeleteExpression extends UnaryExpression { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 40ff1a063f2..f4a1e0216b9 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -3906,7 +3906,7 @@ namespace ts { || kind === SyntaxKind.TrueKeyword || kind === SyntaxKind.SuperKeyword || kind === SyntaxKind.NonNullExpression - || kind === SyntaxKind.MetaProperty + || kind === SyntaxKind.MetaProperty; } export function isLeftHandSideExpression(node: Node): node is LeftHandSideExpression { From d1d5cac9002636214aed8d8811804fddeed2e993 Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Thu, 6 Apr 2017 09:01:20 -0700 Subject: [PATCH 46/67] Address PR: Remove duplication --- src/compiler/types.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 0b51f7e2173..ddb32e284f8 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1,4 +1,4 @@ -namespace ts { +namespace ts { /** * Type of objects whose values are all of the same type. * The `in` and `for-in` operators can *not* be safely used, @@ -1451,10 +1451,6 @@ namespace ts { expression: SuperExpression; } - export interface ImportExpression extends PrimaryExpression { - kind: SyntaxKind.ImportKeyword; - } - export interface ImportCall extends CallExpression { expression: ImportExpression; } From 2b96374a18787aba5f065acbd972a09074e1bf28 Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Thu, 6 Apr 2017 09:17:29 -0700 Subject: [PATCH 47/67] fix no-bom linting rule --- src/compiler/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/types.ts b/src/compiler/types.ts index ddb32e284f8..8272c4252a1 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1,4 +1,4 @@ -namespace ts { +namespace ts { /** * Type of objects whose values are all of the same type. * The `in` and `for-in` operators can *not* be safely used, From 2f61d472ed043f7efdfc4476d4a5e8fc7009f7aa Mon Sep 17 00:00:00 2001 From: Yui T Date: Wed, 26 Apr 2017 12:56:15 -0700 Subject: [PATCH 48/67] Address minor PR comment --- src/compiler/parser.ts | 8 ++++---- src/compiler/program.ts | 2 +- src/compiler/types.ts | 27 ++++++++++++++++----------- src/services/services.ts | 2 +- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index f0d456758a2..2293934baf1 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3517,10 +3517,10 @@ namespace ts { * 5) --UnaryExpression[?Yield] */ if (isUpdateExpression()) { - const UpdateExpression = parseUpdateExpression(); + const updateExpression = parseUpdateExpression(); return token() === SyntaxKind.AsteriskAsteriskToken ? - parseBinaryExpressionRest(getBinaryOperatorPrecedence(), UpdateExpression) : - UpdateExpression; + parseBinaryExpressionRest(getBinaryOperatorPrecedence(), updateExpression) : + updateExpression; } /** @@ -3700,7 +3700,7 @@ namespace ts { // For example: // var foo3 = require("subfolder // import * as foo1 from "module-from-node -> we want this import to be a statement rather than import call expression - sourceFile.possiblyContainDynamicImport = true; + sourceFile.flags |= NodeFlags.possiblyContainDynamicImport; expression = parseTokenNode(); } else { diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 57462cf1947..04acf667343 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1223,7 +1223,7 @@ namespace ts { for (const node of file.statements) { collectModuleReferences(node, /*inAmbientModule*/ false); - if (file.possiblyContainDynamicImport || isJavaScriptFile) { + if ((file.flags & NodeFlags.possiblyContainDynamicImport) || isJavaScriptFile) { collectDynamicImportOrRequireCalls(node); } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 8272c4252a1..b5187a123cb 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -448,6 +448,14 @@ namespace ts { ThisNodeOrAnySubNodesHasError = 1 << 17, // If this node or any of its children had an error HasAggregatedChildData = 1 << 18, // If we've computed data from children and cached it in this node + // This flag will be set to true when the parse encounter dynamic import so that post-parsing process of module resolution + // will not walk the tree if the flag is not set. However, this flag is just a approximation because once it is set, the flag never get reset. + // (hence it is named "possiblyContainDynamicImport"). + // During editing, if dynamic import is remove, incremental parsing will *NOT* update this flag. This will then causes walking of the tree during module resolution. + // However, the removal operation should not occur often and in the case of the removal, it is likely that users will add back the import anyway. + // The advantage of this approach is its simplicity. For the case of batch compilation, we garuntee that users won't have to pay the price of walking the tree if dynamic import isn't used. + possiblyContainDynamicImport = 1 << 19, + BlockScoped = Let | Const, ReachabilityCheckFlags = HasImplicitReturn | HasExplicitReturn, @@ -990,8 +998,10 @@ namespace ts { _unaryExpressionBrand: any; } + /** Deprecated, please use UpdateExpression */ + export type IncrementExpression = UpdateExpression; export interface UpdateExpression extends UnaryExpression { - _incrementExpressionBrand: any; + _updateExpressionBrand: any; } // see: https://tc39.github.io/ecma262/#prod-UpdateExpression @@ -1002,8 +1012,7 @@ namespace ts { | SyntaxKind.PlusToken | SyntaxKind.MinusToken | SyntaxKind.TildeToken - | SyntaxKind.ExclamationToken - ; + | SyntaxKind.ExclamationToken; export interface PrefixUnaryExpression extends UpdateExpression { kind: SyntaxKind.PrefixUnaryExpression; @@ -2305,13 +2314,6 @@ namespace ts { /* @internal */ patternAmbientModules?: PatternAmbientModule[]; /* @internal */ ambientModuleNames: string[]; /* @internal */ checkJsDirective: CheckJsDirective | undefined; - // This flag will be set to true when the parse encounter dynamic import so that post-parsing process of module resolution - // will not walk the tree if the flag is not set. However, this flag is just a approximation because once it is set, the flag never get reset. - // (hence it is named "possiblyContainDynamicImport"). - // During editing, if dynamic import is remove, incremental parsing will *NOT* update this flag. This will then causes walking of the tree during module resolution. - // However, the removal operation should not occur often and in the case of the removal, it is likely that users will add back the import anyway. - // The advantage of this approach is its simplicity. For the case of batch compilation, we garuntee that users won't have to pay the price of walking the tree if dynamic import isn't used. - /* @internal */ possiblyContainDynamicImport: boolean; } export interface Bundle extends Node { @@ -3866,7 +3868,10 @@ namespace ts { ContainsDynamicImport = 1 << 26, - HasComputedFlags = 1 << 27, // Transform flags have been computed. + // Please leave this as 1 << 29. + // It is the maximum bit we can set before we outgrow the size of a v8 small integer (SMI) on an x86 system. + // It is a good reminder of how much room we have left + HasComputedFlags = 1 << 29, // Transform flags have been computed. // Assertions // - Bitmasks that are used to assert facts about the syntax of a node and its subtree. diff --git a/src/services/services.ts b/src/services/services.ts index f5e3def6472..9b5ddc6fbe8 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -355,7 +355,7 @@ namespace ts { _primaryExpressionBrand: any; _memberExpressionBrand: any; _leftHandSideExpressionBrand: any; - _incrementExpressionBrand: any; + _updateExpressionBrand: any; _unaryExpressionBrand: any; _expressionBrand: any; constructor(_kind: SyntaxKind.Identifier, pos: number, end: number) { From a10e668c3409c89960f4cb8b91be098481e65cdf Mon Sep 17 00:00:00 2001 From: Yui T Date: Wed, 26 Apr 2017 14:16:44 -0700 Subject: [PATCH 49/67] Move check for module kind is ES2015 into grammar check; Use checkNonNullExpression and add tests --- src/compiler/checker.ts | 10 +++--- .../importCallExpression5ES2018.errors.txt | 31 +++++++++++++++++ .../reference/importCallExpression5ES2018.js | 33 +++++++++++++++++++ .../importCallExpression6ES2018.errors.txt | 25 ++++++++++++++ .../reference/importCallExpression6ES2018.js | 33 +++++++++++++++++++ .../importCallExpression5ES2018.ts | 20 +++++++++++ .../importCallExpression6ES2018.ts | 19 +++++++++++ 7 files changed, 166 insertions(+), 5 deletions(-) create mode 100644 tests/baselines/reference/importCallExpression5ES2018.errors.txt create mode 100644 tests/baselines/reference/importCallExpression5ES2018.js create mode 100644 tests/baselines/reference/importCallExpression6ES2018.errors.txt create mode 100644 tests/baselines/reference/importCallExpression6ES2018.js create mode 100644 tests/cases/conformance/es2018/dynamicImport/importCallExpression5ES2018.ts create mode 100644 tests/cases/conformance/es2018/dynamicImport/importCallExpression6ES2018.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1089e9d2c7d..8eb163e7aa8 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -15580,12 +15580,8 @@ namespace ts { return createPromiseReturnType(node, anyType); } - if (modulekind === ModuleKind.ES2015) { - grammarErrorOnNode(node, Diagnostics.Dynamic_import_cannot_be_used_when_targeting_ECMAScript_2015_modules); - } - const specifier = node.arguments[0]; - const specifierType = checkExpression(specifier); + const specifierType = checkNonNullExpression(specifier); if (!isTypeAssignableTo(specifierType, stringType)) { error(specifier, Diagnostics.Dynamic_import_s_specifier_must_be_of_type_string_but_here_has_type_0, typeToString(specifierType)); } @@ -24081,6 +24077,10 @@ namespace ts { if (isSpreadExpression(arguments[0])) { return grammarErrorOnNode(arguments[0], Diagnostics.Specifier_of_dynamic_import_cannot_be_spread_element); } + + if (modulekind === ModuleKind.ES2015) { + grammarErrorOnNode(node, Diagnostics.Dynamic_import_cannot_be_used_when_targeting_ECMAScript_2015_modules); + } } } } \ No newline at end of file diff --git a/tests/baselines/reference/importCallExpression5ES2018.errors.txt b/tests/baselines/reference/importCallExpression5ES2018.errors.txt new file mode 100644 index 00000000000..372fda0a685 --- /dev/null +++ b/tests/baselines/reference/importCallExpression5ES2018.errors.txt @@ -0,0 +1,31 @@ +tests/cases/conformance/es2018/dynamicImport/2.ts(3,23): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/es2018/dynamicImport/2.ts(4,24): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/es2018/dynamicImport/2.ts(5,24): error TS2531: Object is possibly 'null'. +tests/cases/conformance/es2018/dynamicImport/2.ts(6,24): error TS2531: Object is possibly 'null'. + + +==== tests/cases/conformance/es2018/dynamicImport/0.ts (0 errors) ==== + export class B { + print() { return "I am B"} + } + + export function foo() { return "foo" } + +==== tests/cases/conformance/es2018/dynamicImport/1.ts (0 errors) ==== + export function backup() { return "backup"; } + +==== tests/cases/conformance/es2018/dynamicImport/2.ts (4 errors) ==== + declare function bar(): boolean; + const specify = bar() ? "./0" : undefined; + let myModule = import(specify); + ~~~~~~~ +!!! error TS2532: Object is possibly 'undefined'. + let myModule1 = import(undefined); + ~~~~~~~~~ +!!! error TS2532: Object is possibly 'undefined'. + let myModule2 = import(bar() ? "./1" : null); + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2531: Object is possibly 'null'. + let myModule3 = import(null); + ~~~~ +!!! error TS2531: Object is possibly 'null'. \ No newline at end of file diff --git a/tests/baselines/reference/importCallExpression5ES2018.js b/tests/baselines/reference/importCallExpression5ES2018.js new file mode 100644 index 00000000000..802988cedbc --- /dev/null +++ b/tests/baselines/reference/importCallExpression5ES2018.js @@ -0,0 +1,33 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpression5ES2018.ts] //// + +//// [0.ts] +export class B { + print() { return "I am B"} +} + +export function foo() { return "foo" } + +//// [1.ts] +export function backup() { return "backup"; } + +//// [2.ts] +declare function bar(): boolean; +const specify = bar() ? "./0" : undefined; +let myModule = import(specify); +let myModule1 = import(undefined); +let myModule2 = import(bar() ? "./1" : null); +let myModule3 = import(null); + +//// [0.js] +export class B { + print() { return "I am B"; } +} +export function foo() { return "foo"; } +//// [1.js] +export function backup() { return "backup"; } +//// [2.js] +const specify = bar() ? "./0" : undefined; +let myModule = import(specify); +let myModule1 = import(undefined); +let myModule2 = import(bar() ? "./1" : null); +let myModule3 = import(null); diff --git a/tests/baselines/reference/importCallExpression6ES2018.errors.txt b/tests/baselines/reference/importCallExpression6ES2018.errors.txt new file mode 100644 index 00000000000..33f93ef4d39 --- /dev/null +++ b/tests/baselines/reference/importCallExpression6ES2018.errors.txt @@ -0,0 +1,25 @@ +tests/cases/conformance/es2018/dynamicImport/2.ts(4,24): error TS2532: Object is possibly 'undefined'. +tests/cases/conformance/es2018/dynamicImport/2.ts(6,24): error TS2531: Object is possibly 'null'. + + +==== tests/cases/conformance/es2018/dynamicImport/0.ts (0 errors) ==== + export class B { + print() { return "I am B"} + } + + export function foo() { return "foo" } + +==== tests/cases/conformance/es2018/dynamicImport/1.ts (0 errors) ==== + export function backup() { return "backup"; } + +==== tests/cases/conformance/es2018/dynamicImport/2.ts (2 errors) ==== + declare function bar(): boolean; + const specify = bar() ? "./0" : undefined; + let myModule = import(specify); + let myModule1 = import(undefined); + ~~~~~~~~~ +!!! error TS2532: Object is possibly 'undefined'. + let myModule2 = import(bar() ? "./1" : null); + let myModule3 = import(null); + ~~~~ +!!! error TS2531: Object is possibly 'null'. \ No newline at end of file diff --git a/tests/baselines/reference/importCallExpression6ES2018.js b/tests/baselines/reference/importCallExpression6ES2018.js new file mode 100644 index 00000000000..cde74278f33 --- /dev/null +++ b/tests/baselines/reference/importCallExpression6ES2018.js @@ -0,0 +1,33 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpression6ES2018.ts] //// + +//// [0.ts] +export class B { + print() { return "I am B"} +} + +export function foo() { return "foo" } + +//// [1.ts] +export function backup() { return "backup"; } + +//// [2.ts] +declare function bar(): boolean; +const specify = bar() ? "./0" : undefined; +let myModule = import(specify); +let myModule1 = import(undefined); +let myModule2 = import(bar() ? "./1" : null); +let myModule3 = import(null); + +//// [0.js] +export class B { + print() { return "I am B"; } +} +export function foo() { return "foo"; } +//// [1.js] +export function backup() { return "backup"; } +//// [2.js] +const specify = bar() ? "./0" : undefined; +let myModule = import(specify); +let myModule1 = import(undefined); +let myModule2 = import(bar() ? "./1" : null); +let myModule3 = import(null); diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpression5ES2018.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpression5ES2018.ts new file mode 100644 index 00000000000..254e99f3907 --- /dev/null +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpression5ES2018.ts @@ -0,0 +1,20 @@ +// @module: es2018 +// @target: esnext +// @strictNullChecks: true +// @filename: 0.ts +export class B { + print() { return "I am B"} +} + +export function foo() { return "foo" } + +// @filename: 1.ts +export function backup() { return "backup"; } + +// @filename: 2.ts +declare function bar(): boolean; +const specify = bar() ? "./0" : undefined; +let myModule = import(specify); +let myModule1 = import(undefined); +let myModule2 = import(bar() ? "./1" : null); +let myModule3 = import(null); \ No newline at end of file diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpression6ES2018.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpression6ES2018.ts new file mode 100644 index 00000000000..8c1a1071fbc --- /dev/null +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpression6ES2018.ts @@ -0,0 +1,19 @@ +// @module: es2018 +// @target: esnext +// @filename: 0.ts +export class B { + print() { return "I am B"} +} + +export function foo() { return "foo" } + +// @filename: 1.ts +export function backup() { return "backup"; } + +// @filename: 2.ts +declare function bar(): boolean; +const specify = bar() ? "./0" : undefined; +let myModule = import(specify); +let myModule1 = import(undefined); +let myModule2 = import(bar() ? "./1" : null); +let myModule3 = import(null); \ No newline at end of file From e50667e49e82961288a40e810c470492357b60ba Mon Sep 17 00:00:00 2001 From: Yui T Date: Wed, 26 Apr 2017 15:02:54 -0700 Subject: [PATCH 50/67] Address minor PR comment --- src/compiler/checker.ts | 3 ++- src/compiler/parser.ts | 9 ++------- src/compiler/program.ts | 4 ++++ 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 8eb163e7aa8..10d96581656 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -17134,10 +17134,11 @@ namespace ts { case SyntaxKind.ElementAccessExpression: return checkIndexedAccess(node); case SyntaxKind.CallExpression: - case SyntaxKind.NewExpression: if ((node).expression.kind === SyntaxKind.ImportKeyword) { return checkImportCallExpression(node); } + // Fall through + case SyntaxKind.NewExpression: return checkCallExpression(node); case SyntaxKind.TaggedTemplateExpression: return checkTaggedTemplateExpression(node); diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 2293934baf1..f5577c4b908 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2416,7 +2416,7 @@ namespace ts { if (token() === SyntaxKind.OpenParenToken || token() === SyntaxKind.LessThanToken) { return parseSignatureMember(SyntaxKind.CallSignature); } - if (token() === SyntaxKind.NewKeyword && lookAhead(isStartOfConstructSignature)) { + if (token() === SyntaxKind.NewKeyword && lookAhead(nextTokenIsOpenParenOrLessThan)) { return parseSignatureMember(SyntaxKind.ConstructSignature); } const fullStart = getNodePos(); @@ -2427,7 +2427,7 @@ namespace ts { return parsePropertyOrMethodSignature(fullStart, modifiers); } - function isStartOfConstructSignature() { + function nextTokenIsOpenParenOrLessThan() { nextToken(); return token() === SyntaxKind.OpenParenToken || token() === SyntaxKind.LessThanToken; } @@ -5619,11 +5619,6 @@ namespace ts { return nextToken() === SyntaxKind.OpenParenToken; } - function nextTokenIsOpenParenOrLessThan() { - const next = nextToken(); - return next === SyntaxKind.OpenParenToken || next === SyntaxKind.LessThanToken; - } - function nextTokenIsSlash() { return nextToken() === SyntaxKind.SlashToken; } diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 04acf667343..05dc96cf5cb 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1199,6 +1199,10 @@ namespace ts { } function collectExternalModuleReferences(file: SourceFile): void { + if (file.imports) { + return; + } + const isJavaScriptFile = isSourceFileJavaScript(file); const isExternalModuleFile = isExternalModule(file); const isDtsFile = isDeclarationFile(file); From 742d5150a55fc5b9b3fb41685c18a17d152f18fc Mon Sep 17 00:00:00 2001 From: Yui T Date: Wed, 26 Apr 2017 15:38:58 -0700 Subject: [PATCH 51/67] Fix baselines and function call from merging master --- src/compiler/checker.ts | 4 ++-- ...portCallExpressionErrorInES2015.errors.txt | 12 +++++------ ...mportCallExpressionGrammarError.errors.txt | 16 +++++++-------- ...sionSpecifierNotStringTypeError.errors.txt | 20 +++++++++---------- ...tCallExpressionWithTypeArgument.errors.txt | 8 ++++---- 5 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index cb3962ae4e0..9a2a07f53c1 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -15701,7 +15701,7 @@ namespace ts { // resolveExternalModuleName will return undefined if the moduleReferenceExpression is not a string literal const moduleSymbol = resolveExternalModuleName(node, specifier); if (moduleSymbol) { - const esModuleSymbol = resolveESModuleSymbol(moduleSymbol, specifier); + const esModuleSymbol = resolveESModuleSymbol(moduleSymbol, specifier, /*dontRecursivelyResolve*/ true); if (esModuleSymbol) { return createPromiseReturnType(node, getTypeOfSymbol(esModuleSymbol)); } @@ -17284,7 +17284,7 @@ namespace ts { if ((node).expression.kind === SyntaxKind.ImportKeyword) { return checkImportCallExpression(node); } - // Fall through + /* tslint:disable: no-switch-case-fall-through */ case SyntaxKind.NewExpression: return checkCallExpression(node); case SyntaxKind.TaggedTemplateExpression: diff --git a/tests/baselines/reference/importCallExpressionErrorInES2015.errors.txt b/tests/baselines/reference/importCallExpressionErrorInES2015.errors.txt index ccd867f831c..0c31a0f434c 100644 --- a/tests/baselines/reference/importCallExpressionErrorInES2015.errors.txt +++ b/tests/baselines/reference/importCallExpressionErrorInES2015.errors.txt @@ -1,6 +1,6 @@ -tests/cases/conformance/es2018/dynamicImport/1.ts(1,1): error TS1320: Dynamic import cannot be used when targeting ECMAScript 2015 modules. -tests/cases/conformance/es2018/dynamicImport/1.ts(2,10): error TS1320: Dynamic import cannot be used when targeting ECMAScript 2015 modules. -tests/cases/conformance/es2018/dynamicImport/1.ts(8,16): error TS1320: Dynamic import cannot be used when targeting ECMAScript 2015 modules. +tests/cases/conformance/es2018/dynamicImport/1.ts(1,1): error TS1323: Dynamic import cannot be used when targeting ECMAScript 2015 modules. +tests/cases/conformance/es2018/dynamicImport/1.ts(2,10): error TS1323: Dynamic import cannot be used when targeting ECMAScript 2015 modules. +tests/cases/conformance/es2018/dynamicImport/1.ts(8,16): error TS1323: Dynamic import cannot be used when targeting ECMAScript 2015 modules. ==== tests/cases/conformance/es2018/dynamicImport/0.ts (0 errors) ==== @@ -9,10 +9,10 @@ tests/cases/conformance/es2018/dynamicImport/1.ts(8,16): error TS1320: Dynamic i ==== tests/cases/conformance/es2018/dynamicImport/1.ts (3 errors) ==== import("./0"); ~~~~~~~~~~~~~ -!!! error TS1320: Dynamic import cannot be used when targeting ECMAScript 2015 modules. +!!! error TS1323: Dynamic import cannot be used when targeting ECMAScript 2015 modules. var p1 = import("./0"); ~~~~~~~~~~~~~ -!!! error TS1320: Dynamic import cannot be used when targeting ECMAScript 2015 modules. +!!! error TS1323: Dynamic import cannot be used when targeting ECMAScript 2015 modules. p1.then(zero => { return zero.foo(); }) @@ -20,5 +20,5 @@ tests/cases/conformance/es2018/dynamicImport/1.ts(8,16): error TS1320: Dynamic i function foo() { const p2 = import("./0"); ~~~~~~~~~~~~~ -!!! error TS1320: Dynamic import cannot be used when targeting ECMAScript 2015 modules. +!!! error TS1323: Dynamic import cannot be used when targeting ECMAScript 2015 modules. } \ No newline at end of file diff --git a/tests/baselines/reference/importCallExpressionGrammarError.errors.txt b/tests/baselines/reference/importCallExpressionGrammarError.errors.txt index c089452be3b..c4c62b8ff8f 100644 --- a/tests/baselines/reference/importCallExpressionGrammarError.errors.txt +++ b/tests/baselines/reference/importCallExpressionGrammarError.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts(5,8): error TS1322: Specifier of dynamic import cannot be spread element. -tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts(7,17): error TS1322: Specifier of dynamic import cannot be spread element. -tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts(8,12): error TS1321: Dynamic import must have one specifier as an argument. +tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts(5,8): error TS1325: Specifier of dynamic import cannot be spread element. +tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts(7,17): error TS1325: Specifier of dynamic import cannot be spread element. +tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts(8,12): error TS1324: Dynamic import must have one specifier as an argument. tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts(9,19): error TS1135: Argument expression expected. -tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts(10,12): error TS1321: Dynamic import must have one specifier as an argument. +tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts(10,12): error TS1324: Dynamic import must have one specifier as an argument. ==== tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts (5 errors) ==== @@ -12,17 +12,17 @@ tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts var a = ["./0"]; import(...["PathModule"]); ~~~~~~~~~~~~~~~~~ -!!! error TS1322: Specifier of dynamic import cannot be spread element. +!!! error TS1325: Specifier of dynamic import cannot be spread element. var p1 = import(...a); ~~~~ -!!! error TS1322: Specifier of dynamic import cannot be spread element. +!!! error TS1325: Specifier of dynamic import cannot be spread element. const p2 = import(); ~~~~~~~~ -!!! error TS1321: Dynamic import must have one specifier as an argument. +!!! error TS1324: Dynamic import must have one specifier as an argument. const p3 = import(,); !!! error TS1135: Argument expression expected. const p4 = import("pathToModule", "secondModule"); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1321: Dynamic import must have one specifier as an argument. \ No newline at end of file +!!! error TS1324: Dynamic import must have one specifier as an argument. \ No newline at end of file diff --git a/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.errors.txt b/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.errors.txt index 575247b2380..dd705582827 100644 --- a/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.errors.txt +++ b/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/es2018/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts(5,8): error TS7035: Dynamic import's specifier must be of type 'string', but here has type 'boolean'. -tests/cases/conformance/es2018/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts(6,17): error TS7035: Dynamic import's specifier must be of type 'string', but here has type 'boolean'. -tests/cases/conformance/es2018/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts(7,19): error TS7035: Dynamic import's specifier must be of type 'string', but here has type 'boolean | "defaulPath"'. -tests/cases/conformance/es2018/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts(12,17): error TS7035: Dynamic import's specifier must be of type 'string', but here has type 'string[]'. -tests/cases/conformance/es2018/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts(13,17): error TS7035: Dynamic import's specifier must be of type 'string', but here has type '() => string'. +tests/cases/conformance/es2018/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts(5,8): error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'boolean'. +tests/cases/conformance/es2018/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts(6,17): error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'boolean'. +tests/cases/conformance/es2018/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts(7,19): error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'boolean | "defaulPath"'. +tests/cases/conformance/es2018/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts(12,17): error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'string[]'. +tests/cases/conformance/es2018/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts(13,17): error TS7036: Dynamic import's specifier must be of type 'string', but here has type '() => string'. ==== tests/cases/conformance/es2018/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts (5 errors) ==== @@ -12,20 +12,20 @@ tests/cases/conformance/es2018/dynamicImport/importCallExpressionSpecifierNotStr // Error specifier is not assignable to string import(getSpecifier()); ~~~~~~~~~~~~~~ -!!! error TS7035: Dynamic import's specifier must be of type 'string', but here has type 'boolean'. +!!! error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'boolean'. var p1 = import(getSpecifier()); ~~~~~~~~~~~~~~ -!!! error TS7035: Dynamic import's specifier must be of type 'string', but here has type 'boolean'. +!!! error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'boolean'. const p2 = import(whatToLoad ? getSpecifier() : "defaulPath") ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS7035: Dynamic import's specifier must be of type 'string', but here has type 'boolean | "defaulPath"'. +!!! error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'boolean | "defaulPath"'. p1.then(zero => { return zero.foo(); // ok, zero is any }); var p3 = import(["path1", "path2"]); ~~~~~~~~~~~~~~~~~~ -!!! error TS7035: Dynamic import's specifier must be of type 'string', but here has type 'string[]'. +!!! error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'string[]'. var p4 = import(()=>"PathToModule"); ~~~~~~~~~~~~~~~~~~ -!!! error TS7035: Dynamic import's specifier must be of type 'string', but here has type '() => string'. \ No newline at end of file +!!! error TS7036: Dynamic import's specifier must be of type 'string', but here has type '() => string'. \ No newline at end of file diff --git a/tests/baselines/reference/importCallExpressionWithTypeArgument.errors.txt b/tests/baselines/reference/importCallExpressionWithTypeArgument.errors.txt index f0076f223fd..f9375ec695f 100644 --- a/tests/baselines/reference/importCallExpressionWithTypeArgument.errors.txt +++ b/tests/baselines/reference/importCallExpressionWithTypeArgument.errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/es2018/dynamicImport/1.ts(2,10): error TS1323: Dynamic import cannot have type arguments -tests/cases/conformance/es2018/dynamicImport/1.ts(3,10): error TS1323: Dynamic import cannot have type arguments +tests/cases/conformance/es2018/dynamicImport/1.ts(2,10): error TS1326: Dynamic import cannot have type arguments +tests/cases/conformance/es2018/dynamicImport/1.ts(3,10): error TS1326: Dynamic import cannot have type arguments ==== tests/cases/conformance/es2018/dynamicImport/0.ts (0 errors) ==== @@ -9,10 +9,10 @@ tests/cases/conformance/es2018/dynamicImport/1.ts(3,10): error TS1323: Dynamic i "use strict" var p1 = import>("./0"); // error ~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1323: Dynamic import cannot have type arguments +!!! error TS1326: Dynamic import cannot have type arguments var p2 = import<>("./0"); // error ~~~~~~~~~~~~~~~ -!!! error TS1323: Dynamic import cannot have type arguments +!!! error TS1326: Dynamic import cannot have type arguments // p1.then(value => { // value.anyFunction(); // }) \ No newline at end of file From 35e22899513f66bd3b0503ddcd4e11611dace706 Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Fri, 28 Apr 2017 15:39:54 -0700 Subject: [PATCH 52/67] Address PR: don't use Promise.resolve, capture reject in AMD require callback, create helper for UMD don't use arrow function --- src/compiler/transformers/module/module.ts | 79 +++++++++++++++------- 1 file changed, 56 insertions(+), 23 deletions(-) diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index 54623e5085e..70e85cfa678 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -46,6 +46,7 @@ namespace ts { let currentSourceFile: SourceFile; // The current file. let currentModuleInfo: ExternalModuleInfo; // The ExternalModuleInfo for the current file. let noSubstitution: boolean[]; // Set of nodes for which substitution rules should be ignored. + let needUMDDynamicImportHelper: boolean; return transformSourceFile; @@ -66,9 +67,9 @@ namespace ts { // Perform the transformation. const transformModule = getTransformModuleDelegate(moduleKind); const updated = transformModule(node); - currentSourceFile = undefined; currentModuleInfo = undefined; + needUMDDynamicImportHelper = false; return aggregateTransformFlags(updated); } @@ -107,6 +108,7 @@ namespace ts { // we need to inform the emitter to add the __export helper. addEmitHelper(updated, exportStarHelper); } + addEmitHelpers(updated, context.readEmitHelpers()); return updated; } @@ -411,6 +413,9 @@ namespace ts { // we need to inform the emitter to add the __export helper. addEmitHelper(body, exportStarHelper); } + if (needUMDDynamicImportHelper) { + addEmitHelper(body, dynamicImportUMDHelper); + } return body; } @@ -526,13 +531,16 @@ namespace ts { // })(function (require, exports, useSyncRequire) { // "use strict"; // Object.defineProperty(exports, "__esModule", { value: true }); - // require.length === 1 ? - // /*CommonJs Require*/ Promise.resolve().then(() => require('blah')); - // /*Amd Require*/ new Promise(resolve => require(['blah'], resolve)); + // var __syncRequire = typeof module === "object" && typeof module.exports === "object"; + // var __resolved = new Promise(function (resolve) { resolve(); }); + // ..... + // __syncRequire + // ? __resolved.then(function () { return require(x); }) /*CommonJs Require*/ + // : new Promise(function (_a, _b) { require([x], _a, _b); }); /*Amd Require*/ // }); - const require = createIdentifier("require"); + needUMDDynamicImportHelper = true; return createConditional( - /*condition*/ createBinary(createPropertyAccess(require, /*name*/ "length"), /*operator*/ createToken(SyntaxKind.EqualsEqualsEqualsToken), createNumericLiteral("1")), + /*condition*/ createIdentifier("__syncRequire"), /*whenTrue*/ transformImportCallExpressionCommonJS(node), /*whenFalse*/ transformImportCallExpressionAMD(node) ); @@ -543,43 +551,52 @@ namespace ts { // emit as // define(["require", "exports", "blah"], function (require, exports) { // ... - // new Promise(resolve => require(['blah'], resolve)); + // new Promise(function (_a, _b) { require([x], _a, _b); }); /*Amd Require*/ // }); - const resolve = createIdentifier("resolve"); + const resolve = createIdentifier("_a"); + const reject = createIdentifier("_b"); return createNew( createIdentifier("Promise"), /*typeArguments*/ undefined, - [createArrowFunction( - /*modifiers*/undefined, + [createFunctionExpression( + /*modifiers*/ undefined, + /*asteriskToken*/ undefined, + /*name*/ undefined, /*typeParameters*/ undefined, - [createParameter(/*decorator*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, /*name*/ resolve)], + [createParameter(/*decorator*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, /*name*/ resolve), + createParameter(/*decorator*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, /*name*/ reject)], /*type*/ undefined, - createToken(SyntaxKind.EqualsGreaterThanToken), - createCall(createIdentifier("require"), /*typeArguments*/ undefined, [createArrayLiteral(node.arguments), resolve])) - ]); + createBlock([createStatement( + createCall( + createIdentifier("require"), + /*typeArguments*/ undefined, + [createArrayLiteral(node.arguments), resolve, reject] + ))]) + )]); } function transformImportCallExpressionCommonJS(node: ImportCall): Expression { // import("./blah") // emit as + // var __resolved = new Promise(function (resolve) { resolve(); }); + // .... + // __resolved.then(function () { return require(x); }) /*CommonJs Require*/ + // Promise.resolve().then(() => require("./blah")); // We have to wrap require in then callback so that require is done in asynchronously // if we simply do require in resolve callback in Promise constructor. We will execute the loading immediately + context.requestEmitHelper(dynamicImportCreateResolvedHelper); return createCall( - createPropertyAccess( - createCall( - createPropertyAccess(createIdentifier("Promise"), "resolve"), - /*typeArguments*/ undefined, - /*argumentsArray*/[] - ), "then"), + createPropertyAccess(createIdentifier("__resolved"), "then"), /*typeArguments*/ undefined, - [createArrowFunction( + [createFunctionExpression( /*modifiers*/ undefined, + /*asteriskToken*/ undefined, + /*name*/ undefined, /*typeParameters*/ undefined, /*parameters*/ undefined, /*type*/ undefined, - createToken(SyntaxKind.EqualsGreaterThanToken), - createCall(createIdentifier("require"), /*typeArguments*/ undefined, node.arguments) + createBlock([createReturn(createCall(createIdentifier("require"), /*typeArguments*/ undefined, node.arguments))]) )]); } @@ -1586,4 +1603,20 @@ namespace ts { for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; }` }; + + // emit helper for dynamic import + const dynamicImportUMDHelper: EmitHelper = { + name: "typescript:dynamicimport-sync-require", + scoped: true, + text: ` + var __syncRequire = typeof module === "object" && typeof module.exports === "object"; + var __resolved = new Promise(function (resolve) { resolve(); });` + }; + + const dynamicImportCreateResolvedHelper: EmitHelper = { + name: "typescript:dynamicimport-create-resolved", + scoped: false, + priority: 1, + text: `var __resolved = new Promise(function (resolve) { resolve(); });` + }; } From a2d9fd4ac7e93a70ad0616376cbdd65b7c304d2f Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Fri, 28 Apr 2017 15:40:21 -0700 Subject: [PATCH 53/67] Add target ES5 emit --- .../dynamicImport/importCallExpressionES5AMD.ts | 15 +++++++++++++++ .../dynamicImport/importCallExpressionES5CJS.ts | 15 +++++++++++++++ .../importCallExpressionES5System.ts | 15 +++++++++++++++ .../dynamicImport/importCallExpressionES5UMD.ts | 15 +++++++++++++++ 4 files changed, 60 insertions(+) create mode 100644 tests/cases/conformance/es2018/dynamicImport/importCallExpressionES5AMD.ts create mode 100644 tests/cases/conformance/es2018/dynamicImport/importCallExpressionES5CJS.ts create mode 100644 tests/cases/conformance/es2018/dynamicImport/importCallExpressionES5System.ts create mode 100644 tests/cases/conformance/es2018/dynamicImport/importCallExpressionES5UMD.ts diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionES5AMD.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionES5AMD.ts new file mode 100644 index 00000000000..f44ce0e6e13 --- /dev/null +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionES5AMD.ts @@ -0,0 +1,15 @@ +// @module: amd +// @target: es5 +// @filename: 0.ts +export function foo() { return "foo"; } + +// @filename: 1.ts +import("./0"); +var p1 = import("./0"); +p1.then(zero => { + return zero.foo(); +}); + +function foo() { + const p2 = import("./0"); +} \ No newline at end of file diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionES5CJS.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionES5CJS.ts new file mode 100644 index 00000000000..e1457017552 --- /dev/null +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionES5CJS.ts @@ -0,0 +1,15 @@ +// @module: commonjs +// @target: esnext +// @filename: 0.ts +export function foo() { return "foo"; } + +// @filename: 1.ts +import("./0"); +var p1 = import("./0"); +p1.then(zero => { + return zero.foo(); +}); + +function foo() { + const p2 = import("./0"); +} \ No newline at end of file diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionES5System.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionES5System.ts new file mode 100644 index 00000000000..a69e844c7a7 --- /dev/null +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionES5System.ts @@ -0,0 +1,15 @@ +// @module: system +// @target: esnext +// @filename: 0.ts +export function foo() { return "foo"; } + +// @filename: 1.ts +import("./0"); +var p1 = import("./0"); +p1.then(zero => { + return zero.foo(); +}); + +function foo() { + const p2 = import("./0"); +} \ No newline at end of file diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionES5UMD.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionES5UMD.ts new file mode 100644 index 00000000000..05c4d699104 --- /dev/null +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionES5UMD.ts @@ -0,0 +1,15 @@ +// @module: umd +// @target: esnext +// @filename: 0.ts +export function foo() { return "foo"; } + +// @filename: 1.ts +import("./0"); +var p1 = import("./0"); +p1.then(zero => { + return zero.foo(); +}); + +function foo() { + const p2 = import("./0"); +} \ No newline at end of file From 1b0d020082e0c4848d7a4846e30819c8f019968b Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Fri, 28 Apr 2017 16:01:44 -0700 Subject: [PATCH 54/67] Add tests and update baselines --- .../importCallExpressionCheckReturntype1.js | 7 +-- .../importCallExpressionDeclarationEmit1.js | 11 ++-- .../reference/importCallExpressionES5AMD.js | 35 ++++++++++++ .../importCallExpressionES5AMD.symbols | 28 ++++++++++ .../importCallExpressionES5AMD.types | 39 ++++++++++++++ .../reference/importCallExpressionES5CJS.js | 31 +++++++++++ .../importCallExpressionES5CJS.symbols | 28 ++++++++++ .../importCallExpressionES5CJS.types | 39 ++++++++++++++ .../importCallExpressionES5System.js | 46 ++++++++++++++++ .../importCallExpressionES5System.symbols | 28 ++++++++++ .../importCallExpressionES5System.types | 39 ++++++++++++++ .../reference/importCallExpressionES5UMD.js | 53 +++++++++++++++++++ .../importCallExpressionES5UMD.symbols | 28 ++++++++++ .../importCallExpressionES5UMD.types | 39 ++++++++++++++ .../importCallExpressionGrammarError.js | 11 ++-- .../reference/importCallExpressionInAMD1.js | 6 +-- .../reference/importCallExpressionInAMD2.js | 2 +- .../reference/importCallExpressionInAMD3.js | 2 +- .../reference/importCallExpressionInAMD4.js | 4 +- .../reference/importCallExpressionInCJS1.js | 7 +-- .../reference/importCallExpressionInCJS2.js | 5 +- .../reference/importCallExpressionInCJS3.js | 3 +- .../reference/importCallExpressionInCJS4.js | 3 +- .../reference/importCallExpressionInCJS5.js | 5 +- .../importCallExpressionInScriptContext1.js | 3 +- .../importCallExpressionInScriptContext2.js | 3 +- .../reference/importCallExpressionInUMD1.js | 8 +-- .../reference/importCallExpressionInUMD2.js | 4 +- .../reference/importCallExpressionInUMD3.js | 4 +- .../reference/importCallExpressionInUMD4.js | 6 ++- .../importCallExpressionReturnPromiseOfAny.js | 17 +++--- ...llExpressionSpecifierNotStringTypeError.js | 11 ++-- .../importCallExpressionES5AMD.ts | 1 + .../importCallExpressionES5CJS.ts | 3 +- .../importCallExpressionES5System.ts | 3 +- .../importCallExpressionES5UMD.ts | 3 +- 36 files changed, 511 insertions(+), 54 deletions(-) create mode 100644 tests/baselines/reference/importCallExpressionES5AMD.js create mode 100644 tests/baselines/reference/importCallExpressionES5AMD.symbols create mode 100644 tests/baselines/reference/importCallExpressionES5AMD.types create mode 100644 tests/baselines/reference/importCallExpressionES5CJS.js create mode 100644 tests/baselines/reference/importCallExpressionES5CJS.symbols create mode 100644 tests/baselines/reference/importCallExpressionES5CJS.types create mode 100644 tests/baselines/reference/importCallExpressionES5System.js create mode 100644 tests/baselines/reference/importCallExpressionES5System.symbols create mode 100644 tests/baselines/reference/importCallExpressionES5System.types create mode 100644 tests/baselines/reference/importCallExpressionES5UMD.js create mode 100644 tests/baselines/reference/importCallExpressionES5UMD.symbols create mode 100644 tests/baselines/reference/importCallExpressionES5UMD.types diff --git a/tests/baselines/reference/importCallExpressionCheckReturntype1.js b/tests/baselines/reference/importCallExpressionCheckReturntype1.js index cddc20d925a..a4b564d89dc 100644 --- a/tests/baselines/reference/importCallExpressionCheckReturntype1.js +++ b/tests/baselines/reference/importCallExpressionCheckReturntype1.js @@ -29,7 +29,8 @@ class C { exports.C = C; //// [1.js] "use strict"; +var __resolved = new Promise(function (resolve) { resolve(); }); Object.defineProperty(exports, "__esModule", { value: true }); -let p1 = Promise.resolve().then(() => require("./defaultPath")); -let p2 = Promise.resolve().then(() => require("./defaultPath")); -let p3 = Promise.resolve().then(() => require("./defaultPath")); +let p1 = __resolved.then(function () { return require("./defaultPath"); }); +let p2 = __resolved.then(function () { return require("./defaultPath"); }); +let p3 = __resolved.then(function () { return require("./defaultPath"); }); diff --git a/tests/baselines/reference/importCallExpressionDeclarationEmit1.js b/tests/baselines/reference/importCallExpressionDeclarationEmit1.js index 721d85abe71..4319935bff5 100644 --- a/tests/baselines/reference/importCallExpressionDeclarationEmit1.js +++ b/tests/baselines/reference/importCallExpressionDeclarationEmit1.js @@ -15,12 +15,13 @@ function returnDynamicLoad(path: string) { } //// [importCallExpressionDeclarationEmit1.js] -Promise.resolve().then(() => require(getSpecifier())); -var p0 = Promise.resolve().then(() => require(`${directory}\${moduleFile}`)); -var p1 = Promise.resolve().then(() => require(getSpecifier())); -const p2 = Promise.resolve().then(() => require(whatToLoad ? getSpecifier() : "defaulPath")); +var __resolved = new Promise(function (resolve) { resolve(); }); +__resolved.then(function () { return require(getSpecifier()); }); +var p0 = __resolved.then(function () { return require(`${directory}\${moduleFile}`); }); +var p1 = __resolved.then(function () { return require(getSpecifier()); }); +const p2 = __resolved.then(function () { return require(whatToLoad ? getSpecifier() : "defaulPath"); }); function returnDynamicLoad(path) { - return Promise.resolve().then(() => require(path)); + return __resolved.then(function () { return require(path); }); } diff --git a/tests/baselines/reference/importCallExpressionES5AMD.js b/tests/baselines/reference/importCallExpressionES5AMD.js new file mode 100644 index 00000000000..0a1aa0deb22 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionES5AMD.js @@ -0,0 +1,35 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionES5AMD.ts] //// + +//// [0.ts] +export function foo() { return "foo"; } + +//// [1.ts] +import("./0"); +var p1 = import("./0"); +p1.then(zero => { + return zero.foo(); +}); + +function foo() { + const p2 = import("./0"); +} + +//// [0.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + function foo() { return "foo"; } + exports.foo = foo; +}); +//// [1.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + new Promise(function (_a, _b) { require(["./0"], _a, _b); }); + var p1 = new Promise(function (_a, _b) { require(["./0"], _a, _b); }); + p1.then(function (zero) { + return zero.foo(); + }); + function foo() { + var p2 = new Promise(function (_a, _b) { require(["./0"], _a, _b); }); + } +}); diff --git a/tests/baselines/reference/importCallExpressionES5AMD.symbols b/tests/baselines/reference/importCallExpressionES5AMD.symbols new file mode 100644 index 00000000000..15356c694ed --- /dev/null +++ b/tests/baselines/reference/importCallExpressionES5AMD.symbols @@ -0,0 +1,28 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export function foo() { return "foo"; } +>foo : Symbol(foo, Decl(0.ts, 0, 0)) + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +import("./0"); +var p1 = import("./0"); +>p1 : Symbol(p1, Decl(1.ts, 1, 3)) + +p1.then(zero => { +>p1.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>p1 : Symbol(p1, Decl(1.ts, 1, 3)) +>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>zero : Symbol(zero, Decl(1.ts, 2, 8)) + + return zero.foo(); +>zero.foo : Symbol(foo, Decl(0.ts, 0, 0)) +>zero : Symbol(zero, Decl(1.ts, 2, 8)) +>foo : Symbol(foo, Decl(0.ts, 0, 0)) + +}); + +function foo() { +>foo : Symbol(foo, Decl(1.ts, 4, 3)) + + const p2 = import("./0"); +>p2 : Symbol(p2, Decl(1.ts, 7, 9)) +} diff --git a/tests/baselines/reference/importCallExpressionES5AMD.types b/tests/baselines/reference/importCallExpressionES5AMD.types new file mode 100644 index 00000000000..2733f3ff14a --- /dev/null +++ b/tests/baselines/reference/importCallExpressionES5AMD.types @@ -0,0 +1,39 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export function foo() { return "foo"; } +>foo : () => string +>"foo" : "foo" + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +import("./0"); +>import("./0") : Promise +>"./0" : "./0" + +var p1 = import("./0"); +>p1 : Promise +>import("./0") : Promise +>"./0" : "./0" + +p1.then(zero => { +>p1.then(zero => { return zero.foo();}) : Promise +>p1.then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>p1 : Promise +>then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>zero => { return zero.foo();} : (zero: typeof "tests/cases/conformance/es2018/dynamicImport/0") => string +>zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" + + return zero.foo(); +>zero.foo() : string +>zero.foo : () => string +>zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>foo : () => string + +}); + +function foo() { +>foo : () => void + + const p2 = import("./0"); +>p2 : Promise +>import("./0") : Promise +>"./0" : "./0" +} diff --git a/tests/baselines/reference/importCallExpressionES5CJS.js b/tests/baselines/reference/importCallExpressionES5CJS.js new file mode 100644 index 00000000000..77587259a82 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionES5CJS.js @@ -0,0 +1,31 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionES5CJS.ts] //// + +//// [0.ts] +export function foo() { return "foo"; } + +//// [1.ts] +import("./0"); +var p1 = import("./0"); +p1.then(zero => { + return zero.foo(); +}); + +function foo() { + const p2 = import("./0"); +} + +//// [0.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +function foo() { return "foo"; } +exports.foo = foo; +//// [1.js] +var __resolved = new Promise(function (resolve) { resolve(); }); +__resolved.then(function () { return require("./0"); }); +var p1 = __resolved.then(function () { return require("./0"); }); +p1.then(function (zero) { + return zero.foo(); +}); +function foo() { + var p2 = __resolved.then(function () { return require("./0"); }); +} diff --git a/tests/baselines/reference/importCallExpressionES5CJS.symbols b/tests/baselines/reference/importCallExpressionES5CJS.symbols new file mode 100644 index 00000000000..15356c694ed --- /dev/null +++ b/tests/baselines/reference/importCallExpressionES5CJS.symbols @@ -0,0 +1,28 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export function foo() { return "foo"; } +>foo : Symbol(foo, Decl(0.ts, 0, 0)) + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +import("./0"); +var p1 = import("./0"); +>p1 : Symbol(p1, Decl(1.ts, 1, 3)) + +p1.then(zero => { +>p1.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>p1 : Symbol(p1, Decl(1.ts, 1, 3)) +>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>zero : Symbol(zero, Decl(1.ts, 2, 8)) + + return zero.foo(); +>zero.foo : Symbol(foo, Decl(0.ts, 0, 0)) +>zero : Symbol(zero, Decl(1.ts, 2, 8)) +>foo : Symbol(foo, Decl(0.ts, 0, 0)) + +}); + +function foo() { +>foo : Symbol(foo, Decl(1.ts, 4, 3)) + + const p2 = import("./0"); +>p2 : Symbol(p2, Decl(1.ts, 7, 9)) +} diff --git a/tests/baselines/reference/importCallExpressionES5CJS.types b/tests/baselines/reference/importCallExpressionES5CJS.types new file mode 100644 index 00000000000..2733f3ff14a --- /dev/null +++ b/tests/baselines/reference/importCallExpressionES5CJS.types @@ -0,0 +1,39 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export function foo() { return "foo"; } +>foo : () => string +>"foo" : "foo" + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +import("./0"); +>import("./0") : Promise +>"./0" : "./0" + +var p1 = import("./0"); +>p1 : Promise +>import("./0") : Promise +>"./0" : "./0" + +p1.then(zero => { +>p1.then(zero => { return zero.foo();}) : Promise +>p1.then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>p1 : Promise +>then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>zero => { return zero.foo();} : (zero: typeof "tests/cases/conformance/es2018/dynamicImport/0") => string +>zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" + + return zero.foo(); +>zero.foo() : string +>zero.foo : () => string +>zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>foo : () => string + +}); + +function foo() { +>foo : () => void + + const p2 = import("./0"); +>p2 : Promise +>import("./0") : Promise +>"./0" : "./0" +} diff --git a/tests/baselines/reference/importCallExpressionES5System.js b/tests/baselines/reference/importCallExpressionES5System.js new file mode 100644 index 00000000000..e0b017370a0 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionES5System.js @@ -0,0 +1,46 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionES5System.ts] //// + +//// [0.ts] +export function foo() { return "foo"; } + +//// [1.ts] +import("./0"); +var p1 = import("./0"); +p1.then(zero => { + return zero.foo(); +}); + +function foo() { + const p2 = import("./0"); +} + +//// [0.js] +System.register([], function (exports_1, context_1) { + "use strict"; + var __moduleName = context_1 && context_1.id; + function foo() { return "foo"; } + exports_1("foo", foo); + return { + setters: [], + execute: function () { + } + }; +}); +//// [1.js] +System.register([], function (exports_1, context_1) { + var __moduleName = context_1 && context_1.id; + function foo() { + var p2 = context_1.import("./0"); + } + var p1; + return { + setters: [], + execute: function () { + context_1.import("./0"); + p1 = context_1.import("./0"); + p1.then(function (zero) { + return zero.foo(); + }); + } + }; +}); diff --git a/tests/baselines/reference/importCallExpressionES5System.symbols b/tests/baselines/reference/importCallExpressionES5System.symbols new file mode 100644 index 00000000000..15356c694ed --- /dev/null +++ b/tests/baselines/reference/importCallExpressionES5System.symbols @@ -0,0 +1,28 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export function foo() { return "foo"; } +>foo : Symbol(foo, Decl(0.ts, 0, 0)) + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +import("./0"); +var p1 = import("./0"); +>p1 : Symbol(p1, Decl(1.ts, 1, 3)) + +p1.then(zero => { +>p1.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>p1 : Symbol(p1, Decl(1.ts, 1, 3)) +>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>zero : Symbol(zero, Decl(1.ts, 2, 8)) + + return zero.foo(); +>zero.foo : Symbol(foo, Decl(0.ts, 0, 0)) +>zero : Symbol(zero, Decl(1.ts, 2, 8)) +>foo : Symbol(foo, Decl(0.ts, 0, 0)) + +}); + +function foo() { +>foo : Symbol(foo, Decl(1.ts, 4, 3)) + + const p2 = import("./0"); +>p2 : Symbol(p2, Decl(1.ts, 7, 9)) +} diff --git a/tests/baselines/reference/importCallExpressionES5System.types b/tests/baselines/reference/importCallExpressionES5System.types new file mode 100644 index 00000000000..2733f3ff14a --- /dev/null +++ b/tests/baselines/reference/importCallExpressionES5System.types @@ -0,0 +1,39 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export function foo() { return "foo"; } +>foo : () => string +>"foo" : "foo" + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +import("./0"); +>import("./0") : Promise +>"./0" : "./0" + +var p1 = import("./0"); +>p1 : Promise +>import("./0") : Promise +>"./0" : "./0" + +p1.then(zero => { +>p1.then(zero => { return zero.foo();}) : Promise +>p1.then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>p1 : Promise +>then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>zero => { return zero.foo();} : (zero: typeof "tests/cases/conformance/es2018/dynamicImport/0") => string +>zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" + + return zero.foo(); +>zero.foo() : string +>zero.foo : () => string +>zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>foo : () => string + +}); + +function foo() { +>foo : () => void + + const p2 = import("./0"); +>p2 : Promise +>import("./0") : Promise +>"./0" : "./0" +} diff --git a/tests/baselines/reference/importCallExpressionES5UMD.js b/tests/baselines/reference/importCallExpressionES5UMD.js new file mode 100644 index 00000000000..ee96a145854 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionES5UMD.js @@ -0,0 +1,53 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionES5UMD.ts] //// + +//// [0.ts] +export function foo() { return "foo"; } + +//// [1.ts] +import("./0"); +var p1 = import("./0"); +p1.then(zero => { + return zero.foo(); +}); + +function foo() { + const p2 = import("./0"); +} + +//// [0.js] +(function (factory) { + if (typeof module === "object" && typeof module.exports === "object") { + var v = factory(require, exports); + if (v !== undefined) module.exports = v; + } + else if (typeof define === "function" && define.amd) { + define(["require", "exports"], factory); + } +})(function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + function foo() { return "foo"; } + exports.foo = foo; +}); +//// [1.js] +(function (factory) { + if (typeof module === "object" && typeof module.exports === "object") { + var v = factory(require, exports); + if (v !== undefined) module.exports = v; + } + else if (typeof define === "function" && define.amd) { + define(["require", "exports"], factory); + } +})(function (require, exports) { + "use strict"; + var __syncRequire = typeof module === "object" && typeof module.exports === "object"; + var __resolved = new Promise(function (resolve) { resolve(); }); + __syncRequire ? __resolved.then(function () { return require("./0"); }) : new Promise(function (_a, _b) { require(["./0"], _a, _b); }); + var p1 = __syncRequire ? __resolved.then(function () { return require("./0"); }) : new Promise(function (_a, _b) { require(["./0"], _a, _b); }); + p1.then(function (zero) { + return zero.foo(); + }); + function foo() { + var p2 = __syncRequire ? __resolved.then(function () { return require("./0"); }) : new Promise(function (_a, _b) { require(["./0"], _a, _b); }); + } +}); diff --git a/tests/baselines/reference/importCallExpressionES5UMD.symbols b/tests/baselines/reference/importCallExpressionES5UMD.symbols new file mode 100644 index 00000000000..15356c694ed --- /dev/null +++ b/tests/baselines/reference/importCallExpressionES5UMD.symbols @@ -0,0 +1,28 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export function foo() { return "foo"; } +>foo : Symbol(foo, Decl(0.ts, 0, 0)) + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +import("./0"); +var p1 = import("./0"); +>p1 : Symbol(p1, Decl(1.ts, 1, 3)) + +p1.then(zero => { +>p1.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>p1 : Symbol(p1, Decl(1.ts, 1, 3)) +>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>zero : Symbol(zero, Decl(1.ts, 2, 8)) + + return zero.foo(); +>zero.foo : Symbol(foo, Decl(0.ts, 0, 0)) +>zero : Symbol(zero, Decl(1.ts, 2, 8)) +>foo : Symbol(foo, Decl(0.ts, 0, 0)) + +}); + +function foo() { +>foo : Symbol(foo, Decl(1.ts, 4, 3)) + + const p2 = import("./0"); +>p2 : Symbol(p2, Decl(1.ts, 7, 9)) +} diff --git a/tests/baselines/reference/importCallExpressionES5UMD.types b/tests/baselines/reference/importCallExpressionES5UMD.types new file mode 100644 index 00000000000..2733f3ff14a --- /dev/null +++ b/tests/baselines/reference/importCallExpressionES5UMD.types @@ -0,0 +1,39 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export function foo() { return "foo"; } +>foo : () => string +>"foo" : "foo" + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +import("./0"); +>import("./0") : Promise +>"./0" : "./0" + +var p1 = import("./0"); +>p1 : Promise +>import("./0") : Promise +>"./0" : "./0" + +p1.then(zero => { +>p1.then(zero => { return zero.foo();}) : Promise +>p1.then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>p1 : Promise +>then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>zero => { return zero.foo();} : (zero: typeof "tests/cases/conformance/es2018/dynamicImport/0") => string +>zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" + + return zero.foo(); +>zero.foo() : string +>zero.foo : () => string +>zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>foo : () => string + +}); + +function foo() { +>foo : () => void + + const p2 = import("./0"); +>p2 : Promise +>import("./0") : Promise +>"./0" : "./0" +} diff --git a/tests/baselines/reference/importCallExpressionGrammarError.js b/tests/baselines/reference/importCallExpressionGrammarError.js index e2ffc55577d..f907493a9a8 100644 --- a/tests/baselines/reference/importCallExpressionGrammarError.js +++ b/tests/baselines/reference/importCallExpressionGrammarError.js @@ -11,9 +11,10 @@ const p3 = import(,); const p4 = import("pathToModule", "secondModule"); //// [importCallExpressionGrammarError.js] +var __resolved = new Promise(function (resolve) { resolve(); }); var a = ["./0"]; -Promise.resolve().then(() => require(...["PathModule"])); -var p1 = Promise.resolve().then(() => require(...a)); -const p2 = Promise.resolve().then(() => require()); -const p3 = Promise.resolve().then(() => require()); -const p4 = Promise.resolve().then(() => require("pathToModule", "secondModule")); +__resolved.then(function () { return require(...["PathModule"]); }); +var p1 = __resolved.then(function () { return require(...a); }); +const p2 = __resolved.then(function () { return require(); }); +const p3 = __resolved.then(function () { return require(); }); +const p4 = __resolved.then(function () { return require("pathToModule", "secondModule"); }); diff --git a/tests/baselines/reference/importCallExpressionInAMD1.js b/tests/baselines/reference/importCallExpressionInAMD1.js index ed02c4893c3..852668f67de 100644 --- a/tests/baselines/reference/importCallExpressionInAMD1.js +++ b/tests/baselines/reference/importCallExpressionInAMD1.js @@ -24,12 +24,12 @@ define(["require", "exports"], function (require, exports) { //// [1.js] define(["require", "exports"], function (require, exports) { "use strict"; - new Promise(resolve => require(["./0"], resolve)); - var p1 = new Promise(resolve => require(["./0"], resolve)); + new Promise(function (_a, _b) { require(["./0"], _a, _b); }); + var p1 = new Promise(function (_a, _b) { require(["./0"], _a, _b); }); p1.then(zero => { return zero.foo(); }); function foo() { - const p2 = new Promise(resolve => require(["./0"], resolve)); + const p2 = new Promise(function (_a, _b) { require(["./0"], _a, _b); }); } }); diff --git a/tests/baselines/reference/importCallExpressionInAMD2.js b/tests/baselines/reference/importCallExpressionInAMD2.js index 8f451643b5a..eb2f2795d3d 100644 --- a/tests/baselines/reference/importCallExpressionInAMD2.js +++ b/tests/baselines/reference/importCallExpressionInAMD2.js @@ -35,5 +35,5 @@ define(["require", "exports"], function (require, exports) { b.print(); }); } - foo(new Promise(resolve => require(["./0"], resolve))); + foo(new Promise(function (_a, _b) { require(["./0"], _a, _b); })); }); diff --git a/tests/baselines/reference/importCallExpressionInAMD3.js b/tests/baselines/reference/importCallExpressionInAMD3.js index be752805346..295dbb9b87e 100644 --- a/tests/baselines/reference/importCallExpressionInAMD3.js +++ b/tests/baselines/reference/importCallExpressionInAMD3.js @@ -26,7 +26,7 @@ define(["require", "exports"], function (require, exports) { define(["require", "exports"], function (require, exports) { "use strict"; async function foo() { - class C extends (await new Promise(resolve => require(["./0"], resolve))).B { + class C extends (await new Promise(function (_a, _b) { require(["./0"], _a, _b); })).B { } var c = new C(); c.print(); diff --git a/tests/baselines/reference/importCallExpressionInAMD4.js b/tests/baselines/reference/importCallExpressionInAMD4.js index 796e1a7996e..ce7a0ba9e23 100644 --- a/tests/baselines/reference/importCallExpressionInAMD4.js +++ b/tests/baselines/reference/importCallExpressionInAMD4.js @@ -48,14 +48,14 @@ define(["require", "exports"], function (require, exports) { "use strict"; class C { constructor() { - this.myModule = new Promise(resolve => require(["./0"], resolve)); + this.myModule = new Promise(function (_a, _b) { require(["./0"], _a, _b); }); } method() { this.myModule.then(Zero => { console.log(Zero.foo()); }, async (err) => { console.log(err); - let one = await new Promise(resolve => require(["./1"], resolve)); + let one = await new Promise(function (_a, _b) { require(["./1"], _a, _b); }); console.log(one.backup()); }); } diff --git a/tests/baselines/reference/importCallExpressionInCJS1.js b/tests/baselines/reference/importCallExpressionInCJS1.js index 85d99dfa4c3..a939c78bf49 100644 --- a/tests/baselines/reference/importCallExpressionInCJS1.js +++ b/tests/baselines/reference/importCallExpressionInCJS1.js @@ -20,11 +20,12 @@ Object.defineProperty(exports, "__esModule", { value: true }); function foo() { return "foo"; } exports.foo = foo; //// [1.js] -Promise.resolve().then(() => require("./0")); -var p1 = Promise.resolve().then(() => require("./0")); +var __resolved = new Promise(function (resolve) { resolve(); }); +__resolved.then(function () { return require("./0"); }); +var p1 = __resolved.then(function () { return require("./0"); }); p1.then(zero => { return zero.foo(); }); function foo() { - const p2 = Promise.resolve().then(() => require("./0")); + const p2 = __resolved.then(function () { return require("./0"); }); } diff --git a/tests/baselines/reference/importCallExpressionInCJS2.js b/tests/baselines/reference/importCallExpressionInCJS2.js index a5b96c45ee0..d21c81b1a15 100644 --- a/tests/baselines/reference/importCallExpressionInCJS2.js +++ b/tests/baselines/reference/importCallExpressionInCJS2.js @@ -29,12 +29,13 @@ Object.defineProperty(exports, "__esModule", { value: true }); function backup() { return "backup"; } exports.backup = backup; //// [2.js] +var __resolved = new Promise(function (resolve) { resolve(); }); async function compute(promise) { let j = await promise; if (!j) { - j = await Promise.resolve().then(() => require("./1")); + j = await __resolved.then(function () { return require("./1"); }); return j.backup(); } return j.foo(); } -compute(Promise.resolve().then(() => require("./0"))); +compute(__resolved.then(function () { return require("./0"); })); diff --git a/tests/baselines/reference/importCallExpressionInCJS3.js b/tests/baselines/reference/importCallExpressionInCJS3.js index 499c8f9b496..bce029c4675 100644 --- a/tests/baselines/reference/importCallExpressionInCJS3.js +++ b/tests/baselines/reference/importCallExpressionInCJS3.js @@ -24,6 +24,7 @@ class B { } exports.B = B; //// [2.js] +var __resolved = new Promise(function (resolve) { resolve(); }); // We use Promise for now as there is no way to specify shape of module object function foo(x) { x.then(value => { @@ -31,4 +32,4 @@ function foo(x) { b.print(); }); } -foo(Promise.resolve().then(() => require("./0"))); +foo(__resolved.then(function () { return require("./0"); })); diff --git a/tests/baselines/reference/importCallExpressionInCJS4.js b/tests/baselines/reference/importCallExpressionInCJS4.js index 038e9649bfd..aeb537e05bf 100644 --- a/tests/baselines/reference/importCallExpressionInCJS4.js +++ b/tests/baselines/reference/importCallExpressionInCJS4.js @@ -21,8 +21,9 @@ class B { } exports.B = B; //// [2.js] +var __resolved = new Promise(function (resolve) { resolve(); }); async function foo() { - class C extends (await Promise.resolve().then(() => require("./0"))).B { + class C extends (await __resolved.then(function () { return require("./0"); })).B { } var c = new C(); c.print(); diff --git a/tests/baselines/reference/importCallExpressionInCJS5.js b/tests/baselines/reference/importCallExpressionInCJS5.js index d1158fe48b8..aaa0c0f3d11 100644 --- a/tests/baselines/reference/importCallExpressionInCJS5.js +++ b/tests/baselines/reference/importCallExpressionInCJS5.js @@ -40,16 +40,17 @@ Object.defineProperty(exports, "__esModule", { value: true }); function backup() { return "backup"; } exports.backup = backup; //// [2.js] +var __resolved = new Promise(function (resolve) { resolve(); }); class C { constructor() { - this.myModule = Promise.resolve().then(() => require("./0")); + this.myModule = __resolved.then(function () { return require("./0"); }); } method() { this.myModule.then(Zero => { console.log(Zero.foo()); }, async (err) => { console.log(err); - let one = await Promise.resolve().then(() => require("./1")); + let one = await __resolved.then(function () { return require("./1"); }); console.log(one.backup()); }); } diff --git a/tests/baselines/reference/importCallExpressionInScriptContext1.js b/tests/baselines/reference/importCallExpressionInScriptContext1.js index 20a72ff565d..4476fac6c7b 100644 --- a/tests/baselines/reference/importCallExpressionInScriptContext1.js +++ b/tests/baselines/reference/importCallExpressionInScriptContext1.js @@ -13,5 +13,6 @@ Object.defineProperty(exports, "__esModule", { value: true }); function foo() { return "foo"; } exports.foo = foo; //// [1.js] -var p1 = Promise.resolve().then(() => require("./0")); +var __resolved = new Promise(function (resolve) { resolve(); }); +var p1 = __resolved.then(function () { return require("./0"); }); function arguments() { } // this is allow as the file doesn't have implicit "use strict" diff --git a/tests/baselines/reference/importCallExpressionInScriptContext2.js b/tests/baselines/reference/importCallExpressionInScriptContext2.js index 3f2510493f0..594b806ee73 100644 --- a/tests/baselines/reference/importCallExpressionInScriptContext2.js +++ b/tests/baselines/reference/importCallExpressionInScriptContext2.js @@ -15,5 +15,6 @@ function foo() { return "foo"; } exports.foo = foo; //// [1.js] "use strict"; -var p1 = Promise.resolve().then(() => require("./0")); +var __resolved = new Promise(function (resolve) { resolve(); }); +var p1 = __resolved.then(function () { return require("./0"); }); function arguments() { } diff --git a/tests/baselines/reference/importCallExpressionInUMD1.js b/tests/baselines/reference/importCallExpressionInUMD1.js index 16668df030f..317c6452942 100644 --- a/tests/baselines/reference/importCallExpressionInUMD1.js +++ b/tests/baselines/reference/importCallExpressionInUMD1.js @@ -40,12 +40,14 @@ function foo() { } })(function (require, exports) { "use strict"; - require.length === 1 ? Promise.resolve().then(() => require("./0")) : new Promise(resolve => require(["./0"], resolve)); - var p1 = require.length === 1 ? Promise.resolve().then(() => require("./0")) : new Promise(resolve => require(["./0"], resolve)); + var __syncRequire = typeof module === "object" && typeof module.exports === "object"; + var __resolved = new Promise(function (resolve) { resolve(); }); + __syncRequire ? __resolved.then(function () { return require("./0"); }) : new Promise(function (_a, _b) { require(["./0"], _a, _b); }); + var p1 = __syncRequire ? __resolved.then(function () { return require("./0"); }) : new Promise(function (_a, _b) { require(["./0"], _a, _b); }); p1.then(zero => { return zero.foo(); }); function foo() { - const p2 = require.length === 1 ? Promise.resolve().then(() => require("./0")) : new Promise(resolve => require(["./0"], resolve)); + const p2 = __syncRequire ? __resolved.then(function () { return require("./0"); }) : new Promise(function (_a, _b) { require(["./0"], _a, _b); }); } }); diff --git a/tests/baselines/reference/importCallExpressionInUMD2.js b/tests/baselines/reference/importCallExpressionInUMD2.js index ebaeca6311a..c55b522160f 100644 --- a/tests/baselines/reference/importCallExpressionInUMD2.js +++ b/tests/baselines/reference/importCallExpressionInUMD2.js @@ -44,6 +44,8 @@ foo(import("./0")); } })(function (require, exports) { "use strict"; + var __syncRequire = typeof module === "object" && typeof module.exports === "object"; + var __resolved = new Promise(function (resolve) { resolve(); }); // We use Promise for now as there is no way to specify shape of module object function foo(x) { x.then(value => { @@ -51,5 +53,5 @@ foo(import("./0")); b.print(); }); } - foo(require.length === 1 ? Promise.resolve().then(() => require("./0")) : new Promise(resolve => require(["./0"], resolve))); + foo(__syncRequire ? __resolved.then(function () { return require("./0"); }) : new Promise(function (_a, _b) { require(["./0"], _a, _b); })); }); diff --git a/tests/baselines/reference/importCallExpressionInUMD3.js b/tests/baselines/reference/importCallExpressionInUMD3.js index 5aef0967131..8b8ddef84d1 100644 --- a/tests/baselines/reference/importCallExpressionInUMD3.js +++ b/tests/baselines/reference/importCallExpressionInUMD3.js @@ -41,8 +41,10 @@ foo(); } })(function (require, exports) { "use strict"; + var __syncRequire = typeof module === "object" && typeof module.exports === "object"; + var __resolved = new Promise(function (resolve) { resolve(); }); async function foo() { - class C extends (await (require.length === 1 ? Promise.resolve().then(() => require("./0")) : new Promise(resolve => require(["./0"], resolve)))).B { + class C extends (await (__syncRequire ? __resolved.then(function () { return require("./0"); }) : new Promise(function (_a, _b) { require(["./0"], _a, _b); }))).B { } var c = new C(); c.print(); diff --git a/tests/baselines/reference/importCallExpressionInUMD4.js b/tests/baselines/reference/importCallExpressionInUMD4.js index ac36081a536..36702c55a7f 100644 --- a/tests/baselines/reference/importCallExpressionInUMD4.js +++ b/tests/baselines/reference/importCallExpressionInUMD4.js @@ -70,16 +70,18 @@ class C { } })(function (require, exports) { "use strict"; + var __syncRequire = typeof module === "object" && typeof module.exports === "object"; + var __resolved = new Promise(function (resolve) { resolve(); }); class C { constructor() { - this.myModule = require.length === 1 ? Promise.resolve().then(() => require("./0")) : new Promise(resolve => require(["./0"], resolve)); + this.myModule = __syncRequire ? __resolved.then(function () { return require("./0"); }) : new Promise(function (_a, _b) { require(["./0"], _a, _b); }); } method() { this.myModule.then(Zero => { console.log(Zero.foo()); }, async (err) => { console.log(err); - let one = await (require.length === 1 ? Promise.resolve().then(() => require("./1")) : new Promise(resolve => require(["./1"], resolve))); + let one = await (__syncRequire ? __resolved.then(function () { return require("./1"); }) : new Promise(function (_a, _b) { require(["./1"], _a, _b); })); console.log(one.backup()); }); } diff --git a/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.js b/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.js index 0ba536b4c39..5116da7a3fc 100644 --- a/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.js +++ b/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.js @@ -41,21 +41,22 @@ class C { exports.C = C; //// [1.js] "use strict"; +var __resolved = new Promise(function (resolve) { resolve(); }); Object.defineProperty(exports, "__esModule", { value: true }); -Promise.resolve().then(() => require(`${directory}\${moduleFile}`)); -Promise.resolve().then(() => require(getSpecifier())); -var p1 = Promise.resolve().then(() => require(ValidSomeCondition() ? "./0" : "externalModule")); -var p1 = Promise.resolve().then(() => require(getSpecifier())); -var p11 = Promise.resolve().then(() => require(getSpecifier())); -const p2 = Promise.resolve().then(() => require(whatToLoad ? getSpecifier() : "defaulPath")); +__resolved.then(function () { return require(`${directory}\${moduleFile}`); }); +__resolved.then(function () { return require(getSpecifier()); }); +var p1 = __resolved.then(function () { return require(ValidSomeCondition() ? "./0" : "externalModule"); }); +var p1 = __resolved.then(function () { return require(getSpecifier()); }); +var p11 = __resolved.then(function () { return require(getSpecifier()); }); +const p2 = __resolved.then(function () { return require(whatToLoad ? getSpecifier() : "defaulPath"); }); p1.then(zero => { return zero.foo(); // ok, zero is any }); let j; -var p3 = Promise.resolve().then(() => require(j = getSpecifier())); +var p3 = __resolved.then(function () { return require(j = getSpecifier()); }); function* loadModule(directories) { for (const directory of directories) { const path = `${directory}\moduleFile`; - Promise.resolve().then(() => require(yield path)); + __resolved.then(function () { return require(yield path); }); } } diff --git a/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.js b/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.js index 5e2ace1c401..ce0b60dd618 100644 --- a/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.js +++ b/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.js @@ -14,12 +14,13 @@ var p3 = import(["path1", "path2"]); var p4 = import(()=>"PathToModule"); //// [importCallExpressionSpecifierNotStringTypeError.js] +var __resolved = new Promise(function (resolve) { resolve(); }); // Error specifier is not assignable to string -Promise.resolve().then(() => require(getSpecifier())); -var p1 = Promise.resolve().then(() => require(getSpecifier())); -const p2 = Promise.resolve().then(() => require(whatToLoad ? getSpecifier() : "defaulPath")); +__resolved.then(function () { return require(getSpecifier()); }); +var p1 = __resolved.then(function () { return require(getSpecifier()); }); +const p2 = __resolved.then(function () { return require(whatToLoad ? getSpecifier() : "defaulPath"); }); p1.then(zero => { return zero.foo(); // ok, zero is any }); -var p3 = Promise.resolve().then(() => require(["path1", "path2"])); -var p4 = Promise.resolve().then(() => require(() => "PathToModule")); +var p3 = __resolved.then(function () { return require(["path1", "path2"]); }); +var p4 = __resolved.then(function () { return require(() => "PathToModule"); }); diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionES5AMD.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionES5AMD.ts index f44ce0e6e13..33c31283ea0 100644 --- a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionES5AMD.ts +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionES5AMD.ts @@ -1,5 +1,6 @@ // @module: amd // @target: es5 +// @lib: es6 // @filename: 0.ts export function foo() { return "foo"; } diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionES5CJS.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionES5CJS.ts index e1457017552..900ddbdba0c 100644 --- a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionES5CJS.ts +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionES5CJS.ts @@ -1,5 +1,6 @@ // @module: commonjs -// @target: esnext +// @target: es5 +// @lib: es6 // @filename: 0.ts export function foo() { return "foo"; } diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionES5System.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionES5System.ts index a69e844c7a7..c00ab6899c6 100644 --- a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionES5System.ts +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionES5System.ts @@ -1,5 +1,6 @@ // @module: system -// @target: esnext +// @target: es5 +// @lib: es6 // @filename: 0.ts export function foo() { return "foo"; } diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionES5UMD.ts b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionES5UMD.ts index 05c4d699104..699b0ffc342 100644 --- a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionES5UMD.ts +++ b/tests/cases/conformance/es2018/dynamicImport/importCallExpressionES5UMD.ts @@ -1,5 +1,6 @@ // @module: umd -// @target: esnext +// @target: es5 +// @lib: es6 // @filename: 0.ts export function foo() { return "foo"; } From a02edb1cd0277ba0a0ac89c27ba6c10dd635ee21 Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 1 Jun 2017 22:33:39 -0700 Subject: [PATCH 55/67] Address PR: don't early exit when there are grammar errors --- src/compiler/checker.ts | 15 +++++++++++---- .../importCallExpression5ES2018.errors.txt | 16 ++++++++-------- .../importCallExpression6ES2018.errors.txt | 8 ++++---- .../importCallExpressionGrammarError.errors.txt | 10 ++++++++-- 4 files changed, 31 insertions(+), 18 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0da2e311376..cbae09a25a8 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -16099,15 +16099,22 @@ namespace ts { function checkImportCallExpression(node: ImportCall): Type { // Check grammar of dynamic import - if (checkGrammarArguments(node, node.arguments) || checkGrammarImportCallExpression(node)) { + checkGrammarArguments(node, node.arguments) || checkGrammarImportCallExpression(node); + + if (node.arguments.length === 0) { return createPromiseReturnType(node, anyType); } - const specifier = node.arguments[0]; - const specifierType = checkNonNullExpression(specifier); - if (!isTypeAssignableTo(specifierType, stringType)) { + const specifierType = checkExpressionCached(specifier); + // Even though multiple arugments is grammatically incorrect, type-check extra arguments for completion + for (let i = 1; i < node.arguments.length; ++i) { + checkExpressionCached(node.arguments[i]); + } + + if (specifierType.flags & TypeFlags.Undefined || specifierType.flags & TypeFlags.Null || !isTypeAssignableTo(specifierType, stringType)) { error(specifier, Diagnostics.Dynamic_import_s_specifier_must_be_of_type_string_but_here_has_type_0, typeToString(specifierType)); } + // resolveExternalModuleName will return undefined if the moduleReferenceExpression is not a string literal const moduleSymbol = resolveExternalModuleName(node, specifier); if (moduleSymbol) { diff --git a/tests/baselines/reference/importCallExpression5ES2018.errors.txt b/tests/baselines/reference/importCallExpression5ES2018.errors.txt index 372fda0a685..a7836124184 100644 --- a/tests/baselines/reference/importCallExpression5ES2018.errors.txt +++ b/tests/baselines/reference/importCallExpression5ES2018.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/es2018/dynamicImport/2.ts(3,23): error TS2532: Object is possibly 'undefined'. -tests/cases/conformance/es2018/dynamicImport/2.ts(4,24): error TS2532: Object is possibly 'undefined'. -tests/cases/conformance/es2018/dynamicImport/2.ts(5,24): error TS2531: Object is possibly 'null'. -tests/cases/conformance/es2018/dynamicImport/2.ts(6,24): error TS2531: Object is possibly 'null'. +tests/cases/conformance/es2018/dynamicImport/2.ts(3,23): error TS7036: Dynamic import's specifier must be of type 'string', but here has type '"./0" | undefined'. +tests/cases/conformance/es2018/dynamicImport/2.ts(4,24): error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'undefined'. +tests/cases/conformance/es2018/dynamicImport/2.ts(5,24): error TS7036: Dynamic import's specifier must be of type 'string', but here has type '"./1" | null'. +tests/cases/conformance/es2018/dynamicImport/2.ts(6,24): error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'null'. ==== tests/cases/conformance/es2018/dynamicImport/0.ts (0 errors) ==== @@ -19,13 +19,13 @@ tests/cases/conformance/es2018/dynamicImport/2.ts(6,24): error TS2531: Object is const specify = bar() ? "./0" : undefined; let myModule = import(specify); ~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. +!!! error TS7036: Dynamic import's specifier must be of type 'string', but here has type '"./0" | undefined'. let myModule1 = import(undefined); ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. +!!! error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'undefined'. let myModule2 = import(bar() ? "./1" : null); ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2531: Object is possibly 'null'. +!!! error TS7036: Dynamic import's specifier must be of type 'string', but here has type '"./1" | null'. let myModule3 = import(null); ~~~~ -!!! error TS2531: Object is possibly 'null'. \ No newline at end of file +!!! error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'null'. \ No newline at end of file diff --git a/tests/baselines/reference/importCallExpression6ES2018.errors.txt b/tests/baselines/reference/importCallExpression6ES2018.errors.txt index 33f93ef4d39..2e349408569 100644 --- a/tests/baselines/reference/importCallExpression6ES2018.errors.txt +++ b/tests/baselines/reference/importCallExpression6ES2018.errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/es2018/dynamicImport/2.ts(4,24): error TS2532: Object is possibly 'undefined'. -tests/cases/conformance/es2018/dynamicImport/2.ts(6,24): error TS2531: Object is possibly 'null'. +tests/cases/conformance/es2018/dynamicImport/2.ts(4,24): error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'undefined'. +tests/cases/conformance/es2018/dynamicImport/2.ts(6,24): error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'null'. ==== tests/cases/conformance/es2018/dynamicImport/0.ts (0 errors) ==== @@ -18,8 +18,8 @@ tests/cases/conformance/es2018/dynamicImport/2.ts(6,24): error TS2531: Object is let myModule = import(specify); let myModule1 = import(undefined); ~~~~~~~~~ -!!! error TS2532: Object is possibly 'undefined'. +!!! error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'undefined'. let myModule2 = import(bar() ? "./1" : null); let myModule3 = import(null); ~~~~ -!!! error TS2531: Object is possibly 'null'. \ No newline at end of file +!!! error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'null'. \ No newline at end of file diff --git a/tests/baselines/reference/importCallExpressionGrammarError.errors.txt b/tests/baselines/reference/importCallExpressionGrammarError.errors.txt index c4c62b8ff8f..c0684edaabe 100644 --- a/tests/baselines/reference/importCallExpressionGrammarError.errors.txt +++ b/tests/baselines/reference/importCallExpressionGrammarError.errors.txt @@ -2,10 +2,12 @@ tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts(7,17): error TS1325: Specifier of dynamic import cannot be spread element. tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts(8,12): error TS1324: Dynamic import must have one specifier as an argument. tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts(9,19): error TS1135: Argument expression expected. +tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts(9,19): error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'undefined'. tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts(10,12): error TS1324: Dynamic import must have one specifier as an argument. +tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts(10,19): error TS2307: Cannot find module 'pathToModule'. -==== tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts (5 errors) ==== +==== tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts (7 errors) ==== declare function getSpecifier(): string; declare var whatToLoad: boolean; @@ -23,6 +25,10 @@ tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts const p3 = import(,); !!! error TS1135: Argument expression expected. + +!!! error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'undefined'. const p4 = import("pathToModule", "secondModule"); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1324: Dynamic import must have one specifier as an argument. \ No newline at end of file +!!! error TS1324: Dynamic import must have one specifier as an argument. + ~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'pathToModule'. \ No newline at end of file From 72ba23c6500ca97df1da49dfd6c01dfcb14fb2c0 Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 1 Jun 2017 23:11:43 -0700 Subject: [PATCH 56/67] Address PR: change order of grammar check --- src/compiler/checker.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index cbae09a25a8..db2a3c0e066 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -24641,24 +24641,24 @@ namespace ts { } function checkGrammarImportCallExpression(node: ImportCall): boolean { - const arguments = node.arguments; - if (arguments.length !== 1) { - return grammarErrorOnNode(node, Diagnostics.Dynamic_import_must_have_one_specifier_as_an_argument); + if (modulekind === ModuleKind.ES2015) { + return grammarErrorOnNode(node, Diagnostics.Dynamic_import_cannot_be_used_when_targeting_ECMAScript_2015_modules); } if (node.typeArguments) { return grammarErrorOnNode(node, Diagnostics.Dynamic_import_cannot_have_type_arguments); } + const arguments = node.arguments; + if (arguments.length !== 1) { + return grammarErrorOnNode(node, Diagnostics.Dynamic_import_must_have_one_specifier_as_an_argument); + } + // see: parseArgumentOrArrayLiteralElement...we use this function which parse arguments of callExpression to parse specifier for dynamic import. // parseArgumentOrArrayLiteralElement allows spread element to be in an argument list which is not allowed as specifier in dynamic import. if (isSpreadExpression(arguments[0])) { return grammarErrorOnNode(arguments[0], Diagnostics.Specifier_of_dynamic_import_cannot_be_spread_element); } - - if (modulekind === ModuleKind.ES2015) { - grammarErrorOnNode(node, Diagnostics.Dynamic_import_cannot_be_used_when_targeting_ECMAScript_2015_modules); - } } } From e6d7327c3f29106a1a43ee525c09abc4d8d7834b Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 1 Jun 2017 23:21:59 -0700 Subject: [PATCH 57/67] Address PR: error message, fix capitalization, only allow functionLikeDeclaration and ImportCall for create Promise, use fall through comment --- src/compiler/checker.ts | 6 +++--- src/compiler/diagnosticMessages.json | 2 +- src/compiler/parser.ts | 2 +- src/compiler/program.ts | 2 +- src/compiler/types.ts | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index db2a3c0e066..f54e363487c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -16332,11 +16332,11 @@ namespace ts { return emptyObjectType; } - function createPromiseReturnType(func: FunctionLikeDeclaration | CallExpression, promisedType: Type) { + function createPromiseReturnType(func: FunctionLikeDeclaration | ImportCall, promisedType: Type) { const promiseType = createPromiseType(promisedType); if (promiseType === emptyObjectType) { error(func, isImportCall(func) ? - Diagnostics.A_dynamic_import_call_must_return_a_Promise_Make_sure_you_have_a_declaration_for_Promise_or_include_ES2015_in_your_lib_option : + Diagnostics.A_dynamic_import_call_return_a_Promise_Make_sure_you_have_a_declaration_for_Promise_or_include_ES2015_in_your_lib_option : Diagnostics.An_async_function_or_method_must_return_a_Promise_Make_sure_you_have_a_declaration_for_Promise_or_include_ES2015_in_your_lib_option); return unknownType; } @@ -17705,7 +17705,7 @@ namespace ts { if ((node).expression.kind === SyntaxKind.ImportKeyword) { return checkImportCallExpression(node); } - /* tslint:disable: no-switch-case-fall-through */ + /* falls through */ case SyntaxKind.NewExpression: return checkCallExpression(node); case SyntaxKind.TaggedTemplateExpression: diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 70a3465a6ee..4a6c2153567 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2172,7 +2172,7 @@ "category": "Error", "code": 2710 }, - "A dynamic import call must return a 'Promise'. Make sure you have a declaration for 'Promise' or include 'ES2015' in your `--lib` option.": { + "A dynamic import call return a 'Promise'. Make sure you have a declaration for 'Promise' or include 'ES2015' in your `--lib` option.": { "category": "Error", "code": 2711 }, diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 58270627d49..2e4de9bdd24 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3700,7 +3700,7 @@ namespace ts { // For example: // var foo3 = require("subfolder // import * as foo1 from "module-from-node -> we want this import to be a statement rather than import call expression - sourceFile.flags |= NodeFlags.possiblyContainDynamicImport; + sourceFile.flags |= NodeFlags.PossiblyContainDynamicImport; expression = parseTokenNode(); } else { diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 61a1e0ba246..c37d07db81a 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1383,7 +1383,7 @@ namespace ts { for (const node of file.statements) { collectModuleReferences(node, /*inAmbientModule*/ false); - if ((file.flags & NodeFlags.possiblyContainDynamicImport) || isJavaScriptFile) { + if ((file.flags & NodeFlags.PossiblyContainDynamicImport) || isJavaScriptFile) { collectDynamicImportOrRequireCalls(node); } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index b2d4878a415..756ef4adbac 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -456,7 +456,7 @@ namespace ts { // During editing, if dynamic import is remove, incremental parsing will *NOT* update this flag. This will then causes walking of the tree during module resolution. // However, the removal operation should not occur often and in the case of the removal, it is likely that users will add back the import anyway. // The advantage of this approach is its simplicity. For the case of batch compilation, we garuntee that users won't have to pay the price of walking the tree if dynamic import isn't used. - possiblyContainDynamicImport = 1 << 19, + PossiblyContainDynamicImport = 1 << 19, BlockScoped = Let | Const, From d9e2033dfc7c29eed92f6724b482ab1750f34774 Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 1 Jun 2017 23:26:40 -0700 Subject: [PATCH 58/67] Address PR: remove __resolved when emit for commonJs and just do Promise.resolve().then(...) --- src/compiler/transformers/module/module.ts | 27 +++++++--------------- src/compiler/transformers/module/system.ts | 2 +- 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index d81265a569f..f776ec23695 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -553,8 +553,8 @@ namespace ts { // ... // new Promise(function (_a, _b) { require([x], _a, _b); }); /*Amd Require*/ // }); - const resolve = createIdentifier("_a"); - const reject = createIdentifier("_b"); + const resolve = createUniqueName("resolve"); + const reject = createUniqueName("reject") return createNew( createIdentifier("Promise"), /*typeArguments*/ undefined, @@ -570,7 +570,7 @@ namespace ts { createCall( createIdentifier("require"), /*typeArguments*/ undefined, - [createArrayLiteral(node.arguments), resolve, reject] + [createArrayLiteral([firstOrUndefined(node.arguments) || createOmittedExpression()]), resolve, reject] ))]) )]); } @@ -578,16 +578,13 @@ namespace ts { function transformImportCallExpressionCommonJS(node: ImportCall): Expression { // import("./blah") // emit as - // var __resolved = new Promise(function (resolve) { resolve(); }); - // .... - // __resolved.then(function () { return require(x); }) /*CommonJs Require*/ - - // Promise.resolve().then(() => require("./blah")); + // Promise.resolve().then(function () { return require(x); }) /*CommonJs Require*/ // We have to wrap require in then callback so that require is done in asynchronously // if we simply do require in resolve callback in Promise constructor. We will execute the loading immediately - context.requestEmitHelper(dynamicImportCreateResolvedHelper); return createCall( - createPropertyAccess(createIdentifier("__resolved"), "then"), + createPropertyAccess( + createCall(createPropertyAccess(createIdentifier("Promise"), "resolve"), /*typeArguments*/ undefined, /*argumentsArray*/ []), + "then"), /*typeArguments*/ undefined, [createFunctionExpression( /*modifiers*/ undefined, @@ -1609,14 +1606,6 @@ namespace ts { name: "typescript:dynamicimport-sync-require", scoped: true, text: ` - var __syncRequire = typeof module === "object" && typeof module.exports === "object"; - var __resolved = new Promise(function (resolve) { resolve(); });` - }; - - const dynamicImportCreateResolvedHelper: EmitHelper = { - name: "typescript:dynamicimport-create-resolved", - scoped: false, - priority: 1, - text: `var __resolved = new Promise(function (resolve) { resolve(); });` + var __syncRequire = typeof module === "object" && typeof module.exports === "object";` }; } diff --git a/src/compiler/transformers/module/system.ts b/src/compiler/transformers/module/system.ts index 8e7f0ae30d9..6005f381d8b 100644 --- a/src/compiler/transformers/module/system.ts +++ b/src/compiler/transformers/module/system.ts @@ -50,7 +50,7 @@ namespace ts { * @param node The SourceFile node. */ function transformSourceFile(node: SourceFile) { - if (node.isDeclarationFile || !(isExternalModule(node) || compilerOptions.isolatedModules || node.transformFlags & TransformFlags.ContainsDynamicImport)) { + if (node.isDeclarationFile || !(isEffectiveExternalModule(node, compilerOptions)|| node.transformFlags & TransformFlags.ContainsDynamicImport)) { return node; } From 769f6adf29b02b0cfa67d72ebe5de1a31ab1081c Mon Sep 17 00:00:00 2001 From: Yui T Date: Fri, 2 Jun 2017 06:56:18 -0700 Subject: [PATCH 59/67] Update baselines --- .../importCallExpressionCheckReturntype1.js | 7 +++---- .../importCallExpressionDeclarationEmit1.js | 11 +++++------ .../reference/importCallExpressionES5AMD.js | 6 +++--- .../reference/importCallExpressionES5CJS.js | 7 +++---- .../reference/importCallExpressionES5UMD.js | 7 +++---- .../importCallExpressionGrammarError.js | 11 +++++------ .../reference/importCallExpressionInAMD1.js | 6 +++--- .../reference/importCallExpressionInAMD2.js | 2 +- .../reference/importCallExpressionInAMD3.js | 2 +- .../reference/importCallExpressionInAMD4.js | 4 ++-- .../reference/importCallExpressionInCJS1.js | 7 +++---- .../reference/importCallExpressionInCJS2.js | 5 ++--- .../reference/importCallExpressionInCJS3.js | 3 +-- .../reference/importCallExpressionInCJS4.js | 3 +-- .../reference/importCallExpressionInCJS5.js | 5 ++--- .../importCallExpressionInScriptContext1.js | 3 +-- .../importCallExpressionInScriptContext2.js | 3 +-- .../reference/importCallExpressionInUMD1.js | 7 +++---- .../reference/importCallExpressionInUMD2.js | 3 +-- .../reference/importCallExpressionInUMD3.js | 3 +-- .../reference/importCallExpressionInUMD4.js | 5 ++--- .../importCallExpressionReturnPromiseOfAny.js | 17 ++++++++--------- ...CallExpressionSpecifierNotStringTypeError.js | 11 +++++------ 23 files changed, 60 insertions(+), 78 deletions(-) diff --git a/tests/baselines/reference/importCallExpressionCheckReturntype1.js b/tests/baselines/reference/importCallExpressionCheckReturntype1.js index a4b564d89dc..f317a799f13 100644 --- a/tests/baselines/reference/importCallExpressionCheckReturntype1.js +++ b/tests/baselines/reference/importCallExpressionCheckReturntype1.js @@ -29,8 +29,7 @@ class C { exports.C = C; //// [1.js] "use strict"; -var __resolved = new Promise(function (resolve) { resolve(); }); Object.defineProperty(exports, "__esModule", { value: true }); -let p1 = __resolved.then(function () { return require("./defaultPath"); }); -let p2 = __resolved.then(function () { return require("./defaultPath"); }); -let p3 = __resolved.then(function () { return require("./defaultPath"); }); +let p1 = Promise.resolve().then(function () { return require("./defaultPath"); }); +let p2 = Promise.resolve().then(function () { return require("./defaultPath"); }); +let p3 = Promise.resolve().then(function () { return require("./defaultPath"); }); diff --git a/tests/baselines/reference/importCallExpressionDeclarationEmit1.js b/tests/baselines/reference/importCallExpressionDeclarationEmit1.js index 4319935bff5..07f95d3b3b2 100644 --- a/tests/baselines/reference/importCallExpressionDeclarationEmit1.js +++ b/tests/baselines/reference/importCallExpressionDeclarationEmit1.js @@ -15,13 +15,12 @@ function returnDynamicLoad(path: string) { } //// [importCallExpressionDeclarationEmit1.js] -var __resolved = new Promise(function (resolve) { resolve(); }); -__resolved.then(function () { return require(getSpecifier()); }); -var p0 = __resolved.then(function () { return require(`${directory}\${moduleFile}`); }); -var p1 = __resolved.then(function () { return require(getSpecifier()); }); -const p2 = __resolved.then(function () { return require(whatToLoad ? getSpecifier() : "defaulPath"); }); +Promise.resolve().then(function () { return require(getSpecifier()); }); +var p0 = Promise.resolve().then(function () { return require(`${directory}\${moduleFile}`); }); +var p1 = Promise.resolve().then(function () { return require(getSpecifier()); }); +const p2 = Promise.resolve().then(function () { return require(whatToLoad ? getSpecifier() : "defaulPath"); }); function returnDynamicLoad(path) { - return __resolved.then(function () { return require(path); }); + return Promise.resolve().then(function () { return require(path); }); } diff --git a/tests/baselines/reference/importCallExpressionES5AMD.js b/tests/baselines/reference/importCallExpressionES5AMD.js index 0a1aa0deb22..fd402c163e9 100644 --- a/tests/baselines/reference/importCallExpressionES5AMD.js +++ b/tests/baselines/reference/importCallExpressionES5AMD.js @@ -24,12 +24,12 @@ define(["require", "exports"], function (require, exports) { //// [1.js] define(["require", "exports"], function (require, exports) { "use strict"; - new Promise(function (_a, _b) { require(["./0"], _a, _b); }); - var p1 = new Promise(function (_a, _b) { require(["./0"], _a, _b); }); + new Promise(function (resolve_1, reject_1) { require(["./0"], resolve_1, reject_1); }); + var p1 = new Promise(function (resolve_2, reject_2) { require(["./0"], resolve_2, reject_2); }); p1.then(function (zero) { return zero.foo(); }); function foo() { - var p2 = new Promise(function (_a, _b) { require(["./0"], _a, _b); }); + var p2 = new Promise(function (resolve_3, reject_3) { require(["./0"], resolve_3, reject_3); }); } }); diff --git a/tests/baselines/reference/importCallExpressionES5CJS.js b/tests/baselines/reference/importCallExpressionES5CJS.js index 77587259a82..c5c4f5933a8 100644 --- a/tests/baselines/reference/importCallExpressionES5CJS.js +++ b/tests/baselines/reference/importCallExpressionES5CJS.js @@ -20,12 +20,11 @@ Object.defineProperty(exports, "__esModule", { value: true }); function foo() { return "foo"; } exports.foo = foo; //// [1.js] -var __resolved = new Promise(function (resolve) { resolve(); }); -__resolved.then(function () { return require("./0"); }); -var p1 = __resolved.then(function () { return require("./0"); }); +Promise.resolve().then(function () { return require("./0"); }); +var p1 = Promise.resolve().then(function () { return require("./0"); }); p1.then(function (zero) { return zero.foo(); }); function foo() { - var p2 = __resolved.then(function () { return require("./0"); }); + var p2 = Promise.resolve().then(function () { return require("./0"); }); } diff --git a/tests/baselines/reference/importCallExpressionES5UMD.js b/tests/baselines/reference/importCallExpressionES5UMD.js index ee96a145854..2952a43cd24 100644 --- a/tests/baselines/reference/importCallExpressionES5UMD.js +++ b/tests/baselines/reference/importCallExpressionES5UMD.js @@ -41,13 +41,12 @@ function foo() { })(function (require, exports) { "use strict"; var __syncRequire = typeof module === "object" && typeof module.exports === "object"; - var __resolved = new Promise(function (resolve) { resolve(); }); - __syncRequire ? __resolved.then(function () { return require("./0"); }) : new Promise(function (_a, _b) { require(["./0"], _a, _b); }); - var p1 = __syncRequire ? __resolved.then(function () { return require("./0"); }) : new Promise(function (_a, _b) { require(["./0"], _a, _b); }); + __syncRequire ? Promise.resolve().then(function () { return require("./0"); }) : new Promise(function (resolve_1, reject_1) { require(["./0"], resolve_1, reject_1); }); + var p1 = __syncRequire ? Promise.resolve().then(function () { return require("./0"); }) : new Promise(function (resolve_2, reject_2) { require(["./0"], resolve_2, reject_2); }); p1.then(function (zero) { return zero.foo(); }); function foo() { - var p2 = __syncRequire ? __resolved.then(function () { return require("./0"); }) : new Promise(function (_a, _b) { require(["./0"], _a, _b); }); + var p2 = __syncRequire ? Promise.resolve().then(function () { return require("./0"); }) : new Promise(function (resolve_3, reject_3) { require(["./0"], resolve_3, reject_3); }); } }); diff --git a/tests/baselines/reference/importCallExpressionGrammarError.js b/tests/baselines/reference/importCallExpressionGrammarError.js index f907493a9a8..b30b0c9ddd5 100644 --- a/tests/baselines/reference/importCallExpressionGrammarError.js +++ b/tests/baselines/reference/importCallExpressionGrammarError.js @@ -11,10 +11,9 @@ const p3 = import(,); const p4 = import("pathToModule", "secondModule"); //// [importCallExpressionGrammarError.js] -var __resolved = new Promise(function (resolve) { resolve(); }); var a = ["./0"]; -__resolved.then(function () { return require(...["PathModule"]); }); -var p1 = __resolved.then(function () { return require(...a); }); -const p2 = __resolved.then(function () { return require(); }); -const p3 = __resolved.then(function () { return require(); }); -const p4 = __resolved.then(function () { return require("pathToModule", "secondModule"); }); +Promise.resolve().then(function () { return require(...["PathModule"]); }); +var p1 = Promise.resolve().then(function () { return require(...a); }); +const p2 = Promise.resolve().then(function () { return require(); }); +const p3 = Promise.resolve().then(function () { return require(); }); +const p4 = Promise.resolve().then(function () { return require("pathToModule", "secondModule"); }); diff --git a/tests/baselines/reference/importCallExpressionInAMD1.js b/tests/baselines/reference/importCallExpressionInAMD1.js index 852668f67de..b55066a1b6a 100644 --- a/tests/baselines/reference/importCallExpressionInAMD1.js +++ b/tests/baselines/reference/importCallExpressionInAMD1.js @@ -24,12 +24,12 @@ define(["require", "exports"], function (require, exports) { //// [1.js] define(["require", "exports"], function (require, exports) { "use strict"; - new Promise(function (_a, _b) { require(["./0"], _a, _b); }); - var p1 = new Promise(function (_a, _b) { require(["./0"], _a, _b); }); + new Promise(function (resolve_1, reject_1) { require(["./0"], resolve_1, reject_1); }); + var p1 = new Promise(function (resolve_2, reject_2) { require(["./0"], resolve_2, reject_2); }); p1.then(zero => { return zero.foo(); }); function foo() { - const p2 = new Promise(function (_a, _b) { require(["./0"], _a, _b); }); + const p2 = new Promise(function (resolve_3, reject_3) { require(["./0"], resolve_3, reject_3); }); } }); diff --git a/tests/baselines/reference/importCallExpressionInAMD2.js b/tests/baselines/reference/importCallExpressionInAMD2.js index eb2f2795d3d..bac579d0507 100644 --- a/tests/baselines/reference/importCallExpressionInAMD2.js +++ b/tests/baselines/reference/importCallExpressionInAMD2.js @@ -35,5 +35,5 @@ define(["require", "exports"], function (require, exports) { b.print(); }); } - foo(new Promise(function (_a, _b) { require(["./0"], _a, _b); })); + foo(new Promise(function (resolve_1, reject_1) { require(["./0"], resolve_1, reject_1); })); }); diff --git a/tests/baselines/reference/importCallExpressionInAMD3.js b/tests/baselines/reference/importCallExpressionInAMD3.js index 295dbb9b87e..6245f437398 100644 --- a/tests/baselines/reference/importCallExpressionInAMD3.js +++ b/tests/baselines/reference/importCallExpressionInAMD3.js @@ -26,7 +26,7 @@ define(["require", "exports"], function (require, exports) { define(["require", "exports"], function (require, exports) { "use strict"; async function foo() { - class C extends (await new Promise(function (_a, _b) { require(["./0"], _a, _b); })).B { + class C extends (await new Promise(function (resolve_1, reject_1) { require(["./0"], resolve_1, reject_1); })).B { } var c = new C(); c.print(); diff --git a/tests/baselines/reference/importCallExpressionInAMD4.js b/tests/baselines/reference/importCallExpressionInAMD4.js index ce7a0ba9e23..d498b3df080 100644 --- a/tests/baselines/reference/importCallExpressionInAMD4.js +++ b/tests/baselines/reference/importCallExpressionInAMD4.js @@ -48,14 +48,14 @@ define(["require", "exports"], function (require, exports) { "use strict"; class C { constructor() { - this.myModule = new Promise(function (_a, _b) { require(["./0"], _a, _b); }); + this.myModule = new Promise(function (resolve_1, reject_1) { require(["./0"], resolve_1, reject_1); }); } method() { this.myModule.then(Zero => { console.log(Zero.foo()); }, async (err) => { console.log(err); - let one = await new Promise(function (_a, _b) { require(["./1"], _a, _b); }); + let one = await new Promise(function (resolve_2, reject_2) { require(["./1"], resolve_2, reject_2); }); console.log(one.backup()); }); } diff --git a/tests/baselines/reference/importCallExpressionInCJS1.js b/tests/baselines/reference/importCallExpressionInCJS1.js index a939c78bf49..1b0783fe018 100644 --- a/tests/baselines/reference/importCallExpressionInCJS1.js +++ b/tests/baselines/reference/importCallExpressionInCJS1.js @@ -20,12 +20,11 @@ Object.defineProperty(exports, "__esModule", { value: true }); function foo() { return "foo"; } exports.foo = foo; //// [1.js] -var __resolved = new Promise(function (resolve) { resolve(); }); -__resolved.then(function () { return require("./0"); }); -var p1 = __resolved.then(function () { return require("./0"); }); +Promise.resolve().then(function () { return require("./0"); }); +var p1 = Promise.resolve().then(function () { return require("./0"); }); p1.then(zero => { return zero.foo(); }); function foo() { - const p2 = __resolved.then(function () { return require("./0"); }); + const p2 = Promise.resolve().then(function () { return require("./0"); }); } diff --git a/tests/baselines/reference/importCallExpressionInCJS2.js b/tests/baselines/reference/importCallExpressionInCJS2.js index d21c81b1a15..4a845e2e4e3 100644 --- a/tests/baselines/reference/importCallExpressionInCJS2.js +++ b/tests/baselines/reference/importCallExpressionInCJS2.js @@ -29,13 +29,12 @@ Object.defineProperty(exports, "__esModule", { value: true }); function backup() { return "backup"; } exports.backup = backup; //// [2.js] -var __resolved = new Promise(function (resolve) { resolve(); }); async function compute(promise) { let j = await promise; if (!j) { - j = await __resolved.then(function () { return require("./1"); }); + j = await Promise.resolve().then(function () { return require("./1"); }); return j.backup(); } return j.foo(); } -compute(__resolved.then(function () { return require("./0"); })); +compute(Promise.resolve().then(function () { return require("./0"); })); diff --git a/tests/baselines/reference/importCallExpressionInCJS3.js b/tests/baselines/reference/importCallExpressionInCJS3.js index bce029c4675..a55f57c5674 100644 --- a/tests/baselines/reference/importCallExpressionInCJS3.js +++ b/tests/baselines/reference/importCallExpressionInCJS3.js @@ -24,7 +24,6 @@ class B { } exports.B = B; //// [2.js] -var __resolved = new Promise(function (resolve) { resolve(); }); // We use Promise for now as there is no way to specify shape of module object function foo(x) { x.then(value => { @@ -32,4 +31,4 @@ function foo(x) { b.print(); }); } -foo(__resolved.then(function () { return require("./0"); })); +foo(Promise.resolve().then(function () { return require("./0"); })); diff --git a/tests/baselines/reference/importCallExpressionInCJS4.js b/tests/baselines/reference/importCallExpressionInCJS4.js index aeb537e05bf..0264be113ee 100644 --- a/tests/baselines/reference/importCallExpressionInCJS4.js +++ b/tests/baselines/reference/importCallExpressionInCJS4.js @@ -21,9 +21,8 @@ class B { } exports.B = B; //// [2.js] -var __resolved = new Promise(function (resolve) { resolve(); }); async function foo() { - class C extends (await __resolved.then(function () { return require("./0"); })).B { + class C extends (await Promise.resolve().then(function () { return require("./0"); })).B { } var c = new C(); c.print(); diff --git a/tests/baselines/reference/importCallExpressionInCJS5.js b/tests/baselines/reference/importCallExpressionInCJS5.js index aaa0c0f3d11..196c37e6e72 100644 --- a/tests/baselines/reference/importCallExpressionInCJS5.js +++ b/tests/baselines/reference/importCallExpressionInCJS5.js @@ -40,17 +40,16 @@ Object.defineProperty(exports, "__esModule", { value: true }); function backup() { return "backup"; } exports.backup = backup; //// [2.js] -var __resolved = new Promise(function (resolve) { resolve(); }); class C { constructor() { - this.myModule = __resolved.then(function () { return require("./0"); }); + this.myModule = Promise.resolve().then(function () { return require("./0"); }); } method() { this.myModule.then(Zero => { console.log(Zero.foo()); }, async (err) => { console.log(err); - let one = await __resolved.then(function () { return require("./1"); }); + let one = await Promise.resolve().then(function () { return require("./1"); }); console.log(one.backup()); }); } diff --git a/tests/baselines/reference/importCallExpressionInScriptContext1.js b/tests/baselines/reference/importCallExpressionInScriptContext1.js index 4476fac6c7b..68e51497d14 100644 --- a/tests/baselines/reference/importCallExpressionInScriptContext1.js +++ b/tests/baselines/reference/importCallExpressionInScriptContext1.js @@ -13,6 +13,5 @@ Object.defineProperty(exports, "__esModule", { value: true }); function foo() { return "foo"; } exports.foo = foo; //// [1.js] -var __resolved = new Promise(function (resolve) { resolve(); }); -var p1 = __resolved.then(function () { return require("./0"); }); +var p1 = Promise.resolve().then(function () { return require("./0"); }); function arguments() { } // this is allow as the file doesn't have implicit "use strict" diff --git a/tests/baselines/reference/importCallExpressionInScriptContext2.js b/tests/baselines/reference/importCallExpressionInScriptContext2.js index 594b806ee73..f8bf268468c 100644 --- a/tests/baselines/reference/importCallExpressionInScriptContext2.js +++ b/tests/baselines/reference/importCallExpressionInScriptContext2.js @@ -15,6 +15,5 @@ function foo() { return "foo"; } exports.foo = foo; //// [1.js] "use strict"; -var __resolved = new Promise(function (resolve) { resolve(); }); -var p1 = __resolved.then(function () { return require("./0"); }); +var p1 = Promise.resolve().then(function () { return require("./0"); }); function arguments() { } diff --git a/tests/baselines/reference/importCallExpressionInUMD1.js b/tests/baselines/reference/importCallExpressionInUMD1.js index 317c6452942..0886da93287 100644 --- a/tests/baselines/reference/importCallExpressionInUMD1.js +++ b/tests/baselines/reference/importCallExpressionInUMD1.js @@ -41,13 +41,12 @@ function foo() { })(function (require, exports) { "use strict"; var __syncRequire = typeof module === "object" && typeof module.exports === "object"; - var __resolved = new Promise(function (resolve) { resolve(); }); - __syncRequire ? __resolved.then(function () { return require("./0"); }) : new Promise(function (_a, _b) { require(["./0"], _a, _b); }); - var p1 = __syncRequire ? __resolved.then(function () { return require("./0"); }) : new Promise(function (_a, _b) { require(["./0"], _a, _b); }); + __syncRequire ? Promise.resolve().then(function () { return require("./0"); }) : new Promise(function (resolve_1, reject_1) { require(["./0"], resolve_1, reject_1); }); + var p1 = __syncRequire ? Promise.resolve().then(function () { return require("./0"); }) : new Promise(function (resolve_2, reject_2) { require(["./0"], resolve_2, reject_2); }); p1.then(zero => { return zero.foo(); }); function foo() { - const p2 = __syncRequire ? __resolved.then(function () { return require("./0"); }) : new Promise(function (_a, _b) { require(["./0"], _a, _b); }); + const p2 = __syncRequire ? Promise.resolve().then(function () { return require("./0"); }) : new Promise(function (resolve_3, reject_3) { require(["./0"], resolve_3, reject_3); }); } }); diff --git a/tests/baselines/reference/importCallExpressionInUMD2.js b/tests/baselines/reference/importCallExpressionInUMD2.js index c55b522160f..1e268403088 100644 --- a/tests/baselines/reference/importCallExpressionInUMD2.js +++ b/tests/baselines/reference/importCallExpressionInUMD2.js @@ -45,7 +45,6 @@ foo(import("./0")); })(function (require, exports) { "use strict"; var __syncRequire = typeof module === "object" && typeof module.exports === "object"; - var __resolved = new Promise(function (resolve) { resolve(); }); // We use Promise for now as there is no way to specify shape of module object function foo(x) { x.then(value => { @@ -53,5 +52,5 @@ foo(import("./0")); b.print(); }); } - foo(__syncRequire ? __resolved.then(function () { return require("./0"); }) : new Promise(function (_a, _b) { require(["./0"], _a, _b); })); + foo(__syncRequire ? Promise.resolve().then(function () { return require("./0"); }) : new Promise(function (resolve_1, reject_1) { require(["./0"], resolve_1, reject_1); })); }); diff --git a/tests/baselines/reference/importCallExpressionInUMD3.js b/tests/baselines/reference/importCallExpressionInUMD3.js index 8b8ddef84d1..228c43fd0a2 100644 --- a/tests/baselines/reference/importCallExpressionInUMD3.js +++ b/tests/baselines/reference/importCallExpressionInUMD3.js @@ -42,9 +42,8 @@ foo(); })(function (require, exports) { "use strict"; var __syncRequire = typeof module === "object" && typeof module.exports === "object"; - var __resolved = new Promise(function (resolve) { resolve(); }); async function foo() { - class C extends (await (__syncRequire ? __resolved.then(function () { return require("./0"); }) : new Promise(function (_a, _b) { require(["./0"], _a, _b); }))).B { + class C extends (await (__syncRequire ? Promise.resolve().then(function () { return require("./0"); }) : new Promise(function (resolve_1, reject_1) { require(["./0"], resolve_1, reject_1); }))).B { } var c = new C(); c.print(); diff --git a/tests/baselines/reference/importCallExpressionInUMD4.js b/tests/baselines/reference/importCallExpressionInUMD4.js index 36702c55a7f..677ba8c3d27 100644 --- a/tests/baselines/reference/importCallExpressionInUMD4.js +++ b/tests/baselines/reference/importCallExpressionInUMD4.js @@ -71,17 +71,16 @@ class C { })(function (require, exports) { "use strict"; var __syncRequire = typeof module === "object" && typeof module.exports === "object"; - var __resolved = new Promise(function (resolve) { resolve(); }); class C { constructor() { - this.myModule = __syncRequire ? __resolved.then(function () { return require("./0"); }) : new Promise(function (_a, _b) { require(["./0"], _a, _b); }); + this.myModule = __syncRequire ? Promise.resolve().then(function () { return require("./0"); }) : new Promise(function (resolve_1, reject_1) { require(["./0"], resolve_1, reject_1); }); } method() { this.myModule.then(Zero => { console.log(Zero.foo()); }, async (err) => { console.log(err); - let one = await (__syncRequire ? __resolved.then(function () { return require("./1"); }) : new Promise(function (_a, _b) { require(["./1"], _a, _b); })); + let one = await (__syncRequire ? Promise.resolve().then(function () { return require("./1"); }) : new Promise(function (resolve_2, reject_2) { require(["./1"], resolve_2, reject_2); })); console.log(one.backup()); }); } diff --git a/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.js b/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.js index 5116da7a3fc..d9dba458296 100644 --- a/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.js +++ b/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.js @@ -41,22 +41,21 @@ class C { exports.C = C; //// [1.js] "use strict"; -var __resolved = new Promise(function (resolve) { resolve(); }); Object.defineProperty(exports, "__esModule", { value: true }); -__resolved.then(function () { return require(`${directory}\${moduleFile}`); }); -__resolved.then(function () { return require(getSpecifier()); }); -var p1 = __resolved.then(function () { return require(ValidSomeCondition() ? "./0" : "externalModule"); }); -var p1 = __resolved.then(function () { return require(getSpecifier()); }); -var p11 = __resolved.then(function () { return require(getSpecifier()); }); -const p2 = __resolved.then(function () { return require(whatToLoad ? getSpecifier() : "defaulPath"); }); +Promise.resolve().then(function () { return require(`${directory}\${moduleFile}`); }); +Promise.resolve().then(function () { return require(getSpecifier()); }); +var p1 = Promise.resolve().then(function () { return require(ValidSomeCondition() ? "./0" : "externalModule"); }); +var p1 = Promise.resolve().then(function () { return require(getSpecifier()); }); +var p11 = Promise.resolve().then(function () { return require(getSpecifier()); }); +const p2 = Promise.resolve().then(function () { return require(whatToLoad ? getSpecifier() : "defaulPath"); }); p1.then(zero => { return zero.foo(); // ok, zero is any }); let j; -var p3 = __resolved.then(function () { return require(j = getSpecifier()); }); +var p3 = Promise.resolve().then(function () { return require(j = getSpecifier()); }); function* loadModule(directories) { for (const directory of directories) { const path = `${directory}\moduleFile`; - __resolved.then(function () { return require(yield path); }); + Promise.resolve().then(function () { return require(yield path); }); } } diff --git a/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.js b/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.js index ce0b60dd618..dde35d8048b 100644 --- a/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.js +++ b/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.js @@ -14,13 +14,12 @@ var p3 = import(["path1", "path2"]); var p4 = import(()=>"PathToModule"); //// [importCallExpressionSpecifierNotStringTypeError.js] -var __resolved = new Promise(function (resolve) { resolve(); }); // Error specifier is not assignable to string -__resolved.then(function () { return require(getSpecifier()); }); -var p1 = __resolved.then(function () { return require(getSpecifier()); }); -const p2 = __resolved.then(function () { return require(whatToLoad ? getSpecifier() : "defaulPath"); }); +Promise.resolve().then(function () { return require(getSpecifier()); }); +var p1 = Promise.resolve().then(function () { return require(getSpecifier()); }); +const p2 = Promise.resolve().then(function () { return require(whatToLoad ? getSpecifier() : "defaulPath"); }); p1.then(zero => { return zero.foo(); // ok, zero is any }); -var p3 = __resolved.then(function () { return require(["path1", "path2"]); }); -var p4 = __resolved.then(function () { return require(() => "PathToModule"); }); +var p3 = Promise.resolve().then(function () { return require(["path1", "path2"]); }); +var p4 = Promise.resolve().then(function () { return require(() => "PathToModule"); }); From 9203f952eda8132aa4007d5b38de36b4b3d62184 Mon Sep 17 00:00:00 2001 From: Yui T Date: Fri, 2 Jun 2017 09:16:17 -0700 Subject: [PATCH 60/67] Update name change of isSpreadExpression --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c3cd566894a..bd3714537ba 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -24680,7 +24680,7 @@ namespace ts { // see: parseArgumentOrArrayLiteralElement...we use this function which parse arguments of callExpression to parse specifier for dynamic import. // parseArgumentOrArrayLiteralElement allows spread element to be in an argument list which is not allowed as specifier in dynamic import. - if (isSpreadExpression(arguments[0])) { + if (isSpreadElement(arguments[0])) { return grammarErrorOnNode(arguments[0], Diagnostics.Specifier_of_dynamic_import_cannot_be_spread_element); } } From 4733f0dcb3cca4d694e696bc196bb9b0216e9e01 Mon Sep 17 00:00:00 2001 From: Yui T Date: Fri, 2 Jun 2017 09:21:15 -0700 Subject: [PATCH 61/67] Fix linting --- src/compiler/transformers/module/module.ts | 2 +- src/compiler/transformers/module/system.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index f776ec23695..b2e1c1c70a9 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -554,7 +554,7 @@ namespace ts { // new Promise(function (_a, _b) { require([x], _a, _b); }); /*Amd Require*/ // }); const resolve = createUniqueName("resolve"); - const reject = createUniqueName("reject") + const reject = createUniqueName("reject"); return createNew( createIdentifier("Promise"), /*typeArguments*/ undefined, diff --git a/src/compiler/transformers/module/system.ts b/src/compiler/transformers/module/system.ts index 5c0a42ef66a..fa126d1faa7 100644 --- a/src/compiler/transformers/module/system.ts +++ b/src/compiler/transformers/module/system.ts @@ -50,7 +50,7 @@ namespace ts { * @param node The SourceFile node. */ function transformSourceFile(node: SourceFile) { - if (node.isDeclarationFile || !(isEffectiveExternalModule(node, compilerOptions)|| node.transformFlags & TransformFlags.ContainsDynamicImport)) { + if (node.isDeclarationFile || !(isEffectiveExternalModule(node, compilerOptions) || node.transformFlags & TransformFlags.ContainsDynamicImport)) { return node; } From c2056c0579dbc84f234cc359068e84ab48500518 Mon Sep 17 00:00:00 2001 From: Yui T Date: Fri, 2 Jun 2017 16:13:32 -0700 Subject: [PATCH 62/67] Address minor error messages --- src/compiler/checker.ts | 2 +- src/compiler/diagnosticMessages.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index bd3714537ba..c647a8ad554 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -16368,7 +16368,7 @@ namespace ts { const promiseType = createPromiseType(promisedType); if (promiseType === emptyObjectType) { error(func, isImportCall(func) ? - Diagnostics.A_dynamic_import_call_return_a_Promise_Make_sure_you_have_a_declaration_for_Promise_or_include_ES2015_in_your_lib_option : + Diagnostics.A_dynamic_import_call_returns_a_Promise_Make_sure_you_have_a_declaration_for_Promise_or_include_ES2015_in_your_lib_option : Diagnostics.An_async_function_or_method_must_return_a_Promise_Make_sure_you_have_a_declaration_for_Promise_or_include_ES2015_in_your_lib_option); return unknownType; } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 4a6c2153567..6bcd28811f9 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2172,7 +2172,7 @@ "category": "Error", "code": 2710 }, - "A dynamic import call return a 'Promise'. Make sure you have a declaration for 'Promise' or include 'ES2015' in your `--lib` option.": { + "A dynamic import call returns a 'Promise'. Make sure you have a declaration for 'Promise' or include 'ES2015' in your `--lib` option.": { "category": "Error", "code": 2711 }, From e386d65ed62e3596573af0482de858bb08f1ee95 Mon Sep 17 00:00:00 2001 From: Yui T Date: Sun, 4 Jun 2017 19:58:24 -0700 Subject: [PATCH 63/67] Use ESNext instead of ES2018 --- src/compiler/commandLineParser.ts | 4 ++-- src/compiler/diagnosticMessages.json | 2 +- src/compiler/transformer.ts | 2 +- src/compiler/types.ts | 2 +- .../tsConfig/Default initialized TSConfig/tsconfig.json | 2 +- .../tsconfig.json | 2 +- .../tsconfig.json | 2 +- .../Initialized TSConfig with files options/tsconfig.json | 2 +- .../tsconfig.json | 2 +- .../tsconfig.json | 2 +- .../tsconfig.json | 2 +- .../tsconfig.json | 2 +- 12 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 033f6b5ab59..adb6a0df189 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -100,12 +100,12 @@ namespace ts { "umd": ModuleKind.UMD, "es6": ModuleKind.ES2015, "es2015": ModuleKind.ES2015, - "es2018": ModuleKind.ES2018 + "es2018": ModuleKind.ESNext }), paramType: Diagnostics.KIND, showInSimplifiedHelpView: true, category: Diagnostics.Basic_Options, - description: Diagnostics.Specify_module_code_generation_Colon_commonjs_amd_system_umd_es2015_or_es2018, + description: Diagnostics.Specify_module_code_generation_Colon_commonjs_amd_system_umd_es2015_or_ESNext, }, { name: "lib", diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 6bcd28811f9..a74d41ff473 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2646,7 +2646,7 @@ "category": "Message", "code": 6015 }, - "Specify module code generation: 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'es2018'.": { + "Specify module code generation: 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'.": { "category": "Message", "code": 6016 }, diff --git a/src/compiler/transformer.ts b/src/compiler/transformer.ts index cd5cc95e2e1..f0c827d8396 100644 --- a/src/compiler/transformer.ts +++ b/src/compiler/transformer.ts @@ -15,7 +15,7 @@ namespace ts { function getModuleTransformer(moduleKind: ModuleKind): TransformerFactory { switch (moduleKind) { - case ModuleKind.ES2018: + case ModuleKind.ESNext: case ModuleKind.ES2015: return transformES2015Module; case ModuleKind.System: diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 57c193297bc..8fb3d98fca8 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3579,7 +3579,7 @@ namespace ts { UMD = 3, System = 4, ES2015 = 5, - ES2018 = 6 + ESNext = 6 } export const enum JsxEmit { diff --git a/tests/baselines/reference/tsConfig/Default initialized TSConfig/tsconfig.json b/tests/baselines/reference/tsConfig/Default initialized TSConfig/tsconfig.json index 0ef3acb7c06..772c218eb4e 100644 --- a/tests/baselines/reference/tsConfig/Default initialized TSConfig/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Default initialized TSConfig/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { /* Basic Options */ "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */ - "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'es2018'. */ + "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ // "lib": [], /* Specify library files to be included in the compilation: */ // "allowJs": true, /* Allow javascript files to be compiled. */ // "checkJs": true, /* Report errors in .js files. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json index bffdc71b254..7a9b895636c 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { /* Basic Options */ "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */ - "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'es2018'. */ + "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ // "lib": [], /* Specify library files to be included in the compilation: */ // "allowJs": true, /* Allow javascript files to be compiled. */ // "checkJs": true, /* Report errors in .js files. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with enum value compiler options/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with enum value compiler options/tsconfig.json index 8ab4a03a9ca..70d5ed9d738 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with enum value compiler options/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with enum value compiler options/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { /* Basic Options */ "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */ - "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'es2018'. */ + "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ // "lib": [], /* Specify library files to be included in the compilation: */ // "allowJs": true, /* Allow javascript files to be compiled. */ // "checkJs": true, /* Report errors in .js files. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with files options/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with files options/tsconfig.json index 914e7432f14..914b9d99d1b 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with files options/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with files options/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { /* Basic Options */ "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */ - "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'es2018'. */ + "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ // "lib": [], /* Specify library files to be included in the compilation: */ // "allowJs": true, /* Allow javascript files to be compiled. */ // "checkJs": true, /* Report errors in .js files. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json index 4797ea79f57..50bd28442bb 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { /* Basic Options */ "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */ - "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'es2018'. */ + "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ "lib": ["es5","es2015.promise"], /* Specify library files to be included in the compilation: */ // "allowJs": true, /* Allow javascript files to be compiled. */ // "checkJs": true, /* Report errors in .js files. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json index 0ef3acb7c06..772c218eb4e 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { /* Basic Options */ "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */ - "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'es2018'. */ + "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ // "lib": [], /* Specify library files to be included in the compilation: */ // "allowJs": true, /* Allow javascript files to be compiled. */ // "checkJs": true, /* Report errors in .js files. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json index 8f6aeadad34..afae7193d58 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { /* Basic Options */ "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */ - "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'es2018'. */ + "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ "lib": ["es5","es2015.core"], /* Specify library files to be included in the compilation: */ // "allowJs": true, /* Allow javascript files to be compiled. */ // "checkJs": true, /* Report errors in .js files. */ diff --git a/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options/tsconfig.json b/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options/tsconfig.json index e5b684c9863..a87fe9c5206 100644 --- a/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Initialized TSConfig with list compiler options/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { /* Basic Options */ "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */ - "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'es2018'. */ + "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ // "lib": [], /* Specify library files to be included in the compilation: */ // "allowJs": true, /* Allow javascript files to be compiled. */ // "checkJs": true, /* Report errors in .js files. */ From 3118afe9bcb4fc365d19c0d84fb9acb1907c2081 Mon Sep 17 00:00:00 2001 From: Yui T Date: Sun, 4 Jun 2017 20:32:12 -0700 Subject: [PATCH 64/67] Remove ES2018 folder --- .../importCallExpression1ESNext.ts} | 2 +- .../importCallExpression2ESNext.ts} | 2 +- .../importCallExpression3ESNext.ts} | 2 +- .../importCallExpression4ESNext.ts} | 2 +- .../importCallExpression5ESNext.ts} | 2 +- .../importCallExpression6ESNext.ts} | 2 +- .../dynamicImport/importCallExpressionCheckReturntype1.ts | 0 .../dynamicImport/importCallExpressionDeclarationEmit1.ts | 0 .../dynamicImport/importCallExpressionDeclarationEmit2.ts | 2 +- .../dynamicImport/importCallExpressionDeclarationEmit3.ts | 2 +- .../{es2018 => }/dynamicImport/importCallExpressionES5AMD.ts | 0 .../{es2018 => }/dynamicImport/importCallExpressionES5CJS.ts | 0 .../{es2018 => }/dynamicImport/importCallExpressionES5System.ts | 0 .../{es2018 => }/dynamicImport/importCallExpressionES5UMD.ts | 0 .../dynamicImport/importCallExpressionErrorInES2015.ts | 0 .../dynamicImport/importCallExpressionGrammarError.ts | 0 .../{es2018 => }/dynamicImport/importCallExpressionInAMD1.ts | 0 .../{es2018 => }/dynamicImport/importCallExpressionInAMD2.ts | 0 .../{es2018 => }/dynamicImport/importCallExpressionInAMD3.ts | 0 .../{es2018 => }/dynamicImport/importCallExpressionInAMD4.ts | 0 .../{es2018 => }/dynamicImport/importCallExpressionInCJS1.ts | 0 .../{es2018 => }/dynamicImport/importCallExpressionInCJS2.ts | 0 .../{es2018 => }/dynamicImport/importCallExpressionInCJS3.ts | 0 .../{es2018 => }/dynamicImport/importCallExpressionInCJS4.ts | 0 .../{es2018 => }/dynamicImport/importCallExpressionInCJS5.ts | 0 .../dynamicImport/importCallExpressionInScriptContext1.ts | 0 .../dynamicImport/importCallExpressionInScriptContext2.ts | 0 .../{es2018 => }/dynamicImport/importCallExpressionInSystem1.ts | 0 .../{es2018 => }/dynamicImport/importCallExpressionInSystem2.ts | 0 .../{es2018 => }/dynamicImport/importCallExpressionInSystem3.ts | 0 .../{es2018 => }/dynamicImport/importCallExpressionInSystem4.ts | 0 .../{es2018 => }/dynamicImport/importCallExpressionInUMD1.ts | 0 .../{es2018 => }/dynamicImport/importCallExpressionInUMD2.ts | 0 .../{es2018 => }/dynamicImport/importCallExpressionInUMD3.ts | 0 .../{es2018 => }/dynamicImport/importCallExpressionInUMD4.ts | 0 .../dynamicImport/importCallExpressionReturnPromiseOfAny.ts | 0 .../importCallExpressionSpecifierNotStringTypeError.ts | 0 .../dynamicImport/importCallExpressionWithTypeArgument.ts | 0 38 files changed, 8 insertions(+), 8 deletions(-) rename tests/cases/conformance/{es2018/dynamicImport/importCallExpression1ES2018.ts => dynamicImport/importCallExpression1ESNext.ts} (86%) rename tests/cases/conformance/{es2018/dynamicImport/importCallExpression2ES2018.ts => dynamicImport/importCallExpression2ESNext.ts} (86%) rename tests/cases/conformance/{es2018/dynamicImport/importCallExpression3ES2018.ts => dynamicImport/importCallExpression3ESNext.ts} (86%) rename tests/cases/conformance/{es2018/dynamicImport/importCallExpression4ES2018.ts => dynamicImport/importCallExpression4ESNext.ts} (91%) rename tests/cases/conformance/{es2018/dynamicImport/importCallExpression5ES2018.ts => dynamicImport/importCallExpression5ESNext.ts} (91%) rename tests/cases/conformance/{es2018/dynamicImport/importCallExpression6ES2018.ts => dynamicImport/importCallExpression6ESNext.ts} (91%) rename tests/cases/conformance/{es2018 => }/dynamicImport/importCallExpressionCheckReturntype1.ts (100%) rename tests/cases/conformance/{es2018 => }/dynamicImport/importCallExpressionDeclarationEmit1.ts (100%) rename tests/cases/conformance/{es2018 => }/dynamicImport/importCallExpressionDeclarationEmit2.ts (84%) rename tests/cases/conformance/{es2018 => }/dynamicImport/importCallExpressionDeclarationEmit3.ts (91%) rename tests/cases/conformance/{es2018 => }/dynamicImport/importCallExpressionES5AMD.ts (100%) rename tests/cases/conformance/{es2018 => }/dynamicImport/importCallExpressionES5CJS.ts (100%) rename tests/cases/conformance/{es2018 => }/dynamicImport/importCallExpressionES5System.ts (100%) rename tests/cases/conformance/{es2018 => }/dynamicImport/importCallExpressionES5UMD.ts (100%) rename tests/cases/conformance/{es2018 => }/dynamicImport/importCallExpressionErrorInES2015.ts (100%) rename tests/cases/conformance/{es2018 => }/dynamicImport/importCallExpressionGrammarError.ts (100%) rename tests/cases/conformance/{es2018 => }/dynamicImport/importCallExpressionInAMD1.ts (100%) rename tests/cases/conformance/{es2018 => }/dynamicImport/importCallExpressionInAMD2.ts (100%) rename tests/cases/conformance/{es2018 => }/dynamicImport/importCallExpressionInAMD3.ts (100%) rename tests/cases/conformance/{es2018 => }/dynamicImport/importCallExpressionInAMD4.ts (100%) rename tests/cases/conformance/{es2018 => }/dynamicImport/importCallExpressionInCJS1.ts (100%) rename tests/cases/conformance/{es2018 => }/dynamicImport/importCallExpressionInCJS2.ts (100%) rename tests/cases/conformance/{es2018 => }/dynamicImport/importCallExpressionInCJS3.ts (100%) rename tests/cases/conformance/{es2018 => }/dynamicImport/importCallExpressionInCJS4.ts (100%) rename tests/cases/conformance/{es2018 => }/dynamicImport/importCallExpressionInCJS5.ts (100%) rename tests/cases/conformance/{es2018 => }/dynamicImport/importCallExpressionInScriptContext1.ts (100%) rename tests/cases/conformance/{es2018 => }/dynamicImport/importCallExpressionInScriptContext2.ts (100%) rename tests/cases/conformance/{es2018 => }/dynamicImport/importCallExpressionInSystem1.ts (100%) rename tests/cases/conformance/{es2018 => }/dynamicImport/importCallExpressionInSystem2.ts (100%) rename tests/cases/conformance/{es2018 => }/dynamicImport/importCallExpressionInSystem3.ts (100%) rename tests/cases/conformance/{es2018 => }/dynamicImport/importCallExpressionInSystem4.ts (100%) rename tests/cases/conformance/{es2018 => }/dynamicImport/importCallExpressionInUMD1.ts (100%) rename tests/cases/conformance/{es2018 => }/dynamicImport/importCallExpressionInUMD2.ts (100%) rename tests/cases/conformance/{es2018 => }/dynamicImport/importCallExpressionInUMD3.ts (100%) rename tests/cases/conformance/{es2018 => }/dynamicImport/importCallExpressionInUMD4.ts (100%) rename tests/cases/conformance/{es2018 => }/dynamicImport/importCallExpressionReturnPromiseOfAny.ts (100%) rename tests/cases/conformance/{es2018 => }/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts (100%) rename tests/cases/conformance/{es2018 => }/dynamicImport/importCallExpressionWithTypeArgument.ts (100%) diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpression1ES2018.ts b/tests/cases/conformance/dynamicImport/importCallExpression1ESNext.ts similarity index 86% rename from tests/cases/conformance/es2018/dynamicImport/importCallExpression1ES2018.ts rename to tests/cases/conformance/dynamicImport/importCallExpression1ESNext.ts index f7abb325d99..295b6470301 100644 --- a/tests/cases/conformance/es2018/dynamicImport/importCallExpression1ES2018.ts +++ b/tests/cases/conformance/dynamicImport/importCallExpression1ESNext.ts @@ -1,4 +1,4 @@ -// @module: es2018 +// @module: esnext // @target: esnext // @filename: 0.ts export function foo() { return "foo"; } diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpression2ES2018.ts b/tests/cases/conformance/dynamicImport/importCallExpression2ESNext.ts similarity index 86% rename from tests/cases/conformance/es2018/dynamicImport/importCallExpression2ES2018.ts rename to tests/cases/conformance/dynamicImport/importCallExpression2ESNext.ts index 994e6f9e776..f0e9b358854 100644 --- a/tests/cases/conformance/es2018/dynamicImport/importCallExpression2ES2018.ts +++ b/tests/cases/conformance/dynamicImport/importCallExpression2ESNext.ts @@ -1,4 +1,4 @@ -// @module: es2018 +// @module: esnext // @target: esnext // @filename: 0.ts export class B { diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpression3ES2018.ts b/tests/cases/conformance/dynamicImport/importCallExpression3ESNext.ts similarity index 86% rename from tests/cases/conformance/es2018/dynamicImport/importCallExpression3ES2018.ts rename to tests/cases/conformance/dynamicImport/importCallExpression3ESNext.ts index 6b2fc219d24..ee7264b8c7e 100644 --- a/tests/cases/conformance/es2018/dynamicImport/importCallExpression3ES2018.ts +++ b/tests/cases/conformance/dynamicImport/importCallExpression3ESNext.ts @@ -1,4 +1,4 @@ -// @module: es2018 +// @module: esnext // @target: esnext // @filename: 0.ts export class B { diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpression4ES2018.ts b/tests/cases/conformance/dynamicImport/importCallExpression4ESNext.ts similarity index 91% rename from tests/cases/conformance/es2018/dynamicImport/importCallExpression4ES2018.ts rename to tests/cases/conformance/dynamicImport/importCallExpression4ESNext.ts index 03e72bb6d4d..91342770d7d 100644 --- a/tests/cases/conformance/es2018/dynamicImport/importCallExpression4ES2018.ts +++ b/tests/cases/conformance/dynamicImport/importCallExpression4ESNext.ts @@ -1,4 +1,4 @@ -// @module: es2018 +// @module: esnext // @target: esnext // @filename: 0.ts export class B { diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpression5ES2018.ts b/tests/cases/conformance/dynamicImport/importCallExpression5ESNext.ts similarity index 91% rename from tests/cases/conformance/es2018/dynamicImport/importCallExpression5ES2018.ts rename to tests/cases/conformance/dynamicImport/importCallExpression5ESNext.ts index 254e99f3907..173b606a50c 100644 --- a/tests/cases/conformance/es2018/dynamicImport/importCallExpression5ES2018.ts +++ b/tests/cases/conformance/dynamicImport/importCallExpression5ESNext.ts @@ -1,4 +1,4 @@ -// @module: es2018 +// @module: esnext // @target: esnext // @strictNullChecks: true // @filename: 0.ts diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpression6ES2018.ts b/tests/cases/conformance/dynamicImport/importCallExpression6ESNext.ts similarity index 91% rename from tests/cases/conformance/es2018/dynamicImport/importCallExpression6ES2018.ts rename to tests/cases/conformance/dynamicImport/importCallExpression6ESNext.ts index 8c1a1071fbc..f09521186e8 100644 --- a/tests/cases/conformance/es2018/dynamicImport/importCallExpression6ES2018.ts +++ b/tests/cases/conformance/dynamicImport/importCallExpression6ESNext.ts @@ -1,4 +1,4 @@ -// @module: es2018 +// @module: esnext // @target: esnext // @filename: 0.ts export class B { diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionCheckReturntype1.ts b/tests/cases/conformance/dynamicImport/importCallExpressionCheckReturntype1.ts similarity index 100% rename from tests/cases/conformance/es2018/dynamicImport/importCallExpressionCheckReturntype1.ts rename to tests/cases/conformance/dynamicImport/importCallExpressionCheckReturntype1.ts diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionDeclarationEmit1.ts b/tests/cases/conformance/dynamicImport/importCallExpressionDeclarationEmit1.ts similarity index 100% rename from tests/cases/conformance/es2018/dynamicImport/importCallExpressionDeclarationEmit1.ts rename to tests/cases/conformance/dynamicImport/importCallExpressionDeclarationEmit1.ts diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionDeclarationEmit2.ts b/tests/cases/conformance/dynamicImport/importCallExpressionDeclarationEmit2.ts similarity index 84% rename from tests/cases/conformance/es2018/dynamicImport/importCallExpressionDeclarationEmit2.ts rename to tests/cases/conformance/dynamicImport/importCallExpressionDeclarationEmit2.ts index 7d9b5fec1d0..4b9196dea20 100644 --- a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionDeclarationEmit2.ts +++ b/tests/cases/conformance/dynamicImport/importCallExpressionDeclarationEmit2.ts @@ -1,4 +1,4 @@ -// @module: es2018 +// @module: esnext // @target: esnext // @declaration: true diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionDeclarationEmit3.ts b/tests/cases/conformance/dynamicImport/importCallExpressionDeclarationEmit3.ts similarity index 91% rename from tests/cases/conformance/es2018/dynamicImport/importCallExpressionDeclarationEmit3.ts rename to tests/cases/conformance/dynamicImport/importCallExpressionDeclarationEmit3.ts index cde7ad0a42f..6d17d624190 100644 --- a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionDeclarationEmit3.ts +++ b/tests/cases/conformance/dynamicImport/importCallExpressionDeclarationEmit3.ts @@ -1,4 +1,4 @@ -// @module: es2018 +// @module: esnext // @target: esnext // @declaration: true diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionES5AMD.ts b/tests/cases/conformance/dynamicImport/importCallExpressionES5AMD.ts similarity index 100% rename from tests/cases/conformance/es2018/dynamicImport/importCallExpressionES5AMD.ts rename to tests/cases/conformance/dynamicImport/importCallExpressionES5AMD.ts diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionES5CJS.ts b/tests/cases/conformance/dynamicImport/importCallExpressionES5CJS.ts similarity index 100% rename from tests/cases/conformance/es2018/dynamicImport/importCallExpressionES5CJS.ts rename to tests/cases/conformance/dynamicImport/importCallExpressionES5CJS.ts diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionES5System.ts b/tests/cases/conformance/dynamicImport/importCallExpressionES5System.ts similarity index 100% rename from tests/cases/conformance/es2018/dynamicImport/importCallExpressionES5System.ts rename to tests/cases/conformance/dynamicImport/importCallExpressionES5System.ts diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionES5UMD.ts b/tests/cases/conformance/dynamicImport/importCallExpressionES5UMD.ts similarity index 100% rename from tests/cases/conformance/es2018/dynamicImport/importCallExpressionES5UMD.ts rename to tests/cases/conformance/dynamicImport/importCallExpressionES5UMD.ts diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionErrorInES2015.ts b/tests/cases/conformance/dynamicImport/importCallExpressionErrorInES2015.ts similarity index 100% rename from tests/cases/conformance/es2018/dynamicImport/importCallExpressionErrorInES2015.ts rename to tests/cases/conformance/dynamicImport/importCallExpressionErrorInES2015.ts diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts b/tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts similarity index 100% rename from tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts rename to tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInAMD1.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInAMD1.ts similarity index 100% rename from tests/cases/conformance/es2018/dynamicImport/importCallExpressionInAMD1.ts rename to tests/cases/conformance/dynamicImport/importCallExpressionInAMD1.ts diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInAMD2.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInAMD2.ts similarity index 100% rename from tests/cases/conformance/es2018/dynamicImport/importCallExpressionInAMD2.ts rename to tests/cases/conformance/dynamicImport/importCallExpressionInAMD2.ts diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInAMD3.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInAMD3.ts similarity index 100% rename from tests/cases/conformance/es2018/dynamicImport/importCallExpressionInAMD3.ts rename to tests/cases/conformance/dynamicImport/importCallExpressionInAMD3.ts diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInAMD4.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInAMD4.ts similarity index 100% rename from tests/cases/conformance/es2018/dynamicImport/importCallExpressionInAMD4.ts rename to tests/cases/conformance/dynamicImport/importCallExpressionInAMD4.ts diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInCJS1.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInCJS1.ts similarity index 100% rename from tests/cases/conformance/es2018/dynamicImport/importCallExpressionInCJS1.ts rename to tests/cases/conformance/dynamicImport/importCallExpressionInCJS1.ts diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInCJS2.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInCJS2.ts similarity index 100% rename from tests/cases/conformance/es2018/dynamicImport/importCallExpressionInCJS2.ts rename to tests/cases/conformance/dynamicImport/importCallExpressionInCJS2.ts diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInCJS3.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInCJS3.ts similarity index 100% rename from tests/cases/conformance/es2018/dynamicImport/importCallExpressionInCJS3.ts rename to tests/cases/conformance/dynamicImport/importCallExpressionInCJS3.ts diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInCJS4.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInCJS4.ts similarity index 100% rename from tests/cases/conformance/es2018/dynamicImport/importCallExpressionInCJS4.ts rename to tests/cases/conformance/dynamicImport/importCallExpressionInCJS4.ts diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInCJS5.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInCJS5.ts similarity index 100% rename from tests/cases/conformance/es2018/dynamicImport/importCallExpressionInCJS5.ts rename to tests/cases/conformance/dynamicImport/importCallExpressionInCJS5.ts diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInScriptContext1.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInScriptContext1.ts similarity index 100% rename from tests/cases/conformance/es2018/dynamicImport/importCallExpressionInScriptContext1.ts rename to tests/cases/conformance/dynamicImport/importCallExpressionInScriptContext1.ts diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInScriptContext2.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInScriptContext2.ts similarity index 100% rename from tests/cases/conformance/es2018/dynamicImport/importCallExpressionInScriptContext2.ts rename to tests/cases/conformance/dynamicImport/importCallExpressionInScriptContext2.ts diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInSystem1.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInSystem1.ts similarity index 100% rename from tests/cases/conformance/es2018/dynamicImport/importCallExpressionInSystem1.ts rename to tests/cases/conformance/dynamicImport/importCallExpressionInSystem1.ts diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInSystem2.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInSystem2.ts similarity index 100% rename from tests/cases/conformance/es2018/dynamicImport/importCallExpressionInSystem2.ts rename to tests/cases/conformance/dynamicImport/importCallExpressionInSystem2.ts diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInSystem3.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInSystem3.ts similarity index 100% rename from tests/cases/conformance/es2018/dynamicImport/importCallExpressionInSystem3.ts rename to tests/cases/conformance/dynamicImport/importCallExpressionInSystem3.ts diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInSystem4.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInSystem4.ts similarity index 100% rename from tests/cases/conformance/es2018/dynamicImport/importCallExpressionInSystem4.ts rename to tests/cases/conformance/dynamicImport/importCallExpressionInSystem4.ts diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInUMD1.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInUMD1.ts similarity index 100% rename from tests/cases/conformance/es2018/dynamicImport/importCallExpressionInUMD1.ts rename to tests/cases/conformance/dynamicImport/importCallExpressionInUMD1.ts diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInUMD2.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInUMD2.ts similarity index 100% rename from tests/cases/conformance/es2018/dynamicImport/importCallExpressionInUMD2.ts rename to tests/cases/conformance/dynamicImport/importCallExpressionInUMD2.ts diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInUMD3.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInUMD3.ts similarity index 100% rename from tests/cases/conformance/es2018/dynamicImport/importCallExpressionInUMD3.ts rename to tests/cases/conformance/dynamicImport/importCallExpressionInUMD3.ts diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionInUMD4.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInUMD4.ts similarity index 100% rename from tests/cases/conformance/es2018/dynamicImport/importCallExpressionInUMD4.ts rename to tests/cases/conformance/dynamicImport/importCallExpressionInUMD4.ts diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionReturnPromiseOfAny.ts b/tests/cases/conformance/dynamicImport/importCallExpressionReturnPromiseOfAny.ts similarity index 100% rename from tests/cases/conformance/es2018/dynamicImport/importCallExpressionReturnPromiseOfAny.ts rename to tests/cases/conformance/dynamicImport/importCallExpressionReturnPromiseOfAny.ts diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts b/tests/cases/conformance/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts similarity index 100% rename from tests/cases/conformance/es2018/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts rename to tests/cases/conformance/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts diff --git a/tests/cases/conformance/es2018/dynamicImport/importCallExpressionWithTypeArgument.ts b/tests/cases/conformance/dynamicImport/importCallExpressionWithTypeArgument.ts similarity index 100% rename from tests/cases/conformance/es2018/dynamicImport/importCallExpressionWithTypeArgument.ts rename to tests/cases/conformance/dynamicImport/importCallExpressionWithTypeArgument.ts From 75aa4bdbccde8745c8dbeeea395f83b293c60a5e Mon Sep 17 00:00:00 2001 From: Yui T Date: Sun, 4 Jun 2017 21:08:05 -0700 Subject: [PATCH 65/67] Rename test file with ES2018 to ESNext --- .../importCallExpression1ES2018.types | 39 ------------------- ...2018.js => importCallExpression1ESNext.js} | 2 +- ...ls => importCallExpression1ESNext.symbols} | 4 +- .../importCallExpression1ESNext.types | 39 +++++++++++++++++++ ...2018.js => importCallExpression2ESNext.js} | 2 +- ...ls => importCallExpression2ESNext.symbols} | 4 +- ...ypes => importCallExpression2ESNext.types} | 6 +-- ...2018.js => importCallExpression3ESNext.js} | 2 +- ...ls => importCallExpression3ESNext.symbols} | 4 +- ...ypes => importCallExpression3ESNext.types} | 10 ++--- ...2018.js => importCallExpression4ESNext.js} | 2 +- ...ls => importCallExpression4ESNext.symbols} | 6 +-- ...ypes => importCallExpression4ESNext.types} | 32 +++++++-------- ...=> importCallExpression5ESNext.errors.txt} | 14 +++---- ...2018.js => importCallExpression5ESNext.js} | 2 +- ...=> importCallExpression6ESNext.errors.txt} | 10 ++--- ...2018.js => importCallExpression6ESNext.js} | 2 +- 17 files changed, 90 insertions(+), 90 deletions(-) delete mode 100644 tests/baselines/reference/importCallExpression1ES2018.types rename tests/baselines/reference/{importCallExpression1ES2018.js => importCallExpression1ESNext.js} (78%) rename tests/baselines/reference/{importCallExpression1ES2018.symbols => importCallExpression1ESNext.symbols} (81%) create mode 100644 tests/baselines/reference/importCallExpression1ESNext.types rename tests/baselines/reference/{importCallExpression2ES2018.js => importCallExpression2ESNext.js} (79%) rename tests/baselines/reference/{importCallExpression2ES2018.symbols => importCallExpression2ESNext.symbols} (85%) rename tests/baselines/reference/{importCallExpression2ES2018.types => importCallExpression2ESNext.types} (82%) rename tests/baselines/reference/{importCallExpression3ES2018.js => importCallExpression3ESNext.js} (78%) rename tests/baselines/reference/{importCallExpression3ES2018.symbols => importCallExpression3ESNext.symbols} (81%) rename tests/baselines/reference/{importCallExpression3ES2018.types => importCallExpression3ESNext.types} (54%) rename tests/baselines/reference/{importCallExpression4ES2018.js => importCallExpression4ESNext.js} (89%) rename tests/baselines/reference/{importCallExpression4ES2018.symbols => importCallExpression4ESNext.symbols} (87%) rename tests/baselines/reference/{importCallExpression4ES2018.types => importCallExpression4ESNext.types} (53%) rename tests/baselines/reference/{importCallExpression5ES2018.errors.txt => importCallExpression5ESNext.errors.txt} (52%) rename tests/baselines/reference/{importCallExpression5ES2018.js => importCallExpression5ESNext.js} (87%) rename tests/baselines/reference/{importCallExpression6ES2018.errors.txt => importCallExpression6ESNext.errors.txt} (55%) rename tests/baselines/reference/{importCallExpression6ES2018.js => importCallExpression6ESNext.js} (87%) diff --git a/tests/baselines/reference/importCallExpression1ES2018.types b/tests/baselines/reference/importCallExpression1ES2018.types deleted file mode 100644 index 6d67b0f20b4..00000000000 --- a/tests/baselines/reference/importCallExpression1ES2018.types +++ /dev/null @@ -1,39 +0,0 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === -export function foo() { return "foo"; } ->foo : () => string ->"foo" : "foo" - -=== tests/cases/conformance/es2018/dynamicImport/1.ts === -import("./0"); ->import("./0") : Promise ->"./0" : "./0" - -var p1 = import("./0"); ->p1 : Promise ->import("./0") : Promise ->"./0" : "./0" - -p1.then(zero => { ->p1.then(zero => { return zero.foo();}) : Promise ->p1.then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->p1 : Promise ->then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->zero => { return zero.foo();} : (zero: typeof "tests/cases/conformance/es2018/dynamicImport/0") => string ->zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" - - return zero.foo(); ->zero.foo() : string ->zero.foo : () => string ->zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" ->foo : () => string - -}) - -function foo() { ->foo : () => void - - const p2 = import("./0"); ->p2 : Promise ->import("./0") : Promise ->"./0" : "./0" -} diff --git a/tests/baselines/reference/importCallExpression1ES2018.js b/tests/baselines/reference/importCallExpression1ESNext.js similarity index 78% rename from tests/baselines/reference/importCallExpression1ES2018.js rename to tests/baselines/reference/importCallExpression1ESNext.js index e98562ba360..39b779c921f 100644 --- a/tests/baselines/reference/importCallExpression1ES2018.js +++ b/tests/baselines/reference/importCallExpression1ESNext.js @@ -1,4 +1,4 @@ -//// [tests/cases/conformance/es2018/dynamicImport/importCallExpression1ES2018.ts] //// +//// [tests/cases/conformance/dynamicImport/importCallExpression1ESNext.ts] //// //// [0.ts] export function foo() { return "foo"; } diff --git a/tests/baselines/reference/importCallExpression1ES2018.symbols b/tests/baselines/reference/importCallExpression1ESNext.symbols similarity index 81% rename from tests/baselines/reference/importCallExpression1ES2018.symbols rename to tests/baselines/reference/importCallExpression1ESNext.symbols index 93f0d8f6deb..28b5ba13e99 100644 --- a/tests/baselines/reference/importCallExpression1ES2018.symbols +++ b/tests/baselines/reference/importCallExpression1ESNext.symbols @@ -1,8 +1,8 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export function foo() { return "foo"; } >foo : Symbol(foo, Decl(0.ts, 0, 0)) -=== tests/cases/conformance/es2018/dynamicImport/1.ts === +=== tests/cases/conformance/dynamicImport/1.ts === import("./0"); var p1 = import("./0"); >p1 : Symbol(p1, Decl(1.ts, 1, 3)) diff --git a/tests/baselines/reference/importCallExpression1ESNext.types b/tests/baselines/reference/importCallExpression1ESNext.types new file mode 100644 index 00000000000..53a1b3d08fa --- /dev/null +++ b/tests/baselines/reference/importCallExpression1ESNext.types @@ -0,0 +1,39 @@ +=== tests/cases/conformance/dynamicImport/0.ts === +export function foo() { return "foo"; } +>foo : () => string +>"foo" : "foo" + +=== tests/cases/conformance/dynamicImport/1.ts === +import("./0"); +>import("./0") : Promise +>"./0" : "./0" + +var p1 = import("./0"); +>p1 : Promise +>import("./0") : Promise +>"./0" : "./0" + +p1.then(zero => { +>p1.then(zero => { return zero.foo();}) : Promise +>p1.then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>p1 : Promise +>then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>zero => { return zero.foo();} : (zero: typeof "tests/cases/conformance/dynamicImport/0") => string +>zero : typeof "tests/cases/conformance/dynamicImport/0" + + return zero.foo(); +>zero.foo() : string +>zero.foo : () => string +>zero : typeof "tests/cases/conformance/dynamicImport/0" +>foo : () => string + +}) + +function foo() { +>foo : () => void + + const p2 = import("./0"); +>p2 : Promise +>import("./0") : Promise +>"./0" : "./0" +} diff --git a/tests/baselines/reference/importCallExpression2ES2018.js b/tests/baselines/reference/importCallExpression2ESNext.js similarity index 79% rename from tests/baselines/reference/importCallExpression2ES2018.js rename to tests/baselines/reference/importCallExpression2ESNext.js index 293fa4e49d2..662f57f07ff 100644 --- a/tests/baselines/reference/importCallExpression2ES2018.js +++ b/tests/baselines/reference/importCallExpression2ESNext.js @@ -1,4 +1,4 @@ -//// [tests/cases/conformance/es2018/dynamicImport/importCallExpression2ES2018.ts] //// +//// [tests/cases/conformance/dynamicImport/importCallExpression2ESNext.ts] //// //// [0.ts] export class B { diff --git a/tests/baselines/reference/importCallExpression2ES2018.symbols b/tests/baselines/reference/importCallExpression2ESNext.symbols similarity index 85% rename from tests/baselines/reference/importCallExpression2ES2018.symbols rename to tests/baselines/reference/importCallExpression2ESNext.symbols index 4e8931cb729..2002398aeb9 100644 --- a/tests/baselines/reference/importCallExpression2ES2018.symbols +++ b/tests/baselines/reference/importCallExpression2ESNext.symbols @@ -1,4 +1,4 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export class B { >B : Symbol(B, Decl(0.ts, 0, 0)) @@ -6,7 +6,7 @@ export class B { >print : Symbol(B.print, Decl(0.ts, 0, 16)) } -=== tests/cases/conformance/es2018/dynamicImport/2.ts === +=== tests/cases/conformance/dynamicImport/2.ts === function foo(x: Promise) { >foo : Symbol(foo, Decl(2.ts, 0, 0)) >x : Symbol(x, Decl(2.ts, 0, 13)) diff --git a/tests/baselines/reference/importCallExpression2ES2018.types b/tests/baselines/reference/importCallExpression2ESNext.types similarity index 82% rename from tests/baselines/reference/importCallExpression2ES2018.types rename to tests/baselines/reference/importCallExpression2ESNext.types index 01e3c0d99bd..084eb33dde9 100644 --- a/tests/baselines/reference/importCallExpression2ES2018.types +++ b/tests/baselines/reference/importCallExpression2ESNext.types @@ -1,4 +1,4 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export class B { >B : B @@ -7,7 +7,7 @@ export class B { >"I am B" : "I am B" } -=== tests/cases/conformance/es2018/dynamicImport/2.ts === +=== tests/cases/conformance/dynamicImport/2.ts === function foo(x: Promise) { >foo : (x: Promise) => void >x : Promise @@ -40,6 +40,6 @@ function foo(x: Promise) { foo(import("./0")); >foo(import("./0")) : void >foo : (x: Promise) => void ->import("./0") : Promise +>import("./0") : Promise >"./0" : "./0" diff --git a/tests/baselines/reference/importCallExpression3ES2018.js b/tests/baselines/reference/importCallExpression3ESNext.js similarity index 78% rename from tests/baselines/reference/importCallExpression3ES2018.js rename to tests/baselines/reference/importCallExpression3ESNext.js index 247e78bb46c..0cd41388616 100644 --- a/tests/baselines/reference/importCallExpression3ES2018.js +++ b/tests/baselines/reference/importCallExpression3ESNext.js @@ -1,4 +1,4 @@ -//// [tests/cases/conformance/es2018/dynamicImport/importCallExpression3ES2018.ts] //// +//// [tests/cases/conformance/dynamicImport/importCallExpression3ESNext.ts] //// //// [0.ts] export class B { diff --git a/tests/baselines/reference/importCallExpression3ES2018.symbols b/tests/baselines/reference/importCallExpression3ESNext.symbols similarity index 81% rename from tests/baselines/reference/importCallExpression3ES2018.symbols rename to tests/baselines/reference/importCallExpression3ESNext.symbols index 06b328f5745..5ca85d6e693 100644 --- a/tests/baselines/reference/importCallExpression3ES2018.symbols +++ b/tests/baselines/reference/importCallExpression3ESNext.symbols @@ -1,4 +1,4 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export class B { >B : Symbol(B, Decl(0.ts, 0, 0)) @@ -6,7 +6,7 @@ export class B { >print : Symbol(B.print, Decl(0.ts, 0, 16)) } -=== tests/cases/conformance/es2018/dynamicImport/2.ts === +=== tests/cases/conformance/dynamicImport/2.ts === async function foo() { >foo : Symbol(foo, Decl(2.ts, 0, 0)) diff --git a/tests/baselines/reference/importCallExpression3ES2018.types b/tests/baselines/reference/importCallExpression3ESNext.types similarity index 54% rename from tests/baselines/reference/importCallExpression3ES2018.types rename to tests/baselines/reference/importCallExpression3ESNext.types index e88ddd04431..e517be6e722 100644 --- a/tests/baselines/reference/importCallExpression3ES2018.types +++ b/tests/baselines/reference/importCallExpression3ESNext.types @@ -1,4 +1,4 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export class B { >B : B @@ -7,16 +7,16 @@ export class B { >"I am B" : "I am B" } -=== tests/cases/conformance/es2018/dynamicImport/2.ts === +=== tests/cases/conformance/dynamicImport/2.ts === async function foo() { >foo : () => Promise class C extends (await import("./0")).B {} >C : C >(await import("./0")).B : B ->(await import("./0")) : typeof "tests/cases/conformance/es2018/dynamicImport/0" ->await import("./0") : typeof "tests/cases/conformance/es2018/dynamicImport/0" ->import("./0") : Promise +>(await import("./0")) : typeof "tests/cases/conformance/dynamicImport/0" +>await import("./0") : typeof "tests/cases/conformance/dynamicImport/0" +>import("./0") : Promise >"./0" : "./0" >B : typeof B diff --git a/tests/baselines/reference/importCallExpression4ES2018.js b/tests/baselines/reference/importCallExpression4ESNext.js similarity index 89% rename from tests/baselines/reference/importCallExpression4ES2018.js rename to tests/baselines/reference/importCallExpression4ESNext.js index a132bd8ac65..e148d5c1e51 100644 --- a/tests/baselines/reference/importCallExpression4ES2018.js +++ b/tests/baselines/reference/importCallExpression4ESNext.js @@ -1,4 +1,4 @@ -//// [tests/cases/conformance/es2018/dynamicImport/importCallExpression4ES2018.ts] //// +//// [tests/cases/conformance/dynamicImport/importCallExpression4ESNext.ts] //// //// [0.ts] export class B { diff --git a/tests/baselines/reference/importCallExpression4ES2018.symbols b/tests/baselines/reference/importCallExpression4ESNext.symbols similarity index 87% rename from tests/baselines/reference/importCallExpression4ES2018.symbols rename to tests/baselines/reference/importCallExpression4ESNext.symbols index 1d2a9aec25c..34a1dcf4d7b 100644 --- a/tests/baselines/reference/importCallExpression4ES2018.symbols +++ b/tests/baselines/reference/importCallExpression4ESNext.symbols @@ -1,4 +1,4 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export class B { >B : Symbol(B, Decl(0.ts, 0, 0)) @@ -9,11 +9,11 @@ export class B { export function foo() { return "foo" } >foo : Symbol(foo, Decl(0.ts, 2, 1)) -=== tests/cases/conformance/es2018/dynamicImport/1.ts === +=== tests/cases/conformance/dynamicImport/1.ts === export function backup() { return "backup"; } >backup : Symbol(backup, Decl(1.ts, 0, 0)) -=== tests/cases/conformance/es2018/dynamicImport/2.ts === +=== tests/cases/conformance/dynamicImport/2.ts === declare var console: any; >console : Symbol(console, Decl(2.ts, 0, 11)) diff --git a/tests/baselines/reference/importCallExpression4ES2018.types b/tests/baselines/reference/importCallExpression4ESNext.types similarity index 53% rename from tests/baselines/reference/importCallExpression4ES2018.types rename to tests/baselines/reference/importCallExpression4ESNext.types index 6da36879f64..2ea666ba672 100644 --- a/tests/baselines/reference/importCallExpression4ES2018.types +++ b/tests/baselines/reference/importCallExpression4ESNext.types @@ -1,4 +1,4 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export class B { >B : B @@ -11,12 +11,12 @@ export function foo() { return "foo" } >foo : () => string >"foo" : "foo" -=== tests/cases/conformance/es2018/dynamicImport/1.ts === +=== tests/cases/conformance/dynamicImport/1.ts === export function backup() { return "backup"; } >backup : () => string >"backup" : "backup" -=== tests/cases/conformance/es2018/dynamicImport/2.ts === +=== tests/cases/conformance/dynamicImport/2.ts === declare var console: any; >console : any @@ -24,8 +24,8 @@ class C { >C : C private myModule = import("./0"); ->myModule : Promise ->import("./0") : Promise +>myModule : Promise +>import("./0") : Promise >"./0" : "./0" method() { @@ -33,13 +33,13 @@ class C { this.myModule.then(Zero => { >this.myModule.then(Zero => { console.log(Zero.foo()); }, async err => { console.log(err); let one = await import("./1"); console.log(one.backup()); }) : Promise ->this.myModule.then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->this.myModule : Promise +>this.myModule.then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>this.myModule : Promise >this : this ->myModule : Promise ->then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->Zero => { console.log(Zero.foo()); } : (Zero: typeof "tests/cases/conformance/es2018/dynamicImport/0") => void ->Zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>myModule : Promise +>then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>Zero => { console.log(Zero.foo()); } : (Zero: typeof "tests/cases/conformance/dynamicImport/0") => void +>Zero : typeof "tests/cases/conformance/dynamicImport/0" console.log(Zero.foo()); >console.log(Zero.foo()) : any @@ -48,7 +48,7 @@ class C { >log : any >Zero.foo() : string >Zero.foo : () => string ->Zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>Zero : typeof "tests/cases/conformance/dynamicImport/0" >foo : () => string }, async err => { @@ -63,9 +63,9 @@ class C { >err : any let one = await import("./1"); ->one : typeof "tests/cases/conformance/es2018/dynamicImport/1" ->await import("./1") : typeof "tests/cases/conformance/es2018/dynamicImport/1" ->import("./1") : Promise +>one : typeof "tests/cases/conformance/dynamicImport/1" +>await import("./1") : typeof "tests/cases/conformance/dynamicImport/1" +>import("./1") : Promise >"./1" : "./1" console.log(one.backup()); @@ -75,7 +75,7 @@ class C { >log : any >one.backup() : string >one.backup : () => string ->one : typeof "tests/cases/conformance/es2018/dynamicImport/1" +>one : typeof "tests/cases/conformance/dynamicImport/1" >backup : () => string }); diff --git a/tests/baselines/reference/importCallExpression5ES2018.errors.txt b/tests/baselines/reference/importCallExpression5ESNext.errors.txt similarity index 52% rename from tests/baselines/reference/importCallExpression5ES2018.errors.txt rename to tests/baselines/reference/importCallExpression5ESNext.errors.txt index a7836124184..ed5900c2a03 100644 --- a/tests/baselines/reference/importCallExpression5ES2018.errors.txt +++ b/tests/baselines/reference/importCallExpression5ESNext.errors.txt @@ -1,20 +1,20 @@ -tests/cases/conformance/es2018/dynamicImport/2.ts(3,23): error TS7036: Dynamic import's specifier must be of type 'string', but here has type '"./0" | undefined'. -tests/cases/conformance/es2018/dynamicImport/2.ts(4,24): error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'undefined'. -tests/cases/conformance/es2018/dynamicImport/2.ts(5,24): error TS7036: Dynamic import's specifier must be of type 'string', but here has type '"./1" | null'. -tests/cases/conformance/es2018/dynamicImport/2.ts(6,24): error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'null'. +tests/cases/conformance/dynamicImport/2.ts(3,23): error TS7036: Dynamic import's specifier must be of type 'string', but here has type '"./0" | undefined'. +tests/cases/conformance/dynamicImport/2.ts(4,24): error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'undefined'. +tests/cases/conformance/dynamicImport/2.ts(5,24): error TS7036: Dynamic import's specifier must be of type 'string', but here has type '"./1" | null'. +tests/cases/conformance/dynamicImport/2.ts(6,24): error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'null'. -==== tests/cases/conformance/es2018/dynamicImport/0.ts (0 errors) ==== +==== tests/cases/conformance/dynamicImport/0.ts (0 errors) ==== export class B { print() { return "I am B"} } export function foo() { return "foo" } -==== tests/cases/conformance/es2018/dynamicImport/1.ts (0 errors) ==== +==== tests/cases/conformance/dynamicImport/1.ts (0 errors) ==== export function backup() { return "backup"; } -==== tests/cases/conformance/es2018/dynamicImport/2.ts (4 errors) ==== +==== tests/cases/conformance/dynamicImport/2.ts (4 errors) ==== declare function bar(): boolean; const specify = bar() ? "./0" : undefined; let myModule = import(specify); diff --git a/tests/baselines/reference/importCallExpression5ES2018.js b/tests/baselines/reference/importCallExpression5ESNext.js similarity index 87% rename from tests/baselines/reference/importCallExpression5ES2018.js rename to tests/baselines/reference/importCallExpression5ESNext.js index 802988cedbc..1f4c789120b 100644 --- a/tests/baselines/reference/importCallExpression5ES2018.js +++ b/tests/baselines/reference/importCallExpression5ESNext.js @@ -1,4 +1,4 @@ -//// [tests/cases/conformance/es2018/dynamicImport/importCallExpression5ES2018.ts] //// +//// [tests/cases/conformance/dynamicImport/importCallExpression5ESNext.ts] //// //// [0.ts] export class B { diff --git a/tests/baselines/reference/importCallExpression6ES2018.errors.txt b/tests/baselines/reference/importCallExpression6ESNext.errors.txt similarity index 55% rename from tests/baselines/reference/importCallExpression6ES2018.errors.txt rename to tests/baselines/reference/importCallExpression6ESNext.errors.txt index 2e349408569..1703e0913d1 100644 --- a/tests/baselines/reference/importCallExpression6ES2018.errors.txt +++ b/tests/baselines/reference/importCallExpression6ESNext.errors.txt @@ -1,18 +1,18 @@ -tests/cases/conformance/es2018/dynamicImport/2.ts(4,24): error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'undefined'. -tests/cases/conformance/es2018/dynamicImport/2.ts(6,24): error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'null'. +tests/cases/conformance/dynamicImport/2.ts(4,24): error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'undefined'. +tests/cases/conformance/dynamicImport/2.ts(6,24): error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'null'. -==== tests/cases/conformance/es2018/dynamicImport/0.ts (0 errors) ==== +==== tests/cases/conformance/dynamicImport/0.ts (0 errors) ==== export class B { print() { return "I am B"} } export function foo() { return "foo" } -==== tests/cases/conformance/es2018/dynamicImport/1.ts (0 errors) ==== +==== tests/cases/conformance/dynamicImport/1.ts (0 errors) ==== export function backup() { return "backup"; } -==== tests/cases/conformance/es2018/dynamicImport/2.ts (2 errors) ==== +==== tests/cases/conformance/dynamicImport/2.ts (2 errors) ==== declare function bar(): boolean; const specify = bar() ? "./0" : undefined; let myModule = import(specify); diff --git a/tests/baselines/reference/importCallExpression6ES2018.js b/tests/baselines/reference/importCallExpression6ESNext.js similarity index 87% rename from tests/baselines/reference/importCallExpression6ES2018.js rename to tests/baselines/reference/importCallExpression6ESNext.js index cde74278f33..bdac7328f69 100644 --- a/tests/baselines/reference/importCallExpression6ES2018.js +++ b/tests/baselines/reference/importCallExpression6ESNext.js @@ -1,4 +1,4 @@ -//// [tests/cases/conformance/es2018/dynamicImport/importCallExpression6ES2018.ts] //// +//// [tests/cases/conformance/dynamicImport/importCallExpression6ESNext.ts] //// //// [0.ts] export class B { From 7d64ec94a0ec9e656b70cadc9532d15093ab719d Mon Sep 17 00:00:00 2001 From: Yui T Date: Sun, 4 Jun 2017 21:18:42 -0700 Subject: [PATCH 66/67] Update baselines from moving out of es2018 --- src/harness/unittests/commandLineParsing.ts | 2 +- .../convertCompilerOptionsFromJson.ts | 2 +- ...tCallExpressionCheckReturntype1.errors.txt | 30 ++++++++--------- .../importCallExpressionCheckReturntype1.js | 2 +- ...portCallExpressionDeclarationEmit1.symbols | 2 +- ...importCallExpressionDeclarationEmit1.types | 2 +- ...tCallExpressionDeclarationEmit2.errors.txt | 8 ++--- .../importCallExpressionDeclarationEmit2.js | 2 +- .../importCallExpressionDeclarationEmit3.js | 2 +- ...portCallExpressionDeclarationEmit3.symbols | 4 +-- ...importCallExpressionDeclarationEmit3.types | 4 +-- .../reference/importCallExpressionES5AMD.js | 2 +- .../importCallExpressionES5AMD.symbols | 4 +-- .../importCallExpressionES5AMD.types | 26 +++++++-------- .../reference/importCallExpressionES5CJS.js | 2 +- .../importCallExpressionES5CJS.symbols | 4 +-- .../importCallExpressionES5CJS.types | 26 +++++++-------- .../importCallExpressionES5System.js | 2 +- .../importCallExpressionES5System.symbols | 4 +-- .../importCallExpressionES5System.types | 26 +++++++-------- .../reference/importCallExpressionES5UMD.js | 2 +- .../importCallExpressionES5UMD.symbols | 4 +-- .../importCallExpressionES5UMD.types | 26 +++++++-------- ...portCallExpressionErrorInES2015.errors.txt | 10 +++--- .../importCallExpressionErrorInES2015.js | 2 +- ...mportCallExpressionGrammarError.errors.txt | 16 +++++----- .../reference/importCallExpressionInAMD1.js | 2 +- .../importCallExpressionInAMD1.symbols | 4 +-- .../importCallExpressionInAMD1.types | 26 +++++++-------- .../reference/importCallExpressionInAMD2.js | 2 +- .../importCallExpressionInAMD2.symbols | 4 +-- .../importCallExpressionInAMD2.types | 6 ++-- .../reference/importCallExpressionInAMD3.js | 2 +- .../importCallExpressionInAMD3.symbols | 4 +-- .../importCallExpressionInAMD3.types | 10 +++--- .../reference/importCallExpressionInAMD4.js | 2 +- .../importCallExpressionInAMD4.symbols | 6 ++-- .../importCallExpressionInAMD4.types | 32 +++++++++---------- .../reference/importCallExpressionInCJS1.js | 2 +- .../importCallExpressionInCJS1.symbols | 4 +-- .../importCallExpressionInCJS1.types | 26 +++++++-------- .../reference/importCallExpressionInCJS2.js | 2 +- .../importCallExpressionInCJS2.symbols | 6 ++-- .../importCallExpressionInCJS2.types | 14 ++++---- .../reference/importCallExpressionInCJS3.js | 2 +- .../importCallExpressionInCJS3.symbols | 4 +-- .../importCallExpressionInCJS3.types | 6 ++-- .../reference/importCallExpressionInCJS4.js | 2 +- .../importCallExpressionInCJS4.symbols | 4 +-- .../importCallExpressionInCJS4.types | 10 +++--- .../reference/importCallExpressionInCJS5.js | 2 +- .../importCallExpressionInCJS5.symbols | 6 ++-- .../importCallExpressionInCJS5.types | 32 +++++++++---------- .../importCallExpressionInScriptContext1.js | 2 +- ...portCallExpressionInScriptContext1.symbols | 4 +-- ...importCallExpressionInScriptContext1.types | 8 ++--- ...tCallExpressionInScriptContext2.errors.txt | 6 ++-- .../importCallExpressionInScriptContext2.js | 2 +- .../importCallExpressionInSystem1.js | 2 +- .../importCallExpressionInSystem1.symbols | 4 +-- .../importCallExpressionInSystem1.types | 26 +++++++-------- .../importCallExpressionInSystem2.js | 2 +- .../importCallExpressionInSystem2.symbols | 4 +-- .../importCallExpressionInSystem2.types | 6 ++-- .../importCallExpressionInSystem3.js | 2 +- .../importCallExpressionInSystem3.symbols | 4 +-- .../importCallExpressionInSystem3.types | 10 +++--- .../importCallExpressionInSystem4.js | 2 +- .../importCallExpressionInSystem4.symbols | 6 ++-- .../importCallExpressionInSystem4.types | 32 +++++++++---------- .../reference/importCallExpressionInUMD1.js | 2 +- .../importCallExpressionInUMD1.symbols | 4 +-- .../importCallExpressionInUMD1.types | 26 +++++++-------- .../reference/importCallExpressionInUMD2.js | 2 +- .../importCallExpressionInUMD2.symbols | 4 +-- .../importCallExpressionInUMD2.types | 6 ++-- .../reference/importCallExpressionInUMD3.js | 2 +- .../importCallExpressionInUMD3.symbols | 4 +-- .../importCallExpressionInUMD3.types | 10 +++--- .../reference/importCallExpressionInUMD4.js | 2 +- .../importCallExpressionInUMD4.symbols | 6 ++-- .../importCallExpressionInUMD4.types | 32 +++++++++---------- .../importCallExpressionReturnPromiseOfAny.js | 2 +- ...rtCallExpressionReturnPromiseOfAny.symbols | 4 +-- ...portCallExpressionReturnPromiseOfAny.types | 4 +-- ...sionSpecifierNotStringTypeError.errors.txt | 12 +++---- ...tCallExpressionWithTypeArgument.errors.txt | 8 ++--- .../importCallExpressionWithTypeArgument.js | 2 +- ...ons module-kind is out-of-range.errors.txt | 4 +-- ...s target-script is out-of-range.errors.txt | 4 +-- 90 files changed, 350 insertions(+), 350 deletions(-) diff --git a/src/harness/unittests/commandLineParsing.ts b/src/harness/unittests/commandLineParsing.ts index fc600bb55b4..01a208aa330 100644 --- a/src/harness/unittests/commandLineParsing.ts +++ b/src/harness/unittests/commandLineParsing.ts @@ -113,7 +113,7 @@ namespace ts { start: undefined, length: undefined, }, { - messageText: "Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'es2018'.", + messageText: "Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'esnext'.", category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category, code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code, diff --git a/src/harness/unittests/convertCompilerOptionsFromJson.ts b/src/harness/unittests/convertCompilerOptionsFromJson.ts index 2fe4ba83aff..798f8c6a76b 100644 --- a/src/harness/unittests/convertCompilerOptionsFromJson.ts +++ b/src/harness/unittests/convertCompilerOptionsFromJson.ts @@ -122,7 +122,7 @@ namespace ts { file: undefined, start: 0, length: 0, - messageText: "Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'es2018'.", + messageText: "Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'esnext'.", code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code, category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category }] diff --git a/tests/baselines/reference/importCallExpressionCheckReturntype1.errors.txt b/tests/baselines/reference/importCallExpressionCheckReturntype1.errors.txt index adb904ce7fa..39622f39b3f 100644 --- a/tests/baselines/reference/importCallExpressionCheckReturntype1.errors.txt +++ b/tests/baselines/reference/importCallExpressionCheckReturntype1.errors.txt @@ -1,30 +1,30 @@ -tests/cases/conformance/es2018/dynamicImport/1.ts(4,5): error TS2322: Type 'Promise' is not assignable to type 'Promise'. - Type 'typeof "tests/cases/conformance/es2018/dynamicImport/defaultPath"' is not assignable to type 'typeof "tests/cases/conformance/es2018/dynamicImport/anotherModule"'. - Property 'D' is missing in type 'typeof "tests/cases/conformance/es2018/dynamicImport/defaultPath"'. -tests/cases/conformance/es2018/dynamicImport/1.ts(5,10): error TS2352: Type 'Promise' cannot be converted to type 'Promise'. - Type 'typeof "tests/cases/conformance/es2018/dynamicImport/defaultPath"' is not comparable to type 'typeof "tests/cases/conformance/es2018/dynamicImport/anotherModule"'. - Property 'D' is missing in type 'typeof "tests/cases/conformance/es2018/dynamicImport/defaultPath"'. +tests/cases/conformance/dynamicImport/1.ts(4,5): error TS2322: Type 'Promise' is not assignable to type 'Promise'. + Type 'typeof "tests/cases/conformance/dynamicImport/defaultPath"' is not assignable to type 'typeof "tests/cases/conformance/dynamicImport/anotherModule"'. + Property 'D' is missing in type 'typeof "tests/cases/conformance/dynamicImport/defaultPath"'. +tests/cases/conformance/dynamicImport/1.ts(5,10): error TS2352: Type 'Promise' cannot be converted to type 'Promise'. + Type 'typeof "tests/cases/conformance/dynamicImport/defaultPath"' is not comparable to type 'typeof "tests/cases/conformance/dynamicImport/anotherModule"'. + Property 'D' is missing in type 'typeof "tests/cases/conformance/dynamicImport/defaultPath"'. -==== tests/cases/conformance/es2018/dynamicImport/anotherModule.ts (0 errors) ==== +==== tests/cases/conformance/dynamicImport/anotherModule.ts (0 errors) ==== export class D{} -==== tests/cases/conformance/es2018/dynamicImport/defaultPath.ts (0 errors) ==== +==== tests/cases/conformance/dynamicImport/defaultPath.ts (0 errors) ==== export class C {} -==== tests/cases/conformance/es2018/dynamicImport/1.ts (2 errors) ==== +==== tests/cases/conformance/dynamicImport/1.ts (2 errors) ==== import * as defaultModule from "./defaultPath"; import * as anotherModule from "./anotherModule"; let p1: Promise = import("./defaultPath"); ~~ -!!! error TS2322: Type 'Promise' is not assignable to type 'Promise'. -!!! error TS2322: Type 'typeof "tests/cases/conformance/es2018/dynamicImport/defaultPath"' is not assignable to type 'typeof "tests/cases/conformance/es2018/dynamicImport/anotherModule"'. -!!! error TS2322: Property 'D' is missing in type 'typeof "tests/cases/conformance/es2018/dynamicImport/defaultPath"'. +!!! error TS2322: Type 'Promise' is not assignable to type 'Promise'. +!!! error TS2322: Type 'typeof "tests/cases/conformance/dynamicImport/defaultPath"' is not assignable to type 'typeof "tests/cases/conformance/dynamicImport/anotherModule"'. +!!! error TS2322: Property 'D' is missing in type 'typeof "tests/cases/conformance/dynamicImport/defaultPath"'. let p2 = import("./defaultPath") as Promise; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2352: Type 'Promise' cannot be converted to type 'Promise'. -!!! error TS2352: Type 'typeof "tests/cases/conformance/es2018/dynamicImport/defaultPath"' is not comparable to type 'typeof "tests/cases/conformance/es2018/dynamicImport/anotherModule"'. -!!! error TS2352: Property 'D' is missing in type 'typeof "tests/cases/conformance/es2018/dynamicImport/defaultPath"'. +!!! error TS2352: Type 'Promise' cannot be converted to type 'Promise'. +!!! error TS2352: Type 'typeof "tests/cases/conformance/dynamicImport/defaultPath"' is not comparable to type 'typeof "tests/cases/conformance/dynamicImport/anotherModule"'. +!!! error TS2352: Property 'D' is missing in type 'typeof "tests/cases/conformance/dynamicImport/defaultPath"'. let p3: Promise = import("./defaultPath"); \ No newline at end of file diff --git a/tests/baselines/reference/importCallExpressionCheckReturntype1.js b/tests/baselines/reference/importCallExpressionCheckReturntype1.js index f317a799f13..facb6913388 100644 --- a/tests/baselines/reference/importCallExpressionCheckReturntype1.js +++ b/tests/baselines/reference/importCallExpressionCheckReturntype1.js @@ -1,4 +1,4 @@ -//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionCheckReturntype1.ts] //// +//// [tests/cases/conformance/dynamicImport/importCallExpressionCheckReturntype1.ts] //// //// [anotherModule.ts] export class D{} diff --git a/tests/baselines/reference/importCallExpressionDeclarationEmit1.symbols b/tests/baselines/reference/importCallExpressionDeclarationEmit1.symbols index 997911b9481..d2266cc768b 100644 --- a/tests/baselines/reference/importCallExpressionDeclarationEmit1.symbols +++ b/tests/baselines/reference/importCallExpressionDeclarationEmit1.symbols @@ -1,4 +1,4 @@ -=== tests/cases/conformance/es2018/dynamicImport/importCallExpressionDeclarationEmit1.ts === +=== tests/cases/conformance/dynamicImport/importCallExpressionDeclarationEmit1.ts === declare function getSpecifier(): string; >getSpecifier : Symbol(getSpecifier, Decl(importCallExpressionDeclarationEmit1.ts, 0, 0)) diff --git a/tests/baselines/reference/importCallExpressionDeclarationEmit1.types b/tests/baselines/reference/importCallExpressionDeclarationEmit1.types index c45d3b3775e..db5400818c8 100644 --- a/tests/baselines/reference/importCallExpressionDeclarationEmit1.types +++ b/tests/baselines/reference/importCallExpressionDeclarationEmit1.types @@ -1,4 +1,4 @@ -=== tests/cases/conformance/es2018/dynamicImport/importCallExpressionDeclarationEmit1.ts === +=== tests/cases/conformance/dynamicImport/importCallExpressionDeclarationEmit1.ts === declare function getSpecifier(): string; >getSpecifier : () => string diff --git a/tests/baselines/reference/importCallExpressionDeclarationEmit2.errors.txt b/tests/baselines/reference/importCallExpressionDeclarationEmit2.errors.txt index f397ee1e95f..6c394c98bdf 100644 --- a/tests/baselines/reference/importCallExpressionDeclarationEmit2.errors.txt +++ b/tests/baselines/reference/importCallExpressionDeclarationEmit2.errors.txt @@ -1,10 +1,10 @@ -tests/cases/conformance/es2018/dynamicImport/1.ts(1,5): error TS4023: Exported variable 'p1' has or is using name '"tests/cases/conformance/es2018/dynamicImport/0"' from external module "tests/cases/conformance/es2018/dynamicImport/0" but cannot be named. +tests/cases/conformance/dynamicImport/1.ts(1,5): error TS4023: Exported variable 'p1' has or is using name '"tests/cases/conformance/dynamicImport/0"' from external module "tests/cases/conformance/dynamicImport/0" but cannot be named. -==== tests/cases/conformance/es2018/dynamicImport/0.ts (0 errors) ==== +==== tests/cases/conformance/dynamicImport/0.ts (0 errors) ==== export function foo() { return "foo"; } -==== tests/cases/conformance/es2018/dynamicImport/1.ts (1 errors) ==== +==== tests/cases/conformance/dynamicImport/1.ts (1 errors) ==== var p1 = import("./0"); ~~ -!!! error TS4023: Exported variable 'p1' has or is using name '"tests/cases/conformance/es2018/dynamicImport/0"' from external module "tests/cases/conformance/es2018/dynamicImport/0" but cannot be named. \ No newline at end of file +!!! error TS4023: Exported variable 'p1' has or is using name '"tests/cases/conformance/dynamicImport/0"' from external module "tests/cases/conformance/dynamicImport/0" but cannot be named. \ No newline at end of file diff --git a/tests/baselines/reference/importCallExpressionDeclarationEmit2.js b/tests/baselines/reference/importCallExpressionDeclarationEmit2.js index 49dee5c9f99..7659e94ee81 100644 --- a/tests/baselines/reference/importCallExpressionDeclarationEmit2.js +++ b/tests/baselines/reference/importCallExpressionDeclarationEmit2.js @@ -1,4 +1,4 @@ -//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionDeclarationEmit2.ts] //// +//// [tests/cases/conformance/dynamicImport/importCallExpressionDeclarationEmit2.ts] //// //// [0.ts] export function foo() { return "foo"; } diff --git a/tests/baselines/reference/importCallExpressionDeclarationEmit3.js b/tests/baselines/reference/importCallExpressionDeclarationEmit3.js index 32775b00500..d38c2309a33 100644 --- a/tests/baselines/reference/importCallExpressionDeclarationEmit3.js +++ b/tests/baselines/reference/importCallExpressionDeclarationEmit3.js @@ -1,4 +1,4 @@ -//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionDeclarationEmit3.ts] //// +//// [tests/cases/conformance/dynamicImport/importCallExpressionDeclarationEmit3.ts] //// //// [0.ts] export function foo() { return "foo"; } diff --git a/tests/baselines/reference/importCallExpressionDeclarationEmit3.symbols b/tests/baselines/reference/importCallExpressionDeclarationEmit3.symbols index 1e9e3ca9184..1491e05db55 100644 --- a/tests/baselines/reference/importCallExpressionDeclarationEmit3.symbols +++ b/tests/baselines/reference/importCallExpressionDeclarationEmit3.symbols @@ -1,8 +1,8 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export function foo() { return "foo"; } >foo : Symbol(foo, Decl(0.ts, 0, 0)) -=== tests/cases/conformance/es2018/dynamicImport/1.ts === +=== tests/cases/conformance/dynamicImport/1.ts === declare function getPath(): string; >getPath : Symbol(getPath, Decl(1.ts, 0, 0)) diff --git a/tests/baselines/reference/importCallExpressionDeclarationEmit3.types b/tests/baselines/reference/importCallExpressionDeclarationEmit3.types index a3e2b58157f..fe4552b708f 100644 --- a/tests/baselines/reference/importCallExpressionDeclarationEmit3.types +++ b/tests/baselines/reference/importCallExpressionDeclarationEmit3.types @@ -1,9 +1,9 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export function foo() { return "foo"; } >foo : () => string >"foo" : "foo" -=== tests/cases/conformance/es2018/dynamicImport/1.ts === +=== tests/cases/conformance/dynamicImport/1.ts === declare function getPath(): string; >getPath : () => string diff --git a/tests/baselines/reference/importCallExpressionES5AMD.js b/tests/baselines/reference/importCallExpressionES5AMD.js index fd402c163e9..cce61a5a3f9 100644 --- a/tests/baselines/reference/importCallExpressionES5AMD.js +++ b/tests/baselines/reference/importCallExpressionES5AMD.js @@ -1,4 +1,4 @@ -//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionES5AMD.ts] //// +//// [tests/cases/conformance/dynamicImport/importCallExpressionES5AMD.ts] //// //// [0.ts] export function foo() { return "foo"; } diff --git a/tests/baselines/reference/importCallExpressionES5AMD.symbols b/tests/baselines/reference/importCallExpressionES5AMD.symbols index 15356c694ed..333251da662 100644 --- a/tests/baselines/reference/importCallExpressionES5AMD.symbols +++ b/tests/baselines/reference/importCallExpressionES5AMD.symbols @@ -1,8 +1,8 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export function foo() { return "foo"; } >foo : Symbol(foo, Decl(0.ts, 0, 0)) -=== tests/cases/conformance/es2018/dynamicImport/1.ts === +=== tests/cases/conformance/dynamicImport/1.ts === import("./0"); var p1 = import("./0"); >p1 : Symbol(p1, Decl(1.ts, 1, 3)) diff --git a/tests/baselines/reference/importCallExpressionES5AMD.types b/tests/baselines/reference/importCallExpressionES5AMD.types index 2733f3ff14a..59da055ee01 100644 --- a/tests/baselines/reference/importCallExpressionES5AMD.types +++ b/tests/baselines/reference/importCallExpressionES5AMD.types @@ -1,30 +1,30 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export function foo() { return "foo"; } >foo : () => string >"foo" : "foo" -=== tests/cases/conformance/es2018/dynamicImport/1.ts === +=== tests/cases/conformance/dynamicImport/1.ts === import("./0"); ->import("./0") : Promise +>import("./0") : Promise >"./0" : "./0" var p1 = import("./0"); ->p1 : Promise ->import("./0") : Promise +>p1 : Promise +>import("./0") : Promise >"./0" : "./0" p1.then(zero => { >p1.then(zero => { return zero.foo();}) : Promise ->p1.then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->p1 : Promise ->then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->zero => { return zero.foo();} : (zero: typeof "tests/cases/conformance/es2018/dynamicImport/0") => string ->zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>p1.then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>p1 : Promise +>then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>zero => { return zero.foo();} : (zero: typeof "tests/cases/conformance/dynamicImport/0") => string +>zero : typeof "tests/cases/conformance/dynamicImport/0" return zero.foo(); >zero.foo() : string >zero.foo : () => string ->zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>zero : typeof "tests/cases/conformance/dynamicImport/0" >foo : () => string }); @@ -33,7 +33,7 @@ function foo() { >foo : () => void const p2 = import("./0"); ->p2 : Promise ->import("./0") : Promise +>p2 : Promise +>import("./0") : Promise >"./0" : "./0" } diff --git a/tests/baselines/reference/importCallExpressionES5CJS.js b/tests/baselines/reference/importCallExpressionES5CJS.js index c5c4f5933a8..11d1bf46319 100644 --- a/tests/baselines/reference/importCallExpressionES5CJS.js +++ b/tests/baselines/reference/importCallExpressionES5CJS.js @@ -1,4 +1,4 @@ -//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionES5CJS.ts] //// +//// [tests/cases/conformance/dynamicImport/importCallExpressionES5CJS.ts] //// //// [0.ts] export function foo() { return "foo"; } diff --git a/tests/baselines/reference/importCallExpressionES5CJS.symbols b/tests/baselines/reference/importCallExpressionES5CJS.symbols index 15356c694ed..333251da662 100644 --- a/tests/baselines/reference/importCallExpressionES5CJS.symbols +++ b/tests/baselines/reference/importCallExpressionES5CJS.symbols @@ -1,8 +1,8 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export function foo() { return "foo"; } >foo : Symbol(foo, Decl(0.ts, 0, 0)) -=== tests/cases/conformance/es2018/dynamicImport/1.ts === +=== tests/cases/conformance/dynamicImport/1.ts === import("./0"); var p1 = import("./0"); >p1 : Symbol(p1, Decl(1.ts, 1, 3)) diff --git a/tests/baselines/reference/importCallExpressionES5CJS.types b/tests/baselines/reference/importCallExpressionES5CJS.types index 2733f3ff14a..59da055ee01 100644 --- a/tests/baselines/reference/importCallExpressionES5CJS.types +++ b/tests/baselines/reference/importCallExpressionES5CJS.types @@ -1,30 +1,30 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export function foo() { return "foo"; } >foo : () => string >"foo" : "foo" -=== tests/cases/conformance/es2018/dynamicImport/1.ts === +=== tests/cases/conformance/dynamicImport/1.ts === import("./0"); ->import("./0") : Promise +>import("./0") : Promise >"./0" : "./0" var p1 = import("./0"); ->p1 : Promise ->import("./0") : Promise +>p1 : Promise +>import("./0") : Promise >"./0" : "./0" p1.then(zero => { >p1.then(zero => { return zero.foo();}) : Promise ->p1.then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->p1 : Promise ->then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->zero => { return zero.foo();} : (zero: typeof "tests/cases/conformance/es2018/dynamicImport/0") => string ->zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>p1.then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>p1 : Promise +>then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>zero => { return zero.foo();} : (zero: typeof "tests/cases/conformance/dynamicImport/0") => string +>zero : typeof "tests/cases/conformance/dynamicImport/0" return zero.foo(); >zero.foo() : string >zero.foo : () => string ->zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>zero : typeof "tests/cases/conformance/dynamicImport/0" >foo : () => string }); @@ -33,7 +33,7 @@ function foo() { >foo : () => void const p2 = import("./0"); ->p2 : Promise ->import("./0") : Promise +>p2 : Promise +>import("./0") : Promise >"./0" : "./0" } diff --git a/tests/baselines/reference/importCallExpressionES5System.js b/tests/baselines/reference/importCallExpressionES5System.js index e0b017370a0..1842fc6e60a 100644 --- a/tests/baselines/reference/importCallExpressionES5System.js +++ b/tests/baselines/reference/importCallExpressionES5System.js @@ -1,4 +1,4 @@ -//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionES5System.ts] //// +//// [tests/cases/conformance/dynamicImport/importCallExpressionES5System.ts] //// //// [0.ts] export function foo() { return "foo"; } diff --git a/tests/baselines/reference/importCallExpressionES5System.symbols b/tests/baselines/reference/importCallExpressionES5System.symbols index 15356c694ed..333251da662 100644 --- a/tests/baselines/reference/importCallExpressionES5System.symbols +++ b/tests/baselines/reference/importCallExpressionES5System.symbols @@ -1,8 +1,8 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export function foo() { return "foo"; } >foo : Symbol(foo, Decl(0.ts, 0, 0)) -=== tests/cases/conformance/es2018/dynamicImport/1.ts === +=== tests/cases/conformance/dynamicImport/1.ts === import("./0"); var p1 = import("./0"); >p1 : Symbol(p1, Decl(1.ts, 1, 3)) diff --git a/tests/baselines/reference/importCallExpressionES5System.types b/tests/baselines/reference/importCallExpressionES5System.types index 2733f3ff14a..59da055ee01 100644 --- a/tests/baselines/reference/importCallExpressionES5System.types +++ b/tests/baselines/reference/importCallExpressionES5System.types @@ -1,30 +1,30 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export function foo() { return "foo"; } >foo : () => string >"foo" : "foo" -=== tests/cases/conformance/es2018/dynamicImport/1.ts === +=== tests/cases/conformance/dynamicImport/1.ts === import("./0"); ->import("./0") : Promise +>import("./0") : Promise >"./0" : "./0" var p1 = import("./0"); ->p1 : Promise ->import("./0") : Promise +>p1 : Promise +>import("./0") : Promise >"./0" : "./0" p1.then(zero => { >p1.then(zero => { return zero.foo();}) : Promise ->p1.then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->p1 : Promise ->then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->zero => { return zero.foo();} : (zero: typeof "tests/cases/conformance/es2018/dynamicImport/0") => string ->zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>p1.then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>p1 : Promise +>then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>zero => { return zero.foo();} : (zero: typeof "tests/cases/conformance/dynamicImport/0") => string +>zero : typeof "tests/cases/conformance/dynamicImport/0" return zero.foo(); >zero.foo() : string >zero.foo : () => string ->zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>zero : typeof "tests/cases/conformance/dynamicImport/0" >foo : () => string }); @@ -33,7 +33,7 @@ function foo() { >foo : () => void const p2 = import("./0"); ->p2 : Promise ->import("./0") : Promise +>p2 : Promise +>import("./0") : Promise >"./0" : "./0" } diff --git a/tests/baselines/reference/importCallExpressionES5UMD.js b/tests/baselines/reference/importCallExpressionES5UMD.js index 2952a43cd24..dfe6813839c 100644 --- a/tests/baselines/reference/importCallExpressionES5UMD.js +++ b/tests/baselines/reference/importCallExpressionES5UMD.js @@ -1,4 +1,4 @@ -//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionES5UMD.ts] //// +//// [tests/cases/conformance/dynamicImport/importCallExpressionES5UMD.ts] //// //// [0.ts] export function foo() { return "foo"; } diff --git a/tests/baselines/reference/importCallExpressionES5UMD.symbols b/tests/baselines/reference/importCallExpressionES5UMD.symbols index 15356c694ed..333251da662 100644 --- a/tests/baselines/reference/importCallExpressionES5UMD.symbols +++ b/tests/baselines/reference/importCallExpressionES5UMD.symbols @@ -1,8 +1,8 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export function foo() { return "foo"; } >foo : Symbol(foo, Decl(0.ts, 0, 0)) -=== tests/cases/conformance/es2018/dynamicImport/1.ts === +=== tests/cases/conformance/dynamicImport/1.ts === import("./0"); var p1 = import("./0"); >p1 : Symbol(p1, Decl(1.ts, 1, 3)) diff --git a/tests/baselines/reference/importCallExpressionES5UMD.types b/tests/baselines/reference/importCallExpressionES5UMD.types index 2733f3ff14a..59da055ee01 100644 --- a/tests/baselines/reference/importCallExpressionES5UMD.types +++ b/tests/baselines/reference/importCallExpressionES5UMD.types @@ -1,30 +1,30 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export function foo() { return "foo"; } >foo : () => string >"foo" : "foo" -=== tests/cases/conformance/es2018/dynamicImport/1.ts === +=== tests/cases/conformance/dynamicImport/1.ts === import("./0"); ->import("./0") : Promise +>import("./0") : Promise >"./0" : "./0" var p1 = import("./0"); ->p1 : Promise ->import("./0") : Promise +>p1 : Promise +>import("./0") : Promise >"./0" : "./0" p1.then(zero => { >p1.then(zero => { return zero.foo();}) : Promise ->p1.then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->p1 : Promise ->then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->zero => { return zero.foo();} : (zero: typeof "tests/cases/conformance/es2018/dynamicImport/0") => string ->zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>p1.then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>p1 : Promise +>then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>zero => { return zero.foo();} : (zero: typeof "tests/cases/conformance/dynamicImport/0") => string +>zero : typeof "tests/cases/conformance/dynamicImport/0" return zero.foo(); >zero.foo() : string >zero.foo : () => string ->zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>zero : typeof "tests/cases/conformance/dynamicImport/0" >foo : () => string }); @@ -33,7 +33,7 @@ function foo() { >foo : () => void const p2 = import("./0"); ->p2 : Promise ->import("./0") : Promise +>p2 : Promise +>import("./0") : Promise >"./0" : "./0" } diff --git a/tests/baselines/reference/importCallExpressionErrorInES2015.errors.txt b/tests/baselines/reference/importCallExpressionErrorInES2015.errors.txt index 0c31a0f434c..d47980d1312 100644 --- a/tests/baselines/reference/importCallExpressionErrorInES2015.errors.txt +++ b/tests/baselines/reference/importCallExpressionErrorInES2015.errors.txt @@ -1,12 +1,12 @@ -tests/cases/conformance/es2018/dynamicImport/1.ts(1,1): error TS1323: Dynamic import cannot be used when targeting ECMAScript 2015 modules. -tests/cases/conformance/es2018/dynamicImport/1.ts(2,10): error TS1323: Dynamic import cannot be used when targeting ECMAScript 2015 modules. -tests/cases/conformance/es2018/dynamicImport/1.ts(8,16): error TS1323: Dynamic import cannot be used when targeting ECMAScript 2015 modules. +tests/cases/conformance/dynamicImport/1.ts(1,1): error TS1323: Dynamic import cannot be used when targeting ECMAScript 2015 modules. +tests/cases/conformance/dynamicImport/1.ts(2,10): error TS1323: Dynamic import cannot be used when targeting ECMAScript 2015 modules. +tests/cases/conformance/dynamicImport/1.ts(8,16): error TS1323: Dynamic import cannot be used when targeting ECMAScript 2015 modules. -==== tests/cases/conformance/es2018/dynamicImport/0.ts (0 errors) ==== +==== tests/cases/conformance/dynamicImport/0.ts (0 errors) ==== export function foo() { return "foo"; } -==== tests/cases/conformance/es2018/dynamicImport/1.ts (3 errors) ==== +==== tests/cases/conformance/dynamicImport/1.ts (3 errors) ==== import("./0"); ~~~~~~~~~~~~~ !!! error TS1323: Dynamic import cannot be used when targeting ECMAScript 2015 modules. diff --git a/tests/baselines/reference/importCallExpressionErrorInES2015.js b/tests/baselines/reference/importCallExpressionErrorInES2015.js index afe29bbe9ca..f07486504ee 100644 --- a/tests/baselines/reference/importCallExpressionErrorInES2015.js +++ b/tests/baselines/reference/importCallExpressionErrorInES2015.js @@ -1,4 +1,4 @@ -//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionErrorInES2015.ts] //// +//// [tests/cases/conformance/dynamicImport/importCallExpressionErrorInES2015.ts] //// //// [0.ts] export function foo() { return "foo"; } diff --git a/tests/baselines/reference/importCallExpressionGrammarError.errors.txt b/tests/baselines/reference/importCallExpressionGrammarError.errors.txt index c0684edaabe..6d64808e111 100644 --- a/tests/baselines/reference/importCallExpressionGrammarError.errors.txt +++ b/tests/baselines/reference/importCallExpressionGrammarError.errors.txt @@ -1,13 +1,13 @@ -tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts(5,8): error TS1325: Specifier of dynamic import cannot be spread element. -tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts(7,17): error TS1325: Specifier of dynamic import cannot be spread element. -tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts(8,12): error TS1324: Dynamic import must have one specifier as an argument. -tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts(9,19): error TS1135: Argument expression expected. -tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts(9,19): error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'undefined'. -tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts(10,12): error TS1324: Dynamic import must have one specifier as an argument. -tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts(10,19): error TS2307: Cannot find module 'pathToModule'. +tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(5,8): error TS1325: Specifier of dynamic import cannot be spread element. +tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(7,17): error TS1325: Specifier of dynamic import cannot be spread element. +tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(8,12): error TS1324: Dynamic import must have one specifier as an argument. +tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(9,19): error TS1135: Argument expression expected. +tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(9,19): error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'undefined'. +tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(10,12): error TS1324: Dynamic import must have one specifier as an argument. +tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(10,19): error TS2307: Cannot find module 'pathToModule'. -==== tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts (7 errors) ==== +==== tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts (7 errors) ==== declare function getSpecifier(): string; declare var whatToLoad: boolean; diff --git a/tests/baselines/reference/importCallExpressionInAMD1.js b/tests/baselines/reference/importCallExpressionInAMD1.js index b55066a1b6a..e1758173646 100644 --- a/tests/baselines/reference/importCallExpressionInAMD1.js +++ b/tests/baselines/reference/importCallExpressionInAMD1.js @@ -1,4 +1,4 @@ -//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInAMD1.ts] //// +//// [tests/cases/conformance/dynamicImport/importCallExpressionInAMD1.ts] //// //// [0.ts] export function foo() { return "foo"; } diff --git a/tests/baselines/reference/importCallExpressionInAMD1.symbols b/tests/baselines/reference/importCallExpressionInAMD1.symbols index 15356c694ed..333251da662 100644 --- a/tests/baselines/reference/importCallExpressionInAMD1.symbols +++ b/tests/baselines/reference/importCallExpressionInAMD1.symbols @@ -1,8 +1,8 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export function foo() { return "foo"; } >foo : Symbol(foo, Decl(0.ts, 0, 0)) -=== tests/cases/conformance/es2018/dynamicImport/1.ts === +=== tests/cases/conformance/dynamicImport/1.ts === import("./0"); var p1 = import("./0"); >p1 : Symbol(p1, Decl(1.ts, 1, 3)) diff --git a/tests/baselines/reference/importCallExpressionInAMD1.types b/tests/baselines/reference/importCallExpressionInAMD1.types index 2733f3ff14a..59da055ee01 100644 --- a/tests/baselines/reference/importCallExpressionInAMD1.types +++ b/tests/baselines/reference/importCallExpressionInAMD1.types @@ -1,30 +1,30 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export function foo() { return "foo"; } >foo : () => string >"foo" : "foo" -=== tests/cases/conformance/es2018/dynamicImport/1.ts === +=== tests/cases/conformance/dynamicImport/1.ts === import("./0"); ->import("./0") : Promise +>import("./0") : Promise >"./0" : "./0" var p1 = import("./0"); ->p1 : Promise ->import("./0") : Promise +>p1 : Promise +>import("./0") : Promise >"./0" : "./0" p1.then(zero => { >p1.then(zero => { return zero.foo();}) : Promise ->p1.then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->p1 : Promise ->then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->zero => { return zero.foo();} : (zero: typeof "tests/cases/conformance/es2018/dynamicImport/0") => string ->zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>p1.then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>p1 : Promise +>then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>zero => { return zero.foo();} : (zero: typeof "tests/cases/conformance/dynamicImport/0") => string +>zero : typeof "tests/cases/conformance/dynamicImport/0" return zero.foo(); >zero.foo() : string >zero.foo : () => string ->zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>zero : typeof "tests/cases/conformance/dynamicImport/0" >foo : () => string }); @@ -33,7 +33,7 @@ function foo() { >foo : () => void const p2 = import("./0"); ->p2 : Promise ->import("./0") : Promise +>p2 : Promise +>import("./0") : Promise >"./0" : "./0" } diff --git a/tests/baselines/reference/importCallExpressionInAMD2.js b/tests/baselines/reference/importCallExpressionInAMD2.js index bac579d0507..7347e2f8105 100644 --- a/tests/baselines/reference/importCallExpressionInAMD2.js +++ b/tests/baselines/reference/importCallExpressionInAMD2.js @@ -1,4 +1,4 @@ -//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInAMD2.ts] //// +//// [tests/cases/conformance/dynamicImport/importCallExpressionInAMD2.ts] //// //// [0.ts] export class B { diff --git a/tests/baselines/reference/importCallExpressionInAMD2.symbols b/tests/baselines/reference/importCallExpressionInAMD2.symbols index 7db47944520..16fc79c774f 100644 --- a/tests/baselines/reference/importCallExpressionInAMD2.symbols +++ b/tests/baselines/reference/importCallExpressionInAMD2.symbols @@ -1,4 +1,4 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export class B { >B : Symbol(B, Decl(0.ts, 0, 0)) @@ -6,7 +6,7 @@ export class B { >print : Symbol(B.print, Decl(0.ts, 0, 16)) } -=== tests/cases/conformance/es2018/dynamicImport/2.ts === +=== tests/cases/conformance/dynamicImport/2.ts === // We use Promise for now as there is no way to specify shape of module object function foo(x: Promise) { >foo : Symbol(foo, Decl(2.ts, 0, 0)) diff --git a/tests/baselines/reference/importCallExpressionInAMD2.types b/tests/baselines/reference/importCallExpressionInAMD2.types index 2db06142911..44b17eb51fd 100644 --- a/tests/baselines/reference/importCallExpressionInAMD2.types +++ b/tests/baselines/reference/importCallExpressionInAMD2.types @@ -1,4 +1,4 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export class B { >B : B @@ -7,7 +7,7 @@ export class B { >"I am B" : "I am B" } -=== tests/cases/conformance/es2018/dynamicImport/2.ts === +=== tests/cases/conformance/dynamicImport/2.ts === // We use Promise for now as there is no way to specify shape of module object function foo(x: Promise) { >foo : (x: Promise) => void @@ -41,6 +41,6 @@ function foo(x: Promise) { foo(import("./0")); >foo(import("./0")) : void >foo : (x: Promise) => void ->import("./0") : Promise +>import("./0") : Promise >"./0" : "./0" diff --git a/tests/baselines/reference/importCallExpressionInAMD3.js b/tests/baselines/reference/importCallExpressionInAMD3.js index 6245f437398..471f35a6415 100644 --- a/tests/baselines/reference/importCallExpressionInAMD3.js +++ b/tests/baselines/reference/importCallExpressionInAMD3.js @@ -1,4 +1,4 @@ -//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInAMD3.ts] //// +//// [tests/cases/conformance/dynamicImport/importCallExpressionInAMD3.ts] //// //// [0.ts] export class B { diff --git a/tests/baselines/reference/importCallExpressionInAMD3.symbols b/tests/baselines/reference/importCallExpressionInAMD3.symbols index 06b328f5745..5ca85d6e693 100644 --- a/tests/baselines/reference/importCallExpressionInAMD3.symbols +++ b/tests/baselines/reference/importCallExpressionInAMD3.symbols @@ -1,4 +1,4 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export class B { >B : Symbol(B, Decl(0.ts, 0, 0)) @@ -6,7 +6,7 @@ export class B { >print : Symbol(B.print, Decl(0.ts, 0, 16)) } -=== tests/cases/conformance/es2018/dynamicImport/2.ts === +=== tests/cases/conformance/dynamicImport/2.ts === async function foo() { >foo : Symbol(foo, Decl(2.ts, 0, 0)) diff --git a/tests/baselines/reference/importCallExpressionInAMD3.types b/tests/baselines/reference/importCallExpressionInAMD3.types index e88ddd04431..e517be6e722 100644 --- a/tests/baselines/reference/importCallExpressionInAMD3.types +++ b/tests/baselines/reference/importCallExpressionInAMD3.types @@ -1,4 +1,4 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export class B { >B : B @@ -7,16 +7,16 @@ export class B { >"I am B" : "I am B" } -=== tests/cases/conformance/es2018/dynamicImport/2.ts === +=== tests/cases/conformance/dynamicImport/2.ts === async function foo() { >foo : () => Promise class C extends (await import("./0")).B {} >C : C >(await import("./0")).B : B ->(await import("./0")) : typeof "tests/cases/conformance/es2018/dynamicImport/0" ->await import("./0") : typeof "tests/cases/conformance/es2018/dynamicImport/0" ->import("./0") : Promise +>(await import("./0")) : typeof "tests/cases/conformance/dynamicImport/0" +>await import("./0") : typeof "tests/cases/conformance/dynamicImport/0" +>import("./0") : Promise >"./0" : "./0" >B : typeof B diff --git a/tests/baselines/reference/importCallExpressionInAMD4.js b/tests/baselines/reference/importCallExpressionInAMD4.js index d498b3df080..6e50e139116 100644 --- a/tests/baselines/reference/importCallExpressionInAMD4.js +++ b/tests/baselines/reference/importCallExpressionInAMD4.js @@ -1,4 +1,4 @@ -//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInAMD4.ts] //// +//// [tests/cases/conformance/dynamicImport/importCallExpressionInAMD4.ts] //// //// [0.ts] export class B { diff --git a/tests/baselines/reference/importCallExpressionInAMD4.symbols b/tests/baselines/reference/importCallExpressionInAMD4.symbols index 1d2a9aec25c..34a1dcf4d7b 100644 --- a/tests/baselines/reference/importCallExpressionInAMD4.symbols +++ b/tests/baselines/reference/importCallExpressionInAMD4.symbols @@ -1,4 +1,4 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export class B { >B : Symbol(B, Decl(0.ts, 0, 0)) @@ -9,11 +9,11 @@ export class B { export function foo() { return "foo" } >foo : Symbol(foo, Decl(0.ts, 2, 1)) -=== tests/cases/conformance/es2018/dynamicImport/1.ts === +=== tests/cases/conformance/dynamicImport/1.ts === export function backup() { return "backup"; } >backup : Symbol(backup, Decl(1.ts, 0, 0)) -=== tests/cases/conformance/es2018/dynamicImport/2.ts === +=== tests/cases/conformance/dynamicImport/2.ts === declare var console: any; >console : Symbol(console, Decl(2.ts, 0, 11)) diff --git a/tests/baselines/reference/importCallExpressionInAMD4.types b/tests/baselines/reference/importCallExpressionInAMD4.types index 6da36879f64..2ea666ba672 100644 --- a/tests/baselines/reference/importCallExpressionInAMD4.types +++ b/tests/baselines/reference/importCallExpressionInAMD4.types @@ -1,4 +1,4 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export class B { >B : B @@ -11,12 +11,12 @@ export function foo() { return "foo" } >foo : () => string >"foo" : "foo" -=== tests/cases/conformance/es2018/dynamicImport/1.ts === +=== tests/cases/conformance/dynamicImport/1.ts === export function backup() { return "backup"; } >backup : () => string >"backup" : "backup" -=== tests/cases/conformance/es2018/dynamicImport/2.ts === +=== tests/cases/conformance/dynamicImport/2.ts === declare var console: any; >console : any @@ -24,8 +24,8 @@ class C { >C : C private myModule = import("./0"); ->myModule : Promise ->import("./0") : Promise +>myModule : Promise +>import("./0") : Promise >"./0" : "./0" method() { @@ -33,13 +33,13 @@ class C { this.myModule.then(Zero => { >this.myModule.then(Zero => { console.log(Zero.foo()); }, async err => { console.log(err); let one = await import("./1"); console.log(one.backup()); }) : Promise ->this.myModule.then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->this.myModule : Promise +>this.myModule.then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>this.myModule : Promise >this : this ->myModule : Promise ->then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->Zero => { console.log(Zero.foo()); } : (Zero: typeof "tests/cases/conformance/es2018/dynamicImport/0") => void ->Zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>myModule : Promise +>then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>Zero => { console.log(Zero.foo()); } : (Zero: typeof "tests/cases/conformance/dynamicImport/0") => void +>Zero : typeof "tests/cases/conformance/dynamicImport/0" console.log(Zero.foo()); >console.log(Zero.foo()) : any @@ -48,7 +48,7 @@ class C { >log : any >Zero.foo() : string >Zero.foo : () => string ->Zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>Zero : typeof "tests/cases/conformance/dynamicImport/0" >foo : () => string }, async err => { @@ -63,9 +63,9 @@ class C { >err : any let one = await import("./1"); ->one : typeof "tests/cases/conformance/es2018/dynamicImport/1" ->await import("./1") : typeof "tests/cases/conformance/es2018/dynamicImport/1" ->import("./1") : Promise +>one : typeof "tests/cases/conformance/dynamicImport/1" +>await import("./1") : typeof "tests/cases/conformance/dynamicImport/1" +>import("./1") : Promise >"./1" : "./1" console.log(one.backup()); @@ -75,7 +75,7 @@ class C { >log : any >one.backup() : string >one.backup : () => string ->one : typeof "tests/cases/conformance/es2018/dynamicImport/1" +>one : typeof "tests/cases/conformance/dynamicImport/1" >backup : () => string }); diff --git a/tests/baselines/reference/importCallExpressionInCJS1.js b/tests/baselines/reference/importCallExpressionInCJS1.js index 1b0783fe018..3fb298b5bde 100644 --- a/tests/baselines/reference/importCallExpressionInCJS1.js +++ b/tests/baselines/reference/importCallExpressionInCJS1.js @@ -1,4 +1,4 @@ -//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInCJS1.ts] //// +//// [tests/cases/conformance/dynamicImport/importCallExpressionInCJS1.ts] //// //// [0.ts] export function foo() { return "foo"; } diff --git a/tests/baselines/reference/importCallExpressionInCJS1.symbols b/tests/baselines/reference/importCallExpressionInCJS1.symbols index 15356c694ed..333251da662 100644 --- a/tests/baselines/reference/importCallExpressionInCJS1.symbols +++ b/tests/baselines/reference/importCallExpressionInCJS1.symbols @@ -1,8 +1,8 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export function foo() { return "foo"; } >foo : Symbol(foo, Decl(0.ts, 0, 0)) -=== tests/cases/conformance/es2018/dynamicImport/1.ts === +=== tests/cases/conformance/dynamicImport/1.ts === import("./0"); var p1 = import("./0"); >p1 : Symbol(p1, Decl(1.ts, 1, 3)) diff --git a/tests/baselines/reference/importCallExpressionInCJS1.types b/tests/baselines/reference/importCallExpressionInCJS1.types index 2733f3ff14a..59da055ee01 100644 --- a/tests/baselines/reference/importCallExpressionInCJS1.types +++ b/tests/baselines/reference/importCallExpressionInCJS1.types @@ -1,30 +1,30 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export function foo() { return "foo"; } >foo : () => string >"foo" : "foo" -=== tests/cases/conformance/es2018/dynamicImport/1.ts === +=== tests/cases/conformance/dynamicImport/1.ts === import("./0"); ->import("./0") : Promise +>import("./0") : Promise >"./0" : "./0" var p1 = import("./0"); ->p1 : Promise ->import("./0") : Promise +>p1 : Promise +>import("./0") : Promise >"./0" : "./0" p1.then(zero => { >p1.then(zero => { return zero.foo();}) : Promise ->p1.then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->p1 : Promise ->then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->zero => { return zero.foo();} : (zero: typeof "tests/cases/conformance/es2018/dynamicImport/0") => string ->zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>p1.then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>p1 : Promise +>then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>zero => { return zero.foo();} : (zero: typeof "tests/cases/conformance/dynamicImport/0") => string +>zero : typeof "tests/cases/conformance/dynamicImport/0" return zero.foo(); >zero.foo() : string >zero.foo : () => string ->zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>zero : typeof "tests/cases/conformance/dynamicImport/0" >foo : () => string }); @@ -33,7 +33,7 @@ function foo() { >foo : () => void const p2 = import("./0"); ->p2 : Promise ->import("./0") : Promise +>p2 : Promise +>import("./0") : Promise >"./0" : "./0" } diff --git a/tests/baselines/reference/importCallExpressionInCJS2.js b/tests/baselines/reference/importCallExpressionInCJS2.js index 4a845e2e4e3..aa983a7a2fe 100644 --- a/tests/baselines/reference/importCallExpressionInCJS2.js +++ b/tests/baselines/reference/importCallExpressionInCJS2.js @@ -1,4 +1,4 @@ -//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInCJS2.ts] //// +//// [tests/cases/conformance/dynamicImport/importCallExpressionInCJS2.ts] //// //// [0.ts] export function foo() { return "foo"; } diff --git a/tests/baselines/reference/importCallExpressionInCJS2.symbols b/tests/baselines/reference/importCallExpressionInCJS2.symbols index 8a62908868c..24f7a5cdb48 100644 --- a/tests/baselines/reference/importCallExpressionInCJS2.symbols +++ b/tests/baselines/reference/importCallExpressionInCJS2.symbols @@ -1,12 +1,12 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export function foo() { return "foo"; } >foo : Symbol(foo, Decl(0.ts, 0, 0)) -=== tests/cases/conformance/es2018/dynamicImport/1.ts === +=== tests/cases/conformance/dynamicImport/1.ts === export function backup() { return "backup"; } >backup : Symbol(backup, Decl(1.ts, 0, 0)) -=== tests/cases/conformance/es2018/dynamicImport/2.ts === +=== tests/cases/conformance/dynamicImport/2.ts === async function compute(promise: Promise) { >compute : Symbol(compute, Decl(2.ts, 0, 0)) >promise : Symbol(promise, Decl(2.ts, 0, 23)) diff --git a/tests/baselines/reference/importCallExpressionInCJS2.types b/tests/baselines/reference/importCallExpressionInCJS2.types index 88317f387fe..063a5224539 100644 --- a/tests/baselines/reference/importCallExpressionInCJS2.types +++ b/tests/baselines/reference/importCallExpressionInCJS2.types @@ -1,14 +1,14 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export function foo() { return "foo"; } >foo : () => string >"foo" : "foo" -=== tests/cases/conformance/es2018/dynamicImport/1.ts === +=== tests/cases/conformance/dynamicImport/1.ts === export function backup() { return "backup"; } >backup : () => string >"backup" : "backup" -=== tests/cases/conformance/es2018/dynamicImport/2.ts === +=== tests/cases/conformance/dynamicImport/2.ts === async function compute(promise: Promise) { >compute : (promise: Promise) => Promise >promise : Promise @@ -24,10 +24,10 @@ async function compute(promise: Promise) { >j : any j = await import("./1"); ->j = await import("./1") : typeof "tests/cases/conformance/es2018/dynamicImport/1" +>j = await import("./1") : typeof "tests/cases/conformance/dynamicImport/1" >j : any ->await import("./1") : typeof "tests/cases/conformance/es2018/dynamicImport/1" ->import("./1") : Promise +>await import("./1") : typeof "tests/cases/conformance/dynamicImport/1" +>import("./1") : Promise >"./1" : "./1" return j.backup(); @@ -46,6 +46,6 @@ async function compute(promise: Promise) { compute(import("./0")); >compute(import("./0")) : Promise >compute : (promise: Promise) => Promise ->import("./0") : Promise +>import("./0") : Promise >"./0" : "./0" diff --git a/tests/baselines/reference/importCallExpressionInCJS3.js b/tests/baselines/reference/importCallExpressionInCJS3.js index a55f57c5674..2f956d9ac3a 100644 --- a/tests/baselines/reference/importCallExpressionInCJS3.js +++ b/tests/baselines/reference/importCallExpressionInCJS3.js @@ -1,4 +1,4 @@ -//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInCJS3.ts] //// +//// [tests/cases/conformance/dynamicImport/importCallExpressionInCJS3.ts] //// //// [0.ts] export class B { diff --git a/tests/baselines/reference/importCallExpressionInCJS3.symbols b/tests/baselines/reference/importCallExpressionInCJS3.symbols index 7db47944520..16fc79c774f 100644 --- a/tests/baselines/reference/importCallExpressionInCJS3.symbols +++ b/tests/baselines/reference/importCallExpressionInCJS3.symbols @@ -1,4 +1,4 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export class B { >B : Symbol(B, Decl(0.ts, 0, 0)) @@ -6,7 +6,7 @@ export class B { >print : Symbol(B.print, Decl(0.ts, 0, 16)) } -=== tests/cases/conformance/es2018/dynamicImport/2.ts === +=== tests/cases/conformance/dynamicImport/2.ts === // We use Promise for now as there is no way to specify shape of module object function foo(x: Promise) { >foo : Symbol(foo, Decl(2.ts, 0, 0)) diff --git a/tests/baselines/reference/importCallExpressionInCJS3.types b/tests/baselines/reference/importCallExpressionInCJS3.types index 2db06142911..44b17eb51fd 100644 --- a/tests/baselines/reference/importCallExpressionInCJS3.types +++ b/tests/baselines/reference/importCallExpressionInCJS3.types @@ -1,4 +1,4 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export class B { >B : B @@ -7,7 +7,7 @@ export class B { >"I am B" : "I am B" } -=== tests/cases/conformance/es2018/dynamicImport/2.ts === +=== tests/cases/conformance/dynamicImport/2.ts === // We use Promise for now as there is no way to specify shape of module object function foo(x: Promise) { >foo : (x: Promise) => void @@ -41,6 +41,6 @@ function foo(x: Promise) { foo(import("./0")); >foo(import("./0")) : void >foo : (x: Promise) => void ->import("./0") : Promise +>import("./0") : Promise >"./0" : "./0" diff --git a/tests/baselines/reference/importCallExpressionInCJS4.js b/tests/baselines/reference/importCallExpressionInCJS4.js index 0264be113ee..554a0b222ab 100644 --- a/tests/baselines/reference/importCallExpressionInCJS4.js +++ b/tests/baselines/reference/importCallExpressionInCJS4.js @@ -1,4 +1,4 @@ -//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInCJS4.ts] //// +//// [tests/cases/conformance/dynamicImport/importCallExpressionInCJS4.ts] //// //// [0.ts] export class B { diff --git a/tests/baselines/reference/importCallExpressionInCJS4.symbols b/tests/baselines/reference/importCallExpressionInCJS4.symbols index 06b328f5745..5ca85d6e693 100644 --- a/tests/baselines/reference/importCallExpressionInCJS4.symbols +++ b/tests/baselines/reference/importCallExpressionInCJS4.symbols @@ -1,4 +1,4 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export class B { >B : Symbol(B, Decl(0.ts, 0, 0)) @@ -6,7 +6,7 @@ export class B { >print : Symbol(B.print, Decl(0.ts, 0, 16)) } -=== tests/cases/conformance/es2018/dynamicImport/2.ts === +=== tests/cases/conformance/dynamicImport/2.ts === async function foo() { >foo : Symbol(foo, Decl(2.ts, 0, 0)) diff --git a/tests/baselines/reference/importCallExpressionInCJS4.types b/tests/baselines/reference/importCallExpressionInCJS4.types index e88ddd04431..e517be6e722 100644 --- a/tests/baselines/reference/importCallExpressionInCJS4.types +++ b/tests/baselines/reference/importCallExpressionInCJS4.types @@ -1,4 +1,4 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export class B { >B : B @@ -7,16 +7,16 @@ export class B { >"I am B" : "I am B" } -=== tests/cases/conformance/es2018/dynamicImport/2.ts === +=== tests/cases/conformance/dynamicImport/2.ts === async function foo() { >foo : () => Promise class C extends (await import("./0")).B {} >C : C >(await import("./0")).B : B ->(await import("./0")) : typeof "tests/cases/conformance/es2018/dynamicImport/0" ->await import("./0") : typeof "tests/cases/conformance/es2018/dynamicImport/0" ->import("./0") : Promise +>(await import("./0")) : typeof "tests/cases/conformance/dynamicImport/0" +>await import("./0") : typeof "tests/cases/conformance/dynamicImport/0" +>import("./0") : Promise >"./0" : "./0" >B : typeof B diff --git a/tests/baselines/reference/importCallExpressionInCJS5.js b/tests/baselines/reference/importCallExpressionInCJS5.js index 196c37e6e72..762da592827 100644 --- a/tests/baselines/reference/importCallExpressionInCJS5.js +++ b/tests/baselines/reference/importCallExpressionInCJS5.js @@ -1,4 +1,4 @@ -//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInCJS5.ts] //// +//// [tests/cases/conformance/dynamicImport/importCallExpressionInCJS5.ts] //// //// [0.ts] export class B { diff --git a/tests/baselines/reference/importCallExpressionInCJS5.symbols b/tests/baselines/reference/importCallExpressionInCJS5.symbols index 1d2a9aec25c..34a1dcf4d7b 100644 --- a/tests/baselines/reference/importCallExpressionInCJS5.symbols +++ b/tests/baselines/reference/importCallExpressionInCJS5.symbols @@ -1,4 +1,4 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export class B { >B : Symbol(B, Decl(0.ts, 0, 0)) @@ -9,11 +9,11 @@ export class B { export function foo() { return "foo" } >foo : Symbol(foo, Decl(0.ts, 2, 1)) -=== tests/cases/conformance/es2018/dynamicImport/1.ts === +=== tests/cases/conformance/dynamicImport/1.ts === export function backup() { return "backup"; } >backup : Symbol(backup, Decl(1.ts, 0, 0)) -=== tests/cases/conformance/es2018/dynamicImport/2.ts === +=== tests/cases/conformance/dynamicImport/2.ts === declare var console: any; >console : Symbol(console, Decl(2.ts, 0, 11)) diff --git a/tests/baselines/reference/importCallExpressionInCJS5.types b/tests/baselines/reference/importCallExpressionInCJS5.types index 6da36879f64..2ea666ba672 100644 --- a/tests/baselines/reference/importCallExpressionInCJS5.types +++ b/tests/baselines/reference/importCallExpressionInCJS5.types @@ -1,4 +1,4 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export class B { >B : B @@ -11,12 +11,12 @@ export function foo() { return "foo" } >foo : () => string >"foo" : "foo" -=== tests/cases/conformance/es2018/dynamicImport/1.ts === +=== tests/cases/conformance/dynamicImport/1.ts === export function backup() { return "backup"; } >backup : () => string >"backup" : "backup" -=== tests/cases/conformance/es2018/dynamicImport/2.ts === +=== tests/cases/conformance/dynamicImport/2.ts === declare var console: any; >console : any @@ -24,8 +24,8 @@ class C { >C : C private myModule = import("./0"); ->myModule : Promise ->import("./0") : Promise +>myModule : Promise +>import("./0") : Promise >"./0" : "./0" method() { @@ -33,13 +33,13 @@ class C { this.myModule.then(Zero => { >this.myModule.then(Zero => { console.log(Zero.foo()); }, async err => { console.log(err); let one = await import("./1"); console.log(one.backup()); }) : Promise ->this.myModule.then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->this.myModule : Promise +>this.myModule.then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>this.myModule : Promise >this : this ->myModule : Promise ->then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->Zero => { console.log(Zero.foo()); } : (Zero: typeof "tests/cases/conformance/es2018/dynamicImport/0") => void ->Zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>myModule : Promise +>then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>Zero => { console.log(Zero.foo()); } : (Zero: typeof "tests/cases/conformance/dynamicImport/0") => void +>Zero : typeof "tests/cases/conformance/dynamicImport/0" console.log(Zero.foo()); >console.log(Zero.foo()) : any @@ -48,7 +48,7 @@ class C { >log : any >Zero.foo() : string >Zero.foo : () => string ->Zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>Zero : typeof "tests/cases/conformance/dynamicImport/0" >foo : () => string }, async err => { @@ -63,9 +63,9 @@ class C { >err : any let one = await import("./1"); ->one : typeof "tests/cases/conformance/es2018/dynamicImport/1" ->await import("./1") : typeof "tests/cases/conformance/es2018/dynamicImport/1" ->import("./1") : Promise +>one : typeof "tests/cases/conformance/dynamicImport/1" +>await import("./1") : typeof "tests/cases/conformance/dynamicImport/1" +>import("./1") : Promise >"./1" : "./1" console.log(one.backup()); @@ -75,7 +75,7 @@ class C { >log : any >one.backup() : string >one.backup : () => string ->one : typeof "tests/cases/conformance/es2018/dynamicImport/1" +>one : typeof "tests/cases/conformance/dynamicImport/1" >backup : () => string }); diff --git a/tests/baselines/reference/importCallExpressionInScriptContext1.js b/tests/baselines/reference/importCallExpressionInScriptContext1.js index 68e51497d14..2c2d2f904d5 100644 --- a/tests/baselines/reference/importCallExpressionInScriptContext1.js +++ b/tests/baselines/reference/importCallExpressionInScriptContext1.js @@ -1,4 +1,4 @@ -//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInScriptContext1.ts] //// +//// [tests/cases/conformance/dynamicImport/importCallExpressionInScriptContext1.ts] //// //// [0.ts] export function foo() { return "foo"; } diff --git a/tests/baselines/reference/importCallExpressionInScriptContext1.symbols b/tests/baselines/reference/importCallExpressionInScriptContext1.symbols index 21e63635ed4..513612056a8 100644 --- a/tests/baselines/reference/importCallExpressionInScriptContext1.symbols +++ b/tests/baselines/reference/importCallExpressionInScriptContext1.symbols @@ -1,8 +1,8 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export function foo() { return "foo"; } >foo : Symbol(foo, Decl(0.ts, 0, 0)) -=== tests/cases/conformance/es2018/dynamicImport/1.ts === +=== tests/cases/conformance/dynamicImport/1.ts === var p1 = import("./0"); >p1 : Symbol(p1, Decl(1.ts, 0, 3)) diff --git a/tests/baselines/reference/importCallExpressionInScriptContext1.types b/tests/baselines/reference/importCallExpressionInScriptContext1.types index 82e00221e33..c318667c7d8 100644 --- a/tests/baselines/reference/importCallExpressionInScriptContext1.types +++ b/tests/baselines/reference/importCallExpressionInScriptContext1.types @@ -1,12 +1,12 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export function foo() { return "foo"; } >foo : () => string >"foo" : "foo" -=== tests/cases/conformance/es2018/dynamicImport/1.ts === +=== tests/cases/conformance/dynamicImport/1.ts === var p1 = import("./0"); ->p1 : Promise ->import("./0") : Promise +>p1 : Promise +>import("./0") : Promise >"./0" : "./0" function arguments() { } // this is allow as the file doesn't have implicit "use strict" diff --git a/tests/baselines/reference/importCallExpressionInScriptContext2.errors.txt b/tests/baselines/reference/importCallExpressionInScriptContext2.errors.txt index d87798eb0c9..9020963f68f 100644 --- a/tests/baselines/reference/importCallExpressionInScriptContext2.errors.txt +++ b/tests/baselines/reference/importCallExpressionInScriptContext2.errors.txt @@ -1,10 +1,10 @@ -tests/cases/conformance/es2018/dynamicImport/1.ts(3,10): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/conformance/dynamicImport/1.ts(3,10): error TS1100: Invalid use of 'arguments' in strict mode. -==== tests/cases/conformance/es2018/dynamicImport/0.ts (0 errors) ==== +==== tests/cases/conformance/dynamicImport/0.ts (0 errors) ==== export function foo() { return "foo"; } -==== tests/cases/conformance/es2018/dynamicImport/1.ts (1 errors) ==== +==== tests/cases/conformance/dynamicImport/1.ts (1 errors) ==== "use strict" var p1 = import("./0"); function arguments() { } diff --git a/tests/baselines/reference/importCallExpressionInScriptContext2.js b/tests/baselines/reference/importCallExpressionInScriptContext2.js index f8bf268468c..6b6e0109fda 100644 --- a/tests/baselines/reference/importCallExpressionInScriptContext2.js +++ b/tests/baselines/reference/importCallExpressionInScriptContext2.js @@ -1,4 +1,4 @@ -//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInScriptContext2.ts] //// +//// [tests/cases/conformance/dynamicImport/importCallExpressionInScriptContext2.ts] //// //// [0.ts] export function foo() { return "foo"; } diff --git a/tests/baselines/reference/importCallExpressionInSystem1.js b/tests/baselines/reference/importCallExpressionInSystem1.js index d200111c70c..d74eb6ffc76 100644 --- a/tests/baselines/reference/importCallExpressionInSystem1.js +++ b/tests/baselines/reference/importCallExpressionInSystem1.js @@ -1,4 +1,4 @@ -//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInSystem1.ts] //// +//// [tests/cases/conformance/dynamicImport/importCallExpressionInSystem1.ts] //// //// [0.ts] export function foo() { return "foo"; } diff --git a/tests/baselines/reference/importCallExpressionInSystem1.symbols b/tests/baselines/reference/importCallExpressionInSystem1.symbols index 15356c694ed..333251da662 100644 --- a/tests/baselines/reference/importCallExpressionInSystem1.symbols +++ b/tests/baselines/reference/importCallExpressionInSystem1.symbols @@ -1,8 +1,8 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export function foo() { return "foo"; } >foo : Symbol(foo, Decl(0.ts, 0, 0)) -=== tests/cases/conformance/es2018/dynamicImport/1.ts === +=== tests/cases/conformance/dynamicImport/1.ts === import("./0"); var p1 = import("./0"); >p1 : Symbol(p1, Decl(1.ts, 1, 3)) diff --git a/tests/baselines/reference/importCallExpressionInSystem1.types b/tests/baselines/reference/importCallExpressionInSystem1.types index 2733f3ff14a..59da055ee01 100644 --- a/tests/baselines/reference/importCallExpressionInSystem1.types +++ b/tests/baselines/reference/importCallExpressionInSystem1.types @@ -1,30 +1,30 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export function foo() { return "foo"; } >foo : () => string >"foo" : "foo" -=== tests/cases/conformance/es2018/dynamicImport/1.ts === +=== tests/cases/conformance/dynamicImport/1.ts === import("./0"); ->import("./0") : Promise +>import("./0") : Promise >"./0" : "./0" var p1 = import("./0"); ->p1 : Promise ->import("./0") : Promise +>p1 : Promise +>import("./0") : Promise >"./0" : "./0" p1.then(zero => { >p1.then(zero => { return zero.foo();}) : Promise ->p1.then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->p1 : Promise ->then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->zero => { return zero.foo();} : (zero: typeof "tests/cases/conformance/es2018/dynamicImport/0") => string ->zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>p1.then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>p1 : Promise +>then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>zero => { return zero.foo();} : (zero: typeof "tests/cases/conformance/dynamicImport/0") => string +>zero : typeof "tests/cases/conformance/dynamicImport/0" return zero.foo(); >zero.foo() : string >zero.foo : () => string ->zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>zero : typeof "tests/cases/conformance/dynamicImport/0" >foo : () => string }); @@ -33,7 +33,7 @@ function foo() { >foo : () => void const p2 = import("./0"); ->p2 : Promise ->import("./0") : Promise +>p2 : Promise +>import("./0") : Promise >"./0" : "./0" } diff --git a/tests/baselines/reference/importCallExpressionInSystem2.js b/tests/baselines/reference/importCallExpressionInSystem2.js index 704af5822b3..ea84e47e63c 100644 --- a/tests/baselines/reference/importCallExpressionInSystem2.js +++ b/tests/baselines/reference/importCallExpressionInSystem2.js @@ -1,4 +1,4 @@ -//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInSystem2.ts] //// +//// [tests/cases/conformance/dynamicImport/importCallExpressionInSystem2.ts] //// //// [0.ts] export class B { diff --git a/tests/baselines/reference/importCallExpressionInSystem2.symbols b/tests/baselines/reference/importCallExpressionInSystem2.symbols index 7db47944520..16fc79c774f 100644 --- a/tests/baselines/reference/importCallExpressionInSystem2.symbols +++ b/tests/baselines/reference/importCallExpressionInSystem2.symbols @@ -1,4 +1,4 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export class B { >B : Symbol(B, Decl(0.ts, 0, 0)) @@ -6,7 +6,7 @@ export class B { >print : Symbol(B.print, Decl(0.ts, 0, 16)) } -=== tests/cases/conformance/es2018/dynamicImport/2.ts === +=== tests/cases/conformance/dynamicImport/2.ts === // We use Promise for now as there is no way to specify shape of module object function foo(x: Promise) { >foo : Symbol(foo, Decl(2.ts, 0, 0)) diff --git a/tests/baselines/reference/importCallExpressionInSystem2.types b/tests/baselines/reference/importCallExpressionInSystem2.types index 2db06142911..44b17eb51fd 100644 --- a/tests/baselines/reference/importCallExpressionInSystem2.types +++ b/tests/baselines/reference/importCallExpressionInSystem2.types @@ -1,4 +1,4 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export class B { >B : B @@ -7,7 +7,7 @@ export class B { >"I am B" : "I am B" } -=== tests/cases/conformance/es2018/dynamicImport/2.ts === +=== tests/cases/conformance/dynamicImport/2.ts === // We use Promise for now as there is no way to specify shape of module object function foo(x: Promise) { >foo : (x: Promise) => void @@ -41,6 +41,6 @@ function foo(x: Promise) { foo(import("./0")); >foo(import("./0")) : void >foo : (x: Promise) => void ->import("./0") : Promise +>import("./0") : Promise >"./0" : "./0" diff --git a/tests/baselines/reference/importCallExpressionInSystem3.js b/tests/baselines/reference/importCallExpressionInSystem3.js index cdc6856d96b..309be9114fe 100644 --- a/tests/baselines/reference/importCallExpressionInSystem3.js +++ b/tests/baselines/reference/importCallExpressionInSystem3.js @@ -1,4 +1,4 @@ -//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInSystem3.ts] //// +//// [tests/cases/conformance/dynamicImport/importCallExpressionInSystem3.ts] //// //// [0.ts] export class B { diff --git a/tests/baselines/reference/importCallExpressionInSystem3.symbols b/tests/baselines/reference/importCallExpressionInSystem3.symbols index 06b328f5745..5ca85d6e693 100644 --- a/tests/baselines/reference/importCallExpressionInSystem3.symbols +++ b/tests/baselines/reference/importCallExpressionInSystem3.symbols @@ -1,4 +1,4 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export class B { >B : Symbol(B, Decl(0.ts, 0, 0)) @@ -6,7 +6,7 @@ export class B { >print : Symbol(B.print, Decl(0.ts, 0, 16)) } -=== tests/cases/conformance/es2018/dynamicImport/2.ts === +=== tests/cases/conformance/dynamicImport/2.ts === async function foo() { >foo : Symbol(foo, Decl(2.ts, 0, 0)) diff --git a/tests/baselines/reference/importCallExpressionInSystem3.types b/tests/baselines/reference/importCallExpressionInSystem3.types index e88ddd04431..e517be6e722 100644 --- a/tests/baselines/reference/importCallExpressionInSystem3.types +++ b/tests/baselines/reference/importCallExpressionInSystem3.types @@ -1,4 +1,4 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export class B { >B : B @@ -7,16 +7,16 @@ export class B { >"I am B" : "I am B" } -=== tests/cases/conformance/es2018/dynamicImport/2.ts === +=== tests/cases/conformance/dynamicImport/2.ts === async function foo() { >foo : () => Promise class C extends (await import("./0")).B {} >C : C >(await import("./0")).B : B ->(await import("./0")) : typeof "tests/cases/conformance/es2018/dynamicImport/0" ->await import("./0") : typeof "tests/cases/conformance/es2018/dynamicImport/0" ->import("./0") : Promise +>(await import("./0")) : typeof "tests/cases/conformance/dynamicImport/0" +>await import("./0") : typeof "tests/cases/conformance/dynamicImport/0" +>import("./0") : Promise >"./0" : "./0" >B : typeof B diff --git a/tests/baselines/reference/importCallExpressionInSystem4.js b/tests/baselines/reference/importCallExpressionInSystem4.js index 81562b65212..ac01a0439e8 100644 --- a/tests/baselines/reference/importCallExpressionInSystem4.js +++ b/tests/baselines/reference/importCallExpressionInSystem4.js @@ -1,4 +1,4 @@ -//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInSystem4.ts] //// +//// [tests/cases/conformance/dynamicImport/importCallExpressionInSystem4.ts] //// //// [0.ts] export class B { diff --git a/tests/baselines/reference/importCallExpressionInSystem4.symbols b/tests/baselines/reference/importCallExpressionInSystem4.symbols index 1d2a9aec25c..34a1dcf4d7b 100644 --- a/tests/baselines/reference/importCallExpressionInSystem4.symbols +++ b/tests/baselines/reference/importCallExpressionInSystem4.symbols @@ -1,4 +1,4 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export class B { >B : Symbol(B, Decl(0.ts, 0, 0)) @@ -9,11 +9,11 @@ export class B { export function foo() { return "foo" } >foo : Symbol(foo, Decl(0.ts, 2, 1)) -=== tests/cases/conformance/es2018/dynamicImport/1.ts === +=== tests/cases/conformance/dynamicImport/1.ts === export function backup() { return "backup"; } >backup : Symbol(backup, Decl(1.ts, 0, 0)) -=== tests/cases/conformance/es2018/dynamicImport/2.ts === +=== tests/cases/conformance/dynamicImport/2.ts === declare var console: any; >console : Symbol(console, Decl(2.ts, 0, 11)) diff --git a/tests/baselines/reference/importCallExpressionInSystem4.types b/tests/baselines/reference/importCallExpressionInSystem4.types index 6da36879f64..2ea666ba672 100644 --- a/tests/baselines/reference/importCallExpressionInSystem4.types +++ b/tests/baselines/reference/importCallExpressionInSystem4.types @@ -1,4 +1,4 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export class B { >B : B @@ -11,12 +11,12 @@ export function foo() { return "foo" } >foo : () => string >"foo" : "foo" -=== tests/cases/conformance/es2018/dynamicImport/1.ts === +=== tests/cases/conformance/dynamicImport/1.ts === export function backup() { return "backup"; } >backup : () => string >"backup" : "backup" -=== tests/cases/conformance/es2018/dynamicImport/2.ts === +=== tests/cases/conformance/dynamicImport/2.ts === declare var console: any; >console : any @@ -24,8 +24,8 @@ class C { >C : C private myModule = import("./0"); ->myModule : Promise ->import("./0") : Promise +>myModule : Promise +>import("./0") : Promise >"./0" : "./0" method() { @@ -33,13 +33,13 @@ class C { this.myModule.then(Zero => { >this.myModule.then(Zero => { console.log(Zero.foo()); }, async err => { console.log(err); let one = await import("./1"); console.log(one.backup()); }) : Promise ->this.myModule.then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->this.myModule : Promise +>this.myModule.then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>this.myModule : Promise >this : this ->myModule : Promise ->then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->Zero => { console.log(Zero.foo()); } : (Zero: typeof "tests/cases/conformance/es2018/dynamicImport/0") => void ->Zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>myModule : Promise +>then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>Zero => { console.log(Zero.foo()); } : (Zero: typeof "tests/cases/conformance/dynamicImport/0") => void +>Zero : typeof "tests/cases/conformance/dynamicImport/0" console.log(Zero.foo()); >console.log(Zero.foo()) : any @@ -48,7 +48,7 @@ class C { >log : any >Zero.foo() : string >Zero.foo : () => string ->Zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>Zero : typeof "tests/cases/conformance/dynamicImport/0" >foo : () => string }, async err => { @@ -63,9 +63,9 @@ class C { >err : any let one = await import("./1"); ->one : typeof "tests/cases/conformance/es2018/dynamicImport/1" ->await import("./1") : typeof "tests/cases/conformance/es2018/dynamicImport/1" ->import("./1") : Promise +>one : typeof "tests/cases/conformance/dynamicImport/1" +>await import("./1") : typeof "tests/cases/conformance/dynamicImport/1" +>import("./1") : Promise >"./1" : "./1" console.log(one.backup()); @@ -75,7 +75,7 @@ class C { >log : any >one.backup() : string >one.backup : () => string ->one : typeof "tests/cases/conformance/es2018/dynamicImport/1" +>one : typeof "tests/cases/conformance/dynamicImport/1" >backup : () => string }); diff --git a/tests/baselines/reference/importCallExpressionInUMD1.js b/tests/baselines/reference/importCallExpressionInUMD1.js index 0886da93287..f1bfcd3cc71 100644 --- a/tests/baselines/reference/importCallExpressionInUMD1.js +++ b/tests/baselines/reference/importCallExpressionInUMD1.js @@ -1,4 +1,4 @@ -//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInUMD1.ts] //// +//// [tests/cases/conformance/dynamicImport/importCallExpressionInUMD1.ts] //// //// [0.ts] export function foo() { return "foo"; } diff --git a/tests/baselines/reference/importCallExpressionInUMD1.symbols b/tests/baselines/reference/importCallExpressionInUMD1.symbols index 15356c694ed..333251da662 100644 --- a/tests/baselines/reference/importCallExpressionInUMD1.symbols +++ b/tests/baselines/reference/importCallExpressionInUMD1.symbols @@ -1,8 +1,8 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export function foo() { return "foo"; } >foo : Symbol(foo, Decl(0.ts, 0, 0)) -=== tests/cases/conformance/es2018/dynamicImport/1.ts === +=== tests/cases/conformance/dynamicImport/1.ts === import("./0"); var p1 = import("./0"); >p1 : Symbol(p1, Decl(1.ts, 1, 3)) diff --git a/tests/baselines/reference/importCallExpressionInUMD1.types b/tests/baselines/reference/importCallExpressionInUMD1.types index 2733f3ff14a..59da055ee01 100644 --- a/tests/baselines/reference/importCallExpressionInUMD1.types +++ b/tests/baselines/reference/importCallExpressionInUMD1.types @@ -1,30 +1,30 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export function foo() { return "foo"; } >foo : () => string >"foo" : "foo" -=== tests/cases/conformance/es2018/dynamicImport/1.ts === +=== tests/cases/conformance/dynamicImport/1.ts === import("./0"); ->import("./0") : Promise +>import("./0") : Promise >"./0" : "./0" var p1 = import("./0"); ->p1 : Promise ->import("./0") : Promise +>p1 : Promise +>import("./0") : Promise >"./0" : "./0" p1.then(zero => { >p1.then(zero => { return zero.foo();}) : Promise ->p1.then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->p1 : Promise ->then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->zero => { return zero.foo();} : (zero: typeof "tests/cases/conformance/es2018/dynamicImport/0") => string ->zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>p1.then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>p1 : Promise +>then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>zero => { return zero.foo();} : (zero: typeof "tests/cases/conformance/dynamicImport/0") => string +>zero : typeof "tests/cases/conformance/dynamicImport/0" return zero.foo(); >zero.foo() : string >zero.foo : () => string ->zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>zero : typeof "tests/cases/conformance/dynamicImport/0" >foo : () => string }); @@ -33,7 +33,7 @@ function foo() { >foo : () => void const p2 = import("./0"); ->p2 : Promise ->import("./0") : Promise +>p2 : Promise +>import("./0") : Promise >"./0" : "./0" } diff --git a/tests/baselines/reference/importCallExpressionInUMD2.js b/tests/baselines/reference/importCallExpressionInUMD2.js index 1e268403088..db8b87a2f79 100644 --- a/tests/baselines/reference/importCallExpressionInUMD2.js +++ b/tests/baselines/reference/importCallExpressionInUMD2.js @@ -1,4 +1,4 @@ -//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInUMD2.ts] //// +//// [tests/cases/conformance/dynamicImport/importCallExpressionInUMD2.ts] //// //// [0.ts] export class B { diff --git a/tests/baselines/reference/importCallExpressionInUMD2.symbols b/tests/baselines/reference/importCallExpressionInUMD2.symbols index 7db47944520..16fc79c774f 100644 --- a/tests/baselines/reference/importCallExpressionInUMD2.symbols +++ b/tests/baselines/reference/importCallExpressionInUMD2.symbols @@ -1,4 +1,4 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export class B { >B : Symbol(B, Decl(0.ts, 0, 0)) @@ -6,7 +6,7 @@ export class B { >print : Symbol(B.print, Decl(0.ts, 0, 16)) } -=== tests/cases/conformance/es2018/dynamicImport/2.ts === +=== tests/cases/conformance/dynamicImport/2.ts === // We use Promise for now as there is no way to specify shape of module object function foo(x: Promise) { >foo : Symbol(foo, Decl(2.ts, 0, 0)) diff --git a/tests/baselines/reference/importCallExpressionInUMD2.types b/tests/baselines/reference/importCallExpressionInUMD2.types index 2db06142911..44b17eb51fd 100644 --- a/tests/baselines/reference/importCallExpressionInUMD2.types +++ b/tests/baselines/reference/importCallExpressionInUMD2.types @@ -1,4 +1,4 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export class B { >B : B @@ -7,7 +7,7 @@ export class B { >"I am B" : "I am B" } -=== tests/cases/conformance/es2018/dynamicImport/2.ts === +=== tests/cases/conformance/dynamicImport/2.ts === // We use Promise for now as there is no way to specify shape of module object function foo(x: Promise) { >foo : (x: Promise) => void @@ -41,6 +41,6 @@ function foo(x: Promise) { foo(import("./0")); >foo(import("./0")) : void >foo : (x: Promise) => void ->import("./0") : Promise +>import("./0") : Promise >"./0" : "./0" diff --git a/tests/baselines/reference/importCallExpressionInUMD3.js b/tests/baselines/reference/importCallExpressionInUMD3.js index 228c43fd0a2..41106e3ab78 100644 --- a/tests/baselines/reference/importCallExpressionInUMD3.js +++ b/tests/baselines/reference/importCallExpressionInUMD3.js @@ -1,4 +1,4 @@ -//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInUMD3.ts] //// +//// [tests/cases/conformance/dynamicImport/importCallExpressionInUMD3.ts] //// //// [0.ts] export class B { diff --git a/tests/baselines/reference/importCallExpressionInUMD3.symbols b/tests/baselines/reference/importCallExpressionInUMD3.symbols index 06b328f5745..5ca85d6e693 100644 --- a/tests/baselines/reference/importCallExpressionInUMD3.symbols +++ b/tests/baselines/reference/importCallExpressionInUMD3.symbols @@ -1,4 +1,4 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export class B { >B : Symbol(B, Decl(0.ts, 0, 0)) @@ -6,7 +6,7 @@ export class B { >print : Symbol(B.print, Decl(0.ts, 0, 16)) } -=== tests/cases/conformance/es2018/dynamicImport/2.ts === +=== tests/cases/conformance/dynamicImport/2.ts === async function foo() { >foo : Symbol(foo, Decl(2.ts, 0, 0)) diff --git a/tests/baselines/reference/importCallExpressionInUMD3.types b/tests/baselines/reference/importCallExpressionInUMD3.types index e88ddd04431..e517be6e722 100644 --- a/tests/baselines/reference/importCallExpressionInUMD3.types +++ b/tests/baselines/reference/importCallExpressionInUMD3.types @@ -1,4 +1,4 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export class B { >B : B @@ -7,16 +7,16 @@ export class B { >"I am B" : "I am B" } -=== tests/cases/conformance/es2018/dynamicImport/2.ts === +=== tests/cases/conformance/dynamicImport/2.ts === async function foo() { >foo : () => Promise class C extends (await import("./0")).B {} >C : C >(await import("./0")).B : B ->(await import("./0")) : typeof "tests/cases/conformance/es2018/dynamicImport/0" ->await import("./0") : typeof "tests/cases/conformance/es2018/dynamicImport/0" ->import("./0") : Promise +>(await import("./0")) : typeof "tests/cases/conformance/dynamicImport/0" +>await import("./0") : typeof "tests/cases/conformance/dynamicImport/0" +>import("./0") : Promise >"./0" : "./0" >B : typeof B diff --git a/tests/baselines/reference/importCallExpressionInUMD4.js b/tests/baselines/reference/importCallExpressionInUMD4.js index 677ba8c3d27..47ba83b1718 100644 --- a/tests/baselines/reference/importCallExpressionInUMD4.js +++ b/tests/baselines/reference/importCallExpressionInUMD4.js @@ -1,4 +1,4 @@ -//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInUMD4.ts] //// +//// [tests/cases/conformance/dynamicImport/importCallExpressionInUMD4.ts] //// //// [0.ts] export class B { diff --git a/tests/baselines/reference/importCallExpressionInUMD4.symbols b/tests/baselines/reference/importCallExpressionInUMD4.symbols index 1d2a9aec25c..34a1dcf4d7b 100644 --- a/tests/baselines/reference/importCallExpressionInUMD4.symbols +++ b/tests/baselines/reference/importCallExpressionInUMD4.symbols @@ -1,4 +1,4 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export class B { >B : Symbol(B, Decl(0.ts, 0, 0)) @@ -9,11 +9,11 @@ export class B { export function foo() { return "foo" } >foo : Symbol(foo, Decl(0.ts, 2, 1)) -=== tests/cases/conformance/es2018/dynamicImport/1.ts === +=== tests/cases/conformance/dynamicImport/1.ts === export function backup() { return "backup"; } >backup : Symbol(backup, Decl(1.ts, 0, 0)) -=== tests/cases/conformance/es2018/dynamicImport/2.ts === +=== tests/cases/conformance/dynamicImport/2.ts === declare var console: any; >console : Symbol(console, Decl(2.ts, 0, 11)) diff --git a/tests/baselines/reference/importCallExpressionInUMD4.types b/tests/baselines/reference/importCallExpressionInUMD4.types index 6da36879f64..2ea666ba672 100644 --- a/tests/baselines/reference/importCallExpressionInUMD4.types +++ b/tests/baselines/reference/importCallExpressionInUMD4.types @@ -1,4 +1,4 @@ -=== tests/cases/conformance/es2018/dynamicImport/0.ts === +=== tests/cases/conformance/dynamicImport/0.ts === export class B { >B : B @@ -11,12 +11,12 @@ export function foo() { return "foo" } >foo : () => string >"foo" : "foo" -=== tests/cases/conformance/es2018/dynamicImport/1.ts === +=== tests/cases/conformance/dynamicImport/1.ts === export function backup() { return "backup"; } >backup : () => string >"backup" : "backup" -=== tests/cases/conformance/es2018/dynamicImport/2.ts === +=== tests/cases/conformance/dynamicImport/2.ts === declare var console: any; >console : any @@ -24,8 +24,8 @@ class C { >C : C private myModule = import("./0"); ->myModule : Promise ->import("./0") : Promise +>myModule : Promise +>import("./0") : Promise >"./0" : "./0" method() { @@ -33,13 +33,13 @@ class C { this.myModule.then(Zero => { >this.myModule.then(Zero => { console.log(Zero.foo()); }, async err => { console.log(err); let one = await import("./1"); console.log(one.backup()); }) : Promise ->this.myModule.then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->this.myModule : Promise +>this.myModule.then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>this.myModule : Promise >this : this ->myModule : Promise ->then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->Zero => { console.log(Zero.foo()); } : (Zero: typeof "tests/cases/conformance/es2018/dynamicImport/0") => void ->Zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>myModule : Promise +>then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>Zero => { console.log(Zero.foo()); } : (Zero: typeof "tests/cases/conformance/dynamicImport/0") => void +>Zero : typeof "tests/cases/conformance/dynamicImport/0" console.log(Zero.foo()); >console.log(Zero.foo()) : any @@ -48,7 +48,7 @@ class C { >log : any >Zero.foo() : string >Zero.foo : () => string ->Zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>Zero : typeof "tests/cases/conformance/dynamicImport/0" >foo : () => string }, async err => { @@ -63,9 +63,9 @@ class C { >err : any let one = await import("./1"); ->one : typeof "tests/cases/conformance/es2018/dynamicImport/1" ->await import("./1") : typeof "tests/cases/conformance/es2018/dynamicImport/1" ->import("./1") : Promise +>one : typeof "tests/cases/conformance/dynamicImport/1" +>await import("./1") : typeof "tests/cases/conformance/dynamicImport/1" +>import("./1") : Promise >"./1" : "./1" console.log(one.backup()); @@ -75,7 +75,7 @@ class C { >log : any >one.backup() : string >one.backup : () => string ->one : typeof "tests/cases/conformance/es2018/dynamicImport/1" +>one : typeof "tests/cases/conformance/dynamicImport/1" >backup : () => string }); diff --git a/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.js b/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.js index d9dba458296..728d6636953 100644 --- a/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.js +++ b/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.js @@ -1,4 +1,4 @@ -//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionReturnPromiseOfAny.ts] //// +//// [tests/cases/conformance/dynamicImport/importCallExpressionReturnPromiseOfAny.ts] //// //// [defaultPath.ts] export class C {} diff --git a/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.symbols b/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.symbols index 275bedd4c93..0d46961475f 100644 --- a/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.symbols +++ b/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.symbols @@ -1,8 +1,8 @@ -=== tests/cases/conformance/es2018/dynamicImport/defaultPath.ts === +=== tests/cases/conformance/dynamicImport/defaultPath.ts === export class C {} >C : Symbol(C, Decl(defaultPath.ts, 0, 0)) -=== tests/cases/conformance/es2018/dynamicImport/1.ts === +=== tests/cases/conformance/dynamicImport/1.ts === import * as defaultModule from "./defaultPath"; >defaultModule : Symbol(defaultModule, Decl(1.ts, 0, 6)) diff --git a/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.types b/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.types index 4337e970bd1..fc52b38c1fb 100644 --- a/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.types +++ b/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.types @@ -1,8 +1,8 @@ -=== tests/cases/conformance/es2018/dynamicImport/defaultPath.ts === +=== tests/cases/conformance/dynamicImport/defaultPath.ts === export class C {} >C : C -=== tests/cases/conformance/es2018/dynamicImport/1.ts === +=== tests/cases/conformance/dynamicImport/1.ts === import * as defaultModule from "./defaultPath"; >defaultModule : typeof defaultModule diff --git a/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.errors.txt b/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.errors.txt index dd705582827..a1159a31ebd 100644 --- a/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.errors.txt +++ b/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.errors.txt @@ -1,11 +1,11 @@ -tests/cases/conformance/es2018/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts(5,8): error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'boolean'. -tests/cases/conformance/es2018/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts(6,17): error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'boolean'. -tests/cases/conformance/es2018/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts(7,19): error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'boolean | "defaulPath"'. -tests/cases/conformance/es2018/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts(12,17): error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'string[]'. -tests/cases/conformance/es2018/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts(13,17): error TS7036: Dynamic import's specifier must be of type 'string', but here has type '() => string'. +tests/cases/conformance/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts(5,8): error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'boolean'. +tests/cases/conformance/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts(6,17): error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'boolean'. +tests/cases/conformance/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts(7,19): error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'boolean | "defaulPath"'. +tests/cases/conformance/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts(12,17): error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'string[]'. +tests/cases/conformance/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts(13,17): error TS7036: Dynamic import's specifier must be of type 'string', but here has type '() => string'. -==== tests/cases/conformance/es2018/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts (5 errors) ==== +==== tests/cases/conformance/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts (5 errors) ==== declare function getSpecifier(): boolean; declare var whatToLoad: boolean; diff --git a/tests/baselines/reference/importCallExpressionWithTypeArgument.errors.txt b/tests/baselines/reference/importCallExpressionWithTypeArgument.errors.txt index f9375ec695f..8adf2789585 100644 --- a/tests/baselines/reference/importCallExpressionWithTypeArgument.errors.txt +++ b/tests/baselines/reference/importCallExpressionWithTypeArgument.errors.txt @@ -1,11 +1,11 @@ -tests/cases/conformance/es2018/dynamicImport/1.ts(2,10): error TS1326: Dynamic import cannot have type arguments -tests/cases/conformance/es2018/dynamicImport/1.ts(3,10): error TS1326: Dynamic import cannot have type arguments +tests/cases/conformance/dynamicImport/1.ts(2,10): error TS1326: Dynamic import cannot have type arguments +tests/cases/conformance/dynamicImport/1.ts(3,10): error TS1326: Dynamic import cannot have type arguments -==== tests/cases/conformance/es2018/dynamicImport/0.ts (0 errors) ==== +==== tests/cases/conformance/dynamicImport/0.ts (0 errors) ==== export function foo() { return "foo"; } -==== tests/cases/conformance/es2018/dynamicImport/1.ts (2 errors) ==== +==== tests/cases/conformance/dynamicImport/1.ts (2 errors) ==== "use strict" var p1 = import>("./0"); // error ~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/tests/baselines/reference/importCallExpressionWithTypeArgument.js b/tests/baselines/reference/importCallExpressionWithTypeArgument.js index de487bc45cc..d8690cf5d75 100644 --- a/tests/baselines/reference/importCallExpressionWithTypeArgument.js +++ b/tests/baselines/reference/importCallExpressionWithTypeArgument.js @@ -1,4 +1,4 @@ -//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionWithTypeArgument.ts] //// +//// [tests/cases/conformance/dynamicImport/importCallExpressionWithTypeArgument.ts] //// //// [0.ts] export function foo() { return "foo"; } diff --git a/tests/baselines/reference/transpile/Report an error when compiler-options module-kind is out-of-range.errors.txt b/tests/baselines/reference/transpile/Report an error when compiler-options module-kind is out-of-range.errors.txt index 16fb5e7b205..f746915da7d 100644 --- a/tests/baselines/reference/transpile/Report an error when compiler-options module-kind is out-of-range.errors.txt +++ b/tests/baselines/reference/transpile/Report an error when compiler-options module-kind is out-of-range.errors.txt @@ -1,6 +1,6 @@ -error TS6046: Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'es2018'. +error TS6046: Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'esnext'. -!!! error TS6046: Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'es2018'. +!!! error TS6046: Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'esnext'. ==== file.ts (0 errors) ==== \ No newline at end of file diff --git a/tests/baselines/reference/transpile/Report an error when compiler-options target-script is out-of-range.errors.txt b/tests/baselines/reference/transpile/Report an error when compiler-options target-script is out-of-range.errors.txt index 16fb5e7b205..f746915da7d 100644 --- a/tests/baselines/reference/transpile/Report an error when compiler-options target-script is out-of-range.errors.txt +++ b/tests/baselines/reference/transpile/Report an error when compiler-options target-script is out-of-range.errors.txt @@ -1,6 +1,6 @@ -error TS6046: Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'es2018'. +error TS6046: Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'esnext'. -!!! error TS6046: Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'es2018'. +!!! error TS6046: Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'esnext'. ==== file.ts (0 errors) ==== \ No newline at end of file From 1729ea860925485616de87e751eccdd7c81a2f5e Mon Sep 17 00:00:00 2001 From: Yui T Date: Sun, 4 Jun 2017 21:18:52 -0700 Subject: [PATCH 67/67] Update command line --- src/compiler/commandLineParser.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index adb6a0df189..23efd047e46 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -100,7 +100,7 @@ namespace ts { "umd": ModuleKind.UMD, "es6": ModuleKind.ES2015, "es2015": ModuleKind.ES2015, - "es2018": ModuleKind.ESNext + "esnext": ModuleKind.ESNext }), paramType: Diagnostics.KIND, showInSimplifiedHelpView: true,