@azerothjs/compiler 0.3.0-alpha.2 → 0.4.0-beta.1
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 +115 -0
- package/dist/codegen.d.ts +45 -0
- package/dist/codegen.d.ts.map +1 -0
- package/dist/codegen.js +279 -0
- package/dist/codegen.js.map +1 -0
- package/dist/compile.d.ts +47 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +209 -0
- package/dist/compile.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -14
- package/dist/index.js.map +1 -1
- package/dist/parser.d.ts +37 -0
- package/dist/parser.d.ts.map +1 -0
- package/dist/parser.js +303 -0
- package/dist/parser.js.map +1 -0
- package/dist/scanner.d.ts +110 -0
- package/dist/scanner.d.ts.map +1 -0
- package/dist/scanner.js +333 -0
- package/dist/scanner.js.map +1 -0
- package/dist/sourcemap.d.ts +64 -0
- package/dist/sourcemap.d.ts.map +1 -0
- package/dist/sourcemap.js +109 -0
- package/dist/sourcemap.js.map +1 -0
- package/dist/types.d.ts +82 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +9 -0
- package/dist/types.js.map +1 -0
- package/dist/vite.d.ts +33 -0
- package/dist/vite.d.ts.map +1 -0
- package/dist/vite.js +65 -0
- package/dist/vite.js.map +1 -0
- package/package.json +32 -9
package/dist/compile.js
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
// Orchestrates the transform of a `.azeroth` module:
|
|
2
|
+
//
|
|
3
|
+
// 1. Walk the source, skipping non-code, to find each top-level markup
|
|
4
|
+
// region (scanner.findMarkupStart).
|
|
5
|
+
// 2. Parse the region into a markup AST (parser.parseMarkup).
|
|
6
|
+
// 3. Generate h() / component-call code (codegen.generate), recompiling any
|
|
7
|
+
// nested markup inside `{ ... }` holes by calling back into the hole
|
|
8
|
+
// transform.
|
|
9
|
+
// 4. Splice the generated code in place of the region; everything else
|
|
10
|
+
// (imports, types, functions) is left byte-for-byte.
|
|
11
|
+
//
|
|
12
|
+
// Finally, if markup was emitted and the module doesn't already import `h`,
|
|
13
|
+
// prepend the import.
|
|
14
|
+
import { findMarkupStart } from "./scanner.js";
|
|
15
|
+
import { parseMarkup } from "./parser.js";
|
|
16
|
+
import { generate, walkComponentTags } from "./codegen.js";
|
|
17
|
+
import { buildLineStarts, locationFor, encodeMappings } from "./sourcemap.js";
|
|
18
|
+
/** Default module the auto-injected imports point at. */
|
|
19
|
+
const RUNTIME_MODULE = '@azerothjs/core';
|
|
20
|
+
/**
|
|
21
|
+
* Built-in components that markup can use without importing - the compiler
|
|
22
|
+
* injects their import from the runtime. User components are not
|
|
23
|
+
* auto-imported (the author imports those explicitly).
|
|
24
|
+
*/
|
|
25
|
+
const BUILTIN_COMPONENTS = new Set([
|
|
26
|
+
'Show', 'For', 'Switch', 'Match', 'Portal', 'Dynamic',
|
|
27
|
+
'Suspense', 'ErrorBoundary', 'Transition', 'Outlet'
|
|
28
|
+
]);
|
|
29
|
+
/**
|
|
30
|
+
* True when the module already imports `name` via a named import.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* alreadyImports("import { h, For } from 'x';", 'For'); // true
|
|
35
|
+
* alreadyImports("import { h } from 'x';", 'Show'); // false
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
function alreadyImports(source, name) {
|
|
39
|
+
return new RegExp(`import\\s*\\{[^}]*\\b${name}\\b[^}]*\\}\\s*from`).test(source);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Compiles a `.azeroth` source string: markup -> h() calls, with the `h`
|
|
43
|
+
* import auto-injected when needed.
|
|
44
|
+
*
|
|
45
|
+
* @param source - The `.azeroth` module source
|
|
46
|
+
*
|
|
47
|
+
* @returns The compiled JS/TS and its source map
|
|
48
|
+
*
|
|
49
|
+
* Without compile: author UI as nested h() calls by hand, wrapping every
|
|
50
|
+
* dynamic hole in a getter yourself:
|
|
51
|
+
*
|
|
52
|
+
* import { h } from '@azerothjs/core';
|
|
53
|
+
* export default () =>
|
|
54
|
+
* h('h1', { }, 'Hello ', () => (name())); // hand-write h() + getters, easy to get wrong
|
|
55
|
+
*
|
|
56
|
+
* With compile: write the markup in a `.azeroth` file and compile() emits the
|
|
57
|
+
* equivalent h() calls (and the `h` import) for you:
|
|
58
|
+
*
|
|
59
|
+
* const { code } = compile('export default () => <h1>Hello {name()}</h1>;');
|
|
60
|
+
* // code -> import { h } from '@azerothjs/core'; ... h('h1', { }, 'Hello ', () => (name()))
|
|
61
|
+
* // write JSX-like markup; the getters and the import are generated
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* const { code } = compile(`
|
|
66
|
+
* export default function Hi() {
|
|
67
|
+
* return <h1>Hello {name()}</h1>;
|
|
68
|
+
* }
|
|
69
|
+
* `);
|
|
70
|
+
* // code becomes:
|
|
71
|
+
* // import { h } from '@azerothjs/core';
|
|
72
|
+
* // export default function Hi() {
|
|
73
|
+
* // return h('h1', { }, 'Hello ', () => (name()));
|
|
74
|
+
* // }
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export function compile(source, filename = 'module.azeroth') {
|
|
78
|
+
// Built-in components referenced anywhere in the file's markup
|
|
79
|
+
// (including nested inside `{ ... }` holes, thanks to the recursion).
|
|
80
|
+
const usedBuiltins = new Set();
|
|
81
|
+
const collect = (node) => walkComponentTags(node, (tag) => {
|
|
82
|
+
if (BUILTIN_COMPONENTS.has(tag)) {
|
|
83
|
+
usedBuiltins.add(tag);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
// String-based transform for `{ ... }` holes (nested markup). Holes are
|
|
87
|
+
// embedded inside a region's generated string, so they don't get their own
|
|
88
|
+
// source-map pieces - the whole region maps to its start, which is plenty
|
|
89
|
+
// for debugging.
|
|
90
|
+
const transformHole = (input) => {
|
|
91
|
+
let result = '';
|
|
92
|
+
let j = 0;
|
|
93
|
+
for (;;) {
|
|
94
|
+
const start = findMarkupStart(input, j);
|
|
95
|
+
if (start === -1) {
|
|
96
|
+
result += input.slice(j);
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
result += input.slice(j, start);
|
|
100
|
+
const { node, end } = parseMarkup(input, start);
|
|
101
|
+
collect(node);
|
|
102
|
+
result += generate(node, transformHole);
|
|
103
|
+
j = end;
|
|
104
|
+
}
|
|
105
|
+
return result;
|
|
106
|
+
};
|
|
107
|
+
// Top-level assembly, tracking pieces for the source map.
|
|
108
|
+
const pieces = [];
|
|
109
|
+
let out = '';
|
|
110
|
+
const push = (text, sourceStart, verbatim) => {
|
|
111
|
+
pieces.push({ outStart: out.length, sourceStart, verbatim });
|
|
112
|
+
out += text;
|
|
113
|
+
};
|
|
114
|
+
let i = 0;
|
|
115
|
+
for (;;) {
|
|
116
|
+
const start = findMarkupStart(source, i);
|
|
117
|
+
if (start === -1) {
|
|
118
|
+
push(source.slice(i), i, true);
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
if (start > i) {
|
|
122
|
+
push(source.slice(i, start), i, true);
|
|
123
|
+
}
|
|
124
|
+
const { node, end } = parseMarkup(source, start);
|
|
125
|
+
collect(node);
|
|
126
|
+
push(generate(node, transformHole), start, false);
|
|
127
|
+
i = end;
|
|
128
|
+
}
|
|
129
|
+
const hasMarkup = pieces.some(p => !p.verbatim);
|
|
130
|
+
if (!hasMarkup) {
|
|
131
|
+
return { code: out, map: null };
|
|
132
|
+
}
|
|
133
|
+
// Auto-inject `h` plus any built-in components the markup used,
|
|
134
|
+
// skipping names the source already imports.
|
|
135
|
+
const names = ['h', ...usedBuiltins].filter(name => !alreadyImports(source, name));
|
|
136
|
+
const prefix = names.length > 0
|
|
137
|
+
? `import { ${names.join(', ')} } from '${RUNTIME_MODULE}';\n`
|
|
138
|
+
: '';
|
|
139
|
+
const code = prefix + out;
|
|
140
|
+
return { code, map: buildSourceMap(code, prefix.length, pieces, source, filename) };
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Finds the piece whose span contains a given OUTPUT (post-`out`) offset.
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```ts
|
|
147
|
+
* const pieces = [
|
|
148
|
+
* { outStart: 0, sourceStart: 0, verbatim: true },
|
|
149
|
+
* { outStart: 10, sourceStart: 10, verbatim: false }
|
|
150
|
+
* ];
|
|
151
|
+
* findPiece(pieces, 12); // the piece at outStart 10
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
function findPiece(pieces, outOffset) {
|
|
155
|
+
let lo = 0;
|
|
156
|
+
let hi = pieces.length - 1;
|
|
157
|
+
while (lo < hi) {
|
|
158
|
+
const mid = (lo + hi + 1) >> 1;
|
|
159
|
+
if (pieces[mid].outStart <= outOffset) {
|
|
160
|
+
lo = mid;
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
hi = mid - 1;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return pieces[lo];
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Builds a line-level source map: one segment per generated line.
|
|
170
|
+
* `prefixLen` accounts for the prepended import line(s), which map
|
|
171
|
+
* to the top of the source.
|
|
172
|
+
*
|
|
173
|
+
* @internal
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```ts
|
|
177
|
+
* const map = buildSourceMap(code, prefix.length, pieces, source, 'm.azeroth');
|
|
178
|
+
* map.version; // 3
|
|
179
|
+
* map.sources; // ['m.azeroth']
|
|
180
|
+
* map.mappings; // 'AAAA;AACA;...' (one segment per generated line)
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
function buildSourceMap(code, prefixLen, pieces, source, filename) {
|
|
184
|
+
const sourceLineStarts = buildLineStarts(source);
|
|
185
|
+
const codeLineStarts = buildLineStarts(code);
|
|
186
|
+
const lines = [];
|
|
187
|
+
for (const codeOffset of codeLineStarts) {
|
|
188
|
+
if (codeOffset < prefixLen) {
|
|
189
|
+
// The injected import line(s) map to the top of source.
|
|
190
|
+
lines.push([{ genColumn: 0, sourceLine: 0, sourceColumn: 0 }]);
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
const outOffset = codeOffset - prefixLen;
|
|
194
|
+
const piece = findPiece(pieces, outOffset);
|
|
195
|
+
const sourceOffset = piece.verbatim
|
|
196
|
+
? piece.sourceStart + (outOffset - piece.outStart)
|
|
197
|
+
: piece.sourceStart;
|
|
198
|
+
const loc = locationFor(sourceOffset, sourceLineStarts);
|
|
199
|
+
lines.push([{ genColumn: 0, sourceLine: loc.line, sourceColumn: loc.column }]);
|
|
200
|
+
}
|
|
201
|
+
return {
|
|
202
|
+
version: 3,
|
|
203
|
+
sources: [filename],
|
|
204
|
+
sourcesContent: [source],
|
|
205
|
+
names: [],
|
|
206
|
+
mappings: encodeMappings(lines)
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
//# sourceMappingURL=compile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile.js","sourceRoot":"","sources":["../src/compile.ts"],"names":[],"mappings":"AAAA,qDAAqD;AACrD,EAAE;AACF,yEAAyE;AACzE,yCAAyC;AACzC,gEAAgE;AAChE,8EAA8E;AAC9E,0EAA0E;AAC1E,kBAAkB;AAClB,yEAAyE;AACzE,0DAA0D;AAC1D,EAAE;AACF,4EAA4E;AAC5E,sBAAsB;AAEtB,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAA2B,MAAM,cAAc,CAAC;AACpF,OAAO,EACH,eAAe,EACf,WAAW,EACX,cAAc,EAGjB,MAAM,gBAAgB,CAAC;AAExB,yDAAyD;AACzD,MAAM,cAAc,GAAG,iBAAiB,CAAC;AAEzC;;;;GAIG;AAC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C;QACV,OAAO,EAAE,CAAC,QAAQ,CAAC;QACnB,cAAc,EAAE,CAAC,MAAM,CAAC;QACxB,KAAK,EAAE,EAAE;QACT,QAAQ,EAAE,cAAc,CAAC,KAAK,CAAC;KAClC,CAAC;AACN,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1,8 @@
|
|
|
1
|
+
export { compile, type CompileResult } from './compile.ts';
|
|
2
|
+
export { CompileError, parseMarkup } from './parser.ts';
|
|
3
|
+
export { findMarkupStart, isWhitespace, isIdentStart, isIdentPart, skipBalanced, skipString, skipTemplate, skipLineComment, skipBlockComment, skipRegex } from './scanner.ts';
|
|
4
|
+
export { generate, walkComponentTags, type ExpressionCompiler } from './codegen.ts';
|
|
5
|
+
export { azeroth, type AzerothPluginOptions } from './vite.ts';
|
|
6
|
+
export { vlqEncode, buildLineStarts, locationFor, encodeMappings, type SourceMapV3, type RawSegment } from './sourcemap.ts';
|
|
7
|
+
export type { Span, MarkupElement, MarkupFragment, MarkupText, MarkupExpression, MarkupChild, MarkupAttribute, MarkupAttributeValue, MarkupRegion } from './types.ts';
|
|
1
8
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EACH,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,SAAS,EACZ,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,KAAK,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACpF,OAAO,EAAE,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAC/D,OAAO,EACH,SAAS,EACT,eAAe,EACf,WAAW,EACX,cAAc,EACd,KAAK,WAAW,EAChB,KAAK,UAAU,EAClB,MAAM,gBAAgB,CAAC;AAExB,YAAY,EACR,IAAI,EACJ,aAAa,EACb,cAAc,EACd,UAAU,EACV,gBAAgB,EAChB,WAAW,EACX,eAAe,EACf,oBAAoB,EACpB,YAAY,EACf,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
// ============================================================================
|
|
3
|
-
// AZEROTHJS — Compiler
|
|
4
|
-
// ============================================================================
|
|
1
|
+
// @azerothjs/compiler
|
|
5
2
|
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
// - Scoped CSS
|
|
11
|
-
// - Vite plugin
|
|
12
|
-
// - HMR support
|
|
13
|
-
// - Source maps
|
|
3
|
+
// Compiles `.azeroth` files - JS/TS modules written with AzerothJS markup (a
|
|
4
|
+
// JSX-style syntax) - into plain modules that call the runtime's h()
|
|
5
|
+
// hyperscript with fine-grained reactive bindings. For example
|
|
6
|
+
// `<h1>Count: {count()}</h1>` becomes `h('h1', {}, 'Count: ', () => (count()))`.
|
|
14
7
|
//
|
|
15
|
-
//
|
|
16
|
-
//
|
|
8
|
+
// The pipeline, in the order it runs (and a good order to read it in):
|
|
9
|
+
// scanner - finds markup regions inside arbitrary JS, skipping
|
|
10
|
+
// strings/templates/comments/regex and detecting expression
|
|
11
|
+
// position
|
|
12
|
+
// parser - markup region -> AST
|
|
13
|
+
// codegen - AST -> h()/component-call source, with reactive wrapping
|
|
14
|
+
// compile - orchestrates scan -> parse -> codegen -> splice
|
|
15
|
+
export { compile } from "./compile.js";
|
|
16
|
+
export { CompileError, parseMarkup } from "./parser.js";
|
|
17
|
+
export { findMarkupStart, isWhitespace, isIdentStart, isIdentPart, skipBalanced, skipString, skipTemplate, skipLineComment, skipBlockComment, skipRegex } from "./scanner.js";
|
|
18
|
+
export { generate, walkComponentTags } from "./codegen.js";
|
|
19
|
+
export { azeroth } from "./vite.js";
|
|
20
|
+
export { vlqEncode, buildLineStarts, locationFor, encodeMappings } from "./sourcemap.js";
|
|
17
21
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,sBAAsB;AACtB,EAAE;AACF,6EAA6E;AAC7E,qEAAqE;AACrE,+DAA+D;AAC/D,iFAAiF;AACjF,EAAE;AACF,uEAAuE;AACvE,kEAAkE;AAClE,yEAAyE;AACzE,wBAAwB;AACxB,oCAAoC;AACpC,wEAAwE;AACxE,+DAA+D;AAE/D,OAAO,EAAE,OAAO,EAAsB,MAAM,cAAc,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EACH,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,SAAS,EACZ,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAA2B,MAAM,cAAc,CAAC;AACpF,OAAO,EAAE,OAAO,EAA6B,MAAM,WAAW,CAAC;AAC/D,OAAO,EACH,SAAS,EACT,eAAe,EACf,WAAW,EACX,cAAc,EAGjB,MAAM,gBAAgB,CAAC"}
|
package/dist/parser.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { MarkupElement, MarkupFragment } from './types.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Thrown when the markup is malformed. Carries the source offset.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* try
|
|
8
|
+
* {
|
|
9
|
+
* parseMarkup('<a></b>', 0); // mismatched closing tag
|
|
10
|
+
* }
|
|
11
|
+
* catch (err)
|
|
12
|
+
* {
|
|
13
|
+
* if (err instanceof CompileError) console.log(err.offset); // source index of the error
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare class CompileError extends Error {
|
|
18
|
+
readonly offset: number;
|
|
19
|
+
constructor(message: string, offset: number);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Parses the markup element/fragment beginning at `start` (the `<`). Returns
|
|
23
|
+
* the AST node and the offset just after it.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* const { node, end } = parseMarkup('<h1>Hi</h1>', 0);
|
|
28
|
+
* node.kind; // 'element'
|
|
29
|
+
* node.tag; // 'h1'
|
|
30
|
+
* end; // 11 (offset just past '</h1>')
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare function parseMarkup(src: string, start: number): {
|
|
34
|
+
node: MarkupElement | MarkupFragment;
|
|
35
|
+
end: number;
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACR,aAAa,EACb,cAAc,EAIjB,MAAM,YAAY,CAAC;AASpB;;;;;;;;;;;;;;GAcG;AACH,qBAAa,YAAa,SAAQ,KAAK;aAEU,MAAM,EAAE,MAAM;gBAA/C,OAAO,EAAE,MAAM,EAAkB,MAAM,EAAE,MAAM;CAK9D;AAsVD;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,aAAa,GAAG,cAAc,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAK7G"}
|
package/dist/parser.js
ADDED
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
// Parses one markup region (an element or fragment) starting at a `<` into the
|
|
2
|
+
// AST from types.ts. Expression holes (`{ ... }`) and attribute expressions
|
|
3
|
+
// are captured as raw source - nested markup inside them is handled later by
|
|
4
|
+
// codegen, which recursively compiles the hole text. That keeps the parser
|
|
5
|
+
// focused purely on markup structure.
|
|
6
|
+
import { isIdentStart, isIdentPart, isWhitespace, skipBalanced, skipString } from "./scanner.js";
|
|
7
|
+
/**
|
|
8
|
+
* Thrown when the markup is malformed. Carries the source offset.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* try
|
|
13
|
+
* {
|
|
14
|
+
* parseMarkup('<a></b>', 0); // mismatched closing tag
|
|
15
|
+
* }
|
|
16
|
+
* catch (err)
|
|
17
|
+
* {
|
|
18
|
+
* if (err instanceof CompileError) console.log(err.offset); // source index of the error
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export class CompileError extends Error {
|
|
23
|
+
offset;
|
|
24
|
+
constructor(message, offset) {
|
|
25
|
+
super(message);
|
|
26
|
+
this.offset = offset;
|
|
27
|
+
this.name = 'CompileError';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
class MarkupParser {
|
|
31
|
+
src;
|
|
32
|
+
pos;
|
|
33
|
+
constructor(src, pos) {
|
|
34
|
+
this.src = src;
|
|
35
|
+
this.pos = pos;
|
|
36
|
+
}
|
|
37
|
+
/** Entry point; `pos` must be at the opening `<`. */
|
|
38
|
+
parse() {
|
|
39
|
+
return this.parseElement();
|
|
40
|
+
}
|
|
41
|
+
peek(offset = 0) {
|
|
42
|
+
return this.src[this.pos + offset] ?? '';
|
|
43
|
+
}
|
|
44
|
+
skipWs() {
|
|
45
|
+
while (this.pos < this.src.length && isWhitespace(this.src[this.pos])) {
|
|
46
|
+
this.pos++;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
expect(ch) {
|
|
50
|
+
if (this.peek() !== ch) {
|
|
51
|
+
throw new CompileError(`Expected '${ch}' but found '${this.peek() || 'EOF'}'`, this.pos);
|
|
52
|
+
}
|
|
53
|
+
this.pos++;
|
|
54
|
+
}
|
|
55
|
+
/** `pos` at `<`. Parses an element or `<>...</>` fragment. */
|
|
56
|
+
parseElement() {
|
|
57
|
+
const start = this.pos;
|
|
58
|
+
this.expect('<');
|
|
59
|
+
// Fragment: `<>`
|
|
60
|
+
if (this.peek() === '>') {
|
|
61
|
+
this.pos++; // past '>'
|
|
62
|
+
const children = this.parseChildren();
|
|
63
|
+
this.expectClosingTag(''); // </>
|
|
64
|
+
return { kind: 'fragment', children, start, end: this.pos };
|
|
65
|
+
}
|
|
66
|
+
const tag = this.readTagName();
|
|
67
|
+
const attributes = this.parseAttributes();
|
|
68
|
+
this.skipWs();
|
|
69
|
+
// Self-closing: `<tag ... />`
|
|
70
|
+
if (this.peek() === '/') {
|
|
71
|
+
this.pos++;
|
|
72
|
+
this.expect('>');
|
|
73
|
+
return {
|
|
74
|
+
kind: 'element',
|
|
75
|
+
tag,
|
|
76
|
+
isComponent: MarkupParser.isComponentTag(tag),
|
|
77
|
+
attributes,
|
|
78
|
+
children: [],
|
|
79
|
+
start,
|
|
80
|
+
end: this.pos
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
this.expect('>');
|
|
84
|
+
const children = this.parseChildren();
|
|
85
|
+
this.expectClosingTag(tag);
|
|
86
|
+
return {
|
|
87
|
+
kind: 'element',
|
|
88
|
+
tag,
|
|
89
|
+
isComponent: MarkupParser.isComponentTag(tag),
|
|
90
|
+
attributes,
|
|
91
|
+
children,
|
|
92
|
+
start,
|
|
93
|
+
end: this.pos
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
static isComponentTag(tag) {
|
|
97
|
+
return /[A-Z]/.test(tag[0] ?? '') || tag.includes('.');
|
|
98
|
+
}
|
|
99
|
+
/** Reads a tag name: identifiers plus `.` (`Foo.Bar`) and `-` (custom elements). */
|
|
100
|
+
readTagName() {
|
|
101
|
+
const start = this.pos;
|
|
102
|
+
if (!isIdentStart(this.peek())) {
|
|
103
|
+
throw new CompileError('Expected a tag name', this.pos);
|
|
104
|
+
}
|
|
105
|
+
this.pos++;
|
|
106
|
+
while (this.pos < this.src.length) {
|
|
107
|
+
const ch = this.src[this.pos];
|
|
108
|
+
if (isIdentPart(ch) || ch === '.' || ch === '-') {
|
|
109
|
+
this.pos++;
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return this.src.slice(start, this.pos);
|
|
116
|
+
}
|
|
117
|
+
parseAttributes() {
|
|
118
|
+
const attrs = [];
|
|
119
|
+
for (;;) {
|
|
120
|
+
this.skipWs();
|
|
121
|
+
const ch = this.peek();
|
|
122
|
+
// End of the opening tag.
|
|
123
|
+
if (ch === '>' || ch === '/' || ch === '') {
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
const attrStart = this.pos;
|
|
127
|
+
// Spread: `{...expr}`
|
|
128
|
+
if (ch === '{') {
|
|
129
|
+
const end = skipBalanced(this.src, this.pos);
|
|
130
|
+
const inner = this.src.slice(this.pos + 1, end - 1).trim();
|
|
131
|
+
this.pos = end;
|
|
132
|
+
const code = inner.startsWith('...') ? inner.slice(3).trim() : inner;
|
|
133
|
+
attrs.push({
|
|
134
|
+
kind: 'attribute',
|
|
135
|
+
name: null,
|
|
136
|
+
value: { kind: 'expression', code },
|
|
137
|
+
spread: true,
|
|
138
|
+
start: attrStart,
|
|
139
|
+
end
|
|
140
|
+
});
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
// Named attribute.
|
|
144
|
+
const name = this.readAttributeName();
|
|
145
|
+
this.skipWs();
|
|
146
|
+
if (this.peek() !== '=') {
|
|
147
|
+
// Bare attribute -> boolean true.
|
|
148
|
+
attrs.push({
|
|
149
|
+
kind: 'attribute',
|
|
150
|
+
name,
|
|
151
|
+
value: { kind: 'none' },
|
|
152
|
+
spread: false,
|
|
153
|
+
start: attrStart,
|
|
154
|
+
end: this.pos
|
|
155
|
+
});
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
this.pos++; // past '='
|
|
159
|
+
this.skipWs();
|
|
160
|
+
const valueChar = this.peek();
|
|
161
|
+
if (valueChar === '{') {
|
|
162
|
+
const end = skipBalanced(this.src, this.pos);
|
|
163
|
+
const code = this.src.slice(this.pos + 1, end - 1).trim();
|
|
164
|
+
this.pos = end;
|
|
165
|
+
attrs.push({
|
|
166
|
+
kind: 'attribute',
|
|
167
|
+
name,
|
|
168
|
+
value: { kind: 'expression', code },
|
|
169
|
+
spread: false,
|
|
170
|
+
start: attrStart,
|
|
171
|
+
end
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
else if (valueChar === '"' || valueChar === '\'') {
|
|
175
|
+
const end = skipString(this.src, this.pos);
|
|
176
|
+
const value = this.src.slice(this.pos + 1, end - 1);
|
|
177
|
+
this.pos = end;
|
|
178
|
+
attrs.push({
|
|
179
|
+
kind: 'attribute',
|
|
180
|
+
name,
|
|
181
|
+
value: { kind: 'static', value },
|
|
182
|
+
spread: false,
|
|
183
|
+
start: attrStart,
|
|
184
|
+
end
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
throw new CompileError(`Expected a value for attribute '${name}'`, this.pos);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return attrs;
|
|
192
|
+
}
|
|
193
|
+
/** Attribute names: identifiers plus `-` and `:` (`data-x`, `aria-label`). */
|
|
194
|
+
readAttributeName() {
|
|
195
|
+
const start = this.pos;
|
|
196
|
+
while (this.pos < this.src.length) {
|
|
197
|
+
const ch = this.src[this.pos];
|
|
198
|
+
if (isIdentPart(ch) || ch === '-' || ch === ':') {
|
|
199
|
+
this.pos++;
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
if (this.pos === start) {
|
|
206
|
+
throw new CompileError('Expected an attribute name', this.pos);
|
|
207
|
+
}
|
|
208
|
+
return this.src.slice(start, this.pos);
|
|
209
|
+
}
|
|
210
|
+
parseChildren() {
|
|
211
|
+
const children = [];
|
|
212
|
+
while (this.pos < this.src.length) {
|
|
213
|
+
// Closing tag -> stop.
|
|
214
|
+
if (this.peek() === '<' && this.peek(1) === '/') {
|
|
215
|
+
break;
|
|
216
|
+
}
|
|
217
|
+
if (this.peek() === '<') {
|
|
218
|
+
children.push(this.parseElement());
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
if (this.peek() === '{') {
|
|
222
|
+
const start = this.pos;
|
|
223
|
+
const end = skipBalanced(this.src, this.pos);
|
|
224
|
+
const code = this.src.slice(this.pos + 1, end - 1);
|
|
225
|
+
this.pos = end;
|
|
226
|
+
// Drop comment-only / empty holes (e.g. `{/* note */}`).
|
|
227
|
+
if (!MarkupParser.isEmptyExpression(code)) {
|
|
228
|
+
children.push({ kind: 'expression', code, start, end });
|
|
229
|
+
}
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
const text = this.readText();
|
|
233
|
+
if (text) {
|
|
234
|
+
children.push(text);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return children;
|
|
238
|
+
}
|
|
239
|
+
/** Reads raw text up to the next `<` or `{`, normalised JSX-style. */
|
|
240
|
+
readText() {
|
|
241
|
+
const start = this.pos;
|
|
242
|
+
while (this.pos < this.src.length && this.peek() !== '<' && this.peek() !== '{') {
|
|
243
|
+
this.pos++;
|
|
244
|
+
}
|
|
245
|
+
const raw = this.src.slice(start, this.pos);
|
|
246
|
+
const value = MarkupParser.normalizeText(raw);
|
|
247
|
+
if (value === '') {
|
|
248
|
+
return null;
|
|
249
|
+
}
|
|
250
|
+
return { kind: 'text', value, start, end: this.pos };
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* JSX-style whitespace handling: collapse runs that are purely formatting
|
|
254
|
+
* (whitespace containing a newline) to a single space, and preserve
|
|
255
|
+
* meaningful same-line spacing like `Count: `.
|
|
256
|
+
*/
|
|
257
|
+
static normalizeText(raw) {
|
|
258
|
+
if (/^\s*$/.test(raw)) {
|
|
259
|
+
return '';
|
|
260
|
+
}
|
|
261
|
+
return raw.replace(/\s*\n\s*/g, ' ');
|
|
262
|
+
}
|
|
263
|
+
/** True when a `{ ... }` hole has no actual expression (only comments/space). */
|
|
264
|
+
static isEmptyExpression(code) {
|
|
265
|
+
const stripped = code
|
|
266
|
+
.replace(/\/\*[\s\S]*?\*\//g, '')
|
|
267
|
+
.replace(/\/\/[^\n]*/g, '')
|
|
268
|
+
.trim();
|
|
269
|
+
return stripped === '';
|
|
270
|
+
}
|
|
271
|
+
/** Consumes `</tag>` (or `</>` when `tag === ''`). */
|
|
272
|
+
expectClosingTag(tag) {
|
|
273
|
+
this.expect('<');
|
|
274
|
+
this.expect('/');
|
|
275
|
+
this.skipWs();
|
|
276
|
+
if (tag !== '') {
|
|
277
|
+
const closing = this.readTagName();
|
|
278
|
+
if (closing !== tag) {
|
|
279
|
+
throw new CompileError(`Mismatched closing tag: expected </${tag}> but found </${closing}>`, this.pos);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
this.skipWs();
|
|
283
|
+
this.expect('>');
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Parses the markup element/fragment beginning at `start` (the `<`). Returns
|
|
288
|
+
* the AST node and the offset just after it.
|
|
289
|
+
*
|
|
290
|
+
* @example
|
|
291
|
+
* ```ts
|
|
292
|
+
* const { node, end } = parseMarkup('<h1>Hi</h1>', 0);
|
|
293
|
+
* node.kind; // 'element'
|
|
294
|
+
* node.tag; // 'h1'
|
|
295
|
+
* end; // 11 (offset just past '</h1>')
|
|
296
|
+
* ```
|
|
297
|
+
*/
|
|
298
|
+
export function parseMarkup(src, start) {
|
|
299
|
+
const parser = new MarkupParser(src, start);
|
|
300
|
+
const node = parser.parse();
|
|
301
|
+
return { node, end: parser.pos };
|
|
302
|
+
}
|
|
303
|
+
//# sourceMappingURL=parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,4EAA4E;AAC5E,6EAA6E;AAC7E,2EAA2E;AAC3E,sCAAsC;AAStC,OAAO,EACH,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,UAAU,EACb,MAAM,cAAc,CAAC;AAEtB;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAO,YAAa,SAAQ,KAAK;IAEU;IAA7C,YAAY,OAAe,EAAkB,MAAc;QAEvD,KAAK,CAAC,OAAO,CAAC,CAAC;QAF0B,WAAM,GAAN,MAAM,CAAQ;QAGvD,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC/B,CAAC;CACJ;AAED,MAAM,YAAY;IAEe;IAAoB;IAAjD,YAA6B,GAAW,EAAS,GAAW;QAA/B,QAAG,GAAH,GAAG,CAAQ;QAAS,QAAG,GAAH,GAAG,CAAQ;IAC3D,CAAC;IAEF,qDAAqD;IAC9C,KAAK;QAER,OAAO,IAAI,CAAC,YAAY,EAAE,CAAC;IAC/B,CAAC;IAEO,IAAI,CAAC,MAAM,GAAG,CAAC;QAEnB,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC;IAC7C,CAAC;IAEO,MAAM;QAEV,OAAO,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,IAAI,YAAY,CAAC,IAAI,CAAC,GAAG,C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