Skip to content

Commit 586b0d5

Browse files
authored
moduleResolution: node12 support (#45884)
* Initial support for module: node12 * Add allowJs and declaration emit enabled tests * Fix typos * cts, mts, cjs, mjs, etc extension support * Fix watch of files whose intepretation changes due to a package.json update * Minor PR feedback * Adjust error message * Initial import/export/self-name support * Accept new error codes * TypesVersions support in export/import map conditions * Fix import suggestion and autoimport default extensions under new resolution modes * Add tests for import maps non-relative name lookup feature * Fix isDeclarationFileName for .d.mts and .d.cts * Preserve new extensions when generating module specifiers * Fix spurious implict any suggestion caused by file ordering bug and optimize import name format detection by relying on parents being set * Fix a bunch of incremental bugs that dont repro under fourslash for some reason * Accept updated baseline * Always include extensions on completions for cjs/mjs style imports * String completion relative import suggestions respect the mode of the import when choosing if they provide extensions * Style feedback * Change diagnostic case
1 parent 12003e5 commit 586b0d5

File tree

569 files changed

+38872
-901
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

569 files changed

+38872
-901
lines changed

Diff for: src/compiler/binder.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2374,7 +2374,7 @@ namespace ts {
23742374

23752375
function checkStrictModeLabeledStatement(node: LabeledStatement) {
23762376
// Grammar checking for labeledStatement
2377-
if (inStrictMode && options.target! >= ScriptTarget.ES2015) {
2377+
if (inStrictMode && getEmitScriptTarget(options) >= ScriptTarget.ES2015) {
23782378
if (isDeclarationStatement(node.statement) || isVariableStatement(node.statement)) {
23792379
errorOnFirstToken(node.label, Diagnostics.A_label_is_not_allowed_here);
23802380
}

Diff for: src/compiler/builder.ts

+13-5
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,14 @@ namespace ts {
258258
Debug.assert(!state.seenAffectedFiles || !state.seenAffectedFiles.size);
259259
state.seenAffectedFiles = state.seenAffectedFiles || new Set();
260260
}
261+
if (useOldState) {
262+
// Any time the interpretation of a source file changes, mark it as changed
263+
forEachEntry(oldState!.fileInfos, (info, sourceFilePath) => {
264+
if (state.fileInfos.has(sourceFilePath) && state.fileInfos.get(sourceFilePath)!.impliedFormat !== info.impliedFormat) {
265+
state.changedFilesSet.add(sourceFilePath);
266+
}
267+
});
268+
}
261269

262270
state.buildInfoEmitPending = !!state.changedFilesSet.size;
263271
return state;
@@ -744,13 +752,13 @@ namespace ts {
744752
const actualSignature = signature ?? value.signature;
745753
return value.version === actualSignature ?
746754
value.affectsGlobalScope ?
747-
{ version: value.version, signature: undefined, affectsGlobalScope: true } :
755+
{ version: value.version, signature: undefined, affectsGlobalScope: true, impliedFormat: value.impliedFormat } :
748756
value.version :
749757
actualSignature !== undefined ?
750758
signature === undefined ?
751759
value :
752-
{ version: value.version, signature, affectsGlobalScope: value.affectsGlobalScope } :
753-
{ version: value.version, signature: false, affectsGlobalScope: value.affectsGlobalScope };
760+
{ version: value.version, signature, affectsGlobalScope: value.affectsGlobalScope, impliedFormat: value.impliedFormat } :
761+
{ version: value.version, signature: false, affectsGlobalScope: value.affectsGlobalScope, impliedFormat: value.impliedFormat };
754762
});
755763

756764
let referencedMap: ProgramBuildInfoReferencedMap | undefined;
@@ -1243,10 +1251,10 @@ namespace ts {
12431251

12441252
export function toBuilderStateFileInfo(fileInfo: ProgramBuildInfoFileInfo): BuilderState.FileInfo {
12451253
return isString(fileInfo) ?
1246-
{ version: fileInfo, signature: fileInfo, affectsGlobalScope: undefined } :
1254+
{ version: fileInfo, signature: fileInfo, affectsGlobalScope: undefined, impliedFormat: undefined } :
12471255
isString(fileInfo.signature) ?
12481256
fileInfo as BuilderState.FileInfo :
1249-
{ version: fileInfo.version, signature: fileInfo.signature === false ? undefined : fileInfo.version, affectsGlobalScope: fileInfo.affectsGlobalScope };
1257+
{ version: fileInfo.version, signature: fileInfo.signature === false ? undefined : fileInfo.version, affectsGlobalScope: fileInfo.affectsGlobalScope, impliedFormat: fileInfo.impliedFormat };
12501258
}
12511259

12521260
export function createBuildProgramUsingProgramBuildInfo(program: ProgramBuildInfo, buildInfoPath: string, host: ReadBuildProgramHost): EmitAndSemanticDiagnosticsBuilderProgram {

Diff for: src/compiler/builderState.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ namespace ts {
8282
readonly version: string;
8383
signature: string | undefined;
8484
affectsGlobalScope: boolean | undefined;
85+
impliedFormat: number | undefined;
8586
}
8687

8788
export interface ReadonlyManyToManyPathMap {
@@ -332,7 +333,7 @@ namespace ts {
332333
}
333334
}
334335
}
335-
fileInfos.set(sourceFile.resolvedPath, { version, signature: oldInfo && oldInfo.signature, affectsGlobalScope: isFileAffectingGlobalScope(sourceFile) || undefined });
336+
fileInfos.set(sourceFile.resolvedPath, { version, signature: oldInfo && oldInfo.signature, affectsGlobalScope: isFileAffectingGlobalScope(sourceFile) || undefined, impliedFormat: sourceFile.impliedNodeFormat });
336337
}
337338

338339
return {
@@ -433,7 +434,7 @@ namespace ts {
433434
);
434435
const firstDts = firstOrUndefined(emitOutput.outputFiles);
435436
if (firstDts) {
436-
Debug.assert(fileExtensionIs(firstDts.name, Extension.Dts), "File extension for signature expected to be dts", () => `Found: ${getAnyExtensionFromPath(firstDts.name)} for ${firstDts.name}:: All output files: ${JSON.stringify(emitOutput.outputFiles.map(f => f.name))}`);
437+
Debug.assert(fileExtensionIsOneOf(firstDts.name, [Extension.Dts, Extension.Dmts, Extension.Dcts]), "File extension for signature expected to be dts", () => `Found: ${getAnyExtensionFromPath(firstDts.name)} for ${firstDts.name}:: All output files: ${JSON.stringify(emitOutput.outputFiles.map(f => f.name))}`);
437438
latestSignature = (computeHash || generateDjb2Hash)(firstDts.text);
438439
if (exportedModulesMapCache && latestSignature !== prevSignature) {
439440
updateExportedModules(sourceFile, emitOutput.exportedModulesFromDeclarationEmit, exportedModulesMapCache);

0 commit comments

Comments
 (0)