tutuca 0.9.33 → 0.9.34
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/tutuca-cli.js +267 -82
- package/dist/tutuca-dev.js +215 -92
- package/dist/tutuca-dev.min.js +2 -2
- package/dist/tutuca-extra.js +28 -21
- package/dist/tutuca-extra.min.js +2 -2
- package/dist/tutuca.js +27 -20
- package/dist/tutuca.min.js +1 -1
- package/package.json +1 -1
package/dist/tutuca-cli.js
CHANGED
|
@@ -1478,6 +1478,7 @@ class ParseContext {
|
|
|
1478
1478
|
this.Text = Text ?? globalThis.Text;
|
|
1479
1479
|
this.Comment = Comment ?? globalThis.Comment;
|
|
1480
1480
|
this.cacheConstNodes = true;
|
|
1481
|
+
this.currentTag = null;
|
|
1481
1482
|
}
|
|
1482
1483
|
isInsideMacro(name) {
|
|
1483
1484
|
return this.frame.macroName === name || this.parent?.isInsideMacro(name);
|
|
@@ -1533,7 +1534,7 @@ class ParseContext {
|
|
|
1533
1534
|
getNodeForId(id) {
|
|
1534
1535
|
return this.nodes[id] ?? null;
|
|
1535
1536
|
}
|
|
1536
|
-
onAttributes(_attrs, _wrapperAttrs, _textChild, _isMacroCall) {}
|
|
1537
|
+
onAttributes(_attrs, _wrapperAttrs, _textChild, _isMacroCall, _tag) {}
|
|
1537
1538
|
onParseIssue(kind, info) {
|
|
1538
1539
|
console.warn(`tutuca parse issue [${kind}]`, info);
|
|
1539
1540
|
}
|
|
@@ -1741,27 +1742,33 @@ var init_anode = __esm(() => {
|
|
|
1741
1742
|
if (child !== null)
|
|
1742
1743
|
childs.push(child);
|
|
1743
1744
|
}
|
|
1744
|
-
const
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1745
|
+
const prevTag = px.currentTag;
|
|
1746
|
+
px.currentTag = tag;
|
|
1747
|
+
try {
|
|
1748
|
+
const isPseudoX = attrs[0]?.name === "@x";
|
|
1749
|
+
if (tag === "X" || isPseudoX) {
|
|
1750
|
+
return parseXOp(attrs, childs, isPseudoX ? 1 : 0, px);
|
|
1751
|
+
} else if (tag.charCodeAt(1) === 58 && tag.charCodeAt(0) === 88) {
|
|
1752
|
+
const macroName = tag.slice(2).toLowerCase();
|
|
1753
|
+
if (macroName === "slot") {
|
|
1754
|
+
const slotName = attrs.getNamedItem("name")?.value ?? "_";
|
|
1755
|
+
return px.frame.macroSlots[slotName] ?? maybeFragment(childs);
|
|
1756
|
+
}
|
|
1757
|
+
const [nAttrs, wrappers] = Attributes.parse(attrs, px, true);
|
|
1758
|
+
px.onAttributes(nAttrs, wrappers, null, true, tag);
|
|
1759
|
+
return wrap(px.newMacroNode(macroName, nAttrs.toMacroVars(), childs), px, wrappers);
|
|
1760
|
+
} else if (VALID_NODE_RE.test(tag)) {
|
|
1761
|
+
const [nAttrs, wrappers, textChild] = Attributes.parse(attrs, px);
|
|
1762
|
+
px.onAttributes(nAttrs, wrappers, textChild, false, tag);
|
|
1763
|
+
if (textChild)
|
|
1764
|
+
childs.unshift(new RenderTextNode(null, textChild));
|
|
1765
|
+
const domChilds = tag !== "PRE" ? condenseChildsWhites(childs) : childs;
|
|
1766
|
+
return wrap(new DomNode(tag, nAttrs, domChilds), px, wrappers);
|
|
1752
1767
|
}
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
} else if (VALID_NODE_RE.test(tag)) {
|
|
1757
|
-
const [nAttrs, wrappers, textChild] = Attributes.parse(attrs, px);
|
|
1758
|
-
px.onAttributes(nAttrs, wrappers, textChild);
|
|
1759
|
-
if (textChild)
|
|
1760
|
-
childs.unshift(new RenderTextNode(null, textChild));
|
|
1761
|
-
const domChilds = tag !== "PRE" ? condenseChildsWhites(childs) : childs;
|
|
1762
|
-
return wrap(new DomNode(tag, nAttrs, domChilds), px, wrappers);
|
|
1768
|
+
return new CommentNode(`Error: InvalidTagName ${tag}`);
|
|
1769
|
+
} finally {
|
|
1770
|
+
px.currentTag = prevTag;
|
|
1763
1771
|
}
|
|
1764
|
-
return new CommentNode(`Error: InvalidTagName ${tag}`);
|
|
1765
1772
|
}
|
|
1766
1773
|
};
|
|
1767
1774
|
MacroNode = class MacroNode extends BaseNode {
|
|
@@ -2212,7 +2219,8 @@ function checkMacroCallArgs(lx, view, Comp) {
|
|
|
2212
2219
|
if (!(argName in defaults)) {
|
|
2213
2220
|
lx.error(UNKNOWN_MACRO_ARG, {
|
|
2214
2221
|
name: argName,
|
|
2215
|
-
macroName: macroNode.name
|
|
2222
|
+
macroName: macroNode.name,
|
|
2223
|
+
tag: `x:${macroNode.name}`
|
|
2216
2224
|
});
|
|
2217
2225
|
}
|
|
2218
2226
|
}
|
|
@@ -2266,7 +2274,13 @@ function checkEventModifiers(lx, view) {
|
|
|
2266
2274
|
const modWrappers = MOD_WRAPPERS_BY_EVENT[name] ?? NO_WRAPPERS;
|
|
2267
2275
|
for (const modifier of modifiers) {
|
|
2268
2276
|
if (modWrappers[modifier] === undefined) {
|
|
2269
|
-
lx.error(UNKNOWN_EVENT_MODIFIER, {
|
|
2277
|
+
lx.error(UNKNOWN_EVENT_MODIFIER, {
|
|
2278
|
+
name,
|
|
2279
|
+
modifier,
|
|
2280
|
+
handler,
|
|
2281
|
+
event,
|
|
2282
|
+
originAttr: `@on.${name}+${modifiers.join("+")}`
|
|
2283
|
+
});
|
|
2270
2284
|
}
|
|
2271
2285
|
}
|
|
2272
2286
|
}
|
|
@@ -2281,10 +2295,16 @@ function checkKnownHandlerNames(lx, view, Comp, referencedAlters, referencedComp
|
|
|
2281
2295
|
const { fields } = Class.getMetaClass();
|
|
2282
2296
|
for (const event of view.ctx.events) {
|
|
2283
2297
|
for (const handler of event.handlers) {
|
|
2284
|
-
const { args } = handler.handlerCall;
|
|
2298
|
+
const { args, handlerVal } = handler.handlerCall;
|
|
2299
|
+
const handlerName = handlerVal?.name;
|
|
2300
|
+
const eventName = handler.name;
|
|
2301
|
+
const errCtx = {
|
|
2302
|
+
eventName,
|
|
2303
|
+
handlerName,
|
|
2304
|
+
originAttr: `@on.${eventName}`
|
|
2305
|
+
};
|
|
2285
2306
|
for (let i = 0;i < args.length; i++) {
|
|
2286
|
-
|
|
2287
|
-
checkConsistentAttrVal(lx, arg, fields, proto, computed, scope, alter, referencedAlters, referencedComputed);
|
|
2307
|
+
checkConsistentAttrVal(lx, args[i], fields, proto, computed, scope, alter, referencedAlters, referencedComputed, false, { ...errCtx, argIndex: i });
|
|
2288
2308
|
}
|
|
2289
2309
|
}
|
|
2290
2310
|
}
|
|
@@ -2299,19 +2319,25 @@ function checkEventHandlersHaveImpls(lx, Comp, referencedInputs) {
|
|
|
2299
2319
|
for (const handler of event.handlers) {
|
|
2300
2320
|
const { handlerVal } = handler.handlerCall;
|
|
2301
2321
|
const hvName = handlerVal?.constructor.name;
|
|
2322
|
+
const eventName = handler.name;
|
|
2323
|
+
const originAttr = `@on.${eventName}`;
|
|
2302
2324
|
if (hvName === "InputHandlerNameVal") {
|
|
2303
2325
|
referencedInputs?.add(handlerVal.name);
|
|
2304
2326
|
if (input[handlerVal.name] === undefined) {
|
|
2305
2327
|
lx.error(INPUT_HANDLER_NOT_IMPLEMENTED, {
|
|
2306
2328
|
name: handlerVal.name,
|
|
2307
2329
|
handler,
|
|
2308
|
-
event
|
|
2330
|
+
event,
|
|
2331
|
+
eventName,
|
|
2332
|
+
originAttr
|
|
2309
2333
|
});
|
|
2310
2334
|
if (proto[handlerVal.name] !== undefined) {
|
|
2311
2335
|
lx.hint(INPUT_HANDLER_METHOD_FOR_INPUT_HANDLER, {
|
|
2312
2336
|
name: handlerVal.name,
|
|
2313
2337
|
handler,
|
|
2314
|
-
event
|
|
2338
|
+
event,
|
|
2339
|
+
eventName,
|
|
2340
|
+
originAttr
|
|
2315
2341
|
});
|
|
2316
2342
|
}
|
|
2317
2343
|
}
|
|
@@ -2321,13 +2347,17 @@ function checkEventHandlersHaveImpls(lx, Comp, referencedInputs) {
|
|
|
2321
2347
|
lx.error(INPUT_HANDLER_METHOD_NOT_IMPLEMENTED, {
|
|
2322
2348
|
name: handlerVal.name,
|
|
2323
2349
|
handler,
|
|
2324
|
-
event
|
|
2350
|
+
event,
|
|
2351
|
+
eventName,
|
|
2352
|
+
originAttr
|
|
2325
2353
|
});
|
|
2326
2354
|
if (input[handlerVal.name] !== undefined) {
|
|
2327
2355
|
lx.hint(INPUT_HANDLER_FOR_INPUT_HANDLER_METHOD, {
|
|
2328
2356
|
name: handlerVal.name,
|
|
2329
2357
|
handler,
|
|
2330
|
-
event
|
|
2358
|
+
event,
|
|
2359
|
+
eventName,
|
|
2360
|
+
originAttr
|
|
2331
2361
|
});
|
|
2332
2362
|
}
|
|
2333
2363
|
}
|
|
@@ -2337,47 +2367,68 @@ function checkEventHandlersHaveImpls(lx, Comp, referencedInputs) {
|
|
|
2337
2367
|
});
|
|
2338
2368
|
}
|
|
2339
2369
|
}
|
|
2340
|
-
function checkConsistentAttrVal(lx, val, fields, proto, computed, scope, alter, referencedAlters, referencedComputed, skipNameVal = false) {
|
|
2370
|
+
function checkConsistentAttrVal(lx, val, fields, proto, computed, scope, alter, referencedAlters, referencedComputed, skipNameVal = false, errCtx = null) {
|
|
2341
2371
|
const valName = val?.constructor.name;
|
|
2342
2372
|
if (valName === "FieldVal" || valName === "RawFieldVal") {
|
|
2343
2373
|
const { name } = val;
|
|
2344
2374
|
if (fields[name] === undefined && proto[name] === undefined) {
|
|
2345
|
-
lx.error(FIELD_VAL_NOT_DEFINED, { val, name });
|
|
2375
|
+
lx.error(FIELD_VAL_NOT_DEFINED, { ...errCtx, val, name });
|
|
2346
2376
|
}
|
|
2347
2377
|
} else if (valName === "ComputedVal") {
|
|
2348
2378
|
const { name } = val;
|
|
2349
2379
|
referencedComputed?.add(name);
|
|
2350
2380
|
if (computed[name] === undefined) {
|
|
2351
|
-
lx.error(COMPUTED_VAL_NOT_DEFINED, { val, name });
|
|
2381
|
+
lx.error(COMPUTED_VAL_NOT_DEFINED, { ...errCtx, val, name });
|
|
2352
2382
|
}
|
|
2353
2383
|
} else if (valName === "SeqAccessVal") {
|
|
2354
|
-
checkConsistentAttrVal(lx, val.seqVal, fields, proto, computed, scope, alter, referencedAlters, referencedComputed, skipNameVal);
|
|
2355
|
-
checkConsistentAttrVal(lx, val.keyVal, fields, proto, computed, scope, alter, referencedAlters, referencedComputed, skipNameVal);
|
|
2384
|
+
checkConsistentAttrVal(lx, val.seqVal, fields, proto, computed, scope, alter, referencedAlters, referencedComputed, skipNameVal, errCtx);
|
|
2385
|
+
checkConsistentAttrVal(lx, val.keyVal, fields, proto, computed, scope, alter, referencedAlters, referencedComputed, skipNameVal, errCtx);
|
|
2356
2386
|
} else if (valName === "RequestVal") {
|
|
2357
2387
|
if (scope.lookupRequest(val.name) === null) {
|
|
2358
|
-
lx.error(UNKNOWN_REQUEST_NAME, { name: val.name });
|
|
2388
|
+
lx.error(UNKNOWN_REQUEST_NAME, { ...errCtx, name: val.name });
|
|
2359
2389
|
}
|
|
2360
2390
|
} else if (valName === "TypeVal") {
|
|
2361
2391
|
if (scope.lookupComponent(val.name) === null) {
|
|
2362
|
-
lx.error(UNKNOWN_COMPONENT_NAME, { name: val.name });
|
|
2392
|
+
lx.error(UNKNOWN_COMPONENT_NAME, { ...errCtx, name: val.name });
|
|
2363
2393
|
}
|
|
2364
2394
|
} else if (valName === "NameVal") {
|
|
2365
2395
|
if (!skipNameVal && !isKnownHandlerName(val.name)) {
|
|
2366
|
-
lx.error(UNKNOWN_HANDLER_ARG_NAME, { name: val.name });
|
|
2396
|
+
lx.error(UNKNOWN_HANDLER_ARG_NAME, { ...errCtx, name: val.name });
|
|
2367
2397
|
}
|
|
2368
2398
|
} else if (valName === "StrTplVal") {
|
|
2369
2399
|
for (const subVal of val.vals) {
|
|
2370
|
-
checkConsistentAttrVal(lx, subVal, fields, proto, computed, scope, alter, referencedAlters, referencedComputed, skipNameVal);
|
|
2400
|
+
checkConsistentAttrVal(lx, subVal, fields, proto, computed, scope, alter, referencedAlters, referencedComputed, skipNameVal, errCtx);
|
|
2371
2401
|
}
|
|
2372
2402
|
} else if (valName === "AlterHandlerNameVal") {
|
|
2373
2403
|
referencedAlters?.add(val.name);
|
|
2374
2404
|
if (alter[val.name] === undefined) {
|
|
2375
|
-
lx.error(ALT_HANDLER_NOT_DEFINED, { name: val.name });
|
|
2405
|
+
lx.error(ALT_HANDLER_NOT_DEFINED, { ...errCtx, name: val.name });
|
|
2376
2406
|
}
|
|
2377
2407
|
} else if (valName !== "ConstVal" && valName !== "BindVal" && valName !== "DynVal") {
|
|
2378
2408
|
console.log(val);
|
|
2379
2409
|
}
|
|
2380
2410
|
}
|
|
2411
|
+
function nodeCtxForNode(nodeKind) {
|
|
2412
|
+
return NODE_KIND_TO_CTX[nodeKind] ?? null;
|
|
2413
|
+
}
|
|
2414
|
+
function attrSourceLabel(attr) {
|
|
2415
|
+
const cn = attr.constructor.name;
|
|
2416
|
+
if (cn === "ConstAttr")
|
|
2417
|
+
return "literal";
|
|
2418
|
+
if (cn === "IfAttr")
|
|
2419
|
+
return `@if.${attr.name}`;
|
|
2420
|
+
if (cn === "RawHtmlAttr")
|
|
2421
|
+
return "@dangerouslysetinnerhtml";
|
|
2422
|
+
return `:${attr.name}`;
|
|
2423
|
+
}
|
|
2424
|
+
function attrOriginAttr(attr) {
|
|
2425
|
+
const cn = attr.constructor.name;
|
|
2426
|
+
if (cn === "IfAttr")
|
|
2427
|
+
return `@if.${attr.name}`;
|
|
2428
|
+
if (cn === "RawHtmlAttr")
|
|
2429
|
+
return "@dangerouslysetinnerhtml";
|
|
2430
|
+
return `:${attr.name}`;
|
|
2431
|
+
}
|
|
2381
2432
|
function checkConsistentAttrs(lx, Comp, referencedAlters, referencedComputed) {
|
|
2382
2433
|
const { computed, scope, views, alter, Class } = Comp;
|
|
2383
2434
|
const { prototype: proto } = Class;
|
|
@@ -2385,25 +2436,39 @@ function checkConsistentAttrs(lx, Comp, referencedAlters, referencedComputed) {
|
|
|
2385
2436
|
for (const viewName in views) {
|
|
2386
2437
|
lx.push({ viewName }, () => {
|
|
2387
2438
|
const view = views[viewName];
|
|
2388
|
-
for (const
|
|
2389
|
-
const { attrs, wrapperAttrs, textChild, isMacroCall } =
|
|
2439
|
+
for (const entry of view.ctx.attrs) {
|
|
2440
|
+
const { attrs, wrapperAttrs, textChild, isMacroCall, tag } = entry;
|
|
2390
2441
|
if (attrs?.constructor.name === "DynAttrs") {
|
|
2391
|
-
const
|
|
2392
|
-
for (const
|
|
2393
|
-
const name =
|
|
2442
|
+
const sourcesByName = new Map;
|
|
2443
|
+
for (const attr of attrs.items) {
|
|
2444
|
+
const name = attr?.name;
|
|
2394
2445
|
if (name !== undefined && name !== "data-eid") {
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2446
|
+
const sources = sourcesByName.get(name);
|
|
2447
|
+
const label = attrSourceLabel(attr);
|
|
2448
|
+
if (sources)
|
|
2449
|
+
sources.push(label);
|
|
2450
|
+
else
|
|
2451
|
+
sourcesByName.set(name, [label]);
|
|
2400
2452
|
}
|
|
2401
|
-
if (
|
|
2402
|
-
|
|
2403
|
-
|
|
2453
|
+
if (attr?.constructor.name === "IfAttr") {
|
|
2454
|
+
if (!attr.anyBranchIsSet) {
|
|
2455
|
+
lx.error(IF_NO_BRANCH_SET, { attr: attr.name, tag });
|
|
2456
|
+
}
|
|
2457
|
+
const branches = [
|
|
2458
|
+
["@if", attr.condVal],
|
|
2459
|
+
["@then", attr.thenVal],
|
|
2460
|
+
["@else", attr.elseVal]
|
|
2461
|
+
];
|
|
2462
|
+
for (const [branch, subVal] of branches) {
|
|
2463
|
+
checkConsistentAttrVal(lx, subVal, fields, proto, computed, scope, alter, referencedAlters, referencedComputed, isMacroCall, { tag, originAttr: `@if.${attr.name}`, branch });
|
|
2404
2464
|
}
|
|
2405
|
-
} else if (
|
|
2406
|
-
checkConsistentAttrVal(lx,
|
|
2465
|
+
} else if (attr?.val !== undefined) {
|
|
2466
|
+
checkConsistentAttrVal(lx, attr.val, fields, proto, computed, scope, alter, referencedAlters, referencedComputed, isMacroCall, { tag, originAttr: attrOriginAttr(attr) });
|
|
2467
|
+
}
|
|
2468
|
+
}
|
|
2469
|
+
for (const [name, sources] of sourcesByName) {
|
|
2470
|
+
if (sources.length > 1) {
|
|
2471
|
+
lx.error(DUPLICATE_ATTR_DEFINITION, { name, sources, tag });
|
|
2407
2472
|
}
|
|
2408
2473
|
}
|
|
2409
2474
|
}
|
|
@@ -2411,30 +2476,35 @@ function checkConsistentAttrs(lx, Comp, referencedAlters, referencedComputed) {
|
|
|
2411
2476
|
for (const w of wrapperAttrs) {
|
|
2412
2477
|
if (w.name === "each") {
|
|
2413
2478
|
if (w.whenVal)
|
|
2414
|
-
checkConsistentAttrVal(lx, w.whenVal, fields, proto, computed, scope, alter, referencedAlters, referencedComputed);
|
|
2479
|
+
checkConsistentAttrVal(lx, w.whenVal, fields, proto, computed, scope, alter, referencedAlters, referencedComputed, false, { tag, originAttr: "@when" });
|
|
2415
2480
|
if (w.enrichWithVal)
|
|
2416
|
-
checkConsistentAttrVal(lx, w.enrichWithVal, fields, proto, computed, scope, alter, referencedAlters, referencedComputed);
|
|
2481
|
+
checkConsistentAttrVal(lx, w.enrichWithVal, fields, proto, computed, scope, alter, referencedAlters, referencedComputed, false, { tag, originAttr: "@enrich-with" });
|
|
2417
2482
|
if (w.loopWithVal)
|
|
2418
|
-
checkConsistentAttrVal(lx, w.loopWithVal, fields, proto, computed, scope, alter, referencedAlters, referencedComputed);
|
|
2419
|
-
} else
|
|
2420
|
-
|
|
2483
|
+
checkConsistentAttrVal(lx, w.loopWithVal, fields, proto, computed, scope, alter, referencedAlters, referencedComputed, false, { tag, originAttr: "@loop-with" });
|
|
2484
|
+
} else {
|
|
2485
|
+
const originAttr = w.name === "scope" ? "@enrich-with" : `@${w.name}`;
|
|
2486
|
+
checkConsistentAttrVal(lx, w.val, fields, proto, computed, scope, alter, referencedAlters, referencedComputed, false, { tag, originAttr });
|
|
2421
2487
|
}
|
|
2422
2488
|
}
|
|
2423
2489
|
}
|
|
2424
2490
|
if (textChild) {
|
|
2425
|
-
checkConsistentAttrVal(lx, textChild, fields, proto, computed, scope, alter, referencedAlters, referencedComputed);
|
|
2491
|
+
checkConsistentAttrVal(lx, textChild, fields, proto, computed, scope, alter, referencedAlters, referencedComputed, false, { tag, originAttr: "@text" });
|
|
2426
2492
|
}
|
|
2427
2493
|
}
|
|
2428
2494
|
for (const node of view.ctx.nodes) {
|
|
2495
|
+
const nodeKind = node.constructor.name;
|
|
2496
|
+
if (nodeKind === "ScopeNode")
|
|
2497
|
+
continue;
|
|
2498
|
+
const baseCtx = nodeCtxForNode(nodeKind);
|
|
2429
2499
|
if (node.val) {
|
|
2430
|
-
checkConsistentAttrVal(lx, node.val, fields, proto, computed, scope, alter, referencedAlters, referencedComputed);
|
|
2500
|
+
checkConsistentAttrVal(lx, node.val, fields, proto, computed, scope, alter, referencedAlters, referencedComputed, false, baseCtx);
|
|
2431
2501
|
}
|
|
2432
|
-
if (
|
|
2502
|
+
if (nodeKind === "RenderEachNode") {
|
|
2433
2503
|
const iter = node.iterInfo;
|
|
2434
2504
|
if (iter.whenVal)
|
|
2435
|
-
checkConsistentAttrVal(lx, iter.whenVal, fields, proto, computed, scope, alter, referencedAlters, referencedComputed);
|
|
2505
|
+
checkConsistentAttrVal(lx, iter.whenVal, fields, proto, computed, scope, alter, referencedAlters, referencedComputed, false, { originAttr: "<x render-each when>" });
|
|
2436
2506
|
if (iter.loopWithVal)
|
|
2437
|
-
checkConsistentAttrVal(lx, iter.loopWithVal, fields, proto, computed, scope, alter, referencedAlters, referencedComputed);
|
|
2507
|
+
checkConsistentAttrVal(lx, iter.loopWithVal, fields, proto, computed, scope, alter, referencedAlters, referencedComputed, false, { originAttr: "<x render-each loop-with>" });
|
|
2438
2508
|
}
|
|
2439
2509
|
}
|
|
2440
2510
|
});
|
|
@@ -2489,7 +2559,7 @@ class LintContext {
|
|
|
2489
2559
|
this.reports.push({ id, info, level, context: { ...this.frame } });
|
|
2490
2560
|
}
|
|
2491
2561
|
}
|
|
2492
|
-
var ALT_HANDLER_NOT_DEFINED = "ALT_HANDLER_NOT_DEFINED", ALT_HANDLER_NOT_REFERENCED = "ALT_HANDLER_NOT_REFERENCED", RENDER_IT_OUTSIDE_OF_LOOP = "RENDER_IT_OUTSIDE_OF_LOOP", UNKNOWN_EVENT_MODIFIER = "UNKNOWN_EVENT_MODIFIER", UNKNOWN_HANDLER_ARG_NAME = "UNKNOWN_HANDLER_ARG_NAME", INPUT_HANDLER_NOT_IMPLEMENTED = "INPUT_HANDLER_NOT_IMPLEMENTED", INPUT_HANDLER_NOT_REFERENCED = "INPUT_HANDLER_NOT_REFERENCED", INPUT_HANDLER_METHOD_NOT_IMPLEMENTED = "INPUT_HANDLER_METHOD_NOT_IMPLEMENTED", INPUT_HANDLER_FOR_INPUT_HANDLER_METHOD = "INPUT_HANDLER_FOR_INPUT_HANDLER_METHOD", INPUT_HANDLER_METHOD_FOR_INPUT_HANDLER = "INPUT_HANDLER_METHOD_FOR_INPUT_HANDLER", FIELD_VAL_NOT_DEFINED = "FIELD_VAL_NOT_DEFINED", COMPUTED_VAL_NOT_DEFINED = "COMPUTED_VAL_NOT_DEFINED", COMPUTED_NOT_REFERENCED = "COMPUTED_NOT_REFERENCED", DUPLICATE_ATTR_DEFINITION = "DUPLICATE_ATTR_DEFINITION", UNKNOWN_REQUEST_NAME = "UNKNOWN_REQUEST_NAME", UNKNOWN_COMPONENT_NAME = "UNKNOWN_COMPONENT_NAME", UNKNOWN_MACRO_ARG = "UNKNOWN_MACRO_ARG", UNKNOWN_DIRECTIVE = "UNKNOWN_DIRECTIVE", UNKNOWN_X_OP = "UNKNOWN_X_OP", UNKNOWN_X_ATTR = "UNKNOWN_X_ATTR", MAYBE_DROP_AT_PREFIX = "MAYBE_DROP_AT_PREFIX", BAD_VALUE = "BAD_VALUE", PARSE_ISSUE_KIND_TO_LINT_ID, X_KNOWN_OP_NAMES, X_KNOWN_ATTR_NAMES, AT_PREFIX_HINT_KNOWN_BY_KIND, LEVEL_WARN = "warn", LEVEL_ERROR = "error", LEVEL_HINT = "hint", NO_WRAPPERS, KNOWN_HANDLER_NAMES, LintParseContext;
|
|
2562
|
+
var ALT_HANDLER_NOT_DEFINED = "ALT_HANDLER_NOT_DEFINED", ALT_HANDLER_NOT_REFERENCED = "ALT_HANDLER_NOT_REFERENCED", RENDER_IT_OUTSIDE_OF_LOOP = "RENDER_IT_OUTSIDE_OF_LOOP", UNKNOWN_EVENT_MODIFIER = "UNKNOWN_EVENT_MODIFIER", UNKNOWN_HANDLER_ARG_NAME = "UNKNOWN_HANDLER_ARG_NAME", INPUT_HANDLER_NOT_IMPLEMENTED = "INPUT_HANDLER_NOT_IMPLEMENTED", INPUT_HANDLER_NOT_REFERENCED = "INPUT_HANDLER_NOT_REFERENCED", INPUT_HANDLER_METHOD_NOT_IMPLEMENTED = "INPUT_HANDLER_METHOD_NOT_IMPLEMENTED", INPUT_HANDLER_FOR_INPUT_HANDLER_METHOD = "INPUT_HANDLER_FOR_INPUT_HANDLER_METHOD", INPUT_HANDLER_METHOD_FOR_INPUT_HANDLER = "INPUT_HANDLER_METHOD_FOR_INPUT_HANDLER", FIELD_VAL_NOT_DEFINED = "FIELD_VAL_NOT_DEFINED", COMPUTED_VAL_NOT_DEFINED = "COMPUTED_VAL_NOT_DEFINED", COMPUTED_NOT_REFERENCED = "COMPUTED_NOT_REFERENCED", DUPLICATE_ATTR_DEFINITION = "DUPLICATE_ATTR_DEFINITION", IF_NO_BRANCH_SET = "IF_NO_BRANCH_SET", UNKNOWN_REQUEST_NAME = "UNKNOWN_REQUEST_NAME", UNKNOWN_COMPONENT_NAME = "UNKNOWN_COMPONENT_NAME", UNKNOWN_MACRO_ARG = "UNKNOWN_MACRO_ARG", UNKNOWN_DIRECTIVE = "UNKNOWN_DIRECTIVE", UNKNOWN_X_OP = "UNKNOWN_X_OP", UNKNOWN_X_ATTR = "UNKNOWN_X_ATTR", MAYBE_DROP_AT_PREFIX = "MAYBE_DROP_AT_PREFIX", BAD_VALUE = "BAD_VALUE", PARSE_ISSUE_KIND_TO_LINT_ID, X_KNOWN_OP_NAMES, X_KNOWN_ATTR_NAMES, AT_PREFIX_HINT_KNOWN_BY_KIND, LEVEL_WARN = "warn", LEVEL_ERROR = "error", LEVEL_HINT = "hint", NO_WRAPPERS, KNOWN_HANDLER_NAMES, NODE_KIND_TO_CTX, LintParseContext;
|
|
2493
2563
|
var init_lint_check = __esm(() => {
|
|
2494
2564
|
init_anode();
|
|
2495
2565
|
PARSE_ISSUE_KIND_TO_LINT_ID = {
|
|
@@ -2533,17 +2603,27 @@ var init_lint_check = __esm(() => {
|
|
|
2533
2603
|
"ctx",
|
|
2534
2604
|
"dragInfo"
|
|
2535
2605
|
]);
|
|
2606
|
+
NODE_KIND_TO_CTX = {
|
|
2607
|
+
RenderTextNode: { originAttr: "<x text>" },
|
|
2608
|
+
RenderNode: { originAttr: "<x render>" },
|
|
2609
|
+
RenderItNode: { originAttr: "<x render-it>" },
|
|
2610
|
+
RenderEachNode: { originAttr: "<x render-each>" },
|
|
2611
|
+
ShowNode: { originAttr: "<x show>" },
|
|
2612
|
+
HideNode: { originAttr: "<x hide>" },
|
|
2613
|
+
PushViewNameNode: { originAttr: "<x push-view>" }
|
|
2614
|
+
};
|
|
2536
2615
|
LintParseContext = class LintParseContext extends ParseContext {
|
|
2537
2616
|
constructor(document2, Text, Comment) {
|
|
2538
2617
|
super(document2, Text, Comment);
|
|
2539
2618
|
this.attrs = [];
|
|
2540
2619
|
this.parseIssues = [];
|
|
2541
2620
|
}
|
|
2542
|
-
onAttributes(attrs, wrapperAttrs, textChild, isMacroCall = false) {
|
|
2543
|
-
this.attrs.push({ attrs, wrapperAttrs, textChild, isMacroCall });
|
|
2621
|
+
onAttributes(attrs, wrapperAttrs, textChild, isMacroCall = false, tag = null) {
|
|
2622
|
+
this.attrs.push({ attrs, wrapperAttrs, textChild, isMacroCall, tag });
|
|
2544
2623
|
}
|
|
2545
2624
|
onParseIssue(kind, info) {
|
|
2546
|
-
|
|
2625
|
+
const tag = this.currentTag;
|
|
2626
|
+
this.parseIssues.push({ kind, info: tag && info.tag === undefined ? { ...info, tag } : info });
|
|
2547
2627
|
}
|
|
2548
2628
|
};
|
|
2549
2629
|
});
|
|
@@ -8509,6 +8589,121 @@ function makeFormatter(name, table) {
|
|
|
8509
8589
|
};
|
|
8510
8590
|
}
|
|
8511
8591
|
|
|
8592
|
+
// tools/format/lint.js
|
|
8593
|
+
function badValueMessage(info) {
|
|
8594
|
+
const v = JSON.stringify(info.value);
|
|
8595
|
+
switch (info.role) {
|
|
8596
|
+
case "attr":
|
|
8597
|
+
return `Cannot parse value ${v} for attribute ':${info.attr}'`;
|
|
8598
|
+
case "directive":
|
|
8599
|
+
return `Cannot parse value ${v} for directive '@${info.directive}'`;
|
|
8600
|
+
case "if":
|
|
8601
|
+
return `Cannot parse condition ${v} for '@if.${info.attr}'`;
|
|
8602
|
+
case "x-op":
|
|
8603
|
+
return `Cannot parse value ${v} for <x ${info.op}>`;
|
|
8604
|
+
case "handler-name":
|
|
8605
|
+
return `Cannot parse handler name ${v}`;
|
|
8606
|
+
case "handler-arg":
|
|
8607
|
+
return `Cannot parse handler argument ${v}`;
|
|
8608
|
+
case "macro-var":
|
|
8609
|
+
return `Macro variable '^${info.name}' is not defined`;
|
|
8610
|
+
default:
|
|
8611
|
+
return `Cannot parse value ${v}`;
|
|
8612
|
+
}
|
|
8613
|
+
}
|
|
8614
|
+
function tagDisplay(tag) {
|
|
8615
|
+
return tag ? String(tag).toLowerCase() : null;
|
|
8616
|
+
}
|
|
8617
|
+
function fmtTagSuffix(info) {
|
|
8618
|
+
const t = tagDisplay(info?.tag);
|
|
8619
|
+
return t && t !== "x" ? ` on <${t}>` : "";
|
|
8620
|
+
}
|
|
8621
|
+
function fmtOriginSuffix(info) {
|
|
8622
|
+
if (!info)
|
|
8623
|
+
return "";
|
|
8624
|
+
const parts = [];
|
|
8625
|
+
if (info.originAttr) {
|
|
8626
|
+
const branch = info.branch ? `[${info.branch}]` : "";
|
|
8627
|
+
parts.push(`in ${info.originAttr}${branch}`);
|
|
8628
|
+
}
|
|
8629
|
+
if (info.handlerName) {
|
|
8630
|
+
parts.push(`handler '${info.handlerName}'${info.argIndex !== undefined ? ` arg ${info.argIndex}` : ""}`);
|
|
8631
|
+
}
|
|
8632
|
+
const t = tagDisplay(info.tag);
|
|
8633
|
+
if (t && t !== "x")
|
|
8634
|
+
parts.push(`on <${t}>`);
|
|
8635
|
+
return parts.length ? ` (${parts.join(", ")})` : "";
|
|
8636
|
+
}
|
|
8637
|
+
function fmtEventSuffix(info) {
|
|
8638
|
+
if (info?.originAttr)
|
|
8639
|
+
return ` in ${info.originAttr}`;
|
|
8640
|
+
if (info?.eventName)
|
|
8641
|
+
return ` in @on.${info.eventName}`;
|
|
8642
|
+
return "";
|
|
8643
|
+
}
|
|
8644
|
+
function lintIdToMessage(id, info) {
|
|
8645
|
+
switch (id) {
|
|
8646
|
+
case "RENDER_IT_OUTSIDE_OF_LOOP":
|
|
8647
|
+
return "render-it used outside of a loop";
|
|
8648
|
+
case "UNKNOWN_EVENT_MODIFIER": {
|
|
8649
|
+
const mods = info.handler?.modifiers ?? [info.modifier];
|
|
8650
|
+
const written = `@on.${info.name}+${mods.join("+")}`;
|
|
8651
|
+
return `Unknown modifier '+${info.modifier}' in '${written}'`;
|
|
8652
|
+
}
|
|
8653
|
+
case "UNKNOWN_HANDLER_ARG_NAME":
|
|
8654
|
+
return `Unknown handler argument '${info.name}'${fmtOriginSuffix(info)}`;
|
|
8655
|
+
case "INPUT_HANDLER_NOT_IMPLEMENTED":
|
|
8656
|
+
return `Input handler '${info.name}' is not implemented${fmtEventSuffix(info)}`;
|
|
8657
|
+
case "INPUT_HANDLER_NOT_REFERENCED":
|
|
8658
|
+
return `Input handler '${info.name}' is defined but not referenced`;
|
|
8659
|
+
case "INPUT_HANDLER_METHOD_NOT_IMPLEMENTED":
|
|
8660
|
+
return `Method '.${info.name}' is not implemented${fmtEventSuffix(info)}`;
|
|
8661
|
+
case "INPUT_HANDLER_FOR_INPUT_HANDLER_METHOD":
|
|
8662
|
+
return `'${info.name}' exists as input handler — use without '.' prefix${fmtEventSuffix(info)}`;
|
|
8663
|
+
case "INPUT_HANDLER_METHOD_FOR_INPUT_HANDLER":
|
|
8664
|
+
return `'${info.name}' exists as method — use with '.' prefix${fmtEventSuffix(info)}`;
|
|
8665
|
+
case "FIELD_VAL_NOT_DEFINED":
|
|
8666
|
+
return `Field '.${info.name}' is not defined${fmtOriginSuffix(info)}`;
|
|
8667
|
+
case "COMPUTED_VAL_NOT_DEFINED":
|
|
8668
|
+
return `Computed property '$${info.name}' is not defined${fmtOriginSuffix(info)}`;
|
|
8669
|
+
case "COMPUTED_NOT_REFERENCED":
|
|
8670
|
+
return `Computed property '$${info.name}' is defined but not referenced`;
|
|
8671
|
+
case "DUPLICATE_ATTR_DEFINITION": {
|
|
8672
|
+
const sources = info.sources?.length ? ` (${info.sources.join(", ")})` : "";
|
|
8673
|
+
const tag = info.tag ? ` on <${String(info.tag).toLowerCase()}>` : "";
|
|
8674
|
+
return `Attribute '${info.name}' is set ${info.sources?.length ?? "multiple"} times${sources}${tag}`;
|
|
8675
|
+
}
|
|
8676
|
+
case "IF_NO_BRANCH_SET":
|
|
8677
|
+
return `'@if.${info.attr}' has no '@then' or '@else' branch — at least one must be set${fmtTagSuffix(info)}`;
|
|
8678
|
+
case "UNKNOWN_REQUEST_NAME":
|
|
8679
|
+
return `Unknown request '!${info.name}'${fmtOriginSuffix(info)}`;
|
|
8680
|
+
case "UNKNOWN_COMPONENT_NAME":
|
|
8681
|
+
return `Unknown component '${info.name}'${fmtOriginSuffix(info)}`;
|
|
8682
|
+
case "ALT_HANDLER_NOT_DEFINED":
|
|
8683
|
+
return `Alter handler '${info.name}' is not defined${fmtOriginSuffix(info)}`;
|
|
8684
|
+
case "ALT_HANDLER_NOT_REFERENCED":
|
|
8685
|
+
return `Alter handler '${info.name}' is defined but not referenced`;
|
|
8686
|
+
case "UNKNOWN_MACRO_ARG":
|
|
8687
|
+
return `Argument '${info.name}' is not declared in macro '${info.macroName}'`;
|
|
8688
|
+
case "UNKNOWN_DIRECTIVE":
|
|
8689
|
+
return `Unknown directive '@${info.name}=${JSON.stringify(info.value)}'${fmtTagSuffix(info)}`;
|
|
8690
|
+
case "UNKNOWN_X_OP":
|
|
8691
|
+
return `Unknown <x> op '${info.name}=${JSON.stringify(info.value)}'${fmtTagSuffix(info)}`;
|
|
8692
|
+
case "UNKNOWN_X_ATTR":
|
|
8693
|
+
return `Unknown attribute '${info.name}=${JSON.stringify(info.value)}' on <x ${info.op}>${fmtTagSuffix(info)}`;
|
|
8694
|
+
case "MAYBE_DROP_AT_PREFIX": {
|
|
8695
|
+
const written = info.value !== undefined ? `${info.name}=${JSON.stringify(info.value)}` : info.name;
|
|
8696
|
+
return `Did you mean '${info.suggestion}'? Drop the '@' from '${written}' on <x>.`;
|
|
8697
|
+
}
|
|
8698
|
+
case "BAD_VALUE":
|
|
8699
|
+
return `${badValueMessage(info)}${fmtTagSuffix(info)}`;
|
|
8700
|
+
case "LINT_ERROR":
|
|
8701
|
+
return info.message;
|
|
8702
|
+
default:
|
|
8703
|
+
return id;
|
|
8704
|
+
}
|
|
8705
|
+
}
|
|
8706
|
+
|
|
8512
8707
|
// tools/format/cli.js
|
|
8513
8708
|
function fmtModuleInfo(info) {
|
|
8514
8709
|
const lines = [];
|
|
@@ -8578,15 +8773,6 @@ function fmtComponentDocs(docs) {
|
|
|
8578
8773
|
return lines.join(`
|
|
8579
8774
|
`);
|
|
8580
8775
|
}
|
|
8581
|
-
function fmtFindingInfo(info) {
|
|
8582
|
-
const keys = ["name", "modifier", "id"];
|
|
8583
|
-
const parts = [];
|
|
8584
|
-
for (const k of keys) {
|
|
8585
|
-
if (info?.[k] !== undefined)
|
|
8586
|
-
parts.push(`${k}=${info[k]}`);
|
|
8587
|
-
}
|
|
8588
|
-
return parts.join(" ");
|
|
8589
|
-
}
|
|
8590
8776
|
function fmtLintReport(rep) {
|
|
8591
8777
|
if (rep.components.length === 0)
|
|
8592
8778
|
return "(no components)";
|
|
@@ -8599,9 +8785,8 @@ function fmtLintReport(rep) {
|
|
|
8599
8785
|
lines.push(`${c.componentName}:`);
|
|
8600
8786
|
for (const f of c.findings) {
|
|
8601
8787
|
const tag = f.level.toUpperCase();
|
|
8602
|
-
const view = f.context?.viewName ? ` view=${f.context.viewName}` : "";
|
|
8603
|
-
|
|
8604
|
-
lines.push(` [${tag}] ${f.id}${view}${extra ? ` (${extra})` : ""}`);
|
|
8788
|
+
const view = f.context?.viewName ? ` [view=${f.context.viewName}]` : "";
|
|
8789
|
+
lines.push(` [${tag}]${view} ${lintIdToMessage(f.id, f.info)}`);
|
|
8605
8790
|
}
|
|
8606
8791
|
}
|
|
8607
8792
|
lines.push("");
|
|
@@ -8748,8 +8933,8 @@ function fmtLintReport2(rep) {
|
|
|
8748
8933
|
continue;
|
|
8749
8934
|
}
|
|
8750
8935
|
for (const f of c.findings) {
|
|
8751
|
-
const view = f.context?.viewName ? `
|
|
8752
|
-
lines.push(`- **${f.level.toUpperCase()}**
|
|
8936
|
+
const view = f.context?.viewName ? ` _(view: \`${f.context.viewName}\`)_` : "";
|
|
8937
|
+
lines.push(`- **${f.level.toUpperCase()}** ${lintIdToMessage(f.id, f.info)}${view}`);
|
|
8753
8938
|
}
|
|
8754
8939
|
lines.push("");
|
|
8755
8940
|
}
|