This commit is contained in:
Andrew Branch 2024-06-13 16:40:23 -07:00 коммит произвёл GitHub
Родитель 4857546865
Коммит 56289733a4
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
90 изменённых файлов: 354 добавлений и 3083 удалений

Просмотреть файл

@ -54,7 +54,7 @@ export * from "../transformers/generators.js";
export * from "../transformers/module/module.js";
export * from "../transformers/module/system.js";
export * from "../transformers/module/esnextAnd2015.js";
export * from "../transformers/module/impliedNodeFormatDependent.js";
export * from "../transformers/module/node.js";
export * from "../transformers/declarations/diagnostics.js";
export * from "../transformers/declarations.js";
export * from "../transformer.js";

Просмотреть файл

@ -60,7 +60,6 @@ import {
canHaveJSDoc,
canHaveLocals,
canHaveModifiers,
canHaveModuleSpecifier,
canHaveSymbol,
canIncludeBindAndCheckDiagnostics,
canUsePropertyAccess,
@ -3655,36 +3654,27 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|| isNamespaceExport(node));
}
function getEmitSyntaxForModuleSpecifierExpression(usage: Expression) {
return isStringLiteralLike(usage) ? host.getEmitSyntaxForUsageLocation(getSourceFileOfNode(usage), usage) : undefined;
function getUsageModeForExpression(usage: Expression) {
return isStringLiteralLike(usage) ? host.getModeForUsageLocation(getSourceFileOfNode(usage), usage) : undefined;
}
function isESMFormatImportImportingCommonjsFormatFile(usageMode: ResolutionMode, targetMode: ResolutionMode) {
return usageMode === ModuleKind.ESNext && targetMode === ModuleKind.CommonJS;
}
function isOnlyImportableAsDefault(usage: Expression) {
// In Node.js, JSON modules don't get named exports
if (ModuleKind.Node16 <= moduleKind && moduleKind <= ModuleKind.NodeNext) {
const usageMode = getEmitSyntaxForModuleSpecifierExpression(usage);
return usageMode === ModuleKind.ESNext && endsWith((usage as StringLiteralLike).text, Extension.Json);
}
return false;
function isOnlyImportedAsDefault(usage: Expression) {
const usageMode = getUsageModeForExpression(usage);
return usageMode === ModuleKind.ESNext && endsWith((usage as StringLiteralLike).text, Extension.Json);
}
function canHaveSyntheticDefault(file: SourceFile | undefined, moduleSymbol: Symbol, dontResolveAlias: boolean, usage: Expression) {
const usageMode = file && getEmitSyntaxForModuleSpecifierExpression(usage);
if (file && usageMode !== undefined) {
const targetMode = host.getImpliedNodeFormatForEmit(file);
if (usageMode === ModuleKind.ESNext && targetMode === ModuleKind.CommonJS && ModuleKind.Node16 <= moduleKind && moduleKind <= ModuleKind.NodeNext) {
// In Node.js, CommonJS modules always have a synthetic default when imported into ESM
return true;
}
if (usageMode === ModuleKind.ESNext && targetMode === ModuleKind.ESNext) {
// No matter what the `module` setting is, if we're confident that both files
// are ESM, there cannot be a synthetic default.
return false;
const usageMode = file && getUsageModeForExpression(usage);
if (file && usageMode !== undefined && ModuleKind.Node16 <= moduleKind && moduleKind <= ModuleKind.NodeNext) {
const result = isESMFormatImportImportingCommonjsFormatFile(usageMode, file.impliedNodeFormat);
if (usageMode === ModuleKind.ESNext || result) {
return result;
}
// fallthrough on cjs usages so we imply defaults for interop'd imports, too
}
if (!allowSyntheticDefaultImports) {
return false;
@ -3737,7 +3727,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
if (!specifier) {
return exportDefaultSymbol;
}
const hasDefaultOnly = isOnlyImportableAsDefault(specifier);
const hasDefaultOnly = isOnlyImportedAsDefault(specifier);
const hasSyntheticDefault = canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, specifier);
if (!exportDefaultSymbol && !hasSyntheticDefault && !hasDefaultOnly) {
if (hasExportAssignmentSymbol(moduleSymbol) && !allowSyntheticDefaultImports) {
@ -3922,7 +3912,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
let symbolFromModule = getExportOfModule(targetSymbol, nameText, specifier, dontResolveAlias);
if (symbolFromModule === undefined && nameText === InternalSymbolName.Default) {
const file = moduleSymbol.declarations?.find(isSourceFile);
if (isOnlyImportableAsDefault(moduleSpecifier) || canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, moduleSpecifier)) {
if (isOnlyImportedAsDefault(moduleSpecifier) || canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, moduleSpecifier)) {
symbolFromModule = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias) || resolveSymbol(moduleSymbol, dontResolveAlias);
}
}
@ -4586,9 +4576,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
findAncestor(location, isImportDeclaration)?.moduleSpecifier ||
findAncestor(location, isExternalModuleImportEqualsDeclaration)?.moduleReference.expression ||
findAncestor(location, isExportDeclaration)?.moduleSpecifier;
const mode = contextSpecifier && isStringLiteralLike(contextSpecifier)
? host.getModeForUsageLocation(currentSourceFile, contextSpecifier)
: host.getDefaultResolutionModeForFile(currentSourceFile);
const mode = contextSpecifier && isStringLiteralLike(contextSpecifier) ? host.getModeForUsageLocation(currentSourceFile, contextSpecifier) : currentSourceFile.impliedNodeFormat;
const moduleResolutionKind = getEmitModuleResolutionKind(compilerOptions);
const resolvedModule = host.getResolvedModule(currentSourceFile, moduleReference, mode)?.resolvedModule;
const resolutionDiagnostic = resolvedModule && getResolutionDiagnostic(compilerOptions, resolvedModule, currentSourceFile);
@ -4875,7 +4863,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}
const targetFile = moduleSymbol?.declarations?.find(isSourceFile);
const isEsmCjsRef = targetFile && isESMFormatImportImportingCommonjsFormatFile(getEmitSyntaxForModuleSpecifierExpression(reference), host.getImpliedNodeFormatForEmit(targetFile));
const isEsmCjsRef = targetFile && isESMFormatImportImportingCommonjsFormatFile(getUsageModeForExpression(reference), targetFile.impliedNodeFormat);
if (getESModuleInterop(compilerOptions) || isEsmCjsRef) {
let sigs = getSignaturesOfStructuredType(type, SignatureKind.Call);
if (!sigs || !sigs.length) {
@ -7809,12 +7797,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}
return getSourceFileOfNode(getNonAugmentationDeclaration(symbol)!).fileName; // A resolver may not be provided for baselines and errors - in those cases we use the fileName in full
}
const enclosingDeclaration = getOriginalNode(context.enclosingDeclaration);
const originalModuleSpecifier = canHaveModuleSpecifier(enclosingDeclaration) ? tryGetModuleSpecifierFromDeclaration(enclosingDeclaration) : undefined;
const contextFile = context.enclosingFile;
const resolutionMode = overrideImportMode
|| originalModuleSpecifier && host.getModeForUsageLocation(contextFile, originalModuleSpecifier)
|| contextFile && host.getDefaultResolutionModeForFile(contextFile);
const resolutionMode = overrideImportMode || contextFile?.impliedNodeFormat;
const cacheKey = createModeAwareCacheKey(contextFile.path, resolutionMode);
const links = getSymbolLinks(symbol);
let specifier = links.specifierCache && links.specifierCache.get(cacheKey);
@ -36940,7 +36924,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}
function getTypeWithSyntheticDefaultOnly(type: Type, symbol: Symbol, originalSymbol: Symbol, moduleSpecifier: Expression) {
const hasDefaultOnly = isOnlyImportableAsDefault(moduleSpecifier);
const hasDefaultOnly = isOnlyImportedAsDefault(moduleSpecifier);
if (hasDefaultOnly && type && !isErrorType(type)) {
const synthType = type as SyntheticDefaultModuleType;
if (!synthType.defaultOnlyType) {
@ -43486,7 +43470,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
function checkCollisionWithRequireExportsInGeneratedCode(node: Node, name: Identifier | undefined) {
// No need to check for require or exports for ES6 modules and later
if (host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) >= ModuleKind.ES2015) {
if (moduleKind >= ModuleKind.ES2015 && !(moduleKind >= ModuleKind.Node16 && getSourceFileOfNode(node).impliedNodeFormat === ModuleKind.CommonJS)) {
return;
}
@ -45375,7 +45359,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
function checkClassNameCollisionWithObject(name: Identifier): void {
if (
languageVersion >= ScriptTarget.ES5 && name.escapedText === "Object"
&& host.getEmitModuleFormatOfFile(getSourceFileOfNode(name)) < ModuleKind.ES2015
&& (moduleKind < ModuleKind.ES2015 || getSourceFileOfNode(name).impliedNodeFormat === ModuleKind.CommonJS)
) {
error(name, Diagnostics.Class_name_cannot_be_Object_when_targeting_ES5_with_module_0, ModuleKind[moduleKind]); // https://github.com/Microsoft/TypeScript/issues/17494
}
@ -46714,7 +46698,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
if (
compilerOptions.verbatimModuleSyntax &&
node.parent.kind === SyntaxKind.SourceFile &&
host.getEmitModuleFormatOfFile(node.parent) === ModuleKind.CommonJS
(moduleKind === ModuleKind.CommonJS || node.parent.impliedNodeFormat === ModuleKind.CommonJS)
) {
const exportModifier = node.modifiers?.find(m => m.kind === SyntaxKind.ExportKeyword);
if (exportModifier) {
@ -47006,22 +46990,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
compilerOptions.verbatimModuleSyntax &&
node.kind !== SyntaxKind.ImportEqualsDeclaration &&
!isInJSFile(node) &&
host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) === ModuleKind.CommonJS
(moduleKind === ModuleKind.CommonJS || getSourceFileOfNode(node).impliedNodeFormat === ModuleKind.CommonJS)
) {
error(node, Diagnostics.ESM_syntax_is_not_allowed_in_a_CommonJS_module_when_verbatimModuleSyntax_is_enabled);
}
else if (
moduleKind === ModuleKind.Preserve &&
node.kind !== SyntaxKind.ImportEqualsDeclaration &&
node.kind !== SyntaxKind.VariableDeclaration &&
host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) === ModuleKind.CommonJS
) {
// In `--module preserve`, ESM input syntax emits ESM output syntax, but there will be times
// when we look at the `impliedNodeFormat` of this file and decide it's CommonJS. To avoid
// that inconsistency, we disallow ESM syntax in files that are unambiguously CommonJS in
// this mode.
error(node, Diagnostics.ESM_syntax_is_not_allowed_in_a_CommonJS_module_when_module_is_set_to_preserve);
}
}
if (isImportSpecifier(node)) {
@ -47071,7 +47043,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
if (
moduleExportNameIsDefault(node.propertyName || node.name) &&
getESModuleInterop(compilerOptions) &&
host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) < ModuleKind.System
moduleKind !== ModuleKind.System && (moduleKind < ModuleKind.ES2015 || getSourceFileOfNode(node).impliedNodeFormat === ModuleKind.CommonJS)
) {
checkExternalEmitHelpers(node, ExternalEmitHelpers.ImportDefault);
}
@ -47093,7 +47065,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
return; // Other grammar checks do not apply to type-only imports with resolution mode assertions
}
const mode = (moduleKind === ModuleKind.NodeNext) && declaration.moduleSpecifier && getEmitSyntaxForModuleSpecifierExpression(declaration.moduleSpecifier);
const mode = (moduleKind === ModuleKind.NodeNext) && declaration.moduleSpecifier && getUsageModeForExpression(declaration.moduleSpecifier);
if (mode !== ModuleKind.ESNext && moduleKind !== ModuleKind.ESNext && moduleKind !== ModuleKind.Preserve) {
const message = isImportAttributes
? moduleKind === ModuleKind.NodeNext
@ -47137,7 +47109,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
if (importClause.namedBindings) {
if (importClause.namedBindings.kind === SyntaxKind.NamespaceImport) {
checkImportBinding(importClause.namedBindings);
if (host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) < ModuleKind.System && getESModuleInterop(compilerOptions)) {
if (moduleKind !== ModuleKind.System && (moduleKind < ModuleKind.ES2015 || getSourceFileOfNode(node).impliedNodeFormat === ModuleKind.CommonJS) && getESModuleInterop(compilerOptions)) {
// import * as ns from "foo";
checkExternalEmitHelpers(node, ExternalEmitHelpers.ImportStar);
}
@ -47184,8 +47156,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}
}
else {
if (ModuleKind.ES2015 <= moduleKind && moduleKind <= ModuleKind.ESNext && !node.isTypeOnly && !(node.flags & NodeFlags.Ambient)) {
// Import equals declaration cannot be emitted as ESM
if (moduleKind >= ModuleKind.ES2015 && moduleKind !== ModuleKind.Preserve && getSourceFileOfNode(node).impliedNodeFormat === undefined && !node.isTypeOnly && !(node.flags & NodeFlags.Ambient)) {
// Import equals declaration is deprecated in es6 or above
grammarErrorOnNode(node, Diagnostics.Import_assignment_cannot_be_used_when_targeting_ECMAScript_modules_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_import_d_from_mod_or_another_module_format_instead);
}
}
@ -47226,7 +47198,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
checkAliasSymbol(node.exportClause);
checkModuleExportName(node.exportClause.name);
}
if (host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) < ModuleKind.System) {
if (moduleKind !== ModuleKind.System && (moduleKind < ModuleKind.ES2015 || getSourceFileOfNode(node).impliedNodeFormat === ModuleKind.CommonJS)) {
if (node.exportClause) {
// export * as ns from "foo";
// For ES2015 modules, we emit it as a pair of `import * as a_1 ...; export { a_1 as ns }` and don't need the helper.
@ -47285,7 +47257,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
else {
if (
getESModuleInterop(compilerOptions) &&
host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) < ModuleKind.System &&
moduleKind !== ModuleKind.System &&
(moduleKind < ModuleKind.ES2015 || getSourceFileOfNode(node).impliedNodeFormat === ModuleKind.CommonJS) &&
moduleExportNameIsDefault(node.propertyName || node.name)
) {
checkExternalEmitHelpers(node, ExternalEmitHelpers.ImportDefault);
@ -47326,7 +47299,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
const isIllegalExportDefaultInCJS = !node.isExportEquals &&
!(node.flags & NodeFlags.Ambient) &&
compilerOptions.verbatimModuleSyntax &&
host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) === ModuleKind.CommonJS;
(moduleKind === ModuleKind.CommonJS || getSourceFileOfNode(node).impliedNodeFormat === ModuleKind.CommonJS);
if (node.expression.kind === SyntaxKind.Identifier) {
const id = node.expression as Identifier;
@ -47424,8 +47397,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
if (
moduleKind >= ModuleKind.ES2015 &&
moduleKind !== ModuleKind.Preserve &&
((node.flags & NodeFlags.Ambient && host.getImpliedNodeFormatForEmit(getSourceFileOfNode(node)) === ModuleKind.ESNext) ||
(!(node.flags & NodeFlags.Ambient) && host.getImpliedNodeFormatForEmit(getSourceFileOfNode(node)) !== ModuleKind.CommonJS))
((node.flags & NodeFlags.Ambient && getSourceFileOfNode(node).impliedNodeFormat === ModuleKind.ESNext) ||
(!(node.flags & NodeFlags.Ambient) && getSourceFileOfNode(node).impliedNodeFormat !== ModuleKind.CommonJS))
) {
// export assignment is not supported in es6 modules
grammarErrorOnNode(node, Diagnostics.Export_assignment_cannot_be_used_when_targeting_ECMAScript_modules_Consider_using_export_default_or_another_module_format_instead);
@ -50362,7 +50335,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
// ModuleDeclaration needs to be checked that it is uninstantiated later
node.kind !== SyntaxKind.ModuleDeclaration &&
node.parent.kind === SyntaxKind.SourceFile &&
host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) === ModuleKind.CommonJS
(moduleKind === ModuleKind.CommonJS || getSourceFileOfNode(node).impliedNodeFormat === ModuleKind.CommonJS)
) {
return grammarErrorOnNode(modifier, Diagnostics.A_top_level_export_modifier_cannot_be_used_on_value_declarations_in_a_CommonJS_module_when_verbatimModuleSyntax_is_enabled);
}
@ -51520,7 +51493,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}
if (
host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) < ModuleKind.System &&
(moduleKind < ModuleKind.ES2015 || getSourceFileOfNode(node).impliedNodeFormat === ModuleKind.CommonJS) && moduleKind !== ModuleKind.System &&
!(node.parent.parent.flags & NodeFlags.Ambient) && hasSyntacticModifier(node.parent.parent, ModifierFlags.Export)
) {
checkESModuleMarker(node.name);
@ -52167,8 +52140,6 @@ function createBasicNodeBuilderModuleSpecifierResolutionHost(host: TypeCheckerHo
fileExists: fileName => host.fileExists(fileName),
getFileIncludeReasons: () => host.getFileIncludeReasons(),
readFile: host.readFile ? (fileName => host.readFile!(fileName)) : undefined,
getDefaultResolutionModeForFile: file => host.getDefaultResolutionModeForFile(file),
getModeForResolutionAtIndex: (file, index) => host.getModeForResolutionAtIndex(file, index),
};
}

Просмотреть файл

@ -967,10 +967,6 @@
"category": "Error",
"code": 1292
},
"ESM syntax is not allowed in a CommonJS module when 'module' is set to 'preserve'.": {
"category": "Error",
"code": 1293
},
"'with' statements are not allowed in an async function block.": {
"category": "Error",

Просмотреть файл

@ -131,7 +131,6 @@ import {
getEmitFlags,
getEmitHelpers,
getEmitModuleKind,
getEmitModuleResolutionKind,
getEmitScriptTarget,
getExternalModuleName,
getIdentifierTypeArguments,
@ -830,7 +829,6 @@ export function emitFiles(
newLine: compilerOptions.newLine,
noEmitHelpers: compilerOptions.noEmitHelpers,
module: getEmitModuleKind(compilerOptions),
moduleResolution: getEmitModuleResolutionKind(compilerOptions),
target: getEmitScriptTarget(compilerOptions),
sourceMap: compilerOptions.sourceMap,
inlineSourceMap: compilerOptions.inlineSourceMap,
@ -906,7 +904,6 @@ export function emitFiles(
newLine: compilerOptions.newLine,
noEmitHelpers: true,
module: compilerOptions.module,
moduleResolution: compilerOptions.moduleResolution,
target: compilerOptions.target,
sourceMap: !forceDtsEmit && compilerOptions.declarationMap,
inlineSourceMap: compilerOptions.inlineSourceMap,

Просмотреть файл

@ -53,12 +53,10 @@ import {
getAllAccessorDeclarations,
getEmitFlags,
getEmitHelpers,
getEmitModuleFormatOfFileWorker,
getEmitModuleKind,
getESModuleInterop,
getExternalModuleName,
getExternalModuleNameFromPath,
getImpliedNodeFormatForEmitWorker,
getJSDocType,
getJSDocTypeTag,
getModifiers,
@ -714,7 +712,7 @@ export function createExternalHelpersImportDeclarationIfNeeded(nodeFactory: Node
if (compilerOptions.importHelpers && isEffectiveExternalModule(sourceFile, compilerOptions)) {
let namedBindings: NamedImportBindings | undefined;
const moduleKind = getEmitModuleKind(compilerOptions);
if ((moduleKind >= ModuleKind.ES2015 && moduleKind <= ModuleKind.ESNext) || getImpliedNodeFormatForEmitWorker(sourceFile, compilerOptions) === ModuleKind.ESNext) {
if ((moduleKind >= ModuleKind.ES2015 && moduleKind <= ModuleKind.ESNext) || sourceFile.impliedNodeFormat === ModuleKind.ESNext) {
// use named imports
const helpers = getEmitHelpers(sourceFile);
if (helpers) {
@ -771,8 +769,10 @@ export function getOrCreateExternalHelpersModuleNameIfNeeded(factory: NodeFactor
return externalHelpersModuleName;
}
const moduleKind = getEmitModuleKind(compilerOptions);
let create = (hasExportStarsToExportValues || (getESModuleInterop(compilerOptions) && hasImportStarOrImportDefault))
&& getEmitModuleFormatOfFileWorker(node, compilerOptions) < ModuleKind.System;
&& moduleKind !== ModuleKind.System
&& (moduleKind < ModuleKind.ES2015 || node.impliedNodeFormat === ModuleKind.CommonJS);
if (!create) {
const helpers = getEmitHelpers(node);
if (helpers) {

Просмотреть файл

@ -37,9 +37,9 @@ import {
getBaseFileName,
GetCanonicalFileName,
getConditions,
getDefaultResolutionModeForFileWorker,
getDirectoryPath,
getEmitModuleResolutionKind,
getModeForResolutionAtIndex,
getModuleNameStringLiteralAt,
getModuleSpecifierEndingPreference,
getNodeModulePathParts,
@ -143,13 +143,12 @@ export interface ModuleSpecifierPreferences {
/**
* @param syntaxImpliedNodeFormat Used when the import syntax implies ESM or CJS irrespective of the mode of the file.
*/
getAllowedEndingsInPreferredOrder(syntaxImpliedNodeFormat?: ResolutionMode): ModuleSpecifierEnding[];
getAllowedEndingsInPreferredOrder(syntaxImpliedNodeFormat?: SourceFile["impliedNodeFormat"]): ModuleSpecifierEnding[];
}
/** @internal */
export function getModuleSpecifierPreferences(
{ importModuleSpecifierPreference, importModuleSpecifierEnding }: UserPreferences,
host: Pick<ModuleSpecifierResolutionHost, "getDefaultResolutionModeForFile">,
compilerOptions: CompilerOptions,
importingSourceFile: Pick<SourceFile, "fileName" | "impliedNodeFormat">,
oldImportSpecifier?: string,
@ -164,10 +163,8 @@ export function getModuleSpecifierPreferences(
importModuleSpecifierPreference === "project-relative" ? RelativePreference.ExternalNonRelative :
RelativePreference.Shortest,
getAllowedEndingsInPreferredOrder: syntaxImpliedNodeFormat => {
const impliedNodeFormat = getDefaultResolutionModeForFile(importingSourceFile, host, compilerOptions);
const preferredEnding = syntaxImpliedNodeFormat !== impliedNodeFormat ? getPreferredEnding(syntaxImpliedNodeFormat) : filePreferredEnding;
const moduleResolution = getEmitModuleResolutionKind(compilerOptions);
if ((syntaxImpliedNodeFormat ?? impliedNodeFormat) === ModuleKind.ESNext && ModuleResolutionKind.Node16 <= moduleResolution && moduleResolution <= ModuleResolutionKind.NodeNext) {
const preferredEnding = syntaxImpliedNodeFormat !== importingSourceFile.impliedNodeFormat ? getPreferredEnding(syntaxImpliedNodeFormat) : filePreferredEnding;
if ((syntaxImpliedNodeFormat ?? importingSourceFile.impliedNodeFormat) === ModuleKind.ESNext) {
if (shouldAllowImportingTsExtension(compilerOptions, importingSourceFile.fileName)) {
return [ModuleSpecifierEnding.TsExtension, ModuleSpecifierEnding.JsExtension];
}
@ -207,7 +204,7 @@ export function getModuleSpecifierPreferences(
}
return getModuleSpecifierEndingPreference(
importModuleSpecifierEnding,
resolutionMode ?? getDefaultResolutionModeForFile(importingSourceFile, host, compilerOptions),
resolutionMode ?? importingSourceFile.impliedNodeFormat,
compilerOptions,
isFullSourceFile(importingSourceFile) ? importingSourceFile : undefined,
);
@ -228,7 +225,7 @@ export function updateModuleSpecifier(
oldImportSpecifier: string,
options: ModuleSpecifierOptions = {},
): string | undefined {
const res = getModuleSpecifierWorker(compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host, getModuleSpecifierPreferences({}, host, compilerOptions, importingSourceFile, oldImportSpecifier), {}, options);
const res = getModuleSpecifierWorker(compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host, getModuleSpecifierPreferences({}, compilerOptions, importingSourceFile, oldImportSpecifier), {}, options);
if (res === oldImportSpecifier) return undefined;
return res;
}
@ -248,7 +245,7 @@ export function getModuleSpecifier(
host: ModuleSpecifierResolutionHost,
options: ModuleSpecifierOptions = {},
): string {
return getModuleSpecifierWorker(compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host, getModuleSpecifierPreferences({}, host, compilerOptions, importingSourceFile), {}, options);
return getModuleSpecifierWorker(compilerOptions, importingSourceFile, importingSourceFileName, toFileName, host, getModuleSpecifierPreferences({}, compilerOptions, importingSourceFile), {}, options);
}
/** @internal */
@ -278,7 +275,7 @@ function getModuleSpecifierWorker(
const info = getInfo(importingSourceFileName, host);
const modulePaths = getAllModulePaths(info, toFileName, host, userPreferences, compilerOptions, options);
return firstDefined(modulePaths, modulePath => tryGetModuleNameAsNodeModule(modulePath, info, importingSourceFile, host, compilerOptions, userPreferences, /*packageNameOnly*/ undefined, options.overrideImportMode)) ||
getLocalModuleSpecifier(toFileName, info, compilerOptions, host, options.overrideImportMode || getDefaultResolutionModeForFile(importingSourceFile, host, compilerOptions), preferences);
getLocalModuleSpecifier(toFileName, info, compilerOptions, host, options.overrideImportMode || importingSourceFile.impliedNodeFormat, preferences);
}
/** @internal */
@ -406,7 +403,7 @@ export function getLocalModuleSpecifierBetweenFileNames(
compilerOptions,
host,
importMode,
getModuleSpecifierPreferences({}, host, compilerOptions, importingFile),
getModuleSpecifierPreferences({}, compilerOptions, importingFile),
);
}
@ -420,7 +417,7 @@ function computeModuleSpecifiers(
forAutoImport: boolean,
): ModuleSpecifierResult {
const info = getInfo(importingSourceFile.fileName, host);
const preferences = getModuleSpecifierPreferences(userPreferences, host, compilerOptions, importingSourceFile);
const preferences = getModuleSpecifierPreferences(userPreferences, compilerOptions, importingSourceFile);
const existingSpecifier = isFullSourceFile(importingSourceFile) && forEach(modulePaths, modulePath =>
forEach(
host.getFileIncludeReasons().get(toPath(modulePath.path, host.getCurrentDirectory(), info.getCanonicalFileName)),
@ -428,11 +425,7 @@ function computeModuleSpecifiers(
if (reason.kind !== FileIncludeKind.Import || reason.file !== importingSourceFile.path) return undefined;
// If the candidate import mode doesn't match the mode we're generating for, don't consider it
// TODO: maybe useful to keep around as an alternative option for certain contexts where the mode is overridable
const existingMode = host.getModeForResolutionAtIndex(importingSourceFile, reason.index);
const targetMode = options.overrideImportMode ?? host.getDefaultResolutionModeForFile(importingSourceFile);
if (existingMode !== targetMode && existingMode !== undefined && targetMode !== undefined) {
return undefined;
}
if (importingSourceFile.impliedNodeFormat && importingSourceFile.impliedNodeFormat !== getModeForResolutionAtIndex(importingSourceFile, reason.index, compilerOptions)) return undefined;
const specifier = getModuleNameStringLiteralAt(importingSourceFile, reason.index).text;
// If the preference is for non relative and the module specifier is relative, ignore it
return preferences.relativePreference !== RelativePreference.NonRelative || !pathIsRelative(specifier) ?
@ -1100,7 +1093,7 @@ function tryGetModuleNameAsNodeModule({ path, isRedirect }: ModulePath, { getCan
// Simplify the full file path to something that can be resolved by Node.
const preferences = getModuleSpecifierPreferences(userPreferences, host, options, importingSourceFile);
const preferences = getModuleSpecifierPreferences(userPreferences, options, importingSourceFile);
const allowedEndings = preferences.getAllowedEndingsInPreferredOrder();
let moduleSpecifier = path;
let isPackageRootPath = false;
@ -1160,7 +1153,7 @@ function tryGetModuleNameAsNodeModule({ path, isRedirect }: ModulePath, { getCan
const cachedPackageJson = host.getPackageJsonInfoCache?.()?.getPackageJsonInfo(packageJsonPath);
if (isPackageJsonInfo(cachedPackageJson) || cachedPackageJson === undefined && host.fileExists(packageJsonPath)) {
const packageJsonContent: Record<string, any> | undefined = cachedPackageJson?.contents.packageJsonContent || tryParseJson(host.readFile!(packageJsonPath)!);
const importMode = overrideMode || getDefaultResolutionModeForFile(importingSourceFile, host, options);
const importMode = overrideMode || importingSourceFile.impliedNodeFormat;
if (getResolvePackageJsonExports(options)) {
// The package name that we found in node_modules could be different from the package
// name in the package.json content via url/filepath dependency specifiers. We need to
@ -1355,7 +1348,3 @@ function getRelativePathIfInSameVolume(path: string, directoryPath: string, getC
function isPathRelativeToParent(path: string): boolean {
return startsWith(path, "..");
}
function getDefaultResolutionModeForFile(file: Pick<SourceFile, "fileName" | "impliedNodeFormat" | "packageJsonScope">, host: Pick<ModuleSpecifierResolutionHost, "getDefaultResolutionModeForFile">, compilerOptions: CompilerOptions) {
return isFullSourceFile(file) ? host.getDefaultResolutionModeForFile(file) : getDefaultResolutionModeForFileWorker(file, compilerOptions);
}

Просмотреть файл

@ -173,7 +173,6 @@ import {
ImportClause,
ImportDeclaration,
ImportOrExportSpecifier,
importSyntaxAffectsModuleResolution,
InternalEmitFlags,
inverseJsxOptionMap,
isAmbientModule,
@ -839,11 +838,9 @@ export function flattenDiagnosticMessageText(diag: string | DiagnosticMessageCha
* @internal
*/
export interface SourceFileImportsList {
imports: SourceFile["imports"];
moduleAugmentations: SourceFile["moduleAugmentations"];
/** @internal */ imports: SourceFile["imports"];
/** @internal */ moduleAugmentations: SourceFile["moduleAugmentations"];
impliedNodeFormat?: ResolutionMode;
fileName: string;
packageJsonScope?: SourceFile["packageJsonScope"];
}
/**
@ -889,47 +886,22 @@ export function isExclusivelyTypeOnlyImportOrExport(decl: ImportDeclaration | Ex
/**
* Use `program.getModeForUsageLocation`, which retrieves the correct `compilerOptions`, instead of this function whenever possible.
* Calculates the final resolution mode for a given module reference node. This function only returns a result when module resolution
* settings allow differing resolution between ESM imports and CJS requires, or when a mode is explicitly provided via import attributes,
* which cause an `import` or `require` condition to be used during resolution regardless of module resolution settings. In absence of
* overriding attributes, and in modes that support differing resolution, the result indicates the syntax the usage would emit to JavaScript.
* Some examples:
*
* ```ts
* // tsc foo.mts --module nodenext
* import {} from "mod";
* // Result: ESNext - the import emits as ESM due to `impliedNodeFormat` set by .mts file extension
*
* // tsc foo.cts --module nodenext
* import {} from "mod";
* // Result: CommonJS - the import emits as CJS due to `impliedNodeFormat` set by .cts file extension
*
* // tsc foo.ts --module preserve --moduleResolution bundler
* import {} from "mod";
* // Result: ESNext - the import emits as ESM due to `--module preserve` and `--moduleResolution bundler`
* // supports conditional imports/exports
*
* // tsc foo.ts --module preserve --moduleResolution node10
* import {} from "mod";
* // Result: undefined - the import emits as ESM due to `--module preserve`, but `--moduleResolution node10`
* // does not support conditional imports/exports
*
* // tsc foo.ts --module commonjs --moduleResolution node10
* import type {} from "mod" with { "resolution-mode": "import" };
* // Result: ESNext - conditional imports/exports always supported with "resolution-mode" attribute
* ```
*
* Calculates the final resolution mode for a given module reference node. This is the resolution mode explicitly provided via import
* attributes, if present, or the syntax the usage would have if emitted to JavaScript. In `--module node16` or `nodenext`, this may
* depend on the file's `impliedNodeFormat`. In `--module preserve`, it depends only on the input syntax of the reference. In other
* `module` modes, when overriding import attributes are not provided, this function returns `undefined`, as the result would have no
* impact on module resolution, emit, or type checking.
* @param file The file the import or import-like reference is contained within
* @param usage The module reference string
* @param compilerOptions The compiler options for the program that owns the file. If the file belongs to a referenced project, the compiler options
* should be the options of the referenced project, not the referencing project.
* @returns The final resolution mode of the import
*/
export function getModeForUsageLocation(file: SourceFile, usage: StringLiteralLike, compilerOptions: CompilerOptions) {
export function getModeForUsageLocation(file: { impliedNodeFormat?: ResolutionMode; }, usage: StringLiteralLike, compilerOptions: CompilerOptions) {
return getModeForUsageLocationWorker(file, usage, compilerOptions);
}
function getModeForUsageLocationWorker(file: Pick<SourceFile, "fileName" | "impliedNodeFormat" | "packageJsonScope">, usage: StringLiteralLike, compilerOptions?: CompilerOptions) {
function getModeForUsageLocationWorker(file: { impliedNodeFormat?: ResolutionMode; }, usage: StringLiteralLike, compilerOptions?: CompilerOptions) {
if ((isImportDeclaration(usage.parent) || isExportDeclaration(usage.parent))) {
const isTypeOnly = isExclusivelyTypeOnlyImportOrExport(usage.parent);
if (isTypeOnly) {
@ -945,36 +917,20 @@ function getModeForUsageLocationWorker(file: Pick<SourceFile, "fileName" | "impl
return override;
}
}
if (compilerOptions && importSyntaxAffectsModuleResolution(compilerOptions)) {
return getEmitSyntaxForUsageLocationWorker(file, usage, compilerOptions);
if (compilerOptions && getEmitModuleKind(compilerOptions) === ModuleKind.Preserve) {
return (usage.parent.parent && isImportEqualsDeclaration(usage.parent.parent) || isRequireCall(usage.parent, /*requireStringLiteralLikeArgument*/ false))
? ModuleKind.CommonJS
: ModuleKind.ESNext;
}
}
function getEmitSyntaxForUsageLocationWorker(file: Pick<SourceFile, "fileName" | "impliedNodeFormat" | "packageJsonScope">, usage: StringLiteralLike, compilerOptions?: CompilerOptions): ResolutionMode {
if (!compilerOptions) {
// This should always be provided, but we try to fail somewhat
// gracefully to allow projects like ts-node time to update.
return undefined;
if (file.impliedNodeFormat === undefined) return undefined;
if (file.impliedNodeFormat !== ModuleKind.ESNext) {
// in cjs files, import call expressions are esm format, otherwise everything is cjs
return isImportCall(walkUpParenthesizedExpressions(usage.parent)) ? ModuleKind.ESNext : ModuleKind.CommonJS;
}
// in esm files, import=require statements are cjs format, otherwise everything is esm
// imports are only parent'd up to their containing declaration/expression, so access farther parents with care
const exprParentParent = walkUpParenthesizedExpressions(usage.parent)?.parent;
if (exprParentParent && isImportEqualsDeclaration(exprParentParent) || isRequireCall(usage.parent, /*requireStringLiteralLikeArgument*/ false)) {
return ModuleKind.CommonJS;
}
if (isImportCall(walkUpParenthesizedExpressions(usage.parent))) {
return shouldTransformImportCallWorker(file, compilerOptions) ? ModuleKind.CommonJS : ModuleKind.ESNext;
}
// If we're in --module preserve on an input file, we know that an import
// is an import. But if this is a declaration file, we'd prefer to use the
// impliedNodeFormat. Since we want things to be consistent between the two,
// we need to issue errors when the user writes ESM syntax in a definitely-CJS
// file, until/unless declaration emit can indicate a true ESM import. On the
// other hand, writing CJS syntax in a definitely-ESM file is fine, since declaration
// emit preserves the CJS syntax.
const fileEmitMode = getEmitModuleFormatOfFileWorker(file, compilerOptions);
return fileEmitMode === ModuleKind.CommonJS ? ModuleKind.CommonJS :
emitModuleKindIsNonNodeESM(fileEmitMode) || fileEmitMode === ModuleKind.Preserve ? ModuleKind.ESNext :
undefined;
return exprParentParent && isImportEqualsDeclaration(exprParentParent) ? ModuleKind.CommonJS : ModuleKind.ESNext;
}
/** @internal */
@ -1064,7 +1020,7 @@ function getTypeReferenceResolutionName<T extends FileReference | string>(entry:
const typeReferenceResolutionNameAndModeGetter: ResolutionNameAndModeGetter<FileReference | string, SourceFile | undefined> = {
getName: getTypeReferenceResolutionName,
getMode: (entry, file, compilerOptions) => getModeForFileReference(entry, file && getDefaultResolutionModeForFileWorker(file, compilerOptions)),
getMode: (entry, file) => getModeForFileReference(entry, file?.impliedNodeFormat),
};
/** @internal */
@ -1399,7 +1355,6 @@ export function getImpliedNodeFormatForFileWorker(
default:
return undefined;
}
function lookupFromPackageJson(): Partial<CreateSourceFileOptions> {
const state = getTemporaryModuleResolutionState(packageJsonInfoCache, host, options);
const packageJsonLocations: string[] = [];
@ -1971,7 +1926,6 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
isSourceFileFromExternalLibrary,
isSourceFileDefaultLibrary,
getModeForUsageLocation,
getEmitSyntaxForUsageLocation,
getModeForResolutionAtIndex,
getSourceFileFromReference,
getLibFileFromReference,
@ -2000,11 +1954,6 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
forEachResolvedProjectReference,
isSourceOfProjectReferenceRedirect,
getRedirectReferenceForResolutionFromSourceOfProject,
getCompilerOptionsForFile,
getDefaultResolutionModeForFile,
getEmitModuleFormatOfFile,
getImpliedNodeFormatForEmit,
shouldTransformImportCall,
emitBuildInfo,
fileExists,
readFile,
@ -2757,10 +2706,6 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
getSymlinkCache,
writeFile: writeFileCallback || writeFile,
isEmitBlocked,
shouldTransformImportCall,
getEmitModuleFormatOfFile,
getDefaultResolutionModeForFile,
getModeForResolutionAtIndex,
readFile: f => host.readFile(f),
fileExists: f => {
// Use local caches
@ -4061,15 +4006,11 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
// store resolved type directive on the file
const fileName = ref.fileName;
resolutionsInFile.set(fileName, getModeForFileReference(ref, file.impliedNodeFormat), resolvedTypeReferenceDirective);
const mode = ref.resolutionMode || getDefaultResolutionModeForFile(file);
const mode = ref.resolutionMode || file.impliedNodeFormat;
processTypeReferenceDirective(fileName, mode, resolvedTypeReferenceDirective, { kind: FileIncludeKind.TypeReferenceDirective, file: file.path, index });
}
}
function getCompilerOptionsForFile(file: SourceFile): CompilerOptions {
return getRedirectReferenceForResolution(file)?.commandLine.options || options;
}
function processTypeReferenceDirective(
typeReferenceDirective: string,
mode: ResolutionMode,
@ -4184,7 +4125,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
const resolutions = resolvedModulesProcessing?.get(file.path) ||
resolveModuleNamesReusingOldState(moduleNames, file);
Debug.assert(resolutions.length === moduleNames.length);
const optionsForFile = getCompilerOptionsForFile(file);
const optionsForFile = getRedirectReferenceForResolution(file)?.commandLine.options || options;
const resolutionsInFile = createModeAwareCache<ResolutionWithFailedLookupLocations>();
(resolvedModules ??= new Map()).set(file.path, resolutionsInFile);
for (let index = 0; index < moduleNames.length; index++) {
@ -4783,7 +4724,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
}
else {
reasons?.forEach(processReason);
redirectInfo = file && explainIfFileIsRedirectAndImpliedFormat(file, getCompilerOptionsForFile(file));
redirectInfo = file && explainIfFileIsRedirectAndImpliedFormat(file);
}
if (fileProcessingReason) processReason(fileProcessingReason);
@ -5217,70 +5158,13 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
}
function getModeForUsageLocation(file: SourceFile, usage: StringLiteralLike): ResolutionMode {
return getModeForUsageLocationWorker(file, usage, getCompilerOptionsForFile(file));
}
function getEmitSyntaxForUsageLocation(file: SourceFile, usage: StringLiteralLike): ResolutionMode {
return getEmitSyntaxForUsageLocationWorker(file, usage, getCompilerOptionsForFile(file));
const optionsForFile = getRedirectReferenceForResolution(file)?.commandLine.options || options;
return getModeForUsageLocationWorker(file, usage, optionsForFile);
}
function getModeForResolutionAtIndex(file: SourceFile, index: number): ResolutionMode {
return getModeForUsageLocation(file, getModuleNameStringLiteralAt(file, index));
}
function getDefaultResolutionModeForFile(sourceFile: SourceFile): ResolutionMode {
return getDefaultResolutionModeForFileWorker(sourceFile, getCompilerOptionsForFile(sourceFile));
}
function getImpliedNodeFormatForEmit(sourceFile: SourceFile): ResolutionMode {
return getImpliedNodeFormatForEmitWorker(sourceFile, getCompilerOptionsForFile(sourceFile));
}
function getEmitModuleFormatOfFile(sourceFile: SourceFile): ModuleKind {
return getEmitModuleFormatOfFileWorker(sourceFile, getCompilerOptionsForFile(sourceFile));
}
function shouldTransformImportCall(sourceFile: SourceFile): boolean {
return shouldTransformImportCallWorker(sourceFile, getCompilerOptionsForFile(sourceFile));
}
}
function shouldTransformImportCallWorker(sourceFile: Pick<SourceFile, "fileName" | "impliedNodeFormat" | "packageJsonScope">, options: CompilerOptions): boolean {
const moduleKind = getEmitModuleKind(options);
if (ModuleKind.Node16 <= moduleKind && moduleKind <= ModuleKind.NodeNext || moduleKind === ModuleKind.Preserve) {
return false;
}
return getEmitModuleFormatOfFileWorker(sourceFile, options) < ModuleKind.ES2015;
}
/** @internal Prefer `program.getEmitModuleFormatOfFile` when possible. */
export function getEmitModuleFormatOfFileWorker(sourceFile: Pick<SourceFile, "fileName" | "impliedNodeFormat" | "packageJsonScope">, options: CompilerOptions): ModuleKind {
return getImpliedNodeFormatForEmitWorker(sourceFile, options) ?? getEmitModuleKind(options);
}
/** @internal Prefer `program.getImpliedNodeFormatForEmit` when possible. */
export function getImpliedNodeFormatForEmitWorker(sourceFile: Pick<SourceFile, "fileName" | "impliedNodeFormat" | "packageJsonScope">, options: CompilerOptions): ResolutionMode {
const moduleKind = getEmitModuleKind(options);
if (ModuleKind.Node16 <= moduleKind && moduleKind <= ModuleKind.NodeNext) {
return sourceFile.impliedNodeFormat;
}
if (
sourceFile.impliedNodeFormat === ModuleKind.CommonJS
&& (sourceFile.packageJsonScope?.contents.packageJsonContent.type === "commonjs"
|| fileExtensionIsOneOf(sourceFile.fileName, [Extension.Cjs, Extension.Cts]))
) {
return ModuleKind.CommonJS;
}
if (
sourceFile.impliedNodeFormat === ModuleKind.ESNext
&& (sourceFile.packageJsonScope?.contents.packageJsonContent.type === "module"
|| fileExtensionIsOneOf(sourceFile.fileName, [Extension.Mjs, Extension.Mts]))
) {
return ModuleKind.ESNext;
}
return undefined;
}
/** @internal Prefer `program.getDefaultResolutionModeForFile` when possible. */
export function getDefaultResolutionModeForFileWorker(sourceFile: Pick<SourceFile, "fileName" | "impliedNodeFormat" | "packageJsonScope">, options: CompilerOptions): ResolutionMode {
return importSyntaxAffectsModuleResolution(options) ? getImpliedNodeFormatForEmitWorker(sourceFile, options) : undefined;
}
interface HostForUseSourceOfProjectReferenceRedirect {

Просмотреть файл

@ -65,10 +65,10 @@ import {
transformESDecorators,
transformESNext,
transformGenerators,
transformImpliedNodeFormatDependentModule,
transformJsx,
transformLegacyDecorators,
transformModule,
transformNodeModule,
transformSystemModule,
transformTypeScript,
VariableDeclaration,
@ -77,23 +77,17 @@ import * as performance from "./_namespaces/ts.performance.js";
function getModuleTransformer(moduleKind: ModuleKind): TransformerFactory<SourceFile | Bundle> {
switch (moduleKind) {
case ModuleKind.Preserve:
// `transformECMAScriptModule` contains logic for preserving
// CJS input syntax in `--module preserve`
return transformECMAScriptModule;
case ModuleKind.ESNext:
case ModuleKind.ES2022:
case ModuleKind.ES2020:
case ModuleKind.ES2015:
case ModuleKind.Node16:
case ModuleKind.NodeNext:
case ModuleKind.CommonJS:
// Wraps `transformModule` and `transformECMAScriptModule` and
// selects between them based on the `impliedNodeFormat` of the
// source file.
return transformImpliedNodeFormatDependentModule;
case ModuleKind.Preserve:
return transformECMAScriptModule;
case ModuleKind.System:
return transformSystemModule;
case ModuleKind.Node16:
case ModuleKind.NodeNext:
return transformNodeModule;
default:
return transformModule;
}

Просмотреть файл

@ -797,7 +797,7 @@ export function transformModule(context: TransformationContext): (x: SourceFile
case SyntaxKind.PartiallyEmittedExpression:
return visitPartiallyEmittedExpression(node as PartiallyEmittedExpression, valueIsDiscarded);
case SyntaxKind.CallExpression:
if (isImportCall(node) && host.shouldTransformImportCall(currentSourceFile)) {
if (isImportCall(node) && currentSourceFile.impliedNodeFormat === undefined) {
return visitImportCallExpression(node);
}
break;

Просмотреть файл

@ -14,7 +14,7 @@ import {
} from "../../_namespaces/ts.js";
/** @internal */
export function transformImpliedNodeFormatDependentModule(context: TransformationContext) {
export function transformNodeModule(context: TransformationContext) {
const previousOnSubstituteNode = context.onSubstituteNode;
const previousOnEmitNode = context.onEmitNode;
@ -30,7 +30,6 @@ export function transformImpliedNodeFormatDependentModule(context: Transformatio
const cjsOnSubstituteNode = context.onSubstituteNode;
const cjsOnEmitNode = context.onEmitNode;
const getEmitModuleFormatOfFile = (file: SourceFile) => context.getEmitHost().getEmitModuleFormatOfFile(file);
context.onSubstituteNode = onSubstituteNode;
context.onEmitNode = onEmitNode;
@ -52,7 +51,7 @@ export function transformImpliedNodeFormatDependentModule(context: Transformatio
if (!currentSourceFile) {
return previousOnSubstituteNode(hint, node);
}
if (getEmitModuleFormatOfFile(currentSourceFile) >= ModuleKind.ES2015) {
if (currentSourceFile.impliedNodeFormat === ModuleKind.ESNext) {
return esmOnSubstituteNode(hint, node);
}
return cjsOnSubstituteNode(hint, node);
@ -66,14 +65,14 @@ export function transformImpliedNodeFormatDependentModule(context: Transformatio
if (!currentSourceFile) {
return previousOnEmitNode(hint, node, emitCallback);
}
if (getEmitModuleFormatOfFile(currentSourceFile) >= ModuleKind.ES2015) {
if (currentSourceFile.impliedNodeFormat === ModuleKind.ESNext) {
return esmOnEmitNode(hint, node, emitCallback);
}
return cjsOnEmitNode(hint, node, emitCallback);
}
function getModuleTransformForFile(file: SourceFile): typeof esmTransform {
return getEmitModuleFormatOfFile(file) >= ModuleKind.ES2015 ? esmTransform : cjsTransform;
return file.impliedNodeFormat === ModuleKind.ESNext ? esmTransform : cjsTransform;
}
function transformSourceFile(node: SourceFile) {

Просмотреть файл

@ -4750,79 +4750,21 @@ export interface Program extends ScriptReferenceHost {
isSourceFileFromExternalLibrary(file: SourceFile): boolean;
isSourceFileDefaultLibrary(file: SourceFile): boolean;
/**
* Calculates the final resolution mode for a given module reference node. This function only returns a result when module resolution
* settings allow differing resolution between ESM imports and CJS requires, or when a mode is explicitly provided via import attributes,
* which cause an `import` or `require` condition to be used during resolution regardless of module resolution settings. In absence of
* overriding attributes, and in modes that support differing resolution, the result indicates the syntax the usage would emit to JavaScript.
* Some examples:
*
* ```ts
* // tsc foo.mts --module nodenext
* import {} from "mod";
* // Result: ESNext - the import emits as ESM due to `impliedNodeFormat` set by .mts file extension
*
* // tsc foo.cts --module nodenext
* import {} from "mod";
* // Result: CommonJS - the import emits as CJS due to `impliedNodeFormat` set by .cts file extension
*
* // tsc foo.ts --module preserve --moduleResolution bundler
* import {} from "mod";
* // Result: ESNext - the import emits as ESM due to `--module preserve` and `--moduleResolution bundler`
* // supports conditional imports/exports
*
* // tsc foo.ts --module preserve --moduleResolution node10
* import {} from "mod";
* // Result: undefined - the import emits as ESM due to `--module preserve`, but `--moduleResolution node10`
* // does not support conditional imports/exports
*
* // tsc foo.ts --module commonjs --moduleResolution node10
* import type {} from "mod" with { "resolution-mode": "import" };
* // Result: ESNext - conditional imports/exports always supported with "resolution-mode" attribute
* ```
* Calculates the final resolution mode for a given module reference node. This is the resolution mode explicitly provided via import
* attributes, if present, or the syntax the usage would have if emitted to JavaScript. In `--module node16` or `nodenext`, this may
* depend on the file's `impliedNodeFormat`. In `--module preserve`, it depends only on the input syntax of the reference. In other
* `module` modes, when overriding import attributes are not provided, this function returns `undefined`, as the result would have no
* impact on module resolution, emit, or type checking.
*/
getModeForUsageLocation(file: SourceFile, usage: StringLiteralLike): ResolutionMode;
/**
* Calculates the final resolution mode for an import at some index within a file's `imports` list. This function only returns a result
* when module resolution settings allow differing resolution between ESM imports and CJS requires, or when a mode is explicitly provided
* via import attributes, which cause an `import` or `require` condition to be used during resolution regardless of module resolution
* settings. In absence of overriding attributes, and in modes that support differing resolution, the result indicates the syntax the
* usage would emit to JavaScript. Some examples:
*
* ```ts
* // tsc foo.mts --module nodenext
* import {} from "mod";
* // Result: ESNext - the import emits as ESM due to `impliedNodeFormat` set by .mts file extension
*
* // tsc foo.cts --module nodenext
* import {} from "mod";
* // Result: CommonJS - the import emits as CJS due to `impliedNodeFormat` set by .cts file extension
*
* // tsc foo.ts --module preserve --moduleResolution bundler
* import {} from "mod";
* // Result: ESNext - the import emits as ESM due to `--module preserve` and `--moduleResolution bundler`
* // supports conditional imports/exports
*
* // tsc foo.ts --module preserve --moduleResolution node10
* import {} from "mod";
* // Result: undefined - the import emits as ESM due to `--module preserve`, but `--moduleResolution node10`
* // does not support conditional imports/exports
*
* // tsc foo.ts --module commonjs --moduleResolution node10
* import type {} from "mod" with { "resolution-mode": "import" };
* // Result: ESNext - conditional imports/exports always supported with "resolution-mode" attribute
* ```
* Calculates the final resolution mode for an import at some index within a file's `imports` list. This is the resolution mode
* explicitly provided via import attributes, if present, or the syntax the usage would have if emitted to JavaScript. In
* `--module node16` or `nodenext`, this may depend on the file's `impliedNodeFormat`. In `--module preserve`, it depends only on the
* input syntax of the reference. In other `module` modes, when overriding import attributes are not provided, this function returns
* `undefined`, as the result would have no impact on module resolution, emit, or type checking.
*/
getModeForResolutionAtIndex(file: SourceFile, index: number): ResolutionMode;
/**
* @internal
* The resolution mode to use for module resolution or module specifier resolution
* outside the context of an existing module reference, where
* `program.getModeForUsageLocation` should be used instead.
*/
getDefaultResolutionModeForFile(sourceFile: SourceFile): ResolutionMode;
/** @internal */ getImpliedNodeFormatForEmit(sourceFile: SourceFile): ResolutionMode;
/** @internal */ getEmitModuleFormatOfFile(sourceFile: SourceFile): ModuleKind;
/** @internal */ shouldTransformImportCall(sourceFile: SourceFile): boolean;
// For testing purposes only.
// This is set on created program to let us know how the program was created using old program
@ -4877,7 +4819,6 @@ export interface Program extends ScriptReferenceHost {
/** @internal */ getResolvedProjectReferenceByPath(projectReferencePath: Path): ResolvedProjectReference | undefined;
/** @internal */ getRedirectReferenceForResolutionFromSourceOfProject(filePath: Path): ResolvedProjectReference | undefined;
/** @internal */ isSourceOfProjectReferenceRedirect(fileName: string): boolean;
/** @internal */ getCompilerOptionsForFile(file: SourceFile): CompilerOptions;
/** @internal */ getBuildInfo?(): BuildInfo;
/** @internal */ emitBuildInfo(writeFile?: WriteFileCallback, cancellationToken?: CancellationToken): EmitResult;
/**
@ -4993,12 +4934,8 @@ export interface TypeCheckerHost extends ModuleSpecifierResolutionHost {
getSourceFile(fileName: string): SourceFile | undefined;
getProjectReferenceRedirect(fileName: string): string | undefined;
isSourceOfProjectReferenceRedirect(fileName: string): boolean;
getEmitSyntaxForUsageLocation(file: SourceFile, usage: StringLiteralLike): ResolutionMode;
getRedirectReferenceForResolutionFromSourceOfProject(filePath: Path): ResolvedProjectReference | undefined;
getModeForUsageLocation(file: SourceFile, usage: StringLiteralLike): ResolutionMode;
getDefaultResolutionModeForFile(sourceFile: SourceFile): ResolutionMode;
getImpliedNodeFormatForEmit(sourceFile: SourceFile): ResolutionMode;
getEmitModuleFormatOfFile(sourceFile: SourceFile): ModuleKind;
getResolvedModule(f: SourceFile, moduleName: string, mode: ResolutionMode): ResolvedModuleWithFailedLookupLocations | undefined;
@ -5668,9 +5605,6 @@ export interface RequireVariableDeclarationList extends VariableDeclarationList
readonly declarations: NodeArray<VariableDeclarationInitializedTo<RequireOrImportCall>>;
}
/** @internal */
export type CanHaveModuleSpecifier = AnyImportOrBareOrAccessedRequire | AliasDeclarationNode | ExportDeclaration | ImportTypeNode;
/** @internal */
export type LateVisibilityPaintedStatement =
| AnyImportOrJsDocImport
@ -8434,8 +8368,6 @@ export interface EmitHost extends ScriptReferenceHost, ModuleSpecifierResolution
getCanonicalFileName(fileName: string): string;
isEmitBlocked(emitFileName: string): boolean;
shouldTransformImportCall(sourceFile: SourceFile): boolean;
getEmitModuleFormatOfFile(sourceFile: SourceFile): ModuleKind;
writeFile: WriteFileCallback;
getBuildInfo(): BuildInfo | undefined;
@ -9676,7 +9608,6 @@ export interface PrinterOptions {
omitTrailingSemicolon?: boolean;
noEmitHelpers?: boolean;
/** @internal */ module?: CompilerOptions["module"];
/** @internal */ moduleResolution?: CompilerOptions["moduleResolution"];
/** @internal */ target?: CompilerOptions["target"];
/** @internal */ sourceMap?: boolean;
/** @internal */ inlineSourceMap?: boolean;
@ -9811,8 +9742,6 @@ export interface ModuleSpecifierResolutionHost {
isSourceOfProjectReferenceRedirect(fileName: string): boolean;
getFileIncludeReasons(): MultiMap<Path, FileIncludeReason>;
getCommonSourceDirectory(): string;
getDefaultResolutionModeForFile(sourceFile: SourceFile): ResolutionMode;
getModeForResolutionAtIndex(file: SourceFile, index: number): ResolutionMode;
getModuleResolutionCache?(): ModuleResolutionCache | undefined;
trace?(s: string): void;

Просмотреть файл

@ -5,6 +5,7 @@ import {
addRange,
affectsDeclarationPathOptionDeclarations,
affectsEmitOptionDeclarations,
AliasDeclarationNode,
AllAccessorDeclarations,
AmbientModuleDeclaration,
AmpersandAmpersandEqualsToken,
@ -40,7 +41,6 @@ import {
canHaveDecorators,
canHaveLocals,
canHaveModifiers,
type CanHaveModuleSpecifier,
CanonicalDiagnostic,
CaseBlock,
CaseClause,
@ -168,7 +168,6 @@ import {
getCommonSourceDirectory,
getContainerFlags,
getDirectoryPath,
getImpliedNodeFormatForEmitWorker,
getJSDocAugmentsTag,
getJSDocDeprecatedTagNoCache,
getJSDocImplementsTags,
@ -4080,26 +4079,7 @@ export function isFunctionSymbol(symbol: Symbol | undefined) {
}
/** @internal */
export function canHaveModuleSpecifier(node: Node | undefined): node is CanHaveModuleSpecifier {
switch (node?.kind) {
case SyntaxKind.VariableDeclaration:
case SyntaxKind.BindingElement:
case SyntaxKind.ImportDeclaration:
case SyntaxKind.ExportDeclaration:
case SyntaxKind.ImportEqualsDeclaration:
case SyntaxKind.ImportClause:
case SyntaxKind.NamespaceExport:
case SyntaxKind.NamespaceImport:
case SyntaxKind.ExportSpecifier:
case SyntaxKind.ImportSpecifier:
case SyntaxKind.ImportType:
return true;
}
return false;
}
/** @internal */
export function tryGetModuleSpecifierFromDeclaration(node: CanHaveModuleSpecifier | JSDocImportTag): StringLiteralLike | undefined {
export function tryGetModuleSpecifierFromDeclaration(node: AnyImportOrBareOrAccessedRequire | AliasDeclarationNode | ExportDeclaration | ImportTypeNode | JSDocImportTag): StringLiteralLike | undefined {
switch (node.kind) {
case SyntaxKind.VariableDeclaration:
case SyntaxKind.BindingElement:
@ -8770,13 +8750,11 @@ function isFileModuleFromUsingJSXTag(file: SourceFile): Node | undefined {
* Note that this requires file.impliedNodeFormat be set already; meaning it must be set very early on
* in SourceFile construction.
*/
function isFileForcedToBeModuleByFormat(file: SourceFile, options: CompilerOptions): true | undefined {
function isFileForcedToBeModuleByFormat(file: SourceFile): true | undefined {
// Excludes declaration files - they still require an explicit `export {}` or the like
// for back compat purposes. The only non-declaration files _not_ forced to be a module are `.js` files
// that aren't esm-mode (meaning not in a `type: module` scope).
//
// TODO: extension check never considered compilerOptions; should impliedNodeFormat?
return (getImpliedNodeFormatForEmitWorker(file, options) === ModuleKind.ESNext || (fileExtensionIsOneOf(file.fileName, [Extension.Cjs, Extension.Cts, Extension.Mjs, Extension.Mts]))) && !file.isDeclarationFile ? true : undefined;
return (file.impliedNodeFormat === ModuleKind.ESNext || (fileExtensionIsOneOf(file.fileName, [Extension.Cjs, Extension.Cts, Extension.Mjs, Extension.Mts]))) && !file.isDeclarationFile ? true : undefined;
}
/** @internal */
@ -8797,29 +8775,17 @@ export function getSetExternalModuleIndicator(options: CompilerOptions): (file:
// If module is nodenext or node16, all esm format files are modules
// If jsx is react-jsx or react-jsxdev then jsx tags force module-ness
// otherwise, the presence of import or export statments (or import.meta) implies module-ness
const checks: ((file: SourceFile, options: CompilerOptions) => Node | true | undefined)[] = [isFileProbablyExternalModule];
const checks: ((file: SourceFile) => Node | true | undefined)[] = [isFileProbablyExternalModule];
if (options.jsx === JsxEmit.ReactJSX || options.jsx === JsxEmit.ReactJSXDev) {
checks.push(isFileModuleFromUsingJSXTag);
}
checks.push(isFileForcedToBeModuleByFormat);
const combined = or(...checks);
const callback = (file: SourceFile) => void (file.externalModuleIndicator = combined(file, options));
const callback = (file: SourceFile) => void (file.externalModuleIndicator = combined(file));
return callback;
}
}
/**
* @internal
* Returns true if an `import` and a `require` of the same module specifier
* can resolve to a different file.
*/
export function importSyntaxAffectsModuleResolution(options: CompilerOptions) {
const moduleResolution = getEmitModuleResolutionKind(options);
return ModuleResolutionKind.Node16 <= moduleResolution && moduleResolution <= ModuleResolutionKind.NodeNext
|| getResolvePackageJsonExports(options)
|| getResolvePackageJsonImports(options);
}
type CompilerOptionKeys = keyof { [K in keyof CompilerOptions as string extends K ? never : K]: any; };
function createComputedCompilerOptions<T extends Record<string, CompilerOptionKeys[]>>(
options: {

Просмотреть файл

@ -56,7 +56,6 @@ import {
getDefaultLibFileName,
getDirectoryPath,
getEmitScriptTarget,
getImpliedNodeFormatForEmitWorker,
getLineAndCharacterOfPosition,
getNameOfScriptTarget,
getNewLineCharacter,
@ -352,14 +351,13 @@ export function explainFiles(program: Program, write: (s: string) => void) {
for (const file of program.getSourceFiles()) {
write(`${toFileName(file, relativeFileName)}`);
reasons.get(file.path)?.forEach(reason => write(` ${fileIncludeReasonToDiagnostics(program, reason, relativeFileName).messageText}`));
explainIfFileIsRedirectAndImpliedFormat(file, program.getCompilerOptionsForFile(file), relativeFileName)?.forEach(d => write(` ${d.messageText}`));
explainIfFileIsRedirectAndImpliedFormat(file, relativeFileName)?.forEach(d => write(` ${d.messageText}`));
}
}
/** @internal */
export function explainIfFileIsRedirectAndImpliedFormat(
file: SourceFile,
options: CompilerOptions,
fileNameConvertor?: (fileName: string) => string,
): DiagnosticMessageChain[] | undefined {
let result: DiagnosticMessageChain[] | undefined;
@ -378,7 +376,7 @@ export function explainIfFileIsRedirectAndImpliedFormat(
));
}
if (isExternalOrCommonJsModule(file)) {
switch (getImpliedNodeFormatForEmitWorker(file, options)) {
switch (file.impliedNodeFormat) {
case ModuleKind.ESNext:
if (file.packageJsonScope) {
(result ??= []).push(chainDiagnosticMessages(

Просмотреть файл

@ -49,12 +49,10 @@ import {
getBaseFileName,
getDefaultLikeExportInfo,
getDirectoryPath,
getEmitModuleFormatOfFileWorker,
getEmitModuleKind,
getEmitModuleResolutionKind,
getEmitScriptTarget,
getExportInfoMap,
getImpliedNodeFormatForEmitWorker,
getMeaningFromLocation,
getNameForExportedSymbol,
getOutputExtension,
@ -329,7 +327,7 @@ function createImportAdderWorker(sourceFile: SourceFile | FutureSourceFile, prog
compilerOptions,
createModuleSpecifierResolutionHost(program, host),
);
const importKind = getImportKind(futureExportingSourceFile, exportKind, program);
const importKind = getImportKind(futureExportingSourceFile, exportKind, compilerOptions);
const addAsTypeOnly = getAddAsTypeOnly(
isImportUsageValidAsTypeOnly,
/*isForNewImportDeclaration*/ true,
@ -693,7 +691,7 @@ export interface ImportSpecifierResolver {
/** @internal */
export function createImportSpecifierResolver(importingFile: SourceFile, program: Program, host: LanguageServiceHost, preferences: UserPreferences): ImportSpecifierResolver {
const packageJsonImportFilter = createPackageJsonImportFilter(importingFile, preferences, host);
const importMap = createExistingImportMap(importingFile, program);
const importMap = createExistingImportMap(program.getTypeChecker(), importingFile, program.getCompilerOptions());
return { getModuleSpecifierForBestExportInfo };
function getModuleSpecifierForBestExportInfo(
@ -898,7 +896,7 @@ function getImportFixes(
sourceFile: SourceFile | FutureSourceFile,
host: LanguageServiceHost,
preferences: UserPreferences,
importMap = isFullSourceFile(sourceFile) ? createExistingImportMap(sourceFile, program) : undefined,
importMap = isFullSourceFile(sourceFile) ? createExistingImportMap(program.getTypeChecker(), sourceFile, program.getCompilerOptions()) : undefined,
fromCacheOnly?: boolean,
): { computedWithoutCacheCount: number; fixes: readonly ImportFixWithModuleSpecifier[]; } {
const checker = program.getTypeChecker();
@ -1065,8 +1063,7 @@ function tryAddToExistingImport(existingImports: readonly FixAddToExistingImport
}
}
function createExistingImportMap(importingFile: SourceFile, program: Program) {
const checker = program.getTypeChecker();
function createExistingImportMap(checker: TypeChecker, importingFile: SourceFile, compilerOptions: CompilerOptions) {
let importMap: MultiMap<SymbolId, AnyImportOrRequire> | undefined;
for (const moduleSpecifier of importingFile.imports) {
const i = importFromModuleSpecifier(moduleSpecifier);
@ -1096,7 +1093,7 @@ function createExistingImportMap(importingFile: SourceFile, program: Program) {
&& !every(matchingDeclarations, isJSDocImportTag)
) return emptyArray;
const importKind = getImportKind(importingFile, exportKind, program);
const importKind = getImportKind(importingFile, exportKind, compilerOptions);
return matchingDeclarations.map(declaration => ({ declaration, importKind, symbol, targetFlags }));
},
};
@ -1120,9 +1117,8 @@ function shouldUseRequire(sourceFile: SourceFile | FutureSourceFile, program: Pr
// 4. In --module nodenext, assume we're not emitting JS -> JS, so use
// whatever syntax Node expects based on the detected module kind
// TODO: consider removing `impliedNodeFormatForEmit`
if (getImpliedNodeFormatForEmit(sourceFile, program) === ModuleKind.CommonJS) return true;
if (getImpliedNodeFormatForEmit(sourceFile, program) === ModuleKind.ESNext) return false;
if (sourceFile.impliedNodeFormat === ModuleKind.CommonJS) return true;
if (sourceFile.impliedNodeFormat === ModuleKind.ESNext) return false;
// 5. Match the first other JS file in the program that's unambiguously CJS or ESM
for (const otherFile of program.getSourceFiles()) {
@ -1175,7 +1171,7 @@ function getNewImportFixes(
// `position` should only be undefined at a missing jsx namespace, in which case we shouldn't be looking for pure types.
return { kind: ImportFixKind.JsdocTypeImport, moduleSpecifierKind, moduleSpecifier, usagePosition, exportInfo, isReExport: i > 0 };
}
const importKind = getImportKind(sourceFile, exportInfo.exportKind, program);
const importKind = getImportKind(sourceFile, exportInfo.exportKind, compilerOptions);
let qualification: Qualification | undefined;
if (usagePosition !== undefined && importKind === ImportKind.CommonJS && exportInfo.exportKind === ExportKind.Named) {
// Compiler options are restricting our import options to a require, but we need to access
@ -1187,7 +1183,7 @@ function getNewImportFixes(
const exportEquals = checker.resolveExternalModuleSymbol(exportInfo.moduleSymbol);
let namespacePrefix;
if (exportEquals !== exportInfo.moduleSymbol) {
namespacePrefix = forEachNameOfDefaultExport(exportEquals, checker, getEmitScriptTarget(compilerOptions), identity)!;
namespacePrefix = forEachNameOfDefaultExport(exportEquals, checker, compilerOptions, /*preferCapitalizedNames*/ false, identity)!;
}
namespacePrefix ||= moduleSymbolToValidIdentifier(
exportInfo.moduleSymbol,
@ -1406,8 +1402,8 @@ function getUmdSymbol(token: Node, checker: TypeChecker): Symbol | undefined {
*
* @internal
*/
export function getImportKind(importingFile: SourceFile | FutureSourceFile, exportKind: ExportKind, program: Program, forceImportKeyword?: boolean): ImportKind {
if (program.getCompilerOptions().verbatimModuleSyntax && getEmitModuleFormatOfFile(importingFile, program) === ModuleKind.CommonJS) {
export function getImportKind(importingFile: SourceFile | FutureSourceFile, exportKind: ExportKind, compilerOptions: CompilerOptions, forceImportKeyword?: boolean): ImportKind {
if (compilerOptions.verbatimModuleSyntax && (getEmitModuleKind(compilerOptions) === ModuleKind.CommonJS || importingFile.impliedNodeFormat === ModuleKind.CommonJS)) {
// TODO: if the exporting file is ESM under nodenext, or `forceImport` is given in a JS file, this is impossible
return ImportKind.CommonJS;
}
@ -1417,22 +1413,22 @@ export function getImportKind(importingFile: SourceFile | FutureSourceFile, expo
case ExportKind.Default:
return ImportKind.Default;
case ExportKind.ExportEquals:
return getExportEqualsImportKind(importingFile, program.getCompilerOptions(), !!forceImportKeyword);
return getExportEqualsImportKind(importingFile, compilerOptions, !!forceImportKeyword);
case ExportKind.UMD:
return getUmdImportKind(importingFile, program, !!forceImportKeyword);
return getUmdImportKind(importingFile, compilerOptions, !!forceImportKeyword);
default:
return Debug.assertNever(exportKind);
}
}
function getUmdImportKind(importingFile: SourceFile | FutureSourceFile, program: Program, forceImportKeyword: boolean): ImportKind {
function getUmdImportKind(importingFile: SourceFile | FutureSourceFile, compilerOptions: CompilerOptions, forceImportKeyword: boolean): ImportKind {
// Import a synthetic `default` if enabled.
if (getAllowSyntheticDefaultImports(program.getCompilerOptions())) {
if (getAllowSyntheticDefaultImports(compilerOptions)) {
return ImportKind.Default;
}
// When a synthetic `default` is unavailable, use `import..require` if the module kind supports it.
const moduleKind = getEmitModuleKind(program.getCompilerOptions());
const moduleKind = getEmitModuleKind(compilerOptions);
switch (moduleKind) {
case ModuleKind.AMD:
case ModuleKind.CommonJS:
@ -1452,7 +1448,7 @@ function getUmdImportKind(importingFile: SourceFile | FutureSourceFile, program:
return ImportKind.Namespace;
case ModuleKind.Node16:
case ModuleKind.NodeNext:
return getImpliedNodeFormatForEmit(importingFile, program) === ModuleKind.ESNext ? ImportKind.Namespace : ImportKind.CommonJS;
return importingFile.impliedNodeFormat === ModuleKind.ESNext ? ImportKind.Namespace : ImportKind.CommonJS;
default:
return Debug.assertNever(moduleKind, `Unexpected moduleKind ${moduleKind}`);
}
@ -1544,7 +1540,7 @@ function getExportInfos(
if (
defaultInfo
&& symbolFlagsHaveMeaning(checker.getSymbolFlags(defaultInfo.symbol), currentTokenMeaning)
&& forEachNameOfDefaultExport(defaultInfo.symbol, checker, getEmitScriptTarget(compilerOptions), (name, capitalizedName) => (isJsxTagName ? capitalizedName ?? name : name) === symbolName)
&& forEachNameOfDefaultExport(defaultInfo.symbol, checker, compilerOptions, isJsxTagName, name => name === symbolName)
) {
addSymbol(moduleSymbol, sourceFile, defaultInfo.symbol, defaultInfo.exportKind, program, isFromPackageJson);
}
@ -2027,11 +2023,3 @@ function symbolFlagsHaveMeaning(flags: SymbolFlags, meaning: SemanticMeaning): b
meaning & SemanticMeaning.Namespace ? !!(flags & SymbolFlags.Namespace) :
false;
}
function getImpliedNodeFormatForEmit(file: SourceFile | FutureSourceFile, program: Program) {
return isFullSourceFile(file) ? program.getImpliedNodeFormatForEmit(file) : getImpliedNodeFormatForEmitWorker(file, program.getCompilerOptions());
}
function getEmitModuleFormatOfFile(file: SourceFile | FutureSourceFile, program: Program) {
return isFullSourceFile(file) ? program.getEmitModuleFormatOfFile(file) : getEmitModuleFormatOfFileWorker(file, program.getCompilerOptions());
}

Просмотреть файл

@ -1161,13 +1161,11 @@ function getJSDocParamAnnotation(
? createSnippetPrinter({
removeComments: true,
module: options.module,
moduleResolution: options.moduleResolution,
target: options.target,
})
: createPrinter({
removeComments: true,
module: options.module,
moduleResolution: options.moduleResolution,
target: options.target,
});
setEmitFlags(typeNode, EmitFlags.SingleLine);
@ -1461,7 +1459,6 @@ function getExhaustiveCaseSnippets(
const printer = createSnippetPrinter({
removeComments: true,
module: options.module,
moduleResolution: options.moduleResolution,
target: options.target,
newLine: getNewLineKind(newLineChar),
});
@ -1723,7 +1720,7 @@ function createCompletionEntry(
if (originIsResolvedExport(origin)) {
sourceDisplay = [textPart(origin.moduleSpecifier)];
if (importStatementCompletion) {
({ insertText, replacementSpan } = getInsertTextAndReplacementSpanForImportCompletion(name, importStatementCompletion, origin, useSemicolons, sourceFile, program, preferences));
({ insertText, replacementSpan } = getInsertTextAndReplacementSpanForImportCompletion(name, importStatementCompletion, origin, useSemicolons, sourceFile, options, preferences));
isSnippet = preferences.includeCompletionsWithSnippetText ? true : undefined;
}
}
@ -1981,7 +1978,6 @@ function getEntryForMemberCompletion(
const printer = createSnippetPrinter({
removeComments: true,
module: options.module,
moduleResolution: options.moduleResolution,
target: options.target,
omitTrailingSemicolon: false,
newLine: getNewLineKind(getNewLineOrDefaultFromHost(host, formatContext?.options)),
@ -2208,7 +2204,6 @@ function getEntryForObjectLiteralMethodCompletion(
const printer = createSnippetPrinter({
removeComments: true,
module: options.module,
moduleResolution: options.moduleResolution,
target: options.target,
omitTrailingSemicolon: false,
newLine: getNewLineKind(getNewLineOrDefaultFromHost(host, formatContext?.options)),
@ -2223,7 +2218,6 @@ function getEntryForObjectLiteralMethodCompletion(
const signaturePrinter = createPrinter({
removeComments: true,
module: options.module,
moduleResolution: options.moduleResolution,
target: options.target,
omitTrailingSemicolon: true,
});
@ -2526,14 +2520,14 @@ function completionEntryDataToSymbolOriginInfo(data: CompletionEntryData, comple
return unresolvedOrigin;
}
function getInsertTextAndReplacementSpanForImportCompletion(name: string, importStatementCompletion: ImportStatementCompletionInfo, origin: SymbolOriginInfoResolvedExport, useSemicolons: boolean, sourceFile: SourceFile, program: Program, preferences: UserPreferences) {
function getInsertTextAndReplacementSpanForImportCompletion(name: string, importStatementCompletion: ImportStatementCompletionInfo, origin: SymbolOriginInfoResolvedExport, useSemicolons: boolean, sourceFile: SourceFile, options: CompilerOptions, preferences: UserPreferences) {
const replacementSpan = importStatementCompletion.replacementSpan;
const quotedModuleSpecifier = escapeSnippetText(quote(sourceFile, preferences, origin.moduleSpecifier));
const exportKind = origin.isDefaultExport ? ExportKind.Default :
origin.exportName === InternalSymbolName.ExportEquals ? ExportKind.ExportEquals :
ExportKind.Named;
const tabStop = preferences.includeCompletionsWithSnippetText ? "$1" : "";
const importKind = codefix.getImportKind(sourceFile, exportKind, program, /*forceImportKeyword*/ true);
const importKind = codefix.getImportKind(sourceFile, exportKind, options, /*forceImportKeyword*/ true);
const isImportSpecifierTypeOnly = importStatementCompletion.couldBeTypeOnlyImportSpecifier;
const topLevelTypeOnlyText = importStatementCompletion.isTopLevelTypeOnly ? ` ${tokenToString(SyntaxKind.TypeKeyword)} ` : " ";
const importSpecifierTypeOnlyText = isImportSpecifierTypeOnly ? `${tokenToString(SyntaxKind.TypeKeyword)} ` : "";

Просмотреть файл

@ -4,6 +4,7 @@ import {
append,
arrayIsEqualTo,
CancellationToken,
CompilerOptions,
consumesNodeCoreModules,
createMultiMap,
Debug,
@ -17,7 +18,9 @@ import {
GetCanonicalFileName,
getDefaultLikeExportNameFromDeclaration,
getDirectoryPath,
getEmitScriptTarget,
getLocalSymbolForExportDefault,
getNamesForExportedSymbol,
getNodeModulePathParts,
getPackageNameFromTypesPackageName,
getRegexFromPattern,
@ -43,7 +46,6 @@ import {
Path,
pathContainsNodeModules,
Program,
ScriptTarget,
skipAlias,
SourceFile,
startsWith,
@ -196,7 +198,7 @@ export function createCacheableExportInfoMap(host: CacheableExportInfoMapHost):
// get a better name.
const names = exportKind === ExportKind.Named || isExternalModuleSymbol(namedSymbol)
? unescapeLeadingUnderscores(symbolTableKey)
: getNamesForExportedSymbol(namedSymbol, checker, /*scriptTarget*/ undefined);
: getNamesForExportedSymbol(namedSymbol, /*scriptTarget*/ undefined);
const symbolName = typeof names === "string" ? names : names[0];
const capitalizedSymbolName = typeof names === "string" ? undefined : names[1];
@ -556,21 +558,12 @@ function isImportableSymbol(symbol: Symbol, checker: TypeChecker) {
return !checker.isUndefinedSymbol(symbol) && !checker.isUnknownSymbol(symbol) && !isKnownSymbol(symbol) && !isPrivateIdentifierSymbol(symbol);
}
function getNamesForExportedSymbol(defaultExport: Symbol, checker: TypeChecker, scriptTarget: ScriptTarget | undefined) {
let names: string | string[] | undefined;
forEachNameOfDefaultExport(defaultExport, checker, scriptTarget, (name, capitalizedName) => {
names = capitalizedName ? [name, capitalizedName] : name;
return true;
});
return Debug.checkDefined(names);
}
/**
* @internal
* May call `cb` multiple times with the same name.
* Terminates when `cb` returns a truthy value.
*/
export function forEachNameOfDefaultExport<T>(defaultExport: Symbol, checker: TypeChecker, scriptTarget: ScriptTarget | undefined, cb: (name: string, capitalizedName?: string) => T | undefined): T | undefined {
export function forEachNameOfDefaultExport<T>(defaultExport: Symbol, checker: TypeChecker, compilerOptions: CompilerOptions, preferCapitalizedNames: boolean, cb: (name: string) => T | undefined): T | undefined {
let chain: Symbol[] | undefined;
let current: Symbol | undefined = defaultExport;
@ -595,10 +588,7 @@ export function forEachNameOfDefaultExport<T>(defaultExport: Symbol, checker: Ty
for (const symbol of chain ?? emptyArray) {
if (symbol.parent && isExternalModuleSymbol(symbol.parent)) {
const final = cb(
moduleSymbolToValidIdentifier(symbol.parent, scriptTarget, /*forceCapitalize*/ false),
moduleSymbolToValidIdentifier(symbol.parent, scriptTarget, /*forceCapitalize*/ true),
);
const final = cb(moduleSymbolToValidIdentifier(symbol.parent, getEmitScriptTarget(compilerOptions), preferCapitalizedNames));
if (final) return final;
}
}

Просмотреть файл

@ -200,7 +200,7 @@ export function getStringLiteralCompletions(
includeSymbol: boolean,
): CompletionInfo | undefined {
if (isInReferenceComment(sourceFile, position)) {
const entries = getTripleSlashReferenceCompletion(sourceFile, position, program, host);
const entries = getTripleSlashReferenceCompletion(sourceFile, position, options, host);
return entries && convertPathCompletions(entries);
}
if (isInString(sourceFile, position, contextToken)) {
@ -614,8 +614,8 @@ function getStringLiteralCompletionsFromModuleNamesWorker(sourceFile: SourceFile
const extensionOptions = getExtensionOptions(compilerOptions, ReferenceKind.ModuleSpecifier, sourceFile, typeChecker, preferences, mode);
return isPathRelativeToScript(literalValue) || !compilerOptions.baseUrl && !compilerOptions.paths && (isRootedDiskPath(literalValue) || isUrl(literalValue))
? getCompletionEntriesForRelativeModules(literalValue, scriptDirectory, program, host, scriptPath, extensionOptions)
: getCompletionEntriesForNonRelativeModules(literalValue, scriptDirectory, mode, program, host, extensionOptions);
? getCompletionEntriesForRelativeModules(literalValue, scriptDirectory, compilerOptions, host, scriptPath, extensionOptions)
: getCompletionEntriesForNonRelativeModules(literalValue, scriptDirectory, mode, compilerOptions, host, extensionOptions, typeChecker);
}
interface ExtensionOptions {
@ -635,21 +635,20 @@ function getExtensionOptions(compilerOptions: CompilerOptions, referenceKind: Re
resolutionMode,
};
}
function getCompletionEntriesForRelativeModules(literalValue: string, scriptDirectory: string, program: Program, host: LanguageServiceHost, scriptPath: Path, extensionOptions: ExtensionOptions) {
const compilerOptions = program.getCompilerOptions();
function getCompletionEntriesForRelativeModules(literalValue: string, scriptDirectory: string, compilerOptions: CompilerOptions, host: LanguageServiceHost, scriptPath: Path, extensionOptions: ExtensionOptions) {
if (compilerOptions.rootDirs) {
return getCompletionEntriesForDirectoryFragmentWithRootDirs(
compilerOptions.rootDirs,
literalValue,
scriptDirectory,
extensionOptions,
program,
compilerOptions,
host,
scriptPath,
);
}
else {
return arrayFrom(getCompletionEntriesForDirectoryFragment(literalValue, scriptDirectory, extensionOptions, program, host, /*moduleSpecifierIsRelative*/ true, scriptPath).values());
return arrayFrom(getCompletionEntriesForDirectoryFragment(literalValue, scriptDirectory, extensionOptions, host, /*moduleSpecifierIsRelative*/ true, scriptPath).values());
}
}
@ -687,13 +686,12 @@ function getBaseDirectoriesFromRootDirs(rootDirs: string[], basePath: string, sc
);
}
function getCompletionEntriesForDirectoryFragmentWithRootDirs(rootDirs: string[], fragment: string, scriptDirectory: string, extensionOptions: ExtensionOptions, program: Program, host: LanguageServiceHost, exclude: string): readonly NameAndKind[] {
const compilerOptions = program.getCompilerOptions();
function getCompletionEntriesForDirectoryFragmentWithRootDirs(rootDirs: string[], fragment: string, scriptDirectory: string, extensionOptions: ExtensionOptions, compilerOptions: CompilerOptions, host: LanguageServiceHost, exclude: string): readonly NameAndKind[] {
const basePath = compilerOptions.project || host.getCurrentDirectory();
const ignoreCase = !(host.useCaseSensitiveFileNames && host.useCaseSensitiveFileNames());
const baseDirectories = getBaseDirectoriesFromRootDirs(rootDirs, basePath, scriptDirectory, ignoreCase);
return deduplicate<NameAndKind>(
flatMap(baseDirectories, baseDirectory => arrayFrom(getCompletionEntriesForDirectoryFragment(fragment, baseDirectory, extensionOptions, program, host, /*moduleSpecifierIsRelative*/ true, exclude).values())),
flatMap(baseDirectories, baseDirectory => arrayFrom(getCompletionEntriesForDirectoryFragment(fragment, baseDirectory, extensionOptions, host, /*moduleSpecifierIsRelative*/ true, exclude).values())),
(itemA, itemB) => itemA.name === itemB.name && itemA.kind === itemB.kind && itemA.extension === itemB.extension,
);
}
@ -709,7 +707,6 @@ function getCompletionEntriesForDirectoryFragment(
fragment: string,
scriptDirectory: string,
extensionOptions: ExtensionOptions,
program: Program,
host: LanguageServiceHost,
moduleSpecifierIsRelative: boolean,
exclude?: string,
@ -749,7 +746,7 @@ function getCompletionEntriesForDirectoryFragment(
if (versionPaths) {
const packageDirectory = getDirectoryPath(packageJsonPath);
const pathInPackage = absolutePath.slice(ensureTrailingDirectorySeparator(packageDirectory).length);
if (addCompletionEntriesFromPaths(result, pathInPackage, packageDirectory, extensionOptions, program, host, versionPaths)) {
if (addCompletionEntriesFromPaths(result, pathInPackage, packageDirectory, extensionOptions, host, versionPaths)) {
// A true result means one of the `versionPaths` was matched, which will block relative resolution
// to files and folders from here. All reachable paths given the pattern match are already added.
return result;
@ -772,7 +769,7 @@ function getCompletionEntriesForDirectoryFragment(
continue;
}
const { name, extension } = getFilenameWithExtensionOption(getBaseFileName(filePath), program, extensionOptions, /*isExportsWildcard*/ false);
const { name, extension } = getFilenameWithExtensionOption(getBaseFileName(filePath), host.getCompilationSettings(), extensionOptions, /*isExportsWildcard*/ false);
result.add(nameAndKind(name, ScriptElementKind.scriptElement, extension));
}
}
@ -792,7 +789,7 @@ function getCompletionEntriesForDirectoryFragment(
return result;
}
function getFilenameWithExtensionOption(name: string, program: Program, extensionOptions: ExtensionOptions, isExportsWildcard: boolean): { name: string; extension: Extension | undefined; } {
function getFilenameWithExtensionOption(name: string, compilerOptions: CompilerOptions, extensionOptions: ExtensionOptions, isExportsWildcard: boolean): { name: string; extension: Extension | undefined; } {
const nonJsResult = moduleSpecifiers.tryGetRealFileNameForNonJsDeclarationFileName(name);
if (nonJsResult) {
return { name: nonJsResult, extension: tryGetExtensionFromPath(nonJsResult) };
@ -803,8 +800,7 @@ function getFilenameWithExtensionOption(name: string, program: Program, extensio
let allowedEndings = getModuleSpecifierPreferences(
{ importModuleSpecifierEnding: extensionOptions.endingPreference },
program,
program.getCompilerOptions(),
compilerOptions,
extensionOptions.importingSourceFile,
).getAllowedEndingsInPreferredOrder(extensionOptions.resolutionMode);
@ -818,7 +814,7 @@ function getFilenameWithExtensionOption(name: string, program: Program, extensio
if (fileExtensionIsOneOf(name, supportedTSImplementationExtensions)) {
return { name, extension: tryGetExtensionFromPath(name) };
}
const outputExtension = moduleSpecifiers.tryGetJSExtensionForFile(name, program.getCompilerOptions());
const outputExtension = moduleSpecifiers.tryGetJSExtensionForFile(name, compilerOptions);
return outputExtension
? { name: changeExtension(name, outputExtension), extension: outputExtension }
: { name, extension: tryGetExtensionFromPath(name) };
@ -832,7 +828,7 @@ function getFilenameWithExtensionOption(name: string, program: Program, extensio
return { name: removeFileExtension(name), extension: tryGetExtensionFromPath(name) };
}
const outputExtension = moduleSpecifiers.tryGetJSExtensionForFile(name, program.getCompilerOptions());
const outputExtension = moduleSpecifiers.tryGetJSExtensionForFile(name, compilerOptions);
return outputExtension
? { name: changeExtension(name, outputExtension), extension: outputExtension }
: { name, extension: tryGetExtensionFromPath(name) };
@ -844,7 +840,6 @@ function addCompletionEntriesFromPaths(
fragment: string,
baseDirectory: string,
extensionOptions: ExtensionOptions,
program: Program,
host: LanguageServiceHost,
paths: MapLike<string[]>,
) {
@ -856,7 +851,7 @@ function addCompletionEntriesFromPaths(
const lengthB = typeof patternB === "object" ? patternB.prefix.length : b.length;
return compareValues(lengthB, lengthA);
};
return addCompletionEntriesFromPathsOrExports(result, /*isExports*/ false, fragment, baseDirectory, extensionOptions, program, host, getOwnKeys(paths), getPatternsForKey, comparePaths);
return addCompletionEntriesFromPathsOrExports(result, /*isExports*/ false, fragment, baseDirectory, extensionOptions, host, getOwnKeys(paths), getPatternsForKey, comparePaths);
}
/** @returns whether `fragment` was a match for any `paths` (which should indicate whether any other path completions should be offered) */
@ -866,7 +861,6 @@ function addCompletionEntriesFromPathsOrExports(
fragment: string,
baseDirectory: string,
extensionOptions: ExtensionOptions,
program: Program,
host: LanguageServiceHost,
keys: readonly string[],
getPatternsForKey: (key: string) => string[] | undefined,
@ -901,7 +895,7 @@ function addCompletionEntriesFromPathsOrExports(
if (typeof pathPattern === "string" || matchedPath === undefined || comparePaths(key, matchedPath) !== Comparison.GreaterThan) {
pathResults.push({
matchedPattern: isMatch,
results: getCompletionsForPathMapping(keyWithoutLeadingDotSlash, patterns, fragment, baseDirectory, extensionOptions, isExports && isMatch, program, host)
results: getCompletionsForPathMapping(keyWithoutLeadingDotSlash, patterns, fragment, baseDirectory, extensionOptions, isExports && isMatch, host)
.map(({ name, kind, extension }) => nameAndKind(name, kind, extension)),
});
}
@ -923,12 +917,11 @@ function getCompletionEntriesForNonRelativeModules(
fragment: string,
scriptPath: string,
mode: ResolutionMode,
program: Program,
compilerOptions: CompilerOptions,
host: LanguageServiceHost,
extensionOptions: ExtensionOptions,
typeChecker: TypeChecker,
): readonly NameAndKind[] {
const typeChecker = program.getTypeChecker();
const compilerOptions = program.getCompilerOptions();
const { baseUrl, paths } = compilerOptions;
const result = createNameAndKindSet();
@ -936,12 +929,12 @@ function getCompletionEntriesForNonRelativeModules(
if (baseUrl) {
const absolute = normalizePath(combinePaths(host.getCurrentDirectory(), baseUrl));
getCompletionEntriesForDirectoryFragment(fragment, absolute, extensionOptions, program, host, /*moduleSpecifierIsRelative*/ false, /*exclude*/ undefined, result);
getCompletionEntriesForDirectoryFragment(fragment, absolute, extensionOptions, host, /*moduleSpecifierIsRelative*/ false, /*exclude*/ undefined, result);
}
if (paths) {
const absolute = getPathsBasePath(compilerOptions, host)!;
addCompletionEntriesFromPaths(result, fragment, absolute, extensionOptions, program, host, paths);
addCompletionEntriesFromPaths(result, fragment, absolute, extensionOptions, host, paths);
}
const fragmentDirectory = getFragmentDirectory(fragment);
@ -949,7 +942,7 @@ function getCompletionEntriesForNonRelativeModules(
result.add(nameAndKind(ambientName, ScriptElementKind.externalModuleName, /*extension*/ undefined));
}
getCompletionEntriesFromTypings(host, program, scriptPath, fragmentDirectory, extensionOptions, result);
getCompletionEntriesFromTypings(host, compilerOptions, scriptPath, fragmentDirectory, extensionOptions, result);
if (moduleResolutionUsesNodeModules(moduleResolution)) {
// If looking for a global package name, don't just include everything in `node_modules` because that includes dependencies' own dependencies.
@ -968,7 +961,7 @@ function getCompletionEntriesForNonRelativeModules(
let ancestorLookup: (directory: string) => void | undefined = ancestor => {
const nodeModules = combinePaths(ancestor, "node_modules");
if (tryDirectoryExists(host, nodeModules)) {
getCompletionEntriesForDirectoryFragment(fragment, nodeModules, extensionOptions, program, host, /*moduleSpecifierIsRelative*/ false, /*exclude*/ undefined, result);
getCompletionEntriesForDirectoryFragment(fragment, nodeModules, extensionOptions, host, /*moduleSpecifierIsRelative*/ false, /*exclude*/ undefined, result);
}
};
if (fragmentDirectory && getResolvePackageJsonExports(compilerOptions)) {
@ -1005,7 +998,6 @@ function getCompletionEntriesForNonRelativeModules(
fragmentSubpath,
packageDirectory,
extensionOptions,
program,
host,
keys,
key => singleElementArray(getPatternFromFirstMatchingCondition(exports[key], conditions)),
@ -1049,7 +1041,6 @@ function getCompletionsForPathMapping(
packageDirectory: string,
extensionOptions: ExtensionOptions,
isExportsWildcard: boolean,
program: Program,
host: LanguageServiceHost,
): readonly NameAndKind[] {
if (!endsWith(path, "*")) {
@ -1061,9 +1052,9 @@ function getCompletionsForPathMapping(
const remainingFragment = tryRemovePrefix(fragment, pathPrefix);
if (remainingFragment === undefined) {
const starIsFullPathComponent = path[path.length - 2] === "/";
return starIsFullPathComponent ? justPathMappingName(pathPrefix, ScriptElementKind.directory) : flatMap(patterns, pattern => getModulesForPathsPattern("", packageDirectory, pattern, extensionOptions, isExportsWildcard, program, host)?.map(({ name, ...rest }) => ({ name: pathPrefix + name, ...rest })));
return starIsFullPathComponent ? justPathMappingName(pathPrefix, ScriptElementKind.directory) : flatMap(patterns, pattern => getModulesForPathsPattern("", packageDirectory, pattern, extensionOptions, isExportsWildcard, host)?.map(({ name, ...rest }) => ({ name: pathPrefix + name, ...rest })));
}
return flatMap(patterns, pattern => getModulesForPathsPattern(remainingFragment, packageDirectory, pattern, extensionOptions, isExportsWildcard, program, host));
return flatMap(patterns, pattern => getModulesForPathsPattern(remainingFragment, packageDirectory, pattern, extensionOptions, isExportsWildcard, host));
function justPathMappingName(name: string, kind: ScriptElementKind.directory | ScriptElementKind.scriptElement): readonly NameAndKind[] {
return startsWith(name, fragment) ? [{ name: removeTrailingDirectorySeparator(name), kind, extension: undefined }] : emptyArray;
@ -1076,7 +1067,6 @@ function getModulesForPathsPattern(
pattern: string,
extensionOptions: ExtensionOptions,
isExportsWildcard: boolean,
program: Program,
host: LanguageServiceHost,
): readonly NameAndKind[] | undefined {
if (!host.readDirectory) {
@ -1125,7 +1115,7 @@ function getModulesForPathsPattern(
if (containsSlash(trimmedWithPattern)) {
return directoryResult(getPathComponents(removeLeadingDirectorySeparator(trimmedWithPattern))[1]);
}
const { name, extension } = getFilenameWithExtensionOption(trimmedWithPattern, program, extensionOptions, isExportsWildcard);
const { name, extension } = getFilenameWithExtensionOption(trimmedWithPattern, host.getCompilationSettings(), extensionOptions, isExportsWildcard);
return nameAndKind(name, ScriptElementKind.scriptElement, extension);
}
});
@ -1169,8 +1159,7 @@ function getAmbientModuleCompletions(fragment: string, fragmentDirectory: string
return nonRelativeModuleNames;
}
function getTripleSlashReferenceCompletion(sourceFile: SourceFile, position: number, program: Program, host: LanguageServiceHost): readonly PathCompletion[] | undefined {
const compilerOptions = program.getCompilerOptions();
function getTripleSlashReferenceCompletion(sourceFile: SourceFile, position: number, compilerOptions: CompilerOptions, host: LanguageServiceHost): readonly PathCompletion[] | undefined {
const token = getTokenAtPosition(sourceFile, position);
const commentRanges = getLeadingCommentRanges(sourceFile.text, token.pos);
const range = commentRanges && find(commentRanges, commentRange => position >= commentRange.pos && position <= commentRange.end);
@ -1185,14 +1174,13 @@ function getTripleSlashReferenceCompletion(sourceFile: SourceFile, position: num
const [, prefix, kind, toComplete] = match;
const scriptPath = getDirectoryPath(sourceFile.path);
const names = kind === "path" ? getCompletionEntriesForDirectoryFragment(toComplete, scriptPath, getExtensionOptions(compilerOptions, ReferenceKind.Filename, sourceFile), program, host, /*moduleSpecifierIsRelative*/ true, sourceFile.path)
: kind === "types" ? getCompletionEntriesFromTypings(host, program, scriptPath, getFragmentDirectory(toComplete), getExtensionOptions(compilerOptions, ReferenceKind.ModuleSpecifier, sourceFile))
const names = kind === "path" ? getCompletionEntriesForDirectoryFragment(toComplete, scriptPath, getExtensionOptions(compilerOptions, ReferenceKind.Filename, sourceFile), host, /*moduleSpecifierIsRelative*/ true, sourceFile.path)
: kind === "types" ? getCompletionEntriesFromTypings(host, compilerOptions, scriptPath, getFragmentDirectory(toComplete), getExtensionOptions(compilerOptions, ReferenceKind.ModuleSpecifier, sourceFile))
: Debug.fail();
return addReplacementSpans(toComplete, range.pos + prefix.length, arrayFrom(names.values()));
}
function getCompletionEntriesFromTypings(host: LanguageServiceHost, program: Program, scriptPath: string, fragmentDirectory: string | undefined, extensionOptions: ExtensionOptions, result = createNameAndKindSet()): NameAndKindSet {
const options = program.getCompilerOptions();
function getCompletionEntriesFromTypings(host: LanguageServiceHost, options: CompilerOptions, scriptPath: string, fragmentDirectory: string | undefined, extensionOptions: ExtensionOptions, result = createNameAndKindSet()): NameAndKindSet {
// Check for typings specified in compiler options
const seen = new Map<string, true>();
@ -1227,7 +1215,7 @@ function getCompletionEntriesFromTypings(host: LanguageServiceHost, program: Pro
const baseDirectory = combinePaths(directory, typeDirectoryName);
const remainingFragment = tryRemoveDirectoryPrefix(fragmentDirectory, packageName, hostGetCanonicalFileName(host));
if (remainingFragment !== undefined) {
getCompletionEntriesForDirectoryFragment(remainingFragment, baseDirectory, extensionOptions, program, host, /*moduleSpecifierIsRelative*/ false, /*exclude*/ undefined, result);
getCompletionEntriesForDirectoryFragment(remainingFragment, baseDirectory, extensionOptions, host, /*moduleSpecifierIsRelative*/ false, /*exclude*/ undefined, result);
}
}
}

Просмотреть файл

@ -66,7 +66,7 @@ export function computeSuggestionDiagnostics(sourceFile: SourceFile, program: Pr
program.getSemanticDiagnostics(sourceFile, cancellationToken);
const diags: DiagnosticWithLocation[] = [];
const checker = program.getTypeChecker();
const isCommonJSFile = program.getImpliedNodeFormatForEmit(sourceFile) === ModuleKind.CommonJS || fileExtensionIsOneOf(sourceFile.fileName, [Extension.Cts, Extension.Cjs]);
const isCommonJSFile = sourceFile.impliedNodeFormat === ModuleKind.CommonJS || fileExtensionIsOneOf(sourceFile.fileName, [Extension.Cts, Extension.Cjs]);
if (
!isCommonJSFile &&

Просмотреть файл

@ -97,7 +97,6 @@ import {
getEmitModuleKind,
getEmitScriptTarget,
getExternalModuleImportEqualsDeclarationExpression,
getImpliedNodeFormatForEmitWorker,
getImpliedNodeFormatForFile,
getImpliedNodeFormatForFileWorker,
getIndentString,
@ -2493,8 +2492,6 @@ export function createModuleSpecifierResolutionHost(program: Program, host: Lang
getNearestAncestorDirectoryWithPackageJson: maybeBind(host, host.getNearestAncestorDirectoryWithPackageJson),
getFileIncludeReasons: () => program.getFileIncludeReasons(),
getCommonSourceDirectory: () => program.getCommonSourceDirectory(),
getDefaultResolutionModeForFile: file => program.getDefaultResolutionModeForFile(file),
getModeForResolutionAtIndex: (file, index) => program.getModeForResolutionAtIndex(file, index),
};
}
@ -4024,13 +4021,22 @@ export function firstOrOnly<T>(valueOrArray: T | readonly T[]): T {
return isArray(valueOrArray) ? first(valueOrArray) : valueOrArray;
}
/**
* If a type checker and multiple files are available, consider using `forEachNameOfDefaultExport`
* instead, which searches for names of re-exported defaults/namespaces in target files.
* @internal
*/
/** @internal */
export function getNamesForExportedSymbol(symbol: Symbol, scriptTarget: ScriptTarget | undefined): string | [lowercase: string, capitalized: string] {
if (needsNameFromDeclaration(symbol)) {
const fromDeclaration = getDefaultLikeExportNameFromDeclaration(symbol);
if (fromDeclaration) return fromDeclaration;
const fileNameCase = moduleSymbolToValidIdentifier(getSymbolParentOrFail(symbol), scriptTarget, /*forceCapitalize*/ false);
const capitalized = moduleSymbolToValidIdentifier(getSymbolParentOrFail(symbol), scriptTarget, /*forceCapitalize*/ true);
if (fileNameCase === capitalized) return fileNameCase;
return [fileNameCase, capitalized];
}
return symbol.name;
}
/** @internal */
export function getNameForExportedSymbol(symbol: Symbol, scriptTarget: ScriptTarget | undefined, preferCapitalized?: boolean) {
if (symbol.escapedName === InternalSymbolName.ExportEquals || symbol.escapedName === InternalSymbolName.Default) {
if (needsNameFromDeclaration(symbol)) {
// Names for default exports:
// - export default foo => foo
// - export { foo as default } => foo
@ -4041,11 +4047,11 @@ export function getNameForExportedSymbol(symbol: Symbol, scriptTarget: ScriptTar
return symbol.name;
}
/**
* If a type checker and multiple files are available, consider using `forEachNameOfDefaultExport`
* instead, which searches for names of re-exported defaults/namespaces in target files.
* @internal
*/
function needsNameFromDeclaration(symbol: Symbol) {
return !(symbol.flags & SymbolFlags.Transient) && (symbol.escapedName === InternalSymbolName.ExportEquals || symbol.escapedName === InternalSymbolName.Default);
}
/** @internal */
export function getDefaultLikeExportNameFromDeclaration(symbol: Symbol): string | undefined {
return firstDefined(symbol.declarations, d => {
// "export default" in this case. See `ExportAssignment`for more details.
@ -4295,13 +4301,11 @@ export function fileShouldUseJavaScriptRequire(file: SourceFile | string, progra
if (!hasJSFileExtension(fileName)) {
return false;
}
const compilerOptions = typeof file === "string" ? program.getCompilerOptions() : program.getCompilerOptionsForFile(file);
const compilerOptions = program.getCompilerOptions();
const moduleKind = getEmitModuleKind(compilerOptions);
const sourceFileLike = typeof file === "string" ? {
fileName: file,
impliedNodeFormat: getImpliedNodeFormatForFile(toPath(file, host.getCurrentDirectory(), hostGetCanonicalFileName(host)), program.getPackageJsonInfoCache?.(), host, compilerOptions),
} : file;
const impliedNodeFormat = getImpliedNodeFormatForEmitWorker(sourceFileLike, compilerOptions);
const impliedNodeFormat = typeof file === "string"
? getImpliedNodeFormatForFile(toPath(file, host.getCurrentDirectory(), hostGetCanonicalFileName(host)), program.getPackageJsonInfoCache?.(), host, compilerOptions)
: file.impliedNodeFormat;
if (impliedNodeFormat === ModuleKind.ESNext) {
return false;

Просмотреть файл

@ -44,51 +44,6 @@ describe("unittests:: tsc:: projectReferences::", () => {
commandLineArgs: ["--p", "src/project"],
});
verifyTsc({
scenario: "projectReferences",
subScenario: "default import interop uses referenced project settings",
fs: () =>
loadProjectFromFiles({
"/node_modules/ambiguous-package/package.json": `{ "name": "ambiguous-package" }`,
"/node_modules/ambiguous-package/index.d.ts": "export declare const ambiguous: number;",
"/node_modules/esm-package/package.json": `{ "name": "esm-package", "type": "module" }`,
"/node_modules/esm-package/index.d.ts": "export declare const esm: number;",
"/lib/tsconfig.json": jsonToReadableText({
compilerOptions: {
composite: true,
declaration: true,
rootDir: "src",
outDir: "dist",
module: "esnext",
moduleResolution: "bundler",
},
include: ["src"],
}),
"/lib/src/a.ts": "export const a = 0;",
"/lib/dist/a.d.ts": "export declare const a = 0;",
"/app/tsconfig.json": jsonToReadableText({
compilerOptions: {
module: "esnext",
moduleResolution: "bundler",
rootDir: "src",
outDir: "dist",
},
include: ["src"],
references: [
{ path: "../lib" },
],
}),
"/app/src/local.ts": "export const local = 0;",
"/app/src/index.ts": `
import local from "./local"; // Error
import esm from "esm-package"; // Error
import referencedSource from "../../lib/src/a"; // Error
import referencedDeclaration from "../../lib/dist/a"; // Error
import ambiguous from "ambiguous-package"; // Ok`,
}),
commandLineArgs: ["--p", "app", "--pretty", "false"],
});
verifyTsc({
scenario: "projectReferences",
subScenario: "referencing ambient const enum from referenced project with preserveConstEnums",

111
tests/baselines/reference/api/typescript.d.ts поставляемый
Просмотреть файл

@ -6025,67 +6025,19 @@ declare namespace ts {
isSourceFileFromExternalLibrary(file: SourceFile): boolean;
isSourceFileDefaultLibrary(file: SourceFile): boolean;
/**
* Calculates the final resolution mode for a given module reference node. This function only returns a result when module resolution
* settings allow differing resolution between ESM imports and CJS requires, or when a mode is explicitly provided via import attributes,
* which cause an `import` or `require` condition to be used during resolution regardless of module resolution settings. In absence of
* overriding attributes, and in modes that support differing resolution, the result indicates the syntax the usage would emit to JavaScript.
* Some examples:
*
* ```ts
* // tsc foo.mts --module nodenext
* import {} from "mod";
* // Result: ESNext - the import emits as ESM due to `impliedNodeFormat` set by .mts file extension
*
* // tsc foo.cts --module nodenext
* import {} from "mod";
* // Result: CommonJS - the import emits as CJS due to `impliedNodeFormat` set by .cts file extension
*
* // tsc foo.ts --module preserve --moduleResolution bundler
* import {} from "mod";
* // Result: ESNext - the import emits as ESM due to `--module preserve` and `--moduleResolution bundler`
* // supports conditional imports/exports
*
* // tsc foo.ts --module preserve --moduleResolution node10
* import {} from "mod";
* // Result: undefined - the import emits as ESM due to `--module preserve`, but `--moduleResolution node10`
* // does not support conditional imports/exports
*
* // tsc foo.ts --module commonjs --moduleResolution node10
* import type {} from "mod" with { "resolution-mode": "import" };
* // Result: ESNext - conditional imports/exports always supported with "resolution-mode" attribute
* ```
* Calculates the final resolution mode for a given module reference node. This is the resolution mode explicitly provided via import
* attributes, if present, or the syntax the usage would have if emitted to JavaScript. In `--module node16` or `nodenext`, this may
* depend on the file's `impliedNodeFormat`. In `--module preserve`, it depends only on the input syntax of the reference. In other
* `module` modes, when overriding import attributes are not provided, this function returns `undefined`, as the result would have no
* impact on module resolution, emit, or type checking.
*/
getModeForUsageLocation(file: SourceFile, usage: StringLiteralLike): ResolutionMode;
/**
* Calculates the final resolution mode for an import at some index within a file's `imports` list. This function only returns a result
* when module resolution settings allow differing resolution between ESM imports and CJS requires, or when a mode is explicitly provided
* via import attributes, which cause an `import` or `require` condition to be used during resolution regardless of module resolution
* settings. In absence of overriding attributes, and in modes that support differing resolution, the result indicates the syntax the
* usage would emit to JavaScript. Some examples:
*
* ```ts
* // tsc foo.mts --module nodenext
* import {} from "mod";
* // Result: ESNext - the import emits as ESM due to `impliedNodeFormat` set by .mts file extension
*
* // tsc foo.cts --module nodenext
* import {} from "mod";
* // Result: CommonJS - the import emits as CJS due to `impliedNodeFormat` set by .cts file extension
*
* // tsc foo.ts --module preserve --moduleResolution bundler
* import {} from "mod";
* // Result: ESNext - the import emits as ESM due to `--module preserve` and `--moduleResolution bundler`
* // supports conditional imports/exports
*
* // tsc foo.ts --module preserve --moduleResolution node10
* import {} from "mod";
* // Result: undefined - the import emits as ESM due to `--module preserve`, but `--moduleResolution node10`
* // does not support conditional imports/exports
*
* // tsc foo.ts --module commonjs --moduleResolution node10
* import type {} from "mod" with { "resolution-mode": "import" };
* // Result: ESNext - conditional imports/exports always supported with "resolution-mode" attribute
* ```
* Calculates the final resolution mode for an import at some index within a file's `imports` list. This is the resolution mode
* explicitly provided via import attributes, if present, or the syntax the usage would have if emitted to JavaScript. In
* `--module node16` or `nodenext`, this may depend on the file's `impliedNodeFormat`. In `--module preserve`, it depends only on the
* input syntax of the reference. In other `module` modes, when overriding import attributes are not provided, this function returns
* `undefined`, as the result would have no impact on module resolution, emit, or type checking.
*/
getModeForResolutionAtIndex(file: SourceFile, index: number): ResolutionMode;
getProjectReferences(): readonly ProjectReference[] | undefined;
@ -9439,43 +9391,24 @@ declare namespace ts {
function getModeForResolutionAtIndex(file: SourceFile, index: number, compilerOptions: CompilerOptions): ResolutionMode;
/**
* Use `program.getModeForUsageLocation`, which retrieves the correct `compilerOptions`, instead of this function whenever possible.
* Calculates the final resolution mode for a given module reference node. This function only returns a result when module resolution
* settings allow differing resolution between ESM imports and CJS requires, or when a mode is explicitly provided via import attributes,
* which cause an `import` or `require` condition to be used during resolution regardless of module resolution settings. In absence of
* overriding attributes, and in modes that support differing resolution, the result indicates the syntax the usage would emit to JavaScript.
* Some examples:
*
* ```ts
* // tsc foo.mts --module nodenext
* import {} from "mod";
* // Result: ESNext - the import emits as ESM due to `impliedNodeFormat` set by .mts file extension
*
* // tsc foo.cts --module nodenext
* import {} from "mod";
* // Result: CommonJS - the import emits as CJS due to `impliedNodeFormat` set by .cts file extension
*
* // tsc foo.ts --module preserve --moduleResolution bundler
* import {} from "mod";
* // Result: ESNext - the import emits as ESM due to `--module preserve` and `--moduleResolution bundler`
* // supports conditional imports/exports
*
* // tsc foo.ts --module preserve --moduleResolution node10
* import {} from "mod";
* // Result: undefined - the import emits as ESM due to `--module preserve`, but `--moduleResolution node10`
* // does not support conditional imports/exports
*
* // tsc foo.ts --module commonjs --moduleResolution node10
* import type {} from "mod" with { "resolution-mode": "import" };
* // Result: ESNext - conditional imports/exports always supported with "resolution-mode" attribute
* ```
*
* Calculates the final resolution mode for a given module reference node. This is the resolution mode explicitly provided via import
* attributes, if present, or the syntax the usage would have if emitted to JavaScript. In `--module node16` or `nodenext`, this may
* depend on the file's `impliedNodeFormat`. In `--module preserve`, it depends only on the input syntax of the reference. In other
* `module` modes, when overriding import attributes are not provided, this function returns `undefined`, as the result would have no
* impact on module resolution, emit, or type checking.
* @param file The file the import or import-like reference is contained within
* @param usage The module reference string
* @param compilerOptions The compiler options for the program that owns the file. If the file belongs to a referenced project, the compiler options
* should be the options of the referenced project, not the referencing project.
* @returns The final resolution mode of the import
*/
function getModeForUsageLocation(file: SourceFile, usage: StringLiteralLike, compilerOptions: CompilerOptions): ResolutionMode;
function getModeForUsageLocation(
file: {
impliedNodeFormat?: ResolutionMode;
},
usage: StringLiteralLike,
compilerOptions: CompilerOptions,
): ModuleKind.CommonJS | ModuleKind.ESNext | undefined;
function getConfigFileParsingDiagnostics(configFileParseResult: ParsedCommandLine): readonly Diagnostic[];
/**
* A function for determining if a given file is esm or cjs format, assuming modern node module resolution rules, as configured by the

Просмотреть файл

@ -0,0 +1,29 @@
error TS5095: Option 'bundler' can only be used when 'module' is set to 'preserve' or to 'es2015' or later.
!!! error TS5095: Option 'bundler' can only be used when 'module' is set to 'preserve' or to 'es2015' or later.
==== /node_modules/dep/package.json (0 errors) ====
{
"name": "dep",
"version": "1.0.0",
"exports": {
".": {
"import": "./dist/index.mjs",
"require": "./dist/index.js",
"types": "./dist/index.d.ts",
}
}
}
==== /node_modules/dep/dist/index.d.ts (0 errors) ====
export {};
==== /node_modules/dep/dist/index.mjs (0 errors) ====
export {};
==== /index.mts (0 errors) ====
import {} from "dep";
// Should be an untyped resolution to dep/dist/index.mjs,
// but the first search is only for TS files, and when
// there's no dist/index.d.mts, it continues looking for
// matching conditions and resolves via `types`.

Просмотреть файл

@ -0,0 +1,31 @@
error TS5095: Option 'bundler' can only be used when 'module' is set to 'preserve' or to 'es2015' or later.
!!! error TS5095: Option 'bundler' can only be used when 'module' is set to 'preserve' or to 'es2015' or later.
==== /node_modules/lodash/package.json (0 errors) ====
{
"name": "lodash",
"version": "1.0.0",
"main": "index.js",
"exports": {
"browser": "./browser.js",
"webpack": "./webpack.js",
"default": "./index.js"
}
}
==== /node_modules/lodash/index.d.ts (0 errors) ====
declare const _: "index";
export = _;
==== /node_modules/lodash/browser.d.ts (0 errors) ====
declare const _: "browser";
export default _;
==== /node_modules/lodash/webpack.d.ts (0 errors) ====
declare const _: "webpack";
export = _;
==== /index.ts (0 errors) ====
import _ from "lodash";

Просмотреть файл

@ -29,3 +29,5 @@ import _ from "lodash";
//// [index.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

Просмотреть файл

@ -0,0 +1,31 @@
error TS5095: Option 'bundler' can only be used when 'module' is set to 'preserve' or to 'es2015' or later.
!!! error TS5095: Option 'bundler' can only be used when 'module' is set to 'preserve' or to 'es2015' or later.
==== /node_modules/lodash/package.json (0 errors) ====
{
"name": "lodash",
"version": "1.0.0",
"main": "index.js",
"exports": {
"browser": "./browser.js",
"webpack": "./webpack.js",
"default": "./index.js"
}
}
==== /node_modules/lodash/index.d.ts (0 errors) ====
declare const _: "index";
export = _;
==== /node_modules/lodash/browser.d.ts (0 errors) ====
declare const _: "browser";
export default _;
==== /node_modules/lodash/webpack.d.ts (0 errors) ====
declare const _: "webpack";
export = _;
==== /index.ts (0 errors) ====
import _ from "lodash";

Просмотреть файл

@ -29,3 +29,5 @@ import _ from "lodash";
//// [index.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

Просмотреть файл

@ -10,17 +10,20 @@ const y = { ...o };
//// [a.js]
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.A = void 0;
let A = class A {
};
A = __decorate([
exports.A = A;
exports.A = A = __decorate([
dec
], A);
export { A };
const o = { a: 1 };
const y = Object.assign({}, o);

Просмотреть файл

@ -10,17 +10,20 @@ const y = { ...o };
//// [a.js]
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.A = void 0;
let A = class A {
};
A = __decorate([
exports.A = A;
exports.A = A = __decorate([
dec
], A);
export { A };
const o = { a: 1 };
const y = Object.assign({}, o);

Просмотреть файл

@ -1,25 +0,0 @@
//// [tests/cases/compiler/esmNoSynthesizedDefault.ts] ////
//// [package.json]
{ "type": "module" }
//// [index.d.ts]
export function toString(): string;
//// [index.ts]
import mdast, { toString } from 'mdast-util-to-string';
mdast;
mdast.toString();
const mdast2 = await import('mdast-util-to-string');
mdast2.toString();
mdast2.default;
//// [index.js]
import mdast from 'mdast-util-to-string';
mdast;
mdast.toString();
const mdast2 = await import('mdast-util-to-string');
mdast2.toString();
mdast2.default;

Просмотреть файл

@ -1,33 +0,0 @@
//// [tests/cases/compiler/esmNoSynthesizedDefault.ts] ////
=== /node_modules/mdast-util-to-string/index.d.ts ===
export function toString(): string;
>toString : Symbol(toString, Decl(index.d.ts, 0, 0))
=== /index.ts ===
import mdast, { toString } from 'mdast-util-to-string';
>mdast : Symbol(mdast, Decl(index.ts, 0, 6))
>toString : Symbol(toString, Decl(index.ts, 0, 15))
mdast;
>mdast : Symbol(mdast, Decl(index.ts, 0, 6))
mdast.toString();
>mdast.toString : Symbol(mdast.toString, Decl(index.d.ts, 0, 0))
>mdast : Symbol(mdast, Decl(index.ts, 0, 6))
>toString : Symbol(mdast.toString, Decl(index.d.ts, 0, 0))
const mdast2 = await import('mdast-util-to-string');
>mdast2 : Symbol(mdast2, Decl(index.ts, 4, 5))
>'mdast-util-to-string' : Symbol(mdast, Decl(index.d.ts, 0, 0))
mdast2.toString();
>mdast2.toString : Symbol(mdast.toString, Decl(index.d.ts, 0, 0))
>mdast2 : Symbol(mdast2, Decl(index.ts, 4, 5))
>toString : Symbol(mdast.toString, Decl(index.d.ts, 0, 0))
mdast2.default;
>mdast2.default : Symbol(mdast.default)
>mdast2 : Symbol(mdast2, Decl(index.ts, 4, 5))
>default : Symbol(mdast.default)

Просмотреть файл

@ -1,56 +0,0 @@
//// [tests/cases/compiler/esmNoSynthesizedDefault.ts] ////
=== /node_modules/mdast-util-to-string/index.d.ts ===
export function toString(): string;
>toString : () => string
> : ^^^^^^
=== /index.ts ===
import mdast, { toString } from 'mdast-util-to-string';
>mdast : typeof mdast
> : ^^^^^^^^^^^^
>toString : () => string
> : ^^^^^^
mdast;
>mdast : typeof mdast
> : ^^^^^^^^^^^^
mdast.toString();
>mdast.toString() : string
> : ^^^^^^
>mdast.toString : () => string
> : ^^^^^^
>mdast : typeof mdast
> : ^^^^^^^^^^^^
>toString : () => string
> : ^^^^^^
const mdast2 = await import('mdast-util-to-string');
>mdast2 : { default: typeof mdast; toString(): string; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^
>await import('mdast-util-to-string') : { default: typeof mdast; toString(): string; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^
>import('mdast-util-to-string') : Promise<{ default: typeof mdast; toString(): string; }>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^
>'mdast-util-to-string' : "mdast-util-to-string"
> : ^^^^^^^^^^^^^^^^^^^^^^
mdast2.toString();
>mdast2.toString() : string
> : ^^^^^^
>mdast2.toString : () => string
> : ^^^^^^
>mdast2 : { default: typeof mdast; toString(): string; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^
>toString : () => string
> : ^^^^^^
mdast2.default;
>mdast2.default : typeof mdast
> : ^^^^^^^^^^^^
>mdast2 : { default: typeof mdast; toString(): string; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^
>default : typeof mdast
> : ^^^^^^^^^^^^

Просмотреть файл

@ -1,25 +0,0 @@
//// [tests/cases/compiler/esmNoSynthesizedDefault.ts] ////
//// [package.json]
{ "type": "module" }
//// [index.d.ts]
export function toString(): string;
//// [index.ts]
import mdast, { toString } from 'mdast-util-to-string';
mdast;
mdast.toString();
const mdast2 = await import('mdast-util-to-string');
mdast2.toString();
mdast2.default;
//// [index.js]
import mdast from 'mdast-util-to-string';
mdast;
mdast.toString();
const mdast2 = await import('mdast-util-to-string');
mdast2.toString();
mdast2.default;

Просмотреть файл

@ -1,33 +0,0 @@
//// [tests/cases/compiler/esmNoSynthesizedDefault.ts] ////
=== /node_modules/mdast-util-to-string/index.d.ts ===
export function toString(): string;
>toString : Symbol(toString, Decl(index.d.ts, 0, 0))
=== /index.ts ===
import mdast, { toString } from 'mdast-util-to-string';
>mdast : Symbol(mdast, Decl(index.ts, 0, 6))
>toString : Symbol(toString, Decl(index.ts, 0, 15))
mdast;
>mdast : Symbol(mdast, Decl(index.ts, 0, 6))
mdast.toString();
>mdast.toString : Symbol(mdast.toString, Decl(index.d.ts, 0, 0))
>mdast : Symbol(mdast, Decl(index.ts, 0, 6))
>toString : Symbol(mdast.toString, Decl(index.d.ts, 0, 0))
const mdast2 = await import('mdast-util-to-string');
>mdast2 : Symbol(mdast2, Decl(index.ts, 4, 5))
>'mdast-util-to-string' : Symbol(mdast, Decl(index.d.ts, 0, 0))
mdast2.toString();
>mdast2.toString : Symbol(mdast.toString, Decl(index.d.ts, 0, 0))
>mdast2 : Symbol(mdast2, Decl(index.ts, 4, 5))
>toString : Symbol(mdast.toString, Decl(index.d.ts, 0, 0))
mdast2.default;
>mdast2.default : Symbol(mdast.default)
>mdast2 : Symbol(mdast2, Decl(index.ts, 4, 5))
>default : Symbol(mdast.default)

Просмотреть файл

@ -1,56 +0,0 @@
//// [tests/cases/compiler/esmNoSynthesizedDefault.ts] ////
=== /node_modules/mdast-util-to-string/index.d.ts ===
export function toString(): string;
>toString : () => string
> : ^^^^^^
=== /index.ts ===
import mdast, { toString } from 'mdast-util-to-string';
>mdast : typeof mdast
> : ^^^^^^^^^^^^
>toString : () => string
> : ^^^^^^
mdast;
>mdast : typeof mdast
> : ^^^^^^^^^^^^
mdast.toString();
>mdast.toString() : string
> : ^^^^^^
>mdast.toString : () => string
> : ^^^^^^
>mdast : typeof mdast
> : ^^^^^^^^^^^^
>toString : () => string
> : ^^^^^^
const mdast2 = await import('mdast-util-to-string');
>mdast2 : { default: typeof mdast; toString(): string; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^
>await import('mdast-util-to-string') : { default: typeof mdast; toString(): string; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^
>import('mdast-util-to-string') : Promise<{ default: typeof mdast; toString(): string; }>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^
>'mdast-util-to-string' : "mdast-util-to-string"
> : ^^^^^^^^^^^^^^^^^^^^^^
mdast2.toString();
>mdast2.toString() : string
> : ^^^^^^
>mdast2.toString : () => string
> : ^^^^^^
>mdast2 : { default: typeof mdast; toString(): string; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^
>toString : () => string
> : ^^^^^^
mdast2.default;
>mdast2.default : typeof mdast
> : ^^^^^^^^^^^^
>mdast2 : { default: typeof mdast; toString(): string; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^
>default : typeof mdast
> : ^^^^^^^^^^^^

Просмотреть файл

@ -1,37 +0,0 @@
error TS5095: Option 'bundler' can only be used when 'module' is set to 'preserve' or to 'es2015' or later.
!!! error TS5095: Option 'bundler' can only be used when 'module' is set to 'preserve' or to 'es2015' or later.
==== /a.ts (0 errors) ====
export const _ = 0;
==== /b.mts (0 errors) ====
export const _ = 0;
==== /c.cts (0 errors) ====
export const _ = 0;
==== /d.js (0 errors) ====
export const _ = 0;
==== /e.mjs (0 errors) ====
export const _ = 0;
==== /f.mjs (0 errors) ====
export const _ = 0;
==== /g.ts (0 errors) ====
import {} from "./a";
import a = require("./a");
==== /h.mts (0 errors) ====
import {} from "./a";
import a = require("./a");
==== /i.cts (0 errors) ====
import {} from "./a";
import a = require("./a");
==== /dummy.ts (0 errors) ====
export {};

Просмотреть файл

@ -1,98 +0,0 @@
//// [tests/cases/compiler/impliedNodeFormatEmit1.ts] ////
//// [a.ts]
export const _ = 0;
//// [b.mts]
export const _ = 0;
//// [c.cts]
export const _ = 0;
//// [d.js]
export const _ = 0;
//// [e.mjs]
export const _ = 0;
//// [f.mjs]
export const _ = 0;
//// [g.ts]
import {} from "./a";
import a = require("./a");
//// [h.mts]
import {} from "./a";
import a = require("./a");
//// [i.cts]
import {} from "./a";
import a = require("./a");
//// [dummy.ts]
export {};
//// [a.js]
define(["require", "exports"], function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._ = void 0;
exports._ = 0;
});
//// [b.mjs]
define(["require", "exports"], function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._ = void 0;
exports._ = 0;
});
//// [c.cjs]
define(["require", "exports"], function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._ = void 0;
exports._ = 0;
});
//// [d.js]
define(["require", "exports"], function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._ = void 0;
exports._ = 0;
});
//// [e.mjs]
define(["require", "exports"], function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._ = void 0;
exports._ = 0;
});
//// [f.mjs]
define(["require", "exports"], function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._ = void 0;
exports._ = 0;
});
//// [g.js]
define(["require", "exports"], function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
});
//// [h.mjs]
define(["require", "exports"], function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
});
//// [i.cjs]
define(["require", "exports"], function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
});
//// [dummy.js]
define(["require", "exports"], function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
});

Просмотреть файл

@ -1,37 +0,0 @@
error TS5095: Option 'bundler' can only be used when 'module' is set to 'preserve' or to 'es2015' or later.
!!! error TS5095: Option 'bundler' can only be used when 'module' is set to 'preserve' or to 'es2015' or later.
==== /a.ts (0 errors) ====
export const _ = 0;
==== /b.mts (0 errors) ====
export const _ = 0;
==== /c.cts (0 errors) ====
export const _ = 0;
==== /d.js (0 errors) ====
export const _ = 0;
==== /e.mjs (0 errors) ====
export const _ = 0;
==== /f.mjs (0 errors) ====
export const _ = 0;
==== /g.ts (0 errors) ====
import {} from "./a";
import a = require("./a");
==== /h.mts (0 errors) ====
import {} from "./a";
import a = require("./a");
==== /i.cts (0 errors) ====
import {} from "./a";
import a = require("./a");
==== /dummy.ts (0 errors) ====
export {};

Просмотреть файл

@ -1,78 +0,0 @@
//// [tests/cases/compiler/impliedNodeFormatEmit1.ts] ////
//// [a.ts]
export const _ = 0;
//// [b.mts]
export const _ = 0;
//// [c.cts]
export const _ = 0;
//// [d.js]
export const _ = 0;
//// [e.mjs]
export const _ = 0;
//// [f.mjs]
export const _ = 0;
//// [g.ts]
import {} from "./a";
import a = require("./a");
//// [h.mts]
import {} from "./a";
import a = require("./a");
//// [i.cts]
import {} from "./a";
import a = require("./a");
//// [dummy.ts]
export {};
//// [a.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._ = void 0;
exports._ = 0;
//// [b.mjs]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._ = void 0;
exports._ = 0;
//// [c.cjs]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._ = void 0;
exports._ = 0;
//// [d.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._ = void 0;
exports._ = 0;
//// [e.mjs]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._ = void 0;
exports._ = 0;
//// [f.mjs]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._ = void 0;
exports._ = 0;
//// [g.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//// [h.mjs]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//// [i.cjs]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//// [dummy.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

Просмотреть файл

@ -1,44 +0,0 @@
/g.ts(2,1): error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.
/h.mts(2,1): error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.
/i.cts(2,1): error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.
==== /a.ts (0 errors) ====
export const _ = 0;
==== /b.mts (0 errors) ====
export const _ = 0;
==== /c.cts (0 errors) ====
export const _ = 0;
==== /d.js (0 errors) ====
export const _ = 0;
==== /e.mjs (0 errors) ====
export const _ = 0;
==== /f.mjs (0 errors) ====
export const _ = 0;
==== /g.ts (1 errors) ====
import {} from "./a";
import a = require("./a");
~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.
==== /h.mts (1 errors) ====
import {} from "./a";
import a = require("./a");
~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.
==== /i.cts (1 errors) ====
import {} from "./a";
import a = require("./a");
~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.
==== /dummy.ts (0 errors) ====
export {};

Просмотреть файл

@ -1,56 +0,0 @@
//// [tests/cases/compiler/impliedNodeFormatEmit1.ts] ////
//// [a.ts]
export const _ = 0;
//// [b.mts]
export const _ = 0;
//// [c.cts]
export const _ = 0;
//// [d.js]
export const _ = 0;
//// [e.mjs]
export const _ = 0;
//// [f.mjs]
export const _ = 0;
//// [g.ts]
import {} from "./a";
import a = require("./a");
//// [h.mts]
import {} from "./a";
import a = require("./a");
//// [i.cts]
import {} from "./a";
import a = require("./a");
//// [dummy.ts]
export {};
//// [a.js]
export var _ = 0;
//// [b.mjs]
export var _ = 0;
//// [c.cjs]
export var _ = 0;
//// [d.js]
export var _ = 0;
//// [e.mjs]
export var _ = 0;
//// [f.mjs]
export var _ = 0;
//// [g.js]
export {};
//// [h.mjs]
export {};
//// [i.cjs]
export {};
//// [dummy.js]
export {};

Просмотреть файл

@ -1,52 +0,0 @@
//// [tests/cases/compiler/impliedNodeFormatEmit1.ts] ////
//// [a.ts]
export const _ = 0;
//// [b.mts]
export const _ = 0;
//// [c.cts]
export const _ = 0;
//// [d.js]
export const _ = 0;
//// [e.mjs]
export const _ = 0;
//// [f.mjs]
export const _ = 0;
//// [g.ts]
import {} from "./a";
import a = require("./a");
//// [h.mts]
import {} from "./a";
import a = require("./a");
//// [i.cts]
import {} from "./a";
import a = require("./a");
//// [dummy.ts]
export {};
//// [a.js]
export var _ = 0;
//// [b.mjs]
export var _ = 0;
//// [c.cjs]
export var _ = 0;
//// [d.js]
export var _ = 0;
//// [e.mjs]
export var _ = 0;
//// [f.mjs]
export var _ = 0;
//// [g.js]
//// [h.mjs]
//// [i.cjs]
//// [dummy.js]

Просмотреть файл

@ -1,39 +0,0 @@
error TS5071: Option '--resolveJsonModule' cannot be specified when 'module' is set to 'none', 'system', or 'umd'.
error TS5095: Option 'bundler' can only be used when 'module' is set to 'preserve' or to 'es2015' or later.
!!! error TS5071: Option '--resolveJsonModule' cannot be specified when 'module' is set to 'none', 'system', or 'umd'.
!!! error TS5095: Option 'bundler' can only be used when 'module' is set to 'preserve' or to 'es2015' or later.
==== /a.ts (0 errors) ====
export const _ = 0;
==== /b.mts (0 errors) ====
export const _ = 0;
==== /c.cts (0 errors) ====
export const _ = 0;
==== /d.js (0 errors) ====
export const _ = 0;
==== /e.mjs (0 errors) ====
export const _ = 0;
==== /f.mjs (0 errors) ====
export const _ = 0;
==== /g.ts (0 errors) ====
import {} from "./a";
import a = require("./a");
==== /h.mts (0 errors) ====
import {} from "./a";
import a = require("./a");
==== /i.cts (0 errors) ====
import {} from "./a";
import a = require("./a");
==== /dummy.ts (0 errors) ====
export {};

Просмотреть файл

@ -1,148 +0,0 @@
//// [tests/cases/compiler/impliedNodeFormatEmit1.ts] ////
//// [a.ts]
export const _ = 0;
//// [b.mts]
export const _ = 0;
//// [c.cts]
export const _ = 0;
//// [d.js]
export const _ = 0;
//// [e.mjs]
export const _ = 0;
//// [f.mjs]
export const _ = 0;
//// [g.ts]
import {} from "./a";
import a = require("./a");
//// [h.mts]
import {} from "./a";
import a = require("./a");
//// [i.cts]
import {} from "./a";
import a = require("./a");
//// [dummy.ts]
export {};
//// [a.js]
System.register([], function (exports_1, context_1) {
"use strict";
var _;
var __moduleName = context_1 && context_1.id;
return {
setters: [],
execute: function () {
exports_1("_", _ = 0);
}
};
});
//// [b.mjs]
System.register([], function (exports_1, context_1) {
"use strict";
var _;
var __moduleName = context_1 && context_1.id;
return {
setters: [],
execute: function () {
exports_1("_", _ = 0);
}
};
});
//// [c.cjs]
System.register([], function (exports_1, context_1) {
"use strict";
var _;
var __moduleName = context_1 && context_1.id;
return {
setters: [],
execute: function () {
exports_1("_", _ = 0);
}
};
});
//// [d.js]
System.register([], function (exports_1, context_1) {
"use strict";
var _;
var __moduleName = context_1 && context_1.id;
return {
setters: [],
execute: function () {
exports_1("_", _ = 0);
}
};
});
//// [e.mjs]
System.register([], function (exports_1, context_1) {
"use strict";
var _;
var __moduleName = context_1 && context_1.id;
return {
setters: [],
execute: function () {
exports_1("_", _ = 0);
}
};
});
//// [f.mjs]
System.register([], function (exports_1, context_1) {
"use strict";
var _;
var __moduleName = context_1 && context_1.id;
return {
setters: [],
execute: function () {
exports_1("_", _ = 0);
}
};
});
//// [g.js]
System.register([], function (exports_1, context_1) {
"use strict";
var __moduleName = context_1 && context_1.id;
return {
setters: [],
execute: function () {
}
};
});
//// [h.mjs]
System.register([], function (exports_1, context_1) {
"use strict";
var __moduleName = context_1 && context_1.id;
return {
setters: [],
execute: function () {
}
};
});
//// [i.cjs]
System.register([], function (exports_1, context_1) {
"use strict";
var __moduleName = context_1 && context_1.id;
return {
setters: [],
execute: function () {
}
};
});
//// [dummy.js]
System.register([], function (exports_1, context_1) {
"use strict";
var __moduleName = context_1 && context_1.id;
return {
setters: [],
execute: function () {
}
};
});

Просмотреть файл

@ -1,39 +0,0 @@
error TS5071: Option '--resolveJsonModule' cannot be specified when 'module' is set to 'none', 'system', or 'umd'.
error TS5095: Option 'bundler' can only be used when 'module' is set to 'preserve' or to 'es2015' or later.
!!! error TS5071: Option '--resolveJsonModule' cannot be specified when 'module' is set to 'none', 'system', or 'umd'.
!!! error TS5095: Option 'bundler' can only be used when 'module' is set to 'preserve' or to 'es2015' or later.
==== /a.ts (0 errors) ====
export const _ = 0;
==== /b.mts (0 errors) ====
export const _ = 0;
==== /c.cts (0 errors) ====
export const _ = 0;
==== /d.js (0 errors) ====
export const _ = 0;
==== /e.mjs (0 errors) ====
export const _ = 0;
==== /f.mjs (0 errors) ====
export const _ = 0;
==== /g.ts (0 errors) ====
import {} from "./a";
import a = require("./a");
==== /h.mts (0 errors) ====
import {} from "./a";
import a = require("./a");
==== /i.cts (0 errors) ====
import {} from "./a";
import a = require("./a");
==== /dummy.ts (0 errors) ====
export {};

Просмотреть файл

@ -1,178 +0,0 @@
//// [tests/cases/compiler/impliedNodeFormatEmit1.ts] ////
//// [a.ts]
export const _ = 0;
//// [b.mts]
export const _ = 0;
//// [c.cts]
export const _ = 0;
//// [d.js]
export const _ = 0;
//// [e.mjs]
export const _ = 0;
//// [f.mjs]
export const _ = 0;
//// [g.ts]
import {} from "./a";
import a = require("./a");
//// [h.mts]
import {} from "./a";
import a = require("./a");
//// [i.cts]
import {} from "./a";
import a = require("./a");
//// [dummy.ts]
export {};
//// [a.js]
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._ = void 0;
exports._ = 0;
});
//// [b.mjs]
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._ = void 0;
exports._ = 0;
});
//// [c.cjs]
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._ = void 0;
exports._ = 0;
});
//// [d.js]
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._ = void 0;
exports._ = 0;
});
//// [e.mjs]
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._ = void 0;
exports._ = 0;
});
//// [f.mjs]
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._ = void 0;
exports._ = 0;
});
//// [g.js]
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
});
//// [h.mjs]
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
});
//// [i.cjs]
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
});
//// [dummy.js]
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
});

Просмотреть файл

@ -1,40 +0,0 @@
error TS5095: Option 'bundler' can only be used when 'module' is set to 'preserve' or to 'es2015' or later.
!!! error TS5095: Option 'bundler' can only be used when 'module' is set to 'preserve' or to 'es2015' or later.
==== /package.json (0 errors) ====
{}
==== /a.ts (0 errors) ====
export const _ = 0;
==== /b.mts (0 errors) ====
export const _ = 0;
==== /c.cts (0 errors) ====
export const _ = 0;
==== /d.js (0 errors) ====
export const _ = 0;
==== /e.mjs (0 errors) ====
export const _ = 0;
==== /f.mjs (0 errors) ====
export const _ = 0;
==== /g.ts (0 errors) ====
import {} from "./a";
import a = require("./a");
==== /h.mts (0 errors) ====
import {} from "./a";
import a = require("./a");
==== /i.cts (0 errors) ====
import {} from "./a";
import a = require("./a");
==== /dummy.ts (0 errors) ====
export {};

Просмотреть файл

@ -1,81 +0,0 @@
//// [tests/cases/compiler/impliedNodeFormatEmit2.ts] ////
//// [package.json]
{}
//// [a.ts]
export const _ = 0;
//// [b.mts]
export const _ = 0;
//// [c.cts]
export const _ = 0;
//// [d.js]
export const _ = 0;
//// [e.mjs]
export const _ = 0;
//// [f.mjs]
export const _ = 0;
//// [g.ts]
import {} from "./a";
import a = require("./a");
//// [h.mts]
import {} from "./a";
import a = require("./a");
//// [i.cts]
import {} from "./a";
import a = require("./a");
//// [dummy.ts]
export {};
//// [a.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._ = void 0;
exports._ = 0;
//// [b.mjs]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._ = void 0;
exports._ = 0;
//// [c.cjs]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._ = void 0;
exports._ = 0;
//// [d.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._ = void 0;
exports._ = 0;
//// [e.mjs]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._ = void 0;
exports._ = 0;
//// [f.mjs]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._ = void 0;
exports._ = 0;
//// [g.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//// [h.mjs]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//// [i.cjs]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//// [dummy.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

Просмотреть файл

@ -1,47 +0,0 @@
/g.ts(2,1): error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.
/h.mts(2,1): error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.
/i.cts(2,1): error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.
==== /package.json (0 errors) ====
{}
==== /a.ts (0 errors) ====
export const _ = 0;
==== /b.mts (0 errors) ====
export const _ = 0;
==== /c.cts (0 errors) ====
export const _ = 0;
==== /d.js (0 errors) ====
export const _ = 0;
==== /e.mjs (0 errors) ====
export const _ = 0;
==== /f.mjs (0 errors) ====
export const _ = 0;
==== /g.ts (1 errors) ====
import {} from "./a";
import a = require("./a");
~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.
==== /h.mts (1 errors) ====
import {} from "./a";
import a = require("./a");
~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.
==== /i.cts (1 errors) ====
import {} from "./a";
import a = require("./a");
~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.
==== /dummy.ts (0 errors) ====
export {};

Просмотреть файл

@ -1,59 +0,0 @@
//// [tests/cases/compiler/impliedNodeFormatEmit2.ts] ////
//// [package.json]
{}
//// [a.ts]
export const _ = 0;
//// [b.mts]
export const _ = 0;
//// [c.cts]
export const _ = 0;
//// [d.js]
export const _ = 0;
//// [e.mjs]
export const _ = 0;
//// [f.mjs]
export const _ = 0;
//// [g.ts]
import {} from "./a";
import a = require("./a");
//// [h.mts]
import {} from "./a";
import a = require("./a");
//// [i.cts]
import {} from "./a";
import a = require("./a");
//// [dummy.ts]
export {};
//// [a.js]
export var _ = 0;
//// [b.mjs]
export var _ = 0;
//// [c.cjs]
export var _ = 0;
//// [d.js]
export var _ = 0;
//// [e.mjs]
export var _ = 0;
//// [f.mjs]
export var _ = 0;
//// [g.js]
export {};
//// [h.mjs]
export {};
//// [i.cjs]
export {};
//// [dummy.js]
export {};

Просмотреть файл

@ -1,55 +0,0 @@
//// [tests/cases/compiler/impliedNodeFormatEmit2.ts] ////
//// [package.json]
{}
//// [a.ts]
export const _ = 0;
//// [b.mts]
export const _ = 0;
//// [c.cts]
export const _ = 0;
//// [d.js]
export const _ = 0;
//// [e.mjs]
export const _ = 0;
//// [f.mjs]
export const _ = 0;
//// [g.ts]
import {} from "./a";
import a = require("./a");
//// [h.mts]
import {} from "./a";
import a = require("./a");
//// [i.cts]
import {} from "./a";
import a = require("./a");
//// [dummy.ts]
export {};
//// [a.js]
export var _ = 0;
//// [b.mjs]
export var _ = 0;
//// [c.cjs]
export var _ = 0;
//// [d.js]
export var _ = 0;
//// [e.mjs]
export var _ = 0;
//// [f.mjs]
export var _ = 0;
//// [g.js]
//// [h.mjs]
//// [i.cjs]
//// [dummy.js]

Просмотреть файл

@ -1,42 +0,0 @@
error TS5095: Option 'bundler' can only be used when 'module' is set to 'preserve' or to 'es2015' or later.
!!! error TS5095: Option 'bundler' can only be used when 'module' is set to 'preserve' or to 'es2015' or later.
==== /package.json (0 errors) ====
{
"type": "module"
}
==== /a.ts (0 errors) ====
export const _ = 0;
==== /b.mts (0 errors) ====
export const _ = 0;
==== /c.cts (0 errors) ====
export const _ = 0;
==== /d.js (0 errors) ====
export const _ = 0;
==== /e.mjs (0 errors) ====
export const _ = 0;
==== /f.mjs (0 errors) ====
export const _ = 0;
==== /g.ts (0 errors) ====
import {} from "./a";
import a = require("./a");
==== /h.mts (0 errors) ====
import {} from "./a";
import a = require("./a");
==== /i.cts (0 errors) ====
import {} from "./a";
import a = require("./a");
==== /dummy.ts (0 errors) ====
export {};

Просмотреть файл

@ -1,83 +0,0 @@
//// [tests/cases/compiler/impliedNodeFormatEmit3.ts] ////
//// [package.json]
{
"type": "module"
}
//// [a.ts]
export const _ = 0;
//// [b.mts]
export const _ = 0;
//// [c.cts]
export const _ = 0;
//// [d.js]
export const _ = 0;
//// [e.mjs]
export const _ = 0;
//// [f.mjs]
export const _ = 0;
//// [g.ts]
import {} from "./a";
import a = require("./a");
//// [h.mts]
import {} from "./a";
import a = require("./a");
//// [i.cts]
import {} from "./a";
import a = require("./a");
//// [dummy.ts]
export {};
//// [a.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._ = void 0;
exports._ = 0;
//// [b.mjs]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._ = void 0;
exports._ = 0;
//// [c.cjs]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._ = void 0;
exports._ = 0;
//// [d.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._ = void 0;
exports._ = 0;
//// [e.mjs]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._ = void 0;
exports._ = 0;
//// [f.mjs]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._ = void 0;
exports._ = 0;
//// [g.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//// [h.mjs]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//// [i.cjs]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//// [dummy.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

Просмотреть файл

@ -1,49 +0,0 @@
/g.ts(2,1): error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.
/h.mts(2,1): error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.
/i.cts(2,1): error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.
==== /package.json (0 errors) ====
{
"type": "module"
}
==== /a.ts (0 errors) ====
export const _ = 0;
==== /b.mts (0 errors) ====
export const _ = 0;
==== /c.cts (0 errors) ====
export const _ = 0;
==== /d.js (0 errors) ====
export const _ = 0;
==== /e.mjs (0 errors) ====
export const _ = 0;
==== /f.mjs (0 errors) ====
export const _ = 0;
==== /g.ts (1 errors) ====
import {} from "./a";
import a = require("./a");
~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.
==== /h.mts (1 errors) ====
import {} from "./a";
import a = require("./a");
~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.
==== /i.cts (1 errors) ====
import {} from "./a";
import a = require("./a");
~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.
==== /dummy.ts (0 errors) ====
export {};

Просмотреть файл

@ -1,61 +0,0 @@
//// [tests/cases/compiler/impliedNodeFormatEmit3.ts] ////
//// [package.json]
{
"type": "module"
}
//// [a.ts]
export const _ = 0;
//// [b.mts]
export const _ = 0;
//// [c.cts]
export const _ = 0;
//// [d.js]
export const _ = 0;
//// [e.mjs]
export const _ = 0;
//// [f.mjs]
export const _ = 0;
//// [g.ts]
import {} from "./a";
import a = require("./a");
//// [h.mts]
import {} from "./a";
import a = require("./a");
//// [i.cts]
import {} from "./a";
import a = require("./a");
//// [dummy.ts]
export {};
//// [a.js]
export var _ = 0;
//// [b.mjs]
export var _ = 0;
//// [c.cjs]
export var _ = 0;
//// [d.js]
export var _ = 0;
//// [e.mjs]
export var _ = 0;
//// [f.mjs]
export var _ = 0;
//// [g.js]
export {};
//// [h.mjs]
export {};
//// [i.cjs]
export {};
//// [dummy.js]
export {};

Просмотреть файл

@ -1,57 +0,0 @@
//// [tests/cases/compiler/impliedNodeFormatEmit3.ts] ////
//// [package.json]
{
"type": "module"
}
//// [a.ts]
export const _ = 0;
//// [b.mts]
export const _ = 0;
//// [c.cts]
export const _ = 0;
//// [d.js]
export const _ = 0;
//// [e.mjs]
export const _ = 0;
//// [f.mjs]
export const _ = 0;
//// [g.ts]
import {} from "./a";
import a = require("./a");
//// [h.mts]
import {} from "./a";
import a = require("./a");
//// [i.cts]
import {} from "./a";
import a = require("./a");
//// [dummy.ts]
export {};
//// [a.js]
export var _ = 0;
//// [b.mjs]
export var _ = 0;
//// [c.cjs]
export var _ = 0;
//// [d.js]
export var _ = 0;
//// [e.mjs]
export var _ = 0;
//// [f.mjs]
export var _ = 0;
//// [g.js]
//// [h.mjs]
//// [i.cjs]
//// [dummy.js]

Просмотреть файл

@ -1,42 +0,0 @@
error TS5095: Option 'bundler' can only be used when 'module' is set to 'preserve' or to 'es2015' or later.
!!! error TS5095: Option 'bundler' can only be used when 'module' is set to 'preserve' or to 'es2015' or later.
==== /package.json (0 errors) ====
{
"type": "commonjs"
}
==== /a.ts (0 errors) ====
export const _ = 0;
==== /b.mts (0 errors) ====
export const _ = 0;
==== /c.cts (0 errors) ====
export const _ = 0;
==== /d.js (0 errors) ====
export const _ = 0;
==== /e.mjs (0 errors) ====
export const _ = 0;
==== /f.mjs (0 errors) ====
export const _ = 0;
==== /g.ts (0 errors) ====
import {} from "./a";
import a = require("./a");
==== /h.mts (0 errors) ====
import {} from "./a";
import a = require("./a");
==== /i.cts (0 errors) ====
import {} from "./a";
import a = require("./a");
==== /dummy.ts (0 errors) ====
export {};

Просмотреть файл

@ -1,83 +0,0 @@
//// [tests/cases/compiler/impliedNodeFormatEmit4.ts] ////
//// [package.json]
{
"type": "commonjs"
}
//// [a.ts]
export const _ = 0;
//// [b.mts]
export const _ = 0;
//// [c.cts]
export const _ = 0;
//// [d.js]
export const _ = 0;
//// [e.mjs]
export const _ = 0;
//// [f.mjs]
export const _ = 0;
//// [g.ts]
import {} from "./a";
import a = require("./a");
//// [h.mts]
import {} from "./a";
import a = require("./a");
//// [i.cts]
import {} from "./a";
import a = require("./a");
//// [dummy.ts]
export {};
//// [a.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._ = void 0;
exports._ = 0;
//// [b.mjs]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._ = void 0;
exports._ = 0;
//// [c.cjs]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._ = void 0;
exports._ = 0;
//// [d.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._ = void 0;
exports._ = 0;
//// [e.mjs]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._ = void 0;
exports._ = 0;
//// [f.mjs]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports._ = void 0;
exports._ = 0;
//// [g.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//// [h.mjs]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//// [i.cjs]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//// [dummy.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

Просмотреть файл

@ -1,49 +0,0 @@
/g.ts(2,1): error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.
/h.mts(2,1): error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.
/i.cts(2,1): error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.
==== /package.json (0 errors) ====
{
"type": "commonjs"
}
==== /a.ts (0 errors) ====
export const _ = 0;
==== /b.mts (0 errors) ====
export const _ = 0;
==== /c.cts (0 errors) ====
export const _ = 0;
==== /d.js (0 errors) ====
export const _ = 0;
==== /e.mjs (0 errors) ====
export const _ = 0;
==== /f.mjs (0 errors) ====
export const _ = 0;
==== /g.ts (1 errors) ====
import {} from "./a";
import a = require("./a");
~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.
==== /h.mts (1 errors) ====
import {} from "./a";
import a = require("./a");
~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.
==== /i.cts (1 errors) ====
import {} from "./a";
import a = require("./a");
~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.
==== /dummy.ts (0 errors) ====
export {};

Просмотреть файл

@ -1,61 +0,0 @@
//// [tests/cases/compiler/impliedNodeFormatEmit4.ts] ////
//// [package.json]
{
"type": "commonjs"
}
//// [a.ts]
export const _ = 0;
//// [b.mts]
export const _ = 0;
//// [c.cts]
export const _ = 0;
//// [d.js]
export const _ = 0;
//// [e.mjs]
export const _ = 0;
//// [f.mjs]
export const _ = 0;
//// [g.ts]
import {} from "./a";
import a = require("./a");
//// [h.mts]
import {} from "./a";
import a = require("./a");
//// [i.cts]
import {} from "./a";
import a = require("./a");
//// [dummy.ts]
export {};
//// [a.js]
export var _ = 0;
//// [b.mjs]
export var _ = 0;
//// [c.cjs]
export var _ = 0;
//// [d.js]
export var _ = 0;
//// [e.mjs]
export var _ = 0;
//// [f.mjs]
export var _ = 0;
//// [g.js]
export {};
//// [h.mjs]
export {};
//// [i.cjs]
export {};
//// [dummy.js]
export {};

Просмотреть файл

@ -1,57 +0,0 @@
//// [tests/cases/compiler/impliedNodeFormatEmit4.ts] ////
//// [package.json]
{
"type": "commonjs"
}
//// [a.ts]
export const _ = 0;
//// [b.mts]
export const _ = 0;
//// [c.cts]
export const _ = 0;
//// [d.js]
export const _ = 0;
//// [e.mjs]
export const _ = 0;
//// [f.mjs]
export const _ = 0;
//// [g.ts]
import {} from "./a";
import a = require("./a");
//// [h.mts]
import {} from "./a";
import a = require("./a");
//// [i.cts]
import {} from "./a";
import a = require("./a");
//// [dummy.ts]
export {};
//// [a.js]
export var _ = 0;
//// [b.mjs]
export var _ = 0;
//// [c.cjs]
export var _ = 0;
//// [d.js]
export var _ = 0;
//// [e.mjs]
export var _ = 0;
//// [f.mjs]
export var _ = 0;
//// [g.js]
//// [h.mjs]
//// [i.cjs]
//// [dummy.js]

Просмотреть файл

@ -1,30 +0,0 @@
//// [tests/cases/compiler/impliedNodeFormatInterop1.ts] ////
//// [package.json]
{
"name": "highlight.js",
"type": "commonjs",
"types": "index.d.ts"
}
//// [index.d.ts]
declare module "highlight.js" {
export interface HighlightAPI {
highlight(code: string): string;
}
const hljs: HighlightAPI;
export default hljs;
}
//// [core.d.ts]
import hljs from "highlight.js";
export default hljs;
//// [index.ts]
import hljs from "highlight.js/lib/core";
hljs.highlight("code");
//// [index.js]
import hljs from "highlight.js/lib/core";
hljs.highlight("code");

Просмотреть файл

@ -1,37 +0,0 @@
//// [tests/cases/compiler/impliedNodeFormatInterop1.ts] ////
=== /node_modules/highlight.js/index.d.ts ===
declare module "highlight.js" {
>"highlight.js" : Symbol("highlight.js", Decl(index.d.ts, 0, 0))
export interface HighlightAPI {
>HighlightAPI : Symbol(HighlightAPI, Decl(index.d.ts, 0, 31))
highlight(code: string): string;
>highlight : Symbol(HighlightAPI.highlight, Decl(index.d.ts, 1, 33))
>code : Symbol(code, Decl(index.d.ts, 2, 14))
}
const hljs: HighlightAPI;
>hljs : Symbol(hljs, Decl(index.d.ts, 4, 7))
>HighlightAPI : Symbol(HighlightAPI, Decl(index.d.ts, 0, 31))
export default hljs;
>hljs : Symbol(hljs, Decl(index.d.ts, 4, 7))
}
=== /node_modules/highlight.js/lib/core.d.ts ===
import hljs from "highlight.js";
>hljs : Symbol(hljs, Decl(core.d.ts, 0, 6))
export default hljs;
>hljs : Symbol(hljs, Decl(core.d.ts, 0, 6))
=== /index.ts ===
import hljs from "highlight.js/lib/core";
>hljs : Symbol(hljs, Decl(index.ts, 0, 6))
hljs.highlight("code");
>hljs.highlight : Symbol(HighlightAPI.highlight, Decl(index.d.ts, 1, 33))
>hljs : Symbol(hljs, Decl(index.ts, 0, 6))
>highlight : Symbol(HighlightAPI.highlight, Decl(index.d.ts, 1, 33))

Просмотреть файл

@ -1,49 +0,0 @@
//// [tests/cases/compiler/impliedNodeFormatInterop1.ts] ////
=== /node_modules/highlight.js/index.d.ts ===
declare module "highlight.js" {
>"highlight.js" : typeof import("highlight.js")
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
export interface HighlightAPI {
highlight(code: string): string;
>highlight : (code: string) => string
> : ^ ^^ ^^^^^
>code : string
> : ^^^^^^
}
const hljs: HighlightAPI;
>hljs : HighlightAPI
> : ^^^^^^^^^^^^
export default hljs;
>hljs : HighlightAPI
> : ^^^^^^^^^^^^
}
=== /node_modules/highlight.js/lib/core.d.ts ===
import hljs from "highlight.js";
>hljs : import("highlight.js").HighlightAPI
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
export default hljs;
>hljs : import("highlight.js").HighlightAPI
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
=== /index.ts ===
import hljs from "highlight.js/lib/core";
>hljs : import("highlight.js").HighlightAPI
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
hljs.highlight("code");
>hljs.highlight("code") : string
> : ^^^^^^
>hljs.highlight : (code: string) => string
> : ^ ^^ ^^^^^
>hljs : import("highlight.js").HighlightAPI
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>highlight : (code: string) => string
> : ^ ^^ ^^^^^
>"code" : "code"
> : ^^^^^^

Просмотреть файл

@ -127,9 +127,6 @@
import g1 from "./g"; // { default: 0 }
const g2 = require("./g"); // { default: 0 }
==== /main4.cjs (0 errors) ====
exports.x = require("./g");
==== /dummy.ts (0 errors) ====
export {}; // Silly test harness

Просмотреть файл

@ -100,9 +100,6 @@ const f2 = require("./f.cjs"); // { default: 0 }
import g1 from "./g"; // { default: 0 }
const g2 = require("./g"); // { default: 0 }
//// [main4.cjs]
exports.x = require("./g");
//// [dummy.ts]
export {}; // Silly test harness
@ -188,8 +185,6 @@ import f1 from "./f.cjs"; // 0
const f2 = require("./f.cjs"); // { default: 0 }
import g1 from "./g"; // { default: 0 }
const g2 = require("./g"); // { default: 0 }
//// [main4.cjs]
exports.x = require("./g");
//// [dummy.js]
export {}; // Silly test harness
@ -222,7 +217,5 @@ export {};
export {};
//// [main3.d.cts]
export {};
//// [main4.d.cts]
export const x: typeof import("./g");
//// [dummy.d.ts]
export {};

Просмотреть файл

@ -256,14 +256,6 @@ const g2 = require("./g"); // { default: 0 }
>require : Symbol(require)
>"./g" : Symbol(g1, Decl(g.js, 0, 0))
=== /main4.cjs ===
exports.x = require("./g");
>exports.x : Symbol(x, Decl(main4.cjs, 0, 0))
>exports : Symbol(x, Decl(main4.cjs, 0, 0))
>x : Symbol(x, Decl(main4.cjs, 0, 0))
>require : Symbol(require)
>"./g" : Symbol("/g", Decl(g.js, 0, 0))
=== /dummy.ts ===
export {}; // Silly test harness

Просмотреть файл

@ -441,23 +441,6 @@ const g2 = require("./g"); // { default: 0 }
>"./g" : "./g"
> : ^^^^^
=== /main4.cjs ===
exports.x = require("./g");
>exports.x = require("./g") : typeof import("/g")
> : ^^^^^^^^^^^^^^^^^^^
>exports.x : typeof import("/g")
> : ^^^^^^^^^^^^^^^^^^^
>exports : typeof import("/main4")
> : ^^^^^^^^^^^^^^^^^^^^^^^
>x : typeof import("/g")
> : ^^^^^^^^^^^^^^^^^^^
>require("./g") : typeof import("/g")
> : ^^^^^^^^^^^^^^^^^^^
>require : any
> : ^^^
>"./g" : "./g"
> : ^^^^^
=== /dummy.ts ===
export {}; // Silly test harness

Просмотреть файл

@ -1,7 +1,7 @@
[
"======== Resolving module '@restart/hooks/useMergedRefs' from '/main.ts'. ========",
"Explicitly specified module resolution kind: 'Bundler'.",
"Resolving in CJS mode with conditions 'require', 'types'.",
"Resolving in CJS mode with conditions 'import', 'types'.",
"File '/package.json' does not exist.",
"Loading module '@restart/hooks/useMergedRefs' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration, JSON.",
"Searching all ancestor node_modules directories for preferred extensions: TypeScript, Declaration.",

Просмотреть файл

@ -157,8 +157,8 @@ export declare const e: typeof import("inner/mjs");
export declare const a: Promise<{
default: typeof import("./index.cjs");
}>;
export declare const b: Promise<typeof import("package/mjs", { with: { "resolution-mode": "import" } })>;
export declare const c: Promise<typeof import("package", { with: { "resolution-mode": "import" } })>;
export declare const b: Promise<typeof import("./index.mjs", { with: { "resolution-mode": "import" } })>;
export declare const c: Promise<typeof import("./index.js", { with: { "resolution-mode": "import" } })>;
export declare const f: Promise<{
default: typeof import("inner");
cjsMain: true;

Просмотреть файл

@ -15,4 +15,5 @@ import {x} from "foo";
//// [app.js]
export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

Просмотреть файл

@ -16,4 +16,5 @@ import {x} from "foo";
//// [app.mjs]
export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

Просмотреть файл

@ -1,3 +1,4 @@
error TS5095: Option 'bundler' can only be used when 'module' is set to 'preserve' or to 'es2015' or later.
error TS6504: File '/node_modules/bar/index.js' is a JavaScript file. Did you mean to enable the 'allowJs' option?
The file is in the program because:
Root file specified for compilation
@ -16,6 +17,7 @@ error TS6504: File '/node_modules/foo/index.mjs' is a JavaScript file. Did you m
There are types at '/node_modules/@types/bar/index.d.ts', but this result could not be resolved when respecting package.json "exports". The '@types/bar' library may need to update its package.json or typings.
!!! error TS5095: Option 'bundler' can only be used when 'module' is set to 'preserve' or to 'es2015' or later.
!!! error TS6504: File '/node_modules/bar/index.js' is a JavaScript file. Did you mean to enable the 'allowJs' option?
!!! error TS6504: The file is in the program because:
!!! error TS6504: Root file specified for compilation

Просмотреть файл

@ -383,7 +383,7 @@ Shape signatures in builder refreshed for::
//// [/home/src/projects/project/index.mjs]
"use strict";
export {};
Object.defineProperty(exports, "__esModule", { value: true });
//// [/home/src/projects/project/tsconfig.tsbuildinfo]

Просмотреть файл

@ -1,95 +0,0 @@
currentDirectory:: / useCaseSensitiveFileNames: false
Input::
//// [/app/src/index.ts]
import local from "./local"; // Error
import esm from "esm-package"; // Error
import referencedSource from "../../lib/src/a"; // Error
import referencedDeclaration from "../../lib/dist/a"; // Error
import ambiguous from "ambiguous-package"; // Ok
//// [/app/src/local.ts]
export const local = 0;
//// [/app/tsconfig.json]
{
"compilerOptions": {
"module": "esnext",
"moduleResolution": "bundler",
"rootDir": "src",
"outDir": "dist"
},
"include": [
"src"
],
"references": [
{
"path": "../lib"
}
]
}
//// [/lib/dist/a.d.ts]
export declare const a = 0;
//// [/lib/lib.d.ts]
/// <reference no-default-lib="true"/>
interface Boolean {}
interface Function {}
interface CallableFunction {}
interface NewableFunction {}
interface IArguments {}
interface Number { toExponential: any; }
interface Object {}
interface RegExp {}
interface String { charAt: any; }
interface Array<T> { length: number; [n: number]: T; }
interface ReadonlyArray<T> {}
declare const console: { log(msg: any): void; };
//// [/lib/src/a.ts]
export const a = 0;
//// [/lib/tsconfig.json]
{
"compilerOptions": {
"composite": true,
"declaration": true,
"rootDir": "src",
"outDir": "dist",
"module": "esnext",
"moduleResolution": "bundler"
},
"include": [
"src"
]
}
//// [/node_modules/ambiguous-package/index.d.ts]
export declare const ambiguous: number;
//// [/node_modules/ambiguous-package/package.json]
{ "name": "ambiguous-package" }
//// [/node_modules/esm-package/index.d.ts]
export declare const esm: number;
//// [/node_modules/esm-package/package.json]
{ "name": "esm-package", "type": "module" }
Output::
/lib/tsc --p app --pretty false
app/src/index.ts(2,28): error TS2613: Module '"/app/src/local"' has no default export. Did you mean to use 'import { local } from "/app/src/local"' instead?
exitCode:: ExitStatus.DiagnosticsPresent_OutputsGenerated
//// [/app/dist/index.js]
export {};
//// [/app/dist/local.js]
export var local = 0;

Просмотреть файл

@ -111,8 +111,10 @@ File '/package.json' does not exist according to earlier cached lookups.
node_modules/@types/yargs/index.d.ts
Imported via "yargs" from file 'src/bin.ts' with packageId 'yargs/index.d.ts@17.0.12'
Entry point for implicit type library 'yargs' with packageId 'yargs/index.d.ts@17.0.12'
File is CommonJS module because 'node_modules/@types/yargs/package.json' does not have field "type"
src/bin.ts
Matched by default include pattern '**/*'
File is CommonJS module because 'package.json' was not found
[HH:MM:SS AM] Found 1 error. Watching for file changes.

Просмотреть файл

@ -375,7 +375,7 @@ Elapsed:: *ms DirectoryWatcher:: Triggered with /home/src/projects/project/tscon
//// [/home/src/projects/project/index.mjs]
"use strict";
export {};
Object.defineProperty(exports, "__esModule", { value: true });
//// [/home/src/projects/project/tsconfig.tsbuildinfo]

Просмотреть файл

@ -80,9 +80,12 @@ File '/package.json' does not exist.
//// [/user/username/projects/myproject/dist/index.js]
import * as me from "@this/package";
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.thing = thing;
var me = require("@this/package");
me.thing();
export function thing() { }
function thing() { }
//// [/user/username/projects/myproject/types/index.d.ts]
@ -90,7 +93,10 @@ export declare function thing(): void;
//// [/user/username/projects/myproject/dist/index2.js]
export function thing() { }
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.thing = thing;
function thing() { }
//// [/user/username/projects/myproject/types/index2.d.ts]

Просмотреть файл

@ -375,7 +375,7 @@ Info seq [hh:mm:ss:mss] getCompletionData: Is inside comment: *
Info seq [hh:mm:ss:mss] getCompletionData: Get previous token: *
Info seq [hh:mm:ss:mss] getExportInfoMap: cache miss or empty; calculating new results
Info seq [hh:mm:ss:mss] getExportInfoMap: done in * ms
Info seq [hh:mm:ss:mss] collectAutoImports: resolved 0 module specifiers, plus 0 ambient and 4 from cache
Info seq [hh:mm:ss:mss] collectAutoImports: resolved 0 module specifiers, plus 0 ambient and 3 from cache
Info seq [hh:mm:ss:mss] collectAutoImports: response is incomplete
Info seq [hh:mm:ss:mss] collectAutoImports: *
Info seq [hh:mm:ss:mss] getCompletionData: Semantic work: *
@ -1048,19 +1048,6 @@ Info seq [hh:mm:ss:mss] response:
"fileName": "/third_party/marked/src/defaults.js"
}
},
{
"name": "defaults",
"kind": "property",
"kindModifiers": "",
"sortText": "16",
"hasAction": true,
"source": "/third_party/marked/src/defaults",
"data": {
"exportName": "export=",
"exportMapKey": "8 * defaults ",
"fileName": "/third_party/marked/src/defaults.js"
}
},
{
"name": "defaults",
"kind": "alias",
@ -1265,7 +1252,7 @@ Info seq [hh:mm:ss:mss] getCompletionData: Get current token: *
Info seq [hh:mm:ss:mss] getCompletionData: Is inside comment: *
Info seq [hh:mm:ss:mss] getCompletionData: Get previous token: *
Info seq [hh:mm:ss:mss] getExportInfoMap: cache hit
Info seq [hh:mm:ss:mss] collectAutoImports: resolved 0 module specifiers, plus 0 ambient and 4 from cache
Info seq [hh:mm:ss:mss] collectAutoImports: resolved 0 module specifiers, plus 0 ambient and 3 from cache
Info seq [hh:mm:ss:mss] collectAutoImports: response is incomplete
Info seq [hh:mm:ss:mss] collectAutoImports: *
Info seq [hh:mm:ss:mss] getCompletionData: Semantic work: *
@ -1951,19 +1938,6 @@ Info seq [hh:mm:ss:mss] response:
"fileName": "/third_party/marked/src/defaults.js"
}
},
{
"name": "defaults",
"kind": "property",
"kindModifiers": "",
"sortText": "16",
"hasAction": true,
"source": "/third_party/marked/src/defaults",
"data": {
"exportName": "export=",
"exportMapKey": "8 * defaults ",
"fileName": "/third_party/marked/src/defaults.js"
}
},
{
"name": "defaults",
"kind": "alias",

Просмотреть файл

@ -394,8 +394,10 @@ Info seq [hh:mm:ss:mss] Files (4)
Default library for target 'es5'
node_modules/foo2/index.d.ts
Imported via "foo2" from file 'index.mts' with packageId 'foo2/index.d.ts@1.0.0'
File is CommonJS module because 'node_modules/foo2/package.json' does not have field "type"
node_modules/@types/bar2/index.d.ts
Imported via "bar2" from file 'index.mts' with packageId '@types/bar2/index.d.ts@1.0.0'
File is CommonJS module because 'node_modules/@types/bar2/package.json' does not have field "type"
index.mts
Part of 'files' list in tsconfig.json
@ -2172,10 +2174,13 @@ Info seq [hh:mm:ss:mss] Files (5)
Default library for target 'es5'
node_modules/@types/bar/index.d.ts
Imported via "bar" from file 'index.mts' with packageId '@types/bar/index.d.ts@1.0.0'
File is CommonJS module because 'node_modules/@types/bar/package.json' does not have field "type"
node_modules/foo2/index.d.ts
Imported via "foo2" from file 'index.mts' with packageId 'foo2/index.d.ts@1.0.0'
File is CommonJS module because 'node_modules/foo2/package.json' does not have field "type"
node_modules/@types/bar2/index.d.ts
Imported via "bar2" from file 'index.mts' with packageId '@types/bar2/index.d.ts@1.0.0'
File is CommonJS module because 'node_modules/@types/bar2/package.json' does not have field "type"
index.mts
Part of 'files' list in tsconfig.json
@ -2496,12 +2501,16 @@ Info seq [hh:mm:ss:mss] Files (6)
Default library for target 'es5'
node_modules/foo/index.d.ts
Imported via "foo" from file 'index.mts' with packageId 'foo/index.d.ts@1.0.0'
File is CommonJS module because 'node_modules/foo/package.json' does not have field "type"
node_modules/@types/bar/index.d.ts
Imported via "bar" from file 'index.mts' with packageId '@types/bar/index.d.ts@1.0.0'
File is CommonJS module because 'node_modules/@types/bar/package.json' does not have field "type"
node_modules/foo2/index.d.ts
Imported via "foo2" from file 'index.mts' with packageId 'foo2/index.d.ts@1.0.0'
File is CommonJS module because 'node_modules/foo2/package.json' does not have field "type"
node_modules/@types/bar2/index.d.ts
Imported via "bar2" from file 'index.mts' with packageId '@types/bar2/index.d.ts@1.0.0'
File is CommonJS module because 'node_modules/@types/bar2/package.json' does not have field "type"
index.mts
Part of 'files' list in tsconfig.json
@ -2890,10 +2899,13 @@ Info seq [hh:mm:ss:mss] Files (5)
Default library for target 'es5'
node_modules/foo/index.d.ts
Imported via "foo" from file 'index.mts' with packageId 'foo/index.d.ts@1.0.0'
File is CommonJS module because 'node_modules/foo/package.json' does not have field "type"
node_modules/@types/bar/index.d.ts
Imported via "bar" from file 'index.mts' with packageId '@types/bar/index.d.ts@1.0.0'
File is CommonJS module because 'node_modules/@types/bar/package.json' does not have field "type"
node_modules/foo2/index.d.ts
Imported via "foo2" from file 'index.mts' with packageId 'foo2/index.d.ts@1.0.0'
File is CommonJS module because 'node_modules/foo2/package.json' does not have field "type"
index.mts
Part of 'files' list in tsconfig.json
@ -3270,8 +3282,10 @@ Info seq [hh:mm:ss:mss] Files (4)
Default library for target 'es5'
node_modules/foo/index.d.ts
Imported via "foo" from file 'index.mts' with packageId 'foo/index.d.ts@1.0.0'
File is CommonJS module because 'node_modules/foo/package.json' does not have field "type"
node_modules/@types/bar/index.d.ts
Imported via "bar" from file 'index.mts' with packageId '@types/bar/index.d.ts@1.0.0'
File is CommonJS module because 'node_modules/@types/bar/package.json' does not have field "type"
index.mts
Part of 'files' list in tsconfig.json

Просмотреть файл

@ -1,18 +0,0 @@
// @target: esnext
// @module: preserve, esnext
// @moduleResolution: bundler
// @Filename: /node_modules/mdast-util-to-string/package.json
{ "type": "module" }
// @Filename: /node_modules/mdast-util-to-string/index.d.ts
export function toString(): string;
// @Filename: /index.ts
import mdast, { toString } from 'mdast-util-to-string';
mdast;
mdast.toString();
const mdast2 = await import('mdast-util-to-string');
mdast2.toString();
mdast2.default;

Просмотреть файл

@ -1,39 +0,0 @@
// @allowJs: true
// @checkJs: true
// @outDir: dist
// @module: esnext, commonjs, amd, system, umd, preserve
// @moduleResolution: bundler
// @noTypesAndSymbols: true
// @Filename: /a.ts
export const _ = 0;
// @Filename: /b.mts
export const _ = 0;
// @Filename: /c.cts
export const _ = 0;
// @Filename: /d.js
export const _ = 0;
// @Filename: /e.mjs
export const _ = 0;
// @Filename: /f.mjs
export const _ = 0;
// @Filename: /g.ts
import {} from "./a";
import a = require("./a");
// @Filename: /h.mts
import {} from "./a";
import a = require("./a");
// @Filename: /i.cts
import {} from "./a";
import a = require("./a");
// @Filename: /dummy.ts
export {};

Просмотреть файл

@ -1,42 +0,0 @@
// @allowJs: true
// @checkJs: true
// @outDir: dist
// @module: esnext, commonjs, preserve
// @moduleResolution: bundler
// @noTypesAndSymbols: true
// @Filename: /package.json
{}
// @Filename: /a.ts
export const _ = 0;
// @Filename: /b.mts
export const _ = 0;
// @Filename: /c.cts
export const _ = 0;
// @Filename: /d.js
export const _ = 0;
// @Filename: /e.mjs
export const _ = 0;
// @Filename: /f.mjs
export const _ = 0;
// @Filename: /g.ts
import {} from "./a";
import a = require("./a");
// @Filename: /h.mts
import {} from "./a";
import a = require("./a");
// @Filename: /i.cts
import {} from "./a";
import a = require("./a");
// @Filename: /dummy.ts
export {};

Просмотреть файл

@ -1,44 +0,0 @@
// @allowJs: true
// @checkJs: true
// @outDir: dist
// @module: esnext, commonjs, preserve
// @moduleResolution: bundler
// @noTypesAndSymbols: true
// @Filename: /package.json
{
"type": "module"
}
// @Filename: /a.ts
export const _ = 0;
// @Filename: /b.mts
export const _ = 0;
// @Filename: /c.cts
export const _ = 0;
// @Filename: /d.js
export const _ = 0;
// @Filename: /e.mjs
export const _ = 0;
// @Filename: /f.mjs
export const _ = 0;
// @Filename: /g.ts
import {} from "./a";
import a = require("./a");
// @Filename: /h.mts
import {} from "./a";
import a = require("./a");
// @Filename: /i.cts
import {} from "./a";
import a = require("./a");
// @Filename: /dummy.ts
export {};

Просмотреть файл

@ -1,44 +0,0 @@
// @allowJs: true
// @checkJs: true
// @outDir: dist
// @module: esnext, commonjs, preserve
// @moduleResolution: bundler
// @noTypesAndSymbols: true
// @Filename: /package.json
{
"type": "commonjs"
}
// @Filename: /a.ts
export const _ = 0;
// @Filename: /b.mts
export const _ = 0;
// @Filename: /c.cts
export const _ = 0;
// @Filename: /d.js
export const _ = 0;
// @Filename: /e.mjs
export const _ = 0;
// @Filename: /f.mjs
export const _ = 0;
// @Filename: /g.ts
import {} from "./a";
import a = require("./a");
// @Filename: /h.mts
import {} from "./a";
import a = require("./a");
// @Filename: /i.cts
import {} from "./a";
import a = require("./a");
// @Filename: /dummy.ts
export {};

Просмотреть файл

@ -1,27 +0,0 @@
// @module: es2020
// @moduleResolution: node10
// @esModuleInterop: true
// @Filename: /node_modules/highlight.js/package.json
{
"name": "highlight.js",
"type": "commonjs",
"types": "index.d.ts"
}
// @Filename: /node_modules/highlight.js/index.d.ts
declare module "highlight.js" {
export interface HighlightAPI {
highlight(code: string): string;
}
const hljs: HighlightAPI;
export default hljs;
}
// @Filename: /node_modules/highlight.js/lib/core.d.ts
import hljs from "highlight.js";
export default hljs;
// @Filename: /index.ts
import hljs from "highlight.js/lib/core";
hljs.highlight("code");

Просмотреть файл

@ -106,8 +106,5 @@ const f2 = require("./f.cjs"); // { default: 0 }
import g1 from "./g"; // { default: 0 }
const g2 = require("./g"); // { default: 0 }
// @Filename: /main4.cjs
exports.x = require("./g");
// @Filename: /dummy.ts
export {}; // Silly test harness

Просмотреть файл

@ -1,4 +1,3 @@
// @module: esnext
// @moduleResolution: node16,nodenext,bundler
// @traceResolution: true
// @allowJs: true

Просмотреть файл

@ -1,4 +1,3 @@
// @module: preserve
// @moduleResolution: bundler
// @customConditions: webpack, browser
// @resolvePackageJsonExports: true, false

Просмотреть файл

@ -1,4 +1,3 @@
// @module: preserve
// @moduleResolution: bundler,node16
// @strict: true
// @noTypesAndSymbols: true

Просмотреть файл

@ -1,39 +0,0 @@
/// <reference path="fourslash.ts" />
// @module: preserve
// @checkJs: true
// @Filename: /node_modules/example/package.json
//// { "name": "example", "version": "1.0.0", "main": "dist/index.js" }
// @Filename: /node_modules/example/dist/nested/module.d.ts
//// declare const defaultExport: () => void;
//// declare const namedExport: () => void;
////
//// export default defaultExport;
//// export { namedExport };
// @Filename: /node_modules/example/dist/index.d.ts
//// export { default, namedExport } from "./nested/module";
// @Filename: /index.mjs
//// import { namedExport } from "example";
//// defaultExp/**/
verify.completions({
marker: "",
exact: completion.globalsInJsPlus([
"namedExport",
{
name: "defaultExport",
source: "example",
sourceDisplay: "example",
hasAction: true,
sortText: completion.SortText.AutoImportSuggestions
},
]),
preferences: {
includeCompletionsForModuleExports: true,
allowIncompleteCompletions: true,
},
});