diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1421c4a3749ae..0089854f0b8a5 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1464,6 +1464,43 @@ namespace ts { return getSymbolOfPartOfRightHandSideOfImportEquals(node.moduleReference, dontResolveAlias); } + function resolveExportByName(moduleSymbol: Symbol, name: __String, dontResolveAlias: boolean) { + const exportValue = moduleSymbol.exports.get(InternalSymbolName.ExportEquals); + return exportValue + ? getPropertyOfType(getTypeOfSymbol(exportValue), name) + : resolveSymbol(moduleSymbol.exports.get(name), dontResolveAlias); + } + + function canHaveSyntheticDefault(file: SourceFile | undefined, moduleSymbol: Symbol, dontResolveAlias: boolean) { + if (!allowSyntheticDefaultImports) { + return false; + } + // Declaration files (and ambient modules) + if (!file || file.isDeclarationFile) { + // Definitely cannot have a synthetic default if they have a default member specified + if (resolveExportByName(moduleSymbol, InternalSymbolName.Default, dontResolveAlias)) { + return false; + } + // It _might_ still be incorrect to assume there is no __esModule marker on the import at runtime, even if there is no `default` member + // So we check a bit more, + if (resolveExportByName(moduleSymbol, escapeLeadingUnderscores("__esModule"), dontResolveAlias)) { + // If there is an `__esModule` specified in the declaration (meaning someone explicitly added it or wrote it in their code), + // it definitely is a module and does not have a synthetic default + return false; + } + // There are _many_ declaration files not written with esmodules in mind that still get compiled into a format with __esModule set + // Meaning there may be no default at runtime - however to be on the permissive side, we allow access to a synthetic default member + // as there is no marker to indicate if the accompanying JS has `__esModule` or not, or is even native esm + return true; + } + // TypeScript files never have a synthetic default (as they are always emitted with an __esModule marker) _unless_ they contain an export= statement + if (!isSourceFileJavaScript(file)) { + return hasExportAssignmentSymbol(moduleSymbol); + } + // JS files have a synthetic default if they do not contain ES2015+ module syntax (export = is not valid in js) _and_ do not have an __esModule marker + return !file.externalModuleIndicator && !resolveExportByName(moduleSymbol, escapeLeadingUnderscores("__esModule"), dontResolveAlias); + } + function getTargetOfImportClause(node: ImportClause, dontResolveAlias: boolean): Symbol { const moduleSymbol = resolveExternalModuleName(node, (node.parent).moduleSpecifier); @@ -1473,16 +1510,16 @@ namespace ts { exportDefaultSymbol = moduleSymbol; } else { - const exportValue = moduleSymbol.exports.get("export=" as __String); - exportDefaultSymbol = exportValue - ? getPropertyOfType(getTypeOfSymbol(exportValue), InternalSymbolName.Default) - : resolveSymbol(moduleSymbol.exports.get(InternalSymbolName.Default), dontResolveAlias); + exportDefaultSymbol = resolveExportByName(moduleSymbol, InternalSymbolName.Default, dontResolveAlias); } - if (!exportDefaultSymbol && !allowSyntheticDefaultImports) { + const file = find(moduleSymbol.declarations, isSourceFile); + const hasSyntheticDefault = canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias); + if (!exportDefaultSymbol && !hasSyntheticDefault) { error(node.name, Diagnostics.Module_0_has_no_default_export, symbolToString(moduleSymbol)); } - else if (!exportDefaultSymbol && allowSyntheticDefaultImports) { + else if (!exportDefaultSymbol && hasSyntheticDefault) { + // per emit behavior, a synthetic default overrides a "real" .default member if `__esModule` is not present return resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias) || resolveSymbol(moduleSymbol, dontResolveAlias); } return exportDefaultSymbol; @@ -1882,8 +1919,40 @@ namespace ts { // combine other declarations with the module or variable (e.g. a class/module, function/module, interface/variable). function resolveESModuleSymbol(moduleSymbol: Symbol, moduleReferenceExpression: Expression, dontResolveAlias: boolean): Symbol { const symbol = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias); - if (!dontResolveAlias && symbol && !(symbol.flags & (SymbolFlags.Module | SymbolFlags.Variable))) { - error(moduleReferenceExpression, Diagnostics.Module_0_resolves_to_a_non_module_entity_and_cannot_be_imported_using_this_construct, symbolToString(moduleSymbol)); + if (!dontResolveAlias && symbol) { + if (!(symbol.flags & (SymbolFlags.Module | SymbolFlags.Variable))) { + error(moduleReferenceExpression, Diagnostics.Module_0_resolves_to_a_non_module_entity_and_cannot_be_imported_using_this_construct, symbolToString(moduleSymbol)); + return symbol; + } + if (compilerOptions.esModuleInterop) { + const referenceParent = moduleReferenceExpression.parent; + if ( + (isImportDeclaration(referenceParent) && getNamespaceDeclarationNode(referenceParent)) || + isImportCall(referenceParent) + ) { + const type = getTypeOfSymbol(symbol); + let sigs = getSignaturesOfStructuredType(type, SignatureKind.Call); + if (!sigs || !sigs.length) { + sigs = getSignaturesOfStructuredType(type, SignatureKind.Construct); + } + if (sigs && sigs.length) { + const moduleType = getTypeWithSyntheticDefaultImportType(type, symbol, moduleSymbol); + // Create a new symbol which has the module's type less the call and construct signatures + const result = createSymbol(symbol.flags, symbol.escapedName); + result.declarations = symbol.declarations ? symbol.declarations.slice() : []; + result.parent = symbol.parent; + result.target = symbol; + result.originatingImport = referenceParent; + if (symbol.valueDeclaration) result.valueDeclaration = symbol.valueDeclaration; + if (symbol.constEnumOnlyModule) result.constEnumOnlyModule = true; + if (symbol.members) result.members = cloneMap(symbol.members); + if (symbol.exports) result.exports = cloneMap(symbol.exports); + const resolvedModuleType = resolveStructuredTypeMembers(moduleType as StructuredType); // Should already be resolved from the signature checks above + result.type = createAnonymousType(result, resolvedModuleType.members, emptyArray, emptyArray, resolvedModuleType.stringIndexInfo, resolvedModuleType.numberIndexInfo); + return result; + } + } + } } return symbol; } @@ -9401,6 +9470,17 @@ namespace ts { diagnostics.add(createDiagnosticForNodeFromMessageChain(errorNode, errorInfo)); } + // Check if we should issue an extra diagnostic to produce a quickfix for a slightly incorrect import statement + if (headMessage && errorNode && !result && source.symbol) { + const links = getSymbolLinks(source.symbol); + if (links.originatingImport && !isImportCall(links.originatingImport)) { + const helpfulRetry = checkTypeRelatedTo(getTypeOfSymbol(links.target), target, relation, /*errorNode*/ undefined); + if (helpfulRetry) { + // Likely an incorrect import. Issue a helpful diagnostic to produce a quickfix to change the import + diagnostics.add(createDiagnosticForNode(links.originatingImport, Diagnostics.A_namespace_style_import_cannot_be_called_or_constructed_and_will_cause_a_failure_at_runtime)); + } + } + } return result !== Ternary.False; function reportError(message: DiagnosticMessage, arg0?: string, arg1?: string, arg2?: string): void { @@ -17256,7 +17336,7 @@ namespace ts { error(node, Diagnostics.Value_of_type_0_is_not_callable_Did_you_mean_to_include_new, typeToString(funcType)); } else { - error(node, Diagnostics.Cannot_invoke_an_expression_whose_type_lacks_a_call_signature_Type_0_has_no_compatible_call_signatures, typeToString(apparentType)); + invocationError(node, apparentType, SignatureKind.Call); } return resolveErrorCall(node); } @@ -17346,7 +17426,7 @@ namespace ts { return signature; } - error(node, Diagnostics.Cannot_use_new_with_an_expression_whose_type_lacks_a_call_or_construct_signature); + invocationError(node, expressionType, SignatureKind.Construct); return resolveErrorCall(node); } @@ -17393,6 +17473,28 @@ namespace ts { return true; } + function invocationError(node: Node, apparentType: Type, kind: SignatureKind) { + error(node, kind === SignatureKind.Call + ? Diagnostics.Cannot_invoke_an_expression_whose_type_lacks_a_call_signature_Type_0_has_no_compatible_call_signatures + : Diagnostics.Cannot_use_new_with_an_expression_whose_type_lacks_a_call_or_construct_signature + , typeToString(apparentType)); + invocationErrorRecovery(apparentType, kind); + } + + function invocationErrorRecovery(apparentType: Type, kind: SignatureKind) { + if (!apparentType.symbol) { + return; + } + const importNode = getSymbolLinks(apparentType.symbol).originatingImport; + // Create a diagnostic on the originating import if possible onto which we can attach a quickfix + // An import call expression cannot be rewritten into another form to correct the error - the only solution is to use `.default` at the use-site + if (importNode && !isImportCall(importNode)) { + const sigs = getSignaturesOfType(getTypeOfSymbol(getSymbolLinks(apparentType.symbol).target), kind); + if (!sigs || !sigs.length) return; + error(importNode, Diagnostics.A_namespace_style_import_cannot_be_called_or_constructed_and_will_cause_a_failure_at_runtime); + } + } + function resolveTaggedTemplateExpression(node: TaggedTemplateExpression, candidatesOutArray: Signature[]): Signature { const tagType = checkExpression(node.tag); const apparentType = getApparentType(tagType); @@ -17410,7 +17512,7 @@ namespace ts { } if (!callSignatures.length) { - error(node, Diagnostics.Cannot_invoke_an_expression_whose_type_lacks_a_call_signature_Type_0_has_no_compatible_call_signatures, typeToString(apparentType)); + invocationError(node, apparentType, SignatureKind.Call); return resolveErrorCall(node); } @@ -17467,6 +17569,7 @@ namespace ts { errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Cannot_invoke_an_expression_whose_type_lacks_a_call_signature_Type_0_has_no_compatible_call_signatures, typeToString(apparentType)); errorInfo = chainDiagnosticMessages(errorInfo, headMessage); diagnostics.add(createDiagnosticForNodeFromMessageChain(node, errorInfo)); + invocationErrorRecovery(apparentType, SignatureKind.Call); return resolveErrorCall(node); } @@ -17721,17 +17824,19 @@ namespace ts { if (moduleSymbol) { const esModuleSymbol = resolveESModuleSymbol(moduleSymbol, specifier, /*dontRecursivelyResolve*/ true); if (esModuleSymbol) { - return createPromiseReturnType(node, getTypeWithSyntheticDefaultImportType(getTypeOfSymbol(esModuleSymbol), esModuleSymbol)); + return createPromiseReturnType(node, getTypeWithSyntheticDefaultImportType(getTypeOfSymbol(esModuleSymbol), esModuleSymbol, moduleSymbol)); } } return createPromiseReturnType(node, anyType); } - function getTypeWithSyntheticDefaultImportType(type: Type, symbol: Symbol): Type { + function getTypeWithSyntheticDefaultImportType(type: Type, symbol: Symbol, originalSymbol: Symbol): Type { if (allowSyntheticDefaultImports && type && type !== unknownType) { const synthType = type as SyntheticDefaultModuleType; if (!synthType.syntheticType) { - if (!getPropertyOfType(type, InternalSymbolName.Default)) { + const file = find(originalSymbol.declarations, isSourceFile); + const hasSyntheticDefault = canHaveSyntheticDefault(file, originalSymbol, /*dontResolveAlias*/ false); + if (hasSyntheticDefault) { const memberTable = createSymbolTable(); const newSymbol = createSymbol(SymbolFlags.Alias, InternalSymbolName.Default); newSymbol.target = resolveSymbol(symbol); @@ -17739,7 +17844,7 @@ namespace ts { const anonymousSymbol = createSymbol(SymbolFlags.TypeLiteral, InternalSymbolName.Type); const defaultContainingObject = createAnonymousType(anonymousSymbol, memberTable, emptyArray, emptyArray, /*stringIndexInfo*/ undefined, /*numberIndexInfo*/ undefined); anonymousSymbol.type = defaultContainingObject; - synthType.syntheticType = getIntersectionType([type, defaultContainingObject]); + synthType.syntheticType = (type.flags & TypeFlags.StructuredType && type.symbol.flags & (SymbolFlags.Module | SymbolFlags.Variable)) ? getSpreadType(type, defaultContainingObject, anonymousSymbol, /*propegatedFlags*/ 0) : defaultContainingObject; } else { synthType.syntheticType = type; diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index a0f91e3d0e90d..d173059a549c5 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -400,6 +400,13 @@ namespace ts { category: Diagnostics.Module_Resolution_Options, description: Diagnostics.Allow_default_imports_from_modules_with_no_default_export_This_does_not_affect_code_emit_just_typechecking }, + { + name: "esModuleInterop", + type: "boolean", + showInSimplifiedHelpView: true, + category: Diagnostics.Module_Resolution_Options, + description: Diagnostics.Enables_emit_interoperability_between_CommonJS_and_ES_Modules_via_creation_of_namespace_objects_for_all_imports_Implies_allowSyntheticDefaultImports + }, { name: "preserveSymlinks", type: "boolean", @@ -702,7 +709,8 @@ namespace ts { export const defaultInitCompilerOptions: CompilerOptions = { module: ModuleKind.CommonJS, target: ScriptTarget.ES5, - strict: true + strict: true, + esModuleInterop: true }; let optionNameMapCache: OptionNameMap; diff --git a/src/compiler/core.ts b/src/compiler/core.ts index a79a3751db67f..c94b36372ec6f 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -2016,7 +2016,9 @@ namespace ts { const moduleKind = getEmitModuleKind(compilerOptions); return compilerOptions.allowSyntheticDefaultImports !== undefined ? compilerOptions.allowSyntheticDefaultImports - : moduleKind === ModuleKind.System; + : compilerOptions.esModuleInterop + ? moduleKind !== ModuleKind.None && moduleKind < ModuleKind.ES2015 + : moduleKind === ModuleKind.System; } export type StrictOptionName = "noImplicitAny" | "noImplicitThis" | "strictNullChecks" | "strictFunctionTypes" | "strictPropertyInitialization" | "alwaysStrict"; diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 336def7ea52be..34e0e70c44b73 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -3536,6 +3536,14 @@ "category": "Error", "code": 7036 }, + "Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'.": { + "category": "Message", + "code": 7037 + }, + "A namespace-style import cannot be called or constructed, and will cause a failure at runtime.": { + "category": "Error", + "code": 7038 + }, "You cannot rename this element.": { "category": "Error", @@ -3894,5 +3902,13 @@ "Install '{0}'": { "category": "Message", "code": 95014 + }, + "Replace import with '{0}'.": { + "category": "Message", + "code": 95015 + }, + "Use synthetic 'default' member.": { + "category": "Message", + "code": 95016 } } diff --git a/src/compiler/program.ts b/src/compiler/program.ts index de106bae2cdf3..ad24281f67b9d 100755 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1589,6 +1589,7 @@ namespace ts { // synthesize 'import "tslib"' declaration const externalHelpersModuleReference = createLiteral(externalHelpersModuleNameText); const importDecl = createImportDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, /*importClause*/ undefined); + addEmitFlags(importDecl, EmitFlags.NeverApplyImportHelper); externalHelpersModuleReference.parent = importDecl; importDecl.parent = file; imports = [externalHelpersModuleReference]; diff --git a/src/compiler/transformers/module/es2015.ts b/src/compiler/transformers/module/es2015.ts index 3951d08109da7..4f218e4fdcf11 100644 --- a/src/compiler/transformers/module/es2015.ts +++ b/src/compiler/transformers/module/es2015.ts @@ -25,14 +25,14 @@ namespace ts { if (externalHelpersModuleName) { const statements: Statement[] = []; const statementOffset = addPrologue(statements, node.statements); - append(statements, - createImportDeclaration( - /*decorators*/ undefined, - /*modifiers*/ undefined, - createImportClause(/*name*/ undefined, createNamespaceImport(externalHelpersModuleName)), - createLiteral(externalHelpersModuleNameText) - ) + const tslibImport = createImportDeclaration( + /*decorators*/ undefined, + /*modifiers*/ undefined, + createImportClause(/*name*/ undefined, createNamespaceImport(externalHelpersModuleName)), + createLiteral(externalHelpersModuleNameText) ); + addEmitFlags(tslibImport, EmitFlags.NeverApplyImportHelper); + append(statements, tslibImport); addRange(statements, visitNodes(node.statements, visitor, isStatement, statementOffset)); return updateSourceFileNode( diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index 0c8e2cda0f5f4..0d4e5b6864acf 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -148,7 +148,7 @@ namespace ts { // Create an updated SourceFile: // // define(moduleName?, ["module1", "module2"], function ... - return updateSourceFileNode(node, + const updated = updateSourceFileNode(node, setTextRange( createNodeArray([ createStatement( @@ -192,6 +192,9 @@ namespace ts { /*location*/ node.statements ) ); + + addEmitHelpers(updated, context.readEmitHelpers()); + return updated; } /** @@ -296,7 +299,7 @@ namespace ts { // } // })(function ...) - return updateSourceFileNode( + const updated = updateSourceFileNode( node, setTextRange( createNodeArray([ @@ -328,6 +331,9 @@ namespace ts { /*location*/ node.statements ) ); + + addEmitHelpers(updated, context.readEmitHelpers()); + return updated; } /** @@ -385,6 +391,18 @@ namespace ts { return { aliasedModuleNames, unaliasedModuleNames, importAliasNames }; } + function getAMDImportExpressionForImport(node: ImportDeclaration | ExportDeclaration | ImportEqualsDeclaration) { + if (isImportEqualsDeclaration(node) || isExportDeclaration(node) || !getExternalModuleNameLiteral(node, currentSourceFile, host, resolver, compilerOptions)) { + return undefined; + } + const name = getLocalNameForExternalImport(node, currentSourceFile); + const expr = getHelperExpressionForImport(node, name); + if (expr === name) { + return undefined; + } + return createStatement(createAssignment(name, expr)); + } + /** * Transforms a SourceFile into an AMD or UMD module body. * @@ -402,6 +420,9 @@ namespace ts { // Visit each statement of the module body. append(statements, visitNode(currentModuleInfo.externalHelpersImportDeclaration, sourceElementVisitor, isStatement)); + if (moduleKind === ModuleKind.AMD) { + addRange(statements, mapDefined(currentModuleInfo.externalImports, getAMDImportExpressionForImport)); + } addRange(statements, visitNodes(node.statements, sourceElementVisitor, isStatement, statementOffset)); // Append the 'export =' statement if provided. @@ -617,7 +638,12 @@ namespace ts { } } - return createNew(createIdentifier("Promise"), /*typeArguments*/ undefined, [func]); + const promise = createNew(createIdentifier("Promise"), /*typeArguments*/ undefined, [func]); + if (compilerOptions.esModuleInterop) { + context.requestEmitHelper(importStarHelper); + return createCall(createPropertyAccess(promise, createIdentifier("then")), /*typeArguments*/ undefined, [getHelperName("__importStar")]); + } + return promise; } function createImportCallExpressionCommonJS(arg: Expression | undefined, containsLexicalThis: boolean): Expression { @@ -627,7 +653,11 @@ namespace ts { // 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 const promiseResolveCall = createCall(createPropertyAccess(createIdentifier("Promise"), "resolve"), /*typeArguments*/ undefined, /*argumentsArray*/ []); - const requireCall = createCall(createIdentifier("require"), /*typeArguments*/ undefined, arg ? [arg] : []); + let requireCall = createCall(createIdentifier("require"), /*typeArguments*/ undefined, arg ? [arg] : []); + if (compilerOptions.esModuleInterop) { + context.requestEmitHelper(importStarHelper); + requireCall = createCall(getHelperName("__importStar"), /*typeArguments*/ undefined, [requireCall]); + } let func: FunctionExpression | ArrowFunction; if (languageVersion >= ScriptTarget.ES2015) { @@ -660,6 +690,22 @@ namespace ts { return createCall(createPropertyAccess(promiseResolveCall, "then"), /*typeArguments*/ undefined, [func]); } + + function getHelperExpressionForImport(node: ImportDeclaration, innerExpr: Expression) { + if (!compilerOptions.esModuleInterop || getEmitFlags(node) & EmitFlags.NeverApplyImportHelper) { + return innerExpr; + } + if (getNamespaceDeclarationNode(node)) { + context.requestEmitHelper(importStarHelper); + return createCall(getHelperName("__importStar"), /*typeArguments*/ undefined, [innerExpr]); + } + if (isDefaultImport(node)) { + context.requestEmitHelper(importDefaultHelper); + return createCall(getHelperName("__importDefault"), /*typeArguments*/ undefined, [innerExpr]); + } + return innerExpr; + } + /** * Visits an ImportDeclaration node. * @@ -681,7 +727,7 @@ namespace ts { createVariableDeclaration( getSynthesizedClone(namespaceDeclaration.name), /*type*/ undefined, - createRequireCall(node) + getHelperExpressionForImport(node, createRequireCall(node)) ) ); } @@ -694,7 +740,7 @@ namespace ts { createVariableDeclaration( getGeneratedNameForNode(node), /*type*/ undefined, - createRequireCall(node) + getHelperExpressionForImport(node, createRequireCall(node)) ) ); @@ -1671,4 +1717,28 @@ namespace ts { text: ` var __syncRequire = typeof module === "object" && typeof module.exports === "object";` }; + + // emit helper for `import * as Name from "foo"` + const importStarHelper: EmitHelper = { + name: "typescript:commonjsimportstar", + scoped: false, + text: ` +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}` + }; + + // emit helper for `import Name from "foo"` + const importDefaultHelper: EmitHelper = { + name: "typescript:commonjsimportdefault", + scoped: false, + text: ` +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}` + }; } diff --git a/src/compiler/transformers/utilities.ts b/src/compiler/transformers/utilities.ts index a012c9be7db9a..15e91d755caf7 100644 --- a/src/compiler/transformers/utilities.ts +++ b/src/compiler/transformers/utilities.ts @@ -143,6 +143,7 @@ namespace ts { createLiteral(externalHelpersModuleNameText)); if (externalHelpersImportDeclaration) { + addEmitFlags(externalHelpersImportDeclaration, EmitFlags.NeverApplyImportHelper); externalImports.unshift(externalHelpersImportDeclaration); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 51465a6baf569..ac8ded7c3b2c9 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3225,6 +3225,7 @@ namespace ts { bindingElement?: BindingElement; // Binding element associated with property symbol exportsSomeValue?: boolean; // True if module exports some value (not just types) enumKind?: EnumKind; // Enum declaration classification + originatingImport?: ImportDeclaration | ImportCall; // Import declaration which produced the symbol, present if the symbol is marked as uncallable but had call signatures in `resolveESModuleSymbol` lateSymbol?: Symbol; // Late-bound symbol for a computed property } @@ -3941,6 +3942,7 @@ namespace ts { typeRoots?: string[]; /*@internal*/ version?: boolean; /*@internal*/ watch?: boolean; + esModuleInterop?: boolean; [option: string]: CompilerOptionsValue | JsonSourceFile | undefined; } @@ -4508,6 +4510,7 @@ namespace ts { Iterator = 1 << 23, // The expression to a `yield*` should be treated as an Iterator when down-leveling, not an Iterable. NoAsciiEscaping = 1 << 24, // When synthesizing nodes that lack an original node or textSourceNode, we want to write the text on the node with ASCII escaping substitutions. /*@internal*/ TypeScriptClassWrapper = 1 << 25, // The node is an IIFE class wrapper created by the ts transform. + /*@internal*/ NeverApplyImportHelper = 1 << 26, // Indicates the node should never be wrapped with an import star helper (because, for example, it imports tslib itself) } export interface EmitHelper { diff --git a/src/services/codefixes/fixInvalidImportSyntax.ts b/src/services/codefixes/fixInvalidImportSyntax.ts new file mode 100644 index 0000000000000..f98f1eaea7cc9 --- /dev/null +++ b/src/services/codefixes/fixInvalidImportSyntax.ts @@ -0,0 +1,98 @@ +/* @internal */ +namespace ts.codefix { + registerCodeFix({ + errorCodes: [Diagnostics.A_namespace_style_import_cannot_be_called_or_constructed_and_will_cause_a_failure_at_runtime.code], + getCodeActions: getActionsForInvalidImport + }); + + function getActionsForInvalidImport(context: CodeFixContext): CodeAction[] | undefined { + const sourceFile = context.sourceFile; + + // This is the whole import statement, eg: + // import * as Bluebird from 'bluebird'; + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + const node = getTokenAtPosition(sourceFile, context.span.start, /*includeJsDocComment*/ false).parent as ImportDeclaration; + if (!isImportDeclaration(node)) { + // No import quick fix for import calls + return []; + } + return getCodeFixesForImportDeclaration(context, node); + } + + function getCodeFixesForImportDeclaration(context: CodeFixContext, node: ImportDeclaration) { + const sourceFile = getSourceFileOfNode(node); + const namespace = getNamespaceDeclarationNode(node) as NamespaceImport; + const opts = context.program.getCompilerOptions(); + const variations: CodeAction[] = []; + + // import Bluebird from "bluebird"; + const replacement = createImportDeclaration( + /*decorators*/ undefined, + /*modifiers*/ undefined, + createImportClause(namespace.name, /*namedBindings*/ undefined), + node.moduleSpecifier + ); + const changeTracker = textChanges.ChangeTracker.fromContext(context); + changeTracker.replaceNode(sourceFile, node, replacement, { useNonAdjustedEndPosition: true }); + const changes = changeTracker.getChanges(); + variations.push({ + description: formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Replace_import_with_0), [changes[0].textChanges[0].newText]), + changes + }); + + if (getEmitModuleKind(opts) === ModuleKind.CommonJS) { + // import Bluebird = require("bluebird"); + const replacement = createImportEqualsDeclaration( + /*decorators*/ undefined, + /*modifiers*/ undefined, + namespace.name, + createExternalModuleReference(node.moduleSpecifier) + ); + const changeTracker = textChanges.ChangeTracker.fromContext(context); + changeTracker.replaceNode(sourceFile, node, replacement, { useNonAdjustedEndPosition: true }); + const changes = changeTracker.getChanges(); + variations.push({ + description: formatStringFromArgs(getLocaleSpecificMessage(Diagnostics.Replace_import_with_0), [changes[0].textChanges[0].newText]), + changes + }); + } + + return variations; + } + + registerCodeFix({ + errorCodes: [ + Diagnostics.Cannot_invoke_an_expression_whose_type_lacks_a_call_signature_Type_0_has_no_compatible_call_signatures.code, + Diagnostics.Cannot_use_new_with_an_expression_whose_type_lacks_a_call_or_construct_signature.code, + ], + getCodeActions: getActionsForUsageOfInvalidImport + }); + + function getActionsForUsageOfInvalidImport(context: CodeFixContext): CodeAction[] | undefined { + const sourceFile = context.sourceFile; + const targetKind = Diagnostics.Cannot_invoke_an_expression_whose_type_lacks_a_call_signature_Type_0_has_no_compatible_call_signatures.code === context.errorCode ? SyntaxKind.CallExpression : SyntaxKind.NewExpression; + const node = findAncestor(getTokenAtPosition(sourceFile, context.span.start, /*includeJsDocComment*/ false), a => a.kind === targetKind && a.getStart() === context.span.start && a.getEnd() === (context.span.start + context.span.length)) as CallExpression | NewExpression; + if (!node) { + return []; + } + const expr = node.expression; + const type = context.program.getTypeChecker().getTypeAtLocation(expr); + if (!(type.symbol && (type.symbol as TransientSymbol).originatingImport)) { + return []; + } + const fixes: CodeAction[] = []; + const relatedImport = (type.symbol as TransientSymbol).originatingImport; + if (!isImportCall(relatedImport)) { + addRange(fixes, getCodeFixesForImportDeclaration(context, relatedImport)); + } + const propertyAccess = createPropertyAccess(expr, "default"); + const changeTracker = textChanges.ChangeTracker.fromContext(context); + changeTracker.replaceNode(sourceFile, expr, propertyAccess, {}); + const changes = changeTracker.getChanges(); + fixes.push({ + description: getLocaleSpecificMessage(Diagnostics.Use_synthetic_default_member), + changes + }); + return fixes; + } +} diff --git a/src/services/codefixes/fixes.ts b/src/services/codefixes/fixes.ts index 5b1ee8ec8572c..bdbd8311a762d 100644 --- a/src/services/codefixes/fixes.ts +++ b/src/services/codefixes/fixes.ts @@ -15,3 +15,5 @@ /// /// /// +/// + diff --git a/tests/baselines/reference/allowSyntheticDefaultImports1.js b/tests/baselines/reference/allowSyntheticDefaultImports1.js index fee1d13770630..8c5565a1fb723 100644 --- a/tests/baselines/reference/allowSyntheticDefaultImports1.js +++ b/tests/baselines/reference/allowSyntheticDefaultImports1.js @@ -4,21 +4,12 @@ import Namespace from "./b"; export var x = new Namespace.Foo(); -//// [b.ts] +//// [b.d.ts] export class Foo { member: string; } -//// [b.js] -"use strict"; -exports.__esModule = true; -var Foo = /** @class */ (function () { - function Foo() { - } - return Foo; -}()); -exports.Foo = Foo; //// [a.js] "use strict"; exports.__esModule = true; diff --git a/tests/baselines/reference/allowSyntheticDefaultImports1.symbols b/tests/baselines/reference/allowSyntheticDefaultImports1.symbols index ecbe9e4c2057a..5ee2812ab59c6 100644 --- a/tests/baselines/reference/allowSyntheticDefaultImports1.symbols +++ b/tests/baselines/reference/allowSyntheticDefaultImports1.symbols @@ -4,15 +4,15 @@ import Namespace from "./b"; export var x = new Namespace.Foo(); >x : Symbol(x, Decl(a.ts, 1, 10)) ->Namespace.Foo : Symbol(Namespace.Foo, Decl(b.ts, 0, 0)) +>Namespace.Foo : Symbol(Namespace.Foo, Decl(b.d.ts, 0, 0)) >Namespace : Symbol(Namespace, Decl(a.ts, 0, 6)) ->Foo : Symbol(Namespace.Foo, Decl(b.ts, 0, 0)) +>Foo : Symbol(Namespace.Foo, Decl(b.d.ts, 0, 0)) -=== tests/cases/compiler/b.ts === +=== tests/cases/compiler/b.d.ts === export class Foo { ->Foo : Symbol(Foo, Decl(b.ts, 0, 0)) +>Foo : Symbol(Foo, Decl(b.d.ts, 0, 0)) member: string; ->member : Symbol(Foo.member, Decl(b.ts, 0, 18)) +>member : Symbol(Foo.member, Decl(b.d.ts, 0, 18)) } diff --git a/tests/baselines/reference/allowSyntheticDefaultImports1.types b/tests/baselines/reference/allowSyntheticDefaultImports1.types index c2265d7611b38..c8092331a4784 100644 --- a/tests/baselines/reference/allowSyntheticDefaultImports1.types +++ b/tests/baselines/reference/allowSyntheticDefaultImports1.types @@ -9,7 +9,7 @@ export var x = new Namespace.Foo(); >Namespace : typeof Namespace >Foo : typeof Namespace.Foo -=== tests/cases/compiler/b.ts === +=== tests/cases/compiler/b.d.ts === export class Foo { >Foo : Foo diff --git a/tests/baselines/reference/allowSyntheticDefaultImports2.js b/tests/baselines/reference/allowSyntheticDefaultImports2.js index 5dc8472d58bc8..c1e43a4fc81e4 100644 --- a/tests/baselines/reference/allowSyntheticDefaultImports2.js +++ b/tests/baselines/reference/allowSyntheticDefaultImports2.js @@ -4,28 +4,11 @@ import Namespace from "./b"; export var x = new Namespace.Foo(); -//// [b.ts] +//// [b.d.ts] export class Foo { member: string; } -//// [b.js] -System.register([], function (exports_1, context_1) { - "use strict"; - var __moduleName = context_1 && context_1.id; - var Foo; - return { - setters: [], - execute: function () { - Foo = /** @class */ (function () { - function Foo() { - } - return Foo; - }()); - exports_1("Foo", Foo); - } - }; -}); //// [a.js] System.register(["./b"], function (exports_1, context_1) { "use strict"; diff --git a/tests/baselines/reference/allowSyntheticDefaultImports2.symbols b/tests/baselines/reference/allowSyntheticDefaultImports2.symbols index 615b1095c66c3..a2b33c94d82a5 100644 --- a/tests/baselines/reference/allowSyntheticDefaultImports2.symbols +++ b/tests/baselines/reference/allowSyntheticDefaultImports2.symbols @@ -4,14 +4,14 @@ import Namespace from "./b"; export var x = new Namespace.Foo(); >x : Symbol(x, Decl(a.ts, 1, 10)) ->Namespace.Foo : Symbol(Namespace.Foo, Decl(b.ts, 0, 0)) +>Namespace.Foo : Symbol(Namespace.Foo, Decl(b.d.ts, 0, 0)) >Namespace : Symbol(Namespace, Decl(a.ts, 0, 6)) ->Foo : Symbol(Namespace.Foo, Decl(b.ts, 0, 0)) +>Foo : Symbol(Namespace.Foo, Decl(b.d.ts, 0, 0)) -=== tests/cases/compiler/b.ts === +=== tests/cases/compiler/b.d.ts === export class Foo { ->Foo : Symbol(Foo, Decl(b.ts, 0, 0)) +>Foo : Symbol(Foo, Decl(b.d.ts, 0, 0)) member: string; ->member : Symbol(Foo.member, Decl(b.ts, 0, 18)) +>member : Symbol(Foo.member, Decl(b.d.ts, 0, 18)) } diff --git a/tests/baselines/reference/allowSyntheticDefaultImports2.types b/tests/baselines/reference/allowSyntheticDefaultImports2.types index c40fbc7e98859..420c19b7c1dd7 100644 --- a/tests/baselines/reference/allowSyntheticDefaultImports2.types +++ b/tests/baselines/reference/allowSyntheticDefaultImports2.types @@ -9,7 +9,7 @@ export var x = new Namespace.Foo(); >Namespace : typeof Namespace >Foo : typeof Namespace.Foo -=== tests/cases/compiler/b.ts === +=== tests/cases/compiler/b.d.ts === export class Foo { >Foo : Foo diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index ad34924a097f9..08d93eb2ace10 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -2294,6 +2294,7 @@ declare namespace ts { types?: string[]; /** Paths used to compute primary types search locations */ typeRoots?: string[]; + esModuleInterop?: boolean; [option: string]: CompilerOptionsValue | JsonSourceFile | undefined; } interface TypeAcquisition { diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 4d06e48dc2565..6a71244f84ca7 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -2294,6 +2294,7 @@ declare namespace ts { types?: string[]; /** Paths used to compute primary types search locations */ typeRoots?: string[]; + esModuleInterop?: boolean; [option: string]: CompilerOptionsValue | JsonSourceFile | undefined; } interface TypeAcquisition { diff --git a/tests/baselines/reference/esModuleInterop.js b/tests/baselines/reference/esModuleInterop.js new file mode 100644 index 0000000000000..9a04ab01be69d --- /dev/null +++ b/tests/baselines/reference/esModuleInterop.js @@ -0,0 +1,39 @@ +//// [tests/cases/compiler/esModuleInterop.ts] //// + +//// [index.d.ts] +export function sayHello(): string; +//// [path.d.ts] +declare const anything: any; +export = anything; +//// [fs.d.ts] +declare const anything: any; +export = anything; +//// [mjts.ts] +import { sayHello } from "./hybrid"; +import path from "./path"; +import * as fs from "./fs"; + +path; +sayHello(); +fs; + + +//// [mjts.js] +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +} +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +} +exports.__esModule = true; +var hybrid_1 = require("./hybrid"); +var path_1 = __importDefault(require("./path")); +var fs = __importStar(require("./fs")); +path_1["default"]; +hybrid_1.sayHello(); +fs; diff --git a/tests/baselines/reference/esModuleInterop.symbols b/tests/baselines/reference/esModuleInterop.symbols new file mode 100644 index 0000000000000..8e173220d4344 --- /dev/null +++ b/tests/baselines/reference/esModuleInterop.symbols @@ -0,0 +1,37 @@ +=== tests/cases/compiler/hybrid/index.d.ts === +export function sayHello(): string; +>sayHello : Symbol(sayHello, Decl(index.d.ts, 0, 0)) + +=== tests/cases/compiler/path.d.ts === +declare const anything: any; +>anything : Symbol(anything, Decl(path.d.ts, 0, 13)) + +export = anything; +>anything : Symbol(anything, Decl(path.d.ts, 0, 13)) + +=== tests/cases/compiler/fs.d.ts === +declare const anything: any; +>anything : Symbol(anything, Decl(fs.d.ts, 0, 13)) + +export = anything; +>anything : Symbol(anything, Decl(fs.d.ts, 0, 13)) + +=== tests/cases/compiler/mjts.ts === +import { sayHello } from "./hybrid"; +>sayHello : Symbol(sayHello, Decl(mjts.ts, 0, 8)) + +import path from "./path"; +>path : Symbol(path, Decl(mjts.ts, 1, 6)) + +import * as fs from "./fs"; +>fs : Symbol(fs, Decl(mjts.ts, 2, 6)) + +path; +>path : Symbol(path, Decl(mjts.ts, 1, 6)) + +sayHello(); +>sayHello : Symbol(sayHello, Decl(mjts.ts, 0, 8)) + +fs; +>fs : Symbol(fs, Decl(mjts.ts, 2, 6)) + diff --git a/tests/baselines/reference/esModuleInterop.types b/tests/baselines/reference/esModuleInterop.types new file mode 100644 index 0000000000000..98e39f596a871 --- /dev/null +++ b/tests/baselines/reference/esModuleInterop.types @@ -0,0 +1,38 @@ +=== tests/cases/compiler/hybrid/index.d.ts === +export function sayHello(): string; +>sayHello : () => string + +=== tests/cases/compiler/path.d.ts === +declare const anything: any; +>anything : any + +export = anything; +>anything : any + +=== tests/cases/compiler/fs.d.ts === +declare const anything: any; +>anything : any + +export = anything; +>anything : any + +=== tests/cases/compiler/mjts.ts === +import { sayHello } from "./hybrid"; +>sayHello : () => string + +import path from "./path"; +>path : any + +import * as fs from "./fs"; +>fs : any + +path; +>path : any + +sayHello(); +>sayHello() : string +>sayHello : () => string + +fs; +>fs : any + diff --git a/tests/baselines/reference/esModuleInteropImportCall.js b/tests/baselines/reference/esModuleInteropImportCall.js new file mode 100644 index 0000000000000..2aa681ded7f92 --- /dev/null +++ b/tests/baselines/reference/esModuleInteropImportCall.js @@ -0,0 +1,23 @@ +//// [tests/cases/compiler/esModuleInteropImportCall.ts] //// + +//// [foo.d.ts] +declare function foo(): void; +declare namespace foo {} +export = foo; + +//// [index.ts] +import("./foo").then(f => { + f.default; +}); + +//// [index.js] +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +} +Promise.resolve().then(function () { return __importStar(require("./foo")); }).then(function (f) { + f["default"]; +}); diff --git a/tests/baselines/reference/esModuleInteropImportCall.symbols b/tests/baselines/reference/esModuleInteropImportCall.symbols new file mode 100644 index 0000000000000..58c5e066f863a --- /dev/null +++ b/tests/baselines/reference/esModuleInteropImportCall.symbols @@ -0,0 +1,23 @@ +=== tests/cases/compiler/foo.d.ts === +declare function foo(): void; +>foo : Symbol(foo, Decl(foo.d.ts, 0, 0), Decl(foo.d.ts, 0, 29)) + +declare namespace foo {} +>foo : Symbol(foo, Decl(foo.d.ts, 0, 0), Decl(foo.d.ts, 0, 29)) + +export = foo; +>foo : Symbol(foo, Decl(foo.d.ts, 0, 0), Decl(foo.d.ts, 0, 29)) + +=== tests/cases/compiler/index.ts === +import("./foo").then(f => { +>import("./foo").then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>"./foo" : Symbol("tests/cases/compiler/foo", Decl(foo.d.ts, 0, 0)) +>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>f : Symbol(f, Decl(index.ts, 0, 21)) + + f.default; +>f.default : Symbol(default) +>f : Symbol(f, Decl(index.ts, 0, 21)) +>default : Symbol(default) + +}); diff --git a/tests/baselines/reference/esModuleInteropImportCall.types b/tests/baselines/reference/esModuleInteropImportCall.types new file mode 100644 index 0000000000000..c194af96c53d6 --- /dev/null +++ b/tests/baselines/reference/esModuleInteropImportCall.types @@ -0,0 +1,26 @@ +=== tests/cases/compiler/foo.d.ts === +declare function foo(): void; +>foo : () => void + +declare namespace foo {} +>foo : () => void + +export = foo; +>foo : () => void + +=== tests/cases/compiler/index.ts === +import("./foo").then(f => { +>import("./foo").then(f => { f.default;}) : Promise +>import("./foo").then : void; }, TResult2 = never>(onfulfilled?: (value: { default: () => void; }) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>import("./foo") : Promise<{ default: () => void; }> +>"./foo" : "./foo" +>then : void; }, TResult2 = never>(onfulfilled?: (value: { default: () => void; }) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>f => { f.default;} : (f: { default: () => void; }) => void +>f : { default: () => void; } + + f.default; +>f.default : () => void +>f : { default: () => void; } +>default : () => void + +}); diff --git a/tests/baselines/reference/esModuleInteropImportNamespace.js b/tests/baselines/reference/esModuleInteropImportNamespace.js new file mode 100644 index 0000000000000..605976faaaa78 --- /dev/null +++ b/tests/baselines/reference/esModuleInteropImportNamespace.js @@ -0,0 +1,24 @@ +//// [tests/cases/compiler/esModuleInteropImportNamespace.ts] //// + +//// [foo.d.ts] +declare function foo(): void; +declare namespace foo {} +export = foo; + +//// [index.ts] +import * as foo from "./foo"; +foo.default; + + +//// [index.js] +"use strict"; +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +} +exports.__esModule = true; +var foo = __importStar(require("./foo")); +foo["default"]; diff --git a/tests/baselines/reference/esModuleInteropImportNamespace.symbols b/tests/baselines/reference/esModuleInteropImportNamespace.symbols new file mode 100644 index 0000000000000..d381d55356855 --- /dev/null +++ b/tests/baselines/reference/esModuleInteropImportNamespace.symbols @@ -0,0 +1,19 @@ +=== tests/cases/compiler/foo.d.ts === +declare function foo(): void; +>foo : Symbol(foo, Decl(foo.d.ts, 0, 0), Decl(foo.d.ts, 0, 29)) + +declare namespace foo {} +>foo : Symbol(foo, Decl(foo.d.ts, 0, 0), Decl(foo.d.ts, 0, 29)) + +export = foo; +>foo : Symbol(foo, Decl(foo.d.ts, 0, 0), Decl(foo.d.ts, 0, 29)) + +=== tests/cases/compiler/index.ts === +import * as foo from "./foo"; +>foo : Symbol(foo, Decl(index.ts, 0, 6)) + +foo.default; +>foo.default : Symbol(default) +>foo : Symbol(foo, Decl(index.ts, 0, 6)) +>default : Symbol(default) + diff --git a/tests/baselines/reference/esModuleInteropImportNamespace.types b/tests/baselines/reference/esModuleInteropImportNamespace.types new file mode 100644 index 0000000000000..e0a49db2794c0 --- /dev/null +++ b/tests/baselines/reference/esModuleInteropImportNamespace.types @@ -0,0 +1,19 @@ +=== tests/cases/compiler/foo.d.ts === +declare function foo(): void; +>foo : () => void + +declare namespace foo {} +>foo : () => void + +export = foo; +>foo : () => void + +=== tests/cases/compiler/index.ts === +import * as foo from "./foo"; +>foo : { default: () => void; } + +foo.default; +>foo.default : () => void +>foo : { default: () => void; } +>default : () => void + diff --git a/tests/baselines/reference/importCallExpressionAsyncES3System.types b/tests/baselines/reference/importCallExpressionAsyncES3System.types index 90c981c01ca75..4f6a2bb31bea1 100644 --- a/tests/baselines/reference/importCallExpressionAsyncES3System.types +++ b/tests/baselines/reference/importCallExpressionAsyncES3System.types @@ -3,9 +3,9 @@ export async function fn() { >fn : () => Promise const req = await import('./test') // ONE ->req : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } ->await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } ->import('./test') : Promise +>req : typeof "tests/cases/conformance/dynamicImport/test" +>await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" +>import('./test') : Promise >'./test' : "./test" } @@ -16,9 +16,9 @@ export class cl1 { >m : () => Promise const req = await import('./test') // TWO ->req : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } ->await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } ->import('./test') : Promise +>req : typeof "tests/cases/conformance/dynamicImport/test" +>await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" +>import('./test') : Promise >'./test' : "./test" } } @@ -32,9 +32,9 @@ export const obj = { >async () => { const req = await import('./test') // THREE } : () => Promise const req = await import('./test') // THREE ->req : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } ->await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } ->import('./test') : Promise +>req : typeof "tests/cases/conformance/dynamicImport/test" +>await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" +>import('./test') : Promise >'./test' : "./test" } } @@ -51,9 +51,9 @@ export class cl2 { >async () => { const req = await import('./test') // FOUR } : () => Promise const req = await import('./test') // FOUR ->req : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } ->await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } ->import('./test') : Promise +>req : typeof "tests/cases/conformance/dynamicImport/test" +>await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" +>import('./test') : Promise >'./test' : "./test" } } @@ -64,9 +64,9 @@ export const l = async () => { >async () => { const req = await import('./test') // FIVE} : () => Promise const req = await import('./test') // FIVE ->req : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } ->await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } ->import('./test') : Promise +>req : typeof "tests/cases/conformance/dynamicImport/test" +>await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" +>import('./test') : Promise >'./test' : "./test" } diff --git a/tests/baselines/reference/importCallExpressionAsyncES5System.types b/tests/baselines/reference/importCallExpressionAsyncES5System.types index 90c981c01ca75..4f6a2bb31bea1 100644 --- a/tests/baselines/reference/importCallExpressionAsyncES5System.types +++ b/tests/baselines/reference/importCallExpressionAsyncES5System.types @@ -3,9 +3,9 @@ export async function fn() { >fn : () => Promise const req = await import('./test') // ONE ->req : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } ->await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } ->import('./test') : Promise +>req : typeof "tests/cases/conformance/dynamicImport/test" +>await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" +>import('./test') : Promise >'./test' : "./test" } @@ -16,9 +16,9 @@ export class cl1 { >m : () => Promise const req = await import('./test') // TWO ->req : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } ->await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } ->import('./test') : Promise +>req : typeof "tests/cases/conformance/dynamicImport/test" +>await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" +>import('./test') : Promise >'./test' : "./test" } } @@ -32,9 +32,9 @@ export const obj = { >async () => { const req = await import('./test') // THREE } : () => Promise const req = await import('./test') // THREE ->req : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } ->await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } ->import('./test') : Promise +>req : typeof "tests/cases/conformance/dynamicImport/test" +>await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" +>import('./test') : Promise >'./test' : "./test" } } @@ -51,9 +51,9 @@ export class cl2 { >async () => { const req = await import('./test') // FOUR } : () => Promise const req = await import('./test') // FOUR ->req : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } ->await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } ->import('./test') : Promise +>req : typeof "tests/cases/conformance/dynamicImport/test" +>await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" +>import('./test') : Promise >'./test' : "./test" } } @@ -64,9 +64,9 @@ export const l = async () => { >async () => { const req = await import('./test') // FIVE} : () => Promise const req = await import('./test') // FIVE ->req : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } ->await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } ->import('./test') : Promise +>req : typeof "tests/cases/conformance/dynamicImport/test" +>await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" +>import('./test') : Promise >'./test' : "./test" } diff --git a/tests/baselines/reference/importCallExpressionAsyncES6System.types b/tests/baselines/reference/importCallExpressionAsyncES6System.types index 90c981c01ca75..4f6a2bb31bea1 100644 --- a/tests/baselines/reference/importCallExpressionAsyncES6System.types +++ b/tests/baselines/reference/importCallExpressionAsyncES6System.types @@ -3,9 +3,9 @@ export async function fn() { >fn : () => Promise const req = await import('./test') // ONE ->req : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } ->await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } ->import('./test') : Promise +>req : typeof "tests/cases/conformance/dynamicImport/test" +>await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" +>import('./test') : Promise >'./test' : "./test" } @@ -16,9 +16,9 @@ export class cl1 { >m : () => Promise const req = await import('./test') // TWO ->req : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } ->await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } ->import('./test') : Promise +>req : typeof "tests/cases/conformance/dynamicImport/test" +>await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" +>import('./test') : Promise >'./test' : "./test" } } @@ -32,9 +32,9 @@ export const obj = { >async () => { const req = await import('./test') // THREE } : () => Promise const req = await import('./test') // THREE ->req : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } ->await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } ->import('./test') : Promise +>req : typeof "tests/cases/conformance/dynamicImport/test" +>await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" +>import('./test') : Promise >'./test' : "./test" } } @@ -51,9 +51,9 @@ export class cl2 { >async () => { const req = await import('./test') // FOUR } : () => Promise const req = await import('./test') // FOUR ->req : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } ->await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } ->import('./test') : Promise +>req : typeof "tests/cases/conformance/dynamicImport/test" +>await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" +>import('./test') : Promise >'./test' : "./test" } } @@ -64,9 +64,9 @@ export const l = async () => { >async () => { const req = await import('./test') // FIVE} : () => Promise const req = await import('./test') // FIVE ->req : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } ->await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } ->import('./test') : Promise +>req : typeof "tests/cases/conformance/dynamicImport/test" +>await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" +>import('./test') : Promise >'./test' : "./test" } diff --git a/tests/baselines/reference/importCallExpressionES5System.types b/tests/baselines/reference/importCallExpressionES5System.types index 02bd64142d499..e97f722b14ff5 100644 --- a/tests/baselines/reference/importCallExpressionES5System.types +++ b/tests/baselines/reference/importCallExpressionES5System.types @@ -5,41 +5,41 @@ export function foo() { return "foo"; } === tests/cases/conformance/dynamicImport/1.ts === import("./0"); ->import("./0") : Promise +>import("./0") : Promise >"./0" : "./0" var p1 = import("./0"); ->p1 : Promise ->import("./0") : Promise +>p1 : Promise +>import("./0") : Promise >"./0" : "./0" p1.then(zero => { >p1.then(zero => { return zero.foo();}) : Promise ->p1.then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0" & { default: 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" & { default: 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" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }) => string ->zero : typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; } +>p1.then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>p1 : Promise +>then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>zero => { return zero.foo();} : (zero: typeof "tests/cases/conformance/dynamicImport/0") => string +>zero : typeof "tests/cases/conformance/dynamicImport/0" return zero.foo(); >zero.foo() : string >zero.foo : () => string ->zero : typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; } +>zero : typeof "tests/cases/conformance/dynamicImport/0" >foo : () => string }); export var p2 = import("./0"); ->p2 : Promise ->import("./0") : Promise +>p2 : Promise +>import("./0") : Promise >"./0" : "./0" function foo() { >foo : () => void const p2 = import("./0"); ->p2 : Promise ->import("./0") : Promise +>p2 : Promise +>import("./0") : Promise >"./0" : "./0" } @@ -50,8 +50,8 @@ class C { >method : () => void const loadAsync = import ("./0"); ->loadAsync : Promise ->import ("./0") : Promise +>loadAsync : Promise +>import ("./0") : Promise >"./0" : "./0" } } @@ -63,8 +63,8 @@ export class D { >method : () => void const loadAsync = import ("./0"); ->loadAsync : Promise ->import ("./0") : Promise +>loadAsync : Promise +>import ("./0") : Promise >"./0" : "./0" } } diff --git a/tests/baselines/reference/importCallExpressionES6System.types b/tests/baselines/reference/importCallExpressionES6System.types index 02bd64142d499..e97f722b14ff5 100644 --- a/tests/baselines/reference/importCallExpressionES6System.types +++ b/tests/baselines/reference/importCallExpressionES6System.types @@ -5,41 +5,41 @@ export function foo() { return "foo"; } === tests/cases/conformance/dynamicImport/1.ts === import("./0"); ->import("./0") : Promise +>import("./0") : Promise >"./0" : "./0" var p1 = import("./0"); ->p1 : Promise ->import("./0") : Promise +>p1 : Promise +>import("./0") : Promise >"./0" : "./0" p1.then(zero => { >p1.then(zero => { return zero.foo();}) : Promise ->p1.then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0" & { default: 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" & { default: 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" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }) => string ->zero : typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; } +>p1.then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>p1 : Promise +>then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>zero => { return zero.foo();} : (zero: typeof "tests/cases/conformance/dynamicImport/0") => string +>zero : typeof "tests/cases/conformance/dynamicImport/0" return zero.foo(); >zero.foo() : string >zero.foo : () => string ->zero : typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; } +>zero : typeof "tests/cases/conformance/dynamicImport/0" >foo : () => string }); export var p2 = import("./0"); ->p2 : Promise ->import("./0") : Promise +>p2 : Promise +>import("./0") : Promise >"./0" : "./0" function foo() { >foo : () => void const p2 = import("./0"); ->p2 : Promise ->import("./0") : Promise +>p2 : Promise +>import("./0") : Promise >"./0" : "./0" } @@ -50,8 +50,8 @@ class C { >method : () => void const loadAsync = import ("./0"); ->loadAsync : Promise ->import ("./0") : Promise +>loadAsync : Promise +>import ("./0") : Promise >"./0" : "./0" } } @@ -63,8 +63,8 @@ export class D { >method : () => void const loadAsync = import ("./0"); ->loadAsync : Promise ->import ("./0") : Promise +>loadAsync : Promise +>import ("./0") : Promise >"./0" : "./0" } } diff --git a/tests/baselines/reference/importCallExpressionInSystem1.types b/tests/baselines/reference/importCallExpressionInSystem1.types index a82d817675388..661d27d14692e 100644 --- a/tests/baselines/reference/importCallExpressionInSystem1.types +++ b/tests/baselines/reference/importCallExpressionInSystem1.types @@ -5,40 +5,40 @@ export function foo() { return "foo"; } === tests/cases/conformance/dynamicImport/1.ts === import("./0"); ->import("./0") : Promise +>import("./0") : Promise >"./0" : "./0" var p1 = import("./0"); ->p1 : Promise ->import("./0") : Promise +>p1 : Promise +>import("./0") : Promise >"./0" : "./0" p1.then(zero => { >p1.then(zero => { return zero.foo();}) : Promise ->p1.then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0" & { default: 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" & { default: 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" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }) => string ->zero : typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; } +>p1.then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>p1 : Promise +>then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>zero => { return zero.foo();} : (zero: typeof "tests/cases/conformance/dynamicImport/0") => string +>zero : typeof "tests/cases/conformance/dynamicImport/0" return zero.foo(); >zero.foo() : string >zero.foo : () => string ->zero : typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; } +>zero : typeof "tests/cases/conformance/dynamicImport/0" >foo : () => string }); export var p2 = import("./0"); ->p2 : Promise ->import("./0") : Promise +>p2 : Promise +>import("./0") : Promise >"./0" : "./0" function foo() { >foo : () => void const p2 = import("./0"); ->p2 : Promise ->import("./0") : Promise +>p2 : Promise +>import("./0") : Promise >"./0" : "./0" } diff --git a/tests/baselines/reference/importCallExpressionInSystem2.types b/tests/baselines/reference/importCallExpressionInSystem2.types index 160da81b214fb..44b17eb51fd5c 100644 --- a/tests/baselines/reference/importCallExpressionInSystem2.types +++ b/tests/baselines/reference/importCallExpressionInSystem2.types @@ -41,6 +41,6 @@ function foo(x: Promise) { foo(import("./0")); >foo(import("./0")) : void >foo : (x: Promise) => void ->import("./0") : Promise +>import("./0") : Promise >"./0" : "./0" diff --git a/tests/baselines/reference/importCallExpressionInSystem3.types b/tests/baselines/reference/importCallExpressionInSystem3.types index 08bf03fb506ad..e517be6e722f4 100644 --- a/tests/baselines/reference/importCallExpressionInSystem3.types +++ b/tests/baselines/reference/importCallExpressionInSystem3.types @@ -14,9 +14,9 @@ async function foo() { class C extends (await import("./0")).B {} >C : C >(await import("./0")).B : B ->(await import("./0")) : typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; } ->await import("./0") : typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; } ->import("./0") : Promise +>(await import("./0")) : typeof "tests/cases/conformance/dynamicImport/0" +>await import("./0") : typeof "tests/cases/conformance/dynamicImport/0" +>import("./0") : Promise >"./0" : "./0" >B : typeof B diff --git a/tests/baselines/reference/importCallExpressionInSystem4.types b/tests/baselines/reference/importCallExpressionInSystem4.types index c9f2b2e5211ac..156247851c914 100644 --- a/tests/baselines/reference/importCallExpressionInSystem4.types +++ b/tests/baselines/reference/importCallExpressionInSystem4.types @@ -24,27 +24,27 @@ class C { >C : C private myModule = import("./0"); ->myModule : Promise ->import("./0") : Promise +>myModule : Promise +>import("./0") : Promise >"./0" : "./0" method() { >method : () => void const loadAsync = import("./0"); ->loadAsync : Promise ->import("./0") : Promise +>loadAsync : Promise +>import("./0") : Promise >"./0" : "./0" 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" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->this.myModule : Promise +>this.myModule.then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>this.myModule : Promise >this : this ->myModule : Promise ->then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0" & { default: 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" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }) => void ->Zero : typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; } +>myModule : Promise +>then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>Zero => { console.log(Zero.foo()); } : (Zero: typeof "tests/cases/conformance/dynamicImport/0") => void +>Zero : typeof "tests/cases/conformance/dynamicImport/0" console.log(Zero.foo()); >console.log(Zero.foo()) : any @@ -53,7 +53,7 @@ class C { >log : any >Zero.foo() : string >Zero.foo : () => string ->Zero : typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; } +>Zero : typeof "tests/cases/conformance/dynamicImport/0" >foo : () => string }, async err => { @@ -68,9 +68,9 @@ class C { >err : any let one = await import("./1"); ->one : typeof "tests/cases/conformance/dynamicImport/1" & { default: typeof "tests/cases/conformance/dynamicImport/1"; } ->await import("./1") : typeof "tests/cases/conformance/dynamicImport/1" & { default: typeof "tests/cases/conformance/dynamicImport/1"; } ->import("./1") : Promise +>one : typeof "tests/cases/conformance/dynamicImport/1" +>await import("./1") : typeof "tests/cases/conformance/dynamicImport/1" +>import("./1") : Promise >"./1" : "./1" console.log(one.backup()); @@ -80,7 +80,7 @@ class C { >log : any >one.backup() : string >one.backup : () => string ->one : typeof "tests/cases/conformance/dynamicImport/1" & { default: typeof "tests/cases/conformance/dynamicImport/1"; } +>one : typeof "tests/cases/conformance/dynamicImport/1" >backup : () => string }); @@ -91,27 +91,27 @@ export class D { >D : D private myModule = import("./0"); ->myModule : Promise ->import("./0") : Promise +>myModule : Promise +>import("./0") : Promise >"./0" : "./0" method() { >method : () => void const loadAsync = import("./0"); ->loadAsync : Promise ->import("./0") : Promise +>loadAsync : Promise +>import("./0") : Promise >"./0" : "./0" 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" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->this.myModule : Promise +>this.myModule.then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>this.myModule : Promise >this : this ->myModule : Promise ->then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0" & { default: 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" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }) => void ->Zero : typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; } +>myModule : Promise +>then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>Zero => { console.log(Zero.foo()); } : (Zero: typeof "tests/cases/conformance/dynamicImport/0") => void +>Zero : typeof "tests/cases/conformance/dynamicImport/0" console.log(Zero.foo()); >console.log(Zero.foo()) : any @@ -120,7 +120,7 @@ export class D { >log : any >Zero.foo() : string >Zero.foo : () => string ->Zero : typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; } +>Zero : typeof "tests/cases/conformance/dynamicImport/0" >foo : () => string }, async err => { @@ -135,9 +135,9 @@ export class D { >err : any let one = await import("./1"); ->one : typeof "tests/cases/conformance/dynamicImport/1" & { default: typeof "tests/cases/conformance/dynamicImport/1"; } ->await import("./1") : typeof "tests/cases/conformance/dynamicImport/1" & { default: typeof "tests/cases/conformance/dynamicImport/1"; } ->import("./1") : Promise +>one : typeof "tests/cases/conformance/dynamicImport/1" +>await import("./1") : typeof "tests/cases/conformance/dynamicImport/1" +>import("./1") : Promise >"./1" : "./1" console.log(one.backup()); @@ -147,7 +147,7 @@ export class D { >log : any >one.backup() : string >one.backup : () => string ->one : typeof "tests/cases/conformance/dynamicImport/1" & { default: typeof "tests/cases/conformance/dynamicImport/1"; } +>one : typeof "tests/cases/conformance/dynamicImport/1" >backup : () => string }); diff --git a/tests/baselines/reference/syntheticDefaultExportsWithDynamicImports.types b/tests/baselines/reference/syntheticDefaultExportsWithDynamicImports.types index 1c38ecc466ce5..3f1ef83a0ae9c 100644 --- a/tests/baselines/reference/syntheticDefaultExportsWithDynamicImports.types +++ b/tests/baselines/reference/syntheticDefaultExportsWithDynamicImports.types @@ -9,11 +9,11 @@ export = packageExport; === tests/cases/compiler/index.ts === import("package").then(({default: foo}) => foo(42)); >import("package").then(({default: foo}) => foo(42)) : Promise ->import("package").then : string) & { default: (x: number) => string; }, TResult2 = never>(onfulfilled?: (value: ((x: number) => string) & { default: (x: number) => string; }) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->import("package") : Promise<((x: number) => string) & { default: (x: number) => string; }> +>import("package").then : string; }, TResult2 = never>(onfulfilled?: (value: { default: (x: number) => string; }) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>import("package") : Promise<{ default: (x: number) => string; }> >"package" : "package" ->then : string) & { default: (x: number) => string; }, TResult2 = never>(onfulfilled?: (value: ((x: number) => string) & { default: (x: number) => string; }) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->({default: foo}) => foo(42) : ({ default: foo }: ((x: number) => string) & { default: (x: number) => string; }) => string +>then : string; }, TResult2 = never>(onfulfilled?: (value: { default: (x: number) => string; }) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>({default: foo}) => foo(42) : ({ default: foo }: { default: (x: number) => string; }) => string >default : any >foo : (x: number) => string >foo(42) : string diff --git a/tests/baselines/reference/tsConfig/Default initialized TSConfig/tsconfig.json b/tests/baselines/reference/tsConfig/Default initialized TSConfig/tsconfig.json index d66c75aaf4ef1..26cf24cc2e46d 100644 --- a/tests/baselines/reference/tsConfig/Default initialized TSConfig/tsconfig.json +++ b/tests/baselines/reference/tsConfig/Default initialized TSConfig/tsconfig.json @@ -19,7 +19,7 @@ // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ /* Strict Type-Checking Options */ - "strict": true /* Enable all strict type-checking options. */ + "strict": true, /* Enable all strict type-checking options. */ // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ // "strictNullChecks": true, /* Enable strict null checks. */ // "strictFunctionTypes": true, /* Enable strict checking of function types. */ @@ -41,6 +41,7 @@ // "typeRoots": [], /* List of folders to include type definitions from. */ // "types": [], /* Type declaration files to be included in compilation. */ // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ + "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ /* Source Map Options */ 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 003ee7ff68407..5d7960c825419 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 @@ -28,7 +28,7 @@ // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ /* Additional Checks */ - "noUnusedLocals": true /* Report errors on unused locals. */ + "noUnusedLocals": true, /* Report errors on unused locals. */ // "noUnusedParameters": true, /* Report errors on unused parameters. */ // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ @@ -41,6 +41,7 @@ // "typeRoots": [], /* List of folders to include type definitions from. */ // "types": [], /* Type declaration files to be included in compilation. */ // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ + "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ /* Source Map Options */ 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 c04ad57e297aa..353cb68ea959f 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 @@ -19,7 +19,7 @@ // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ /* Strict Type-Checking Options */ - "strict": true /* Enable all strict type-checking options. */ + "strict": true, /* Enable all strict type-checking options. */ // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ // "strictNullChecks": true, /* Enable strict null checks. */ // "strictFunctionTypes": true, /* Enable strict checking of function types. */ @@ -41,6 +41,7 @@ // "typeRoots": [], /* List of folders to include type definitions from. */ // "types": [], /* Type declaration files to be included in compilation. */ // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ + "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ /* Source Map Options */ 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 05524339c287d..4a28e6f2491a0 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 @@ -19,7 +19,7 @@ // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ /* Strict Type-Checking Options */ - "strict": true /* Enable all strict type-checking options. */ + "strict": true, /* Enable all strict type-checking options. */ // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ // "strictNullChecks": true, /* Enable strict null checks. */ // "strictFunctionTypes": true, /* Enable strict checking of function types. */ @@ -41,6 +41,7 @@ // "typeRoots": [], /* List of folders to include type definitions from. */ // "types": [], /* Type declaration files to be included in compilation. */ // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ + "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ /* Source Map Options */ 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 1681d7202853f..46ae199430d0b 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 @@ -19,7 +19,7 @@ // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ /* Strict Type-Checking Options */ - "strict": true /* Enable all strict type-checking options. */ + "strict": true, /* Enable all strict type-checking options. */ // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ // "strictNullChecks": true, /* Enable strict null checks. */ // "strictFunctionTypes": true, /* Enable strict checking of function types. */ @@ -41,6 +41,7 @@ // "typeRoots": [], /* List of folders to include type definitions from. */ // "types": [], /* Type declaration files to be included in compilation. */ // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ + "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ /* Source Map Options */ 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 d66c75aaf4ef1..26cf24cc2e46d 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 @@ -19,7 +19,7 @@ // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ /* Strict Type-Checking Options */ - "strict": true /* Enable all strict type-checking options. */ + "strict": true, /* Enable all strict type-checking options. */ // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ // "strictNullChecks": true, /* Enable strict null checks. */ // "strictFunctionTypes": true, /* Enable strict checking of function types. */ @@ -41,6 +41,7 @@ // "typeRoots": [], /* List of folders to include type definitions from. */ // "types": [], /* Type declaration files to be included in compilation. */ // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ + "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ /* Source Map Options */ 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 11a8651947afc..069305e2d35b5 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 @@ -19,7 +19,7 @@ // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ /* Strict Type-Checking Options */ - "strict": true /* Enable all strict type-checking options. */ + "strict": true, /* Enable all strict type-checking options. */ // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ // "strictNullChecks": true, /* Enable strict null checks. */ // "strictFunctionTypes": true, /* Enable strict checking of function types. */ @@ -41,6 +41,7 @@ // "typeRoots": [], /* List of folders to include type definitions from. */ // "types": [], /* Type declaration files to be included in compilation. */ // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ + "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ /* Source Map Options */ 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 ed01f3e6abd29..9e1c409f56e1b 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 @@ -39,8 +39,9 @@ // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ // "typeRoots": [], /* List of folders to include type definitions from. */ - "types": ["jquery","mocha"] /* Type declaration files to be included in compilation. */ + "types": ["jquery","mocha"], /* Type declaration files to be included in compilation. */ // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ + "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ /* Source Map Options */ diff --git a/tests/cases/compiler/allowSyntheticDefaultImports1.ts b/tests/cases/compiler/allowSyntheticDefaultImports1.ts index 4793da791361c..a2aadfa0b6eeb 100644 --- a/tests/cases/compiler/allowSyntheticDefaultImports1.ts +++ b/tests/cases/compiler/allowSyntheticDefaultImports1.ts @@ -4,7 +4,7 @@ import Namespace from "./b"; export var x = new Namespace.Foo(); -// @Filename: b.ts +// @Filename: b.d.ts export class Foo { member: string; } diff --git a/tests/cases/compiler/allowSyntheticDefaultImports2.ts b/tests/cases/compiler/allowSyntheticDefaultImports2.ts index 8fa004be38720..efdee90e81742 100644 --- a/tests/cases/compiler/allowSyntheticDefaultImports2.ts +++ b/tests/cases/compiler/allowSyntheticDefaultImports2.ts @@ -3,7 +3,7 @@ import Namespace from "./b"; export var x = new Namespace.Foo(); -// @Filename: b.ts +// @Filename: b.d.ts export class Foo { member: string; } \ No newline at end of file diff --git a/tests/cases/compiler/esModuleInterop.ts b/tests/cases/compiler/esModuleInterop.ts new file mode 100644 index 0000000000000..7dfd8ff8611d0 --- /dev/null +++ b/tests/cases/compiler/esModuleInterop.ts @@ -0,0 +1,17 @@ +// @esModuleInterop: true +// @filename: hybrid/index.d.ts +export function sayHello(): string; +// @filename: path.d.ts +declare const anything: any; +export = anything; +// @filename: fs.d.ts +declare const anything: any; +export = anything; +// @filename: mjts.ts +import { sayHello } from "./hybrid"; +import path from "./path"; +import * as fs from "./fs"; + +path; +sayHello(); +fs; diff --git a/tests/cases/compiler/esModuleInteropImportCall.ts b/tests/cases/compiler/esModuleInteropImportCall.ts new file mode 100644 index 0000000000000..759d4f3f9368b --- /dev/null +++ b/tests/cases/compiler/esModuleInteropImportCall.ts @@ -0,0 +1,11 @@ +// @esModuleInterop: true +// @lib: es6 +// @Filename: foo.d.ts +declare function foo(): void; +declare namespace foo {} +export = foo; + +// @Filename: index.ts +import("./foo").then(f => { + f.default; +}); \ No newline at end of file diff --git a/tests/cases/compiler/esModuleInteropImportNamespace.ts b/tests/cases/compiler/esModuleInteropImportNamespace.ts new file mode 100644 index 0000000000000..0b3c92577ef6c --- /dev/null +++ b/tests/cases/compiler/esModuleInteropImportNamespace.ts @@ -0,0 +1,9 @@ +// @esModuleInterop: true +// @Filename: foo.d.ts +declare function foo(): void; +declare namespace foo {} +export = foo; + +// @Filename: index.ts +import * as foo from "./foo"; +foo.default; diff --git a/tests/cases/fourslash/codeFixCalledES2015Import1.ts b/tests/cases/fourslash/codeFixCalledES2015Import1.ts new file mode 100644 index 0000000000000..45e88c190478d --- /dev/null +++ b/tests/cases/fourslash/codeFixCalledES2015Import1.ts @@ -0,0 +1,18 @@ +/// +// @esModuleInterop: true +// @Filename: foo.d.ts +////declare function foo(): void; +////declare namespace foo {} +////export = foo; + +// @Filename: index.ts +////[|import * as foo from "./foo";|] +////function invoke(f: () => void) { f(); } +////invoke(foo); + +goTo.file(1); +verify.codeFix({ + description: `Replace import with 'import foo = require("./foo");'.`, + newRangeContent: `import foo = require("./foo");`, + index: 1, +}); diff --git a/tests/cases/fourslash/codeFixCalledES2015Import10.ts b/tests/cases/fourslash/codeFixCalledES2015Import10.ts new file mode 100644 index 0000000000000..d82e345c56ce5 --- /dev/null +++ b/tests/cases/fourslash/codeFixCalledES2015Import10.ts @@ -0,0 +1,18 @@ +/// +// @esModuleInterop: true +// @Filename: foo.d.ts +////declare function foo(): void; +////declare namespace foo {} +////export = foo; + +// @Filename: index.ts +////import * as foo from "./foo"; +////[|foo()|]; + +goTo.file(1); +verify.codeFix({ + description: `Replace import with 'import foo = require("./foo");'.`, + newFileContent: `import foo = require("./foo"); +foo();`, + index: 1, +}); diff --git a/tests/cases/fourslash/codeFixCalledES2015Import11.ts b/tests/cases/fourslash/codeFixCalledES2015Import11.ts new file mode 100644 index 0000000000000..14b02fa38bcf3 --- /dev/null +++ b/tests/cases/fourslash/codeFixCalledES2015Import11.ts @@ -0,0 +1,18 @@ +/// +// @esModuleInterop: true +// @Filename: foo.d.ts +////declare function foo(): void; +////declare namespace foo {} +////export = foo; + +// @Filename: index.ts +////import * as foo from "./foo"; +////[|foo()|]; + +goTo.file(1); +verify.codeFix({ + description: `Replace import with 'import foo from "./foo";'.`, + newFileContent: `import foo from "./foo"; +foo();`, + index: 0, +}); diff --git a/tests/cases/fourslash/codeFixCalledES2015Import12.ts b/tests/cases/fourslash/codeFixCalledES2015Import12.ts new file mode 100644 index 0000000000000..6c31531d572ef --- /dev/null +++ b/tests/cases/fourslash/codeFixCalledES2015Import12.ts @@ -0,0 +1,18 @@ +/// +// @esModuleInterop: true +// @Filename: foo.d.ts +////declare function foo(): void; +////declare namespace foo {} +////export = foo; + +// @Filename: index.ts +////import * as foo from "./foo"; +////[|foo()|]; + +goTo.file(1); +verify.codeFix({ + description: `Use synthetic 'default' member.`, + newFileContent: `import * as foo from "./foo"; +foo.default();`, + index: 4, +}); diff --git a/tests/cases/fourslash/codeFixCalledES2015Import13.ts b/tests/cases/fourslash/codeFixCalledES2015Import13.ts new file mode 100644 index 0000000000000..a67371bd46a96 --- /dev/null +++ b/tests/cases/fourslash/codeFixCalledES2015Import13.ts @@ -0,0 +1,18 @@ +/// +// @esModuleInterop: true +// @Filename: foo.d.ts +////declare function foo(): void; +////declare namespace foo {} +////export = foo; + +// @Filename: index.ts +////import * as Foo from "./foo"; +////[|new Foo()|]; + +goTo.file(1); +verify.codeFix({ + description: `Use synthetic 'default' member.`, + newFileContent: `import * as Foo from "./foo"; +new Foo.default();`, + index: 2, +}); diff --git a/tests/cases/fourslash/codeFixCalledES2015Import2.ts b/tests/cases/fourslash/codeFixCalledES2015Import2.ts new file mode 100644 index 0000000000000..80040cb419287 --- /dev/null +++ b/tests/cases/fourslash/codeFixCalledES2015Import2.ts @@ -0,0 +1,18 @@ +/// +// @esModuleInterop: true +// @Filename: foo.d.ts +////declare function foo(): void; +////declare namespace foo {} +////export = foo; + +// @Filename: index.ts +////[|import * as foo from "./foo";|] +////function invoke(f: () => void) { f(); } +////invoke(foo); + +goTo.file(1); +verify.codeFix({ + description: `Replace import with 'import foo from "./foo";'.`, + newRangeContent: `import foo from "./foo";`, + index: 0, +}); diff --git a/tests/cases/fourslash/codeFixCalledES2015Import3.ts b/tests/cases/fourslash/codeFixCalledES2015Import3.ts new file mode 100644 index 0000000000000..82f08fbc22f0b --- /dev/null +++ b/tests/cases/fourslash/codeFixCalledES2015Import3.ts @@ -0,0 +1,19 @@ +/// +// @esModuleInterop: true +// @module: amd +// @Filename: foo.d.ts +////declare function foo(): void; +////declare namespace foo {} +////export = foo; + +// @Filename: index.ts +////[|import * as foo from "./foo";|] +////function invoke(f: () => void) { f(); } +////invoke(foo); + +goTo.file(1); +verify.codeFix({ + description: `Replace import with 'import foo from "./foo";'.`, + newRangeContent: `import foo from "./foo";`, + index: 0, +}); diff --git a/tests/cases/fourslash/codeFixCalledES2015Import4.ts b/tests/cases/fourslash/codeFixCalledES2015Import4.ts new file mode 100644 index 0000000000000..ba6d90d6d411f --- /dev/null +++ b/tests/cases/fourslash/codeFixCalledES2015Import4.ts @@ -0,0 +1,17 @@ +/// +// @esModuleInterop: true +// @Filename: foo.d.ts +////declare function foo(): void; +////declare namespace foo {} +////export = foo; + +// @Filename: index.ts +////[|import * as foo from "./foo";|] +////foo(); + +goTo.file(1); +verify.codeFix({ + description: `Replace import with 'import foo = require("./foo");'.`, + newRangeContent: `import foo = require("./foo");`, + index: 1, +}); diff --git a/tests/cases/fourslash/codeFixCalledES2015Import5.ts b/tests/cases/fourslash/codeFixCalledES2015Import5.ts new file mode 100644 index 0000000000000..63b2137b6efbb --- /dev/null +++ b/tests/cases/fourslash/codeFixCalledES2015Import5.ts @@ -0,0 +1,17 @@ +/// +// @esModuleInterop: true +// @Filename: foo.d.ts +////declare function foo(): void; +////declare namespace foo {} +////export = foo; + +// @Filename: index.ts +////[|import * as foo from "./foo";|] +////foo(); + +goTo.file(1); +verify.codeFix({ + description: `Replace import with 'import foo from "./foo";'.`, + newRangeContent: `import foo from "./foo";`, + index: 0, +}); diff --git a/tests/cases/fourslash/codeFixCalledES2015Import6.ts b/tests/cases/fourslash/codeFixCalledES2015Import6.ts new file mode 100644 index 0000000000000..b741831bce96b --- /dev/null +++ b/tests/cases/fourslash/codeFixCalledES2015Import6.ts @@ -0,0 +1,18 @@ +/// +// @esModuleInterop: true +// @module: amd +// @Filename: foo.d.ts +////declare function foo(): void; +////declare namespace foo {} +////export = foo; + +// @Filename: index.ts +////[|import * as foo from "./foo";|] +////foo(); + +goTo.file(1); +verify.codeFix({ + description: `Replace import with 'import foo from "./foo";'.`, + newRangeContent: `import foo from "./foo";`, + index: 0, +}); diff --git a/tests/cases/fourslash/codeFixCalledES2015Import7.ts b/tests/cases/fourslash/codeFixCalledES2015Import7.ts new file mode 100644 index 0000000000000..070a25254cb13 --- /dev/null +++ b/tests/cases/fourslash/codeFixCalledES2015Import7.ts @@ -0,0 +1,17 @@ +/// +// @esModuleInterop: true +// @Filename: foo.d.ts +////declare class foo(): void; +////declare namespace foo {} +////export = foo; + +// @Filename: index.ts +////[|import * as foo from "./foo";|] +////new foo(); + +goTo.file(1); +verify.codeFix({ + description: `Replace import with 'import foo = require("./foo");'.`, + newRangeContent: `import foo = require("./foo");`, + index: 1, +}); diff --git a/tests/cases/fourslash/codeFixCalledES2015Import8.ts b/tests/cases/fourslash/codeFixCalledES2015Import8.ts new file mode 100644 index 0000000000000..41e547c8abb39 --- /dev/null +++ b/tests/cases/fourslash/codeFixCalledES2015Import8.ts @@ -0,0 +1,17 @@ +/// +// @esModuleInterop: true +// @Filename: foo.d.ts +////declare class foo(): void; +////declare namespace foo {} +////export = foo; + +// @Filename: index.ts +////[|import * as foo from "./foo";|] +////new foo(); + +goTo.file(1); +verify.codeFix({ + description: `Replace import with 'import foo from "./foo";'.`, + newRangeContent: `import foo from "./foo";`, + index: 0, +}); diff --git a/tests/cases/fourslash/codeFixCalledES2015Import9.ts b/tests/cases/fourslash/codeFixCalledES2015Import9.ts new file mode 100644 index 0000000000000..1ce110f056a0b --- /dev/null +++ b/tests/cases/fourslash/codeFixCalledES2015Import9.ts @@ -0,0 +1,18 @@ +/// +// @esModuleInterop: true +// @module: amd +// @Filename: foo.d.ts +////declare class foo(): void; +////declare namespace foo {} +////export = foo; + +// @Filename: index.ts +////[|import * as foo from "./foo";|] +////new foo(); + +goTo.file(1); +verify.codeFix({ + description: `Replace import with 'import foo from "./foo";'.`, + newRangeContent: `import foo from "./foo";`, + index: 0, +}); diff --git a/tests/cases/fourslash/findAllRefsImportStarOfExportEquals.ts b/tests/cases/fourslash/findAllRefsImportStarOfExportEquals.ts index c57f4a67fda98..c409f0c67eba6 100644 --- a/tests/cases/fourslash/findAllRefsImportStarOfExportEquals.ts +++ b/tests/cases/fourslash/findAllRefsImportStarOfExportEquals.ts @@ -1,5 +1,6 @@ /// +// @allowSyntheticDefaultimports: true // @Filename: /node_modules/a/index.d.ts ////declare function [|{| "isWriteAccess": true, "isDefinition": true |}a|](): void; ////declare namespace [|{| "isWriteAccess": true, "isDefinition": true |}a|] { @@ -9,13 +10,13 @@ // Import with different name and we find local refs // @Filename: /b.ts -////import * as [|{| "isWriteAccess": true, "isDefinition": true |}b|] from "a"; +////import [|{| "isWriteAccess": true, "isDefinition": true |}b|] from "a"; ////[|b|](); ////[|b|].x; // Import with same name and we find all refs // @Filename: /c.ts -////import * as [|{| "isWriteAccess": true, "isDefinition": true |}a|] from "a"; +////import [|{| "isWriteAccess": true, "isDefinition": true |}a|] from "a"; ////[|a|](); ////[|a|].x; diff --git a/tests/cases/user/TypeScript-Node-Starter/TypeScript-Node-Starter b/tests/cases/user/TypeScript-Node-Starter/TypeScript-Node-Starter index 9c8f67f596e23..40bdb4eadabc9 160000 --- a/tests/cases/user/TypeScript-Node-Starter/TypeScript-Node-Starter +++ b/tests/cases/user/TypeScript-Node-Starter/TypeScript-Node-Starter @@ -1 +1 @@ -Subproject commit 9c8f67f596e23283f7fe452d67372233d2e4e5d6 +Subproject commit 40bdb4eadabc9fbed7d83e3f26817a931c0763b6