@barefootjs/jsx 0.40.1 → 0.41.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.
Files changed (211) hide show
  1. package/dist/adapters/boolean-result.d.ts +32 -10
  2. package/dist/adapters/boolean-result.d.ts.map +1 -1
  3. package/dist/adapters/brace-delimiter-text.d.ts +18 -0
  4. package/dist/adapters/brace-delimiter-text.d.ts.map +1 -0
  5. package/dist/adapters/callback-method.d.ts +45 -5
  6. package/dist/adapters/callback-method.d.ts.map +1 -1
  7. package/dist/adapters/component-props.d.ts +3 -4
  8. package/dist/adapters/component-props.d.ts.map +1 -1
  9. package/dist/adapters/computed-const.d.ts +11 -1
  10. package/dist/adapters/computed-const.d.ts.map +1 -1
  11. package/dist/adapters/dsl-template-adapter.d.ts +24 -12
  12. package/dist/adapters/dsl-template-adapter.d.ts.map +1 -1
  13. package/dist/adapters/loop-bound-names.d.ts +9 -1
  14. package/dist/adapters/loop-bound-names.d.ts.map +1 -1
  15. package/dist/adapters/loop-row-type.d.ts +59 -0
  16. package/dist/adapters/loop-row-type.d.ts.map +1 -0
  17. package/dist/adapters/nil-reading.d.ts +63 -0
  18. package/dist/adapters/nil-reading.d.ts.map +1 -0
  19. package/dist/adapters/non-primitive-equality.d.ts +33 -0
  20. package/dist/adapters/non-primitive-equality.d.ts.map +1 -0
  21. package/dist/adapters/number-value.d.ts +5 -3
  22. package/dist/adapters/number-value.d.ts.map +1 -1
  23. package/dist/adapters/operand-typing.d.ts +126 -0
  24. package/dist/adapters/operand-typing.d.ts.map +1 -0
  25. package/dist/adapters/parsed-expr-emitter.d.ts +80 -12
  26. package/dist/adapters/parsed-expr-emitter.d.ts.map +1 -1
  27. package/dist/adapters/primitive-plan.d.ts +320 -0
  28. package/dist/adapters/primitive-plan.d.ts.map +1 -0
  29. package/dist/adapters/prop-classes.d.ts +5 -0
  30. package/dist/adapters/prop-classes.d.ts.map +1 -1
  31. package/dist/analyzer-context.d.ts +4 -0
  32. package/dist/analyzer-context.d.ts.map +1 -1
  33. package/dist/analyzer.d.ts.map +1 -1
  34. package/dist/augment-inherited-props.d.ts +63 -8
  35. package/dist/augment-inherited-props.d.ts.map +1 -1
  36. package/dist/compiler.d.ts.map +1 -1
  37. package/dist/event-handler-name.d.ts +12 -0
  38. package/dist/event-handler-name.d.ts.map +1 -1
  39. package/dist/expression-parser.d.ts +8 -0
  40. package/dist/expression-parser.d.ts.map +1 -1
  41. package/dist/index.d.ts +20 -11
  42. package/dist/index.d.ts.map +1 -1
  43. package/dist/index.js +4903 -2311
  44. package/dist/ir-to-client-js/build-references.d.ts.map +1 -1
  45. package/dist/ir-to-client-js/child-props-object.d.ts +106 -0
  46. package/dist/ir-to-client-js/child-props-object.d.ts.map +1 -0
  47. package/dist/ir-to-client-js/collect-elements.d.ts.map +1 -1
  48. package/dist/ir-to-client-js/control-flow/plan/build-inner-loop.d.ts.map +1 -1
  49. package/dist/ir-to-client-js/control-flow/plan/build-loop-child-arm.d.ts.map +1 -1
  50. package/dist/ir-to-client-js/control-flow/shared.d.ts.map +1 -1
  51. package/dist/ir-to-client-js/control-flow/stringify/claim-plan.d.ts +4 -2
  52. package/dist/ir-to-client-js/control-flow/stringify/claim-plan.d.ts.map +1 -1
  53. package/dist/ir-to-client-js/html-template.d.ts.map +1 -1
  54. package/dist/ir-to-client-js/imports.d.ts +2 -2
  55. package/dist/ir-to-client-js/imports.d.ts.map +1 -1
  56. package/dist/ir-to-client-js/index.d.ts +2 -6
  57. package/dist/ir-to-client-js/index.d.ts.map +1 -1
  58. package/dist/ir-to-client-js/phases/props-extraction.d.ts +3 -3
  59. package/dist/ir-to-client-js/plan/build-declaration-emit.d.ts.map +1 -1
  60. package/dist/ir-to-client-js/plan/build-static-array-child-init.d.ts.map +1 -1
  61. package/dist/ir-to-client-js/plan/static-array-child-init.d.ts +30 -18
  62. package/dist/ir-to-client-js/plan/static-array-child-init.d.ts.map +1 -1
  63. package/dist/ir-to-client-js/prop-handling.d.ts.map +1 -1
  64. package/dist/ir-to-client-js/prune-unused-prop-extractions.d.ts +3 -1
  65. package/dist/ir-to-client-js/prune-unused-prop-extractions.d.ts.map +1 -1
  66. package/dist/ir-to-client-js/stringify/static-array-child-init.d.ts +3 -2
  67. package/dist/ir-to-client-js/stringify/static-array-child-init.d.ts.map +1 -1
  68. package/dist/jsx-to-ir.d.ts +1 -0
  69. package/dist/jsx-to-ir.d.ts.map +1 -1
  70. package/dist/nullable-signal-attr.d.ts +51 -34
  71. package/dist/nullable-signal-attr.d.ts.map +1 -1
  72. package/dist/prop-rewrite.d.ts +7 -0
  73. package/dist/prop-rewrite.d.ts.map +1 -1
  74. package/dist/props-binding.d.ts +58 -13
  75. package/dist/props-binding.d.ts.map +1 -1
  76. package/dist/props-object-whole-read.d.ts +15 -0
  77. package/dist/props-object-whole-read.d.ts.map +1 -0
  78. package/dist/rich-type-refusal.d.ts.map +1 -1
  79. package/dist/scope/binding-scope.d.ts +85 -10
  80. package/dist/scope/binding-scope.d.ts.map +1 -1
  81. package/dist/scope/lexical-scope-walk.d.ts +3 -2
  82. package/dist/scope/lexical-scope-walk.d.ts.map +1 -1
  83. package/dist/scope/root-prop-alias.d.ts +10 -7
  84. package/dist/scope/root-prop-alias.d.ts.map +1 -1
  85. package/dist/ssr-defaults.d.ts +39 -3
  86. package/dist/ssr-defaults.d.ts.map +1 -1
  87. package/dist/strip-types.d.ts +13 -0
  88. package/dist/strip-types.d.ts.map +1 -1
  89. package/dist/template-position-walk.d.ts +21 -3
  90. package/dist/template-position-walk.d.ts.map +1 -1
  91. package/dist/types.d.ts +90 -0
  92. package/dist/types.d.ts.map +1 -1
  93. package/package.json +2 -2
  94. package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +9 -9
  95. package/src/__tests__/binding-scope.test.ts +89 -1
  96. package/src/__tests__/body-destructure-props-object-alias.test.ts +123 -0
  97. package/src/__tests__/body-destructured-prop-default-arrow.test.ts +2 -2
  98. package/src/__tests__/body-destructured-props-live.test.ts +5 -5
  99. package/src/__tests__/boolean-result.test.ts +22 -5
  100. package/src/__tests__/brace-delimiter-text.test.ts +26 -0
  101. package/src/__tests__/callback-method.test.ts +62 -2
  102. package/src/__tests__/child-components-in-map.test.ts +1 -1
  103. package/src/__tests__/client-js-generation.test.ts +3 -3
  104. package/src/__tests__/computed-const.test.ts +103 -0
  105. package/src/__tests__/destructure-default-reads-earlier-param.test.ts +7 -7
  106. package/src/__tests__/destructured-props-live.test.ts +1 -1
  107. package/src/__tests__/emit-to-string-call.test.ts +2 -1
  108. package/src/__tests__/hydration-payload-analysis.test.ts +166 -0
  109. package/src/__tests__/issue-2724-prop-alias-loop-not-static.test.ts +7 -7
  110. package/src/__tests__/issue-2754-rest-spread-needs-slot.test.ts +5 -2
  111. package/src/__tests__/issue-2798-static-nested-loop-bindings.test.ts +1 -1
  112. package/src/__tests__/issue-2835-props-type-member-name-collision.test.ts +4 -4
  113. package/src/__tests__/issue-3044-nested-prop-object-array-not-static.test.ts +1 -1
  114. package/src/__tests__/issue-3688-props-spread-child-csr.test.ts +2 -1
  115. package/src/__tests__/issue-3713-props-spread-loop-row.test.ts +65 -0
  116. package/src/__tests__/issue-3861-object-spread-child.test.ts +102 -0
  117. package/src/__tests__/lookup-literal-const.test.ts +9 -3
  118. package/src/__tests__/loop-index-reactivity.test.ts +2 -2
  119. package/src/__tests__/loop-param-accessor-key-member-safety.test.ts +1 -1
  120. package/src/__tests__/loop-plan.test.ts +1 -1
  121. package/src/__tests__/loop-row-const-initializer-shadow.test.ts +146 -0
  122. package/src/__tests__/loop-row-type.test.ts +64 -0
  123. package/src/__tests__/lowering-value-position.test.ts +4 -0
  124. package/src/__tests__/memo-body-expr.test.ts +2 -2
  125. package/src/__tests__/module-const-destructure-default.test.ts +156 -0
  126. package/src/__tests__/nested-loop-index-param.test.ts +1 -1
  127. package/src/__tests__/nested-loop-reactive-attrs.test.ts +2 -2
  128. package/src/__tests__/nested-row-shadowing.test.ts +2 -2
  129. package/src/__tests__/nil-reading.test.ts +78 -0
  130. package/src/__tests__/nullable-signal-attr.test.ts +109 -48
  131. package/src/__tests__/primitive-plan.test.ts +494 -0
  132. package/src/__tests__/profile-loop-binding-ids.test.ts +2 -2
  133. package/src/__tests__/profile-nested-binding-ids.test.ts +2 -2
  134. package/src/__tests__/prop-default-undefined-only.test.ts +115 -0
  135. package/src/__tests__/prop-references.test.ts +2 -2
  136. package/src/__tests__/props-destructuring.test.ts +17 -0
  137. package/src/__tests__/props-object-whole-read.test.ts +40 -0
  138. package/src/__tests__/prune-unused-prop-extractions.test.ts +3 -3
  139. package/src/__tests__/reactive-attrs-in-map.test.ts +1 -1
  140. package/src/__tests__/reactive-factory-inlining.test.ts +4 -1
  141. package/src/__tests__/renamed-body-destructure-template.test.ts +7 -7
  142. package/src/__tests__/rest-binding-gaps.test.ts +192 -0
  143. package/src/__tests__/rewrite-destructured-props.test.ts +1 -1
  144. package/src/__tests__/root-prop-alias.test.ts +53 -8
  145. package/src/__tests__/ssr-defaults.test.ts +113 -25
  146. package/src/__tests__/static-loop-csr-materialize.test.ts +2 -2
  147. package/src/__tests__/static-record-literal-array.test.ts +171 -0
  148. package/src/__tests__/string-concat-identifier.test.ts +40 -1
  149. package/src/__tests__/written-binding-substitution.test.ts +8 -8
  150. package/src/adapters/boolean-result.ts +72 -66
  151. package/src/adapters/brace-delimiter-text.ts +25 -0
  152. package/src/adapters/callback-method.ts +159 -27
  153. package/src/adapters/component-props.ts +3 -4
  154. package/src/adapters/computed-const.ts +238 -4
  155. package/src/adapters/dsl-template-adapter.ts +62 -26
  156. package/src/adapters/loop-bound-names.ts +9 -1
  157. package/src/adapters/loop-plan.ts +1 -1
  158. package/src/adapters/loop-row-type.ts +149 -0
  159. package/src/adapters/nil-reading.ts +295 -0
  160. package/src/adapters/non-primitive-equality.ts +92 -0
  161. package/src/adapters/number-value.ts +17 -4
  162. package/src/adapters/operand-typing.ts +522 -0
  163. package/src/adapters/parsed-expr-emitter.ts +183 -19
  164. package/src/adapters/primitive-plan.ts +765 -0
  165. package/src/adapters/prop-classes.ts +16 -3
  166. package/src/analyzer-context.ts +6 -0
  167. package/src/analyzer.ts +532 -26
  168. package/src/augment-inherited-props.ts +108 -10
  169. package/src/compiler.ts +17 -0
  170. package/src/event-handler-name.ts +15 -0
  171. package/src/expression-parser.ts +70 -1
  172. package/src/index.ts +35 -16
  173. package/src/ir-to-client-js/build-references.ts +69 -0
  174. package/src/ir-to-client-js/child-props-object.ts +240 -0
  175. package/src/ir-to-client-js/collect-elements.ts +31 -63
  176. package/src/ir-to-client-js/control-flow/plan/build-inner-loop.ts +8 -1
  177. package/src/ir-to-client-js/control-flow/plan/build-loop-child-arm.ts +31 -28
  178. package/src/ir-to-client-js/control-flow/shared.ts +20 -22
  179. package/src/ir-to-client-js/control-flow/stringify/claim-plan.ts +5 -3
  180. package/src/ir-to-client-js/control-flow/stringify/inner-loop.ts +2 -2
  181. package/src/ir-to-client-js/control-flow/stringify/lazy-row.ts +1 -1
  182. package/src/ir-to-client-js/control-flow/stringify/loop-child-arm.ts +2 -2
  183. package/src/ir-to-client-js/control-flow/stringify/loop.ts +1 -1
  184. package/src/ir-to-client-js/control-flow/stringify/reactive-effects.ts +3 -3
  185. package/src/ir-to-client-js/html-template.ts +43 -17
  186. package/src/ir-to-client-js/imports.ts +2 -2
  187. package/src/ir-to-client-js/index.ts +53 -11
  188. package/src/ir-to-client-js/phases/props-extraction.ts +11 -7
  189. package/src/ir-to-client-js/plan/build-declaration-emit.ts +40 -7
  190. package/src/ir-to-client-js/plan/build-static-array-child-init.ts +31 -14
  191. package/src/ir-to-client-js/plan/static-array-child-init.ts +27 -18
  192. package/src/ir-to-client-js/prop-handling.ts +22 -3
  193. package/src/ir-to-client-js/prune-unused-prop-extractions.ts +58 -5
  194. package/src/ir-to-client-js/rewrite-destructured-props.ts +31 -1
  195. package/src/ir-to-client-js/stringify/static-array-child-init.ts +26 -10
  196. package/src/jsx-to-ir.ts +459 -37
  197. package/src/nullable-signal-attr.ts +200 -110
  198. package/src/prop-rewrite.ts +30 -6
  199. package/src/props-binding.ts +84 -19
  200. package/src/props-object-whole-read.ts +87 -0
  201. package/src/rich-type-refusal.ts +2 -1
  202. package/src/scope/binding-scope.ts +182 -18
  203. package/src/scope/lexical-scope-walk.ts +4 -3
  204. package/src/scope/root-prop-alias.ts +15 -8
  205. package/src/ssr-defaults.ts +100 -11
  206. package/src/strip-types.ts +31 -3
  207. package/src/template-position-walk.ts +57 -28
  208. package/src/types.ts +87 -0
  209. package/dist/adapters/ambiguous-nil-arithmetic.d.ts +0 -41
  210. package/dist/adapters/ambiguous-nil-arithmetic.d.ts.map +0 -1
  211. package/src/adapters/ambiguous-nil-arithmetic.ts +0 -94
@@ -0,0 +1,126 @@
1
+ /**
2
+ * Operand typing for the JS primitive plan (`spec/js-primitive-semantics.md`,
3
+ * "Decision point"). One `collectOperandTyping` per component reads the
4
+ * Phase-1 metadata (props with their optionality and declared types, signals,
5
+ * memos, local constants, named types) into the facts a name read proves;
6
+ * `typing.at(scope)` sees it through a `BindingScope`, so a loop or callback
7
+ * binding shadows an outer name and a row read takes its type from
8
+ * `ScopeBinding.row` (as `BindingScope.isStringValueName` does for strings).
9
+ *
10
+ * This module only answers "what does a read of this name prove". The
11
+ * expression-level classifier is `operandFacts` (`primitive-plan.ts`).
12
+ */
13
+ import type { IRMetadata } from '../types.ts';
14
+ import { BindingScope, type LoopValueType, type NamedTypeFields } from '../scope/binding-scope.ts';
15
+ /** A JS type an operand can have at its read; `unknown` when not proven. */
16
+ export type OperandType = 'number' | 'string' | 'boolean' | 'nil' | 'object' | 'unknown';
17
+ /** Which JS value a host nil stands for at a read. */
18
+ export type NilReading = 'null' | 'undefined' | 'either';
19
+ /** What Phase-1 types prove about an operand at its read. */
20
+ export interface OperandFacts {
21
+ /** The JS types the value can have; `unknown` when not proven. */
22
+ readonly types: ReadonlySet<OperandType>;
23
+ /** Which JS value a nil stands for, when `types` has `nil`. */
24
+ readonly nil?: NilReading;
25
+ /** A non-negative integer (a loop index binding). */
26
+ readonly index?: boolean;
27
+ /**
28
+ * The value is an array. Not in the design note's sketch: the `get` plan's
29
+ * `array-index` proof needs the receiver proven an array, and `object`
30
+ * alone does not tell an array from a record.
31
+ */
32
+ readonly array?: boolean;
33
+ /**
34
+ * What an element proves when the value is or may be an array and the
35
+ * declared element type or the array-literal seed says (#3824 step 8:
36
+ * `===` refuses an element read that may be an object). A union keeps it
37
+ * from any member that has it (`rows?: Row[]` is `Row[]` or nil), so it is
38
+ * possible-object evidence only and never proves the value an array:
39
+ * `array` does that. Read only by `mayHoldObject`; no plan reads it.
40
+ */
41
+ readonly element?: OperandFacts;
42
+ /**
43
+ * When `types` has `object` only because of named type references (a
44
+ * declared `Row` or `Tone`, which Phase 1 types as `interface` whatever
45
+ * the name resolves to): those names. Absent when a structural object
46
+ * type or literal contributed `object`. Read only by `mayHoldObject`
47
+ * (#3824 step 8), which resolves the names against the component's type
48
+ * definitions: `type Tone = 'warm' | 'cool'` is not an object.
49
+ */
50
+ readonly namedObjects?: readonly string[];
51
+ }
52
+ /** Facts proving nothing. */
53
+ export declare const UNKNOWN_FACTS: OperandFacts;
54
+ /** Facts of a value of exactly one JS type (never nil). */
55
+ export declare function factsOf(type: Exclude<OperandType, 'nil' | 'unknown'>): OperandFacts;
56
+ /** Facts of a nil read as `reading`. */
57
+ export declare function nilFacts(reading: Exclude<NilReading, 'either'>): OperandFacts;
58
+ /**
59
+ * The facts of a value that is one of `a` or `b`. An unknown member makes the
60
+ * whole value unknown; `index` and `array` hold only when both hold, while
61
+ * `element` is kept from either member ({@link mergeElement}).
62
+ */
63
+ export declare function unionFacts(a: OperandFacts, b: OperandFacts): OperandFacts;
64
+ /** `facts` with the nil member removed (the value after a `??`). */
65
+ export declare function withoutNil(facts: OperandFacts): OperandFacts;
66
+ /** `facts` that may also be nil read as `reading`. */
67
+ export declare function withNil(facts: OperandFacts, reading: Exclude<NilReading, 'either'>): OperandFacts;
68
+ /** Whether `facts` prove exactly the one type `type`, never nil. */
69
+ export declare function isExactly(facts: OperandFacts, type: OperandType): boolean;
70
+ /** The one primitive type `facts` prove (never nil), or null. */
71
+ export declare function provenPrimitive(facts: OperandFacts): 'number' | 'string' | 'boolean' | null;
72
+ /** Whether `facts` prove the value is never nil. */
73
+ export declare function isNeverNil(facts: OperandFacts): boolean;
74
+ /** The facts of a declared type (a `TypeInfo`, or the structural `LoopValueType` a row carries). */
75
+ export declare function factsOfType(type: LoopValueType | null | undefined): OperandFacts;
76
+ /** The component-level operand typing, built once per component. */
77
+ export interface OperandTyping {
78
+ /** This typing seen through `scope`. */
79
+ at(scope: BindingScope): ScopedOperandTyping;
80
+ }
81
+ /**
82
+ * {@link OperandTyping} at one emission site. Every answer respects the
83
+ * nearest binding: a loop row, a callback param or a preamble local shadows
84
+ * an outer name.
85
+ */
86
+ export interface ScopedOperandTyping {
87
+ readonly scope: BindingScope;
88
+ /** A bare-name read: an identifier, or a zero-argument getter call. */
89
+ name(name: string): OperandFacts;
90
+ /** The literal `props.<key>` read. */
91
+ prop(key: string): OperandFacts;
92
+ /** The member chain `root.<path…>` (`row.id`); `name(root)` for an empty path. */
93
+ path(root: string, path: readonly string[]): OperandFacts;
94
+ /**
95
+ * This typing inside a callback whose `params` bind (`BindingScope.enterCallback`):
96
+ * each param shadows an outer name and proves nothing itself.
97
+ */
98
+ enterCallback(params: readonly string[]): ScopedOperandTyping;
99
+ }
100
+ export interface OperandTypingOptions {
101
+ /** The fields of a named type, for a row read through a named element type. */
102
+ readonly namedFields?: NamedTypeFields;
103
+ }
104
+ type TypingMetadata = Pick<IRMetadata, 'signals' | 'memos' | 'propsParams' | 'localConstants' | 'propsObjectName' | 'typeDefinitions'>;
105
+ /**
106
+ * Build the component's {@link OperandTyping} from its metadata. Bare names
107
+ * hold signal getters, memos, local constants and (only when the props are
108
+ * destructured) the props; `props.<key>` reads hold the props by their
109
+ * caller-facing key. A later source shadows an earlier one of the same name,
110
+ * so a local constant shadows a destructured prop.
111
+ *
112
+ * Unlike `collectNumberValueNames` and the adapters' `collectStringValueNames`,
113
+ * an optional prop without a default is not proven its declared type: an
114
+ * omitted prop reads nil (`undefined`).
115
+ */
116
+ export declare function collectOperandTyping(metadata: TypingMetadata, options?: OperandTypingOptions): OperandTyping;
117
+ /** An {@link OperandTyping} proving nothing about any outer name; loop bindings still type. */
118
+ export declare const EMPTY_OPERAND_TYPING: OperandTyping;
119
+ /**
120
+ * An {@link OperandTyping}-shaped view over name tests, for the legacy
121
+ * classifiers that take a callback instead of a typing (`isBooleanResultParsed`'s
122
+ * `isBooleanName`). A name the test accepts is proven `type`; nothing else is.
123
+ */
124
+ export declare function typingFromNameTest(type: 'boolean' | 'string' | 'number', test: ((name: string, componentProperty?: boolean) => boolean) | undefined): ScopedOperandTyping;
125
+ export {};
126
+ //# sourceMappingURL=operand-typing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operand-typing.d.ts","sourceRoot":"","sources":["../../src/adapters/operand-typing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAY,MAAM,aAAa,CAAA;AAEvD,OAAO,EACL,YAAY,EAGZ,KAAK,aAAa,EAClB,KAAK,eAAe,EAErB,MAAM,2BAA2B,CAAA;AAElC,4EAA4E;AAC5E,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,KAAK,GAAG,QAAQ,GAAG,SAAS,CAAA;AAExF,sDAAsD;AACtD,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,WAAW,GAAG,QAAQ,CAAA;AAExD,6DAA6D;AAC7D,MAAM,WAAW,YAAY;IAC3B,kEAAkE;IAClE,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,WAAW,CAAC,CAAA;IACxC,+DAA+D;IAC/D,QAAQ,CAAC,GAAG,CAAC,EAAE,UAAU,CAAA;IACzB,qDAAqD;IACrD,QAAQ,CAAC,KAAK,CAAC,EAA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Property } from '../expression-parser.ts';
36
36
  import type { LoweringMatcher, LoweringNode } from '../lowering-registry.ts';
37
+ import { type NilTestHelper, type PrimitiveInputs, type PrimitivePlan } from './primitive-plan.ts';
37
38
  export type HigherOrderMethod = 'filter' | 'every' | 'some' | 'find' | 'findIndex' | 'findLast' | 'findLastIndex';
38
39
  /**
39
40
  * Non-higher-order array methods (#1443). One discriminator for the
@@ -84,19 +85,57 @@ export interface LoweringEmitter {
84
85
  * the emitter can inspect their kinds before deciding how to lower
85
86
  * them, plus an `emit` callback to recurse on any child it wants the
86
87
  * default rendering for.
88
+ *
89
+ * The primitive operations (`binary`, `unary`, `logical`, a `conditional`'s
90
+ * test, `indexAccess`, a computed `member`, a number `literal`) also receive
91
+ * their {@link PrimitivePlan} as the last parameter (#3824,
92
+ * `spec/js-primitive-semantics.md` "How it reaches emitters"): native or
93
+ * helper, decided once by `planPrimitive` from the emitter's
94
+ * {@link ParsedExprEmitter.primitives}. `null` for a node that is not a
95
+ * primitive operation (a non-number literal, a non-computed member, loose
96
+ * `==`, …). Step 0: every emitter accepts the plan and keeps its own
97
+ * spelling; the rollout makes each one spell the plan.
87
98
  */
88
99
  export interface ParsedExprEmitter {
100
+ /**
101
+ * The inputs `planPrimitive` reads for this emitter: the operand typing at
102
+ * the emission site (the component's `collectOperandTyping` through the
103
+ * current `BindingScope`) and the target's `NativeSafeTable`.
104
+ */
105
+ readonly primitives: PrimitiveInputs;
89
106
  identifier(name: string): string;
90
- literal(value: string | number | boolean | null, literalType: LiteralType): string;
107
+ literal(value: string | number | boolean | null, literalType: LiteralType, plan: PrimitivePlan | null): string;
91
108
  call(callee: ParsedExpr, args: ParsedExpr[], emit: (e: ParsedExpr) => string): string;
92
109
  lowering?: LoweringEmitter;
93
- member(object: ParsedExpr, property: string, computed: boolean, optional: boolean, emit: (e: ParsedExpr) => string): string;
94
- indexAccess(object: ParsedExpr, index: ParsedExpr, emit: (e: ParsedExpr) => string): string;
95
- binary(op: string, left: ParsedExpr, right: ParsedExpr, emit: (e: ParsedExpr) => string): string;
96
- unary(op: string, argument: ParsedExpr, emit: (e: ParsedExpr) => string): string;
97
- logical(op: '&&' | '||' | '??', left: ParsedExpr, right: ParsedExpr, emit: (e: ParsedExpr) => string): string;
98
- conditional(test: ParsedExpr, consequent: ParsedExpr, alternate: ParsedExpr, emit: (e: ParsedExpr) => string): string;
99
- templateLiteral(parts: TemplatePart[], emit: (e: ParsedExpr) => string): string;
110
+ /**
111
+ * Spell a boolean-value plan (#3824 step 5): materialize `rendered`, a
112
+ * boolean whose value leaves the expression, as the host's boolean.
113
+ * {@link emitParsedValue} calls it only for a `helper` plan, so a target
114
+ * whose `NativeSafeTable` claims `boolean-value` never needs it.
115
+ */
116
+ booleanValue?(rendered: string, plan: PrimitivePlan): string;
117
+ member(object: ParsedExpr, property: string, computed: boolean, optional: boolean, emit: (e: ParsedExpr) => string, plan: PrimitivePlan | null): string;
118
+ indexAccess(object: ParsedExpr, index: ParsedExpr, emit: (e: ParsedExpr) => string, plan: PrimitivePlan | null): string;
119
+ binary(op: string, left: ParsedExpr, right: ParsedExpr, emit: (e: ParsedExpr) => string, plan: PrimitivePlan | null): string;
120
+ /**
121
+ * A nil-test plan (`spec/js-undefined-value.md`, "Decisions" (3) and (7)):
122
+ * on a target that carries `undefined`, `x === null`, `x === undefined`
123
+ * and the loose `x == null` plan as the runtime's `is_null`,
124
+ * `is_undefined` and `is_nullish` over `operand` (the side that is not the
125
+ * nil literal, {@link nilTestOperand}), `negated` for `!==` / `!=`. An
126
+ * emitter without it refuses the plan ({@link refuseUnspelledNilTest});
127
+ * only the emitter of a target that carries `undefined` receives one.
128
+ */
129
+ nilTest?(helper: NilTestHelper, negated: boolean, operand: ParsedExpr, emit: (e: ParsedExpr) => string): string;
130
+ unary(op: string, argument: ParsedExpr, emit: (e: ParsedExpr) => string, plan: PrimitivePlan | null): string;
131
+ logical(op: '&&' | '||' | '??', left: ParsedExpr, right: ParsedExpr, emit: (e: ParsedExpr) => string, plan: PrimitivePlan | null): string;
132
+ conditional(test: ParsedExpr, consequent: ParsedExpr, alternate: ParsedExpr, emit: (e: ParsedExpr) => string, plan: PrimitivePlan | null): string;
133
+ /**
134
+ * `plans[i]` is the ToString plan of `parts[i]` (`planToString`, #3824
135
+ * step 4) for an expression part, null for a string part: the part as it
136
+ * is when native, through the runtime's `to_string` otherwise.
137
+ */
138
+ templateLiteral(parts: TemplatePart[], emit: (e: ParsedExpr) => string, plans: readonly (PrimitivePlan | null)[]): string;
100
139
  callbackMethod(method: string, object: ParsedExpr, arrow: Extract<ParsedExpr, {
101
140
  kind: 'arrow';
102
141
  }>, restArgs: ParsedExpr[], emit: (e: ParsedExpr) => string): string;
@@ -110,6 +149,12 @@ export interface ParsedExprEmitter {
110
149
  }, emit: (e: ParsedExpr) => string): string;
111
150
  unsupported(raw: string, reason: string): string;
112
151
  }
152
+ /**
153
+ * The adapter's string typing of a name at the emission site (its
154
+ * `BindingScope`): `componentProperty` when the read is `props.<name>`,
155
+ * `path` when it is the member chain `name.<path…>` (`row.id`).
156
+ */
157
+ export type StringNameTest = (name: string, componentProperty?: boolean, path?: readonly string[]) => boolean;
113
158
  /**
114
159
  * Whether an operand is string-typed, as far as the ParsedExpr tree can
115
160
  * tell: a string literal, a template literal, a zero-arg getter call /
@@ -122,7 +167,7 @@ export interface ParsedExprEmitter {
122
167
  * Consumed by `===`/`!==` lowering on backends whose `==` is numeric
123
168
  * (Perl `eq`/`ne`) and by `isStringConcatBinary` below.
124
169
  */
125
- export declare function isStringTypedOperand(expr: ParsedExpr, isStringName: (n: string, componentProperty?: boolean) => boolean): boolean;
170
+ export declare function isStringTypedOperand(expr: ParsedExpr, isStringName: StringNameTest): boolean;
126
171
  /**
127
172
  * Whether a `binary` node is JS STRING concatenation rather than numeric
128
173
  * addition: `+` with at least one string-typed operand (#2176). JS `+`
@@ -133,7 +178,7 @@ export declare function isStringTypedOperand(expr: ParsedExpr, isStringName: (n:
133
178
  * decision is shared-layer semantics; each adapter only maps true to
134
179
  * its own operator.
135
180
  */
136
- export declare function isStringConcatBinary(op: string, left: ParsedExpr, right: ParsedExpr, isStringName: (n: string, componentProperty?: boolean) => boolean): boolean;
181
+ export declare function isStringConcatBinary(op: string, left: ParsedExpr, right: ParsedExpr, isStringName: StringNameTest): boolean;
137
182
  /**
138
183
  * Whether a top-level expression yields a JS NUMBER from arithmetic: a
139
184
  * `-` / `*` / `/` / `%` binary, a `+` that is not string concatenation, or
@@ -141,7 +186,7 @@ export declare function isStringConcatBinary(op: string, left: ParsedExpr, right
141
186
  * language's own number stringification (Perl's `%.15g`) route such a
142
187
  * result through their JS `Number::toString` helper instead (#3380).
143
188
  */
144
- export declare function isNumericArithmeticResult(expr: ParsedExpr | null | undefined, isStringName: (n: string, componentProperty?: boolean) => boolean): boolean;
189
+ export declare function isNumericArithmeticResult(expr: ParsedExpr | null | undefined, isStringName: StringNameTest): boolean;
145
190
  /** A runtime helper of the template-helper catalogue (`spec/template-helpers.md`)
146
191
  * that a binary arithmetic operator lowers to. */
147
192
  export type ArithmeticHelper = 'mod' | 'div';
@@ -223,6 +268,11 @@ export declare function groupObjectLiteralSegments(properties: readonly ObjectLi
223
268
  * are not this shape.
224
269
  */
225
270
  export declare function asToStringCall(expr: ParsedExpr): ParsedExpr | null;
271
+ /**
272
+ * The plan `emitParsedExpr` hands an emitter method for `expr`: decided by
273
+ * `planPrimitive` from the emitter's own typing and native-safe table.
274
+ */
275
+ export declare function primitivePlanFor(expr: ParsedExpr, emitter: Pick<ParsedExprEmitter, 'primitives'>): PrimitivePlan | null;
226
276
  /**
227
277
  * Single point of dispatch from `ParsedExpr.kind` to the adapter's
228
278
  * method. Adapters call this once at their entry point; the recursion
@@ -232,5 +282,23 @@ export declare function asToStringCall(expr: ParsedExpr): ParsedExpr | null;
232
282
  * a TS compile error here — and, transitively, in every adapter that
233
283
  * hasn't extended its `ParsedExprEmitter` implementation.
234
284
  */
235
- export declare function emitParsedExpr(expr: ParsedExpr, emitter: ParsedExprEmitter): string;
285
+ export declare function emitParsedExpr(expr: ParsedExpr, emitter: ParsedExprEmitter, sites?: ReadonlyMap<ParsedExpr, PrimitivePlan>): string;
286
+ /**
287
+ * {@link emitParsedExpr} for `expr` read as a value that leaves the
288
+ * expression (a child prop, a stored seed, a `JSON.stringify` argument, a
289
+ * displayed text child): every boolean its value can be is spelled through
290
+ * the boolean-value plan `booleanValueSites` decides (#3824 step 5).
291
+ */
292
+ export declare function emitParsedValue(expr: ParsedExpr, emitter: ParsedExprEmitter): string;
293
+ /**
294
+ * The ToString plans of a template literal's parts, for
295
+ * {@link ParsedExprEmitter.templateLiteral}: null for a string part.
296
+ */
297
+ export declare function templatePartPlans(parts: readonly TemplatePart[], emitter: Pick<ParsedExprEmitter, 'primitives'>): (PrimitivePlan | null)[];
298
+ /**
299
+ * `expr` with the nil-reading rewrite applied to its own operands
300
+ * (`rewriteNilReadings`, #3824 step 4), in the emitter's scope. Only the
301
+ * kinds whose coercion the rewrite reads take the typing.
302
+ */
303
+ export declare function withNilReadings(expr: ParsedExpr, emitter: Pick<ParsedExprEmitter, 'primitives'>): ParsedExpr;
236
304
  //# sourceMappingURL=parsed-expr-emitter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"parsed-expr-emitter.d.ts","sourceRoot":"","sources":["../../src/adapters/parsed-expr-emitter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;AAEzG,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAE5E,MAAM,MAAM,iBAAiB,GAAG,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,WAAW,GAAG,UAAU,GAAG,eAAe,CAAA;AAEjH;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,WAAW,GAC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,CAAC,iBAAiB,EAAE,YAAY,CAAC,GAAG,CAAC,aAAa,GAAG,IAAI,CAAC,EAAE,CAG1I;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,IAAI,CAAC,iBAAiB,EAAE,YAAY,CAAC,GAAG,UAAU,CAG5G"}
@@ -0,0 +1,320 @@
1
+ /**
2
+ * The JS primitive plan (`spec/js-primitive-semantics.md`, "Decision
3
+ * point"): one pure decision per primitive operation — ToBoolean, ToNumber,
4
+ * `+`, `===`, relational, unary `-`, number literal, nullish, index read —
5
+ * whether a target may spell its native operator (Phase-1 types prove the
6
+ * operands are in a range where native and JS agree, and the target's
7
+ * {@link NativeSafeTable} claims that proof) or must call the runtime
8
+ * helper.
9
+ *
10
+ * `emitParsedExpr` computes the plan for every operator node and hands it to
11
+ * the emitter as the method's last parameter; the emitter only spells it.
12
+ * Step 0 of #3824 fills each adapter's table so that the plans describe
13
+ * today's output; each rollout step narrows a table to what the
14
+ * `primitives/` vectors pin and makes the emitters spell the plan.
15
+ */
16
+ import type { ParsedExpr } from '../expression-parser.ts';
17
+ import { type BindingScope } from '../scope/binding-scope.ts';
18
+ import { type OperandFacts, type OperandTyping, type ScopedOperandTyping } from './operand-typing.ts';
19
+ export type PrimitiveOp = 'to-boolean' | 'to-number' | 'to-string' | 'boolean-value' | 'get' | 'strict-eq' | 'relational' | 'plus' | 'neg' | 'number-literal' | 'nullish' | 'nil-test';
20
+ /**
21
+ * What Phase 1 proved about the operands of one operation.
22
+ *
23
+ * `unproven` is not in the design note's sketch: it is the proof of an
24
+ * operation whose operands Phase 1 proves nothing about. No target claims
25
+ * it: every runtime carries JS `undefined` apart from `null`
26
+ * (`spec/js-undefined-value.md`), so an unproven operand may be `UNDEF`,
27
+ * which only the runtime's helper reads exactly.
28
+ */
29
+ export type Proof = 'boolean' | 'number' | 'string' | 'number-pair' | 'string-pair' | 'boolean-pair' | 'array-index' | 'safe-integer' | 'non-nil' | 'unproven';
30
+ /**
31
+ * The (op, proof) pairs a target's native operators are pinned for. Every
32
+ * target's runtime carries JS `undefined` apart from `null`
33
+ * (`spec/js-undefined-value.md`), so the plan needs nothing else about it:
34
+ * an operand Phase 1 does not prove (`either`, unknown, a dynamic `+`) takes
35
+ * the runtime's helper, which reads `null` and `UNDEF` exactly, and
36
+ * `x === null` / `x === undefined` / `x == null` plan as the `is_null` /
37
+ * `is_undefined` / `is_nullish` tests ("Decisions" (3) and (7)).
38
+ */
39
+ export type NativeSafeClaims = Readonly<Partial<Record<PrimitiveOp, readonly Exclude<Proof, 'unproven'>[]>>>;
40
+ /** A target's native-operator claims ({@link NativeSafeClaims}). */
41
+ export type NativeSafeTable = NativeSafeClaims;
42
+ /**
43
+ * The runtime helper a plan names, by its catalogue id
44
+ * (`spec/template-helpers.md`); each runtime keeps its own spelling (Perl's
45
+ * `subtract`, Go's `bf_eq`, PHP's `index` for `get`).
46
+ */
47
+ export type PrimitiveHelper = 'truthy' | 'to_number' | 'add' | 'sub' | 'mul' | 'div' | 'mod' | 'plus' | 'to_string' | 'strict_eq' | 'lt' | 'le' | 'gt' | 'ge' | 'neg' | 'number' | 'coalesce' | 'get' | 'boolean' | NilTestHelper;
48
+ /**
49
+ * The nil tests of a target that carries `undefined`
50
+ * (`spec/js-undefined-value.md`, "Decisions" (3)): `x === null`,
51
+ * `x === undefined` and the loose `x == null` / `x == undefined`.
52
+ */
53
+ export type NilTestHelper = 'is_null' | 'is_undefined' | 'is_nullish';
54
+ export type PrimitivePlan = {
55
+ readonly mode: 'native';
56
+ readonly op: PrimitiveOp;
57
+ readonly proof: Proof;
58
+ /**
59
+ * A native string `+` (`plus` over the `string` proof): which operand
60
+ * the emitter spells through the runtime's `to_string` before the
61
+ * host's concatenation, `[left, right]`. A proven string operand is
62
+ * concatenated as it is (#3824 step 4).
63
+ */
64
+ readonly stringify?: readonly [boolean, boolean];
65
+ } | {
66
+ readonly mode: 'helper';
67
+ readonly op: PrimitiveOp;
68
+ readonly helper: PrimitiveHelper;
69
+ readonly proof: Proof;
70
+ }
71
+ /** `===` / `!==` across operands proven of different primitive types. */
72
+ | {
73
+ readonly mode: 'const';
74
+ readonly op: PrimitiveOp;
75
+ readonly value: boolean;
76
+ }
77
+ /** A BF101 refusal (e.g. a nil reading `either` under a numeric operator). */
78
+ | {
79
+ readonly mode: 'refuse';
80
+ readonly op: PrimitiveOp;
81
+ readonly reason: string;
82
+ };
83
+ /**
84
+ * What Phase-1 types prove about `expr` at its read in `typing`'s scope: the
85
+ * single classifier the primitive plan, and the legacy predicates that wrap
86
+ * it, read.
87
+ *
88
+ * Step 0 deliberately types no call other than a getter read and no method
89
+ * result (`.includes()` is a boolean in JS, `.join()` a string), so that
90
+ * `isBooleanResultParsed`, which wraps this, stays byte-identical.
91
+ */
92
+ export declare function operandFacts(expr: ParsedExpr, typing: ScopedOperandTyping): OperandFacts;
93
+ /** The literal `null`, or an unbound `undefined`: the operand of a nullish test. */
94
+ export declare function isNilLiteralOperand(expr: ParsedExpr, typing?: ScopedOperandTyping): boolean;
95
+ /** A `===` / `!==` / `==` / `!=` with a nil literal on one side: a nullish test, not a strict equality. */
96
+ export declare function isNullishTest(op: string, left: ParsedExpr, right: ParsedExpr, typing?: ScopedOperandTyping): boolean;
97
+ /**
98
+ * The operand a nil test ({@link planNilTest}) tests: the side that is not
99
+ * the nil literal, `left` when both are (`null === undefined` tests `null`).
100
+ */
101
+ export declare function nilTestOperand(left: ParsedExpr, right: ParsedExpr, typing?: ScopedOperandTyping): ParsedExpr;
102
+ /**
103
+ * Refuse a nil-test plan ({@link planNilTest}) at an emitter that has no
104
+ * spelling for it (no `nilTest`), instead of letting it fall back to its
105
+ * host nil test, which cannot tell `null` from `undefined`.
106
+ */
107
+ export declare function refuseUnspelledNilTest(plan: PrimitivePlan | null): void;
108
+ /**
109
+ * Whether `expr` may hold an object or array at its read
110
+ * (`spec/js-primitive-semantics.md`, "Decisions" (4)): its facts admit
111
+ * `object` (an object, array or interface type, an object or array
112
+ * literal), or it is an element read of an array whose declared element
113
+ * type or array-literal seed admits one (`rows().at(0)` over
114
+ * `createSignal([{ id: 1 }])`, typed `unknown[]`). An operand Phase 1
115
+ * proves nothing else about (an untyped row field, a call result) is not
116
+ * refused: the runtime's `strict_eq` compares it. A named type reference
117
+ * (`Row`, `Tone`) counts only when `isObjectTypeName` resolves it to an
118
+ * object shape; by default it does not.
119
+ */
120
+ export declare function mayHoldObject(expr: ParsedExpr, typing: ScopedOperandTyping, isObjectTypeName?: (name: string) => boolean): boolean;
121
+ /** The BF101 reason of a `===` / `!==` over an operand that may be an object (#3774). */
122
+ export declare const NON_PRIMITIVE_EQUALITY_REASON = "non-primitive-strict-equality";
123
+ /**
124
+ * How an emitter spells a `===` / `!==` under its plan (#3824 step 8):
125
+ *
126
+ * - `native`: the target's own operator for the proven pair (`proof`).
127
+ * - `helper`: the runtime's `strict_eq`, negated for `!==`. A refused plan
128
+ * spells it too: the refusal itself is recorded once per component by
129
+ * `refuseNonPrimitiveStrictEquality`.
130
+ * - `const`: the folded answer for operands proven of different types.
131
+ * - `nullish`: a nullish test (`x === null`) reached without a plan (an
132
+ * emitter method called outside `emitParsedExpr`). Under a plan a nullish
133
+ * test is a nil test, which `emitParsedExpr` hands to the emitter's
134
+ * `nilTest` ({@link refuseUnspelledNilTest} when it has none).
135
+ *
136
+ * Null for any other operator (loose `==` keeps its own lowering). A null
137
+ * plan takes the helper, which is never wrong.
138
+ */
139
+ export type StrictEqSpelling = {
140
+ readonly kind: 'native';
141
+ readonly proof: Proof;
142
+ readonly negated: boolean;
143
+ } | {
144
+ readonly kind: 'helper';
145
+ readonly negated: boolean;
146
+ } | {
147
+ readonly kind: 'const';
148
+ readonly value: boolean;
149
+ } | {
150
+ readonly kind: 'nullish';
151
+ };
152
+ export declare function strictEqSpelling(op: string, left: ParsedExpr, right: ParsedExpr, plan: PrimitivePlan | null): StrictEqSpelling | null;
153
+ /**
154
+ * How an emitter spells a `+` under its plan (#3824 step 4):
155
+ *
156
+ * - `add`: the host's numeric `+` (`native`), or the runtime's numbers-only
157
+ * `add` helper (`helper`, Perl and Go).
158
+ * - `concat`: the host's string concatenation, each operand whose
159
+ * `stringify` flag is set through the runtime's `to_string`.
160
+ * - `plus`: the runtime's JS `+`.
161
+ *
162
+ * A null plan (an emitter method reached outside `emitParsedExpr`) takes
163
+ * `plus`, which is never wrong.
164
+ */
165
+ export type PlusSpelling = {
166
+ readonly kind: 'add';
167
+ readonly native: boolean;
168
+ } | {
169
+ readonly kind: 'concat';
170
+ readonly stringify: readonly [boolean, boolean];
171
+ } | {
172
+ readonly kind: 'plus';
173
+ };
174
+ export declare function plusSpelling(plan: PrimitivePlan | null): PlusSpelling;
175
+ /**
176
+ * The ToString plan of a template-literal part (#3824 step 4): the part
177
+ * itself when it is a proven non-nil string and the target claims the
178
+ * `string` proof for `to-string`, the runtime's `to_string` otherwise. The
179
+ * nil-reading rewrite has already turned a typed nil-capable part into a
180
+ * non-nil one.
181
+ */
182
+ export declare function planToString(part: ParsedExpr, typing: ScopedOperandTyping, target: NativeSafeTable): PrimitivePlan;
183
+ /** Whether a ToString plan names the runtime's `to_string`; a null plan does. */
184
+ export declare function needsToString(plan: PrimitivePlan | null): boolean;
185
+ /**
186
+ * The ToBoolean plan of a test position whose node `emitParsedExpr` does not
187
+ * plan, because the position, not an operator node, applies the conversion:
188
+ * an `if` condition (a JSX conditional, a conditional return), a `.filter()`
189
+ * / `.every()` / `.some()` predicate body, a loop filter's guard, an
190
+ * attribute's presence test. The `!`, `&&`, `||` and `?:` nodes receive the
191
+ * same plan from the dispatcher.
192
+ */
193
+ export declare function planTest(test: ParsedExpr, typing: ScopedOperandTyping, target: NativeSafeTable): PrimitivePlan;
194
+ /**
195
+ * Spell a ToBoolean plan over a rendered test: the test itself when the plan
196
+ * is native, `helper(rendered)` otherwise. A null plan (an emitter method
197
+ * reached outside `emitParsedExpr`) takes the helper, which is never wrong.
198
+ */
199
+ export declare function spellTest(plan: PrimitivePlan | null, rendered: string, helper: (rendered: string) => string): string;
200
+ type NumberLiteral = Extract<ParsedExpr, {
201
+ kind: 'literal';
202
+ }> & {
203
+ value: number;
204
+ };
205
+ /**
206
+ * A unary `-` over a non-zero number literal, folded into the literal it
207
+ * denotes (`-1.5` is the literal `-1.5`); null for any other node
208
+ * (`spec/js-primitive-semantics.md`, "Unary `-` and number literals"). The
209
+ * fold is the only native-safe unary minus: any other operand can be an
210
+ * integer zero in a host whose integer and float types differ, and the sign
211
+ * of `-0` would be lost, so it takes the `neg` helper. `-0` itself is not
212
+ * folded: a zero operand is exactly that case.
213
+ */
214
+ export declare function foldNegatedNumberLiteral(expr: ParsedExpr): NumberLiteral | null;
215
+ /**
216
+ * The helper a relational plan names for `op` (`<` → `lt`, …), or null when
217
+ * the plan names the native operator (both operands proven non-nil numbers
218
+ * and the target claims `number-pair`; #3824 step 3). A null plan (an
219
+ * emitter method reached outside `emitParsedExpr`) takes the helper, which
220
+ * is never wrong. Null too for an `op` that is not relational.
221
+ */
222
+ export declare function relationalHelper(op: string, plan: PrimitivePlan | null): PrimitiveHelper | null;
223
+ /**
224
+ * Whether a unary-`+` plan names the native spelling (the operand itself, a
225
+ * proven number); otherwise the emitter spells the runtime's `to_number`
226
+ * (#3824 step 3). A null plan takes the helper.
227
+ */
228
+ export declare function isNativeToNumber(plan: PrimitivePlan | null): boolean;
229
+ /**
230
+ * Whether `plan` names the native operator of `op`. A null plan (an emitter
231
+ * method reached outside `emitParsedExpr`) is never native: the helper is
232
+ * never wrong.
233
+ */
234
+ export declare function isNativePlan(plan: PrimitivePlan | null, op: PrimitiveOp): boolean;
235
+ /**
236
+ * Whether `expr` is a number literal that no target spells as a host literal
237
+ * (anything but a safe integer, so `-0` too): its value comes from the
238
+ * runtime's `number` / `neg` and prints in the host's own notation (Perl
239
+ * `1e-07`, Go `1e+20`) unless the text sink routes it through the runtime's
240
+ * JS `Number::toString`.
241
+ */
242
+ export declare function isRuntimeNumberLiteral(expr: ParsedExpr): boolean;
243
+ /**
244
+ * How an emitter spells a number literal of `value` under its plan:
245
+ *
246
+ * - `native`: the host literal `text` (a safe integer, `String(value)`).
247
+ * - `parse`: the runtime's `number` helper over the string `text`, the JS
248
+ * spelling `String(value)` (`1e+21`, `1e-7`, `0.1`,
249
+ * `100000000000000000000`), which every runtime's `number` parses, so no
250
+ * target needs an exponent or big-integer literal syntax.
251
+ * - `negative-zero`: the runtime's `neg` helper over `0`.
252
+ *
253
+ * A null plan (an emitter method reached outside `emitParsedExpr`) gets the
254
+ * plan of a target that claims only safe integers natively, which every
255
+ * target's table does.
256
+ */
257
+ export type NumberLiteralSpelling = {
258
+ readonly kind: 'native';
259
+ readonly text: string;
260
+ } | {
261
+ readonly kind: 'parse';
262
+ readonly text: string;
263
+ } | {
264
+ readonly kind: 'negative-zero';
265
+ };
266
+ export declare function numberLiteralSpelling(value: number, plan: PrimitivePlan | null): NumberLiteralSpelling;
267
+ /**
268
+ * The plan for `node` in `typing`'s scope on a target whose native operators
269
+ * are pinned for `target`'s (op, proof) pairs, or null when `node` is not a
270
+ * primitive operation (a non-number literal, loose `==`, `in`, a
271
+ * non-computed member, …).
272
+ *
273
+ * Planned kinds: `binary` (`===` `!==` `<` `<=` `>` `>=` `+` `-` `*` `/`
274
+ * `%`, and a nullish test with `==` / `!=` too, {@link planNilTest}), `unary` (`!` `-` `+`), `logical` (its left operand's test, or `??`),
275
+ * `conditional` (its test), `index-access`, computed `member` and number
276
+ * `literal`.
277
+ */
278
+ export declare function planPrimitive(node: ParsedExpr, typing: ScopedOperandTyping, target: NativeSafeTable): PrimitivePlan | null;
279
+ /**
280
+ * The boolean-value plan of every node of `expr` whose value leaves the
281
+ * expression when `expr` itself does (`spec/js-primitive-semantics.md`,
282
+ * "Boolean values"): `expr` read as a value — a child prop, a stored signal
283
+ * seed / memo / local, a `JSON.stringify` argument, a rendered value — and,
284
+ * through it, an operand `&&` / `||` / `??` returns, a ternary branch and an
285
+ * array or object literal element. A test (a ternary's test, the operand of
286
+ * `!`, an `if` condition) is not a value: it keeps the target's native
287
+ * truthiness. A target with a boolean type claims `boolean-value` natively
288
+ * and spells nothing; Perl materializes each site with its runtime's
289
+ * `boolean`.
290
+ */
291
+ export declare function booleanValueSites(expr: ParsedExpr, target: NativeSafeTable): ReadonlyMap<ParsedExpr, PrimitivePlan>;
292
+ /**
293
+ * How a JSX text child displays its value (`spec/js-primitive-semantics.md`,
294
+ * "ToString and boolean values"): JSX renders nothing for `true`, `false`,
295
+ * `null` and `undefined`.
296
+ *
297
+ * - `empty`: Phase 1 proves the value is a boolean or nil, so the child
298
+ * renders nothing (its markers stay).
299
+ * - `display`: the value may be a boolean among other types, so the runtime's
300
+ * `display` helper blanks a boolean at render time.
301
+ * - `plain`: the value is never a boolean (or Phase 1 proves nothing), so the
302
+ * target's text sink prints it as before.
303
+ */
304
+ export type TextDisplay = 'empty' | 'display' | 'plain';
305
+ export declare function planTextDisplay(expr: ParsedExpr, typing: ScopedOperandTyping): TextDisplay;
306
+ /** The inputs an emitter supplies for the plans it receives (`ParsedExprEmitter.primitives`). */
307
+ export interface PrimitiveInputs {
308
+ /** The operand typing at the emission site (`typing.at(scope)`). */
309
+ typing(): ScopedOperandTyping;
310
+ /** The target's native-safe (op, proof) pairs. */
311
+ readonly nativeSafe: NativeSafeTable;
312
+ }
313
+ /**
314
+ * {@link PrimitiveInputs} reading `typing` at `scope`. An emitter that is
315
+ * built for one fixed scope (a filter predicate's) supplies this; one that
316
+ * follows the adapter's current scope supplies its own `typing()`.
317
+ */
318
+ export declare function primitivesAt(typing: OperandTyping, scope: BindingScope, nativeSafe: NativeSafeTable): PrimitiveInputs;
319
+ export {};
320
+ //# sourceMappingURL=primitive-plan.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"primitive-plan.d.ts","sourceRoot":"","sources":["../../src/adapters/primitive-plan.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,y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