@jesscss/jess-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 +15433 -9474
- package/lib/grammar/ast/positions.js +15417 -9483
- package/lib/grammar/ast.cjs +15395 -70448
- package/lib/grammar/ast.js +15423 -70501
- package/lib/grammar/cst/positions.cjs +15109 -9150
- package/lib/grammar/cst/positions.js +15090 -9156
- package/lib/grammar/cst.cjs +15361 -9349
- package/lib/grammar/cst.js +15098 -9111
- package/lib/grammar-helpers.d.ts +208 -0
- package/lib/grammar.d.ts +4 -4
- package/package.json +8 -8
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Jess grammar reducer helpers, hoisted out of `jess-parser/src/grammar.ts`.
|
|
3
|
+
*
|
|
4
|
+
* These are the module-private helpers the Jess grammar's `node(...)`/`leaf(...)`
|
|
5
|
+
* reducers call. They lived inside `grammar.ts` as free module scope, which is
|
|
6
|
+
* fine for a standalone `composeLeaf(...)` grammar but not for a COMPOSABLE
|
|
7
|
+
* delta: the parseman compose analyzer can only carry a reducer across a package
|
|
8
|
+
* boundary when every name the reducer reads has import provenance. A free
|
|
9
|
+
* module-private helper has none, so `compose([cssBaseRules, rules(jessDelta)])`
|
|
10
|
+
* refused them. Hoisting them into this importable module gives each one a
|
|
11
|
+
* resolvable import, and the analyzer re-emits those imports into the composing
|
|
12
|
+
* module. A relative same-package import is sufficient (proven by B0-less):
|
|
13
|
+
* parseman carries same-package relative-import provenance, not only
|
|
14
|
+
* workspace-package imports.
|
|
15
|
+
*
|
|
16
|
+
* This is a pure code motion (B0-jess): every body is byte-identical to its
|
|
17
|
+
* former in-grammar definition and the helpers keep calling each other exactly
|
|
18
|
+
* as before. No reducer logic, recognition const, or rule structure changed.
|
|
19
|
+
*
|
|
20
|
+
* Cross-dialect dedup (promoting the helpers that turn out byte-identical to the
|
|
21
|
+
* css/scss/less helpers into the shared `@jesscss/core/ast` module) is
|
|
22
|
+
* deliberately DEFERRED to a separate pass, guarded by the open-recursion rule:
|
|
23
|
+
* a helper is only shareable when its whole transitive helper-closure is
|
|
24
|
+
* identical too.
|
|
25
|
+
*/
|
|
26
|
+
import type { FieldCapture, FieldMap } from 'parseman';
|
|
27
|
+
import type { Token, AnonymousMixin, Apply, AtRuleBlock, AtRuleStatement, Combinator as AstCombinator, Declaration, CollectionEntry, ExtendInstruction, For, ForBinding, If, IfBranch, InterpPart, Interpolation, Keyword, MixinCall, MixinDefinition, UnknownAtRuleBlock, Param, Quoted, PseudoSelector, Reference, SelectorBranch, SelectorTerm, Ruleset, SelectorList, SimpleSelector, SimpleToken, Sequence, Statement, StyleImport, Url, ValueNode, ValueSlot, VariableDeclaration, Lookup, GuardNode, While } from '@jesscss/core/ast';
|
|
28
|
+
type ExpressionFact = {
|
|
29
|
+
readonly value: ValueNode;
|
|
30
|
+
readonly src: string;
|
|
31
|
+
};
|
|
32
|
+
type JessOperatorFact = {
|
|
33
|
+
readonly value: string;
|
|
34
|
+
readonly src: string;
|
|
35
|
+
};
|
|
36
|
+
type JessReferenceTail = {
|
|
37
|
+
readonly step: Reference['steps'][number];
|
|
38
|
+
readonly src: string;
|
|
39
|
+
};
|
|
40
|
+
type JessComplexTail = {
|
|
41
|
+
readonly combinator: ' ' | '>' | '+' | '~' | '||';
|
|
42
|
+
readonly term: SelectorTerm;
|
|
43
|
+
};
|
|
44
|
+
type JessSelectorSegment = {
|
|
45
|
+
combinator?: AstCombinator;
|
|
46
|
+
term: SelectorTerm;
|
|
47
|
+
};
|
|
48
|
+
type JessQueryFeatureName = {
|
|
49
|
+
readonly property: Keyword;
|
|
50
|
+
};
|
|
51
|
+
type JessAtRuleHeader = {
|
|
52
|
+
readonly name: string;
|
|
53
|
+
readonly prelude: ValueNode | null;
|
|
54
|
+
};
|
|
55
|
+
type JessMixinCallArgument = MixinCall['args'][number];
|
|
56
|
+
declare function requireToken(value: unknown): Token;
|
|
57
|
+
declare function requireFields(fields: FieldMap | undefined, name: string): readonly FieldCapture[];
|
|
58
|
+
declare function jessCombinator(value: Token): JessComplexTail['combinator'];
|
|
59
|
+
declare function jessRelativeCombinator(child: unknown): '>' | '+' | '~';
|
|
60
|
+
declare function jessBranchSegments(branch: SelectorBranch): [JessSelectorSegment, ...JessSelectorSegment[]];
|
|
61
|
+
declare function isExpressionFact(value: unknown): value is ExpressionFact;
|
|
62
|
+
declare function isJessAtRuleHeader(value: unknown): value is JessAtRuleHeader;
|
|
63
|
+
declare function requireJessAtRuleHeader(value: unknown): JessAtRuleHeader;
|
|
64
|
+
declare function isAtRuleNameToken(value: unknown): value is Token;
|
|
65
|
+
declare function isSelectorTerm(value: unknown): value is SelectorTerm;
|
|
66
|
+
declare function isSimpleSelector(value: unknown): value is SimpleSelector;
|
|
67
|
+
declare function isJessSelectorBranch(value: unknown): value is SelectorBranch;
|
|
68
|
+
declare function isJessSelectorList(value: unknown): value is SelectorList;
|
|
69
|
+
declare function isJessReferenceTail(value: unknown): value is JessReferenceTail;
|
|
70
|
+
declare function isPseudoSelector(value: unknown): value is PseudoSelector;
|
|
71
|
+
declare function isSimpleToken(value: unknown): value is SimpleToken;
|
|
72
|
+
declare const selectorTermFromTokens: (tokens: readonly SimpleToken[]) => SelectorTerm;
|
|
73
|
+
declare function requireSelectorList(value: unknown): SelectorList;
|
|
74
|
+
declare function requireJessReferenceTail(value: unknown): JessReferenceTail;
|
|
75
|
+
declare function requireString(value: unknown): string;
|
|
76
|
+
declare function requireInterpolation(value: unknown): Interpolation;
|
|
77
|
+
declare function requireKeyword(value: unknown): Keyword;
|
|
78
|
+
declare function staticSelectorText(selector: SelectorList): string;
|
|
79
|
+
declare const JESS_STRUCTURED_PSEUDOS: Set<string>;
|
|
80
|
+
declare function isExtendInstruction(value: unknown): value is ExtendInstruction;
|
|
81
|
+
declare function isParam(value: unknown): value is Param;
|
|
82
|
+
declare function isParamList(value: unknown): value is Param[];
|
|
83
|
+
declare function isMixinCallArray(value: unknown): value is MixinCall[];
|
|
84
|
+
declare function isExtendInstructionArray(value: unknown): value is ExtendInstruction[];
|
|
85
|
+
declare function isValueNode(value: unknown): value is ValueNode;
|
|
86
|
+
declare function isValueNodeArray(value: unknown): value is ValueNode[];
|
|
87
|
+
declare function isValueSlotArray(value: ValueSlot): value is readonly ValueSlot[];
|
|
88
|
+
declare function jessValueSlot(value: ValueSlot): ValueSlot;
|
|
89
|
+
declare function isSequence(value: ValueSlot): value is Sequence;
|
|
90
|
+
declare function isJessValueSlotValue(value: unknown): value is ValueSlot;
|
|
91
|
+
declare function requireValueSlot(value: unknown): ValueSlot;
|
|
92
|
+
declare function isJessMixinCallArgument(value: unknown): value is JessMixinCallArgument;
|
|
93
|
+
declare function requireValueNode(value: unknown): ValueNode;
|
|
94
|
+
declare function isGuardNode(value: unknown): value is GuardNode;
|
|
95
|
+
declare function requireGuardNode(value: unknown): GuardNode;
|
|
96
|
+
declare function isJessInterpolation(value: unknown): value is Interpolation;
|
|
97
|
+
declare function isInterpolationLiteral(part: InterpPart): part is {
|
|
98
|
+
readonly lit: string;
|
|
99
|
+
};
|
|
100
|
+
declare function appendInterpolationLiteral(parts: Interpolation['parts'], text: string): void;
|
|
101
|
+
declare function templateInterpolationFromChildren(children: readonly unknown[]): Interpolation;
|
|
102
|
+
/**
|
|
103
|
+
* Flatten the grammar-owned parts of a custom-property value. Custom-property
|
|
104
|
+
* values are never evaluated, so every byte outside a typed `$[…]` segment
|
|
105
|
+
* stays literal `<declaration-value>` text and the reduction only joins grammar
|
|
106
|
+
* children — it never rescans source. Nested balanced groups arrive as nested
|
|
107
|
+
* arrays from the paren/square/curly productions.
|
|
108
|
+
*/
|
|
109
|
+
declare function appendCustomValueParts(children: readonly unknown[], parts: Interpolation['parts'], seen: {
|
|
110
|
+
interpolated: boolean;
|
|
111
|
+
}): void;
|
|
112
|
+
/** Reduce a whole custom-property value to `Interpolation` (when it carries a
|
|
113
|
+
* `$[…]`) or to verbatim `Any` text. */
|
|
114
|
+
declare function customValueFromChildren(children: readonly unknown[]): ValueNode;
|
|
115
|
+
declare function requireExpressionFact(value: unknown): ExpressionFact;
|
|
116
|
+
declare function requireJessOperatorFact(value: unknown): JessOperatorFact;
|
|
117
|
+
declare function foldExpression(children: readonly unknown[]): ExpressionFact;
|
|
118
|
+
/**
|
|
119
|
+
* A {@link Lookup} name is `string | ValueNode` now that `@@indirect` is spelled
|
|
120
|
+
* as a node-valued name; a literal name is its own spelling, a node-valued one
|
|
121
|
+
* defers to the expression printer.
|
|
122
|
+
*/
|
|
123
|
+
declare function lookupNameSource(name: string | ValueNode): string;
|
|
124
|
+
declare function expressionSource(value: ValueNode): string;
|
|
125
|
+
/**
|
|
126
|
+
* Fold one logical rung left-associatively (§4.5.5). The result is an
|
|
127
|
+
* `Operation` carrying the word itself as its operator — the node that means
|
|
128
|
+
* "return one of these operands, short-circuiting" — so the transpiled `.jess`
|
|
129
|
+
* still reads `$a or $default` rather than a rewritten `$if` that duplicates
|
|
130
|
+
* the operand and no direct author would write.
|
|
131
|
+
*/
|
|
132
|
+
declare function foldLogicalExpression(kind: 'and' | 'or', children: readonly unknown[]): ExpressionFact;
|
|
133
|
+
declare function referenceBaseSource(value: ValueNode): string;
|
|
134
|
+
/** A member step is a `LookupStep` whose name is a literal — the old `DotLookup`. */
|
|
135
|
+
declare function isMemberStep(step: JessReferenceTail['step'] | undefined): boolean;
|
|
136
|
+
declare function declarationMemberReferenceFromVariableBase(base: Lookup, tails: readonly JessReferenceTail[]): Reference | null;
|
|
137
|
+
declare function interpolationFromChildren(children: readonly unknown[], span?: {
|
|
138
|
+
readonly start: number;
|
|
139
|
+
readonly end: number;
|
|
140
|
+
}): Interpolation;
|
|
141
|
+
/**
|
|
142
|
+
* Reduce a `${…}` interpolation. BARE-vs-BRACKETED selects the namespace:
|
|
143
|
+
*
|
|
144
|
+
* - `${foo}` → the VARIABLE `$foo`
|
|
145
|
+
* - `${[foo]}` → a LOOKUP, i.e. the PROPERTY `foo` declared in scope
|
|
146
|
+
* - `${["a b"]}` → the same lookup; the quotes are only escaping, because
|
|
147
|
+
* `a b` is not a valid identifier. `[foo]` and `["foo"]` are
|
|
148
|
+
* the same plain-string key (ledger P14), so quoting never
|
|
149
|
+
* carries meaning here.
|
|
150
|
+
* - `${[$k]}` → a lookup whose key is computed from `$k`.
|
|
151
|
+
*/
|
|
152
|
+
declare function dollarBraceInterpolation(children: readonly unknown[], span?: {
|
|
153
|
+
readonly start: number;
|
|
154
|
+
readonly end: number;
|
|
155
|
+
}): Interpolation;
|
|
156
|
+
declare function referenceArgSource(value: JessMixinCallArgument['value']): string;
|
|
157
|
+
declare function tokenSource(children: readonly unknown[]): string;
|
|
158
|
+
declare function sourceFromState(state: unknown): string | undefined;
|
|
159
|
+
declare function interpolationValue(child: unknown): Interpolation;
|
|
160
|
+
declare function quotedInterpolationFromChildren(children: readonly unknown[]): Quoted | Interpolation;
|
|
161
|
+
declare function escapedInterpolationFromChildren(children: readonly unknown[]): Interpolation;
|
|
162
|
+
declare function quotedExpressionFact(children: readonly unknown[]): ExpressionFact;
|
|
163
|
+
declare function reduceColonFeature(children: readonly unknown[], lostMessage: string): ValueNode;
|
|
164
|
+
declare function jessFunctionOpenName(child: unknown): string;
|
|
165
|
+
declare function requireStatements(children: readonly unknown[]): Statement[];
|
|
166
|
+
declare function collectBlockStatements(children: readonly unknown[], open: number): Statement[];
|
|
167
|
+
declare function collectBodyStatements(children: readonly unknown[], open: number): Statement[];
|
|
168
|
+
declare function requireStatementList(value: unknown): Statement[];
|
|
169
|
+
declare function isIfBranch(value: unknown): value is IfBranch;
|
|
170
|
+
declare function requireIfBranch(value: unknown): IfBranch;
|
|
171
|
+
declare function requireIfBranchArray(value: unknown): IfBranch[];
|
|
172
|
+
declare function requireIfBranchTuple(value: IfBranch[]): [IfBranch, ...IfBranch[]];
|
|
173
|
+
declare function requireForBinding(value: unknown): ForBinding;
|
|
174
|
+
declare function isAtRuleBlock(value: unknown): value is AtRuleBlock;
|
|
175
|
+
declare function isAtRuleStatement(value: unknown): value is AtRuleStatement;
|
|
176
|
+
declare function isUnknownAtRuleBlock(value: unknown): value is UnknownAtRuleBlock;
|
|
177
|
+
declare function isStyleImport(value: unknown): value is StyleImport;
|
|
178
|
+
declare function isApply(value: unknown): value is Apply;
|
|
179
|
+
declare function isReferenceCall(value: unknown): value is Reference;
|
|
180
|
+
declare function isQuoted(value: unknown): value is Quoted;
|
|
181
|
+
declare function isUrl(value: unknown): value is Url;
|
|
182
|
+
declare function urlFromChildren(children: readonly unknown[]): Url;
|
|
183
|
+
declare function requireLiteralQuoted(value: unknown): Quoted;
|
|
184
|
+
declare function isJessDeclaration(value: unknown): value is Declaration;
|
|
185
|
+
declare function isCollectionEntry(value: unknown): value is CollectionEntry;
|
|
186
|
+
declare function isRuleset(value: unknown): value is Ruleset;
|
|
187
|
+
declare function isMixinDefinition(value: unknown): value is MixinDefinition;
|
|
188
|
+
declare function isMixinCall(value: unknown): value is MixinCall;
|
|
189
|
+
declare function isFor(value: unknown): value is For;
|
|
190
|
+
declare function isIf(value: unknown): value is If;
|
|
191
|
+
declare function isWhile(value: unknown): value is While;
|
|
192
|
+
declare function requireExactToken(value: unknown, expected: string): void;
|
|
193
|
+
declare function isVarDeclaration(value: unknown): value is VariableDeclaration;
|
|
194
|
+
declare function reduceGuardTruth(children: readonly unknown[]): GuardNode;
|
|
195
|
+
declare function reduceIfCompare(children: readonly unknown[]): GuardNode;
|
|
196
|
+
declare function reduceGuardCompare(children: readonly unknown[]): GuardNode;
|
|
197
|
+
declare function reduceGuardAnd(children: readonly unknown[]): GuardNode;
|
|
198
|
+
declare function reduceGuardOr(children: readonly unknown[]): GuardNode;
|
|
199
|
+
declare function reduceVarDeclaration(children: readonly unknown[]): VariableDeclaration;
|
|
200
|
+
declare function reduceLambda(children: readonly unknown[]): AnonymousMixin;
|
|
201
|
+
declare function reduceCompound(children: readonly unknown[]): SelectorTerm;
|
|
202
|
+
declare function reduceSelectorTail(children: readonly unknown[]): SelectorBranch;
|
|
203
|
+
declare function reduceSelectorList(children: readonly unknown[]): SelectorList;
|
|
204
|
+
declare function isCalcOperator(text: string): boolean;
|
|
205
|
+
declare function dollarValueFromChildren(children: readonly unknown[]): ValueNode;
|
|
206
|
+
declare function foldCalcOperation(children: readonly unknown[]): ValueNode;
|
|
207
|
+
export { requireToken, requireFields, jessCombinator, jessRelativeCombinator, jessBranchSegments, isExpressionFact, isJessAtRuleHeader, requireJessAtRuleHeader, isAtRuleNameToken, isSelectorTerm, isSimpleSelector, isJessSelectorBranch, isJessSelectorList, isJessReferenceTail, isPseudoSelector, isSimpleToken, selectorTermFromTokens, requireSelectorList, requireJessReferenceTail, requireString, requireInterpolation, requireKeyword, staticSelectorText, JESS_STRUCTURED_PSEUDOS, isExtendInstruction, isParam, isParamList, isMixinCallArray, isExtendInstructionArray, isValueNode, isValueNodeArray, isValueSlotArray, jessValueSlot, isSequence, isJessValueSlotValue, requireValueSlot, isJessMixinCallArgument, requireValueNode, isGuardNode, requireGuardNode, isJessInterpolation, isInterpolationLiteral, appendInterpolationLiteral, templateInterpolationFromChildren, appendCustomValueParts, customValueFromChildren, requireExpressionFact, requireJessOperatorFact, foldExpression, lookupNameSource, expressionSource, foldLogicalExpression, referenceBaseSource, isMemberStep, declarationMemberReferenceFromVariableBase, interpolationFromChildren, dollarBraceInterpolation, referenceArgSource, tokenSource, sourceFromState, interpolationValue, quotedInterpolationFromChildren, escapedInterpolationFromChildren, quotedExpressionFact, reduceColonFeature, jessFunctionOpenName, requireStatements, collectBlockStatements, collectBodyStatements, requireStatementList, isIfBranch, requireIfBranch, requireIfBranchArray, requireIfBranchTuple, requireForBinding, isAtRuleBlock, isAtRuleStatement, isUnknownAtRuleBlock, isStyleImport, isApply, isReferenceCall, isQuoted, isUrl, urlFromChildren, requireLiteralQuoted, isJessDeclaration, isCollectionEntry, isRuleset, isMixinDefinition, isMixinCall, isFor, isIf, isWhile, requireExactToken, isVarDeclaration, reduceGuardTruth, reduceIfCompare, reduceGuardCompare, reduceGuardAnd, reduceGuardOr, reduceVarDeclaration, reduceLambda, reduceCompound, reduceSelectorTail, reduceSelectorList, isCalcOperator, dollarValueFromChildren, foldCalcOperation };
|
|
208
|
+
export type { ExpressionFact, JessOperatorFact, JessReferenceTail, JessComplexTail, JessSelectorSegment, JessQueryFeatureName, JessAtRuleHeader, JessMixinCallArgument };
|
package/lib/grammar.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export declare const jessGrammar: Record<string, import("parseman").
|
|
1
|
+
export declare const jessGrammar: Record<string, import("parseman").FusedRule>;
|
|
2
2
|
/** AST artifact with Parseman line/column tracking enabled. */
|
|
3
|
-
export declare const jessPositionsGrammar: Record<string, import("parseman").
|
|
4
|
-
export declare const jessCstGrammar: Record<string, import("parseman").
|
|
3
|
+
export declare const jessPositionsGrammar: Record<string, import("parseman").FusedRule>;
|
|
4
|
+
export declare const jessCstGrammar: Record<string, import("parseman").FusedRule>;
|
|
5
5
|
/** CST artifact with Parseman line/column tracking enabled. */
|
|
6
|
-
export declare const jessCstPositionsGrammar: Record<string, import("parseman").
|
|
6
|
+
export declare const jessCstPositionsGrammar: Record<string, import("parseman").FusedRule>;
|
package/package.json
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "2.0.0-alpha.
|
|
6
|
+
"version": "2.0.0-alpha.13",
|
|
7
7
|
"engines": {
|
|
8
|
-
"node": "^20.19.0 || >=22.
|
|
8
|
+
"node": "^20.19.0 || >=22.12.0"
|
|
9
9
|
},
|
|
10
10
|
"description": "Jess parser with direct canonical AST parsing and an explicit language-service CST entry",
|
|
11
11
|
"main": "lib/index.cjs",
|
|
@@ -65,11 +65,11 @@
|
|
|
65
65
|
"license": "MIT",
|
|
66
66
|
"dependencies": {
|
|
67
67
|
"color-name": "~2.0.0",
|
|
68
|
-
"@jesscss/css-parser": "2.0.0-alpha.
|
|
68
|
+
"@jesscss/css-parser": "2.0.0-alpha.13"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
|
-
"parseman": "^0.50.
|
|
72
|
-
"@jesscss/core": "2.0.0-alpha.
|
|
71
|
+
"parseman": "^0.50.5",
|
|
72
|
+
"@jesscss/core": "2.0.0-alpha.13"
|
|
73
73
|
},
|
|
74
74
|
"peerDependenciesMeta": {
|
|
75
75
|
"@jesscss/core": {
|
|
@@ -78,9 +78,9 @@
|
|
|
78
78
|
},
|
|
79
79
|
"devDependencies": {
|
|
80
80
|
"@types/color-name": "^1.1.1",
|
|
81
|
-
"parseman": "^0.50.
|
|
82
|
-
"@jesscss/
|
|
83
|
-
"@jesscss/
|
|
81
|
+
"parseman": "^0.50.5",
|
|
82
|
+
"@jesscss/core": "2.0.0-alpha.13",
|
|
83
|
+
"@jesscss/parser-shared": "2.0.0-alpha.13"
|
|
84
84
|
},
|
|
85
85
|
"type": "module",
|
|
86
86
|
"module": "lib/index.js",
|