Skip to content

Commit 6ab3057

Browse files
committed
Merge branch 'main' into custom-transformers
2 parents 05b1015 + 08285ab commit 6ab3057

File tree

551 files changed

+47657
-6107
lines changed

Some content is hidden

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

551 files changed

+47657
-6107
lines changed

Diff for: .github/ISSUE_TEMPLATE/Bug_report.md

+3-5
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,16 @@ Please keep and fill in the line that best applies:
4343
### ⏯ Playground Link
4444

4545
<!--
46-
A link to a TypeScript Playground "Share" link which shows this behavior
47-
48-
The TypeScript Workbench can be used for more complex setups, try
49-
https://www.typescriptlang.org/dev/bug-workbench/
46+
A link to a TypeScript Playground "Share" link which shows this behavior.
47+
This should have the same code as the code snippet below, and use whichever settings are relevant to your report.
5048
5149
As a last resort, you can link to a repo, but these will be slower for us to investigate.
5250
-->
5351
[Playground link with relevant code](https://www.typescriptlang.org/play?#code/PTAEFkE9QYwewCYFNQHM5IM6gBZIE5JA)
5452

5553
### 💻 Code
5654

57-
<!-- Please post the relevant code sample here as well-->
55+
<!-- Please post the relevant code sample here as well. This code and the Playground code should be the same, do not use separate examples -->
5856
```ts
5957
// We can quickly address your report if:
6058
// - The code sample is short. Nearly all TypeScript bugs can be demonstrated in 20-30 lines of code!

Diff for: .github/workflows/ci.yml

+28-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
strategy:
2121
matrix:
2222
node-version:
23-
- "19"
23+
- "20"
2424
- "18"
2525
- "16"
2626
- "14"
@@ -202,3 +202,30 @@ jobs:
202202

203203
- name: Self build
204204
run: npx hereby build-src --built
205+
206+
unused-baselines:
207+
runs-on: ubuntu-latest
208+
209+
steps:
210+
- uses: actions/checkout@v3
211+
- uses: actions/setup-node@v3
212+
with:
213+
node-version: "*"
214+
check-latest: true
215+
- run: npm ci
216+
217+
- name: Remove all baselines
218+
run: rm -rf tests/baselines/reference
219+
220+
- name: Run tests
221+
run: npm test &> /dev/null || exit 0
222+
223+
- name: Accept baselines
224+
run: npx hereby baseline-accept
225+
226+
- name: Check for unused baselines
227+
run: |
228+
if ! git diff --exit-code --quiet; then
229+
echo "Unused baselines:"
230+
git diff --exit-code --name-only
231+
fi

Diff for: Herebyfile.mjs

-1
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,6 @@ export const runTestsAndWatch = task({
627627
});
628628

629629
process.on("SIGINT", endWatchMode);
630-
process.on("SIGKILL", endWatchMode);
631630
process.on("beforeExit", endWatchMode);
632631
watchTestsEmitter.on("rebuild", onRebuild);
633632
testCaseWatcher.on("all", onChange);

Diff for: package-lock.json

+188-188
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+4-6
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,7 @@
8383
"which": "^2.0.2"
8484
},
8585
"overrides": {
86-
"typescript@*": "$typescript",
87-
"@octokit/types": "9.0.0",
88-
"@octokit/openapi-types": "16.0.0"
86+
"typescript@*": "$typescript"
8987
},
9088
"scripts": {
9189
"test": "hereby runtests-parallel --light=false",
@@ -110,9 +108,9 @@
110108
"source-map-support": false,
111109
"inspector": false
112110
},
113-
"packageManager": "[email protected].3",
111+
"packageManager": "[email protected].4",
114112
"volta": {
115-
"node": "14.21.1",
116-
"npm": "8.19.3"
113+
"node": "20.1.0",
114+
"npm": "8.19.4"
117115
}
118116
}

Diff for: src/compiler/builder.ts

+91-4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
convertToOptionsWithAbsolutePaths,
2323
createBuildInfo,
2424
createGetCanonicalFileName,
25+
createModuleNotFoundChain,
2526
createProgram,
2627
CustomTransformers,
2728
Debug,
@@ -68,8 +69,11 @@ import {
6869
ProjectReference,
6970
ReadBuildProgramHost,
7071
ReadonlyCollection,
72+
RepopulateDiagnosticChainInfo,
73+
RepopulateModuleNotFoundDiagnosticChain,
7174
returnFalse,
7275
returnUndefined,
76+
sameMap,
7377
SemanticDiagnosticsBuilderProgram,
7478
skipTypeChecking,
7579
some,
@@ -103,7 +107,18 @@ export interface ReusableDiagnosticRelatedInformation {
103107
}
104108

105109
/** @internal */
106-
export type ReusableDiagnosticMessageChain = DiagnosticMessageChain;
110+
export interface ReusableRepopulateModuleNotFoundChain {
111+
info: RepopulateModuleNotFoundDiagnosticChain;
112+
next?: ReusableDiagnosticMessageChain[];
113+
}
114+
115+
/** @internal */
116+
export type SerializedDiagnosticMessageChain = Omit<DiagnosticMessageChain, "next" | "repopulateInfo"> & {
117+
next?: ReusableDiagnosticMessageChain[];
118+
};
119+
120+
/** @internal */
121+
export type ReusableDiagnosticMessageChain = SerializedDiagnosticMessageChain | ReusableRepopulateModuleNotFoundChain;
107122

108123
/**
109124
* Signature (Hash of d.ts emitted), is string if it was emitted using same d.ts.map option as what compilerOptions indicate, otherwise tuple of string
@@ -364,7 +379,12 @@ function createBuilderProgramState(newProgram: Program, oldState: Readonly<Reusa
364379
// Unchanged file copy diagnostics
365380
const diagnostics = oldState!.semanticDiagnosticsPerFile!.get(sourceFilePath);
366381
if (diagnostics) {
367-
state.semanticDiagnosticsPerFile!.set(sourceFilePath, oldState!.hasReusableDiagnostic ? convertToDiagnostics(diagnostics as readonly ReusableDiagnostic[], newProgram) : diagnostics as readonly Diagnostic[]);
382+
state.semanticDiagnosticsPerFile!.set(
383+
sourceFilePath,
384+
oldState!.hasReusableDiagnostic ?
385+
convertToDiagnostics(diagnostics as readonly ReusableDiagnostic[], newProgram) :
386+
repopulateDiagnostics(diagnostics as readonly Diagnostic[], newProgram)
387+
);
368388
if (!state.semanticDiagnosticsFromOldState) {
369389
state.semanticDiagnosticsFromOldState = new Set();
370390
}
@@ -448,6 +468,43 @@ function getEmitSignatureFromOldSignature(options: CompilerOptions, oldOptions:
448468
isString(oldEmitSignature) ? [oldEmitSignature] : oldEmitSignature[0];
449469
}
450470

471+
function repopulateDiagnostics(diagnostics: readonly Diagnostic[], newProgram: Program): readonly Diagnostic[] {
472+
if (!diagnostics.length) return diagnostics;
473+
return sameMap(diagnostics, diag => {
474+
if (isString(diag.messageText)) return diag;
475+
const repopulatedChain = convertOrRepopulateDiagnosticMessageChain(diag.messageText, diag.file, newProgram, chain => chain.repopulateInfo?.());
476+
return repopulatedChain === diag.messageText ?
477+
diag :
478+
{ ...diag, messageText: repopulatedChain };
479+
});
480+
}
481+
482+
function convertOrRepopulateDiagnosticMessageChain<T extends DiagnosticMessageChain | ReusableDiagnosticMessageChain>(
483+
chain: T,
484+
sourceFile: SourceFile | undefined,
485+
newProgram: Program,
486+
repopulateInfo: (chain: T) => RepopulateDiagnosticChainInfo | undefined,
487+
): DiagnosticMessageChain {
488+
const info = repopulateInfo(chain);
489+
if (info) {
490+
return {
491+
...createModuleNotFoundChain(sourceFile!, newProgram, info.moduleReference, info.mode, info.packageName || info.moduleReference),
492+
next: convertOrRepopulateDiagnosticMessageChainArray(chain.next as T[], sourceFile, newProgram, repopulateInfo),
493+
};
494+
}
495+
const next = convertOrRepopulateDiagnosticMessageChainArray(chain.next as T[], sourceFile, newProgram, repopulateInfo);
496+
return next === chain.next ? chain as DiagnosticMessageChain : { ...chain as DiagnosticMessageChain, next };
497+
}
498+
499+
function convertOrRepopulateDiagnosticMessageChainArray<T extends DiagnosticMessageChain | ReusableDiagnosticMessageChain>(
500+
array: T[] | undefined,
501+
sourceFile: SourceFile | undefined,
502+
newProgram: Program,
503+
repopulateInfo: (chain: T) => RepopulateDiagnosticChainInfo | undefined,
504+
): DiagnosticMessageChain[] | undefined {
505+
return sameMap(array, chain => convertOrRepopulateDiagnosticMessageChain(chain, sourceFile, newProgram, repopulateInfo));
506+
}
507+
451508
function convertToDiagnostics(diagnostics: readonly ReusableDiagnostic[], newProgram: Program): readonly Diagnostic[] {
452509
if (!diagnostics.length) return emptyArray;
453510
let buildInfoDirectory: string | undefined;
@@ -474,9 +531,13 @@ function convertToDiagnostics(diagnostics: readonly ReusableDiagnostic[], newPro
474531

475532
function convertToDiagnosticRelatedInformation(diagnostic: ReusableDiagnosticRelatedInformation, newProgram: Program, toPath: (path: string) => Path): DiagnosticRelatedInformation {
476533
const { file } = diagnostic;
534+
const sourceFile = file ? newProgram.getSourceFileByPath(toPath(file)) : undefined;
477535
return {
478536
...diagnostic,
479-
file: file ? newProgram.getSourceFileByPath(toPath(file)) : undefined
537+
file: sourceFile,
538+
messageText: isString(diagnostic.messageText) ?
539+
diagnostic.messageText :
540+
convertOrRepopulateDiagnosticMessageChain(diagnostic.messageText, sourceFile, newProgram, chain => (chain as ReusableRepopulateModuleNotFoundChain).info),
480541
};
481542
}
482543

@@ -1232,10 +1293,36 @@ function convertToReusableDiagnosticRelatedInformation(diagnostic: DiagnosticRel
12321293
const { file } = diagnostic;
12331294
return {
12341295
...diagnostic,
1235-
file: file ? relativeToBuildInfo(file.resolvedPath) : undefined
1296+
file: file ? relativeToBuildInfo(file.resolvedPath) : undefined,
1297+
messageText: isString(diagnostic.messageText) ? diagnostic.messageText : convertToReusableDiagnosticMessageChain(diagnostic.messageText),
12361298
};
12371299
}
12381300

1301+
function convertToReusableDiagnosticMessageChain(chain: DiagnosticMessageChain): ReusableDiagnosticMessageChain {
1302+
if (chain.repopulateInfo) {
1303+
return {
1304+
info: chain.repopulateInfo(),
1305+
next: convertToReusableDiagnosticMessageChainArray(chain.next),
1306+
};
1307+
}
1308+
const next = convertToReusableDiagnosticMessageChainArray(chain.next);
1309+
return next === chain.next ? chain : { ...chain, next };
1310+
}
1311+
1312+
function convertToReusableDiagnosticMessageChainArray(array: DiagnosticMessageChain[] | undefined): ReusableDiagnosticMessageChain[] | undefined {
1313+
if (!array) return array;
1314+
return forEach(array, (chain, index) => {
1315+
const reusable = convertToReusableDiagnosticMessageChain(chain);
1316+
if (chain === reusable) return undefined;
1317+
const result: ReusableDiagnosticMessageChain[] = index > 0 ? array.slice(0, index - 1) : [];
1318+
result.push(reusable);
1319+
for (let i = index + 1; i < array.length; i++) {
1320+
result.push(convertToReusableDiagnosticMessageChain(array[i]));
1321+
}
1322+
return result;
1323+
}) || array;
1324+
}
1325+
12391326
/** @internal */
12401327
export enum BuilderProgramKind {
12411328
SemanticDiagnosticsBuilderProgram,

0 commit comments

Comments
 (0)