Skip to content

Commit f941d92

Browse files
committed
Merge branch 'main' into import_assertion
2 parents 88e39d5 + 0cd447d commit f941d92

File tree

517 files changed

+27153
-7738
lines changed

Some content is hidden

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

517 files changed

+27153
-7738
lines changed

Gulpfile.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -510,21 +510,15 @@ task("baseline-accept").description = "Makes the most recent test results the ne
510510
task("baseline-accept-rwc", () => baselineAccept(localRwcBaseline, refRwcBaseline));
511511
task("baseline-accept-rwc").description = "Makes the most recent rwc test results the new baseline, overwriting the old baseline";
512512

513-
const buildLoggedIO = async () => {
514-
mkdirp.sync("built/local/temp");
515-
await exec(process.execPath, ["lib/tsc", "--types", "--target", "es5", "--lib", "es5", "--outdir", "built/local/temp", "src/harness/loggedIO.ts"]);
516-
fs.renameSync("built/local/temp/harness/loggedIO.js", "built/local/loggedIO.js");
517-
await del("built/local/temp");
518-
};
519-
520-
const cleanLoggedIO = () => del("built/local/temp/loggedIO.js");
513+
const buildLoggedIO = () => buildProject("src/loggedIO/tsconfig-tsc-instrumented.json");
514+
const cleanLoggedIO = () => del("built/local/loggedIO.js");
521515
cleanTasks.push(cleanLoggedIO);
522516

523517
const buildInstrumenter = () => buildProject("src/instrumenter");
524518
const cleanInstrumenter = () => cleanProject("src/instrumenter");
525519
cleanTasks.push(cleanInstrumenter);
526520

527-
const tscInstrumented = () => exec(process.execPath, ["built/local/instrumenter.js", "record", cmdLineOptions.tests || "iocapture", "built/local"]);
521+
const tscInstrumented = () => exec(process.execPath, ["built/local/instrumenter.js", "record", cmdLineOptions.tests || "iocapture", "built/local/tsc.js"]);
528522
task("tsc-instrumented", series(lkgPreBuild, parallel(localize, buildTsc, buildServer, buildServices, buildLssl, buildLoggedIO, buildInstrumenter), tscInstrumented));
529523
task("tsc-instrumented").description = "Builds an instrumented tsc.js";
530524
task("tsc-instrumented").flags = {

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "typescript",
33
"author": "Microsoft Corp.",
44
"homepage": "https://www.typescriptlang.org/",
5-
"version": "4.4.0",
5+
"version": "4.5.0",
66
"license": "Apache-2.0",
77
"description": "TypeScript is a language for application scale JavaScript development",
88
"keywords": [

src/compiler/binder.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -916,10 +916,6 @@ namespace ts {
916916
return isTypeOfExpression(expr1) && isNarrowableOperand(expr1.expression) && isStringLiteralLike(expr2);
917917
}
918918

919-
function isNarrowableInOperands(left: Expression, right: Expression) {
920-
return isStringLiteralLike(left) && isNarrowingExpression(right);
921-
}
922-
923919
function isNarrowingBinaryExpression(expr: BinaryExpression) {
924920
switch (expr.operatorToken.kind) {
925921
case SyntaxKind.EqualsToken:
@@ -936,7 +932,7 @@ namespace ts {
936932
case SyntaxKind.InstanceOfKeyword:
937933
return isNarrowableOperand(expr.left);
938934
case SyntaxKind.InKeyword:
939-
return isNarrowableInOperands(expr.left, expr.right);
935+
return isNarrowingExpression(expr.right);
940936
case SyntaxKind.CommaToken:
941937
return isNarrowingExpression(expr.right);
942938
}
@@ -1670,11 +1666,15 @@ namespace ts {
16701666
}
16711667

16721668
function bindJSDocTypeAlias(node: JSDocTypedefTag | JSDocCallbackTag | JSDocEnumTag) {
1673-
setParent(node.tagName, node);
1669+
bind(node.tagName);
16741670
if (node.kind !== SyntaxKind.JSDocEnumTag && node.fullName) {
1671+
// don't bind the type name yet; that's delayed until delayedBindJSDocTypedefTag
16751672
setParent(node.fullName, node);
16761673
setParentRecursive(node.fullName, /*incremental*/ false);
16771674
}
1675+
if (typeof node.comment !== "string") {
1676+
bindEach(node.comment);
1677+
}
16781678
}
16791679

16801680
function bindJSDocClassTag(node: JSDocClassTag) {
@@ -2294,7 +2294,7 @@ namespace ts {
22942294
// Provide specialized messages to help the user understand why we think they're in
22952295
// strict mode.
22962296
if (getContainingClass(node)) {
2297-
return Diagnostics.Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode;
2297+
return Diagnostics.Code_contained_in_a_class_is_evaluated_in_JavaScript_s_strict_mode_which_does_not_allow_this_use_of_0_For_more_information_see_https_Colon_Slash_Slashdeveloper_mozilla_org_Slashen_US_Slashdocs_SlashWeb_SlashJavaScript_SlashReference_SlashStrict_mode;
22982298
}
22992299

23002300
if (file.externalModuleIndicator) {

src/compiler/builderState.ts

Lines changed: 46 additions & 20 deletions
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
};
@@ -178,22 +196,16 @@ namespace ts {
178196
*/
179197
export type ComputeHash = ((data: string) => string) | undefined;
180198

181-
/**
182-
* Get the referencedFile from the imported module symbol
183-
*/
184-
function getReferencedFileFromImportedModuleSymbol(symbol: Symbol) {
185-
if (symbol.declarations && symbol.declarations[0]) {
186-
const declarationSourceFile = getSourceFileOfNode(symbol.declarations[0]);
187-
return declarationSourceFile && declarationSourceFile.resolvedPath;
188-
}
199+
function getReferencedFilesFromImportedModuleSymbol(symbol: Symbol): Path[] {
200+
return mapDefined(symbol.declarations, declaration => getSourceFileOfNode(declaration)?.resolvedPath);
189201
}
190202

191203
/**
192-
* Get the referencedFile from the import name node from file
204+
* Get the module source file and all augmenting files from the import name node from file
193205
*/
194-
function getReferencedFileFromImportLiteral(checker: TypeChecker, importName: StringLiteralLike) {
206+
function getReferencedFilesFromImportLiteral(checker: TypeChecker, importName: StringLiteralLike): Path[] | undefined {
195207
const symbol = checker.getSymbolAtLocation(importName);
196-
return symbol && getReferencedFileFromImportedModuleSymbol(symbol);
208+
return symbol && getReferencedFilesFromImportedModuleSymbol(symbol);
197209
}
198210

199211
/**
@@ -215,10 +227,8 @@ namespace ts {
215227
if (sourceFile.imports && sourceFile.imports.length > 0) {
216228
const checker: TypeChecker = program.getTypeChecker();
217229
for (const importName of sourceFile.imports) {
218-
const declarationSourceFilePath = getReferencedFileFromImportLiteral(checker, importName);
219-
if (declarationSourceFilePath) {
220-
addReferencedFile(declarationSourceFilePath);
221-
}
230+
const declarationSourceFilePaths = getReferencedFilesFromImportLiteral(checker, importName);
231+
declarationSourceFilePaths?.forEach(addReferencedFile);
222232
}
223233
}
224234

@@ -458,20 +468,20 @@ namespace ts {
458468
}
459469

460470
let exportedModules: Set<Path> | undefined;
461-
exportedModulesFromDeclarationEmit.forEach(symbol => addExportedModule(getReferencedFileFromImportedModuleSymbol(symbol)));
471+
exportedModulesFromDeclarationEmit.forEach(symbol => addExportedModule(getReferencedFilesFromImportedModuleSymbol(symbol)));
462472
if (exportedModules) {
463473
exportedModulesMapCache.set(sourceFile.resolvedPath, exportedModules);
464474
}
465475
else {
466476
exportedModulesMapCache.deleteKey(sourceFile.resolvedPath);
467477
}
468478

469-
function addExportedModule(exportedModulePath: Path | undefined) {
470-
if (exportedModulePath) {
479+
function addExportedModule(exportedModulePaths: Path[] | undefined) {
480+
if (exportedModulePaths?.length) {
471481
if (!exportedModules) {
472482
exportedModules = new Set();
473483
}
474-
exportedModules.add(exportedModulePath);
484+
exportedModulePaths.forEach(path => exportedModules!.add(path));
475485
}
476486
}
477487
}
@@ -483,6 +493,22 @@ namespace ts {
483493
export function updateExportedFilesMapFromCache(state: BuilderState, exportedModulesMapCache: ManyToManyPathMap | undefined) {
484494
if (exportedModulesMapCache) {
485495
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+
486512
exportedModulesMapCache.deletedKeys()?.forEach(path => state.exportedModulesMap!.deleteKey(path));
487513
exportedModulesMapCache.forEach((exportedModules, path) => state.exportedModulesMap!.set(path, exportedModules));
488514
}

0 commit comments

Comments
 (0)