release: WRNexusJS 0.2.77

This commit is contained in:
2026-07-22 01:26:10 +05:30
parent 569365143b
commit 7ff5b3e8c5
95 changed files with 1077 additions and 177 deletions
+93
View File
@@ -17,6 +17,91 @@ const VOID_ELEMENTS = new Set([
"wbr",
]);
function splitPropDeclarations(value) {
const declarations = [];
let start = 0;
let index = 0;
let quote = null;
let escaped = false;
let square = 0;
let brace = 0;
let paren = 0;
const isIdentifierStart = (character) => /[A-Za-z_]/.test(character || "");
const isIdentifierPart = (character) => /[A-Za-z0-9_]/.test(character || "");
const beginsDeclaration = (position) => {
let cursor = position;
while (cursor < value.length && /[ \t]/.test(value[cursor])) cursor += 1;
if (!isIdentifierStart(value[cursor])) return false;
cursor += 1;
while (cursor < value.length && isIdentifierPart(value[cursor])) cursor += 1;
while (cursor < value.length && /[ \t]/.test(value[cursor])) cursor += 1;
return value[cursor] === "=" || value[cursor] === ":";
};
while (index < value.length) {
const character = value[index];
if (quote !== null) {
if (escaped) escaped = false;
else if (character === "\\") escaped = true;
else if (character === quote) quote = null;
index += 1;
continue;
}
if (character === '"' || character === "'" || character === "`") {
quote = character;
index += 1;
continue;
}
if (character === "[") square += 1;
else if (character === "]" && square > 0) square -= 1;
else if (character === "{") brace += 1;
else if (character === "}" && brace > 0) brace -= 1;
else if (character === "(") paren += 1;
else if (character === ")" && paren > 0) paren -= 1;
if (
square === 0 &&
brace === 0 &&
paren === 0 &&
/\s/.test(character) &&
beginsDeclaration(index)
) {
const declaration = value.slice(start, index).trim();
if (declaration) declarations.push(declaration);
while (index < value.length && /\s/.test(value[index])) index += 1;
start = index;
continue;
}
index += 1;
}
const declaration = value.slice(start).trim();
if (declaration) declarations.push(declaration);
return declarations;
}
function formatInlinePropsBlock(value, unit, depth) {
const match = /^props\s*\{([\s\S]*)\}$/.exec(value.trim());
if (!match) return null;
const declarations = splitPropDeclarations(match[1].trim());
if (declarations.length === 0) {
return [`${unit.repeat(depth)}props {`, `${unit.repeat(depth)}}`];
}
return [
`${unit.repeat(depth)}props {`,
...declarations.map((declaration) => `${unit.repeat(depth + 1)}${declaration}`),
`${unit.repeat(depth)}}`,
];
}
function findOpeningTagEnd(value) {
let quote = null;
let escaped = false;
@@ -347,6 +432,13 @@ function formatWrn(source, options = {}) {
index = collected.endIndex;
}
const inlineProps = formatInlinePropsBlock(value, unit, codeDepth + htmlDepth);
if (inlineProps) {
output.push(...inlineProps);
index += 1;
continue;
}
const leadingClosingBraces = countLeadingClosingBraces(value);
const lineCodeDepth = Math.max(0, codeDepth - leadingClosingBraces);
@@ -405,4 +497,5 @@ module.exports = {
formatWrn,
parseAttributes,
parseOpeningTag,
splitPropDeclarations,
};