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.
- package/llms.txt +148 -0
- package/package.json +53 -4
- package/src/ambient.d.ts +6 -0
- package/src/attrs.ts +35 -0
- package/src/build/bundle.ts +613 -0
- package/src/build/carry.ts +57 -0
- package/src/build/client-entries.ts +107 -0
- package/src/build/client-plugin.ts +169 -0
- package/src/build/client-prune.ts +118 -0
- package/src/build/compile.ts +128 -0
- package/src/build/files.ts +156 -0
- package/src/build/first-load.ts +164 -0
- package/src/build/graph.ts +247 -0
- package/src/build/index.ts +614 -0
- package/src/build/is-inside.ts +12 -0
- package/src/build/islands.ts +641 -0
- package/src/build/manifest.ts +281 -0
- package/src/build/output.ts +84 -0
- package/src/build/plugin-host.ts +220 -0
- package/src/build/precompress.ts +139 -0
- package/src/build/prerender.ts +150 -0
- package/src/build/render-rules.ts +205 -0
- package/src/build/report.ts +247 -0
- package/src/build/resolve.ts +50 -0
- package/src/build/routes.ts +338 -0
- package/src/build/server-entry.ts +38 -0
- package/src/build/static.ts +163 -0
- package/src/build/status-pages.ts +127 -0
- package/src/cli/check-forms.ts +654 -0
- package/src/cli/check-links.ts +619 -0
- package/src/cli/check.ts +367 -0
- package/src/cli/commands.ts +265 -0
- package/src/cli/index.ts +70 -0
- package/src/cli/inspect.ts +335 -0
- package/src/cli/new.ts +41 -0
- package/src/cli/upgrade-names.ts +209 -0
- package/src/cli/upgrade.ts +354 -0
- package/src/compiler/analyze.ts +618 -0
- package/src/compiler/ast.ts +82 -0
- package/src/compiler/browser-globals.ts +127 -0
- package/src/compiler/compliance-rgaa.ts +502 -0
- package/src/compiler/compliance.ts +497 -0
- package/src/compiler/data-keys.ts +295 -0
- package/src/compiler/dom-attrs.ts +379 -0
- package/src/compiler/dom.ts +566 -0
- package/src/compiler/emit.ts +131 -0
- package/src/compiler/expr-context.ts +408 -0
- package/src/compiler/index.ts +8 -0
- package/src/compiler/interactivity.ts +366 -0
- package/src/compiler/mistakes.ts +499 -0
- package/src/compiler/node-env.ts +50 -0
- package/src/compiler/patch.ts +97 -0
- package/src/compiler/props.ts +460 -0
- package/src/compiler/scope.ts +568 -0
- package/src/compiler/server-only.ts +326 -0
- package/src/compiler/shared.ts +369 -0
- package/src/compiler/signal-reads.ts +242 -0
- package/src/compiler/slots.ts +227 -0
- package/src/compiler/ssr-helpers.ts +555 -0
- package/src/compiler/ssr-island.ts +90 -0
- package/src/compiler/ssr-prunelle-tags.ts +56 -0
- package/src/compiler/ssr.ts +491 -0
- package/src/context.ts +165 -0
- package/src/dev/child.ts +30 -0
- package/src/dev/index.ts +208 -0
- package/src/dev/modules.ts +68 -0
- package/src/dev/protocol.ts +21 -0
- package/src/dev/queue.ts +79 -0
- package/src/dev/reload.ts +157 -0
- package/src/dev/supervisor.ts +187 -0
- package/src/dev/watchers.ts +215 -0
- package/src/dom/action.ts +164 -0
- package/src/dom/attrs.ts +72 -0
- package/src/dom/claim.ts +120 -0
- package/src/dom/extras.ts +562 -0
- package/src/dom/index.ts +289 -0
- package/src/dom/island.ts +284 -0
- package/src/dom/loop.ts +450 -0
- package/src/dom/revive.ts +36 -0
- package/src/index.ts +22 -0
- package/src/jsx-runtime.ts +566 -0
- package/src/plugins/config.ts +86 -0
- package/src/plugins/context.ts +66 -0
- package/src/plugins/index.ts +14 -0
- package/src/plugins/load.ts +70 -0
- package/src/plugins/order.ts +111 -0
- package/src/plugins/public.ts +12 -0
- package/src/plugins/requires.ts +47 -0
- package/src/plugins/services.ts +35 -0
- package/src/plugins/types.ts +242 -0
- package/src/reactivity/graph.ts +249 -0
- package/src/reactivity/index.ts +533 -0
- package/src/reactivity/selector.ts +51 -0
- package/src/reactivity/store.ts +208 -0
- package/src/server/action-protect.ts +186 -0
- package/src/server/action-registry.ts +78 -0
- package/src/server/action.ts +498 -0
- package/src/server/app-entry.ts +23 -0
- package/src/server/assets.ts +136 -0
- package/src/server/compress.ts +560 -0
- package/src/server/consent.ts +253 -0
- package/src/server/cookies.ts +139 -0
- package/src/server/document.ts +271 -0
- package/src/server/env.ts +33 -0
- package/src/server/errors.ts +382 -0
- package/src/server/form-schema.ts +343 -0
- package/src/server/health.ts +244 -0
- package/src/server/http.ts +508 -0
- package/src/server/index.ts +687 -0
- package/src/server/lifecycle.ts +75 -0
- package/src/server/loader.ts +118 -0
- package/src/server/page.ts +107 -0
- package/src/server/param-matchers.ts +112 -0
- package/src/server/plugin-host.ts +256 -0
- package/src/server/prerendered.ts +71 -0
- package/src/server/public.ts +19 -0
- package/src/server/rate-limit.ts +133 -0
- package/src/server/region.ts +96 -0
- package/src/server/request-body.ts +27 -0
- package/src/server/request-path.ts +73 -0
- package/src/server/request-scope.ts +22 -0
- package/src/server/route-table.ts +82 -0
- package/src/server/router.ts +261 -0
- package/src/server/routing.ts +377 -0
- package/src/server/security.ts +472 -0
- package/src/server/serve-handlers.ts +83 -0
- package/src/server/served-file.ts +128 -0
- package/src/server/standard-schema.ts +87 -0
- package/src/server/start.ts +99 -0
- package/src/server/static-dir.ts +167 -0
- package/src/server/stream.ts +192 -0
- package/src/ssr/context.ts +350 -0
- package/src/ssr/index.ts +596 -0
- package/src/ssr/navigation.ts +96 -0
- package/src/ssr/region.ts +171 -0
- package/src/style.ts +33 -0
- package/src/test/browser.ts +192 -0
- package/src/test/index.ts +191 -0
- package/src/unrenderable.ts +35 -0
- package/templates/_shared/AGENTS.md +10 -0
- package/templates/_shared/CLAUDE.md +1 -0
- package/templates/_shared/gitignore +3 -0
- package/templates/_shared/public/robots.txt +2 -0
- package/templates/_shared/src/routes/legal.tsx +13 -0
- package/templates/_shared/tsconfig.json +20 -0
- package/templates/app/.env.example +4 -0
- package/templates/app/package.json +21 -0
- package/templates/app/prunelle.config.ts +11 -0
- package/templates/app/src/auth.ts +14 -0
- package/templates/app/src/routes/_layout.tsx +32 -0
- package/templates/app/src/routes/dashboard/_middleware.ts +3 -0
- package/templates/app/src/routes/dashboard/index.tsx +13 -0
- package/templates/app/src/routes/index.tsx +15 -0
- package/templates/app/src/routes/login.tsx +34 -0
- package/templates/app/src/styles/app.css +7 -0
- package/templates/app/tests/app.test.ts +32 -0
- package/templates/blog/content/posts/welcome.md +9 -0
- package/templates/blog/package.json +22 -0
- package/templates/blog/prunelle.config.ts +23 -0
- package/templates/blog/src/posts.ts +26 -0
- package/templates/blog/src/routes/_layout.tsx +20 -0
- package/templates/blog/src/routes/blog/[slug].tsx +31 -0
- package/templates/blog/src/routes/index.tsx +33 -0
- package/templates/blog/src/styles/app.css +10 -0
- package/templates/fullstack/package.json +19 -0
- package/templates/fullstack/prunelle.config.ts +6 -0
- package/templates/fullstack/src/actions/greet.ts +19 -0
- package/templates/fullstack/src/components/Counter.tsx +10 -0
- package/templates/fullstack/src/components/GreetForm.tsx +27 -0
- package/templates/fullstack/src/routes/_layout.tsx +14 -0
- package/templates/fullstack/src/routes/api/health.ts +5 -0
- package/templates/fullstack/src/routes/index.tsx +13 -0
- package/templates/fullstack/src/styles/app.css +29 -0
- package/templates/fullstack/tests/app.test.ts +37 -0
- package/templates/minimal/package.json +19 -0
- package/templates/minimal/prunelle.config.ts +6 -0
- package/templates/minimal/src/components/Counter.tsx +10 -0
- package/templates/minimal/src/routes/_layout.tsx +14 -0
- package/templates/minimal/src/routes/index.tsx +11 -0
- package/templates/minimal/src/styles/app.css +22 -0
- 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'
|