Skip to content

Commit 3a89fea

Browse files
committed
Merge branch 'master' into ignoreStringIndexSignaturesOnly
# Conflicts: # tests/baselines/reference/keyofAndIndexedAccess2.errors.txt # tests/baselines/reference/keyofAndIndexedAccess2.js # tests/baselines/reference/keyofAndIndexedAccess2.symbols # tests/baselines/reference/keyofAndIndexedAccess2.types # tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts
2 parents f9a55ac + 33c3ce9 commit 3a89fea

File tree

44 files changed

+705
-391
lines changed

Some content is hidden

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

44 files changed

+705
-391
lines changed

src/compiler/builder.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,7 @@ namespace ts {
236236
}
237237
});
238238

239-
if (oldCompilerOptions &&
240-
(oldCompilerOptions.outDir !== compilerOptions.outDir ||
241-
oldCompilerOptions.declarationDir !== compilerOptions.declarationDir ||
242-
(oldCompilerOptions.outFile || oldCompilerOptions.out) !== (compilerOptions.outFile || compilerOptions.out))) {
239+
if (oldCompilerOptions && compilerOptionsAffectEmit(compilerOptions, oldCompilerOptions)) {
243240
// Add all files to affectedFilesPendingEmit since emit changed
244241
state.affectedFilesPendingEmit = concatenate(state.affectedFilesPendingEmit, newProgram.getSourceFiles().map(f => f.path));
245242
if (state.affectedFilesPendingEmitIndex === undefined) {

src/compiler/checker.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ namespace ts {
114114
getIdentifierCount: () => sum(host.getSourceFiles(), "identifierCount"),
115115
getSymbolCount: () => sum(host.getSourceFiles(), "symbolCount") + symbolCount,
116116
getTypeCount: () => typeCount,
117+
getRelationCacheSizes: () => ({
118+
assignable: assignableRelation.size,
119+
identity: identityRelation.size,
120+
subtype: subtypeRelation.size,
121+
}),
117122
isUndefinedSymbol: symbol => symbol === undefinedSymbol,
118123
isArgumentsSymbol: symbol => symbol === argumentsSymbol,
119124
isUnknownSymbol: symbol => symbol === unknownSymbol,
@@ -6709,11 +6714,12 @@ namespace ts {
67096714
const links = getSymbolLinks(symbol);
67106715
if (!links.lateSymbol && some(symbol.declarations, hasLateBindableName)) {
67116716
// force late binding of members/exports. This will set the late-bound symbol
6717+
const parent = getMergedSymbol(symbol.parent)!;
67126718
if (some(symbol.declarations, hasStaticModifier)) {
6713-
getExportsOfSymbol(symbol.parent!);
6719+
getExportsOfSymbol(parent);
67146720
}
67156721
else {
6716-
getMembersOfSymbol(symbol.parent!);
6722+
getMembersOfSymbol(parent);
67176723
}
67186724
}
67196725
return links.lateSymbol || (links.lateSymbol = symbol);
@@ -12043,7 +12049,7 @@ namespace ts {
1204312049
}
1204412050

1204512051
function isStringIndexSignatureOnlyType(type: Type): boolean {
12046-
return type.flags & TypeFlags.Object && getPropertiesOfType(type).length === 0 && getIndexInfoOfType(type, IndexKind.String) && !getIndexInfoOfType(type, IndexKind.Number) ||
12052+
return type.flags & TypeFlags.Object && !isGenericMappedType(type) && getPropertiesOfType(type).length === 0 && getIndexInfoOfType(type, IndexKind.String) && !getIndexInfoOfType(type, IndexKind.Number) ||
1204712053
type.flags & TypeFlags.UnionOrIntersection && every((<UnionOrIntersectionType>type).types, isStringIndexSignatureOnlyType) ||
1204812054
false;
1204912055
}
@@ -15016,12 +15022,11 @@ namespace ts {
1501615022
}
1501715023
// If no inferences can be made to K's constraint, infer from a union of the property types
1501815024
// in the source to the template type X.
15019-
const valueTypes = compact([
15020-
getIndexTypeOfType(source, IndexKind.String),
15021-
getIndexTypeOfType(source, IndexKind.Number),
15022-
...map(getPropertiesOfType(source), getTypeOfSymbol)
15023-
]);
15024-
inferFromTypes(getUnionType(valueTypes), getTemplateTypeFromMappedType(target));
15025+
const propTypes = map(getPropertiesOfType(source), getTypeOfSymbol);
15026+
const stringIndexType = getIndexTypeOfType(source, IndexKind.String);
15027+
const numberIndexInfo = getNonEnumNumberIndexInfo(source);
15028+
const numberIndexType = numberIndexInfo && numberIndexInfo.type;
15029+
inferFromTypes(getUnionType(append(append(propTypes, stringIndexType), numberIndexType)), getTemplateTypeFromMappedType(target));
1502515030
return true;
1502615031
}
1502715032
return false;

src/compiler/commandLineParser.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,33 +281,38 @@ namespace ts {
281281
name: "declaration",
282282
shortName: "d",
283283
type: "boolean",
284+
affectsEmit: true,
284285
showInSimplifiedHelpView: true,
285286
category: Diagnostics.Basic_Options,
286287
description: Diagnostics.Generates_corresponding_d_ts_file,
287288
},
288289
{
289290
name: "declarationMap",
290291
type: "boolean",
292+
affectsEmit: true,
291293
showInSimplifiedHelpView: true,
292294
category: Diagnostics.Basic_Options,
293295
description: Diagnostics.Generates_a_sourcemap_for_each_corresponding_d_ts_file,
294296
},
295297
{
296298
name: "emitDeclarationOnly",
297299
type: "boolean",
300+
affectsEmit: true,
298301
category: Diagnostics.Advanced_Options,
299302
description: Diagnostics.Only_emit_d_ts_declaration_files,
300303
},
301304
{
302305
name: "sourceMap",
303306
type: "boolean",
307+
affectsEmit: true,
304308
showInSimplifiedHelpView: true,
305309
category: Diagnostics.Basic_Options,
306310
description: Diagnostics.Generates_corresponding_map_file,
307311
},
308312
{
309313
name: "outFile",
310314
type: "string",
315+
affectsEmit: true,
311316
isFilePath: true,
312317
paramType: Diagnostics.FILE,
313318
showInSimplifiedHelpView: true,
@@ -317,6 +322,7 @@ namespace ts {
317322
{
318323
name: "outDir",
319324
type: "string",
325+
affectsEmit: true,
320326
isFilePath: true,
321327
paramType: Diagnostics.DIRECTORY,
322328
showInSimplifiedHelpView: true,
@@ -326,6 +332,7 @@ namespace ts {
326332
{
327333
name: "rootDir",
328334
type: "string",
335+
affectsEmit: true,
329336
isFilePath: true,
330337
paramType: Diagnostics.LOCATION,
331338
category: Diagnostics.Basic_Options,
@@ -334,13 +341,15 @@ namespace ts {
334341
{
335342
name: "composite",
336343
type: "boolean",
344+
affectsEmit: true,
337345
isTSConfigOnly: true,
338346
category: Diagnostics.Basic_Options,
339347
description: Diagnostics.Enable_project_compilation,
340348
},
341349
{
342350
name: "tsBuildInfoFile",
343351
type: "string",
352+
affectsEmit: true,
344353
isFilePath: true,
345354
paramType: Diagnostics.FILE,
346355
category: Diagnostics.Basic_Options,
@@ -349,26 +358,30 @@ namespace ts {
349358
{
350359
name: "removeComments",
351360
type: "boolean",
361+
affectsEmit: true,
352362
showInSimplifiedHelpView: true,
353363
category: Diagnostics.Basic_Options,
354364
description: Diagnostics.Do_not_emit_comments_to_output,
355365
},
356366
{
357367
name: "noEmit",
358368
type: "boolean",
369+
affectsEmit: true,
359370
showInSimplifiedHelpView: true,
360371
category: Diagnostics.Basic_Options,
361372
description: Diagnostics.Do_not_emit_outputs,
362373
},
363374
{
364375
name: "importHelpers",
365376
type: "boolean",
377+
affectsEmit: true,
366378
category: Diagnostics.Basic_Options,
367379
description: Diagnostics.Import_emit_helpers_from_tslib
368380
},
369381
{
370382
name: "downlevelIteration",
371383
type: "boolean",
384+
affectsEmit: true,
372385
category: Diagnostics.Basic_Options,
373386
description: Diagnostics.Provide_full_support_for_iterables_in_for_of_spread_and_destructuring_when_targeting_ES5_or_ES3
374387
},
@@ -580,26 +593,30 @@ namespace ts {
580593
{
581594
name: "sourceRoot",
582595
type: "string",
596+
affectsEmit: true,
583597
paramType: Diagnostics.LOCATION,
584598
category: Diagnostics.Source_Map_Options,
585599
description: Diagnostics.Specify_the_location_where_debugger_should_locate_TypeScript_files_instead_of_source_locations,
586600
},
587601
{
588602
name: "mapRoot",
589603
type: "string",
604+
affectsEmit: true,
590605
paramType: Diagnostics.LOCATION,
591606
category: Diagnostics.Source_Map_Options,
592607
description: Diagnostics.Specify_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations,
593608
},
594609
{
595610
name: "inlineSourceMap",
596611
type: "boolean",
612+
affectsEmit: true,
597613
category: Diagnostics.Source_Map_Options,
598614
description: Diagnostics.Emit_a_single_file_with_source_maps_instead_of_having_a_separate_file
599615
},
600616
{
601617
name: "inlineSources",
602618
type: "boolean",
619+
affectsEmit: true,
603620
category: Diagnostics.Source_Map_Options,
604621
description: Diagnostics.Emit_the_source_alongside_the_sourcemaps_within_a_single_file_requires_inlineSourceMap_or_sourceMap_to_be_set
605622
},
@@ -635,6 +652,7 @@ namespace ts {
635652
{
636653
name: "out",
637654
type: "string",
655+
affectsEmit: true,
638656
isFilePath: false, // This is intentionally broken to support compatability with existing tsconfig files
639657
// for correct behaviour, please use outFile
640658
category: Diagnostics.Advanced_Options,
@@ -644,6 +662,7 @@ namespace ts {
644662
{
645663
name: "reactNamespace",
646664
type: "string",
665+
affectsEmit: true,
647666
category: Diagnostics.Advanced_Options,
648667
description: Diagnostics.Deprecated_Use_jsxFactory_instead_Specify_the_object_invoked_for_createElement_when_targeting_react_JSX_emit
649668
},
@@ -662,6 +681,7 @@ namespace ts {
662681
{
663682
name: "emitBOM",
664683
type: "boolean",
684+
affectsEmit: true,
665685
category: Diagnostics.Advanced_Options,
666686
description: Diagnostics.Emit_a_UTF_8_Byte_Order_Mark_BOM_in_the_beginning_of_output_files
667687
},
@@ -677,6 +697,7 @@ namespace ts {
677697
crlf: NewLineKind.CarriageReturnLineFeed,
678698
lf: NewLineKind.LineFeed
679699
}),
700+
affectsEmit: true,
680701
paramType: Diagnostics.NEWLINE,
681702
category: Diagnostics.Advanced_Options,
682703
description: Diagnostics.Specify_the_end_of_line_sequence_to_be_used_when_emitting_files_Colon_CRLF_dos_or_LF_unix,
@@ -704,6 +725,7 @@ namespace ts {
704725
{
705726
name: "stripInternal",
706727
type: "boolean",
728+
affectsEmit: true,
707729
category: Diagnostics.Advanced_Options,
708730
description: Diagnostics.Do_not_emit_declarations_for_code_that_has_an_internal_annotation,
709731
},
@@ -724,24 +746,28 @@ namespace ts {
724746
{
725747
name: "noEmitHelpers",
726748
type: "boolean",
749+
affectsEmit: true,
727750
category: Diagnostics.Advanced_Options,
728751
description: Diagnostics.Do_not_generate_custom_helper_functions_like_extends_in_compiled_output
729752
},
730753
{
731754
name: "noEmitOnError",
732755
type: "boolean",
756+
affectsEmit: true,
733757
category: Diagnostics.Advanced_Options,
734758
description: Diagnostics.Do_not_emit_outputs_if_any_errors_were_reported,
735759
},
736760
{
737761
name: "preserveConstEnums",
738762
type: "boolean",
763+
affectsEmit: true,
739764
category: Diagnostics.Advanced_Options,
740765
description: Diagnostics.Do_not_erase_const_enum_declarations_in_generated_code
741766
},
742767
{
743768
name: "declarationDir",
744769
type: "string",
770+
affectsEmit: true,
745771
isFilePath: true,
746772
paramType: Diagnostics.DIRECTORY,
747773
category: Diagnostics.Advanced_Options,
@@ -826,6 +852,10 @@ namespace ts {
826852
export const semanticDiagnosticsOptionDeclarations: ReadonlyArray<CommandLineOption> =
827853
optionDeclarations.filter(option => !!option.affectsSemanticDiagnostics);
828854

855+
/* @internal */
856+
export const affectsEmitOptionDeclarations: ReadonlyArray<CommandLineOption> =
857+
optionDeclarations.filter(option => !!option.affectsEmit);
858+
829859
/* @internal */
830860
export const moduleResolutionOptionDeclarations: ReadonlyArray<CommandLineOption> =
831861
optionDeclarations.filter(option => !!option.affectsModuleResolution);

src/compiler/program.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,7 @@ namespace ts {
927927
getIdentifierCount: () => getDiagnosticsProducingTypeChecker().getIdentifierCount(),
928928
getSymbolCount: () => getDiagnosticsProducingTypeChecker().getSymbolCount(),
929929
getTypeCount: () => getDiagnosticsProducingTypeChecker().getTypeCount(),
930+
getRelationCacheSizes: () => getDiagnosticsProducingTypeChecker().getRelationCacheSizes(),
930931
getFileProcessingDiagnostics: () => fileProcessingDiagnostics,
931932
getResolvedTypeReferenceDirectives: () => resolvedTypeReferenceDirectives,
932933
isSourceFileFromExternalLibrary,

src/compiler/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2961,6 +2961,7 @@ namespace ts {
29612961
/* @internal */ getIdentifierCount(): number;
29622962
/* @internal */ getSymbolCount(): number;
29632963
/* @internal */ getTypeCount(): number;
2964+
/* @internal */ getRelationCacheSizes(): { assignable: number, identity: number, subtype: number };
29642965

29652966
/* @internal */ getFileProcessingDiagnostics(): DiagnosticCollection;
29662967
/* @internal */ getResolvedTypeReferenceDirectives(): Map<ResolvedTypeReferenceDirective | undefined>;
@@ -3246,6 +3247,7 @@ namespace ts {
32463247
/* @internal */ getIdentifierCount(): number;
32473248
/* @internal */ getSymbolCount(): number;
32483249
/* @internal */ getTypeCount(): number;
3250+
/* @internal */ getRelationCacheSizes(): { assignable: number, identity: number, subtype: number };
32493251

32503252
/* @internal */ isArrayType(type: Type): boolean;
32513253
/* @internal */ isTupleType(type: Type): boolean;
@@ -4827,6 +4829,7 @@ namespace ts {
48274829
affectsModuleResolution?: true; // currently same effect as `affectsSourceFile`
48284830
affectsBindDiagnostics?: true; // true if this affects binding (currently same effect as `affectsSourceFile`)
48294831
affectsSemanticDiagnostics?: true; // true if option affects semantic diagnostics
4832+
affectsEmit?: true; // true if the options affects emit
48304833
}
48314834

48324835
/* @internal */

src/compiler/utilities.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7320,6 +7320,11 @@ namespace ts {
73207320
semanticDiagnosticsOptionDeclarations.some(option => !isJsonEqual(getCompilerOptionValue(oldOptions, option), getCompilerOptionValue(newOptions, option)));
73217321
}
73227322

7323+
export function compilerOptionsAffectEmit(newOptions: CompilerOptions, oldOptions: CompilerOptions): boolean {
7324+
return oldOptions !== newOptions &&
7325+
affectsEmitOptionDeclarations.some(option => !isJsonEqual(getCompilerOptionValue(oldOptions, option), getCompilerOptionValue(newOptions, option)));
7326+
}
7327+
73237328
export function getCompilerOptionValue(options: CompilerOptions, option: CommandLineOption): unknown {
73247329
return option.strictFlag ? getStrictOptionValue(options, option.name as StrictOptionName) : options[option.name];
73257330
}

src/harness/fakes.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -397,19 +397,6 @@ namespace fakes {
397397
const value = super.readFile(path);
398398
if (!value || !ts.isBuildInfoFile(path)) return value;
399399
const buildInfo = ts.getBuildInfo(value);
400-
if (buildInfo.program) {
401-
// Fix lib signatures
402-
for (const path of ts.getOwnKeys(buildInfo.program.fileInfos)) {
403-
if (ts.startsWith(path, "/lib/")) {
404-
const currentValue = buildInfo.program.fileInfos[path];
405-
ts.Debug.assert(currentValue.signature === path);
406-
ts.Debug.assert(currentValue.signature === currentValue.version);
407-
const text = super.readFile(path)!;
408-
const signature = ts.generateDjb2Hash(text);
409-
buildInfo.program.fileInfos[path] = { version: signature, signature };
410-
}
411-
}
412-
}
413400
ts.Debug.assert(buildInfo.version === version);
414401
buildInfo.version = ts.version;
415402
return ts.getBuildInfoText(buildInfo);
@@ -419,15 +406,6 @@ namespace fakes {
419406
if (!ts.isBuildInfoFile(fileName)) return super.writeFile(fileName, content, writeByteOrderMark);
420407
const buildInfo = ts.getBuildInfo(content);
421408
if (buildInfo.program) {
422-
// Fix lib signatures
423-
for (const path of ts.getOwnKeys(buildInfo.program.fileInfos)) {
424-
if (ts.startsWith(path, "/lib/")) {
425-
const currentValue = buildInfo.program.fileInfos[path];
426-
ts.Debug.assert(currentValue.signature === currentValue.version);
427-
buildInfo.program.fileInfos[path] = { version: path, signature: path };
428-
}
429-
}
430-
431409
// reference Map
432410
if (buildInfo.program.referencedMap) {
433411
const referencedMap: ts.MapLike<string[]> = {};

src/testRunner/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
"unittests/tsbuild/amdModulesWithOut.ts",
9393
"unittests/tsbuild/emptyFiles.ts",
9494
"unittests/tsbuild/graphOrdering.ts",
95+
"unittests/tsbuild/lateBoundSymbol.ts",
9596
"unittests/tsbuild/missingExtendedFile.ts",
9697
"unittests/tsbuild/outFile.ts",
9798
"unittests/tsbuild/referencesWithRootDirInParent.ts",

0 commit comments

Comments
 (0)