@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
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
|
+
}
|