prunelle 0.0.0-stage → 0.2.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.
Files changed (181) hide show
  1. package/llms.txt +148 -0
  2. package/package.json +53 -4
  3. package/src/ambient.d.ts +6 -0
  4. package/src/attrs.ts +35 -0
  5. package/src/build/bundle.ts +613 -0
  6. package/src/build/carry.ts +57 -0
  7. package/src/build/client-entries.ts +107 -0
  8. package/src/build/client-plugin.ts +169 -0
  9. package/src/build/client-prune.ts +118 -0
  10. package/src/build/compile.ts +128 -0
  11. package/src/build/files.ts +156 -0
  12. package/src/build/first-load.ts +164 -0
  13. package/src/build/graph.ts +247 -0
  14. package/src/build/index.ts +614 -0
  15. package/src/build/is-inside.ts +12 -0
  16. package/src/build/islands.ts +641 -0
  17. package/src/build/manifest.ts +281 -0
  18. package/src/build/output.ts +84 -0
  19. package/src/build/plugin-host.ts +220 -0
  20. package/src/build/precompress.ts +139 -0
  21. package/src/build/prerender.ts +150 -0
  22. package/src/build/render-rules.ts +205 -0
  23. package/src/build/report.ts +247 -0
  24. package/src/build/resolve.ts +50 -0
  25. package/src/build/routes.ts +338 -0
  26. package/src/build/server-entry.ts +38 -0
  27. package/src/build/static.ts +163 -0
  28. package/src/build/status-pages.ts +127 -0
  29. package/src/cli/check-forms.ts +654 -0
  30. package/src/cli/check-links.ts +619 -0
  31. package/src/cli/check.ts +367 -0
  32. package/src/cli/commands.ts +265 -0
  33. package/src/cli/index.ts +70 -0
  34. package/src/cli/inspect.ts +335 -0
  35. package/src/cli/new.ts +41 -0
  36. package/src/cli/upgrade-names.ts +209 -0
  37. package/src/cli/upgrade.ts +354 -0
  38. package/src/compiler/analyze.ts +618 -0
  39. package/src/compiler/ast.ts +82 -0
  40. package/src/compiler/browser-globals.ts +127 -0
  41. package/src/compiler/compliance-rgaa.ts +502 -0
  42. package/src/compiler/compliance.ts +497 -0
  43. package/src/compiler/data-keys.ts +295 -0
  44. package/src/compiler/dom-attrs.ts +379 -0
  45. package/src/compiler/dom.ts +566 -0
  46. package/src/compiler/emit.ts +131 -0
  47. package/src/compiler/expr-context.ts +408 -0
  48. package/src/compiler/index.ts +8 -0
  49. package/src/compiler/interactivity.ts +366 -0
  50. package/src/compiler/mistakes.ts +499 -0
  51. package/src/compiler/node-env.ts +50 -0
  52. package/src/compiler/patch.ts +97 -0
  53. package/src/compiler/props.ts +460 -0
  54. package/src/compiler/scope.ts +568 -0
  55. package/src/compiler/server-only.ts +326 -0
  56. package/src/compiler/shared.ts +369 -0
  57. package/src/compiler/signal-reads.ts +242 -0
  58. package/src/compiler/slots.ts +227 -0
  59. package/src/compiler/ssr-helpers.ts +555 -0
  60. package/src/compiler/ssr-island.ts +90 -0
  61. package/src/compiler/ssr-prunelle-tags.ts +56 -0
  62. package/src/compiler/ssr.ts +491 -0
  63. package/src/context.ts +165 -0
  64. package/src/dev/child.ts +30 -0
  65. package/src/dev/index.ts +208 -0
  66. package/src/dev/modules.ts +68 -0
  67. package/src/dev/protocol.ts +21 -0
  68. package/src/dev/queue.ts +79 -0
  69. package/src/dev/reload.ts +157 -0
  70. package/src/dev/supervisor.ts +187 -0
  71. package/src/dev/watchers.ts +215 -0
  72. package/src/dom/action.ts +164 -0
  73. package/src/dom/attrs.ts +72 -0
  74. package/src/dom/claim.ts +120 -0
  75. package/src/dom/extras.ts +562 -0
  76. package/src/dom/index.ts +289 -0
  77. package/src/dom/island.ts +284 -0
  78. package/src/dom/loop.ts +450 -0
  79. package/src/dom/revive.ts +36 -0
  80. package/src/index.ts +22 -0
  81. package/src/jsx-runtime.ts +566 -0
  82. package/src/plugins/config.ts +86 -0
  83. package/src/plugins/context.ts +66 -0
  84. package/src/plugins/index.ts +14 -0
  85. package/src/plugins/load.ts +70 -0
  86. package/src/plugins/order.ts +111 -0
  87. package/src/plugins/public.ts +12 -0
  88. package/src/plugins/requires.ts +47 -0
  89. package/src/plugins/services.ts +35 -0
  90. package/src/plugins/types.ts +242 -0
  91. package/src/reactivity/graph.ts +249 -0
  92. package/src/reactivity/index.ts +533 -0
  93. package/src/reactivity/selector.ts +51 -0
  94. package/src/reactivity/store.ts +208 -0
  95. package/src/server/action-protect.ts +186 -0
  96. package/src/server/action-registry.ts +78 -0
  97. package/src/server/action.ts +498 -0
  98. package/src/server/app-entry.ts +23 -0
  99. package/src/server/assets.ts +136 -0
  100. package/src/server/compress.ts +560 -0
  101. package/src/server/consent.ts +253 -0
  102. package/src/server/cookies.ts +139 -0
  103. package/src/server/document.ts +271 -0
  104. package/src/server/env.ts +33 -0
  105. package/src/server/errors.ts +382 -0
  106. package/src/server/form-schema.ts +343 -0
  107. package/src/server/health.ts +244 -0
  108. package/src/server/http.ts +508 -0
  109. package/src/server/index.ts +687 -0
  110. package/src/server/lifecycle.ts +75 -0
  111. package/src/server/loader.ts +118 -0
  112. package/src/server/page.ts +107 -0
  113. package/src/server/param-matchers.ts +112 -0
  114. package/src/server/plugin-host.ts +256 -0
  115. package/src/server/prerendered.ts +71 -0
  116. package/src/server/public.ts +19 -0
  117. package/src/server/rate-limit.ts +133 -0
  118. package/src/server/region.ts +96 -0
  119. package/src/server/request-body.ts +27 -0
  120. package/src/server/request-path.ts +73 -0
  121. package/src/server/request-scope.ts +22 -0
  122. package/src/server/route-table.ts +82 -0
  123. package/src/server/router.ts +261 -0
  124. package/src/server/routing.ts +377 -0
  125. package/src/server/security.ts +472 -0
  126. package/src/server/serve-handlers.ts +83 -0
  127. package/src/server/served-file.ts +128 -0
  128. package/src/server/standard-schema.ts +87 -0
  129. package/src/server/start.ts +99 -0
  130. package/src/server/static-dir.ts +167 -0
  131. package/src/server/stream.ts +192 -0
  132. package/src/ssr/context.ts +350 -0
  133. package/src/ssr/index.ts +596 -0
  134. package/src/ssr/navigation.ts +96 -0
  135. package/src/ssr/region.ts +171 -0
  136. package/src/style.ts +33 -0
  137. package/src/test/browser.ts +192 -0
  138. package/src/test/index.ts +191 -0
  139. package/src/unrenderable.ts +35 -0
  140. package/templates/_shared/AGENTS.md +10 -0
  141. package/templates/_shared/CLAUDE.md +1 -0
  142. package/templates/_shared/gitignore +3 -0
  143. package/templates/_shared/public/robots.txt +2 -0
  144. package/templates/_shared/src/routes/legal.tsx +13 -0
  145. package/templates/_shared/tsconfig.json +20 -0
  146. package/templates/app/.env.example +4 -0
  147. package/templates/app/package.json +21 -0
  148. package/templates/app/prunelle.config.ts +11 -0
  149. package/templates/app/src/auth.ts +14 -0
  150. package/templates/app/src/routes/_layout.tsx +32 -0
  151. package/templates/app/src/routes/dashboard/_middleware.ts +3 -0
  152. package/templates/app/src/routes/dashboard/index.tsx +13 -0
  153. package/templates/app/src/routes/index.tsx +15 -0
  154. package/templates/app/src/routes/login.tsx +34 -0
  155. package/templates/app/src/styles/app.css +7 -0
  156. package/templates/app/tests/app.test.ts +32 -0
  157. package/templates/blog/content/posts/welcome.md +9 -0
  158. package/templates/blog/package.json +22 -0
  159. package/templates/blog/prunelle.config.ts +23 -0
  160. package/templates/blog/src/posts.ts +26 -0
  161. package/templates/blog/src/routes/_layout.tsx +20 -0
  162. package/templates/blog/src/routes/blog/[slug].tsx +31 -0
  163. package/templates/blog/src/routes/index.tsx +33 -0
  164. package/templates/blog/src/styles/app.css +10 -0
  165. package/templates/fullstack/package.json +19 -0
  166. package/templates/fullstack/prunelle.config.ts +6 -0
  167. package/templates/fullstack/src/actions/greet.ts +19 -0
  168. package/templates/fullstack/src/components/Counter.tsx +10 -0
  169. package/templates/fullstack/src/components/GreetForm.tsx +27 -0
  170. package/templates/fullstack/src/routes/_layout.tsx +14 -0
  171. package/templates/fullstack/src/routes/api/health.ts +5 -0
  172. package/templates/fullstack/src/routes/index.tsx +13 -0
  173. package/templates/fullstack/src/styles/app.css +29 -0
  174. package/templates/fullstack/tests/app.test.ts +37 -0
  175. package/templates/minimal/package.json +19 -0
  176. package/templates/minimal/prunelle.config.ts +6 -0
  177. package/templates/minimal/src/components/Counter.tsx +10 -0
  178. package/templates/minimal/src/routes/_layout.tsx +14 -0
  179. package/templates/minimal/src/routes/index.tsx +11 -0
  180. package/templates/minimal/src/styles/app.css +22 -0
  181. package/README.md +0 -3
@@ -0,0 +1,408 @@
1
+ // File-level primitive/JSX expression analysis shared identically by SSR and DOM compilers for `setText` vs `insert` slot planning.
2
+
3
+ import type {
4
+ CallExpression,
5
+ Expression,
6
+ Node,
7
+ ObjectPattern,
8
+ ParamPattern,
9
+ Program,
10
+ } from 'oxc-parser'
11
+ import { walk } from './ast'
12
+ import { collectPatternNames, containsJsx, unwrapTsExpr } from './shared'
13
+ import { matchJsxMapCall } from './slots'
14
+
15
+ const PRIMITIVE_GLOBALS = new Set([
16
+ 'String', 'Number', 'Boolean', 'parseInt', 'parseFloat',
17
+ 'encodeURI', 'encodeURIComponent', 'decodeURI', 'decodeURIComponent',
18
+ ])
19
+
20
+ const PRIMITIVE_METHODS = new Set([
21
+ 'toString', 'toFixed', 'toPrecision', 'toExponential', 'toLocaleString',
22
+ 'toLocaleDateString', 'toLocaleTimeString', 'toISOString', 'toUpperCase',
23
+ 'toLowerCase', 'toLocaleUpperCase', 'toLocaleLowerCase', 'trim', 'trimStart',
24
+ 'trimEnd', 'join', 'padStart', 'padEnd', 'repeat', 'replace', 'replaceAll',
25
+ 'substring', 'substr', 'charAt', 'charCodeAt', 'codePointAt', 'indexOf',
26
+ 'lastIndexOf', 'includes', 'startsWith', 'endsWith', 'getTime', 'getFullYear',
27
+ 'getMonth', 'getDate', 'getHours', 'getMinutes', 'getSeconds',
28
+ ])
29
+
30
+ const PRIMITIVE_PROPS = new Set(['length', 'size', 'byteLength'])
31
+ const PRIMITIVE_IDENTIFIERS = new Set(['undefined', 'NaN', 'Infinity'])
32
+
33
+ function isKnownPrimitiveCall(node: CallExpression): boolean {
34
+ const callee = node.callee
35
+ if (callee.type === 'Identifier' && PRIMITIVE_GLOBALS.has(callee.name))
36
+ return true
37
+ if (callee.type === 'MemberExpression' && !callee.computed && callee.property.type === 'Identifier') {
38
+ const prop = callee.property.name
39
+ if (callee.object.type === 'Identifier') {
40
+ const obj = callee.object.name
41
+ if (obj === 'Math' || (obj === 'JSON' && prop === 'stringify') || (obj === 'Date' && prop === 'now'))
42
+ return true
43
+ }
44
+ if (PRIMITIVE_METHODS.has(prop))
45
+ return true
46
+ }
47
+ return false
48
+ }
49
+
50
+ function isPrimitiveTypeNode(node: Node | null | undefined): boolean {
51
+ if (node === null || node === undefined)
52
+ return false
53
+ switch (node.type) {
54
+ case 'TSStringKeyword':
55
+ case 'TSNumberKeyword':
56
+ case 'TSBooleanKeyword':
57
+ case 'TSBigIntKeyword':
58
+ case 'TSSymbolKeyword':
59
+ case 'TSNullKeyword':
60
+ case 'TSUndefinedKeyword':
61
+ case 'TSVoidKeyword':
62
+ case 'TSNeverKeyword':
63
+ case 'TSLiteralType':
64
+ case 'TSTemplateLiteralType':
65
+ return true
66
+ case 'TSParenthesizedType':
67
+ return isPrimitiveTypeNode(node.typeAnnotation)
68
+ case 'TSUnionType':
69
+ return node.types.length > 0 && node.types.every(isPrimitiveTypeNode)
70
+ default:
71
+ return false
72
+ }
73
+ }
74
+
75
+ function isPrimitiveSignalTypeNode(node: Node | null | undefined): boolean {
76
+ if (node === null || node === undefined || node.type !== 'TSTypeReference')
77
+ return false
78
+ const name = node.typeName.type === 'Identifier' ? node.typeName.name : ''
79
+ if (name !== 'Signal' && name !== 'ReadonlySignal')
80
+ return false
81
+ const params = node.typeArguments?.params
82
+ return params !== undefined && params.length === 1 && isPrimitiveTypeNode(params[0])
83
+ }
84
+
85
+ function memberPropKey(node: Node): string | undefined {
86
+ if (node.type === 'Identifier')
87
+ return node.name
88
+ if (node.type === 'Literal' && (typeof node.value === 'string' || typeof node.value === 'number'))
89
+ return String(node.value)
90
+ return undefined
91
+ }
92
+
93
+ function extractTypeLiteralPrimitives(typeNode: Node | null | undefined): { prims: Set<string>, primSignals: Set<string> } | undefined {
94
+ if (typeNode === null || typeNode === undefined || typeNode.type !== 'TSTypeLiteral')
95
+ return undefined
96
+ const prims = new Set<string>()
97
+ const primSignals = new Set<string>()
98
+ for (const m of typeNode.members) {
99
+ if (m.type !== 'TSPropertySignature' || m.computed || m.typeAnnotation === null || m.typeAnnotation === undefined)
100
+ continue
101
+ const key = memberPropKey(m.key)
102
+ if (key === undefined)
103
+ continue
104
+ if (isPrimitiveTypeNode(m.typeAnnotation.typeAnnotation))
105
+ prims.add(key)
106
+ else if (isPrimitiveSignalTypeNode(m.typeAnnotation.typeAnnotation))
107
+ primSignals.add(key)
108
+ }
109
+ return { prims, primSignals }
110
+ }
111
+
112
+ function rootIdentifierName(node: Node): string | undefined {
113
+ let cur = unwrapTsExpr(node)
114
+ while (cur.type === 'MemberExpression' || cur.type === 'ChainExpression')
115
+ cur = unwrapTsExpr(cur.type === 'ChainExpression' ? cur.expression : cur.object)
116
+ return cur.type === 'Identifier' ? cur.name : undefined
117
+ }
118
+
119
+ export interface ExprContext {
120
+ primitiveVars: ReadonlySet<string>
121
+ primitiveSignals: ReadonlySet<string>
122
+ propsParams: ReadonlySet<string>
123
+ primitivePropKeys: ReadonlyMap<string, ReadonlySet<string>>
124
+ jsxVars: ReadonlySet<string>
125
+ }
126
+
127
+ function isSignalCall(node: Node): { kind: 'signal' | 'computed', call: CallExpression } | undefined {
128
+ const cur = unwrapTsExpr(node)
129
+ if (cur.type !== 'CallExpression')
130
+ return undefined
131
+ const c = cur.callee
132
+ const name = c.type === 'Identifier'
133
+ ? c.name
134
+ : c.type === 'MemberExpression' && !c.computed && c.property.type === 'Identifier'
135
+ ? c.property.name
136
+ : ''
137
+ if (name === 'signal' || name === 'computed')
138
+ return { kind: name, call: cur }
139
+ return undefined
140
+ }
141
+
142
+ /**
143
+ * File-level static primitive/JSX binding analysis shared identically by SSR and DOM compilers
144
+ * so `planChildSlots` chooses matching `setText` vs `insert` slots and markers on both targets.
145
+ */
146
+ export function createExprContext(program: Program, jsxNodes: WeakSet<Node>): ExprContext {
147
+ const primCandidates = new Set<string>()
148
+ const nonPrimNames = new Set<string>()
149
+ const sigCandidates = new Set<string>()
150
+ const nonSigNames = new Set<string>()
151
+ const propsParams = new Set<string>()
152
+ const primitivePropKeys = new Map<string, Set<string>>()
153
+ const jsxVars = new Set<string>()
154
+ const deferredInits: { name: string, init: Node, isSignal: boolean, signalKind?: 'signal' | 'computed' }[] = []
155
+
156
+ const markNonPrim = (pat: Node | null | undefined): void => {
157
+ if (pat === null || pat === undefined)
158
+ return
159
+ collectPatternNames(pat, nonPrimNames)
160
+ collectPatternNames(pat, nonSigNames)
161
+ }
162
+
163
+ const recordObjectPatternTypes = (pat: ObjectPattern, typeNode: Node | null | undefined): void => {
164
+ const info = extractTypeLiteralPrimitives(typeNode)
165
+ for (const prop of pat.properties) {
166
+ if (prop.type === 'RestElement') {
167
+ markNonPrim(prop.argument)
168
+ continue
169
+ }
170
+ const key = !prop.computed ? memberPropKey(prop.key) : undefined
171
+ const val = prop.value.type === 'AssignmentPattern' ? prop.value.left : prop.value
172
+ if (val.type === 'Identifier' && key !== undefined && info !== undefined) {
173
+ if (info.prims.has(key)) {
174
+ primCandidates.add(val.name)
175
+ nonSigNames.add(val.name)
176
+ continue
177
+ }
178
+ if (info.primSignals.has(key)) {
179
+ sigCandidates.add(val.name)
180
+ nonPrimNames.add(val.name)
181
+ continue
182
+ }
183
+ }
184
+ markNonPrim(val)
185
+ }
186
+ }
187
+
188
+ const recordParam = (param: ParamPattern, isComponentFirstParam: boolean, isMapIndexParam: boolean): void => {
189
+ const inner = param.type === 'AssignmentPattern' ? param.left : param
190
+ if (inner.type === 'ObjectPattern') {
191
+ recordObjectPatternTypes(inner, inner.typeAnnotation?.typeAnnotation)
192
+ return
193
+ }
194
+ if (inner.type === 'Identifier') {
195
+ const ann = inner.typeAnnotation?.typeAnnotation
196
+ if (isMapIndexParam || isPrimitiveTypeNode(ann)) {
197
+ primCandidates.add(inner.name)
198
+ nonSigNames.add(inner.name)
199
+ return
200
+ }
201
+ if (isPrimitiveSignalTypeNode(ann)) {
202
+ sigCandidates.add(inner.name)
203
+ nonPrimNames.add(inner.name)
204
+ return
205
+ }
206
+ if (isComponentFirstParam) {
207
+ propsParams.add(inner.name)
208
+ const info = extractTypeLiteralPrimitives(ann)
209
+ if (info !== undefined && !primitivePropKeys.has(inner.name))
210
+ primitivePropKeys.set(inner.name, info.prims)
211
+ }
212
+ }
213
+ markNonPrim(inner)
214
+ }
215
+
216
+ const mapCallbacks = new WeakSet<Node>()
217
+ walk(program, (node) => {
218
+ const mapMatch = matchJsxMapCall(node, jsxNodes)
219
+ if (mapMatch !== undefined)
220
+ mapCallbacks.add(mapMatch.cb)
221
+ })
222
+
223
+ walk(program, (node) => {
224
+ if (node.type === 'VariableDeclaration') {
225
+ for (const d of node.declarations) {
226
+ if (d.init !== null && containsJsx(d.init, jsxNodes))
227
+ collectPatternNames(d.id, jsxVars)
228
+ if (d.id.type === 'Identifier') {
229
+ const ann = d.id.typeAnnotation?.typeAnnotation
230
+ if (isPrimitiveTypeNode(ann)) {
231
+ primCandidates.add(d.id.name)
232
+ nonSigNames.add(d.id.name)
233
+ continue
234
+ }
235
+ if (isPrimitiveSignalTypeNode(ann)) {
236
+ sigCandidates.add(d.id.name)
237
+ nonPrimNames.add(d.id.name)
238
+ continue
239
+ }
240
+ if (node.kind === 'const' && d.init !== null) {
241
+ const sig = isSignalCall(d.init)
242
+ if (sig !== undefined) {
243
+ nonPrimNames.add(d.id.name)
244
+ const tArgs = sig.call.typeArguments?.params
245
+ if (tArgs !== undefined && tArgs.length === 1 && isPrimitiveTypeNode(tArgs[0]))
246
+ sigCandidates.add(d.id.name)
247
+ else
248
+ deferredInits.push({ name: d.id.name, init: sig.call, isSignal: true, signalKind: sig.kind })
249
+ continue
250
+ }
251
+ deferredInits.push({ name: d.id.name, init: d.init, isSignal: false })
252
+ nonSigNames.add(d.id.name)
253
+ continue
254
+ }
255
+ }
256
+ markNonPrim(d.id)
257
+ }
258
+ return
259
+ }
260
+ if (node.type === 'ImportSpecifier' || node.type === 'ImportDefaultSpecifier' || node.type === 'ImportNamespaceSpecifier') {
261
+ markNonPrim(node.local)
262
+ return
263
+ }
264
+ if (node.type === 'FunctionDeclaration' || node.type === 'ClassDeclaration')
265
+ markNonPrim(node.id)
266
+ if (node.type === 'FunctionDeclaration' || node.type === 'FunctionExpression' || node.type === 'ArrowFunctionExpression') {
267
+ const isMapCb = mapCallbacks.has(node)
268
+ const isComponent = !isMapCb && node.body !== null && containsJsx(node.body, jsxNodes)
269
+ for (let i = 0; i < node.params.length; i++)
270
+ recordParam(node.params[i]!, isComponent && i === 0, isMapCb && i === 1)
271
+ return
272
+ }
273
+ if (node.type === 'CatchClause') {
274
+ markNonPrim(node.param)
275
+ return
276
+ }
277
+ if (node.type === 'AssignmentExpression') {
278
+ if (containsJsx(node.right, jsxNodes)) {
279
+ const targetRoot = rootIdentifierName(node.left)
280
+ if (targetRoot !== undefined)
281
+ jsxVars.add(targetRoot)
282
+ }
283
+ if (node.left.type === 'MemberExpression' && !node.left.computed && node.left.object.type === 'Identifier' && node.left.property.type === 'Identifier' && node.left.property.name === 'value') {
284
+ if (!isDefinitelyPrimitive(node.right, undefined))
285
+ nonSigNames.add(node.left.object.name)
286
+ }
287
+ else {
288
+ const names = new Set<string>()
289
+ collectPatternNames(node.left, names)
290
+ for (const n of names) {
291
+ if (!isDefinitelyPrimitive(node.right, undefined))
292
+ nonPrimNames.add(n)
293
+ nonSigNames.add(n)
294
+ }
295
+ }
296
+ }
297
+ })
298
+
299
+ for (const n of nonPrimNames)
300
+ primCandidates.delete(n)
301
+ for (const n of nonSigNames)
302
+ sigCandidates.delete(n)
303
+
304
+ const ctx: ExprContext = {
305
+ primitiveVars: primCandidates,
306
+ primitiveSignals: sigCandidates,
307
+ propsParams,
308
+ primitivePropKeys,
309
+ jsxVars,
310
+ }
311
+
312
+ for (let pass = 0; pass < 2; pass++) {
313
+ for (const item of deferredInits) {
314
+ if (item.isSignal) {
315
+ if (nonSigNames.has(item.name))
316
+ continue
317
+ const call = item.init as CallExpression
318
+ const arg = call.arguments[0]
319
+ if (item.signalKind === 'signal' && arg !== undefined && arg.type !== 'SpreadElement' && isDefinitelyPrimitive(arg, ctx)) {
320
+ sigCandidates.add(item.name)
321
+ }
322
+ else if (item.signalKind === 'computed' && arg !== undefined && (arg.type === 'ArrowFunctionExpression' || arg.type === 'FunctionExpression')) {
323
+ if (arg.body !== null && arg.body.type !== 'BlockStatement' && isDefinitelyPrimitive(arg.body, ctx))
324
+ sigCandidates.add(item.name)
325
+ }
326
+ }
327
+ else if (!nonPrimNames.has(item.name) && isDefinitelyPrimitive(item.init, ctx)) {
328
+ primCandidates.add(item.name)
329
+ }
330
+ }
331
+ }
332
+
333
+ for (const n of nonPrimNames)
334
+ primCandidates.delete(n)
335
+ for (const n of nonSigNames)
336
+ sigCandidates.delete(n)
337
+
338
+ return ctx
339
+ }
340
+
341
+ export function isDefinitelyPrimitive(node: Node, ctx?: ExprContext): boolean {
342
+ if (node.type === 'TSAsExpression' || node.type === 'TSSatisfiesExpression' || node.type === 'TSTypeAssertion') {
343
+ if (isPrimitiveTypeNode(node.typeAnnotation))
344
+ return true
345
+ return isDefinitelyPrimitive(node.expression, ctx)
346
+ }
347
+ const cur = unwrapTsExpr(node)
348
+ switch (cur.type) {
349
+ case 'Literal':
350
+ case 'TemplateLiteral':
351
+ case 'BinaryExpression':
352
+ case 'UnaryExpression':
353
+ case 'UpdateExpression':
354
+ return true
355
+ case 'Identifier':
356
+ return PRIMITIVE_IDENTIFIERS.has(cur.name) || ctx?.primitiveVars.has(cur.name) === true
357
+ case 'CallExpression':
358
+ return isKnownPrimitiveCall(cur)
359
+ case 'LogicalExpression':
360
+ if (cur.operator === '&&')
361
+ return isDefinitelyPrimitive(cur.right, ctx)
362
+ return isDefinitelyPrimitive(cur.left, ctx) && isDefinitelyPrimitive(cur.right, ctx)
363
+ case 'ConditionalExpression':
364
+ return isDefinitelyPrimitive(cur.consequent, ctx) && isDefinitelyPrimitive(cur.alternate, ctx)
365
+ case 'SequenceExpression':
366
+ return cur.expressions.length > 0 && isDefinitelyPrimitive(cur.expressions[cur.expressions.length - 1]!, ctx)
367
+ case 'ChainExpression':
368
+ return isDefinitelyPrimitive(cur.expression, ctx)
369
+ case 'MemberExpression': {
370
+ if (!cur.computed && cur.property.type === 'Identifier') {
371
+ const prop = cur.property.name
372
+ if (PRIMITIVE_PROPS.has(prop))
373
+ return true
374
+ if (prop === 'children')
375
+ return false
376
+ if (prop === 'value')
377
+ return cur.object.type === 'Identifier' && ctx?.primitiveSignals.has(cur.object.name) === true
378
+ const root = rootIdentifierName(cur.object)
379
+ if (root !== undefined && ctx?.jsxVars.has(root) === true)
380
+ return false
381
+ if (cur.object.type === 'Identifier' && ctx?.propsParams.has(cur.object.name) === true)
382
+ return ctx.primitivePropKeys.get(cur.object.name)?.has(prop) === true
383
+ return true
384
+ }
385
+ return false
386
+ }
387
+ default:
388
+ return false
389
+ }
390
+ }
391
+
392
+ export function mayReturnNode(node: Node): boolean {
393
+ const cur = unwrapTsExpr(node)
394
+ if (cur.type === 'CallExpression')
395
+ return !isKnownPrimitiveCall(cur)
396
+ if (cur.type === 'LogicalExpression')
397
+ return mayReturnNode(cur.left) || mayReturnNode(cur.right)
398
+ if (cur.type === 'ConditionalExpression')
399
+ return mayReturnNode(cur.consequent) || mayReturnNode(cur.alternate)
400
+ return false
401
+ }
402
+
403
+ /** Shared SSR/DOM check for whether a dynamic expression slot may produce DOM nodes/fragments (requiring balanced `<!--k[-->...<!--k]-->` markers). */
404
+ export function isNodeCapableExpr(expr: Expression, jsxNodes?: WeakSet<Node>, exprContext?: ExprContext): boolean {
405
+ if (containsJsx(expr, jsxNodes))
406
+ return true
407
+ return !isDefinitelyPrimitive(expr, exprContext)
408
+ }
@@ -0,0 +1,8 @@
1
+ export { analyzeModule, parseTsx } from './analyze'
2
+ export type { ImportInfo, ModuleAnalysis } from './analyze'
3
+ export { checkCompliance, checkCssCompliance, checkRouteCompliance, collectProjectComplianceWarnings, isRuleIgnored, shouldEmitWarning } from './compliance'
4
+ export type { ComplianceConfig, ComplianceRule } from './compliance'
5
+ export { compileDom } from './dom'
6
+ export type { CompileDomOptions, CompileDomResult } from './dom'
7
+ export { compileSsr } from './ssr'
8
+ export type { CompileResult, CompileSsrOptions, IslandBinding } from './ssr'