Skip to content

Commit 9f8bfca

Browse files
style(javascript): keep the printer's untouched lines as main formats them
Claude-Session: https://claude.ai/code/session_01Tgxgyb4N35ndP6cC4KcrXC
1 parent 3ed2cdd commit 9f8bfca

1 file changed

Lines changed: 11 additions & 50 deletions

File tree

‎lib/javascript/syntax-printer.js‎

Lines changed: 11 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1785,20 +1785,12 @@ const reachChildren = (children, reach, backwards) =>
17851785
let statement;
17861786
if (kind === "*") {
17871787
statement = backwards
1788-
? `{ var i${index} = ${value}.length; while (i${index}--) ${reach(
1789-
`${value}[i${index}]`
1790-
)} }`
1791-
: `{ var list${index} = ${value}; for (var i${index} = 0, len${index} = list${index}.length; i${index} < len${index}; i${index}++) ${reach(
1792-
`list${index}[i${index}]`
1793-
)} }`;
1788+
? `{ var i${index} = ${value}.length; while (i${index}--) ${reach(`${value}[i${index}]`)} }`
1789+
: `{ var list${index} = ${value}; for (var i${index} = 0, len${index} = list${index}.length; i${index} < len${index}; i${index}++) ${reach(`list${index}[i${index}]`)} }`;
17941790
} else if (kind === "+") {
17951791
statement = backwards
1796-
? `{ var i${index} = ${value}.length; while (i${index}--) if (${value}[i${index}] !== null) ${reach(
1797-
`${value}[i${index}]`
1798-
)} }`
1799-
: `{ var list${index} = ${value}; for (var i${index} = 0, len${index} = list${index}.length; i${index} < len${index}; i${index}++) if (list${index}[i${index}] !== null) ${reach(
1800-
`list${index}[i${index}]`
1801-
)} }`;
1792+
? `{ var i${index} = ${value}.length; while (i${index}--) if (${value}[i${index}] !== null) ${reach(`${value}[i${index}]`)} }`
1793+
: `{ var list${index} = ${value}; for (var i${index} = 0, len${index} = list${index}.length; i${index} < len${index}; i${index}++) if (list${index}[i${index}] !== null) ${reach(`list${index}[i${index}]`)} }`;
18021794
} else if (kind === "~") {
18031795
statement = `if (isSyntaxNode(${value})) ${reach(value)}`;
18041796
} else if (kind === "^") {
@@ -1840,20 +1832,12 @@ const installTraversal = (ast) => {
18401832
descend: new Function(
18411833
"isSyntaxNode",
18421834
"walkNode",
1843-
`"use strict"; return function descend(node, visitor) {${reachChildren(
1844-
walk,
1845-
(value) => `walkNode(${value}, visitor);`,
1846-
false
1847-
)}};`
1835+
`"use strict"; return function descend(node, visitor) {${reachChildren(walk, (value) => `walkNode(${value}, visitor);`, false)}};`
18481836
)(isSyntaxNode, walkNode),
18491837
// eslint-disable-next-line no-new-func
18501838
backwards: new Function(
18511839
"isSyntaxNode",
1852-
`"use strict"; return function backwards(node, push) {${reachChildren(
1853-
backwards,
1854-
(value) => `push(${value});`,
1855-
true
1856-
)}};`
1840+
`"use strict"; return function backwards(node, push) {${reachChildren(backwards, (value) => `push(${value});`, true)}};`
18571841
)(isSyntaxNode)
18581842
});
18591843
/**
@@ -4492,9 +4476,7 @@ const installScope = (modules) => {
44924476
}
44934477
if (kind & SCOPE_MODULE_STATEMENT && !isToplevelNode(scope)) {
44944478
jsError(
4495-
`"${
4496-
isExportNode(node) ? "Export" : ast.kindOf(node)
4497-
}" statement may only appear at the top level`,
4479+
`"${isExportNode(node) ? "Export" : ast.kindOf(node)}" statement may only appear at the top level`,
44984480
node.startToken.file,
44994481
node.startToken.line,
45004482
node.startToken.col,
@@ -7653,9 +7635,7 @@ const installMinify = (modules) => {
76537635
throw err;
76547636
}
76557637
}
7656-
const logPath = `${debugFolder}/terser-debug-${
7657-
(Math.random() * 9999999) | 0
7658-
}.log`;
7638+
const logPath = `${debugFolder}/terser-debug-${(Math.random() * 9999999) | 0}.log`;
76597639
options = options || {};
76607640
const optionsText = JSON.stringify(
76617641
options,
@@ -8168,9 +8148,7 @@ class ParsedToken {
81688148
const special = (text) => options.stylize(text, "special");
81698149
const quote =
81708150
typeof this.value === "string" && this.value.includes("`") ? "'" : "`";
8171-
return `${special("[ParsedToken")} ${quote}${this.value}${quote} at ${
8172-
this.line
8173-
}:${this.col}${special("]")}`;
8151+
return `${special("[ParsedToken")} ${quote}${this.value}${quote} at ${this.line}:${this.col}${special("]")}`;
81748152
}
81758153

81768154
/**
@@ -10321,15 +10299,7 @@ const compileNodeFactory = (ast, entry) => {
1032110299
"NO_PROPS",
1032210300
"PROTOTYPE",
1032310301
"PRIVATE_PROTOTYPE",
10324-
`"use strict"; function Kind(${props}) { ${parts.join(
10325-
" "
10326-
)} } Kind.prototype = PROTOTYPE; function PrivateKind(${props}) { ${parts.join(
10327-
" "
10328-
)} } PrivateKind.prototype = PRIVATE_PROTOTYPE; return function ${plainIdentifier(
10329-
classNameOf(kind)
10330-
)}(props) { ${
10331-
entry.unguarded ? "" : "const p = props || NO_PROPS;"
10332-
} const node = ${made}; ${label} return node; };`
10302+
`"use strict"; function Kind(${props}) { ${parts.join(" ")} } Kind.prototype = PROTOTYPE; function PrivateKind(${props}) { ${parts.join(" ")} } PrivateKind.prototype = PRIVATE_PROTOTYPE; return function ${plainIdentifier(classNameOf(kind))}(props) { ${entry.unguarded ? "" : "const p = props || NO_PROPS;"} const node = ${made}; ${label} return node; };`
1033310303
)(
1033410304
values,
1033510305
(/** @type {Node} */ block) => ast.factoryOf(block)(block),
@@ -13875,16 +13845,7 @@ class SourceToken {
1387513845
* @returns {string} the token, as Node's console shows it
1387613846
*/
1387713847
[Symbol.for("nodejs.util.inspect.custom")](_depth, options) {
13878-
return `ParsedToken { type: ${options.stylize(
13879-
JSON.stringify(this.type),
13880-
"string"
13881-
)}, value: ${options.stylize(
13882-
JSON.stringify(this.value),
13883-
"string"
13884-
)}, line: ${options.stylize(
13885-
String(this.line),
13886-
"number"
13887-
)}, col: ${options.stylize(String(this.col), "number")} }`;
13848+
return `ParsedToken { type: ${options.stylize(JSON.stringify(this.type), "string")}, value: ${options.stylize(JSON.stringify(this.value), "string")}, line: ${options.stylize(String(this.line), "number")}, col: ${options.stylize(String(this.col), "number")} }`;
1388813849
}
1388913850
}
1389013851

0 commit comments

Comments
 (0)