@tamagui/compiler-core 0.0.0-bootstrap.0 → 3.0.0-beta.637.1
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/LICENSE +21 -0
- package/README.md +57 -1
- package/dist/cjs/ast.cjs +95 -0
- package/dist/cjs/contracts.cjs +62 -0
- package/dist/cjs/diagnostics.cjs +69 -0
- package/dist/cjs/evaluate.cjs +351 -0
- package/dist/cjs/graph.cjs +279 -0
- package/dist/cjs/hash.cjs +49 -0
- package/dist/cjs/index.cjs +44 -0
- package/dist/cjs/ir.cjs +33 -0
- package/dist/cjs/lower.cjs +225 -0
- package/dist/cjs/materialize.cjs +200 -0
- package/dist/cjs/normalize.cjs +622 -0
- package/dist/cjs/output.cjs +149 -0
- package/dist/cjs/planCache.cjs +224 -0
- package/dist/cjs/session.cjs +119 -0
- package/dist/cjs/yuku.cjs +159 -0
- package/dist/cjs/zero.cjs +387 -0
- package/dist/esm/ast.mjs +65 -0
- package/dist/esm/ast.mjs.map +1 -0
- package/dist/esm/contracts.mjs +34 -0
- package/dist/esm/contracts.mjs.map +1 -0
- package/dist/esm/diagnostics.mjs +44 -0
- package/dist/esm/diagnostics.mjs.map +1 -0
- package/dist/esm/evaluate.mjs +327 -0
- package/dist/esm/evaluate.mjs.map +1 -0
- package/dist/esm/graph.mjs +256 -0
- package/dist/esm/graph.mjs.map +1 -0
- package/dist/esm/hash.mjs +26 -0
- package/dist/esm/hash.mjs.map +1 -0
- package/dist/esm/index.mjs +30 -0
- package/dist/esm/ir.mjs +12 -0
- package/dist/esm/ir.mjs.map +1 -0
- package/dist/esm/lower.mjs +202 -0
- package/dist/esm/lower.mjs.map +1 -0
- package/dist/esm/materialize.mjs +179 -0
- package/dist/esm/materialize.mjs.map +1 -0
- package/dist/esm/normalize.mjs +596 -0
- package/dist/esm/normalize.mjs.map +1 -0
- package/dist/esm/output.mjs +119 -0
- package/dist/esm/output.mjs.map +1 -0
- package/dist/esm/planCache.mjs +194 -0
- package/dist/esm/planCache.mjs.map +1 -0
- package/dist/esm/session.mjs +99 -0
- package/dist/esm/session.mjs.map +1 -0
- package/dist/esm/yuku.mjs +136 -0
- package/dist/esm/yuku.mjs.map +1 -0
- package/dist/esm/zero.mjs +352 -0
- package/dist/esm/zero.mjs.map +1 -0
- package/package.json +42 -4
- package/src/ast.ts +86 -0
- package/src/contracts.ts +148 -0
- package/src/diagnostics.ts +96 -0
- package/src/evaluate.ts +497 -0
- package/src/graph.ts +347 -0
- package/src/hash.ts +36 -0
- package/src/index.ts +15 -0
- package/src/ir.ts +154 -0
- package/src/lower.ts +418 -0
- package/src/materialize.ts +330 -0
- package/src/normalize.ts +846 -0
- package/src/output.ts +175 -0
- package/src/planCache.ts +327 -0
- package/src/session.ts +172 -0
- package/src/yuku.ts +189 -0
- package/src/zero.ts +598 -0
- package/types/ast.d.ts +10 -0
- package/types/ast.d.ts.map +1 -0
- package/types/contracts.d.ts +97 -0
- package/types/contracts.d.ts.map +1 -0
- package/types/diagnostics.d.ts +31 -0
- package/types/diagnostics.d.ts.map +1 -0
- package/types/evaluate.d.ts +36 -0
- package/types/evaluate.d.ts.map +1 -0
- package/types/graph.d.ts +37 -0
- package/types/graph.d.ts.map +1 -0
- package/types/hash.d.ts +8 -0
- package/types/hash.d.ts.map +1 -0
- package/types/index.d.ts +16 -0
- package/types/index.d.ts.map +1 -0
- package/types/ir.d.ts +118 -0
- package/types/ir.d.ts.map +1 -0
- package/types/lower.d.ts +99 -0
- package/types/lower.d.ts.map +1 -0
- package/types/materialize.d.ts +104 -0
- package/types/materialize.d.ts.map +1 -0
- package/types/normalize.d.ts +8 -0
- package/types/normalize.d.ts.map +1 -0
- package/types/output.d.ts +32 -0
- package/types/output.d.ts.map +1 -0
- package/types/planCache.d.ts +113 -0
- package/types/planCache.d.ts.map +1 -0
- package/types/session.d.ts +44 -0
- package/types/session.d.ts.map +1 -0
- package/types/yuku.d.ts +4 -0
- package/types/yuku.d.ts.map +1 -0
- package/types/zero.d.ts +98 -0
- package/types/zero.d.ts.map +1 -0
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
import type { ResolvedModuleId, SourceSpan } from './contracts'
|
|
2
|
+
import type { BailoutReason } from './diagnostics'
|
|
3
|
+
import type { StaticEvaluationValue } from './evaluate'
|
|
4
|
+
import type { ProjectGraph } from './graph'
|
|
5
|
+
import type {
|
|
6
|
+
ComponentImportProvenance,
|
|
7
|
+
ElementComponentIR,
|
|
8
|
+
ElementEntryIR,
|
|
9
|
+
ElementIR,
|
|
10
|
+
StyledDefinitionIR,
|
|
11
|
+
DOMStyleDefinitionIR,
|
|
12
|
+
} from './ir'
|
|
13
|
+
|
|
14
|
+
export type MaterializedValue =
|
|
15
|
+
| {
|
|
16
|
+
kind: 'static'
|
|
17
|
+
value: StaticEvaluationValue
|
|
18
|
+
dependencies: ResolvedModuleId[]
|
|
19
|
+
span: SourceSpan
|
|
20
|
+
/**
|
|
21
|
+
* Present only when normalization received syntax-level literal input:
|
|
22
|
+
* a string, number, boolean, or null AST literal, or JSXText. Template
|
|
23
|
+
* literals, constant-folded expressions, and values reached through a
|
|
24
|
+
* binding are evaluated static values but do not have literal origin.
|
|
25
|
+
*/
|
|
26
|
+
literalOrigin?: true
|
|
27
|
+
}
|
|
28
|
+
| {
|
|
29
|
+
kind: 'bailout'
|
|
30
|
+
bailout: BailoutReason
|
|
31
|
+
span: SourceSpan
|
|
32
|
+
}
|
|
33
|
+
| {
|
|
34
|
+
/**
|
|
35
|
+
* A conditional whose branches evaluated statically while the test did
|
|
36
|
+
* not: `cond ? 'body' : 'heading'`. Lowerings that cannot use it treat
|
|
37
|
+
* it exactly like a bailout (the bailout it would otherwise have been
|
|
38
|
+
* is preserved for that purpose).
|
|
39
|
+
*/
|
|
40
|
+
kind: 'conditional'
|
|
41
|
+
test: SourceSpan
|
|
42
|
+
whenTrue: StaticEvaluationValue
|
|
43
|
+
whenFalse: StaticEvaluationValue
|
|
44
|
+
dependencies: ResolvedModuleId[]
|
|
45
|
+
bailout: BailoutReason
|
|
46
|
+
span: SourceSpan
|
|
47
|
+
}
|
|
48
|
+
| {
|
|
49
|
+
kind: 'dom-style'
|
|
50
|
+
span: SourceSpan
|
|
51
|
+
items: {
|
|
52
|
+
condition: SourceSpan | null
|
|
53
|
+
value: Exclude<MaterializedValue, { kind: 'dom-style' }>
|
|
54
|
+
}[]
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export type MaterializedElementEntry =
|
|
58
|
+
| {
|
|
59
|
+
kind: 'prop'
|
|
60
|
+
name: string
|
|
61
|
+
span: SourceSpan
|
|
62
|
+
value: MaterializedValue
|
|
63
|
+
}
|
|
64
|
+
| {
|
|
65
|
+
kind: 'spread'
|
|
66
|
+
span: SourceSpan
|
|
67
|
+
value: MaterializedValue
|
|
68
|
+
}
|
|
69
|
+
| {
|
|
70
|
+
kind: 'child'
|
|
71
|
+
span: SourceSpan
|
|
72
|
+
value:
|
|
73
|
+
| MaterializedValue
|
|
74
|
+
| { kind: 'element'; span: SourceSpan }
|
|
75
|
+
| { kind: 'empty'; span: SourceSpan }
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface MaterializedElement {
|
|
79
|
+
kind: 'element'
|
|
80
|
+
form: ElementIR['form']
|
|
81
|
+
id: ResolvedModuleId
|
|
82
|
+
span: SourceSpan
|
|
83
|
+
propsSpan: SourceSpan | null
|
|
84
|
+
component: ElementComponentIR
|
|
85
|
+
complete: boolean
|
|
86
|
+
entries: MaterializedElementEntry[]
|
|
87
|
+
bailouts: BailoutReason[]
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface MaterializedStyledDefinition {
|
|
91
|
+
kind: 'styled-definition'
|
|
92
|
+
id: ResolvedModuleId
|
|
93
|
+
name: string
|
|
94
|
+
span: SourceSpan
|
|
95
|
+
definitionSpan: SourceSpan
|
|
96
|
+
factory: ComponentImportProvenance
|
|
97
|
+
base: ElementComponentIR
|
|
98
|
+
baseClassName: MaterializedValue | null
|
|
99
|
+
options: MaterializedValue
|
|
100
|
+
complete: boolean
|
|
101
|
+
bailouts: BailoutReason[]
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export interface MaterializedDOMStyleDefinition extends Omit<
|
|
105
|
+
DOMStyleDefinitionIR,
|
|
106
|
+
'value'
|
|
107
|
+
> {
|
|
108
|
+
value: MaterializedValue
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export interface MaterializedModule {
|
|
112
|
+
version: 1
|
|
113
|
+
id: ResolvedModuleId
|
|
114
|
+
inputHash: string
|
|
115
|
+
elements: MaterializedElement[]
|
|
116
|
+
styledDefinitions: MaterializedStyledDefinition[]
|
|
117
|
+
domStyleDefinitions: MaterializedDOMStyleDefinition[]
|
|
118
|
+
diagnostics: BailoutReason[]
|
|
119
|
+
dependencies: ResolvedModuleId[]
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function compareCodeUnits(left: string, right: string): number {
|
|
123
|
+
return left < right ? -1 : left > right ? 1 : 0
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function materializeValue(
|
|
127
|
+
graph: ProjectGraph,
|
|
128
|
+
value: Extract<ElementEntryIR, { kind: 'prop' }>['value']
|
|
129
|
+
): MaterializedValue {
|
|
130
|
+
if (value.kind === 'static') {
|
|
131
|
+
return {
|
|
132
|
+
kind: 'static',
|
|
133
|
+
value: value.value,
|
|
134
|
+
dependencies: [],
|
|
135
|
+
span: value.span,
|
|
136
|
+
literalOrigin: true,
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (value.kind === 'dom-style') {
|
|
140
|
+
return {
|
|
141
|
+
kind: 'dom-style',
|
|
142
|
+
span: value.span,
|
|
143
|
+
items: value.items.map((item) => ({
|
|
144
|
+
condition: item.condition,
|
|
145
|
+
value: materializeValue(graph, item.value) as Exclude<
|
|
146
|
+
MaterializedValue,
|
|
147
|
+
{ kind: 'dom-style' }
|
|
148
|
+
>,
|
|
149
|
+
})),
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
const result = graph.evaluate(value)
|
|
153
|
+
if (result.ok) {
|
|
154
|
+
return {
|
|
155
|
+
kind: 'static',
|
|
156
|
+
value: result.value,
|
|
157
|
+
dependencies: result.dependencies,
|
|
158
|
+
span: value,
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
const conditional = graph.evaluateConditional(value)
|
|
162
|
+
if (conditional) {
|
|
163
|
+
return {
|
|
164
|
+
kind: 'conditional',
|
|
165
|
+
test: conditional.test,
|
|
166
|
+
whenTrue: conditional.whenTrue.value,
|
|
167
|
+
whenFalse: conditional.whenFalse.value,
|
|
168
|
+
dependencies: [
|
|
169
|
+
...new Set([
|
|
170
|
+
...conditional.whenTrue.dependencies,
|
|
171
|
+
...conditional.whenFalse.dependencies,
|
|
172
|
+
]),
|
|
173
|
+
].sort(compareCodeUnits),
|
|
174
|
+
bailout: result.bailout,
|
|
175
|
+
span: value,
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return { kind: 'bailout', bailout: result.bailout, span: value }
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function materializeEntry(
|
|
182
|
+
graph: ProjectGraph,
|
|
183
|
+
entry: ElementEntryIR
|
|
184
|
+
): MaterializedElementEntry {
|
|
185
|
+
if (entry.kind === 'prop') {
|
|
186
|
+
return {
|
|
187
|
+
kind: entry.kind,
|
|
188
|
+
name: entry.name,
|
|
189
|
+
span: entry.span,
|
|
190
|
+
value: materializeValue(graph, entry.value),
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
if (entry.kind === 'spread') {
|
|
194
|
+
return {
|
|
195
|
+
kind: entry.kind,
|
|
196
|
+
span: entry.span,
|
|
197
|
+
value: materializeValue(graph, entry.value),
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
if (entry.value.kind === 'element' || entry.value.kind === 'empty') {
|
|
201
|
+
return { kind: entry.kind, span: entry.span, value: entry.value }
|
|
202
|
+
}
|
|
203
|
+
return {
|
|
204
|
+
kind: entry.kind,
|
|
205
|
+
span: entry.span,
|
|
206
|
+
value: materializeValue(graph, entry.value),
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function materializeElement(
|
|
211
|
+
graph: ProjectGraph,
|
|
212
|
+
element: ElementIR
|
|
213
|
+
): MaterializedElement {
|
|
214
|
+
const entries = element.complete ? element.entries : element.bailedEntries
|
|
215
|
+
return {
|
|
216
|
+
kind: element.kind,
|
|
217
|
+
form: element.form,
|
|
218
|
+
id: element.id,
|
|
219
|
+
span: element.span,
|
|
220
|
+
propsSpan: element.propsSpan,
|
|
221
|
+
component: element.component,
|
|
222
|
+
complete: element.complete,
|
|
223
|
+
entries: entries.map((entry) => materializeEntry(graph, entry)),
|
|
224
|
+
bailouts: [...element.bailouts],
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function materializeStyledDefinition(
|
|
229
|
+
graph: ProjectGraph,
|
|
230
|
+
definition: StyledDefinitionIR
|
|
231
|
+
): MaterializedStyledDefinition {
|
|
232
|
+
return {
|
|
233
|
+
kind: definition.kind,
|
|
234
|
+
id: definition.id,
|
|
235
|
+
name: definition.name,
|
|
236
|
+
span: definition.span,
|
|
237
|
+
definitionSpan: definition.definitionSpan,
|
|
238
|
+
factory: definition.factory,
|
|
239
|
+
base: definition.base,
|
|
240
|
+
baseClassName: definition.baseClassName
|
|
241
|
+
? materializeValue(graph, definition.baseClassName)
|
|
242
|
+
: null,
|
|
243
|
+
options: materializeValue(graph, definition.options),
|
|
244
|
+
complete: definition.complete,
|
|
245
|
+
bailouts: [...definition.bailouts],
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function collectDependencies(module: Omit<MaterializedModule, 'dependencies'>) {
|
|
250
|
+
const dependencies = new Set<ResolvedModuleId>()
|
|
251
|
+
const collect = (value: MaterializedValue) => {
|
|
252
|
+
if (value.kind === 'static' || value.kind === 'conditional') {
|
|
253
|
+
for (const dependency of value.dependencies) dependencies.add(dependency)
|
|
254
|
+
} else if (value.kind === 'dom-style') {
|
|
255
|
+
for (const item of value.items) collect(item.value)
|
|
256
|
+
} else if (value.bailout.dependencyId) {
|
|
257
|
+
dependencies.add(value.bailout.dependencyId)
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
for (const element of module.elements) {
|
|
261
|
+
if (element.component.provenance) {
|
|
262
|
+
dependencies.add(element.component.provenance.resolvedId)
|
|
263
|
+
}
|
|
264
|
+
if (element.component.definition) dependencies.add(element.component.definition.id)
|
|
265
|
+
for (const entry of element.entries) {
|
|
266
|
+
if (
|
|
267
|
+
'value' in entry &&
|
|
268
|
+
entry.value.kind !== 'element' &&
|
|
269
|
+
entry.value.kind !== 'empty'
|
|
270
|
+
) {
|
|
271
|
+
collect(entry.value)
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
for (const definition of module.styledDefinitions) {
|
|
276
|
+
dependencies.add(definition.factory.resolvedId)
|
|
277
|
+
if (definition.base.provenance)
|
|
278
|
+
dependencies.add(definition.base.provenance.resolvedId)
|
|
279
|
+
if (definition.base.definition) dependencies.add(definition.base.definition.id)
|
|
280
|
+
if (definition.baseClassName) collect(definition.baseClassName)
|
|
281
|
+
collect(definition.options)
|
|
282
|
+
}
|
|
283
|
+
for (const definition of module.domStyleDefinitions) {
|
|
284
|
+
dependencies.add(definition.factory.resolvedId)
|
|
285
|
+
collect(definition.value)
|
|
286
|
+
}
|
|
287
|
+
return [...dependencies].sort(compareCodeUnits)
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export function materializeModule(
|
|
291
|
+
graph: ProjectGraph,
|
|
292
|
+
id: ResolvedModuleId
|
|
293
|
+
): MaterializedModule {
|
|
294
|
+
const inputHash = graph.contentHash(id)
|
|
295
|
+
if (!inputHash) throw new Error(`Cannot materialize unknown host module ${id}`)
|
|
296
|
+
const result = graph.elementsOf(id)
|
|
297
|
+
const definitions = [...result.styledDefinitions]
|
|
298
|
+
const definitionKeys = new Set(
|
|
299
|
+
definitions.map((definition) => `${definition.id}\0${definition.name}`)
|
|
300
|
+
)
|
|
301
|
+
for (const element of result.elements) {
|
|
302
|
+
const linked = element.component.definition
|
|
303
|
+
if (!linked || linked.id === id) continue
|
|
304
|
+
const definition = graph
|
|
305
|
+
.elementsOf(linked.id)
|
|
306
|
+
.styledDefinitions.find(
|
|
307
|
+
(candidate) => candidate.id === linked.id && candidate.name === linked.name
|
|
308
|
+
)
|
|
309
|
+
const key = definition && `${definition.id}\0${definition.name}`
|
|
310
|
+
if (definition && key && !definitionKeys.has(key)) {
|
|
311
|
+
definitionKeys.add(key)
|
|
312
|
+
definitions.push(definition)
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
const base = {
|
|
316
|
+
version: 1 as const,
|
|
317
|
+
id,
|
|
318
|
+
inputHash,
|
|
319
|
+
elements: result.elements.map((element) => materializeElement(graph, element)),
|
|
320
|
+
styledDefinitions: definitions.map((definition) =>
|
|
321
|
+
materializeStyledDefinition(graph, definition)
|
|
322
|
+
),
|
|
323
|
+
domStyleDefinitions: result.domStyleDefinitions.map((definition) => ({
|
|
324
|
+
...definition,
|
|
325
|
+
value: materializeValue(graph, definition.value),
|
|
326
|
+
})),
|
|
327
|
+
diagnostics: graph.diagnostics().filter(({ span }) => span.id === id),
|
|
328
|
+
}
|
|
329
|
+
return { ...base, dependencies: collectDependencies(base) }
|
|
330
|
+
}
|