@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.
Files changed (98) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +57 -1
  3. package/dist/cjs/ast.cjs +95 -0
  4. package/dist/cjs/contracts.cjs +62 -0
  5. package/dist/cjs/diagnostics.cjs +69 -0
  6. package/dist/cjs/evaluate.cjs +351 -0
  7. package/dist/cjs/graph.cjs +279 -0
  8. package/dist/cjs/hash.cjs +49 -0
  9. package/dist/cjs/index.cjs +44 -0
  10. package/dist/cjs/ir.cjs +33 -0
  11. package/dist/cjs/lower.cjs +225 -0
  12. package/dist/cjs/materialize.cjs +200 -0
  13. package/dist/cjs/normalize.cjs +622 -0
  14. package/dist/cjs/output.cjs +149 -0
  15. package/dist/cjs/planCache.cjs +224 -0
  16. package/dist/cjs/session.cjs +119 -0
  17. package/dist/cjs/yuku.cjs +159 -0
  18. package/dist/cjs/zero.cjs +387 -0
  19. package/dist/esm/ast.mjs +65 -0
  20. package/dist/esm/ast.mjs.map +1 -0
  21. package/dist/esm/contracts.mjs +34 -0
  22. package/dist/esm/contracts.mjs.map +1 -0
  23. package/dist/esm/diagnostics.mjs +44 -0
  24. package/dist/esm/diagnostics.mjs.map +1 -0
  25. package/dist/esm/evaluate.mjs +327 -0
  26. package/dist/esm/evaluate.mjs.map +1 -0
  27. package/dist/esm/graph.mjs +256 -0
  28. package/dist/esm/graph.mjs.map +1 -0
  29. package/dist/esm/hash.mjs +26 -0
  30. package/dist/esm/hash.mjs.map +1 -0
  31. package/dist/esm/index.mjs +30 -0
  32. package/dist/esm/ir.mjs +12 -0
  33. package/dist/esm/ir.mjs.map +1 -0
  34. package/dist/esm/lower.mjs +202 -0
  35. package/dist/esm/lower.mjs.map +1 -0
  36. package/dist/esm/materialize.mjs +179 -0
  37. package/dist/esm/materialize.mjs.map +1 -0
  38. package/dist/esm/normalize.mjs +596 -0
  39. package/dist/esm/normalize.mjs.map +1 -0
  40. package/dist/esm/output.mjs +119 -0
  41. package/dist/esm/output.mjs.map +1 -0
  42. package/dist/esm/planCache.mjs +194 -0
  43. package/dist/esm/planCache.mjs.map +1 -0
  44. package/dist/esm/session.mjs +99 -0
  45. package/dist/esm/session.mjs.map +1 -0
  46. package/dist/esm/yuku.mjs +136 -0
  47. package/dist/esm/yuku.mjs.map +1 -0
  48. package/dist/esm/zero.mjs +352 -0
  49. package/dist/esm/zero.mjs.map +1 -0
  50. package/package.json +42 -4
  51. package/src/ast.ts +86 -0
  52. package/src/contracts.ts +148 -0
  53. package/src/diagnostics.ts +96 -0
  54. package/src/evaluate.ts +497 -0
  55. package/src/graph.ts +347 -0
  56. package/src/hash.ts +36 -0
  57. package/src/index.ts +15 -0
  58. package/src/ir.ts +154 -0
  59. package/src/lower.ts +418 -0
  60. package/src/materialize.ts +330 -0
  61. package/src/normalize.ts +846 -0
  62. package/src/output.ts +175 -0
  63. package/src/planCache.ts +327 -0
  64. package/src/session.ts +172 -0
  65. package/src/yuku.ts +189 -0
  66. package/src/zero.ts +598 -0
  67. package/types/ast.d.ts +10 -0
  68. package/types/ast.d.ts.map +1 -0
  69. package/types/contracts.d.ts +97 -0
  70. package/types/contracts.d.ts.map +1 -0
  71. package/types/diagnostics.d.ts +31 -0
  72. package/types/diagnostics.d.ts.map +1 -0
  73. package/types/evaluate.d.ts +36 -0
  74. package/types/evaluate.d.ts.map +1 -0
  75. package/types/graph.d.ts +37 -0
  76. package/types/graph.d.ts.map +1 -0
  77. package/types/hash.d.ts +8 -0
  78. package/types/hash.d.ts.map +1 -0
  79. package/types/index.d.ts +16 -0
  80. package/types/index.d.ts.map +1 -0
  81. package/types/ir.d.ts +118 -0
  82. package/types/ir.d.ts.map +1 -0
  83. package/types/lower.d.ts +99 -0
  84. package/types/lower.d.ts.map +1 -0
  85. package/types/materialize.d.ts +104 -0
  86. package/types/materialize.d.ts.map +1 -0
  87. package/types/normalize.d.ts +8 -0
  88. package/types/normalize.d.ts.map +1 -0
  89. package/types/output.d.ts +32 -0
  90. package/types/output.d.ts.map +1 -0
  91. package/types/planCache.d.ts +113 -0
  92. package/types/planCache.d.ts.map +1 -0
  93. package/types/session.d.ts +44 -0
  94. package/types/session.d.ts.map +1 -0
  95. package/types/yuku.d.ts +4 -0
  96. package/types/yuku.d.ts.map +1 -0
  97. package/types/zero.d.ts +98 -0
  98. package/types/zero.d.ts.map +1 -0
@@ -0,0 +1,148 @@
1
+ export interface AstNode {
2
+ type: string
3
+ start: number
4
+ end: number
5
+ [key: string]: unknown
6
+ }
7
+
8
+ export type ResolvedModuleId = string & { readonly __resolvedModuleId: unique symbol }
9
+
10
+ export interface SourceSpan {
11
+ id: ResolvedModuleId
12
+ /** UTF-16 source-string index, inclusive. */
13
+ start: number
14
+ /** UTF-16 source-string index, exclusive. */
15
+ end: number
16
+ }
17
+
18
+ export interface HostResolvedImport {
19
+ specifier: string
20
+ resolvedId: ResolvedModuleId
21
+ external?: boolean
22
+ }
23
+
24
+ export interface HostModuleInput {
25
+ id: ResolvedModuleId
26
+ source: string
27
+ /** Every import identity is canonical and resolved before the compiler sees it. */
28
+ imports: readonly HostResolvedImport[]
29
+ }
30
+
31
+ export interface HostResolvedProject {
32
+ modules: readonly HostModuleInput[]
33
+ }
34
+
35
+ export interface ProjectInput {
36
+ files: ReadonlyMap<string, string>
37
+ resolutions: ReadonlyMap<string, string>
38
+ }
39
+
40
+ export interface DefinitionSite {
41
+ id: ResolvedModuleId
42
+ name: string
43
+ start: number
44
+ end: number
45
+ initializer: AstNode | null
46
+ constant: boolean
47
+ }
48
+
49
+ export interface ReferenceSite {
50
+ id: ResolvedModuleId
51
+ name: string
52
+ start: number
53
+ end: number
54
+ }
55
+
56
+ export interface ParseDiagnostic {
57
+ kind: 'parse' | 'link'
58
+ id: ResolvedModuleId
59
+ message: string
60
+ }
61
+
62
+ export interface AnalyzerCandidate {
63
+ readonly name: string
64
+ addFile(id: string, source: string): void
65
+ removeFile(id: string): boolean
66
+ link(): void
67
+ definitionOf(id: string, localName: string): DefinitionSite | null
68
+ referencesOf(definition: DefinitionSite): ReferenceSite[]
69
+ dependenciesOf(id: string): string[]
70
+ dependentsOf(id: string): string[]
71
+ affectedBy(id: string): string[]
72
+ programOf(id: string): AstNode
73
+ sourceOf(id: string): string
74
+ parseCount(id: string): number
75
+ diagnostics(): ParseDiagnostic[]
76
+ }
77
+
78
+ export interface ExpressionReference extends SourceSpan {
79
+ readonly kind: 'expression'
80
+ }
81
+
82
+ export interface SymbolDefinition {
83
+ id: ResolvedModuleId
84
+ name: string
85
+ span: SourceSpan
86
+ initializer: ExpressionReference | null
87
+ constant: boolean
88
+ }
89
+
90
+ /** Parser-independent symbol access used by partial evaluation and element IR. */
91
+ export interface SymbolResolver {
92
+ resolveBinding(id: ResolvedModuleId, localName: string): SymbolDefinition | null
93
+ expressionNode(reference: ExpressionReference): AstNode | null
94
+ sourceOf(id: ResolvedModuleId): string
95
+ }
96
+
97
+ export interface CandidateFactory {
98
+ name: AnalyzerCandidate['name']
99
+ create(project: ProjectInput): AnalyzerCandidate
100
+ /** Parser-owned static module scan; no parser-specific node types escape this boundary. */
101
+ scanImports(id: ResolvedModuleId, source: string): string[]
102
+ }
103
+
104
+ export function resolutionKey(importer: string, specifier: string): string {
105
+ return `${importer}\0${specifier}`
106
+ }
107
+
108
+ export function resolveFromHost(
109
+ resolutions: ReadonlyMap<string, string>,
110
+ specifier: string,
111
+ importer: string
112
+ ): string | null {
113
+ return resolutions.get(resolutionKey(importer, specifier)) ?? null
114
+ }
115
+
116
+ export function resolvedModuleId(id: string): ResolvedModuleId {
117
+ const isAbsolute =
118
+ id.startsWith('/') ||
119
+ id.startsWith('\\') ||
120
+ id.startsWith('\0') ||
121
+ /^[A-Za-z]:[\\/]/.test(id) ||
122
+ /^[A-Za-z][A-Za-z\d+.-]*:\/\//.test(id)
123
+ if (!isAbsolute) {
124
+ throw new Error(`Host module id must be canonical and already resolved: ${id}`)
125
+ }
126
+ return id as ResolvedModuleId
127
+ }
128
+
129
+ export function expressionReference(
130
+ id: ResolvedModuleId,
131
+ node: Pick<AstNode, 'start' | 'end'>
132
+ ): ExpressionReference {
133
+ return { kind: 'expression', id, start: node.start, end: node.end }
134
+ }
135
+
136
+ export function spanOf(
137
+ id: ResolvedModuleId,
138
+ node: Pick<AstNode, 'start' | 'end'>
139
+ ): SourceSpan {
140
+ return { id, start: node.start, end: node.end }
141
+ }
142
+
143
+ export function textOfSpan(
144
+ source: string,
145
+ span: Pick<SourceSpan, 'start' | 'end'>
146
+ ): string {
147
+ return source.slice(span.start, span.end)
148
+ }
@@ -0,0 +1,96 @@
1
+ import type { ResolvedModuleId, SourceSpan } from './contracts'
2
+
3
+ export type BailoutCode =
4
+ | 'local/invalid-element-call'
5
+ | 'local/unsupported-element-name'
6
+ | 'local/unsupported-prop-key'
7
+ | 'local/unsupported-child'
8
+ | 'local/unsupported-expression'
9
+ | 'local/unsupported-styled-definition'
10
+ | 'local/dynamic-style-value'
11
+ | 'local/unsafe-style-spread'
12
+ | 'local/unsupported-target'
13
+ | 'local/style-resolution-failed'
14
+ | 'local/overlapping-edit'
15
+ | 'local/non-object-spread'
16
+ | 'local/static-evaluation-cycle'
17
+ | 'local/parse-error'
18
+ | 'linked/unresolved-component-binding'
19
+ | 'linked/unresolved-binding'
20
+ | 'linked/missing-initializer'
21
+ | 'linked/unresolved-import'
22
+ | 'linked/unresolved-component-config'
23
+
24
+ /**
25
+ * The zero-runtime rule a diagnostic belongs to. Set by whichever site knows the
26
+ * reason; `zeroRuleForBailout` supplies the default for the rest.
27
+ */
28
+ export type ZeroRule = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8
29
+
30
+ export interface BailoutReason {
31
+ code: BailoutCode
32
+ kind: 'local' | 'linked'
33
+ message: string
34
+ span: SourceSpan
35
+ dependencyId?: ResolvedModuleId
36
+ component?: string
37
+ specifier?: string
38
+ prop?: string
39
+ /**
40
+ * True when this diagnostic stopped its candidate from lowering. Zero mode
41
+ * reports exactly these: a diagnostic recorded alongside a successful
42
+ * lowering describes a dropped prop, not a retained runtime.
43
+ */
44
+ blocking?: boolean
45
+ /** Set where the reporting site knows better than the code-level default. */
46
+ zeroRule?: ZeroRule
47
+ /** The design's fixed text for sites that have one, used verbatim. */
48
+ zeroMessage?: string
49
+ }
50
+
51
+ /**
52
+ * The rule a bailout code belongs to when its site did not name one. Ordinary
53
+ * compiler mode ignores this entirely.
54
+ */
55
+ const ZERO_RULE_BY_CODE: Record<BailoutCode, ZeroRule> = {
56
+ 'local/invalid-element-call': 2,
57
+ 'local/unsupported-element-name': 2,
58
+ 'local/unsupported-prop-key': 3,
59
+ 'local/unsupported-child': 3,
60
+ 'local/unsupported-expression': 3,
61
+ 'local/unsupported-styled-definition': 3,
62
+ 'local/dynamic-style-value': 3,
63
+ 'local/unsafe-style-spread': 1,
64
+ 'local/unsupported-target': 6,
65
+ 'local/style-resolution-failed': 3,
66
+ 'local/overlapping-edit': 6,
67
+ 'local/non-object-spread': 1,
68
+ 'local/static-evaluation-cycle': 3,
69
+ 'local/parse-error': 3,
70
+ 'linked/unresolved-component-binding': 2,
71
+ 'linked/unresolved-binding': 2,
72
+ 'linked/missing-initializer': 3,
73
+ 'linked/unresolved-import': 2,
74
+ 'linked/unresolved-component-config': 2,
75
+ }
76
+
77
+ export function zeroRuleForBailout(reason: BailoutReason): ZeroRule {
78
+ return reason.zeroRule ?? ZERO_RULE_BY_CODE[reason.code]
79
+ }
80
+
81
+ export function localBailout(
82
+ code: Extract<BailoutCode, `local/${string}`>,
83
+ span: SourceSpan,
84
+ message: string
85
+ ): BailoutReason {
86
+ return { code, kind: 'local', message, span }
87
+ }
88
+
89
+ export function linkedBailout(
90
+ code: Extract<BailoutCode, `linked/${string}`>,
91
+ span: SourceSpan,
92
+ message: string,
93
+ dependencyId?: ResolvedModuleId
94
+ ): BailoutReason {
95
+ return { code, kind: 'linked', message, span, dependencyId }
96
+ }