@torpor/view 1.3.0 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/compile.cjs +19 -25
- package/dist/compile.d.cts +3 -2
- package/dist/compile.d.cts.map +1 -1
- package/dist/compile.d.mts +3 -2
- package/dist/compile.d.mts.map +1 -1
- package/dist/compile.mjs +19 -25
- package/dist/compile.mjs.map +1 -1
- package/dist/index.cjs +152 -34
- package/dist/index.d.cts +46 -9
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +46 -9
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +152 -34
- package/dist/index.mjs.map +1 -1
- package/dist/runtime.iife.js +1 -1
- package/dist/ssr.cjs +15 -0
- package/dist/ssr.d.cts +12 -1
- package/dist/ssr.d.cts.map +1 -1
- package/dist/ssr.d.mts +12 -1
- package/dist/ssr.d.mts.map +1 -1
- package/dist/ssr.mjs +15 -1
- package/dist/ssr.mjs.map +1 -1
- package/package.json +1 -1
package/dist/compile.cjs
CHANGED
|
@@ -488,10 +488,11 @@ function addPopDevBoundary(status, b) {
|
|
|
488
488
|
function addPushDevBoundary(type, name, status, b) {
|
|
489
489
|
if (status.options.dev === true) {
|
|
490
490
|
status.imports.add("t_push_dev_bound");
|
|
491
|
+
name = name.replace(/\s+/g, " ");
|
|
491
492
|
if (name.startsWith("'") && name.endsWith("'") || name.startsWith("\"") && name.endsWith("\"") || name.startsWith("`") && name.endsWith("`")) {
|
|
492
493
|
const quote = name[0];
|
|
493
494
|
name = quote + name.substring(1, name.length - 1).replaceAll(quote, "\\" + quote) + quote;
|
|
494
|
-
} else name =
|
|
495
|
+
} else name = JSON.stringify(name);
|
|
495
496
|
b.append(`t_push_dev_bound("${type}", ${name});`);
|
|
496
497
|
b.append("");
|
|
497
498
|
}
|
|
@@ -597,7 +598,7 @@ function isReactive(text) {
|
|
|
597
598
|
function trimQuotes(text) {
|
|
598
599
|
let start = 0;
|
|
599
600
|
let end = text.length;
|
|
600
|
-
while (text[start] === "'" && text[end - 1] === "'" || text[start] === "\"" && text[end - 1] === "\"" || text[start] === "`" && text[end - 1] === "`") {
|
|
601
|
+
while (start < end && (text[start] === "'" && text[end - 1] === "'" || text[start] === "\"" && text[end - 1] === "\"" || text[start] === "`" && text[end - 1] === "`")) {
|
|
601
602
|
start += 1;
|
|
602
603
|
end -= 1;
|
|
603
604
|
}
|
|
@@ -2312,7 +2313,6 @@ function buildIfNode(node, status, b) {
|
|
|
2312
2313
|
status.imports.add("t_region");
|
|
2313
2314
|
status.imports.add("t_run_control");
|
|
2314
2315
|
status.imports.add("t_run_branch");
|
|
2315
|
-
status.imports.add("t_push_region");
|
|
2316
2316
|
status.imports.add("t_pop_region");
|
|
2317
2317
|
b.append("");
|
|
2318
2318
|
b.append("/* @if */");
|
|
@@ -2330,12 +2330,9 @@ function buildIfNode(node, status, b) {
|
|
|
2330
2330
|
}
|
|
2331
2331
|
function buildIfBranch(node, status, b, parentName, regionName, indexName, index) {
|
|
2332
2332
|
addMappedText("", `${node.statement}`, " {", node.span, status, b);
|
|
2333
|
-
b.append(`
|
|
2333
|
+
b.append(`const t_old_region = t_run_branch(${regionName}, ${indexName}, ${index}${status.options.dev === true ? `, "if_branch"` : ""});`);
|
|
2334
|
+
b.append("if (t_old_region === null) return;");
|
|
2334
2335
|
if (node.children.length > 0) {
|
|
2335
|
-
b.append(`
|
|
2336
|
-
const t_new_region = t_region(${status.options.dev === true ? `"if_branch"` : ""});
|
|
2337
|
-
const t_old_region = t_push_region(t_new_region, true);
|
|
2338
|
-
`);
|
|
2339
2336
|
buildFragment(node, status, b, parentName, "t_before");
|
|
2340
2337
|
status.fragmentStack.push({
|
|
2341
2338
|
fragment: node.fragment,
|
|
@@ -2344,8 +2341,8 @@ function buildIfBranch(node, status, b, parentName, regionName, indexName, index
|
|
|
2344
2341
|
for (let child of node.children) buildNode(child, status, b, parentName, "t_before");
|
|
2345
2342
|
status.fragmentStack.pop();
|
|
2346
2343
|
buildAddFragment(node, status, b, parentName, "t_before");
|
|
2347
|
-
b.append("t_pop_region(t_old_region);");
|
|
2348
2344
|
}
|
|
2345
|
+
b.append("t_pop_region(t_old_region);");
|
|
2349
2346
|
b.append(`${indexName} = ${index};`);
|
|
2350
2347
|
b.append("}");
|
|
2351
2348
|
}
|
|
@@ -2359,7 +2356,6 @@ function buildReplaceNode(node, status, b) {
|
|
|
2359
2356
|
status.imports.add("t_region");
|
|
2360
2357
|
status.imports.add("t_run_control");
|
|
2361
2358
|
status.imports.add("t_run_branch");
|
|
2362
|
-
status.imports.add("t_push_region");
|
|
2363
2359
|
status.imports.add("t_pop_region");
|
|
2364
2360
|
b.append("");
|
|
2365
2361
|
b.append(`
|
|
@@ -2372,13 +2368,9 @@ function buildReplaceNode(node, status, b) {
|
|
|
2372
2368
|
b.append("");
|
|
2373
2369
|
}
|
|
2374
2370
|
function buildReplaceBranch(node, status, b, parentName, regionName) {
|
|
2375
|
-
status.imports.add("t_run_branch");
|
|
2376
2371
|
b.append(`${node.statement};`);
|
|
2377
|
-
b.append(`
|
|
2378
|
-
b.append(
|
|
2379
|
-
const t_new_region = t_region(${status.options.dev === true ? `"replace_branch"` : ""});
|
|
2380
|
-
const t_old_region = t_push_region(t_new_region, true);
|
|
2381
|
-
`);
|
|
2372
|
+
b.append(`const t_old_region = t_run_branch(${regionName}, 0, -1${status.options.dev === true ? `, "replace_branch"` : ""});`);
|
|
2373
|
+
b.append("if (t_old_region === null) return;");
|
|
2382
2374
|
buildFragment(node, status, b, parentName, "t_before");
|
|
2383
2375
|
status.fragmentStack.push({
|
|
2384
2376
|
fragment: node.fragment,
|
|
@@ -2422,7 +2414,6 @@ function buildSwitchNode(node, status, b) {
|
|
|
2422
2414
|
status.imports.add("t_region");
|
|
2423
2415
|
status.imports.add("t_run_control");
|
|
2424
2416
|
status.imports.add("t_run_branch");
|
|
2425
|
-
status.imports.add("t_push_region");
|
|
2426
2417
|
status.imports.add("t_pop_region");
|
|
2427
2418
|
b.append("");
|
|
2428
2419
|
b.append("/* @switch */");
|
|
@@ -2443,12 +2434,9 @@ function buildSwitchNode(node, status, b) {
|
|
|
2443
2434
|
}
|
|
2444
2435
|
function buildSwitchBranch(node, status, b, parentName, regionName, indexName, index) {
|
|
2445
2436
|
addMappedText("", `${node.statement}`, " {", node.span, status, b);
|
|
2446
|
-
b.append(`
|
|
2437
|
+
b.append(`const t_old_region = t_run_branch(${regionName}, ${indexName}, ${index}${status.options.dev === true ? `, "switch_branch"` : ""});`);
|
|
2438
|
+
b.append("if (t_old_region === null) return;");
|
|
2447
2439
|
if (node.children.length > 0) {
|
|
2448
|
-
b.append(`
|
|
2449
|
-
const t_new_region = t_region(${status.options.dev === true ? `"switch_branch"` : ""});
|
|
2450
|
-
const t_old_region = t_push_region(t_new_region, true);
|
|
2451
|
-
`);
|
|
2452
2440
|
buildFragment(node, status, b, parentName, "t_before");
|
|
2453
2441
|
status.fragmentStack.push({
|
|
2454
2442
|
fragment: node.fragment,
|
|
@@ -2457,8 +2445,8 @@ function buildSwitchBranch(node, status, b, parentName, regionName, indexName, i
|
|
|
2457
2445
|
for (let child of node.children) buildNode(child, status, b, parentName, "t_before");
|
|
2458
2446
|
status.fragmentStack.pop();
|
|
2459
2447
|
buildAddFragment(node, status, b, parentName, "t_before");
|
|
2460
|
-
b.append("t_pop_region(t_old_region);");
|
|
2461
2448
|
}
|
|
2449
|
+
b.append("t_pop_region(t_old_region);");
|
|
2462
2450
|
b.append(`
|
|
2463
2451
|
${indexName} = ${index};
|
|
2464
2452
|
break;
|
|
@@ -3153,6 +3141,7 @@ function buildCode(template, map, options, errors = [], warnings = []) {
|
|
|
3153
3141
|
let imports = /* @__PURE__ */ new Set();
|
|
3154
3142
|
imports.add("SlotRender");
|
|
3155
3143
|
buildTemplate(template, map, imports, b, options, errors, warnings);
|
|
3144
|
+
if (imports.has("t_next") && !b.toString().includes("t_next(")) imports.delete("t_next");
|
|
3156
3145
|
let startSize = b.toString().length;
|
|
3157
3146
|
if (imports.size) {
|
|
3158
3147
|
const folder = options?.renderFolder ?? "@torpor/view";
|
|
@@ -3676,8 +3665,8 @@ function buildElementAttributes(node, status) {
|
|
|
3676
3665
|
status.imports.add("t_style");
|
|
3677
3666
|
attributes.push(`\${t_style(${value})}`);
|
|
3678
3667
|
} else {
|
|
3679
|
-
status.imports.add("
|
|
3680
|
-
attributes.push(`\${(${
|
|
3668
|
+
status.imports.add("t_attr_if");
|
|
3669
|
+
attributes.push(`\${t_attr_if("${name}", ${value})}`);
|
|
3681
3670
|
}
|
|
3682
3671
|
} else if (value != null && reactive) {
|
|
3683
3672
|
status.imports.add("t_attr");
|
|
@@ -3823,6 +3812,7 @@ const importsMap = {
|
|
|
3823
3812
|
t_await_server: "import { t_await_server } from \"${folder}\";",
|
|
3824
3813
|
t_fmt: "import { t_fmt } from \"${folder}\";",
|
|
3825
3814
|
t_attr: "import { t_attr } from \"${folder}\";",
|
|
3815
|
+
t_attr_if: "import { t_attr_if } from \"${folder}\";",
|
|
3826
3816
|
t_class: "import { t_class } from \"${folder}\";",
|
|
3827
3817
|
t_style: "import { t_style } from \"${folder}\";",
|
|
3828
3818
|
t_slot_guard: "import { t_slot_guard } from \"${folder}\";",
|
|
@@ -5928,6 +5918,10 @@ function parseControlOpen(status) {
|
|
|
5928
5918
|
if (operation === "@replace" || operation === "@html") statement = trimMatched(statement.substring(statement.indexOf("(")).trim(), "(", ")");
|
|
5929
5919
|
if (operation === "@await" && /^await\s*\(/.test(statement)) addError(status, "old `@await (expr) { … } then (…) { … }` syntax is removed — use `@await { … } with { … }` with `$async` getters", start, status.i);
|
|
5930
5920
|
} else {
|
|
5921
|
+
if (/^@[a-zA-Z]+</.test(operation)) {
|
|
5922
|
+
addError(status, `Unknown operation: ${operation}. A literal '@' in text must be escaped as '@'`, start, status.i);
|
|
5923
|
+
return null;
|
|
5924
|
+
}
|
|
5931
5925
|
addError(status, `Unknown operation: ${operation}`, status.i, status.i + operation.length);
|
|
5932
5926
|
return null;
|
|
5933
5927
|
}
|
package/dist/compile.d.cts
CHANGED
|
@@ -317,8 +317,9 @@ interface RestrictedStaticAttribute {
|
|
|
317
317
|
/**
|
|
318
318
|
* A dynamic attribute: the value is an expression evaluated at render time.
|
|
319
319
|
*
|
|
320
|
-
* - `format: "attr"` —
|
|
321
|
-
* server build's conditional attribute behavior
|
|
320
|
+
* - `format: "attr"` — dropped for null/undefined/false, HTML-escaped
|
|
321
|
+
* otherwise (matches the JS server build's conditional attribute behavior;
|
|
322
|
+
* empty string and 0 still render).
|
|
322
323
|
* - `format: "class"` — class value semantics (arrays/objects); `scoped` is
|
|
323
324
|
* the component's style-hash class to append.
|
|
324
325
|
* - `format: "style"` — style value semantics (objects/arrays).
|
package/dist/compile.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile.d.cts","names":["_$______types_CompileError0.default"],"sources":["../src/compile/types/Import.ts","../src/compile/types/SourceSpan.ts","../src/compile/types/ScriptChunk.ts","../src/compile/types/nodes/Fragment.ts","../src/compile/types/nodes/NodeType.ts","../src/compile/types/nodes/TemplateNode.ts","../src/compile/types/nodes/ParentNode.ts","../src/compile/types/nodes/RootNode.ts","../src/compile/types/styles/StyleNode.ts","../src/compile/types/styles/Style.ts","../src/types/TemplateComponent.ts","../src/types/Template.ts","../src/compile/types/BuildOptions.ts","../src/compile/types/CompileError.ts","../src/compile/types/SourceMapping.ts","../src/compile/types/BuildResult.ts","../src/compile/build.ts","../src/compile/build/restricted/types.ts","../src/compile/build/restricted/buildRestricted.ts","../src/compile/buildType.ts","../src/compile/types/ParseResult.ts","../src/compile/parse.ts","../src/compile/parse/bindDataTemplate.ts","../src/compile/build/restricted/parseExpression.ts"],"mappings":";;UAAyB;EACxB;EACA;EACA;EACA;EACA;;;;UCLwB;EACxB;EACA;;;;UCAwB;EACxB;EACA,MAAM;;;;UCFkB;EACxB;EACA;EACA;EACA;IACC;IACA,OAAO;IACP;IACA;IACA;;EAED;IACC;IACA;IACA;;EAED;EACA;;;;;;;EAOA;;;;;;;;;;EAUA;;;;;;;;;EASA;;;;KC7CI;;;UCEoB;EACxB,MAAM;EAGN;EAKA;EAKA;;;;UCbwB,mBAAmB;EAC3C,MAAM;EACN,UAAU;;;;UCDc,iBAAiB;EACzC;EACA,UAAU;EAGV,WAAW;;;;UCTa;EACxB;EACA;;;;UCAwB;EACxB;EACA,UAAU;EACV;;;;UCFwB;EACxB;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;EACA,SAAS;;EAET,QAAQ;;EAER;EACA,OAAO;EACP,QAAQ;;EAER;;EAEA;;EAEA;;EAEA;;EAEA;;;;;;;UC1BwB;EACxB,SAAS;EACT,QAAQ;EACR,YAAY;;;;UCVY;;;;EAIxB;;;;EAIA;;;;EAIA;;;;;;;EAOA;;;;EAIA;;;;;;;;EAQA;;;;;;EAMA;;;;UCrCwB;EACxB;EACA;EACA;EACA;EACA;EACA;EACA;;;;UCLwB;EACxB;EACA,QAAQ;EACR,UAAU;;;;UCFc;EACxB;EACA;IACC;IACA;;EAED,KAAK;EACL,QAAQ;;;;;;EAMR,UAAU;;;;;;;;;;;iBCCa,MAAM,UAAU,UAAU,UAAU,eAAe;;;;;;;;;;;;;;KCL/D;KACA;KAkBA;;;;;;;;;;;KAYA;EACP;EAAW,OAAO;;EAClB;EAAW;;EACX;EAAW,QAAQ;EAAgB;EAAa;;EAChD;EAAa,QAAQ;EAAgB,OAAO;EAAgB;;EAK5D;EAAY;EAAc,MAAM;;EAChC;EAAa,UAAU;EAAyB,SAAS;;EAE3D;EACA,UAAU;EACV,MAAM;EACN,OAAO;;EAEL;EAAe,MAAM;EAAgB,YAAY;EAAgB,WAAW;;EAC5E;EAAa,OAAO;;EACpB;EAAc,SAAS,eAAe;;;;;;UAM1B;EAChB;EACA;;;;;;EAMA
|
|
1
|
+
{"version":3,"file":"compile.d.cts","names":["_$______types_CompileError0.default"],"sources":["../src/compile/types/Import.ts","../src/compile/types/SourceSpan.ts","../src/compile/types/ScriptChunk.ts","../src/compile/types/nodes/Fragment.ts","../src/compile/types/nodes/NodeType.ts","../src/compile/types/nodes/TemplateNode.ts","../src/compile/types/nodes/ParentNode.ts","../src/compile/types/nodes/RootNode.ts","../src/compile/types/styles/StyleNode.ts","../src/compile/types/styles/Style.ts","../src/types/TemplateComponent.ts","../src/types/Template.ts","../src/compile/types/BuildOptions.ts","../src/compile/types/CompileError.ts","../src/compile/types/SourceMapping.ts","../src/compile/types/BuildResult.ts","../src/compile/build.ts","../src/compile/build/restricted/types.ts","../src/compile/build/restricted/buildRestricted.ts","../src/compile/buildType.ts","../src/compile/types/ParseResult.ts","../src/compile/parse.ts","../src/compile/parse/bindDataTemplate.ts","../src/compile/build/restricted/parseExpression.ts"],"mappings":";;UAAyB;EACxB;EACA;EACA;EACA;EACA;;;;UCLwB;EACxB;EACA;;;;UCAwB;EACxB;EACA,MAAM;;;;UCFkB;EACxB;EACA;EACA;EACA;IACC;IACA,OAAO;IACP;IACA;IACA;;EAED;IACC;IACA;IACA;;EAED;EACA;;;;;;;EAOA;;;;;;;;;;EAUA;;;;;;;;;EASA;;;;KC7CI;;;UCEoB;EACxB,MAAM;EAGN;EAKA;EAKA;;;;UCbwB,mBAAmB;EAC3C,MAAM;EACN,UAAU;;;;UCDc,iBAAiB;EACzC;EACA,UAAU;EAGV,WAAW;;;;UCTa;EACxB;EACA;;;;UCAwB;EACxB;EACA,UAAU;EACV;;;;UCFwB;EACxB;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;EACA,SAAS;;EAET,QAAQ;;EAER;EACA,OAAO;EACP,QAAQ;;EAER;;EAEA;;EAEA;;EAEA;;EAEA;;;;;;;UC1BwB;EACxB,SAAS;EACT,QAAQ;EACR,YAAY;;;;UCVY;;;;EAIxB;;;;EAIA;;;;EAIA;;;;;;;EAOA;;;;EAIA;;;;;;;;EAQA;;;;;;EAMA;;;;UCrCwB;EACxB;EACA;EACA;EACA;EACA;EACA;EACA;;;;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xB,gBACvB,UAAU,UACV,UAAU,yBACR;;;;;;;;;;;iBCrDqB,UAAU,UAAU,UAAU,UAAU;;;UCTvC;EACxB;EACA,QAAQ;EACR,WAAW;;;;;;;;;;;;iBCKY,MAAM,iBAAiB;;;;;;;;;iBCHvB,iBAAiB,UAAU;;;;;;;;;;;;;;;;;;;;;;qBCctC,8BAA8B;;EAE1C;;EAEA;EAEA,YAAY,iBAAiB,eAAe;;UAwP5B;EAChB,YAAY;;EAEZ;;UAGgB;;;;;;EAMhB;;;;;;;wBAuBe,sBACf,gBACA,iBACA,UAAU,yBACR"}
|
package/dist/compile.d.mts
CHANGED
|
@@ -317,8 +317,9 @@ interface RestrictedStaticAttribute {
|
|
|
317
317
|
/**
|
|
318
318
|
* A dynamic attribute: the value is an expression evaluated at render time.
|
|
319
319
|
*
|
|
320
|
-
* - `format: "attr"` —
|
|
321
|
-
* server build's conditional attribute behavior
|
|
320
|
+
* - `format: "attr"` — dropped for null/undefined/false, HTML-escaped
|
|
321
|
+
* otherwise (matches the JS server build's conditional attribute behavior;
|
|
322
|
+
* empty string and 0 still render).
|
|
322
323
|
* - `format: "class"` — class value semantics (arrays/objects); `scoped` is
|
|
323
324
|
* the component's style-hash class to append.
|
|
324
325
|
* - `format: "style"` — style value semantics (objects/arrays).
|
package/dist/compile.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile.d.mts","names":["_$______types_CompileError0.default"],"sources":["../src/compile/types/Import.ts","../src/compile/types/SourceSpan.ts","../src/compile/types/ScriptChunk.ts","../src/compile/types/nodes/Fragment.ts","../src/compile/types/nodes/NodeType.ts","../src/compile/types/nodes/TemplateNode.ts","../src/compile/types/nodes/ParentNode.ts","../src/compile/types/nodes/RootNode.ts","../src/compile/types/styles/StyleNode.ts","../src/compile/types/styles/Style.ts","../src/types/TemplateComponent.ts","../src/types/Template.ts","../src/compile/types/BuildOptions.ts","../src/compile/types/CompileError.ts","../src/compile/types/SourceMapping.ts","../src/compile/types/BuildResult.ts","../src/compile/build.ts","../src/compile/build/restricted/types.ts","../src/compile/build/restricted/buildRestricted.ts","../src/compile/buildType.ts","../src/compile/types/ParseResult.ts","../src/compile/parse.ts","../src/compile/parse/bindDataTemplate.ts","../src/compile/build/restricted/parseExpression.ts"],"mappings":";;UAAyB;EACxB;EACA;EACA;EACA;EACA;;;;UCLwB;EACxB;EACA;;;;UCAwB;EACxB;EACA,MAAM;;;;UCFkB;EACxB;EACA;EACA;EACA;IACC;IACA,OAAO;IACP;IACA;IACA;;EAED;IACC;IACA;IACA;;EAED;EACA;;;;;;;EAOA;;;;;;;;;;EAUA;;;;;;;;;EASA;;;;KC7CI;;;UCEoB;EACxB,MAAM;EAGN;EAKA;EAKA;;;;UCbwB,mBAAmB;EAC3C,MAAM;EACN,UAAU;;;;UCDc,iBAAiB;EACzC;EACA,UAAU;EAGV,WAAW;;;;UCTa;EACxB;EACA;;;;UCAwB;EACxB;EACA,UAAU;EACV;;;;UCFwB;EACxB;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;EACA,SAAS;;EAET,QAAQ;;EAER;EACA,OAAO;EACP,QAAQ;;EAER;;EAEA;;EAEA;;EAEA;;EAEA;;;;;;;UC1BwB;EACxB,SAAS;EACT,QAAQ;EACR,YAAY;;;;UCVY;;;;EAIxB;;;;EAIA;;;;EAIA;;;;;;;EAOA;;;;EAIA;;;;;;;;EAQA;;;;;;EAMA;;;;UCrCwB;EACxB;EACA;EACA;EACA;EACA;EACA;EACA;;;;UCLwB;EACxB;EACA,QAAQ;EACR,UAAU;;;;UCFc;EACxB;EACA;IACC;IACA;;EAED,KAAK;EACL,QAAQ;;;;;;EAMR,UAAU;;;;;;;;;;;iBCCa,MAAM,UAAU,UAAU,UAAU,eAAe;;;;;;;;;;;;;;KCL/D;KACA;KAkBA;;;;;;;;;;;KAYA;EACP;EAAW,OAAO;;EAClB;EAAW;;EACX;EAAW,QAAQ;EAAgB;EAAa;;EAChD;EAAa,QAAQ;EAAgB,OAAO;EAAgB;;EAK5D;EAAY;EAAc,MAAM;;EAChC;EAAa,UAAU;EAAyB,SAAS;;EAE3D;EACA,UAAU;EACV,MAAM;EACN,OAAO;;EAEL;EAAe,MAAM;EAAgB,YAAY;EAAgB,WAAW;;EAC5E;EAAa,OAAO;;EACpB;EAAc,SAAS,eAAe;;;;;;UAM1B;EAChB;EACA;;;;;;EAMA
|
|
1
|
+
{"version":3,"file":"compile.d.mts","names":["_$______types_CompileError0.default"],"sources":["../src/compile/types/Import.ts","../src/compile/types/SourceSpan.ts","../src/compile/types/ScriptChunk.ts","../src/compile/types/nodes/Fragment.ts","../src/compile/types/nodes/NodeType.ts","../src/compile/types/nodes/TemplateNode.ts","../src/compile/types/nodes/ParentNode.ts","../src/compile/types/nodes/RootNode.ts","../src/compile/types/styles/StyleNode.ts","../src/compile/types/styles/Style.ts","../src/types/TemplateComponent.ts","../src/types/Template.ts","../src/compile/types/BuildOptions.ts","../src/compile/types/CompileError.ts","../src/compile/types/SourceMapping.ts","../src/compile/types/BuildResult.ts","../src/compile/build.ts","../src/compile/build/restricted/types.ts","../src/compile/build/restricted/buildRestricted.ts","../src/compile/buildType.ts","../src/compile/types/ParseResult.ts","../src/compile/parse.ts","../src/compile/parse/bindDataTemplate.ts","../src/compile/build/restricted/parseExpression.ts"],"mappings":";;UAAyB;EACxB;EACA;EACA;EACA;EACA;;;;UCLwB;EACxB;EACA;;;;UCAwB;EACxB;EACA,MAAM;;;;UCFkB;EACxB;EACA;EACA;EACA;IACC;IACA,OAAO;IACP;IACA;IACA;;EAED;IACC;IACA;IACA;;EAED;EACA;;;;;;;EAOA;;;;;;;;;;EAUA;;;;;;;;;EASA;;;;KC7CI;;;UCEoB;EACxB,MAAM;EAGN;EAKA;EAKA;;;;UCbwB,mBAAmB;EAC3C,MAAM;EACN,UAAU;;;;UCDc,iBAAiB;EACzC;EACA,UAAU;EAGV,WAAW;;;;UCTa;EACxB;EACA;;;;UCAwB;EACxB;EACA,UAA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EAEhB;;EAEA;EACA,MAAM,eAAe;;UAGL;EAChB;EACA;EACA,QAAQ;;;;;;;EAOR,QAAQ;;UAGQ;EAChB;EACA,MAAM;;UAGU;;EAEhB,cAAc;EACd,YAAY;;UAGI;EAChB,SAAS;EACT;IACC;IACA;;EAED,QALSA;;UAQO;;EAEhB;;EAEA;;UAGgB;EAChB;EACA,MAAM;;EAEN;EACA;EACA;;KAGW,sCACX,MAAM,uBACN,SAAS,iBAAiB,eAAe,sBACzC,UAAU;;;UCxKM,+BAA+B;;;;;;;;;;;iBAiCxB,gBACvB,UAAU,UACV,UAAU,yBACR;;;;;;;;;;;iBCrDqB,UAAU,UAAU,UAAU,UAAU;;;UCTvC;EACxB;EACA,QAAQ;EACR,WAAW;;;;;;;;;;;;iBCKY,MAAM,iBAAiB;;;;;;;;;iBCHvB,iBAAiB,UAAU;;;;;;;;;;;;;;;;;;;;;;qBCctC,8BAA8B;;EAE1C;;EAEA;EAEA,YAAY,iBAAiB,eAAe;;UAwP5B;EAChB,YAAY;;EAEZ;;UAGgB;;;;;;EAMhB;;;;;;;wBAuBe,sBACf,gBACA,iBACA,UAAU,yBACR"}
|
package/dist/compile.mjs
CHANGED
|
@@ -487,10 +487,11 @@ function addPopDevBoundary(status, b) {
|
|
|
487
487
|
function addPushDevBoundary(type, name, status, b) {
|
|
488
488
|
if (status.options.dev === true) {
|
|
489
489
|
status.imports.add("t_push_dev_bound");
|
|
490
|
+
name = name.replace(/\s+/g, " ");
|
|
490
491
|
if (name.startsWith("'") && name.endsWith("'") || name.startsWith("\"") && name.endsWith("\"") || name.startsWith("`") && name.endsWith("`")) {
|
|
491
492
|
const quote = name[0];
|
|
492
493
|
name = quote + name.substring(1, name.length - 1).replaceAll(quote, "\\" + quote) + quote;
|
|
493
|
-
} else name =
|
|
494
|
+
} else name = JSON.stringify(name);
|
|
494
495
|
b.append(`t_push_dev_bound("${type}", ${name});`);
|
|
495
496
|
b.append("");
|
|
496
497
|
}
|
|
@@ -596,7 +597,7 @@ function isReactive(text) {
|
|
|
596
597
|
function trimQuotes(text) {
|
|
597
598
|
let start = 0;
|
|
598
599
|
let end = text.length;
|
|
599
|
-
while (text[start] === "'" && text[end - 1] === "'" || text[start] === "\"" && text[end - 1] === "\"" || text[start] === "`" && text[end - 1] === "`") {
|
|
600
|
+
while (start < end && (text[start] === "'" && text[end - 1] === "'" || text[start] === "\"" && text[end - 1] === "\"" || text[start] === "`" && text[end - 1] === "`")) {
|
|
600
601
|
start += 1;
|
|
601
602
|
end -= 1;
|
|
602
603
|
}
|
|
@@ -2311,7 +2312,6 @@ function buildIfNode(node, status, b) {
|
|
|
2311
2312
|
status.imports.add("t_region");
|
|
2312
2313
|
status.imports.add("t_run_control");
|
|
2313
2314
|
status.imports.add("t_run_branch");
|
|
2314
|
-
status.imports.add("t_push_region");
|
|
2315
2315
|
status.imports.add("t_pop_region");
|
|
2316
2316
|
b.append("");
|
|
2317
2317
|
b.append("/* @if */");
|
|
@@ -2329,12 +2329,9 @@ function buildIfNode(node, status, b) {
|
|
|
2329
2329
|
}
|
|
2330
2330
|
function buildIfBranch(node, status, b, parentName, regionName, indexName, index) {
|
|
2331
2331
|
addMappedText("", `${node.statement}`, " {", node.span, status, b);
|
|
2332
|
-
b.append(`
|
|
2332
|
+
b.append(`const t_old_region = t_run_branch(${regionName}, ${indexName}, ${index}${status.options.dev === true ? `, "if_branch"` : ""});`);
|
|
2333
|
+
b.append("if (t_old_region === null) return;");
|
|
2333
2334
|
if (node.children.length > 0) {
|
|
2334
|
-
b.append(`
|
|
2335
|
-
const t_new_region = t_region(${status.options.dev === true ? `"if_branch"` : ""});
|
|
2336
|
-
const t_old_region = t_push_region(t_new_region, true);
|
|
2337
|
-
`);
|
|
2338
2335
|
buildFragment(node, status, b, parentName, "t_before");
|
|
2339
2336
|
status.fragmentStack.push({
|
|
2340
2337
|
fragment: node.fragment,
|
|
@@ -2343,8 +2340,8 @@ function buildIfBranch(node, status, b, parentName, regionName, indexName, index
|
|
|
2343
2340
|
for (let child of node.children) buildNode(child, status, b, parentName, "t_before");
|
|
2344
2341
|
status.fragmentStack.pop();
|
|
2345
2342
|
buildAddFragment(node, status, b, parentName, "t_before");
|
|
2346
|
-
b.append("t_pop_region(t_old_region);");
|
|
2347
2343
|
}
|
|
2344
|
+
b.append("t_pop_region(t_old_region);");
|
|
2348
2345
|
b.append(`${indexName} = ${index};`);
|
|
2349
2346
|
b.append("}");
|
|
2350
2347
|
}
|
|
@@ -2358,7 +2355,6 @@ function buildReplaceNode(node, status, b) {
|
|
|
2358
2355
|
status.imports.add("t_region");
|
|
2359
2356
|
status.imports.add("t_run_control");
|
|
2360
2357
|
status.imports.add("t_run_branch");
|
|
2361
|
-
status.imports.add("t_push_region");
|
|
2362
2358
|
status.imports.add("t_pop_region");
|
|
2363
2359
|
b.append("");
|
|
2364
2360
|
b.append(`
|
|
@@ -2371,13 +2367,9 @@ function buildReplaceNode(node, status, b) {
|
|
|
2371
2367
|
b.append("");
|
|
2372
2368
|
}
|
|
2373
2369
|
function buildReplaceBranch(node, status, b, parentName, regionName) {
|
|
2374
|
-
status.imports.add("t_run_branch");
|
|
2375
2370
|
b.append(`${node.statement};`);
|
|
2376
|
-
b.append(`
|
|
2377
|
-
b.append(
|
|
2378
|
-
const t_new_region = t_region(${status.options.dev === true ? `"replace_branch"` : ""});
|
|
2379
|
-
const t_old_region = t_push_region(t_new_region, true);
|
|
2380
|
-
`);
|
|
2371
|
+
b.append(`const t_old_region = t_run_branch(${regionName}, 0, -1${status.options.dev === true ? `, "replace_branch"` : ""});`);
|
|
2372
|
+
b.append("if (t_old_region === null) return;");
|
|
2381
2373
|
buildFragment(node, status, b, parentName, "t_before");
|
|
2382
2374
|
status.fragmentStack.push({
|
|
2383
2375
|
fragment: node.fragment,
|
|
@@ -2421,7 +2413,6 @@ function buildSwitchNode(node, status, b) {
|
|
|
2421
2413
|
status.imports.add("t_region");
|
|
2422
2414
|
status.imports.add("t_run_control");
|
|
2423
2415
|
status.imports.add("t_run_branch");
|
|
2424
|
-
status.imports.add("t_push_region");
|
|
2425
2416
|
status.imports.add("t_pop_region");
|
|
2426
2417
|
b.append("");
|
|
2427
2418
|
b.append("/* @switch */");
|
|
@@ -2442,12 +2433,9 @@ function buildSwitchNode(node, status, b) {
|
|
|
2442
2433
|
}
|
|
2443
2434
|
function buildSwitchBranch(node, status, b, parentName, regionName, indexName, index) {
|
|
2444
2435
|
addMappedText("", `${node.statement}`, " {", node.span, status, b);
|
|
2445
|
-
b.append(`
|
|
2436
|
+
b.append(`const t_old_region = t_run_branch(${regionName}, ${indexName}, ${index}${status.options.dev === true ? `, "switch_branch"` : ""});`);
|
|
2437
|
+
b.append("if (t_old_region === null) return;");
|
|
2446
2438
|
if (node.children.length > 0) {
|
|
2447
|
-
b.append(`
|
|
2448
|
-
const t_new_region = t_region(${status.options.dev === true ? `"switch_branch"` : ""});
|
|
2449
|
-
const t_old_region = t_push_region(t_new_region, true);
|
|
2450
|
-
`);
|
|
2451
2439
|
buildFragment(node, status, b, parentName, "t_before");
|
|
2452
2440
|
status.fragmentStack.push({
|
|
2453
2441
|
fragment: node.fragment,
|
|
@@ -2456,8 +2444,8 @@ function buildSwitchBranch(node, status, b, parentName, regionName, indexName, i
|
|
|
2456
2444
|
for (let child of node.children) buildNode(child, status, b, parentName, "t_before");
|
|
2457
2445
|
status.fragmentStack.pop();
|
|
2458
2446
|
buildAddFragment(node, status, b, parentName, "t_before");
|
|
2459
|
-
b.append("t_pop_region(t_old_region);");
|
|
2460
2447
|
}
|
|
2448
|
+
b.append("t_pop_region(t_old_region);");
|
|
2461
2449
|
b.append(`
|
|
2462
2450
|
${indexName} = ${index};
|
|
2463
2451
|
break;
|
|
@@ -3152,6 +3140,7 @@ function buildCode(template, map, options, errors = [], warnings = []) {
|
|
|
3152
3140
|
let imports = /* @__PURE__ */ new Set();
|
|
3153
3141
|
imports.add("SlotRender");
|
|
3154
3142
|
buildTemplate(template, map, imports, b, options, errors, warnings);
|
|
3143
|
+
if (imports.has("t_next") && !b.toString().includes("t_next(")) imports.delete("t_next");
|
|
3155
3144
|
let startSize = b.toString().length;
|
|
3156
3145
|
if (imports.size) {
|
|
3157
3146
|
const folder = options?.renderFolder ?? "@torpor/view";
|
|
@@ -3675,8 +3664,8 @@ function buildElementAttributes(node, status) {
|
|
|
3675
3664
|
status.imports.add("t_style");
|
|
3676
3665
|
attributes.push(`\${t_style(${value})}`);
|
|
3677
3666
|
} else {
|
|
3678
|
-
status.imports.add("
|
|
3679
|
-
attributes.push(`\${(${
|
|
3667
|
+
status.imports.add("t_attr_if");
|
|
3668
|
+
attributes.push(`\${t_attr_if("${name}", ${value})}`);
|
|
3680
3669
|
}
|
|
3681
3670
|
} else if (value != null && reactive) {
|
|
3682
3671
|
status.imports.add("t_attr");
|
|
@@ -3822,6 +3811,7 @@ const importsMap = {
|
|
|
3822
3811
|
t_await_server: "import { t_await_server } from \"${folder}\";",
|
|
3823
3812
|
t_fmt: "import { t_fmt } from \"${folder}\";",
|
|
3824
3813
|
t_attr: "import { t_attr } from \"${folder}\";",
|
|
3814
|
+
t_attr_if: "import { t_attr_if } from \"${folder}\";",
|
|
3825
3815
|
t_class: "import { t_class } from \"${folder}\";",
|
|
3826
3816
|
t_style: "import { t_style } from \"${folder}\";",
|
|
3827
3817
|
t_slot_guard: "import { t_slot_guard } from \"${folder}\";",
|
|
@@ -5927,6 +5917,10 @@ function parseControlOpen(status) {
|
|
|
5927
5917
|
if (operation === "@replace" || operation === "@html") statement = trimMatched(statement.substring(statement.indexOf("(")).trim(), "(", ")");
|
|
5928
5918
|
if (operation === "@await" && /^await\s*\(/.test(statement)) addError(status, "old `@await (expr) { … } then (…) { … }` syntax is removed — use `@await { … } with { … }` with `$async` getters", start, status.i);
|
|
5929
5919
|
} else {
|
|
5920
|
+
if (/^@[a-zA-Z]+</.test(operation)) {
|
|
5921
|
+
addError(status, `Unknown operation: ${operation}. A literal '@' in text must be escaped as '@'`, start, status.i);
|
|
5922
|
+
return null;
|
|
5923
|
+
}
|
|
5930
5924
|
addError(status, `Unknown operation: ${operation}`, status.i, status.i + operation.length);
|
|
5931
5925
|
return null;
|
|
5932
5926
|
}
|