jq79 0.7.12 → 0.7.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/dist/jq79-sw.js +1 -1
- package/dist/jq79.cjs +14 -14
- package/dist/jq79.cjs.map +1 -1
- package/dist/jq79.global.js +14 -14
- package/dist/jq79.global.js.map +1 -1
- package/dist/jq79.js +14 -14
- package/dist/jq79.js.map +1 -1
- package/dist/precompile.cjs +1 -1
- package/dist/precompile.cjs.map +1 -1
- package/dist/precompile.js +1 -1
- package/dist/precompile.js.map +1 -1
- package/dist/source.d.ts +1 -1
- package/package.json +1 -1
- package/src/jq79.ts +38 -6
- package/src/source.ts +7 -2
package/dist/source.d.ts
CHANGED
|
@@ -57,7 +57,7 @@ export declare const setupBody: (code: string) => string;
|
|
|
57
57
|
export declare const factoryParams: (helperNames: string[]) => string[];
|
|
58
58
|
export declare const factoryBody: (code: string) => string;
|
|
59
59
|
export declare const readSetupSignature: (script: TagBlock) => PropDecl[] | null;
|
|
60
|
-
export declare const declaredPropNames: (scripts: TagBlock[], signature: (script: TagBlock) => PropDecl[] | null) => Set<string>;
|
|
60
|
+
export declare const declaredPropNames: (scripts: TagBlock[], signature: (script: TagBlock) => PropDecl[] | null, factoryProps?: (src: string) => PropDecl[] | null) => Set<string>;
|
|
61
61
|
export declare const SETUP_HELPER_NAMES: string[];
|
|
62
62
|
export declare const INSTANCE_HELPER_NAMES: string[];
|
|
63
63
|
export declare const PRECOMPILED_QUEUE = "__jq79precompiled";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jq79",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.13",
|
|
4
4
|
"description": "Mini reactive component library: single-file .html components, Svelte-style setup scripts, fine-grained proxy reactivity. No compiler, no bundler, no dependencies — works from any static host.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"reactive",
|
package/src/jq79.ts
CHANGED
|
@@ -3887,8 +3887,40 @@ const declareProps = (store: Record<string, any>, props: PropDecl[] | null) => {
|
|
|
3887
3887
|
// Only the empty *value* is closed. An absent attribute (a factory <script>
|
|
3888
3888
|
// with no :setup at all) stays `null`, so its signature is still read from the
|
|
3889
3889
|
// factory's first parameter
|
|
3890
|
+
// What a script's text compiles to, memoized by that text. Every instance of a
|
|
3891
|
+
// definition runs the same scripts, and these passes are pure functions of the
|
|
3892
|
+
// string - re-running them per instance was most of a list's render time. The
|
|
3893
|
+
// values are shared, so the arrays are frozen on the way in. A throw (the
|
|
3894
|
+
// pre-0.4 factory signature) is not cached: it rethrows on every render, as it
|
|
3895
|
+
// always did. Kept here, not in transform.ts, because the editor's language
|
|
3896
|
+
// server re-reads a script on every keystroke and would grow a map per edit.
|
|
3897
|
+
// See RECORD/2026-11-15.cache-script-transforms.md
|
|
3898
|
+
const memoByText = <T>(fn: (src: string) => T): ((src: string) => T) => {
|
|
3899
|
+
const cache = new Map<string, T>()
|
|
3900
|
+
return src => {
|
|
3901
|
+
if (cache.has(src)) return cache.get(src)!
|
|
3902
|
+
const value = fn(src)
|
|
3903
|
+
cache.set(src, value)
|
|
3904
|
+
return value
|
|
3905
|
+
}
|
|
3906
|
+
}
|
|
3907
|
+
const freezeProps = (props: PropDecl[] | null): PropDecl[] | null => {
|
|
3908
|
+
props?.forEach(prop => Object.freeze(prop))
|
|
3909
|
+
if (props) Object.freeze(props)
|
|
3910
|
+
return props
|
|
3911
|
+
}
|
|
3912
|
+
const factoryCodeOf = memoByText(transformFactoryScript)
|
|
3913
|
+
const factoryPropsOf = memoByText(src => freezeProps(parseFactoryProps(src)))
|
|
3914
|
+
const setupTransformOf = memoByText(src => {
|
|
3915
|
+
const transform = transformSetupScript(src)
|
|
3916
|
+
Object.freeze(transform.vars)
|
|
3917
|
+
return Object.freeze(transform)
|
|
3918
|
+
})
|
|
3919
|
+
const signatureOf = memoByText(src => freezeProps(readSetupSignature({ attrs: { ":setup": src }, content: "" })))
|
|
3920
|
+
|
|
3890
3921
|
const setupSignature = (script: TagBlock): PropDecl[] | null => {
|
|
3891
|
-
const
|
|
3922
|
+
const pattern = script.attrs[":setup"]
|
|
3923
|
+
const props = pattern === undefined ? null : signatureOf(pattern)
|
|
3892
3924
|
if (!props && script.attrs[":setup"] !== undefined) warnUnreadableSignature(script, script.attrs[":setup"])
|
|
3893
3925
|
return props
|
|
3894
3926
|
}
|
|
@@ -3926,7 +3958,7 @@ const warnUnreadableSignature = (script: TagBlock, pattern: string) => {
|
|
|
3926
3958
|
const declaredPropSet = (scripts: TagBlock[]): Set<string> | null => {
|
|
3927
3959
|
let names: Set<string> | null = null
|
|
3928
3960
|
scripts.forEach(script => {
|
|
3929
|
-
const declarations =
|
|
3961
|
+
const declarations = factoryPropsOf(script.content) ?? setupSignature(script)
|
|
3930
3962
|
if (!declarations) return
|
|
3931
3963
|
const into = (names ??= new Set())
|
|
3932
3964
|
declarations.forEach(({ name }) => into.add(name))
|
|
@@ -4781,7 +4813,7 @@ export class Component79 {
|
|
|
4781
4813
|
// what this component can see of its file's other components, and which of
|
|
4782
4814
|
// its declared props arrived empty - both decided by the signature, before
|
|
4783
4815
|
// the store exists (see siblingsInScope / UNFILLED_PROPS)
|
|
4784
|
-
const declared = declaredPropNames(this.scripts, setupSignature)
|
|
4816
|
+
const declared = declaredPropNames(this.scripts, setupSignature, factoryPropsOf)
|
|
4785
4817
|
const siblingScope = siblingsInScope(this.siblings, declared)
|
|
4786
4818
|
const raw: Record<string, any> = siblingScope
|
|
4787
4819
|
? Object.assign(Object.create(siblingScope), data)
|
|
@@ -5017,7 +5049,7 @@ export class Component79 {
|
|
|
5017
5049
|
const instanceHelpers = { $mounted, $destroyed, $attached, $detached, $computed: $instanceComputed, $self, $$self, ...injected, $importAll, ...siblingScope }
|
|
5018
5050
|
const at: ScriptLocation = { filename: this.filename, index }
|
|
5019
5051
|
const deferred = ":mounted" in script.attrs
|
|
5020
|
-
const factoryCode =
|
|
5052
|
+
const factoryCode = factoryCodeOf(script.content)
|
|
5021
5053
|
const run = ((): ScriptRun => {
|
|
5022
5054
|
if (factoryCode !== null) {
|
|
5023
5055
|
// a factory publishes its names by returning them, so one that yields
|
|
@@ -5032,11 +5064,11 @@ export class Component79 {
|
|
|
5032
5064
|
"so none of its bindings exist yet - await $mounted() inside the factory instead."
|
|
5033
5065
|
)
|
|
5034
5066
|
}
|
|
5035
|
-
declareProps(store,
|
|
5067
|
+
declareProps(store, factoryPropsOf(script.content))
|
|
5036
5068
|
const body = deferred ? defer(factoryCode) : factoryCode
|
|
5037
5069
|
return runFactoryScript(body, store, run => fx.effect(run), instanceHelpers, $import, at)
|
|
5038
5070
|
}
|
|
5039
|
-
const { vars, code } =
|
|
5071
|
+
const { vars, code } = setupTransformOf(script.content)
|
|
5040
5072
|
declareProps(store, setupSignature(script))
|
|
5041
5073
|
// pre-declare script vars on the store so `with` resolves assignments
|
|
5042
5074
|
// to them (and reads of them) through the reactive proxy
|
package/src/source.ts
CHANGED
|
@@ -352,10 +352,15 @@ export const readSetupSignature = (script: TagBlock): PropDecl[] | null => {
|
|
|
352
352
|
// says it comes from the parent, so the file's own definition of that name is
|
|
353
353
|
// deliberately not in this component's scope. The runtime reads the setup
|
|
354
354
|
// signatures with setupSignature, which warns; precompile, with readSetupSignature
|
|
355
|
-
|
|
355
|
+
// `factoryProps` lets the runtime pass its memoized reader (see factoryPropsOf)
|
|
356
|
+
export const declaredPropNames = (
|
|
357
|
+
scripts: TagBlock[],
|
|
358
|
+
signature: (script: TagBlock) => PropDecl[] | null,
|
|
359
|
+
factoryProps: (src: string) => PropDecl[] | null = parseFactoryProps,
|
|
360
|
+
): Set<string> => {
|
|
356
361
|
const names = new Set<string>()
|
|
357
362
|
scripts.forEach(script => {
|
|
358
|
-
const declarations =
|
|
363
|
+
const declarations = factoryProps(script.content) ?? signature(script)
|
|
359
364
|
declarations?.forEach(({ name }) => names.add(name))
|
|
360
365
|
})
|
|
361
366
|
return names
|