diff --git a/Jakefile.js b/Jakefile.js index 439fced0720ff..900859f033a0f 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -802,7 +802,8 @@ function runConsoleTests(defaultReporter, runInParallel) { var debug = process.env.debug || process.env.d; var inspect = process.env.inspect; - tests = process.env.test || process.env.tests || process.env.t; + var testTimeout = process.env.timeout || defaultTestTimeout; + var tests = process.env.test || process.env.tests || process.env.t; var light = process.env.light || false; var stackTraceLimit = process.env.stackTraceLimit; var testConfigFile = 'test.config'; @@ -820,7 +821,7 @@ function runConsoleTests(defaultReporter, runInParallel) { } while (fs.existsSync(taskConfigsFolder)); fs.mkdirSync(taskConfigsFolder); - workerCount = process.env.workerCount || os.cpus().length; + workerCount = process.env.workerCount || process.env.p || os.cpus().length; } if (tests || light || taskConfigsFolder) { @@ -925,7 +926,7 @@ function runConsoleTests(defaultReporter, runInParallel) { } } -var testTimeout = 20000; +var defaultTestTimeout = 22000; desc("Runs all the tests in parallel using the built run.js file. Optional arguments are: t[ests]=category1|category2|... d[ebug]=true."); task("runtests-parallel", ["build-rules", "tests", builtLocalDirectory], function () { runConsoleTests('min', /*runInParallel*/ true); diff --git a/scripts/tslint/nextLineRule.ts b/scripts/tslint/nextLineRule.ts index b149d09eb38a8..fa03746afc6b9 100644 --- a/scripts/tslint/nextLineRule.ts +++ b/scripts/tslint/nextLineRule.ts @@ -18,7 +18,7 @@ export class Rule extends Lint.Rules.AbstractRule { function walk(ctx: Lint.WalkContext, checkCatch: boolean, checkElse: boolean): void { const { sourceFile } = ctx; - function recur(node: ts.Node): void { + ts.forEachChild(sourceFile, function recur(node) { switch (node.kind) { case ts.SyntaxKind.IfStatement: checkIf(node as ts.IfStatement); @@ -28,7 +28,7 @@ function walk(ctx: Lint.WalkContext, checkCatch: boolean, checkElse: boole break; } ts.forEachChild(node, recur); - } + }); function checkIf(node: ts.IfStatement): void { const { thenStatement, elseStatement } = node; 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 ea9f37aa92ebe..ea41705a65507 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -210,6 +210,11 @@ namespace ts { getSuggestionForNonexistentProperty, getSuggestionForNonexistentSymbol, getBaseConstraintOfType, + getJsxNamespace, + resolveNameAtLocation(location: Node, name: string, meaning: SymbolFlags): Symbol | undefined { + location = getParseTreeNode(location); + return resolveName(location, name, meaning, /*nameNotFoundMessage*/ undefined, name); + }, }; const tupleTypes: GenericType[] = []; @@ -735,6 +740,7 @@ namespace ts { if (declarationFile !== useFile) { if ((modulekind && (declarationFile.externalModuleIndicator || useFile.externalModuleIndicator)) || (!compilerOptions.outFile && !compilerOptions.out) || + isInTypeQuery(usage) || isInAmbientContext(declaration)) { // nodes are in different files and order cannot be determined return true; @@ -847,7 +853,7 @@ namespace ts { location: Node | undefined, name: string, meaning: SymbolFlags, - nameNotFoundMessage: DiagnosticMessage, + nameNotFoundMessage: DiagnosticMessage | undefined, nameArg: string | Identifier, suggestedNameNotFoundMessage?: DiagnosticMessage): Symbol { return resolveNameHelper(location, name, meaning, nameNotFoundMessage, nameArg, getSymbol, suggestedNameNotFoundMessage); @@ -1364,6 +1370,9 @@ namespace ts { // An 'import { Point } from "graphics"' needs to create a symbol that combines the value side 'Point' // property with the type/namespace side interface 'Point'. function combineValueAndTypeSymbols(valueSymbol: Symbol, typeSymbol: Symbol): Symbol { + if (valueSymbol === unknownSymbol && typeSymbol === unknownSymbol) { + return unknownSymbol; + } if (valueSymbol.flags & (SymbolFlags.Type | SymbolFlags.Namespace)) { return valueSymbol; } @@ -1464,8 +1473,15 @@ namespace ts { } } + /** + * Indicates that a symbol is an alias that does not merge with a local declaration. + */ + function isNonLocalAlias(symbol: Symbol, excludes = SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace) { + return symbol && (symbol.flags & (SymbolFlags.Alias | excludes)) === SymbolFlags.Alias; + } + function resolveSymbol(symbol: Symbol, dontResolveAlias?: boolean): Symbol { - const shouldResolve = !dontResolveAlias && symbol && symbol.flags & SymbolFlags.Alias && !(symbol.flags & (SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace)); + const shouldResolve = !dontResolveAlias && isNonLocalAlias(symbol); return shouldResolve ? resolveAlias(symbol) : symbol; } @@ -2282,7 +2298,7 @@ namespace ts { function typeToString(type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): string { const typeNode = nodeBuilder.typeToTypeNode(type, enclosingDeclaration, toNodeBuilderFlags(flags) | NodeBuilderFlags.IgnoreErrors | NodeBuilderFlags.WriteTypeParametersInQualifiedName); - Debug.assert(typeNode !== undefined, "should always get typenode?"); + Debug.assert(typeNode !== undefined, "should always get typenode"); const options = { removeComments: true }; const writer = createTextWriter(""); const printer = createPrinter(options); @@ -5841,7 +5857,8 @@ namespace ts { } } return arrayFrom(props.values()); - } else { + } + else { return getPropertiesOfType(type); } } @@ -7632,11 +7649,9 @@ namespace ts { if (left.flags & TypeFlags.Any || right.flags & TypeFlags.Any) { return anyType; } - left = filterType(left, t => !(t.flags & TypeFlags.Nullable)); if (left.flags & TypeFlags.Never) { return right; } - right = filterType(right, t => !(t.flags & TypeFlags.Nullable)); if (right.flags & TypeFlags.Never) { return left; } @@ -8356,6 +8371,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); @@ -8582,6 +8603,7 @@ namespace ts { function isEmptyObjectType(type: Type): boolean { return type.flags & TypeFlags.Object ? isEmptyResolvedType(resolveStructuredTypeMembers(type)) : + type.flags & TypeFlags.NonPrimitive ? true : type.flags & TypeFlags.Union ? forEach((type).types, isEmptyObjectType) : type.flags & TypeFlags.Intersection ? !forEach((type).types, t => !isEmptyObjectType(t)) : false; @@ -10248,7 +10270,7 @@ namespace ts { const objectFlags = getObjectFlags(type); return !!(type.flags & TypeFlags.TypeVariable || objectFlags & ObjectFlags.Reference && forEach((type).typeArguments, couldContainTypeVariables) || - objectFlags & ObjectFlags.Anonymous && type.symbol && type.symbol.flags & (SymbolFlags.Method | SymbolFlags.TypeLiteral | SymbolFlags.Class) || + objectFlags & ObjectFlags.Anonymous && type.symbol && type.symbol.flags & (SymbolFlags.Function | SymbolFlags.Method | SymbolFlags.TypeLiteral | SymbolFlags.Class) || objectFlags & ObjectFlags.Mapped || type.flags & TypeFlags.UnionOrIntersection && couldUnionOrIntersectionContainTypeVariables(type)); } @@ -12014,7 +12036,9 @@ namespace ts { return getTypeOfSymbol(symbol); } - if (symbol.flags & SymbolFlags.Alias && !isInTypeQuery(node) && !isConstEnumOrConstEnumOnlyModule(resolveAlias(symbol))) { + // We should only mark aliases as referenced if there isn't a local value declaration + // for the symbol. + if (isNonLocalAlias(symbol, /*excludes*/ SymbolFlags.Value) && !isInTypeQuery(node) && !isConstEnumOrConstEnumOnlyModule(resolveAlias(symbol))) { markAliasSymbolAsReferenced(symbol); } @@ -13051,13 +13075,13 @@ namespace ts { return node ? node.contextualMapper : identityMapper; } - // If the given type is an object or union type, if that type has a single signature, and if - // that signature is non-generic, return the signature. Otherwise return undefined. - function getNonGenericSignature(type: Type, node: FunctionExpression | ArrowFunction | MethodDeclaration): Signature { + // If the given type is an object or union type with a single signature, and if that signature has at + // least as many parameters as the given function, return the signature. Otherwise return undefined. + function getContextualCallSignature(type: Type, node: FunctionExpression | ArrowFunction | MethodDeclaration): Signature { const signatures = getSignaturesOfStructuredType(type, SignatureKind.Call); if (signatures.length === 1) { const signature = signatures[0]; - if (!signature.typeParameters && !isAritySmaller(signature, node)) { + if (!isAritySmaller(signature, node)) { return signature; } } @@ -13108,12 +13132,12 @@ namespace ts { return undefined; } if (!(type.flags & TypeFlags.Union)) { - return getNonGenericSignature(type, node); + return getContextualCallSignature(type, node); } let signatureList: Signature[]; const types = (type).types; for (const current of types) { - const signature = getNonGenericSignature(current, node); + const signature = getContextualCallSignature(current, node); if (signature) { if (!signatureList) { // This signature will contribute to contextual union signature @@ -14160,7 +14184,7 @@ namespace ts { checkJsxPreconditions(node); // The reactNamespace/jsxFactory's root symbol should be marked as 'used' so we don't incorrectly elide its import. // And if there is no reactNamespace/jsxFactory's symbol in scope when targeting React emit, we should issue an error. - const reactRefErr = compilerOptions.jsx === JsxEmit.React ? Diagnostics.Cannot_find_name_0 : undefined; + const reactRefErr = diagnostics && compilerOptions.jsx === JsxEmit.React ? Diagnostics.Cannot_find_name_0 : undefined; const reactNamespace = getJsxNamespace(); const reactSym = resolveName(node.tagName, reactNamespace, SymbolFlags.Value, reactRefErr, reactNamespace); if (reactSym) { @@ -14531,6 +14555,7 @@ namespace ts { const maximumLengthDifference = Math.min(3, name.length * 0.34); let bestDistance = Number.MAX_VALUE; let bestCandidate = undefined; + let justCheckExactMatches = false; if (name.length > 30) { return undefined; } @@ -14543,6 +14568,9 @@ namespace ts { if (candidateName === name) { return candidate; } + if (justCheckExactMatches) { + continue; + } if (candidateName.length < 3 || name.length < 3 || candidateName === "eval" || @@ -14558,7 +14586,8 @@ namespace ts { continue; } if (distance < 3) { - return candidate; + justCheckExactMatches = true; + bestCandidate = candidate; } else if (distance < bestDistance) { bestDistance = distance; @@ -14971,11 +15000,21 @@ namespace ts { // We clone the contextual mapper to avoid disturbing a resolution in progress for an // outer call expression. Effectively we just want a snapshot of whatever has been // inferred for any outer call expression so far. - const mapper = cloneTypeMapper(getContextualMapper(node)); - const instantiatedType = instantiateType(contextualType, mapper); - const returnType = getReturnTypeOfSignature(signature); - // Inferences made from return types have lower priority than all other inferences. - inferTypes(context.inferences, instantiatedType, returnType, InferencePriority.ReturnType); + const instantiatedType = instantiateType(contextualType, cloneTypeMapper(getContextualMapper(node))); + // If the contextual type is a generic pure function type, we instantiate the type with + // its own type parameters and type arguments. This ensures that the type parameters are + // not erased to type any during type inference such that they can be inferred as actual + // types from the contextual type. For example: + // declare function arrayMap(f: (x: T) => U): (a: T[]) => U[]; + // const boxElements: (a: A[]) => { value: A }[] = arrayMap(value => ({ value })); + // Above, the type of the 'value' parameter is inferred to be 'A'. + const contextualSignature = getSingleCallSignature(instantiatedType); + const inferenceSourceType = contextualSignature && contextualSignature.typeParameters ? + getOrCreateTypeFromSignature(getSignatureInstantiation(contextualSignature, contextualSignature.typeParameters)) : + instantiatedType; + const inferenceTargetType = getReturnTypeOfSignature(signature); + // Inferences made from return types have lower priority than all other inferences. + inferTypes(context.inferences, inferenceSourceType, inferenceTargetType, InferencePriority.ReturnType); } } @@ -15882,7 +15921,7 @@ namespace ts { const callSignatures = getSignaturesOfType(expressionType, SignatureKind.Call); if (callSignatures.length) { const signature = resolveCall(node, callSignatures, candidatesOutArray); - if (getReturnTypeOfSignature(signature) !== voidType) { + if (!isJavaScriptConstructor(signature.declaration) && getReturnTypeOfSignature(signature) !== voidType) { error(node, Diagnostics.Only_a_void_function_can_be_called_with_the_new_keyword); } if (getThisTypeOfSignature(signature) === voidType) { @@ -16109,10 +16148,30 @@ namespace ts { return getNodeLinks(node).resolvedSignature === resolvingSignature ? resolvingSignature : getResolvedSignature(node); } + /** + * Indicates whether a declaration can be treated as a constructor in a JavaScript + * file. + */ + function isJavaScriptConstructor(node: Declaration): boolean { + if (isInJavaScriptFile(node)) { + // If the node has a @class tag, treat it like a constructor. + if (getJSDocClassTag(node)) return true; + + // If the symbol of the node has members, treat it like a constructor. + const symbol = isFunctionDeclaration(node) || isFunctionExpression(node) ? getSymbolOfNode(node) : + isVariableDeclaration(node) && isFunctionExpression(node.initializer) ? getSymbolOfNode(node.initializer) : + undefined; + + return symbol && symbol.members !== undefined; + } + + return false; + } + function getInferredClassType(symbol: Symbol) { const links = getSymbolLinks(symbol); if (!links.inferredClassType) { - links.inferredClassType = createAnonymousType(symbol, symbol.members, emptyArray, emptyArray, /*stringIndexType*/ undefined, /*numberIndexType*/ undefined); + links.inferredClassType = createAnonymousType(symbol, symbol.members || emptySymbols, emptyArray, emptyArray, /*stringIndexType*/ undefined, /*numberIndexType*/ undefined); } return links.inferredClassType; } @@ -16152,7 +16211,7 @@ namespace ts { if (funcSymbol && isDeclarationOfFunctionOrClassExpression(funcSymbol)) { funcSymbol = getSymbolOfNode((funcSymbol.valueDeclaration).initializer); } - if (funcSymbol && funcSymbol.members && funcSymbol.flags & SymbolFlags.Function) { + if (funcSymbol && funcSymbol.flags & SymbolFlags.Function && (funcSymbol.members || getJSDocClassTag(funcSymbol.valueDeclaration))) { return getInferredClassType(funcSymbol); } else if (noImplicitAny) { @@ -16170,6 +16229,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; @@ -16376,14 +16464,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; @@ -17742,6 +17834,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: @@ -22861,7 +22957,9 @@ namespace ts { node = getParseTreeNode(node, isIdentifier); if (node) { const symbol = getReferencedValueSymbol(node); - if (symbol && symbol.flags & SymbolFlags.Alias) { + // We should only get the declaration of an alias if there isn't a local value + // declaration for the symbol + if (isNonLocalAlias(symbol, /*excludes*/ SymbolFlags.Value)) { return getDeclarationOfAliasSymbol(symbol); } } @@ -24667,6 +24765,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/core.ts b/src/compiler/core.ts index 5819e634ff423..1792a393234ea 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -473,7 +473,7 @@ namespace ts { * @param array The array to map. * @param mapfn The callback used to map the result into one or more values. */ - export function flatMap(array: T[], mapfn: (x: T, i: number) => U | U[]): U[] { + export function flatMap(array: T[] | undefined, mapfn: (x: T, i: number) => U | U[] | undefined): U[] | undefined { let result: U[]; if (array) { result = []; diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index e8ad8a033ffa9..70efe50143e56 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 @@ -1927,10 +1944,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 @@ -2163,6 +2176,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", @@ -2629,7 +2650,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 }, @@ -3365,6 +3386,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 @@ -3559,11 +3585,11 @@ "category": "Message", "code": 90015 }, - "Add declaration for missing property '{0}'.": { + "Declare property '{0}'.": { "category": "Message", "code": 90016 }, - "Add index signature for missing property '{0}'.": { + "Add index signature for property '{0}'.": { "category": "Message", "code": 90017 }, @@ -3587,7 +3613,15 @@ "category": "Message", "code": 90022 }, - + "Declare method '{0}'.": { + "category": "Message", + "code": 90023 + }, + "Declare static method '{0}'.": { + "category": "Message", + "code": 90024 + }, + "Convert function to an ES2015 class": { "category": "Message", "code": 95001 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/factory.ts b/src/compiler/factory.ts index 26c40b0523997..12e8110e7bec4 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -2503,6 +2503,7 @@ namespace ts { helpers } = sourceEmitNode; if (!destEmitNode) destEmitNode = {}; + // We are using `.slice()` here in case `destEmitNode.leadingComments` is pushed to later. if (leadingComments) destEmitNode.leadingComments = addRange(leadingComments.slice(), destEmitNode.leadingComments); if (trailingComments) destEmitNode.trailingComments = addRange(trailingComments.slice(), destEmitNode.trailingComments); if (flags) destEmitNode.flags = flags; diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 849f97bbbaf7c..b398ee66e0ad2 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; } @@ -2777,6 +2783,8 @@ namespace ts { case SyntaxKind.SlashEqualsToken: case SyntaxKind.Identifier: return true; + case SyntaxKind.ImportKeyword: + return lookAhead(nextTokenIsOpenParenOrLessThan); default: return isIdentifier(); } @@ -3509,10 +3517,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 +3586,7 @@ namespace ts { } // falls through default: - return parseIncrementExpression(); + return parseUpdateExpression(); } } @@ -3594,7 +3602,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 +3626,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 +3636,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 +3686,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) { + // 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 +3714,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: // @@ -4792,9 +4810,11 @@ namespace ts { case SyntaxKind.FinallyKeyword: return true; + case SyntaxKind.ImportKeyword: + return isStartOfDeclaration() || lookAhead(nextTokenIsOpenParenOrLessThan); + case SyntaxKind.ConstKeyword: case SyntaxKind.ExportKeyword: - case SyntaxKind.ImportKeyword: return isStartOfDeclaration(); case SyntaxKind.AsyncKeyword: @@ -6513,6 +6533,10 @@ namespace ts { case "augments": tag = parseAugmentsTag(atToken, tagName); break; + case "class": + case "constructor": + tag = parseClassTag(atToken, tagName); + break; case "arg": case "argument": case "param": @@ -6732,6 +6756,13 @@ namespace ts { return finishNode(result); } + function parseClassTag(atToken: AtToken, tagName: Identifier): JSDocClassTag { + const tag = createNode(SyntaxKind.JSDocClassTag, atToken.pos); + tag.atToken = atToken; + tag.tagName = tagName; + return finishNode(tag); + } + function parseTypedefTag(atToken: AtToken, tagName: Identifier): JSDocTypedefTag { const typeExpression = tryParseTypeExpression(); skipWhitespace(); diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 834122b3584f6..92c50e6ddffc9 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -984,16 +984,12 @@ namespace ts { if (sourceFile) { return getDiagnostics(sourceFile, cancellationToken); } - - const allDiagnostics: Diagnostic[] = []; - forEach(program.getSourceFiles(), sourceFile => { + return sortAndDeduplicateDiagnostics(flatMap(program.getSourceFiles(), sourceFile => { if (cancellationToken) { cancellationToken.throwIfCancellationRequested(); } - addRange(allDiagnostics, getDiagnostics(sourceFile, cancellationToken)); - }); - - return sortAndDeduplicateDiagnostics(allDiagnostics); + return getDiagnostics(sourceFile, cancellationToken); + })); } function getSyntacticDiagnostics(sourceFile: SourceFile, cancellationToken: CancellationToken): Diagnostic[] { @@ -1330,16 +1326,13 @@ namespace ts { } function getOptionsDiagnostics(): Diagnostic[] { - const allDiagnostics: Diagnostic[] = []; - addRange(allDiagnostics, fileProcessingDiagnostics.getGlobalDiagnostics()); - addRange(allDiagnostics, programDiagnostics.getGlobalDiagnostics()); - return sortAndDeduplicateDiagnostics(allDiagnostics); + return sortAndDeduplicateDiagnostics(concatenate( + fileProcessingDiagnostics.getGlobalDiagnostics(), + programDiagnostics.getGlobalDiagnostics())); } function getGlobalDiagnostics(): Diagnostic[] { - const allDiagnostics: Diagnostic[] = []; - addRange(allDiagnostics, getDiagnosticsProducingTypeChecker().getGlobalDiagnostics()); - return sortAndDeduplicateDiagnostics(allDiagnostics); + return sortAndDeduplicateDiagnostics(getDiagnosticsProducingTypeChecker().getGlobalDiagnostics().slice()); } function processRootFile(fileName: string, isDefaultLib: boolean) { @@ -1366,6 +1359,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 +1379,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 +1443,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); } } } @@ -1486,7 +1484,8 @@ namespace ts { } } return sourceFile; - } else { + } + else { const sourceFileNoExtension = options.allowNonTsExtensions && getSourceFile(fileName); if (sourceFileNoExtension) return sourceFileNoExtension; 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/es2015.ts b/src/compiler/transformers/es2015.ts index a0656476421d4..7acbd3126b4fa 100644 --- a/src/compiler/transformers/es2015.ts +++ b/src/compiler/transformers/es2015.ts @@ -2095,9 +2095,9 @@ namespace ts { enableSubstitutionsForBlockScopedBindings(); } - const declarations = flatten(map(node.declarations, node.flags & NodeFlags.Let + const declarations = flatMap(node.declarations, node.flags & NodeFlags.Let ? visitVariableDeclarationInLetDeclarationList - : visitVariableDeclaration)); + : visitVariableDeclaration); const declarationList = createVariableDeclarationList(declarations); setOriginalNode(declarationList, node); diff --git a/src/compiler/transformers/esnext.ts b/src/compiler/transformers/esnext.ts index 6e2f70b5c35d3..a3aa0139aa41c 100644 --- a/src/compiler/transformers/esnext.ts +++ b/src/compiler/transformers/esnext.ts @@ -351,8 +351,10 @@ namespace ts { ); } - function awaitAsYield(expression: Expression) { - return createYield(/*asteriskToken*/ undefined, enclosingFunctionFlags & FunctionFlags.Generator ? createAwaitHelper(context, expression) : expression); + function createDownlevelAwait(expression: Expression) { + return enclosingFunctionFlags & FunctionFlags.Generator + ? createYield(/*asteriskToken*/ undefined, createAwaitHelper(context, expression)) + : createAwait(expression); } function transformForAwaitOfStatement(node: ForOfStatement, outermostLabeledStatement: LabeledStatement) { @@ -385,11 +387,11 @@ namespace ts { EmitFlags.NoHoisting ), /*condition*/ createComma( - createAssignment(result, awaitAsYield(callNext)), + createAssignment(result, createDownlevelAwait(callNext)), createLogicalNot(getDone) ), /*incrementor*/ undefined, - /*statement*/ convertForOfStatementHead(node, awaitAsYield(getValue)) + /*statement*/ convertForOfStatementHead(node, createDownlevelAwait(getValue)) ), /*location*/ node ), @@ -434,7 +436,7 @@ namespace ts { createPropertyAccess(iterator, "return") ) ), - createStatement(awaitAsYield(callReturn)) + createStatement(createDownlevelAwait(callReturn)) ), EmitFlags.SingleLine ) 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..ab04f72faf0c9 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -374,6 +374,7 @@ namespace ts { JSDocComment, JSDocTag, JSDocAugmentsTag, + JSDocClassTag, JSDocParameterTag, JSDocReturnTag, JSDocTypeTag, @@ -395,6 +396,7 @@ namespace ts { // Enum value count Count, + // Markers FirstAssignment = EqualsToken, LastAssignment = CaretEqualsToken, @@ -449,6 +451,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 +1011,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 +1025,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 +1039,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 +1073,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 +1469,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 +1483,10 @@ namespace ts { expression: SuperExpression; } + export interface ImportCall extends CallExpression { + expression: ImportExpression; + } + export interface ExpressionWithTypeArguments extends TypeNode { kind: SyntaxKind.ExpressionWithTypeArguments; parent?: HeritageClause; @@ -2117,6 +2133,10 @@ namespace ts { typeExpression: JSDocTypeExpression; } + export interface JSDocClassTag extends JSDocTag { + kind: SyntaxKind.JSDocClassTag; + } + export interface JSDocTemplateTag extends JSDocTag { kind: SyntaxKind.JSDocTemplateTag; typeParameters: NodeArray; @@ -2535,7 +2555,6 @@ namespace ts { getNonNullableType(type: Type): Type; /** Note that the resulting nodes cannot be checked. */ - typeToTypeNode(type: Type, enclosingDeclaration?: Node, flags?: NodeBuilderFlags): TypeNode; /** Note that the resulting nodes cannot be checked. */ signatureToSignatureDeclaration(signature: Signature, kind: SyntaxKind, enclosingDeclaration?: Node, flags?: NodeBuilderFlags): SignatureDeclaration; @@ -2605,6 +2624,9 @@ namespace ts { * Does not include properties of primitive types. */ /* @internal */ getAllPossiblePropertiesOfType(type: Type): Symbol[]; + + /* @internal */ getJsxNamespace(): string; + /* @internal */ resolveNameAtLocation(location: Node, name: string, meaning: SymbolFlags): Symbol | undefined; } export enum NodeBuilderFlags { @@ -3564,6 +3586,7 @@ namespace ts { UMD = 3, System = 4, ES2015 = 5, + ESNext = 6 } export const enum JsxEmit { @@ -3948,6 +3971,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..77f1e43c9cbaa 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; @@ -1434,24 +1438,10 @@ namespace ts { } function getJSDocTags(node: Node, kind: SyntaxKind): JSDocTag[] { - const docs = getJSDocs(node); - if (docs) { - const result: JSDocTag[] = []; - for (const doc of docs) { - if (doc.kind === SyntaxKind.JSDocParameterTag) { - if (doc.kind === kind) { - result.push(doc as JSDocTag); - } - } - else { - const tags = (doc as JSDoc).tags; - if (tags) { - result.push(...filter(tags, tag => tag.kind === kind)); - } - } - } - return result; - } + return flatMap(getJSDocs(node), doc => + doc.kind === SyntaxKind.JSDocComment + ? filter((doc as JSDoc).tags, tag => tag.kind === kind) + : doc.kind === kind && doc); } function getFirstJSDocTag(node: Node, kind: SyntaxKind): JSDocTag { @@ -1572,6 +1562,10 @@ namespace ts { return getFirstJSDocTag(node, SyntaxKind.JSDocAugmentsTag) as JSDocAugmentsTag; } + export function getJSDocClassTag(node: Node): JSDocClassTag { + return getFirstJSDocTag(node, SyntaxKind.JSDocClassTag) as JSDocClassTag; + } + export function getJSDocReturnTag(node: Node): JSDocReturnTag { return getFirstJSDocTag(node, SyntaxKind.JSDocReturnTag) as JSDocReturnTag; } diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 8f19b83c7ada5..07aacf3c8a709 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -479,24 +479,11 @@ namespace FourSlash { } private getDiagnostics(fileName: string): ts.Diagnostic[] { - const syntacticErrors = this.languageService.getSyntacticDiagnostics(fileName); - const semanticErrors = this.languageService.getSemanticDiagnostics(fileName); - - const diagnostics: ts.Diagnostic[] = []; - diagnostics.push.apply(diagnostics, syntacticErrors); - diagnostics.push.apply(diagnostics, semanticErrors); - - return diagnostics; + return this.languageService.getSyntacticDiagnostics(fileName).concat(this.languageService.getSemanticDiagnostics(fileName)); } private getAllDiagnostics(): ts.Diagnostic[] { - const diagnostics: ts.Diagnostic[] = []; - - for (const fileName of this.languageServiceAdapterHost.getFilenames()) { - diagnostics.push.apply(this.getDiagnostics(fileName)); - } - - return diagnostics; + return ts.flatMap(this.languageServiceAdapterHost.getFilenames(), fileName => this.getDiagnostics(fileName)); } public verifyErrorExistsAfterMarker(markerName: string, negative: boolean, after: boolean) { @@ -2276,23 +2263,22 @@ namespace FourSlash { } /** - * Compares expected text to the text that would be in the sole range - * (ie: [|...|]) in the file after applying the codefix sole codefix - * in the source file. - * - * Because codefixes are only applied on the working file, it is unsafe - * to apply this more than once (consider a refactoring across files). + * Finds and applies a code action corresponding to the supplied parameters. + * If index is undefined, applies the unique code action available. + * @param errorCode The error code that generated the code action. + * @param index The nth (0-index-based) codeaction available generated by errorCode. */ - public verifyRangeAfterCodeFix(expectedText: string, includeWhiteSpace?: boolean, errorCode?: number, index?: number) { + public getAndApplyCodeActions(errorCode?: number, index?: number) { + const fileName = this.activeFile.fileName; + this.applyCodeActions(this.getCodeFixActions(fileName, errorCode), index); + } + + public verifyRangeIs(expectedText: string, includeWhiteSpace?: boolean) { const ranges = this.getRanges(); if (ranges.length !== 1) { this.raiseError("Exactly one range should be specified in the testfile."); } - const fileName = this.activeFile.fileName; - - this.applyCodeAction(fileName, this.getCodeFixActions(fileName, errorCode), index); - const actualText = this.rangeText(ranges[0]); const result = includeWhiteSpace @@ -2304,6 +2290,16 @@ namespace FourSlash { } } + /** + * Compares expected text to the text that would be in the sole range + * (ie: [|...|]) in the file after applying the codefix sole codefix + * in the source file. + */ + public verifyRangeAfterCodeFix(expectedText: string, includeWhiteSpace?: boolean, errorCode?: number, index?: number) { + this.getAndApplyCodeActions(errorCode, index); + this.verifyRangeIs(expectedText, includeWhiteSpace); + } + /** * Applies fixes for the errors in fileName and compares the results to * expectedContents after all fixes have been applied. @@ -2316,7 +2312,7 @@ namespace FourSlash { public verifyFileAfterCodeFix(expectedContents: string, fileName?: string) { fileName = fileName ? fileName : this.activeFile.fileName; - this.applyCodeAction(fileName, this.getCodeFixActions(fileName)); + this.applyCodeActions(this.getCodeFixActions(fileName)); const actualContents: string = this.getFileContent(fileName); if (this.removeWhitespace(actualContents) !== this.removeWhitespace(expectedContents)) { @@ -2354,11 +2350,10 @@ namespace FourSlash { return actions; } - private applyCodeAction(fileName: string, actions: ts.CodeAction[], index?: number): void { + private applyCodeActions(actions: ts.CodeAction[], index?: number): void { if (index === undefined) { if (!(actions && actions.length === 1)) { - const actionText = (actions && actions.length) ? JSON.stringify(actions) : "none"; - this.raiseError(`Should find exactly one codefix, but found ${actionText}`); + this.raiseError(`Should find exactly one codefix, but ${actions ? actions.length : "none"} found.`); } index = 0; } @@ -2368,12 +2363,11 @@ namespace FourSlash { } } - const fileChanges = ts.find(actions[index].changes, change => change.fileName === fileName); - if (!fileChanges) { - this.raiseError("The CodeFix found doesn't provide any changes in this file."); - } + const changes = actions[index].changes; - this.applyEdits(fileChanges.fileName, fileChanges.textChanges, /*isFormattingEdit*/ false); + for (const change of changes) { + this.applyEdits(change.fileName, change.textChanges, /*isFormattingEdit*/ false); + } } public verifyImportFixAtPosition(expectedTextArray: string[], errorCode?: number) { @@ -2385,7 +2379,10 @@ namespace FourSlash { const codeFixes = this.getCodeFixActions(this.activeFile.fileName, errorCode); if (!codeFixes || codeFixes.length === 0) { - this.raiseError("No codefixes returned."); + if (expectedTextArray.length !== 0) { + this.raiseError("No codefixes returned."); + } + return; } const actualTextArray: string[] = []; @@ -2758,7 +2755,7 @@ namespace FourSlash { const codeActions = this.languageService.getRefactorCodeActions(this.activeFile.fileName, formattingOptions, markerPos, refactorNameToApply); - this.applyCodeAction(this.activeFile.fileName, codeActions); + this.applyCodeActions(codeActions); const actualContent = this.getFileContent(this.activeFile.fileName); if (this.normalizeNewlines(actualContent) !== this.normalizeNewlines(expectedContent)) { @@ -3805,6 +3802,14 @@ namespace FourSlashInterface { this.state.verifyFileAfterApplyingRefactorAtMarker(markerName, expectedContent, refactorNameToApply, formattingOptions); } + public rangeIs(expectedText: string, includeWhiteSpace?: boolean): void { + this.state.verifyRangeIs(expectedText, includeWhiteSpace); + } + + public getAndApplyCodeFix(errorCode?: number, index?: number): void { + this.state.getAndApplyCodeActions(errorCode, index); + } + public importFixAtPosition(expectedTextArray: string[], errorCode?: number): void { this.state.verifyImportFixAtPosition(expectedTextArray, errorCode); } 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/loggedIO.ts b/src/harness/loggedIO.ts index eeb47f0cfa03c..76f585b623a12 100644 --- a/src/harness/loggedIO.ts +++ b/src/harness/loggedIO.ts @@ -232,14 +232,11 @@ namespace Playback { // different entry). // TODO (yuisu): We can certainly remove these once we recapture the RWC using new API const normalizedPath = ts.normalizePath(path).toLowerCase(); - const result: string[] = []; - for (const directory of replayLog.directoriesRead) { + return ts.flatMap(replayLog.directoriesRead, directory => { if (ts.normalizeSlashes(directory.path).toLowerCase() === normalizedPath) { - result.push(...directory.result); + return directory.result; } - } - - return result; + }); }); wrapper.writeFile = recordReplay(wrapper.writeFile, underlying)( 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/harness/unittests/telemetry.ts b/src/harness/unittests/telemetry.ts index d3811edf25196..f250c732c0b71 100644 --- a/src/harness/unittests/telemetry.ts +++ b/src/harness/unittests/telemetry.ts @@ -252,7 +252,8 @@ namespace ts.projectSystem { } getEvent(eventName: T["eventName"], mayBeMore = false): T["data"] { - if (mayBeMore) assert(this.events.length !== 0); else assert.equal(this.events.length, 1); + if (mayBeMore) { assert(this.events.length !== 0); } + else { assert.equal(this.events.length, 1); } const event = this.events.shift(); assert.equal(event.eventName, eventName); return event.data; diff --git a/src/harness/unittests/tsserverProjectSystem.ts b/src/harness/unittests/tsserverProjectSystem.ts index 6f898e7f4a66c..7a19aa9167f05 100644 --- a/src/harness/unittests/tsserverProjectSystem.ts +++ b/src/harness/unittests/tsserverProjectSystem.ts @@ -13,7 +13,8 @@ namespace ts.projectSystem { express: "express", jquery: "jquery", lodash: "lodash", - moment: "moment" + moment: "moment", + chroma: "chroma-js" }) }; @@ -61,7 +62,6 @@ namespace ts.projectSystem { super(installTypingHost, globalTypingsCacheLocation, safeList.path, throttleLimit, log); } - safeFileList = safeList.path; protected postExecActions: PostExecAction[] = []; executePendingCommands() { diff --git a/src/harness/unittests/typingsInstaller.ts b/src/harness/unittests/typingsInstaller.ts index 699b180742860..c356d0941c02c 100644 --- a/src/harness/unittests/typingsInstaller.ts +++ b/src/harness/unittests/typingsInstaller.ts @@ -1009,6 +1009,26 @@ namespace ts.projectSystem { }); describe("discover typings", () => { + it("should use mappings from safe list", () => { + const app = { + path: "/a/b/app.js", + content: "" + }; + const jquery = { + path: "/a/b/jquery.js", + content: "" + }; + const chroma = { + path: "/a/b/chroma.min.js", + content: "" + }; + const cache = createMap(); + + const host = createServerHost([app, jquery, chroma]); + const result = JsTyping.discoverTypings(host, [app.path, jquery.path, chroma.path], getDirectoryPath(app.path), /*safeListPath*/ undefined, cache, { enable: true }, []); + assert.deepEqual(result.newTypingNames, ["jquery", "chroma-js"]); + }); + it("should return node for core modules", () => { const f = { path: "/a/b/app.js", @@ -1016,6 +1036,7 @@ namespace ts.projectSystem { }; const host = createServerHost([f]); const cache = createMap(); + for (const name of JsTyping.nodeCoreModuleList) { const result = JsTyping.discoverTypings(host, [f.path], getDirectoryPath(f.path), /*safeListPath*/ undefined, cache, { enable: true }, [name, "somename"]); assert.deepEqual(result.newTypingNames.sort(), ["node", "somename"]); @@ -1040,7 +1061,7 @@ namespace ts.projectSystem { }); describe("telemetry events", () => { - it ("should be received", () => { + it("should be received", () => { const f1 = { path: "/a/app.js", content: "" @@ -1089,7 +1110,7 @@ namespace ts.projectSystem { }); describe("progress notifications", () => { - it ("should be sent for success", () => { + it("should be sent for success", () => { const f1 = { path: "/a/app.js", content: "" @@ -1140,7 +1161,7 @@ namespace ts.projectSystem { checkProjectActualFiles(projectService.inferredProjects[0], [f1.path, commander.path]); }); - it ("should be sent for error", () => { + it("should be sent for error", () => { const f1 = { path: "/a/app.js", content: "" diff --git a/src/server/project.ts b/src/server/project.ts index 524b4d816e035..be854f948ea48 100644 --- a/src/server/project.ts +++ b/src/server/project.ts @@ -106,6 +106,7 @@ namespace ts.server { private rootFiles: ScriptInfo[] = []; private rootFilesMap: FileMap = createFileMap(); private program: ts.Program; + private externalFiles: SortedReadonlyArray; private cachedUnresolvedImportsPerFile = new UnresolvedImportsMap(); private lastCachedUnresolvedImportsList: SortedReadonlyArray; @@ -261,8 +262,8 @@ namespace ts.server { abstract getProjectRootPath(): string | undefined; abstract getTypeAcquisition(): TypeAcquisition; - getExternalFiles(): string[] { - return []; + getExternalFiles(): SortedReadonlyArray { + return emptyArray as SortedReadonlyArray; } getSourceFile(path: Path) { @@ -561,6 +562,24 @@ namespace ts.server { } } } + + const oldExternalFiles = this.externalFiles || emptyArray as SortedReadonlyArray; + this.externalFiles = this.getExternalFiles(); + enumerateInsertsAndDeletes(this.externalFiles, oldExternalFiles, + // Ensure a ScriptInfo is created for new external files. This is performed indirectly + // by the LSHost for files in the program when the program is retrieved above but + // the program doesn't contain external files so this must be done explicitly. + inserted => { + const scriptInfo = this.projectService.getOrCreateScriptInfo(inserted, /*openedByClient*/ false); + scriptInfo.attachToProject(this); + }, + removed => { + const scriptInfoToDetach = this.projectService.getScriptInfo(removed); + if (scriptInfoToDetach) { + scriptInfoToDetach.detachFromProject(this); + } + }); + return hasChanges; } @@ -956,19 +975,16 @@ namespace ts.server { return this.typeAcquisition; } - getExternalFiles(): string[] { - const items: string[] = []; - for (const plugin of this.plugins) { - if (typeof plugin.getExternalFiles === "function") { - try { - items.push(...plugin.getExternalFiles(this)); - } - catch (e) { - this.projectService.logger.info(`A plugin threw an exception in getExternalFiles: ${e}`); - } + getExternalFiles(): SortedReadonlyArray { + return toSortedReadonlyArray(flatMap(this.plugins, plugin => { + if (typeof plugin.getExternalFiles !== "function") return; + try { + return plugin.getExternalFiles(this); } - } - return items; + catch (e) { + this.projectService.logger.info(`A plugin threw an exception in getExternalFiles: ${e}`); + } + })); } watchConfigFile(callback: (project: ConfiguredProject) => void) { diff --git a/src/server/utilities.ts b/src/server/utilities.ts index 093958b60c55f..9e492601430f8 100644 --- a/src/server/utilities.ts +++ b/src/server/utilities.ts @@ -195,6 +195,37 @@ namespace ts.server { return arr; } + export function enumerateInsertsAndDeletes(a: SortedReadonlyArray, b: SortedReadonlyArray, inserted: (item: T) => void, deleted: (item: T) => void, compare?: (a: T, b: T) => Comparison) { + compare = compare || ts.compareValues; + let aIndex = 0; + let bIndex = 0; + const aLen = a.length; + const bLen = b.length; + while (aIndex < aLen && bIndex < bLen) { + const aItem = a[aIndex]; + const bItem = b[bIndex]; + const compareResult = compare(aItem, bItem); + if (compareResult === Comparison.LessThan) { + inserted(aItem); + aIndex++; + } + else if (compareResult === Comparison.GreaterThan) { + deleted(bItem); + bIndex++; + } + else { + aIndex++; + bIndex++; + } + } + while (aIndex < aLen) { + inserted(a[aIndex++]); + } + while (bIndex < bLen) { + deleted(b[bIndex++]); + } + } + export class ThrottledOperations { private pendingTimeouts: Map = createMap(); constructor(private readonly host: ServerHost) { diff --git a/src/services/codefixes/fixAddMissingMember.ts b/src/services/codefixes/fixAddMissingMember.ts index 64e7e56009478..1587b47c01b64 100644 --- a/src/services/codefixes/fixAddMissingMember.ts +++ b/src/services/codefixes/fixAddMissingMember.ts @@ -8,107 +8,161 @@ namespace ts.codefix { function getActionsForAddMissingMember(context: CodeFixContext): CodeAction[] | undefined { - const sourceFile = context.sourceFile; + const tokenSourceFile = context.sourceFile; const start = context.span.start; - // This is the identifier of the missing property. eg: + // The identifier of the missing property. eg: // this.missing = 1; // ^^^^^^^ - const token = getTokenAtPosition(sourceFile, start, /*includeJsDocComment*/ false); + const token = getTokenAtPosition(tokenSourceFile, start, /*includeJsDocComment*/ false); if (token.kind !== SyntaxKind.Identifier) { return undefined; } - if (!isPropertyAccessExpression(token.parent) || token.parent.expression.kind !== SyntaxKind.ThisKeyword) { + if (!isPropertyAccessExpression(token.parent)) { return undefined; } - const classMemberDeclaration = getThisContainer(token, /*includeArrowFunctions*/ false); - if (!isClassElement(classMemberDeclaration)) { - return undefined; + const tokenName = token.getText(tokenSourceFile); + + let makeStatic = false; + let classDeclaration: ClassLikeDeclaration; + + if (token.parent.expression.kind === SyntaxKind.ThisKeyword) { + const containingClassMemberDeclaration = getThisContainer(token, /*includeArrowFunctions*/ false); + if (!isClassElement(containingClassMemberDeclaration)) { + return undefined; + } + + classDeclaration = containingClassMemberDeclaration.parent; + + // Property accesses on `this` in a static method are accesses of a static member. + makeStatic = classDeclaration && hasModifier(containingClassMemberDeclaration, ModifierFlags.Static); + } + else { + + const checker = context.program.getTypeChecker(); + const leftExpression = token.parent.expression; + const leftExpressionType = checker.getTypeAtLocation(leftExpression); + + if (leftExpressionType.flags & TypeFlags.Object) { + const symbol = leftExpressionType.symbol; + if (symbol.flags & SymbolFlags.Class) { + classDeclaration = symbol.declarations && symbol.declarations[0]; + if (leftExpressionType !== checker.getDeclaredTypeOfSymbol(symbol)) { + // The expression is a class symbol but the type is not the instance-side. + makeStatic = true; + } + } + } } - const classDeclaration = classMemberDeclaration.parent; if (!classDeclaration || !isClassLike(classDeclaration)) { return undefined; } - const isStatic = hasModifier(classMemberDeclaration, ModifierFlags.Static); + const classDeclarationSourceFile = getSourceFileOfNode(classDeclaration); + const classOpenBrace = getOpenBraceOfClassLike(classDeclaration, classDeclarationSourceFile); + + return isInJavaScriptFile(classDeclarationSourceFile) ? + getActionsForAddMissingMemberInJavaScriptFile(classDeclaration, makeStatic) : + getActionsForAddMissingMemberInTypeScriptFile(classDeclaration, makeStatic); - return isInJavaScriptFile(sourceFile) ? getActionsForAddMissingMemberInJavaScriptFile() : getActionsForAddMissingMemberInTypeScriptFile(); + function getActionsForAddMissingMemberInJavaScriptFile(classDeclaration: ClassLikeDeclaration, makeStatic: boolean): CodeAction[] | undefined { + let actions: CodeAction[]; - function getActionsForAddMissingMemberInJavaScriptFile(): CodeAction[] | undefined { - const memberName = token.getText(); + const methodCodeAction = getActionForMethodDeclaration(/*includeTypeScriptSyntax*/ false); + if (methodCodeAction) { + actions = [methodCodeAction]; + } - if (isStatic) { + if (makeStatic) { if (classDeclaration.kind === SyntaxKind.ClassExpression) { - return undefined; + return actions; } const className = classDeclaration.name.getText(); - return [{ - description: formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Initialize_static_property_0), [memberName]), - changes: [{ - fileName: sourceFile.fileName, - textChanges: [{ - span: { start: classDeclaration.getEnd(), length: 0 }, - newText: `${context.newLineCharacter}${className}.${memberName} = undefined;${context.newLineCharacter}` - }] - }] - }]; - + const staticInitialization = createStatement(createAssignment( + createPropertyAccess(createIdentifier(className), tokenName), + createIdentifier("undefined"))); + + const staticInitializationChangeTracker = textChanges.ChangeTracker.fromCodeFixContext(context); + staticInitializationChangeTracker.insertNodeAfter( + classDeclarationSourceFile, + classDeclaration, + staticInitialization, + { suffix: context.newLineCharacter }); + const initializeStaticAction = { + description: formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Initialize_static_property_0), [tokenName]), + changes: staticInitializationChangeTracker.getChanges() + }; + + (actions || (actions = [])).push(initializeStaticAction); + return actions; } else { const classConstructor = getFirstConstructorWithBody(classDeclaration); if (!classConstructor) { - return undefined; + return actions; } - return [{ - description: formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Initialize_property_0_in_the_constructor), [memberName]), - changes: [{ - fileName: sourceFile.fileName, - textChanges: [{ - span: { start: classConstructor.body.getEnd() - 1, length: 0 }, - newText: `this.${memberName} = undefined;${context.newLineCharacter}` - }] - }] - }]; + const propertyInitialization = createStatement(createAssignment( + createPropertyAccess(createThis(), tokenName), + createIdentifier("undefined"))); + + const propertyInitializationChangeTracker = textChanges.ChangeTracker.fromCodeFixContext(context); + propertyInitializationChangeTracker.insertNodeAt( + classDeclarationSourceFile, + classConstructor.body.getEnd() - 1, + propertyInitialization, + { prefix: context.newLineCharacter, suffix: context.newLineCharacter }); + + const initializeAction = { + description: formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Initialize_property_0_in_the_constructor), [tokenName]), + changes: propertyInitializationChangeTracker.getChanges() + }; + + (actions || (actions = [])).push(initializeAction); + return actions; } } - function getActionsForAddMissingMemberInTypeScriptFile(): CodeAction[] | undefined { - let typeNode: TypeNode; + function getActionsForAddMissingMemberInTypeScriptFile(classDeclaration: ClassLikeDeclaration, makeStatic: boolean): CodeAction[] | undefined { + let actions: CodeAction[]; + const methodCodeAction = getActionForMethodDeclaration(/*includeTypeScriptSyntax*/ true); + if (methodCodeAction) { + actions = [methodCodeAction]; + } + + let typeNode: TypeNode; if (token.parent.parent.kind === SyntaxKind.BinaryExpression) { const binaryExpression = token.parent.parent as BinaryExpression; - + const otherExpression = token.parent === binaryExpression.left ? binaryExpression.right : binaryExpression.left; const checker = context.program.getTypeChecker(); - const widenedType = checker.getWidenedType(checker.getBaseTypeOfLiteralType(checker.getTypeAtLocation(binaryExpression.right))); + const widenedType = checker.getWidenedType(checker.getBaseTypeOfLiteralType(checker.getTypeAtLocation(otherExpression))); typeNode = checker.typeToTypeNode(widenedType, classDeclaration); } - typeNode = typeNode || createKeywordTypeNode(SyntaxKind.AnyKeyword); - const openBrace = getOpenBraceOfClassLike(classDeclaration, sourceFile); - const property = createProperty( /*decorators*/undefined, - /*modifiers*/ isStatic ? [createToken(SyntaxKind.StaticKeyword)] : undefined, - token.getText(sourceFile), + /*modifiers*/ makeStatic ? [createToken(SyntaxKind.StaticKeyword)] : undefined, + tokenName, /*questionToken*/ undefined, typeNode, /*initializer*/ undefined); const propertyChangeTracker = textChanges.ChangeTracker.fromCodeFixContext(context); - propertyChangeTracker.insertNodeAfter(sourceFile, openBrace, property, { suffix: context.newLineCharacter }); + propertyChangeTracker.insertNodeAfter(classDeclarationSourceFile, classOpenBrace, property, { suffix: context.newLineCharacter }); - const actions = [{ - description: formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Add_declaration_for_missing_property_0), [token.getText()]), + (actions || (actions = [])).push({ + description: formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Declare_property_0), [tokenName]), changes: propertyChangeTracker.getChanges() - }]; + }); - if (!isStatic) { + if (!makeStatic) { + // Index signatures cannot have the static modifier. const stringTypeNode = createKeywordTypeNode(SyntaxKind.StringKeyword); const indexingParameter = createParameter( /*decorators*/ undefined, @@ -125,15 +179,32 @@ namespace ts.codefix { typeNode); const indexSignatureChangeTracker = textChanges.ChangeTracker.fromCodeFixContext(context); - indexSignatureChangeTracker.insertNodeAfter(sourceFile, openBrace, indexSignature, { suffix: context.newLineCharacter }); + indexSignatureChangeTracker.insertNodeAfter(classDeclarationSourceFile, classOpenBrace, indexSignature, { suffix: context.newLineCharacter }); actions.push({ - description: formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Add_index_signature_for_missing_property_0), [token.getText()]), + description: formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Add_index_signature_for_property_0), [tokenName]), changes: indexSignatureChangeTracker.getChanges() }); } return actions; } + + function getActionForMethodDeclaration(includeTypeScriptSyntax: boolean): CodeAction | undefined { + if (token.parent.parent.kind === SyntaxKind.CallExpression) { + const callExpression = token.parent.parent; + const methodDeclaration = createMethodFromCallExpression(callExpression, tokenName, includeTypeScriptSyntax, makeStatic); + + const methodDeclarationChangeTracker = textChanges.ChangeTracker.fromCodeFixContext(context); + methodDeclarationChangeTracker.insertNodeAfter(classDeclarationSourceFile, classOpenBrace, methodDeclaration, { suffix: context.newLineCharacter }); + return { + description: formatStringFromArgs(getLocaleSpecificMessage(makeStatic ? + Diagnostics.Declare_method_0 : + Diagnostics.Declare_static_method_0), + [tokenName]), + changes: methodDeclarationChangeTracker.getChanges() + }; + } + } } } diff --git a/src/services/codefixes/helpers.ts b/src/services/codefixes/helpers.ts index 39d8e13dde9f6..81aae4c0e5e3a 100644 --- a/src/services/codefixes/helpers.ts +++ b/src/services/codefixes/helpers.ts @@ -142,6 +142,50 @@ namespace ts.codefix { } } + export function createMethodFromCallExpression(callExpression: CallExpression, methodName: string, includeTypeScriptSyntax: boolean, makeStatic: boolean): MethodDeclaration { + const parameters = createDummyParameters(callExpression.arguments.length, /*names*/ undefined, /*minArgumentCount*/ undefined, includeTypeScriptSyntax); + + let typeParameters: TypeParameterDeclaration[]; + if (includeTypeScriptSyntax) { + const typeArgCount = length(callExpression.typeArguments); + for (let i = 0; i < typeArgCount; i++) { + const name = typeArgCount < 8 ? String.fromCharCode(CharacterCodes.T + i) : `T${i}`; + const typeParameter = createTypeParameterDeclaration(name, /*constraint*/ undefined, /*defaultType*/ undefined); + (typeParameters ? typeParameters : typeParameters = []).push(typeParameter); + } + } + + const newMethod = createMethod( + /*decorators*/ undefined, + /*modifiers*/ makeStatic ? [createToken(SyntaxKind.StaticKeyword)] : undefined, + /*asteriskToken*/ undefined, + methodName, + /*questionToken*/ undefined, + typeParameters, + parameters, + /*type*/ includeTypeScriptSyntax ? createKeywordTypeNode(SyntaxKind.AnyKeyword) : undefined, + createStubbedMethodBody() + ); + return newMethod; + } + + function createDummyParameters(argCount: number, names: string[] | undefined, minArgumentCount: number | undefined, addAnyType: boolean) { + const parameters: ParameterDeclaration[] = []; + for (let i = 0; i < argCount; i++) { + const newParameter = createParameter( + /*decorators*/ undefined, + /*modifiers*/ undefined, + /*dotDotDotToken*/ undefined, + /*name*/ names && names[i] || `arg${i}`, + /*questionToken*/ minArgumentCount !== undefined && i >= minArgumentCount ? createToken(SyntaxKind.QuestionToken) : undefined, + /*type*/ addAnyType ? createKeywordTypeNode(SyntaxKind.AnyKeyword) : undefined, + /*initializer*/ undefined); + parameters.push(newParameter); + } + + return parameters; + } + function createMethodImplementingSignatures(signatures: Signature[], name: PropertyName, optional: boolean, modifiers: Modifier[] | undefined): MethodDeclaration { /** This is *a* signature with the maximal number of arguments, * such that if there is a "maximal" signature without rest arguments, @@ -163,19 +207,7 @@ namespace ts.codefix { const maxNonRestArgs = maxArgsSignature.parameters.length - (maxArgsSignature.hasRestParameter ? 1 : 0); const maxArgsParameterSymbolNames = maxArgsSignature.parameters.map(symbol => symbol.getName()); - const parameters: ParameterDeclaration[] = []; - for (let i = 0; i < maxNonRestArgs; i++) { - const anyType = createKeywordTypeNode(SyntaxKind.AnyKeyword); - const newParameter = createParameter( - /*decorators*/ undefined, - /*modifiers*/ undefined, - /*dotDotDotToken*/ undefined, - maxArgsParameterSymbolNames[i], - /*questionToken*/ i >= minArgumentCount ? createToken(SyntaxKind.QuestionToken) : undefined, - anyType, - /*initializer*/ undefined); - parameters.push(newParameter); - } + const parameters = createDummyParameters(maxNonRestArgs, maxArgsParameterSymbolNames, minArgumentCount, /*addAnyType*/ true); if (someSigHasRestParameter) { const anyArrayType = createArrayTypeNode(createKeywordTypeNode(SyntaxKind.AnyKeyword)); diff --git a/src/services/codefixes/importFixes.ts b/src/services/codefixes/importFixes.ts index 53ec99fac81a4..c2d26da4392d1 100644 --- a/src/services/codefixes/importFixes.ts +++ b/src/services/codefixes/importFixes.ts @@ -138,8 +138,23 @@ namespace ts.codefix { const currentTokenMeaning = getMeaningFromLocation(token); if (context.errorCode === Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead.code) { - const symbol = checker.getAliasedSymbol(checker.getSymbolAtLocation(token)); - return getCodeActionForImport(symbol, /*isDefault*/ false, /*isNamespaceImport*/ true); + const umdSymbol = checker.getSymbolAtLocation(token); + let symbol: ts.Symbol; + let symbolName: string; + if (umdSymbol.flags & ts.SymbolFlags.Alias) { + symbol = checker.getAliasedSymbol(umdSymbol); + symbolName = name; + } + else if (isJsxOpeningLikeElement(token.parent) && token.parent.tagName === token) { + // The error wasn't for the symbolAtLocation, it was for the JSX tag itself, which needs access to e.g. `React`. + symbol = checker.getAliasedSymbol(checker.resolveNameAtLocation(token, checker.getJsxNamespace(), SymbolFlags.Value)); + symbolName = symbol.name; + } + else { + Debug.fail("Either the symbol or the JSX namespace should be a UMD global if we got here"); + } + + return getCodeActionForImport(symbol, symbolName, /*isDefault*/ false, /*isNamespaceImport*/ true); } const candidateModules = checker.getAmbientModules(); @@ -159,7 +174,7 @@ namespace ts.codefix { if (localSymbol && localSymbol.name === name && checkSymbolHasMeaning(localSymbol, currentTokenMeaning)) { // check if this symbol is already used const symbolId = getUniqueSymbolId(localSymbol); - symbolIdActionMap.addActions(symbolId, getCodeActionForImport(moduleSymbol, /*isDefault*/ true)); + symbolIdActionMap.addActions(symbolId, getCodeActionForImport(moduleSymbol, name, /*isDefault*/ true)); } } @@ -167,7 +182,7 @@ namespace ts.codefix { const exportSymbolWithIdenticalName = checker.tryGetMemberInModuleExports(name, moduleSymbol); if (exportSymbolWithIdenticalName && checkSymbolHasMeaning(exportSymbolWithIdenticalName, currentTokenMeaning)) { const symbolId = getUniqueSymbolId(exportSymbolWithIdenticalName); - symbolIdActionMap.addActions(symbolId, getCodeActionForImport(moduleSymbol)); + symbolIdActionMap.addActions(symbolId, getCodeActionForImport(moduleSymbol, name)); } } @@ -218,7 +233,7 @@ namespace ts.codefix { return declarations ? some(symbol.declarations, decl => !!(getMeaningFromDeclaration(decl) & meaning)) : false; } - function getCodeActionForImport(moduleSymbol: Symbol, isDefault?: boolean, isNamespaceImport?: boolean): ImportCodeAction[] { + function getCodeActionForImport(moduleSymbol: Symbol, symbolName: string, isDefault?: boolean, isNamespaceImport?: boolean): ImportCodeAction[] { const existingDeclarations = getImportDeclarations(moduleSymbol); if (existingDeclarations.length > 0) { // With an existing import statement, there are more than one actions the user can do. @@ -375,10 +390,10 @@ namespace ts.codefix { const moduleSpecifierWithoutQuotes = stripQuotes(moduleSpecifier || getModuleSpecifierForNewImport()); const changeTracker = createChangeTracker(); const importClause = isDefault - ? createImportClause(createIdentifier(name), /*namedBindings*/ undefined) + ? createImportClause(createIdentifier(symbolName), /*namedBindings*/ undefined) : isNamespaceImport - ? createImportClause(/*name*/ undefined, createNamespaceImport(createIdentifier(name))) - : createImportClause(/*name*/ undefined, createNamedImports([createImportSpecifier(/*propertyName*/ undefined, createIdentifier(name))])); + ? createImportClause(/*name*/ undefined, createNamespaceImport(createIdentifier(symbolName))) + : createImportClause(/*name*/ undefined, createNamedImports([createImportSpecifier(/*propertyName*/ undefined, createIdentifier(symbolName))])); const importDecl = createImportDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, importClause, createLiteral(moduleSpecifierWithoutQuotes)); if (!lastImportDeclaration) { changeTracker.insertNodeAt(sourceFile, sourceFile.getStart(), importDecl, { suffix: `${context.newLineCharacter}${context.newLineCharacter}` }); @@ -392,7 +407,7 @@ namespace ts.codefix { // are there are already a new line seperating code and import statements. return createCodeAction( Diagnostics.Import_0_from_1, - [name, `"${moduleSpecifierWithoutQuotes}"`], + [symbolName, `"${moduleSpecifierWithoutQuotes}"`], changeTracker.getChanges(), "NewImport", moduleSpecifierWithoutQuotes @@ -412,8 +427,9 @@ namespace ts.codefix { removeFileExtension(getRelativePath(moduleFileName, sourceDirectory)); function tryGetModuleNameFromAmbientModule(): string { - if (moduleSymbol.valueDeclaration.kind !== SyntaxKind.SourceFile) { - return moduleSymbol.name; + const decl = moduleSymbol.valueDeclaration; + if (isModuleDeclaration(decl) && isStringLiteral(decl.name)) { + return decl.name.text; } } diff --git a/src/services/completions.ts b/src/services/completions.ts index a895be8a7da11..71fe4ce1c781b 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -20,6 +20,22 @@ namespace ts.Completions { const { symbols, isGlobalCompletion, isMemberCompletion, isNewIdentifierLocation, location, requestJsDocTagName, requestJsDocTag, hasFilteredClassMemberKeywords } = completionData; + if (sourceFile.languageVariant === LanguageVariant.JSX && + location && location.parent && location.parent.kind === SyntaxKind.JsxClosingElement) { + // In the TypeScript JSX element, if such element is not defined. When users query for completion at closing tag, + // instead of simply giving unknown value, the completion will return the tag-name of an associated opening-element. + // For example: + // var x =
completion list at "1" will contain "div" with type any + const tagName = (location.parent.parent).openingElement.tagName; + return { isGlobalCompletion: false, isMemberCompletion: true, isNewIdentifierLocation: false, + entries: [{ + name: (tagName).getFullText(), + kind: ScriptElementKind.classElement, + kindModifiers: undefined, + sortText: "0", + }]}; + } + if (requestJsDocTagName) { // If the current position is a jsDoc tag name, only tag names should be provided for completion return { isGlobalCompletion: false, isMemberCompletion: false, isNewIdentifierLocation: false, entries: JsDoc.getJSDocTagNameCompletions() }; @@ -38,21 +54,7 @@ namespace ts.Completions { } else { if (!symbols || symbols.length === 0) { - if (sourceFile.languageVariant === LanguageVariant.JSX && - location.parent && location.parent.kind === SyntaxKind.JsxClosingElement) { - // In the TypeScript JSX element, if such element is not defined. When users query for completion at closing tag, - // instead of simply giving unknown value, the completion will return the tag-name of an associated opening-element. - // For example: - // var x =
completion list at "1" will contain "div" with type any - const tagName = (location.parent.parent).openingElement.tagName; - entries.push({ - name: (tagName).text, - kind: undefined, - kindModifiers: undefined, - sortText: "0", - }); - } - else if (!hasFilteredClassMemberKeywords) { + if (!hasFilteredClassMemberKeywords) { return undefined; } } @@ -495,7 +497,7 @@ namespace ts.Completions { // It has a left-hand side, so we're not in an opening JSX tag. break; } - // falls through + // falls through case SyntaxKind.JsxSelfClosingElement: case SyntaxKind.JsxElement: @@ -1050,7 +1052,7 @@ namespace ts.Completions { default: if (isFromClassElementDeclaration(contextToken) && (isClassMemberCompletionKeyword(contextToken.kind) || - isClassMemberCompletionKeywordText(contextToken.getText()))) { + isClassMemberCompletionKeywordText(contextToken.getText()))) { return contextToken.parent.parent as ClassLikeDeclaration; } } @@ -1213,7 +1215,7 @@ namespace ts.Completions { if (isFromClassElementDeclaration(contextToken)) { return false; } - // falls through + // falls through case SyntaxKind.ClassKeyword: case SyntaxKind.EnumKeyword: case SyntaxKind.InterfaceKeyword: diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index df499cbd38a42..c1a7408fae710 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -185,7 +185,8 @@ namespace ts.FindAllReferences { if (entry.type === "node") { const { node } = entry; return { textSpan: getTextSpan(node), fileName: node.getSourceFile().fileName, ...implementationKindDisplayParts(node, checker) }; - } else { + } + else { const { textSpan, fileName } = entry; return { textSpan, fileName, kind: ScriptElementKind.unknown, displayParts: [] }; } diff --git a/src/services/importTracker.ts b/src/services/importTracker.ts index f20c80c14ef96..585af7ebd31aa 100644 --- a/src/services/importTracker.ts +++ b/src/services/importTracker.ts @@ -530,7 +530,8 @@ namespace ts.FindAllReferences { if (parent.kind === SyntaxKind.VariableDeclaration) { const p = parent as ts.VariableDeclaration; return p.parent.kind === ts.SyntaxKind.CatchClause ? undefined : p.parent.parent.kind === SyntaxKind.VariableStatement ? p.parent.parent : undefined; - } else { + } + else { return parent; } } diff --git a/src/services/jsTyping.ts b/src/services/jsTyping.ts index f601c9604de24..5e31d6a0190f0 100644 --- a/src/services/jsTyping.ts +++ b/src/services/jsTyping.ts @@ -143,7 +143,7 @@ namespace ts.JsTyping { /** * Merge a given list of typingNames to the inferredTypings map */ - function mergeTypings(typingNames: string[]) { + function mergeTypings(typingNames: ReadonlyArray) { if (!typingNames) { return; } @@ -192,7 +192,7 @@ namespace ts.JsTyping { const cleanedTypingNames = map(inferredTypingNames, f => f.replace(/((?:\.|-)min(?=\.|$))|((?:-|\.)\d+)/g, "")); if (safeList !== EmptySafeList) { - mergeTypings(filter(cleanedTypingNames, f => safeList.has(f))); + mergeTypings(ts.mapDefined(cleanedTypingNames, f => safeList.get(f))); } const hasJsxFile = forEach(fileNames, f => ensureScriptKind(f, getScriptKindFromFileName(f)) === ScriptKind.JSX); diff --git a/src/services/refactorProvider.ts b/src/services/refactorProvider.ts index 0b6ea3487ecdb..1058f9c2ca6b0 100644 --- a/src/services/refactorProvider.ts +++ b/src/services/refactorProvider.ts @@ -52,18 +52,8 @@ namespace ts { } export function getRefactorCodeActions(context: RefactorContext, refactorName: string): CodeAction[] | undefined { - - let result: CodeAction[]; const refactor = refactors.get(refactorName); - if (!refactor) { - return undefined; - } - - const codeActions = refactor.getCodeActions(context); - if (codeActions) { - addRange((result || (result = [])), codeActions); - } - return result; + return refactor && refactor.getCodeActions(context); } } } 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/blockScopedClassDeclarationAcrossFiles.js b/tests/baselines/reference/blockScopedClassDeclarationAcrossFiles.js new file mode 100644 index 0000000000000..b89943b24ff4e --- /dev/null +++ b/tests/baselines/reference/blockScopedClassDeclarationAcrossFiles.js @@ -0,0 +1,15 @@ +//// [tests/cases/compiler/blockScopedClassDeclarationAcrossFiles.ts] //// + +//// [c.ts] +let foo: typeof C; +//// [b.ts] +class C { } + + +//// [foo.js] +var foo; +var C = (function () { + function C() { + } + return C; +}()); diff --git a/tests/baselines/reference/blockScopedClassDeclarationAcrossFiles.symbols b/tests/baselines/reference/blockScopedClassDeclarationAcrossFiles.symbols new file mode 100644 index 0000000000000..c5c6e40da2078 --- /dev/null +++ b/tests/baselines/reference/blockScopedClassDeclarationAcrossFiles.symbols @@ -0,0 +1,9 @@ +=== tests/cases/compiler/c.ts === +let foo: typeof C; +>foo : Symbol(foo, Decl(c.ts, 0, 3)) +>C : Symbol(C, Decl(b.ts, 0, 0)) + +=== tests/cases/compiler/b.ts === +class C { } +>C : Symbol(C, Decl(b.ts, 0, 0)) + diff --git a/tests/baselines/reference/blockScopedClassDeclarationAcrossFiles.types b/tests/baselines/reference/blockScopedClassDeclarationAcrossFiles.types new file mode 100644 index 0000000000000..5bc8862b2aaad --- /dev/null +++ b/tests/baselines/reference/blockScopedClassDeclarationAcrossFiles.types @@ -0,0 +1,9 @@ +=== tests/cases/compiler/c.ts === +let foo: typeof C; +>foo : typeof C +>C : typeof C + +=== tests/cases/compiler/b.ts === +class C { } +>C : C + diff --git a/tests/baselines/reference/constructorFunctions.symbols b/tests/baselines/reference/constructorFunctions.symbols new file mode 100644 index 0000000000000..f55075794ab70 --- /dev/null +++ b/tests/baselines/reference/constructorFunctions.symbols @@ -0,0 +1,76 @@ +=== tests/cases/conformance/salsa/index.js === +function C1() { +>C1 : Symbol(C1, Decl(index.js, 0, 0)) + + if (!(this instanceof C1)) return new C1(); +>C1 : Symbol(C1, Decl(index.js, 0, 0)) +>C1 : Symbol(C1, Decl(index.js, 0, 0)) + + this.x = 1; +>x : Symbol(C1.x, Decl(index.js, 1, 47)) +} + +const c1_v1 = C1(); +>c1_v1 : Symbol(c1_v1, Decl(index.js, 5, 5)) +>C1 : Symbol(C1, Decl(index.js, 0, 0)) + +const c1_v2 = new C1(); +>c1_v2 : Symbol(c1_v2, Decl(index.js, 6, 5)) +>C1 : Symbol(C1, Decl(index.js, 0, 0)) + +var C2 = function () { +>C2 : Symbol(C2, Decl(index.js, 8, 3)) + + if (!(this instanceof C2)) return new C2(); +>C2 : Symbol(C2, Decl(index.js, 8, 3)) +>C2 : Symbol(C2, Decl(index.js, 8, 3)) + + this.x = 1; +>x : Symbol(C2.x, Decl(index.js, 9, 47)) + +}; + +const c2_v1 = C2(); +>c2_v1 : Symbol(c2_v1, Decl(index.js, 13, 5)) +>C2 : Symbol(C2, Decl(index.js, 8, 3)) + +const c2_v2 = new C2(); +>c2_v2 : Symbol(c2_v2, Decl(index.js, 14, 5)) +>C2 : Symbol(C2, Decl(index.js, 8, 3)) + +/** @class */ +function C3() { +>C3 : Symbol(C3, Decl(index.js, 14, 23)) + + if (!(this instanceof C3)) return new C3(); +>C3 : Symbol(C3, Decl(index.js, 14, 23)) +>C3 : Symbol(C3, Decl(index.js, 14, 23)) + +}; + +const c3_v1 = C3(); +>c3_v1 : Symbol(c3_v1, Decl(index.js, 21, 5)) +>C3 : Symbol(C3, Decl(index.js, 14, 23)) + +const c3_v2 = new C3(); +>c3_v2 : Symbol(c3_v2, Decl(index.js, 22, 5)) +>C3 : Symbol(C3, Decl(index.js, 14, 23)) + +/** @class */ +var C4 = function () { +>C4 : Symbol(C4, Decl(index.js, 25, 3)) + + if (!(this instanceof C4)) return new C4(); +>C4 : Symbol(C4, Decl(index.js, 25, 3)) +>C4 : Symbol(C4, Decl(index.js, 25, 3)) + +}; + +const c4_v1 = C4(); +>c4_v1 : Symbol(c4_v1, Decl(index.js, 29, 5)) +>C4 : Symbol(C4, Decl(index.js, 25, 3)) + +const c4_v2 = new C4(); +>c4_v2 : Symbol(c4_v2, Decl(index.js, 30, 5)) +>C4 : Symbol(C4, Decl(index.js, 25, 3)) + diff --git a/tests/baselines/reference/constructorFunctions.types b/tests/baselines/reference/constructorFunctions.types new file mode 100644 index 0000000000000..3429758b0170c --- /dev/null +++ b/tests/baselines/reference/constructorFunctions.types @@ -0,0 +1,114 @@ +=== tests/cases/conformance/salsa/index.js === +function C1() { +>C1 : () => typeof C1 + + if (!(this instanceof C1)) return new C1(); +>!(this instanceof C1) : boolean +>(this instanceof C1) : boolean +>this instanceof C1 : boolean +>this : any +>C1 : () => typeof C1 +>new C1() : { x: number; } +>C1 : () => typeof C1 + + this.x = 1; +>this.x = 1 : 1 +>this.x : any +>this : any +>x : any +>1 : 1 +} + +const c1_v1 = C1(); +>c1_v1 : { x: number; } +>C1() : { x: number; } +>C1 : () => typeof C1 + +const c1_v2 = new C1(); +>c1_v2 : { x: number; } +>new C1() : { x: number; } +>C1 : () => typeof C1 + +var C2 = function () { +>C2 : () => any +>function () { if (!(this instanceof C2)) return new C2(); this.x = 1;} : () => any + + if (!(this instanceof C2)) return new C2(); +>!(this instanceof C2) : boolean +>(this instanceof C2) : boolean +>this instanceof C2 : boolean +>this : any +>C2 : () => any +>new C2() : { x: number; } +>C2 : () => any + + this.x = 1; +>this.x = 1 : 1 +>this.x : any +>this : any +>x : any +>1 : 1 + +}; + +const c2_v1 = C2(); +>c2_v1 : { x: number; } +>C2() : { x: number; } +>C2 : () => any + +const c2_v2 = new C2(); +>c2_v2 : { x: number; } +>new C2() : { x: number; } +>C2 : () => any + +/** @class */ +function C3() { +>C3 : () => typeof C3 + + if (!(this instanceof C3)) return new C3(); +>!(this instanceof C3) : boolean +>(this instanceof C3) : boolean +>this instanceof C3 : boolean +>this : any +>C3 : () => typeof C3 +>new C3() : {} +>C3 : () => typeof C3 + +}; + +const c3_v1 = C3(); +>c3_v1 : {} +>C3() : {} +>C3 : () => typeof C3 + +const c3_v2 = new C3(); +>c3_v2 : {} +>new C3() : {} +>C3 : () => typeof C3 + +/** @class */ +var C4 = function () { +>C4 : () => any +>function () { if (!(this instanceof C4)) return new C4();} : () => any + + if (!(this instanceof C4)) return new C4(); +>!(this instanceof C4) : boolean +>(this instanceof C4) : boolean +>this instanceof C4 : boolean +>this : any +>C4 : () => any +>new C4() : {} +>C4 : () => any + +}; + +const c4_v1 = C4(); +>c4_v1 : {} +>C4() : {} +>C4 : () => any + +const c4_v2 = new C4(); +>c4_v2 : {} +>new C4() : {} +>C4 : () => any + diff --git a/tests/baselines/reference/contextualTypingWithGenericSignature.types b/tests/baselines/reference/contextualTypingWithGenericSignature.types index 68c5f3c422d72..e662f2c419252 100644 --- a/tests/baselines/reference/contextualTypingWithGenericSignature.types +++ b/tests/baselines/reference/contextualTypingWithGenericSignature.types @@ -16,10 +16,10 @@ var f2: { }; f2 = (x, y) => { return x } ->f2 = (x, y) => { return x } : (x: any, y: any) => any +>f2 = (x, y) => { return x } : (x: T, y: U) => T >f2 : (x: T, y: U) => T ->(x, y) => { return x } : (x: any, y: any) => any ->x : any ->y : any ->x : any +>(x, y) => { return x } : (x: T, y: U) => T +>x : T +>y : U +>x : T diff --git a/tests/baselines/reference/emitter.forAwait.es2017.js b/tests/baselines/reference/emitter.forAwait.es2017.js new file mode 100644 index 0000000000000..eb953781ab35d --- /dev/null +++ b/tests/baselines/reference/emitter.forAwait.es2017.js @@ -0,0 +1,143 @@ +//// [tests/cases/conformance/emitter/es2017/forAwait/emitter.forAwait.es2017.ts] //// + +//// [file1.ts] +async function f1() { + let y: any; + for await (const x of y) { + } +} +//// [file2.ts] +async function f2() { + let x: any, y: any; + for await (x of y) { + } +} +//// [file3.ts] +async function* f3() { + let y: any; + for await (const x of y) { + } +} +//// [file4.ts] +async function* f4() { + let x: any, y: any; + for await (x of y) { + } +} + +//// [file1.js] +var __asyncValues = (this && this.__asyncIterator) || function (o) { + if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); + var m = o[Symbol.asyncIterator]; + return m ? m.call(o) : typeof __values === "function" ? __values(o) : o[Symbol.iterator](); +}; +async function f1() { + let y; + try { + for (var y_1 = __asyncValues(y), y_1_1; y_1_1 = await y_1.next(), !y_1_1.done;) { + const x = await y_1_1.value; + } + } + catch (e_1_1) { e_1 = { error: e_1_1 }; } + finally { + try { + if (y_1_1 && !y_1_1.done && (_a = y_1.return)) await _a.call(y_1); + } + finally { if (e_1) throw e_1.error; } + } + var e_1, _a; +} +//// [file2.js] +var __asyncValues = (this && this.__asyncIterator) || function (o) { + if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); + var m = o[Symbol.asyncIterator]; + return m ? m.call(o) : typeof __values === "function" ? __values(o) : o[Symbol.iterator](); +}; +async function f2() { + let x, y; + try { + for (var y_1 = __asyncValues(y), y_1_1; y_1_1 = await y_1.next(), !y_1_1.done;) { + x = await y_1_1.value; + } + } + catch (e_1_1) { e_1 = { error: e_1_1 }; } + finally { + try { + if (y_1_1 && !y_1_1.done && (_a = y_1.return)) await _a.call(y_1); + } + finally { if (e_1) throw e_1.error; } + } + var e_1, _a; +} +//// [file3.js] +var __asyncValues = (this && this.__asyncIterator) || function (o) { + if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); + var m = o[Symbol.asyncIterator]; + return m ? m.call(o) : typeof __values === "function" ? __values(o) : o[Symbol.iterator](); +}; +var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); } +var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) { + if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); + var g = generator.apply(thisArg, _arguments || []), i, q = []; + return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i; + function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; } + function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } } + function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); } + function fulfill(value) { resume("next", value); } + function reject(value) { resume("throw", value); } + function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); } +}; +function f3() { + return __asyncGenerator(this, arguments, function* f3_1() { + let y; + try { + for (var y_1 = __asyncValues(y), y_1_1; y_1_1 = yield __await(y_1.next()), !y_1_1.done;) { + const x = yield __await(y_1_1.value); + } + } + catch (e_1_1) { e_1 = { error: e_1_1 }; } + finally { + try { + if (y_1_1 && !y_1_1.done && (_a = y_1.return)) yield __await(_a.call(y_1)); + } + finally { if (e_1) throw e_1.error; } + } + var e_1, _a; + }); +} +//// [file4.js] +var __asyncValues = (this && this.__asyncIterator) || function (o) { + if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); + var m = o[Symbol.asyncIterator]; + return m ? m.call(o) : typeof __values === "function" ? __values(o) : o[Symbol.iterator](); +}; +var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); } +var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) { + if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); + var g = generator.apply(thisArg, _arguments || []), i, q = []; + return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i; + function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; } + function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } } + function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); } + function fulfill(value) { resume("next", value); } + function reject(value) { resume("throw", value); } + function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); } +}; +function f4() { + return __asyncGenerator(this, arguments, function* f4_1() { + let x, y; + try { + for (var y_1 = __asyncValues(y), y_1_1; y_1_1 = yield __await(y_1.next()), !y_1_1.done;) { + x = yield __await(y_1_1.value); + } + } + catch (e_1_1) { e_1 = { error: e_1_1 }; } + finally { + try { + if (y_1_1 && !y_1_1.done && (_a = y_1.return)) yield __await(_a.call(y_1)); + } + finally { if (e_1) throw e_1.error; } + } + var e_1, _a; + }); +} diff --git a/tests/baselines/reference/emitter.forAwait.es2017.symbols b/tests/baselines/reference/emitter.forAwait.es2017.symbols new file mode 100644 index 0000000000000..a08e31f5553c0 --- /dev/null +++ b/tests/baselines/reference/emitter.forAwait.es2017.symbols @@ -0,0 +1,50 @@ +=== tests/cases/conformance/emitter/es2017/forAwait/file1.ts === +async function f1() { +>f1 : Symbol(f1, Decl(file1.ts, 0, 0)) + + let y: any; +>y : Symbol(y, Decl(file1.ts, 1, 7)) + + for await (const x of y) { +>x : Symbol(x, Decl(file1.ts, 2, 20)) +>y : Symbol(y, Decl(file1.ts, 1, 7)) + } +} +=== tests/cases/conformance/emitter/es2017/forAwait/file2.ts === +async function f2() { +>f2 : Symbol(f2, Decl(file2.ts, 0, 0)) + + let x: any, y: any; +>x : Symbol(x, Decl(file2.ts, 1, 7)) +>y : Symbol(y, Decl(file2.ts, 1, 15)) + + for await (x of y) { +>x : Symbol(x, Decl(file2.ts, 1, 7)) +>y : Symbol(y, Decl(file2.ts, 1, 15)) + } +} +=== tests/cases/conformance/emitter/es2017/forAwait/file3.ts === +async function* f3() { +>f3 : Symbol(f3, Decl(file3.ts, 0, 0)) + + let y: any; +>y : Symbol(y, Decl(file3.ts, 1, 7)) + + for await (const x of y) { +>x : Symbol(x, Decl(file3.ts, 2, 20)) +>y : Symbol(y, Decl(file3.ts, 1, 7)) + } +} +=== tests/cases/conformance/emitter/es2017/forAwait/file4.ts === +async function* f4() { +>f4 : Symbol(f4, Decl(file4.ts, 0, 0)) + + let x: any, y: any; +>x : Symbol(x, Decl(file4.ts, 1, 7)) +>y : Symbol(y, Decl(file4.ts, 1, 15)) + + for await (x of y) { +>x : Symbol(x, Decl(file4.ts, 1, 7)) +>y : Symbol(y, Decl(file4.ts, 1, 15)) + } +} diff --git a/tests/baselines/reference/emitter.forAwait.es2017.types b/tests/baselines/reference/emitter.forAwait.es2017.types new file mode 100644 index 0000000000000..0d886cca4cc58 --- /dev/null +++ b/tests/baselines/reference/emitter.forAwait.es2017.types @@ -0,0 +1,50 @@ +=== tests/cases/conformance/emitter/es2017/forAwait/file1.ts === +async function f1() { +>f1 : () => Promise + + let y: any; +>y : any + + for await (const x of y) { +>x : any +>y : any + } +} +=== tests/cases/conformance/emitter/es2017/forAwait/file2.ts === +async function f2() { +>f2 : () => Promise + + let x: any, y: any; +>x : any +>y : any + + for await (x of y) { +>x : any +>y : any + } +} +=== tests/cases/conformance/emitter/es2017/forAwait/file3.ts === +async function* f3() { +>f3 : () => AsyncIterableIterator + + let y: any; +>y : any + + for await (const x of y) { +>x : any +>y : any + } +} +=== tests/cases/conformance/emitter/es2017/forAwait/file4.ts === +async function* f4() { +>f4 : () => AsyncIterableIterator + + let x: any, y: any; +>x : any +>y : any + + for await (x of y) { +>x : any +>y : any + } +} diff --git a/tests/baselines/reference/exactSpellingSuggestion.errors.txt b/tests/baselines/reference/exactSpellingSuggestion.errors.txt new file mode 100644 index 0000000000000..dbe611590d4bc --- /dev/null +++ b/tests/baselines/reference/exactSpellingSuggestion.errors.txt @@ -0,0 +1,16 @@ +tests/cases/compiler/exactSpellingSuggestion.ts(9,4): error TS2551: Property 'bit_2' does not exist on type 'typeof U8'. Did you mean 'BIT_2'? + + +==== tests/cases/compiler/exactSpellingSuggestion.ts (1 errors) ==== + // Fixes #16245 -- always suggest the exact match, even when + // other options are very close + enum U8 { + BIT_0 = 1 << 0, + BIT_1 = 1 << 1, + BIT_2 = 1 << 2 + } + + U8.bit_2 + ~~~~~ +!!! error TS2551: Property 'bit_2' does not exist on type 'typeof U8'. Did you mean 'BIT_2'? + \ No newline at end of file diff --git a/tests/baselines/reference/exactSpellingSuggestion.js b/tests/baselines/reference/exactSpellingSuggestion.js new file mode 100644 index 0000000000000..7b71065061d41 --- /dev/null +++ b/tests/baselines/reference/exactSpellingSuggestion.js @@ -0,0 +1,22 @@ +//// [exactSpellingSuggestion.ts] +// Fixes #16245 -- always suggest the exact match, even when +// other options are very close +enum U8 { + BIT_0 = 1 << 0, + BIT_1 = 1 << 1, + BIT_2 = 1 << 2 +} + +U8.bit_2 + + +//// [exactSpellingSuggestion.js] +// Fixes #16245 -- always suggest the exact match, even when +// other options are very close +var U8; +(function (U8) { + U8[U8["BIT_0"] = 1] = "BIT_0"; + U8[U8["BIT_1"] = 2] = "BIT_1"; + U8[U8["BIT_2"] = 4] = "BIT_2"; +})(U8 || (U8 = {})); +U8.bit_2; diff --git a/tests/baselines/reference/genericContextualTypes1.js b/tests/baselines/reference/genericContextualTypes1.js new file mode 100644 index 0000000000000..9472412333081 --- /dev/null +++ b/tests/baselines/reference/genericContextualTypes1.js @@ -0,0 +1,107 @@ +//// [genericContextualTypes1.ts] +type Box = { value: T }; + +declare function wrap(f: (a: A) => B): (a: A) => B; + +declare function compose(f: (a: A) => B, g: (b: B) => C): (a: A) => C; + +declare function list(a: T): T[]; + +declare function unlist(a: T[]): T; + +declare function box(x: V): Box; + +declare function unbox(x: Box): W; + +declare function map(a: T[], f: (x: T) => U): U[]; + +declare function identity(x: T): T; + +declare function zip(a: A, b: B): [A, B]; + +declare function flip(f: (x: X, y: Y) => Z): (y: Y, x: X) => Z; + +const f00: (x: A) => A[] = list; +const f01: (x: A) => A[] = x => [x]; +const f02: (x: A) => A[] = wrap(list); +const f03: (x: A) => A[] = wrap(x => [x]); + +const f10: (x: T) => Box = compose(a => list(a), b => box(b)); +const f11: (x: T) => Box = compose(list, box); +const f12: (x: Box) => T = compose(a => unbox(a), b => unlist(b)); +const f13: (x: Box) => T = compose(unbox, unlist); + +const arrayMap = (f: (x: T) => U) => (a: T[]) => a.map(f); +const arrayFilter = (f: (x: T) => boolean) => (a: T[]) => a.filter(f); + +const f20: (a: string[]) => number[] = arrayMap(x => x.length); +const f21: (a: A[]) => A[][] = arrayMap(x => [x]); +const f22: (a: A[]) => A[] = arrayMap(identity); +const f23: (a: A[]) => Box[] = arrayMap(value => ({ value })); + +const f30: (a: string[]) => string[] = arrayFilter(x => x.length > 10); +const f31: >(a: T[]) => T[] = arrayFilter(x => x.value > 10); + +const f40: (b: B, a: A) => [A, B] = flip(zip); + +// Repro from #16293 + +type fn = (a: A) => A; +const fn: fn = a => a; + + +//// [genericContextualTypes1.js] +"use strict"; +var f00 = list; +var f01 = function (x) { return [x]; }; +var f02 = wrap(list); +var f03 = wrap(function (x) { return [x]; }); +var f10 = compose(function (a) { return list(a); }, function (b) { return box(b); }); +var f11 = compose(list, box); +var f12 = compose(function (a) { return unbox(a); }, function (b) { return unlist(b); }); +var f13 = compose(unbox, unlist); +var arrayMap = function (f) { return function (a) { return a.map(f); }; }; +var arrayFilter = function (f) { return function (a) { return a.filter(f); }; }; +var f20 = arrayMap(function (x) { return x.length; }); +var f21 = arrayMap(function (x) { return [x]; }); +var f22 = arrayMap(identity); +var f23 = arrayMap(function (value) { return ({ value: value }); }); +var f30 = arrayFilter(function (x) { return x.length > 10; }); +var f31 = arrayFilter(function (x) { return x.value > 10; }); +var f40 = flip(zip); +var fn = function (a) { return a; }; + + +//// [genericContextualTypes1.d.ts] +declare type Box = { + value: T; +}; +declare function wrap(f: (a: A) => B): (a: A) => B; +declare function compose(f: (a: A) => B, g: (b: B) => C): (a: A) => C; +declare function list(a: T): T[]; +declare function unlist(a: T[]): T; +declare function box(x: V): Box; +declare function unbox(x: Box): W; +declare function map(a: T[], f: (x: T) => U): U[]; +declare function identity(x: T): T; +declare function zip(a: A, b: B): [A, B]; +declare function flip(f: (x: X, y: Y) => Z): (y: Y, x: X) => Z; +declare const f00: (x: A) => A[]; +declare const f01: (x: A) => A[]; +declare const f02: (x: A) => A[]; +declare const f03: (x: A) => A[]; +declare const f10: (x: T) => Box; +declare const f11: (x: T) => Box; +declare const f12: (x: Box) => T; +declare const f13: (x: Box) => T; +declare const arrayMap: (f: (x: T) => U) => (a: T[]) => U[]; +declare const arrayFilter: (f: (x: T) => boolean) => (a: T[]) => T[]; +declare const f20: (a: string[]) => number[]; +declare const f21: (a: A[]) => A[][]; +declare const f22: (a: A[]) => A[]; +declare const f23: (a: A[]) => Box[]; +declare const f30: (a: string[]) => string[]; +declare const f31: >(a: T[]) => T[]; +declare const f40: (b: B, a: A) => [A, B]; +declare type fn = (a: A) => A; +declare const fn: fn; diff --git a/tests/baselines/reference/genericContextualTypes1.symbols b/tests/baselines/reference/genericContextualTypes1.symbols new file mode 100644 index 0000000000000..29d8766abca3a --- /dev/null +++ b/tests/baselines/reference/genericContextualTypes1.symbols @@ -0,0 +1,318 @@ +=== tests/cases/conformance/types/typeRelationships/typeInference/genericContextualTypes1.ts === +type Box = { value: T }; +>Box : Symbol(Box, Decl(genericContextualTypes1.ts, 0, 0)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 0, 9)) +>value : Symbol(value, Decl(genericContextualTypes1.ts, 0, 15)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 0, 9)) + +declare function wrap(f: (a: A) => B): (a: A) => B; +>wrap : Symbol(wrap, Decl(genericContextualTypes1.ts, 0, 27)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 2, 22)) +>B : Symbol(B, Decl(genericContextualTypes1.ts, 2, 24)) +>f : Symbol(f, Decl(genericContextualTypes1.ts, 2, 28)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 2, 32)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 2, 22)) +>B : Symbol(B, Decl(genericContextualTypes1.ts, 2, 24)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 2, 46)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 2, 22)) +>B : Symbol(B, Decl(genericContextualTypes1.ts, 2, 24)) + +declare function compose(f: (a: A) => B, g: (b: B) => C): (a: A) => C; +>compose : Symbol(compose, Decl(genericContextualTypes1.ts, 2, 57)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 4, 25)) +>B : Symbol(B, Decl(genericContextualTypes1.ts, 4, 27)) +>C : Symbol(C, Decl(genericContextualTypes1.ts, 4, 30)) +>f : Symbol(f, Decl(genericContextualTypes1.ts, 4, 34)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 4, 38)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 4, 25)) +>B : Symbol(B, Decl(genericContextualTypes1.ts, 4, 27)) +>g : Symbol(g, Decl(genericContextualTypes1.ts, 4, 49)) +>b : Symbol(b, Decl(genericContextualTypes1.ts, 4, 54)) +>B : Symbol(B, Decl(genericContextualTypes1.ts, 4, 27)) +>C : Symbol(C, Decl(genericContextualTypes1.ts, 4, 30)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 4, 68)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 4, 25)) +>C : Symbol(C, Decl(genericContextualTypes1.ts, 4, 30)) + +declare function list(a: T): T[]; +>list : Symbol(list, Decl(genericContextualTypes1.ts, 4, 79)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 6, 22)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 6, 25)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 6, 22)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 6, 22)) + +declare function unlist(a: T[]): T; +>unlist : Symbol(unlist, Decl(genericContextualTypes1.ts, 6, 36)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 8, 24)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 8, 27)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 8, 24)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 8, 24)) + +declare function box(x: V): Box; +>box : Symbol(box, Decl(genericContextualTypes1.ts, 8, 38)) +>V : Symbol(V, Decl(genericContextualTypes1.ts, 10, 21)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 10, 24)) +>V : Symbol(V, Decl(genericContextualTypes1.ts, 10, 21)) +>Box : Symbol(Box, Decl(genericContextualTypes1.ts, 0, 0)) +>V : Symbol(V, Decl(genericContextualTypes1.ts, 10, 21)) + +declare function unbox(x: Box): W; +>unbox : Symbol(unbox, Decl(genericContextualTypes1.ts, 10, 38)) +>W : Symbol(W, Decl(genericContextualTypes1.ts, 12, 23)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 12, 26)) +>Box : Symbol(Box, Decl(genericContextualTypes1.ts, 0, 0)) +>W : Symbol(W, Decl(genericContextualTypes1.ts, 12, 23)) +>W : Symbol(W, Decl(genericContextualTypes1.ts, 12, 23)) + +declare function map(a: T[], f: (x: T) => U): U[]; +>map : Symbol(map, Decl(genericContextualTypes1.ts, 12, 40)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 14, 21)) +>U : Symbol(U, Decl(genericContextualTypes1.ts, 14, 23)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 14, 27)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 14, 21)) +>f : Symbol(f, Decl(genericContextualTypes1.ts, 14, 34)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 14, 39)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 14, 21)) +>U : Symbol(U, Decl(genericContextualTypes1.ts, 14, 23)) +>U : Symbol(U, Decl(genericContextualTypes1.ts, 14, 23)) + +declare function identity(x: T): T; +>identity : Symbol(identity, Decl(genericContextualTypes1.ts, 14, 56)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 16, 26)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 16, 29)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 16, 26)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 16, 26)) + +declare function zip(a: A, b: B): [A, B]; +>zip : Symbol(zip, Decl(genericContextualTypes1.ts, 16, 38)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 18, 21)) +>B : Symbol(B, Decl(genericContextualTypes1.ts, 18, 23)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 18, 27)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 18, 21)) +>b : Symbol(b, Decl(genericContextualTypes1.ts, 18, 32)) +>B : Symbol(B, Decl(genericContextualTypes1.ts, 18, 23)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 18, 21)) +>B : Symbol(B, Decl(genericContextualTypes1.ts, 18, 23)) + +declare function flip(f: (x: X, y: Y) => Z): (y: Y, x: X) => Z; +>flip : Symbol(flip, Decl(genericContextualTypes1.ts, 18, 47)) +>X : Symbol(X, Decl(genericContextualTypes1.ts, 20, 22)) +>Y : Symbol(Y, Decl(genericContextualTypes1.ts, 20, 24)) +>Z : Symbol(Z, Decl(genericContextualTypes1.ts, 20, 27)) +>f : Symbol(f, Decl(genericContextualTypes1.ts, 20, 31)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 20, 35)) +>X : Symbol(X, Decl(genericContextualTypes1.ts, 20, 22)) +>y : Symbol(y, Decl(genericContextualTypes1.ts, 20, 40)) +>Y : Symbol(Y, Decl(genericContextualTypes1.ts, 20, 24)) +>Z : Symbol(Z, Decl(genericContextualTypes1.ts, 20, 27)) +>y : Symbol(y, Decl(genericContextualTypes1.ts, 20, 55)) +>Y : Symbol(Y, Decl(genericContextualTypes1.ts, 20, 24)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 20, 60)) +>X : Symbol(X, Decl(genericContextualTypes1.ts, 20, 22)) +>Z : Symbol(Z, Decl(genericContextualTypes1.ts, 20, 27)) + +const f00: (x: A) => A[] = list; +>f00 : Symbol(f00, Decl(genericContextualTypes1.ts, 22, 5)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 22, 12)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 22, 15)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 22, 12)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 22, 12)) +>list : Symbol(list, Decl(genericContextualTypes1.ts, 4, 79)) + +const f01: (x: A) => A[] = x => [x]; +>f01 : Symbol(f01, Decl(genericContextualTypes1.ts, 23, 5)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 23, 12)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 23, 15)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 23, 12)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 23, 12)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 23, 29)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 23, 29)) + +const f02: (x: A) => A[] = wrap(list); +>f02 : Symbol(f02, Decl(genericContextualTypes1.ts, 24, 5)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 24, 12)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 24, 15)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 24, 12)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 24, 12)) +>wrap : Symbol(wrap, Decl(genericContextualTypes1.ts, 0, 27)) +>list : Symbol(list, Decl(genericContextualTypes1.ts, 4, 79)) + +const f03: (x: A) => A[] = wrap(x => [x]); +>f03 : Symbol(f03, Decl(genericContextualTypes1.ts, 25, 5)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 25, 12)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 25, 15)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 25, 12)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 25, 12)) +>wrap : Symbol(wrap, Decl(genericContextualTypes1.ts, 0, 27)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 25, 35)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 25, 35)) + +const f10: (x: T) => Box = compose(a => list(a), b => box(b)); +>f10 : Symbol(f10, Decl(genericContextualTypes1.ts, 27, 5)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 27, 12)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 27, 15)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 27, 12)) +>Box : Symbol(Box, Decl(genericContextualTypes1.ts, 0, 0)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 27, 12)) +>compose : Symbol(compose, Decl(genericContextualTypes1.ts, 2, 57)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 27, 43)) +>list : Symbol(list, Decl(genericContextualTypes1.ts, 4, 79)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 27, 43)) +>b : Symbol(b, Decl(genericContextualTypes1.ts, 27, 56)) +>box : Symbol(box, Decl(genericContextualTypes1.ts, 8, 38)) +>b : Symbol(b, Decl(genericContextualTypes1.ts, 27, 56)) + +const f11: (x: T) => Box = compose(list, box); +>f11 : Symbol(f11, Decl(genericContextualTypes1.ts, 28, 5)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 28, 12)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 28, 15)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 28, 12)) +>Box : Symbol(Box, Decl(genericContextualTypes1.ts, 0, 0)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 28, 12)) +>compose : Symbol(compose, Decl(genericContextualTypes1.ts, 2, 57)) +>list : Symbol(list, Decl(genericContextualTypes1.ts, 4, 79)) +>box : Symbol(box, Decl(genericContextualTypes1.ts, 8, 38)) + +const f12: (x: Box) => T = compose(a => unbox(a), b => unlist(b)); +>f12 : Symbol(f12, Decl(genericContextualTypes1.ts, 29, 5)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 29, 12)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 29, 15)) +>Box : Symbol(Box, Decl(genericContextualTypes1.ts, 0, 0)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 29, 12)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 29, 12)) +>compose : Symbol(compose, Decl(genericContextualTypes1.ts, 2, 57)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 29, 43)) +>unbox : Symbol(unbox, Decl(genericContextualTypes1.ts, 10, 38)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 29, 43)) +>b : Symbol(b, Decl(genericContextualTypes1.ts, 29, 57)) +>unlist : Symbol(unlist, Decl(genericContextualTypes1.ts, 6, 36)) +>b : Symbol(b, Decl(genericContextualTypes1.ts, 29, 57)) + +const f13: (x: Box) => T = compose(unbox, unlist); +>f13 : Symbol(f13, Decl(genericContextualTypes1.ts, 30, 5)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 30, 12)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 30, 15)) +>Box : Symbol(Box, Decl(genericContextualTypes1.ts, 0, 0)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 30, 12)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 30, 12)) +>compose : Symbol(compose, Decl(genericContextualTypes1.ts, 2, 57)) +>unbox : Symbol(unbox, Decl(genericContextualTypes1.ts, 10, 38)) +>unlist : Symbol(unlist, Decl(genericContextualTypes1.ts, 6, 36)) + +const arrayMap = (f: (x: T) => U) => (a: T[]) => a.map(f); +>arrayMap : Symbol(arrayMap, Decl(genericContextualTypes1.ts, 32, 5)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 32, 18)) +>U : Symbol(U, Decl(genericContextualTypes1.ts, 32, 20)) +>f : Symbol(f, Decl(genericContextualTypes1.ts, 32, 24)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 32, 28)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 32, 18)) +>U : Symbol(U, Decl(genericContextualTypes1.ts, 32, 20)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 32, 44)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 32, 18)) +>a.map : Symbol(Array.map, Decl(lib.d.ts, --, --)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 32, 44)) +>map : Symbol(Array.map, Decl(lib.d.ts, --, --)) +>f : Symbol(f, Decl(genericContextualTypes1.ts, 32, 24)) + +const arrayFilter = (f: (x: T) => boolean) => (a: T[]) => a.filter(f); +>arrayFilter : Symbol(arrayFilter, Decl(genericContextualTypes1.ts, 33, 5)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 33, 21)) +>f : Symbol(f, Decl(genericContextualTypes1.ts, 33, 24)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 33, 28)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 33, 21)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 33, 50)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 33, 21)) +>a.filter : Symbol(Array.filter, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 33, 50)) +>filter : Symbol(Array.filter, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>f : Symbol(f, Decl(genericContextualTypes1.ts, 33, 24)) + +const f20: (a: string[]) => number[] = arrayMap(x => x.length); +>f20 : Symbol(f20, Decl(genericContextualTypes1.ts, 35, 5)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 35, 12)) +>arrayMap : Symbol(arrayMap, Decl(genericContextualTypes1.ts, 32, 5)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 35, 48)) +>x.length : Symbol(String.length, Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 35, 48)) +>length : Symbol(String.length, Decl(lib.d.ts, --, --)) + +const f21: (a: A[]) => A[][] = arrayMap(x => [x]); +>f21 : Symbol(f21, Decl(genericContextualTypes1.ts, 36, 5)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 36, 12)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 36, 15)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 36, 12)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 36, 12)) +>arrayMap : Symbol(arrayMap, Decl(genericContextualTypes1.ts, 32, 5)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 36, 43)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 36, 43)) + +const f22: (a: A[]) => A[] = arrayMap(identity); +>f22 : Symbol(f22, Decl(genericContextualTypes1.ts, 37, 5)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 37, 12)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 37, 15)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 37, 12)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 37, 12)) +>arrayMap : Symbol(arrayMap, Decl(genericContextualTypes1.ts, 32, 5)) +>identity : Symbol(identity, Decl(genericContextualTypes1.ts, 14, 56)) + +const f23: (a: A[]) => Box[] = arrayMap(value => ({ value })); +>f23 : Symbol(f23, Decl(genericContextualTypes1.ts, 38, 5)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 38, 12)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 38, 15)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 38, 12)) +>Box : Symbol(Box, Decl(genericContextualTypes1.ts, 0, 0)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 38, 12)) +>arrayMap : Symbol(arrayMap, Decl(genericContextualTypes1.ts, 32, 5)) +>value : Symbol(value, Decl(genericContextualTypes1.ts, 38, 46)) +>value : Symbol(value, Decl(genericContextualTypes1.ts, 38, 57)) + +const f30: (a: string[]) => string[] = arrayFilter(x => x.length > 10); +>f30 : Symbol(f30, Decl(genericContextualTypes1.ts, 40, 5)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 40, 12)) +>arrayFilter : Symbol(arrayFilter, Decl(genericContextualTypes1.ts, 33, 5)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 40, 51)) +>x.length : Symbol(String.length, Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 40, 51)) +>length : Symbol(String.length, Decl(lib.d.ts, --, --)) + +const f31: >(a: T[]) => T[] = arrayFilter(x => x.value > 10); +>f31 : Symbol(f31, Decl(genericContextualTypes1.ts, 41, 5)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 41, 12)) +>Box : Symbol(Box, Decl(genericContextualTypes1.ts, 0, 0)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 41, 35)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 41, 12)) +>T : Symbol(T, Decl(genericContextualTypes1.ts, 41, 12)) +>arrayFilter : Symbol(arrayFilter, Decl(genericContextualTypes1.ts, 33, 5)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 41, 64)) +>x.value : Symbol(value, Decl(genericContextualTypes1.ts, 0, 15)) +>x : Symbol(x, Decl(genericContextualTypes1.ts, 41, 64)) +>value : Symbol(value, Decl(genericContextualTypes1.ts, 0, 15)) + +const f40: (b: B, a: A) => [A, B] = flip(zip); +>f40 : Symbol(f40, Decl(genericContextualTypes1.ts, 43, 5)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 43, 12)) +>B : Symbol(B, Decl(genericContextualTypes1.ts, 43, 14)) +>b : Symbol(b, Decl(genericContextualTypes1.ts, 43, 18)) +>B : Symbol(B, Decl(genericContextualTypes1.ts, 43, 14)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 43, 23)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 43, 12)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 43, 12)) +>B : Symbol(B, Decl(genericContextualTypes1.ts, 43, 14)) +>flip : Symbol(flip, Decl(genericContextualTypes1.ts, 18, 47)) +>zip : Symbol(zip, Decl(genericContextualTypes1.ts, 16, 38)) + +// Repro from #16293 + +type fn = (a: A) => A; +>fn : Symbol(fn, Decl(genericContextualTypes1.ts, 43, 52), Decl(genericContextualTypes1.ts, 48, 5)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 47, 11)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 47, 14)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 47, 11)) +>A : Symbol(A, Decl(genericContextualTypes1.ts, 47, 11)) + +const fn: fn = a => a; +>fn : Symbol(fn, Decl(genericContextualTypes1.ts, 43, 52), Decl(genericContextualTypes1.ts, 48, 5)) +>fn : Symbol(fn, Decl(genericContextualTypes1.ts, 43, 52), Decl(genericContextualTypes1.ts, 48, 5)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 48, 14)) +>a : Symbol(a, Decl(genericContextualTypes1.ts, 48, 14)) + diff --git a/tests/baselines/reference/genericContextualTypes1.types b/tests/baselines/reference/genericContextualTypes1.types new file mode 100644 index 0000000000000..4aedcd6e81b22 --- /dev/null +++ b/tests/baselines/reference/genericContextualTypes1.types @@ -0,0 +1,362 @@ +=== tests/cases/conformance/types/typeRelationships/typeInference/genericContextualTypes1.ts === +type Box = { value: T }; +>Box : Box +>T : T +>value : T +>T : T + +declare function wrap(f: (a: A) => B): (a: A) => B; +>wrap : (f: (a: A) => B) => (a: A) => B +>A : A +>B : B +>f : (a: A) => B +>a : A +>A : A +>B : B +>a : A +>A : A +>B : B + +declare function compose(f: (a: A) => B, g: (b: B) => C): (a: A) => C; +>compose : (f: (a: A) => B, g: (b: B) => C) => (a: A) => C +>A : A +>B : B +>C : C +>f : (a: A) => B +>a : A +>A : A +>B : B +>g : (b: B) => C +>b : B +>B : B +>C : C +>a : A +>A : A +>C : C + +declare function list(a: T): T[]; +>list : (a: T) => T[] +>T : T +>a : T +>T : T +>T : T + +declare function unlist(a: T[]): T; +>unlist : (a: T[]) => T +>T : T +>a : T[] +>T : T +>T : T + +declare function box(x: V): Box; +>box : (x: V) => Box +>V : V +>x : V +>V : V +>Box : Box +>V : V + +declare function unbox(x: Box): W; +>unbox : (x: Box) => W +>W : W +>x : Box +>Box : Box +>W : W +>W : W + +declare function map(a: T[], f: (x: T) => U): U[]; +>map : (a: T[], f: (x: T) => U) => U[] +>T : T +>U : U +>a : T[] +>T : T +>f : (x: T) => U +>x : T +>T : T +>U : U +>U : U + +declare function identity(x: T): T; +>identity : (x: T) => T +>T : T +>x : T +>T : T +>T : T + +declare function zip(a: A, b: B): [A, B]; +>zip : (a: A, b: B) => [A, B] +>A : A +>B : B +>a : A +>A : A +>b : B +>B : B +>A : A +>B : B + +declare function flip(f: (x: X, y: Y) => Z): (y: Y, x: X) => Z; +>flip : (f: (x: X, y: Y) => Z) => (y: Y, x: X) => Z +>X : X +>Y : Y +>Z : Z +>f : (x: X, y: Y) => Z +>x : X +>X : X +>y : Y +>Y : Y +>Z : Z +>y : Y +>Y : Y +>x : X +>X : X +>Z : Z + +const f00: (x: A) => A[] = list; +>f00 : (x: A) => A[] +>A : A +>x : A +>A : A +>A : A +>list : (a: T) => T[] + +const f01: (x: A) => A[] = x => [x]; +>f01 : (x: A) => A[] +>A : A +>x : A +>A : A +>A : A +>x => [x] : (x: A) => A[] +>x : A +>[x] : A[] +>x : A + +const f02: (x: A) => A[] = wrap(list); +>f02 : (x: A) => A[] +>A : A +>x : A +>A : A +>A : A +>wrap(list) : (a: A) => A[] +>wrap : (f: (a: A) => B) => (a: A) => B +>list : (a: T) => T[] + +const f03: (x: A) => A[] = wrap(x => [x]); +>f03 : (x: A) => A[] +>A : A +>x : A +>A : A +>A : A +>wrap(x => [x]) : (a: A) => A[] +>wrap : (f: (a: A) => B) => (a: A) => B +>x => [x] : (x: A) => A[] +>x : A +>[x] : A[] +>x : A + +const f10: (x: T) => Box = compose(a => list(a), b => box(b)); +>f10 : (x: T) => Box +>T : T +>x : T +>T : T +>Box : Box +>T : T +>compose(a => list(a), b => box(b)) : (a: T) => Box +>compose : (f: (a: A) => B, g: (b: B) => C) => (a: A) => C +>a => list(a) : (a: T) => T[] +>a : T +>list(a) : T[] +>list : (a: T) => T[] +>a : T +>b => box(b) : (b: T[]) => Box +>b : T[] +>box(b) : Box +>box : (x: V) => Box +>b : T[] + +const f11: (x: T) => Box = compose(list, box); +>f11 : (x: T) => Box +>T : T +>x : T +>T : T +>Box : Box +>T : T +>compose(list, box) : (a: T) => Box +>compose : (f: (a: A) => B, g: (b: B) => C) => (a: A) => C +>list : (a: T) => T[] +>box : (x: V) => Box + +const f12: (x: Box) => T = compose(a => unbox(a), b => unlist(b)); +>f12 : (x: Box) => T +>T : T +>x : Box +>Box : Box +>T : T +>T : T +>compose(a => unbox(a), b => unlist(b)) : (a: Box) => T +>compose : (f: (a: A) => B, g: (b: B) => C) => (a: A) => C +>a => unbox(a) : (a: Box) => T[] +>a : Box +>unbox(a) : T[] +>unbox : (x: Box) => W +>a : Box +>b => unlist(b) : (b: T[]) => T +>b : T[] +>unlist(b) : T +>unlist : (a: T[]) => T +>b : T[] + +const f13: (x: Box) => T = compose(unbox, unlist); +>f13 : (x: Box) => T +>T : T +>x : Box +>Box : Box +>T : T +>T : T +>compose(unbox, unlist) : (a: Box) => T +>compose : (f: (a: A) => B, g: (b: B) => C) => (a: A) => C +>unbox : (x: Box) => W +>unlist : (a: T[]) => T + +const arrayMap = (f: (x: T) => U) => (a: T[]) => a.map(f); +>arrayMap : (f: (x: T) => U) => (a: T[]) => U[] +>(f: (x: T) => U) => (a: T[]) => a.map(f) : (f: (x: T) => U) => (a: T[]) => U[] +>T : T +>U : U +>f : (x: T) => U +>x : T +>T : T +>U : U +>(a: T[]) => a.map(f) : (a: T[]) => U[] +>a : T[] +>T : T +>a.map(f) : U[] +>a.map : (callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any) => U[] +>a : T[] +>map : (callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any) => U[] +>f : (x: T) => U + +const arrayFilter = (f: (x: T) => boolean) => (a: T[]) => a.filter(f); +>arrayFilter : (f: (x: T) => boolean) => (a: T[]) => T[] +>(f: (x: T) => boolean) => (a: T[]) => a.filter(f) : (f: (x: T) => boolean) => (a: T[]) => T[] +>T : T +>f : (x: T) => boolean +>x : T +>T : T +>(a: T[]) => a.filter(f) : (a: T[]) => T[] +>a : T[] +>T : T +>a.filter(f) : T[] +>a.filter : { (callbackfn: (value: T, index: number, array: T[]) => value is S, thisArg?: any): S[]; (callbackfn: (value: T, index: number, array: T[]) => any, thisArg?: any): T[]; } +>a : T[] +>filter : { (callbackfn: (value: T, index: number, array: T[]) => value is S, thisArg?: any): S[]; (callbackfn: (value: T, index: number, array: T[]) => any, thisArg?: any): T[]; } +>f : (x: T) => boolean + +const f20: (a: string[]) => number[] = arrayMap(x => x.length); +>f20 : (a: string[]) => number[] +>a : string[] +>arrayMap(x => x.length) : (a: string[]) => number[] +>arrayMap : (f: (x: T) => U) => (a: T[]) => U[] +>x => x.length : (x: string) => number +>x : string +>x.length : number +>x : string +>length : number + +const f21: (a: A[]) => A[][] = arrayMap(x => [x]); +>f21 : (a: A[]) => A[][] +>A : A +>a : A[] +>A : A +>A : A +>arrayMap(x => [x]) : (a: A[]) => A[][] +>arrayMap : (f: (x: T) => U) => (a: T[]) => U[] +>x => [x] : (x: A) => A[] +>x : A +>[x] : A[] +>x : A + +const f22: (a: A[]) => A[] = arrayMap(identity); +>f22 : (a: A[]) => A[] +>A : A +>a : A[] +>A : A +>A : A +>arrayMap(identity) : (a: A[]) => A[] +>arrayMap : (f: (x: T) => U) => (a: T[]) => U[] +>identity : (x: T) => T + +const f23: (a: A[]) => Box[] = arrayMap(value => ({ value })); +>f23 : (a: A[]) => Box[] +>A : A +>a : A[] +>A : A +>Box : Box +>A : A +>arrayMap(value => ({ value })) : (a: A[]) => { value: A; }[] +>arrayMap : (f: (x: T) => U) => (a: T[]) => U[] +>value => ({ value }) : (value: A) => { value: A; } +>value : A +>({ value }) : { value: A; } +>{ value } : { value: A; } +>value : A + +const f30: (a: string[]) => string[] = arrayFilter(x => x.length > 10); +>f30 : (a: string[]) => string[] +>a : string[] +>arrayFilter(x => x.length > 10) : (a: string[]) => string[] +>arrayFilter : (f: (x: T) => boolean) => (a: T[]) => T[] +>x => x.length > 10 : (x: string) => boolean +>x : string +>x.length > 10 : boolean +>x.length : number +>x : string +>length : number +>10 : 10 + +const f31: >(a: T[]) => T[] = arrayFilter(x => x.value > 10); +>f31 : >(a: T[]) => T[] +>T : T +>Box : Box +>a : T[] +>T : T +>T : T +>arrayFilter(x => x.value > 10) : (a: T[]) => T[] +>arrayFilter : (f: (x: T) => boolean) => (a: T[]) => T[] +>x => x.value > 10 : (x: T) => boolean +>x : T +>x.value > 10 : boolean +>x.value : number +>x : T +>value : number +>10 : 10 + +const f40: (b: B, a: A) => [A, B] = flip(zip); +>f40 : (b: B, a: A) => [A, B] +>A : A +>B : B +>b : B +>B : B +>a : A +>A : A +>A : A +>B : B +>flip(zip) : (y: B, x: A) => [A, B] +>flip : (f: (x: X, y: Y) => Z) => (y: Y, x: X) => Z +>zip : (a: A, b: B) => [A, B] + +// Repro from #16293 + +type fn = (a: A) => A; +>fn : fn +>A : A +>a : A +>A : A +>A : A + +const fn: fn = a => a; +>fn : fn +>fn : fn +>a => a : (a: A) => A +>a : A +>a : A + diff --git a/tests/baselines/reference/genericFunctionHasFreshTypeArgs.types b/tests/baselines/reference/genericFunctionHasFreshTypeArgs.types index 3a3afebb9ac18..d6f64bdc933aa 100644 --- a/tests/baselines/reference/genericFunctionHasFreshTypeArgs.types +++ b/tests/baselines/reference/genericFunctionHasFreshTypeArgs.types @@ -9,13 +9,13 @@ function f(p: (x: T) => void) { }; f(x => f(y => x = y)); >f(x => f(y => x = y)) : void >f : (p: (x: T) => void) => void ->x => f(y => x = y) : (x: any) => void ->x : any +>x => f(y => x = y) : (x: T) => void +>x : T >f(y => x = y) : void >f : (p: (x: T) => void) => void ->y => x = y : (y: any) => any ->y : any ->x = y : any ->x : any ->y : any +>y => x = y : (y: T) => T +>y : T +>x = y : T +>x : T +>y : T diff --git a/tests/baselines/reference/genericTypeAssertions3.types b/tests/baselines/reference/genericTypeAssertions3.types index 9f7facc8d478d..e46dd4aaa4e50 100644 --- a/tests/baselines/reference/genericTypeAssertions3.types +++ b/tests/baselines/reference/genericTypeAssertions3.types @@ -6,9 +6,9 @@ var r = < (x: T) => T > ((x) => { return null; }); // bug was 'could not find >x : T >T : T >T : T ->((x) => { return null; }) : (x: any) => any ->(x) => { return null; } : (x: any) => any ->x : any +>((x) => { return null; }) : (x: T) => any +>(x) => { return null; } : (x: T) => any +>x : T >null : null var s = < (x: T) => T > ((x: any) => { return null; }); // no error diff --git a/tests/baselines/reference/implicitAnyGenericTypeInference.errors.txt b/tests/baselines/reference/implicitAnyGenericTypeInference.errors.txt deleted file mode 100644 index 0c64c3e612535..0000000000000 --- a/tests/baselines/reference/implicitAnyGenericTypeInference.errors.txt +++ /dev/null @@ -1,16 +0,0 @@ -tests/cases/compiler/implicitAnyGenericTypeInference.ts(6,19): error TS7006: Parameter 'x' implicitly has an 'any' type. -tests/cases/compiler/implicitAnyGenericTypeInference.ts(6,22): error TS7006: Parameter 'y' implicitly has an 'any' type. - - -==== tests/cases/compiler/implicitAnyGenericTypeInference.ts (2 errors) ==== - interface Comparer { - compareTo(x: T, y: U): U; - } - - var c: Comparer; - c = { compareTo: (x, y) => { return y; } }; - ~ -!!! error TS7006: Parameter 'x' implicitly has an 'any' type. - ~ -!!! error TS7006: Parameter 'y' implicitly has an 'any' type. - var r = c.compareTo(1, ''); \ No newline at end of file diff --git a/tests/baselines/reference/implicitAnyGenericTypeInference.symbols b/tests/baselines/reference/implicitAnyGenericTypeInference.symbols new file mode 100644 index 0000000000000..e56b68a713457 --- /dev/null +++ b/tests/baselines/reference/implicitAnyGenericTypeInference.symbols @@ -0,0 +1,32 @@ +=== tests/cases/compiler/implicitAnyGenericTypeInference.ts === +interface Comparer { +>Comparer : Symbol(Comparer, Decl(implicitAnyGenericTypeInference.ts, 0, 0)) +>T : Symbol(T, Decl(implicitAnyGenericTypeInference.ts, 0, 19)) + + compareTo(x: T, y: U): U; +>compareTo : Symbol(Comparer.compareTo, Decl(implicitAnyGenericTypeInference.ts, 0, 23)) +>U : Symbol(U, Decl(implicitAnyGenericTypeInference.ts, 1, 14)) +>x : Symbol(x, Decl(implicitAnyGenericTypeInference.ts, 1, 17)) +>T : Symbol(T, Decl(implicitAnyGenericTypeInference.ts, 0, 19)) +>y : Symbol(y, Decl(implicitAnyGenericTypeInference.ts, 1, 22)) +>U : Symbol(U, Decl(implicitAnyGenericTypeInference.ts, 1, 14)) +>U : Symbol(U, Decl(implicitAnyGenericTypeInference.ts, 1, 14)) +} + +var c: Comparer; +>c : Symbol(c, Decl(implicitAnyGenericTypeInference.ts, 4, 3)) +>Comparer : Symbol(Comparer, Decl(implicitAnyGenericTypeInference.ts, 0, 0)) + +c = { compareTo: (x, y) => { return y; } }; +>c : Symbol(c, Decl(implicitAnyGenericTypeInference.ts, 4, 3)) +>compareTo : Symbol(compareTo, Decl(implicitAnyGenericTypeInference.ts, 5, 5)) +>x : Symbol(x, Decl(implicitAnyGenericTypeInference.ts, 5, 18)) +>y : Symbol(y, Decl(implicitAnyGenericTypeInference.ts, 5, 20)) +>y : Symbol(y, Decl(implicitAnyGenericTypeInference.ts, 5, 20)) + +var r = c.compareTo(1, ''); +>r : Symbol(r, Decl(implicitAnyGenericTypeInference.ts, 6, 3)) +>c.compareTo : Symbol(Comparer.compareTo, Decl(implicitAnyGenericTypeInference.ts, 0, 23)) +>c : Symbol(c, Decl(implicitAnyGenericTypeInference.ts, 4, 3)) +>compareTo : Symbol(Comparer.compareTo, Decl(implicitAnyGenericTypeInference.ts, 0, 23)) + diff --git a/tests/baselines/reference/implicitAnyGenericTypeInference.types b/tests/baselines/reference/implicitAnyGenericTypeInference.types new file mode 100644 index 0000000000000..4124c729f14b1 --- /dev/null +++ b/tests/baselines/reference/implicitAnyGenericTypeInference.types @@ -0,0 +1,38 @@ +=== tests/cases/compiler/implicitAnyGenericTypeInference.ts === +interface Comparer { +>Comparer : Comparer +>T : T + + compareTo(x: T, y: U): U; +>compareTo : (x: T, y: U) => U +>U : U +>x : T +>T : T +>y : U +>U : U +>U : U +} + +var c: Comparer; +>c : Comparer +>Comparer : Comparer + +c = { compareTo: (x, y) => { return y; } }; +>c = { compareTo: (x, y) => { return y; } } : { compareTo: (x: any, y: U) => U; } +>c : Comparer +>{ compareTo: (x, y) => { return y; } } : { compareTo: (x: any, y: U) => U; } +>compareTo : (x: any, y: U) => U +>(x, y) => { return y; } : (x: any, y: U) => U +>x : any +>y : U +>y : U + +var r = c.compareTo(1, ''); +>r : string +>c.compareTo(1, '') : "" +>c.compareTo : (x: any, y: U) => U +>c : Comparer +>compareTo : (x: any, y: U) => U +>1 : 1 +>'' : "" + 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/nonPrimitiveUnionIntersection.errors.txt b/tests/baselines/reference/nonPrimitiveUnionIntersection.errors.txt index 5fb1e89c2e3c0..5aad982dc20f0 100644 --- a/tests/baselines/reference/nonPrimitiveUnionIntersection.errors.txt +++ b/tests/baselines/reference/nonPrimitiveUnionIntersection.errors.txt @@ -1,18 +1,32 @@ tests/cases/conformance/types/nonPrimitive/nonPrimitiveUnionIntersection.ts(1,5): error TS2322: Type '""' is not assignable to type 'object & string'. Type '""' is not assignable to type 'object'. -tests/cases/conformance/types/nonPrimitive/nonPrimitiveUnionIntersection.ts(3,1): error TS2322: Type 'string' is not assignable to type 'object & string'. +tests/cases/conformance/types/nonPrimitive/nonPrimitiveUnionIntersection.ts(3,5): error TS2322: Type '123' is not assignable to type 'object & {}'. + Type '123' is not assignable to type 'object'. +tests/cases/conformance/types/nonPrimitive/nonPrimitiveUnionIntersection.ts(4,1): error TS2322: Type 'string' is not assignable to type 'object & string'. Type 'string' is not assignable to type 'object'. +tests/cases/conformance/types/nonPrimitive/nonPrimitiveUnionIntersection.ts(8,38): error TS2322: Type '{ bar: string; }' is not assignable to type 'object & { err: string; }'. + Object literal may only specify known properties, and 'bar' does not exist in type 'object & { err: string; }'. -==== tests/cases/conformance/types/nonPrimitive/nonPrimitiveUnionIntersection.ts (2 errors) ==== +==== tests/cases/conformance/types/nonPrimitive/nonPrimitiveUnionIntersection.ts (4 errors) ==== var a: object & string = ""; // error ~ !!! error TS2322: Type '""' is not assignable to type 'object & string'. !!! error TS2322: Type '""' is not assignable to type 'object'. var b: object | string = ""; // ok + var c: object & {} = 123; // error + ~ +!!! error TS2322: Type '123' is not assignable to type 'object & {}'. +!!! error TS2322: Type '123' is not assignable to type 'object'. a = b; // error ~ !!! error TS2322: Type 'string' is not assignable to type 'object & string'. !!! error TS2322: Type 'string' is not assignable to type 'object'. b = a; // ok + + const foo: object & {} = {bar: 'bar'}; // ok + const bar: object & {err: string} = {bar: 'bar'}; // error + ~~~~~~~~~~ +!!! error TS2322: Type '{ bar: string; }' is not assignable to type 'object & { err: string; }'. +!!! error TS2322: Object literal may only specify known properties, and 'bar' does not exist in type 'object & { err: string; }'. \ No newline at end of file diff --git a/tests/baselines/reference/nonPrimitiveUnionIntersection.js b/tests/baselines/reference/nonPrimitiveUnionIntersection.js index 7f4b46c42ed11..771024f15e6b8 100644 --- a/tests/baselines/reference/nonPrimitiveUnionIntersection.js +++ b/tests/baselines/reference/nonPrimitiveUnionIntersection.js @@ -1,17 +1,29 @@ //// [nonPrimitiveUnionIntersection.ts] var a: object & string = ""; // error var b: object | string = ""; // ok +var c: object & {} = 123; // error a = b; // error b = a; // ok + +const foo: object & {} = {bar: 'bar'}; // ok +const bar: object & {err: string} = {bar: 'bar'}; // error //// [nonPrimitiveUnionIntersection.js] var a = ""; // error var b = ""; // ok +var c = 123; // error a = b; // error b = a; // ok +var foo = { bar: 'bar' }; // ok +var bar = { bar: 'bar' }; // error //// [nonPrimitiveUnionIntersection.d.ts] declare var a: object & string; declare var b: object | string; +declare var c: object & {}; +declare const foo: object & {}; +declare const bar: object & { + err: string; +}; diff --git a/tests/baselines/reference/reexportedMissingAlias.errors.txt b/tests/baselines/reference/reexportedMissingAlias.errors.txt new file mode 100644 index 0000000000000..c22bf2da9d069 --- /dev/null +++ b/tests/baselines/reference/reexportedMissingAlias.errors.txt @@ -0,0 +1,18 @@ +tests/cases/compiler/second.d.ts(2,27): error TS2304: Cannot find name 'CompletelyMissing'. +tests/cases/compiler/second.d.ts(2,27): error TS2503: Cannot find namespace 'CompletelyMissing'. + + +==== tests/cases/compiler/second.d.ts (2 errors) ==== + // Fixes #15094 + export import Component = CompletelyMissing; + ~~~~~~~~~~~~~~~~~ +!!! error TS2304: Cannot find name 'CompletelyMissing'. + ~~~~~~~~~~~~~~~~~ +!!! error TS2503: Cannot find namespace 'CompletelyMissing'. +==== tests/cases/compiler/first.d.ts (0 errors) ==== + import * as Second from './second'; + export = Second; +==== tests/cases/compiler/crash.ts (0 errors) ==== + import { Component } from './first'; + class C extends Component { } + \ No newline at end of file diff --git a/tests/baselines/reference/reexportedMissingAlias.js b/tests/baselines/reference/reexportedMissingAlias.js new file mode 100644 index 0000000000000..792ea3eb5c2cd --- /dev/null +++ b/tests/baselines/reference/reexportedMissingAlias.js @@ -0,0 +1,34 @@ +//// [tests/cases/compiler/reexportedMissingAlias.ts] //// + +//// [second.d.ts] +// Fixes #15094 +export import Component = CompletelyMissing; +//// [first.d.ts] +import * as Second from './second'; +export = Second; +//// [crash.ts] +import { Component } from './first'; +class C extends Component { } + + +//// [crash.js] +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +exports.__esModule = true; +var first_1 = require("./first"); +var C = (function (_super) { + __extends(C, _super); + function C() { + return _super !== null && _super.apply(this, arguments) || this; + } + return C; +}(first_1.Component)); diff --git a/tests/baselines/reference/spreadUnion.symbols b/tests/baselines/reference/spreadUnion.symbols index 40a63d56d49c8..bef8f5522d70d 100644 --- a/tests/baselines/reference/spreadUnion.symbols +++ b/tests/baselines/reference/spreadUnion.symbols @@ -1,4 +1,4 @@ -=== tests/cases/compiler/spreadUnion.ts === +=== tests/cases/conformance/types/spread/spreadUnion.ts === var union: { a: number } | { b: string }; >union : Symbol(union, Decl(spreadUnion.ts, 0, 3)) >a : Symbol(a, Decl(spreadUnion.ts, 0, 12)) diff --git a/tests/baselines/reference/spreadUnion.types b/tests/baselines/reference/spreadUnion.types index 9e5ac1cffd555..fb1ef5f2018ea 100644 --- a/tests/baselines/reference/spreadUnion.types +++ b/tests/baselines/reference/spreadUnion.types @@ -1,4 +1,4 @@ -=== tests/cases/compiler/spreadUnion.ts === +=== tests/cases/conformance/types/spread/spreadUnion.ts === var union: { a: number } | { b: string }; >union : { a: number; } | { b: string; } >a : number diff --git a/tests/baselines/reference/spreadUnion2.js b/tests/baselines/reference/spreadUnion2.js index b98046463c3a5..6e49770617a15 100644 --- a/tests/baselines/reference/spreadUnion2.js +++ b/tests/baselines/reference/spreadUnion2.js @@ -3,25 +3,25 @@ declare const undefinedUnion: { a: number } | undefined; declare const nullUnion: { b: number } | null; declare const nullAndUndefinedUnion: null | undefined; -var o1: { a: number }; +var o1: {} | { a: number }; var o1 = { ...undefinedUnion }; -var o2: { b: number }; +var o2: {} | { b: number }; var o2 = { ...nullUnion }; -var o3: { a: number, b: number }; +var o3: {} | { b: number } | { a: number } | { a: number, b: number }; var o3 = { ...undefinedUnion, ...nullUnion }; var o3 = { ...nullUnion, ...undefinedUnion }; -var o4: { a: number }; +var o4: {} | { a: number }; var o4 = { ...undefinedUnion, ...undefinedUnion }; -var o5: { b: number }; +var o5: {} | { b: number }; var o5 = { ...nullUnion, ...nullUnion }; -var o6: { }; var o6 = { ...nullAndUndefinedUnion, ...nullAndUndefinedUnion }; -var o6 = { ...nullAndUndefinedUnion }; +var o7 = { ...nullAndUndefinedUnion }; + //// [spreadUnion2.js] var __assign = (this && this.__assign) || Object.assign || function(t) { @@ -43,6 +43,5 @@ var o4; var o4 = __assign({}, undefinedUnion, undefinedUnion); var o5; var o5 = __assign({}, nullUnion, nullUnion); -var o6; var o6 = __assign({}, nullAndUndefinedUnion, nullAndUndefinedUnion); -var o6 = __assign({}, nullAndUndefinedUnion); +var o7 = __assign({}, nullAndUndefinedUnion); diff --git a/tests/baselines/reference/spreadUnion2.symbols b/tests/baselines/reference/spreadUnion2.symbols index 05703fc32bde2..c4d1f19b6d9f9 100644 --- a/tests/baselines/reference/spreadUnion2.symbols +++ b/tests/baselines/reference/spreadUnion2.symbols @@ -1,4 +1,4 @@ -=== tests/cases/compiler/spreadUnion2.ts === +=== tests/cases/conformance/types/spread/spreadUnion2.ts === declare const undefinedUnion: { a: number } | undefined; >undefinedUnion : Symbol(undefinedUnion, Decl(spreadUnion2.ts, 0, 13)) >a : Symbol(a, Decl(spreadUnion2.ts, 0, 31)) @@ -10,26 +10,28 @@ declare const nullUnion: { b: number } | null; declare const nullAndUndefinedUnion: null | undefined; >nullAndUndefinedUnion : Symbol(nullAndUndefinedUnion, Decl(spreadUnion2.ts, 2, 13)) -var o1: { a: number }; +var o1: {} | { a: number }; >o1 : Symbol(o1, Decl(spreadUnion2.ts, 4, 3), Decl(spreadUnion2.ts, 5, 3)) ->a : Symbol(a, Decl(spreadUnion2.ts, 4, 9)) +>a : Symbol(a, Decl(spreadUnion2.ts, 4, 14)) var o1 = { ...undefinedUnion }; >o1 : Symbol(o1, Decl(spreadUnion2.ts, 4, 3), Decl(spreadUnion2.ts, 5, 3)) >undefinedUnion : Symbol(undefinedUnion, Decl(spreadUnion2.ts, 0, 13)) -var o2: { b: number }; +var o2: {} | { b: number }; >o2 : Symbol(o2, Decl(spreadUnion2.ts, 7, 3), Decl(spreadUnion2.ts, 8, 3)) ->b : Symbol(b, Decl(spreadUnion2.ts, 7, 9)) +>b : Symbol(b, Decl(spreadUnion2.ts, 7, 14)) var o2 = { ...nullUnion }; >o2 : Symbol(o2, Decl(spreadUnion2.ts, 7, 3), Decl(spreadUnion2.ts, 8, 3)) >nullUnion : Symbol(nullUnion, Decl(spreadUnion2.ts, 1, 13)) -var o3: { a: number, b: number }; +var o3: {} | { b: number } | { a: number } | { a: number, b: number }; >o3 : Symbol(o3, Decl(spreadUnion2.ts, 10, 3), Decl(spreadUnion2.ts, 11, 3), Decl(spreadUnion2.ts, 12, 3)) ->a : Symbol(a, Decl(spreadUnion2.ts, 10, 9)) ->b : Symbol(b, Decl(spreadUnion2.ts, 10, 20)) +>b : Symbol(b, Decl(spreadUnion2.ts, 10, 14)) +>a : Symbol(a, Decl(spreadUnion2.ts, 10, 30)) +>a : Symbol(a, Decl(spreadUnion2.ts, 10, 46)) +>b : Symbol(b, Decl(spreadUnion2.ts, 10, 57)) var o3 = { ...undefinedUnion, ...nullUnion }; >o3 : Symbol(o3, Decl(spreadUnion2.ts, 10, 3), Decl(spreadUnion2.ts, 11, 3), Decl(spreadUnion2.ts, 12, 3)) @@ -41,33 +43,30 @@ var o3 = { ...nullUnion, ...undefinedUnion }; >nullUnion : Symbol(nullUnion, Decl(spreadUnion2.ts, 1, 13)) >undefinedUnion : Symbol(undefinedUnion, Decl(spreadUnion2.ts, 0, 13)) -var o4: { a: number }; +var o4: {} | { a: number }; >o4 : Symbol(o4, Decl(spreadUnion2.ts, 14, 3), Decl(spreadUnion2.ts, 15, 3)) ->a : Symbol(a, Decl(spreadUnion2.ts, 14, 9)) +>a : Symbol(a, Decl(spreadUnion2.ts, 14, 14)) var o4 = { ...undefinedUnion, ...undefinedUnion }; >o4 : Symbol(o4, Decl(spreadUnion2.ts, 14, 3), Decl(spreadUnion2.ts, 15, 3)) >undefinedUnion : Symbol(undefinedUnion, Decl(spreadUnion2.ts, 0, 13)) >undefinedUnion : Symbol(undefinedUnion, Decl(spreadUnion2.ts, 0, 13)) -var o5: { b: number }; +var o5: {} | { b: number }; >o5 : Symbol(o5, Decl(spreadUnion2.ts, 17, 3), Decl(spreadUnion2.ts, 18, 3)) ->b : Symbol(b, Decl(spreadUnion2.ts, 17, 9)) +>b : Symbol(b, Decl(spreadUnion2.ts, 17, 14)) var o5 = { ...nullUnion, ...nullUnion }; >o5 : Symbol(o5, Decl(spreadUnion2.ts, 17, 3), Decl(spreadUnion2.ts, 18, 3)) >nullUnion : Symbol(nullUnion, Decl(spreadUnion2.ts, 1, 13)) >nullUnion : Symbol(nullUnion, Decl(spreadUnion2.ts, 1, 13)) -var o6: { }; ->o6 : Symbol(o6, Decl(spreadUnion2.ts, 20, 3), Decl(spreadUnion2.ts, 21, 3), Decl(spreadUnion2.ts, 22, 3)) - var o6 = { ...nullAndUndefinedUnion, ...nullAndUndefinedUnion }; ->o6 : Symbol(o6, Decl(spreadUnion2.ts, 20, 3), Decl(spreadUnion2.ts, 21, 3), Decl(spreadUnion2.ts, 22, 3)) +>o6 : Symbol(o6, Decl(spreadUnion2.ts, 20, 3)) >nullAndUndefinedUnion : Symbol(nullAndUndefinedUnion, Decl(spreadUnion2.ts, 2, 13)) >nullAndUndefinedUnion : Symbol(nullAndUndefinedUnion, Decl(spreadUnion2.ts, 2, 13)) -var o6 = { ...nullAndUndefinedUnion }; ->o6 : Symbol(o6, Decl(spreadUnion2.ts, 20, 3), Decl(spreadUnion2.ts, 21, 3), Decl(spreadUnion2.ts, 22, 3)) +var o7 = { ...nullAndUndefinedUnion }; +>o7 : Symbol(o7, Decl(spreadUnion2.ts, 21, 3)) >nullAndUndefinedUnion : Symbol(nullAndUndefinedUnion, Decl(spreadUnion2.ts, 2, 13)) diff --git a/tests/baselines/reference/spreadUnion2.types b/tests/baselines/reference/spreadUnion2.types index 97fbb9838c7cc..ea3364f296b75 100644 --- a/tests/baselines/reference/spreadUnion2.types +++ b/tests/baselines/reference/spreadUnion2.types @@ -1,4 +1,4 @@ -=== tests/cases/compiler/spreadUnion2.ts === +=== tests/cases/conformance/types/spread/spreadUnion2.ts === declare const undefinedUnion: { a: number } | undefined; >undefinedUnion : { a: number; } | undefined >a : number @@ -12,72 +12,71 @@ declare const nullAndUndefinedUnion: null | undefined; >nullAndUndefinedUnion : null | undefined >null : null -var o1: { a: number }; ->o1 : { a: number; } +var o1: {} | { a: number }; +>o1 : {} | { a: number; } >a : number var o1 = { ...undefinedUnion }; ->o1 : { a: number; } ->{ ...undefinedUnion } : { a: number; } +>o1 : {} | { a: number; } +>{ ...undefinedUnion } : {} | { a: number; } >undefinedUnion : { a: number; } | undefined -var o2: { b: number }; ->o2 : { b: number; } +var o2: {} | { b: number }; +>o2 : {} | { b: number; } >b : number var o2 = { ...nullUnion }; ->o2 : { b: number; } ->{ ...nullUnion } : { b: number; } +>o2 : {} | { b: number; } +>{ ...nullUnion } : {} | { b: number; } >nullUnion : { b: number; } | null -var o3: { a: number, b: number }; ->o3 : { a: number; b: number; } +var o3: {} | { b: number } | { a: number } | { a: number, b: number }; +>o3 : {} | { b: number; } | { a: number; } | { a: number; b: number; } +>b : number +>a : number >a : number >b : number var o3 = { ...undefinedUnion, ...nullUnion }; ->o3 : { a: number; b: number; } ->{ ...undefinedUnion, ...nullUnion } : { b: number; a: number; } +>o3 : {} | { b: number; } | { a: number; } | { a: number; b: number; } +>{ ...undefinedUnion, ...nullUnion } : {} | { b: number; } | { a: number; } | { b: number; a: number; } >undefinedUnion : { a: number; } | undefined >nullUnion : { b: number; } | null var o3 = { ...nullUnion, ...undefinedUnion }; ->o3 : { a: number; b: number; } ->{ ...nullUnion, ...undefinedUnion } : { a: number; b: number; } +>o3 : {} | { b: number; } | { a: number; } | { a: number; b: number; } +>{ ...nullUnion, ...undefinedUnion } : {} | { a: number; } | { b: number; } | { a: number; b: number; } >nullUnion : { b: number; } | null >undefinedUnion : { a: number; } | undefined -var o4: { a: number }; ->o4 : { a: number; } +var o4: {} | { a: number }; +>o4 : {} | { a: number; } >a : number var o4 = { ...undefinedUnion, ...undefinedUnion }; ->o4 : { a: number; } ->{ ...undefinedUnion, ...undefinedUnion } : { a: number; } +>o4 : {} | { a: number; } +>{ ...undefinedUnion, ...undefinedUnion } : {} | { a: number; } | { a: number; } | { a: number; } >undefinedUnion : { a: number; } | undefined >undefinedUnion : { a: number; } | undefined -var o5: { b: number }; ->o5 : { b: number; } +var o5: {} | { b: number }; +>o5 : {} | { b: number; } >b : number var o5 = { ...nullUnion, ...nullUnion }; ->o5 : { b: number; } ->{ ...nullUnion, ...nullUnion } : { b: number; } +>o5 : {} | { b: number; } +>{ ...nullUnion, ...nullUnion } : {} | { b: number; } | { b: number; } | { b: number; } >nullUnion : { b: number; } | null >nullUnion : { b: number; } | null -var o6: { }; ->o6 : {} - var o6 = { ...nullAndUndefinedUnion, ...nullAndUndefinedUnion }; ->o6 : {} ->{ ...nullAndUndefinedUnion, ...nullAndUndefinedUnion } : {} +>o6 : {} | {} | {} | {} +>{ ...nullAndUndefinedUnion, ...nullAndUndefinedUnion } : {} | {} | {} | {} >nullAndUndefinedUnion : null | undefined >nullAndUndefinedUnion : null | undefined -var o6 = { ...nullAndUndefinedUnion }; ->o6 : {} ->{ ...nullAndUndefinedUnion } : {} +var o7 = { ...nullAndUndefinedUnion }; +>o7 : {} | {} +>{ ...nullAndUndefinedUnion } : {} | {} >nullAndUndefinedUnion : null | undefined diff --git a/tests/baselines/reference/spreadUnion3.errors.txt b/tests/baselines/reference/spreadUnion3.errors.txt new file mode 100644 index 0000000000000..5f5b620685c5b --- /dev/null +++ b/tests/baselines/reference/spreadUnion3.errors.txt @@ -0,0 +1,31 @@ +tests/cases/conformance/types/spread/spreadUnion3.ts(2,5): error TS2322: Type '{ y: number; } | { y: string; }' is not assignable to type '{ y: string; }'. + Type '{ y: number; }' is not assignable to type '{ y: string; }'. + Types of property 'y' are incompatible. + Type 'number' is not assignable to type 'string'. +tests/cases/conformance/types/spread/spreadUnion3.ts(9,23): error TS2339: Property 'a' does not exist on type '{} | {} | { a: number; }'. + Property 'a' does not exist on type '{}'. + + +==== tests/cases/conformance/types/spread/spreadUnion3.ts (2 errors) ==== + function f(x: { y: string } | undefined): { y: string } { + return { y: 123, ...x } // y: string | number + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2322: Type '{ y: number; } | { y: string; }' is not assignable to type '{ y: string; }'. +!!! error TS2322: Type '{ y: number; }' is not assignable to type '{ y: string; }'. +!!! error TS2322: Types of property 'y' are incompatible. +!!! error TS2322: Type 'number' is not assignable to type 'string'. + } + f(undefined) + + + function g(t?: { a: number } | null): void { + let b = { ...t }; + let c: number = b.a; // might not have 'a' + ~ +!!! error TS2339: Property 'a' does not exist on type '{} | {} | { a: number; }'. +!!! error TS2339: Property 'a' does not exist on type '{}'. + } + g() + g(undefined) + g(null) + \ No newline at end of file diff --git a/tests/baselines/reference/spreadUnion3.js b/tests/baselines/reference/spreadUnion3.js new file mode 100644 index 0000000000000..2aaf9efeb78f9 --- /dev/null +++ b/tests/baselines/reference/spreadUnion3.js @@ -0,0 +1,36 @@ +//// [spreadUnion3.ts] +function f(x: { y: string } | undefined): { y: string } { + return { y: 123, ...x } // y: string | number +} +f(undefined) + + +function g(t?: { a: number } | null): void { + let b = { ...t }; + let c: number = b.a; // might not have 'a' +} +g() +g(undefined) +g(null) + + +//// [spreadUnion3.js] +var __assign = (this && this.__assign) || Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; +}; +function f(x) { + return __assign({ y: 123 }, x); // y: string | number +} +f(undefined); +function g(t) { + var b = __assign({}, t); + var c = b.a; // might not have 'a' +} +g(); +g(undefined); +g(null); diff --git a/tests/baselines/reference/symbolMergeValueAndImportedType.js b/tests/baselines/reference/symbolMergeValueAndImportedType.js new file mode 100644 index 0000000000000..70da47268d5e4 --- /dev/null +++ b/tests/baselines/reference/symbolMergeValueAndImportedType.js @@ -0,0 +1,17 @@ +//// [tests/cases/compiler/symbolMergeValueAndImportedType.ts] //// + +//// [main.ts] +import { X } from "./other"; +const X = 42; +console.log('X is ' + X); +//// [other.ts] +export type X = {}; + +//// [other.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +//// [main.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const X = 42; +console.log('X is ' + X); diff --git a/tests/baselines/reference/symbolMergeValueAndImportedType.symbols b/tests/baselines/reference/symbolMergeValueAndImportedType.symbols new file mode 100644 index 0000000000000..7e1422faa4697 --- /dev/null +++ b/tests/baselines/reference/symbolMergeValueAndImportedType.symbols @@ -0,0 +1,17 @@ +=== tests/cases/compiler/main.ts === +import { X } from "./other"; +>X : Symbol(X, Decl(main.ts, 0, 8), Decl(main.ts, 1, 5)) + +const X = 42; +>X : Symbol(X, Decl(main.ts, 0, 8), Decl(main.ts, 1, 5)) + +console.log('X is ' + X); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>X : Symbol(X, Decl(main.ts, 0, 8), Decl(main.ts, 1, 5)) + +=== tests/cases/compiler/other.ts === +export type X = {}; +>X : Symbol(X, Decl(other.ts, 0, 0)) + diff --git a/tests/baselines/reference/symbolMergeValueAndImportedType.types b/tests/baselines/reference/symbolMergeValueAndImportedType.types new file mode 100644 index 0000000000000..a7dc72ab0b638 --- /dev/null +++ b/tests/baselines/reference/symbolMergeValueAndImportedType.types @@ -0,0 +1,21 @@ +=== tests/cases/compiler/main.ts === +import { X } from "./other"; +>X : 42 + +const X = 42; +>X : 42 +>42 : 42 + +console.log('X is ' + X); +>console.log('X is ' + X) : void +>console.log : (message?: any, ...optionalParams: any[]) => void +>console : Console +>log : (message?: any, ...optionalParams: any[]) => void +>'X is ' + X : string +>'X is ' : "X is " +>X : 42 + +=== tests/cases/compiler/other.ts === +export type X = {}; +>X : X + 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/compiler/blockScopedClassDeclarationAcrossFiles.ts b/tests/cases/compiler/blockScopedClassDeclarationAcrossFiles.ts new file mode 100644 index 0000000000000..168276023085c --- /dev/null +++ b/tests/cases/compiler/blockScopedClassDeclarationAcrossFiles.ts @@ -0,0 +1,5 @@ +// @outFile: foo.js +// @Filename: c.ts +let foo: typeof C; +// @Filename: b.ts +class C { } diff --git a/tests/cases/compiler/exactSpellingSuggestion.ts b/tests/cases/compiler/exactSpellingSuggestion.ts new file mode 100644 index 0000000000000..99aec9a01992b --- /dev/null +++ b/tests/cases/compiler/exactSpellingSuggestion.ts @@ -0,0 +1,9 @@ +// Fixes #16245 -- always suggest the exact match, even when +// other options are very close +enum U8 { + BIT_0 = 1 << 0, + BIT_1 = 1 << 1, + BIT_2 = 1 << 2 +} + +U8.bit_2 diff --git a/tests/cases/compiler/reexportedMissingAlias.ts b/tests/cases/compiler/reexportedMissingAlias.ts new file mode 100644 index 0000000000000..b430cd526c810 --- /dev/null +++ b/tests/cases/compiler/reexportedMissingAlias.ts @@ -0,0 +1,9 @@ +// Fixes #15094 +// @Filename: second.d.ts +export import Component = CompletelyMissing; +// @Filename: first.d.ts +import * as Second from './second'; +export = Second; +// @Filename: crash.ts +import { Component } from './first'; +class C extends Component { } diff --git a/tests/cases/compiler/symbolMergeValueAndImportedType.ts b/tests/cases/compiler/symbolMergeValueAndImportedType.ts new file mode 100644 index 0000000000000..4779ff22e9df8 --- /dev/null +++ b/tests/cases/compiler/symbolMergeValueAndImportedType.ts @@ -0,0 +1,9 @@ +// @target: es2015 +// @module: commonjs +// @lib: es2015,dom +// @filename: main.ts +import { X } from "./other"; +const X = 42; +console.log('X is ' + X); +// @filename: other.ts +export type X = {}; \ No newline at end of file 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 diff --git a/tests/cases/conformance/emitter/es2017/forAwait/emitter.forAwait.es2017.ts b/tests/cases/conformance/emitter/es2017/forAwait/emitter.forAwait.es2017.ts new file mode 100644 index 0000000000000..f2d1f46873de7 --- /dev/null +++ b/tests/cases/conformance/emitter/es2017/forAwait/emitter.forAwait.es2017.ts @@ -0,0 +1,26 @@ +// @target: es2017 +// @lib: esnext +// @filename: file1.ts +async function f1() { + let y: any; + for await (const x of y) { + } +} +// @filename: file2.ts +async function f2() { + let x: any, y: any; + for await (x of y) { + } +} +// @filename: file3.ts +async function* f3() { + let y: any; + for await (const x of y) { + } +} +// @filename: file4.ts +async function* f4() { + let x: any, y: any; + for await (x of y) { + } +} \ No newline at end of file diff --git a/tests/cases/conformance/salsa/constructorFunctions.ts b/tests/cases/conformance/salsa/constructorFunctions.ts new file mode 100644 index 0000000000000..4f1a03682444a --- /dev/null +++ b/tests/cases/conformance/salsa/constructorFunctions.ts @@ -0,0 +1,36 @@ +// @allowJs: true +// @checkJs: true +// @noEmit: true +// @filename: index.js + +function C1() { + if (!(this instanceof C1)) return new C1(); + this.x = 1; +} + +const c1_v1 = C1(); +const c1_v2 = new C1(); + +var C2 = function () { + if (!(this instanceof C2)) return new C2(); + this.x = 1; +}; + +const c2_v1 = C2(); +const c2_v2 = new C2(); + +/** @class */ +function C3() { + if (!(this instanceof C3)) return new C3(); +}; + +const c3_v1 = C3(); +const c3_v2 = new C3(); + +/** @class */ +var C4 = function () { + if (!(this instanceof C4)) return new C4(); +}; + +const c4_v1 = C4(); +const c4_v2 = new C4(); \ No newline at end of file diff --git a/tests/cases/conformance/types/nonPrimitive/nonPrimitiveUnionIntersection.ts b/tests/cases/conformance/types/nonPrimitive/nonPrimitiveUnionIntersection.ts index a9d5872705c1b..55c1acb03b35b 100644 --- a/tests/cases/conformance/types/nonPrimitive/nonPrimitiveUnionIntersection.ts +++ b/tests/cases/conformance/types/nonPrimitive/nonPrimitiveUnionIntersection.ts @@ -1,5 +1,9 @@ // @declaration: true var a: object & string = ""; // error var b: object | string = ""; // ok +var c: object & {} = 123; // error a = b; // error b = a; // ok + +const foo: object & {} = {bar: 'bar'}; // ok +const bar: object & {err: string} = {bar: 'bar'}; // error diff --git a/tests/cases/compiler/spreadUnion.ts b/tests/cases/conformance/types/spread/spreadUnion.ts similarity index 100% rename from tests/cases/compiler/spreadUnion.ts rename to tests/cases/conformance/types/spread/spreadUnion.ts diff --git a/tests/cases/compiler/spreadUnion2.ts b/tests/cases/conformance/types/spread/spreadUnion2.ts similarity index 67% rename from tests/cases/compiler/spreadUnion2.ts rename to tests/cases/conformance/types/spread/spreadUnion2.ts index 25dba81c0dfca..e2f72879915f2 100644 --- a/tests/cases/compiler/spreadUnion2.ts +++ b/tests/cases/conformance/types/spread/spreadUnion2.ts @@ -4,22 +4,21 @@ declare const undefinedUnion: { a: number } | undefined; declare const nullUnion: { b: number } | null; declare const nullAndUndefinedUnion: null | undefined; -var o1: { a: number }; +var o1: {} | { a: number }; var o1 = { ...undefinedUnion }; -var o2: { b: number }; +var o2: {} | { b: number }; var o2 = { ...nullUnion }; -var o3: { a: number, b: number }; +var o3: {} | { b: number } | { a: number } | { a: number, b: number }; var o3 = { ...undefinedUnion, ...nullUnion }; var o3 = { ...nullUnion, ...undefinedUnion }; -var o4: { a: number }; +var o4: {} | { a: number }; var o4 = { ...undefinedUnion, ...undefinedUnion }; -var o5: { b: number }; +var o5: {} | { b: number }; var o5 = { ...nullUnion, ...nullUnion }; -var o6: { }; var o6 = { ...nullAndUndefinedUnion, ...nullAndUndefinedUnion }; -var o6 = { ...nullAndUndefinedUnion }; \ No newline at end of file +var o7 = { ...nullAndUndefinedUnion }; diff --git a/tests/cases/conformance/types/spread/spreadUnion3.ts b/tests/cases/conformance/types/spread/spreadUnion3.ts new file mode 100644 index 0000000000000..c16acbdf7d356 --- /dev/null +++ b/tests/cases/conformance/types/spread/spreadUnion3.ts @@ -0,0 +1,14 @@ +// @strictNullChecks: true +function f(x: { y: string } | undefined): { y: string } { + return { y: 123, ...x } // y: string | number +} +f(undefined) + + +function g(t?: { a: number } | null): void { + let b = { ...t }; + let c: number = b.a; // might not have 'a' +} +g() +g(undefined) +g(null) diff --git a/tests/cases/conformance/types/typeRelationships/typeInference/genericContextualTypes1.ts b/tests/cases/conformance/types/typeRelationships/typeInference/genericContextualTypes1.ts new file mode 100644 index 0000000000000..6d937adcbf626 --- /dev/null +++ b/tests/cases/conformance/types/typeRelationships/typeInference/genericContextualTypes1.ts @@ -0,0 +1,52 @@ +// @strict: true +// @declaration: true + +type Box = { value: T }; + +declare function wrap(f: (a: A) => B): (a: A) => B; + +declare function compose(f: (a: A) => B, g: (b: B) => C): (a: A) => C; + +declare function list(a: T): T[]; + +declare function unlist(a: T[]): T; + +declare function box(x: V): Box; + +declare function unbox(x: Box): W; + +declare function map(a: T[], f: (x: T) => U): U[]; + +declare function identity(x: T): T; + +declare function zip(a: A, b: B): [A, B]; + +declare function flip(f: (x: X, y: Y) => Z): (y: Y, x: X) => Z; + +const f00: (x: A) => A[] = list; +const f01: (x: A) => A[] = x => [x]; +const f02: (x: A) => A[] = wrap(list); +const f03: (x: A) => A[] = wrap(x => [x]); + +const f10: (x: T) => Box = compose(a => list(a), b => box(b)); +const f11: (x: T) => Box = compose(list, box); +const f12: (x: Box) => T = compose(a => unbox(a), b => unlist(b)); +const f13: (x: Box) => T = compose(unbox, unlist); + +const arrayMap = (f: (x: T) => U) => (a: T[]) => a.map(f); +const arrayFilter = (f: (x: T) => boolean) => (a: T[]) => a.filter(f); + +const f20: (a: string[]) => number[] = arrayMap(x => x.length); +const f21: (a: A[]) => A[][] = arrayMap(x => [x]); +const f22: (a: A[]) => A[] = arrayMap(identity); +const f23: (a: A[]) => Box[] = arrayMap(value => ({ value })); + +const f30: (a: string[]) => string[] = arrayFilter(x => x.length > 10); +const f31: >(a: T[]) => T[] = arrayFilter(x => x.value > 10); + +const f40: (b: B, a: A) => [A, B] = flip(zip); + +// Repro from #16293 + +type fn = (a: A) => A; +const fn: fn = a => a; diff --git a/tests/cases/fourslash/codeFixAddMissingMember5.ts b/tests/cases/fourslash/codeFixAddMissingMember5.ts index cbabc0ba6c58f..db893cb61d3fe 100644 --- a/tests/cases/fourslash/codeFixAddMissingMember5.ts +++ b/tests/cases/fourslash/codeFixAddMissingMember5.ts @@ -11,9 +11,11 @@ ////} ////|] -verify.rangeAfterCodeFix(`class C { +verify.getAndApplyCodeFix(/*errorCode*/ undefined, /*index*/ 0); +verify.currentFileContentIs(`class C { static method() { ()=>{ this.foo === 10 }; } } -C.foo = undefined;`, /*includeWhiteSpace*/false, /*errorCode*/ undefined, /*index*/ 0); \ No newline at end of file +C.foo = undefined; +`); \ No newline at end of file diff --git a/tests/cases/fourslash/codeFixAddMissingMember7.ts b/tests/cases/fourslash/codeFixAddMissingMember7.ts index 0e937a3ab6e95..8ac7f2b5aff0d 100644 --- a/tests/cases/fourslash/codeFixAddMissingMember7.ts +++ b/tests/cases/fourslash/codeFixAddMissingMember7.ts @@ -9,7 +9,9 @@ ////} ////|] -verify.rangeAfterCodeFix(`class C { +verify.getAndApplyCodeFix(/*errorCode*/ undefined, /*index*/ 2) +verify.currentFileContentIs(`class C { static p = ()=>{ this.foo === 10 }; } -C.foo = undefined;`, /*includeWhiteSpace*/false, /*errorCode*/ undefined, /*index*/ 2); \ No newline at end of file +C.foo = undefined; +`); diff --git a/tests/cases/fourslash/codeFixUndeclaredAcrossFiles1.ts b/tests/cases/fourslash/codeFixUndeclaredAcrossFiles1.ts new file mode 100644 index 0000000000000..435b78ba3faf9 --- /dev/null +++ b/tests/cases/fourslash/codeFixUndeclaredAcrossFiles1.ts @@ -0,0 +1,34 @@ +/// + +// @allowJs: true +// @checkJs: true + +// @Filename: f2.js +//// import * as X from "./f1"; +//// X.C.m0(1, "", []); +//// X.C.x; +//// let c = new X.C; +//// c.m1(); +//// c.y = {}; + +// @Filename: f1.ts +//// export class C {[| +//// |]x: number; +//// static y: string; +//// } + +verify.getAndApplyCodeFix(/*errorCode*/undefined, 0); +verify.getAndApplyCodeFix(/*errorCode*/undefined, 0); +verify.getAndApplyCodeFix(/*errorCode*/undefined, 0); +verify.getAndApplyCodeFix(/*errorCode*/undefined, 0); + +verify.rangeIs(` + y: { [x: string]: any; }; + m1(): any { + throw new Error("Method not implemented."); + } + static x: any; + static m0(arg0: any, arg1: any, arg2: any): any { + throw new Error("Method not implemented."); + } +`); \ No newline at end of file diff --git a/tests/cases/fourslash/codeFixUndeclaredAcrossFiles2.ts b/tests/cases/fourslash/codeFixUndeclaredAcrossFiles2.ts new file mode 100644 index 0000000000000..04e2afc667cc5 --- /dev/null +++ b/tests/cases/fourslash/codeFixUndeclaredAcrossFiles2.ts @@ -0,0 +1,39 @@ +/// + +// @allowJs: true +// @checkJs: true + +// @Filename: f2.ts +//// import * as X from "./f1"; +//// X.C.m0(1, "", []); +//// X.C.x; +//// let c = new X.C; +//// c.m1(); +//// c.y = {}; + +// @Filename: f1.js +//// [|export class C { +//// constructor() { } +//// } +//// +//// |] + +verify.getAndApplyCodeFix(/*errorCode*/undefined, 0); +verify.getAndApplyCodeFix(/*errorCode*/undefined, 0); +verify.getAndApplyCodeFix(/*errorCode*/undefined, 0); +verify.getAndApplyCodeFix(/*errorCode*/undefined, 0); + +verify.rangeIs(` +export class C { + m1() { + throw new Error("Method not implemented."); + } + static m0(arg0, arg1, arg2) { + throw new Error("Method not implemented."); + } + constructor() { + this.y = undefined; + } +} +C.x = undefined; +`); \ No newline at end of file diff --git a/tests/cases/fourslash/codeFixUndeclaredInStaticMethod.ts b/tests/cases/fourslash/codeFixUndeclaredInStaticMethod.ts new file mode 100644 index 0000000000000..75be5420e43d9 --- /dev/null +++ b/tests/cases/fourslash/codeFixUndeclaredInStaticMethod.ts @@ -0,0 +1,26 @@ +/// + +//// class A {[| +//// |]static foo0() { +//// this.m1(1,2,3); +//// A.m2(1,2); +//// this.prop1 = 10; +//// A.prop2 = "asdf"; +//// } +//// } + +verify.getAndApplyCodeFix(/*errorCode*/undefined, 0); +verify.getAndApplyCodeFix(/*errorCode*/undefined, 0); +verify.getAndApplyCodeFix(/*errorCode*/undefined, 0); +verify.getAndApplyCodeFix(/*errorCode*/undefined, 0); + +verify.rangeIs(` + static prop2: string; + static prop1: number; + static m2(arg0: any, arg1: any): any { + throw new Error("Method not implemented."); + } + static m1(arg0: any, arg1: any, arg2: any): any { + throw new Error("Method not implemented."); + } +`); diff --git a/tests/cases/fourslash/codeFixUndeclaredMethod.ts b/tests/cases/fourslash/codeFixUndeclaredMethod.ts new file mode 100644 index 0000000000000..6a61f8421aa43 --- /dev/null +++ b/tests/cases/fourslash/codeFixUndeclaredMethod.ts @@ -0,0 +1,27 @@ +/// + +//// class A {[| +//// |]constructor() { +//// this.foo1(1,2,3); +//// // 7 type args +//// this.foo2<1,2,3,4,5,6,7>(); +//// // 8 type args +//// this.foo3<1,2,3,4,5,6,7,8>(); +//// } +//// } + +verify.getAndApplyCodeFix(/*errorCode*/undefined, 0); +verify.getAndApplyCodeFix(/*errorCode*/undefined, 0); +verify.getAndApplyCodeFix(/*errorCode*/undefined, 0); + +verify.rangeIs(` + foo3(): any { + throw new Error("Method not implemented."); + } + foo2(): any { + throw new Error("Method not implemented."); + } + foo1(arg0: any, arg1: any, arg2: any): any { + throw new Error("Method not implemented."); + } +`); \ No newline at end of file diff --git a/tests/cases/fourslash/codeFixUndeclaredPropertyAccesses.ts b/tests/cases/fourslash/codeFixUndeclaredPropertyAccesses.ts new file mode 100644 index 0000000000000..ee05d2c0a9c95 --- /dev/null +++ b/tests/cases/fourslash/codeFixUndeclaredPropertyAccesses.ts @@ -0,0 +1,17 @@ +/// + +//// interface I { x: number; } +//// let i: I; +//// i.y; +//// i.foo(); +//// enum E { a,b } +//// let e: typeof E; +//// e.a; +//// e.c; +//// let obj = { a: 1, b: "asdf"}; +//// obj.c; +//// type T = I | U; +//// let t: T; +//// t.x; + +verify.not.codeFixAvailable(); \ No newline at end of file diff --git a/tests/cases/fourslash/contextualTypingOfGenericCallSignatures2.ts b/tests/cases/fourslash/contextualTypingOfGenericCallSignatures2.ts index 0f610a2a53910..efb26cb3af1a4 100644 --- a/tests/cases/fourslash/contextualTypingOfGenericCallSignatures2.ts +++ b/tests/cases/fourslash/contextualTypingOfGenericCallSignatures2.ts @@ -7,5 +7,5 @@ ////// x should not be contextually typed so this should be an error ////f6(/**/x => x()) -verify.quickInfoAt("", "(parameter) x: any"); +verify.quickInfoAt("", "(parameter) x: T extends I"); verify.numberOfErrorsInCurrentFile(1); diff --git a/tests/cases/fourslash/contextuallyTypedFunctionExpressionGeneric1.ts b/tests/cases/fourslash/contextuallyTypedFunctionExpressionGeneric1.ts index a33e2cc5e7aab..bfc4d7ea6fdf4 100644 --- a/tests/cases/fourslash/contextuallyTypedFunctionExpressionGeneric1.ts +++ b/tests/cases/fourslash/contextuallyTypedFunctionExpressionGeneric1.ts @@ -1,17 +1,17 @@ /// ////interface Comparable { -//// compareTo(other: T): T; +//// compareTo(other: T): T; ////} ////interface Comparer { -//// >(x: T, y: T): T; +//// >(x: T, y: T): T; ////} ////var max2: Comparer = (x/*1*/x, y/*2*/y) => { return x/*3*/x.compareTo(y/*4*/y) }; verify.quickInfos({ - 1: "(parameter) xx: any", - 2: "(parameter) yy: any", - 3: "(parameter) xx: any", - 4: "(parameter) yy: any" + 1: "(parameter) xx: T extends Comparable", + 2: "(parameter) yy: T extends Comparable", + 3: "(parameter) xx: T extends Comparable", + 4: "(parameter) yy: T extends Comparable" }); diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 3fada673f354d..3e80b0056250e 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -236,7 +236,9 @@ declare namespace FourSlashInterface { noMatchingBracePositionInCurrentFile(bracePosition: number): void; DocCommentTemplate(expectedText: string, expectedOffset: number, empty?: boolean): void; noDocCommentTemplate(): void; - rangeAfterCodeFix(expectedText: string, includeWhiteSpace?: boolean, errorCode?: number, index?: number): void; + rangeAfterCodeFix(expectedText: string, includeWhiteSpace?: boolean, errorCode?: number, index?: number): void + getAndApplyCodeFix(errorCode?: number, index?: number): void; + rangeIs(expectedText: string, includeWhiteSpace?: boolean): void; fileAfterApplyingRefactorAtMarker(markerName: string, expectedContent: string, refactorNameToApply: string, formattingOptions?: FormatCodeOptions): void; importFixAtPosition(expectedTextArray: string[], errorCode?: number): void; diff --git a/tests/cases/fourslash/importNameCodeFixUMDGlobalReact0.ts b/tests/cases/fourslash/importNameCodeFixUMDGlobalReact0.ts new file mode 100644 index 0000000000000..260c34d10a604 --- /dev/null +++ b/tests/cases/fourslash/importNameCodeFixUMDGlobalReact0.ts @@ -0,0 +1,28 @@ +/// + +// @jsx: react + +// @Filename: /node_modules/@types/react/index.d.ts +////export = React; +////export as namespace React; +////declare namespace React { +//// export class Component { render(): JSX.Element | null; } +////} +////declare global { +//// namespace JSX { +//// interface Element {} +//// } +////} + +// @Filename: /a.tsx +////[|import { Component } from "react"; +////export class MyMap extends Component { } +////;|] + +goTo.file("/a.tsx"); + +verify.importFixAtPosition([ +`import { Component } from "react"; +import * as React from "react"; +export class MyMap extends Component { } +;`]); diff --git a/tests/cases/fourslash/importNameCodeFixUMDGlobalReact1.ts b/tests/cases/fourslash/importNameCodeFixUMDGlobalReact1.ts new file mode 100644 index 0000000000000..ccd69c501997a --- /dev/null +++ b/tests/cases/fourslash/importNameCodeFixUMDGlobalReact1.ts @@ -0,0 +1,28 @@ +/// + +// @jsx: react + +// @Filename: /node_modules/@types/react/index.d.ts +////export = React; +////export as namespace React; +////declare namespace React { +//// export class Component { render(): JSX.Element | null; } +////} +////declare global { +//// namespace JSX { +//// interface Element {} +//// } +////} + +// @Filename: /a.tsx +////[|import { Component } from "react"; +////export class MyMap extends Component { } +////;|] + +goTo.file("/a.tsx"); + +verify.importFixAtPosition([ +`import { Component } from "react"; +import * as React from "react"; +export class MyMap extends Component { } +;`]); diff --git a/tests/cases/fourslash/importNameCodeFixUMDGlobalReact2.ts b/tests/cases/fourslash/importNameCodeFixUMDGlobalReact2.ts new file mode 100644 index 0000000000000..a3c8253fbd1a7 --- /dev/null +++ b/tests/cases/fourslash/importNameCodeFixUMDGlobalReact2.ts @@ -0,0 +1,21 @@ +/// + +// https://github.com/Microsoft/TypeScript/issues/16065 + +// @jsx: react +// @jsxFactory: factory + +// @Filename: /factory.ts +////export function factory() { return {}; } +////declare global { +//// namespace JSX { +//// interface Element {} +//// } +////} + +// @Filename: /a.tsx +////[|
|] + +goTo.file("/a.tsx"); +verify.not +verify.importFixAtPosition([]); diff --git a/tests/cases/fourslash/jsxQualifiedTagCompletion.ts b/tests/cases/fourslash/jsxQualifiedTagCompletion.ts new file mode 100644 index 0000000000000..3d799324e7edf --- /dev/null +++ b/tests/cases/fourslash/jsxQualifiedTagCompletion.ts @@ -0,0 +1,15 @@ +/// + +//@Filename: file.tsx +//// declare var React: any; +//// namespace NS { +//// export var Foo: any = null; +//// } +//// const j = Hello!/**/ +//// + +goTo.marker(); +edit.insert("