release: WRNexusJS 0.3.2

This commit is contained in:
2026-07-22 20:10:44 +05:30
parent 304819dfe9
commit 58ba2f2046
63 changed files with 242 additions and 121 deletions
+32 -19
View File
@@ -602,10 +602,11 @@ function generate(ast) {
seedScope[entry.name] = undefined;
}
}
const reactiveNames = [...ast.states.map((entry) => entry.name), ...ast.computed.map((entry) => entry.name)];
const reactive = reactiveNames.length > 0
? { stateNames: new Set(reactiveNames), scope: seedScope }
: null;
const reactiveNames = [
...ast.states.map((entry) => entry.name),
...ast.computed.map((entry) => entry.name),
];
const reactive = reactiveNames.length > 0 ? { stateNames: new Set(reactiveNames), scope: seedScope } : null;
const loops = [];
let html = ast.view
.map((node) => renderNode(node, ssrBindings, csrBindings, apiBindings, loops, reactive))
@@ -613,7 +614,10 @@ function generate(ast) {
const styles = ast.styles.map((body) => body.trim()).filter(Boolean);
const pageBehavior = ast.runtime === "server" ? null : componentBehavior(ast);
const needsClientRuntime = ast.runtime !== "server" &&
(ast.states.length > 0 || ast.computed.length > 0 || hasClientBehavior(ast.view) || pageBehavior !== null);
(ast.states.length > 0 ||
ast.computed.length > 0 ||
hasClientBehavior(ast.view) ||
pageBehavior !== null);
if (needsClientRuntime) {
const scopePlaceholder = "__WRNEXUS_DYNAMIC_SCOPE__";
html = `<div data-scope="${scopePlaceholder}"${behaviorAttribute(pageBehavior)}${hydrationAttribute(ast)}>${html}</div>`;
@@ -721,7 +725,9 @@ function generate(ast) {
out.push(`export async function __wrnexusLoad(ctx: any) {\n${serverLoads.map((entry) => entry.body).join("\n")}\n}`);
}
if (clientLoads.length > 0) {
out.push(`export const __wrnexusClientLoad = ${JSON.stringify(clientLoads.map((entry) => entry.body))};`);
out.push(`export async function __wrnexusClientLoad(ctx: any) {
${clientLoads.map((entry) => entry.body).join("\n")}
}`);
}
}
if (ast.actions.length > 0) {
@@ -1200,7 +1206,10 @@ function generateComponent(ast) {
// no JavaScript at all.
const behavior = componentBehavior(ast);
const needsScope = ast.runtime !== "server" &&
(ast.states.length > 0 || ast.computed.length > 0 || viewHasEvents(ast.view) || behavior !== null);
(ast.states.length > 0 ||
ast.computed.length > 0 ||
viewHasEvents(ast.view) ||
behavior !== null);
const scopeKeys = [
...effectiveProps.map((prop) => prop.name),
...ast.states.map((state) => state.name),
@@ -1220,7 +1229,11 @@ function generateComponent(ast) {
decls.push(` const ${nameRefs.get(entry.name)} = (${resolveExpr(entry.expr)});`);
}
const returnExpr = needsScope
? "`" + styleTag + `<div data-scope="\${__scope}"${behaviorAttr}${hydrationAttribute(ast)}>` + viewCode + "</div>`"
? "`" +
styleTag +
`<div data-scope="\${__scope}"${behaviorAttr}${hydrationAttribute(ast)}>` +
viewCode +
"</div>`"
: "`" + styleTag + viewCode + "`";
const scopeLine = needsScope && scopeKeys.length > 0
? ` const __scope = __wrnexusScopeDecl({ ${scopeKeys
@@ -1948,7 +1961,7 @@ function astDiagnostics(ast, options) {
code: spec_ts_1.WRN_DIAGNOSTIC_CODES.accessibility,
severity: "warning",
message: "Image is missing an alt attribute.",
hint: "Add alt text, or alt=\"\" for a decorative image.",
hint: 'Add alt text, or alt="" for a decorative image.',
file: options.file,
});
}
@@ -1958,7 +1971,7 @@ function astDiagnostics(ast, options) {
code: spec_ts_1.WRN_DIAGNOSTIC_CODES.serverInteractive,
severity: "error",
message: "A server-only WRN root cannot contain client state, effects, watches, or event handlers.",
hint: "Use runtime = \"universal\" or remove interactive behavior.",
hint: 'Use runtime = "universal" or remove interactive behavior.',
file: options.file,
});
}
@@ -1989,8 +2002,14 @@ function isRuntimeTarget(value) {
function formatDiagnostic(source, diagnostic) {
const location = diagnostic.position
? `${diagnostic.file ?? "<inline .wrn>"}:${diagnostic.position.line}:${diagnostic.position.column}`
: diagnostic.file ?? "<inline .wrn>";
const lines = [`${diagnostic.code} ${diagnostic.severity.toUpperCase()}`, "", diagnostic.message, "", location];
: (diagnostic.file ?? "<inline .wrn>");
const lines = [
`${diagnostic.code} ${diagnostic.severity.toUpperCase()}`,
"",
diagnostic.message,
"",
location,
];
if (diagnostic.position) {
const sourceLine = source.split(/\r?\n/)[diagnostic.position.line - 1] ?? "";
lines.push("", sourceLine, `${" ".repeat(Math.max(0, diagnostic.position.column - 1))}^`);
@@ -2829,13 +2848,7 @@ exports.WRN_ROOT_MEMBERS = [
"style",
"functions",
];
exports.WRN_HYDRATION_STRATEGIES = [
"load",
"idle",
"visible",
"interaction",
"none",
];
exports.WRN_HYDRATION_STRATEGIES = ["load", "idle", "visible", "interaction", "none"];
exports.WRN_RUNTIME_TARGETS = ["server", "client", "universal"];
exports.WRN_DIAGNOSTIC_CODES = {
parse: "WRN-PARSE-001",