@tamagui/babel-plugin 1.74.2 → 1.74.4
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/dist/esm/index.native.js +186 -0
- package/dist/esm/index.native.js.map +6 -0
- package/package.json +4 -4
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { basename } from "path";
|
|
2
|
+
import generator from "@babel/generator";
|
|
3
|
+
import { declare } from "@babel/helper-plugin-utils";
|
|
4
|
+
import template from "@babel/template";
|
|
5
|
+
import * as t from "@babel/types";
|
|
6
|
+
import { simpleHash } from "@tamagui/simple-hash";
|
|
7
|
+
const importNativeView = template(`
|
|
8
|
+
const __ReactNativeView = require('react-native').View;
|
|
9
|
+
const __ReactNativeText = require('react-native').Text;
|
|
10
|
+
`), importStyleSheet = template(`
|
|
11
|
+
const __ReactNativeStyleSheet = require('react-native').StyleSheet;
|
|
12
|
+
`);
|
|
13
|
+
process.env.TAMAGUI_TARGET = "native";
|
|
14
|
+
const {
|
|
15
|
+
createExtractor,
|
|
16
|
+
getPragmaOptions,
|
|
17
|
+
isSimpleSpread,
|
|
18
|
+
literalToAst
|
|
19
|
+
} = require("@tamagui/static"), extractor = createExtractor();
|
|
20
|
+
var src_default = declare(function(api, options) {
|
|
21
|
+
return api.assertVersion(7), {
|
|
22
|
+
name: "tamagui",
|
|
23
|
+
visitor: {
|
|
24
|
+
Program: {
|
|
25
|
+
enter(root) {
|
|
26
|
+
let sourcePath = this.file.opts.filename;
|
|
27
|
+
process.env.SOURCE_ROOT?.endsWith("ios") && (sourcePath = sourcePath.replace("/ios", ""));
|
|
28
|
+
let hasImportedView = !1;
|
|
29
|
+
const sheetStyles = {}, sheetIdentifier = root.scope.generateUidIdentifier("sheet"), firstComment = root.node.body[0]?.leadingComments?.[0]?.value?.trim() ?? "", { shouldPrintDebug, shouldDisable } = getPragmaOptions({
|
|
30
|
+
disableCommentCheck: !0,
|
|
31
|
+
source: firstComment,
|
|
32
|
+
path: sourcePath
|
|
33
|
+
});
|
|
34
|
+
if (shouldDisable)
|
|
35
|
+
return;
|
|
36
|
+
function addSheetStyle(style, node) {
|
|
37
|
+
let key = `${`${Object.keys(sheetStyles).length}`}`;
|
|
38
|
+
if (process.env.NODE_ENV === "development") {
|
|
39
|
+
const lineNumbers = node.loc ? node.loc.start.line + (node.loc.start.line !== node.loc.end.line ? `-${node.loc.end.line}` : "") : "";
|
|
40
|
+
key += `:${basename(sourcePath)}:${lineNumbers}`;
|
|
41
|
+
}
|
|
42
|
+
return sheetStyles[key] = style, readStyleExpr(key);
|
|
43
|
+
}
|
|
44
|
+
function readStyleExpr(key) {
|
|
45
|
+
return template("SHEET['KEY']")({
|
|
46
|
+
SHEET: sheetIdentifier.name,
|
|
47
|
+
KEY: key
|
|
48
|
+
}).expression;
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
extractor.parseSync(root, {
|
|
52
|
+
// @ts-expect-error in case they leave it out
|
|
53
|
+
platform: "native",
|
|
54
|
+
shouldPrintDebug,
|
|
55
|
+
importsWhitelist: ["constants.js", "colors.js"],
|
|
56
|
+
deoptProps: /* @__PURE__ */ new Set([
|
|
57
|
+
"focusStyle",
|
|
58
|
+
"hoverStyle",
|
|
59
|
+
"pressStyle",
|
|
60
|
+
"pointerEvents"
|
|
61
|
+
]),
|
|
62
|
+
extractStyledDefinitions: options.forceExtractStyleDefinitions,
|
|
63
|
+
excludeProps: /* @__PURE__ */ new Set([
|
|
64
|
+
"className",
|
|
65
|
+
"userSelect",
|
|
66
|
+
"whiteSpace",
|
|
67
|
+
"textOverflow",
|
|
68
|
+
"cursor",
|
|
69
|
+
"contain"
|
|
70
|
+
]),
|
|
71
|
+
...options,
|
|
72
|
+
// disable this extraction for now at least, need to figure out merging theme vs non-theme
|
|
73
|
+
// because theme need to stay in render(), whereas non-theme can be extracted
|
|
74
|
+
// for now just turn it off entirely at a small perf loss
|
|
75
|
+
disableExtractInlineMedia: !0,
|
|
76
|
+
// disable extracting variables as no native concept of them (only theme values)
|
|
77
|
+
disableExtractVariables: "theme",
|
|
78
|
+
sourcePath,
|
|
79
|
+
// disabling flattening for now
|
|
80
|
+
// it's flattening a plain <Paragraph>hello</Paragraph> which breaks things because themes
|
|
81
|
+
// thinking it's not really worth the effort to do much compilation on native
|
|
82
|
+
// for now just disable flatten as it can only run in narrow places on native
|
|
83
|
+
// disableFlattening: 'styled',
|
|
84
|
+
getFlattenedNode({ isTextView }) {
|
|
85
|
+
return hasImportedView || (hasImportedView = !0, root.unshiftContainer("body", importNativeView())), isTextView ? "__ReactNativeText" : "__ReactNativeView";
|
|
86
|
+
},
|
|
87
|
+
onExtractTag(props) {
|
|
88
|
+
if (!props.isFlattened)
|
|
89
|
+
return;
|
|
90
|
+
assertValidTag(props.node);
|
|
91
|
+
const stylesExpr = t.arrayExpression([]), finalAttrs = [];
|
|
92
|
+
function addStyle(expr, key) {
|
|
93
|
+
props.isFlattened ? stylesExpr.elements.push(expr) : finalAttrs.push(
|
|
94
|
+
t.jsxAttribute(
|
|
95
|
+
t.jsxIdentifier(`_style${key}`),
|
|
96
|
+
t.jsxExpressionContainer(expr)
|
|
97
|
+
)
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
for (const attr of props.attrs)
|
|
101
|
+
switch (attr.type) {
|
|
102
|
+
case "style": {
|
|
103
|
+
const { themed, plain } = splitThemeStyles(attr.value);
|
|
104
|
+
for (const key in themed)
|
|
105
|
+
finalAttrs.push(
|
|
106
|
+
t.jsxAttribute(
|
|
107
|
+
t.jsxIdentifier(key),
|
|
108
|
+
t.stringLiteral(themed[key])
|
|
109
|
+
)
|
|
110
|
+
);
|
|
111
|
+
const ident = addSheetStyle(plain, props.node);
|
|
112
|
+
addStyle(ident, simpleHash(JSON.stringify(plain)));
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
case "ternary": {
|
|
116
|
+
const { consequent, alternate } = attr.value, cons = addSheetStyle(consequent, props.node), alt = addSheetStyle(alternate, props.node), styleExpr = t.conditionalExpression(
|
|
117
|
+
attr.value.test,
|
|
118
|
+
cons,
|
|
119
|
+
alt
|
|
120
|
+
);
|
|
121
|
+
addStyle(
|
|
122
|
+
styleExpr,
|
|
123
|
+
simpleHash(JSON.stringify({ consequent, alternate }))
|
|
124
|
+
);
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
case "attr": {
|
|
128
|
+
t.isJSXSpreadAttribute(attr.value) && isSimpleSpread(attr.value) && stylesExpr.elements.push(
|
|
129
|
+
t.memberExpression(attr.value.argument, t.identifier("style"))
|
|
130
|
+
), finalAttrs.push(attr.value);
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
props.node.attributes = finalAttrs, props.isFlattened && props.node.attributes.push(
|
|
135
|
+
t.jsxAttribute(
|
|
136
|
+
t.jsxIdentifier("style"),
|
|
137
|
+
t.jsxExpressionContainer(
|
|
138
|
+
stylesExpr.elements.length === 1 ? stylesExpr.elements[0] : stylesExpr
|
|
139
|
+
)
|
|
140
|
+
)
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
} catch (err) {
|
|
145
|
+
if (err instanceof Error) {
|
|
146
|
+
let message = `${shouldPrintDebug === "verbose" ? err : err.message}`;
|
|
147
|
+
message.includes("Unexpected return value from visitor method") && (message = "Unexpected return value from visitor method"), console.warn("Error in Tamagui parse, skipping", message, err.stack);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (!Object.keys(sheetStyles).length) {
|
|
152
|
+
shouldPrintDebug && console.log("END no styles");
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
const sheetObject = literalToAst(sheetStyles), sheetOuter = template(
|
|
156
|
+
"const SHEET = __ReactNativeStyleSheet.create(null)"
|
|
157
|
+
)({
|
|
158
|
+
SHEET: sheetIdentifier.name
|
|
159
|
+
});
|
|
160
|
+
sheetOuter.declarations[0].init.arguments[0] = sheetObject, root.unshiftContainer("body", sheetOuter), root.unshiftContainer("body", importStyleSheet()), shouldPrintDebug && (console.log(`
|
|
161
|
+
-------- output code -------
|
|
162
|
+
`), console.log(
|
|
163
|
+
generator(root.parent).code.split(`
|
|
164
|
+
`).filter((x) => !x.startsWith("//")).join(`
|
|
165
|
+
`)
|
|
166
|
+
));
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
});
|
|
172
|
+
function assertValidTag(node) {
|
|
173
|
+
node.attributes.find((x) => x.type === "JSXAttribute" && x.name.name === "style") && process.env.DEBUG?.startsWith("tamagui") && console.warn("\u26A0\uFE0F Cannot pass style attribute to extracted style");
|
|
174
|
+
}
|
|
175
|
+
function splitThemeStyles(style) {
|
|
176
|
+
const themed = {}, plain = {};
|
|
177
|
+
for (const key in style) {
|
|
178
|
+
const val = style[key];
|
|
179
|
+
val && val[0] === "$" ? themed[key] = val : plain[key] = val;
|
|
180
|
+
}
|
|
181
|
+
return { themed, plain };
|
|
182
|
+
}
|
|
183
|
+
export {
|
|
184
|
+
src_default as default
|
|
185
|
+
};
|
|
186
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/index.ts"],
|
|
4
|
+
"mappings": "AAAA,SAAS,gBAAgB;AAEzB,OAAO,eAAe;AACtB,SAAS,eAAe;AACxB,OAAO,cAAc;AAErB,YAAY,OAAO;AACnB,SAAS,kBAAkB;AAG3B,MAAM,mBAAmB,SAAS;AAAA;AAAA;AAAA,CAGjC,GAEK,mBAAmB,SAAS;AAAA;AAAA,CAEjC;AAGD,QAAQ,IAAI,iBAAiB;AAE7B,MAAM;AAAA,EACJ;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,IAAI,QAAQ,iBAAiB,GAEvB,YAAY,gBAAgB;AAElC,IAAO,cAAQ,QAAQ,SACrB,KACA,SAIA;AACA,aAAI,cAAc,C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;AAAA,YACA,OAAO,gBAAgB;AAAA,UACzB,CAAC;AAGD,qBAAW,aAAa,CAAC,EAAE,KAAK,UAAU,CAAC,IAAI,aAC/C,KAAK,iBAAiB,QAAQ,UAAU,GAExC,KAAK,iBAAiB,QAAQ,iBAAiB,CAAC,GAE5C,qBAEF,QAAQ,IAAI;AAAA;AAAA,CAAoC,GAEhD,QAAQ;AAAA,YACN,UAAU,KAAK,MAAM,EAClB,KAAK,MAAM;AAAA,CAAI,EACf,OAAO,CAAC,MAAM,CAAC,EAAE,WAAW,IAAI,CAAC,EACjC,KAAK;AAAA,CAAI;AAAA,UACd;AAAA,QAEJ;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF,CAAC;AAED,SAAS,eAAe,MAA2B;AACjD,EAAI,KAAK,WAAW,KAAK,CAAC,MAAM,EAAE,SAAS,kBAAkB,EAAE,KAAK,SAAS,OAAO,KAG9E,QAAQ,IAAI,OAAO,WAAW,SAAS,KACzC,QAAQ,KAAK,6DAAmD;AAGtE;AAEA,SAAS,iBAAiB,OAAe;AACvC,QAAM,SAAS,CAAC,GACV,QAAQ,CAAC;AACf,aAAW,OAAO,OAAO;AACvB,UAAM,MAAM,MAAM,GAAG;AACrB,IAAI,OAAO,IAAI,CAAC,MAAM,MACpB,OAAO,GAAG,IAAI,MAEd,MAAM,GAAG,IAAI;AAAA,EAEjB;AACA,SAAO,EAAE,QAAQ,MAAM;AACzB;",
|
|
5
|
+
"names": []
|
|
6
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/babel-plugin",
|
|
3
|
-
"version": "1.74.
|
|
3
|
+
"version": "1.74.4",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"types": "./types/index.d.ts",
|
|
6
6
|
"main": "dist/cjs",
|
|
@@ -27,12 +27,12 @@
|
|
|
27
27
|
"@babel/helper-plugin-utils": "^7.21.5",
|
|
28
28
|
"@babel/template": "^7.20.7",
|
|
29
29
|
"@babel/traverse": "^7.21.5",
|
|
30
|
-
"@tamagui/simple-hash": "1.74.
|
|
31
|
-
"@tamagui/static": "1.74.
|
|
30
|
+
"@tamagui/simple-hash": "1.74.4",
|
|
31
|
+
"@tamagui/static": "1.74.4"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@babel/types": "^7.21.5",
|
|
35
|
-
"@tamagui/build": "1.74.
|
|
35
|
+
"@tamagui/build": "1.74.4"
|
|
36
36
|
},
|
|
37
37
|
"gitHead": "a49cc7ea6b93ba384e77a4880ae48ac4a5635c14"
|
|
38
38
|
}
|