@tylix/compiler 0.5.1 → 0.6.0

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.
@@ -1,8 +1,25 @@
1
1
  import { generateTemplateExpression } from './generateTemplateExpression.js'
2
-
3
- const EVENT_ATTR_PREFIX = /^on(click|input|change|submit)$/i
2
+ import { paramNames } from './jsGlobals.js'
3
+
4
+ // Any attribute named on<event> on a plain HTML element is an event
5
+ // listener: onclick, onkeydown, onblur, onmouseenter, ondblclick,
6
+ // onscroll, onsubmit, oninput, oncontextmenu, ... (case-insensitive,
7
+ // so onClick works too). Capitalized component tags handle their own
8
+ // onXxx callback props separately in compileElement.
9
+ const EVENT_ATTR_PREFIX = /^on[a-z]+$/i
4
10
  const COMPONENT_TAG_PATTERN = /^[A-Z]/
5
11
 
12
+ // A handler whose expression is one of these node types is a function
13
+ // VALUE that gets called with the event: onclick="{{ save }}",
14
+ // "{{ Auth.logout }}", "{{ e => doIt(e.target.value) }}". Anything
15
+ // else is a STATEMENT run when the event fires: "{{ count++ }}",
16
+ // "{{ save(item) }}", "{{ ok and save() }}", "{{ open ? close() : open() }}".
17
+ const FUNCTION_VALUED = new Set([
18
+ 'Identifier',
19
+ 'MemberExpression',
20
+ 'ArrowFunctionExpression',
21
+ ])
22
+
6
23
  const SVG_NS = 'http://www.w3.org/2000/svg'
7
24
 
8
25
  let nodeCounter = 0
@@ -66,6 +83,7 @@ function compileNode(node, lines, scope, inSvg = false) {
66
83
 
67
84
  throw new Error(`generateTemplate: unknown node type "${node.type}"`)
68
85
  }
86
+
69
87
  // Renders node.children into a local fragment and returns the lines
70
88
  // needed to build it plus the fragment's own variable name, without
71
89
  // touching the caller's `lines` array directly (used inside effect
@@ -79,18 +97,46 @@ function compileChildrenIntoFragment(children, scope, fragVar, inSvg = false) {
79
97
  return childLines
80
98
  }
81
99
 
100
+ function emitBranch(lines, children, scope, inSvg, indent) {
101
+ compileChildrenIntoFragment(children, scope, 'frag', inSvg).forEach((l) =>
102
+ lines.push(`${indent}${l}`),
103
+ )
104
+ }
105
+
82
106
  // Conditional rendering with no VDOM: an anchor comment node marks
83
107
  // the block's position; on first run (before the anchor is even
84
108
  // attached to the real DOM by the caller) content builds into the
85
109
  // same fragment that holds the anchor. On every later run (state
86
110
  // changed), previous nodes are removed and new ones inserted right
87
- // after the anchor in the live DOM.
111
+ // after the anchor in the live DOM. `{{#else}}` / `{{#else if}}`
112
+ // branches render into the same slot when the condition is false.
88
113
  function compileIf(node, lines, scope, inSvg = false) {
89
114
  const anchorVar = nextVar('ifAnchor')
90
115
  const containerVar = nextVar('ifContainer')
91
116
  const nodesVar = nextVar('ifNodes')
92
117
  const initialVar = nextVar('ifInitial')
93
- const condExpr = generateTemplateExpression(node.condition, scope)
118
+
119
+ // `{{#else if}}` chains (and an {{#else}} holding nothing but one
120
+ // {{#if}}, which means the same thing) are flattened into a single
121
+ // if / else if / else so the whole chain is ONE effect. Nesting
122
+ // them would leave stale effects from replaced branches subscribed
123
+ // to the same state.
124
+ const branches = []
125
+ let current = node
126
+ let finalElse = null
127
+ while (true) {
128
+ branches.push({
129
+ cond: generateTemplateExpression(current.condition, scope),
130
+ children: current.children,
131
+ })
132
+ const rest = current.elseChildren
133
+ if (rest && rest.length === 1 && rest[0].type === 'If') {
134
+ current = rest[0]
135
+ continue
136
+ }
137
+ finalElse = rest
138
+ break
139
+ }
94
140
 
95
141
  lines.push(`const ${anchorVar} = document.createComment("if");`)
96
142
  lines.push(`const ${containerVar} = document.createDocumentFragment();`)
@@ -100,19 +146,21 @@ function compileIf(node, lines, scope, inSvg = false) {
100
146
  lines.push(`effect(() => {`)
101
147
  lines.push(` for (const n of ${nodesVar}) n.remove();`)
102
148
  lines.push(` ${nodesVar} = [];`)
103
- lines.push(` if (${condExpr}) {`)
104
- lines.push(` const frag = document.createDocumentFragment();`)
105
- const childLines = compileChildrenIntoFragment(
106
- node.children,
107
- scope,
108
- 'frag',
109
- inSvg,
110
- )
111
- childLines.forEach((l) => lines.push(` ${l}`))
112
- lines.push(` ${nodesVar} = Array.from(frag.childNodes);`)
149
+ lines.push(` const frag = document.createDocumentFragment();`)
150
+ branches.forEach((b, i) => {
151
+ lines.push(i === 0 ? ` if (${b.cond}) {` : ` } else if (${b.cond}) {`)
152
+ emitBranch(lines, b.children, scope, inSvg, ' ')
153
+ })
154
+ if (finalElse) {
155
+ lines.push(` } else {`)
156
+ emitBranch(lines, finalElse, scope, inSvg, ' ')
157
+ }
158
+ lines.push(` }`)
159
+ lines.push(` ${nodesVar} = Array.from(frag.childNodes);`)
160
+ lines.push(` if (${nodesVar}.length > 0) {`)
113
161
  lines.push(` if (${initialVar}) { ${containerVar}.appendChild(frag); }`)
114
162
  lines.push(
115
- ` else { ${anchorVar}.parentNode.insertBefore(frag, ${anchorVar}.nextSibling); }`,
163
+ ` else if (${anchorVar}.parentNode) { ${anchorVar}.parentNode.insertBefore(frag, ${anchorVar}.nextSibling); }`,
116
164
  )
117
165
  lines.push(` }`)
118
166
  lines.push(` ${initialVar} = false;`)
@@ -121,13 +169,23 @@ function compileIf(node, lines, scope, inSvg = false) {
121
169
  return containerVar
122
170
  }
123
171
 
172
+ // {{#each item in items}}, {{#each item, i in items}},
173
+ // {{#each [k, v] in Object.entries(o)}}, {{#each { id } in rows}}.
174
+ // `{{#else}}` renders when the list is empty.
124
175
  function compileEach(node, lines, scope, inSvg = false) {
125
176
  const anchorVar = nextVar('eachAnchor')
126
177
  const containerVar = nextVar('eachContainer')
127
178
  const nodesVar = nextVar('eachNodes')
128
179
  const initialVar = nextVar('eachInitial')
129
180
  const iterableExpr = generateTemplateExpression(node.iterable, scope)
130
- const innerScope = new Set([...scope, node.itemName])
181
+ const innerScope = new Set([
182
+ ...scope,
183
+ ...paramNames([node.itemName]),
184
+ ...(node.indexName ? [node.indexName] : []),
185
+ ])
186
+ const hasElse = !!node.elseChildren
187
+ const listVar = nextVar('eachList')
188
+ const indexVar = nextVar('eachIndex')
131
189
 
132
190
  lines.push(`const ${anchorVar} = document.createComment("each");`)
133
191
  lines.push(`const ${containerVar} = document.createDocumentFragment();`)
@@ -137,25 +195,36 @@ function compileEach(node, lines, scope, inSvg = false) {
137
195
  lines.push(`effect(() => {`)
138
196
  lines.push(` for (const n of ${nodesVar}) n.remove();`)
139
197
  lines.push(` const frag = document.createDocumentFragment();`)
140
- lines.push(` for (const ${node.itemName} of ${iterableExpr}) {`)
141
- const childLines = compileChildrenIntoFragment(
142
- node.children,
143
- innerScope,
144
- 'frag',
145
- inSvg,
198
+ if (hasElse) {
199
+ lines.push(` const ${listVar} = Array.from(${iterableExpr} ?? []);`)
200
+ }
201
+ if (node.indexName) lines.push(` let ${indexVar} = 0;`)
202
+ lines.push(
203
+ ` for (const ${node.itemName} of ${hasElse ? listVar : iterableExpr}) {`,
146
204
  )
147
- childLines.forEach((l) => lines.push(` ${l}`))
205
+ if (node.indexName) {
206
+ lines.push(` const ${node.indexName} = ${indexVar}++;`)
207
+ }
208
+ emitBranch(lines, node.children, innerScope, inSvg, ' ')
148
209
  lines.push(` }`)
210
+ if (hasElse) {
211
+ lines.push(` if (${listVar}.length === 0) {`)
212
+ emitBranch(lines, node.elseChildren, scope, inSvg, ' ')
213
+ lines.push(` }`)
214
+ }
149
215
  lines.push(` ${nodesVar} = Array.from(frag.childNodes);`)
150
- lines.push(` if (${initialVar}) { ${containerVar}.appendChild(frag); }`)
216
+ lines.push(` if (${nodesVar}.length > 0) {`)
217
+ lines.push(` if (${initialVar}) { ${containerVar}.appendChild(frag); }`)
151
218
  lines.push(
152
- ` else { ${anchorVar}.parentNode.insertBefore(frag, ${anchorVar}.nextSibling); }`,
219
+ ` else if (${anchorVar}.parentNode) { ${anchorVar}.parentNode.insertBefore(frag, ${anchorVar}.nextSibling); }`,
153
220
  )
221
+ lines.push(` }`)
154
222
  lines.push(` ${initialVar} = false;`)
155
223
  lines.push(`});`)
156
224
 
157
225
  return containerVar
158
226
  }
227
+
159
228
  function isComponentTag(tag) {
160
229
  return COMPONENT_TAG_PATTERN.test(tag)
161
230
  }
@@ -165,25 +234,26 @@ function compileElement(node, lines, scope, inSvg = false) {
165
234
  const varName = nextVar('component')
166
235
  const tagLiteral = JSON.stringify(node.tag)
167
236
 
168
- const propEntries = node.attributes.map((attr) => {
169
- let expr
170
- if (attr.dynamic) {
171
- expr = generateTemplateExpression(attr.value, scope)
172
- // Callback props (onXxx="{{ methodName }}") pass a bare
173
- // instance-method reference. `generateTemplateExpression`
174
- // turns `methodName` into `instance.methodName`, but handing
175
- // that off as a plain value loses its `this` binding the
176
- // moment the child calls it. Bind it here, while we still
177
- // have `instance` in scope.
178
- if (/^on[A-Z]/.test(attr.name) && attr.value.type === 'Identifier') {
179
- expr = `(${expr}).bind(instance)`
180
- }
181
- } else {
182
- expr = JSON.stringify(attr.value)
183
- }
184
- return `${JSON.stringify(attr.name)}: ${expr}`
185
- })
186
- const propsExpr = `{ ${propEntries.join(', ')} }`
237
+ const propEntries = node.attributes.map((attr) => {
238
+ const key = JSON.stringify(attr.name)
239
+ if (!attr.dynamic) return `${key}: ${JSON.stringify(attr.value)}`
240
+
241
+ let expr = generateTemplateExpression(attr.value, scope)
242
+
243
+ // Callback props (onXxx="{{ methodName }}") are plain values. A bare
244
+ // instance-method reference loses its `this` the moment the child
245
+ // calls it, so bind it here while `instance` is still in scope.
246
+ if (/^on[A-Z]/.test(attr.name)) {
247
+ if (attr.value.type === 'Identifier') expr = `(${expr}).bind(instance)`
248
+ return `${key}: ${expr}`
249
+ }
250
+
251
+ // Everything else is a lazy getter: the child reads it inside its
252
+ // own effects, so `<Child value="{{ count }}">` stays live instead
253
+ // of being a snapshot taken at mount().
254
+ return `get ${key}() { return ${expr}; }`
255
+ })
256
+ const propsExpr = `{ ${propEntries.join(', ')} }`
187
257
 
188
258
  lines.push(`let ${varName};`)
189
259
  lines.push(`if (components[${tagLiteral}]) {`)
@@ -232,6 +302,7 @@ function compileElement(node, lines, scope, inSvg = false) {
232
302
 
233
303
  return varName
234
304
  }
305
+
235
306
  // Attributes that reflect live user-editable DOM state -- setting
236
307
  // them via setAttribute() only seeds the *initial* value; once the
237
308
  // user interacts with the control, the live property diverges from
@@ -270,21 +341,21 @@ function compileAttribute(elVar, tag, attr, lines, scope) {
270
341
  // bare "event" -- both are treated as the same local so neither
271
342
  // gets mistakenly prefixed with "instance.".
272
343
  const scopeWithEvent = new Set([...scope, '$event', 'event'])
344
+ const expr = generateTemplateExpression(attr.value, scopeWithEvent)
273
345
 
274
- if (
275
- attr.value.type === 'CallExpression' ||
276
- attr.value.type === 'AssignmentExpression'
277
- ) {
278
- const expr = generateTemplateExpression(attr.value, scopeWithEvent)
346
+ if (FUNCTION_VALUED.has(attr.value.type)) {
347
+ // Function value: call it with the event.
279
348
  lines.push(
280
- `${elVar}.addEventListener(${JSON.stringify(eventName)}, ($event) => { const event = $event; ${expr}; });`,
349
+ `${elVar}.addEventListener(${JSON.stringify(eventName)}, ($event) => { const event = $event; ${expr}($event); });`,
281
350
  )
282
351
  return
283
352
  }
284
353
 
285
- const expr = generateTemplateExpression(attr.value, scopeWithEvent)
354
+ // Statement: run it when the event fires. Handlers that contain
355
+ // `await` become async arrows.
356
+ const asyncPrefix = /\bawait\b/.test(expr) ? 'async ' : ''
286
357
  lines.push(
287
- `${elVar}.addEventListener(${JSON.stringify(eventName)}, ($event) => { const event = $event; ${expr}($event); });`,
358
+ `${elVar}.addEventListener(${JSON.stringify(eventName)}, ${asyncPrefix}($event) => { const event = $event; ${expr}; });`,
288
359
  )
289
360
  return
290
361
  }
@@ -317,4 +388,4 @@ function compileAttribute(elVar, tag, attr, lines, scope) {
317
388
  lines.push(
318
389
  `${elVar}.setAttribute(${JSON.stringify(attr.name)}, ${JSON.stringify(attr.value)});`,
319
390
  )
320
- }
391
+ }
@@ -1,40 +1,10 @@
1
1
  import { generateExpression } from './generateExpression.js'
2
+ import { JS_GLOBALS, paramNames } from './jsGlobals.js'
2
3
 
3
- // Plain JS globals that templates may use directly. Everything else
4
- // that isn't a local (each variable, arrow param, $event) is treated
5
- // as page state/capability and prefixed with "instance.".
6
- const JS_GLOBALS = new Set([
7
- 'null',
8
- 'true',
9
- 'false',
10
- 'undefined',
11
- 'NaN',
12
- 'Infinity',
13
- 'Math',
14
- 'JSON',
15
- 'Date',
16
- 'Number',
17
- 'String',
18
- 'Boolean',
19
- 'Array',
20
- 'Object',
21
- 'Set',
22
- 'Map',
23
- 'Intl',
24
- 'Promise',
25
- 'RegExp',
26
- 'Symbol',
27
- 'Error',
28
- 'URL',
29
- 'parseInt',
30
- 'parseFloat',
31
- 'isNaN',
32
- 'isFinite',
33
- 'encodeURIComponent',
34
- 'decodeURIComponent',
35
- 'console',
36
- 'window',
37
- ])
4
+ // JS_GLOBALS (see jsGlobals.js) lists the plain JS/browser globals that
5
+ // templates may use directly. Everything else that isn't a local (each
6
+ // variable, arrow param, $event) is treated as page state/capability
7
+ // and prefixed with "instance.".
38
8
 
39
9
  function escapeTemplateLiteralText(text) {
40
10
  return text
@@ -84,15 +54,18 @@ export function generateTemplateExpression(node, scope = new Set()) {
84
54
  return `(${unaryPrefix(node.operator)}${generateTemplateExpression(node.argument, scope)})`
85
55
  }
86
56
 
87
- // Only valid inside an `async` arrow (`{{ async () => await ... }}`);
88
- // a bare `{{ await x }}` would land in a non-async render effect and
89
- // fail when the generated code is loaded.
57
+ // Only valid inside an `async` arrow (`{{ async () => await ... }}`)
58
+ // or an event handler (which is made async automatically when it
59
+ // contains `await`); a bare `{{ await x }}` in a text/attribute
60
+ // binding would land in a non-async render effect.
90
61
  if (node.type === 'AwaitExpression') {
91
62
  return `(await ${generateTemplateExpression(node.argument, scope)})`
92
63
  }
93
64
 
65
+ // Parenthesized so `ok and count++` -> `(ok && (count = ...))` is
66
+ // valid JS rather than an assignment on the right of `&&`.
94
67
  if (node.type === 'AssignmentExpression') {
95
- return `${generateTemplateExpression(node.target, scope)} = ${generateTemplateExpression(node.value, scope)}`
68
+ return `(${generateTemplateExpression(node.target, scope)} = ${generateTemplateExpression(node.value, scope)})`
96
69
  }
97
70
 
98
71
  if (node.type === 'CallExpression') {
@@ -109,13 +82,23 @@ export function generateTemplateExpression(node, scope = new Set()) {
109
82
  return `new ${generateTemplateExpression(node.callee, scope)}(${args})`
110
83
  }
111
84
 
112
- // (a, b) => expr -- params become locals for the body, so they are
113
- // referenced bare instead of being prefixed with "instance.". The
114
- // whole function is parenthesized so it is safe both as a call
115
- // argument and as an event handler that gets invoked immediately.
85
+ // (a, b = 1) => expr -- params become locals for the body, so they
86
+ // are referenced bare instead of being prefixed with "instance.".
87
+ // Params may be destructuring patterns ("[k, v]", "{ id }") or rest
88
+ // params ("...args"); paramNames() extracts the names they bind.
89
+ // Defaults are evaluated in the arrow's own scope. The whole
90
+ // function is parenthesized so it is safe both as a call argument
91
+ // and as an event handler that gets invoked immediately.
116
92
  if (node.type === 'ArrowFunctionExpression') {
117
- const innerScope = new Set([...scope, ...node.params])
118
- const params = node.params.join(', ')
93
+ const innerScope = new Set([...scope, ...paramNames(node.params)])
94
+ const defaults = node.paramDefaults ?? []
95
+ const params = node.params
96
+ .map((name, i) =>
97
+ defaults[i]
98
+ ? `${name} = ${generateTemplateExpression(defaults[i], innerScope)}`
99
+ : name,
100
+ )
101
+ .join(', ')
119
102
  const body = generateTemplateExpression(node.body, innerScope)
120
103
  const asyncPrefix = node.isAsync ? 'async ' : ''
121
104
  return `(${asyncPrefix}(${params}) => ${body})`
@@ -132,11 +115,18 @@ export function generateTemplateExpression(node, scope = new Set()) {
132
115
  // when it ends up as an arrow function body: x => ({ ... })
133
116
  if (node.type === 'ObjectExpression') {
134
117
  const properties = node.properties
135
- .map((p) =>
136
- p.spread
137
- ? `...${generateTemplateExpression(p.value, scope)}`
138
- : `${JSON.stringify(p.key)}: ${generateTemplateExpression(p.value, scope)}`,
139
- )
118
+ .map((p) => {
119
+ if (p.spread) return `...${generateTemplateExpression(p.value, scope)}`
120
+ if (p.method) {
121
+ throw new Error(
122
+ 'Method shorthand ({ fn() {} }) is only allowed in script code, not in template expressions',
123
+ )
124
+ }
125
+ const keySrc = p.keyExpr
126
+ ? `[${generateTemplateExpression(p.keyExpr, scope)}]`
127
+ : JSON.stringify(p.key)
128
+ return `${keySrc}: ${generateTemplateExpression(p.value, scope)}`
129
+ })
140
130
  .join(', ')
141
131
  return `({ ${properties} })`
142
132
  }
@@ -0,0 +1,151 @@
1
+ // Single source of truth for plain JS/browser globals that templates may
2
+ // use bare. Everything else (that isn't a local) is page state/props/
3
+ // capability and gets "instance." (or "this." in the virtual .ts).
4
+ //
5
+ // Intentionally NOT listed, because they are common field or capability
6
+ // names: status, name, location, history, event, open, close, print, top,
7
+ // length, parent, screen, Notification, Storage, Request, Response,
8
+ // Image, File, Event, Audio. Use window.location, window.history, etc.
9
+
10
+ export const JS_GLOBALS = new Set([
11
+ // values
12
+ 'null',
13
+ 'true',
14
+ 'false',
15
+ 'undefined',
16
+ 'NaN',
17
+ 'Infinity',
18
+ 'globalThis',
19
+
20
+ // environment
21
+ 'console',
22
+ 'window',
23
+ 'document',
24
+ 'navigator',
25
+ 'performance',
26
+ 'crypto',
27
+ 'localStorage',
28
+ 'sessionStorage',
29
+ 'matchMedia',
30
+ 'getComputedStyle',
31
+ 'scrollTo',
32
+ 'scrollBy',
33
+
34
+ // dialogs
35
+ 'alert',
36
+ 'confirm',
37
+ 'prompt',
38
+
39
+ // timers
40
+ 'setTimeout',
41
+ 'clearTimeout',
42
+ 'setInterval',
43
+ 'clearInterval',
44
+ 'requestAnimationFrame',
45
+ 'cancelAnimationFrame',
46
+ 'requestIdleCallback',
47
+ 'cancelIdleCallback',
48
+ 'queueMicrotask',
49
+
50
+ // network
51
+ 'fetch',
52
+ 'FormData',
53
+ 'URL',
54
+ 'URLSearchParams',
55
+ 'AbortController',
56
+ 'AbortSignal',
57
+ 'Headers',
58
+ 'WebSocket',
59
+ 'EventSource',
60
+ 'XMLHttpRequest',
61
+ 'BroadcastChannel',
62
+ 'Worker',
63
+
64
+ // core objects
65
+ 'Math',
66
+ 'JSON',
67
+ 'Date',
68
+ 'Number',
69
+ 'String',
70
+ 'Boolean',
71
+ 'Array',
72
+ 'Object',
73
+ 'Set',
74
+ 'Map',
75
+ 'WeakSet',
76
+ 'WeakMap',
77
+ 'WeakRef',
78
+ 'Promise',
79
+ 'RegExp',
80
+ 'Symbol',
81
+ 'BigInt',
82
+ 'Reflect',
83
+ 'Proxy',
84
+ 'Intl',
85
+ 'Atomics',
86
+
87
+ // errors
88
+ 'Error',
89
+ 'TypeError',
90
+ 'RangeError',
91
+ 'SyntaxError',
92
+ 'ReferenceError',
93
+ 'URIError',
94
+ 'EvalError',
95
+ 'AggregateError',
96
+
97
+ // binary / files
98
+ 'Blob',
99
+ 'FileReader',
100
+ 'ArrayBuffer',
101
+ 'DataView',
102
+ 'TextEncoder',
103
+ 'TextDecoder',
104
+ 'Int8Array',
105
+ 'Uint8Array',
106
+ 'Uint8ClampedArray',
107
+ 'Int16Array',
108
+ 'Uint16Array',
109
+ 'Int32Array',
110
+ 'Uint32Array',
111
+ 'Float32Array',
112
+ 'Float64Array',
113
+ 'BigInt64Array',
114
+
115
+ // DOM types
116
+ 'HTMLElement',
117
+ 'Element',
118
+ 'Node',
119
+ 'NodeList',
120
+ 'DOMParser',
121
+ 'CustomEvent',
122
+ 'KeyboardEvent',
123
+ 'MouseEvent',
124
+ 'MutationObserver',
125
+ 'IntersectionObserver',
126
+ 'ResizeObserver',
127
+ 'CSS',
128
+
129
+ // functions
130
+ 'parseInt',
131
+ 'parseFloat',
132
+ 'isNaN',
133
+ 'isFinite',
134
+ 'structuredClone',
135
+ 'encodeURIComponent',
136
+ 'decodeURIComponent',
137
+ 'encodeURI',
138
+ 'decodeURI',
139
+ 'btoa',
140
+ 'atob',
141
+ 'reportError',
142
+ ])
143
+
144
+ // Arrow params are stored as source strings ("x", "[k, v]", "{ id }",
145
+ // "...args"). This returns the names those params actually bind, so
146
+ // they can be treated as locals inside the arrow body.
147
+ export function paramNames(params) {
148
+ return params.flatMap((p) =>
149
+ /^[A-Za-z_$][\w$]*$/.test(p) ? [p] : (p.match(/[A-Za-z_$][\w$]*/g) ?? []),
150
+ )
151
+ }
@@ -5,7 +5,7 @@ import { Parser } from './parser/Parser.js'
5
5
  import { generatePage } from './codegen/generatePage.js'
6
6
  import { generateTemplate } from './codegen/generateTemplate.js'
7
7
  import { reactive, effect } from './runtime/reactive.js'
8
- import { useApi } from '../../core/src/runtime/useApi.js'
8
+ import { useApi } from './runtime/useApi.js'
9
9
 
10
10
  /**
11
11
  * Compiles raw .tyx source into a mountable component descriptor.
@@ -51,4 +51,4 @@ export function compileComponent(source, className = 'Component') {
51
51
  return { node, instance }
52
52
  },
53
53
  }
54
- }
54
+ }