Skip to content

Commit

Permalink
Rename function
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbranch committed Mar 27, 2024
1 parent d6bf0fe commit 2d4e834
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 21 deletions.
10 changes: 5 additions & 5 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ import {
getIdentifierGeneratedImportReference,
getIdentifierTypeArguments,
getImmediatelyInvokedFunctionExpression,
getImpliedNodeFormatForEmit,
getInitializerOfBinaryExpression,
getInterfaceBaseTypeNodes,
getInvokedExpression,
Expand Down Expand Up @@ -413,7 +414,6 @@ import {
IdentifierTypePredicate,
idText,
IfStatement,
impliedNodeFormatForEmit,
ImportAttribute,
ImportAttributes,
ImportCall,
Expand Down Expand Up @@ -4101,7 +4101,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
function canHaveSyntheticDefault(file: SourceFile | undefined, moduleSymbol: Symbol, dontResolveAlias: boolean, usage: Expression) {
const usageMode = file && getEmitSyntaxForModuleSpecifierExpression(usage);
if (file && usageMode !== undefined) {
const targetMode = impliedNodeFormatForEmit(file, compilerOptions);
const targetMode = getImpliedNodeFormatForEmit(file, compilerOptions);
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;
Expand Down Expand Up @@ -5334,7 +5334,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}

const targetFile = moduleSymbol?.declarations?.find(isSourceFile);
const isEsmCjsRef = targetFile && isESMFormatImportImportingCommonjsFormatFile(getEmitSyntaxForModuleSpecifierExpression(reference), impliedNodeFormatForEmit(targetFile, compilerOptions));
const isEsmCjsRef = targetFile && isESMFormatImportImportingCommonjsFormatFile(getEmitSyntaxForModuleSpecifierExpression(reference), getImpliedNodeFormatForEmit(targetFile, compilerOptions));
if (getESModuleInterop(compilerOptions) || isEsmCjsRef) {
let sigs = getSignaturesOfStructuredType(type, SignatureKind.Call);
if (!sigs || !sigs.length) {
Expand Down Expand Up @@ -46777,8 +46777,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
if (
moduleKind >= ModuleKind.ES2015 &&
moduleKind !== ModuleKind.Preserve &&
((node.flags & NodeFlags.Ambient && impliedNodeFormatForEmit(getSourceFileOfNode(node), compilerOptions) === ModuleKind.ESNext) ||
(!(node.flags & NodeFlags.Ambient) && impliedNodeFormatForEmit(getSourceFileOfNode(node), compilerOptions) !== ModuleKind.CommonJS))
((node.flags & NodeFlags.Ambient && getImpliedNodeFormatForEmit(getSourceFileOfNode(node), compilerOptions) === ModuleKind.ESNext) ||
(!(node.flags & NodeFlags.Ambient) && getImpliedNodeFormatForEmit(getSourceFileOfNode(node), compilerOptions) !== 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);
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/factory/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import {
getESModuleInterop,
getExternalModuleName,
getExternalModuleNameFromPath,
getImpliedNodeFormatForEmit,
getJSDocType,
getJSDocTypeTag,
getModifiers,
Expand All @@ -72,7 +73,6 @@ import {
HasIllegalTypeParameters,
Identifier,
idText,
impliedNodeFormatForEmit,
ImportCall,
ImportDeclaration,
ImportEqualsDeclaration,
Expand Down Expand Up @@ -714,7 +714,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) || impliedNodeFormatForEmit(sourceFile, compilerOptions) === ModuleKind.ESNext) {
if ((moduleKind >= ModuleKind.ES2015 && moduleKind <= ModuleKind.ESNext) || getImpliedNodeFormatForEmit(sourceFile, compilerOptions) === ModuleKind.ESNext) {
// use named imports
const helpers = getEmitHelpers(sourceFile);
if (helpers) {
Expand Down
8 changes: 4 additions & 4 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8575,7 +8575,7 @@ function isFileForcedToBeModuleByFormat(file: SourceFile, options: CompilerOptio
// that aren't esm-mode (meaning not in a `type: module` scope).
//
// TODO: extension check never considered compilerOptions; should impliedNodeFormat?
return (impliedNodeFormatForEmit(file, options) === ModuleKind.ESNext || (fileExtensionIsOneOf(file.fileName, [Extension.Cjs, Extension.Cts, Extension.Mjs, Extension.Mts]))) && !file.isDeclarationFile ? true : undefined;
return (getImpliedNodeFormatForEmit(file, options) === ModuleKind.ESNext || (fileExtensionIsOneOf(file.fileName, [Extension.Cjs, Extension.Cts, Extension.Mjs, Extension.Mts]))) && !file.isDeclarationFile ? true : undefined;
}

/** @internal */
Expand Down Expand Up @@ -8626,11 +8626,11 @@ export function importSyntaxAffectsModuleResolution(options: CompilerOptions) {
* `program.getModeForUsageLocation` should be used instead.
*/
export function getDefaultResolutionModeForFile(sourceFile: Pick<SourceFile, "fileName" | "impliedNodeFormat" | "packageJsonScope">, options: CompilerOptions): ResolutionMode {
return importSyntaxAffectsModuleResolution(options) ? impliedNodeFormatForEmit(sourceFile, options) : undefined;
return importSyntaxAffectsModuleResolution(options) ? getImpliedNodeFormatForEmit(sourceFile, options) : undefined;
}

/** @internal */
export function impliedNodeFormatForEmit(sourceFile: Pick<SourceFile, "fileName" | "impliedNodeFormat" | "packageJsonScope">, options: CompilerOptions): ResolutionMode {
export function getImpliedNodeFormatForEmit(sourceFile: Pick<SourceFile, "fileName" | "impliedNodeFormat" | "packageJsonScope">, options: CompilerOptions): ResolutionMode {
const moduleKind = getEmitModuleKind(options);
if (ModuleKind.Node16 <= moduleKind && moduleKind <= ModuleKind.NodeNext) {
return sourceFile.impliedNodeFormat;
Expand Down Expand Up @@ -8663,7 +8663,7 @@ export function shouldTransformImportCall(sourceFile: Pick<SourceFile, "fileName

/** @internal */
export function getEmitModuleFormatOfFile(sourceFile: Pick<SourceFile, "fileName" | "impliedNodeFormat" | "packageJsonScope">, options: CompilerOptions): ModuleKind {
return impliedNodeFormatForEmit(sourceFile, options) ?? getEmitModuleKind(options);
return getImpliedNodeFormatForEmit(sourceFile, options) ?? getEmitModuleKind(options);
}

type CompilerOptionKeys = keyof { [K in keyof CompilerOptions as string extends K ? never : K]: any; };
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import {
getDefaultLibFileName,
getDirectoryPath,
getEmitScriptTarget,
getImpliedNodeFormatForEmit,
getLineAndCharacterOfPosition,
getNewLineCharacter,
getNormalizedAbsolutePath,
Expand All @@ -66,7 +67,6 @@ import {
getRelativePathFromDirectory,
getWatchFactory,
HasCurrentDirectory,
impliedNodeFormatForEmit,
isExternalOrCommonJsModule,
isLineBreak,
isReferencedFile,
Expand Down Expand Up @@ -379,7 +379,7 @@ export function explainIfFileIsRedirectAndImpliedFormat(
));
}
if (isExternalOrCommonJsModule(file)) {
switch (impliedNodeFormatForEmit(file, options)) {
switch (getImpliedNodeFormatForEmit(file, options)) {
case ModuleKind.ESNext:
if (file.packageJsonScope) {
(result ??= []).push(chainDiagnosticMessages(
Expand Down
8 changes: 4 additions & 4 deletions src/services/codefixes/importFixes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
getEmitModuleResolutionKind,
getEmitScriptTarget,
getExportInfoMap,
getImpliedNodeFormatForEmit,
getMeaningFromDeclaration,
getMeaningFromLocation,
getNameForExportedSymbol,
Expand All @@ -58,7 +59,6 @@ import {
getUniqueSymbolId,
hostGetCanonicalFileName,
Identifier,
impliedNodeFormatForEmit,
ImportClause,
ImportEqualsDeclaration,
importFromModuleSpecifier,
Expand Down Expand Up @@ -855,8 +855,8 @@ function shouldUseRequire(sourceFile: SourceFile, program: Program): boolean {
// 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 (impliedNodeFormatForEmit(sourceFile, compilerOptions) === ModuleKind.CommonJS) return true;
if (impliedNodeFormatForEmit(sourceFile, compilerOptions) === ModuleKind.ESNext) return false;
if (getImpliedNodeFormatForEmit(sourceFile, compilerOptions) === ModuleKind.CommonJS) return true;
if (getImpliedNodeFormatForEmit(sourceFile, compilerOptions) === 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()) {
Expand Down Expand Up @@ -1166,7 +1166,7 @@ function getUmdImportKind(importingFile: SourceFile, compilerOptions: CompilerOp
return ImportKind.Namespace;
case ModuleKind.Node16:
case ModuleKind.NodeNext:
return impliedNodeFormatForEmit(importingFile, compilerOptions) === ModuleKind.ESNext ? ImportKind.Namespace : ImportKind.CommonJS;
return getImpliedNodeFormatForEmit(importingFile, compilerOptions) === ModuleKind.ESNext ? ImportKind.Namespace : ImportKind.CommonJS;
default:
return Debug.assertNever(moduleKind, `Unexpected moduleKind ${moduleKind}`);
}
Expand Down
4 changes: 2 additions & 2 deletions src/services/suggestionDiagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import {
getAllowSyntheticDefaultImports,
getAssignmentDeclarationKind,
getFunctionFlags,
getImpliedNodeFormatForEmit,
hasInitializer,
hasPropertyAccessExpressionWithName,
Identifier,
impliedNodeFormatForEmit,
importFromModuleSpecifier,
isAsyncFunction,
isBinaryExpression,
Expand Down Expand Up @@ -67,7 +67,7 @@ export function computeSuggestionDiagnostics(sourceFile: SourceFile, program: Pr
program.getSemanticDiagnostics(sourceFile, cancellationToken);
const diags: DiagnosticWithLocation[] = [];
const checker = program.getTypeChecker();
const isCommonJSFile = impliedNodeFormatForEmit(sourceFile, program.getCompilerOptions()) === ModuleKind.CommonJS || fileExtensionIsOneOf(sourceFile.fileName, [Extension.Cts, Extension.Cjs]);
const isCommonJSFile = getImpliedNodeFormatForEmit(sourceFile, program.getCompilerOptions()) === ModuleKind.CommonJS || fileExtensionIsOneOf(sourceFile.fileName, [Extension.Cts, Extension.Cjs]);

if (
!isCommonJSFile &&
Expand Down
4 changes: 2 additions & 2 deletions src/services/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ import {
getEmitModuleKind,
getEmitScriptTarget,
getExternalModuleImportEqualsDeclarationExpression,
getImpliedNodeFormatForEmit,
getImpliedNodeFormatForFile,
getIndentString,
getJSDocEnumTag,
Expand Down Expand Up @@ -124,7 +125,6 @@ import {
identity,
idText,
IfStatement,
impliedNodeFormatForEmit,
ImportClause,
ImportDeclaration,
ImportSpecifier,
Expand Down Expand Up @@ -4252,7 +4252,7 @@ export function fileShouldUseJavaScriptRequire(file: SourceFile | string, progra
fileName: file,
impliedNodeFormat: getImpliedNodeFormatForFile(toPath(file, host.getCurrentDirectory(), hostGetCanonicalFileName(host)), program.getPackageJsonInfoCache?.(), host, compilerOptions),
} : file;
const impliedNodeFormat = impliedNodeFormatForEmit(sourceFileLike, compilerOptions);
const impliedNodeFormat = getImpliedNodeFormatForEmit(sourceFileLike, compilerOptions);

if (impliedNodeFormat === ModuleKind.ESNext) {
return false;
Expand Down

0 comments on commit 2d4e834

Please sign in to comment.