@barefootjs/jsx 0.39.5 → 0.39.7
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/adapters/array-method.d.ts +93 -0
- package/dist/adapters/array-method.d.ts.map +1 -0
- package/dist/adapters/attr-plan.d.ts +142 -0
- package/dist/adapters/attr-plan.d.ts.map +1 -0
- package/dist/adapters/boolean-result.d.ts +84 -9
- package/dist/adapters/boolean-result.d.ts.map +1 -1
- package/dist/adapters/callback-method.d.ts +153 -0
- package/dist/adapters/callback-method.d.ts.map +1 -0
- package/dist/adapters/component-props.d.ts +99 -0
- package/dist/adapters/component-props.d.ts.map +1 -0
- package/dist/adapters/component-tree.d.ts +25 -0
- package/dist/adapters/component-tree.d.ts.map +1 -0
- package/dist/adapters/computed-const.d.ts +52 -0
- package/dist/adapters/computed-const.d.ts.map +1 -0
- package/dist/adapters/dangerous-inner-html.d.ts +10 -0
- package/dist/adapters/dangerous-inner-html.d.ts.map +1 -1
- package/dist/adapters/element-shell.d.ts +44 -0
- package/dist/adapters/element-shell.d.ts.map +1 -0
- package/dist/adapters/interface.d.ts +2 -0
- package/dist/adapters/interface.d.ts.map +1 -1
- package/dist/adapters/literal-value.d.ts +22 -0
- package/dist/adapters/literal-value.d.ts.map +1 -0
- package/dist/adapters/loop-plan.d.ts +53 -0
- package/dist/adapters/loop-plan.d.ts.map +1 -0
- package/dist/adapters/prop-classes.d.ts +37 -0
- package/dist/adapters/prop-classes.d.ts.map +1 -0
- package/dist/analyzer.d.ts.map +1 -1
- package/dist/augment-inherited-props.d.ts +7 -0
- package/dist/augment-inherited-props.d.ts.map +1 -1
- package/dist/expression-parser.d.ts +38 -0
- package/dist/expression-parser.d.ts.map +1 -1
- package/dist/fold-render-reassignments.d.ts +43 -0
- package/dist/fold-render-reassignments.d.ts.map +1 -0
- package/dist/free-refs.d.ts +9 -0
- package/dist/free-refs.d.ts.map +1 -1
- package/dist/index.d.ts +23 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3954 -2401
- package/dist/ir-to-client-js/compute-inlinability.d.ts.map +1 -1
- package/dist/ir-to-client-js/csr-substitute.d.ts +0 -13
- package/dist/ir-to-client-js/csr-substitute.d.ts.map +1 -1
- package/dist/ir-to-client-js/emit-registration.d.ts.map +1 -1
- package/dist/ir-to-client-js/html-template.d.ts +9 -10
- package/dist/ir-to-client-js/html-template.d.ts.map +1 -1
- package/dist/ir-to-client-js/index.d.ts.map +1 -1
- package/dist/ir-to-client-js/plan/declaration-emit.d.ts +5 -0
- package/dist/ir-to-client-js/plan/declaration-emit.d.ts.map +1 -1
- package/dist/ir-to-client-js/prop-handling.d.ts +11 -12
- package/dist/ir-to-client-js/prop-handling.d.ts.map +1 -1
- package/dist/ir-to-client-js/utils.d.ts +13 -0
- package/dist/ir-to-client-js/utils.d.ts.map +1 -1
- package/dist/jsx-to-ir.d.ts +465 -1
- package/dist/jsx-to-ir.d.ts.map +1 -1
- package/dist/nullable-signal-attr.d.ts +22 -2
- package/dist/nullable-signal-attr.d.ts.map +1 -1
- package/dist/props-binding.d.ts +34 -5
- package/dist/props-binding.d.ts.map +1 -1
- package/dist/relocate.d.ts +16 -0
- package/dist/relocate.d.ts.map +1 -1
- package/dist/ssr-seed-plan.d.ts +0 -6
- package/dist/ssr-seed-plan.d.ts.map +1 -1
- package/dist/types.d.ts +54 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +1 -1
- package/src/__tests__/action-accessor.test.ts +6 -24
- package/src/__tests__/array-method-catalogue.test.ts +99 -0
- package/src/__tests__/attr-plan.test.ts +121 -0
- package/src/__tests__/binding-scope-ratchet.test.ts +12 -12
- package/src/__tests__/block-memo-type.test.ts +51 -0
- package/src/__tests__/boolean-result-expr.test.ts +106 -0
- package/src/__tests__/boolean-result.test.ts +34 -1
- package/src/__tests__/callback-method.test.ts +264 -0
- package/src/__tests__/client-only-date-lowering.test.ts +2 -2
- package/src/__tests__/component-props.test.ts +148 -0
- package/src/__tests__/computed-const.test.ts +101 -0
- package/src/__tests__/delegated-handler-preamble.test.ts +4 -4
- package/src/__tests__/dsl-shared-helpers.test.ts +166 -0
- package/src/__tests__/element-shell.test.ts +78 -0
- package/src/__tests__/fold-render-reassignments.test.ts +96 -0
- package/src/__tests__/inlinable-local-method-call.test.ts +81 -0
- package/src/__tests__/issue-3240-nested-static-map-event-delegation.test.ts +1 -1
- package/src/__tests__/loop-plan.test.ts +104 -0
- package/src/__tests__/map-call-decisions.test.ts +521 -0
- package/src/__tests__/memo-body-expr.test.ts +120 -0
- package/src/__tests__/nullable-signal-attr.test.ts +45 -0
- package/src/__tests__/prop-handling.test.ts +35 -16
- package/src/__tests__/props-alias-const.test.ts +65 -0
- package/src/__tests__/signal-prop-seed.test.ts +90 -0
- package/src/__tests__/ssr-seed-plan.test.ts +54 -1
- package/src/__tests__/static-template-reachability.test.ts +137 -0
- package/src/adapters/array-method.ts +193 -0
- package/src/adapters/attr-plan.ts +228 -0
- package/src/adapters/boolean-result.ts +208 -12
- package/src/adapters/callback-method.ts +363 -0
- package/src/adapters/component-props.ts +144 -0
- package/src/adapters/component-tree.ts +118 -0
- package/src/adapters/computed-const.ts +185 -0
- package/src/adapters/dangerous-inner-html.ts +33 -0
- package/src/adapters/element-shell.ts +160 -0
- package/src/adapters/interface.ts +8 -0
- package/src/adapters/literal-value.ts +36 -0
- package/src/adapters/loop-plan.ts +88 -0
- package/src/adapters/prop-classes.ts +73 -0
- package/src/analyzer.ts +271 -82
- package/src/augment-inherited-props.ts +12 -0
- package/src/expression-parser.ts +537 -374
- package/src/fold-render-reassignments.ts +314 -0
- package/src/free-refs.ts +49 -0
- package/src/index.ts +61 -3
- package/src/ir-to-client-js/compute-inlinability.ts +93 -17
- package/src/ir-to-client-js/control-flow/stringify/event-delegation.ts +9 -7
- package/src/ir-to-client-js/csr-substitute.ts +13 -35
- package/src/ir-to-client-js/emit-registration.ts +3 -2
- package/src/ir-to-client-js/html-template.ts +26 -70
- package/src/ir-to-client-js/index.ts +3 -2
- package/src/ir-to-client-js/init-declarations.ts +1 -1
- package/src/ir-to-client-js/plan/build-declaration-emit.ts +25 -51
- package/src/ir-to-client-js/plan/declaration-emit.ts +5 -0
- package/src/ir-to-client-js/prop-handling.ts +13 -54
- package/src/ir-to-client-js/rewrite-destructured-props.ts +6 -5
- package/src/ir-to-client-js/stringify/declaration-emit.ts +1 -1
- package/src/ir-to-client-js/utils.ts +11 -0
- package/src/jsx-to-ir.ts +1346 -1022
- package/src/nullable-signal-attr.ts +85 -4
- package/src/props-binding.ts +100 -5
- package/src/relocate.ts +40 -8
- package/src/ssr-seed-plan.ts +18 -6
- package/src/types.ts +50 -2
|
@@ -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":"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
* 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 { CompilerError, 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 BF101 for an attribute value {@link unsupportedAttrExpression}
|
|
29
|
+
* refuses, worded for one adapter (`adapterLabel`, e.g. `Mojo`) and its
|
|
30
|
+
* template language (`languageLabel`, e.g. `Embedded Perl`); `null` when the
|
|
31
|
+
* value goes on to {@link planAttrExpression}.
|
|
32
|
+
*/
|
|
33
|
+
export declare function unsupportedAttrExpressionError(expr: string, attrName: string, loweringMatchers: readonly LoweringMatcher[], componentName: string, adapterLabel: string, languageLabel: string): CompilerError | null;
|
|
34
|
+
/**
|
|
35
|
+
* The emission of an `{expr}` attribute value.
|
|
36
|
+
*
|
|
37
|
+
* - `omit-nullable`: a bare read of an optional, no-default prop or of a
|
|
38
|
+
* nullable signal (#2248, #3304). The attribute is guarded by a nil test
|
|
39
|
+
* on the value itself, as Hono drops an `undefined` attribute.
|
|
40
|
+
* `restKey` marks a closed-type rest-expanded key (`rest.tag`, #3057).
|
|
41
|
+
* - `boolean-attr`: an HTML boolean attribute (`disabled`), present when
|
|
42
|
+
* the value is truthy.
|
|
43
|
+
* - `presence`: `attr={expr || undefined}` (#1897). The value is bound to a
|
|
44
|
+
* temporary once and rendered when truthy.
|
|
45
|
+
* - `undefined-alternate`: `attr={cond ? value : undefined}` (or `: null`).
|
|
46
|
+
* The attribute is rendered when `cond` holds.
|
|
47
|
+
* - `omit-nil`: a value that may reach `null` / `undefined` through a memo,
|
|
48
|
+
* an optional member read or a ternary branch (#3322). The value is bound
|
|
49
|
+
* to a temporary once and rendered when not nil.
|
|
50
|
+
* - `plain`: always rendered.
|
|
51
|
+
*
|
|
52
|
+
* `boolStr`: the value is boolean-shaped and goes through `bool_str`, so the
|
|
53
|
+
* bytes match JS `String(boolean)`.
|
|
54
|
+
*/
|
|
55
|
+
export type AttrExpressionPlan = {
|
|
56
|
+
kind: 'omit-nullable';
|
|
57
|
+
boolStr: boolean;
|
|
58
|
+
restKey: boolean;
|
|
59
|
+
} | {
|
|
60
|
+
kind: 'boolean-attr';
|
|
61
|
+
} | {
|
|
62
|
+
kind: 'presence';
|
|
63
|
+
boolStr: boolean;
|
|
64
|
+
} | {
|
|
65
|
+
kind: 'undefined-alternate';
|
|
66
|
+
ternary: UndefinedAlternateTernary;
|
|
67
|
+
} | {
|
|
68
|
+
kind: 'omit-nil';
|
|
69
|
+
boolStr: boolean;
|
|
70
|
+
} | {
|
|
71
|
+
kind: 'plain';
|
|
72
|
+
boolStr: boolean;
|
|
73
|
+
};
|
|
74
|
+
export interface AttrPlanContext {
|
|
75
|
+
/** The SolidJS-style props identifier (`function C(props: P)`), if any. */
|
|
76
|
+
propsObjectName: string | null;
|
|
77
|
+
/** The destructured `...rest` binding (`function C({ ...rest })`), if any. */
|
|
78
|
+
restPropsName: string | null;
|
|
79
|
+
/** Optional, no-default props, by bare name (`collectNullableOptionalProps`). */
|
|
80
|
+
nullableOptionalProps: ReadonlySet<string>;
|
|
81
|
+
/** Signal getters whose SSR value may be `undefined` (`collectNullableSignalGetters`). */
|
|
82
|
+
nullableSignalGetters: ReadonlySet<string>;
|
|
83
|
+
nullishAttrCtx: NullishAttrContext;
|
|
84
|
+
/** A loop binding at the attribute site shadows `name`. */
|
|
85
|
+
isLoopBound(name: string): boolean;
|
|
86
|
+
/** The adapter routes this value through `bool_str`. */
|
|
87
|
+
boolStr(expr: string, name: string): boolean;
|
|
88
|
+
}
|
|
89
|
+
/** Plan an `{expr}` attribute value. */
|
|
90
|
+
export declare function planAttrExpression(value: ExpressionAttr, name: string, ctx: AttrPlanContext): AttrExpressionPlan;
|
|
91
|
+
/**
|
|
92
|
+
* `cond ? value : undefined` (or `: null`), whose falsy branch drops the
|
|
93
|
+
* attribute (#1897).
|
|
94
|
+
*
|
|
95
|
+
* `testParsed` / `consequentParsed` are the parsed sub-trees, for the caller
|
|
96
|
+
* to lower directly (#2843 review). `condition` / `consequent` are
|
|
97
|
+
* `exprToString` output, a debug formatter that renders a nested object
|
|
98
|
+
* literal as a non-reparseable `[UNSUPPORTED: …]` placeholder: re-parsing it
|
|
99
|
+
* would corrupt a call like `queryHref(base, { tag })` before the lowering
|
|
100
|
+
* registry sees it. They are serialised from the parsed tree rather than
|
|
101
|
+
* sliced from the text, which would mis-split `cond ? 'a:b' : undefined`.
|
|
102
|
+
*/
|
|
103
|
+
export interface UndefinedAlternateTernary {
|
|
104
|
+
condition: string;
|
|
105
|
+
consequent: string;
|
|
106
|
+
testParsed: ParsedExpr;
|
|
107
|
+
consequentParsed: ParsedExpr;
|
|
108
|
+
}
|
|
109
|
+
/** Parse `cond ? value : undefined` (or `: null`), or `null` for any other shape. */
|
|
110
|
+
export declare function parseUndefinedAlternateTernary(expr: string): UndefinedAlternateTernary | null;
|
|
111
|
+
/**
|
|
112
|
+
* The emission of a `{...spread}` attribute.
|
|
113
|
+
*
|
|
114
|
+
* - `props-object`: `{...props}`, the component's own props object, which no
|
|
115
|
+
* template scope holds as one value. The adapter enumerates `params` into
|
|
116
|
+
* a hash literal.
|
|
117
|
+
* - `value`: any other spread. The adapter tries its conditional-spread
|
|
118
|
+
* lowering (`{...(cond ? {…} : {})}`) on each of `candidates` in order:
|
|
119
|
+
* the spread's own tree, then the initializer of the function-scope
|
|
120
|
+
* `const` it names (`const sizeAttrs = size ? {…} : {}`), unless a loop
|
|
121
|
+
* binding shadows that name (#2489). If none lowers, it spreads the
|
|
122
|
+
* expression itself.
|
|
123
|
+
*/
|
|
124
|
+
export type SpreadAttrPlan = {
|
|
125
|
+
kind: 'props-object';
|
|
126
|
+
params: string[];
|
|
127
|
+
} | {
|
|
128
|
+
kind: 'value';
|
|
129
|
+
candidates: Array<ParsedExpr | undefined>;
|
|
130
|
+
};
|
|
131
|
+
export interface SpreadPlanContext {
|
|
132
|
+
propsObjectName: string | null;
|
|
133
|
+
propsParams: ReadonlyArray<{
|
|
134
|
+
name: string;
|
|
135
|
+
}>;
|
|
136
|
+
localConstants: readonly ConstantInfo[];
|
|
137
|
+
/** A binding at the spread site shadows `name`. */
|
|
138
|
+
isBound(name: string): boolean;
|
|
139
|
+
}
|
|
140
|
+
/** Plan a `{...spread}` attribute. */
|
|
141
|
+
export declare function planSpreadAttr(value: SpreadAttr, ctx: SpreadPlanContext): SpreadAttrPlan;
|
|
142
|
+
//# 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,K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,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
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
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
|
-
|
|
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
|
|
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,153 @@
|
|
|
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
|
+
* Whether a call that reached an adapter's generic fallback has no lowering
|
|
119
|
+
* (#3493). A zero-arg call reads a getter (`props.value()`, a getter passed
|
|
120
|
+
* as a prop, a context getter `ctx.open()`), unless its receiver is rooted at
|
|
121
|
+
* a JavaScript global (`Date.now()`, `window.performance.now()`): `isGlobal`
|
|
122
|
+
* answers that from the component's bindings and the live loop scope, and a
|
|
123
|
+
* global has no binding in template scope (#3505). A call to a
|
|
124
|
+
* function-valued prop (`props.renderNode(node)`, a render prop) names a
|
|
125
|
+
* value a backend caller never passes, so the guard around it is never taken
|
|
126
|
+
* there; it keeps the callee read. Any other call with arguments
|
|
127
|
+
* (`s().localeCompare('m')`) would lose the call and its arguments.
|
|
128
|
+
* `propsObjectName` is the undestructured props parameter (`props`), `null`
|
|
129
|
+
* when the props are destructured: a destructured render prop is a
|
|
130
|
+
* bare-name call, which the adapters refuse on their own.
|
|
131
|
+
*/
|
|
132
|
+
export declare function isUnloweredCall(callee: ParsedExpr, args: readonly ParsedExpr[], propsObjectName: string | null, isGlobal: (name: string) => boolean): boolean;
|
|
133
|
+
/**
|
|
134
|
+
* The BF101 for a call no template lowers: a method outside the array-method
|
|
135
|
+
* catalogue (`s().localeCompare('m')`), a zero-arg call on a JavaScript
|
|
136
|
+
* global (`Date.now()`), or any other callee that is not a getter, a template
|
|
137
|
+
* primitive or a lowering plugin's call. Read as its callee, the call and its
|
|
138
|
+
* arguments would silently disappear (#3493, #3505).
|
|
139
|
+
*/
|
|
140
|
+
export declare function unloweredCallRefusal(callee: ParsedExpr, args: readonly ParsedExpr[], adapterName: string): {
|
|
141
|
+
message: string;
|
|
142
|
+
suggestion: string;
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* The BF101 for a callback method nested inside a filter predicate, which a
|
|
146
|
+
* predicate emitter has no scalar form for.
|
|
147
|
+
*/
|
|
148
|
+
export declare function nestedCallbackRefusal(method: string, adapterName: string): {
|
|
149
|
+
message: string;
|
|
150
|
+
suggestion: string;
|
|
151
|
+
};
|
|
152
|
+
export {};
|
|
153
|
+
//# 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,EAOL,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,QAA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QAAQ,EAAE,oBAAoB,GAC7B,MAAM,CAUR;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,SAAS,UAAU,EAAE,EAC3B,eAAe,EAAE,MAAM,GAAG,IAAI,EAC9B,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,GAClC,OAAO,CAMT;AAcD;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,SAAS,UAAU,EAAE,EAC3B,WAAW,EAAE,MAAM,GAClB;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAQzC;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
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