@jesscss/jess-parser 2.0.0-alpha.10
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/LICENSE +21 -0
- package/README.md +122 -0
- package/lib/cst.cjs +14 -0
- package/lib/cst.d.ts +5 -0
- package/lib/cst.js +12 -0
- package/lib/grammar.cjs +99862 -0
- package/lib/grammar.d.ts +386 -0
- package/lib/grammar.js +99858 -0
- package/lib/index.cjs +41 -0
- package/lib/index.d.ts +13 -0
- package/lib/index.js +36 -0
- package/package.json +66 -0
package/lib/index.cjs
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_grammar = require("./grammar.cjs");
|
|
3
|
+
const require_cst = require("./cst.cjs");
|
|
4
|
+
let _jesscss_core_ast = require("@jesscss/core/ast");
|
|
5
|
+
let parseman = require("parseman");
|
|
6
|
+
//#region src/index.ts
|
|
7
|
+
/** Structured failure from the public direct Jess parser. */
|
|
8
|
+
var JessParseError = class extends SyntaxError {
|
|
9
|
+
code = "parse/syntax-error";
|
|
10
|
+
offset;
|
|
11
|
+
expected;
|
|
12
|
+
constructor(offset, expected) {
|
|
13
|
+
const detail = expected.length > 0 ? ` Expected: ${expected.join(", ")}.` : "";
|
|
14
|
+
super(`Jess parser error.${detail}`);
|
|
15
|
+
this.name = "JessParseError";
|
|
16
|
+
this.offset = offset;
|
|
17
|
+
this.expected = expected;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
function isStylesheet(value) {
|
|
21
|
+
return typeof value === "object" && value !== null && "type" in value && value.type === "Stylesheet" && "children" in value && Array.isArray(value.children);
|
|
22
|
+
}
|
|
23
|
+
/** Parse Jess directly into the canonical AST v2 document. */
|
|
24
|
+
function parse(input) {
|
|
25
|
+
const entry = require_grammar.jessAstGrammar.Stylesheet;
|
|
26
|
+
const trivia = require_grammar.jessAstGrammar.whitespace;
|
|
27
|
+
if (entry === void 0 || trivia === void 0) throw new TypeError("Jess AST grammar is missing its public document entry.");
|
|
28
|
+
const result = (0, parseman.run)(entry, input, { trivia });
|
|
29
|
+
if (!result.ok || result.unconsumedFrom !== null || !isStylesheet(result.value)) {
|
|
30
|
+
const offset = result.ok ? result.unconsumedFrom ?? result.span.end : result.span.start;
|
|
31
|
+
const expected = result.expected;
|
|
32
|
+
throw new JessParseError(offset, expected);
|
|
33
|
+
}
|
|
34
|
+
return (0, _jesscss_core_ast.withTriviaMap)((0, _jesscss_core_ast.withSourceSpan)(result.value, result.span), (0, _jesscss_core_ast.createTriviaMapFromParseman)(input, result.triviaMap));
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
exports.JessParseError = JessParseError;
|
|
38
|
+
exports.jessGrammar = require_grammar.jessGrammar;
|
|
39
|
+
exports.parse = parse;
|
|
40
|
+
exports.parseJessCst = require_cst.parseJessCst;
|
|
41
|
+
exports.parseJessDoc = require_cst.parseJessDoc;
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { jessGrammar } from './grammar.js';
|
|
2
|
+
export { parseJessCst, parseJessDoc } from './cst.js';
|
|
3
|
+
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;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
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";
|
|
5
|
+
//#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));
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
export { JessParseError, jessGrammar, parse, parseJessCst, parseJessDoc };
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jesscss/jess-parser",
|
|
3
|
+
"publishConfig": {
|
|
4
|
+
"access": "public"
|
|
5
|
+
},
|
|
6
|
+
"version": "2.0.0-alpha.10",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": "^20.19.0 || >=22.12.0"
|
|
9
|
+
},
|
|
10
|
+
"description": "Jess parser with direct canonical AST parsing and an explicit language-service CST entry",
|
|
11
|
+
"main": "lib/index.cjs",
|
|
12
|
+
"types": "lib/index.d.ts",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./lib/index.d.ts",
|
|
16
|
+
"import": "./lib/index.js",
|
|
17
|
+
"require": "./lib/index.cjs"
|
|
18
|
+
},
|
|
19
|
+
"./cst": {
|
|
20
|
+
"types": "./lib/cst.d.ts",
|
|
21
|
+
"import": "./lib/cst.js",
|
|
22
|
+
"require": "./lib/cst.cjs"
|
|
23
|
+
},
|
|
24
|
+
"./grammar": {
|
|
25
|
+
"types": "./lib/grammar.d.ts",
|
|
26
|
+
"import": "./lib/grammar.js",
|
|
27
|
+
"require": "./lib/grammar.cjs"
|
|
28
|
+
},
|
|
29
|
+
"./package.json": "./package.json"
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"lib"
|
|
33
|
+
],
|
|
34
|
+
"author": "Matthew Dean",
|
|
35
|
+
"license": "MIT",
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"color-name": "~2.0.0",
|
|
38
|
+
"@jesscss/css-parser": "2.0.0-alpha.10"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"parseman": "^0.41.0",
|
|
42
|
+
"@jesscss/core": "2.0.0-alpha.10"
|
|
43
|
+
},
|
|
44
|
+
"peerDependenciesMeta": {
|
|
45
|
+
"@jesscss/core": {
|
|
46
|
+
"optional": true
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@types/color-name": "^1.1.1",
|
|
51
|
+
"parseman": "^0.41.0",
|
|
52
|
+
"@jesscss/core": "2.0.0-alpha.10",
|
|
53
|
+
"@jesscss/parser-shared": "0.0.0"
|
|
54
|
+
},
|
|
55
|
+
"type": "module",
|
|
56
|
+
"module": "lib/index.js",
|
|
57
|
+
"scripts": {
|
|
58
|
+
"ci": "pnpm build && pnpm test",
|
|
59
|
+
"build": "pnpm --filter @jesscss/parser-shared build && pnpm clean && pnpm compile",
|
|
60
|
+
"clean": "shx rm -rf ./lib tsconfig.tsbuildinfo",
|
|
61
|
+
"compile": "tsdown --tsconfig tsconfig.build.json --no-dts && tsc -p tsconfig.build.json --emitDeclarationOnly --noCheck",
|
|
62
|
+
"test": "vitest --run --passWithNoTests",
|
|
63
|
+
"lint:fix": "eslint --fix '**/*.{js,ts}'",
|
|
64
|
+
"lint": "eslint '**/*.{js,ts}'"
|
|
65
|
+
}
|
|
66
|
+
}
|