@barefootjs/jsx 0.39.5 → 0.39.6

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.
Files changed (57) hide show
  1. package/dist/adapters/array-method.d.ts +93 -0
  2. package/dist/adapters/array-method.d.ts.map +1 -0
  3. package/dist/adapters/attr-plan.d.ts +135 -0
  4. package/dist/adapters/attr-plan.d.ts.map +1 -0
  5. package/dist/adapters/boolean-result.d.ts +84 -9
  6. package/dist/adapters/boolean-result.d.ts.map +1 -1
  7. package/dist/adapters/callback-method.d.ts +126 -0
  8. package/dist/adapters/callback-method.d.ts.map +1 -0
  9. package/dist/adapters/component-props.d.ts +99 -0
  10. package/dist/adapters/component-props.d.ts.map +1 -0
  11. package/dist/adapters/component-tree.d.ts +25 -0
  12. package/dist/adapters/component-tree.d.ts.map +1 -0
  13. package/dist/adapters/literal-value.d.ts +22 -0
  14. package/dist/adapters/literal-value.d.ts.map +1 -0
  15. package/dist/adapters/loop-plan.d.ts +53 -0
  16. package/dist/adapters/loop-plan.d.ts.map +1 -0
  17. package/dist/adapters/prop-classes.d.ts +37 -0
  18. package/dist/adapters/prop-classes.d.ts.map +1 -0
  19. package/dist/expression-parser.d.ts +38 -0
  20. package/dist/expression-parser.d.ts.map +1 -1
  21. package/dist/index.d.ts +17 -3
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +1765 -914
  24. package/dist/jsx-to-ir.d.ts +465 -1
  25. package/dist/jsx-to-ir.d.ts.map +1 -1
  26. package/dist/nullable-signal-attr.d.ts +19 -0
  27. package/dist/nullable-signal-attr.d.ts.map +1 -1
  28. package/package.json +2 -2
  29. package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +1 -1
  30. package/src/__tests__/action-accessor.test.ts +6 -24
  31. package/src/__tests__/array-method-catalogue.test.ts +99 -0
  32. package/src/__tests__/attr-plan.test.ts +121 -0
  33. package/src/__tests__/binding-scope-ratchet.test.ts +12 -12
  34. package/src/__tests__/boolean-result-expr.test.ts +106 -0
  35. package/src/__tests__/boolean-result.test.ts +34 -1
  36. package/src/__tests__/callback-method.test.ts +189 -0
  37. package/src/__tests__/component-props.test.ts +148 -0
  38. package/src/__tests__/delegated-handler-preamble.test.ts +4 -4
  39. package/src/__tests__/dsl-shared-helpers.test.ts +166 -0
  40. package/src/__tests__/issue-3240-nested-static-map-event-delegation.test.ts +1 -1
  41. package/src/__tests__/loop-plan.test.ts +104 -0
  42. package/src/__tests__/map-call-decisions.test.ts +521 -0
  43. package/src/__tests__/nullable-signal-attr.test.ts +45 -0
  44. package/src/adapters/array-method.ts +193 -0
  45. package/src/adapters/attr-plan.ts +200 -0
  46. package/src/adapters/boolean-result.ts +208 -12
  47. package/src/adapters/callback-method.ts +301 -0
  48. package/src/adapters/component-props.ts +144 -0
  49. package/src/adapters/component-tree.ts +118 -0
  50. package/src/adapters/literal-value.ts +36 -0
  51. package/src/adapters/loop-plan.ts +88 -0
  52. package/src/adapters/prop-classes.ts +73 -0
  53. package/src/expression-parser.ts +537 -374
  54. package/src/index.ts +53 -2
  55. package/src/ir-to-client-js/control-flow/stringify/event-delegation.ts +9 -7
  56. package/src/jsx-to-ir.ts +1328 -991
  57. package/src/nullable-signal-attr.ts +78 -0
@@ -0,0 +1,93 @@
1
+ /**
2
+ * The array / string method catalogue shared by the DSL adapters (#3476).
3
+ *
4
+ * Each DSL adapter lowers `xs.join(sep)`, `s.padStart(n, c)` and the rest of
5
+ * {@link ArrayMethod} to one call of its template runtime's helper. What the
6
+ * call means is the same in all of them: which helper, which arguments, and
7
+ * what fills an argument the source left out (`join` → `','`, `at` → `0`,
8
+ * `slice` end → "to length"). This module owns that meaning as data. An
9
+ * adapter only spells the call: its helper prefix (`bf.`, `$bf->`, `bf->`,
10
+ * `$bf.`), its undefined literal (`none`, `nil`, `null`, `undef`), and the
11
+ * odd helper it lowers to a native operator instead (ERB's `.downcase`).
12
+ *
13
+ * The `Record<ArrayMethod, …>` type is the exhaustiveness guard: a new
14
+ * `ArrayMethod` member fails to compile here, once, instead of in each
15
+ * adapter's `switch`.
16
+ */
17
+ import type { ParsedExpr } from '../expression-parser.ts';
18
+ import type { ArrayMethod } from './parsed-expr-emitter.ts';
19
+ /**
20
+ * Runtime helper ids. Every DSL runtime names the helper by this id; only the
21
+ * receiver syntax around it differs.
22
+ */
23
+ export type ArrayMethodHelper = 'join' | 'includes' | 'index_of' | 'last_index_of' | 'at' | 'concat' | 'slice' | 'reverse' | 'lc' | 'uc' | 'trim' | 'trim_start' | 'trim_end' | 'to_fixed' | 'split' | 'starts_with' | 'ends_with' | 'replace' | 'replace_all' | 'repeat' | 'pad_start' | 'pad_end';
24
+ /** A literal that fills an argument the source call left out. */
25
+ export type ArrayMethodDefault = {
26
+ kind: 'number';
27
+ value: number;
28
+ } | {
29
+ kind: 'string';
30
+ value: string;
31
+ }
32
+ /** The backend's undefined literal; the runtime reads it as "not given". */
33
+ | {
34
+ kind: 'undefined';
35
+ };
36
+ /** How one argument after the receiver is passed. */
37
+ export type ArrayMethodParam =
38
+ /** Always present. The parser refuses the call without it. */
39
+ {
40
+ kind: 'required';
41
+ }
42
+ /** Filled with `value` when the source left it out. */
43
+ | {
44
+ kind: 'default';
45
+ value: ArrayMethodDefault;
46
+ }
47
+ /** Dropped when the source left it out; the helper call is shorter. */
48
+ | {
49
+ kind: 'optional';
50
+ };
51
+ export interface ArrayMethodEntry {
52
+ helper: ArrayMethodHelper;
53
+ /** The arguments after the receiver, in order. Extra source arguments are dropped. */
54
+ params: readonly ArrayMethodParam[];
55
+ /** `xs.concat()` is the receiver itself, not a helper call. */
56
+ receiverWhenNoArgs?: true;
57
+ }
58
+ export declare const ARRAY_METHOD_CATALOGUE: Readonly<Record<ArrayMethod, ArrayMethodEntry>>;
59
+ /** One argument of a lowered call after the receiver. */
60
+ export type ArrayMethodArg = {
61
+ kind: 'expr';
62
+ expr: ParsedExpr;
63
+ } | {
64
+ kind: 'default';
65
+ value: ArrayMethodDefault;
66
+ };
67
+ /** A lowered array / string method call, as data. */
68
+ export type ArrayMethodPlan = {
69
+ kind: 'receiver';
70
+ object: ParsedExpr;
71
+ } | {
72
+ kind: 'call';
73
+ helper: ArrayMethodHelper;
74
+ object: ParsedExpr;
75
+ args: ArrayMethodArg[];
76
+ };
77
+ /** Lower `object.method(...args)` through {@link ARRAY_METHOD_CATALOGUE}. */
78
+ export declare function lowerArrayMethod(method: ArrayMethod, object: ParsedExpr, args: readonly ParsedExpr[]): ArrayMethodPlan;
79
+ /** How one DSL backend spells a lowered call. */
80
+ export interface ArrayMethodSpelling {
81
+ /** Spell `helper(receiver, ...args)` from already-emitted operands. */
82
+ call(helper: ArrayMethodHelper, operands: readonly string[]): string;
83
+ /** The backend's undefined literal (`none`, `nil`, `null`, `undef`). */
84
+ undefinedLiteral: string;
85
+ }
86
+ /**
87
+ * Emit a plan with `emit` for the operands and `spelling` for the call. The
88
+ * receiver is emitted first, then the arguments in order.
89
+ */
90
+ export declare function emitArrayMethod(plan: ArrayMethodPlan, emit: (e: ParsedExpr) => string, spelling: ArrayMethodSpelling): string;
91
+ /** The usual spelling: `<prefix><helper>(operands)`, e.g. `bf.` or `$bf->`. */
92
+ export declare function prefixedArrayMethodSpelling(prefix: string, undefinedLiteral: string): ArrayMethodSpelling;
93
+ //# sourceMappingURL=array-method.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array-method.d.ts","sourceRoot":"","sources":["../../src/adapters/array-method.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AACzD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAE3D;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GACzB,MAAM,GACN,UAAU,GACV,UAAU,GACV,eAAe,GACf,IAAI,GACJ,QAAQ,GACR,OAAO,GACP,SAAS,GACT,IAAI,GACJ,IAAI,GACJ,MAAM,GACN,YAAY,GACZ,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AAC,MAAM,EAAE,iBAAiB,CAAC;IAAC,MAAM,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,cAAc,EAAE,CAAA;CAAE,CAAA;AAE3F,6EAA6E;AAC7E,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,WAAW,EACnB,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,SAAS,UAAU,EAAE,GAC1B,eAAe,CAiBjB;AAED,iDAAiD;AACjD,MAAM,WAAW,mBAAmB;IAClC,uEAAuE;IACvE,IAAI,CAAC,MAAM,EAAE,iBAAiB,EAAE,QAAQ,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAAA;IACpE,wEAAwE;IACxE,gBAAgB,EAAE,MAAM,CAAA;CACzB;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,eAAe,EACrB,IAAI,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,MAAM,EAC/B,QAAQ,EAAE,mBAAmB,GAC5B,MAAM,CAOR;AAkBD,+EAA+E;AAC/E,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,GAAG,mBAAmB,CAKzG"}
@@ -0,0 +1,135 @@
1
+ /**
2
+ * How a DSL adapter emits an intrinsic element's attribute (#3478), as data.
3
+ *
4
+ * Every DSL adapter's `elementAttrEmitter` makes the same decisions for an
5
+ * `{expr}` attribute value and a `{...spread}`; only the spelling differs.
6
+ * {@link planAttrExpression} and {@link planSpreadAttr} make them once. The
7
+ * adapter keeps what is its own: the style-object lowering and the refusal
8
+ * gate before the plan, and, per plan kind, the escape call (`bf.string`,
9
+ * `bf.h`, `e(...)`), the nil and truthy tests, the temporary binding and the
10
+ * hash literal.
11
+ */
12
+ import { type ParsedExpr } from '../expression-parser.ts';
13
+ import type { LoweringMatcher } from '../lowering-registry.ts';
14
+ import { type NullishAttrContext } from '../nullable-signal-attr.ts';
15
+ import type { ConstantInfo, ExpressionAttr, SpreadAttr } from '../types.ts';
16
+ /**
17
+ * Whether an attribute value is a shape no template lowers: a JS object
18
+ * literal (`style={{…}}` aside, which the adapter lowers first) or a
19
+ * tagged template literal (`cn\`base ${tone()}\``). Returns the refusal, with
20
+ * the support gate's reason when it gives one, or `null` when the value
21
+ * goes on to {@link planAttrExpression}. The adapter reports BF101 in its own
22
+ * words. A value starting with neither shape is never parsed here.
23
+ */
24
+ export declare function unsupportedAttrExpression(expr: string, loweringMatchers: readonly LoweringMatcher[]): {
25
+ reason: string | undefined;
26
+ } | null;
27
+ /**
28
+ * The emission of an `{expr}` attribute value.
29
+ *
30
+ * - `omit-nullable`: a bare read of an optional, no-default prop or of a
31
+ * nullable signal (#2248, #3304). The attribute is guarded by a nil test
32
+ * on the value itself, as Hono drops an `undefined` attribute.
33
+ * `restKey` marks a closed-type rest-expanded key (`rest.tag`, #3057).
34
+ * - `boolean-attr`: an HTML boolean attribute (`disabled`), present when
35
+ * the value is truthy.
36
+ * - `presence`: `attr={expr || undefined}` (#1897). The value is bound to a
37
+ * temporary once and rendered when truthy.
38
+ * - `undefined-alternate`: `attr={cond ? value : undefined}` (or `: null`).
39
+ * The attribute is rendered when `cond` holds.
40
+ * - `omit-nil`: a value that may reach `null` / `undefined` through a memo,
41
+ * an optional member read or a ternary branch (#3322). The value is bound
42
+ * to a temporary once and rendered when not nil.
43
+ * - `plain`: always rendered.
44
+ *
45
+ * `boolStr`: the value is boolean-shaped and goes through `bool_str`, so the
46
+ * bytes match JS `String(boolean)`.
47
+ */
48
+ export type AttrExpressionPlan = {
49
+ kind: 'omit-nullable';
50
+ boolStr: boolean;
51
+ restKey: boolean;
52
+ } | {
53
+ kind: 'boolean-attr';
54
+ } | {
55
+ kind: 'presence';
56
+ boolStr: boolean;
57
+ } | {
58
+ kind: 'undefined-alternate';
59
+ ternary: UndefinedAlternateTernary;
60
+ } | {
61
+ kind: 'omit-nil';
62
+ boolStr: boolean;
63
+ } | {
64
+ kind: 'plain';
65
+ boolStr: boolean;
66
+ };
67
+ export interface AttrPlanContext {
68
+ /** The SolidJS-style props identifier (`function C(props: P)`), if any. */
69
+ propsObjectName: string | null;
70
+ /** The destructured `...rest` binding (`function C({ ...rest })`), if any. */
71
+ restPropsName: string | null;
72
+ /** Optional, no-default props, by bare name (`collectNullableOptionalProps`). */
73
+ nullableOptionalProps: ReadonlySet<string>;
74
+ /** Signal getters whose SSR value may be `undefined` (`collectNullableSignalGetters`). */
75
+ nullableSignalGetters: ReadonlySet<string>;
76
+ nullishAttrCtx: NullishAttrContext;
77
+ /** A loop binding at the attribute site shadows `name`. */
78
+ isLoopBound(name: string): boolean;
79
+ /** The adapter routes this value through `bool_str`. */
80
+ boolStr(expr: string, name: string): boolean;
81
+ }
82
+ /** Plan an `{expr}` attribute value. */
83
+ export declare function planAttrExpression(value: ExpressionAttr, name: string, ctx: AttrPlanContext): AttrExpressionPlan;
84
+ /**
85
+ * `cond ? value : undefined` (or `: null`), whose falsy branch drops the
86
+ * attribute (#1897).
87
+ *
88
+ * `testParsed` / `consequentParsed` are the parsed sub-trees, for the caller
89
+ * to lower directly (#2843 review). `condition` / `consequent` are
90
+ * `exprToString` output, a debug formatter that renders a nested object
91
+ * literal as a non-reparseable `[UNSUPPORTED: …]` placeholder: re-parsing it
92
+ * would corrupt a call like `queryHref(base, { tag })` before the lowering
93
+ * registry sees it. They are serialised from the parsed tree rather than
94
+ * sliced from the text, which would mis-split `cond ? 'a:b' : undefined`.
95
+ */
96
+ export interface UndefinedAlternateTernary {
97
+ condition: string;
98
+ consequent: string;
99
+ testParsed: ParsedExpr;
100
+ consequentParsed: ParsedExpr;
101
+ }
102
+ /** Parse `cond ? value : undefined` (or `: null`), or `null` for any other shape. */
103
+ export declare function parseUndefinedAlternateTernary(expr: string): UndefinedAlternateTernary | null;
104
+ /**
105
+ * The emission of a `{...spread}` attribute.
106
+ *
107
+ * - `props-object`: `{...props}`, the component's own props object, which no
108
+ * template scope holds as one value. The adapter enumerates `params` into
109
+ * a hash literal.
110
+ * - `value`: any other spread. The adapter tries its conditional-spread
111
+ * lowering (`{...(cond ? {…} : {})}`) on each of `candidates` in order:
112
+ * the spread's own tree, then the initializer of the function-scope
113
+ * `const` it names (`const sizeAttrs = size ? {…} : {}`), unless a loop
114
+ * binding shadows that name (#2489). If none lowers, it spreads the
115
+ * expression itself.
116
+ */
117
+ export type SpreadAttrPlan = {
118
+ kind: 'props-object';
119
+ params: string[];
120
+ } | {
121
+ kind: 'value';
122
+ candidates: Array<ParsedExpr | undefined>;
123
+ };
124
+ export interface SpreadPlanContext {
125
+ propsObjectName: string | null;
126
+ propsParams: ReadonlyArray<{
127
+ name: string;
128
+ }>;
129
+ localConstants: readonly ConstantInfo[];
130
+ /** A binding at the spread site shadows `name`. */
131
+ isBound(name: string): boolean;
132
+ }
133
+ /** Plan a `{...spread}` attribute. */
134
+ export declare function planSpreadAttr(value: SpreadAttr, ctx: SpreadPlanContext): SpreadAttrPlan;
135
+ //# sourceMappingURL=attr-plan.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attr-plan.d.ts","sourceRoot":"","sources":["../../src/adapters/attr-plan.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAA8C,KAAK,UAAU,EAAE,MAAM,yBAAyB,CAAA;AACrG,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAC9D,OAAO,EAAmD,KAAK,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AACrH,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAK3E;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,CACvC,IAAI,EAAE,MAAM,EACZ,gBAAgB,EAAE,SAAS,eAAe,EAAE,GAC3C;IAAE,MAAM,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,GAAG,IAAI,CAUvC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,MAAM,kBAAkB,GAC1B;IAAE,IAA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AACrF,wBAAgB,8BAA8B,CAAC,IAAI,EAAE,MAAM,GAAG,yBAAyB,GAAG,IAAI,CAc7F;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,cAAc,GACtB;IAAE,IAAI,EAAE,cAAc,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,GAC1C;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,UAAU,EAAE,KAAK,CAAC,UAAU,GAAG,SAAS,CAAC,CAAA;CAAE,CAAA;AAEhE,MAAM,WAAW,iBAAiB;IAChC,eAAe,EAAE,MAAM,GAAG,IAAI,CAAA;IAC9B,WAAW,EAAE,aAAa,CAAC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IAC5C,cAAc,EAAE,SAAS,YAAY,EAAE,CAAA;IACvC,mDAAmD;IACnD,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAA;CAC/B;AAED,sCAAsC;AACtC,wBAAgB,cAAc,CAAC,KAAK,EAAE,UAAU,EAAE,GAAG,EAAE,iBAAiB,GAAG,cAAc,CASxF"}
@@ -1,10 +1,26 @@
1
1
  /**
2
- * Backend-neutral boolean-result classification shared by the adapters whose
3
- * host language has no boolean type (Mojolicious, Xslate: Perl renders a
4
- * comparison as `''` / `1` and the literal `false` as `0`). Both adapters
5
- * route a boolean-shaped attribute value through their `bool_str` runtime
6
- * helper; this module decides which `ParsedExpr` shapes are boolean-shaped
7
- * and rewrites a ternary that only PARTLY is (#3349).
2
+ * Backend-neutral boolean-result classification shared by every DSL
3
+ * template adapter (Blade, ERB, Jinja, MiniJinja, Mojolicious, Pebble, Twig,
4
+ * Xslate; #3475 lifted the per-adapter copies here). It decides which
5
+ * `ParsedExpr` shapes evaluate to a JS boolean, rewrites a ternary that only
6
+ * PARTLY does (#3349), and names the ARIA attributes whose binding is
7
+ * boolean by definition. The adapters use it for two decisions:
8
+ *
9
+ * 1. **Stringification.** A boolean-shaped attribute / text binding is routed
10
+ * through the runtime's `bool_str` helper so it serialises as JS
11
+ * `String(boolean)` ("true" / "false"). No host language gets this for
12
+ * free: Perl renders a comparison as `''` / `1` and `false` as `0`;
13
+ * Python's `str(True)` is `"True"`; PHP's `(string) true` is `"1"` and
14
+ * `(string) false` is `""`; Java's `Boolean.toString()` happens to match,
15
+ * but Pebble still routes explicitly so `bf.string` handles every JS value
16
+ * shape the same way.
17
+ * 2. **Condition-position truthiness** (Blade, Jinja, MiniJinja, Pebble,
18
+ * Twig). A condition that is already boolean-shaped is emitted as is;
19
+ * anything else is wrapped in the runtime's JS-faithful `truthy` before it
20
+ * becomes an `if` / ternary test, because those hosts disagree with JS on
21
+ * empty containers (`[]` / `{}` are JS-truthy, falsy in Python, PHP and
22
+ * Pebble) and PHP also on the string `'0'`. Perl never needed this: an
23
+ * array / hash reference is always true there.
8
24
  *
9
25
  * Detected boolean-result shapes:
10
26
  * - `binary` with a comparison operator (`<`, `>`, `<=`, `>=`, `==`,
@@ -12,11 +28,26 @@
12
28
  * - `unary` with logical `!`
13
29
  * - `literal` with `literalType: 'boolean'`
14
30
  * - `logical` (`&&` / `||` / `??`) when both sides are boolean-result
31
+ * (`x > 0 && y < 10`, not `x() || 'fallback'`)
15
32
  * - `conditional` (`?:`) when both branches are boolean-result
33
+ * - with a caller's `isBooleanName`, a getter call, `props.X` or bare
34
+ * name declared `boolean`
35
+ *
36
+ * Anything else is not boolean-result, including a bare identifier
37
+ * (`accepted`) or call (`accepted()`) without a witness: its type is not
38
+ * recoverable from source text.
39
+ */
40
+ import { type ParsedExpr } from '../expression-parser.ts';
41
+ import type { IRMetadata } from '../types.ts';
42
+ /**
43
+ * Whether `node` evaluates to a JS boolean: structurally, or, when the
44
+ * caller passes `isBooleanName`, through a leaf declared `boolean` — a
45
+ * zero-arg getter call (`on()`), `props.on`, or a bare name — the same
46
+ * witness shape `isStringTypedOperand` takes for strings. A logical
47
+ * expression mixing a boolean prop with a comparison (`props.on &&
48
+ * !props.off`) then classifies as boolean (#3443).
16
49
  */
17
- import type { ParsedExpr } from '../expression-parser.ts';
18
- /** Whether `node` structurally evaluates to a JS boolean. */
19
- export declare function isBooleanResultParsed(node: ParsedExpr): boolean;
50
+ export declare function isBooleanResultParsed(node: ParsedExpr, isBooleanName?: (name: string, componentProperty?: boolean) => boolean): boolean;
20
51
  /**
21
52
  * Rewrites the boolean-result branches of a ternary whose OTHER branch is
22
53
  * not boolean (`yes() ? false : s()`), so a taken boolean branch carries
@@ -29,4 +60,48 @@ export declare function isBooleanResultParsed(node: ParsedExpr): boolean;
29
60
  * a mixed ternary is returned as is.
30
61
  */
31
62
  export declare function stringifyBooleanTernaryBranches(node: ParsedExpr): ParsedExpr;
63
+ /**
64
+ * Names whose value is always a JS boolean, for {@link isBooleanResultParsed}'s
65
+ * `isBooleanName` (#3443):
66
+ *
67
+ * - `names`, read as a bare identifier or getter call: signals and memos
68
+ * typed `boolean` (or, untyped, seeded with a boolean literal), local
69
+ * constants typed or seeded so, and — only when the props are
70
+ * destructured — the `boolean` props. A local constant of another type
71
+ * shadows a same-named prop: with a props object (`props.enabled`) a bare
72
+ * `enabled` is never the prop.
73
+ * - `props`, read as `props.X`: the `boolean` props by their source key.
74
+ *
75
+ * A prop counts only when it can't be `undefined` (required, or carrying a
76
+ * default proven boolean); an omitted one stringifies as `undefined`, not
77
+ * `false`, and so does one defaulted to `undefined` or any other non-boolean
78
+ * expression. A loop
79
+ * or callback binding of the same name shadows a bare name, which the
80
+ * caller's scope decides.
81
+ */
82
+ export declare function collectBooleanValueNames(metadata: Pick<IRMetadata, 'signals' | 'memos' | 'propsParams' | 'localConstants' | 'propsObjectName'>): {
83
+ names: Set<string>;
84
+ props: Set<string>;
85
+ };
86
+ /**
87
+ * {@link isBooleanResultParsed} over expression source text: parses `expr`
88
+ * and classifies the tree structurally (no `isBooleanName` witness). An
89
+ * unparseable expression is not boolean-result.
90
+ */
91
+ export declare function isBooleanResultExpr(expr: string): boolean;
92
+ /**
93
+ * True when `expr`'s top-level shape is an explicit one-argument JS
94
+ * `String(x)` call (the `EVAL_BUILTIN_IDENTS` builtin the compiler
95
+ * recognizes structurally; each DSL adapter lowers it to its runtime's
96
+ * `string` helper).
97
+ *
98
+ * Guards the {@link isAriaBooleanAttr}-driven `bool_str` override in the DSL
99
+ * adapters' attribute emitters: an author who wrote `String(...)` has opted
100
+ * into JS `String()` semantics, and `bool_str` over that already-stringified
101
+ * value is a truthiness test of a string (`"false"` is a non-empty, truthy
102
+ * string in Python, Ruby, PHP and Java), so it must not run on top.
103
+ */
104
+ export declare function isExplicitStringCall(expr: string): boolean;
105
+ /** Whether `name` is one of {@link ARIA_BOOLEAN_ATTRS}. */
106
+ export declare function isAriaBooleanAttr(name: string): boolean;
32
107
  //# sourceMappingURL=boolean-result.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"boolean-result.d.ts","sourceRoot":"","sources":["../../src/adapters/boolean-result.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAazD,6DAA6D;AAC7D,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAuB/D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,+BAA+B,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAO5E"}
1
+ {"version":3,"file":"boolean-result.d.ts","sourceRoot":"","sources":["../../src/adapters/boolean-result.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH,OAAO,EAAmB,KAAK,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAC1E,OAAO,KAAK,EAAE,UAAU,EAAY,MAAM,aAAa,CAAA;AAavD;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,UAAU,EAChB,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,iBAAiB,CAAC,EAAE,OAAO,KAAK,OAAO,GACrE,OAAO,CA8BT;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,+BAA+B,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAO5E;AAgBD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,IAAI,CAAC,UAAU,EAAE,SAAS,GAAG,OAAO,GAAG,aAAa,GAAG,gBAAgB,GAAG,iBAAiB,CAAC,GACrG;IAAE,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAAC,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;CAAE,CAqD5C;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAIzD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAS1D;AA0CD,2DAA2D;AAC3D,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEvD"}
@@ -0,0 +1,126 @@
1
+ /**
2
+ * The higher-order callback chain shared by the DSL adapters (#3477).
3
+ *
4
+ * `xs.filter(x => …)`, `xs.toSorted((a, b) => …)`, `xs.reduce((acc, x) => …,
5
+ * init)` and the rest of {@link CALLBACK_METHODS} lower the same way on every
6
+ * DSL backend: the runtime evaluator first (the callback body travels as
7
+ * serialized `ParsedExpr` JSON, see `serializeParsedExpr`), then a structured
8
+ * fallback (`.sort` only, the `{keys: …}` descriptor), then the adapter's own
9
+ * native predicate form where it has one (Kolon lambdas, Ruby blocks, Perl
10
+ * `grep`), and otherwise BF101. {@link lowerCallbackMethod} makes those
11
+ * decisions once and returns them as a plan; an adapter only spells the
12
+ * result through {@link CallbackEvalSpelling}.
13
+ *
14
+ * A callback that reads its index or array parameter never gets here: the
15
+ * support gate refuses it (`unboundCallbackParamRead`), because no DSL
16
+ * runtime binds those.
17
+ */
18
+ import { type ParsedExpr, type SortComparator } from '../expression-parser.ts';
19
+ type Arrow = Extract<ParsedExpr, {
20
+ kind: 'arrow';
21
+ }>;
22
+ /** The predicate members of `CALLBACK_METHODS`. */
23
+ export type PredicateMethod = 'filter' | 'every' | 'some' | 'find' | 'findIndex' | 'findLast' | 'findLastIndex';
24
+ /** Whether `method` is one of the {@link PredicateMethod}s. */
25
+ export declare function isPredicateMethod(method: string): method is PredicateMethod;
26
+ /** The runtime evaluator helpers, by id. Every DSL runtime spells them the same. */
27
+ export type CallbackEvalHelper = 'sort_eval' | 'reduce_eval' | 'filter_eval' | 'every_eval' | 'some_eval' | 'find_eval' | 'find_index_eval' | 'flat_map_eval' | 'map_eval';
28
+ /** An evaluator-call operand after the receiver and before the env. */
29
+ export type CallbackEvalOperand = {
30
+ kind: 'string';
31
+ value: string;
32
+ }
33
+ /** A number literal's source text. */
34
+ | {
35
+ kind: 'number';
36
+ text: string;
37
+ } | {
38
+ kind: 'boolean';
39
+ value: boolean;
40
+ };
41
+ /**
42
+ * An evaluator call: `helper(recv, ...operands, env)`. The operands carry the
43
+ * serialized body, the callback's param names and the per-helper extras (a
44
+ * reduce's initial value and direction, a find's direction). `captured` are
45
+ * the body's free names; the env maps each to its SSR value.
46
+ */
47
+ export interface CallbackEvalPlan {
48
+ kind: 'eval';
49
+ helper: CallbackEvalHelper;
50
+ operands: CallbackEvalOperand[];
51
+ captured: string[];
52
+ }
53
+ /** A lowered callback method call, as data. */
54
+ export type CallbackPlan = CallbackEvalPlan
55
+ /** A comparator the evaluator cannot model but the `{keys: …}` descriptor can. */
56
+ | {
57
+ kind: 'structured-sort';
58
+ comparator: SortComparator;
59
+ }
60
+ /** A predicate for the adapter's own native form (see `nativePredicate`). */
61
+ | {
62
+ kind: 'native-predicate';
63
+ method: PredicateMethod;
64
+ param: string;
65
+ predicate: ParsedExpr;
66
+ } | {
67
+ kind: 'refuse';
68
+ message: string;
69
+ suggestion: string;
70
+ }
71
+ /** A method outside `CALLBACK_METHODS`; unreachable, as the parser recognises only those. */
72
+ | {
73
+ kind: 'receiver';
74
+ };
75
+ export interface CallbackLoweringOptions {
76
+ /** The display name BF101 uses: "the Jinja adapter". */
77
+ adapterName: string;
78
+ /**
79
+ * The adapter lowers a predicate the evaluator cannot model to a native
80
+ * form (Xslate, ERB, Mojolicious). Such an adapter also takes the
81
+ * identity filter (`xs.filter(x => x)`) natively without trying the
82
+ * evaluator.
83
+ */
84
+ nativePredicate?: boolean;
85
+ }
86
+ /** Lower `<recv>.<method>(arrow, ...restArgs)`. */
87
+ export declare function lowerCallbackMethod(method: string, arrow: Arrow, restArgs: readonly ParsedExpr[], options: CallbackLoweringOptions): CallbackPlan;
88
+ /**
89
+ * The evaluator plan for a sort comparator, or `null` when the body is
90
+ * outside the evaluator surface (a `localeCompare` comparator) or the arrow
91
+ * has fewer than the two params a comparator needs. The loop-source sort
92
+ * shares this with `.sort(cmp)` at an expression position.
93
+ */
94
+ export declare function sortEvalPlan(body: ParsedExpr, params: readonly string[]): CallbackEvalPlan | null;
95
+ /** The BF101 for a comparator neither the evaluator nor the descriptor can model. */
96
+ export declare function sortRefusal(method: string, adapterName: string): {
97
+ kind: 'refuse';
98
+ message: string;
99
+ suggestion: string;
100
+ };
101
+ /** How one DSL backend spells an evaluator call. */
102
+ export interface CallbackEvalSpelling {
103
+ /** `helper(operands)`: `bf.sort_eval(…)`, `$bf->sort_eval(…)`, `bf->sort_eval(…)`. */
104
+ call(helper: CallbackEvalHelper, operands: readonly string[]): string;
105
+ /** A single-quoted string literal, escaped for the backend. */
106
+ string(value: string): string;
107
+ /** `true` / `false`, or Perl's `1` / `0`. */
108
+ boolean(value: boolean): string;
109
+ /** The env literal mapping each captured name to its SSR value, `{}` when empty. */
110
+ env(entries: ReadonlyArray<readonly [name: string, value: string]>): string;
111
+ }
112
+ /**
113
+ * Emit an evaluator plan. `recv` is the already-emitted receiver; `emit`
114
+ * renders each captured name's SSR value, after the receiver.
115
+ */
116
+ export declare function emitCallbackEval(plan: CallbackEvalPlan, recv: string, emit: (e: ParsedExpr) => string, spelling: CallbackEvalSpelling): string;
117
+ /**
118
+ * The BF101 for a callback method nested inside a filter predicate, which a
119
+ * predicate emitter has no scalar form for.
120
+ */
121
+ export declare function nestedCallbackRefusal(method: string, adapterName: string): {
122
+ message: string;
123
+ suggestion: string;
124
+ };
125
+ export {};
126
+ //# sourceMappingURL=callback-method.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"callback-method.d.ts","sourceRoot":"","sources":["../../src/adapters/callback-method.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAML,KAAK,UAAU,EACf,KAAK,cAAc,EACpB,MAAM,yBAAyB,CAAA;AAEhC,KAAK,KAAK,GAAG,OAAO,CAAC,UAAU,EAAE;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC,CAAA;AAEnD,mDAAmD;AACnD,MAAM,MAAM,eAAe,GACvB,QAAQ,GACR,OAAO,GACP,MAAM,GACN,MAAM,GACN,WAAW,GACX,UAAU,GACV,eAAe,CAAA;AAYnB,+DAA+D;AAC/D,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,IAAI,eAAe,CAE3E;AAED,oFAAoF;AACpF,MAAM,MAAM,kBAAkB,GAC1B,WAAW,GACX,aAAa,GACb,aAAa,GACb,YAAY,GACZ,WAAW,GACX,WAAW,GACX,iBAAiB,GACjB,eAAe,GACf,UAAU,CAAA;AAEd,uEAAuE;AACvE,MAAM,MAAM,mBAAmB,GAC3B;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE;AACnC,sCAAsC;GACpC;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAChC;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAAA;AAEvC;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAC/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,oDAAoD;AACpD,MAAM,WAAW,oBAAoB;IACnC,sFAAsF;IACtF,IAAI,CAAC,MAAM,EAAE,kBAAkB,EAAE,QAAQ,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAAA;IACrE,+DAA+D;IAC/D,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;IAC7B,6CAA6C;IAC7C,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAAA;IAC/B,oFAAoF;IACpF,GAAG,CAAC,OAAO,EAAE,aAAa,CAAC,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,GAAG,MAAM,CAAA;CAC5E;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,gBAAgB,EACtB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,MAAM,EAC/B,QAAQ,EAAE,oBAAoB,GAC7B,MAAM,CAUR;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAKlH"}
@@ -0,0 +1,99 @@
1
+ /**
2
+ * The props a DSL adapter passes to a child component's `render_child`
3
+ * call (#3479), as data.
4
+ *
5
+ * Every DSL adapter assembles them the same way: callback props and `ref`
6
+ * are client-only and dropped; a named JSX-valued prop is captured as
7
+ * HTML; `{...props}` (the component's own props object, which no DSL scope
8
+ * holds as one value) enumerates the props params; any other spread is
9
+ * folded in at its source position, so a later entry wins on a key
10
+ * conflict, as in `{...a, ...b}`; then the compiler-controlled `_bf_slot`
11
+ * and `children` entries come last, so a spread can never override them.
12
+ * {@link planComponentProps} makes those decisions once. An adapter spells
13
+ * the entries and spreads through {@link spellComponentProps}, keeps its
14
+ * own capture mechanism (`{% set %}…{% endset %}`, `_erbout.slice!`,
15
+ * `begin … end`, a Kolon macro), and folds the spelled segments into its
16
+ * own hash literal.
17
+ */
18
+ import type { AttrValue, IRComponent, IRNode, SpreadAttr } from '../types.ts';
19
+ /** One entry of the props hash. */
20
+ export type ComponentPropEntry =
21
+ /** An ordinary prop: the adapter lowers `value` with its `AttrValueEmitter`. */
22
+ {
23
+ kind: 'value';
24
+ name: string;
25
+ value: AttrValue;
26
+ }
27
+ /** A named JSX-valued prop (`header={<b/>}`): captured as HTML, passed by reference. */
28
+ | {
29
+ kind: 'named-slot';
30
+ name: string;
31
+ children: IRNode[];
32
+ }
33
+ /** One param of a spread props object (`{...props}`), read from its own template variable. */
34
+ | {
35
+ kind: 'props-param';
36
+ name: string;
37
+ }
38
+ /** The child's mount slot, for its scope id (`derivesScopeFromSlot`). */
39
+ | {
40
+ kind: 'slot-id';
41
+ slotId: string;
42
+ }
43
+ /** The forwarded children (nested `<Box>…</Box>`, or `children={<jsx/>}`): captured as HTML. */
44
+ | {
45
+ kind: 'children';
46
+ children: IRNode[];
47
+ };
48
+ /** A run of entries, or a spread folded in at its source position. */
49
+ export type ComponentPropSegment = {
50
+ kind: 'entries';
51
+ entries: ComponentPropEntry[];
52
+ } | {
53
+ kind: 'spread';
54
+ value: SpreadAttr;
55
+ };
56
+ export interface ComponentPropsOptions {
57
+ /** The SolidJS-style props identifier (`function C(props: P)`), if any. */
58
+ propsObjectName: string | null;
59
+ /** The analyzer-extracted props params, which `{...props}` enumerates. */
60
+ propsParams: ReadonlyArray<{
61
+ name: string;
62
+ }>;
63
+ }
64
+ /** The key an entry sets in the props hash. */
65
+ export declare function componentPropKey(entry: ComponentPropEntry): string;
66
+ /**
67
+ * The ordered props segments for `comp`. The first segment is always an
68
+ * (possibly empty) entries segment, and a spread is followed by a new one
69
+ * only when an entry comes after it.
70
+ */
71
+ export declare function planComponentProps(comp: IRComponent, options: ComponentPropsOptions): ComponentPropSegment[];
72
+ /** A spelled segment: the entries' hash-literal parts, or the spread's expression. */
73
+ export type SpelledComponentPropSegment = {
74
+ kind: 'entries';
75
+ parts: string[];
76
+ } | {
77
+ kind: 'spread';
78
+ expr: string;
79
+ };
80
+ export interface ComponentPropSpelling {
81
+ /** The hash-literal part for one entry; `''` drops it. */
82
+ entry(entry: ComponentPropEntry): string;
83
+ /** The expression a spread folds in. */
84
+ spread(value: SpreadAttr): string;
85
+ }
86
+ /**
87
+ * Spell a plan in source order, so the captures an entry's spelling emits
88
+ * (named slots, then the children) keep their order and counter values.
89
+ */
90
+ export declare function spellComponentProps(segments: readonly ComponentPropSegment[], spelling: ComponentPropSpelling): SpelledComponentPropSegment[];
91
+ /** Whether a spelled plan passes no props at all. */
92
+ export declare function isEmptyComponentProps(segments: readonly SpelledComponentPropSegment[]): boolean;
93
+ /**
94
+ * The template a child component renders from: the component's declared
95
+ * name, resolved through an import alias (`import { Foo as Bar }`, `<Bar/>`
96
+ * renders `foo`, #2822), in snake_case.
97
+ */
98
+ export declare function childTemplateName(componentName: string, importAliases: ReadonlyMap<string, string>): string;
99
+ //# sourceMappingURL=component-props.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component-props.d.ts","sourceRoot":"","sources":["../../src/adapters/component-props.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAG7E,mCAAmC;AACnC,MAAM,MAAM,kBAAkB;AAC5B,gFAAgF;AAC9E;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,SAAS,CAAA;CAAE;AACnD,wFAAwF;GACtF;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;CAAE;AAC1D,8FAA8F;GAC5F;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,IAAI,EAA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AAoB,EAAE,EACzC,QAAQ,EAAE,qBAAqB,GAC9B,2BAA2B,EAAE,CAU/B;AAED,qDAAqD;AACrD,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,SAAS,2BAA2B,EAAE,GAAG,OAAO,CAE/F;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,aAAa,EAAE,MAAM,EAAE,aAAa,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAM3G"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Component-tree analysis shared by the DSL template adapters (#3475).
3
+ *
4
+ * Pure functions over the IR; they read no adapter instance state.
5
+ * `collectImportedLoopChildComponentErrors` returns its diagnostics instead
6
+ * of pushing onto an adapter's error list, so the adapter stays the sole
7
+ * owner of `errors`.
8
+ */
9
+ import type { ComponentIR, CompilerError } from '../types.ts';
10
+ /**
11
+ * Whether the component needs the client runtime — it owns reactive state
12
+ * (signals / effects / onMount) or the analyzer flagged it as needing init.
13
+ */
14
+ export declare function hasClientInteractivity(ir: ComponentIR): boolean;
15
+ /**
16
+ * Build a `BF103` diagnostic for every component reference inside a loop body
17
+ * whose name is imported from a relative-path module. A DSL template backend
18
+ * renders such a child as a cross-template call, so the child's compiled
19
+ * template must be registered with the backend's loader alongside the
20
+ * parent at render time. `adapterName` is the display name the message
21
+ * uses ("The Jinja adapter emits …", "the resulting Jinja template").
22
+ * Returns the diagnostics so the caller pushes them onto its own error list.
23
+ */
24
+ export declare function collectImportedLoopChildComponentErrors(ir: ComponentIR, componentName: string, adapterName: string): CompilerError[];
25
+ //# sourceMappingURL=component-tree.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component-tree.d.ts","sourceRoot":"","sources":["../../src/adapters/component-tree.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,WAAW,EAUX,aAAa,EACd,MAAM,aAAa,CAAA;AAEpB;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,EAAE,EAAE,WAAW,GAAG,OAAO,CAO/D;AAED;;;;;;;;GAQG;AACH,wBAAgB,uCAAuC,CACrD,EAAE,EAAE,WAAW,EACf,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,MAAM,GAClB,aAAa,EAAE,CAsBjB"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Literal-value predicates shared by the DSL template adapters (#3475).
3
+ *
4
+ * Pure functions over analyzer type info and parsed expressions. Every DSL
5
+ * adapter classifies string-typed signals, props and constants with
6
+ * {@link isStringTypeInfo} / {@link isBareStringLiteral}, and tells a
7
+ * literal index from a variable one with {@link isLiteralIndex}.
8
+ */
9
+ import type { ParsedExpr } from '../expression-parser.ts';
10
+ import type { TypeInfo } from '../types.ts';
11
+ /** True when `type` is the `string` primitive. */
12
+ export declare function isStringTypeInfo(type: TypeInfo | undefined): boolean;
13
+ /** True when `initialValue` is a bare string-literal expression. */
14
+ export declare function isBareStringLiteral(initialValue: string | undefined): boolean;
15
+ /**
16
+ * True when a parsed index is a numeric or string literal (`arr[0]`,
17
+ * `m['k']`). The spread lowerings refuse (BF101) an indexed spread value
18
+ * they could not inline only when its index is NOT a literal: a
19
+ * variable-index record access (`sizeMap[size]`) has no static answer.
20
+ */
21
+ export declare function isLiteralIndex(index: ParsedExpr): boolean;
22
+ //# sourceMappingURL=literal-value.d.ts.map