@jesscss/jess-parser 2.0.0-alpha.11 → 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/index.d.ts CHANGED
@@ -1,13 +1,13 @@
1
- export { jessGrammar } from './grammar.js';
2
- export { parseJessCst, parseJessDoc } from './cst.js';
3
1
  export type { JessCstChild, JessCstError, JessCstLeaf, JessCstNode, JessCstParseResult, JessCstType } from './cst.js';
4
- import { type Stylesheet } from '@jesscss/core/ast';
5
- /** Structured failure from the public direct Jess parser. */
6
- export declare class JessParseError extends SyntaxError {
7
- readonly code: 'parse/syntax-error';
8
- readonly offset: number;
9
- readonly expected: readonly string[];
10
- constructor(offset: number, expected: readonly string[]);
11
- }
12
- /** Parse Jess directly into the canonical AST v2 document. */
13
- export declare function parse(input: string): Stylesheet;
2
+ import type { Stylesheet } from '@jesscss/core/ast';
3
+ import { type JessParseOptions } from './parse-with.js';
4
+ export type { JessParseOptions } from './parse-with.js';
5
+ export { JessParseError } from './parse-error.js';
6
+ /**
7
+ * Parse Jess directly into the canonical AST v2 document.
8
+ *
9
+ * Spans carry offsets only. For `startLine`/`startColumn` facts import `parse`
10
+ * from `@jesscss/jess-parser/positions` the same function bound to the
11
+ * line-aware compiled table. This entry never loads that table.
12
+ */
13
+ export declare function parse(input: string, options?: JessParseOptions): Stylesheet;
package/lib/index.js CHANGED
@@ -1,36 +1,15 @@
1
- import { jessAstGrammar, jessGrammar } from "./grammar.js";
2
- import { parseJessCst, parseJessDoc } from "./cst.js";
3
- import { createTriviaMapFromParseman, withSourceSpan, withTriviaMap } from "@jesscss/core/ast";
4
- import { run } from "parseman";
1
+ import { n as JessParseError, t as parseWith } from "./chunks/parse-with.js";
2
+ import { jessGrammar } from "./grammar/ast.js";
5
3
  //#region src/index.ts
6
- /** Structured failure from the public direct Jess parser. */
7
- var JessParseError = class extends SyntaxError {
8
- code = "parse/syntax-error";
9
- offset;
10
- expected;
11
- constructor(offset, expected) {
12
- const detail = expected.length > 0 ? ` Expected: ${expected.join(", ")}.` : "";
13
- super(`Jess parser error.${detail}`);
14
- this.name = "JessParseError";
15
- this.offset = offset;
16
- this.expected = expected;
17
- }
18
- };
19
- function isStylesheet(value) {
20
- return typeof value === "object" && value !== null && "type" in value && value.type === "Stylesheet" && "children" in value && Array.isArray(value.children);
21
- }
22
- /** Parse Jess directly into the canonical AST v2 document. */
23
- function parse(input) {
24
- const entry = jessAstGrammar.Stylesheet;
25
- const trivia = jessAstGrammar.whitespace;
26
- if (entry === void 0 || trivia === void 0) throw new TypeError("Jess AST grammar is missing its public document entry.");
27
- const result = run(entry, input, { trivia });
28
- if (!result.ok || result.unconsumedFrom !== null || !isStylesheet(result.value)) {
29
- const offset = result.ok ? result.unconsumedFrom ?? result.span.end : result.span.start;
30
- const expected = result.expected;
31
- throw new JessParseError(offset, expected);
32
- }
33
- return withTriviaMap(withSourceSpan(result.value, result.span), createTriviaMapFromParseman(input, result.triviaMap));
4
+ /**
5
+ * Parse Jess directly into the canonical AST v2 document.
6
+ *
7
+ * Spans carry offsets only. For `startLine`/`startColumn` facts import `parse`
8
+ * from `@jesscss/jess-parser/positions` — the same function bound to the
9
+ * line-aware compiled table. This entry never loads that table.
10
+ */
11
+ function parse(input, options = {}) {
12
+ return parseWith(jessGrammar, input, options);
34
13
  }
35
14
  //#endregion
36
- export { JessParseError, jessGrammar, parse, parseJessCst, parseJessDoc };
15
+ export { JessParseError, parse };
@@ -0,0 +1,27 @@
1
+ /**
2
+ * The public Jess parse failure lives in its own module so that both AST
3
+ * entries — `.` and `./positions` — can export it without either one reaching
4
+ * the other's compiled grammar table. A class declared in an entry cannot be
5
+ * re-exported by a sibling entry without dragging that entry's imports along.
6
+ */
7
+ /** Structured failure from the public direct Jess parser. */
8
+ export declare class JessParseError extends SyntaxError {
9
+ readonly code: 'parse/syntax-error';
10
+ readonly offset: number;
11
+ readonly expected: readonly string[];
12
+ readonly line?: number;
13
+ readonly column?: number;
14
+ readonly endLine?: number;
15
+ readonly endColumn?: number;
16
+ readonly reason?: string;
17
+ readonly fix?: string;
18
+ constructor(offset: number, expected: readonly string[], options?: {
19
+ message?: string;
20
+ reason?: string;
21
+ fix?: string;
22
+ line?: number;
23
+ column?: number;
24
+ endLine?: number;
25
+ endColumn?: number;
26
+ });
27
+ }
@@ -0,0 +1,14 @@
1
+ import { type Stylesheet } from '@jesscss/core/ast';
2
+ import type { ApplySelectorKind, ExtendSelectorKind } from '@jesscss/core';
3
+ import type { jessGrammar } from './grammar/ast.js';
4
+ /** The rule map both compiled Jess AST variants expose. */
5
+ export type JessAstGrammar = typeof jessGrammar;
6
+ export interface JessParseOptions {
7
+ readonly allowExtendSelectors?: readonly ExtendSelectorKind[];
8
+ /**
9
+ * Selector kinds accepted by `$apply`. Jess treats `$apply` as a utility-class
10
+ * composition feature by default, so unset means class selectors only.
11
+ */
12
+ readonly allowApplySelectors?: readonly ApplySelectorKind[];
13
+ }
14
+ export declare function parseWith(grammar: JessAstGrammar, input: string, options?: JessParseOptions): Stylesheet;
@@ -0,0 +1,11 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_parse_with = require("./chunks/parse-with.cjs");
3
+ let src_grammar_ast_positions_js = require("./grammar/ast/positions.cjs");
4
+ //#region src/positions.ts
5
+ /** Parse Jess into the canonical AST v2 document with line/column facts. */
6
+ function parse(input, options = {}) {
7
+ return require_parse_with.parseWith(src_grammar_ast_positions_js.jessPositionsGrammar, input, options);
8
+ }
9
+ //#endregion
10
+ exports.JessParseError = require_parse_with.JessParseError;
11
+ exports.parse = parse;
@@ -0,0 +1,9 @@
1
+ import { n as JessParseError, t as parseWith } from "./chunks/parse-with.js";
2
+ import { jessPositionsGrammar } from "./grammar/ast/positions.js";
3
+ //#region src/positions.ts
4
+ /** Parse Jess into the canonical AST v2 document with line/column facts. */
5
+ function parse(input, options = {}) {
6
+ return parseWith(jessPositionsGrammar, input, options);
7
+ }
8
+ //#endregion
9
+ export { JessParseError, parse };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Root-trivia label selection for the Jess grammar.
3
+ *
4
+ * This is a plain fact about the grammar's trivia arm labels, so it lives in a
5
+ * leaf module with no imports. Reading it from the CST entry instead would make
6
+ * every consumer of the package entry load the compiled CST grammar tables:
7
+ * Node's ESM loader does not tree-shake, so an unused named import still
8
+ * executes the module it is taken from, and each table is multiple megabytes.
9
+ */
10
+ export declare const commentTriviaLabels: readonly ['comment'];
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "2.0.0-alpha.11",
6
+ "version": "2.0.0-alpha.13",
7
7
  "engines": {
8
8
  "node": "^20.19.0 || >=22.12.0"
9
9
  },
@@ -16,15 +16,45 @@
16
16
  "import": "./lib/index.js",
17
17
  "require": "./lib/index.cjs"
18
18
  },
19
+ "./positions": {
20
+ "types": "./lib/positions.d.ts",
21
+ "import": "./lib/positions.js",
22
+ "require": "./lib/positions.cjs"
23
+ },
19
24
  "./cst": {
20
25
  "types": "./lib/cst.d.ts",
21
26
  "import": "./lib/cst.js",
22
27
  "require": "./lib/cst.cjs"
23
28
  },
29
+ "./cst/positions": {
30
+ "types": "./lib/cst/positions.d.ts",
31
+ "import": "./lib/cst/positions.js",
32
+ "require": "./lib/cst/positions.cjs"
33
+ },
24
34
  "./grammar": {
25
- "types": "./lib/grammar.d.ts",
26
- "import": "./lib/grammar.js",
27
- "require": "./lib/grammar.cjs"
35
+ "types": "./lib/grammar/ast.d.ts",
36
+ "import": "./lib/grammar/ast.js",
37
+ "require": "./lib/grammar/ast.cjs"
38
+ },
39
+ "./grammar/ast": {
40
+ "types": "./lib/grammar/ast.d.ts",
41
+ "import": "./lib/grammar/ast.js",
42
+ "require": "./lib/grammar/ast.cjs"
43
+ },
44
+ "./grammar/ast/positions": {
45
+ "types": "./lib/grammar/ast/positions.d.ts",
46
+ "import": "./lib/grammar/ast/positions.js",
47
+ "require": "./lib/grammar/ast/positions.cjs"
48
+ },
49
+ "./grammar/cst": {
50
+ "types": "./lib/grammar/cst.d.ts",
51
+ "import": "./lib/grammar/cst.js",
52
+ "require": "./lib/grammar/cst.cjs"
53
+ },
54
+ "./grammar/cst/positions": {
55
+ "types": "./lib/grammar/cst/positions.d.ts",
56
+ "import": "./lib/grammar/cst/positions.js",
57
+ "require": "./lib/grammar/cst/positions.cjs"
28
58
  },
29
59
  "./package.json": "./package.json"
30
60
  },
@@ -35,11 +65,11 @@
35
65
  "license": "MIT",
36
66
  "dependencies": {
37
67
  "color-name": "~2.0.0",
38
- "@jesscss/css-parser": "2.0.0-alpha.11"
68
+ "@jesscss/css-parser": "2.0.0-alpha.13"
39
69
  },
40
70
  "peerDependencies": {
41
- "parseman": "^0.41.0",
42
- "@jesscss/core": "2.0.0-alpha.11"
71
+ "parseman": "^0.50.5",
72
+ "@jesscss/core": "2.0.0-alpha.13"
43
73
  },
44
74
  "peerDependenciesMeta": {
45
75
  "@jesscss/core": {
@@ -48,9 +78,9 @@
48
78
  },
49
79
  "devDependencies": {
50
80
  "@types/color-name": "^1.1.1",
51
- "parseman": "^0.41.0",
52
- "@jesscss/parser-shared": "0.0.0",
53
- "@jesscss/core": "2.0.0-alpha.11"
81
+ "parseman": "^0.50.5",
82
+ "@jesscss/core": "2.0.0-alpha.13",
83
+ "@jesscss/parser-shared": "2.0.0-alpha.13"
54
84
  },
55
85
  "type": "module",
56
86
  "module": "lib/index.js",
@@ -58,7 +88,7 @@
58
88
  "ci": "pnpm build && pnpm test",
59
89
  "build": "pnpm --filter @jesscss/parser-shared build && pnpm clean && pnpm compile",
60
90
  "clean": "shx rm -rf ./lib tsconfig.tsbuildinfo",
61
- "compile": "tsdown --tsconfig tsconfig.build.json --no-dts && tsc -p tsconfig.build.json --emitDeclarationOnly --noCheck",
91
+ "compile": "node -e \"require('node:fs').rmSync('lib',{recursive:true,force:true})\" && tsdown --tsconfig tsconfig.build.json --no-dts && tsc -p tsconfig.build.json --emitDeclarationOnly --noCheck",
62
92
  "test": "vitest --run --passWithNoTests",
63
93
  "lint:fix": "eslint --fix '**/*.{js,ts}'",
64
94
  "lint": "eslint '**/*.{js,ts}'"