@barefootjs/jsx 0.31.10 → 0.32.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/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -68
- package/package.json +2 -2
- package/src/index.ts +0 -1
- package/dist/signal-init-eval.d.ts +0 -82
- package/dist/signal-init-eval.d.ts.map +0 -1
- package/src/__tests__/signal-init-eval.test.ts +0 -138
- package/src/signal-init-eval.ts +0 -165
package/dist/index.d.ts
CHANGED
|
@@ -26,7 +26,6 @@ export { emitParsedExpr, groupBinaryOperand, isStringTypedOperand, isStringConca
|
|
|
26
26
|
export type { ParsedExprEmitter, HigherOrderMethod, ArrayMethod, SortMethod, LiteralType } from './adapters/parsed-expr-emitter.ts';
|
|
27
27
|
export { collectLoopBoundNames } from './adapters/loop-bound-names.ts';
|
|
28
28
|
export { derivesScopeFromSlot } from './adapters/child-scope.ts';
|
|
29
|
-
export { evaluateSignalInit, tryEvaluateSignalInit, type SignalInitEvalResult } from './signal-init-eval.ts';
|
|
30
29
|
export { evaluateStaticLiteral, isFullyStaticLiteral, resolveStaticLoopSource } from './static-literal.ts';
|
|
31
30
|
export { importsSearchParams, searchParamsLocalNames, envSignalLocalNames, envSignalReaderFor, ENV_SIGNAL_READERS, queryHrefLocalNames, formatDateLocalNames, matchSearchParamsMethodCall } from './adapters/env-signal.ts';
|
|
32
31
|
export type { EnvSignalReader } from './adapters/env-signal.ts';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AACzD,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,yBAAyB,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAGzG,OAAO,EAAE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B,EACpB,iBAAiB,EACjB,mBAAmB,EACnB,oBAAoB,EAGpB,gBAAgB,GACjB,MAAM,iBAAiB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -25713,72 +25713,6 @@ function collectLoopBoundNames(ir) {
|
|
|
25713
25713
|
visit3(ir.root);
|
|
25714
25714
|
return names;
|
|
25715
25715
|
}
|
|
25716
|
-
// src/signal-init-eval.ts
|
|
25717
|
-
var BLOCKED_GLOBALS = [
|
|
25718
|
-
"globalThis",
|
|
25719
|
-
"window",
|
|
25720
|
-
"document",
|
|
25721
|
-
"Date",
|
|
25722
|
-
"Math",
|
|
25723
|
-
"crypto",
|
|
25724
|
-
"performance",
|
|
25725
|
-
"fetch",
|
|
25726
|
-
"setTimeout",
|
|
25727
|
-
"setInterval",
|
|
25728
|
-
"require",
|
|
25729
|
-
"process",
|
|
25730
|
-
"Function"
|
|
25731
|
-
];
|
|
25732
|
-
function isTransportable(value, ancestors = new Set) {
|
|
25733
|
-
if (value === null)
|
|
25734
|
-
return true;
|
|
25735
|
-
const t = typeof value;
|
|
25736
|
-
if (t === "boolean" || t === "number" || t === "string")
|
|
25737
|
-
return true;
|
|
25738
|
-
if (t !== "object")
|
|
25739
|
-
return false;
|
|
25740
|
-
if (ancestors.has(value))
|
|
25741
|
-
return false;
|
|
25742
|
-
ancestors.add(value);
|
|
25743
|
-
try {
|
|
25744
|
-
if (Array.isArray(value)) {
|
|
25745
|
-
if (Object.keys(value).length !== value.length)
|
|
25746
|
-
return false;
|
|
25747
|
-
return value.every((el) => el !== undefined && isTransportable(el, ancestors));
|
|
25748
|
-
}
|
|
25749
|
-
const proto = Object.getPrototypeOf(value);
|
|
25750
|
-
if (proto !== Object.prototype && proto !== null)
|
|
25751
|
-
return false;
|
|
25752
|
-
return Object.values(value).every((v) => isTransportable(v, ancestors));
|
|
25753
|
-
} finally {
|
|
25754
|
-
ancestors.delete(value);
|
|
25755
|
-
}
|
|
25756
|
-
}
|
|
25757
|
-
function tryEvaluateSignalInit(expr, props) {
|
|
25758
|
-
const src = expr.trim();
|
|
25759
|
-
if (src === "")
|
|
25760
|
-
return { ok: false };
|
|
25761
|
-
let fn;
|
|
25762
|
-
try {
|
|
25763
|
-
fn = new Function("props", ...BLOCKED_GLOBALS, `'use strict'; return (
|
|
25764
|
-
${src}
|
|
25765
|
-
);`);
|
|
25766
|
-
} catch {
|
|
25767
|
-
return { ok: false };
|
|
25768
|
-
}
|
|
25769
|
-
try {
|
|
25770
|
-
const value = fn(props ?? {});
|
|
25771
|
-
if (value === undefined)
|
|
25772
|
-
return { ok: true, value: undefined };
|
|
25773
|
-
return isTransportable(value) ? { ok: true, value } : { ok: false };
|
|
25774
|
-
} catch {
|
|
25775
|
-
return { ok: false };
|
|
25776
|
-
}
|
|
25777
|
-
}
|
|
25778
|
-
function evaluateSignalInit(expr, props) {
|
|
25779
|
-
const result = tryEvaluateSignalInit(expr, props);
|
|
25780
|
-
return result.ok && result.value !== undefined ? result.value : null;
|
|
25781
|
-
}
|
|
25782
25716
|
// src/static-literal.ts
|
|
25783
25717
|
function evaluateStaticLiteral(expr, bindings) {
|
|
25784
25718
|
switch (expr.kind) {
|
|
@@ -28950,7 +28884,6 @@ function profileToJSON(profile) {
|
|
|
28950
28884
|
registerBuiltinLoweringPlugins();
|
|
28951
28885
|
export {
|
|
28952
28886
|
tsNodeToParsedExpr,
|
|
28953
|
-
tryEvaluateSignalInit,
|
|
28954
28887
|
traceUpdatePath,
|
|
28955
28888
|
testAdapter,
|
|
28956
28889
|
stringifyParsedExpr,
|
|
@@ -29043,7 +28976,6 @@ export {
|
|
|
29043
28976
|
extractArrowBodyExpression,
|
|
29044
28977
|
exprToString,
|
|
29045
28978
|
evaluateStaticLiteral,
|
|
29046
|
-
evaluateSignalInit,
|
|
29047
28979
|
evaluateProfileGates,
|
|
29048
28980
|
evalStringArrayJoin,
|
|
29049
28981
|
envSignalReaderFor,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@barefootjs/jsx",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.32.0",
|
|
4
4
|
"description": "JSX compiler for BarefootJS - transforms JSX to server HTML + client JS",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"directory": "packages/jsx"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@barefootjs/shared": "0.
|
|
52
|
+
"@barefootjs/shared": "0.32.0"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"@barefootjs/client": ">=0.2.0",
|
package/src/index.ts
CHANGED
|
@@ -97,7 +97,6 @@ export { emitParsedExpr, groupBinaryOperand, isStringTypedOperand, isStringConca
|
|
|
97
97
|
export type { ParsedExprEmitter, HigherOrderMethod, ArrayMethod, SortMethod, LiteralType } from './adapters/parsed-expr-emitter.ts'
|
|
98
98
|
export { collectLoopBoundNames } from './adapters/loop-bound-names.ts'
|
|
99
99
|
export { derivesScopeFromSlot } from './adapters/child-scope.ts'
|
|
100
|
-
export { evaluateSignalInit, tryEvaluateSignalInit, type SignalInitEvalResult } from './signal-init-eval.ts'
|
|
101
100
|
export { evaluateStaticLiteral, isFullyStaticLiteral, resolveStaticLoopSource } from './static-literal.ts'
|
|
102
101
|
export { importsSearchParams, searchParamsLocalNames, envSignalLocalNames, envSignalReaderFor, ENV_SIGNAL_READERS, queryHrefLocalNames, formatDateLocalNames, matchSearchParamsMethodCall } from './adapters/env-signal.ts'
|
|
103
102
|
export type { EnvSignalReader } from './adapters/env-signal.ts'
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TEST-HARNESS ONLY. Evaluate a signal initializer / prop-default source
|
|
3
|
-
* expression against a mock `props` object by EXECUTING it (`new
|
|
4
|
-
* Function`, with `undefined` shadowing the globals listed below), the
|
|
5
|
-
* same way the Hono/CSR conformance reference produces its value — by
|
|
6
|
-
* actually running the component. Never call this from a build path (`bf
|
|
7
|
-
* build`, `compileJSX`, any adapter's `generate`); it exists only so each
|
|
8
|
-
* adapter's `test-render.ts` conformance harness can seed a signal/
|
|
9
|
-
* prop-default for a non-JS-runtime SSR render (PHP/Ruby/Python/Perl/Go)
|
|
10
|
-
* that matches what Hono would compute. (#2209)
|
|
11
|
-
*
|
|
12
|
-
* NOT a security sandbox — the global shadowing below is a determinism
|
|
13
|
-
* tripwire (catches the common accidental-nondeterminism case, e.g.
|
|
14
|
-
* `Date.now()`), not containment: a sufficiently creative expression can
|
|
15
|
-
* still reach the real global scope (`new Function` bodies execute
|
|
16
|
-
* unlexically-scoped, so e.g. `[].constructor.constructor('return
|
|
17
|
-
* Date')()` recovers `Date` even though the bare name is shadowed, and
|
|
18
|
-
* `eval` can't be shadowed at all — JS forbids declaring or binding a
|
|
19
|
-
* parameter literally named `eval` in strict-mode code). Do not widen this
|
|
20
|
-
* module's use to anything but first-party fixture source. The actual
|
|
21
|
-
* trust boundary is that the evaluated text is first-party fixture
|
|
22
|
-
* source, already compiled by this same process — the conformance harness
|
|
23
|
-
* already executes fixture-derived code far more invasively (spawning
|
|
24
|
-
* `ruby`/`php`/`perl`/`go run` on generated programs). This module is
|
|
25
|
-
* never reachable from anything a real end user's untrusted input could
|
|
26
|
-
* influence.
|
|
27
|
-
*
|
|
28
|
-
* Why real execution instead of a hand-rolled evaluator: the initializer
|
|
29
|
-
* source is an arbitrary JS-subset expression over `props` (e.g. `(props.x
|
|
30
|
-
* ?? []).map(t => ({ ...t, editing: false }))`, #2209's actual repro) —
|
|
31
|
-
* every previous approach here was a regex/pattern-match over a small
|
|
32
|
-
* catalogue of recognized shapes (`props.x`, `props.x ?? default`, a bare
|
|
33
|
-
* literal), and #2209 is literally "the catalogue missed a shape" (the
|
|
34
|
-
* THIRD such miss on this codebase, per the superseded
|
|
35
|
-
* `evaluate-signal-init.test.ts`'s own #1672 pins). A hand-written
|
|
36
|
-
* evaluator over `ParsedExpr` would face the same drift, and can't
|
|
37
|
-
* represent object spread (`{ ...t, editing: false }`) without extending
|
|
38
|
-
* `ParsedExpr` — a production-compiler change that ripples into every
|
|
39
|
-
* adapter's exhaustive switch, disproportionate for a test-only need.
|
|
40
|
-
* `new Function` delegates parsing to the JS engine itself — CLAUDE.md's
|
|
41
|
-
* regex-parsing ban exists precisely to avoid the false-match/missed-shape
|
|
42
|
-
* failure mode this replaces.
|
|
43
|
-
*
|
|
44
|
-
* Shadowed as `undefined` (best-effort determinism, not containment — see
|
|
45
|
-
* above): `globalThis`, `window`, `document`, `Date`, `Math`, `crypto`,
|
|
46
|
-
* `performance`, `fetch`, `setTimeout`, `setInterval`, `require`,
|
|
47
|
-
* `process`, `Function`. (`eval` is deliberately absent from this list —
|
|
48
|
-
* it cannot be shadowed as a parameter name in strict-mode code; see
|
|
49
|
-
* above.)
|
|
50
|
-
*
|
|
51
|
-
* `props` bare-identifier destructured params (`createSignal(count)` where
|
|
52
|
-
* `count` is a destructured prop, not a `props.x` member) are NOT bound —
|
|
53
|
-
* the evaluator only exposes `props` — so such an initializer throws
|
|
54
|
-
* `ReferenceError` and falls back to "unset", matching every prior
|
|
55
|
-
* evaluator's behavior for that shape. Extending the environment with
|
|
56
|
-
* `ir.metadata.propsParams` bindings is a natural follow-up if a fixture
|
|
57
|
-
* ever needs it.
|
|
58
|
-
*/
|
|
59
|
-
export type SignalInitEvalResult = {
|
|
60
|
-
ok: true;
|
|
61
|
-
value: unknown;
|
|
62
|
-
} | {
|
|
63
|
-
ok: false;
|
|
64
|
-
};
|
|
65
|
-
/**
|
|
66
|
-
* Evaluate `expr` (a JS-subset source expression) against `props`. Returns
|
|
67
|
-
* `{ ok: false }` when the expression fails to parse, throws at evaluation
|
|
68
|
-
* time (e.g. a `ReferenceError` for an unbound identifier), or evaluates to
|
|
69
|
-
* something the downstream serializers can't marshal (see
|
|
70
|
-
* {@link isTransportable}).
|
|
71
|
-
*/
|
|
72
|
-
export declare function tryEvaluateSignalInit(expr: string, props?: Record<string, unknown>): SignalInitEvalResult;
|
|
73
|
-
/**
|
|
74
|
-
* Drop-in replacement for the harnesses' former per-adapter regex
|
|
75
|
-
* evaluator: `null` means "could not evaluate, or evaluated to
|
|
76
|
-
* `undefined` — leave the signal/default unseeded", matching every prior
|
|
77
|
-
* evaluator's convention (an explicit JS `null` initializer also maps to
|
|
78
|
-
* `null` — the same "skip" outcome, since none of these harnesses
|
|
79
|
-
* distinguish "explicitly null" from "unset" downstream).
|
|
80
|
-
*/
|
|
81
|
-
export declare function evaluateSignalInit(expr: string, props?: Record<string, unknown>): unknown;
|
|
82
|
-
//# sourceMappingURL=signal-init-eval.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"signal-init-eval.d.ts","sourceRoot":"","sources":["../src/signal-init-eval.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;AAkBH,MAAM,MAAM,oBAAoB,GAAG;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAA;CAAE,CAAA;AAqC/E;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,MAAM,EACZ,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC9B,oBAAoB,CA6BtB;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAGzF"}
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import { describe, test, expect } from 'bun:test'
|
|
2
|
-
import { evaluateSignalInit, tryEvaluateSignalInit } from '../signal-init-eval'
|
|
3
|
-
|
|
4
|
-
// #2209: replaces 7 near-duplicate regex-based `evaluateSignalInit`
|
|
5
|
-
// evaluators (one per template-string adapter's test-render.ts harness)
|
|
6
|
-
// with a single sandboxed real-JS evaluator. Absorbs and supersedes
|
|
7
|
-
// `packages/adapter-mojolicious/src/__tests__/evaluate-signal-init.test.ts`
|
|
8
|
-
// (#1672's pins) plus the actual #2209 repro shape.
|
|
9
|
-
describe('evaluateSignalInit (#2209)', () => {
|
|
10
|
-
test('the #2209 repro: (props.x ?? []).map(t => ({ ...t, editing: false }))', () => {
|
|
11
|
-
const expr = `(props.initialTodos ?? []).map(t => ({ ...t, editing: false }))`
|
|
12
|
-
expect(evaluateSignalInit(expr, { initialTodos: [{ id: 1, done: false }] })).toEqual([
|
|
13
|
-
{ id: 1, done: false, editing: false },
|
|
14
|
-
])
|
|
15
|
-
expect(evaluateSignalInit(expr, undefined)).toEqual([])
|
|
16
|
-
expect(evaluateSignalInit(expr, {})).toEqual([])
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
test('an object-spread override applies after the spread (matches JS semantics)', () => {
|
|
20
|
-
const expr = `(props.items ?? []).map(t => ({ ...t, done: true }))`
|
|
21
|
-
expect(evaluateSignalInit(expr, { items: [{ id: 1, done: false }] })).toEqual([
|
|
22
|
-
{ id: 1, done: true },
|
|
23
|
-
])
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
// #1672 pins, absorbed from the deleted mojolicious-local test file.
|
|
27
|
-
test('parses an inline object-array initial value', () => {
|
|
28
|
-
expect(evaluateSignalInit(`[{ id: 'a' }, { id: 'b' }, { id: 'c' }]`)).toEqual([
|
|
29
|
-
{ id: 'a' },
|
|
30
|
-
{ id: 'b' },
|
|
31
|
-
{ id: 'c' },
|
|
32
|
-
])
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
test('parses scalar and mixed arrays, including nested objects', () => {
|
|
36
|
-
expect(evaluateSignalInit(`['x', 'y']`)).toEqual(['x', 'y'])
|
|
37
|
-
expect(evaluateSignalInit(`[1, 2, 3]`)).toEqual([1, 2, 3])
|
|
38
|
-
expect(evaluateSignalInit(`[{ id: 'a', n: 1, ok: true }]`)).toEqual([
|
|
39
|
-
{ id: 'a', n: 1, ok: true },
|
|
40
|
-
])
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
test('still parses scalars, empty array, and props passthrough', () => {
|
|
44
|
-
expect(evaluateSignalInit(`'b'`)).toBe('b')
|
|
45
|
-
expect(evaluateSignalInit(`5`)).toBe(5)
|
|
46
|
-
expect(evaluateSignalInit(`[]`)).toEqual([])
|
|
47
|
-
expect(evaluateSignalInit(`props.value`, { value: 42 })).toBe(42)
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
test('bails to null for arrays with non-literal, unbound elements', () => {
|
|
51
|
-
expect(evaluateSignalInit(`[foo(), bar]`)).toBeNull()
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
// Additional shapes the old regex evaluators supported.
|
|
55
|
-
test('props.x ?? default with x present, absent, or explicitly null', () => {
|
|
56
|
-
expect(evaluateSignalInit(`props.x ?? 7`, { x: 3 })).toBe(3)
|
|
57
|
-
expect(evaluateSignalInit(`props.x ?? 7`, {})).toBe(7)
|
|
58
|
-
expect(evaluateSignalInit(`props.x ?? 7`, undefined)).toBe(7)
|
|
59
|
-
// Fix over the old regex evaluators: JS `??` also falls through on an
|
|
60
|
-
// explicit `null`/`undefined` prop value — the old regex only checked
|
|
61
|
-
// `propName in props` and returned the raw (null) value, which was
|
|
62
|
-
// actually a bug relative to real JS `??` semantics.
|
|
63
|
-
expect(evaluateSignalInit(`props.x ?? 7`, { x: null })).toBe(7)
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
test('negative and decimal number literals', () => {
|
|
67
|
-
expect(evaluateSignalInit(`-7.6`)).toBe(-7.6)
|
|
68
|
-
expect(evaluateSignalInit(`42`)).toBe(42)
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
test('booleans', () => {
|
|
72
|
-
expect(evaluateSignalInit(`true`)).toBe(true)
|
|
73
|
-
expect(evaluateSignalInit(`false`)).toBe(false)
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
test('an explicit null initializer maps to null (the "skip" outcome)', () => {
|
|
77
|
-
expect(evaluateSignalInit(`null`)).toBeNull()
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
// New coverage for #2209's sandboxing contract.
|
|
81
|
-
test('blocked globals fail deterministically and fall back to null', () => {
|
|
82
|
-
expect(evaluateSignalInit(`Date.now()`)).toBeNull()
|
|
83
|
-
expect(evaluateSignalInit(`Math.random()`)).toBeNull()
|
|
84
|
-
expect(evaluateSignalInit(`typeof window`)).not.toBe('object')
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
test('a TS-only remnant that fails to parse as an expression falls back to null', () => {
|
|
88
|
-
expect(evaluateSignalInit(`foo as Bar`)).toBeNull()
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
test('a non-transportable value (class instance) falls back to null', () => {
|
|
92
|
-
expect(evaluateSignalInit(`new Set([1, 2])`)).toBeNull()
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
test('a bare destructured-prop identifier (not props.x) is unbound and falls back to null', () => {
|
|
96
|
-
expect(evaluateSignalInit(`count`, { count: 5 })).toBeNull()
|
|
97
|
-
})
|
|
98
|
-
|
|
99
|
-
test('tryEvaluateSignalInit distinguishes an explicit undefined from a real ok:false', () => {
|
|
100
|
-
expect(tryEvaluateSignalInit(`undefined`)).toEqual({ ok: true, value: undefined })
|
|
101
|
-
expect(tryEvaluateSignalInit(`foo()`)).toEqual({ ok: false })
|
|
102
|
-
// evaluateSignalInit's wrapper collapses both to null:
|
|
103
|
-
expect(evaluateSignalInit(`undefined`)).toBeNull()
|
|
104
|
-
expect(evaluateSignalInit(`foo()`)).toBeNull()
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
// Copilot review (#2229): `Function` is now shadowed too — closes the
|
|
108
|
-
// most direct bypass of the blocked-globals list.
|
|
109
|
-
test('the Function constructor is shadowed', () => {
|
|
110
|
-
expect(evaluateSignalInit(`Function('return 1')()`)).toBeNull()
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
// Copilot review (#2229): `isTransportable` must reject a sparse array
|
|
114
|
-
// (a hole is not the same as an element that's explicitly `undefined` —
|
|
115
|
-
// `Array.prototype.every` silently skips holes, which previously let
|
|
116
|
-
// one through undetected).
|
|
117
|
-
test('a sparse array (a hole, not an explicit undefined) falls back to null', () => {
|
|
118
|
-
// biome-ignore lint: intentional sparse-array literal for the hole test
|
|
119
|
-
expect(evaluateSignalInit(`[1, , 3]`)).toBeNull()
|
|
120
|
-
})
|
|
121
|
-
|
|
122
|
-
// Copilot review (#2229): the same object appearing twice in a
|
|
123
|
-
// non-cyclic shape (shared by reference, not by cycle) is transportable
|
|
124
|
-
// — JSON-equivalent behavior would just duplicate it — and must NOT be
|
|
125
|
-
// rejected by an overly-global "seen" set.
|
|
126
|
-
test('a shared (non-cyclic) reference is transportable', () => {
|
|
127
|
-
expect(evaluateSignalInit(`(() => { const shared = { id: 1 }; return [shared, shared] })()`)).toEqual([
|
|
128
|
-
{ id: 1 },
|
|
129
|
-
{ id: 1 },
|
|
130
|
-
])
|
|
131
|
-
})
|
|
132
|
-
|
|
133
|
-
test('a genuine cycle still falls back to null', () => {
|
|
134
|
-
expect(
|
|
135
|
-
evaluateSignalInit(`(() => { const o = { id: 1 }; o.self = o; return o })()`),
|
|
136
|
-
).toBeNull()
|
|
137
|
-
})
|
|
138
|
-
})
|
package/src/signal-init-eval.ts
DELETED
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TEST-HARNESS ONLY. Evaluate a signal initializer / prop-default source
|
|
3
|
-
* expression against a mock `props` object by EXECUTING it (`new
|
|
4
|
-
* Function`, with `undefined` shadowing the globals listed below), the
|
|
5
|
-
* same way the Hono/CSR conformance reference produces its value — by
|
|
6
|
-
* actually running the component. Never call this from a build path (`bf
|
|
7
|
-
* build`, `compileJSX`, any adapter's `generate`); it exists only so each
|
|
8
|
-
* adapter's `test-render.ts` conformance harness can seed a signal/
|
|
9
|
-
* prop-default for a non-JS-runtime SSR render (PHP/Ruby/Python/Perl/Go)
|
|
10
|
-
* that matches what Hono would compute. (#2209)
|
|
11
|
-
*
|
|
12
|
-
* NOT a security sandbox — the global shadowing below is a determinism
|
|
13
|
-
* tripwire (catches the common accidental-nondeterminism case, e.g.
|
|
14
|
-
* `Date.now()`), not containment: a sufficiently creative expression can
|
|
15
|
-
* still reach the real global scope (`new Function` bodies execute
|
|
16
|
-
* unlexically-scoped, so e.g. `[].constructor.constructor('return
|
|
17
|
-
* Date')()` recovers `Date` even though the bare name is shadowed, and
|
|
18
|
-
* `eval` can't be shadowed at all — JS forbids declaring or binding a
|
|
19
|
-
* parameter literally named `eval` in strict-mode code). Do not widen this
|
|
20
|
-
* module's use to anything but first-party fixture source. The actual
|
|
21
|
-
* trust boundary is that the evaluated text is first-party fixture
|
|
22
|
-
* source, already compiled by this same process — the conformance harness
|
|
23
|
-
* already executes fixture-derived code far more invasively (spawning
|
|
24
|
-
* `ruby`/`php`/`perl`/`go run` on generated programs). This module is
|
|
25
|
-
* never reachable from anything a real end user's untrusted input could
|
|
26
|
-
* influence.
|
|
27
|
-
*
|
|
28
|
-
* Why real execution instead of a hand-rolled evaluator: the initializer
|
|
29
|
-
* source is an arbitrary JS-subset expression over `props` (e.g. `(props.x
|
|
30
|
-
* ?? []).map(t => ({ ...t, editing: false }))`, #2209's actual repro) —
|
|
31
|
-
* every previous approach here was a regex/pattern-match over a small
|
|
32
|
-
* catalogue of recognized shapes (`props.x`, `props.x ?? default`, a bare
|
|
33
|
-
* literal), and #2209 is literally "the catalogue missed a shape" (the
|
|
34
|
-
* THIRD such miss on this codebase, per the superseded
|
|
35
|
-
* `evaluate-signal-init.test.ts`'s own #1672 pins). A hand-written
|
|
36
|
-
* evaluator over `ParsedExpr` would face the same drift, and can't
|
|
37
|
-
* represent object spread (`{ ...t, editing: false }`) without extending
|
|
38
|
-
* `ParsedExpr` — a production-compiler change that ripples into every
|
|
39
|
-
* adapter's exhaustive switch, disproportionate for a test-only need.
|
|
40
|
-
* `new Function` delegates parsing to the JS engine itself — CLAUDE.md's
|
|
41
|
-
* regex-parsing ban exists precisely to avoid the false-match/missed-shape
|
|
42
|
-
* failure mode this replaces.
|
|
43
|
-
*
|
|
44
|
-
* Shadowed as `undefined` (best-effort determinism, not containment — see
|
|
45
|
-
* above): `globalThis`, `window`, `document`, `Date`, `Math`, `crypto`,
|
|
46
|
-
* `performance`, `fetch`, `setTimeout`, `setInterval`, `require`,
|
|
47
|
-
* `process`, `Function`. (`eval` is deliberately absent from this list —
|
|
48
|
-
* it cannot be shadowed as a parameter name in strict-mode code; see
|
|
49
|
-
* above.)
|
|
50
|
-
*
|
|
51
|
-
* `props` bare-identifier destructured params (`createSignal(count)` where
|
|
52
|
-
* `count` is a destructured prop, not a `props.x` member) are NOT bound —
|
|
53
|
-
* the evaluator only exposes `props` — so such an initializer throws
|
|
54
|
-
* `ReferenceError` and falls back to "unset", matching every prior
|
|
55
|
-
* evaluator's behavior for that shape. Extending the environment with
|
|
56
|
-
* `ir.metadata.propsParams` bindings is a natural follow-up if a fixture
|
|
57
|
-
* ever needs it.
|
|
58
|
-
*/
|
|
59
|
-
|
|
60
|
-
const BLOCKED_GLOBALS = [
|
|
61
|
-
'globalThis',
|
|
62
|
-
'window',
|
|
63
|
-
'document',
|
|
64
|
-
'Date',
|
|
65
|
-
'Math',
|
|
66
|
-
'crypto',
|
|
67
|
-
'performance',
|
|
68
|
-
'fetch',
|
|
69
|
-
'setTimeout',
|
|
70
|
-
'setInterval',
|
|
71
|
-
'require',
|
|
72
|
-
'process',
|
|
73
|
-
'Function',
|
|
74
|
-
] as const
|
|
75
|
-
|
|
76
|
-
export type SignalInitEvalResult = { ok: true; value: unknown } | { ok: false }
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* A value the harness's downstream language serializers (JSON/Python/PHP/
|
|
80
|
-
* Perl/Ruby literal builders) can actually marshal: `null`, a boolean, a
|
|
81
|
-
* number (including non-finite — several serializers already special-case
|
|
82
|
-
* NaN/Infinity), a string, a dense array with no holes and no `undefined`
|
|
83
|
-
* elements, or a plain object (`Object.prototype` or null prototype only —
|
|
84
|
-
* rejects class instances, functions, Maps/Sets, etc). Rejects genuine
|
|
85
|
-
* cycles; a shared (non-cyclic) reference appearing more than once — e.g.
|
|
86
|
-
* the same object at two array indices — is fine (JSON-equivalent
|
|
87
|
-
* behavior just duplicates it), so `ancestors` tracks only the current
|
|
88
|
-
* recursion path, not every value ever visited.
|
|
89
|
-
*/
|
|
90
|
-
function isTransportable(value: unknown, ancestors: Set<unknown> = new Set()): boolean {
|
|
91
|
-
if (value === null) return true
|
|
92
|
-
const t = typeof value
|
|
93
|
-
if (t === 'boolean' || t === 'number' || t === 'string') return true
|
|
94
|
-
if (t !== 'object') return false
|
|
95
|
-
if (ancestors.has(value)) return false // a real cycle (value is its own ancestor)
|
|
96
|
-
ancestors.add(value)
|
|
97
|
-
try {
|
|
98
|
-
if (Array.isArray(value)) {
|
|
99
|
-
// `Array.prototype.every` silently skips holes (`[1, , 3]`), so a
|
|
100
|
-
// sparse array would otherwise pass — compare against the own
|
|
101
|
-
// enumerable key count (holes aren't own keys) to catch that.
|
|
102
|
-
if (Object.keys(value).length !== value.length) return false
|
|
103
|
-
return value.every(el => el !== undefined && isTransportable(el, ancestors))
|
|
104
|
-
}
|
|
105
|
-
const proto = Object.getPrototypeOf(value)
|
|
106
|
-
if (proto !== Object.prototype && proto !== null) return false
|
|
107
|
-
return Object.values(value as Record<string, unknown>).every(v => isTransportable(v, ancestors))
|
|
108
|
-
} finally {
|
|
109
|
-
ancestors.delete(value)
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Evaluate `expr` (a JS-subset source expression) against `props`. Returns
|
|
115
|
-
* `{ ok: false }` when the expression fails to parse, throws at evaluation
|
|
116
|
-
* time (e.g. a `ReferenceError` for an unbound identifier), or evaluates to
|
|
117
|
-
* something the downstream serializers can't marshal (see
|
|
118
|
-
* {@link isTransportable}).
|
|
119
|
-
*/
|
|
120
|
-
export function tryEvaluateSignalInit(
|
|
121
|
-
expr: string,
|
|
122
|
-
props?: Record<string, unknown>,
|
|
123
|
-
): SignalInitEvalResult {
|
|
124
|
-
const src = expr.trim()
|
|
125
|
-
if (src === '') return { ok: false }
|
|
126
|
-
let fn: (props: Record<string, unknown>, ...blocked: undefined[]) => unknown
|
|
127
|
-
try {
|
|
128
|
-
// `props` plus the blocked-globals shadows are the only bindings
|
|
129
|
-
// passed in — best-effort determinism, not containment; see the file
|
|
130
|
-
// docstring for the trust-boundary rationale (test-harness-only,
|
|
131
|
-
// never a build path).
|
|
132
|
-
fn = new Function(
|
|
133
|
-
'props',
|
|
134
|
-
...BLOCKED_GLOBALS,
|
|
135
|
-
`'use strict'; return (\n${src}\n);`,
|
|
136
|
-
) as typeof fn
|
|
137
|
-
} catch {
|
|
138
|
-
return { ok: false }
|
|
139
|
-
}
|
|
140
|
-
try {
|
|
141
|
-
const value = fn(props ?? {})
|
|
142
|
-
// `undefined` at the TOP level is a genuine, distinguishable result
|
|
143
|
-
// (e.g. an explicit `undefined` initializer, or `props.x` with no `x`
|
|
144
|
-
// and no `??` fallback) — not a marshal failure. `evaluateSignalInit`'s
|
|
145
|
-
// wrapper still collapses it to the "skip" outcome; callers that need
|
|
146
|
-
// the distinction use this function directly.
|
|
147
|
-
if (value === undefined) return { ok: true, value: undefined }
|
|
148
|
-
return isTransportable(value) ? { ok: true, value } : { ok: false }
|
|
149
|
-
} catch {
|
|
150
|
-
return { ok: false }
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Drop-in replacement for the harnesses' former per-adapter regex
|
|
156
|
-
* evaluator: `null` means "could not evaluate, or evaluated to
|
|
157
|
-
* `undefined` — leave the signal/default unseeded", matching every prior
|
|
158
|
-
* evaluator's convention (an explicit JS `null` initializer also maps to
|
|
159
|
-
* `null` — the same "skip" outcome, since none of these harnesses
|
|
160
|
-
* distinguish "explicitly null" from "unset" downstream).
|
|
161
|
-
*/
|
|
162
|
-
export function evaluateSignalInit(expr: string, props?: Record<string, unknown>): unknown {
|
|
163
|
-
const result = tryEvaluateSignalInit(expr, props)
|
|
164
|
-
return result.ok && result.value !== undefined ? result.value : null
|
|
165
|
-
}
|