diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index d55f3650c109c..22209e2e41e17 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -2333,7 +2333,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 @@ -2741,6 +2741,10 @@ namespace ts { transformFlags |= TransformFlags.AssertES2015; } + if (expression.kind === SyntaxKind.ImportKeyword) { + transformFlags |= TransformFlags.ContainsDynamicImport; + } + node.transformFlags = transformFlags | TransformFlags.HasComputedFlags; return transformFlags & ~TransformFlags.ArrayLiteralOrCallOrNewExcludes; } diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index cfe2c5a6bf2d1..c647a8ad554c7 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8356,6 +8356,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); @@ -16123,6 +16129,35 @@ namespace ts { return getReturnTypeOfSignature(signature); } + function checkImportCallExpression(node: ImportCall): Type { + // Check grammar of dynamic import + checkGrammarArguments(node, node.arguments) || checkGrammarImportCallExpression(node); + + if (node.arguments.length === 0) { + return createPromiseReturnType(node, anyType); + } + const specifier = node.arguments[0]; + 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) { + const esModuleSymbol = resolveESModuleSymbol(moduleSymbol, specifier, /*dontRecursivelyResolve*/ true); + if (esModuleSymbol) { + return createPromiseReturnType(node, getTypeOfSymbol(esModuleSymbol)); + } + } + return createPromiseReturnType(node, anyType); + } + function isCommonJsRequire(node: Node) { if (!isRequireCall(node, /*checkArgumentIsStringLiteral*/ true)) { return false; @@ -16329,14 +16364,18 @@ namespace ts { return emptyObjectType; } - function createPromiseReturnType(func: FunctionLikeDeclaration, promisedType: Type) { + function createPromiseReturnType(func: FunctionLikeDeclaration | ImportCall, 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, isImportCall(func) ? + 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; } 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, 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); } return promiseType; @@ -17695,6 +17734,10 @@ namespace ts { case SyntaxKind.ElementAccessExpression: return checkIndexedAccess(node); case SyntaxKind.CallExpression: + if ((node).expression.kind === SyntaxKind.ImportKeyword) { + return checkImportCallExpression(node); + } + /* falls through */ case SyntaxKind.NewExpression: return checkCallExpression(node); case SyntaxKind.TaggedTemplateExpression: @@ -24620,6 +24663,27 @@ namespace ts { }); return result; } + + function checkGrammarImportCallExpression(node: ImportCall): boolean { + 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 (isSpreadElement(arguments[0])) { + return grammarErrorOnNode(arguments[0], Diagnostics.Specifier_of_dynamic_import_cannot_be_spread_element); + } + } } /** Like 'isDeclarationName', but returns true for LHS of `import { x as y }` or `export { x as y }`. */ diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index fa0c8140bb683..23efd047e465f 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -100,11 +100,12 @@ namespace ts { "umd": ModuleKind.UMD, "es6": ModuleKind.ES2015, "es2015": ModuleKind.ES2015, + "esnext": ModuleKind.ESNext }), paramType: Diagnostics.KIND, showInSimplifiedHelpView: true, category: Diagnostics.Basic_Options, - 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_ESNext, }, { name: "lib", diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index a7b6db70e5e57..a74d41ff473c2 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -883,6 +883,23 @@ "category": "Error", "code": 1322 }, + "Dynamic import cannot be used when targeting ECMAScript 2015 modules.": { + "category": "Error", + "code": 1323 + }, + "Dynamic import must have one specifier as an argument.": { + "category": "Error", + "code": 1324 + }, + "Specifier of dynamic import cannot be spread element.": { + "category": "Error", + "code": 1325 + }, + "Dynamic import cannot have type arguments": { + "category": "Error", + "code": 1326 + }, + "Duplicate identifier '{0}'.": { "category": "Error", "code": 2300 @@ -1923,10 +1940,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 @@ -2159,6 +2172,14 @@ "category": "Error", "code": 2710 }, + "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 + }, + "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": 2712 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", @@ -2625,7 +2646,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 'ESNext'.": { "category": "Message", "code": 6016 }, @@ -3361,6 +3382,11 @@ "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 diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 1d2f75fcd6066..1e6cc3b12dbde 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -676,6 +676,7 @@ namespace ts { case SyntaxKind.SuperKeyword: case SyntaxKind.TrueKeyword: case SyntaxKind.ThisKeyword: + case SyntaxKind.ImportKeyword: writeTokenNode(node); return; diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 849f97bbbaf7c..a3f440fd6c079 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 | undefined, cbNodeArray?: (nodes: NodeArray) => T | undefined): T | undefined { if (!node) { return; @@ -2409,7 +2415,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(); @@ -2420,7 +2426,7 @@ namespace ts { return parsePropertyOrMethodSignature(fullStart, modifiers); } - function isStartOfConstructSignature() { + function nextTokenIsOpenParenOrLessThan() { nextToken(); return token() === SyntaxKind.OpenParenToken || token() === SyntaxKind.LessThanToken; } @@ -2776,6 +2782,7 @@ namespace ts { case SyntaxKind.SlashToken: case SyntaxKind.SlashEqualsToken: case SyntaxKind.Identifier: + case SyntaxKind.ImportKeyword: return true; default: return isIdentifier(); @@ -3509,10 +3516,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; } /** @@ -3578,7 +3585,7 @@ namespace ts { } // falls through default: - return parseIncrementExpression(); + return parseUpdateExpression(); } } @@ -3594,7 +3601,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: @@ -3618,9 +3625,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]]-- @@ -3628,7 +3635,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(); @@ -3678,17 +3685,27 @@ 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.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 + // import * as foo1 from "module-from-node -> we want this import to be a statement rather than import call expression + sourceFile.flags |= NodeFlags.PossiblyContainDynamicImport; + expression = parseTokenNode(); + } + else { + 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. @@ -3696,7 +3713,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: // @@ -4790,11 +4807,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: diff --git a/src/compiler/program.ts b/src/compiler/program.ts index e69a89cc61886..cfe12e3a5a7ab 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1366,6 +1366,7 @@ namespace ts { const isJavaScriptFile = isSourceFileJavaScript(file); const isExternalModuleFile = isExternalModule(file); + // file.imports may not be undefined if there exists dynamic import let imports: LiteralExpression[]; let moduleAugmentations: LiteralExpression[]; let ambientModules: string[]; @@ -1385,8 +1386,8 @@ namespace ts { for (const node of file.statements) { collectModuleReferences(node, /*inAmbientModule*/ false); - if (isJavaScriptFile) { - collectRequireCalls(node); + if ((file.flags & NodeFlags.PossiblyContainDynamicImport) || isJavaScriptFile) { + collectDynamicImportOrRequireCalls(node); } } @@ -1449,12 +1450,16 @@ namespace ts { } } - function collectRequireCalls(node: Node): void { + 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. + else if (isImportCall(node) && node.arguments.length === 1 && node.arguments[0].kind === SyntaxKind.StringLiteral) { + (imports || (imports = [])).push((node).arguments[0]); + } else { - forEachChild(node, collectRequireCalls); + forEachChild(node, collectDynamicImportOrRequireCalls); } } } diff --git a/src/compiler/transformer.ts b/src/compiler/transformer.ts index 75f9c43c6fe58..f0c827d83966d 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.ESNext: case ModuleKind.ES2015: return transformES2015Module; case ModuleKind.System: diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index b3e544a3f8b5a..b2e1c1c70a945 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; @@ -55,7 +56,7 @@ namespace ts { * @param node The SourceFile node. */ function transformSourceFile(node: SourceFile) { - if (node.isDeclarationFile || !(isExternalModule(node) || compilerOptions.isolatedModules)) { + if (node.isDeclarationFile || !(isExternalModule(node) || compilerOptions.isolatedModules || node.transformFlags & TransformFlags.ContainsDynamicImport)) { return node; } @@ -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; } @@ -488,10 +493,108 @@ 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, importCallExpressionVisitor, context); + } + } + + 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 (!(node.transformFlags & TransformFlags.ContainsDynamicImport)) { + return node; + } + + if (isImportCall(node)) { + return visitImportCallExpression(node); + } + else { + return visitEachChild(node, importCallExpressionVisitor, context); + } + } + + function visitImportCallExpression(node: ImportCall): Expression { + switch (compilerOptions.module) { + case ModuleKind.CommonJS: + return transformImportCallExpressionCommonJS(node); + case ModuleKind.AMD: + return transformImportCallExpressionAMD(node); + case ModuleKind.UMD: + return transformImportCallExpressionUMD(node); } + Debug.fail("All supported module kind in this transformation step should have been handled"); + } + + function transformImportCallExpressionUMD(node: ImportCall): Expression { + // (function (factory) { + // ... (regular UMD) + // } + // })(function (require, exports, useSyncRequire) { + // "use strict"; + // Object.defineProperty(exports, "__esModule", { value: true }); + // 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*/ + // }); + needUMDDynamicImportHelper = true; + return createConditional( + /*condition*/ createIdentifier("__syncRequire"), + /*whenTrue*/ transformImportCallExpressionCommonJS(node), + /*whenFalse*/ transformImportCallExpressionAMD(node) + ); + } + + function transformImportCallExpressionAMD(node: ImportCall): Expression { + // improt("./blah") + // emit as + // define(["require", "exports", "blah"], function (require, exports) { + // ... + // new Promise(function (_a, _b) { require([x], _a, _b); }); /*Amd Require*/ + // }); + const resolve = createUniqueName("resolve"); + const reject = createUniqueName("reject"); + return createNew( + createIdentifier("Promise"), + /*typeArguments*/ 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*/ reject)], + /*type*/ undefined, + createBlock([createStatement( + createCall( + createIdentifier("require"), + /*typeArguments*/ undefined, + [createArrayLiteral([firstOrUndefined(node.arguments) || createOmittedExpression()]), resolve, reject] + ))]) + )]); + } + + function transformImportCallExpressionCommonJS(node: ImportCall): Expression { + // import("./blah") + // emit as + // 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 + return createCall( + createPropertyAccess( + createCall(createPropertyAccess(createIdentifier("Promise"), "resolve"), /*typeArguments*/ undefined, /*argumentsArray*/ []), + "then"), + /*typeArguments*/ undefined, + [createFunctionExpression( + /*modifiers*/ undefined, + /*asteriskToken*/ undefined, + /*name*/ undefined, + /*typeParameters*/ undefined, + /*parameters*/ undefined, + /*type*/ undefined, + createBlock([createReturn(createCall(createIdentifier("require"), /*typeArguments*/ undefined, node.arguments))]) + )]); } /** @@ -786,9 +889,9 @@ namespace ts { node.asteriskToken, getDeclarationName(node, /*allowComments*/ true, /*allowSourceMaps*/ true), /*typeParameters*/ undefined, - node.parameters, + visitNodes(node.parameters, importCallExpressionVisitor), /*type*/ undefined, - node.body + visitEachChild(node.body, importCallExpressionVisitor, context) ), /*location*/ node ), @@ -797,7 +900,7 @@ namespace ts { ); } else { - statements = append(statements, node); + statements = append(statements, visitEachChild(node, importCallExpressionVisitor, context)); } if (hasAssociatedEndOfDeclarationMarker(node)) { @@ -828,7 +931,7 @@ namespace ts { visitNodes(node.modifiers, modifierVisitor, isModifier), getDeclarationName(node, /*allowComments*/ true, /*allowSourceMaps*/ true), /*typeParameters*/ undefined, - node.heritageClauses, + visitNodes(node.heritageClauses, importCallExpressionVisitor), node.members ), node @@ -838,7 +941,7 @@ namespace ts { ); } else { - statements = append(statements, node); + statements = append(statements, visitEachChild(node, importCallExpressionVisitor, context)); } if (hasAssociatedEndOfDeclarationMarker(node)) { @@ -890,7 +993,7 @@ namespace ts { } } else { - statements = append(statements, node); + statements = append(statements, visitEachChild(node, importCallExpressionVisitor, context)); } if (hasAssociatedEndOfDeclarationMarker(node)) { @@ -913,7 +1016,7 @@ namespace ts { function transformInitializedVariable(node: VariableDeclaration): Expression { if (isBindingPattern(node.name)) { return flattenDestructuringAssignment( - node, + visitNode(node, importCallExpressionVisitor), /*visitor*/ undefined, context, FlattenLevel.All, @@ -930,7 +1033,7 @@ namespace ts { ), /*location*/ node.name ), - node.initializer + visitNode(node.initializer, importCallExpressionVisitor) ); } } @@ -1497,4 +1600,12 @@ 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";` + }; } diff --git a/src/compiler/transformers/module/system.ts b/src/compiler/transformers/module/system.ts index e6351c0965ea1..fa126d1faa79f 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)) { + if (node.isDeclarationFile || !(isEffectiveExternalModule(node, compilerOptions) || node.transformFlags & TransformFlags.ContainsDynamicImport)) { return node; } @@ -646,7 +646,7 @@ namespace ts { return undefined; } - const expression = visitNode(node.expression, destructuringVisitor, isExpression); + const expression = visitNode(node.expression, destructuringAndImportCallVisitor, isExpression); const original = node.original; if (original && hasAssociatedEndOfDeclarationMarker(original)) { // Defer exports until we encounter an EndOfDeclarationMarker node @@ -673,12 +673,12 @@ namespace ts { node.asteriskToken, getDeclarationName(node, /*allowComments*/ true, /*allowSourceMaps*/ true), /*typeParameters*/ undefined, - visitNodes(node.parameters, destructuringVisitor, isParameterDeclaration), + visitNodes(node.parameters, destructuringAndImportCallVisitor, isParameterDeclaration), /*type*/ undefined, - visitNode(node.body, destructuringVisitor, isBlock))); + visitNode(node.body, destructuringAndImportCallVisitor, isBlock))); } else { - hoistedStatements = append(hoistedStatements, node); + hoistedStatements = append(hoistedStatements, visitEachChild(node, destructuringAndImportCallVisitor, context)); } if (hasAssociatedEndOfDeclarationMarker(node)) { @@ -716,8 +716,8 @@ namespace ts { /*modifiers*/ undefined, node.name, /*typeParameters*/ undefined, - visitNodes(node.heritageClauses, destructuringVisitor, isHeritageClause), - visitNodes(node.members, destructuringVisitor, isClassElement) + visitNodes(node.heritageClauses, destructuringAndImportCallVisitor, isHeritageClause), + visitNodes(node.members, destructuringAndImportCallVisitor, isClassElement) ), node ) @@ -747,7 +747,7 @@ namespace ts { */ function visitVariableStatement(node: VariableStatement): VisitResult { if (!shouldHoistVariableDeclarationList(node.declarationList)) { - return visitNode(node, destructuringVisitor, isStatement); + return visitNode(node, destructuringAndImportCallVisitor, isStatement); } let expressions: Expression[]; @@ -820,13 +820,13 @@ namespace ts { return isBindingPattern(node.name) ? flattenDestructuringAssignment( node, - destructuringVisitor, + destructuringAndImportCallVisitor, context, FlattenLevel.All, /*needsValue*/ false, createAssignment ) - : createAssignment(node.name, visitNode(node.initializer, destructuringVisitor, isExpression)); + : createAssignment(node.name, visitNode(node.initializer, destructuringAndImportCallVisitor, isExpression)); } /** @@ -1204,7 +1204,7 @@ namespace ts { return visitEndOfDeclarationMarker(node); default: - return destructuringVisitor(node); + return destructuringAndImportCallVisitor(node); } } @@ -1220,8 +1220,8 @@ namespace ts { node = updateFor( node, visitForInitializer(node.initializer), - visitNode(node.condition, destructuringVisitor, isExpression), - visitNode(node.incrementor, destructuringVisitor, isExpression), + visitNode(node.condition, destructuringAndImportCallVisitor, isExpression), + visitNode(node.incrementor, destructuringAndImportCallVisitor, isExpression), visitNode(node.statement, nestedElementVisitor, isStatement) ); @@ -1241,7 +1241,7 @@ namespace ts { node = updateForIn( node, visitForInitializer(node.initializer), - visitNode(node.expression, destructuringVisitor, isExpression), + visitNode(node.expression, destructuringAndImportCallVisitor, isExpression), visitNode(node.statement, nestedElementVisitor, isStatement, liftToBlock) ); @@ -1262,7 +1262,7 @@ namespace ts { node, node.awaitModifier, visitForInitializer(node.initializer), - visitNode(node.expression, destructuringVisitor, isExpression), + visitNode(node.expression, destructuringAndImportCallVisitor, isExpression), visitNode(node.statement, nestedElementVisitor, isStatement, liftToBlock) ); @@ -1313,7 +1313,7 @@ namespace ts { return updateDo( node, visitNode(node.statement, nestedElementVisitor, isStatement, liftToBlock), - visitNode(node.expression, destructuringVisitor, isExpression) + visitNode(node.expression, destructuringAndImportCallVisitor, isExpression) ); } @@ -1325,7 +1325,7 @@ namespace ts { function visitWhileStatement(node: WhileStatement): VisitResult { return updateWhile( node, - visitNode(node.expression, destructuringVisitor, isExpression), + visitNode(node.expression, destructuringAndImportCallVisitor, isExpression), visitNode(node.statement, nestedElementVisitor, isStatement, liftToBlock) ); } @@ -1351,7 +1351,7 @@ namespace ts { function visitWithStatement(node: WithStatement): VisitResult { return updateWith( node, - visitNode(node.expression, destructuringVisitor, isExpression), + visitNode(node.expression, destructuringAndImportCallVisitor, isExpression), visitNode(node.statement, nestedElementVisitor, isStatement, liftToBlock) ); } @@ -1364,7 +1364,7 @@ namespace ts { function visitSwitchStatement(node: SwitchStatement): VisitResult { return updateSwitch( node, - visitNode(node.expression, destructuringVisitor, isExpression), + visitNode(node.expression, destructuringAndImportCallVisitor, isExpression), visitNode(node.caseBlock, nestedElementVisitor, isCaseBlock) ); } @@ -1395,7 +1395,7 @@ namespace ts { function visitCaseClause(node: CaseClause): VisitResult { return updateCaseClause( node, - visitNode(node.expression, destructuringVisitor, isExpression), + visitNode(node.expression, destructuringAndImportCallVisitor, isExpression), visitNodes(node.statements, nestedElementVisitor, isStatement) ); } @@ -1461,19 +1461,43 @@ namespace ts { * * @param node The node to visit. */ - function destructuringVisitor(node: Node): VisitResult { + function destructuringAndImportCallVisitor(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 if (isImportCall(node)) { + return visitImportCallExpression(node); + } + else if ((node.transformFlags & TransformFlags.ContainsDestructuringAssignment) || (node.transformFlags & TransformFlags.ContainsDynamicImport)) { + return visitEachChild(node, destructuringAndImportCallVisitor, context); } else { return node; } } + function visitImportCallExpression(node: ImportCall): 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.arguments + ); + } + /** * Visits a DestructuringAssignment to flatten destructuring to exported symbols. * @@ -1483,14 +1507,14 @@ namespace ts { if (hasExportedReferenceInDestructuringTarget(node.left)) { return flattenDestructuringAssignment( node, - destructuringVisitor, + destructuringAndImportCallVisitor, context, FlattenLevel.All, /*needsValue*/ true ); } - return visitEachChild(node, destructuringVisitor, context); + return visitEachChild(node, destructuringAndImportCallVisitor, context); } /** diff --git a/src/compiler/types.ts b/src/compiler/types.ts index ed1d5dcbe2313..8fb3d98fca859 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -395,6 +395,7 @@ namespace ts { // Enum value count Count, + // Markers FirstAssignment = EqualsToken, LastAssignment = CaretEqualsToken, @@ -449,6 +450,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, @@ -1001,8 +1010,10 @@ namespace ts { _unaryExpressionBrand: any; } - export interface IncrementExpression extends UnaryExpression { - _incrementExpressionBrand: any; + /** Deprecated, please use UpdateExpression */ + export type IncrementExpression = UpdateExpression; + export interface UpdateExpression extends UnaryExpression { + _updateExpressionBrand: any; } // see: https://tc39.github.io/ecma262/#prod-UpdateExpression @@ -1013,10 +1024,9 @@ namespace ts { | SyntaxKind.PlusToken | SyntaxKind.MinusToken | SyntaxKind.TildeToken - | SyntaxKind.ExclamationToken - ; + | SyntaxKind.ExclamationToken; - export interface PrefixUnaryExpression extends IncrementExpression { + export interface PrefixUnaryExpression extends UpdateExpression { kind: SyntaxKind.PrefixUnaryExpression; operator: PrefixUnaryOperator; operand: UnaryExpression; @@ -1028,13 +1038,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; } @@ -1062,6 +1072,10 @@ namespace ts { kind: SyntaxKind.SuperKeyword; } + export interface ImportExpression extends PrimaryExpression { + kind: SyntaxKind.ImportKeyword; + } + export interface DeleteExpression extends UnaryExpression { kind: SyntaxKind.DeleteExpression; expression: UnaryExpression; @@ -1454,10 +1468,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; @@ -1471,6 +1482,10 @@ namespace ts { expression: SuperExpression; } + export interface ImportCall extends CallExpression { + expression: ImportExpression; + } + export interface ExpressionWithTypeArguments extends TypeNode { kind: SyntaxKind.ExpressionWithTypeArguments; parent?: HeritageClause; @@ -3564,6 +3579,7 @@ namespace ts { UMD = 3, System = 4, ES2015 = 5, + ESNext = 6 } export const enum JsxEmit { @@ -3948,6 +3964,11 @@ namespace ts { ContainsYield = 1 << 24, ContainsHoistedDeclarationOrCompletion = 1 << 25, + ContainsDynamicImport = 1 << 26, + + // 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 diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index b52ace7861548..96aae0e3888c6 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -596,6 +596,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.CallExpression && (n).expression.kind === SyntaxKind.ImportKeyword; + } + export function isPrologueDirective(node: Node): node is PrologueDirective { return node.kind === SyntaxKind.ExpressionStatement && (node).expression.kind === SyntaxKind.StringLiteral; diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 49dbdbf2102e2..9bf4591112d6c 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -857,6 +857,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/src/harness/unittests/commandLineParsing.ts b/src/harness/unittests/commandLineParsing.ts index 19ccc919d4c09..01a208aa330fd 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', '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 3aa1a4c9b8e6a..798f8c6a76bb8 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', '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/src/services/services.ts b/src/services/services.ts index 05fe59084b4af..21c756a9acc3a 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -368,7 +368,7 @@ namespace ts { _primaryExpressionBrand: any; _memberExpressionBrand: any; _leftHandSideExpressionBrand: any; - _incrementExpressionBrand: any; + _updateExpressionBrand: any; _unaryExpressionBrand: any; _expressionBrand: any; /*@internal*/typeArguments: NodeArray; @@ -521,6 +521,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); diff --git a/tests/baselines/reference/importCallExpression1ESNext.js b/tests/baselines/reference/importCallExpression1ESNext.js new file mode 100644 index 0000000000000..39b779c921ff5 --- /dev/null +++ b/tests/baselines/reference/importCallExpression1ESNext.js @@ -0,0 +1,27 @@ +//// [tests/cases/conformance/dynamicImport/importCallExpression1ESNext.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/importCallExpression1ESNext.symbols b/tests/baselines/reference/importCallExpression1ESNext.symbols new file mode 100644 index 0000000000000..28b5ba13e997c --- /dev/null +++ b/tests/baselines/reference/importCallExpression1ESNext.symbols @@ -0,0 +1,28 @@ +=== tests/cases/conformance/dynamicImport/0.ts === +export function foo() { return "foo"; } +>foo : Symbol(foo, Decl(0.ts, 0, 0)) + +=== tests/cases/conformance/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/importCallExpression1ESNext.types b/tests/baselines/reference/importCallExpression1ESNext.types new file mode 100644 index 0000000000000..53a1b3d08fa22 --- /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/importCallExpression2ESNext.js b/tests/baselines/reference/importCallExpression2ESNext.js new file mode 100644 index 0000000000000..662f57f07ff5f --- /dev/null +++ b/tests/baselines/reference/importCallExpression2ESNext.js @@ -0,0 +1,29 @@ +//// [tests/cases/conformance/dynamicImport/importCallExpression2ESNext.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/importCallExpression2ESNext.symbols b/tests/baselines/reference/importCallExpression2ESNext.symbols new file mode 100644 index 0000000000000..2002398aeb93d --- /dev/null +++ b/tests/baselines/reference/importCallExpression2ESNext.symbols @@ -0,0 +1,33 @@ +=== tests/cases/conformance/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/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/importCallExpression2ESNext.types b/tests/baselines/reference/importCallExpression2ESNext.types new file mode 100644 index 0000000000000..084eb33dde95d --- /dev/null +++ b/tests/baselines/reference/importCallExpression2ESNext.types @@ -0,0 +1,45 @@ +=== tests/cases/conformance/dynamicImport/0.ts === +export class B { +>B : B + + print() { return "I am B"} +>print : () => string +>"I am B" : "I am B" +} + +=== tests/cases/conformance/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/importCallExpression3ESNext.js b/tests/baselines/reference/importCallExpression3ESNext.js new file mode 100644 index 0000000000000..0cd41388616b9 --- /dev/null +++ b/tests/baselines/reference/importCallExpression3ESNext.js @@ -0,0 +1,27 @@ +//// [tests/cases/conformance/dynamicImport/importCallExpression3ESNext.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/importCallExpression3ESNext.symbols b/tests/baselines/reference/importCallExpression3ESNext.symbols new file mode 100644 index 0000000000000..5ca85d6e6939d --- /dev/null +++ b/tests/baselines/reference/importCallExpression3ESNext.symbols @@ -0,0 +1,29 @@ +=== tests/cases/conformance/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/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/importCallExpression3ESNext.types b/tests/baselines/reference/importCallExpression3ESNext.types new file mode 100644 index 0000000000000..e517be6e722f4 --- /dev/null +++ b/tests/baselines/reference/importCallExpression3ESNext.types @@ -0,0 +1,37 @@ +=== tests/cases/conformance/dynamicImport/0.ts === +export class B { +>B : B + + print() { return "I am B"} +>print : () => string +>"I am B" : "I am B" +} + +=== 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/dynamicImport/0" +>await import("./0") : typeof "tests/cases/conformance/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/importCallExpression4ESNext.js b/tests/baselines/reference/importCallExpression4ESNext.js new file mode 100644 index 0000000000000..e148d5c1e515d --- /dev/null +++ b/tests/baselines/reference/importCallExpression4ESNext.js @@ -0,0 +1,49 @@ +//// [tests/cases/conformance/dynamicImport/importCallExpression4ESNext.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/importCallExpression4ESNext.symbols b/tests/baselines/reference/importCallExpression4ESNext.symbols new file mode 100644 index 0000000000000..34a1dcf4d7bdf --- /dev/null +++ b/tests/baselines/reference/importCallExpression4ESNext.symbols @@ -0,0 +1,61 @@ +=== tests/cases/conformance/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/dynamicImport/1.ts === +export function backup() { return "backup"; } +>backup : Symbol(backup, Decl(1.ts, 0, 0)) + +=== tests/cases/conformance/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/importCallExpression4ESNext.types b/tests/baselines/reference/importCallExpression4ESNext.types new file mode 100644 index 0000000000000..2ea666ba672aa --- /dev/null +++ b/tests/baselines/reference/importCallExpression4ESNext.types @@ -0,0 +1,83 @@ +=== tests/cases/conformance/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/dynamicImport/1.ts === +export function backup() { return "backup"; } +>backup : () => string +>"backup" : "backup" + +=== tests/cases/conformance/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/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>this.myModule : Promise +>this : this +>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 +>console.log : any +>console : any +>log : any +>Zero.foo() : string +>Zero.foo : () => string +>Zero : typeof "tests/cases/conformance/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/dynamicImport/1" +>await import("./1") : typeof "tests/cases/conformance/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/dynamicImport/1" +>backup : () => string + + }); + } +} diff --git a/tests/baselines/reference/importCallExpression5ESNext.errors.txt b/tests/baselines/reference/importCallExpression5ESNext.errors.txt new file mode 100644 index 0000000000000..ed5900c2a0395 --- /dev/null +++ b/tests/baselines/reference/importCallExpression5ESNext.errors.txt @@ -0,0 +1,31 @@ +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/dynamicImport/0.ts (0 errors) ==== + export class B { + print() { return "I am B"} + } + + export function foo() { return "foo" } + +==== tests/cases/conformance/dynamicImport/1.ts (0 errors) ==== + export function backup() { return "backup"; } + +==== tests/cases/conformance/dynamicImport/2.ts (4 errors) ==== + declare function bar(): boolean; + const specify = bar() ? "./0" : undefined; + let myModule = import(specify); + ~~~~~~~ +!!! error TS7036: Dynamic import's specifier must be of type 'string', but here has type '"./0" | undefined'. + let myModule1 = import(undefined); + ~~~~~~~~~ +!!! error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'undefined'. + let myModule2 = import(bar() ? "./1" : null); + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS7036: Dynamic import's specifier must be of type 'string', but here has type '"./1" | null'. + let myModule3 = import(null); + ~~~~ +!!! error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'null'. \ No newline at end of file diff --git a/tests/baselines/reference/importCallExpression5ESNext.js b/tests/baselines/reference/importCallExpression5ESNext.js new file mode 100644 index 0000000000000..1f4c789120b8a --- /dev/null +++ b/tests/baselines/reference/importCallExpression5ESNext.js @@ -0,0 +1,33 @@ +//// [tests/cases/conformance/dynamicImport/importCallExpression5ESNext.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/importCallExpression6ESNext.errors.txt b/tests/baselines/reference/importCallExpression6ESNext.errors.txt new file mode 100644 index 0000000000000..1703e0913d128 --- /dev/null +++ b/tests/baselines/reference/importCallExpression6ESNext.errors.txt @@ -0,0 +1,25 @@ +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/dynamicImport/0.ts (0 errors) ==== + export class B { + print() { return "I am B"} + } + + export function foo() { return "foo" } + +==== tests/cases/conformance/dynamicImport/1.ts (0 errors) ==== + export function backup() { return "backup"; } + +==== tests/cases/conformance/dynamicImport/2.ts (2 errors) ==== + declare function bar(): boolean; + const specify = bar() ? "./0" : undefined; + let myModule = import(specify); + let myModule1 = import(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 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/importCallExpression6ESNext.js b/tests/baselines/reference/importCallExpression6ESNext.js new file mode 100644 index 0000000000000..bdac7328f69ff --- /dev/null +++ b/tests/baselines/reference/importCallExpression6ESNext.js @@ -0,0 +1,33 @@ +//// [tests/cases/conformance/dynamicImport/importCallExpression6ESNext.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/importCallExpressionCheckReturntype1.errors.txt b/tests/baselines/reference/importCallExpressionCheckReturntype1.errors.txt new file mode 100644 index 0000000000000..39622f39b3f26 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionCheckReturntype1.errors.txt @@ -0,0 +1,30 @@ +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/dynamicImport/anotherModule.ts (0 errors) ==== + export class D{} + +==== tests/cases/conformance/dynamicImport/defaultPath.ts (0 errors) ==== + export class C {} + +==== 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/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/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 new file mode 100644 index 0000000000000..facb691338851 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionCheckReturntype1.js @@ -0,0 +1,35 @@ +//// [tests/cases/conformance/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(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 new file mode 100644 index 0000000000000..07f95d3b3b244 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionDeclarationEmit1.js @@ -0,0 +1,35 @@ +//// [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] +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 Promise.resolve().then(function () { return 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 0000000000000..d2266cc768b62 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionDeclarationEmit1.symbols @@ -0,0 +1,36 @@ +=== tests/cases/conformance/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, 1, 11)) + +declare const directory: string; +>directory : Symbol(directory, Decl(importCallExpressionDeclarationEmit1.ts, 2, 13)) + +declare const moduleFile: number; +>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, 7, 3)) +>directory : Symbol(directory, Decl(importCallExpressionDeclarationEmit1.ts, 2, 13)) + +var p1 = import(getSpecifier()); +>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, 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, 9, 61)) +>path : Symbol(path, Decl(importCallExpressionDeclarationEmit1.ts, 11, 27)) + + return import(path); +>path : Symbol(path, Decl(importCallExpressionDeclarationEmit1.ts, 11, 27)) +} diff --git a/tests/baselines/reference/importCallExpressionDeclarationEmit1.types b/tests/baselines/reference/importCallExpressionDeclarationEmit1.types new file mode 100644 index 0000000000000..db5400818c874 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionDeclarationEmit1.types @@ -0,0 +1,47 @@ +=== tests/cases/conformance/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 0000000000000..6c394c98bdfa1 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionDeclarationEmit2.errors.txt @@ -0,0 +1,10 @@ +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/dynamicImport/0.ts (0 errors) ==== + export function foo() { return "foo"; } + +==== 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/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 new file mode 100644 index 0000000000000..7659e94ee810b --- /dev/null +++ b/tests/baselines/reference/importCallExpressionDeclarationEmit2.js @@ -0,0 +1,16 @@ +//// [tests/cases/conformance/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 0000000000000..d38c2309a3308 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionDeclarationEmit3.js @@ -0,0 +1,31 @@ +//// [tests/cases/conformance/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 0000000000000..1491e05db55b8 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionDeclarationEmit3.symbols @@ -0,0 +1,28 @@ +=== tests/cases/conformance/dynamicImport/0.ts === +export function foo() { return "foo"; } +>foo : Symbol(foo, Decl(0.ts, 0, 0)) + +=== tests/cases/conformance/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 0000000000000..fe4552b708fdd --- /dev/null +++ b/tests/baselines/reference/importCallExpressionDeclarationEmit3.types @@ -0,0 +1,37 @@ +=== tests/cases/conformance/dynamicImport/0.ts === +export function foo() { return "foo"; } +>foo : () => string +>"foo" : "foo" + +=== tests/cases/conformance/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/importCallExpressionES5AMD.js b/tests/baselines/reference/importCallExpressionES5AMD.js new file mode 100644 index 0000000000000..cce61a5a3f96c --- /dev/null +++ b/tests/baselines/reference/importCallExpressionES5AMD.js @@ -0,0 +1,35 @@ +//// [tests/cases/conformance/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 (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 (resolve_3, reject_3) { require(["./0"], resolve_3, reject_3); }); + } +}); diff --git a/tests/baselines/reference/importCallExpressionES5AMD.symbols b/tests/baselines/reference/importCallExpressionES5AMD.symbols new file mode 100644 index 0000000000000..333251da662fd --- /dev/null +++ b/tests/baselines/reference/importCallExpressionES5AMD.symbols @@ -0,0 +1,28 @@ +=== tests/cases/conformance/dynamicImport/0.ts === +export function foo() { return "foo"; } +>foo : Symbol(foo, Decl(0.ts, 0, 0)) + +=== tests/cases/conformance/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 0000000000000..59da055ee0161 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionES5AMD.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/importCallExpressionES5CJS.js b/tests/baselines/reference/importCallExpressionES5CJS.js new file mode 100644 index 0000000000000..11d1bf4631938 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionES5CJS.js @@ -0,0 +1,30 @@ +//// [tests/cases/conformance/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] +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 = Promise.resolve().then(function () { return require("./0"); }); +} diff --git a/tests/baselines/reference/importCallExpressionES5CJS.symbols b/tests/baselines/reference/importCallExpressionES5CJS.symbols new file mode 100644 index 0000000000000..333251da662fd --- /dev/null +++ b/tests/baselines/reference/importCallExpressionES5CJS.symbols @@ -0,0 +1,28 @@ +=== tests/cases/conformance/dynamicImport/0.ts === +export function foo() { return "foo"; } +>foo : Symbol(foo, Decl(0.ts, 0, 0)) + +=== tests/cases/conformance/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 0000000000000..59da055ee0161 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionES5CJS.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/importCallExpressionES5System.js b/tests/baselines/reference/importCallExpressionES5System.js new file mode 100644 index 0000000000000..1842fc6e60ae1 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionES5System.js @@ -0,0 +1,46 @@ +//// [tests/cases/conformance/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 0000000000000..333251da662fd --- /dev/null +++ b/tests/baselines/reference/importCallExpressionES5System.symbols @@ -0,0 +1,28 @@ +=== tests/cases/conformance/dynamicImport/0.ts === +export function foo() { return "foo"; } +>foo : Symbol(foo, Decl(0.ts, 0, 0)) + +=== tests/cases/conformance/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 0000000000000..59da055ee0161 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionES5System.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/importCallExpressionES5UMD.js b/tests/baselines/reference/importCallExpressionES5UMD.js new file mode 100644 index 0000000000000..dfe6813839c22 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionES5UMD.js @@ -0,0 +1,52 @@ +//// [tests/cases/conformance/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"; + __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 ? 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/importCallExpressionES5UMD.symbols b/tests/baselines/reference/importCallExpressionES5UMD.symbols new file mode 100644 index 0000000000000..333251da662fd --- /dev/null +++ b/tests/baselines/reference/importCallExpressionES5UMD.symbols @@ -0,0 +1,28 @@ +=== tests/cases/conformance/dynamicImport/0.ts === +export function foo() { return "foo"; } +>foo : Symbol(foo, Decl(0.ts, 0, 0)) + +=== tests/cases/conformance/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 0000000000000..59da055ee0161 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionES5UMD.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/importCallExpressionErrorInES2015.errors.txt b/tests/baselines/reference/importCallExpressionErrorInES2015.errors.txt new file mode 100644 index 0000000000000..d47980d1312c7 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionErrorInES2015.errors.txt @@ -0,0 +1,24 @@ +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/dynamicImport/0.ts (0 errors) ==== + export function foo() { return "foo"; } + +==== tests/cases/conformance/dynamicImport/1.ts (3 errors) ==== + import("./0"); + ~~~~~~~~~~~~~ +!!! error TS1323: Dynamic import cannot be used when targeting ECMAScript 2015 modules. + var p1 = import("./0"); + ~~~~~~~~~~~~~ +!!! error TS1323: Dynamic import cannot be used when targeting ECMAScript 2015 modules. + p1.then(zero => { + return zero.foo(); + }) + + function foo() { + const p2 = import("./0"); + ~~~~~~~~~~~~~ +!!! error TS1323: 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 0000000000000..f07486504eebe --- /dev/null +++ b/tests/baselines/reference/importCallExpressionErrorInES2015.js @@ -0,0 +1,27 @@ +//// [tests/cases/conformance/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 0000000000000..6d64808e1112e --- /dev/null +++ b/tests/baselines/reference/importCallExpressionGrammarError.errors.txt @@ -0,0 +1,34 @@ +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/dynamicImport/importCallExpressionGrammarError.ts (7 errors) ==== + declare function getSpecifier(): string; + declare var whatToLoad: boolean; + + var a = ["./0"]; + import(...["PathModule"]); + ~~~~~~~~~~~~~~~~~ +!!! error TS1325: Specifier of dynamic import cannot be spread element. + + var p1 = import(...a); + ~~~~ +!!! error TS1325: Specifier of dynamic import cannot be spread element. + const p2 = import(); + ~~~~~~~~ +!!! error TS1324: Dynamic import must have one specifier as an argument. + 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. + ~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'pathToModule'. \ 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 0000000000000..b30b0c9ddd550 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionGrammarError.js @@ -0,0 +1,19 @@ +//// [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] +var a = ["./0"]; +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 new file mode 100644 index 0000000000000..e175817364635 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInAMD1.js @@ -0,0 +1,35 @@ +//// [tests/cases/conformance/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(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 (resolve_3, reject_3) { require(["./0"], resolve_3, reject_3); }); + } +}); diff --git a/tests/baselines/reference/importCallExpressionInAMD1.symbols b/tests/baselines/reference/importCallExpressionInAMD1.symbols new file mode 100644 index 0000000000000..333251da662fd --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInAMD1.symbols @@ -0,0 +1,28 @@ +=== tests/cases/conformance/dynamicImport/0.ts === +export function foo() { return "foo"; } +>foo : Symbol(foo, Decl(0.ts, 0, 0)) + +=== tests/cases/conformance/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 0000000000000..59da055ee0161 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInAMD1.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/importCallExpressionInAMD2.js b/tests/baselines/reference/importCallExpressionInAMD2.js new file mode 100644 index 0000000000000..7347e2f810562 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInAMD2.js @@ -0,0 +1,39 @@ +//// [tests/cases/conformance/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(function (resolve_1, reject_1) { require(["./0"], resolve_1, reject_1); })); +}); diff --git a/tests/baselines/reference/importCallExpressionInAMD2.symbols b/tests/baselines/reference/importCallExpressionInAMD2.symbols new file mode 100644 index 0000000000000..16fc79c774fb4 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInAMD2.symbols @@ -0,0 +1,34 @@ +=== tests/cases/conformance/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/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 0000000000000..44b17eb51fd5c --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInAMD2.types @@ -0,0 +1,46 @@ +=== tests/cases/conformance/dynamicImport/0.ts === +export class B { +>B : B + + print() { return "I am B"} +>print : () => string +>"I am B" : "I am B" +} + +=== 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 +>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/importCallExpressionInAMD3.js b/tests/baselines/reference/importCallExpressionInAMD3.js new file mode 100644 index 0000000000000..471f35a6415ae --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInAMD3.js @@ -0,0 +1,35 @@ +//// [tests/cases/conformance/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(function (resolve_1, reject_1) { require(["./0"], resolve_1, reject_1); })).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 0000000000000..5ca85d6e6939d --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInAMD3.symbols @@ -0,0 +1,29 @@ +=== tests/cases/conformance/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/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 0000000000000..e517be6e722f4 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInAMD3.types @@ -0,0 +1,37 @@ +=== tests/cases/conformance/dynamicImport/0.ts === +export class B { +>B : B + + print() { return "I am B"} +>print : () => string +>"I am B" : "I am B" +} + +=== 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/dynamicImport/0" +>await import("./0") : typeof "tests/cases/conformance/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/importCallExpressionInAMD4.js b/tests/baselines/reference/importCallExpressionInAMD4.js new file mode 100644 index 0000000000000..6e50e139116d3 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInAMD4.js @@ -0,0 +1,63 @@ +//// [tests/cases/conformance/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(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 (resolve_2, reject_2) { require(["./1"], resolve_2, reject_2); }); + console.log(one.backup()); + }); + } + } +}); diff --git a/tests/baselines/reference/importCallExpressionInAMD4.symbols b/tests/baselines/reference/importCallExpressionInAMD4.symbols new file mode 100644 index 0000000000000..34a1dcf4d7bdf --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInAMD4.symbols @@ -0,0 +1,61 @@ +=== tests/cases/conformance/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/dynamicImport/1.ts === +export function backup() { return "backup"; } +>backup : Symbol(backup, Decl(1.ts, 0, 0)) + +=== tests/cases/conformance/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 0000000000000..2ea666ba672aa --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInAMD4.types @@ -0,0 +1,83 @@ +=== tests/cases/conformance/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/dynamicImport/1.ts === +export function backup() { return "backup"; } +>backup : () => string +>"backup" : "backup" + +=== tests/cases/conformance/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/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>this.myModule : Promise +>this : this +>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 +>console.log : any +>console : any +>log : any +>Zero.foo() : string +>Zero.foo : () => string +>Zero : typeof "tests/cases/conformance/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/dynamicImport/1" +>await import("./1") : typeof "tests/cases/conformance/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/dynamicImport/1" +>backup : () => string + + }); + } +} diff --git a/tests/baselines/reference/importCallExpressionInCJS1.js b/tests/baselines/reference/importCallExpressionInCJS1.js new file mode 100644 index 0000000000000..3fb298b5bdef5 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInCJS1.js @@ -0,0 +1,30 @@ +//// [tests/cases/conformance/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] +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 = Promise.resolve().then(function () { return require("./0"); }); +} diff --git a/tests/baselines/reference/importCallExpressionInCJS1.symbols b/tests/baselines/reference/importCallExpressionInCJS1.symbols new file mode 100644 index 0000000000000..333251da662fd --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInCJS1.symbols @@ -0,0 +1,28 @@ +=== tests/cases/conformance/dynamicImport/0.ts === +export function foo() { return "foo"; } +>foo : Symbol(foo, Decl(0.ts, 0, 0)) + +=== tests/cases/conformance/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 0000000000000..59da055ee0161 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInCJS1.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/importCallExpressionInCJS2.js b/tests/baselines/reference/importCallExpressionInCJS2.js new file mode 100644 index 0000000000000..aa983a7a2fece --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInCJS2.js @@ -0,0 +1,40 @@ +//// [tests/cases/conformance/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] +async function compute(promise) { + let j = await promise; + if (!j) { + j = await Promise.resolve().then(function () { return require("./1"); }); + return j.backup(); + } + return j.foo(); +} +compute(Promise.resolve().then(function () { return require("./0"); })); diff --git a/tests/baselines/reference/importCallExpressionInCJS2.symbols b/tests/baselines/reference/importCallExpressionInCJS2.symbols new file mode 100644 index 0000000000000..24f7a5cdb4850 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInCJS2.symbols @@ -0,0 +1,34 @@ +=== tests/cases/conformance/dynamicImport/0.ts === +export function foo() { return "foo"; } +>foo : Symbol(foo, Decl(0.ts, 0, 0)) + +=== tests/cases/conformance/dynamicImport/1.ts === +export function backup() { return "backup"; } +>backup : Symbol(backup, Decl(1.ts, 0, 0)) + +=== 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)) +>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 0000000000000..063a52245395d --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInCJS2.types @@ -0,0 +1,51 @@ +=== tests/cases/conformance/dynamicImport/0.ts === +export function foo() { return "foo"; } +>foo : () => string +>"foo" : "foo" + +=== tests/cases/conformance/dynamicImport/1.ts === +export function backup() { return "backup"; } +>backup : () => string +>"backup" : "backup" + +=== tests/cases/conformance/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/dynamicImport/1" +>j : any +>await import("./1") : typeof "tests/cases/conformance/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 0000000000000..2f956d9ac3aea --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInCJS3.js @@ -0,0 +1,34 @@ +//// [tests/cases/conformance/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] +// 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(function () { return require("./0"); })); diff --git a/tests/baselines/reference/importCallExpressionInCJS3.symbols b/tests/baselines/reference/importCallExpressionInCJS3.symbols new file mode 100644 index 0000000000000..16fc79c774fb4 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInCJS3.symbols @@ -0,0 +1,34 @@ +=== tests/cases/conformance/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/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 0000000000000..44b17eb51fd5c --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInCJS3.types @@ -0,0 +1,46 @@ +=== tests/cases/conformance/dynamicImport/0.ts === +export class B { +>B : B + + print() { return "I am B"} +>print : () => string +>"I am B" : "I am B" +} + +=== 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 +>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/importCallExpressionInCJS4.js b/tests/baselines/reference/importCallExpressionInCJS4.js new file mode 100644 index 0000000000000..554a0b222abca --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInCJS4.js @@ -0,0 +1,30 @@ +//// [tests/cases/conformance/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(function () { return 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 0000000000000..5ca85d6e6939d --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInCJS4.symbols @@ -0,0 +1,29 @@ +=== tests/cases/conformance/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/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 0000000000000..e517be6e722f4 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInCJS4.types @@ -0,0 +1,37 @@ +=== tests/cases/conformance/dynamicImport/0.ts === +export class B { +>B : B + + print() { return "I am B"} +>print : () => string +>"I am B" : "I am B" +} + +=== 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/dynamicImport/0" +>await import("./0") : typeof "tests/cases/conformance/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/importCallExpressionInCJS5.js b/tests/baselines/reference/importCallExpressionInCJS5.js new file mode 100644 index 0000000000000..762da59282784 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInCJS5.js @@ -0,0 +1,56 @@ +//// [tests/cases/conformance/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] +class C { + constructor() { + 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 Promise.resolve().then(function () { return 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 0000000000000..34a1dcf4d7bdf --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInCJS5.symbols @@ -0,0 +1,61 @@ +=== tests/cases/conformance/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/dynamicImport/1.ts === +export function backup() { return "backup"; } +>backup : Symbol(backup, Decl(1.ts, 0, 0)) + +=== tests/cases/conformance/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 0000000000000..2ea666ba672aa --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInCJS5.types @@ -0,0 +1,83 @@ +=== tests/cases/conformance/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/dynamicImport/1.ts === +export function backup() { return "backup"; } +>backup : () => string +>"backup" : "backup" + +=== tests/cases/conformance/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/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>this.myModule : Promise +>this : this +>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 +>console.log : any +>console : any +>log : any +>Zero.foo() : string +>Zero.foo : () => string +>Zero : typeof "tests/cases/conformance/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/dynamicImport/1" +>await import("./1") : typeof "tests/cases/conformance/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/dynamicImport/1" +>backup : () => string + + }); + } +} diff --git a/tests/baselines/reference/importCallExpressionInScriptContext1.js b/tests/baselines/reference/importCallExpressionInScriptContext1.js new file mode 100644 index 0000000000000..2c2d2f904d50c --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInScriptContext1.js @@ -0,0 +1,17 @@ +//// [tests/cases/conformance/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(function () { return 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 0000000000000..513612056a833 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInScriptContext1.symbols @@ -0,0 +1,11 @@ +=== tests/cases/conformance/dynamicImport/0.ts === +export function foo() { return "foo"; } +>foo : Symbol(foo, Decl(0.ts, 0, 0)) + +=== tests/cases/conformance/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 0000000000000..c318667c7d86a --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInScriptContext1.types @@ -0,0 +1,14 @@ +=== tests/cases/conformance/dynamicImport/0.ts === +export function foo() { return "foo"; } +>foo : () => string +>"foo" : "foo" + +=== tests/cases/conformance/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/importCallExpressionInScriptContext2.errors.txt b/tests/baselines/reference/importCallExpressionInScriptContext2.errors.txt new file mode 100644 index 0000000000000..9020963f68f85 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInScriptContext2.errors.txt @@ -0,0 +1,12 @@ +tests/cases/conformance/dynamicImport/1.ts(3,10): error TS1100: Invalid use of 'arguments' in strict mode. + + +==== tests/cases/conformance/dynamicImport/0.ts (0 errors) ==== + export function foo() { return "foo"; } + +==== tests/cases/conformance/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 0000000000000..6b6e0109fdad3 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInScriptContext2.js @@ -0,0 +1,19 @@ +//// [tests/cases/conformance/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(function () { return require("./0"); }); +function arguments() { } diff --git a/tests/baselines/reference/importCallExpressionInSystem1.js b/tests/baselines/reference/importCallExpressionInSystem1.js new file mode 100644 index 0000000000000..d74eb6ffc7633 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInSystem1.js @@ -0,0 +1,46 @@ +//// [tests/cases/conformance/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) { + 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 0000000000000..333251da662fd --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInSystem1.symbols @@ -0,0 +1,28 @@ +=== tests/cases/conformance/dynamicImport/0.ts === +export function foo() { return "foo"; } +>foo : Symbol(foo, Decl(0.ts, 0, 0)) + +=== tests/cases/conformance/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 0000000000000..59da055ee0161 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInSystem1.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/importCallExpressionInSystem2.js b/tests/baselines/reference/importCallExpressionInSystem2.js new file mode 100644 index 0000000000000..ea84e47e63cbd --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInSystem2.js @@ -0,0 +1,50 @@ +//// [tests/cases/conformance/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) { + 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 0000000000000..16fc79c774fb4 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInSystem2.symbols @@ -0,0 +1,34 @@ +=== tests/cases/conformance/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/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 0000000000000..44b17eb51fd5c --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInSystem2.types @@ -0,0 +1,46 @@ +=== tests/cases/conformance/dynamicImport/0.ts === +export class B { +>B : B + + print() { return "I am B"} +>print : () => string +>"I am B" : "I am B" +} + +=== 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 +>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/importCallExpressionInSystem3.js b/tests/baselines/reference/importCallExpressionInSystem3.js new file mode 100644 index 0000000000000..309be9114fe8a --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInSystem3.js @@ -0,0 +1,46 @@ +//// [tests/cases/conformance/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 0000000000000..5ca85d6e6939d --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInSystem3.symbols @@ -0,0 +1,29 @@ +=== tests/cases/conformance/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/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 0000000000000..e517be6e722f4 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInSystem3.types @@ -0,0 +1,37 @@ +=== tests/cases/conformance/dynamicImport/0.ts === +export class B { +>B : B + + print() { return "I am B"} +>print : () => string +>"I am B" : "I am B" +} + +=== 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/dynamicImport/0" +>await import("./0") : typeof "tests/cases/conformance/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/importCallExpressionInSystem4.js b/tests/baselines/reference/importCallExpressionInSystem4.js new file mode 100644 index 0000000000000..ac01a0439e860 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInSystem4.js @@ -0,0 +1,80 @@ +//// [tests/cases/conformance/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) { + 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 0000000000000..34a1dcf4d7bdf --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInSystem4.symbols @@ -0,0 +1,61 @@ +=== tests/cases/conformance/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/dynamicImport/1.ts === +export function backup() { return "backup"; } +>backup : Symbol(backup, Decl(1.ts, 0, 0)) + +=== tests/cases/conformance/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 0000000000000..2ea666ba672aa --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInSystem4.types @@ -0,0 +1,83 @@ +=== tests/cases/conformance/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/dynamicImport/1.ts === +export function backup() { return "backup"; } +>backup : () => string +>"backup" : "backup" + +=== tests/cases/conformance/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/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>this.myModule : Promise +>this : this +>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 +>console.log : any +>console : any +>log : any +>Zero.foo() : string +>Zero.foo : () => string +>Zero : typeof "tests/cases/conformance/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/dynamicImport/1" +>await import("./1") : typeof "tests/cases/conformance/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/dynamicImport/1" +>backup : () => string + + }); + } +} diff --git a/tests/baselines/reference/importCallExpressionInUMD1.js b/tests/baselines/reference/importCallExpressionInUMD1.js new file mode 100644 index 0000000000000..f1bfcd3cc7111 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInUMD1.js @@ -0,0 +1,52 @@ +//// [tests/cases/conformance/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"; + var __syncRequire = typeof module === "object" && typeof module.exports === "object"; + __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 ? 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/importCallExpressionInUMD1.symbols b/tests/baselines/reference/importCallExpressionInUMD1.symbols new file mode 100644 index 0000000000000..333251da662fd --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInUMD1.symbols @@ -0,0 +1,28 @@ +=== tests/cases/conformance/dynamicImport/0.ts === +export function foo() { return "foo"; } +>foo : Symbol(foo, Decl(0.ts, 0, 0)) + +=== tests/cases/conformance/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 0000000000000..59da055ee0161 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInUMD1.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/importCallExpressionInUMD2.js b/tests/baselines/reference/importCallExpressionInUMD2.js new file mode 100644 index 0000000000000..db8b87a2f799e --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInUMD2.js @@ -0,0 +1,56 @@ +//// [tests/cases/conformance/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"; + var __syncRequire = typeof module === "object" && typeof module.exports === "object"; + // 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(__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/importCallExpressionInUMD2.symbols b/tests/baselines/reference/importCallExpressionInUMD2.symbols new file mode 100644 index 0000000000000..16fc79c774fb4 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInUMD2.symbols @@ -0,0 +1,34 @@ +=== tests/cases/conformance/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/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 0000000000000..44b17eb51fd5c --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInUMD2.types @@ -0,0 +1,46 @@ +=== tests/cases/conformance/dynamicImport/0.ts === +export class B { +>B : B + + print() { return "I am B"} +>print : () => string +>"I am B" : "I am B" +} + +=== 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 +>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/importCallExpressionInUMD3.js b/tests/baselines/reference/importCallExpressionInUMD3.js new file mode 100644 index 0000000000000..41106e3ab781a --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInUMD3.js @@ -0,0 +1,52 @@ +//// [tests/cases/conformance/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"; + var __syncRequire = typeof module === "object" && typeof module.exports === "object"; + async function foo() { + 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(); + } + foo(); +}); diff --git a/tests/baselines/reference/importCallExpressionInUMD3.symbols b/tests/baselines/reference/importCallExpressionInUMD3.symbols new file mode 100644 index 0000000000000..5ca85d6e6939d --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInUMD3.symbols @@ -0,0 +1,29 @@ +=== tests/cases/conformance/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/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 0000000000000..e517be6e722f4 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInUMD3.types @@ -0,0 +1,37 @@ +=== tests/cases/conformance/dynamicImport/0.ts === +export class B { +>B : B + + print() { return "I am B"} +>print : () => string +>"I am B" : "I am B" +} + +=== 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/dynamicImport/0" +>await import("./0") : typeof "tests/cases/conformance/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/importCallExpressionInUMD4.js b/tests/baselines/reference/importCallExpressionInUMD4.js new file mode 100644 index 0000000000000..47ba83b1718a1 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInUMD4.js @@ -0,0 +1,88 @@ +//// [tests/cases/conformance/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"; + var __syncRequire = typeof module === "object" && typeof module.exports === "object"; + class C { + constructor() { + 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 ? 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/importCallExpressionInUMD4.symbols b/tests/baselines/reference/importCallExpressionInUMD4.symbols new file mode 100644 index 0000000000000..34a1dcf4d7bdf --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInUMD4.symbols @@ -0,0 +1,61 @@ +=== tests/cases/conformance/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/dynamicImport/1.ts === +export function backup() { return "backup"; } +>backup : Symbol(backup, Decl(1.ts, 0, 0)) + +=== tests/cases/conformance/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 0000000000000..2ea666ba672aa --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInUMD4.types @@ -0,0 +1,83 @@ +=== tests/cases/conformance/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/dynamicImport/1.ts === +export function backup() { return "backup"; } +>backup : () => string +>"backup" : "backup" + +=== tests/cases/conformance/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/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>this.myModule : Promise +>this : this +>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 +>console.log : any +>console : any +>log : any +>Zero.foo() : string +>Zero.foo : () => string +>Zero : typeof "tests/cases/conformance/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/dynamicImport/1" +>await import("./1") : typeof "tests/cases/conformance/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/dynamicImport/1" +>backup : () => string + + }); + } +} diff --git a/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.js b/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.js new file mode 100644 index 0000000000000..728d663695331 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.js @@ -0,0 +1,61 @@ +//// [tests/cases/conformance/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(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 = Promise.resolve().then(function () { return require(j = getSpecifier()); }); +function* loadModule(directories) { + for (const directory of directories) { + const path = `${directory}\moduleFile`; + Promise.resolve().then(function () { return require(yield path); }); + } +} diff --git a/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.symbols b/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.symbols new file mode 100644 index 0000000000000..0d46961475fc1 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.symbols @@ -0,0 +1,89 @@ +=== tests/cases/conformance/dynamicImport/defaultPath.ts === +export class C {} +>C : Symbol(C, Decl(defaultPath.ts, 0, 0)) + +=== tests/cases/conformance/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 0000000000000..fc52b38c1fb9f --- /dev/null +++ b/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.types @@ -0,0 +1,118 @@ +=== tests/cases/conformance/dynamicImport/defaultPath.ts === +export class C {} +>C : C + +=== tests/cases/conformance/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 0000000000000..a1159a31ebd19 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.errors.txt @@ -0,0 +1,31 @@ +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/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts (5 errors) ==== + declare function getSpecifier(): boolean; + declare var whatToLoad: boolean; + + // Error specifier is not assignable to string + import(getSpecifier()); + ~~~~~~~~~~~~~~ +!!! error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'boolean'. + var p1 = import(getSpecifier()); + ~~~~~~~~~~~~~~ +!!! error TS7036: Dynamic import's specifier must be of type 'string', but here has type 'boolean'. + const p2 = import(whatToLoad ? getSpecifier() : "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 TS7036: Dynamic import's specifier must be of type 'string', but here has type 'string[]'. + var p4 = import(()=>"PathToModule"); + ~~~~~~~~~~~~~~~~~~ +!!! 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/importCallExpressionSpecifierNotStringTypeError.js b/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.js new file mode 100644 index 0000000000000..dde35d8048bb0 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.js @@ -0,0 +1,25 @@ +//// [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] +// Error specifier is not assignable to string +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 = Promise.resolve().then(function () { return require(["path1", "path2"]); }); +var p4 = Promise.resolve().then(function () { return require(() => "PathToModule"); }); diff --git a/tests/baselines/reference/importCallExpressionWithTypeArgument.errors.txt b/tests/baselines/reference/importCallExpressionWithTypeArgument.errors.txt new file mode 100644 index 0000000000000..8adf2789585fe --- /dev/null +++ b/tests/baselines/reference/importCallExpressionWithTypeArgument.errors.txt @@ -0,0 +1,18 @@ +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/dynamicImport/0.ts (0 errors) ==== + export function foo() { return "foo"; } + +==== tests/cases/conformance/dynamicImport/1.ts (2 errors) ==== + "use strict" + var p1 = import>("./0"); // error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1326: Dynamic import cannot have type arguments + var p2 = import<>("./0"); // error + ~~~~~~~~~~~~~~~ +!!! error TS1326: 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 0000000000000..d8690cf5d75f8 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionWithTypeArgument.js @@ -0,0 +1,22 @@ +//// [tests/cases/conformance/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 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 d746f35cbe73b..f746915da7d5a 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', 'esnext'. -!!! 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', '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 d746f35cbe73b..f746915da7d5a 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', 'esnext'. -!!! 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', 'esnext'. ==== file.ts (0 errors) ==== \ No newline at end of file diff --git a/tests/baselines/reference/tsConfig/Default initialized TSConfig/tsconfig.json b/tests/baselines/reference/tsConfig/Default initialized TSConfig/tsconfig.json index 0459900524455..772c218eb4edd 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 '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 2a41e2c4df0fc..7a9b895636c73 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 '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 e29a2813282b5..70d5ed9d738ff 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 '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 6983191690436..914b9d99d1b21 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 '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 407df036f8920..50bd28442bb91 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 '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 0459900524455..772c218eb4edd 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 '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 e4d0b37ae5181..afae7193d58bd 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 '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 3e3f7a85b34fc..a87fe9c520667 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 '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/cases/conformance/dynamicImport/importCallExpression1ESNext.ts b/tests/cases/conformance/dynamicImport/importCallExpression1ESNext.ts new file mode 100644 index 0000000000000..295b64703013a --- /dev/null +++ b/tests/cases/conformance/dynamicImport/importCallExpression1ESNext.ts @@ -0,0 +1,15 @@ +// @module: esnext +// @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/dynamicImport/importCallExpression2ESNext.ts b/tests/cases/conformance/dynamicImport/importCallExpression2ESNext.ts new file mode 100644 index 0000000000000..f0e9b358854cb --- /dev/null +++ b/tests/cases/conformance/dynamicImport/importCallExpression2ESNext.ts @@ -0,0 +1,16 @@ +// @module: esnext +// @target: esnext +// @filename: 0.ts +export class B { + print() { return "I am B"} +} + +// @filename: 2.ts +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/dynamicImport/importCallExpression3ESNext.ts b/tests/cases/conformance/dynamicImport/importCallExpression3ESNext.ts new file mode 100644 index 0000000000000..ee7264b8c7ebf --- /dev/null +++ b/tests/cases/conformance/dynamicImport/importCallExpression3ESNext.ts @@ -0,0 +1,14 @@ +// @module: esnext +// @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/dynamicImport/importCallExpression4ESNext.ts b/tests/cases/conformance/dynamicImport/importCallExpression4ESNext.ts new file mode 100644 index 0000000000000..91342770d7d0c --- /dev/null +++ b/tests/cases/conformance/dynamicImport/importCallExpression4ESNext.ts @@ -0,0 +1,26 @@ +// @module: esnext +// @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/dynamicImport/importCallExpression5ESNext.ts b/tests/cases/conformance/dynamicImport/importCallExpression5ESNext.ts new file mode 100644 index 0000000000000..173b606a50c39 --- /dev/null +++ b/tests/cases/conformance/dynamicImport/importCallExpression5ESNext.ts @@ -0,0 +1,20 @@ +// @module: esnext +// @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/dynamicImport/importCallExpression6ESNext.ts b/tests/cases/conformance/dynamicImport/importCallExpression6ESNext.ts new file mode 100644 index 0000000000000..f09521186e816 --- /dev/null +++ b/tests/cases/conformance/dynamicImport/importCallExpression6ESNext.ts @@ -0,0 +1,19 @@ +// @module: esnext +// @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 diff --git a/tests/cases/conformance/dynamicImport/importCallExpressionCheckReturntype1.ts b/tests/cases/conformance/dynamicImport/importCallExpressionCheckReturntype1.ts new file mode 100644 index 0000000000000..1218565fa54c8 --- /dev/null +++ b/tests/cases/conformance/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/dynamicImport/importCallExpressionDeclarationEmit1.ts b/tests/cases/conformance/dynamicImport/importCallExpressionDeclarationEmit1.ts new file mode 100644 index 0000000000000..fb29995114862 --- /dev/null +++ b/tests/cases/conformance/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/dynamicImport/importCallExpressionDeclarationEmit2.ts b/tests/cases/conformance/dynamicImport/importCallExpressionDeclarationEmit2.ts new file mode 100644 index 0000000000000..4b9196dea2019 --- /dev/null +++ b/tests/cases/conformance/dynamicImport/importCallExpressionDeclarationEmit2.ts @@ -0,0 +1,9 @@ +// @module: esnext +// @target: esnext +// @declaration: true + +// @filename: 0.ts +export function foo() { return "foo"; } + +// @filename: 1.ts +var p1 = import("./0"); \ No newline at end of file diff --git a/tests/cases/conformance/dynamicImport/importCallExpressionDeclarationEmit3.ts b/tests/cases/conformance/dynamicImport/importCallExpressionDeclarationEmit3.ts new file mode 100644 index 0000000000000..6d17d624190fd --- /dev/null +++ b/tests/cases/conformance/dynamicImport/importCallExpressionDeclarationEmit3.ts @@ -0,0 +1,15 @@ +// @module: esnext +// @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/dynamicImport/importCallExpressionES5AMD.ts b/tests/cases/conformance/dynamicImport/importCallExpressionES5AMD.ts new file mode 100644 index 0000000000000..33c31283ea064 --- /dev/null +++ b/tests/cases/conformance/dynamicImport/importCallExpressionES5AMD.ts @@ -0,0 +1,16 @@ +// @module: amd +// @target: es5 +// @lib: es6 +// @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/dynamicImport/importCallExpressionES5CJS.ts b/tests/cases/conformance/dynamicImport/importCallExpressionES5CJS.ts new file mode 100644 index 0000000000000..900ddbdba0c07 --- /dev/null +++ b/tests/cases/conformance/dynamicImport/importCallExpressionES5CJS.ts @@ -0,0 +1,16 @@ +// @module: commonjs +// @target: es5 +// @lib: es6 +// @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/dynamicImport/importCallExpressionES5System.ts b/tests/cases/conformance/dynamicImport/importCallExpressionES5System.ts new file mode 100644 index 0000000000000..c00ab6899c6e8 --- /dev/null +++ b/tests/cases/conformance/dynamicImport/importCallExpressionES5System.ts @@ -0,0 +1,16 @@ +// @module: system +// @target: es5 +// @lib: es6 +// @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/dynamicImport/importCallExpressionES5UMD.ts b/tests/cases/conformance/dynamicImport/importCallExpressionES5UMD.ts new file mode 100644 index 0000000000000..699b0ffc342d8 --- /dev/null +++ b/tests/cases/conformance/dynamicImport/importCallExpressionES5UMD.ts @@ -0,0 +1,16 @@ +// @module: umd +// @target: es5 +// @lib: es6 +// @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/dynamicImport/importCallExpressionErrorInES2015.ts b/tests/cases/conformance/dynamicImport/importCallExpressionErrorInES2015.ts new file mode 100644 index 0000000000000..a7fcd8533a328 --- /dev/null +++ b/tests/cases/conformance/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/dynamicImport/importCallExpressionGrammarError.ts b/tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts new file mode 100644 index 0000000000000..38dc47f32077d --- /dev/null +++ b/tests/cases/conformance/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/dynamicImport/importCallExpressionInAMD1.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInAMD1.ts new file mode 100644 index 0000000000000..63cfc54c73226 --- /dev/null +++ b/tests/cases/conformance/dynamicImport/importCallExpressionInAMD1.ts @@ -0,0 +1,15 @@ +// @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(); +}); + +function foo() { + const p2 = import("./0"); +} \ No newline at end of file diff --git a/tests/cases/conformance/dynamicImport/importCallExpressionInAMD2.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInAMD2.ts new file mode 100644 index 0000000000000..96b2fd4ceff65 --- /dev/null +++ b/tests/cases/conformance/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/dynamicImport/importCallExpressionInAMD3.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInAMD3.ts new file mode 100644 index 0000000000000..a2b287b4d9590 --- /dev/null +++ b/tests/cases/conformance/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/dynamicImport/importCallExpressionInAMD4.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInAMD4.ts new file mode 100644 index 0000000000000..10044ab674c5f --- /dev/null +++ b/tests/cases/conformance/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/dynamicImport/importCallExpressionInCJS1.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInCJS1.ts new file mode 100644 index 0000000000000..e14570175522f --- /dev/null +++ b/tests/cases/conformance/dynamicImport/importCallExpressionInCJS1.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/dynamicImport/importCallExpressionInCJS2.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInCJS2.ts new file mode 100644 index 0000000000000..e42a58a290c3c --- /dev/null +++ b/tests/cases/conformance/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 diff --git a/tests/cases/conformance/dynamicImport/importCallExpressionInCJS3.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInCJS3.ts new file mode 100644 index 0000000000000..5990eb3a5a2e4 --- /dev/null +++ b/tests/cases/conformance/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/dynamicImport/importCallExpressionInCJS4.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInCJS4.ts new file mode 100644 index 0000000000000..fba246c0b8b43 --- /dev/null +++ b/tests/cases/conformance/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/dynamicImport/importCallExpressionInCJS5.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInCJS5.ts new file mode 100644 index 0000000000000..db86764802bf5 --- /dev/null +++ b/tests/cases/conformance/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 diff --git a/tests/cases/conformance/dynamicImport/importCallExpressionInScriptContext1.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInScriptContext1.ts new file mode 100644 index 0000000000000..166513321a320 --- /dev/null +++ b/tests/cases/conformance/dynamicImport/importCallExpressionInScriptContext1.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/dynamicImport/importCallExpressionInScriptContext2.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInScriptContext2.ts new file mode 100644 index 0000000000000..754f7e865bb28 --- /dev/null +++ b/tests/cases/conformance/dynamicImport/importCallExpressionInScriptContext2.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/dynamicImport/importCallExpressionInSystem1.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInSystem1.ts new file mode 100644 index 0000000000000..a69e844c7a78b --- /dev/null +++ b/tests/cases/conformance/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/dynamicImport/importCallExpressionInSystem2.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInSystem2.ts new file mode 100644 index 0000000000000..c6fac3683ee2f --- /dev/null +++ b/tests/cases/conformance/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/dynamicImport/importCallExpressionInSystem3.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInSystem3.ts new file mode 100644 index 0000000000000..7f4485d896299 --- /dev/null +++ b/tests/cases/conformance/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/dynamicImport/importCallExpressionInSystem4.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInSystem4.ts new file mode 100644 index 0000000000000..1ab3040862c29 --- /dev/null +++ b/tests/cases/conformance/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/dynamicImport/importCallExpressionInUMD1.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInUMD1.ts new file mode 100644 index 0000000000000..05c4d69910451 --- /dev/null +++ b/tests/cases/conformance/dynamicImport/importCallExpressionInUMD1.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 diff --git a/tests/cases/conformance/dynamicImport/importCallExpressionInUMD2.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInUMD2.ts new file mode 100644 index 0000000000000..2f76d0aa2678e --- /dev/null +++ b/tests/cases/conformance/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/dynamicImport/importCallExpressionInUMD3.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInUMD3.ts new file mode 100644 index 0000000000000..58d21ee52d0a5 --- /dev/null +++ b/tests/cases/conformance/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/dynamicImport/importCallExpressionInUMD4.ts b/tests/cases/conformance/dynamicImport/importCallExpressionInUMD4.ts new file mode 100644 index 0000000000000..ef0f09994072c --- /dev/null +++ b/tests/cases/conformance/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/dynamicImport/importCallExpressionReturnPromiseOfAny.ts b/tests/cases/conformance/dynamicImport/importCallExpressionReturnPromiseOfAny.ts new file mode 100644 index 0000000000000..34f0b63be6f10 --- /dev/null +++ b/tests/cases/conformance/dynamicImport/importCallExpressionReturnPromiseOfAny.ts @@ -0,0 +1,34 @@ +// @module: commonjs +// @target: es6 +// @noImplicitAny: true +// @filename: defaultPath.ts +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; +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); + } +} diff --git a/tests/cases/conformance/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts b/tests/cases/conformance/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts new file mode 100644 index 0000000000000..3af0ec89ac26c --- /dev/null +++ b/tests/cases/conformance/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts @@ -0,0 +1,17 @@ +// @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 +}); + +var p3 = import(["path1", "path2"]); +var p4 = import(()=>"PathToModule"); \ No newline at end of file diff --git a/tests/cases/conformance/dynamicImport/importCallExpressionWithTypeArgument.ts b/tests/cases/conformance/dynamicImport/importCallExpressionWithTypeArgument.ts new file mode 100644 index 0000000000000..895b61af6ff6e --- /dev/null +++ b/tests/cases/conformance/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