@wcstack/lint 4.0.0-rc.9 → 4.0.1
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/cli.cjs +293 -3
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -882,6 +882,10 @@ var SENTENCES = {
|
|
|
882
882
|
121
|
|
883
883
|
/* ForNoFilters */
|
|
884
884
|
]: (t) => `"${t}": "for:" takes no filters \u2014 a row is "<path>.<index>", so the rows of a filtered list would name other elements. Declare a getter that returns the filtered list and loop over it ("for: <getter>").`,
|
|
885
|
+
[
|
|
886
|
+
122
|
|
887
|
+
/* NamespaceNeedsName */
|
|
888
|
+
]: (t, ns) => ns === "class" ? `"${t}": "class:" needs a class name \u2014 "class.NAME:" toggles one class (a bare "class:" would set an element property named "class", which does nothing). To set the whole class attribute, bind "className:".` : `"${t}": "attr:" needs an attribute name \u2014 "attr.NAME:" sets one attribute (a bare "attr:" would set an element property named "attr", which does nothing).`,
|
|
885
889
|
[
|
|
886
890
|
119
|
|
887
891
|
/* EmptySegment */
|
|
@@ -1146,6 +1150,9 @@ function parseBindTextsForElement(bindText) {
|
|
|
1146
1150
|
bindingType: keyword === SPREAD_PROP ? "spread" : keyword
|
|
1147
1151
|
};
|
|
1148
1152
|
}
|
|
1153
|
+
if (keyword === CLASS_NAMESPACE || keyword === ATTR_NAMESPACE) {
|
|
1154
|
+
raise(122, [bindText2, keyword]);
|
|
1155
|
+
}
|
|
1149
1156
|
const stateResult = parseStatePart(statePart);
|
|
1150
1157
|
const propResult = parsePropPart(propPart);
|
|
1151
1158
|
const [head] = propResult.propSegments;
|
|
@@ -2443,6 +2450,7 @@ function analyzeStatePaths(scriptContent) {
|
|
|
2443
2450
|
}
|
|
2444
2451
|
}
|
|
2445
2452
|
collectRowShapesFromAssignments(scriptContent, paths);
|
|
2453
|
+
collectGetterResultShapes(topLevelProps, effectiveDescriptors, paths);
|
|
2446
2454
|
return paths;
|
|
2447
2455
|
}
|
|
2448
2456
|
function specFromRecursionValue(prop) {
|
|
@@ -2826,6 +2834,284 @@ function pushRowFieldPaths(path, prop, paths, depth) {
|
|
|
2826
2834
|
}
|
|
2827
2835
|
}
|
|
2828
2836
|
}
|
|
2837
|
+
var ROW_PRESERVING_METHODS = /* @__PURE__ */ new Set([
|
|
2838
|
+
"filter",
|
|
2839
|
+
"toSorted",
|
|
2840
|
+
"toReversed",
|
|
2841
|
+
"slice",
|
|
2842
|
+
"toSpliced",
|
|
2843
|
+
"concat",
|
|
2844
|
+
"with",
|
|
2845
|
+
"sort",
|
|
2846
|
+
"reverse"
|
|
2847
|
+
]);
|
|
2848
|
+
var ROW_PICKING_METHODS = /* @__PURE__ */ new Set(["find", "findLast", "at"]);
|
|
2849
|
+
var MAX_GETTER_SHAPE_PASSES = 4;
|
|
2850
|
+
function collectGetterResultShapes(props, effective, paths) {
|
|
2851
|
+
const getters = /* @__PURE__ */ new Map();
|
|
2852
|
+
for (const prop of props) {
|
|
2853
|
+
if (prop.kind !== "getter" || prop.accessor !== "get" || prop.value === void 0) continue;
|
|
2854
|
+
if (prop.name.startsWith("$") || hasRecursionWildcard(prop.name) || effective.get(prop.name) === "data") continue;
|
|
2855
|
+
getters.set(prop.name, prop);
|
|
2856
|
+
}
|
|
2857
|
+
for (let pass = 0; pass < MAX_GETTER_SHAPE_PASSES; pass++) {
|
|
2858
|
+
const before = paths.length;
|
|
2859
|
+
for (const [name, prop] of getters) {
|
|
2860
|
+
const shape = getterResultShape(prop.value, paths);
|
|
2861
|
+
if (shape !== null) applyResultShape(name, shape, paths);
|
|
2862
|
+
}
|
|
2863
|
+
if (paths.length === before) break;
|
|
2864
|
+
}
|
|
2865
|
+
}
|
|
2866
|
+
function getterResultShape(body, paths) {
|
|
2867
|
+
const scan = maskCommentsAndStrings(body);
|
|
2868
|
+
const aliases = /* @__PURE__ */ new Map();
|
|
2869
|
+
for (const m of scan.matchAll(/\b(?:const|let|var)\s+([$\w]+)\s*=(?![=>])/g)) {
|
|
2870
|
+
const name = m[1];
|
|
2871
|
+
if (aliases.has(name)) continue;
|
|
2872
|
+
const start = m.index + m[0].length;
|
|
2873
|
+
const shape = expressionShape(readExpression(body, scan, start), paths, aliases);
|
|
2874
|
+
if (shape !== null) aliases.set(name, shape);
|
|
2875
|
+
}
|
|
2876
|
+
const shapes = [];
|
|
2877
|
+
for (const m of scan.matchAll(/\breturn\b/g)) {
|
|
2878
|
+
const start = m.index + m[0].length;
|
|
2879
|
+
const shape = expressionShape(readExpression(body, scan, start), paths, aliases);
|
|
2880
|
+
if (shape !== null) shapes.push(shape);
|
|
2881
|
+
}
|
|
2882
|
+
return shapes.length === 0 ? null : mergeShapes(shapes);
|
|
2883
|
+
}
|
|
2884
|
+
function readExpression(text3, scan, start) {
|
|
2885
|
+
let depth = 0;
|
|
2886
|
+
let i = start;
|
|
2887
|
+
for (; i < scan.length; i++) {
|
|
2888
|
+
const ch = scan[i];
|
|
2889
|
+
if (ch === "(" || ch === "[" || ch === "{") depth++;
|
|
2890
|
+
else if (ch === ")" || ch === "]" || ch === "}") {
|
|
2891
|
+
if (depth === 0) break;
|
|
2892
|
+
depth--;
|
|
2893
|
+
} else if (depth === 0 && (ch === ";" || ch === ",")) break;
|
|
2894
|
+
else if (depth === 0 && ch === "\n") {
|
|
2895
|
+
const before = scan.slice(start, i).trimEnd();
|
|
2896
|
+
const after = scan.slice(i + 1).trimStart();
|
|
2897
|
+
if (before === "") continue;
|
|
2898
|
+
if (!/[.?:|&+\-*/=(,]$/.test(before) && !/^[.?:|&]/.test(after)) break;
|
|
2899
|
+
}
|
|
2900
|
+
}
|
|
2901
|
+
return text3.slice(start, i).trim();
|
|
2902
|
+
}
|
|
2903
|
+
function expressionShape(text3, paths, aliases) {
|
|
2904
|
+
const expr = stripWrappingParens(text3.trim());
|
|
2905
|
+
if (expr === "") return null;
|
|
2906
|
+
const scan = maskCommentsAndStrings(expr);
|
|
2907
|
+
const ternary = splitTernary(scan);
|
|
2908
|
+
if (ternary !== null) {
|
|
2909
|
+
const branches = [expr.slice(ternary[0] + 1, ternary[1]), expr.slice(ternary[1] + 1)].map((part) => expressionShape(part, paths, aliases)).filter((s) => s !== null);
|
|
2910
|
+
return branches.length === 0 ? null : mergeShapes(branches);
|
|
2911
|
+
}
|
|
2912
|
+
const operands = splitTopLevel(scan, /\|\||\?\?/g);
|
|
2913
|
+
if (operands.length > 1) {
|
|
2914
|
+
const sides = operands.map(([s, e]) => expressionShape(expr.slice(s, e), paths, aliases)).filter((s) => s !== null);
|
|
2915
|
+
return sides.length === 0 ? null : mergeShapes(sides);
|
|
2916
|
+
}
|
|
2917
|
+
if (scan.startsWith("{")) {
|
|
2918
|
+
if (extractDelimitedContent(expr, scan, 0, "{", "}").length !== expr.length - 2) return null;
|
|
2919
|
+
return { isList: false, mirrors: [], fields: extractRowLiteralFields(expr).map((field) => ({ to: "", field })) };
|
|
2920
|
+
}
|
|
2921
|
+
let shape;
|
|
2922
|
+
let rest;
|
|
2923
|
+
if (scan.startsWith("[")) {
|
|
2924
|
+
const inner = extractDelimitedContent(expr, scan, 0, "[", "]");
|
|
2925
|
+
rest = inner.length + 2;
|
|
2926
|
+
const spread = /^\s*\.\.\.([\s\S]+)$/.exec(inner);
|
|
2927
|
+
if (spread === null || splitTopLevelElements(inner).length !== 1) return null;
|
|
2928
|
+
const source = expressionShape(spread[1], paths, aliases);
|
|
2929
|
+
if (source === null || !source.isList) return null;
|
|
2930
|
+
shape = source;
|
|
2931
|
+
} else {
|
|
2932
|
+
const base = readBase(expr, scan, aliases, paths);
|
|
2933
|
+
if (base === null) return null;
|
|
2934
|
+
({ shape, rest } = base);
|
|
2935
|
+
}
|
|
2936
|
+
return applyChain(expr, scan, rest, shape);
|
|
2937
|
+
}
|
|
2938
|
+
function readBase(expr, scan, aliases, paths) {
|
|
2939
|
+
const alias = /^([$\w]+)/.exec(scan);
|
|
2940
|
+
if (alias === null) return null;
|
|
2941
|
+
if (alias[1] !== "this") {
|
|
2942
|
+
const shape = aliases.get(alias[1]);
|
|
2943
|
+
return shape === void 0 ? null : { shape, rest: alias[1].length };
|
|
2944
|
+
}
|
|
2945
|
+
const segments = [];
|
|
2946
|
+
let i = 4;
|
|
2947
|
+
for (; ; ) {
|
|
2948
|
+
const dot = /^\s*\??\.\s*([$\w]+)/.exec(scan.slice(i));
|
|
2949
|
+
if (dot !== null) {
|
|
2950
|
+
if (/^\s*\(/.test(scan.slice(i + dot[0].length))) break;
|
|
2951
|
+
segments.push(dot[1]);
|
|
2952
|
+
i += dot[0].length;
|
|
2953
|
+
continue;
|
|
2954
|
+
}
|
|
2955
|
+
const bracket = /^\s*\[\s*(["'])/.exec(scan.slice(i));
|
|
2956
|
+
if (bracket !== null) {
|
|
2957
|
+
const open = i + bracket[0].length - 1;
|
|
2958
|
+
const close = scan.indexOf("]", open);
|
|
2959
|
+
const literal2 = /^(["'])([^"']*)\1\s*$/.exec(expr.slice(open, close));
|
|
2960
|
+
if (close === -1 || literal2 === null) return null;
|
|
2961
|
+
segments.push(literal2[2]);
|
|
2962
|
+
i = close + 1;
|
|
2963
|
+
continue;
|
|
2964
|
+
}
|
|
2965
|
+
break;
|
|
2966
|
+
}
|
|
2967
|
+
const path = segments.join(".");
|
|
2968
|
+
if (path === "" || path.startsWith("$")) return null;
|
|
2969
|
+
return {
|
|
2970
|
+
shape: { isList: hasPath(paths, `${path}.*`), mirrors: [{ from: path, to: "" }], fields: [] },
|
|
2971
|
+
rest: i
|
|
2972
|
+
};
|
|
2973
|
+
}
|
|
2974
|
+
function applyChain(expr, scan, start, initial) {
|
|
2975
|
+
let shape = initial;
|
|
2976
|
+
let i = start;
|
|
2977
|
+
while (scan.slice(i).trim() !== "") {
|
|
2978
|
+
const call = /^\s*\??\.\s*([$\w]+)\s*\(/.exec(scan.slice(i));
|
|
2979
|
+
if (call === null) return null;
|
|
2980
|
+
const open = i + call[0].length - 1;
|
|
2981
|
+
const args = extractDelimitedContent(expr, scan, open, "(", ")");
|
|
2982
|
+
i = open + args.length + 2;
|
|
2983
|
+
const method = call[1];
|
|
2984
|
+
if (ROW_PRESERVING_METHODS.has(method)) {
|
|
2985
|
+
if (!shape.isList) return null;
|
|
2986
|
+
} else if (ROW_PICKING_METHODS.has(method)) {
|
|
2987
|
+
if (!shape.isList) return null;
|
|
2988
|
+
shape = pickRow(shape);
|
|
2989
|
+
} else if (method === "map") {
|
|
2990
|
+
if (!shape.isList) return null;
|
|
2991
|
+
const mapped = mapRows(args, shape);
|
|
2992
|
+
if (mapped === null) return null;
|
|
2993
|
+
shape = mapped;
|
|
2994
|
+
} else {
|
|
2995
|
+
return null;
|
|
2996
|
+
}
|
|
2997
|
+
}
|
|
2998
|
+
return shape;
|
|
2999
|
+
}
|
|
3000
|
+
function pickRow(shape) {
|
|
3001
|
+
return {
|
|
3002
|
+
isList: false,
|
|
3003
|
+
mirrors: shape.mirrors.map((m) => m.to === "" ? { from: `${m.from}.*`, to: "" } : { from: m.from, to: "" }),
|
|
3004
|
+
fields: shape.fields.filter((f) => f.to === ".*").map((f) => ({ to: "", field: f.field }))
|
|
3005
|
+
};
|
|
3006
|
+
}
|
|
3007
|
+
function mapRows(args, shape) {
|
|
3008
|
+
const [callback] = splitTopLevelElements(args);
|
|
3009
|
+
if (callback === void 0) return null;
|
|
3010
|
+
const head = /^(?:async\s+)?(?:function\b[^(]*\(\s*([$\w]+)[^)]*\)|\(\s*([$\w]+)[^)]*\)|([$\w]+))\s*(=>)?\s*/.exec(callback);
|
|
3011
|
+
if (head === null) return null;
|
|
3012
|
+
const param = head[1] ?? head[2] ?? head[3];
|
|
3013
|
+
const body = callback.slice(head[0].length);
|
|
3014
|
+
let literal2 = null;
|
|
3015
|
+
const bodyScan = maskCommentsAndStrings(body);
|
|
3016
|
+
if (bodyScan.startsWith("(")) {
|
|
3017
|
+
const inner = stripWrappingParens(body).trim();
|
|
3018
|
+
if (inner.startsWith("{")) literal2 = inner;
|
|
3019
|
+
} else if (bodyScan.startsWith("{")) {
|
|
3020
|
+
const block = extractDelimitedContent(body, bodyScan, 0, "{", "}");
|
|
3021
|
+
const blockScan = maskCommentsAndStrings(block);
|
|
3022
|
+
const ret = /\breturn\s*\{/.exec(blockScan);
|
|
3023
|
+
if (ret !== null) {
|
|
3024
|
+
const open = ret.index + ret[0].length - 1;
|
|
3025
|
+
literal2 = `{${extractDelimitedContent(block, blockScan, open, "{", "}")}}`;
|
|
3026
|
+
}
|
|
3027
|
+
}
|
|
3028
|
+
if (literal2 === null) return null;
|
|
3029
|
+
const content = extractObjectContent(literal2);
|
|
3030
|
+
const spreadsRow = splitTopLevelElements(content).some((e) => e === `...${param}`);
|
|
3031
|
+
return {
|
|
3032
|
+
isList: true,
|
|
3033
|
+
mirrors: spreadsRow ? shape.mirrors.map((m) => m.to === "" ? { from: `${m.from}.*`, to: ".*" } : m) : [],
|
|
3034
|
+
fields: [
|
|
3035
|
+
...spreadsRow ? shape.fields.filter((f) => f.to === ".*") : [],
|
|
3036
|
+
...extractRowLiteralFields(literal2).map((field) => ({ to: ".*", field }))
|
|
3037
|
+
]
|
|
3038
|
+
};
|
|
3039
|
+
}
|
|
3040
|
+
function applyResultShape(getter, shape, paths) {
|
|
3041
|
+
if (shape.isList) {
|
|
3042
|
+
if (!hasPath(paths, `${getter}.*`)) paths.push({ path: `${getter}.*`, kind: "list" });
|
|
3043
|
+
if (!hasPath(paths, `${getter}.length`)) paths.push({ path: `${getter}.length`, kind: "data", typeHint: "number" });
|
|
3044
|
+
}
|
|
3045
|
+
for (const { from, to } of shape.mirrors) {
|
|
3046
|
+
if (from === getter || from.startsWith(`${getter}.`)) continue;
|
|
3047
|
+
const sources = paths.filter((p) => p.path.startsWith(`${from}.`) && (p.kind === "data" || p.kind === "list"));
|
|
3048
|
+
for (const source of sources) {
|
|
3049
|
+
const target = `${getter}${to}${source.path.slice(from.length)}`;
|
|
3050
|
+
if (!hasPath(paths, target)) paths.push(withHint({ path: target, kind: source.kind }, source.typeHint));
|
|
3051
|
+
}
|
|
3052
|
+
}
|
|
3053
|
+
for (const { to, field } of shape.fields) {
|
|
3054
|
+
pushRowFieldPaths(`${getter}${to}.${field.name}`, field, paths, 1);
|
|
3055
|
+
}
|
|
3056
|
+
}
|
|
3057
|
+
function mergeShapes(shapes) {
|
|
3058
|
+
return {
|
|
3059
|
+
isList: shapes.some((s) => s.isList),
|
|
3060
|
+
mirrors: shapes.flatMap((s) => s.mirrors),
|
|
3061
|
+
fields: shapes.flatMap((s) => s.fields)
|
|
3062
|
+
};
|
|
3063
|
+
}
|
|
3064
|
+
function stripWrappingParens(text3) {
|
|
3065
|
+
let expr = text3.trim();
|
|
3066
|
+
for (; ; ) {
|
|
3067
|
+
if (!expr.startsWith("(")) return expr;
|
|
3068
|
+
const scan = maskCommentsAndStrings(expr);
|
|
3069
|
+
const inner = extractDelimitedContent(expr, scan, 0, "(", ")");
|
|
3070
|
+
if (inner.length !== expr.length - 2) return expr;
|
|
3071
|
+
expr = inner.trim();
|
|
3072
|
+
}
|
|
3073
|
+
}
|
|
3074
|
+
function splitTernary(scan) {
|
|
3075
|
+
let depth = 0;
|
|
3076
|
+
let question = -1;
|
|
3077
|
+
let nested = 0;
|
|
3078
|
+
for (let i = 0; i < scan.length; i++) {
|
|
3079
|
+
const ch = scan[i];
|
|
3080
|
+
if (ch === "(" || ch === "[" || ch === "{") depth++;
|
|
3081
|
+
else if (ch === ")" || ch === "]" || ch === "}") depth--;
|
|
3082
|
+
else if (depth !== 0) continue;
|
|
3083
|
+
else if (ch === "?") {
|
|
3084
|
+
if (scan[i + 1] === "." || scan[i + 1] === "?" || scan[i - 1] === "?") continue;
|
|
3085
|
+
if (question === -1) question = i;
|
|
3086
|
+
else nested++;
|
|
3087
|
+
} else if (ch === ":" && question !== -1) {
|
|
3088
|
+
if (nested > 0) nested--;
|
|
3089
|
+
else return [question, i];
|
|
3090
|
+
}
|
|
3091
|
+
}
|
|
3092
|
+
return null;
|
|
3093
|
+
}
|
|
3094
|
+
function splitTopLevel(scan, separator) {
|
|
3095
|
+
const out = [];
|
|
3096
|
+
let depth = 0;
|
|
3097
|
+
let start = 0;
|
|
3098
|
+
for (let i = 0; i < scan.length; i++) {
|
|
3099
|
+
const ch = scan[i];
|
|
3100
|
+
if (ch === "(" || ch === "[" || ch === "{") depth++;
|
|
3101
|
+
else if (ch === ")" || ch === "]" || ch === "}") depth--;
|
|
3102
|
+
else if (depth === 0) {
|
|
3103
|
+
separator.lastIndex = i;
|
|
3104
|
+
const m = separator.exec(scan);
|
|
3105
|
+
if (m !== null && m.index === i) {
|
|
3106
|
+
out.push([start, i]);
|
|
3107
|
+
start = i + m[0].length;
|
|
3108
|
+
i = start - 1;
|
|
3109
|
+
}
|
|
3110
|
+
}
|
|
3111
|
+
}
|
|
3112
|
+
out.push([start, scan.length]);
|
|
3113
|
+
return out;
|
|
3114
|
+
}
|
|
2829
3115
|
function hasPath(paths, path) {
|
|
2830
3116
|
return paths.some((p) => p.path === path);
|
|
2831
3117
|
}
|
|
@@ -11055,7 +11341,7 @@ function validateFilterUsage(filter, bindingStart, msgs) {
|
|
|
11055
11341
|
start: bindingStart + filter.offset,
|
|
11056
11342
|
end: bindingStart + filter.offset + filter.name.length,
|
|
11057
11343
|
message: removedFilterMessage(filter.name, filter.args, msgs) ?? msgs.filterUnknown(filter.name),
|
|
11058
|
-
severity: "
|
|
11344
|
+
severity: "error"
|
|
11059
11345
|
});
|
|
11060
11346
|
return diagnostics;
|
|
11061
11347
|
}
|
|
@@ -11743,7 +12029,7 @@ function validateTemplateSyntax(html, stateTagName, bindAttrName = "data-wcs", l
|
|
|
11743
12029
|
start: item.exprStart + filterOffset,
|
|
11744
12030
|
end: item.exprStart + filterOffset + filterName.length,
|
|
11745
12031
|
message: removedFilterMessage(filterName, filterArgsOf(segment), msgs) ?? msgs.filterUnknown(filterName),
|
|
11746
|
-
severity: "
|
|
12032
|
+
severity: "error"
|
|
11747
12033
|
});
|
|
11748
12034
|
}
|
|
11749
12035
|
}
|
|
@@ -12360,7 +12646,11 @@ var BUILTIN_TAGS = {
|
|
|
12360
12646
|
"wcs-defined": {
|
|
12361
12647
|
"package": "defined",
|
|
12362
12648
|
"hasWcBindable": true,
|
|
12363
|
-
"observedAttributes": [
|
|
12649
|
+
"observedAttributes": [
|
|
12650
|
+
"tags",
|
|
12651
|
+
"mode",
|
|
12652
|
+
"timeout"
|
|
12653
|
+
],
|
|
12364
12654
|
"inputs": {
|
|
12365
12655
|
"tags": "tags",
|
|
12366
12656
|
"mode": "mode",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wcstack/lint",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "Static-contract validator CLI (wcs-validate) for wcstack data-wcs bindings and wcstack.manifest.json sidecars. Thin npm wrapper around the wcstack-intellisense validator core.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|