Skip to content

Commit 09c916f

Browse files
committed
Merge branch 'main' into fix-exact-optional-unassignable-properties
2 parents 41f0525 + ceef6f7 commit 09c916f

File tree

53 files changed

+5455
-4535
lines changed

Some content is hidden

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

53 files changed

+5455
-4535
lines changed

package-lock.json

Lines changed: 65 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/compiler/builderState.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ namespace ts {
4848
*/
4949
readonly exportedModulesMap: BuilderState.ManyToManyPathMap | undefined;
5050

51+
previousCache?: {
52+
id: number,
53+
version: number,
54+
};
55+
5156
/**
5257
* true if file version is used as signature
5358
* This helps in delaying the calculation of the d.ts hash as version for the file till reasonable time
@@ -80,6 +85,7 @@ namespace ts {
8085
}
8186

8287
export interface ReadonlyManyToManyPathMap {
88+
readonly id: number;
8389
clone(): ManyToManyPathMap;
8490
forEach(action: (v: ReadonlySet<Path>, k: Path) => void): void;
8591
getKeys(v: Path): ReadonlySet<Path> | undefined;
@@ -96,13 +102,18 @@ namespace ts {
96102
}
97103

98104
export interface ManyToManyPathMap extends ReadonlyManyToManyPathMap {
105+
version(): number; // Incremented each time the contents are changed
99106
deleteKey(k: Path): boolean;
100107
set(k: Path, v: ReadonlySet<Path>): void;
101108
}
102109

110+
let manyToManyPathMapCount = 0;
103111
export function createManyToManyPathMap(): ManyToManyPathMap {
104112
function create(forward: ESMap<Path, ReadonlySet<Path>>, reverse: ESMap<Path, Set<Path>>, deleted: Set<Path> | undefined): ManyToManyPathMap {
113+
let version = 0;
105114
const map: ManyToManyPathMap = {
115+
id: manyToManyPathMapCount++,
116+
version: () => version,
106117
clone: () => create(new Map(forward), new Map(reverse), deleted && new Set(deleted)),
107118
forEach: fn => forward.forEach(fn),
108119
getKeys: v => reverse.get(v),
@@ -121,26 +132,33 @@ namespace ts {
121132

122133
set.forEach(v => deleteFromMultimap(reverse, v, k));
123134
forward.delete(k);
135+
version++;
124136
return true;
125137
},
126138
set: (k, vSet) => {
127-
deleted?.delete(k);
139+
let changed = !!deleted?.delete(k);
128140

129141
const existingVSet = forward.get(k);
130142
forward.set(k, vSet);
131143

132144
existingVSet?.forEach(v => {
133145
if (!vSet.has(v)) {
146+
changed = true;
134147
deleteFromMultimap(reverse, v, k);
135148
}
136149
});
137150

138151
vSet.forEach(v => {
139152
if (!existingVSet?.has(v)) {
153+
changed = true;
140154
addToMultimap(reverse, v, k);
141155
}
142156
});
143157

158+
if (changed) {
159+
version++;
160+
}
161+
144162
return map;
145163
},
146164
};
@@ -475,6 +493,22 @@ namespace ts {
475493
export function updateExportedFilesMapFromCache(state: BuilderState, exportedModulesMapCache: ManyToManyPathMap | undefined) {
476494
if (exportedModulesMapCache) {
477495
Debug.assert(!!state.exportedModulesMap);
496+
497+
const cacheId = exportedModulesMapCache.id;
498+
const cacheVersion = exportedModulesMapCache.version();
499+
if (state.previousCache) {
500+
if (state.previousCache.id === cacheId && state.previousCache.version === cacheVersion) {
501+
// If this is the same cache at the same version as last time this BuilderState
502+
// was updated, there's no need to update again
503+
return;
504+
}
505+
state.previousCache.id = cacheId;
506+
state.previousCache.version = cacheVersion;
507+
}
508+
else {
509+
state.previousCache = { id: cacheId, version: cacheVersion };
510+
}
511+
478512
exportedModulesMapCache.deletedKeys()?.forEach(path => state.exportedModulesMap!.deleteKey(path));
479513
exportedModulesMapCache.forEach((exportedModules, path) => state.exportedModulesMap!.set(path, exportedModules));
480514
}

src/compiler/checker.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25438,7 +25438,7 @@ namespace ts {
2543825438
// We avoid calling back into `getTypeOfExpression` and reentering contextual typing to avoid a bogus circularity error in that case.
2543925439
if (decl && (isPropertyDeclaration(decl) || isPropertySignature(decl))) {
2544025440
const overallAnnotation = getEffectiveTypeAnnotationNode(decl);
25441-
return (overallAnnotation && getTypeFromTypeNode(overallAnnotation)) ||
25441+
return (overallAnnotation && instantiateType(getTypeFromTypeNode(overallAnnotation), getSymbolLinks(lhsSymbol).mapper)) ||
2544225442
(decl.initializer && getTypeOfExpression(binaryExpression.left));
2544325443
}
2544425444
if (kind === AssignmentDeclarationKind.None) {
@@ -40513,9 +40513,14 @@ namespace ts {
4051340513
}
4051440514

4051540515
// Resolve the symbol as a value to ensure the type can be reached at runtime during emit.
40516+
let isTypeOnly = false;
40517+
if (isQualifiedName(typeName)) {
40518+
const rootValueSymbol = resolveEntityName(getFirstIdentifier(typeName), SymbolFlags.Value, /*ignoreErrors*/ true, /*dontResolveAlias*/ true, location);
40519+
isTypeOnly = !!rootValueSymbol?.declarations?.every(isTypeOnlyImportOrExportDeclaration);
40520+
}
4051640521
const valueSymbol = resolveEntityName(typeName, SymbolFlags.Value, /*ignoreErrors*/ true, /*dontResolveAlias*/ true, location);
40517-
const isTypeOnly = valueSymbol?.declarations?.every(isTypeOnlyImportOrExportDeclaration) || false;
4051840522
const resolvedSymbol = valueSymbol && valueSymbol.flags & SymbolFlags.Alias ? resolveAlias(valueSymbol) : valueSymbol;
40523+
isTypeOnly ||= !!valueSymbol?.declarations?.every(isTypeOnlyImportOrExportDeclaration);
4051940524

4052040525
// Resolve the symbol as a type so that we can provide a more useful hint for the type serializer.
4052140526
const typeSymbol = resolveEntityName(typeName, SymbolFlags.Type, /*ignoreErrors*/ true, /*dontResolveAlias*/ false, location);

src/compiler/debug.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ namespace ts {
221221
assert(
222222
node !== undefined && (test === undefined || test(node)),
223223
message || "Unexpected node.",
224-
() => `Node ${formatSyntaxKind(node!.kind)} did not pass test '${getFunctionName(test!)}'.`,
224+
() => `Node ${formatSyntaxKind(node?.kind)} did not pass test '${getFunctionName(test!)}'.`,
225225
stackCrawlMark || assertNode);
226226
}
227227
}
@@ -246,7 +246,7 @@ namespace ts {
246246
assert(
247247
test === undefined || node === undefined || test(node),
248248
message || "Unexpected node.",
249-
() => `Node ${formatSyntaxKind(node!.kind)} did not pass test '${getFunctionName(test!)}'.`,
249+
() => `Node ${formatSyntaxKind(node?.kind)} did not pass test '${getFunctionName(test!)}'.`,
250250
stackCrawlMark || assertOptionalNode);
251251
}
252252
}
@@ -259,7 +259,7 @@ namespace ts {
259259
assert(
260260
kind === undefined || node === undefined || node.kind === kind,
261261
message || "Unexpected node.",
262-
() => `Node ${formatSyntaxKind(node!.kind)} was not a '${formatSyntaxKind(kind)}' token.`,
262+
() => `Node ${formatSyntaxKind(node?.kind)} was not a '${formatSyntaxKind(kind)}' token.`,
263263
stackCrawlMark || assertOptionalToken);
264264
}
265265
}

src/compiler/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4219,7 +4219,7 @@ namespace ts {
42194219
/** Follow all aliases to get the original symbol. */
42204220
getAliasedSymbol(symbol: Symbol): Symbol;
42214221
/** Follow a *single* alias to get the immediately aliased symbol. */
4222-
/* @internal */ getImmediateAliasedSymbol(symbol: Symbol): Symbol | undefined;
4222+
getImmediateAliasedSymbol(symbol: Symbol): Symbol | undefined;
42234223
getExportsOfModule(moduleSymbol: Symbol): Symbol[];
42244224
/** Unlike `getExportsOfModule`, this includes properties of an `export =` value. */
42254225
/* @internal */ getExportsAndPropertiesOfModule(moduleSymbol: Symbol): Symbol[];

0 commit comments

Comments
 (0)