Skip to content

Commit 82fb56b

Browse files
committed
Cleanup impliedFormat
1 parent 0f7903d commit 82fb56b

File tree

6 files changed

+68
-57
lines changed

6 files changed

+68
-57
lines changed

src/compiler/builder.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ namespace ts {
207207
!(oldInfo = oldState!.fileInfos.get(sourceFilePath)) ||
208208
// versions dont match
209209
oldInfo.version !== info.version ||
210+
// Implied formats dont match
211+
oldInfo.impliedFormat !== info.impliedFormat ||
210212
// Referenced files changed
211213
!hasSameKeys(newReferences = referencedMap && referencedMap.getValues(sourceFilePath), oldReferencedMap && oldReferencedMap.getValues(sourceFilePath)) ||
212214
// Referenced file was deleted in the new program
@@ -247,15 +249,6 @@ namespace ts {
247249
Debug.assert(!state.seenAffectedFiles || !state.seenAffectedFiles.size);
248250
state.seenAffectedFiles = state.seenAffectedFiles || new Set();
249251
}
250-
if (useOldState) {
251-
// Any time the interpretation of a source file changes, mark it as changed
252-
forEachEntry(oldState!.fileInfos, (info, sourceFilePath) => {
253-
if (state.fileInfos.has(sourceFilePath) && state.fileInfos.get(sourceFilePath)!.impliedFormat !== info.impliedFormat) {
254-
state.changedFilesSet.add(sourceFilePath);
255-
}
256-
});
257-
}
258-
259252
state.buildInfoEmitPending = !useOldState || state.changedFilesSet.size !== oldState!.changedFilesSet.size;
260253
return state;
261254
}

src/compiler/builderState.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ namespace ts {
5757
readonly version: string;
5858
signature: string | undefined;
5959
affectsGlobalScope: true | undefined;
60-
impliedFormat: number | undefined;
60+
impliedFormat: SourceFile["impliedNodeFormat"];
6161
}
6262

6363
export interface ReadonlyManyToManyPathMap {
@@ -300,7 +300,12 @@ namespace ts {
300300
}
301301
}
302302
}
303-
fileInfos.set(sourceFile.resolvedPath, { version, signature: oldInfo && oldInfo.signature, affectsGlobalScope: isFileAffectingGlobalScope(sourceFile) || undefined, impliedFormat: sourceFile.impliedNodeFormat });
303+
fileInfos.set(sourceFile.resolvedPath, {
304+
version,
305+
signature: oldInfo && oldInfo.signature,
306+
affectsGlobalScope: isFileAffectingGlobalScope(sourceFile) || undefined,
307+
impliedFormat: sourceFile.impliedNodeFormat
308+
});
304309
}
305310

306311
return {

src/compiler/commandLineParser.ts

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,33 @@ namespace ts {
341341
defaultValueDescription: ScriptTarget.ES3,
342342
};
343343

344+
/*@internal*/
345+
export const moduleOptionDeclaration: CommandLineOptionOfCustomType = {
346+
name: "module",
347+
shortName: "m",
348+
type: new Map(getEntries({
349+
none: ModuleKind.None,
350+
commonjs: ModuleKind.CommonJS,
351+
amd: ModuleKind.AMD,
352+
system: ModuleKind.System,
353+
umd: ModuleKind.UMD,
354+
es6: ModuleKind.ES2015,
355+
es2015: ModuleKind.ES2015,
356+
es2020: ModuleKind.ES2020,
357+
es2022: ModuleKind.ES2022,
358+
esnext: ModuleKind.ESNext,
359+
node12: ModuleKind.Node12,
360+
nodenext: ModuleKind.NodeNext,
361+
})),
362+
affectsModuleResolution: true,
363+
affectsEmit: true,
364+
paramType: Diagnostics.KIND,
365+
showInSimplifiedHelpView: true,
366+
category: Diagnostics.Modules,
367+
description: Diagnostics.Specify_what_module_code_is_generated,
368+
defaultValueDescription: undefined,
369+
};
370+
344371
const commandOptionsWithoutBuild: CommandLineOption[] = [
345372
// CommandLine only options
346373
{
@@ -409,31 +436,7 @@ namespace ts {
409436

410437
// Basic
411438
targetOptionDeclaration,
412-
{
413-
name: "module",
414-
shortName: "m",
415-
type: new Map(getEntries({
416-
none: ModuleKind.None,
417-
commonjs: ModuleKind.CommonJS,
418-
amd: ModuleKind.AMD,
419-
system: ModuleKind.System,
420-
umd: ModuleKind.UMD,
421-
es6: ModuleKind.ES2015,
422-
es2015: ModuleKind.ES2015,
423-
es2020: ModuleKind.ES2020,
424-
es2022: ModuleKind.ES2022,
425-
esnext: ModuleKind.ESNext,
426-
node12: ModuleKind.Node12,
427-
nodenext: ModuleKind.NodeNext,
428-
})),
429-
affectsModuleResolution: true,
430-
affectsEmit: true,
431-
paramType: Diagnostics.KIND,
432-
showInSimplifiedHelpView: true,
433-
category: Diagnostics.Modules,
434-
description: Diagnostics.Specify_what_module_code_is_generated,
435-
defaultValueDescription: undefined,
436-
},
439+
moduleOptionDeclaration,
437440
{
438441
name: "lib",
439442
type: "list",
@@ -2372,7 +2375,8 @@ namespace ts {
23722375
}
23732376
}
23742377

2375-
function getNameOfCompilerOptionValue(value: CompilerOptionsValue, customTypeMap: ESMap<string, string | number>): string | undefined {
2378+
/* @internal */
2379+
export function getNameOfCompilerOptionValue(value: CompilerOptionsValue, customTypeMap: ESMap<string, string | number>): string | undefined {
23762380
// There is a typeMap associated with this command-line option so use it to map value back to its name
23772381
return forEachEntry(customTypeMap, (mapValue, key) => {
23782382
if (mapValue === value) {

src/testRunner/unittests/tsbuild/helpers.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,11 @@ interface Symbol {
199199
type ReadableProgramBuildInfoDiagnostic = string | [string, readonly ReusableDiagnostic[]];
200200
type ReadableProgramBuilderInfoFilePendingEmit = [string, "DtsOnly" | "Full"];
201201
type ReadableProgramBuildInfoEmitSignature = string | [string, string];
202+
type ReadableFileInfo = Omit<BuilderState.FileInfo, "impliedFormat"> & { impliedFormat: string | undefined; };
202203
interface ReadableProgramBuildInfo {
203204
fileNames: readonly string[] | undefined;
204205
fileNamesList: readonly (readonly string[])[] | undefined;
205-
fileInfos: MapLike<BuilderState.FileInfo> | undefined;
206+
fileInfos: MapLike<ReadableFileInfo> | undefined;
206207
options: CompilerOptions | undefined;
207208
referencedMap?: MapLike<string[]>;
208209
exportedModulesMap?: MapLike<string[]>;
@@ -216,7 +217,7 @@ interface Symbol {
216217
type ReadableBuildInfo = Omit<BuildInfo, "program"> & { program: ReadableProgramBuildInfo | undefined; size: number; };
217218
function generateBuildInfoProgramBaseline(sys: System, buildInfoPath: string, buildInfo: BuildInfo) {
218219
const fileInfos: ReadableProgramBuildInfo["fileInfos"] = {};
219-
buildInfo.program?.fileInfos?.forEach((fileInfo, index) => fileInfos[toFileName(index + 1 as ProgramBuildInfoFileId)] = toBuilderStateFileInfo(fileInfo));
220+
buildInfo.program?.fileInfos?.forEach((fileInfo, index) => fileInfos[toFileName(index + 1 as ProgramBuildInfoFileId)] = toReadableFileInfo(fileInfo));
220221
const fileNamesList = buildInfo.program?.fileIdsList?.map(fileIdsListId => fileIdsListId.map(toFileName));
221222
const program: ReadableProgramBuildInfo | undefined = buildInfo.program && {
222223
fileNames: buildInfo.program.fileNames,
@@ -278,6 +279,14 @@ interface Symbol {
278279
return fileNamesList![fileIdsListId - 1];
279280
}
280281

282+
function toReadableFileInfo(fileInfo: ProgramBuildInfoFileInfo): ReadableFileInfo {
283+
const info = toBuilderStateFileInfo(fileInfo);
284+
return {
285+
...info,
286+
impliedFormat: info.impliedFormat && getNameOfCompilerOptionValue(info.impliedFormat, moduleOptionDeclaration.type),
287+
};
288+
}
289+
281290
function toMapOfReferencedSet(referenceMap: ProgramBuildInfoReferencedMap | undefined): MapLike<string[]> | undefined {
282291
if (!referenceMap) return undefined;
283292
const result: MapLike<string[]> = {};
@@ -490,7 +499,7 @@ interface Symbol {
490499
} {
491500
if (!text) return { buildInfo: text };
492501
const readableBuildInfo = JSON.parse(text) as ReadableBuildInfo;
493-
let sanitizedFileInfos: MapLike<BuilderState.FileInfo> | undefined;
502+
let sanitizedFileInfos: MapLike<ReadableFileInfo> | undefined;
494503
if (readableBuildInfo.program?.fileInfos) {
495504
sanitizedFileInfos = {};
496505
for (const id in readableBuildInfo.program.fileInfos) {

tests/baselines/reference/tsbuild/moduleSpecifiers/synthesized-module-specifiers-across-projects-resolve-correctly.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -247,42 +247,42 @@ LassieDog.getDogConfig = () => LASSIE_CONFIG;
247247
"version": "-7698705165-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }",
248248
"signature": "-7698705165-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }",
249249
"affectsGlobalScope": true,
250-
"impliedFormat": 1
250+
"impliedFormat": "commonjs"
251251
},
252252
"../src-types/dogconfig.d.ts": {
253253
"version": "-2632060142-export interface DogConfig {\r\n name: string;\r\n}\r\n",
254254
"signature": "-2632060142-export interface DogConfig {\r\n name: string;\r\n}\r\n",
255-
"impliedFormat": 99
255+
"impliedFormat": "esnext"
256256
},
257257
"../src-types/index.d.ts": {
258258
"version": "-5608794531-export * from './dogconfig.js';\r\n",
259259
"signature": "-5608794531-export * from './dogconfig.js';\r\n",
260-
"impliedFormat": 99
260+
"impliedFormat": "esnext"
261261
},
262262
"./dogconfig.ts": {
263263
"version": "1966273863-import { DogConfig } from 'src-types';\n\nexport const DOG_CONFIG: DogConfig = {\n name: 'Default dog',\n};\n",
264264
"signature": "17588480778-import { DogConfig } from 'src-types';\r\nexport declare const DOG_CONFIG: DogConfig;\r\n",
265-
"impliedFormat": 99
265+
"impliedFormat": "esnext"
266266
},
267267
"./dog.ts": {
268268
"version": "6091345804-import { DogConfig } from 'src-types';\nimport { DOG_CONFIG } from './dogconfig.js';\n\nexport abstract class Dog {\n\n public static getCapabilities(): DogConfig {\n return DOG_CONFIG;\n }\n}\n",
269269
"signature": "22128633249-import { DogConfig } from 'src-types';\r\nexport declare abstract class Dog {\r\n static getCapabilities(): DogConfig;\r\n}\r\n",
270-
"impliedFormat": 99
270+
"impliedFormat": "esnext"
271271
},
272272
"./lassie/lassieconfig.ts": {
273273
"version": "4440579024-import { DogConfig } from 'src-types';\n\nexport const LASSIE_CONFIG: DogConfig = { name: 'Lassie' };\n",
274274
"signature": "8131483665-import { DogConfig } from 'src-types';\r\nexport declare const LASSIE_CONFIG: DogConfig;\r\n",
275-
"impliedFormat": 99
275+
"impliedFormat": "esnext"
276276
},
277277
"./lassie/lassiedog.ts": {
278278
"version": "-32303727812-import { Dog } from '../dog.js';\nimport { LASSIE_CONFIG } from './lassieconfig.js';\n\nexport class LassieDog extends Dog {\n protected static getDogConfig = () => LASSIE_CONFIG;\n}\n",
279279
"signature": "-20244062422-import { Dog } from '../dog.js';\r\nexport declare class LassieDog extends Dog {\r\n protected static getDogConfig: () => import(\"../index.js\").DogConfig;\r\n}\r\n",
280-
"impliedFormat": 99
280+
"impliedFormat": "esnext"
281281
},
282282
"./index.ts": {
283283
"version": "-15974991320-export * from 'src-types';\nexport * from './lassie/lassiedog.js';\n",
284284
"signature": "-16783836862-export * from 'src-types';\r\nexport * from './lassie/lassiedog.js';\r\n",
285-
"impliedFormat": 99
285+
"impliedFormat": "esnext"
286286
}
287287
},
288288
"options": {
@@ -390,17 +390,17 @@ export * from './dogconfig.js';
390390
"version": "-7698705165-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }",
391391
"signature": "-7698705165-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }",
392392
"affectsGlobalScope": true,
393-
"impliedFormat": 1
393+
"impliedFormat": "commonjs"
394394
},
395395
"./dogconfig.ts": {
396396
"version": "-5575793279-export interface DogConfig {\n name: string;\n}",
397397
"signature": "-2632060142-export interface DogConfig {\r\n name: string;\r\n}\r\n",
398-
"impliedFormat": 99
398+
"impliedFormat": "esnext"
399399
},
400400
"./index.ts": {
401401
"version": "-6189272282-export * from './dogconfig.js';",
402402
"signature": "-5608794531-export * from './dogconfig.js';\r\n",
403-
"impliedFormat": 99
403+
"impliedFormat": "esnext"
404404
}
405405
},
406406
"options": {

tests/baselines/reference/tsbuildWatch/moduleResolution/resolves-specifier-in-output-declaration-file-from-referenced-project-correctly-with-cts-and-mts-extensions.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,17 +214,17 @@ export type { TheNum } from './const.cjs';
214214
"version": "-7698705165-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }",
215215
"signature": "-7698705165-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }",
216216
"affectsGlobalScope": true,
217-
"impliedFormat": 1
217+
"impliedFormat": "commonjs"
218218
},
219219
"../const.cts": {
220220
"version": "-11202312776-export type TheNum = 42;",
221221
"signature": "-9649133742-export declare type TheNum = 42;\n",
222-
"impliedFormat": 1
222+
"impliedFormat": "commonjs"
223223
},
224224
"../index.ts": {
225225
"version": "-9668872159-export type { TheNum } from './const.cjs';",
226226
"signature": "-9835135925-export type { TheNum } from './const.cjs';\n",
227-
"impliedFormat": 99
227+
"impliedFormat": "esnext"
228228
}
229229
},
230230
"options": {
@@ -698,17 +698,17 @@ exitCode:: ExitStatus.undefined
698698
"version": "-7698705165-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }",
699699
"signature": "-7698705165-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }",
700700
"affectsGlobalScope": true,
701-
"impliedFormat": 1
701+
"impliedFormat": "commonjs"
702702
},
703703
"../const.cts": {
704704
"version": "-11202312776-export type TheNum = 42;",
705705
"signature": "-9649133742-export declare type TheNum = 42;\n",
706-
"impliedFormat": 1
706+
"impliedFormat": "commonjs"
707707
},
708708
"../index.cts": {
709709
"version": "-9668872159-export type { TheNum } from './const.cjs';",
710710
"signature": "-9835135925-export type { TheNum } from './const.cjs';\n",
711-
"impliedFormat": 1
711+
"impliedFormat": "commonjs"
712712
}
713713
},
714714
"options": {

0 commit comments

Comments
 (0)