Skip to content

Bump TS devDep to 5.3, hack dtsBundler to remove new comments #56554

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"playwright": "^1.38.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this reminds me that we devdep on playwright =(

Copy link
Member Author

@jakebailey jakebailey Nov 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a big deal; as of 1.38 the package only depends on playwright-core (which is dependency free) and does not install browsers unless requested. The pair of packages is 2-3x smaller than the TypeScript package itself. I actually added this intentionally to simplify our builds once the change was made.

"source-map-support": "^0.5.21",
"tslib": "^2.5.0",
"typescript": "^5.0.2",
"typescript": "^5.3.2",
"which": "^2.0.2"
},
"overrides": {
Expand Down
28 changes: 26 additions & 2 deletions scripts/dtsBundler.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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<ts.Symbol, boolean>} */
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down