mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 21:53:42 -06:00
Synthesize namespace records for proper esm interop (#19675)
* Integrate importStar and importDefault helpers * Accept baselines * Support dynamic imports, write helpers for umd module (and amd is possible) kinds * Accept baselines * Support AMD, use same helper initialization as is normal * update typechecker to have errors on called imported namespaces and good error recovery with a quickfix * Overhaul allowSyntheticDefaultExports to be safer * Put the new behavior behind a flag * Rename strictESM to ESMInterop * ESMInterop -> ESModuleInterop, make default for tsc --init * Rename ESMInterop -> ESModuleInterop in module.ts, add emit test (since fourslash doesnt do that) * Remove erroneous semicolons from helper * Reword diagnostic * Change style * Edit followup diagnostic * Add secondary quickfix for call sites, tests forthcoming * Add synth default to namespace import type, enhance quickfix * Pair of spare tests for good measure * Fix typos in diagnostic message * Improve comment clarity * Actually accept the updated changes to the esmodule interop description * ESModule -> esModule * Use find and not forEach * Use guard * Rely on implicit falsiness of Result.False * These should have been emit flags
This commit is contained in:
parent
859f0e3070
commit
7e6315075d
@ -1471,6 +1471,43 @@ namespace ts {
|
||||
return getSymbolOfPartOfRightHandSideOfImportEquals(<EntityName>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, (<ImportDeclaration>node.parent).moduleSpecifier);
|
||||
|
||||
@ -1480,16 +1517,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;
|
||||
@ -1889,8 +1926,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;
|
||||
}
|
||||
@ -9452,6 +9521,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 {
|
||||
@ -17320,7 +17400,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);
|
||||
}
|
||||
@ -17410,7 +17490,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);
|
||||
}
|
||||
|
||||
@ -17457,6 +17537,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);
|
||||
@ -17474,7 +17576,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);
|
||||
}
|
||||
|
||||
@ -17531,6 +17633,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);
|
||||
}
|
||||
|
||||
@ -17785,17 +17888,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);
|
||||
@ -17803,7 +17908,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;
|
||||
|
||||
@ -402,6 +402,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",
|
||||
@ -704,7 +711,8 @@ namespace ts {
|
||||
export const defaultInitCompilerOptions: CompilerOptions = {
|
||||
module: ModuleKind.CommonJS,
|
||||
target: ScriptTarget.ES5,
|
||||
strict: true
|
||||
strict: true,
|
||||
esModuleInterop: true
|
||||
};
|
||||
|
||||
let optionNameMapCache: OptionNameMap;
|
||||
|
||||
@ -2005,7 +2005,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";
|
||||
|
||||
@ -3548,6 +3548,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",
|
||||
@ -3906,5 +3914,13 @@
|
||||
"Install '{0}'": {
|
||||
"category": "Message",
|
||||
"code": 95014
|
||||
},
|
||||
"Replace import with '{0}'.": {
|
||||
"category": "Message",
|
||||
"code": 95015
|
||||
},
|
||||
"Use synthetic 'default' member.": {
|
||||
"category": "Message",
|
||||
"code": 95016
|
||||
}
|
||||
}
|
||||
|
||||
@ -1601,6 +1601,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];
|
||||
|
||||
@ -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(
|
||||
|
||||
@ -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 };
|
||||
}`
|
||||
};
|
||||
}
|
||||
|
||||
@ -143,6 +143,7 @@ namespace ts {
|
||||
createLiteral(externalHelpersModuleNameText));
|
||||
|
||||
if (externalHelpersImportDeclaration) {
|
||||
addEmitFlags(externalHelpersImportDeclaration, EmitFlags.NeverApplyImportHelper);
|
||||
externalImports.unshift(externalHelpersImportDeclaration);
|
||||
}
|
||||
|
||||
|
||||
@ -3248,6 +3248,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
|
||||
}
|
||||
|
||||
@ -3978,6 +3979,7 @@ namespace ts {
|
||||
typeRoots?: string[];
|
||||
/*@internal*/ version?: boolean;
|
||||
/*@internal*/ watch?: boolean;
|
||||
esModuleInterop?: boolean;
|
||||
|
||||
[option: string]: CompilerOptionsValue | JsonSourceFile | undefined;
|
||||
}
|
||||
@ -4545,6 +4547,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 {
|
||||
|
||||
98
src/services/codefixes/fixInvalidImportSyntax.ts
Normal file
98
src/services/codefixes/fixInvalidImportSyntax.ts
Normal file
@ -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;
|
||||
}
|
||||
}
|
||||
@ -15,3 +15,5 @@
|
||||
/// <reference path='disableJsDiagnostics.ts' />
|
||||
/// <reference path='helpers.ts' />
|
||||
/// <reference path='inferFromUsage.ts' />
|
||||
/// <reference path="fixInvalidImportSyntax.ts" />
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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))
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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";
|
||||
|
||||
@ -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))
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -2296,6 +2296,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 {
|
||||
|
||||
@ -2296,6 +2296,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 {
|
||||
|
||||
39
tests/baselines/reference/esModuleInterop.js
Normal file
39
tests/baselines/reference/esModuleInterop.js
Normal file
@ -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;
|
||||
37
tests/baselines/reference/esModuleInterop.symbols
Normal file
37
tests/baselines/reference/esModuleInterop.symbols
Normal file
@ -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))
|
||||
|
||||
38
tests/baselines/reference/esModuleInterop.types
Normal file
38
tests/baselines/reference/esModuleInterop.types
Normal file
@ -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
|
||||
|
||||
23
tests/baselines/reference/esModuleInteropImportCall.js
Normal file
23
tests/baselines/reference/esModuleInteropImportCall.js
Normal file
@ -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"];
|
||||
});
|
||||
23
tests/baselines/reference/esModuleInteropImportCall.symbols
Normal file
23
tests/baselines/reference/esModuleInteropImportCall.symbols
Normal file
@ -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)
|
||||
|
||||
});
|
||||
26
tests/baselines/reference/esModuleInteropImportCall.types
Normal file
26
tests/baselines/reference/esModuleInteropImportCall.types
Normal file
@ -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<void>
|
||||
>import("./foo").then : <TResult1 = { default: () => void; }, TResult2 = never>(onfulfilled?: (value: { default: () => void; }) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => Promise<TResult1 | TResult2>
|
||||
>import("./foo") : Promise<{ default: () => void; }>
|
||||
>"./foo" : "./foo"
|
||||
>then : <TResult1 = { default: () => void; }, TResult2 = never>(onfulfilled?: (value: { default: () => void; }) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => Promise<TResult1 | TResult2>
|
||||
>f => { f.default;} : (f: { default: () => void; }) => void
|
||||
>f : { default: () => void; }
|
||||
|
||||
f.default;
|
||||
>f.default : () => void
|
||||
>f : { default: () => void; }
|
||||
>default : () => void
|
||||
|
||||
});
|
||||
24
tests/baselines/reference/esModuleInteropImportNamespace.js
Normal file
24
tests/baselines/reference/esModuleInteropImportNamespace.js
Normal file
@ -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"];
|
||||
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
@ -3,9 +3,9 @@ export async function fn() {
|
||||
>fn : () => Promise<void>
|
||||
|
||||
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<typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; }>
|
||||
>req : typeof "tests/cases/conformance/dynamicImport/test"
|
||||
>await import('./test') : typeof "tests/cases/conformance/dynamicImport/test"
|
||||
>import('./test') : Promise<typeof "tests/cases/conformance/dynamicImport/test">
|
||||
>'./test' : "./test"
|
||||
}
|
||||
|
||||
@ -16,9 +16,9 @@ export class cl1 {
|
||||
>m : () => Promise<void>
|
||||
|
||||
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<typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; }>
|
||||
>req : typeof "tests/cases/conformance/dynamicImport/test"
|
||||
>await import('./test') : typeof "tests/cases/conformance/dynamicImport/test"
|
||||
>import('./test') : Promise<typeof "tests/cases/conformance/dynamicImport/test">
|
||||
>'./test' : "./test"
|
||||
}
|
||||
}
|
||||
@ -32,9 +32,9 @@ export const obj = {
|
||||
>async () => { const req = await import('./test') // THREE } : () => Promise<void>
|
||||
|
||||
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<typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; }>
|
||||
>req : typeof "tests/cases/conformance/dynamicImport/test"
|
||||
>await import('./test') : typeof "tests/cases/conformance/dynamicImport/test"
|
||||
>import('./test') : Promise<typeof "tests/cases/conformance/dynamicImport/test">
|
||||
>'./test' : "./test"
|
||||
}
|
||||
}
|
||||
@ -51,9 +51,9 @@ export class cl2 {
|
||||
>async () => { const req = await import('./test') // FOUR } : () => Promise<void>
|
||||
|
||||
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<typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; }>
|
||||
>req : typeof "tests/cases/conformance/dynamicImport/test"
|
||||
>await import('./test') : typeof "tests/cases/conformance/dynamicImport/test"
|
||||
>import('./test') : Promise<typeof "tests/cases/conformance/dynamicImport/test">
|
||||
>'./test' : "./test"
|
||||
}
|
||||
}
|
||||
@ -64,9 +64,9 @@ export const l = async () => {
|
||||
>async () => { const req = await import('./test') // FIVE} : () => Promise<void>
|
||||
|
||||
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<typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; }>
|
||||
>req : typeof "tests/cases/conformance/dynamicImport/test"
|
||||
>await import('./test') : typeof "tests/cases/conformance/dynamicImport/test"
|
||||
>import('./test') : Promise<typeof "tests/cases/conformance/dynamicImport/test">
|
||||
>'./test' : "./test"
|
||||
}
|
||||
|
||||
|
||||
@ -3,9 +3,9 @@ export async function fn() {
|
||||
>fn : () => Promise<void>
|
||||
|
||||
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<typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; }>
|
||||
>req : typeof "tests/cases/conformance/dynamicImport/test"
|
||||
>await import('./test') : typeof "tests/cases/conformance/dynamicImport/test"
|
||||
>import('./test') : Promise<typeof "tests/cases/conformance/dynamicImport/test">
|
||||
>'./test' : "./test"
|
||||
}
|
||||
|
||||
@ -16,9 +16,9 @@ export class cl1 {
|
||||
>m : () => Promise<void>
|
||||
|
||||
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<typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; }>
|
||||
>req : typeof "tests/cases/conformance/dynamicImport/test"
|
||||
>await import('./test') : typeof "tests/cases/conformance/dynamicImport/test"
|
||||
>import('./test') : Promise<typeof "tests/cases/conformance/dynamicImport/test">
|
||||
>'./test' : "./test"
|
||||
}
|
||||
}
|
||||
@ -32,9 +32,9 @@ export const obj = {
|
||||
>async () => { const req = await import('./test') // THREE } : () => Promise<void>
|
||||
|
||||
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<typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; }>
|
||||
>req : typeof "tests/cases/conformance/dynamicImport/test"
|
||||
>await import('./test') : typeof "tests/cases/conformance/dynamicImport/test"
|
||||
>import('./test') : Promise<typeof "tests/cases/conformance/dynamicImport/test">
|
||||
>'./test' : "./test"
|
||||
}
|
||||
}
|
||||
@ -51,9 +51,9 @@ export class cl2 {
|
||||
>async () => { const req = await import('./test') // FOUR } : () => Promise<void>
|
||||
|
||||
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<typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; }>
|
||||
>req : typeof "tests/cases/conformance/dynamicImport/test"
|
||||
>await import('./test') : typeof "tests/cases/conformance/dynamicImport/test"
|
||||
>import('./test') : Promise<typeof "tests/cases/conformance/dynamicImport/test">
|
||||
>'./test' : "./test"
|
||||
}
|
||||
}
|
||||
@ -64,9 +64,9 @@ export const l = async () => {
|
||||
>async () => { const req = await import('./test') // FIVE} : () => Promise<void>
|
||||
|
||||
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<typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; }>
|
||||
>req : typeof "tests/cases/conformance/dynamicImport/test"
|
||||
>await import('./test') : typeof "tests/cases/conformance/dynamicImport/test"
|
||||
>import('./test') : Promise<typeof "tests/cases/conformance/dynamicImport/test">
|
||||
>'./test' : "./test"
|
||||
}
|
||||
|
||||
|
||||
@ -3,9 +3,9 @@ export async function fn() {
|
||||
>fn : () => Promise<void>
|
||||
|
||||
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<typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; }>
|
||||
>req : typeof "tests/cases/conformance/dynamicImport/test"
|
||||
>await import('./test') : typeof "tests/cases/conformance/dynamicImport/test"
|
||||
>import('./test') : Promise<typeof "tests/cases/conformance/dynamicImport/test">
|
||||
>'./test' : "./test"
|
||||
}
|
||||
|
||||
@ -16,9 +16,9 @@ export class cl1 {
|
||||
>m : () => Promise<void>
|
||||
|
||||
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<typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; }>
|
||||
>req : typeof "tests/cases/conformance/dynamicImport/test"
|
||||
>await import('./test') : typeof "tests/cases/conformance/dynamicImport/test"
|
||||
>import('./test') : Promise<typeof "tests/cases/conformance/dynamicImport/test">
|
||||
>'./test' : "./test"
|
||||
}
|
||||
}
|
||||
@ -32,9 +32,9 @@ export const obj = {
|
||||
>async () => { const req = await import('./test') // THREE } : () => Promise<void>
|
||||
|
||||
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<typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; }>
|
||||
>req : typeof "tests/cases/conformance/dynamicImport/test"
|
||||
>await import('./test') : typeof "tests/cases/conformance/dynamicImport/test"
|
||||
>import('./test') : Promise<typeof "tests/cases/conformance/dynamicImport/test">
|
||||
>'./test' : "./test"
|
||||
}
|
||||
}
|
||||
@ -51,9 +51,9 @@ export class cl2 {
|
||||
>async () => { const req = await import('./test') // FOUR } : () => Promise<void>
|
||||
|
||||
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<typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; }>
|
||||
>req : typeof "tests/cases/conformance/dynamicImport/test"
|
||||
>await import('./test') : typeof "tests/cases/conformance/dynamicImport/test"
|
||||
>import('./test') : Promise<typeof "tests/cases/conformance/dynamicImport/test">
|
||||
>'./test' : "./test"
|
||||
}
|
||||
}
|
||||
@ -64,9 +64,9 @@ export const l = async () => {
|
||||
>async () => { const req = await import('./test') // FIVE} : () => Promise<void>
|
||||
|
||||
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<typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; }>
|
||||
>req : typeof "tests/cases/conformance/dynamicImport/test"
|
||||
>await import('./test') : typeof "tests/cases/conformance/dynamicImport/test"
|
||||
>import('./test') : Promise<typeof "tests/cases/conformance/dynamicImport/test">
|
||||
>'./test' : "./test"
|
||||
}
|
||||
|
||||
|
||||
@ -5,41 +5,41 @@ export function foo() { return "foo"; }
|
||||
|
||||
=== tests/cases/conformance/dynamicImport/1.ts ===
|
||||
import("./0");
|
||||
>import("./0") : Promise<typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }>
|
||||
>import("./0") : Promise<typeof "tests/cases/conformance/dynamicImport/0">
|
||||
>"./0" : "./0"
|
||||
|
||||
var p1 = import("./0");
|
||||
>p1 : Promise<typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }>
|
||||
>import("./0") : Promise<typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }>
|
||||
>p1 : Promise<typeof "tests/cases/conformance/dynamicImport/0">
|
||||
>import("./0") : Promise<typeof "tests/cases/conformance/dynamicImport/0">
|
||||
>"./0" : "./0"
|
||||
|
||||
p1.then(zero => {
|
||||
>p1.then(zero => { return zero.foo();}) : Promise<string>
|
||||
>p1.then : <TResult1 = typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }, TResult2 = never>(onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => Promise<TResult1 | TResult2>
|
||||
>p1 : Promise<typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }>
|
||||
>then : <TResult1 = typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }, TResult2 = never>(onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => Promise<TResult1 | TResult2>
|
||||
>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 : <TResult1 = typeof "tests/cases/conformance/dynamicImport/0", TResult2 = never>(onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => Promise<TResult1 | TResult2>
|
||||
>p1 : Promise<typeof "tests/cases/conformance/dynamicImport/0">
|
||||
>then : <TResult1 = typeof "tests/cases/conformance/dynamicImport/0", TResult2 = never>(onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => Promise<TResult1 | TResult2>
|
||||
>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<typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }>
|
||||
>import("./0") : Promise<typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }>
|
||||
>p2 : Promise<typeof "tests/cases/conformance/dynamicImport/0">
|
||||
>import("./0") : Promise<typeof "tests/cases/conformance/dynamicImport/0">
|
||||
>"./0" : "./0"
|
||||
|
||||
function foo() {
|
||||
>foo : () => void
|
||||
|
||||
const p2 = import("./0");
|
||||
>p2 : Promise<typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }>
|
||||
>import("./0") : Promise<typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }>
|
||||
>p2 : Promise<typeof "tests/cases/conformance/dynamicImport/0">
|
||||
>import("./0") : Promise<typeof "tests/cases/conformance/dynamicImport/0">
|
||||
>"./0" : "./0"
|
||||
}
|
||||
|
||||
@ -50,8 +50,8 @@ class C {
|
||||
>method : () => void
|
||||
|
||||
const loadAsync = import ("./0");
|
||||
>loadAsync : Promise<typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }>
|
||||
>import ("./0") : Promise<typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }>
|
||||
>loadAsync : Promise<typeof "tests/cases/conformance/dynamicImport/0">
|
||||
>import ("./0") : Promise<typeof "tests/cases/conformance/dynamicImport/0">
|
||||
>"./0" : "./0"
|
||||
}
|
||||
}
|
||||
@ -63,8 +63,8 @@ export class D {
|
||||
>method : () => void
|
||||
|
||||
const loadAsync = import ("./0");
|
||||
>loadAsync : Promise<typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }>
|
||||
>import ("./0") : Promise<typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }>
|
||||
>loadAsync : Promise<typeof "tests/cases/conformance/dynamicImport/0">
|
||||
>import ("./0") : Promise<typeof "tests/cases/conformance/dynamicImport/0">
|
||||
>"./0" : "./0"
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,41 +5,41 @@ export function foo() { return "foo"; }
|
||||
|
||||
=== tests/cases/conformance/dynamicImport/1.ts ===
|
||||
import("./0");
|
||||
>import("./0") : Promise<typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }>
|
||||
>import("./0") : Promise<typeof "tests/cases/conformance/dynamicImport/0">
|
||||
>"./0" : "./0"
|
||||
|
||||
var p1 = import("./0");
|
||||
>p1 : Promise<typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }>
|
||||
>import("./0") : Promise<typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }>
|
||||
>p1 : Promise<typeof "tests/cases/conformance/dynamicImport/0">
|
||||
>import("./0") : Promise<typeof "tests/cases/conformance/dynamicImport/0">
|
||||
>"./0" : "./0"
|
||||
|
||||
p1.then(zero => {
|
||||
>p1.then(zero => { return zero.foo();}) : Promise<string>
|
||||
>p1.then : <TResult1 = typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }, TResult2 = never>(onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => Promise<TResult1 | TResult2>
|
||||
>p1 : Promise<typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }>
|
||||
>then : <TResult1 = typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }, TResult2 = never>(onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => Promise<TResult1 | TResult2>
|
||||
>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 : <TResult1 = typeof "tests/cases/conformance/dynamicImport/0", TResult2 = never>(onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => Promise<TResult1 | TResult2>
|
||||
>p1 : Promise<typeof "tests/cases/conformance/dynamicImport/0">
|
||||
>then : <TResult1 = typeof "tests/cases/conformance/dynamicImport/0", TResult2 = never>(onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => Promise<TResult1 | TResult2>
|
||||
>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<typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }>
|
||||
>import("./0") : Promise<typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }>
|
||||
>p2 : Promise<typeof "tests/cases/conformance/dynamicImport/0">
|
||||
>import("./0") : Promise<typeof "tests/cases/conformance/dynamicImport/0">
|
||||
>"./0" : "./0"
|
||||
|
||||
function foo() {
|
||||
>foo : () => void
|
||||
|
||||
const p2 = import("./0");
|
||||
>p2 : Promise<typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }>
|
||||
>import("./0") : Promise<typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }>
|
||||
>p2 : Promise<typeof "tests/cases/conformance/dynamicImport/0">
|
||||
>import("./0") : Promise<typeof "tests/cases/conformance/dynamicImport/0">
|
||||
>"./0" : "./0"
|
||||
}
|
||||
|
||||
@ -50,8 +50,8 @@ class C {
|
||||
>method : () => void
|
||||
|
||||
const loadAsync = import ("./0");
|
||||
>loadAsync : Promise<typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }>
|
||||
>import ("./0") : Promise<typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }>
|
||||
>loadAsync : Promise<typeof "tests/cases/conformance/dynamicImport/0">
|
||||
>import ("./0") : Promise<typeof "tests/cases/conformance/dynamicImport/0">
|
||||
>"./0" : "./0"
|
||||
}
|
||||
}
|
||||
@ -63,8 +63,8 @@ export class D {
|
||||
>method : () => void
|
||||
|
||||
const loadAsync = import ("./0");
|
||||
>loadAsync : Promise<typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }>
|
||||
>import ("./0") : Promise<typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }>
|
||||
>loadAsync : Promise<typeof "tests/cases/conformance/dynamicImport/0">
|
||||
>import ("./0") : Promise<typeof "tests/cases/conformance/dynamicImport/0">
|
||||
>"./0" : "./0"
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,40 +5,40 @@ export function foo() { return "foo"; }
|
||||
|
||||
=== tests/cases/conformance/dynamicImport/1.ts ===
|
||||
import("./0");
|
||||
>import("./0") : Promise<typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }>
|
||||
>import("./0") : Promise<typeof "tests/cases/conformance/dynamicImport/0">
|
||||
>"./0" : "./0"
|
||||
|
||||
var p1 = import("./0");
|
||||
>p1 : Promise<typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }>
|
||||
>import("./0") : Promise<typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }>
|
||||
>p1 : Promise<typeof "tests/cases/conformance/dynamicImport/0">
|
||||
>import("./0") : Promise<typeof "tests/cases/conformance/dynamicImport/0">
|
||||
>"./0" : "./0"
|
||||
|
||||
p1.then(zero => {
|
||||
>p1.then(zero => { return zero.foo();}) : Promise<string>
|
||||
>p1.then : <TResult1 = typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }, TResult2 = never>(onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => Promise<TResult1 | TResult2>
|
||||
>p1 : Promise<typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }>
|
||||
>then : <TResult1 = typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }, TResult2 = never>(onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => Promise<TResult1 | TResult2>
|
||||
>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 : <TResult1 = typeof "tests/cases/conformance/dynamicImport/0", TResult2 = never>(onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => Promise<TResult1 | TResult2>
|
||||
>p1 : Promise<typeof "tests/cases/conformance/dynamicImport/0">
|
||||
>then : <TResult1 = typeof "tests/cases/conformance/dynamicImport/0", TResult2 = never>(onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => Promise<TResult1 | TResult2>
|
||||
>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<typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }>
|
||||
>import("./0") : Promise<typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }>
|
||||
>p2 : Promise<typeof "tests/cases/conformance/dynamicImport/0">
|
||||
>import("./0") : Promise<typeof "tests/cases/conformance/dynamicImport/0">
|
||||
>"./0" : "./0"
|
||||
|
||||
function foo() {
|
||||
>foo : () => void
|
||||
|
||||
const p2 = import("./0");
|
||||
>p2 : Promise<typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }>
|
||||
>import("./0") : Promise<typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }>
|
||||
>p2 : Promise<typeof "tests/cases/conformance/dynamicImport/0">
|
||||
>import("./0") : Promise<typeof "tests/cases/conformance/dynamicImport/0">
|
||||
>"./0" : "./0"
|
||||
}
|
||||
|
||||
@ -41,6 +41,6 @@ function foo(x: Promise<any>) {
|
||||
foo(import("./0"));
|
||||
>foo(import("./0")) : void
|
||||
>foo : (x: Promise<any>) => void
|
||||
>import("./0") : Promise<typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }>
|
||||
>import("./0") : Promise<typeof "tests/cases/conformance/dynamicImport/0">
|
||||
>"./0" : "./0"
|
||||
|
||||
|
||||
@ -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<typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }>
|
||||
>(await import("./0")) : typeof "tests/cases/conformance/dynamicImport/0"
|
||||
>await import("./0") : typeof "tests/cases/conformance/dynamicImport/0"
|
||||
>import("./0") : Promise<typeof "tests/cases/conformance/dynamicImport/0">
|
||||
>"./0" : "./0"
|
||||
>B : typeof B
|
||||
|
||||
|
||||
@ -24,27 +24,27 @@ class C {
|
||||
>C : C
|
||||
|
||||
private myModule = import("./0");
|
||||
>myModule : Promise<typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }>
|
||||
>import("./0") : Promise<typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }>
|
||||
>myModule : Promise<typeof "tests/cases/conformance/dynamicImport/0">
|
||||
>import("./0") : Promise<typeof "tests/cases/conformance/dynamicImport/0">
|
||||
>"./0" : "./0"
|
||||
|
||||
method() {
|
||||
>method : () => void
|
||||
|
||||
const loadAsync = import("./0");
|
||||
>loadAsync : Promise<typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }>
|
||||
>import("./0") : Promise<typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }>
|
||||
>loadAsync : Promise<typeof "tests/cases/conformance/dynamicImport/0">
|
||||
>import("./0") : Promise<typeof "tests/cases/conformance/dynamicImport/0">
|
||||
>"./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<void>
|
||||
>this.myModule.then : <TResult1 = typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }, TResult2 = never>(onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => Promise<TResult1 | TResult2>
|
||||
>this.myModule : Promise<typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }>
|
||||
>this.myModule.then : <TResult1 = typeof "tests/cases/conformance/dynamicImport/0", TResult2 = never>(onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => Promise<TResult1 | TResult2>
|
||||
>this.myModule : Promise<typeof "tests/cases/conformance/dynamicImport/0">
|
||||
>this : this
|
||||
>myModule : Promise<typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }>
|
||||
>then : <TResult1 = typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }, TResult2 = never>(onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => Promise<TResult1 | TResult2>
|
||||
>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<typeof "tests/cases/conformance/dynamicImport/0">
|
||||
>then : <TResult1 = typeof "tests/cases/conformance/dynamicImport/0", TResult2 = never>(onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => Promise<TResult1 | TResult2>
|
||||
>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<typeof "tests/cases/conformance/dynamicImport/1" & { default: typeof "tests/cases/conformance/dynamicImport/1"; }>
|
||||
>one : typeof "tests/cases/conformance/dynamicImport/1"
|
||||
>await import("./1") : typeof "tests/cases/conformance/dynamicImport/1"
|
||||
>import("./1") : Promise<typeof "tests/cases/conformance/dynamicImport/1">
|
||||
>"./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<typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }>
|
||||
>import("./0") : Promise<typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }>
|
||||
>myModule : Promise<typeof "tests/cases/conformance/dynamicImport/0">
|
||||
>import("./0") : Promise<typeof "tests/cases/conformance/dynamicImport/0">
|
||||
>"./0" : "./0"
|
||||
|
||||
method() {
|
||||
>method : () => void
|
||||
|
||||
const loadAsync = import("./0");
|
||||
>loadAsync : Promise<typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }>
|
||||
>import("./0") : Promise<typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }>
|
||||
>loadAsync : Promise<typeof "tests/cases/conformance/dynamicImport/0">
|
||||
>import("./0") : Promise<typeof "tests/cases/conformance/dynamicImport/0">
|
||||
>"./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<void>
|
||||
>this.myModule.then : <TResult1 = typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }, TResult2 = never>(onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => Promise<TResult1 | TResult2>
|
||||
>this.myModule : Promise<typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }>
|
||||
>this.myModule.then : <TResult1 = typeof "tests/cases/conformance/dynamicImport/0", TResult2 = never>(onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => Promise<TResult1 | TResult2>
|
||||
>this.myModule : Promise<typeof "tests/cases/conformance/dynamicImport/0">
|
||||
>this : this
|
||||
>myModule : Promise<typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }>
|
||||
>then : <TResult1 = typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }, TResult2 = never>(onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => Promise<TResult1 | TResult2>
|
||||
>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<typeof "tests/cases/conformance/dynamicImport/0">
|
||||
>then : <TResult1 = typeof "tests/cases/conformance/dynamicImport/0", TResult2 = never>(onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => Promise<TResult1 | TResult2>
|
||||
>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<typeof "tests/cases/conformance/dynamicImport/1" & { default: typeof "tests/cases/conformance/dynamicImport/1"; }>
|
||||
>one : typeof "tests/cases/conformance/dynamicImport/1"
|
||||
>await import("./1") : typeof "tests/cases/conformance/dynamicImport/1"
|
||||
>import("./1") : Promise<typeof "tests/cases/conformance/dynamicImport/1">
|
||||
>"./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
|
||||
|
||||
});
|
||||
|
||||
@ -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<string>
|
||||
>import("package").then : <TResult1 = ((x: number) => string) & { default: (x: number) => string; }, TResult2 = never>(onfulfilled?: (value: ((x: number) => string) & { default: (x: number) => string; }) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => Promise<TResult1 | TResult2>
|
||||
>import("package") : Promise<((x: number) => string) & { default: (x: number) => string; }>
|
||||
>import("package").then : <TResult1 = { default: (x: number) => string; }, TResult2 = never>(onfulfilled?: (value: { default: (x: number) => string; }) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => Promise<TResult1 | TResult2>
|
||||
>import("package") : Promise<{ default: (x: number) => string; }>
|
||||
>"package" : "package"
|
||||
>then : <TResult1 = ((x: number) => string) & { default: (x: number) => string; }, TResult2 = never>(onfulfilled?: (value: ((x: number) => string) & { default: (x: number) => string; }) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => Promise<TResult1 | TResult2>
|
||||
>({default: foo}) => foo(42) : ({ default: foo }: ((x: number) => string) & { default: (x: number) => string; }) => string
|
||||
>then : <TResult1 = { default: (x: number) => string; }, TResult2 = never>(onfulfilled?: (value: { default: (x: number) => string; }) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>) => Promise<TResult1 | TResult2>
|
||||
>({default: foo}) => foo(42) : ({ default: foo }: { default: (x: number) => string; }) => string
|
||||
>default : any
|
||||
>foo : (x: number) => string
|
||||
>foo(42) : string
|
||||
|
||||
@ -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 */
|
||||
|
||||
@ -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 */
|
||||
|
||||
@ -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 */
|
||||
|
||||
@ -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 */
|
||||
|
||||
@ -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 */
|
||||
|
||||
@ -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 */
|
||||
|
||||
@ -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 */
|
||||
|
||||
@ -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 */
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
17
tests/cases/compiler/esModuleInterop.ts
Normal file
17
tests/cases/compiler/esModuleInterop.ts
Normal file
@ -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;
|
||||
11
tests/cases/compiler/esModuleInteropImportCall.ts
Normal file
11
tests/cases/compiler/esModuleInteropImportCall.ts
Normal file
@ -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;
|
||||
});
|
||||
9
tests/cases/compiler/esModuleInteropImportNamespace.ts
Normal file
9
tests/cases/compiler/esModuleInteropImportNamespace.ts
Normal file
@ -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;
|
||||
18
tests/cases/fourslash/codeFixCalledES2015Import1.ts
Normal file
18
tests/cases/fourslash/codeFixCalledES2015Import1.ts
Normal file
@ -0,0 +1,18 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
// @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,
|
||||
});
|
||||
18
tests/cases/fourslash/codeFixCalledES2015Import10.ts
Normal file
18
tests/cases/fourslash/codeFixCalledES2015Import10.ts
Normal file
@ -0,0 +1,18 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
// @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,
|
||||
});
|
||||
18
tests/cases/fourslash/codeFixCalledES2015Import11.ts
Normal file
18
tests/cases/fourslash/codeFixCalledES2015Import11.ts
Normal file
@ -0,0 +1,18 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
// @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,
|
||||
});
|
||||
18
tests/cases/fourslash/codeFixCalledES2015Import12.ts
Normal file
18
tests/cases/fourslash/codeFixCalledES2015Import12.ts
Normal file
@ -0,0 +1,18 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
// @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,
|
||||
});
|
||||
18
tests/cases/fourslash/codeFixCalledES2015Import13.ts
Normal file
18
tests/cases/fourslash/codeFixCalledES2015Import13.ts
Normal file
@ -0,0 +1,18 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
// @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,
|
||||
});
|
||||
18
tests/cases/fourslash/codeFixCalledES2015Import2.ts
Normal file
18
tests/cases/fourslash/codeFixCalledES2015Import2.ts
Normal file
@ -0,0 +1,18 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
// @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,
|
||||
});
|
||||
19
tests/cases/fourslash/codeFixCalledES2015Import3.ts
Normal file
19
tests/cases/fourslash/codeFixCalledES2015Import3.ts
Normal file
@ -0,0 +1,19 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
// @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,
|
||||
});
|
||||
17
tests/cases/fourslash/codeFixCalledES2015Import4.ts
Normal file
17
tests/cases/fourslash/codeFixCalledES2015Import4.ts
Normal file
@ -0,0 +1,17 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
// @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,
|
||||
});
|
||||
17
tests/cases/fourslash/codeFixCalledES2015Import5.ts
Normal file
17
tests/cases/fourslash/codeFixCalledES2015Import5.ts
Normal file
@ -0,0 +1,17 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
// @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,
|
||||
});
|
||||
18
tests/cases/fourslash/codeFixCalledES2015Import6.ts
Normal file
18
tests/cases/fourslash/codeFixCalledES2015Import6.ts
Normal file
@ -0,0 +1,18 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
// @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,
|
||||
});
|
||||
17
tests/cases/fourslash/codeFixCalledES2015Import7.ts
Normal file
17
tests/cases/fourslash/codeFixCalledES2015Import7.ts
Normal file
@ -0,0 +1,17 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
// @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,
|
||||
});
|
||||
17
tests/cases/fourslash/codeFixCalledES2015Import8.ts
Normal file
17
tests/cases/fourslash/codeFixCalledES2015Import8.ts
Normal file
@ -0,0 +1,17 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
// @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,
|
||||
});
|
||||
18
tests/cases/fourslash/codeFixCalledES2015Import9.ts
Normal file
18
tests/cases/fourslash/codeFixCalledES2015Import9.ts
Normal file
@ -0,0 +1,18 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
// @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,
|
||||
});
|
||||
@ -1,5 +1,6 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
// @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;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user