Skip to content

Commit f0f9a95

Browse files
alexander-akaitclaude
authored andcommitted
fix(javascript): declare the function-body wrap helpers on the printer's types
Claude-Session: https://claude.ai/code/session_015gdnghKbLJ7VvJ5nNCNHhH
1 parent af2b787 commit f0f9a95

2 files changed

Lines changed: 13 additions & 8 deletions

File tree

‎lib/javascript/syntax-printer.js‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,8 @@ const NO_NODE = /** @type {Node} */ (/** @type {Node | null} */ (null));
888888
* @property {(self: Node) => boolean} usesArguments whether a function reads `arguments`
889889
* @property {(self: Node, name: string) => Node} wrapCommonjs the toplevel wrapped as a CommonJS module
890890
* @property {(self: Node, argsValues: boolean | string) => Node} wrapEnclose the toplevel wrapped in a function called at once
891+
* @property {(self: Node) => Node} wrapFunctionBody a function's body, read as a toplevel, wrapped back in a function
892+
* @property {(self: Node) => Node} unwrapFunctionBody the toplevel `wrapFunctionBody` answered, holding that function's body again
891893
* @property {(self: Node) => Node[]} argsAsNames the names a function's parameters bind
892894
* @property {(self: Node) => Node | false | undefined} isBraceless the expression an arrow's body is, where it has no braces
893895
* @property {(self: Node) => number} lengthProperty a function's `length`
@@ -3516,7 +3518,7 @@ const installNodes = (modules) => {
35163518
self,
35173519
createWalker((/** @type {Node} */ node) => {
35183520
if (isSymbolRefNode(node) || isSymbolDeclarationNode(node)) {
3519-
const runs = /** @type {string} */ (node.name).match(/_+/g);
3521+
const runs = node.name.match(/_+/g);
35203522
if (runs !== null) {
35213523
for (const run of runs) longest = Math.max(longest, run.length);
35223524
}
@@ -9720,7 +9722,10 @@ const installMinify = (modules) => {
97209722
setShorthand("warnings", options, ["compress"]);
97219723
// The function a body is compressed in is the one statement kept.
97229724
if (functionBody && options.compress) {
9723-
options.compress = { ...options.compress, toplevel: false };
9725+
options.compress = {
9726+
.../** @type {Partial<CompressOptions>} */ (options.compress),
9727+
toplevel: false
9728+
};
97249729
}
97259730
/** @type {string[] | undefined} */
97269731
let quotedProperties;

‎test/unitCases/javascript/printer.unittest.js‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14979,14 +14979,14 @@ describe("JavaScript minifier reading an event handler's body", () => {
1497914979

1498014980
it("should read a module or a script as `module` says", async () => {
1498114981
const { minify } = await load();
14982-
for (const [source, sourceType, module] of [
14982+
/** @type {[string, "module" | "script", boolean][]} */
14983+
const cases = [
1498314984
["export const a = 1; let b = 2; f(b)", "module", true],
1498414985
["let b = 2; f(b)", "script", false]
14985-
]) {
14986-
const given = await minify(source, {
14987-
sourceType: /** @type {"module" | "script"} */ (sourceType)
14988-
});
14989-
const reference = await minify(source, { module: Boolean(module) });
14986+
];
14987+
for (const [source, sourceType, module] of cases) {
14988+
const given = await minify(source, { sourceType });
14989+
const reference = await minify(source, { module });
1499014990
expect(given.code).toBe(reference.code);
1499114991
}
1499214992
});

0 commit comments

Comments
 (0)