Skip to content

Commit 34fb470

Browse files
committed
Merge branch 'master' into spread-compact-literals
2 parents 4156662 + a09a714 commit 34fb470

File tree

586 files changed

+11674
-3782
lines changed

Some content is hidden

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

586 files changed

+11674
-3782
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ jobs:
4242
- name: Linter
4343
run: npm run lint:ci
4444

45+
- name: Adding playwright
46+
run: npm install --no-save --no-package-lock playwright
47+
4548
- name: Validate the browser can import TypeScript
4649
run: gulp test-browser-integration
4750

.github/workflows/nightly.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
- name: Setup and publish nightly
2323
run: |
2424
npm whoami
25-
npm i
25+
npm ci
2626
gulp configure-nightly
2727
gulp LKG
2828
gulp runtests-parallel

package-lock.json

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

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@
8888
"mocha-fivemat-progress-reporter": "latest",
8989
"ms": "latest",
9090
"node-fetch": "^2.6.0",
91-
"playwright": "0.12.1",
9291
"plugin-error": "latest",
9392
"pretty-hrtime": "^1.0.3",
9493
"prex": "^0.4.3",

scripts/browserIntegrationTest.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
1-
const playwright = require("playwright");
1+
// @ts-check
22
const chalk = require("chalk");
33
const { join } = require("path");
44
const { readFileSync } = require("fs");
5+
try {
6+
// eslint-disable-next-line import/no-extraneous-dependencies
7+
require("playwright");
8+
}
9+
catch (error) {
10+
throw new Error("Playwright is expected to be installed manually before running this script");
11+
}
12+
13+
// eslint-disable-next-line import/no-extraneous-dependencies
14+
const playwright = require("playwright");
515

616
// Turning this on will leave the Chromium browser open, giving you the
717
// chance to open up the web inspector.
818
const debugging = false;
919

1020
(async () => {
11-
for (const browserType of ["chromium", "firefox", "webkit"]) {
21+
for (const browserType of ["chromium", "firefox"]) {
1222
const browser = await playwright[browserType].launch({ headless: !debugging });
1323
const context = await browser.newContext();
1424
const page = await context.newPage();
@@ -21,7 +31,6 @@ const debugging = false;
2131

2232
page.on("error", errorCaught);
2333
page.on("pageerror", errorCaught);
24-
page.on("console", log => console[log._type](log._text));
2534

2635
await page.setContent(`
2736
<html>
@@ -35,5 +44,14 @@ const debugging = false;
3544
else {
3645
console.log("Not closing the browser, you'll need to exit the process in your terminal manually");
3746
}
47+
console.log(`${browserType} :+1:`);
3848
}
3949
})();
50+
51+
process.on("unhandledRejection", (/** @type {any}*/ err) => {
52+
if (err) {
53+
console.error(err.stack || err.message);
54+
}
55+
process.exit(1);
56+
});
57+

src/compiler/binder.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,9 @@ namespace ts {
586586
}
587587

588588
function jsdocTreatAsExported(node: Node) {
589+
if (node.parent && isModuleDeclaration(node)) {
590+
node = node.parent;
591+
}
589592
if (!isJSDocTypeAlias(node)) return false;
590593
// jsdoc typedef handling is a bit of a doozy, but to summarize, treat the typedef as exported if:
591594
// 1. It has an explicit name (since by default typedefs are always directly exported, either at the top level or in a container), or

src/compiler/builder.ts

Lines changed: 53 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ namespace ts {
274274
result.relatedInformation = relatedInformation ?
275275
relatedInformation.length ?
276276
relatedInformation.map(r => convertToDiagnosticRelatedInformation(r, newProgram, toPath)) :
277-
emptyArray :
277+
[] :
278278
undefined;
279279
return result;
280280
});
@@ -824,7 +824,7 @@ namespace ts {
824824
result.relatedInformation = relatedInformation ?
825825
relatedInformation.length ?
826826
relatedInformation.map(r => convertToReusableDiagnosticRelatedInformation(r, relativeToBuildInfo)) :
827-
emptyArray :
827+
[] :
828828
undefined;
829829
return result;
830830
});
@@ -900,7 +900,7 @@ namespace ts {
900900
/**
901901
* Computing hash to for signature verification
902902
*/
903-
const computeHash = host.createHash || generateDjb2Hash;
903+
const computeHash = maybeBind(host, host.createHash);
904904
let state = createBuilderProgramState(newProgram, getCanonicalFileName, oldState);
905905
let backupState: BuilderProgramState | undefined;
906906
newProgram.getProgramBuildInfo = () => getProgramBuildInfo(state, getCanonicalFileName);
@@ -1019,31 +1019,57 @@ namespace ts {
10191019
* in that order would be used to write the files
10201020
*/
10211021
function emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback, cancellationToken?: CancellationToken, emitOnlyDtsFiles?: boolean, customTransformers?: CustomTransformers): EmitResult {
1022+
let restorePendingEmitOnHandlingNoEmitSuccess = false;
1023+
let savedAffectedFilesPendingEmit;
1024+
let savedAffectedFilesPendingEmitKind;
1025+
let savedAffectedFilesPendingEmitIndex;
1026+
// Backup and restore affected pendings emit state for non emit Builder if noEmitOnError is enabled and emitBuildInfo could be written in case there are errors
1027+
// This ensures pending files to emit is updated in tsbuildinfo
1028+
// Note that when there are no errors, emit proceeds as if everything is emitted as it is callers reponsibility to write the files to disk if at all (because its builder that doesnt track files to emit)
1029+
if (kind !== BuilderProgramKind.EmitAndSemanticDiagnosticsBuilderProgram &&
1030+
!targetSourceFile &&
1031+
!outFile(state.compilerOptions) &&
1032+
!state.compilerOptions.noEmit &&
1033+
state.compilerOptions.noEmitOnError) {
1034+
restorePendingEmitOnHandlingNoEmitSuccess = true;
1035+
savedAffectedFilesPendingEmit = state.affectedFilesPendingEmit && state.affectedFilesPendingEmit.slice();
1036+
savedAffectedFilesPendingEmitKind = state.affectedFilesPendingEmitKind && new Map(state.affectedFilesPendingEmitKind);
1037+
savedAffectedFilesPendingEmitIndex = state.affectedFilesPendingEmitIndex;
1038+
}
1039+
10221040
if (kind === BuilderProgramKind.EmitAndSemanticDiagnosticsBuilderProgram) {
10231041
assertSourceFileOkWithoutNextAffectedCall(state, targetSourceFile);
1024-
const result = handleNoEmitOptions(builderProgram, targetSourceFile, writeFile, cancellationToken);
1025-
if (result) return result;
1026-
if (!targetSourceFile) {
1027-
// Emit and report any errors we ran into.
1028-
let sourceMaps: SourceMapEmitResult[] = [];
1029-
let emitSkipped = false;
1030-
let diagnostics: Diagnostic[] | undefined;
1031-
let emittedFiles: string[] = [];
1032-
1033-
let affectedEmitResult: AffectedFileResult<EmitResult>;
1034-
while (affectedEmitResult = emitNextAffectedFile(writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers)) {
1035-
emitSkipped = emitSkipped || affectedEmitResult.result.emitSkipped;
1036-
diagnostics = addRange(diagnostics, affectedEmitResult.result.diagnostics);
1037-
emittedFiles = addRange(emittedFiles, affectedEmitResult.result.emittedFiles);
1038-
sourceMaps = addRange(sourceMaps, affectedEmitResult.result.sourceMaps);
1039-
}
1040-
return {
1041-
emitSkipped,
1042-
diagnostics: diagnostics || emptyArray,
1043-
emittedFiles,
1044-
sourceMaps
1045-
};
1042+
}
1043+
const result = handleNoEmitOptions(builderProgram, targetSourceFile, writeFile, cancellationToken);
1044+
if (result) return result;
1045+
1046+
if (restorePendingEmitOnHandlingNoEmitSuccess) {
1047+
state.affectedFilesPendingEmit = savedAffectedFilesPendingEmit;
1048+
state.affectedFilesPendingEmitKind = savedAffectedFilesPendingEmitKind;
1049+
state.affectedFilesPendingEmitIndex = savedAffectedFilesPendingEmitIndex;
1050+
}
1051+
1052+
// Emit only affected files if using builder for emit
1053+
if (!targetSourceFile && kind === BuilderProgramKind.EmitAndSemanticDiagnosticsBuilderProgram) {
1054+
// Emit and report any errors we ran into.
1055+
let sourceMaps: SourceMapEmitResult[] = [];
1056+
let emitSkipped = false;
1057+
let diagnostics: Diagnostic[] | undefined;
1058+
let emittedFiles: string[] = [];
1059+
1060+
let affectedEmitResult: AffectedFileResult<EmitResult>;
1061+
while (affectedEmitResult = emitNextAffectedFile(writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers)) {
1062+
emitSkipped = emitSkipped || affectedEmitResult.result.emitSkipped;
1063+
diagnostics = addRange(diagnostics, affectedEmitResult.result.diagnostics);
1064+
emittedFiles = addRange(emittedFiles, affectedEmitResult.result.emittedFiles);
1065+
sourceMaps = addRange(sourceMaps, affectedEmitResult.result.sourceMaps);
10461066
}
1067+
return {
1068+
emitSkipped,
1069+
diagnostics: diagnostics || emptyArray,
1070+
emittedFiles,
1071+
sourceMaps
1072+
};
10471073
}
10481074
return Debug.checkDefined(state.program).emit(targetSourceFile, writeFile || maybeBind(host, host.writeFile), cancellationToken, emitOnlyDtsFiles, customTransformers);
10491075
}
@@ -1069,7 +1095,8 @@ namespace ts {
10691095
}
10701096

10711097
// Add file to affected file pending emit to handle for later emit time
1072-
if (kind === BuilderProgramKind.EmitAndSemanticDiagnosticsBuilderProgram) {
1098+
// Apart for emit builder do this for tsbuildinfo, do this for non emit builder when noEmit is set as tsbuildinfo is written and reused between emitters
1099+
if (kind === BuilderProgramKind.EmitAndSemanticDiagnosticsBuilderProgram || state.compilerOptions.noEmit || state.compilerOptions.noEmitOnError) {
10731100
addToAffectedFilesPendingEmit(state, (affected as SourceFile).resolvedPath, BuilderFileEmit.Full);
10741101
}
10751102

src/compiler/builderState.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ namespace ts {
7777
/**
7878
* Compute the hash to store the shape of the file
7979
*/
80-
export type ComputeHash = (data: string) => string;
80+
export type ComputeHash = ((data: string) => string) | undefined;
8181

8282
/**
8383
* Exported modules to from declaration emit being computed.
@@ -337,7 +337,7 @@ namespace ts {
337337
emitOutput.outputFiles.length > 0 ? emitOutput.outputFiles[0] : undefined;
338338
if (firstDts) {
339339
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))}`);
340-
latestSignature = computeHash(firstDts.text);
340+
latestSignature = (computeHash || generateDjb2Hash)(firstDts.text);
341341
if (exportedModulesMapCache && latestSignature !== prevSignature) {
342342
updateExportedModules(sourceFile, emitOutput.exportedModulesFromDeclarationEmit, exportedModulesMapCache);
343343
}
@@ -521,7 +521,7 @@ namespace ts {
521521
/**
522522
* When program emits modular code, gets the files affected by the sourceFile whose shape has changed
523523
*/
524-
function getFilesAffectedByUpdatedShapeWhenModuleEmit(state: BuilderState, programOfThisState: Program, sourceFileWithUpdatedShape: SourceFile, cacheToUpdateSignature: ESMap<Path, string>, cancellationToken: CancellationToken | undefined, computeHash: ComputeHash | undefined, exportedModulesMapCache: ComputingExportedModulesMap | undefined) {
524+
function getFilesAffectedByUpdatedShapeWhenModuleEmit(state: BuilderState, programOfThisState: Program, sourceFileWithUpdatedShape: SourceFile, cacheToUpdateSignature: ESMap<Path, string>, cancellationToken: CancellationToken | undefined, computeHash: ComputeHash, exportedModulesMapCache: ComputingExportedModulesMap | undefined) {
525525
if (isFileAffectingGlobalScope(sourceFileWithUpdatedShape)) {
526526
return getAllFilesExcludingDefaultLibraryFile(state, programOfThisState, sourceFileWithUpdatedShape);
527527
}
@@ -544,13 +544,12 @@ namespace ts {
544544
if (!seenFileNamesMap.has(currentPath)) {
545545
const currentSourceFile = programOfThisState.getSourceFileByPath(currentPath)!;
546546
seenFileNamesMap.set(currentPath, currentSourceFile);
547-
if (currentSourceFile && updateShapeSignature(state, programOfThisState, currentSourceFile, cacheToUpdateSignature, cancellationToken, computeHash!, exportedModulesMapCache)) { // TODO: GH#18217
547+
if (currentSourceFile && updateShapeSignature(state, programOfThisState, currentSourceFile, cacheToUpdateSignature, cancellationToken, computeHash, exportedModulesMapCache)) {
548548
queue.push(...getReferencedByPaths(state, currentSourceFile.resolvedPath));
549549
}
550550
}
551551
}
552552

553-
// Return array of values that needs emit
554553
// Return array of values that needs emit
555554
return arrayFrom(mapDefinedIterator(seenFileNamesMap.values(), value => value));
556555
}

0 commit comments

Comments
 (0)