@jesscss/scss-parser 2.0.0-alpha.7 → 2.0.0-alpha.9
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 +54 -12
- package/lib/ast/grammar.cjs +36610 -0
- package/lib/ast/grammar.d.ts +1 -0
- package/lib/ast/grammar.js +36609 -0
- package/lib/ast/lower-user-function-calls.d.ts +6 -0
- package/lib/cst.cjs +1 -1
- package/lib/cst.js +1 -1
- package/lib/grammar.cjs +2 -55568
- package/lib/grammar.js +1 -55567
- package/lib/grammar2.cjs +88858 -0
- package/lib/grammar2.js +88853 -0
- package/lib/index.cjs +108 -11
- package/lib/index.d.ts +10 -7
- package/lib/index.js +107 -5
- package/package.json +10 -20
- package/lib/builders.d.ts +0 -154
- package/lib/functional-parser.cjs +0 -2872
- package/lib/functional-parser.d.ts +0 -46
- package/lib/functional-parser.js +0 -2855
- package/lib/interp.d.ts +0 -26
- package/lib/jess.cjs +0 -6
- package/lib/jess.d.ts +0 -2
- package/lib/jess.js +0 -2
- package/lib/scss-atroot-helpers.d.ts +0 -4
- package/lib/scss-atrule-helpers.d.ts +0 -36
- package/lib/scss-value-helpers.d.ts +0 -11
- package/src/builders.ts +0 -1408
- package/src/cst.ts +0 -25
- package/src/functional-parser.ts +0 -135
- package/src/grammar.ts +0 -621
- package/src/index.ts +0 -14
- package/src/interp.ts +0 -158
- package/src/jess.ts +0 -11
- package/src/scss-atroot-helpers.ts +0 -105
- package/src/scss-atrule-helpers.ts +0 -191
- package/src/scss-value-helpers.ts +0 -105
package/src/cst.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { parseCst, parseDocCst, type CssCstNode, type CssCstParseOptions, type CssCstParseResult, type ParseDoc } from '@jesscss/css-parser/cst';
|
|
2
|
-
import { scssGrammar } from './grammar.js';
|
|
3
|
-
|
|
4
|
-
export function parseScssCst(
|
|
5
|
-
input: string,
|
|
6
|
-
startRule = 'Stylesheet',
|
|
7
|
-
options?: CssCstParseOptions
|
|
8
|
-
): CssCstParseResult {
|
|
9
|
-
return parseCst(scssGrammar as Record<string, unknown>, input, startRule, options);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/** Incremental (`.edit()`-able) SCSS document — see `parseDocCst`. */
|
|
13
|
-
export function parseScssDoc(input: string, startRule = 'Stylesheet'): ParseDoc<CssCstNode> {
|
|
14
|
-
return parseDocCst(scssGrammar as Record<string, unknown>, input, startRule);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export type {
|
|
18
|
-
CssCstChild as ScssCstChild,
|
|
19
|
-
CssCstError as ScssCstError,
|
|
20
|
-
CssCstLeaf as ScssCstLeaf,
|
|
21
|
-
CssCstNode as ScssCstNode,
|
|
22
|
-
CssCstParseOptions as ScssCstParseOptions,
|
|
23
|
-
CssCstParseResult as ScssCstParseResult,
|
|
24
|
-
CssCstType as ScssCstType
|
|
25
|
-
} from '@jesscss/css-parser/cst';
|
package/src/functional-parser.ts
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Public functional SCSS parser: the build host (reuses ScssGrammar's SCSS +
|
|
3
|
-
* inherited Less/CSS `buildNode`) and the `parseScssFn` / `ScssParser` entry
|
|
4
|
-
* points. The grammar itself lives in ./grammar.ts; the shared driver is reused
|
|
5
|
-
* from @jesscss/css-parser.
|
|
6
|
-
*/
|
|
7
|
-
import type { FieldMap, Span } from 'parseman';
|
|
8
|
-
import type { TriviaMap, JessError, Rules, TreeContext, IParseResult } from '@jesscss/core';
|
|
9
|
-
import type { ILexingResult } from 'chevrotain';
|
|
10
|
-
import { runFunctionalParse, type FunctionalParseHost } from '@jesscss/css-parser/jess';
|
|
11
|
-
import { scssGrammar } from './grammar.js';
|
|
12
|
-
import { ScssGrammar } from './builders.js';
|
|
13
|
-
import { setParseScssFnForInterp } from './interp.js';
|
|
14
|
-
|
|
15
|
-
/** Config accepted for API compatibility; the functional driver ignores it. */
|
|
16
|
-
export type ScssParserConfig = {
|
|
17
|
-
recoveryEnabled?: boolean;
|
|
18
|
-
[k: string]: unknown;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
/** Grammar rule name (root `Stylesheet` by default). */
|
|
22
|
-
export type ScssRules = string;
|
|
23
|
-
|
|
24
|
-
export type SyntacticContentAssistSuggestion = {
|
|
25
|
-
nextTokenType: string;
|
|
26
|
-
nextTokenLabel?: string;
|
|
27
|
-
ruleStack: string[];
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
// ---------------------------------------------------------------------------
|
|
31
|
-
// Builder host — reuse ScssGrammar's builders (SCSS + inherited Less/CSS).
|
|
32
|
-
// ---------------------------------------------------------------------------
|
|
33
|
-
|
|
34
|
-
class BuilderHost extends ScssGrammar implements FunctionalParseHost {
|
|
35
|
-
setSource(src: string) {
|
|
36
|
-
this._source = src;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
resetWarnings() {
|
|
40
|
-
this._warnings = [];
|
|
41
|
-
this._errors = [];
|
|
42
|
-
this._liftedCommentRanges = [];
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
getWarnings() {
|
|
46
|
-
return this._warnings.slice();
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
getErrors() {
|
|
50
|
-
return this._errors.slice();
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
setContext(context?: TreeContext) {
|
|
54
|
-
this._parseContext = context;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/** `ctx.build` host: every structural `node(type, …)` builds through this,
|
|
58
|
-
* reusing ScssGrammar's (SCSS + inherited Less/CSS) `buildNode` verbatim. */
|
|
59
|
-
captureTriviaForNode(type: string) {
|
|
60
|
-
return type === 'CompoundSelector';
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
build(type: string, children: ReadonlyArray<unknown>, fields: FieldMap | undefined, span: { start: number; end: number }, rawChildren: ReadonlyArray<unknown>, triviaLog: readonly number[]): unknown {
|
|
64
|
-
/* eslint-disable @typescript-eslint/no-unsafe-type-assertion */
|
|
65
|
-
return (this as unknown as {
|
|
66
|
-
buildNode(t: string, s: Span, c: ReadonlyArray<unknown>, st: unknown, r: ReadonlyArray<unknown>, f?: FieldMap, tl?: readonly number[]): unknown;
|
|
67
|
-
}).buildNode(type, { start: span.start, end: span.end } as Span, children, undefined, rawChildren, fields, triviaLog);
|
|
68
|
-
/* eslint-enable @typescript-eslint/no-unsafe-type-assertion */
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const host = new BuilderHost();
|
|
73
|
-
|
|
74
|
-
export type ScssFnParseResult = {
|
|
75
|
-
tree: Rules;
|
|
76
|
-
errors: JessError[];
|
|
77
|
-
warnings: Array<{ message: string; deprecation?: string }>;
|
|
78
|
-
trivia: TriviaMap;
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
export type ScssFnParseOptions = {
|
|
82
|
-
context?: TreeContext;
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
// `rule` is a grammar rule name — the root `Stylesheet` by default.
|
|
86
|
-
export function parseScssFn(
|
|
87
|
-
input: string,
|
|
88
|
-
rule = 'Stylesheet',
|
|
89
|
-
options: ScssFnParseOptions = {}
|
|
90
|
-
): ScssFnParseResult {
|
|
91
|
-
const g = scssGrammar as Record<string, unknown>;
|
|
92
|
-
host.setContext(options.context);
|
|
93
|
-
// SCSS trivia includes `//` line comments, so trailing `//…` is not leftover.
|
|
94
|
-
return runFunctionalParse(input, g[rule], host, { trivia: g.rw });
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
setParseScssFnForInterp(parseScssFn);
|
|
98
|
-
|
|
99
|
-
const EMPTY_LEXER_RESULT: ILexingResult = { tokens: [], errors: [], groups: {} };
|
|
100
|
-
|
|
101
|
-
function toParseResult(result: ScssFnParseResult): IParseResult<Rules> {
|
|
102
|
-
return {
|
|
103
|
-
tree: result.tree,
|
|
104
|
-
// JessError is the normalized error shape; compatible with IParseResult consumers.
|
|
105
|
-
/* eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion */
|
|
106
|
-
errors: result.errors as IParseResult['errors'],
|
|
107
|
-
warnings: result.warnings,
|
|
108
|
-
trivia: result.trivia,
|
|
109
|
-
lexerResult: EMPTY_LEXER_RESULT
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Functional SCSS parser — the default `Parser` export. Wraps `parseScssFn` and
|
|
115
|
-
* returns the same `IParseResult` shape as the legacy Chevrotain parser (with an
|
|
116
|
-
* empty `lexerResult`; the functional grammar does not tokenize separately).
|
|
117
|
-
*/
|
|
118
|
-
export class ScssParser {
|
|
119
|
-
constructor(_config: ScssParserConfig = {}) {
|
|
120
|
-
// Config accepted for API compatibility; not yet wired through the
|
|
121
|
-
// functional driver.
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
parse(text: string): IParseResult<Rules>;
|
|
125
|
-
parse(text: string, rule: 'Stylesheet'): IParseResult<Rules>;
|
|
126
|
-
parse(text: string, rule: 'Stylesheet', options: { context?: TreeContext }): IParseResult<Rules>;
|
|
127
|
-
parse(text: string, rule?: string, options?: { context?: TreeContext }): IParseResult;
|
|
128
|
-
parse(text: string, rule: string = 'Stylesheet', options?: { context?: TreeContext }): IParseResult {
|
|
129
|
-
return toParseResult(parseScssFn(text, rule, { context: options?.context }));
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
suggest(_text: string, _init?: { offset: number; rule?: ScssRules }): SyntacticContentAssistSuggestion[] {
|
|
133
|
-
return [];
|
|
134
|
-
}
|
|
135
|
-
}
|