prunelle 0.8.0 → 0.10.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 +68 -51
- package/package.json +7 -2
- package/src/a11y/declaration.ts +10 -17
- package/src/a11y/index.ts +69 -125
- package/src/animate.ts +127 -0
- package/src/build/asides.ts +51 -0
- package/src/build/bundle.ts +94 -136
- package/src/build/client-entries.ts +6 -6
- package/src/build/client-outputs.ts +75 -0
- package/src/build/client-plugin.ts +9 -4
- package/src/build/ecoindex.ts +4 -2
- package/src/build/files.ts +18 -0
- package/src/build/graph.ts +14 -6
- package/src/build/index.ts +23 -11
- package/src/build/island-promote.ts +42 -2
- package/src/build/islands.ts +63 -9
- package/src/build/key-types.ts +31 -0
- package/src/build/manifest.ts +117 -1
- package/src/build/plugin-host.ts +13 -1
- package/src/build/prerender.ts +8 -3
- package/src/build/reach.ts +18 -4
- package/src/build/report.ts +1 -1
- package/src/build/resolve.ts +5 -1
- package/src/build/route-types.ts +16 -0
- package/src/build/routes.ts +42 -15
- package/src/build/seed-ids.ts +65 -0
- package/src/build/seed-writes.ts +111 -0
- package/src/build/static-headers.ts +2 -2
- package/src/build/static.ts +1 -1
- package/src/cli/check-cache.ts +51 -0
- package/src/cli/check-consent.ts +95 -0
- package/src/cli/check-forms.ts +10 -2
- package/src/cli/check-links-patterns.ts +101 -0
- package/src/cli/check-links.ts +30 -105
- package/src/cli/check-regions.ts +185 -0
- package/src/cli/check-security.ts +50 -6
- package/src/cli/check.ts +49 -21
- package/src/cli/commands.ts +138 -16
- package/src/cli/docs.ts +21 -2
- package/src/cli/form-opaque-children.ts +40 -0
- package/src/cli/index.ts +1 -1
- package/src/cli/inspect.ts +2 -0
- package/src/cli/mcp-tools.ts +2 -2
- package/src/cli/new.ts +9 -5
- package/src/cli/upgrade-names.ts +14 -2
- package/src/cli/upgrade.ts +3 -0
- package/src/compiler/analyze.ts +22 -16
- package/src/compiler/cacheability-private.ts +13 -3
- package/src/compiler/cacheability.ts +24 -2
- package/src/compiler/compliance-contrast.ts +322 -0
- package/src/compiler/compliance-empty.ts +24 -0
- package/src/compiler/compliance-rgaa-content.ts +95 -0
- package/src/compiler/compliance-rgaa-criteria.ts +45 -0
- package/src/compiler/compliance-rgaa-pages.ts +140 -0
- package/src/compiler/compliance-rgaa.ts +19 -0
- package/src/compiler/compliance-rules.ts +72 -0
- package/src/compiler/compliance-third-party.ts +59 -0
- package/src/compiler/compliance-urls.ts +52 -0
- package/src/compiler/compliance.ts +61 -93
- package/src/compiler/cookie-inventory.ts +119 -0
- package/src/compiler/dom-attrs.ts +178 -22
- package/src/compiler/dom.ts +31 -44
- package/src/compiler/emit.ts +17 -6
- package/src/compiler/expr-context.ts +260 -207
- package/src/compiler/foreign-imports.ts +5 -3
- package/src/compiler/mistakes.ts +18 -9
- package/src/compiler/props-body.ts +263 -21
- package/src/compiler/props-pattern.ts +211 -0
- package/src/compiler/props.ts +324 -343
- package/src/compiler/signal-reads.ts +142 -29
- package/src/compiler/spread-handlers.ts +25 -13
- package/src/compiler/ssr-emit.ts +510 -0
- package/src/compiler/ssr-helpers.ts +165 -121
- package/src/compiler/ssr.ts +28 -441
- package/src/context.ts +14 -1
- package/src/dev/child.ts +1 -1
- package/src/dev/host-check.ts +2 -1
- package/src/dev/hot-islands.ts +71 -0
- package/src/dev/index.ts +31 -18
- package/src/dev/protocol.ts +1 -1
- package/src/dev/queue.ts +3 -2
- package/src/dev/reload.ts +5 -2
- package/src/dev/supervisor.ts +3 -1
- package/src/dev/watchers.ts +6 -2
- package/src/dom/action.ts +97 -14
- package/src/dom/attrs.ts +93 -25
- package/src/dom/extras.ts +91 -50
- package/src/dom/field-marks.ts +32 -0
- package/src/dom/hot.ts +9 -0
- package/src/dom/index.ts +44 -18
- package/src/dom/island-hot.ts +29 -0
- package/src/dom/island.ts +13 -2
- package/src/dom/loop.ts +259 -188
- package/src/dom/prefetch.ts +135 -0
- package/src/dom/regions.ts +515 -0
- package/src/dom/swap.ts +246 -0
- package/src/dom/trusted.ts +22 -0
- package/src/dom/upload.ts +44 -0
- package/src/eco/declaration.ts +44 -41
- package/src/eco/index.ts +8 -5
- package/src/href.ts +31 -0
- package/src/index.ts +12 -5
- package/src/plugins/config.ts +1 -1
- package/src/plugins/context.ts +7 -1
- package/src/plugins/daily.ts +27 -0
- package/src/plugins/index.ts +3 -3
- package/src/plugins/order.ts +1 -1
- package/src/plugins/public.ts +12 -5
- package/src/plugins/services.ts +88 -14
- package/src/plugins/types.ts +128 -10
- package/src/reactivity/graph.ts +244 -41
- package/src/reactivity/hmr.ts +101 -0
- package/src/reactivity/index.ts +243 -239
- package/src/reactivity/resource.ts +129 -0
- package/src/reactivity/seed.ts +141 -0
- package/src/reactivity/selector.ts +85 -47
- package/src/reactivity/server-seed.ts +202 -0
- package/src/reactivity/store.ts +331 -97
- package/src/rgpd/draft.ts +171 -0
- package/src/rgpd/forms.ts +85 -0
- package/src/rgpd/index.ts +57 -0
- package/src/server/action-flash.ts +1 -0
- package/src/server/action-protect.ts +3 -0
- package/src/server/action-registry.ts +11 -9
- package/src/server/action.ts +51 -19
- package/src/server/app-secret.ts +14 -8
- package/src/server/cache-invalidation.ts +97 -0
- package/src/server/compress.ts +55 -18
- package/src/server/consent.ts +21 -5
- package/src/server/cookie-inventory.ts +78 -0
- package/src/server/cookies.ts +77 -8
- package/src/server/cors.ts +98 -0
- package/src/server/csp-report.ts +90 -0
- package/src/server/discard.ts +13 -0
- package/src/server/document.ts +2 -2
- package/src/server/env.ts +1 -1
- package/src/server/errors.ts +9 -2
- package/src/server/field-errors.ts +91 -0
- package/src/server/form-schema.ts +16 -11
- package/src/server/health.ts +41 -11
- package/src/server/http.ts +28 -11
- package/src/server/index.ts +122 -307
- package/src/server/loader.ts +2 -0
- package/src/server/page.ts +3 -9
- package/src/server/plugin-host.ts +66 -16
- package/src/server/plugin-route-shadow.ts +24 -0
- package/src/server/public.ts +14 -3
- package/src/server/rate-limit.ts +49 -10
- package/src/server/region.ts +22 -2
- package/src/server/request-handler.ts +406 -0
- package/src/server/request-log.ts +94 -0
- package/src/server/route-cache.ts +55 -8
- package/src/server/route-input.ts +54 -0
- package/src/server/route-table.ts +53 -27
- package/src/server/router.ts +2 -1
- package/src/server/routing.ts +104 -45
- package/src/server/sanitize-html.ts +4 -2
- package/src/server/security.ts +38 -8
- package/src/server/serve-handlers.ts +16 -6
- package/src/server/served-file.ts +19 -14
- package/src/server/shared-store.ts +323 -0
- package/src/server/start.ts +12 -5
- package/src/server/static-dir.ts +34 -12
- package/src/server/stream.ts +2 -1
- package/src/server/surface.ts +39 -0
- package/src/server/webhook.ts +50 -0
- package/src/server/workers.ts +168 -0
- package/src/ssr/consent-banner.ts +20 -16
- package/src/ssr/consent-texts.ts +40 -0
- package/src/ssr/context.ts +174 -53
- package/src/ssr/cookie-table.ts +75 -0
- package/src/ssr/index.ts +63 -58
- package/src/ssr/navigation.ts +161 -14
- package/src/ssr/region.ts +9 -3
- package/src/style.ts +12 -5
- package/src/test/browser.ts +53 -23
- package/src/test/build-reuse.ts +85 -0
- package/src/test/index.ts +51 -8
- package/src/test/mount.ts +53 -0
- package/src/test/outside.ts +94 -0
- package/src/ts-plugin/diagnostics.ts +56 -18
- package/templates/_shared/AGENTS.md +1 -1
- package/templates/_shared/Dockerfile +22 -0
- package/templates/_shared/dockerignore +9 -0
- package/templates/_shared/gitignore +2 -0
- package/templates/app/.env.example +3 -1
- package/templates/app/compose.yaml +32 -0
- package/templates/app/db/migrations/001_notes.sql +7 -0
- package/templates/app/db/schema.ts +11 -0
- package/templates/app/package.json +1 -0
- package/templates/app/prunelle.config.ts +6 -0
- package/templates/app/src/actions/notes.ts +26 -0
- package/templates/app/src/auth.ts +4 -2
- package/templates/app/src/db.ts +5 -0
- package/templates/app/src/routes/dashboard/index.tsx +26 -1
- package/templates/app/src/routes/privacy.tsx +6 -2
- package/templates/app/tests/app.test.ts +14 -3
- package/templates/plugin/AGENTS.md +11 -0
- package/templates/plugin/CLAUDE.md +1 -0
- package/templates/plugin/README.md +27 -0
- package/templates/plugin/gitignore +2 -0
- package/templates/plugin/llms.txt +19 -0
- package/templates/plugin/package.json +33 -0
- package/templates/plugin/src/index.ts +40 -0
- package/templates/plugin/tests/fixture/prunelle.config.ts +4 -0
- package/templates/plugin/tests/fixture/src/routes/index.tsx +11 -0
- package/templates/plugin/tests/plugin.test.ts +42 -0
- package/templates/plugin/tsconfig.json +19 -0
- package/ts-plugin.cjs +4058 -2246
package/src/compiler/props.ts
CHANGED
|
@@ -1,29 +1,13 @@
|
|
|
1
1
|
// Compiles a component's destructured props: reads stay reactive through `__p`, and the function is rewritten around it.
|
|
2
2
|
|
|
3
3
|
import type { ArrowFunctionExpression, Function as OxcFunction, Node, ObjectPattern, ParamPattern } from 'oxc-parser'
|
|
4
|
+
import type { PatternContext } from './props-pattern'
|
|
4
5
|
import { walk } from './ast'
|
|
5
6
|
import { SourceEditor } from './patch'
|
|
6
|
-
import {
|
|
7
|
+
import { patternReads } from './props-pattern'
|
|
8
|
+
import { collectMutatedNames, isSafeLazyJsxRef } from './scope'
|
|
7
9
|
import { collectPatternNames, containsJsx, isJsxNode, unwrapParens, unwrapTsExpr } from './shared'
|
|
8
10
|
|
|
9
|
-
function isReactiveDefault(node: Node, running: ReadonlyMap<string, string>): boolean {
|
|
10
|
-
if (running.size > 0 && referencesAny(node, new Set(running.keys())))
|
|
11
|
-
return true
|
|
12
|
-
let readsValue = false
|
|
13
|
-
walk(node, (child) => {
|
|
14
|
-
if (readsValue)
|
|
15
|
-
return false
|
|
16
|
-
if (child.type === 'ArrowFunctionExpression' || child.type === 'FunctionExpression' || child.type === 'FunctionDeclaration')
|
|
17
|
-
return false
|
|
18
|
-
if (child.type === 'MemberExpression' && !child.computed && child.property.type === 'Identifier' && child.property.name === 'value') {
|
|
19
|
-
readsValue = true
|
|
20
|
-
return false
|
|
21
|
-
}
|
|
22
|
-
return undefined
|
|
23
|
-
})
|
|
24
|
-
return readsValue
|
|
25
|
-
}
|
|
26
|
-
|
|
27
11
|
function patchParamDefaults(
|
|
28
12
|
param: Node | null | undefined,
|
|
29
13
|
rewrites: ReadonlyMap<string, string>,
|
|
@@ -135,13 +119,8 @@ export interface DestructuredParam {
|
|
|
135
119
|
typeAnn: string
|
|
136
120
|
}
|
|
137
121
|
|
|
138
|
-
export interface PropCompilerContext {
|
|
139
|
-
code: string
|
|
122
|
+
export interface PropCompilerContext extends PatternContext {
|
|
140
123
|
editor: SourceEditor
|
|
141
|
-
jsxNodes: WeakSet<Node>
|
|
142
|
-
use: (name: string) => string
|
|
143
|
-
freshVar: (prefix?: string) => string
|
|
144
|
-
compileExpression: (node: Node, rewrites: ReadonlyMap<string, string>) => string
|
|
145
124
|
}
|
|
146
125
|
|
|
147
126
|
export interface PropCompiler {
|
|
@@ -160,352 +139,354 @@ export interface PropCompiler {
|
|
|
160
139
|
processFunction: (fn: ArrowFunctionExpression | OxcFunction) => void
|
|
161
140
|
}
|
|
162
141
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
142
|
+
function extractDestructuredParam(code: string, firstParam: ParamPattern | undefined): DestructuredParam | undefined {
|
|
143
|
+
if (firstParam === undefined)
|
|
144
|
+
return undefined
|
|
145
|
+
if (firstParam.type === 'ObjectPattern') {
|
|
146
|
+
const typeAnn = firstParam.typeAnnotation ? code.slice(firstParam.typeAnnotation.start, firstParam.typeAnnotation.end) : ''
|
|
147
|
+
return { pattern: firstParam, defaultExpr: undefined, replaceStart: firstParam.start, replaceEnd: firstParam.end, typeAnn }
|
|
148
|
+
}
|
|
149
|
+
if (firstParam.type === 'AssignmentPattern' && firstParam.left.type === 'ObjectPattern') {
|
|
150
|
+
const pat = firstParam.left
|
|
151
|
+
const typeAnn = pat.typeAnnotation ? code.slice(pat.typeAnnotation.start, pat.typeAnnotation.end) : ''
|
|
152
|
+
return { pattern: pat, defaultExpr: firstParam.right, replaceStart: firstParam.start, replaceEnd: firstParam.end, typeAnn }
|
|
153
|
+
}
|
|
154
|
+
return undefined
|
|
155
|
+
}
|
|
176
156
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
nextSrc = `${hoist(`() => { const ${v} = ${src}; return ${v} === undefined ? ${fallback} : ${v}; }`)}()`
|
|
194
|
-
}
|
|
195
|
-
else {
|
|
196
|
-
nextSrc = `(${src} === undefined ? ${fallback} : ${src})`
|
|
197
|
-
}
|
|
198
|
-
bindPattern(pat.left, nextSrc)
|
|
199
|
-
return
|
|
200
|
-
}
|
|
201
|
-
if (pat.type === 'ObjectPattern') {
|
|
202
|
-
const excludedKeys: string[] = []
|
|
203
|
-
let canOmit = hoisted !== undefined
|
|
204
|
-
for (const prop of pat.properties) {
|
|
205
|
-
if (prop.type === 'RestElement') {
|
|
206
|
-
if (canOmit) {
|
|
207
|
-
const restRead = `${use('omit')}(${src}, [${excludedKeys.join(', ')}])`
|
|
208
|
-
bindPattern(prop.argument, restRead)
|
|
209
|
-
}
|
|
210
|
-
continue
|
|
211
|
-
}
|
|
212
|
-
let propSrc: string | undefined
|
|
213
|
-
if (!prop.computed && prop.key.type === 'Identifier') {
|
|
214
|
-
excludedKeys.push(JSON.stringify(prop.key.name))
|
|
215
|
-
propSrc = `${src}.${prop.key.name}`
|
|
216
|
-
}
|
|
217
|
-
else if (!prop.computed && prop.key.type === 'Literal' && (typeof prop.key.value === 'string' || typeof prop.key.value === 'number')) {
|
|
218
|
-
excludedKeys.push(JSON.stringify(String(prop.key.value)))
|
|
219
|
-
propSrc = `${src}[${JSON.stringify(prop.key.value)}]`
|
|
220
|
-
}
|
|
221
|
-
else if (prop.computed && hoisted !== undefined) {
|
|
222
|
-
const keyVar = hoist(compileExpression(prop.key, running))
|
|
223
|
-
excludedKeys.push(`typeof ${keyVar} === 'symbol' ? ${keyVar} : String(${keyVar})`)
|
|
224
|
-
propSrc = `${src}[${keyVar}]`
|
|
225
|
-
}
|
|
226
|
-
else {
|
|
227
|
-
canOmit = false
|
|
228
|
-
}
|
|
229
|
-
if (propSrc !== undefined)
|
|
230
|
-
bindPattern(prop.value, propSrc)
|
|
231
|
-
}
|
|
232
|
-
return
|
|
233
|
-
}
|
|
234
|
-
if (pat.type === 'ArrayPattern') {
|
|
235
|
-
for (let i = 0; i < pat.elements.length; i++) {
|
|
236
|
-
const el = pat.elements[i]
|
|
237
|
-
if (el == null)
|
|
238
|
-
continue
|
|
239
|
-
if (el.type === 'RestElement')
|
|
240
|
-
bindPattern(el.argument, `Array.from(${src}).slice(${i})`)
|
|
241
|
-
else
|
|
242
|
-
bindPattern(el, `${src}[${i}]`)
|
|
243
|
-
}
|
|
244
|
-
}
|
|
157
|
+
function computePropRewrites(
|
|
158
|
+
ctx: PropCompilerContext,
|
|
159
|
+
destructured: { pattern: ObjectPattern, defaultExpr: Node | undefined },
|
|
160
|
+
pVar: string,
|
|
161
|
+
outerRewrites: ReadonlyMap<string, string>,
|
|
162
|
+
body: Node | null,
|
|
163
|
+
): { rewrites: Map<string, string>, prelude: string } {
|
|
164
|
+
const rewrites = new Map(outerRewrites)
|
|
165
|
+
const hoisted: string[] = []
|
|
166
|
+
const propReads = patternReads(ctx, destructured.pattern, pVar, outerRewrites, hoisted)
|
|
167
|
+
const mutated = collectMutatedNames(body, new Set(propReads.keys()))
|
|
168
|
+
for (const [name, read] of propReads) {
|
|
169
|
+
if (mutated.has(name)) {
|
|
170
|
+
// A mutated destructured prop becomes a local `let` binding initialized once, avoiding invalid assignment targets like `(a === undefined ? b : a) = c`.
|
|
171
|
+
hoisted.push(`let ${name} = ${read};`)
|
|
172
|
+
rewrites.delete(name)
|
|
245
173
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
const compilePatternSource = (patNode: Node): string => {
|
|
250
|
-
const sub = new SourceEditor(code.slice(patNode.start, patNode.end))
|
|
251
|
-
const base = patNode.start
|
|
252
|
-
const patchPattern = (p: Node | null | undefined): void => {
|
|
253
|
-
if (p === null || p === undefined)
|
|
254
|
-
return
|
|
255
|
-
if ('typeAnnotation' in p && p.typeAnnotation != null) {
|
|
256
|
-
const ann = p.typeAnnotation as Node
|
|
257
|
-
sub.remove(ann.start - base, ann.end - base)
|
|
258
|
-
}
|
|
259
|
-
switch (p.type) {
|
|
260
|
-
case 'AssignmentPattern':
|
|
261
|
-
patchPattern(p.left)
|
|
262
|
-
sub.replace(p.right.start - base, p.right.end - base, compileExpression(p.right, outerRewrites))
|
|
263
|
-
return
|
|
264
|
-
case 'RestElement':
|
|
265
|
-
patchPattern(p.argument)
|
|
266
|
-
return
|
|
267
|
-
case 'ArrayPattern':
|
|
268
|
-
for (const el of p.elements)
|
|
269
|
-
patchPattern(el)
|
|
270
|
-
return
|
|
271
|
-
case 'ObjectPattern':
|
|
272
|
-
for (const prop of p.properties) {
|
|
273
|
-
if (prop.type === 'RestElement') {
|
|
274
|
-
patchPattern(prop.argument)
|
|
275
|
-
}
|
|
276
|
-
else {
|
|
277
|
-
if (prop.computed)
|
|
278
|
-
sub.replace(prop.key.start - base, prop.key.end - base, compileExpression(prop.key, outerRewrites))
|
|
279
|
-
patchPattern(prop.value)
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
patchPattern(patNode)
|
|
285
|
-
return sub.toString()
|
|
174
|
+
else {
|
|
175
|
+
rewrites.set(name, read)
|
|
286
176
|
}
|
|
177
|
+
}
|
|
178
|
+
return { rewrites, prelude: hoisted.join(' ') }
|
|
179
|
+
}
|
|
287
180
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
}
|
|
314
|
-
return reads
|
|
181
|
+
// Puts the hoisted default statements at the start of a body, giving an expression body a block to hold them.
|
|
182
|
+
function withPrelude(compiledBody: string, body: Node, prelude: string): string {
|
|
183
|
+
if (prelude === '')
|
|
184
|
+
return compiledBody
|
|
185
|
+
return body.type === 'BlockStatement' ? `{ ${prelude}${compiledBody.slice(1)}` : `{ ${prelude} return (${compiledBody}); }`
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function buildCompiledFunction(ctx: PropCompilerContext, fn: ArrowFunctionExpression | OxcFunction, outerRewrites: ReadonlyMap<string, string>): string {
|
|
189
|
+
const { code, freshVar, compileExpression } = ctx
|
|
190
|
+
const fnEditor = new SourceEditor(code.slice(fn.start, fn.end))
|
|
191
|
+
const offset = fn.start
|
|
192
|
+
const destructured = extractDestructuredParam(code, fn.params[0])
|
|
193
|
+
const pVar = freshVar('__p')
|
|
194
|
+
const baseRewrites = new Map(outerRewrites)
|
|
195
|
+
if (fn.type !== 'ArrowFunctionExpression' && fn.id !== null)
|
|
196
|
+
baseRewrites.delete(fn.id.name)
|
|
197
|
+
let propRewrites = baseRewrites
|
|
198
|
+
let prelude = ''
|
|
199
|
+
|
|
200
|
+
if (destructured !== undefined) {
|
|
201
|
+
const defSuffix = destructured.defaultExpr !== undefined
|
|
202
|
+
? ` = ${compileExpression(destructured.defaultExpr, baseRewrites)}`
|
|
203
|
+
: ''
|
|
204
|
+
fnEditor.replace(destructured.replaceStart - offset, destructured.replaceEnd - offset, `${pVar}${destructured.typeAnn}${defSuffix}`)
|
|
205
|
+
;({ rewrites: propRewrites, prelude } = computePropRewrites(ctx, destructured, pVar, baseRewrites, fn.body))
|
|
315
206
|
}
|
|
316
207
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
replaceEnd: number
|
|
322
|
-
typeAnn: string
|
|
323
|
-
} | undefined {
|
|
324
|
-
if (firstParam === undefined)
|
|
325
|
-
return undefined
|
|
326
|
-
if (firstParam.type === 'ObjectPattern') {
|
|
327
|
-
const typeAnn = firstParam.typeAnnotation ? code.slice(firstParam.typeAnnotation.start, firstParam.typeAnnotation.end) : ''
|
|
328
|
-
return { pattern: firstParam, defaultExpr: undefined, replaceStart: firstParam.start, replaceEnd: firstParam.end, typeAnn }
|
|
329
|
-
}
|
|
330
|
-
if (firstParam.type === 'AssignmentPattern' && firstParam.left.type === 'ObjectPattern') {
|
|
331
|
-
const pat = firstParam.left
|
|
332
|
-
const typeAnn = pat.typeAnnotation ? code.slice(pat.typeAnnotation.start, pat.typeAnnotation.end) : ''
|
|
333
|
-
return { pattern: pat, defaultExpr: firstParam.right, replaceStart: firstParam.start, replaceEnd: firstParam.end, typeAnn }
|
|
334
|
-
}
|
|
335
|
-
return undefined
|
|
208
|
+
for (let i = 1; i < fn.params.length; i++) {
|
|
209
|
+
const extraParam = fn.params[i]!
|
|
210
|
+
patchParamDefaults(extraParam, propRewrites, fnEditor, offset, compileExpression)
|
|
211
|
+
propRewrites = withoutBindings(propRewrites, [extraParam])
|
|
336
212
|
}
|
|
337
213
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
214
|
+
if (fn.body !== null)
|
|
215
|
+
fnEditor.replace(fn.body.start - offset, fn.body.end - offset, withPrelude(compileExpression(fn.body, propRewrites), fn.body, prelude))
|
|
216
|
+
return fnEditor.toString()
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// Compiles each statement of a component body with the prop reads active, deferring a JSX-valued `const` that only JSX slots read.
|
|
220
|
+
function compileBodyStatements(ctx: PropCompilerContext, body: Extract<Node, { type: 'BlockStatement' }>, propRewrites: Map<string, string>): void {
|
|
221
|
+
const { editor, jsxNodes, compileExpression } = ctx
|
|
222
|
+
const shadowed = new Set<string>()
|
|
223
|
+
for (const stmt of body.body) {
|
|
224
|
+
if (stmt.type === 'FunctionDeclaration' && stmt.id !== null)
|
|
225
|
+
shadowed.add(stmt.id.name)
|
|
226
|
+
else if (stmt.type === 'ClassDeclaration' && stmt.id !== null)
|
|
227
|
+
shadowed.add(stmt.id.name)
|
|
228
|
+
}
|
|
229
|
+
const stmts = body.body
|
|
230
|
+
for (let i = 0; i < stmts.length; i++) {
|
|
231
|
+
const stmt = stmts[i]!
|
|
232
|
+
const active = new Map<string, string>()
|
|
233
|
+
for (const [k, v] of propRewrites) {
|
|
234
|
+
if (!shadowed.has(k))
|
|
235
|
+
active.set(k, v)
|
|
236
|
+
}
|
|
237
|
+
// Defer `const badge = <span />` to `const badge = () => _t0()` when only used in JSX slots so SSR hydration claims the outer element before the slot's nodes.
|
|
238
|
+
if (
|
|
239
|
+
stmt.type === 'VariableDeclaration' && stmt.kind === 'const' && stmt.declarations.length === 1
|
|
240
|
+
&& stmt.declarations[0]!.id.type === 'Identifier' && stmt.declarations[0]!.init !== null
|
|
241
|
+
) {
|
|
242
|
+
const decl = stmt.declarations[0]!
|
|
243
|
+
const jsxInit = unwrapParens(decl.init!)
|
|
244
|
+
const varName = (decl.id as Extract<Node, { type: 'Identifier' }>).name
|
|
245
|
+
if (isJsxNode(jsxInit) && isSafeLazyJsxRef(varName, stmts.slice(i + 1))) {
|
|
246
|
+
editor.replace(stmt.start, stmt.end, `const ${varName} = () => ${compileExpression(jsxInit, active)};`)
|
|
247
|
+
propRewrites.set(varName, `${varName}()`)
|
|
248
|
+
shadowed.delete(varName)
|
|
249
|
+
continue
|
|
356
250
|
}
|
|
357
251
|
}
|
|
358
|
-
|
|
252
|
+
if (active.size > 0 || containsJsx(stmt, jsxNodes))
|
|
253
|
+
editor.replace(stmt.start, stmt.end, compileExpression(stmt, active))
|
|
254
|
+
if (stmt.type === 'VariableDeclaration') {
|
|
255
|
+
for (const d of stmt.declarations)
|
|
256
|
+
collectPatternNames(d.id, shadowed)
|
|
257
|
+
}
|
|
359
258
|
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// Handle top-level component functions with destructured props + JSX compilation
|
|
262
|
+
function processFunction(ctx: PropCompilerContext, fn: ArrowFunctionExpression | OxcFunction): void {
|
|
263
|
+
const { code, editor, jsxNodes, compileExpression } = ctx
|
|
264
|
+
if (fn.body === null || !containsJsx(fn.body, jsxNodes))
|
|
265
|
+
return
|
|
360
266
|
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
267
|
+
const destructured = extractDestructuredParam(code, fn.params[0])
|
|
268
|
+
let propRewrites = new Map<string, string>()
|
|
269
|
+
let prelude = ''
|
|
270
|
+
|
|
271
|
+
if (destructured !== undefined) {
|
|
272
|
+
const pVar = code.includes('__p') ? ctx.freshVar('__p') : '__p'
|
|
273
|
+
const defSuffix = destructured.defaultExpr !== undefined
|
|
274
|
+
? ` = ${compileExpression(destructured.defaultExpr, new Map())}`
|
|
275
|
+
: ''
|
|
276
|
+
editor.replace(destructured.replaceStart, destructured.replaceEnd, `${pVar}${destructured.typeAnn}${defSuffix}`)
|
|
277
|
+
;({ rewrites: propRewrites, prelude } = computePropRewrites(ctx, destructured, pVar, new Map(), fn.body))
|
|
366
278
|
}
|
|
367
279
|
|
|
368
|
-
|
|
369
|
-
const
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
const baseRewrites = new Map(outerRewrites)
|
|
374
|
-
if (fn.type !== 'ArrowFunctionExpression' && fn.id !== null)
|
|
375
|
-
baseRewrites.delete(fn.id.name)
|
|
376
|
-
let propRewrites = baseRewrites
|
|
377
|
-
let prelude = ''
|
|
378
|
-
|
|
379
|
-
if (destructured !== undefined) {
|
|
380
|
-
const defSuffix = destructured.defaultExpr !== undefined
|
|
381
|
-
? ` = ${compileExpression(destructured.defaultExpr, baseRewrites)}`
|
|
382
|
-
: ''
|
|
383
|
-
fnEditor.replace(destructured.replaceStart - offset, destructured.replaceEnd - offset, `${pVar}${destructured.typeAnn}${defSuffix}`)
|
|
384
|
-
;({ rewrites: propRewrites, prelude } = computePropRewrites(destructured, pVar, baseRewrites, fn.body))
|
|
385
|
-
}
|
|
280
|
+
for (let i = 1; i < fn.params.length; i++) {
|
|
281
|
+
const extraParam = fn.params[i]!
|
|
282
|
+
patchParamDefaults(extraParam, propRewrites, editor, 0, compileExpression)
|
|
283
|
+
propRewrites = withoutBindings(propRewrites, [extraParam])
|
|
284
|
+
}
|
|
386
285
|
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
286
|
+
const hasLazyJsxDecl = fn.body.type === 'BlockStatement' && fn.body.body.some(s =>
|
|
287
|
+
s.type === 'VariableDeclaration' && s.kind === 'const' && s.declarations.length === 1
|
|
288
|
+
&& s.declarations[0]!.id.type === 'Identifier' && s.declarations[0]!.init !== null
|
|
289
|
+
&& isJsxNode(unwrapParens(s.declarations[0]!.init)),
|
|
290
|
+
)
|
|
392
291
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
292
|
+
if ((propRewrites.size > 0 || hasLazyJsxDecl) && fn.body.type === 'BlockStatement') {
|
|
293
|
+
if (prelude !== '')
|
|
294
|
+
editor.replace(fn.body.start + 1, fn.body.start + 1, ` ${prelude}`)
|
|
295
|
+
compileBodyStatements(ctx, fn.body, propRewrites)
|
|
396
296
|
}
|
|
297
|
+
else {
|
|
298
|
+
editor.replace(fn.body.start, fn.body.end, withPrelude(compileExpression(fn.body, propRewrites), fn.body, prelude))
|
|
299
|
+
}
|
|
300
|
+
}
|
|
397
301
|
|
|
398
|
-
|
|
399
|
-
function processFunction(fn: ArrowFunctionExpression | OxcFunction): void {
|
|
400
|
-
if (fn.body === null || !containsJsx(fn.body, jsxNodes))
|
|
401
|
-
return
|
|
302
|
+
type LoopRowOptions = Parameters<PropCompiler['compileLoopRow']>[0]
|
|
402
303
|
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
: ''
|
|
412
|
-
editor.replace(destructured.replaceStart, destructured.replaceEnd, `${pVar}${destructured.typeAnn}${defSuffix}`)
|
|
413
|
-
;({ rewrites: propRewrites, prelude } = computePropRewrites(destructured, pVar, new Map(), fn.body))
|
|
414
|
-
}
|
|
304
|
+
interface PendingKeyBind {
|
|
305
|
+
paramName: string | undefined
|
|
306
|
+
keyIdent: string | undefined
|
|
307
|
+
propName: string
|
|
308
|
+
expr: string
|
|
309
|
+
keyVar: string
|
|
310
|
+
basePrelude: string
|
|
311
|
+
}
|
|
415
312
|
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
313
|
+
const PLAIN_IDENT_RE = /^[A-Za-z_$][\w$]*$/
|
|
314
|
+
const IDENT_CHAR_RE = /[\w$]/
|
|
315
|
+
const ASSIGN_AFTER_RE = /^\s*(?:[+\-*/%&|^]|<<|>>|>>>|\*\*|&&|\|\||\?\?)?=(?![=>])/
|
|
316
|
+
const UPDATE_AFTER_RE = /^\s*(?:\+\+|--)/
|
|
317
|
+
const CALL_AFTER_RE = /^\s*(?:\?\.\s*)?[(`]/
|
|
318
|
+
const UPDATE_BEFORE_RE = /(?:\+\+|--)\s*$/
|
|
319
|
+
const DELETE_BEFORE_RE = /\bdelete\s+$/
|
|
421
320
|
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
if (stmt.type === 'VariableDeclaration') {
|
|
464
|
-
for (const d of stmt.declarations)
|
|
465
|
-
collectPatternNames(d.id, shadowed)
|
|
466
|
-
}
|
|
467
|
-
}
|
|
321
|
+
function extractInvariantKeyBind(
|
|
322
|
+
firstParam: ParamPattern | undefined,
|
|
323
|
+
keyAst: Node | undefined,
|
|
324
|
+
rowSig: string,
|
|
325
|
+
rowRewrites: ReadonlyMap<string, string>,
|
|
326
|
+
): Omit<PendingKeyBind, 'keyVar' | 'basePrelude'> | undefined {
|
|
327
|
+
if (keyAst === undefined)
|
|
328
|
+
return undefined
|
|
329
|
+
const keyNode = unwrapTsExpr(keyAst)
|
|
330
|
+
if (firstParam?.type === 'Identifier') {
|
|
331
|
+
if (keyNode.type !== 'MemberExpression' || keyNode.computed || keyNode.optional || keyNode.property.type !== 'Identifier')
|
|
332
|
+
return undefined
|
|
333
|
+
const obj = unwrapTsExpr(keyNode.object)
|
|
334
|
+
if (obj.type !== 'Identifier' || obj.name !== firstParam.name)
|
|
335
|
+
return undefined
|
|
336
|
+
const propName = keyNode.property.name
|
|
337
|
+
return { paramName: firstParam.name, keyIdent: undefined, propName, expr: `${rowSig}.value.${propName}` }
|
|
338
|
+
}
|
|
339
|
+
if (firstParam?.type === 'ObjectPattern' && keyNode.type === 'Identifier') {
|
|
340
|
+
const prefix = `${rowSig}.value.`
|
|
341
|
+
const read = rowRewrites.get(keyNode.name)
|
|
342
|
+
if (read === undefined || !read.startsWith(prefix))
|
|
343
|
+
return undefined
|
|
344
|
+
const propName = read.slice(prefix.length)
|
|
345
|
+
if (!PLAIN_IDENT_RE.test(propName))
|
|
346
|
+
return undefined
|
|
347
|
+
return { paramName: undefined, keyIdent: keyNode.name, propName, expr: read }
|
|
348
|
+
}
|
|
349
|
+
return undefined
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
function targetTouchesProp(target: Node | null | undefined, propName: string): boolean {
|
|
353
|
+
if (target === null || target === undefined)
|
|
354
|
+
return false
|
|
355
|
+
let found = false
|
|
356
|
+
walk(target, (node) => {
|
|
357
|
+
if (found)
|
|
358
|
+
return false
|
|
359
|
+
if (node.type === 'MemberExpression' && !node.computed && node.property.type === 'Identifier' && node.property.name === propName) {
|
|
360
|
+
found = true
|
|
361
|
+
return false
|
|
468
362
|
}
|
|
469
|
-
|
|
470
|
-
|
|
363
|
+
return undefined
|
|
364
|
+
})
|
|
365
|
+
return found
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
function hasKeyMutation(body: Node, bind: PendingKeyBind): boolean {
|
|
369
|
+
const watched = new Set<string>()
|
|
370
|
+
if (bind.paramName !== undefined)
|
|
371
|
+
watched.add(bind.paramName)
|
|
372
|
+
if (bind.keyIdent !== undefined)
|
|
373
|
+
watched.add(bind.keyIdent)
|
|
374
|
+
if (collectMutatedNames(body, watched).size > 0)
|
|
375
|
+
return true
|
|
376
|
+
let mutated = false
|
|
377
|
+
walk(body, (node) => {
|
|
378
|
+
if (mutated)
|
|
379
|
+
return false
|
|
380
|
+
if (node.type === 'AssignmentExpression' && targetTouchesProp(node.left, bind.propName))
|
|
381
|
+
mutated = true
|
|
382
|
+
else if (node.type === 'UpdateExpression' && targetTouchesProp(node.argument, bind.propName))
|
|
383
|
+
mutated = true
|
|
384
|
+
else if (node.type === 'UnaryExpression' && node.operator === 'delete' && targetTouchesProp(node.argument, bind.propName))
|
|
385
|
+
mutated = true
|
|
386
|
+
else if ((node.type === 'ForInStatement' || node.type === 'ForOfStatement') && targetTouchesProp(node.left, bind.propName))
|
|
387
|
+
mutated = true
|
|
388
|
+
return mutated ? false : undefined
|
|
389
|
+
})
|
|
390
|
+
return mutated
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
function rewriteInvariantKeyReads(compiledBody: string, expr: string, keyVar: string): { code: string, replaced: number } {
|
|
394
|
+
const len = expr.length
|
|
395
|
+
let out = ''
|
|
396
|
+
let last = 0
|
|
397
|
+
let pos = 0
|
|
398
|
+
let replaced = 0
|
|
399
|
+
while ((pos = compiledBody.indexOf(expr, pos)) !== -1) {
|
|
400
|
+
const before = pos > 0 ? compiledBody[pos - 1]! : ''
|
|
401
|
+
const after = pos + len < compiledBody.length ? compiledBody[pos + len]! : ''
|
|
402
|
+
const tail = compiledBody.slice(pos + len)
|
|
403
|
+
const head = compiledBody.slice(Math.max(0, pos - 16), pos)
|
|
404
|
+
const blocked = (before !== '' && (IDENT_CHAR_RE.test(before) || before === '.'))
|
|
405
|
+
|| (after !== '' && IDENT_CHAR_RE.test(after))
|
|
406
|
+
|| ASSIGN_AFTER_RE.test(tail)
|
|
407
|
+
|| UPDATE_AFTER_RE.test(tail)
|
|
408
|
+
|| CALL_AFTER_RE.test(tail)
|
|
409
|
+
|| UPDATE_BEFORE_RE.test(head)
|
|
410
|
+
|| DELETE_BEFORE_RE.test(head)
|
|
411
|
+
if (!blocked) {
|
|
412
|
+
out += compiledBody.slice(last, pos) + keyVar
|
|
413
|
+
last = pos + len
|
|
414
|
+
replaced++
|
|
471
415
|
}
|
|
416
|
+
pos += len
|
|
472
417
|
}
|
|
418
|
+
return replaced > 0 ? { code: out + compiledBody.slice(last), replaced } : { code: compiledBody, replaced: 0 }
|
|
419
|
+
}
|
|
473
420
|
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
}
|
|
497
|
-
for (const [name, read] of patternReads(firstParam, `${rowSig}.value`, scopeRewrites, hoisted))
|
|
498
|
-
rowRewrites.set(name, read)
|
|
421
|
+
function formatLoopBody(compiledBody: string, body: Node, prelude: string): string {
|
|
422
|
+
if (body.type === 'JSXElement' && compiledBody.startsWith('(() => { ') && compiledBody.endsWith(' })()'))
|
|
423
|
+
return prelude === '' ? compiledBody.slice(7, -3) : `{ ${prelude} ${compiledBody.slice(9, -3)}`
|
|
424
|
+
return withPrelude(compiledBody, body, prelude)
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
function compileLoopRow(
|
|
428
|
+
ctx: PropCompilerContext,
|
|
429
|
+
opts: LoopRowOptions,
|
|
430
|
+
pendingKeyBinds: Map<string, PendingKeyBind>,
|
|
431
|
+
): { keyFn: string, rowRewrites: Map<string, string>, prelude: string } {
|
|
432
|
+
const { freshVar, compileExpression } = ctx
|
|
433
|
+
const { firstParam, idxParam, keyAst, rowSig, scopeRewrites, keyRewrites } = opts
|
|
434
|
+
const rowRewrites = new Map(scopeRewrites)
|
|
435
|
+
const hoisted: string[] = []
|
|
436
|
+
let keyFn: string
|
|
437
|
+
if (firstParam !== undefined && firstParam.type !== 'Identifier') {
|
|
438
|
+
if (keyAst !== undefined) {
|
|
439
|
+
const keyItem = freshVar('_item')
|
|
440
|
+
const keyScope = new Map(keyRewrites)
|
|
441
|
+
for (const [name, read] of patternReads(ctx, firstParam, keyItem, scopeRewrites))
|
|
442
|
+
keyScope.set(name, read)
|
|
443
|
+
keyFn = `(${keyItem}${idxParam ? `, ${idxParam}` : ''}) => ${compileExpression(keyAst, keyScope)}`
|
|
499
444
|
}
|
|
500
445
|
else {
|
|
501
|
-
|
|
502
|
-
keyFn = keyAst !== undefined
|
|
503
|
-
? `(${itemParam}${idxParam ? `, ${idxParam}` : ''}) => ${compileExpression(keyAst, keyRewrites)}`
|
|
504
|
-
: `(${itemParam}) => ${itemParam}`
|
|
505
|
-
rowRewrites.set(itemParam, `${rowSig}.value`)
|
|
446
|
+
keyFn = `(_item) => _item`
|
|
506
447
|
}
|
|
507
|
-
|
|
448
|
+
for (const [name, read] of patternReads(ctx, firstParam, `${rowSig}.value`, scopeRewrites, hoisted))
|
|
449
|
+
rowRewrites.set(name, read)
|
|
450
|
+
}
|
|
451
|
+
else {
|
|
452
|
+
const itemParam = firstParam?.type === 'Identifier' ? firstParam.name : '_item'
|
|
453
|
+
keyFn = keyAst !== undefined
|
|
454
|
+
? `(${itemParam}${idxParam ? `, ${idxParam}` : ''}) => ${compileExpression(keyAst, keyRewrites)}`
|
|
455
|
+
: `(${itemParam}) => ${itemParam}`
|
|
456
|
+
rowRewrites.set(itemParam, `${rowSig}.value`)
|
|
508
457
|
}
|
|
458
|
+
const basePrelude = hoisted.join(' ')
|
|
459
|
+
const keyBind = extractInvariantKeyBind(firstParam, keyAst, rowSig, rowRewrites)
|
|
460
|
+
if (keyBind !== undefined) {
|
|
461
|
+
const keyVar = freshVar('_k')
|
|
462
|
+
hoisted.push(`const ${keyVar} = ${rowSig}.peek().${keyBind.propName};`)
|
|
463
|
+
const prelude = hoisted.join(' ')
|
|
464
|
+
pendingKeyBinds.set(prelude, { ...keyBind, keyVar, basePrelude })
|
|
465
|
+
return { keyFn, rowRewrites, prelude }
|
|
466
|
+
}
|
|
467
|
+
return { keyFn, rowRewrites, prelude: basePrelude }
|
|
468
|
+
}
|
|
509
469
|
|
|
510
|
-
|
|
470
|
+
export function createPropCompiler(ctx: PropCompilerContext): PropCompiler {
|
|
471
|
+
const pendingKeyBinds = new Map<string, PendingKeyBind>()
|
|
472
|
+
return {
|
|
473
|
+
patternReads: (pattern, source, outerRewrites, hoisted) => patternReads(ctx, pattern, source, outerRewrites, hoisted),
|
|
474
|
+
compileLoopRow: opts => compileLoopRow(ctx, opts, pendingKeyBinds),
|
|
475
|
+
withPrelude: (compiledBody, body, prelude) => {
|
|
476
|
+
const bind = pendingKeyBinds.get(prelude)
|
|
477
|
+
if (bind !== undefined) {
|
|
478
|
+
pendingKeyBinds.delete(prelude)
|
|
479
|
+
if (!hasKeyMutation(body, bind)) {
|
|
480
|
+
const rewritten = rewriteInvariantKeyReads(compiledBody, bind.expr, bind.keyVar)
|
|
481
|
+
if (rewritten.replaced > 0)
|
|
482
|
+
return formatLoopBody(rewritten.code, body, prelude)
|
|
483
|
+
}
|
|
484
|
+
return formatLoopBody(compiledBody, body, bind.basePrelude)
|
|
485
|
+
}
|
|
486
|
+
return formatLoopBody(compiledBody, body, prelude)
|
|
487
|
+
},
|
|
488
|
+
extractDestructuredParam: firstParam => extractDestructuredParam(ctx.code, firstParam),
|
|
489
|
+
buildCompiledFunction: (fn, outerRewrites) => buildCompiledFunction(ctx, fn, outerRewrites),
|
|
490
|
+
processFunction: fn => processFunction(ctx, fn),
|
|
491
|
+
}
|
|
511
492
|
}
|