@kudzujs/core 0.6.12 → 0.6.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/framework/README.md +1 -1
- package/framework/build.mjs +49 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -190,7 +190,7 @@ function Controls({ dispatch }: { dispatch: Dispatch<TodoAction> }) {
|
|
|
190
190
|
return <Controls dispatch={dispatch} />
|
|
191
191
|
```
|
|
192
192
|
|
|
193
|
-
Kudzu specializes that call at build time; no function prop or child component survives in the browser. Lazy initializers, package, namespace, local, async, and generator reducers,
|
|
193
|
+
Kudzu specializes that call at build time; no function prop or child component survives in the browser. Relative TypeScript constants and helpers used inside the child handler are renamed for call-site safety and bundled into the parent handler graph. Lazy initializers, package, namespace, local, async, and generator reducers, package imports or child imports used outside event handlers, forwarding across another component, and reducer dispatch through context remain unsupported.
|
|
194
194
|
|
|
195
195
|
## Reactive Attributes
|
|
196
196
|
|
package/framework/README.md
CHANGED
|
@@ -25,7 +25,7 @@ Inline SVG rendering normalizes an explicit set of common React presentation ali
|
|
|
25
25
|
|
|
26
26
|
Same-file and relative-imported components receiving a direct local-state array prop are specialized to intrinsic JSX before keyed-list analysis, so their component function is not retained in the browser. Handler modules are emitted only when a rendered descriptor references them, preventing specialized imported components from adding dead browser assets. Direct JSON-safe primitive keyed-item dependencies subscribe each row record to its owning list commit and compare selected fields after `list-runtime.js` synchronously refreshes the row marker. Only changed rows rerun with the complete latest item; reorder compares equal, unrelated fields do nothing, and key changes remain remove plus mount. Builds without item dependencies emit no item reader or list-state subscription code.
|
|
27
27
|
|
|
28
|
-
The reduced `useReducer` form reuses ordinary state slots. A direct dispatch in a compiled handler becomes a functional `set` whose reducer is bundled from a relative TypeScript module into that handler graph. One direct dispatch prop into a same-file or relative-imported synchronous component is specialized to intrinsic JSX at the call site, so its handler retains the parent reducer scope and no dispatch capture or child handler asset is emitted. Reducer-free routes and shared runtimes are unchanged; no reducer runtime or browser component instance exists.
|
|
28
|
+
The reduced `useReducer` form reuses ordinary state slots. A direct dispatch in a compiled handler becomes a functional `set` whose reducer is bundled from a relative TypeScript module into that handler graph. One direct dispatch prop into a same-file or relative-imported synchronous component is specialized to intrinsic JSX at the call site, so its handler retains the parent reducer scope and no dispatch capture or child handler asset is emitted. Relative TypeScript imports referenced inside that child handler receive collision-free call-site aliases and join the parent handler graph. Reducer-free routes and shared runtimes are unchanged; no reducer runtime or browser component instance exists.
|
|
29
29
|
|
|
30
30
|
`kudzu.config` may opt one emitted shared-layout group into same-document navigation with legacy `navigation: { routes: ["/product", "/items/[id]"] }`, or multiple groups with `navigation: { groups: [{ routes: [...] }, { routes: [...] }] }`. The forms are mutually exclusive. Identities are globally unique emitted exact paths or `runtimeParams` patterns; each group uses one page-exported layout function identity. Runtime records securely match concrete pathnames under `base`, and their cache-safe parameter initializer runs before route DOM/effects mount on every transition. Each group receives a deterministic route-hashed asset specialized to only its records, pattern decoder, and effect/parameter lifecycle needs. Cross-group and ungrouped anchors remain native and are not prefetched; overlapping path domains across groups fail the build. Route effect entries export cache-safe layout and route mount functions: layout effects, including conditional/keyed DOM-owned effects, persist for the group session; route effects receive a fresh owner registry after each route insertion; and non-persisted page disposal cleans route before layout. Direct primitive state, runtime parameter, and keyed-item property dependencies and cleanup are supported. Fragment payloads and coordinated View Transitions are not implemented.
|
|
31
31
|
|
package/framework/build.mjs
CHANGED
|
@@ -1738,6 +1738,7 @@ function createKudzuTransformer(nativeHandlers, effectHandlers, reactiveBindings
|
|
|
1738
1738
|
const specializedDeclarations = new WeakSet()
|
|
1739
1739
|
const stateBackedComponentFunctions = new WeakSet()
|
|
1740
1740
|
const stateBackedComponentRoots = []
|
|
1741
|
+
let specializedImportIndex = 0
|
|
1741
1742
|
for (const [name, component] of components) {
|
|
1742
1743
|
const calls = jsxTagUses(sourceFile, name)
|
|
1743
1744
|
const stateBackedCalls = calls.filter(call => isStateBackedListComponentCall(call, component.function, settersByFunction.get(nearestFunction(call)) ?? new Map()))
|
|
@@ -1802,11 +1803,29 @@ function createKudzuTransformer(nativeHandlers, effectHandlers, reactiveBindings
|
|
|
1802
1803
|
fail(dispatchCalls[0], `Reducer dispatch props require a component imported from a relative TypeScript module`)
|
|
1803
1804
|
}
|
|
1804
1805
|
const componentSource = component.getSourceFile()
|
|
1805
|
-
|
|
1806
|
+
const componentImports = clientImportBindings(componentSource, componentSource.fileName, sourceFiles)
|
|
1807
|
+
const packageImports = runtimeImportNames(componentSource, false)
|
|
1806
1808
|
for (const call of dispatchCalls) {
|
|
1807
1809
|
if (componentSpecializations.has(call)) fail(call, "Reducer dispatch props cannot be combined with another component specialization")
|
|
1808
1810
|
const specialization = specializeComponentCall(call, component, sourceFile, factory, context, fail, "Reducer-dispatch")
|
|
1809
1811
|
if (specialization.effects.length) fail(call, "Reducer-dispatch components cannot declare effects")
|
|
1812
|
+
for (const name of packageImports) if (referenceIdentifiers(specialization.root, name).length) fail(call, "Imported reducer-dispatch component handlers may only use relative TypeScript runtime imports")
|
|
1813
|
+
const substitutions = new Map()
|
|
1814
|
+
for (const [name, entry] of componentImports) {
|
|
1815
|
+
const references = referenceIdentifiers(specialization.root, name)
|
|
1816
|
+
if (!references.length) continue
|
|
1817
|
+
if (references.some(reference => !insideJsxEventHandler(reference, specialization.root))) fail(call, `Imported reducer-dispatch component runtime import "${name}" may only be used inside event handlers`)
|
|
1818
|
+
let local
|
|
1819
|
+
do local = `__kDispatchImport${specializedImportIndex++}`
|
|
1820
|
+
while (importBindings.has(local))
|
|
1821
|
+
substitutions.set(name, factory.createIdentifier(local))
|
|
1822
|
+
importBindings.set(local, { ...entry, local })
|
|
1823
|
+
}
|
|
1824
|
+
if (substitutions.size) {
|
|
1825
|
+
specialization.root = substituteClone(specialization.root, substitutions, factory, context)
|
|
1826
|
+
ts.setParentRecursive(specialization.root, false)
|
|
1827
|
+
specialization.root.parent = call.parent
|
|
1828
|
+
}
|
|
1810
1829
|
synthesizeTree(specialization.root)
|
|
1811
1830
|
componentSpecializations.set(call, specialization)
|
|
1812
1831
|
}
|
|
@@ -2304,6 +2323,35 @@ function jsxCallHasDirectReducerProp(call, reducers) {
|
|
|
2304
2323
|
})
|
|
2305
2324
|
}
|
|
2306
2325
|
|
|
2326
|
+
function runtimeImportNames(sourceFile, relative) {
|
|
2327
|
+
const names = new Set()
|
|
2328
|
+
for (const statement of sourceFile.statements) {
|
|
2329
|
+
if (!ts.isImportDeclaration(statement) || !statement.importClause || statement.importClause.isTypeOnly || !ts.isStringLiteral(statement.moduleSpecifier) || statement.moduleSpecifier.text.startsWith(".") !== relative) continue
|
|
2330
|
+
const clause = statement.importClause
|
|
2331
|
+
if (clause.name) names.add(clause.name.text)
|
|
2332
|
+
if (clause.namedBindings && ts.isNamespaceImport(clause.namedBindings)) names.add(clause.namedBindings.name.text)
|
|
2333
|
+
if (clause.namedBindings && ts.isNamedImports(clause.namedBindings)) for (const entry of clause.namedBindings.elements) if (!entry.isTypeOnly) names.add(entry.name.text)
|
|
2334
|
+
}
|
|
2335
|
+
return names
|
|
2336
|
+
}
|
|
2337
|
+
|
|
2338
|
+
function referenceIdentifiers(root, name) {
|
|
2339
|
+
const references = []
|
|
2340
|
+
const visit = node => {
|
|
2341
|
+
if (ts.isIdentifier(node) && node.text === name && isReferenceIdentifier(node) && !isShadowedIdentifier(node, root)) references.push(node)
|
|
2342
|
+
ts.forEachChild(node, visit)
|
|
2343
|
+
}
|
|
2344
|
+
visit(root)
|
|
2345
|
+
return references
|
|
2346
|
+
}
|
|
2347
|
+
|
|
2348
|
+
function insideJsxEventHandler(node, root) {
|
|
2349
|
+
for (let current = node.parent; current && current !== root.parent; current = current.parent) {
|
|
2350
|
+
if (ts.isJsxAttribute(current) && /^on[A-Z]/.test(current.name.text)) return true
|
|
2351
|
+
}
|
|
2352
|
+
return false
|
|
2353
|
+
}
|
|
2354
|
+
|
|
2307
2355
|
function validateKeyedList(parts, sourceFile, listValues, listEventItems, listConditions) {
|
|
2308
2356
|
const fail = (node, message) => {
|
|
2309
2357
|
throw sourceNodeError(node, sourceFile, message)
|