@tamagui/compiler-core 0.0.0-bootstrap.0 → 3.0.0-beta.643.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
package/src/yuku.ts ADDED
@@ -0,0 +1,189 @@
1
+ import { Analyzer, type Module, type Symbol as YukuSymbol } from 'yuku-analyzer'
2
+
3
+ import type {
4
+ AnalyzerCandidate,
5
+ AstNode,
6
+ CandidateFactory,
7
+ DefinitionSite,
8
+ ParseDiagnostic,
9
+ ProjectInput,
10
+ ReferenceSite,
11
+ } from './contracts'
12
+ import { resolveFromHost, resolvedModuleId } from './contracts'
13
+ import { childNode, walkAst } from './ast'
14
+ import { asAstNode, declarationForName, definitionFromDeclaration } from './normalize'
15
+
16
+ class YukuCandidate implements AnalyzerCandidate {
17
+ readonly name = 'yuku' as const
18
+ readonly #analyzer: Analyzer
19
+ readonly #parseCounts = new Map<string, number>()
20
+
21
+ constructor(private readonly project: ProjectInput) {
22
+ this.#analyzer = new Analyzer({
23
+ resolve: (specifier, importer) =>
24
+ resolveFromHost(this.project.resolutions, specifier, importer),
25
+ })
26
+ for (const [id, source] of project.files) this.addFile(id, source)
27
+ }
28
+
29
+ addFile(id: string, source: string): void {
30
+ this.#analyzer.addFile(id, source, { preserveParens: true, sourceType: 'module' })
31
+ this.#parseCounts.set(id, (this.#parseCounts.get(id) ?? 0) + 1)
32
+ }
33
+
34
+ removeFile(id: string): boolean {
35
+ return this.#analyzer.removeFile(id)
36
+ }
37
+
38
+ link(): void {
39
+ this.#analyzer.link()
40
+ }
41
+
42
+ #module(id: string): Module {
43
+ const module = this.#analyzer.module(id)
44
+ if (!module) throw new Error(`yuku: unknown module ${id}`)
45
+ return module
46
+ }
47
+
48
+ #canonicalSymbol(id: string, localName: string): YukuSymbol | null {
49
+ const symbol = this.#module(id).resolve(localName)
50
+ return symbol ? (this.#analyzer.definitionOf(symbol)?.symbol ?? null) : null
51
+ }
52
+
53
+ definitionOf(id: string, localName: string): DefinitionSite | null {
54
+ const symbol = this.#canonicalSymbol(id, localName)
55
+ if (!symbol) return null
56
+ const declaration = symbol.declarations[0]
57
+ if (!declaration) return null
58
+ const program = asAstNode(symbol.module.ast, `${symbol.module.path} program`)
59
+ const normalizedDeclaration =
60
+ declarationForName(program, symbol.name) ??
61
+ asAstNode(declaration, `${symbol.name} declaration`)
62
+ return definitionFromDeclaration(
63
+ symbol.module.path,
64
+ symbol.name,
65
+ program,
66
+ normalizedDeclaration
67
+ )
68
+ }
69
+
70
+ referencesOf(definition: DefinitionSite): ReferenceSite[] {
71
+ const symbol = this.#canonicalSymbol(definition.id, definition.name)
72
+ if (!symbol) return []
73
+ return this.#analyzer.referencesOf(symbol).map(({ module, reference }) => ({
74
+ id: resolvedModuleId(module.path),
75
+ name: reference.name,
76
+ start: reference.node.start,
77
+ end: reference.node.end,
78
+ }))
79
+ }
80
+
81
+ dependenciesOf(id: string): string[] {
82
+ return this.#module(id)
83
+ .dependencies.map((module) => module.path)
84
+ .sort()
85
+ }
86
+
87
+ dependentsOf(id: string): string[] {
88
+ return this.#module(id)
89
+ .dependents.map((module) => module.path)
90
+ .sort()
91
+ }
92
+
93
+ affectedBy(id: string): string[] {
94
+ const affected = new Set([id])
95
+ const queue = [id]
96
+ while (queue.length) {
97
+ const current = queue.shift()!
98
+ for (const dependent of this.dependentsOf(current)) {
99
+ if (!affected.has(dependent)) {
100
+ affected.add(dependent)
101
+ queue.push(dependent)
102
+ }
103
+ }
104
+ }
105
+ return [...affected].sort()
106
+ }
107
+
108
+ programOf(id: string) {
109
+ return asAstNode(this.#module(id).ast, `${id} program`)
110
+ }
111
+
112
+ sourceOf(id: string): string {
113
+ return this.#module(id).source
114
+ }
115
+
116
+ parseCount(id: string): number {
117
+ return this.#parseCounts.get(id) ?? 0
118
+ }
119
+
120
+ diagnostics(): ParseDiagnostic[] {
121
+ const parseDiagnostics = [...this.#analyzer.modules.values()].flatMap((module) =>
122
+ module.diagnostics.map((diagnostic) => ({
123
+ kind: 'parse' as const,
124
+ id: resolvedModuleId(module.path),
125
+ message: diagnostic.message,
126
+ }))
127
+ )
128
+ return [
129
+ ...parseDiagnostics,
130
+ ...this.#analyzer.diagnostics.map((diagnostic) => ({
131
+ kind: 'link' as const,
132
+ id: resolvedModuleId(diagnostic.module),
133
+ message: diagnostic.message,
134
+ })),
135
+ ]
136
+ }
137
+ }
138
+
139
+ export const yukuFactory: CandidateFactory = {
140
+ name: 'yuku',
141
+ create: (project) => new YukuCandidate(project),
142
+ scanImports(id, source) {
143
+ const candidate = new YukuCandidate({
144
+ files: new Map([[id, source]]),
145
+ resolutions: new Map(),
146
+ })
147
+ const found: { start: number; specifier: string }[] = []
148
+ walkAst(candidate.programOf(id), (node) => {
149
+ if (
150
+ node.type !== 'ImportDeclaration' &&
151
+ node.type !== 'ExportNamedDeclaration' &&
152
+ node.type !== 'ExportAllDeclaration' &&
153
+ node.type !== 'ImportExpression'
154
+ ) {
155
+ return
156
+ }
157
+ const sourceNode = childNode(node, 'source')
158
+ if (sourceNode && typeof sourceNode.value === 'string') {
159
+ found.push({ start: node.start, specifier: sourceNode.value })
160
+ }
161
+ })
162
+ return [
163
+ ...new Set(
164
+ found
165
+ .sort((left, right) => left.start - right.start)
166
+ .map(({ specifier }) => specifier)
167
+ ),
168
+ ]
169
+ },
170
+ }
171
+
172
+ export function parseModuleAst(
173
+ source: string,
174
+ id = '/tamagui/compiler-module.tsx'
175
+ ): AstNode {
176
+ const candidate = yukuFactory.create({
177
+ files: new Map([[id, source]]),
178
+ resolutions: new Map(),
179
+ })
180
+ const diagnostics = candidate
181
+ .diagnostics()
182
+ .filter((diagnostic) => diagnostic.kind === 'parse')
183
+ if (diagnostics.length) {
184
+ throw new Error(
185
+ `Unable to parse ${id}: ${diagnostics.map(({ message }) => message).join('; ')}`
186
+ )
187
+ }
188
+ return candidate.programOf(id)
189
+ }