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
+1 -1
View File
@@ -2,7 +2,7 @@
"name": "wrnexus",
"displayName": "WRNexus Language Support",
"description": "Complete language support for WRNexus .wrn files, including highlighting, formatting, diagnostics, snippets, lifecycle hooks, state watchers, component functions, completions, and definition navigation.",
"version": "0.2.14",
"version": "0.2.15",
"publisher": "wrnexus",
"private": true,
"license": "SEE LICENSE IN LICENSE",
+66 -1
View File
@@ -173,6 +173,71 @@ class Lexer {
v += src[this.pos++];
return v.trim();
}
readPropInitializer() {
const { src } = this;
let value = "";
let square = 0;
let brace = 0;
let paren = 0;
let quote = null;
const beginsPropDeclaration = (position) => {
let cursor = position;
while (cursor < src.length && (src[cursor] === " " || src[cursor] === "\t"))
cursor++;
if (!isIdentStart(src[cursor] ?? ""))
return false;
cursor++;
while (cursor < src.length && isIdentPart(src[cursor]))
cursor++;
while (cursor < src.length && (src[cursor] === " " || src[cursor] === "\t"))
cursor++;
return src[cursor] === "=" || src[cursor] === ":";
};
while (this.pos < src.length) {
const c = src[this.pos];
if (quote) {
value += c;
this.pos++;
if (c === "\\" && this.pos < src.length)
value += src[this.pos++];
else if (c === quote)
quote = null;
continue;
}
if (c === '"' || c === "'" || c === "`") {
quote = c;
value += c;
this.pos++;
continue;
}
if (c === "[")
square++;
else if (c === "]" && square > 0)
square--;
else if (c === "{")
brace++;
else if (c === "}" && brace > 0)
brace--;
else if (c === "(")
paren++;
else if (c === ")" && paren > 0)
paren--;
const topLevel = square === 0 && brace === 0 && paren === 0;
if (topLevel) {
if (c === `
` || c === "\r" || c === "}")
break;
if ((c === " " || c === "\t") && beginsPropDeclaration(this.pos))
break;
}
value += c;
this.pos++;
}
const result = value.trim();
if (!result)
throw new LexError(`Expected a prop initializer at offset ${this.pos}`);
return result;
}
readTypeAnnotation() {
const { src } = this;
let value = "";
@@ -471,7 +536,7 @@ function parse(source) {
expect("eq");
hasDefault = true;
}
const defaultValue = hasDefault ? lx.readToLineEnd() : "undefined";
const defaultValue = hasDefault ? lx.readPropInitializer() : "undefined";
props.push({ name: pName, valueType, required: !hasDefault, default: defaultValue });
}
expect("rbrace");
+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,
};
+21
View File
@@ -0,0 +1,21 @@
"use strict";
const assert = require("node:assert");
const { test } = require("node:test");
const { formatWrn } = require("../src/formatter");
test("formats compact props blocks with one prop per line", () => {
const source = `component Header {\nprops { eyebrow = "" title = "" description = "" align = "start" class = "" }\nview { <header>{title}</header> }\n}\n`;
const expected = `component Header {\n props {\n eyebrow = ""\n title = ""\n description = ""\n align = "start"\n class = ""\n }\n view { <header>{title}</header> }\n}\n`;
assert.equal(formatWrn(source, { insertSpaces: true, tabSize: 2 }), expected);
});
test("preserves nested prop defaults while formatting", () => {
const source = `component Grid {\nprops { items = [{ label: "A" }, { label: "B" }] options = { gap: 4, dense: false } class = "" }\nview { <div/> }\n}\n`;
const formatted = formatWrn(source, { insertSpaces: true, tabSize: 2 });
assert.match(formatted, /items = \[\{ label: "A" \}, \{ label: "B" \}\]/);
assert.match(formatted, /options = \{ gap: 4, dense: false \}/);
assert.equal(formatWrn(formatted, { insertSpaces: true, tabSize: 2 }), formatted);
});