@tamagui/babel-plugin 1.100.6 → 1.101.0
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/cjs/index.js +3 -279
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/index.native.js +3 -297
- package/dist/cjs/index.native.js.map +2 -2
- package/dist/esm/index.js +2 -280
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +2 -208
- package/dist/esm/index.native.js +2 -292
- package/dist/esm/index.native.js.map +2 -2
- package/package.json +3 -3
- package/src/index.ts +2 -469
- package/types/index.d.ts.map +1 -1
package/dist/esm/index.native.js
CHANGED
|
@@ -1,295 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { declare } from "@babel/helper-plugin-utils";
|
|
4
|
-
import template from "@babel/template";
|
|
5
|
-
import * as t from "@babel/types";
|
|
6
|
-
import { createExtractor, getPragmaOptions, isSimpleSpread, literalToAst, createLogger } from "@tamagui/static";
|
|
7
|
-
function _array_like_to_array(arr, len) {
|
|
8
|
-
(len == null || len > arr.length) && (len = arr.length);
|
|
9
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
10
|
-
return arr2;
|
|
11
|
-
}
|
|
12
|
-
function _array_without_holes(arr) {
|
|
13
|
-
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
14
|
-
}
|
|
15
|
-
function _define_property(obj, key, value) {
|
|
16
|
-
return key in obj ? Object.defineProperty(obj, key, {
|
|
17
|
-
value,
|
|
18
|
-
enumerable: !0,
|
|
19
|
-
configurable: !0,
|
|
20
|
-
writable: !0
|
|
21
|
-
}) : obj[key] = value, obj;
|
|
22
|
-
}
|
|
23
|
-
function _instanceof(left, right) {
|
|
24
|
-
return right != null && typeof Symbol < "u" && right[Symbol.hasInstance] ? !!right[Symbol.hasInstance](left) : left instanceof right;
|
|
25
|
-
}
|
|
26
|
-
function _iterable_to_array(iter) {
|
|
27
|
-
if (typeof Symbol < "u" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
28
|
-
}
|
|
29
|
-
function _non_iterable_spread() {
|
|
30
|
-
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
31
|
-
}
|
|
32
|
-
function _object_spread(target) {
|
|
33
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
34
|
-
var source = arguments[i] != null ? arguments[i] : {}, ownKeys2 = Object.keys(source);
|
|
35
|
-
typeof Object.getOwnPropertySymbols == "function" && (ownKeys2 = ownKeys2.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
36
|
-
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
37
|
-
}))), ownKeys2.forEach(function(key) {
|
|
38
|
-
_define_property(target, key, source[key]);
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
return target;
|
|
42
|
-
}
|
|
43
|
-
function ownKeys(object, enumerableOnly) {
|
|
44
|
-
var keys = Object.keys(object);
|
|
45
|
-
if (Object.getOwnPropertySymbols) {
|
|
46
|
-
var symbols = Object.getOwnPropertySymbols(object);
|
|
47
|
-
enumerableOnly && (symbols = symbols.filter(function(sym) {
|
|
48
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
49
|
-
})), keys.push.apply(keys, symbols);
|
|
50
|
-
}
|
|
51
|
-
return keys;
|
|
52
|
-
}
|
|
53
|
-
function _object_spread_props(target, source) {
|
|
54
|
-
return source = source ?? {}, Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function(key) {
|
|
55
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
56
|
-
}), target;
|
|
57
|
-
}
|
|
58
|
-
function _to_consumable_array(arr) {
|
|
59
|
-
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
60
|
-
}
|
|
61
|
-
function _unsupported_iterable_to_array(o, minLen) {
|
|
62
|
-
if (o) {
|
|
63
|
-
if (typeof o == "string") return _array_like_to_array(o, minLen);
|
|
64
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
65
|
-
if (n === "Object" && o.constructor && (n = o.constructor.name), n === "Map" || n === "Set") return Array.from(n);
|
|
66
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
var importNativeView = template(`
|
|
70
|
-
const __ReactNativeView = require('react-native').View;
|
|
71
|
-
const __ReactNativeText = require('react-native').Text;
|
|
72
|
-
`), importStyleSheet = template(`
|
|
73
|
-
const __ReactNativeStyleSheet = require('react-native').StyleSheet;
|
|
74
|
-
`), importWithStyle = template(`
|
|
75
|
-
const __withStableStyle = require('@tamagui/core')._withStableStyle;
|
|
76
|
-
`), extractor = createExtractor({
|
|
77
|
-
platform: "native"
|
|
78
|
-
}), src_default = declare(function(api, options) {
|
|
79
|
-
return api.assertVersion(7), {
|
|
80
|
-
name: "tamagui",
|
|
81
|
-
visitor: {
|
|
82
|
-
Program: {
|
|
83
|
-
enter: function(root) {
|
|
84
|
-
var _process_env_SOURCE_ROOT, _root_node_body__leadingComments, _root_node_body_, sourcePath = this.file.opts.filename;
|
|
85
|
-
if (sourcePath != null && sourcePath.includes("node_modules") || !(sourcePath != null && sourcePath.endsWith(".jsx")) && !(sourcePath != null && sourcePath.endsWith(".tsx")))
|
|
86
|
-
return;
|
|
87
|
-
!((_process_env_SOURCE_ROOT = process.env.SOURCE_ROOT) === null || _process_env_SOURCE_ROOT === void 0) && _process_env_SOURCE_ROOT.endsWith("ios") && (sourcePath = sourcePath.replace("/ios", ""));
|
|
88
|
-
var hasImportedView = !1, hasImportedViewWrapper = !1, sheetStyles = {}, sheetIdentifier = root.scope.generateUidIdentifier("sheet"), _root_node_body__leadingComments_map_join, firstCommentContents = (_root_node_body__leadingComments_map_join = (_root_node_body_ = root.node.body[0]) === null || _root_node_body_ === void 0 || (_root_node_body__leadingComments = _root_node_body_.leadingComments) === null || _root_node_body__leadingComments === void 0 ? void 0 : _root_node_body__leadingComments.map(function(comment) {
|
|
89
|
-
return (comment == null ? void 0 : comment.value) || " ";
|
|
90
|
-
}).join(" ")) !== null && _root_node_body__leadingComments_map_join !== void 0 ? _root_node_body__leadingComments_map_join : "", firstComment = firstCommentContents ? "//".concat(firstCommentContents) : "", _getPragmaOptions = getPragmaOptions({
|
|
91
|
-
source: firstComment,
|
|
92
|
-
path: sourcePath
|
|
93
|
-
}), shouldPrintDebug = _getPragmaOptions.shouldPrintDebug, shouldDisable = _getPragmaOptions.shouldDisable;
|
|
94
|
-
if (shouldDisable)
|
|
95
|
-
return;
|
|
96
|
-
var finalOptions = _object_spread({
|
|
97
|
-
// @ts-ignore just in case they leave it out
|
|
98
|
-
platform: "native"
|
|
99
|
-
}, options), printLog = createLogger(sourcePath, finalOptions);
|
|
100
|
-
function addSheetStyle(style, node) {
|
|
101
|
-
var styleIndex = "".concat(Object.keys(sheetStyles).length), key = "".concat(styleIndex);
|
|
102
|
-
if (process.env.NODE_ENV === "development") {
|
|
103
|
-
var lineNumbers = node.loc ? node.loc.start.line + (node.loc.start.line !== node.loc.end.line ? "-".concat(node.loc.end.line) : "") : "";
|
|
104
|
-
key += ":".concat(basename(sourcePath), ":").concat(lineNumbers);
|
|
105
|
-
}
|
|
106
|
-
return sheetStyles[key] = style, readStyleExpr(key);
|
|
107
|
-
}
|
|
108
|
-
function readStyleExpr(key) {
|
|
109
|
-
return template("SHEET['KEY']")({
|
|
110
|
-
SHEET: sheetIdentifier.name,
|
|
111
|
-
KEY: key
|
|
112
|
-
}).expression;
|
|
113
|
-
}
|
|
114
|
-
var res;
|
|
115
|
-
try {
|
|
116
|
-
res = extractor.parseSync(root, _object_spread_props(_object_spread({
|
|
117
|
-
importsWhitelist: [
|
|
118
|
-
"constants.js",
|
|
119
|
-
"colors.js"
|
|
120
|
-
],
|
|
121
|
-
extractStyledDefinitions: options.forceExtractStyleDefinitions,
|
|
122
|
-
excludeProps: /* @__PURE__ */ new Set([
|
|
123
|
-
"className",
|
|
124
|
-
"userSelect",
|
|
125
|
-
"whiteSpace",
|
|
126
|
-
"textOverflow",
|
|
127
|
-
"cursor",
|
|
128
|
-
"contain"
|
|
129
|
-
]),
|
|
130
|
-
shouldPrintDebug
|
|
131
|
-
}, finalOptions), {
|
|
132
|
-
// disable this extraction for now at least, need to figure out merging theme vs non-theme
|
|
133
|
-
// because theme need to stay in render(), whereas non-theme can be extracted
|
|
134
|
-
// for now just turn it off entirely at a small perf loss
|
|
135
|
-
disableExtractInlineMedia: !0,
|
|
136
|
-
// disable extracting variables as no native concept of them (only theme values)
|
|
137
|
-
disableExtractVariables: options.experimentalFlattenThemesOnNative ? !1 : "theme",
|
|
138
|
-
sourcePath,
|
|
139
|
-
// disabling flattening for now
|
|
140
|
-
// it's flattening a plain <Paragraph>hello</Paragraph> which breaks things because themes
|
|
141
|
-
// thinking it's not really worth the effort to do much compilation on native
|
|
142
|
-
// for now just disable flatten as it can only run in narrow places on native
|
|
143
|
-
// disableFlattening: 'styled',
|
|
144
|
-
getFlattenedNode: function(param) {
|
|
145
|
-
var isTextView = param.isTextView;
|
|
146
|
-
return hasImportedView || (hasImportedView = !0, root.unshiftContainer("body", importNativeView())), isTextView ? "__ReactNativeText" : "__ReactNativeView";
|
|
147
|
-
},
|
|
148
|
-
onExtractTag: function(props) {
|
|
149
|
-
var isFlattened = props.isFlattened;
|
|
150
|
-
if (!isFlattened)
|
|
151
|
-
return;
|
|
152
|
-
assertValidTag(props.node);
|
|
153
|
-
var stylesExpr = t.arrayExpression([]), hocStylesExpr = t.arrayExpression([]), expressions = [], finalAttrs = [], themeKeysUsed = /* @__PURE__ */ new Set();
|
|
154
|
-
function getStyleExpression(style) {
|
|
155
|
-
if (style) {
|
|
156
|
-
var _splitThemeStyles = splitThemeStyles(style), plain = _splitThemeStyles.plain, themed = _splitThemeStyles.themed, themeExpr = null;
|
|
157
|
-
if (themed && options.experimentalFlattenThemesOnNative) {
|
|
158
|
-
for (var key in themed)
|
|
159
|
-
themeKeysUsed.add(themed[key].split("$")[1]);
|
|
160
|
-
themeExpr = getThemedStyleExpression(themed);
|
|
161
|
-
}
|
|
162
|
-
var ident = addSheetStyle(plain, props.node);
|
|
163
|
-
return themeExpr ? (addStyleExpression(ident), addStyleExpression(ident, !0), themeExpr) : ident;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
function addStyleExpression(expr) {
|
|
167
|
-
var HOC = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : !1;
|
|
168
|
-
if (Array.isArray(expr)) {
|
|
169
|
-
var _elements;
|
|
170
|
-
(_elements = (HOC ? hocStylesExpr : stylesExpr).elements).push.apply(_elements, _to_consumable_array(expr));
|
|
171
|
-
} else
|
|
172
|
-
(HOC ? hocStylesExpr : stylesExpr).elements.push(expr);
|
|
173
|
-
}
|
|
174
|
-
function getThemedStyleExpression(styles) {
|
|
175
|
-
var themedStylesAst = literalToAst(styles);
|
|
176
|
-
return themedStylesAst.properties.forEach(function(_) {
|
|
177
|
-
var prop = _;
|
|
178
|
-
prop.value.type === "StringLiteral" && (prop.value = t.memberExpression(t.identifier("theme"), t.identifier(prop.value.value.slice(1) + ".get()")));
|
|
179
|
-
}), themedStylesAst;
|
|
180
|
-
}
|
|
181
|
-
var hasDynamicStyle = !1, _iteratorNormalCompletion = !0, _didIteratorError = !1, _iteratorError = void 0;
|
|
182
|
-
try {
|
|
183
|
-
for (var _iterator = props.attrs[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) {
|
|
184
|
-
var attr = _step.value;
|
|
185
|
-
switch (attr.type) {
|
|
186
|
-
case "style": {
|
|
187
|
-
var styleExpr = getStyleExpression(attr.value);
|
|
188
|
-
addStyleExpression(styleExpr), options.experimentalFlattenThemesOnNative && addStyleExpression(styleExpr, !0);
|
|
189
|
-
break;
|
|
190
|
-
}
|
|
191
|
-
case "ternary": {
|
|
192
|
-
var _attr_value = attr.value, consequent = _attr_value.consequent, alternate = _attr_value.alternate, consExpr = getStyleExpression(consequent), altExpr = getStyleExpression(alternate);
|
|
193
|
-
options.experimentalFlattenThemesOnNative && (expressions.push(attr.value.test), addStyleExpression(t.conditionalExpression(t.identifier("_expressions[".concat(expressions.length - 1, "]")), consExpr || t.nullLiteral(), altExpr || t.nullLiteral()), !0));
|
|
194
|
-
var styleExpr1 = t.conditionalExpression(attr.value.test, consExpr || t.nullLiteral(), altExpr || t.nullLiteral());
|
|
195
|
-
addStyleExpression(styleExpr1);
|
|
196
|
-
break;
|
|
197
|
-
}
|
|
198
|
-
case "dynamic-style": {
|
|
199
|
-
hasDynamicStyle = !0, expressions.push(attr.value), options.experimentalFlattenDynamicValues ? addStyleExpression(t.objectExpression([
|
|
200
|
-
t.objectProperty(t.identifier(attr.name), t.identifier("_expressions[".concat(expressions.length - 1, "]")))
|
|
201
|
-
]), !0) : addStyleExpression(t.objectExpression([
|
|
202
|
-
t.objectProperty(t.identifier(attr.name), attr.value)
|
|
203
|
-
]));
|
|
204
|
-
break;
|
|
205
|
-
}
|
|
206
|
-
case "attr": {
|
|
207
|
-
t.isJSXSpreadAttribute(attr.value) && isSimpleSpread(attr.value) && (stylesExpr.elements.push(t.memberExpression(attr.value.argument, t.identifier("style"))), options.experimentalFlattenThemesOnNative && hocStylesExpr.elements.push(t.memberExpression(attr.value.argument, t.identifier("style")))), finalAttrs.push(attr.value);
|
|
208
|
-
break;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
} catch (err) {
|
|
213
|
-
_didIteratorError = !0, _iteratorError = err;
|
|
214
|
-
} finally {
|
|
215
|
-
try {
|
|
216
|
-
!_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
|
|
217
|
-
} finally {
|
|
218
|
-
if (_didIteratorError)
|
|
219
|
-
throw _iteratorError;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
if (props.node.attributes = finalAttrs, props.isFlattened)
|
|
223
|
-
if (options.experimentalFlattenThemesOnNative && (themeKeysUsed.size || hocStylesExpr.elements.length > 1 || hasDynamicStyle)) {
|
|
224
|
-
hasImportedViewWrapper || (root.unshiftContainer("body", importWithStyle()), hasImportedViewWrapper = !0);
|
|
225
|
-
var name = props.node.name.name, WrapperIdentifier = root.scope.generateUidIdentifier(name + "Wrapper");
|
|
226
|
-
root.pushContainer("body", t.variableDeclaration("const", [
|
|
227
|
-
t.variableDeclarator(WrapperIdentifier, t.callExpression(t.identifier("__withStableStyle"), [
|
|
228
|
-
t.identifier(name),
|
|
229
|
-
t.arrowFunctionExpression([
|
|
230
|
-
t.identifier("theme"),
|
|
231
|
-
t.identifier("_expressions")
|
|
232
|
-
], t.blockStatement([
|
|
233
|
-
t.returnStatement(t.callExpression(t.memberExpression(t.identifier("React"), t.identifier("useMemo")), [
|
|
234
|
-
t.arrowFunctionExpression([], t.blockStatement([
|
|
235
|
-
t.returnStatement(t.arrayExpression(_to_consumable_array(hocStylesExpr.elements)))
|
|
236
|
-
])),
|
|
237
|
-
t.arrayExpression([
|
|
238
|
-
t.spreadElement(t.identifier("_expressions"))
|
|
239
|
-
])
|
|
240
|
-
]))
|
|
241
|
-
]))
|
|
242
|
-
]))
|
|
243
|
-
])), props.node.name = WrapperIdentifier, props.jsxPath.node.closingElement && (props.jsxPath.node.closingElement.name = WrapperIdentifier), expressions.length && props.node.attributes.push(t.jsxAttribute(t.jsxIdentifier("expressions"), t.jsxExpressionContainer(t.arrayExpression(expressions))));
|
|
244
|
-
} else
|
|
245
|
-
props.node.attributes.push(t.jsxAttribute(t.jsxIdentifier("style"), t.jsxExpressionContainer(stylesExpr.elements.length === 1 ? stylesExpr.elements[0] : stylesExpr)));
|
|
246
|
-
}
|
|
247
|
-
}));
|
|
248
|
-
} catch (err) {
|
|
249
|
-
if (_instanceof(err, Error)) {
|
|
250
|
-
var message = "".concat(shouldPrintDebug === "verbose" ? err : err.message);
|
|
251
|
-
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);
|
|
252
|
-
return;
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
if (!Object.keys(sheetStyles).length) {
|
|
256
|
-
shouldPrintDebug && console.info("END no styles"), res && printLog(res);
|
|
257
|
-
return;
|
|
258
|
-
}
|
|
259
|
-
var sheetObject = literalToAst(sheetStyles), sheetOuter = template("const SHEET = __ReactNativeStyleSheet.create(null)")({
|
|
260
|
-
SHEET: sheetIdentifier.name
|
|
261
|
-
});
|
|
262
|
-
sheetOuter.declarations[0].init.arguments[0] = sheetObject, root.unshiftContainer("body", sheetOuter), root.unshiftContainer("body", importStyleSheet()), shouldPrintDebug && (console.info(`
|
|
263
|
-
-------- output code -------
|
|
264
|
-
`), console.info(generator(root.parent).code.split(`
|
|
265
|
-
`).filter(function(x) {
|
|
266
|
-
return !x.startsWith("//");
|
|
267
|
-
}).join(`
|
|
268
|
-
`))), res && printLog(res);
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
};
|
|
273
|
-
});
|
|
274
|
-
function assertValidTag(node) {
|
|
275
|
-
if (node.attributes.find(function(x) {
|
|
276
|
-
return x.type === "JSXAttribute" && x.name.name === "style";
|
|
277
|
-
})) {
|
|
278
|
-
var _process_env_DEBUG;
|
|
279
|
-
!((_process_env_DEBUG = process.env.DEBUG) === null || _process_env_DEBUG === void 0) && _process_env_DEBUG.startsWith("tamagui") && console.warn("\u26A0\uFE0F Cannot pass style attribute to extracted style");
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
function splitThemeStyles(style) {
|
|
283
|
-
var themed = {}, plain = {}, noTheme = !0;
|
|
284
|
-
for (var key in style) {
|
|
285
|
-
var val = style[key];
|
|
286
|
-
val && val[0] === "$" ? (themed[key] = val, noTheme = !1) : plain[key] = val;
|
|
287
|
-
}
|
|
288
|
-
return {
|
|
289
|
-
themed: noTheme ? null : themed,
|
|
290
|
-
plain
|
|
291
|
-
};
|
|
292
|
-
}
|
|
1
|
+
import { getBabelPlugin } from "@tamagui/static";
|
|
2
|
+
var src_default = getBabelPlugin();
|
|
293
3
|
export {
|
|
294
4
|
src_default as default
|
|
295
5
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Users/n8/tamagui/packages/babel-plugin/src/index.ts"],
|
|
4
|
-
"mappings": "AAAA,SAASA,
|
|
5
|
-
"names": ["
|
|
4
|
+
"mappings": "AAAA,SAASA,sBAAsB;AAE/B,IAAA,cAAeA,eAAAA;",
|
|
5
|
+
"names": ["getBabelPlugin"]
|
|
6
6
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/babel-plugin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.101.0",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"types": "./types/index.d.ts",
|
|
6
6
|
"main": "dist/cjs",
|
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
"@babel/helper-plugin-utils": "^7.22.5",
|
|
28
28
|
"@babel/template": "^7.22.15",
|
|
29
29
|
"@babel/traverse": "^7.23.3",
|
|
30
|
-
"@tamagui/static": "1.
|
|
30
|
+
"@tamagui/static": "1.101.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@babel/types": "^7.23.3",
|
|
34
|
-
"@tamagui/build": "1.
|
|
34
|
+
"@tamagui/build": "1.101.0"
|
|
35
35
|
},
|
|
36
36
|
"gitHead": "a49cc7ea6b93ba384e77a4880ae48ac4a5635c14"
|
|
37
37
|
}
|