@jesscss/less-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 +42 -40
- package/lib/ast/grammar.d.ts +2 -0
- package/lib/ast/grammar.d.ts.map +1 -0
- package/lib/grammar.cjs +40274 -27037
- package/lib/grammar.d.ts.map +1 -1
- package/lib/grammar.js +40274 -27037
- package/lib/index.cjs +49609 -15
- package/lib/index.d.ts +4 -9
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +49607 -5
- package/lib/parse-error.d.ts +15 -0
- package/lib/parse-error.d.ts.map +1 -0
- package/package.json +10 -25
- package/lib/builders.d.ts +0 -381
- package/lib/builders.d.ts.map +0 -1
- package/lib/functional-parser.cjs +0 -2653
- package/lib/functional-parser.d.ts +0 -18
- package/lib/functional-parser.d.ts.map +0 -1
- package/lib/functional-parser.js +0 -2588
- package/lib/jess.cjs +0 -3968
- package/lib/jess.d.ts +0 -7
- package/lib/jess.d.ts.map +0 -1
- package/lib/jess.js +0 -3962
- package/lib/lessParser.d.ts +0 -38
- package/lib/lessParser.d.ts.map +0 -1
- package/lib/lessRecursiveParser.d.ts +0 -99
- package/lib/lessRecursiveParser.d.ts.map +0 -1
- package/lib/lessTokens.d.ts +0 -23
- package/lib/lessTokens.d.ts.map +0 -1
- package/lib/productions/guards.d.ts +0 -113
- package/lib/productions/guards.d.ts.map +0 -1
- package/lib/productions/index.d.ts +0 -5
- package/lib/productions/index.d.ts.map +0 -1
- package/lib/productions/root.d.ts +0 -38
- package/lib/productions/root.d.ts.map +0 -1
- package/lib/productions/selectors.d.ts +0 -41
- package/lib/productions/selectors.d.ts.map +0 -1
- package/lib/productions/values.d.ts +0 -35
- package/lib/productions/values.d.ts.map +0 -1
- package/lib/utils.d.ts +0 -9
- package/lib/utils.d.ts.map +0 -1
- package/src/__tests__/debug-log.ts +0 -35
- package/src/__tests__/wall5-parse.test.ts +0 -67
- package/src/builders.ts +0 -3183
- package/src/cst.ts +0 -25
- package/src/functional-parser.ts +0 -162
- package/src/grammar.ts +0 -869
- package/src/index.ts +0 -19
- package/src/jess.ts +0 -6
- package/src/lessParser.ts +0 -120
- package/src/lessRecursiveParser.ts +0 -279
- package/src/lessTokens.ts +0 -350
- package/src/productions/guards.ts +0 -1066
- package/src/productions/index.ts +0 -29
- package/src/productions/root.ts +0 -1613
- package/src/productions/selectors.ts +0 -1309
- package/src/productions/values.ts +0 -1449
- package/src/utils.ts +0 -178
package/README.md
CHANGED
|
@@ -1,11 +1,29 @@
|
|
|
1
1
|
# @jesscss/less-parser
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
The Less grammar, layered on the CSS base parser, with core-free CST entry points.
|
|
4
|
+
|
|
5
|
+
> **Status: alpha.** Part of [Jess](https://github.com/jesscss/jess). The broader
|
|
6
|
+
> language/tooling picture is still early. Expect gaps and
|
|
7
|
+
> [report bugs](https://github.com/jesscss/jess/issues). Docs live at
|
|
8
|
+
> [jesscss.github.io](https://jesscss.github.io/).
|
|
9
|
+
|
|
10
|
+
## What it is
|
|
11
|
+
|
|
12
|
+
The Less grammar is the shared CSS grammar plus a Less delta:
|
|
13
|
+
`lessGrammar = compose([cssGrammar, <Less delta>])`. It adds `@variable` /
|
|
14
|
+
`@{interpolation}`, mixins, and the rest of Less on top of the spec-aligned CSS
|
|
15
|
+
base in [`@jesscss/css-parser`](https://www.npmjs.com/package/@jesscss/css-parser),
|
|
16
|
+
built on [parseman](https://www.npmjs.com/package/parseman) — **the fastest
|
|
17
|
+
general-purpose JavaScript parser** in its
|
|
18
|
+
[published benchmarks](https://matthew-dean.github.io/parseman/guide/benchmarks)
|
|
19
|
+
(see `@jesscss/css-parser` for figures and engineering details). It is the parser
|
|
20
|
+
Jess uses when it compiles `.less` — the "Now" tier of the language roadmap, and
|
|
21
|
+
the one dialect shipping in the alpha.
|
|
22
|
+
|
|
23
|
+
The default `parse()` operation constructs canonical AST v2 `Stylesheet` directly
|
|
24
|
+
through parser-local Parseman reductions. Use the explicit `./cst` entry when a
|
|
25
|
+
language-service or document consumer needs a CST. The package has no
|
|
26
|
+
core-owned parser driver or AST construction host.
|
|
9
27
|
|
|
10
28
|
## Install
|
|
11
29
|
|
|
@@ -13,7 +31,20 @@ Two ways to use it:
|
|
|
13
31
|
npm install @jesscss/less-parser
|
|
14
32
|
```
|
|
15
33
|
|
|
16
|
-
`@jesscss/core` is an
|
|
34
|
+
`@jesscss/core` is an optional peer for consumers using the default AST v2
|
|
35
|
+
`parse()` result. The explicit CST and grammar subpaths remain core-free.
|
|
36
|
+
Those explicit entries expose Parseman types and grammar values, so consumers
|
|
37
|
+
of them must also provide the package's `parseman` peer.
|
|
38
|
+
|
|
39
|
+
## Canonical AST parsing
|
|
40
|
+
|
|
41
|
+
```js
|
|
42
|
+
import { parse } from '@jesscss/less-parser'
|
|
43
|
+
|
|
44
|
+
const stylesheet = parse('@c: red;\n.foo { color: @c; }')
|
|
45
|
+
|
|
46
|
+
stylesheet.type // 'Stylesheet'
|
|
47
|
+
```
|
|
17
48
|
|
|
18
49
|
## Standalone usage (core-free)
|
|
19
50
|
|
|
@@ -43,8 +74,7 @@ Pass a different `startRule` (any capitalized grammar rule, e.g. `'SelectorList'
|
|
|
43
74
|
| `@jesscss/less-parser/cst` | `parseLessCst` | Core-free parse of a Less string to a CST. |
|
|
44
75
|
| `@jesscss/less-parser/cst` | `LessCstNode`, `LessCstLeaf`, `LessCstError`, `LessCstChild`, `LessCstParseResult`, `LessCstType` (types) | CST type definitions (aliases of the shared `@jesscss/css-parser/cst` types). |
|
|
45
76
|
| `@jesscss/less-parser/grammar` | `lessGrammar` | The compiled Less grammar (a rule map). Extend it with `compose()` or drive it directly with parseman's `run`. |
|
|
46
|
-
| `@jesscss/less-parser` (`.`) | `
|
|
47
|
-
| `@jesscss/less-parser/jess` | `LessParser`, `LessGrammar`, `parseLessFn`, … | Internal Jess-facing surface. |
|
|
77
|
+
| `@jesscss/less-parser` (`.`) | `parse` | Parse Less directly to canonical AST v2 `Stylesheet`. It does not load the CST grammar. |
|
|
48
78
|
|
|
49
79
|
## Default CST shape
|
|
50
80
|
|
|
@@ -131,34 +161,6 @@ type BuildHost = (
|
|
|
131
161
|
|
|
132
162
|
## Part of Jess
|
|
133
163
|
|
|
134
|
-
This package is developed as part of [Jess](https://github.com/jesscss/jess).
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
1. Auto-wrap parens around division to dis-ambiguate.
|
|
139
|
-
2. Convert `@import` to `@use` and `@include` syntax.
|
|
140
|
-
3. Throw errors on `@plugin` and ask to refactor with `@from`
|
|
141
|
-
4. Convert function references to `@from '#less' ([func])`
|
|
142
|
-
5. Add parentheses after mixin calls e.g. `.ns > .mixin;` to `.ns.mixin();`
|
|
143
|
-
6. Convert local imports from `@import 'local'` to `@include './local.less'`
|
|
144
|
-
7. Convert `@import (less) './file.css';` to `@include './file.css' as less;`
|
|
145
|
-
8. Convert `@import (inline) './file.css';` to `@include './file.css' as text;`
|
|
146
|
-
9. Convert `@import (reference) './file.less';` to `@use './file.less';`
|
|
147
|
-
10. Files that consume variables, mixins, or rules (like with extend) should have a `@use` added.
|
|
148
|
-
11. Don't allow `.class` as a value in a declaration. Convert to `\.class` e.g. `@foo: .class` should be converted to `@foo: \.class` (or `selector(.class)`?).
|
|
149
|
-
12. In a custom property value, convert `@variable` to `@{variable}`.
|
|
150
|
-
|
|
151
|
-
### Converting Less 1.x-4.x to Jess
|
|
152
|
-
|
|
153
|
-
1. Auto-wrap expressions (like math) with `$()`
|
|
154
|
-
2. Convert mixin definitions `.my-mixin()` to `@mixin my-mixin()`
|
|
155
|
-
3. Convert mixin calls to function calls: `#ns > .mixin()` to `$ns.mixin()`
|
|
156
|
-
4. Throw errors on mixed case mixins: `.my-mixin()` and `.myMixin()`
|
|
157
|
-
5. Throw errors on mixed hash and class mixins: `#my-mixin()` and `.my-mixin()`
|
|
158
|
-
5. Convert variable declarations `@my-var` with `$my-var`
|
|
159
|
-
6. Convert interpolated vars `@{my-var}` to `$(my-var)`
|
|
160
|
-
7. Convert property references `$prop` to `$[prop]`
|
|
161
|
-
8. Convert color names in expressions to hex values (or wrapped in `color()`?) (because Jess doesn't support color keywords in expressions). Alternatively, should Jess allow `keyword` to denote keywords?
|
|
162
|
-
9. Convert `@rest...` to `...rest`
|
|
163
|
-
10. Convert `.rules()` to `@include .rules()` if `.rules` is a selector. What if it's a selector and mixin? Maybe something like `@include .rules, $rules();`? This might change the execution order from Less though.
|
|
164
|
-
11. Convert `@foo: extract(@bar, 1)` to `@let foo: $bar[0];`?
|
|
164
|
+
This package is developed as part of [Jess](https://github.com/jesscss/jess).
|
|
165
|
+
Jess translates a Less string into the core Jess AST, which the compiler then
|
|
166
|
+
evaluates and renders to CSS. Licensed MIT.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grammar.d.ts","sourceRoot":"","sources":["../../src/ast/grammar.ts"],"names":[],"mappings":"AA49CA,eAAO,MAAM,cAAc,8CAuhGvB,CAAC"}
|