fix(formatter): expand large structured prop defaults
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
// Generated by scripts/build-editor-compiler.mjs. Do not edit directly.
|
||||
// WRN editor compiler source hash: 884c9faffb5517c907321484014e00562654ea0ba96e432bec319e0001934446
|
||||
// WRN editor compiler source hash: edac5449f97a341e79ee7bf7e7f3676f42bbb4ec6aac4432f5ace9ff88f4f85c
|
||||
// WRN editor compiler generator hash: f8c1094b47e695151205899de28cd63d574356d26ac49219c4a43db0f2391ef5
|
||||
// Generated with TypeScript: 6.0.3
|
||||
const __nodeRequire = require;
|
||||
@@ -6227,6 +6227,26 @@ function expandStructuredStateDeclarations(lines, unit) {
|
||||
}
|
||||
});
|
||||
}
|
||||
function formatStructuredPropDeclaration(value, unit, depth, printWidth) {
|
||||
const match = /^([A-Za-z_$][\w$]*\??\s*(?::\s*[^=]+?)?\s*=\s*)([\[{][\s\S]*)$/.exec(value);
|
||||
if (!match)
|
||||
return null;
|
||||
try {
|
||||
const parsed = JSON.parse(match[2].trim());
|
||||
const compact = JSON.stringify(parsed);
|
||||
const indentation = unit.repeat(depth);
|
||||
if (indentation.length + match[1].length + compact.length <= printWidth)
|
||||
return null;
|
||||
const jsonLines = JSON.stringify(parsed, null, unit).split("\n");
|
||||
return [
|
||||
`${indentation}${match[1]}${jsonLines[0]}`,
|
||||
...jsonLines.slice(1).map((jsonLine) => `${indentation}${jsonLine}`),
|
||||
];
|
||||
}
|
||||
catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
function formatWrnPass(source, options = {}) {
|
||||
const unit = options.insertSpaces === false ? "\t" : " ".repeat(options.tabSize ?? 4);
|
||||
const printWidth = options.printWidth ?? 100;
|
||||
@@ -6282,6 +6302,12 @@ function formatWrnPass(source, options = {}) {
|
||||
index += 1;
|
||||
continue;
|
||||
}
|
||||
const structuredProp = formatStructuredPropDeclaration(value, unit, codeDepth + htmlDepth + controlDepth, printWidth);
|
||||
if (structuredProp) {
|
||||
output.push(...structuredProp);
|
||||
index += 1;
|
||||
continue;
|
||||
}
|
||||
const leadingClosingBraces = countLeadingClosingBraces(value);
|
||||
const closesControlBlock = isControlBlockClose(value);
|
||||
const continuesControlBlock = isControlBlockMiddle(value);
|
||||
|
||||
Reference in New Issue
Block a user