Skip to content

Commit b334e07

Browse files
authored
Bump TS devDep to 5.3, hack dtsBundler to remove new comments (#56554)
1 parent d4fbc9b commit b334e07

File tree

4 files changed

+35
-11
lines changed

4 files changed

+35
-11
lines changed

package-lock.json

Lines changed: 7 additions & 7 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
@@ -78,7 +78,7 @@
7878
"playwright": "^1.38.0",
7979
"source-map-support": "^0.5.21",
8080
"tslib": "^2.5.0",
81-
"typescript": "^5.0.2",
81+
"typescript": "^5.3.2",
8282
"which": "^2.0.2"
8383
},
8484
"overrides": {

scripts/dtsBundler.mjs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,31 @@ assert(sourceFile, "Failed to load source file");
8989
const moduleSymbol = typeChecker.getSymbolAtLocation(sourceFile);
9090
assert(moduleSymbol, "Failed to get module's symbol");
9191

92-
const printer = ts.createPrinter({ newLine: newLineKind });
92+
/** @type {{ writeNode(hint: ts.EmitHint, node: ts.Node, sourceFile: ts.SourceFile | undefined, writer: any): void }} */
93+
const printer = /** @type {any} */ (ts.createPrinter({ newLine: newLineKind }));
94+
/** @type {{ writeComment(s: string): void; getText(): string; clear(): void }} */
95+
const writer = /** @type {any} */ (ts).createTextWriter("\n");
96+
const originalWriteComment = writer.writeComment.bind(writer);
97+
writer.writeComment = s => {
98+
// Hack; undo https://github.com/microsoft/TypeScript/pull/50097
99+
// We printNode directly, so we get all of the original source comments.
100+
// If we were using actual declaration emit instead, this wouldn't be needed.
101+
if (s.startsWith("//")) {
102+
return;
103+
}
104+
originalWriteComment(s);
105+
};
106+
107+
/**
108+
* @param {ts.Node} node
109+
* @param {ts.SourceFile} sourceFile
110+
*/
111+
function printNode(node, sourceFile) {
112+
printer.writeNode(ts.EmitHint.Unspecified, node, sourceFile, writer);
113+
const text = writer.getText();
114+
writer.clear();
115+
return text;
116+
}
93117

94118
/** @type {string[]} */
95119
const publicLines = [];
@@ -141,7 +165,7 @@ function write(s, target) {
141165
* @param {WriteTarget} target
142166
*/
143167
function writeNode(node, sourceFile, target) {
144-
write(printer.printNode(ts.EmitHint.Unspecified, node, sourceFile), target);
168+
write(printNode(node, sourceFile), target);
145169
}
146170

147171
/** @type {Map<ts.Symbol, boolean>} */

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3147,7 +3147,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
31473147
else if (location.kind === SyntaxKind.ConditionalType) {
31483148
// A type parameter declared using 'infer T' in a conditional type is visible only in
31493149
// the true branch of the conditional type.
3150-
useResult = lastLocation === (location as ConditionalTypeNode).trueType;
3150+
useResult = lastLocation === location.trueType;
31513151
}
31523152

31533153
if (useResult) {

0 commit comments

Comments
 (0)