@better-css-modules/core 0.2.0 → 0.3.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.
|
@@ -129,11 +129,18 @@ declare const tokenCategories: {
|
|
|
129
129
|
};
|
|
130
130
|
shadow: {
|
|
131
131
|
properties: {
|
|
132
|
-
"box-shadow": "
|
|
133
|
-
"text-shadow": "
|
|
132
|
+
"box-shadow": "items";
|
|
133
|
+
"text-shadow": "items";
|
|
134
134
|
};
|
|
135
135
|
keywords: string[];
|
|
136
136
|
};
|
|
137
|
+
"font-family": {
|
|
138
|
+
properties: {
|
|
139
|
+
"font-family": "items";
|
|
140
|
+
font: "font";
|
|
141
|
+
};
|
|
142
|
+
keywords: never[];
|
|
143
|
+
};
|
|
137
144
|
"font-size": {
|
|
138
145
|
properties: {
|
|
139
146
|
"font-size": "value";
|
|
@@ -155,6 +162,12 @@ declare const tokenCategories: {
|
|
|
155
162
|
};
|
|
156
163
|
keywords: string[];
|
|
157
164
|
};
|
|
165
|
+
"letter-spacing": {
|
|
166
|
+
properties: {
|
|
167
|
+
"letter-spacing": "value";
|
|
168
|
+
};
|
|
169
|
+
keywords: string[];
|
|
170
|
+
};
|
|
158
171
|
"z-index": {
|
|
159
172
|
properties: {
|
|
160
173
|
"z-index": "value";
|
|
@@ -167,8 +180,17 @@ declare const tokenCategories: {
|
|
|
167
180
|
"transition-delay": "value";
|
|
168
181
|
"animation-duration": "value";
|
|
169
182
|
"animation-delay": "value";
|
|
170
|
-
transition: "
|
|
171
|
-
animation: "
|
|
183
|
+
transition: "transition";
|
|
184
|
+
animation: "transition";
|
|
185
|
+
};
|
|
186
|
+
keywords: string[];
|
|
187
|
+
};
|
|
188
|
+
easing: {
|
|
189
|
+
properties: {
|
|
190
|
+
"transition-timing-function": "items";
|
|
191
|
+
"animation-timing-function": "items";
|
|
192
|
+
transition: "transition";
|
|
193
|
+
animation: "transition";
|
|
172
194
|
};
|
|
173
195
|
keywords: string[];
|
|
174
196
|
};
|
|
@@ -192,6 +214,7 @@ declare const RULES: {
|
|
|
192
214
|
readonly "pure/important": "either";
|
|
193
215
|
readonly "pure/at-rule": "either";
|
|
194
216
|
readonly "pure/value": "either";
|
|
217
|
+
readonly "pure/scope": "either";
|
|
195
218
|
readonly "tokens/unknown": "either";
|
|
196
219
|
readonly "tokens/internal": "either";
|
|
197
220
|
readonly "tokens/declaration": "either";
|
|
@@ -83,10 +83,12 @@ function analyzeCss(source, file) {
|
|
|
83
83
|
function unique(names) {
|
|
84
84
|
return [...new Set(names)].sort();
|
|
85
85
|
}
|
|
86
|
-
|
|
86
|
+
/** `composing` is the class of the top-level rule the declarations belong to, or null elsewhere. */
|
|
87
|
+
function walkContainer(container, local, collector, composing = null) {
|
|
87
88
|
container.each((node) => {
|
|
88
89
|
if (node.type === "rule") visitRule(node, local, collector);
|
|
89
90
|
else if (node.type === "atrule") visitAtRule(node, local, collector);
|
|
91
|
+
else if (node.type === "decl" && node.prop.toLowerCase() === "composes") collectComposes(node, composing, collector);
|
|
90
92
|
else if (node.type === "decl" && local) visitDeclaration(node, collector);
|
|
91
93
|
});
|
|
92
94
|
}
|
|
@@ -101,10 +103,7 @@ function visitRule(rule, local, collector) {
|
|
|
101
103
|
collector.node = rule;
|
|
102
104
|
singleClass = collectSelectorList(selector, startOf(rule), local, collector);
|
|
103
105
|
}
|
|
104
|
-
rule.
|
|
105
|
-
if (child.type === "decl" && child.prop.toLowerCase() === "composes") collectComposes(child, singleClass, collector);
|
|
106
|
-
});
|
|
107
|
-
walkContainer(rule, blockLocal, collector);
|
|
106
|
+
walkContainer(rule, blockLocal, collector, rule.parent?.type === "root" ? singleClass : null);
|
|
108
107
|
}
|
|
109
108
|
function visitAtRule(atRule, local, collector) {
|
|
110
109
|
const name = atRule.name.toLowerCase();
|
|
@@ -138,12 +137,42 @@ function parseSelectorList(text, base, collector) {
|
|
|
138
137
|
line: base.line,
|
|
139
138
|
column: base.column
|
|
140
139
|
});
|
|
141
|
-
|
|
140
|
+
if (node.type !== "SelectorList") return null;
|
|
141
|
+
collector.diagnostics.push(...checkSelectorEnds(node, base, collector.file));
|
|
142
|
+
return node;
|
|
142
143
|
} catch (error) {
|
|
143
144
|
collector.diagnostics.push(syntaxDiagnostic(collector.file, error, base));
|
|
144
145
|
return null;
|
|
145
146
|
}
|
|
146
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* css-tree reads an empty selector list and a selector that ends with a
|
|
150
|
+
* combinator without complaint; browsers and lightningcss refuse both.
|
|
151
|
+
*/
|
|
152
|
+
function checkSelectorEnds(list, base, file) {
|
|
153
|
+
if (list.children.isEmpty) return [{
|
|
154
|
+
file,
|
|
155
|
+
line: base.line,
|
|
156
|
+
column: base.column,
|
|
157
|
+
rule: "syntax",
|
|
158
|
+
message: "Selector is expected"
|
|
159
|
+
}];
|
|
160
|
+
const diagnostics = [];
|
|
161
|
+
list.children.forEach((selector) => {
|
|
162
|
+
const last = selector.type === "Selector" ? selector.children.last : null;
|
|
163
|
+
if (last?.type !== "Combinator" || !last.loc) return;
|
|
164
|
+
diagnostics.push({
|
|
165
|
+
file,
|
|
166
|
+
line: last.loc.start.line,
|
|
167
|
+
column: last.loc.start.column,
|
|
168
|
+
endLine: last.loc.end.line,
|
|
169
|
+
endColumn: last.loc.end.column,
|
|
170
|
+
rule: "syntax",
|
|
171
|
+
message: `Selector is expected after ${last.name}`
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
return diagnostics;
|
|
175
|
+
}
|
|
147
176
|
function visitSelectorList(list, local, collector) {
|
|
148
177
|
list.children.forEach((selector) => {
|
|
149
178
|
if (selector.type === "Selector") visitSelector(selector, local, collector);
|
|
@@ -641,11 +670,18 @@ const tokenCategories = {
|
|
|
641
670
|
},
|
|
642
671
|
shadow: {
|
|
643
672
|
properties: {
|
|
644
|
-
"box-shadow": "
|
|
645
|
-
"text-shadow": "
|
|
673
|
+
"box-shadow": "items",
|
|
674
|
+
"text-shadow": "items"
|
|
646
675
|
},
|
|
647
676
|
keywords: ["none"]
|
|
648
677
|
},
|
|
678
|
+
"font-family": {
|
|
679
|
+
properties: {
|
|
680
|
+
"font-family": "items",
|
|
681
|
+
font: "font"
|
|
682
|
+
},
|
|
683
|
+
keywords: []
|
|
684
|
+
},
|
|
649
685
|
"font-size": {
|
|
650
686
|
properties: {
|
|
651
687
|
"font-size": "value",
|
|
@@ -667,6 +703,10 @@ const tokenCategories = {
|
|
|
667
703
|
},
|
|
668
704
|
keywords: ["normal"]
|
|
669
705
|
},
|
|
706
|
+
"letter-spacing": {
|
|
707
|
+
properties: { "letter-spacing": "value" },
|
|
708
|
+
keywords: ["normal"]
|
|
709
|
+
},
|
|
670
710
|
"z-index": {
|
|
671
711
|
properties: { "z-index": "value" },
|
|
672
712
|
keywords: ["auto"]
|
|
@@ -677,11 +717,20 @@ const tokenCategories = {
|
|
|
677
717
|
"transition-delay": "value",
|
|
678
718
|
"animation-duration": "value",
|
|
679
719
|
"animation-delay": "value",
|
|
680
|
-
transition: "
|
|
681
|
-
animation: "
|
|
720
|
+
transition: "transition",
|
|
721
|
+
animation: "transition"
|
|
682
722
|
},
|
|
683
723
|
keywords: ["auto"]
|
|
684
724
|
},
|
|
725
|
+
easing: {
|
|
726
|
+
properties: {
|
|
727
|
+
"transition-timing-function": "items",
|
|
728
|
+
"animation-timing-function": "items",
|
|
729
|
+
transition: "transition",
|
|
730
|
+
animation: "transition"
|
|
731
|
+
},
|
|
732
|
+
keywords: ["linear"]
|
|
733
|
+
},
|
|
685
734
|
breakpoint: {
|
|
686
735
|
properties: {},
|
|
687
736
|
keywords: []
|
|
@@ -815,8 +864,13 @@ function isForeign(node) {
|
|
|
815
864
|
function globalCssFrom(files) {
|
|
816
865
|
const declarations = /* @__PURE__ */ new Map();
|
|
817
866
|
const registrations = /* @__PURE__ */ new Map();
|
|
867
|
+
const given = /* @__PURE__ */ new Map();
|
|
868
|
+
const give = (name, value) => {
|
|
869
|
+
if (value.trim() !== "") given.set(name, [...given.get(name) ?? [], value.trim()]);
|
|
870
|
+
};
|
|
818
871
|
for (const { file, root, conditional } of files) root.walk((node) => {
|
|
819
872
|
if (node.type === "decl" && node.prop.startsWith("--")) {
|
|
873
|
+
if (!isForeign(node)) give(node.prop, node.value);
|
|
820
874
|
if (declaresToken(node, conditional)) declarations.set(node.prop, {
|
|
821
875
|
node,
|
|
822
876
|
file,
|
|
@@ -824,6 +878,7 @@ function globalCssFrom(files) {
|
|
|
824
878
|
});
|
|
825
879
|
} else if (node.type === "atrule" && node.name.toLowerCase() === "property") {
|
|
826
880
|
const name = node.params.trim();
|
|
881
|
+
give(name, initialValueOf(node));
|
|
827
882
|
if (name.startsWith("--") && declaresToken(node, conditional)) registrations.set(name, {
|
|
828
883
|
node,
|
|
829
884
|
file,
|
|
@@ -845,6 +900,7 @@ function globalCssFrom(files) {
|
|
|
845
900
|
return {
|
|
846
901
|
files,
|
|
847
902
|
tokens,
|
|
903
|
+
values: given,
|
|
848
904
|
layers: layersOf(files)
|
|
849
905
|
};
|
|
850
906
|
}
|
|
@@ -1216,7 +1272,10 @@ function wrapInLayer(source, file, layer) {
|
|
|
1216
1272
|
* failed is tried again on the next call.
|
|
1217
1273
|
*/
|
|
1218
1274
|
function createLayerWrapper(config) {
|
|
1219
|
-
const matches = createMatcher(
|
|
1275
|
+
const matches = createMatcher({
|
|
1276
|
+
...config,
|
|
1277
|
+
root: realpathSync(config.root)
|
|
1278
|
+
});
|
|
1220
1279
|
let last;
|
|
1221
1280
|
const read = () => {
|
|
1222
1281
|
const stamps = /* @__PURE__ */ new Map();
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as Diagnostic, c as RuleId, d as ConfigError, f as ResolvedConfig, l as TokenCategory, m as loadConfig, n as generate, o as formatDiagnostic, p as defineConfig, s as formatGitHubAnnotation, t as GenerateResult, u as Config } from "./dts-
|
|
1
|
+
import { a as Diagnostic, c as RuleId, d as ConfigError, f as ResolvedConfig, l as TokenCategory, m as loadConfig, n as generate, o as formatDiagnostic, p as defineConfig, s as formatGitHubAnnotation, t as GenerateResult, u as Config } from "./dts-BFi7f7uh.mjs";
|
|
2
2
|
import "postcss";
|
|
3
3
|
//#region src/check.d.ts
|
|
4
4
|
interface CheckResult {
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as find, D as property, E as parse, O as walk$1, S as valueStart, T as lexer, _ as sortDiagnostics, a as resolveLayer, b as loadConfig, c as loadGlobalCss, d as findCssModules, f as loadCssModules, g as formatGitHubAnnotation, h as formatDiagnostic, m as tokenCategories, o as declaresToken, p as categoryOf, r as checkLayer, s as isForeign, t as generate, u as defaultIgnore, v as ConfigError, w as generate$1, x as paramsStart, y as defineConfig } from "./dts-
|
|
1
|
+
import { C as find, D as property, E as parse, O as walk$1, S as valueStart, T as lexer, _ as sortDiagnostics, a as resolveLayer, b as loadConfig, c as loadGlobalCss, d as findCssModules, f as loadCssModules, g as formatGitHubAnnotation, h as formatDiagnostic, m as tokenCategories, o as declaresToken, p as categoryOf, r as checkLayer, s as isForeign, t as generate, u as defaultIgnore, v as ConfigError, w as generate$1, x as paramsStart, y as defineConfig } from "./dts-De2E7b59.mjs";
|
|
2
2
|
import fs from "node:fs";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { ResolverFactory } from "oxc-resolver";
|
|
@@ -168,6 +168,7 @@ const RULES = {
|
|
|
168
168
|
"pure/important": "either",
|
|
169
169
|
"pure/at-rule": "either",
|
|
170
170
|
"pure/value": "either",
|
|
171
|
+
"pure/scope": "either",
|
|
171
172
|
"tokens/unknown": "either",
|
|
172
173
|
"tokens/internal": "either",
|
|
173
174
|
"tokens/declaration": "either",
|
|
@@ -276,6 +277,8 @@ const GLOBAL_AT_RULES = /* @__PURE__ */ new Set([
|
|
|
276
277
|
"view-transition",
|
|
277
278
|
"color-profile"
|
|
278
279
|
]);
|
|
280
|
+
const ROOT_AT_CLASS = "write @scope (&) in the rule of its root class";
|
|
281
|
+
const UNROOTED = `an @scope without a root selector is rooted at the parent of the stylesheet's <style> or <link>; ${ROOT_AT_CLASS}`;
|
|
279
282
|
/**
|
|
280
283
|
* Check one CSS Module against the pure rules, handing the diagnostics of each
|
|
281
284
|
* rule, at-rule and declaration to `report` with the node they belong to.
|
|
@@ -284,6 +287,8 @@ function checkPure(root, file, report) {
|
|
|
284
287
|
walkContainer(root, {
|
|
285
288
|
nested: false,
|
|
286
289
|
scoped: false,
|
|
290
|
+
unrooted: false,
|
|
291
|
+
nestedScope: false,
|
|
287
292
|
local: true
|
|
288
293
|
}, {
|
|
289
294
|
file,
|
|
@@ -309,6 +314,7 @@ function visitRule(rule, context, checker) {
|
|
|
309
314
|
walkContainer(rule, {
|
|
310
315
|
...context,
|
|
311
316
|
nested: true,
|
|
317
|
+
nestedScope: false,
|
|
312
318
|
local
|
|
313
319
|
}, checker);
|
|
314
320
|
}
|
|
@@ -330,8 +336,9 @@ function visitAtRule(atRule, context, checker) {
|
|
|
330
336
|
if (atRule.nodes) walkContainer(atRule, inner, checker);
|
|
331
337
|
}
|
|
332
338
|
/**
|
|
333
|
-
* The root of an @scope is local when its selectors have a local subject
|
|
334
|
-
*
|
|
339
|
+
* The root of an @scope is local when its selectors have a local subject.
|
|
340
|
+
* Without a root selector, the root is the parent of the stylesheet's owner
|
|
341
|
+
* node, also when the @scope is nested in a style rule or another @scope.
|
|
335
342
|
*/
|
|
336
343
|
function visitScope(atRule, context, checker) {
|
|
337
344
|
const text = atRule.raws.params?.raw ?? atRule.params;
|
|
@@ -350,23 +357,39 @@ function visitScope(atRule, context, checker) {
|
|
|
350
357
|
}
|
|
351
358
|
const scope = find(prelude, (node) => node.type === "Scope");
|
|
352
359
|
const root = scope?.root?.type === "SelectorList" ? scope.root : null;
|
|
360
|
+
const limit = scope?.limit?.type === "SelectorList" ? scope.limit : null;
|
|
361
|
+
const unrooted = !scope?.root;
|
|
362
|
+
const rooted = root !== null && hasLocalSubjects(root, context.local, context.nested);
|
|
353
363
|
const scan = {
|
|
354
364
|
local: false,
|
|
355
365
|
globals: [],
|
|
356
366
|
ids: []
|
|
357
367
|
};
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
368
|
+
if (root) scanList(root, context.local, false, text, scan);
|
|
369
|
+
const limitScan = {
|
|
370
|
+
local: false,
|
|
371
|
+
globals: [],
|
|
372
|
+
ids: []
|
|
373
|
+
};
|
|
374
|
+
if (limit) scanList(limit, context.local, false, text, limitScan);
|
|
375
|
+
const inside = rooted && context.nested && limit ? globalsInside(limit) : /* @__PURE__ */ new Set();
|
|
376
|
+
checker.report(atRule, [
|
|
377
|
+
...[...scan.globals, ...limitScan.globals.filter(({ node }) => !inside.has(node))].map((found) => globalDiagnostic(found, checker.file)),
|
|
378
|
+
...[...scan.ids, ...limitScan.ids].map((found) => idDiagnostic(found, checker.file)),
|
|
379
|
+
...root && context.nested ? repeatedRoots(atRule, root, text, checker.file) : []
|
|
380
|
+
]);
|
|
361
381
|
return {
|
|
362
382
|
...context,
|
|
363
|
-
scoped: context.scoped || rooted
|
|
383
|
+
scoped: !unrooted && (context.scoped || rooted),
|
|
384
|
+
unrooted,
|
|
385
|
+
nestedScope: context.nested
|
|
364
386
|
};
|
|
365
387
|
}
|
|
366
388
|
function checkSelectorList(list, text, context, file) {
|
|
367
389
|
const diagnostics = [];
|
|
368
390
|
list.children.forEach((selector) => {
|
|
369
391
|
if (selector.type !== "Selector") return;
|
|
392
|
+
if (selector.children.last?.type === "Combinator") return;
|
|
370
393
|
const scan = {
|
|
371
394
|
local: false,
|
|
372
395
|
globals: [],
|
|
@@ -374,16 +397,23 @@ function checkSelectorList(list, text, context, file) {
|
|
|
374
397
|
};
|
|
375
398
|
scanSelector(selector, context.local, false, text, scan);
|
|
376
399
|
if (!context.nested && !scan.local) {
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
400
|
+
if (scan.globals.length === 0) {
|
|
401
|
+
const hint = context.scoped ? `, and bundlers do not count the root of a top-level @scope; ${ROOT_AT_CLASS}` : context.unrooted ? `, and ${UNROOTED}` : "; every selector of a CSS Module needs one";
|
|
402
|
+
diagnostics.push(diagnosticAt$1({
|
|
403
|
+
node: selector,
|
|
404
|
+
text
|
|
405
|
+
}, file, "pure/selector", (written) => `${written} has no local class${hint}`));
|
|
406
|
+
}
|
|
382
407
|
} else if (!context.scoped) {
|
|
383
408
|
const subject = subjectOf(selector, context.local);
|
|
384
|
-
if (!isLocalCompound(subject, context.nested) && !isReportedElsewhere(subject)) diagnostics.push(subjectDiagnostic(subject, text, file));
|
|
409
|
+
if (subject.length > 0 && !isLocalCompound(subject, context.nested) && !isReportedElsewhere(subject)) diagnostics.push(subjectDiagnostic(subject, text, context.unrooted, file));
|
|
385
410
|
}
|
|
386
|
-
|
|
411
|
+
if (context.nestedScope && find(selector, isScopePseudoClass) && !find(selector, isNesting)) diagnostics.push(scopeDiagnostic({
|
|
412
|
+
node: selector,
|
|
413
|
+
text
|
|
414
|
+
}, file));
|
|
415
|
+
const inside = context.scoped && context.nested ? globalsInside(selector) : /* @__PURE__ */ new Set();
|
|
416
|
+
diagnostics.push(...scan.globals.filter(({ node }) => !inside.has(node)).map((found) => globalDiagnostic(found, file)), ...scan.ids.map((found) => idDiagnostic(found, file)));
|
|
387
417
|
});
|
|
388
418
|
return diagnostics;
|
|
389
419
|
}
|
|
@@ -488,11 +518,76 @@ function hasLocalSubjects(list, local, nested) {
|
|
|
488
518
|
function isReportedElsewhere(parts) {
|
|
489
519
|
return parts.some(({ node, local }) => !local || find(node, (child) => child.type === "IdSelector" || child.type === "PseudoClassSelector" && child.name.toLowerCase() === "global") !== null);
|
|
490
520
|
}
|
|
521
|
+
/**
|
|
522
|
+
* The `:global` of a selector matched inside an @scope that stay inside its
|
|
523
|
+
* root: those after the last compound holding `&` or `:scope`, reached from it
|
|
524
|
+
* by a descendant or child combinator, or anywhere when no compound holds
|
|
525
|
+
* either, since the selector is then relative to the root. A `:global` in the
|
|
526
|
+
* argument of another pseudo-class may hold a selector that reaches the
|
|
527
|
+
* ancestors of the root, so it is not counted.
|
|
528
|
+
*/
|
|
529
|
+
function globalsInside(node) {
|
|
530
|
+
const inside = /* @__PURE__ */ new Set();
|
|
531
|
+
if (node.type === "SelectorList") {
|
|
532
|
+
node.children.forEach((selector) => {
|
|
533
|
+
if (selector.type !== "Selector") return;
|
|
534
|
+
for (const found of globalsInside(selector)) inside.add(found);
|
|
535
|
+
});
|
|
536
|
+
return inside;
|
|
537
|
+
}
|
|
538
|
+
const parts = node.children.toArray();
|
|
539
|
+
let anchor = -1;
|
|
540
|
+
parts.forEach((part, index) => {
|
|
541
|
+
if (part.type !== "Combinator" && find(part, isAnchor) !== null) anchor = index;
|
|
542
|
+
});
|
|
543
|
+
const start = anchor === -1 ? 0 : parts.findIndex((part, index) => index > anchor && part.type === "Combinator");
|
|
544
|
+
if (start === -1) return inside;
|
|
545
|
+
const step = parts[start];
|
|
546
|
+
if (step?.type === "Combinator" && (step.name === "+" || step.name === "~")) return inside;
|
|
547
|
+
for (const part of parts.slice(start)) if (part.type === "PseudoClassSelector" && part.name.toLowerCase() === "global") {
|
|
548
|
+
const argument = argumentOf(part);
|
|
549
|
+
if (!argument || find(argument.list, isAnchor) === null) inside.add(part);
|
|
550
|
+
}
|
|
551
|
+
return inside;
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* A root selector of an @scope nested in a rule is relative to that rule, so
|
|
555
|
+
* one that repeats the rule's selector roots the @scope at a copy of it
|
|
556
|
+
* nested inside it, not at the element the rule styles.
|
|
557
|
+
*/
|
|
558
|
+
function repeatedRoots(atRule, root, text, file) {
|
|
559
|
+
let parent = atRule.parent ?? void 0;
|
|
560
|
+
while (parent && parent.type !== "rule") parent = parent.parent ?? void 0;
|
|
561
|
+
if (parent?.type !== "rule") return [];
|
|
562
|
+
const own = new Set(parent.selectors.map(normalize));
|
|
563
|
+
const diagnostics = [];
|
|
564
|
+
root.children.forEach((selector) => {
|
|
565
|
+
if (selector.type !== "Selector" || !selector.loc) return;
|
|
566
|
+
if (!own.has(normalize(text.slice(selector.loc.start.offset, selector.loc.end.offset)))) return;
|
|
567
|
+
diagnostics.push(diagnosticAt$1({
|
|
568
|
+
node: selector,
|
|
569
|
+
text
|
|
570
|
+
}, file, "pure/scope", (written) => `the root of an @scope nested in ${written} is relative to it, so this one is a ${written} inside ${written}; write @scope (&)`));
|
|
571
|
+
});
|
|
572
|
+
return diagnostics;
|
|
573
|
+
}
|
|
574
|
+
function normalize(selector) {
|
|
575
|
+
return selector.trim().replace(/\s+/g, " ");
|
|
576
|
+
}
|
|
577
|
+
function isAnchor(node) {
|
|
578
|
+
return isNesting(node) || isScopePseudoClass(node);
|
|
579
|
+
}
|
|
580
|
+
function isScopePseudoClass(node) {
|
|
581
|
+
return node.type === "PseudoClassSelector" && node.name.toLowerCase() === "scope";
|
|
582
|
+
}
|
|
583
|
+
function isNesting(node) {
|
|
584
|
+
return node.type === "NestingSelector";
|
|
585
|
+
}
|
|
491
586
|
function isScoping(node) {
|
|
492
587
|
const name = node.name.toLowerCase();
|
|
493
588
|
return name === "global" || name === "local";
|
|
494
589
|
}
|
|
495
|
-
function subjectDiagnostic(parts, text, file) {
|
|
590
|
+
function subjectDiagnostic(parts, text, unrooted, file) {
|
|
496
591
|
const first = parts[0].node.loc;
|
|
497
592
|
const last = parts[parts.length - 1].node.loc;
|
|
498
593
|
const written = first && last ? text.slice(first.start.offset, last.end.offset) : "";
|
|
@@ -503,11 +598,14 @@ function subjectDiagnostic(parts, text, file) {
|
|
|
503
598
|
endLine: last?.end.line,
|
|
504
599
|
endColumn: last?.end.column,
|
|
505
600
|
rule: "pure/subject",
|
|
506
|
-
message: `${written} is not a local class; give the element a class of its own, or style markup the component does not write inside @scope`
|
|
601
|
+
message: unrooted ? `${written} is not a local class, and ${UNROOTED}` : `${written} is not a local class; give the element a class of its own, or style markup the component does not write inside @scope (&)`
|
|
507
602
|
};
|
|
508
603
|
}
|
|
509
604
|
function globalDiagnostic(found, file) {
|
|
510
|
-
return diagnosticAt$1(found, file, "pure/global", (written) => `${written} reaches outside this module; a mode overrides tokens in the global CSS, and markup the component does not write is styled inside @scope`);
|
|
605
|
+
return diagnosticAt$1(found, file, "pure/global", (written) => `${written} reaches outside this module; a mode overrides tokens in the global CSS, and markup the component does not write is styled inside @scope (&)`);
|
|
606
|
+
}
|
|
607
|
+
function scopeDiagnostic(found, file) {
|
|
608
|
+
return diagnosticAt$1(found, file, "pure/scope", (written) => `lightningcss (Turbopack) rewrites ${written} to & ${written} in an @scope nested in a rule, which matches nothing; write ${written.replace(/:scope\b/gi, "&")}`);
|
|
511
609
|
}
|
|
512
610
|
function idDiagnostic(found, file) {
|
|
513
611
|
return diagnosticAt$1(found, file, "pure/id", (written) => `${written} is an id; its specificity defeats overrides from outside the component, so use a class`);
|
|
@@ -1833,6 +1931,7 @@ var Resolvers = class {
|
|
|
1833
1931
|
references: "auto"
|
|
1834
1932
|
} } : {}
|
|
1835
1933
|
});
|
|
1934
|
+
if (tsconfig) checkTsconfig(resolver, tsconfig);
|
|
1836
1935
|
this.byTsconfig.set(tsconfig, resolver);
|
|
1837
1936
|
}
|
|
1838
1937
|
return resolver;
|
|
@@ -1848,6 +1947,17 @@ var Resolvers = class {
|
|
|
1848
1947
|
return found;
|
|
1849
1948
|
}
|
|
1850
1949
|
};
|
|
1950
|
+
/**
|
|
1951
|
+
* The resolver reads the tsconfig at its first resolution, and one it cannot
|
|
1952
|
+
* read (an `extends` that does not resolve, a syntax error) fails every
|
|
1953
|
+
* resolution after it, relative imports included, which would leave every
|
|
1954
|
+
* module unused. Resolving the tsconfig itself, a file that exists, fails for
|
|
1955
|
+
* that reason only.
|
|
1956
|
+
*/
|
|
1957
|
+
function checkTsconfig(resolver, tsconfig) {
|
|
1958
|
+
const { error } = resolver.sync(path.dirname(tsconfig), `./${path.basename(tsconfig)}`);
|
|
1959
|
+
if (error) throw new ConfigError(`${relative(process.cwd(), tsconfig)} cannot be read, so imports cannot be resolved: ${error}`);
|
|
1960
|
+
}
|
|
1851
1961
|
//#endregion
|
|
1852
1962
|
//#region src/check.ts
|
|
1853
1963
|
const CSS_WIDE_KEYWORDS = /* @__PURE__ */ new Set([
|
|
@@ -1909,6 +2019,21 @@ const GRADIENT_FUNCTIONS = /* @__PURE__ */ new Set([
|
|
|
1909
2019
|
"repeating-conic-gradient"
|
|
1910
2020
|
]);
|
|
1911
2021
|
const TIME_UNITS = /* @__PURE__ */ new Set(["s", "ms"]);
|
|
2022
|
+
/** Keywords and functions that spell an easing out. */
|
|
2023
|
+
const EASING_KEYWORDS = /* @__PURE__ */ new Set([
|
|
2024
|
+
"linear",
|
|
2025
|
+
"ease",
|
|
2026
|
+
"ease-in",
|
|
2027
|
+
"ease-out",
|
|
2028
|
+
"ease-in-out",
|
|
2029
|
+
"step-start",
|
|
2030
|
+
"step-end"
|
|
2031
|
+
]);
|
|
2032
|
+
const EASING_FUNCTIONS = /* @__PURE__ */ new Set([
|
|
2033
|
+
"linear",
|
|
2034
|
+
"cubic-bezier",
|
|
2035
|
+
"steps"
|
|
2036
|
+
]);
|
|
1912
2037
|
const FONT_SIZE_KEYWORDS = /* @__PURE__ */ new Set([
|
|
1913
2038
|
"xx-small",
|
|
1914
2039
|
"x-small",
|
|
@@ -1931,7 +2056,7 @@ const FONT_WEIGHT_KEYWORDS = /* @__PURE__ */ new Set([
|
|
|
1931
2056
|
const WHOLE_VALUE_PARTS = /* @__PURE__ */ new Set([
|
|
1932
2057
|
"value",
|
|
1933
2058
|
"colors",
|
|
1934
|
-
"
|
|
2059
|
+
"items"
|
|
1935
2060
|
]);
|
|
1936
2061
|
const PARTS_BY_PROPERTY = /* @__PURE__ */ new Map();
|
|
1937
2062
|
for (const [category, definition] of Object.entries(tokenCategories)) for (const [name, part] of Object.entries(definition.properties)) {
|
|
@@ -1953,7 +2078,8 @@ async function check(config) {
|
|
|
1953
2078
|
if (files.length === 0) throw new ConfigError(`include matches no files in the project root ${config.root}: ${config.include.join(", ")}`);
|
|
1954
2079
|
const globalCss = await loadGlobalCss(config);
|
|
1955
2080
|
const layer = config.layer === void 0 ? void 0 : resolveLayer(config.layer, globalCss);
|
|
1956
|
-
const
|
|
2081
|
+
const real = [...new Set(files.map((file) => fs.realpathSync(file)))];
|
|
2082
|
+
const { modules, diagnostics } = await loadCssModules(real);
|
|
1957
2083
|
const usage = await analyzeUsage(modules, config);
|
|
1958
2084
|
const found = [
|
|
1959
2085
|
...diagnostics,
|
|
@@ -1963,7 +2089,7 @@ async function check(config) {
|
|
|
1963
2089
|
const declared = new Set([...globalCss.tokens.values()].map(({ category }) => category));
|
|
1964
2090
|
return {
|
|
1965
2091
|
diagnostics: sortDiagnostics(found),
|
|
1966
|
-
modules:
|
|
2092
|
+
modules: real.length,
|
|
1967
2093
|
tokens: Object.keys(tokenCategories).filter((category) => declared.has(category))
|
|
1968
2094
|
};
|
|
1969
2095
|
}
|
|
@@ -1978,8 +2104,8 @@ async function check(config) {
|
|
|
1978
2104
|
* arithmetic on its tokens pass. Anywhere in the file a token name the global
|
|
1979
2105
|
* CSS does not declare is reported, and so is a name it declares without a
|
|
1980
2106
|
* category prefix, which is internal to it. A module cannot declare either kind
|
|
1981
|
-
* of name. `composes` outside a rule of a single local class is
|
|
1982
|
-
* which
|
|
2107
|
+
* of name. `composes` outside a top-level rule of a single local class is
|
|
2108
|
+
* reported, which lightningcss rejects. With a layer, what wrapping the module in it would
|
|
1983
2109
|
* break is reported too. The usage problems found about the module are
|
|
1984
2110
|
* passed in, so that its disable comments apply to them as well. Pure: reads
|
|
1985
2111
|
* nothing but its arguments.
|
|
@@ -2001,7 +2127,7 @@ function checkCss(analysis, globalCss, layer, usage = []) {
|
|
|
2001
2127
|
endLine: range.end.line,
|
|
2002
2128
|
endColumn: range.end.column,
|
|
2003
2129
|
rule: "invalid-composes",
|
|
2004
|
-
message: "composes is only allowed in a rule whose selector is a single local class"
|
|
2130
|
+
message: "composes is only allowed in a top-level rule whose selector is a single local class"
|
|
2005
2131
|
}))]);
|
|
2006
2132
|
}
|
|
2007
2133
|
/**
|
|
@@ -2032,6 +2158,7 @@ function contextOf(file, globalCss, global, layer) {
|
|
|
2032
2158
|
return {
|
|
2033
2159
|
file,
|
|
2034
2160
|
tokens: globalCss.tokens,
|
|
2161
|
+
values: globalCss.values,
|
|
2035
2162
|
restrictions,
|
|
2036
2163
|
breakpoints,
|
|
2037
2164
|
global,
|
|
@@ -2061,6 +2188,13 @@ function checkRoot(root, context, disabled) {
|
|
|
2061
2188
|
if (context.restrictions.has("breakpoint")) root.walkAtRules(/^media$/i, (atRule) => {
|
|
2062
2189
|
keep(atRule, checkMediaQuery(atRule, context.breakpoints, context.file));
|
|
2063
2190
|
});
|
|
2191
|
+
const own = /* @__PURE__ */ new Set();
|
|
2192
|
+
root.walkDecls((declaration) => {
|
|
2193
|
+
if (declaration.prop.startsWith("--")) own.add(declaration.prop);
|
|
2194
|
+
});
|
|
2195
|
+
root.walkAtRules(/^container$/i, (atRule) => {
|
|
2196
|
+
keep(atRule, checkContainerQuery(atRule, context, own));
|
|
2197
|
+
});
|
|
2064
2198
|
if (context.global) {
|
|
2065
2199
|
for (const token of context.tokens.values()) if (token.file === context.file) keep(token.node, checkBreakpointToken(token));
|
|
2066
2200
|
}
|
|
@@ -2122,7 +2256,7 @@ function checkDeclaredName(name, start, node, context) {
|
|
|
2122
2256
|
return report(`${name} is not declared at :root; a mode can only override a token, so declare the token in a :root rule`);
|
|
2123
2257
|
}
|
|
2124
2258
|
const category = categoryOf(name);
|
|
2125
|
-
if (category && context.restrictions.has(category)) return report(`${name} is
|
|
2259
|
+
if (category && context.restrictions.has(category)) return report(`${name} is ${aToken(category)} name and cannot be declared here; rename the custom property`);
|
|
2126
2260
|
if (!category && context.tokens.has(name)) return report(`${name} is internal to the global CSS and cannot be declared here; rename the custom property`);
|
|
2127
2261
|
return [];
|
|
2128
2262
|
}
|
|
@@ -2151,18 +2285,139 @@ function checkReferences(nodes, context, diagnostics) {
|
|
|
2151
2285
|
}
|
|
2152
2286
|
/** The declared token of the category nearest to a misspelt name, within two edits. */
|
|
2153
2287
|
function closestToken(name, category, tokens) {
|
|
2288
|
+
return closestName(name, [...tokens.values()].filter((token) => token.category === category).map((token) => token.name));
|
|
2289
|
+
}
|
|
2290
|
+
/** The name nearest to a misspelt one, within two edits. */
|
|
2291
|
+
function closestName(name, names) {
|
|
2154
2292
|
let closest = null;
|
|
2155
2293
|
let best = 3;
|
|
2156
|
-
for (const
|
|
2157
|
-
|
|
2158
|
-
const distance = editDistance(name, token.name);
|
|
2294
|
+
for (const candidate of names) {
|
|
2295
|
+
const distance = editDistance(name, candidate);
|
|
2159
2296
|
if (distance < best) {
|
|
2160
2297
|
best = distance;
|
|
2161
|
-
closest =
|
|
2298
|
+
closest = candidate;
|
|
2162
2299
|
}
|
|
2163
2300
|
}
|
|
2164
2301
|
return closest;
|
|
2165
2302
|
}
|
|
2303
|
+
/**
|
|
2304
|
+
* Report what a style query of `@container` reads that the CSS does not set.
|
|
2305
|
+
* A style query may read an internal name: a module follows a mode the global
|
|
2306
|
+
* CSS sets that way. Reported are a token name the global CSS does not
|
|
2307
|
+
* declare, as in a var(); a name without a category that neither the global
|
|
2308
|
+
* CSS nor the stylesheet declares, when it is within two edits of one that
|
|
2309
|
+
* is, since the markup may set any other in a style attribute; and a keyword
|
|
2310
|
+
* that the global CSS never gives the name it compares, when it gives it only
|
|
2311
|
+
* keywords.
|
|
2312
|
+
*/
|
|
2313
|
+
function checkContainerQuery(atRule, context, own) {
|
|
2314
|
+
const text = atRule.raws.params?.raw ?? atRule.params;
|
|
2315
|
+
const start = paramsStart(atRule);
|
|
2316
|
+
let prelude;
|
|
2317
|
+
try {
|
|
2318
|
+
prelude = parse(text, {
|
|
2319
|
+
context: "atrulePrelude",
|
|
2320
|
+
atrule: "container",
|
|
2321
|
+
positions: true
|
|
2322
|
+
});
|
|
2323
|
+
} catch {
|
|
2324
|
+
return [];
|
|
2325
|
+
}
|
|
2326
|
+
const diagnostics = [];
|
|
2327
|
+
const report = (offset, length, message) => {
|
|
2328
|
+
const first = positionIn(text, start, offset);
|
|
2329
|
+
const last = positionIn(text, start, offset + length);
|
|
2330
|
+
diagnostics.push({
|
|
2331
|
+
file: context.file,
|
|
2332
|
+
line: first.line,
|
|
2333
|
+
column: first.column,
|
|
2334
|
+
endLine: last.line,
|
|
2335
|
+
endColumn: last.column,
|
|
2336
|
+
rule: "tokens/unknown",
|
|
2337
|
+
message
|
|
2338
|
+
});
|
|
2339
|
+
};
|
|
2340
|
+
walk$1(prelude, (node) => {
|
|
2341
|
+
if (node.type !== "FeatureFunction" || node.feature.toLowerCase() !== "style") return;
|
|
2342
|
+
for (const { name, offset, value } of styleQueriesOf(node)) {
|
|
2343
|
+
const problem = unknownName(name, context, own);
|
|
2344
|
+
if (problem) {
|
|
2345
|
+
report(offset, name.length, problem);
|
|
2346
|
+
continue;
|
|
2347
|
+
}
|
|
2348
|
+
const given = context.values.get(name) ?? [];
|
|
2349
|
+
if (value && context.tokens.has(name) && isKeywordText(value.text) && given.length > 0 && given.every(isKeywordText) && !given.includes(value.text)) {
|
|
2350
|
+
const values = [...new Set(given)].join(", ");
|
|
2351
|
+
report(value.offset, value.text.length, `${value.text} is not a value the global CSS gives ${name}; it gives ${values}`);
|
|
2352
|
+
}
|
|
2353
|
+
}
|
|
2354
|
+
});
|
|
2355
|
+
return diagnostics;
|
|
2356
|
+
}
|
|
2357
|
+
/**
|
|
2358
|
+
* The custom properties a style query reads. css-tree reads `style(--a: b)`
|
|
2359
|
+
* as a declaration and leaves the rest as raw text: a name alone, conditions
|
|
2360
|
+
* joined with `and` / `or`, and ranges. Only the first form is compared.
|
|
2361
|
+
*/
|
|
2362
|
+
function styleQueriesOf(node) {
|
|
2363
|
+
const value = node.value;
|
|
2364
|
+
if (value.type === "Declaration") {
|
|
2365
|
+
if (!value.loc || !value.property.startsWith("--")) return [];
|
|
2366
|
+
const offset = value.loc.start.offset;
|
|
2367
|
+
const raw = value.value.type === "Raw" ? value.value : null;
|
|
2368
|
+
const text = raw?.value.trim() ?? "";
|
|
2369
|
+
const compared = raw?.loc && text !== "" ? {
|
|
2370
|
+
text,
|
|
2371
|
+
offset: raw.loc.start.offset + raw.value.indexOf(text)
|
|
2372
|
+
} : null;
|
|
2373
|
+
return [{
|
|
2374
|
+
name: value.property,
|
|
2375
|
+
offset,
|
|
2376
|
+
value: compared
|
|
2377
|
+
}];
|
|
2378
|
+
}
|
|
2379
|
+
if (value.type !== "Raw" || !value.loc) return [];
|
|
2380
|
+
const queries = [];
|
|
2381
|
+
for (const match of value.value.matchAll(/(?:^|(?<![\w-])\()\s*(--[\w-]+)/g)) {
|
|
2382
|
+
const name = match[1];
|
|
2383
|
+
const offset = value.loc.start.offset + match.index + match[0].length - name.length;
|
|
2384
|
+
queries.push({
|
|
2385
|
+
name,
|
|
2386
|
+
offset,
|
|
2387
|
+
value: null
|
|
2388
|
+
});
|
|
2389
|
+
}
|
|
2390
|
+
return queries;
|
|
2391
|
+
}
|
|
2392
|
+
/** Why a name a style query reads is unknown, or null. */
|
|
2393
|
+
function unknownName(name, context, own) {
|
|
2394
|
+
const category = categoryOf(name);
|
|
2395
|
+
if (category) {
|
|
2396
|
+
if (!context.restrictions.has(category) || context.tokens.has(name)) return null;
|
|
2397
|
+
const suggestion = closestToken(name, category, context.tokens);
|
|
2398
|
+
return `${name} is not defined in the global CSS${suggestion ? `; did you mean ${suggestion}?` : ""}`;
|
|
2399
|
+
}
|
|
2400
|
+
if (context.tokens.has(name) || own.has(name)) return null;
|
|
2401
|
+
const suggestion = closestName(name, [...[...context.tokens.values()].filter((token) => token.category === null).map((token) => token.name), ...own]);
|
|
2402
|
+
return suggestion ? `${name} is declared neither in the global CSS nor in this stylesheet; did you mean ${suggestion}?` : null;
|
|
2403
|
+
}
|
|
2404
|
+
/** A value that is one identifier, such as a mode a custom property names. */
|
|
2405
|
+
function isKeywordText(text) {
|
|
2406
|
+
return /^-?[a-z_][\w-]*$/i.test(text);
|
|
2407
|
+
}
|
|
2408
|
+
/** The position of an offset in a prelude that starts at `start`. */
|
|
2409
|
+
function positionIn(text, start, offset) {
|
|
2410
|
+
const before = text.slice(0, offset);
|
|
2411
|
+
const lastBreak = before.lastIndexOf("\n");
|
|
2412
|
+
if (lastBreak === -1) return {
|
|
2413
|
+
line: start.line,
|
|
2414
|
+
column: start.column + offset
|
|
2415
|
+
};
|
|
2416
|
+
return {
|
|
2417
|
+
line: start.line + before.split("\n").length - 1,
|
|
2418
|
+
column: offset - lastBreak
|
|
2419
|
+
};
|
|
2420
|
+
}
|
|
2166
2421
|
/** Optimal string alignment distance: a swap of two neighbours counts as one edit. */
|
|
2167
2422
|
function editDistance(a, b) {
|
|
2168
2423
|
const rows = Array.from({ length: a.length + 1 }, (_, i) => Array.from({ length: b.length + 1 }, (_, j) => i === 0 ? j : j === 0 ? i : 0));
|
|
@@ -2190,13 +2445,13 @@ function checkPart(part, nodes, scope) {
|
|
|
2190
2445
|
case "gradient-colors":
|
|
2191
2446
|
checkColors(nodes, scope, "unknown");
|
|
2192
2447
|
break;
|
|
2193
|
-
case "
|
|
2194
|
-
|
|
2448
|
+
case "items":
|
|
2449
|
+
checkItems(nodes, scope);
|
|
2195
2450
|
break;
|
|
2196
2451
|
case "font":
|
|
2197
2452
|
checkFont(nodes, scope);
|
|
2198
2453
|
break;
|
|
2199
|
-
case "
|
|
2454
|
+
case "transition": checkTransition(nodes, scope);
|
|
2200
2455
|
}
|
|
2201
2456
|
}
|
|
2202
2457
|
function checkQuantity(node, scope, arithmetic) {
|
|
@@ -2270,23 +2525,25 @@ function checkChannelFunction(node, scope) {
|
|
|
2270
2525
|
else reportRaw(scope, node);
|
|
2271
2526
|
}
|
|
2272
2527
|
function checkGradient(node, scope) {
|
|
2273
|
-
layersOf(node.children.toArray())
|
|
2274
|
-
|
|
2528
|
+
const argumentsOf = layersOf(node.children.toArray());
|
|
2529
|
+
argumentsOf.forEach((argument, index) => {
|
|
2530
|
+
const token = loneVar(argument);
|
|
2531
|
+
checkColors(argument, scope, index === 0 && (argument.some((child) => child.type === "Identifier" && !scope.restriction.keywords.has(child.name.toLowerCase()) && !isRawColorName(child, scope)) || token !== null && !allowsReference(token, scope) && argumentsOf.length > 2) ? "unknown" : "stop-color");
|
|
2275
2532
|
});
|
|
2276
2533
|
}
|
|
2277
|
-
function
|
|
2534
|
+
function checkItems(nodes, scope) {
|
|
2278
2535
|
for (const layer of layersOf(nodes)) {
|
|
2279
2536
|
const token = loneVar(layer);
|
|
2280
2537
|
if (token) {
|
|
2281
2538
|
checkToken(token, scope);
|
|
2282
|
-
|
|
2539
|
+
checkItems(fallbackOf(token), scope);
|
|
2283
2540
|
} else if (layer.length !== 1 || !isKeyword(layer[0], scope.restriction)) reportRaw(scope, layer[0], layer[layer.length - 1]);
|
|
2284
2541
|
}
|
|
2285
2542
|
}
|
|
2286
2543
|
/**
|
|
2287
|
-
* `font: <style, variant, weight, width> <size> / <line-height> <
|
|
2288
|
-
* slash pins the size before it
|
|
2289
|
-
* raw values can be told apart.
|
|
2544
|
+
* `font: <style, variant, weight, width> <size> / <line-height> <families>`.
|
|
2545
|
+
* The slash pins the size before it, the line height after it and the families
|
|
2546
|
+
* after that; without one only raw values can be told apart.
|
|
2290
2547
|
*/
|
|
2291
2548
|
function checkFont(nodes, scope) {
|
|
2292
2549
|
const slash = nodes.findIndex((node) => node.type === "Operator" && node.value === "/");
|
|
@@ -2303,21 +2560,47 @@ function checkFont(nodes, scope) {
|
|
|
2303
2560
|
for (const node of nodes) if (node.type === "Dimension" || node.type === "Percentage") checkQuantity(node, scope, "none");
|
|
2304
2561
|
else if (isIdentifierIn(node, FONT_SIZE_KEYWORDS)) reportRaw(scope, node);
|
|
2305
2562
|
break;
|
|
2306
|
-
case "font-weight":
|
|
2307
|
-
|
|
2563
|
+
case "font-weight":
|
|
2564
|
+
for (const node of size ? nodes.slice(0, slash - 1) : nodes) if (node.type === "Number") checkQuantity(node, scope, "none");
|
|
2565
|
+
else if (isIdentifierIn(node, FONT_WEIGHT_KEYWORDS)) reportRaw(scope, node);
|
|
2566
|
+
break;
|
|
2567
|
+
case "font-family": checkItems(nodes.slice(familiesStart(nodes, slash)), scope);
|
|
2308
2568
|
}
|
|
2309
2569
|
}
|
|
2310
|
-
/**
|
|
2311
|
-
|
|
2570
|
+
/**
|
|
2571
|
+
* Where the families of `font` start. Without a slash a var() before the
|
|
2572
|
+
* first comma may be the size as well as a family, so only the names that end
|
|
2573
|
+
* it are taken: a string, or identifiers back to the size.
|
|
2574
|
+
*/
|
|
2575
|
+
function familiesStart(nodes, slash) {
|
|
2576
|
+
if (slash !== -1) return slash + 2;
|
|
2577
|
+
const comma = nodes.findIndex((node) => node.type === "Operator" && node.value === ",");
|
|
2578
|
+
const end = comma === -1 ? nodes.length : comma;
|
|
2579
|
+
if (nodes[end - 1]?.type === "String") return end - 1;
|
|
2580
|
+
let start = end;
|
|
2581
|
+
while (nodes[start - 1]?.type === "Identifier" && (start === end || !isIdentifierIn(nodes[start - 1], FONT_SIZE_KEYWORDS))) start--;
|
|
2582
|
+
return start;
|
|
2583
|
+
}
|
|
2584
|
+
/** A var() in `transition` or `animation` may be a time, an easing or a name; only raw values are told apart. */
|
|
2585
|
+
function checkTransition(nodes, scope) {
|
|
2312
2586
|
for (const node of nodes) walk$1(node, (child) => {
|
|
2313
|
-
if (child.type === "
|
|
2314
|
-
|
|
2587
|
+
if (child.type === "Function" && child.name.toLowerCase() === "var") {
|
|
2588
|
+
checkTransition(fallbackOf(child), scope);
|
|
2589
|
+
return;
|
|
2590
|
+
}
|
|
2591
|
+
switch (scope.restriction.category) {
|
|
2592
|
+
case "duration":
|
|
2593
|
+
if (child.type === "Dimension" && TIME_UNITS.has(child.unit.toLowerCase())) checkQuantity(child, scope, "none");
|
|
2594
|
+
break;
|
|
2595
|
+
case "easing": if (isEasing(child) && !isKeyword(child, scope.restriction)) reportRaw(scope, child);
|
|
2596
|
+
}
|
|
2315
2597
|
});
|
|
2316
2598
|
}
|
|
2317
2599
|
/**
|
|
2318
2600
|
* Report a `var()` of a custom property that is not a token of the category.
|
|
2319
|
-
* A name of the category the global CSS does not declare
|
|
2320
|
-
*
|
|
2601
|
+
* A name of the category the global CSS does not declare is left to
|
|
2602
|
+
* `checkReferences`, and so is an internal name outside the global CSS, which
|
|
2603
|
+
* uses its internal names freely.
|
|
2321
2604
|
*/
|
|
2322
2605
|
function checkToken(node, scope, inShorthand = false) {
|
|
2323
2606
|
const name = node.children.first;
|
|
@@ -2325,9 +2608,12 @@ function checkToken(node, scope, inShorthand = false) {
|
|
|
2325
2608
|
const { category, hint } = scope.restriction;
|
|
2326
2609
|
const own = categoryOf(name.name);
|
|
2327
2610
|
if (own === category) return;
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2611
|
+
if (own === null && scope.context.tokens.has(name.name)) return;
|
|
2612
|
+
report(scope, node, node, inShorthand ? `${name.name} is taken for the ${category} of this shorthand and is not ${aToken(category)}; ${hint}, or write the longhand` : `${name.name} is not ${aToken(category)}; ${hint}`);
|
|
2613
|
+
}
|
|
2614
|
+
/** `a color token`, `an easing token`. */
|
|
2615
|
+
function aToken(category) {
|
|
2616
|
+
return `${/^[aeiou]/.test(category) ? "an" : "a"} ${category} token`;
|
|
2331
2617
|
}
|
|
2332
2618
|
/** The components of the fallback of a `var()`, which css-tree keeps as raw text. */
|
|
2333
2619
|
function fallbackOf(node) {
|
|
@@ -2397,6 +2683,10 @@ function isKeyword(node, restriction) {
|
|
|
2397
2683
|
function isIdentifierIn(node, names) {
|
|
2398
2684
|
return node.type === "Identifier" && names.has(node.name.toLowerCase());
|
|
2399
2685
|
}
|
|
2686
|
+
function isEasing(node) {
|
|
2687
|
+
if (node.type === "Function") return EASING_FUNCTIONS.has(node.name.toLowerCase());
|
|
2688
|
+
return isIdentifierIn(node, EASING_KEYWORDS);
|
|
2689
|
+
}
|
|
2400
2690
|
/** Named and system colors, which the grammar knows; the category's own keywords are not raw. */
|
|
2401
2691
|
function isRawColorName(node, scope) {
|
|
2402
2692
|
if (scope.restriction.keywords.has(node.name.toLowerCase())) return false;
|
package/dist/internal.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { f as ResolvedConfig, i as createLayerWrapper, r as LayerConfig, t as GenerateResult } from "./dts-
|
|
1
|
+
import { f as ResolvedConfig, i as createLayerWrapper, r as LayerConfig, t as GenerateResult } from "./dts-BFi7f7uh.mjs";
|
|
2
2
|
//#region src/watcher.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* Run `generate` and print how many `.d.ts` files it wrote and which it
|
package/dist/internal.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { h as formatDiagnostic, i as createLayerWrapper, l as createMatcher, n as regenerateDts, t as generate } from "./dts-
|
|
1
|
+
import { h as formatDiagnostic, i as createLayerWrapper, l as createMatcher, n as regenerateDts, t as generate } from "./dts-De2E7b59.mjs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { watch } from "chokidar";
|
|
4
4
|
//#region src/watcher.ts
|
|
@@ -70,7 +70,8 @@ function createSync(config) {
|
|
|
70
70
|
*/
|
|
71
71
|
function startWatcher(config, { persistent = true } = {}) {
|
|
72
72
|
const { root } = config;
|
|
73
|
-
const
|
|
73
|
+
const included = config.include.filter((pattern) => !pattern.startsWith("!"));
|
|
74
|
+
const baseDirs = [...new Set(included.map(extractBaseDir))];
|
|
74
75
|
const sync = createSync(config);
|
|
75
76
|
const outDir = path.resolve(root, config.outDir);
|
|
76
77
|
const ignored = (watched) => {
|
package/package.json
CHANGED