@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.
Files changed (58) hide show
  1. package/README.md +42 -40
  2. package/lib/ast/grammar.d.ts +2 -0
  3. package/lib/ast/grammar.d.ts.map +1 -0
  4. package/lib/grammar.cjs +40274 -27037
  5. package/lib/grammar.d.ts.map +1 -1
  6. package/lib/grammar.js +40274 -27037
  7. package/lib/index.cjs +49609 -15
  8. package/lib/index.d.ts +4 -9
  9. package/lib/index.d.ts.map +1 -1
  10. package/lib/index.js +49607 -5
  11. package/lib/parse-error.d.ts +15 -0
  12. package/lib/parse-error.d.ts.map +1 -0
  13. package/package.json +10 -25
  14. package/lib/builders.d.ts +0 -381
  15. package/lib/builders.d.ts.map +0 -1
  16. package/lib/functional-parser.cjs +0 -2653
  17. package/lib/functional-parser.d.ts +0 -18
  18. package/lib/functional-parser.d.ts.map +0 -1
  19. package/lib/functional-parser.js +0 -2588
  20. package/lib/jess.cjs +0 -3968
  21. package/lib/jess.d.ts +0 -7
  22. package/lib/jess.d.ts.map +0 -1
  23. package/lib/jess.js +0 -3962
  24. package/lib/lessParser.d.ts +0 -38
  25. package/lib/lessParser.d.ts.map +0 -1
  26. package/lib/lessRecursiveParser.d.ts +0 -99
  27. package/lib/lessRecursiveParser.d.ts.map +0 -1
  28. package/lib/lessTokens.d.ts +0 -23
  29. package/lib/lessTokens.d.ts.map +0 -1
  30. package/lib/productions/guards.d.ts +0 -113
  31. package/lib/productions/guards.d.ts.map +0 -1
  32. package/lib/productions/index.d.ts +0 -5
  33. package/lib/productions/index.d.ts.map +0 -1
  34. package/lib/productions/root.d.ts +0 -38
  35. package/lib/productions/root.d.ts.map +0 -1
  36. package/lib/productions/selectors.d.ts +0 -41
  37. package/lib/productions/selectors.d.ts.map +0 -1
  38. package/lib/productions/values.d.ts +0 -35
  39. package/lib/productions/values.d.ts.map +0 -1
  40. package/lib/utils.d.ts +0 -9
  41. package/lib/utils.d.ts.map +0 -1
  42. package/src/__tests__/debug-log.ts +0 -35
  43. package/src/__tests__/wall5-parse.test.ts +0 -67
  44. package/src/builders.ts +0 -3183
  45. package/src/cst.ts +0 -25
  46. package/src/functional-parser.ts +0 -162
  47. package/src/grammar.ts +0 -869
  48. package/src/index.ts +0 -19
  49. package/src/jess.ts +0 -6
  50. package/src/lessParser.ts +0 -120
  51. package/src/lessRecursiveParser.ts +0 -279
  52. package/src/lessTokens.ts +0 -350
  53. package/src/productions/guards.ts +0 -1066
  54. package/src/productions/index.ts +0 -29
  55. package/src/productions/root.ts +0 -1613
  56. package/src/productions/selectors.ts +0 -1309
  57. package/src/productions/values.ts +0 -1449
  58. package/src/utils.ts +0 -178
package/README.md CHANGED
@@ -1,11 +1,29 @@
1
1
  # @jesscss/less-parser
2
2
 
3
- A [Less](https://lesscss.org/) parser built on [parseman](https://www.npmjs.com/package/parseman). The grammar is the CSS grammar plus a Less delta: `lessGrammar = compose([cssGrammar, <Less delta>])`. It adds `@variable` / `@{interpolation}`, mixins, and the rest of Less on top of the shared CSS base in `@jesscss/css-parser`.
4
-
5
- Two ways to use it:
6
-
7
- - **As part of Jess** — the default `.` entry is wired into `@jesscss/core` and produces the core AST the Jess compiler evaluates (this is what runs when Jess compiles Less). This is the internal, core-coupled path.
8
- - **As a standalone CST parser** — the `./cst` entry has **no dependency on `@jesscss/core`**. Install just this package and parse Less source text into a concrete syntax tree (CST). You can also plug your own builders onto the grammar to produce your own AST instead of the default CST.
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 **optional** peer dependency needed only for the core-coupled `.` entry, not for `./cst` or `./grammar`.
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` (`.`) | `LessParser` (also `Parser`), `parseLessFn`, `lessGrammar`, tokens, | The Jess-internal barrel. **Core-coupled** (the functional parser builds the core AST). Prefer `./cst` if you don't need `@jesscss/core`. |
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). Jess translates a Less string into a Jess AST; the sections below track the migration rules that entails.
135
-
136
- ### Converting Less 1.x-5.x to Less 6
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,2 @@
1
+ export declare const lessAstGrammar: Record<string, import("parseman").FusedRule>;
2
+ //# sourceMappingURL=grammar.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grammar.d.ts","sourceRoot":"","sources":["../../src/ast/grammar.ts"],"names":[],"mappings":"AA49CA,eAAO,MAAM,cAAc,8CAuhGvB,CAAC"}