@jesscss/scss-parser 2.0.0-alpha.12 → 2.0.0-alpha.13
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/lib/grammar/ast/positions.cjs +12571 -6740
- package/lib/grammar/ast/positions.js +12733 -6902
- package/lib/grammar/ast.cjs +13109 -63590
- package/lib/grammar/ast.js +13108 -63589
- package/lib/grammar/cst/positions.cjs +12452 -6621
- package/lib/grammar/cst/positions.js +12452 -6621
- package/lib/grammar/cst.cjs +12057 -6197
- package/lib/grammar/cst.js +12053 -6193
- package/lib/grammar-helpers.d.ts +234 -0
- package/lib/grammar.d.ts +4 -4
- package/package.json +8 -8
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SCSS grammar reducer helpers, hoisted out of `scss-parser/src/grammar.ts`.
|
|
3
|
+
*
|
|
4
|
+
* These are the module-private helpers the SCSS grammar's `node(...)` reducers
|
|
5
|
+
* call. They lived inside `grammar.ts` as free module scope, which is fine for a
|
|
6
|
+
* standalone `composeLeaf(...)` grammar but not for a COMPOSABLE delta: the
|
|
7
|
+
* parseman compose analyzer can only carry a reducer across a package boundary
|
|
8
|
+
* when every name the reducer reads has import provenance. A free module-private
|
|
9
|
+
* helper has none, so composing `[cssBaseRules, rules(scssDelta)]` refused them.
|
|
10
|
+
* Hoisting them into this importable module gives each one a resolvable import,
|
|
11
|
+
* and the analyzer re-emits those imports into the composing module.
|
|
12
|
+
*
|
|
13
|
+
* This is a pure code motion (B0-scss): every body is byte-identical to its
|
|
14
|
+
* former in-grammar definition and the helpers keep calling each other exactly
|
|
15
|
+
* as before. These are SCSS's OWN helpers — promoting the ones that turn out
|
|
16
|
+
* byte-identical to the css/less/jess helpers into the shared
|
|
17
|
+
* `@jesscss/core/ast` module is a separate, deferred dedup pass (guarded by the
|
|
18
|
+
* open-recursion rule: a helper is only shareable when its whole transitive
|
|
19
|
+
* helper-closure is identical too).
|
|
20
|
+
*/
|
|
21
|
+
import type { AnonymousMixin, AtRuleBlock, AtRuleStatement, CallArg, Collection, CollectionEntry, Color, Comment, CompoundSelector, Declaration, Dimension, ExtendInstruction, For, ForBinding, FunctionCall, GuardNode, If, IfValue, Interpolation, Keyword, Lookup, MixinCall, MixinDefinition, UnknownAtRuleBlock, Param, Quoted, Reference, Ruleset, SelectorBranch, SelectorList, SelectorTerm, SimpleSelector, SimpleToken, Statement, StyleImport, Token, Url, ValueNode, ValueSlot, VariableDeclaration, While } from '@jesscss/core/ast';
|
|
22
|
+
export type ScssValuePair = {
|
|
23
|
+
readonly separator: string;
|
|
24
|
+
readonly value: ValueSlot;
|
|
25
|
+
};
|
|
26
|
+
export type ScssValueTail = {
|
|
27
|
+
readonly kind: 'space' | 'slash';
|
|
28
|
+
readonly value: ValueNode;
|
|
29
|
+
readonly separator: string;
|
|
30
|
+
};
|
|
31
|
+
/** One authored call argument. The AST's own {@link CallArg}, not a local
|
|
32
|
+
* look-alike: a `$name:` argument is the SAME node whether the callee is a
|
|
33
|
+
* mixin (`@include m($x: 1)`) or a function (`color.adjust($c, $lightness: -10%)`),
|
|
34
|
+
* and every one is built by `callArg` so the array stays monomorphic. */
|
|
35
|
+
export type ScssCallArg = CallArg<ValueSlot>;
|
|
36
|
+
/** An argument-list separator carrying the argument it precedes. */
|
|
37
|
+
export type ScssArgumentPair = {
|
|
38
|
+
readonly separator: string;
|
|
39
|
+
readonly value: ScssCallArg;
|
|
40
|
+
};
|
|
41
|
+
export type ScssSegmentCombinator = ' ' | '>' | '+' | '~' | '|' | '||';
|
|
42
|
+
export declare const scriptModuleExtensions: readonly [".js", ".mjs", ".cjs", ".ts", ".mts", ".cts", ".json"];
|
|
43
|
+
export declare function isScriptModulePath(path: string): boolean;
|
|
44
|
+
export declare function requireToken(value: unknown): Token;
|
|
45
|
+
export declare function scssSourceText(value: unknown): string;
|
|
46
|
+
/** Map query/media-prelude children to value nodes, coercing bare keyword tokens
|
|
47
|
+
* (`and`/`or`/media types) to `Keyword`s while passing structured values through. */
|
|
48
|
+
export declare function keywordizeValues(children: readonly unknown[]): ValueNode[];
|
|
49
|
+
/** Concatenate the authored spelling of every child. The canonical opaque
|
|
50
|
+
* representation for attribute selectors and non-structured pseudo arguments. */
|
|
51
|
+
export declare function joinSourceText(children: readonly unknown[]): string;
|
|
52
|
+
/** Concatenate every child token value into one opaque static-prelude token. */
|
|
53
|
+
export declare function joinTokenValue(children: readonly unknown[]): Token;
|
|
54
|
+
/** Shared reducer for a static `"…"` / `'…'` quoted value: the opening quote is
|
|
55
|
+
* `children[0]`, the raw body is `children[1]`, and both the source spelling and
|
|
56
|
+
* decoded body are preserved verbatim (never interpolation). */
|
|
57
|
+
export declare function staticQuoted(children: readonly unknown[]): Quoted;
|
|
58
|
+
export declare function isQuoted(value: unknown): value is Quoted;
|
|
59
|
+
export declare function isUrl(value: unknown): value is Url;
|
|
60
|
+
export declare function isSimpleSelector(value: unknown): value is SimpleSelector;
|
|
61
|
+
export declare function isCompoundSelector(value: unknown): value is CompoundSelector;
|
|
62
|
+
export declare function isSelectorTerm(value: unknown): value is SelectorTerm;
|
|
63
|
+
export declare function isScssSelectorBranch(value: unknown): value is SelectorBranch;
|
|
64
|
+
export declare function isScssSelectorList(value: unknown): value is SelectorList;
|
|
65
|
+
export declare function requireSelectorList(value: unknown): SelectorList;
|
|
66
|
+
export declare const scssSelectorTermFromTokens: (tokens: readonly SimpleToken[]) => SelectorTerm;
|
|
67
|
+
export declare function isScssSimpleToken(value: unknown): value is SimpleToken;
|
|
68
|
+
export declare function scssCombinatorText(value: unknown): ' ' | '>' | '+' | '~' | '||';
|
|
69
|
+
export declare function scssRelativeCombinator(value: unknown): '>' | '+' | '~';
|
|
70
|
+
export declare function scssBranchSegments(branch: SelectorBranch): [{
|
|
71
|
+
combinator?: ScssSegmentCombinator;
|
|
72
|
+
term: SelectorTerm;
|
|
73
|
+
}, ...Array<{
|
|
74
|
+
combinator?: ScssSegmentCombinator;
|
|
75
|
+
term: SelectorTerm;
|
|
76
|
+
}>];
|
|
77
|
+
export declare function isScssImportTarget(value: unknown): value is Quoted | Url | Interpolation;
|
|
78
|
+
export declare function isParam(value: unknown): value is Param;
|
|
79
|
+
export declare function isParamArray(value: unknown): value is Param[];
|
|
80
|
+
export declare function isAnonymousMixin(value: unknown): value is AnonymousMixin;
|
|
81
|
+
export declare function requireForBinding(value: unknown): ForBinding;
|
|
82
|
+
export declare function requireString(value: unknown): string;
|
|
83
|
+
export declare function isVarRef(value: unknown): value is Lookup;
|
|
84
|
+
export declare function isColor(value: unknown): value is Color;
|
|
85
|
+
export declare function isDimension(value: unknown): value is Dimension;
|
|
86
|
+
export declare function isFunctionCall(value: unknown): value is FunctionCall;
|
|
87
|
+
export declare function isScssInterpolation(value: unknown): value is Interpolation;
|
|
88
|
+
export declare function requireInterpolation(value: unknown): Interpolation;
|
|
89
|
+
export declare function appendLiteral(parts: Interpolation['parts'], text: string): void;
|
|
90
|
+
/** Flatten a grammar-owned raw template without ever reparsing its bytes. */
|
|
91
|
+
export declare function interpolationFromTemplateChildren(children: readonly unknown[]): Interpolation;
|
|
92
|
+
/**
|
|
93
|
+
* Turn the grammar-owned parts of a custom-property value into one canonical
|
|
94
|
+
* value. Custom-property values are not evaluated: everything outside a typed
|
|
95
|
+
* `#{…}` stays literal `<declaration-value>` text, so the reduction only joins
|
|
96
|
+
* grammar children — it never rescans source. Nested balanced groups arrive as
|
|
97
|
+
* nested arrays from the paren/square/curly productions.
|
|
98
|
+
*/
|
|
99
|
+
export declare function customValueFromParts(children: readonly unknown[], parts: Interpolation['parts'], seen: {
|
|
100
|
+
interpolated: boolean;
|
|
101
|
+
}): void;
|
|
102
|
+
/** Reduce a whole custom-property value to `Interpolation` (when it carries a
|
|
103
|
+
* `#{…}`) or to verbatim `Any` text. */
|
|
104
|
+
export declare function customValue(children: readonly unknown[]): ValueNode;
|
|
105
|
+
export declare function isArithmeticOperator(text: string): boolean;
|
|
106
|
+
/** Fold a grammar-produced left-associative operator chain. Precedence belongs
|
|
107
|
+
* to the caller's product/sum production, never to a source-text recovery.
|
|
108
|
+
*
|
|
109
|
+
* Operands and operator characters arrive in authored order with the operators'
|
|
110
|
+
* padding interleaved. The pads are their own terms, so an operator no longer
|
|
111
|
+
* sits a constant distance from its operand and the fold reads the shape rather
|
|
112
|
+
* than a fixed stride — and a pad can hold a comment whose own `/` and `*` would
|
|
113
|
+
* defeat any attempt to recover the operator from the padded text. */
|
|
114
|
+
export declare function scssFoldOperation(children: readonly unknown[]): ValueNode;
|
|
115
|
+
export declare function isScssValue(value: unknown): value is ValueNode;
|
|
116
|
+
export declare function scssValueSlot(value: ValueNode): ValueSlot;
|
|
117
|
+
export declare function isSequence(value: ValueSlot): value is Extract<ValueNode, {
|
|
118
|
+
type: 'Sequence';
|
|
119
|
+
}>;
|
|
120
|
+
export declare function isScssValueSlotValue(value: unknown): value is ValueSlot;
|
|
121
|
+
export declare function requireValueSlot(value: unknown): ValueSlot;
|
|
122
|
+
export declare function isScssDeclaration(value: unknown): value is Declaration;
|
|
123
|
+
export declare function isCollection(value: unknown): value is Collection;
|
|
124
|
+
export declare function isCollectionEntry(value: unknown): value is CollectionEntry;
|
|
125
|
+
export declare function isRuleset(value: unknown): value is Ruleset;
|
|
126
|
+
export declare function isMixinDefinition(value: unknown): value is MixinDefinition;
|
|
127
|
+
export declare function isMixinCall(value: unknown): value is MixinCall;
|
|
128
|
+
export declare function isFor(value: unknown): value is For;
|
|
129
|
+
export declare function isIf(value: unknown): value is If;
|
|
130
|
+
export declare function isWhile(value: unknown): value is While;
|
|
131
|
+
export declare function isAtRuleBlock(value: unknown): value is AtRuleBlock;
|
|
132
|
+
export declare function isAtRuleStatement(value: unknown): value is AtRuleStatement;
|
|
133
|
+
export declare function isComment(value: unknown): value is Comment;
|
|
134
|
+
export declare function isStyleImport(value: unknown): value is StyleImport;
|
|
135
|
+
export declare function isExtendInstruction(value: unknown): value is ExtendInstruction;
|
|
136
|
+
export declare function requireValue(value: unknown): ValueNode;
|
|
137
|
+
export declare function requireKeyword(value: unknown): Keyword;
|
|
138
|
+
/** The best-effort authored spelling of a value node for a Reference `raw`. */
|
|
139
|
+
export declare function referenceKeyRaw(node: ValueNode): string;
|
|
140
|
+
/** The `.jess` spelling of one `@content(…)` argument, used to build the lowered
|
|
141
|
+
* `$content(…)` Reference `raw`. Same read as {@link referenceKeyRaw}, plus the
|
|
142
|
+
* `$name:` prefix a named argument carries. */
|
|
143
|
+
export declare function contentArgRaw(arg: ScssCallArg): string;
|
|
144
|
+
/** `map.get` is the `sass:map` module spelling of the global `map-get`. Both are
|
|
145
|
+
* the same function, so both lower to the same accessor read — a grammar that
|
|
146
|
+
* accepted only one spelling into the accessor form would emit two different
|
|
147
|
+
* trees for one semantics. */
|
|
148
|
+
export declare const MAP_GET_SPELLINGS: Set<string>;
|
|
149
|
+
/** The comparison spellings a call argument may carry (§4.5.2). Named here so
|
|
150
|
+
* the operator token is found by WHAT IT IS rather than by a child index the
|
|
151
|
+
* optional trivia arms would shift. */
|
|
152
|
+
export declare const COMPARISON_OPERATORS: Set<string>;
|
|
153
|
+
/** Lower `map-get($m, k)` to the shared `$[…]` accessor read `$m[k]`: a Reference
|
|
154
|
+
* whose single LookupStep carries the key. A `$var` key selects the
|
|
155
|
+
* variable-namespace lookup; every other key is a value-equality member lookup
|
|
156
|
+
* (map keys compare by value, never by position, so `index` is never used). */
|
|
157
|
+
export declare function lowerMapGet(base: ValueNode, key: ValueNode): Reference;
|
|
158
|
+
/**
|
|
159
|
+
* Lower Sass `if(<cond>, a, b)` to the value-position `$if` (§4.5.3b).
|
|
160
|
+
*
|
|
161
|
+
* It wears call parentheses but it is SYNTAX, not a function (§4.5.3a) — it is
|
|
162
|
+
* branch-lazy and its first argument is a condition, neither of which a
|
|
163
|
+
* `sassFns` entry could express. Lowering it here, in the grammar that knows the
|
|
164
|
+
* dialect, is what lets ONE evaluator answer `if(0, T, F)` with `T` for `.scss`
|
|
165
|
+
* and `F` for `.less`: {@link scssTruth} fixes Sass+'s rule (§4.4.6 — falsy iff
|
|
166
|
+
* `false`, `null`, `""` or `()`) at parse time, Less's grammar fixes its own,
|
|
167
|
+
* and core never learns which dialect a guard came from.
|
|
168
|
+
*
|
|
169
|
+
* Anything but the three-argument form is left an ordinary call — plain CSS
|
|
170
|
+
* `if()` is not this construct.
|
|
171
|
+
*/
|
|
172
|
+
export declare function lowerSassIf(args: readonly ScssCallArg[]): IfValue | undefined;
|
|
173
|
+
export declare function reduceScssCall(name: string, children: readonly unknown[], minArgumentIndex: number): FunctionCall | Reference | IfValue;
|
|
174
|
+
/** A Sass map key stays an authored value node; equality belongs to value-domain
|
|
175
|
+
* map comparison, not to declaration-name stringification. */
|
|
176
|
+
export declare function mapKeyValue(node: ValueNode): ValueSlot;
|
|
177
|
+
/**
|
|
178
|
+
* The SCSS condition lowering (§4.4.2, as revised by §4.4.6): `@if $x` means
|
|
179
|
+
* `$if($x)` — the SAME truth node `.jess` uses.
|
|
180
|
+
*
|
|
181
|
+
* **Sass+ takes §4.4's emptiness rule** (owner, 2026-08-07): falsy iff `false`,
|
|
182
|
+
* `null`, `""` or `()`. It previously spelled Sass's own rule out —
|
|
183
|
+
* `not(($x == false) or ($x == null))` — to keep `""` and `()` truthy. What
|
|
184
|
+
* forced the change was INTERNAL CONTRADICTION, not reference parity: `or`/`and`
|
|
185
|
+
* lower to jess's native operators (§4.5.5), so `.scss "" or 2` already answered
|
|
186
|
+
* `2` under jess truthiness while `@if ""` took the true branch under Sass's.
|
|
187
|
+
* One dialect, one value, two answers, decided by which construct you wrote.
|
|
188
|
+
*
|
|
189
|
+
* This is why `.scss` must mint the value-domain `Null` (§4.3): with
|
|
190
|
+
* `keyword('null')` in the value lane, `$if($x)` would silently take the TRUE
|
|
191
|
+
* branch for `null`.
|
|
192
|
+
*
|
|
193
|
+
* `.less` is unaffected — `when (@x)` still lowers to `$if($x == true)`.
|
|
194
|
+
*/
|
|
195
|
+
export declare function scssTruth(value: ValueSlot): GuardNode;
|
|
196
|
+
/**
|
|
197
|
+
* Sass's `not <value>` — the NEGATION of {@link scssTruth}, i.e. "is `$x`
|
|
198
|
+
* falsy". Under §4.4.6 that is exactly jess's `not($x)`, so it is the truth node
|
|
199
|
+
* under a `not` wrapper and cannot drift from the positive form.
|
|
200
|
+
*/
|
|
201
|
+
export declare function scssNegation(value: ValueSlot): GuardNode;
|
|
202
|
+
/**
|
|
203
|
+
* The authored spelling of a `not` operand, kept so the {@link Condition} it
|
|
204
|
+
* lowers to can replay verbatim when no evaluator is injected. Same job — and
|
|
205
|
+
* the same explicit type list — as the Less grammar's condition source: a shape
|
|
206
|
+
* with no known spelling is a recognition defect, not something to guess at.
|
|
207
|
+
*/
|
|
208
|
+
export declare function scssConditionSource(value: ValueSlot): string;
|
|
209
|
+
/**
|
|
210
|
+
* Fold one logical rung left-associatively onto `Operation` nodes carrying the
|
|
211
|
+
* word itself as the operator. The operator token is kept out of the fold by
|
|
212
|
+
* shape (only values participate), so the rung reduces the same way whether it
|
|
213
|
+
* spelled `and` or `or`.
|
|
214
|
+
*/
|
|
215
|
+
export declare function foldLogicalOperation(children: readonly unknown[]): ValueNode;
|
|
216
|
+
export declare function isGuardNode(value: unknown): value is GuardNode;
|
|
217
|
+
export declare function requireGuardNode(value: unknown): GuardNode;
|
|
218
|
+
export declare function scssOptionalValue(value: unknown): ValueNode | null;
|
|
219
|
+
/** A reduced {@link ScssCallArg} — the payload every argument production yields. */
|
|
220
|
+
export declare function isScssCallArg(value: unknown): value is ScssCallArg;
|
|
221
|
+
export declare function requireScssCallArg(value: unknown): ScssCallArg;
|
|
222
|
+
/** An {@link ScssArgumentPair} — a separator plus the argument it precedes. */
|
|
223
|
+
export declare function isScssArgumentPair(value: unknown): value is ScssArgumentPair;
|
|
224
|
+
export declare function isScssValuePair(value: unknown): value is ScssValuePair;
|
|
225
|
+
export declare function isScssValueTail(value: unknown): value is ScssValueTail;
|
|
226
|
+
export declare function isVarDeclaration(value: unknown): value is VariableDeclaration;
|
|
227
|
+
export declare function isStatementChild(child: unknown, allowDeclarations: boolean): child is Statement;
|
|
228
|
+
export declare function isReferenceStatement(value: unknown): value is Reference;
|
|
229
|
+
export declare function isUnknownAtRuleBlock(value: unknown): value is UnknownAtRuleBlock;
|
|
230
|
+
export declare function statements(children: readonly unknown[], allowDeclarations?: boolean): Statement[];
|
|
231
|
+
export declare function statementChildren(children: readonly unknown[], allowDeclarations?: boolean): Statement[];
|
|
232
|
+
export declare function requireStatementList(value: unknown): Statement[];
|
|
233
|
+
export declare function keyframeSelectorListFromChildren(children: readonly unknown[]): SelectorList;
|
|
234
|
+
export declare function scssPseudoName(opener: string): string;
|
package/lib/grammar.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export declare const scssGrammar: Record<string, import("parseman").
|
|
1
|
+
export declare const scssGrammar: Record<string, import("parseman").FusedRule>;
|
|
2
2
|
/** AST artifact with Parseman line/column tracking enabled. */
|
|
3
|
-
export declare const scssPositionsGrammar: Record<string, import("parseman").
|
|
4
|
-
export declare const scssCstGrammar: Record<string, import("parseman").
|
|
3
|
+
export declare const scssPositionsGrammar: Record<string, import("parseman").FusedRule>;
|
|
4
|
+
export declare const scssCstGrammar: Record<string, import("parseman").FusedRule>;
|
|
5
5
|
/** CST artifact with Parseman line/column tracking enabled. */
|
|
6
|
-
export declare const scssCstPositionsGrammar: Record<string, import("parseman").
|
|
6
|
+
export declare const scssCstPositionsGrammar: Record<string, import("parseman").FusedRule>;
|
package/package.json
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
6
|
"description": "",
|
|
7
|
-
"version": "2.0.0-alpha.
|
|
7
|
+
"version": "2.0.0-alpha.13",
|
|
8
8
|
"engines": {
|
|
9
|
-
"node": "^20.19.0 || >=22.
|
|
9
|
+
"node": "^20.19.0 || >=22.12.0"
|
|
10
10
|
},
|
|
11
11
|
"main": "lib/index.cjs",
|
|
12
12
|
"types": "lib/index.d.ts",
|
|
@@ -62,11 +62,11 @@
|
|
|
62
62
|
"lib"
|
|
63
63
|
],
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@jesscss/css-parser": "2.0.0-alpha.
|
|
65
|
+
"@jesscss/css-parser": "2.0.0-alpha.13"
|
|
66
66
|
},
|
|
67
67
|
"peerDependencies": {
|
|
68
|
-
"parseman": "^0.50.
|
|
69
|
-
"@jesscss/core": "2.0.0-alpha.
|
|
68
|
+
"parseman": "^0.50.5",
|
|
69
|
+
"@jesscss/core": "2.0.0-alpha.13"
|
|
70
70
|
},
|
|
71
71
|
"peerDependenciesMeta": {
|
|
72
72
|
"@jesscss/core": {
|
|
@@ -74,10 +74,10 @@
|
|
|
74
74
|
}
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
|
-
"parseman": "^0.50.
|
|
77
|
+
"parseman": "^0.50.5",
|
|
78
78
|
"sass-spec": "github:sass/sass-spec",
|
|
79
|
-
"@jesscss/
|
|
80
|
-
"@jesscss/
|
|
79
|
+
"@jesscss/core": "2.0.0-alpha.13",
|
|
80
|
+
"@jesscss/parser-shared": "2.0.0-alpha.13"
|
|
81
81
|
},
|
|
82
82
|
"author": "Matthew Dean <matthew-dean@users.noreply.github.com>",
|
|
83
83
|
"license": "MIT",
|