css-typed-vars 0.13.0 → 0.14.0
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/README.md +10 -7
- package/dist/{chunk-JGJ53FND.js → chunk-7J7UZYHB.js} +1 -1
- package/dist/{chunk-XSFYQPH6.js → chunk-BPZRXE6W.js} +141 -22
- package/dist/{chunk-FWKCSH2F.js → chunk-VWEQJVXA.js} +1 -1
- package/dist/cli.cjs +145 -21
- package/dist/cli.js +8 -3
- package/dist/esbuild.cjs +135 -17
- package/dist/esbuild.d.cts +1 -1
- package/dist/esbuild.d.ts +1 -1
- package/dist/esbuild.js +2 -2
- package/dist/{generator-BokM5zux.d.ts → generator-TJNk6ET_.d.cts} +5 -0
- package/dist/{generator-BokM5zux.d.cts → generator-TJNk6ET_.d.ts} +5 -0
- package/dist/index.cjs +133 -19
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/rollup.cjs +135 -17
- package/dist/rollup.d.cts +1 -1
- package/dist/rollup.d.ts +1 -1
- package/dist/rollup.js +2 -2
- package/dist/unplugin.cjs +135 -17
- package/dist/unplugin.d.cts +1 -1
- package/dist/unplugin.d.ts +1 -1
- package/dist/unplugin.js +2 -2
- package/dist/vite.cjs +135 -17
- package/dist/vite.d.cts +1 -1
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +2 -2
- package/dist/webpack.cjs +135 -17
- package/dist/webpack.d.cts +1 -1
- package/dist/webpack.d.ts +1 -1
- package/dist/webpack.js +2 -2
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -165,17 +165,78 @@ function extractValue(text, start) {
|
|
|
165
165
|
else if (char === open[open.length - 1]) open.pop();
|
|
166
166
|
else if (char === "}" || char === ";" && open.length === 0) break;
|
|
167
167
|
}
|
|
168
|
-
return text.slice(start, i).trim();
|
|
168
|
+
return joinLines(text.slice(start, i).trim());
|
|
169
|
+
}
|
|
170
|
+
function joinLines(value) {
|
|
171
|
+
if (!/[\n\r]/.test(value)) return value;
|
|
172
|
+
const masked = maskQuotedContent(value);
|
|
173
|
+
let result = "";
|
|
174
|
+
let last = 0;
|
|
175
|
+
for (const match of masked.matchAll(/\s*[\n\r]\s*/g)) {
|
|
176
|
+
result += value.slice(last, match.index) + " ";
|
|
177
|
+
last = match.index + match[0].length;
|
|
178
|
+
}
|
|
179
|
+
return result + value.slice(last);
|
|
169
180
|
}
|
|
170
181
|
var IMPORTANT = /\s*!\s*important$/i;
|
|
182
|
+
var DECLARATION_NAME = /(?<=(?:^|[{;}])\s*)--[\w-]+(?=\s*:)/g;
|
|
171
183
|
function forEachProperty(block, onProperty, offset = 0) {
|
|
172
184
|
const masked = maskQuotedContent(block);
|
|
173
|
-
for (const prop of masked.matchAll(
|
|
185
|
+
for (const prop of masked.matchAll(DECLARATION_NAME)) {
|
|
174
186
|
const name = prop[0];
|
|
175
187
|
const colonIndex = block.indexOf(":", prop.index + name.length);
|
|
176
188
|
onProperty(name, extractValue(block, colonIndex + 1).replace(IMPORTANT, ""), offset + prop.index);
|
|
177
189
|
}
|
|
178
190
|
}
|
|
191
|
+
var inRanges = (ranges, position) => ranges.some(([start, end]) => position >= start && position < end);
|
|
192
|
+
function nestedRanges(block) {
|
|
193
|
+
const masked = maskQuotedContent(block);
|
|
194
|
+
const ranges = [];
|
|
195
|
+
const statement = /\s*(--[\w-]+\s*:)?/y;
|
|
196
|
+
let i = 0;
|
|
197
|
+
while (i < block.length) {
|
|
198
|
+
statement.lastIndex = i;
|
|
199
|
+
const match = statement.exec(masked);
|
|
200
|
+
i = statement.lastIndex;
|
|
201
|
+
if (match[1]) {
|
|
202
|
+
const raw = block.slice(i);
|
|
203
|
+
i += raw.length - raw.trimStart().length + extractValue(block, i).length;
|
|
204
|
+
while (i < block.length && block[i] !== ";" && block[i] !== "}") i++;
|
|
205
|
+
i++;
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
for (let depth = 0; i < block.length; i++) {
|
|
209
|
+
const char = masked[i];
|
|
210
|
+
if (char === "(") depth++;
|
|
211
|
+
else if (char === ")") depth = Math.max(0, depth - 1);
|
|
212
|
+
else if (depth === 0 && (char === ";" || char === "{" || char === "}")) break;
|
|
213
|
+
}
|
|
214
|
+
if (masked[i] === "{") {
|
|
215
|
+
const body = extractBlock(block, i + 1);
|
|
216
|
+
ranges.push([i + 1, i + 1 + body.length]);
|
|
217
|
+
i += body.length + 1;
|
|
218
|
+
}
|
|
219
|
+
i++;
|
|
220
|
+
}
|
|
221
|
+
return ranges;
|
|
222
|
+
}
|
|
223
|
+
function forEachOwnProperty(block, onProperty, offset = 0) {
|
|
224
|
+
const nested = nestedRanges(block);
|
|
225
|
+
forEachProperty(block, (name, value, position) => {
|
|
226
|
+
if (!inRanges(nested, position - offset)) onProperty(name, value, position);
|
|
227
|
+
}, offset);
|
|
228
|
+
}
|
|
229
|
+
function conditionalRanges(stripped) {
|
|
230
|
+
const masked = maskQuotedContent(stripped);
|
|
231
|
+
const ranges = [];
|
|
232
|
+
const openRegex = /@(?:media|supports|container)\b[^{;]*\{/gi;
|
|
233
|
+
let match;
|
|
234
|
+
while (match = openRegex.exec(masked)) {
|
|
235
|
+
const start = match.index + match[0].length;
|
|
236
|
+
ranges.push([start, start + extractBlock(stripped, start).length]);
|
|
237
|
+
}
|
|
238
|
+
return ranges;
|
|
239
|
+
}
|
|
179
240
|
function forEachSelectorBlock(stripped, selectors, onBlock) {
|
|
180
241
|
for (const sel of selectors) {
|
|
181
242
|
const escaped = sel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
@@ -192,11 +253,27 @@ function forEachSelectorBlock(stripped, selectors, onBlock) {
|
|
|
192
253
|
}
|
|
193
254
|
var BASE_SELECTORS = [":root", "@theme"];
|
|
194
255
|
function scanDeclarations(css, selectors, onProperty, skip = [], stripped = stripComments(css)) {
|
|
256
|
+
const conditional = conditionalRanges(stripped);
|
|
195
257
|
forEachSelectorBlock(stripped, [...BASE_SELECTORS, ...selectors ?? []], (block, [bodyStart]) => {
|
|
196
|
-
|
|
197
|
-
forEachProperty(block,
|
|
258
|
+
const nested = nestedRanges(block);
|
|
259
|
+
forEachProperty(block, (name, value, position) => {
|
|
260
|
+
if (inRanges(skip, position)) return;
|
|
261
|
+
onProperty(name, value, position, inRanges(conditional, position) || inRanges(nested, position - bodyStart));
|
|
262
|
+
}, bodyStart);
|
|
198
263
|
});
|
|
199
264
|
}
|
|
265
|
+
function makeDeclarationCollector() {
|
|
266
|
+
const declarations = /* @__PURE__ */ new Map();
|
|
267
|
+
const conditional = /* @__PURE__ */ new Set();
|
|
268
|
+
const add = (name, value, isConditional) => {
|
|
269
|
+
if (isConditional && declarations.has(name) && !conditional.has(name)) return false;
|
|
270
|
+
declarations.set(name, value);
|
|
271
|
+
if (isConditional) conditional.add(name);
|
|
272
|
+
else conditional.delete(name);
|
|
273
|
+
return true;
|
|
274
|
+
};
|
|
275
|
+
return { declarations, conditional, add };
|
|
276
|
+
}
|
|
200
277
|
var normalizePrelude = (prelude) => prelude.replace(/\s+/g, "").toLowerCase();
|
|
201
278
|
function forEachMediaBlock(stripped, media, onBlock) {
|
|
202
279
|
const wanted = normalizePrelude(media.replace(/^@media/i, ""));
|
|
@@ -252,15 +329,17 @@ function parseThemedDeclarations(css, selectors, themes) {
|
|
|
252
329
|
for (const [themeName, themeSelector] of Object.entries(themes)) {
|
|
253
330
|
const values = /* @__PURE__ */ new Map();
|
|
254
331
|
themeValues.set(themeName, values);
|
|
255
|
-
const
|
|
332
|
+
const onProperty = (name, value, position) => {
|
|
256
333
|
values.set(name, value);
|
|
257
334
|
const doc = docAt(position);
|
|
258
335
|
if (doc) themeDocs.set(name, doc);
|
|
259
|
-
}
|
|
336
|
+
};
|
|
337
|
+
const collect = (block, offset) => forEachProperty(block, onProperty, offset);
|
|
260
338
|
const selector = themeSelector.trim();
|
|
261
339
|
if (/^@media\b/i.test(selector)) {
|
|
262
340
|
forEachMediaBlock(stripped, selector, (mediaBlock, range) => {
|
|
263
341
|
skip.push(range);
|
|
342
|
+
forEachOwnProperty(mediaBlock, onProperty, range[0]);
|
|
264
343
|
forEachSelectorBlock(mediaBlock, BASE_SELECTORS, (block, [innerStart]) => collect(block, range[0] + innerStart));
|
|
265
344
|
});
|
|
266
345
|
} else {
|
|
@@ -270,17 +349,17 @@ function parseThemedDeclarations(css, selectors, themes) {
|
|
|
270
349
|
});
|
|
271
350
|
}
|
|
272
351
|
}
|
|
273
|
-
const declarations
|
|
352
|
+
const { declarations, conditional, add } = makeDeclarationCollector();
|
|
274
353
|
const docs = /* @__PURE__ */ new Map();
|
|
275
|
-
scanDeclarations(css, selectors, (name, value, position) => {
|
|
276
|
-
|
|
354
|
+
scanDeclarations(css, selectors, (name, value, position, isConditional) => {
|
|
355
|
+
if (!add(name, value, isConditional)) return;
|
|
277
356
|
const doc = docAt(position);
|
|
278
357
|
if (doc) docs.set(name, doc);
|
|
279
358
|
}, skip, stripped);
|
|
280
359
|
for (const [name, doc] of themeDocs) {
|
|
281
360
|
if (!docs.has(name)) docs.set(name, doc);
|
|
282
361
|
}
|
|
283
|
-
return { declarations, themes: themeValues, docs };
|
|
362
|
+
return { declarations, conditional, themes: themeValues, docs };
|
|
284
363
|
}
|
|
285
364
|
var PROPERTY_DESCRIPTORS = [
|
|
286
365
|
["syntax", "syntax"],
|
|
@@ -319,13 +398,14 @@ function toRawPosition(stripped, strippedPos) {
|
|
|
319
398
|
}
|
|
320
399
|
return rawPos;
|
|
321
400
|
}
|
|
401
|
+
var CSS_REF_RE = /\bvar\(\s*(--[\w-]+)\s*(?:(,)|\))/gi;
|
|
322
402
|
function parseVarReferences(css) {
|
|
323
403
|
const stripped = stripCommentsWithMap(css);
|
|
324
404
|
const masked = maskQuotedContent(stripped.text);
|
|
325
405
|
const lineStarts = [0];
|
|
326
406
|
for (let i = 0; i < css.length; i++) if (css[i] === "\n") lineStarts.push(i + 1);
|
|
327
407
|
const refs = [];
|
|
328
|
-
for (const match of masked.matchAll(
|
|
408
|
+
for (const match of masked.matchAll(CSS_REF_RE)) {
|
|
329
409
|
const rawPos = toRawPosition(stripped, match.index);
|
|
330
410
|
let line = lineStarts.length - 1;
|
|
331
411
|
while (lineStarts[line] > rawPos) line--;
|
|
@@ -333,7 +413,7 @@ function parseVarReferences(css) {
|
|
|
333
413
|
}
|
|
334
414
|
return refs;
|
|
335
415
|
}
|
|
336
|
-
var SOURCE_REF_RE = /\bvar\(\s*(--[\w-]+)\s*(,)
|
|
416
|
+
var SOURCE_REF_RE = /\bvar\(\s*(--[\w-]+)\s*(?:(,)|\))|(?<=[\w-]-)\((?:[\w-]+:)?(--[\w-]+)\)/g;
|
|
337
417
|
function parseSourceVarReferences(text) {
|
|
338
418
|
const lineStarts = [0];
|
|
339
419
|
for (let i = 0; i < text.length; i++) if (text[i] === "\n") lineStarts.push(i + 1);
|
|
@@ -359,7 +439,7 @@ function parseSourceDeclaredNames(text) {
|
|
|
359
439
|
function parseDeclaredNames(css) {
|
|
360
440
|
const masked = maskQuotedContent(stripComments(css));
|
|
361
441
|
const names = /* @__PURE__ */ new Set();
|
|
362
|
-
for (const match of masked.matchAll(/(?<![\w
|
|
442
|
+
for (const match of masked.matchAll(/(?<![\w&-])(--[\w-]+)\s*:/g)) names.add(match[1]);
|
|
363
443
|
for (const match of masked.matchAll(/@property\s+(--[\w-]+)/g)) names.add(match[1]);
|
|
364
444
|
return names;
|
|
365
445
|
}
|
|
@@ -402,9 +482,13 @@ async function findFiles(patterns, exclude) {
|
|
|
402
482
|
return [...new Set(files.reverse())].reverse();
|
|
403
483
|
}
|
|
404
484
|
function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
|
|
405
|
-
const compile = (globs) => (0, import_picomatch.default)(
|
|
406
|
-
const
|
|
407
|
-
const
|
|
485
|
+
const compile = (globs) => (0, import_picomatch.default)(globs.map((p) => p.replace(/^\.\//, "")));
|
|
486
|
+
const normalized = normalizePatterns(patterns);
|
|
487
|
+
const include = compile(normalized.filter((p) => !p.startsWith("!")));
|
|
488
|
+
const ignore = compile([
|
|
489
|
+
...exclude ? normalizePatterns(exclude) : [],
|
|
490
|
+
...normalized.filter((p) => p.startsWith("!")).map((p) => p.slice(1))
|
|
491
|
+
]);
|
|
408
492
|
return (file) => {
|
|
409
493
|
const absolute = (0, import_node_path.resolve)(cwd, file).replace(/\\/g, "/");
|
|
410
494
|
const fromCwd = (0, import_node_path.relative)(cwd, absolute).replace(/\\/g, "/");
|
|
@@ -415,6 +499,7 @@ function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
|
|
|
415
499
|
function globWatchRoots(patterns, cwd = process.cwd()) {
|
|
416
500
|
const roots = /* @__PURE__ */ new Map();
|
|
417
501
|
for (const pattern of normalizePatterns(patterns)) {
|
|
502
|
+
if (pattern.startsWith("!")) continue;
|
|
418
503
|
const { base, glob: glob2, isGlob } = import_picomatch.default.scan(pattern);
|
|
419
504
|
const dir = (0, import_node_path.resolve)(cwd, isGlob ? base || "." : (0, import_node_path.dirname)(pattern));
|
|
420
505
|
const depth = !isGlob ? 0 : /\*\*|\{[^}]*\//.test(glob2) ? void 0 : glob2.split("/").length - 1;
|
|
@@ -446,12 +531,19 @@ async function scanCss(patterns, exclude, selectors, themes = {}) {
|
|
|
446
531
|
})
|
|
447
532
|
);
|
|
448
533
|
const declarations = /* @__PURE__ */ new Map();
|
|
534
|
+
const conditional = /* @__PURE__ */ new Set();
|
|
449
535
|
const properties = /* @__PURE__ */ new Map();
|
|
450
536
|
const themeValues = new Map(Object.keys(themes).map((theme) => [theme, /* @__PURE__ */ new Map()]));
|
|
451
537
|
const docs = /* @__PURE__ */ new Map();
|
|
452
538
|
for (const result of perFile) {
|
|
453
539
|
if (!result) continue;
|
|
454
|
-
for (const [name, value] of result.declarations)
|
|
540
|
+
for (const [name, value] of result.declarations) {
|
|
541
|
+
const isConditional = result.conditional.has(name);
|
|
542
|
+
if (isConditional && declarations.has(name) && !conditional.has(name)) continue;
|
|
543
|
+
declarations.set(name, value);
|
|
544
|
+
if (isConditional) conditional.add(name);
|
|
545
|
+
else conditional.delete(name);
|
|
546
|
+
}
|
|
455
547
|
for (const [name, rule] of result.properties) properties.set(name, rule);
|
|
456
548
|
for (const [name, doc] of result.docs) docs.set(name, doc);
|
|
457
549
|
for (const [theme, values] of result.themes) {
|
|
@@ -472,19 +564,46 @@ function rootPattern(text) {
|
|
|
472
564
|
const names = [...aliases].map((alias) => alias.replace(/\$/g, "\\$")).join("|");
|
|
473
565
|
return new RegExp(`${ROOT_RE.source}|(?<![\\w$.])(?:${names})(?![\\w$])`, "g");
|
|
474
566
|
}
|
|
475
|
-
var ACCESS_RE = /\s*(
|
|
567
|
+
var ACCESS_RE = /\s*(?:\??\.\s*([A-Za-z_$][\w$]*)|(?:\?\.\s*)?\[\s*(['"`])((?:(?!\2).)*)\2\s*\])/y;
|
|
476
568
|
function readAccess(text, from) {
|
|
477
569
|
ACCESS_RE.lastIndex = from;
|
|
478
570
|
const match = ACCESS_RE.exec(text);
|
|
479
571
|
return match ? { key: match[1] ?? match[3], end: ACCESS_RE.lastIndex } : null;
|
|
480
572
|
}
|
|
573
|
+
var PATTERN_KEY_RE = /^\s*(?:([A-Za-z_$][\w$]*)|(['"`])((?:(?!\2).)*)\2)\s*(?:[:=]|$)/;
|
|
574
|
+
function readPatternKeys(text, at) {
|
|
575
|
+
let i = at - 1;
|
|
576
|
+
while (i >= 0 && /\s/.test(text[i])) i--;
|
|
577
|
+
if (text[i] !== "=") return [];
|
|
578
|
+
i--;
|
|
579
|
+
while (i >= 0 && /\s/.test(text[i])) i--;
|
|
580
|
+
if (text[i] !== "}") return [];
|
|
581
|
+
const open = text.lastIndexOf("{", i);
|
|
582
|
+
if (open === -1) return [];
|
|
583
|
+
const body = text.slice(open + 1, i);
|
|
584
|
+
if (body.includes("}")) return [];
|
|
585
|
+
const keys = [];
|
|
586
|
+
for (const part of body.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, "").split(",")) {
|
|
587
|
+
const match = PATTERN_KEY_RE.exec(part);
|
|
588
|
+
if (match) keys.push(match[1] ?? match[3]);
|
|
589
|
+
}
|
|
590
|
+
return keys;
|
|
591
|
+
}
|
|
481
592
|
function extractUsage(text, into) {
|
|
482
593
|
for (const root of text.matchAll(rootPattern(text))) {
|
|
483
594
|
const first = readAccess(text, root.index + root[0].length);
|
|
484
|
-
|
|
595
|
+
const second = first && readAccess(text, first.end);
|
|
596
|
+
const destructured = second ? [] : readPatternKeys(text, root.index);
|
|
597
|
+
if (!first) {
|
|
598
|
+
for (const key of destructured) {
|
|
599
|
+
into.keys.add(key);
|
|
600
|
+
into.wholeKeys.add(key);
|
|
601
|
+
}
|
|
602
|
+
continue;
|
|
603
|
+
}
|
|
485
604
|
into.keys.add(first.key);
|
|
486
|
-
const second = readAccess(text, first.end);
|
|
487
605
|
if (second) into.paths.add(`${first.key}\0${second.key}`);
|
|
606
|
+
else if (destructured.length > 0) for (const leaf of destructured) into.paths.add(`${first.key}\0${leaf}`);
|
|
488
607
|
else into.wholeKeys.add(first.key);
|
|
489
608
|
}
|
|
490
609
|
}
|
|
@@ -1133,6 +1252,11 @@ function suggest(value, candidates) {
|
|
|
1133
1252
|
const closest = candidates.reduce((best, candidate) => editDistance(value, candidate) < editDistance(value, best) ? candidate : best);
|
|
1134
1253
|
return editDistance(value, closest) <= 2 ? ` Did you mean ${closest}?` : "";
|
|
1135
1254
|
}
|
|
1255
|
+
function suggestNaming(value) {
|
|
1256
|
+
const bare = value.toLowerCase().replace(/[-_ ]?case$/, "");
|
|
1257
|
+
const match = VALID_NAMINGS.find((naming) => naming.toLowerCase().replace(/case$/, "") === bare);
|
|
1258
|
+
return match ? ` Did you mean ${match}?` : suggest(value, VALID_NAMINGS);
|
|
1259
|
+
}
|
|
1136
1260
|
function validateArgs() {
|
|
1137
1261
|
for (let i = 0; i < args.length; i++) {
|
|
1138
1262
|
const arg = args[i];
|
|
@@ -1252,7 +1376,7 @@ function validateModes() {
|
|
|
1252
1376
|
function validateTarget({ options, tag }, single) {
|
|
1253
1377
|
const { input, output, naming, group, prefix, prune, usage } = options;
|
|
1254
1378
|
if (naming !== void 0 && !VALID_NAMINGS.includes(naming)) {
|
|
1255
|
-
throw new CliError(`${tag}: invalid --naming value "${naming}"
|
|
1379
|
+
throw new CliError(`${tag}: invalid --naming value "${naming}".${suggestNaming(String(naming))} Valid values: ${VALID_NAMINGS.join(", ")}`);
|
|
1256
1380
|
}
|
|
1257
1381
|
if (lintRefsMode) {
|
|
1258
1382
|
if (!input) throw new CliError(`${tag}: --lint-refs requires --input <glob> (or "input" in the config file).`);
|
package/dist/cli.js
CHANGED
|
@@ -4,12 +4,12 @@ import {
|
|
|
4
4
|
findUndefinedRefs,
|
|
5
5
|
findUnusedVars,
|
|
6
6
|
generate
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-VWEQJVXA.js";
|
|
8
8
|
import {
|
|
9
9
|
VALID_NAMINGS,
|
|
10
10
|
createFileMatcher,
|
|
11
11
|
globWatchRoots
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-BPZRXE6W.js";
|
|
13
13
|
|
|
14
14
|
// src/cli.ts
|
|
15
15
|
import { access, readFile } from "fs/promises";
|
|
@@ -145,6 +145,11 @@ function suggest(value, candidates) {
|
|
|
145
145
|
const closest = candidates.reduce((best, candidate) => editDistance(value, candidate) < editDistance(value, best) ? candidate : best);
|
|
146
146
|
return editDistance(value, closest) <= 2 ? ` Did you mean ${closest}?` : "";
|
|
147
147
|
}
|
|
148
|
+
function suggestNaming(value) {
|
|
149
|
+
const bare = value.toLowerCase().replace(/[-_ ]?case$/, "");
|
|
150
|
+
const match = VALID_NAMINGS.find((naming) => naming.toLowerCase().replace(/case$/, "") === bare);
|
|
151
|
+
return match ? ` Did you mean ${match}?` : suggest(value, VALID_NAMINGS);
|
|
152
|
+
}
|
|
148
153
|
function validateArgs() {
|
|
149
154
|
for (let i = 0; i < args.length; i++) {
|
|
150
155
|
const arg = args[i];
|
|
@@ -264,7 +269,7 @@ function validateModes() {
|
|
|
264
269
|
function validateTarget({ options, tag }, single) {
|
|
265
270
|
const { input, output, naming, group, prefix, prune, usage } = options;
|
|
266
271
|
if (naming !== void 0 && !VALID_NAMINGS.includes(naming)) {
|
|
267
|
-
throw new CliError(`${tag}: invalid --naming value "${naming}"
|
|
272
|
+
throw new CliError(`${tag}: invalid --naming value "${naming}".${suggestNaming(String(naming))} Valid values: ${VALID_NAMINGS.join(", ")}`);
|
|
268
273
|
}
|
|
269
274
|
if (lintRefsMode) {
|
|
270
275
|
if (!input) throw new CliError(`${tag}: --lint-refs requires --input <glob> (or "input" in the config file).`);
|
package/dist/esbuild.cjs
CHANGED
|
@@ -183,17 +183,78 @@ function extractValue(text, start) {
|
|
|
183
183
|
else if (char === open[open.length - 1]) open.pop();
|
|
184
184
|
else if (char === "}" || char === ";" && open.length === 0) break;
|
|
185
185
|
}
|
|
186
|
-
return text.slice(start, i).trim();
|
|
186
|
+
return joinLines(text.slice(start, i).trim());
|
|
187
|
+
}
|
|
188
|
+
function joinLines(value) {
|
|
189
|
+
if (!/[\n\r]/.test(value)) return value;
|
|
190
|
+
const masked = maskQuotedContent(value);
|
|
191
|
+
let result = "";
|
|
192
|
+
let last = 0;
|
|
193
|
+
for (const match of masked.matchAll(/\s*[\n\r]\s*/g)) {
|
|
194
|
+
result += value.slice(last, match.index) + " ";
|
|
195
|
+
last = match.index + match[0].length;
|
|
196
|
+
}
|
|
197
|
+
return result + value.slice(last);
|
|
187
198
|
}
|
|
188
199
|
var IMPORTANT = /\s*!\s*important$/i;
|
|
200
|
+
var DECLARATION_NAME = /(?<=(?:^|[{;}])\s*)--[\w-]+(?=\s*:)/g;
|
|
189
201
|
function forEachProperty(block, onProperty, offset = 0) {
|
|
190
202
|
const masked = maskQuotedContent(block);
|
|
191
|
-
for (const prop of masked.matchAll(
|
|
203
|
+
for (const prop of masked.matchAll(DECLARATION_NAME)) {
|
|
192
204
|
const name = prop[0];
|
|
193
205
|
const colonIndex = block.indexOf(":", prop.index + name.length);
|
|
194
206
|
onProperty(name, extractValue(block, colonIndex + 1).replace(IMPORTANT, ""), offset + prop.index);
|
|
195
207
|
}
|
|
196
208
|
}
|
|
209
|
+
var inRanges = (ranges, position) => ranges.some(([start, end]) => position >= start && position < end);
|
|
210
|
+
function nestedRanges(block) {
|
|
211
|
+
const masked = maskQuotedContent(block);
|
|
212
|
+
const ranges = [];
|
|
213
|
+
const statement = /\s*(--[\w-]+\s*:)?/y;
|
|
214
|
+
let i = 0;
|
|
215
|
+
while (i < block.length) {
|
|
216
|
+
statement.lastIndex = i;
|
|
217
|
+
const match = statement.exec(masked);
|
|
218
|
+
i = statement.lastIndex;
|
|
219
|
+
if (match[1]) {
|
|
220
|
+
const raw = block.slice(i);
|
|
221
|
+
i += raw.length - raw.trimStart().length + extractValue(block, i).length;
|
|
222
|
+
while (i < block.length && block[i] !== ";" && block[i] !== "}") i++;
|
|
223
|
+
i++;
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
for (let depth = 0; i < block.length; i++) {
|
|
227
|
+
const char = masked[i];
|
|
228
|
+
if (char === "(") depth++;
|
|
229
|
+
else if (char === ")") depth = Math.max(0, depth - 1);
|
|
230
|
+
else if (depth === 0 && (char === ";" || char === "{" || char === "}")) break;
|
|
231
|
+
}
|
|
232
|
+
if (masked[i] === "{") {
|
|
233
|
+
const body = extractBlock(block, i + 1);
|
|
234
|
+
ranges.push([i + 1, i + 1 + body.length]);
|
|
235
|
+
i += body.length + 1;
|
|
236
|
+
}
|
|
237
|
+
i++;
|
|
238
|
+
}
|
|
239
|
+
return ranges;
|
|
240
|
+
}
|
|
241
|
+
function forEachOwnProperty(block, onProperty, offset = 0) {
|
|
242
|
+
const nested = nestedRanges(block);
|
|
243
|
+
forEachProperty(block, (name, value, position) => {
|
|
244
|
+
if (!inRanges(nested, position - offset)) onProperty(name, value, position);
|
|
245
|
+
}, offset);
|
|
246
|
+
}
|
|
247
|
+
function conditionalRanges(stripped) {
|
|
248
|
+
const masked = maskQuotedContent(stripped);
|
|
249
|
+
const ranges = [];
|
|
250
|
+
const openRegex = /@(?:media|supports|container)\b[^{;]*\{/gi;
|
|
251
|
+
let match;
|
|
252
|
+
while (match = openRegex.exec(masked)) {
|
|
253
|
+
const start = match.index + match[0].length;
|
|
254
|
+
ranges.push([start, start + extractBlock(stripped, start).length]);
|
|
255
|
+
}
|
|
256
|
+
return ranges;
|
|
257
|
+
}
|
|
197
258
|
function forEachSelectorBlock(stripped, selectors, onBlock) {
|
|
198
259
|
for (const sel of selectors) {
|
|
199
260
|
const escaped = sel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
@@ -210,11 +271,27 @@ function forEachSelectorBlock(stripped, selectors, onBlock) {
|
|
|
210
271
|
}
|
|
211
272
|
var BASE_SELECTORS = [":root", "@theme"];
|
|
212
273
|
function scanDeclarations(css, selectors, onProperty, skip = [], stripped = stripComments(css)) {
|
|
274
|
+
const conditional = conditionalRanges(stripped);
|
|
213
275
|
forEachSelectorBlock(stripped, [...BASE_SELECTORS, ...selectors ?? []], (block, [bodyStart]) => {
|
|
214
|
-
|
|
215
|
-
forEachProperty(block,
|
|
276
|
+
const nested = nestedRanges(block);
|
|
277
|
+
forEachProperty(block, (name, value, position) => {
|
|
278
|
+
if (inRanges(skip, position)) return;
|
|
279
|
+
onProperty(name, value, position, inRanges(conditional, position) || inRanges(nested, position - bodyStart));
|
|
280
|
+
}, bodyStart);
|
|
216
281
|
});
|
|
217
282
|
}
|
|
283
|
+
function makeDeclarationCollector() {
|
|
284
|
+
const declarations = /* @__PURE__ */ new Map();
|
|
285
|
+
const conditional = /* @__PURE__ */ new Set();
|
|
286
|
+
const add = (name, value, isConditional) => {
|
|
287
|
+
if (isConditional && declarations.has(name) && !conditional.has(name)) return false;
|
|
288
|
+
declarations.set(name, value);
|
|
289
|
+
if (isConditional) conditional.add(name);
|
|
290
|
+
else conditional.delete(name);
|
|
291
|
+
return true;
|
|
292
|
+
};
|
|
293
|
+
return { declarations, conditional, add };
|
|
294
|
+
}
|
|
218
295
|
var normalizePrelude = (prelude) => prelude.replace(/\s+/g, "").toLowerCase();
|
|
219
296
|
function forEachMediaBlock(stripped, media, onBlock) {
|
|
220
297
|
const wanted = normalizePrelude(media.replace(/^@media/i, ""));
|
|
@@ -270,15 +347,17 @@ function parseThemedDeclarations(css, selectors, themes) {
|
|
|
270
347
|
for (const [themeName, themeSelector] of Object.entries(themes)) {
|
|
271
348
|
const values = /* @__PURE__ */ new Map();
|
|
272
349
|
themeValues.set(themeName, values);
|
|
273
|
-
const
|
|
350
|
+
const onProperty = (name, value, position) => {
|
|
274
351
|
values.set(name, value);
|
|
275
352
|
const doc = docAt(position);
|
|
276
353
|
if (doc) themeDocs.set(name, doc);
|
|
277
|
-
}
|
|
354
|
+
};
|
|
355
|
+
const collect = (block, offset) => forEachProperty(block, onProperty, offset);
|
|
278
356
|
const selector = themeSelector.trim();
|
|
279
357
|
if (/^@media\b/i.test(selector)) {
|
|
280
358
|
forEachMediaBlock(stripped, selector, (mediaBlock, range) => {
|
|
281
359
|
skip.push(range);
|
|
360
|
+
forEachOwnProperty(mediaBlock, onProperty, range[0]);
|
|
282
361
|
forEachSelectorBlock(mediaBlock, BASE_SELECTORS, (block, [innerStart]) => collect(block, range[0] + innerStart));
|
|
283
362
|
});
|
|
284
363
|
} else {
|
|
@@ -288,17 +367,17 @@ function parseThemedDeclarations(css, selectors, themes) {
|
|
|
288
367
|
});
|
|
289
368
|
}
|
|
290
369
|
}
|
|
291
|
-
const declarations
|
|
370
|
+
const { declarations, conditional, add } = makeDeclarationCollector();
|
|
292
371
|
const docs = /* @__PURE__ */ new Map();
|
|
293
|
-
scanDeclarations(css, selectors, (name, value, position) => {
|
|
294
|
-
|
|
372
|
+
scanDeclarations(css, selectors, (name, value, position, isConditional) => {
|
|
373
|
+
if (!add(name, value, isConditional)) return;
|
|
295
374
|
const doc = docAt(position);
|
|
296
375
|
if (doc) docs.set(name, doc);
|
|
297
376
|
}, skip, stripped);
|
|
298
377
|
for (const [name, doc] of themeDocs) {
|
|
299
378
|
if (!docs.has(name)) docs.set(name, doc);
|
|
300
379
|
}
|
|
301
|
-
return { declarations, themes: themeValues, docs };
|
|
380
|
+
return { declarations, conditional, themes: themeValues, docs };
|
|
302
381
|
}
|
|
303
382
|
var PROPERTY_DESCRIPTORS = [
|
|
304
383
|
["syntax", "syntax"],
|
|
@@ -376,9 +455,13 @@ async function findFiles(patterns, exclude) {
|
|
|
376
455
|
return [...new Set(files.reverse())].reverse();
|
|
377
456
|
}
|
|
378
457
|
function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
|
|
379
|
-
const compile = (globs) => (0, import_picomatch.default)(
|
|
380
|
-
const
|
|
381
|
-
const
|
|
458
|
+
const compile = (globs) => (0, import_picomatch.default)(globs.map((p) => p.replace(/^\.\//, "")));
|
|
459
|
+
const normalized = normalizePatterns(patterns);
|
|
460
|
+
const include = compile(normalized.filter((p) => !p.startsWith("!")));
|
|
461
|
+
const ignore = compile([
|
|
462
|
+
...exclude ? normalizePatterns(exclude) : [],
|
|
463
|
+
...normalized.filter((p) => p.startsWith("!")).map((p) => p.slice(1))
|
|
464
|
+
]);
|
|
382
465
|
return (file) => {
|
|
383
466
|
const absolute = (0, import_node_path2.resolve)(cwd, file).replace(/\\/g, "/");
|
|
384
467
|
const fromCwd = (0, import_node_path2.relative)(cwd, absolute).replace(/\\/g, "/");
|
|
@@ -389,6 +472,7 @@ function createFileMatcher(patterns, exclude, cwd = process.cwd()) {
|
|
|
389
472
|
function globWatchRoots(patterns, cwd = process.cwd()) {
|
|
390
473
|
const roots = /* @__PURE__ */ new Map();
|
|
391
474
|
for (const pattern of normalizePatterns(patterns)) {
|
|
475
|
+
if (pattern.startsWith("!")) continue;
|
|
392
476
|
const { base, glob: glob2, isGlob } = import_picomatch.default.scan(pattern);
|
|
393
477
|
const dir = (0, import_node_path2.resolve)(cwd, isGlob ? base || "." : (0, import_node_path2.dirname)(pattern));
|
|
394
478
|
const depth = !isGlob ? 0 : /\*\*|\{[^}]*\//.test(glob2) ? void 0 : glob2.split("/").length - 1;
|
|
@@ -423,12 +507,19 @@ async function scanCss(patterns, exclude, selectors, themes = {}) {
|
|
|
423
507
|
})
|
|
424
508
|
);
|
|
425
509
|
const declarations = /* @__PURE__ */ new Map();
|
|
510
|
+
const conditional = /* @__PURE__ */ new Set();
|
|
426
511
|
const properties = /* @__PURE__ */ new Map();
|
|
427
512
|
const themeValues = new Map(Object.keys(themes).map((theme) => [theme, /* @__PURE__ */ new Map()]));
|
|
428
513
|
const docs = /* @__PURE__ */ new Map();
|
|
429
514
|
for (const result of perFile) {
|
|
430
515
|
if (!result) continue;
|
|
431
|
-
for (const [name, value] of result.declarations)
|
|
516
|
+
for (const [name, value] of result.declarations) {
|
|
517
|
+
const isConditional = result.conditional.has(name);
|
|
518
|
+
if (isConditional && declarations.has(name) && !conditional.has(name)) continue;
|
|
519
|
+
declarations.set(name, value);
|
|
520
|
+
if (isConditional) conditional.add(name);
|
|
521
|
+
else conditional.delete(name);
|
|
522
|
+
}
|
|
432
523
|
for (const [name, rule] of result.properties) properties.set(name, rule);
|
|
433
524
|
for (const [name, doc] of result.docs) docs.set(name, doc);
|
|
434
525
|
for (const [theme, values] of result.themes) {
|
|
@@ -449,19 +540,46 @@ function rootPattern(text) {
|
|
|
449
540
|
const names = [...aliases].map((alias) => alias.replace(/\$/g, "\\$")).join("|");
|
|
450
541
|
return new RegExp(`${ROOT_RE.source}|(?<![\\w$.])(?:${names})(?![\\w$])`, "g");
|
|
451
542
|
}
|
|
452
|
-
var ACCESS_RE = /\s*(
|
|
543
|
+
var ACCESS_RE = /\s*(?:\??\.\s*([A-Za-z_$][\w$]*)|(?:\?\.\s*)?\[\s*(['"`])((?:(?!\2).)*)\2\s*\])/y;
|
|
453
544
|
function readAccess(text, from) {
|
|
454
545
|
ACCESS_RE.lastIndex = from;
|
|
455
546
|
const match = ACCESS_RE.exec(text);
|
|
456
547
|
return match ? { key: match[1] ?? match[3], end: ACCESS_RE.lastIndex } : null;
|
|
457
548
|
}
|
|
549
|
+
var PATTERN_KEY_RE = /^\s*(?:([A-Za-z_$][\w$]*)|(['"`])((?:(?!\2).)*)\2)\s*(?:[:=]|$)/;
|
|
550
|
+
function readPatternKeys(text, at) {
|
|
551
|
+
let i = at - 1;
|
|
552
|
+
while (i >= 0 && /\s/.test(text[i])) i--;
|
|
553
|
+
if (text[i] !== "=") return [];
|
|
554
|
+
i--;
|
|
555
|
+
while (i >= 0 && /\s/.test(text[i])) i--;
|
|
556
|
+
if (text[i] !== "}") return [];
|
|
557
|
+
const open = text.lastIndexOf("{", i);
|
|
558
|
+
if (open === -1) return [];
|
|
559
|
+
const body = text.slice(open + 1, i);
|
|
560
|
+
if (body.includes("}")) return [];
|
|
561
|
+
const keys = [];
|
|
562
|
+
for (const part of body.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, "").split(",")) {
|
|
563
|
+
const match = PATTERN_KEY_RE.exec(part);
|
|
564
|
+
if (match) keys.push(match[1] ?? match[3]);
|
|
565
|
+
}
|
|
566
|
+
return keys;
|
|
567
|
+
}
|
|
458
568
|
function extractUsage(text, into) {
|
|
459
569
|
for (const root of text.matchAll(rootPattern(text))) {
|
|
460
570
|
const first = readAccess(text, root.index + root[0].length);
|
|
461
|
-
|
|
571
|
+
const second = first && readAccess(text, first.end);
|
|
572
|
+
const destructured = second ? [] : readPatternKeys(text, root.index);
|
|
573
|
+
if (!first) {
|
|
574
|
+
for (const key of destructured) {
|
|
575
|
+
into.keys.add(key);
|
|
576
|
+
into.wholeKeys.add(key);
|
|
577
|
+
}
|
|
578
|
+
continue;
|
|
579
|
+
}
|
|
462
580
|
into.keys.add(first.key);
|
|
463
|
-
const second = readAccess(text, first.end);
|
|
464
581
|
if (second) into.paths.add(`${first.key}\0${second.key}`);
|
|
582
|
+
else if (destructured.length > 0) for (const leaf of destructured) into.paths.add(`${first.key}\0${leaf}`);
|
|
465
583
|
else into.wholeKeys.add(first.key);
|
|
466
584
|
}
|
|
467
585
|
}
|
package/dist/esbuild.d.cts
CHANGED
package/dist/esbuild.d.ts
CHANGED
package/dist/esbuild.js
CHANGED
|
@@ -9,6 +9,11 @@ interface VarDoc {
|
|
|
9
9
|
interface ThemedDeclarations {
|
|
10
10
|
/** Base values, from `:root`/`@theme`/`selectors` blocks outside any theme block. */
|
|
11
11
|
declarations: Map<string, string>;
|
|
12
|
+
/**
|
|
13
|
+
* Names whose base value is conditional: only declared inside an
|
|
14
|
+
* `@media`/`@supports`/`@container` rule, or a rule nested in a base block.
|
|
15
|
+
*/
|
|
16
|
+
conditional: Set<string>;
|
|
12
17
|
/** Per theme name, the values declared inside that theme's blocks. */
|
|
13
18
|
themes: Map<string, Map<string, string>>;
|
|
14
19
|
/** `/** ... *\/` doc comments placed directly before a declaration — from a base block, else from a theme block. */
|
|
@@ -9,6 +9,11 @@ interface VarDoc {
|
|
|
9
9
|
interface ThemedDeclarations {
|
|
10
10
|
/** Base values, from `:root`/`@theme`/`selectors` blocks outside any theme block. */
|
|
11
11
|
declarations: Map<string, string>;
|
|
12
|
+
/**
|
|
13
|
+
* Names whose base value is conditional: only declared inside an
|
|
14
|
+
* `@media`/`@supports`/`@container` rule, or a rule nested in a base block.
|
|
15
|
+
*/
|
|
16
|
+
conditional: Set<string>;
|
|
12
17
|
/** Per theme name, the values declared inside that theme's blocks. */
|
|
13
18
|
themes: Map<string, Map<string, string>>;
|
|
14
19
|
/** `/** ... *\/` doc comments placed directly before a declaration — from a base block, else from a theme block. */
|