@tamagui/compiler-core 0.0.0-bootstrap.0 → 3.0.0-beta.1093.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 +108 -0
- package/dist/cjs/contracts.cjs +61 -0
- package/dist/cjs/diagnostics.cjs +68 -0
- package/dist/cjs/evaluate.cjs +602 -0
- package/dist/cjs/graph.cjs +335 -0
- package/dist/cjs/hash.cjs +48 -0
- package/dist/cjs/index.cjs +43 -0
- package/dist/cjs/ir.cjs +32 -0
- package/dist/cjs/lower.cjs +232 -0
- package/dist/cjs/materialize.cjs +222 -0
- package/dist/cjs/normalize.cjs +628 -0
- package/dist/cjs/output.cjs +148 -0
- package/dist/cjs/planCache.cjs +262 -0
- package/dist/cjs/session.cjs +127 -0
- package/dist/cjs/yuku.cjs +166 -0
- package/dist/cjs/zero.cjs +389 -0
- package/dist/esm/ast.mjs +79 -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 +576 -0
- package/dist/esm/evaluate.mjs.map +1 -0
- package/dist/esm/graph.mjs +313 -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 +210 -0
- package/dist/esm/lower.mjs.map +1 -0
- package/dist/esm/materialize.mjs +203 -0
- package/dist/esm/materialize.mjs.map +1 -0
- package/dist/esm/normalize.mjs +604 -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 +232 -0
- package/dist/esm/planCache.mjs.map +1 -0
- package/dist/esm/session.mjs +108 -0
- package/dist/esm/session.mjs.map +1 -0
- package/dist/esm/yuku.mjs +144 -0
- package/dist/esm/yuku.mjs.map +1 -0
- package/dist/esm/zero.mjs +354 -0
- package/dist/esm/zero.mjs.map +1 -0
- package/package.json +42 -4
- package/src/ast.ts +106 -0
- package/src/contracts.ts +150 -0
- package/src/diagnostics.ts +96 -0
- package/src/evaluate.ts +875 -0
- package/src/graph.ts +425 -0
- package/src/hash.ts +36 -0
- package/src/index.ts +15 -0
- package/src/ir.ts +156 -0
- package/src/lower.ts +435 -0
- package/src/materialize.ts +383 -0
- package/src/normalize.ts +834 -0
- package/src/output.ts +175 -0
- package/src/planCache.ts +362 -0
- package/src/session.ts +192 -0
- package/src/yuku.ts +197 -0
- package/src/zero.ts +609 -0
- package/types/ast.d.ts +11 -0
- package/types/ast.d.ts.map +1 -0
- package/types/contracts.d.ts +99 -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 +48 -0
- package/types/evaluate.d.ts.map +1 -0
- package/types/graph.d.ts +51 -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 +120 -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 +121 -0
- package/types/materialize.d.ts.map +1 -0
- package/types/normalize.d.ts +7 -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 +123 -0
- package/types/planCache.d.ts.map +1 -0
- package/types/session.d.ts +52 -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 +99 -0
- package/types/zero.d.ts.map +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Nate Wienert
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1 +1,57 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@tamagui/compiler-core`
|
|
2
|
+
|
|
3
|
+
`CompilerSession` is Tamagui's bundler-neutral compiler API. It owns parsing,
|
|
4
|
+
the module graph, invalidation, lowering, and source-map-aware output. The host
|
|
5
|
+
owns resolution and loading.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import {
|
|
9
|
+
CompilerSession,
|
|
10
|
+
resolvedModuleId,
|
|
11
|
+
type CompilerAdapter,
|
|
12
|
+
type HostModuleInput,
|
|
13
|
+
} from '@tamagui/compiler-core'
|
|
14
|
+
|
|
15
|
+
const session = new CompilerSession()
|
|
16
|
+
const entry: HostModuleInput = {
|
|
17
|
+
id: resolvedModuleId('/app/Button.tsx'),
|
|
18
|
+
source: buttonSource,
|
|
19
|
+
imports: [
|
|
20
|
+
{
|
|
21
|
+
specifier: './tokens',
|
|
22
|
+
resolvedId: resolvedModuleId('/app/tokens.ts'),
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const adapter: CompilerAdapter = {
|
|
28
|
+
target: 'web',
|
|
29
|
+
projectGeneration: configHash,
|
|
30
|
+
host: createYourLoweringHost(),
|
|
31
|
+
async load(id) {
|
|
32
|
+
return modules.get(id) ?? null
|
|
33
|
+
},
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const result = await session.compile({ module: entry, adapter })
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Every `HostModuleInput` must contain a canonical id and every import must
|
|
40
|
+
already be resolved by the host. Mark package or runtime boundaries with
|
|
41
|
+
`external: true`. Call `update()` or `remove()` on watch changes and use the
|
|
42
|
+
returned ids to invalidate the host's module graph. Change
|
|
43
|
+
`projectGeneration` whenever Tamagui config or component metadata changes.
|
|
44
|
+
|
|
45
|
+
Adapters should pass the output source map back to their bundler and watch the
|
|
46
|
+
dependencies they loaded. Native adapters must reject CSS output rather than
|
|
47
|
+
silently dropping it.
|
|
48
|
+
|
|
49
|
+
The maintained adapters are:
|
|
50
|
+
|
|
51
|
+
- `@tamagui/vite-plugin` for Vite web and One's iOS/Android Rolldown pipeline
|
|
52
|
+
through its Vite config provider API
|
|
53
|
+
- `@tamagui/metro-plugin` for Metro's main-process graph and worker cache
|
|
54
|
+
- `tamagui build` for explicit precompilation, including Next.js Turbopack
|
|
55
|
+
|
|
56
|
+
The legacy `@tamagui/next-plugin` and `tamagui-loader` packages only support
|
|
57
|
+
webpack and are outside the v3 compiler path.
|
package/dist/cjs/ast.cjs
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: true
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
14
|
+
get: () => from[key],
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
var ast_exports = {};
|
|
22
|
+
__export(ast_exports, {
|
|
23
|
+
childNode: () => childNode,
|
|
24
|
+
childNodes: () => childNodes,
|
|
25
|
+
findAstNode: () => findAstNode,
|
|
26
|
+
identifierName: () => identifierName,
|
|
27
|
+
isAstNode: () => isAstNode,
|
|
28
|
+
literalValue: () => literalValue,
|
|
29
|
+
unwrapExpression: () => unwrapExpression,
|
|
30
|
+
walkAst: () => walkAst
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(ast_exports);
|
|
33
|
+
const ignoredKeys = /* @__PURE__ */ new Set([
|
|
34
|
+
"loc",
|
|
35
|
+
"range",
|
|
36
|
+
"parent",
|
|
37
|
+
"comments",
|
|
38
|
+
"tokens"
|
|
39
|
+
]);
|
|
40
|
+
function isAstNode(value) {
|
|
41
|
+
return typeof value === "object" && value !== null && typeof value.type === "string" && typeof value.start === "number" && typeof value.end === "number";
|
|
42
|
+
}
|
|
43
|
+
function walkAst(node, visitor, parent = null, key = null) {
|
|
44
|
+
visitor(node, parent, key);
|
|
45
|
+
for (const childKey of Object.keys(node)) {
|
|
46
|
+
if (ignoredKeys.has(childKey)) continue;
|
|
47
|
+
const value = node[childKey];
|
|
48
|
+
if (isAstNode(value)) {
|
|
49
|
+
walkAst(value, visitor, node, childKey);
|
|
50
|
+
} else if (Array.isArray(value)) {
|
|
51
|
+
for (const child of value) {
|
|
52
|
+
if (isAstNode(child)) {
|
|
53
|
+
walkAst(child, visitor, node, childKey);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function findAstNode(root, predicate, span) {
|
|
60
|
+
function visit(node, parent, key) {
|
|
61
|
+
if (span && (node.start > span.start || node.end < span.end)) return null;
|
|
62
|
+
if (predicate(node, parent, key)) return node;
|
|
63
|
+
for (const childKey of Object.keys(node)) {
|
|
64
|
+
if (ignoredKeys.has(childKey)) continue;
|
|
65
|
+
const value = node[childKey];
|
|
66
|
+
if (isAstNode(value)) {
|
|
67
|
+
const found = visit(value, node, childKey);
|
|
68
|
+
if (found) return found;
|
|
69
|
+
} else if (Array.isArray(value)) {
|
|
70
|
+
for (const child of value) {
|
|
71
|
+
if (!isAstNode(child)) continue;
|
|
72
|
+
const found = visit(child, node, childKey);
|
|
73
|
+
if (found) return found;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
return visit(root, null, null);
|
|
80
|
+
}
|
|
81
|
+
function childNode(node, key) {
|
|
82
|
+
const value = node[key];
|
|
83
|
+
return isAstNode(value) ? value : null;
|
|
84
|
+
}
|
|
85
|
+
function childNodes(node, key) {
|
|
86
|
+
const value = node[key];
|
|
87
|
+
return Array.isArray(value) ? value.filter(isAstNode) : [];
|
|
88
|
+
}
|
|
89
|
+
function identifierName(node) {
|
|
90
|
+
if (!node || node.type !== "Identifier" && node.type !== "JSXIdentifier") return null;
|
|
91
|
+
return typeof node.name === "string" ? node.name : null;
|
|
92
|
+
}
|
|
93
|
+
function literalValue(node) {
|
|
94
|
+
if (!node) return void 0;
|
|
95
|
+
if (node.type === "Literal" || node.type.endsWith("Literal")) {
|
|
96
|
+
return node.value;
|
|
97
|
+
}
|
|
98
|
+
return void 0;
|
|
99
|
+
}
|
|
100
|
+
function unwrapExpression(node) {
|
|
101
|
+
let current = node;
|
|
102
|
+
while (current.type === "TSAsExpression" || current.type === "TSSatisfiesExpression" || current.type === "TSNonNullExpression" || current.type === "ParenthesizedExpression") {
|
|
103
|
+
const expression = childNode(current, "expression");
|
|
104
|
+
if (!expression) break;
|
|
105
|
+
current = expression;
|
|
106
|
+
}
|
|
107
|
+
return current;
|
|
108
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: true
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
14
|
+
get: () => from[key],
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
var contracts_exports = {};
|
|
22
|
+
__export(contracts_exports, {
|
|
23
|
+
expressionReference: () => expressionReference,
|
|
24
|
+
resolutionKey: () => resolutionKey,
|
|
25
|
+
resolveFromHost: () => resolveFromHost,
|
|
26
|
+
resolvedModuleId: () => resolvedModuleId,
|
|
27
|
+
spanOf: () => spanOf,
|
|
28
|
+
textOfSpan: () => textOfSpan
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(contracts_exports);
|
|
31
|
+
function resolutionKey(importer, specifier) {
|
|
32
|
+
return `${importer}\0${specifier}`;
|
|
33
|
+
}
|
|
34
|
+
function resolveFromHost(resolutions, specifier, importer) {
|
|
35
|
+
return resolutions.get(resolutionKey(importer, specifier)) ?? null;
|
|
36
|
+
}
|
|
37
|
+
function resolvedModuleId(id) {
|
|
38
|
+
const isAbsolute = id.startsWith("/") || id.startsWith("\\") || id.startsWith("\0") || /^[A-Za-z]:[\\/]/.test(id) || /^[A-Za-z][A-Za-z\d+.-]*:\/\//.test(id);
|
|
39
|
+
if (!isAbsolute) {
|
|
40
|
+
throw new Error(`Host module id must be canonical and already resolved: ${id}`);
|
|
41
|
+
}
|
|
42
|
+
return id;
|
|
43
|
+
}
|
|
44
|
+
function expressionReference(id, node) {
|
|
45
|
+
return {
|
|
46
|
+
kind: "expression",
|
|
47
|
+
id,
|
|
48
|
+
start: node.start,
|
|
49
|
+
end: node.end
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function spanOf(id, node) {
|
|
53
|
+
return {
|
|
54
|
+
id,
|
|
55
|
+
start: node.start,
|
|
56
|
+
end: node.end
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function textOfSpan(source, span) {
|
|
60
|
+
return source.slice(span.start, span.end);
|
|
61
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: true
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
14
|
+
get: () => from[key],
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
var diagnostics_exports = {};
|
|
22
|
+
__export(diagnostics_exports, {
|
|
23
|
+
linkedBailout: () => linkedBailout,
|
|
24
|
+
localBailout: () => localBailout,
|
|
25
|
+
zeroRuleForBailout: () => zeroRuleForBailout
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(diagnostics_exports);
|
|
28
|
+
const ZERO_RULE_BY_CODE = {
|
|
29
|
+
"local/invalid-element-call": 2,
|
|
30
|
+
"local/unsupported-element-name": 2,
|
|
31
|
+
"local/unsupported-prop-key": 3,
|
|
32
|
+
"local/unsupported-child": 3,
|
|
33
|
+
"local/unsupported-expression": 3,
|
|
34
|
+
"local/unsupported-styled-definition": 3,
|
|
35
|
+
"local/dynamic-style-value": 3,
|
|
36
|
+
"local/unsafe-style-spread": 1,
|
|
37
|
+
"local/unsupported-target": 6,
|
|
38
|
+
"local/style-resolution-failed": 3,
|
|
39
|
+
"local/overlapping-edit": 6,
|
|
40
|
+
"local/non-object-spread": 1,
|
|
41
|
+
"local/static-evaluation-cycle": 3,
|
|
42
|
+
"local/parse-error": 3,
|
|
43
|
+
"linked/unresolved-component-binding": 2,
|
|
44
|
+
"linked/unresolved-binding": 2,
|
|
45
|
+
"linked/missing-initializer": 3,
|
|
46
|
+
"linked/unresolved-import": 2,
|
|
47
|
+
"linked/unresolved-component-config": 2
|
|
48
|
+
};
|
|
49
|
+
function zeroRuleForBailout(reason) {
|
|
50
|
+
return reason.zeroRule ?? ZERO_RULE_BY_CODE[reason.code];
|
|
51
|
+
}
|
|
52
|
+
function localBailout(code, span, message) {
|
|
53
|
+
return {
|
|
54
|
+
code,
|
|
55
|
+
kind: "local",
|
|
56
|
+
message,
|
|
57
|
+
span
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function linkedBailout(code, span, message, dependencyId) {
|
|
61
|
+
return {
|
|
62
|
+
code,
|
|
63
|
+
kind: "linked",
|
|
64
|
+
message,
|
|
65
|
+
span,
|
|
66
|
+
dependencyId
|
|
67
|
+
};
|
|
68
|
+
}
|