@jesscss/css-parser 1.0.8-alpha.6 → 2.0.0-alpha.2
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/advancedActionsParser.d.ts +60 -0
- package/lib/advancedActionsParser.js +203 -0
- package/lib/advancedActionsParser.js.map +1 -0
- package/lib/cssActionsParser.d.ts +155 -0
- package/lib/cssActionsParser.js +376 -0
- package/lib/cssActionsParser.js.map +1 -0
- package/lib/cssErrorMessageProvider.d.ts +14 -0
- package/lib/cssErrorMessageProvider.js +40 -0
- package/lib/cssErrorMessageProvider.js.map +1 -0
- package/lib/cssParser.d.ts +36 -103
- package/lib/cssParser.js +75 -58
- package/lib/cssParser.js.map +1 -0
- package/lib/cssTokens.d.ts +539 -5
- package/lib/cssTokens.js +488 -232
- package/lib/cssTokens.js.map +1 -0
- package/lib/index.d.ts +8 -16
- package/lib/index.js +9 -41
- package/lib/index.js.map +1 -0
- package/lib/productions.d.ts +273 -0
- package/lib/productions.js +3499 -0
- package/lib/productions.js.map +1 -0
- package/lib/test/ast-serialize.test.d.ts +1 -0
- package/lib/test/ast-serialize.test.js +157 -0
- package/lib/test/ast-serialize.test.js.map +1 -0
- package/lib/test/container.test.d.ts +1 -0
- package/lib/test/container.test.js +369 -0
- package/lib/test/container.test.js.map +1 -0
- package/lib/test/css-files.test.d.ts +1 -0
- package/lib/test/css-files.test.js +21 -0
- package/lib/test/css-files.test.js.map +1 -0
- package/lib/test/less-output.test.d.ts +1 -0
- package/lib/test/less-output.test.js +52 -0
- package/lib/test/less-output.test.js.map +1 -0
- package/lib/util/cst.d.ts +7 -2
- package/lib/util/cst.js +5 -9
- package/lib/util/cst.js.map +1 -0
- package/lib/util/index.d.ts +19 -13
- package/lib/util/index.js +98 -87
- package/lib/util/index.js.map +1 -0
- package/package.json +43 -20
- package/lib/productions/atRules.d.ts +0 -2
- package/lib/productions/atRules.js +0 -196
- package/lib/productions/blocks.d.ts +0 -2
- package/lib/productions/blocks.js +0 -181
- package/lib/productions/declarations.d.ts +0 -14
- package/lib/productions/declarations.js +0 -59
- package/lib/productions/root.d.ts +0 -2
- package/lib/productions/root.js +0 -49
- package/lib/productions/selectors.d.ts +0 -2
- package/lib/productions/selectors.js +0 -231
- package/lib/productions/values.d.ts +0 -2
- package/lib/productions/values.js +0 -114
package/lib/cssParser.js
CHANGED
|
@@ -1,62 +1,79 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const endIndex = this.currIdx;
|
|
39
|
-
if (result && result.name) {
|
|
40
|
-
const startToken = this.input[startIndex];
|
|
41
|
-
const endToken = this.input[endIndex];
|
|
42
|
-
if (startToken && endToken) {
|
|
43
|
-
const { startOffset, startColumn, startLine } = startToken;
|
|
44
|
-
const { endOffset, endColumn, endLine } = endToken;
|
|
45
|
-
result.location = {
|
|
46
|
-
startOffset, startColumn, startLine,
|
|
47
|
-
endOffset, endColumn, endLine
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return result;
|
|
52
|
-
}
|
|
53
|
-
return func();
|
|
1
|
+
import { Lexer } from 'chevrotain';
|
|
2
|
+
import { cssLexer } from './cssTokens.js';
|
|
3
|
+
import { CssActionsParser } from './cssActionsParser.js';
|
|
4
|
+
import { CssErrorMessageProvider } from './cssErrorMessageProvider.js';
|
|
5
|
+
const errorMessageProvider = new CssErrorMessageProvider();
|
|
6
|
+
/**
|
|
7
|
+
* If we're not extending the CSS parser,
|
|
8
|
+
* this is the friendlier interface for returning
|
|
9
|
+
* a CST, as it assigns tokens to the parser automatically.
|
|
10
|
+
*/
|
|
11
|
+
export class CssParser {
|
|
12
|
+
lexer;
|
|
13
|
+
parser;
|
|
14
|
+
/**
|
|
15
|
+
* @note `recoveryEnabled` should be set to true for
|
|
16
|
+
* linting and language services.
|
|
17
|
+
*/
|
|
18
|
+
constructor(config = {}) {
|
|
19
|
+
config = {
|
|
20
|
+
errorMessageProvider,
|
|
21
|
+
/**
|
|
22
|
+
* Override this if you want to omit legacy IE syntax
|
|
23
|
+
* and ancient CSS hacks.
|
|
24
|
+
* @todo Allow overriding when parsing a single rule.
|
|
25
|
+
*/
|
|
26
|
+
legacyMode: true,
|
|
27
|
+
skipValidations: process.env.TEST !== 'true',
|
|
28
|
+
...config
|
|
29
|
+
};
|
|
30
|
+
const { lexer, T } = cssLexer;
|
|
31
|
+
this.lexer = new Lexer(lexer, {
|
|
32
|
+
ensureOptimizations: true,
|
|
33
|
+
// Always run the validations during testing (dev flows).
|
|
34
|
+
// And avoid validation during productive flows to reduce the Lexer's startup time.
|
|
35
|
+
skipValidations: process.env.TEST !== 'true'
|
|
36
|
+
});
|
|
37
|
+
this.parser = new CssActionsParser(lexer, T, config);
|
|
54
38
|
}
|
|
55
|
-
|
|
56
|
-
|
|
39
|
+
parse(text, rule = 'stylesheet') {
|
|
40
|
+
const parser = this.parser;
|
|
41
|
+
const lexerResult = this.lexer.tokenize(text);
|
|
42
|
+
const lexedTokens = lexerResult.tokens;
|
|
43
|
+
// removed diagnostics
|
|
44
|
+
parser.input = lexedTokens;
|
|
45
|
+
const tree = parser[rule]();
|
|
46
|
+
return {
|
|
47
|
+
tree,
|
|
48
|
+
lexerResult,
|
|
49
|
+
errors: parser.errors,
|
|
50
|
+
warnings: [] // CSS parser doesn't produce deprecation warnings
|
|
51
|
+
};
|
|
57
52
|
}
|
|
58
|
-
|
|
59
|
-
|
|
53
|
+
/**
|
|
54
|
+
* IDE helper: suggest next possible token types at `offset` using Chevrotain's
|
|
55
|
+
* syntactic content assist. This is syntactic-only (not semantic completion).
|
|
56
|
+
*
|
|
57
|
+
* Note: content assist is significantly slower than normal parsing, so it
|
|
58
|
+
* should be called on-demand (e.g. near the cursor).
|
|
59
|
+
*/
|
|
60
|
+
suggest(text, init) {
|
|
61
|
+
const { offset, rule = 'stylesheet' } = init;
|
|
62
|
+
const prefix = text.slice(0, Math.max(0, offset));
|
|
63
|
+
const lexerResult = this.lexer.tokenize(prefix);
|
|
64
|
+
const tokens = lexerResult.tokens;
|
|
65
|
+
try {
|
|
66
|
+
const paths = this.parser.computeContentAssist(rule, tokens);
|
|
67
|
+
return paths.map(p => ({
|
|
68
|
+
nextTokenType: p.nextTokenType.name,
|
|
69
|
+
nextTokenLabel: p.nextTokenType.LABEL,
|
|
70
|
+
ruleStack: p.ruleStack,
|
|
71
|
+
occurrenceStack: p.occurrenceStack
|
|
72
|
+
}));
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return [];
|
|
76
|
+
}
|
|
60
77
|
}
|
|
61
78
|
}
|
|
62
|
-
|
|
79
|
+
//# sourceMappingURL=cssParser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cssParser.js","sourceRoot":"","sources":["../src/cssParser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAuC,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9F,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAKvE,MAAM,oBAAoB,GAAG,IAAI,uBAAuB,EAAE,CAAC;AAW3D;;;;GAIG;AACH,MAAM,OAAO,SAAS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