From b334e073d54b46308aac0f214425fb70b6cd0310 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Mon, 27 Nov 2023 09:26:24 -0800 Subject: [PATCH] Bump TS devDep to 5.3, hack dtsBundler to remove new comments (#56554) --- package-lock.json | 14 +++++++------- package.json | 2 +- scripts/dtsBundler.mjs | 28 ++++++++++++++++++++++++++-- src/compiler/checker.ts | 2 +- 4 files changed, 35 insertions(+), 11 deletions(-) diff --git a/package-lock.json b/package-lock.json index c4ace9d407527..24142ab495e6a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -52,7 +52,7 @@ "playwright": "^1.38.0", "source-map-support": "^0.5.21", "tslib": "^2.5.0", - "typescript": "^5.0.2", + "typescript": "^5.3.2", "which": "^2.0.2" }, "engines": { @@ -3786,9 +3786,9 @@ } }, "node_modules/typescript": { - "version": "5.2.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz", - "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==", + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.2.tgz", + "integrity": "sha512-6l+RyNy7oAHDfxC4FzSJcz9vnjTKxrLpDG5M2Vu4SHRVNg6xzqZp6LYSR9zjqQTu8DU/f5xwxUdADOkbrIX2gQ==", "dev": true, "bin": { "tsc": "bin/tsc", @@ -6584,9 +6584,9 @@ } }, "typescript": { - "version": "5.2.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz", - "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==", + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.2.tgz", + "integrity": "sha512-6l+RyNy7oAHDfxC4FzSJcz9vnjTKxrLpDG5M2Vu4SHRVNg6xzqZp6LYSR9zjqQTu8DU/f5xwxUdADOkbrIX2gQ==", "dev": true }, "typical": { diff --git a/package.json b/package.json index 7d77358cb65f1..bea908972e9a3 100644 --- a/package.json +++ b/package.json @@ -78,7 +78,7 @@ "playwright": "^1.38.0", "source-map-support": "^0.5.21", "tslib": "^2.5.0", - "typescript": "^5.0.2", + "typescript": "^5.3.2", "which": "^2.0.2" }, "overrides": { diff --git a/scripts/dtsBundler.mjs b/scripts/dtsBundler.mjs index 7edbc635e7194..0593545aa4bb3 100644 --- a/scripts/dtsBundler.mjs +++ b/scripts/dtsBundler.mjs @@ -89,7 +89,31 @@ assert(sourceFile, "Failed to load source file"); const moduleSymbol = typeChecker.getSymbolAtLocation(sourceFile); assert(moduleSymbol, "Failed to get module's symbol"); -const printer = ts.createPrinter({ newLine: newLineKind }); +/** @type {{ writeNode(hint: ts.EmitHint, node: ts.Node, sourceFile: ts.SourceFile | undefined, writer: any): void }} */ +const printer = /** @type {any} */ (ts.createPrinter({ newLine: newLineKind })); +/** @type {{ writeComment(s: string): void; getText(): string; clear(): void }} */ +const writer = /** @type {any} */ (ts).createTextWriter("\n"); +const originalWriteComment = writer.writeComment.bind(writer); +writer.writeComment = s => { + // Hack; undo https://github.com/microsoft/TypeScript/pull/50097 + // We printNode directly, so we get all of the original source comments. + // If we were using actual declaration emit instead, this wouldn't be needed. + if (s.startsWith("//")) { + return; + } + originalWriteComment(s); +}; + +/** + * @param {ts.Node} node + * @param {ts.SourceFile} sourceFile + */ +function printNode(node, sourceFile) { + printer.writeNode(ts.EmitHint.Unspecified, node, sourceFile, writer); + const text = writer.getText(); + writer.clear(); + return text; +} /** @type {string[]} */ const publicLines = []; @@ -141,7 +165,7 @@ function write(s, target) { * @param {WriteTarget} target */ function writeNode(node, sourceFile, target) { - write(printer.printNode(ts.EmitHint.Unspecified, node, sourceFile), target); + write(printNode(node, sourceFile), target); } /** @type {Map} */ diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 985b0f4968670..3a8d1e736f000 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3147,7 +3147,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { else if (location.kind === SyntaxKind.ConditionalType) { // A type parameter declared using 'infer T' in a conditional type is visible only in // the true branch of the conditional type. - useResult = lastLocation === (location as ConditionalTypeNode).trueType; + useResult = lastLocation === location.trueType; } if (useResult) {