@tamagui/static 2.0.0-rc.9 → 2.0.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/check-dep-versions.cjs +201 -96
- package/dist/checkDeps.cjs +250 -46
- package/dist/constants.cjs +32 -30
- package/dist/exports.cjs +20 -13
- package/dist/extractor/accessSafe.cjs +25 -23
- package/dist/extractor/babelParse.cjs +30 -28
- package/dist/extractor/buildClassName.cjs +59 -35
- package/dist/extractor/bundle.cjs +187 -101
- package/dist/extractor/bundleConfig.cjs +568 -168
- package/dist/extractor/concatClassName.cjs +73 -32
- package/dist/extractor/createEvaluator.cjs +54 -41
- package/dist/extractor/createExtractor.cjs +1405 -574
- package/dist/extractor/createLogger.cjs +30 -25
- package/dist/extractor/detectModuleFormat.cjs +55 -0
- package/dist/extractor/ensureImportingConcat.cjs +31 -25
- package/dist/extractor/errors.cjs +12 -10
- package/dist/extractor/esbuildAliasPlugin.cjs +28 -16
- package/dist/extractor/esbuildTsconfigPaths.cjs +60 -36
- package/dist/extractor/evaluateAstNode.cjs +104 -59
- package/dist/extractor/extractHelpers.cjs +130 -67
- package/dist/extractor/extractMediaStyle.cjs +110 -69
- package/dist/extractor/extractToClassNames.cjs +337 -229
- package/dist/extractor/extractToNative.cjs +248 -152
- package/dist/extractor/findTopmostFunction.cjs +22 -13
- package/dist/extractor/generatedUid.cjs +39 -28
- package/dist/extractor/getPrefixLogs.cjs +12 -10
- package/dist/extractor/getPropValueFromAttributes.cjs +52 -34
- package/dist/extractor/getSourceModule.cjs +73 -37
- package/dist/extractor/getStaticBindingsForScope.cjs +131 -68
- package/dist/extractor/getTamaguiConfigPathFromOptionsConfig.cjs +20 -14
- package/dist/extractor/hasTopLevelAwait.cjs +62 -0
- package/dist/extractor/hoistClassNames.cjs +46 -32
- package/dist/extractor/literalToAst.cjs +67 -42
- package/dist/extractor/loadFile.cjs +9 -3
- package/dist/extractor/loadTamagui.cjs +151 -105
- package/dist/extractor/logLines.cjs +27 -19
- package/dist/extractor/normalizeTernaries.cjs +66 -44
- package/dist/extractor/propsToFontFamilyCache.cjs +15 -11
- package/dist/extractor/regenerateConfig.cjs +109 -81
- package/dist/extractor/removeUnusedHooks.cjs +73 -41
- package/dist/extractor/timer.cjs +23 -14
- package/dist/extractor/validHTMLAttributes.cjs +61 -59
- package/dist/extractor/watchTamaguiConfig.cjs +35 -23
- package/dist/getPragmaOptions.cjs +34 -19
- package/dist/helpers/memoize.cjs +24 -16
- package/dist/helpers/requireTamaguiCore.cjs +22 -15
- package/dist/index.cjs +26 -24
- package/dist/registerRequire.cjs +168 -65
- package/dist/server.cjs +35 -28
- package/dist/types.cjs +7 -5
- package/dist/worker.cjs +62 -40
- package/package.json +27 -24
- package/src/checkDeps.ts +305 -68
- package/src/exports.ts +2 -0
- package/src/extractor/babelParse.ts +1 -0
- package/src/extractor/bundle.ts +172 -40
- package/src/extractor/bundleConfig.ts +459 -65
- package/src/extractor/concatClassName.ts +37 -20
- package/src/extractor/createExtractor.ts +300 -30
- package/src/extractor/detectModuleFormat.ts +42 -0
- package/src/extractor/esbuildTsconfigPaths.ts +6 -1
- package/src/extractor/extractToClassNames.ts +15 -9
- package/src/extractor/extractToNative.ts +65 -32
- package/src/extractor/hasTopLevelAwait.ts +28 -0
- package/src/extractor/loadTamagui.ts +5 -4
- package/src/registerRequire.ts +102 -9
- package/types/checkDeps.d.ts.map +1 -1
- package/types/exports.d.ts +2 -0
- package/types/exports.d.ts.map +1 -1
- package/types/extractor/babelParse.d.ts.map +1 -1
- package/types/extractor/bundle.d.ts +83 -1
- package/types/extractor/bundle.d.ts.map +1 -1
- package/types/extractor/bundleConfig.d.ts +15 -2
- package/types/extractor/bundleConfig.d.ts.map +1 -1
- package/types/extractor/createExtractor.d.ts.map +1 -1
- package/types/extractor/detectModuleFormat.d.ts +5 -0
- package/types/extractor/detectModuleFormat.d.ts.map +1 -0
- package/types/extractor/esbuildTsconfigPaths.d.ts +8 -0
- package/types/extractor/esbuildTsconfigPaths.d.ts.map +1 -1
- package/types/extractor/extractToClassNames.d.ts.map +1 -1
- package/types/extractor/extractToNative.d.ts.map +1 -1
- package/types/extractor/hasTopLevelAwait.d.ts +2 -0
- package/types/extractor/hasTopLevelAwait.d.ts.map +1 -0
- package/types/extractor/loadTamagui.d.ts +1 -1
- package/types/extractor/loadTamagui.d.ts.map +1 -1
- package/types/registerRequire.d.ts.map +1 -1
- package/dist/check-dep-versions.js +0 -389
- package/dist/check-dep-versions.js.map +0 -6
- package/dist/checkDeps.js +0 -60
- package/dist/checkDeps.js.map +0 -6
- package/dist/constants.js +0 -34
- package/dist/constants.js.map +0 -6
- package/dist/exports.js +0 -34
- package/dist/exports.js.map +0 -6
- package/dist/extractor/accessSafe.js +0 -47
- package/dist/extractor/accessSafe.js.map +0 -6
- package/dist/extractor/babelParse.js +0 -59
- package/dist/extractor/babelParse.js.map +0 -6
- package/dist/extractor/buildClassName.js +0 -72
- package/dist/extractor/buildClassName.js.map +0 -6
- package/dist/extractor/bundle.js +0 -135
- package/dist/extractor/bundle.js.map +0 -6
- package/dist/extractor/bundleConfig.js +0 -352
- package/dist/extractor/bundleConfig.js.map +0 -6
- package/dist/extractor/concatClassName.js +0 -69
- package/dist/extractor/concatClassName.js.map +0 -6
- package/dist/extractor/createEvaluator.js +0 -66
- package/dist/extractor/createEvaluator.js.map +0 -6
- package/dist/extractor/createExtractor.js +0 -1212
- package/dist/extractor/createExtractor.js.map +0 -6
- package/dist/extractor/createLogger.js +0 -32
- package/dist/extractor/createLogger.js.map +0 -6
- package/dist/extractor/ensureImportingConcat.js +0 -50
- package/dist/extractor/ensureImportingConcat.js.map +0 -6
- package/dist/extractor/errors.js +0 -22
- package/dist/extractor/errors.js.map +0 -6
- package/dist/extractor/esbuildAliasPlugin.js +0 -36
- package/dist/extractor/esbuildAliasPlugin.js.map +0 -6
- package/dist/extractor/esbuildTsconfigPaths.js +0 -79
- package/dist/extractor/esbuildTsconfigPaths.js.map +0 -6
- package/dist/extractor/evaluateAstNode.js +0 -99
- package/dist/extractor/evaluateAstNode.js.map +0 -6
- package/dist/extractor/extractHelpers.js +0 -108
- package/dist/extractor/extractHelpers.js.map +0 -6
- package/dist/extractor/extractMediaStyle.js +0 -123
- package/dist/extractor/extractMediaStyle.js.map +0 -6
- package/dist/extractor/extractToClassNames.js +0 -351
- package/dist/extractor/extractToClassNames.js.map +0 -6
- package/dist/extractor/extractToNative.js +0 -286
- package/dist/extractor/extractToNative.js.map +0 -6
- package/dist/extractor/findTopmostFunction.js +0 -32
- package/dist/extractor/findTopmostFunction.js.map +0 -6
- package/dist/extractor/generatedUid.js +0 -42
- package/dist/extractor/generatedUid.js.map +0 -6
- package/dist/extractor/getPrefixLogs.js +0 -24
- package/dist/extractor/getPrefixLogs.js.map +0 -6
- package/dist/extractor/getPropValueFromAttributes.js +0 -65
- package/dist/extractor/getPropValueFromAttributes.js.map +0 -6
- package/dist/extractor/getSourceModule.js +0 -62
- package/dist/extractor/getSourceModule.js.map +0 -6
- package/dist/extractor/getStaticBindingsForScope.js +0 -145
- package/dist/extractor/getStaticBindingsForScope.js.map +0 -6
- package/dist/extractor/getTamaguiConfigPathFromOptionsConfig.js +0 -32
- package/dist/extractor/getTamaguiConfigPathFromOptionsConfig.js.map +0 -6
- package/dist/extractor/hoistClassNames.js +0 -63
- package/dist/extractor/hoistClassNames.js.map +0 -6
- package/dist/extractor/literalToAst.js +0 -90
- package/dist/extractor/literalToAst.js.map +0 -6
- package/dist/extractor/loadFile.js +0 -14
- package/dist/extractor/loadFile.js.map +0 -6
- package/dist/extractor/loadTamagui.js +0 -306
- package/dist/extractor/loadTamagui.js.map +0 -6
- package/dist/extractor/logLines.js +0 -30
- package/dist/extractor/logLines.js.map +0 -6
- package/dist/extractor/normalizeTernaries.js +0 -61
- package/dist/extractor/normalizeTernaries.js.map +0 -6
- package/dist/extractor/propsToFontFamilyCache.js +0 -33
- package/dist/extractor/propsToFontFamilyCache.js.map +0 -6
- package/dist/extractor/regenerateConfig.js +0 -123
- package/dist/extractor/regenerateConfig.js.map +0 -6
- package/dist/extractor/removeUnusedHooks.js +0 -72
- package/dist/extractor/removeUnusedHooks.js.map +0 -6
- package/dist/extractor/timer.js +0 -38
- package/dist/extractor/timer.js.map +0 -6
- package/dist/extractor/validHTMLAttributes.js +0 -72
- package/dist/extractor/validHTMLAttributes.js.map +0 -6
- package/dist/extractor/watchTamaguiConfig.js +0 -57
- package/dist/extractor/watchTamaguiConfig.js.map +0 -6
- package/dist/getPragmaOptions.js +0 -50
- package/dist/getPragmaOptions.js.map +0 -6
- package/dist/helpers/memoize.js +0 -33
- package/dist/helpers/memoize.js.map +0 -6
- package/dist/helpers/requireTamaguiCore.js +0 -30
- package/dist/helpers/requireTamaguiCore.js.map +0 -6
- package/dist/index.js +0 -30
- package/dist/index.js.map +0 -6
- package/dist/registerRequire.js +0 -100
- package/dist/registerRequire.js.map +0 -6
- package/dist/server.js +0 -58
- package/dist/server.js.map +0 -6
- package/dist/setup.js +0 -1
- package/dist/setup.js.map +0 -6
- package/dist/types.js +0 -14
- package/dist/types.js.map +0 -6
- package/dist/worker.js +0 -72
- package/dist/worker.js.map +0 -6
|
@@ -2,33 +2,35 @@ var __create = Object.create;
|
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf
|
|
6
|
-
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __export = (target, all) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
15
16
|
get: () => from[key],
|
|
16
17
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
18
|
});
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
20
22
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
28
|
+
value: mod,
|
|
29
|
+
enumerable: true
|
|
30
|
+
}) : target, mod));
|
|
31
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
32
|
+
value: true
|
|
33
|
+
}), mod);
|
|
32
34
|
var extractToNative_exports = {};
|
|
33
35
|
__export(extractToNative_exports, {
|
|
34
36
|
extractToNative: () => extractToNative,
|
|
@@ -36,51 +38,53 @@ __export(extractToNative_exports, {
|
|
|
36
38
|
getBabelPlugin: () => getBabelPlugin
|
|
37
39
|
});
|
|
38
40
|
module.exports = __toCommonJS(extractToNative_exports);
|
|
39
|
-
var import_core = require("@babel/core")
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
41
|
+
var import_core = require("@babel/core");
|
|
42
|
+
var import_generator = __toESM(require("@babel/generator"));
|
|
43
|
+
var import_helper_plugin_utils = require("@babel/helper-plugin-utils");
|
|
44
|
+
var import_parser = require("@babel/parser");
|
|
45
|
+
var import_template = __toESM(require("@babel/template"));
|
|
46
|
+
var t = __toESM(require("@babel/types"));
|
|
47
|
+
var import_node_path = require("node:path");
|
|
48
|
+
var import_getPragmaOptions = require("../getPragmaOptions.cjs");
|
|
49
|
+
var import_createExtractor = require("./createExtractor.cjs");
|
|
50
|
+
var import_createLogger = require("./createLogger.cjs");
|
|
51
|
+
var import_extractHelpers = require("./extractHelpers.cjs");
|
|
52
|
+
var import_literalToAst = require("./literalToAst.cjs");
|
|
53
|
+
var import_loadTamagui = require("./loadTamagui.cjs");
|
|
52
54
|
const importNativeView = (0, import_template.default)(`
|
|
53
55
|
const __ReactNativeView = require('react-native').View;
|
|
54
56
|
const __ReactNativeText = require('react-native').Text;
|
|
55
|
-
`)
|
|
56
|
-
|
|
57
|
+
`);
|
|
58
|
+
const importStyleSheet = (0, import_template.default)(`
|
|
57
59
|
const __ReactNativeStyleSheet = require('react-native').StyleSheet;
|
|
58
|
-
`)
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
extractor = (0, import_createExtractor.createExtractor)({
|
|
64
|
-
platform: "native"
|
|
65
|
-
});
|
|
60
|
+
`);
|
|
61
|
+
const importWithStyle = import_template.default.ast(`import { _withStableStyle } from '@tamagui/core';`);
|
|
62
|
+
const extractor = (0, import_createExtractor.createExtractor)({
|
|
63
|
+
platform: "native"
|
|
64
|
+
});
|
|
66
65
|
let tamaguiBuildOptionsLoaded;
|
|
67
66
|
function extractToNative(sourceFileName, sourceCode, options) {
|
|
68
67
|
const ast = (0, import_parser.parse)(sourceCode, {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if (!out)
|
|
68
|
+
sourceType: "module",
|
|
69
|
+
plugins: ["jsx", "typescript"]
|
|
70
|
+
});
|
|
71
|
+
const babelPlugin = getBabelPlugin();
|
|
72
|
+
const out = (0, import_core.transformFromAstSync)(ast, sourceCode, {
|
|
73
|
+
plugins: [[babelPlugin, options]],
|
|
74
|
+
configFile: false,
|
|
75
|
+
sourceFileName,
|
|
76
|
+
filename: sourceFileName
|
|
77
|
+
});
|
|
78
|
+
if (!out) {
|
|
79
|
+
throw new Error(`No output returned`);
|
|
80
|
+
}
|
|
80
81
|
return out;
|
|
81
82
|
}
|
|
82
83
|
function getBabelPlugin() {
|
|
83
|
-
return (0, import_helper_plugin_utils.declare)((api, options) =>
|
|
84
|
+
return (0, import_helper_plugin_utils.declare)((api, options) => {
|
|
85
|
+
api.assertVersion(7);
|
|
86
|
+
return getBabelParseDefinition(options);
|
|
87
|
+
});
|
|
84
88
|
}
|
|
85
89
|
function getBabelParseDefinition(options) {
|
|
86
90
|
return {
|
|
@@ -89,56 +93,71 @@ function getBabelParseDefinition(options) {
|
|
|
89
93
|
Program: {
|
|
90
94
|
enter(root) {
|
|
91
95
|
let sourcePath = this.file.opts.filename;
|
|
92
|
-
if (sourcePath?.includes("node_modules")
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
96
|
+
if (sourcePath?.includes("node_modules")) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (!sourcePath?.endsWith(".jsx") && !sourcePath?.endsWith(".tsx")) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (process.env.SOURCE_ROOT?.endsWith("ios")) {
|
|
103
|
+
sourcePath = sourcePath.replace("/ios", "");
|
|
104
|
+
}
|
|
105
|
+
let hasImportedView = false;
|
|
106
|
+
let hasImportedViewWrapper = false;
|
|
107
|
+
let wrapperCount = 0;
|
|
108
|
+
const sheetStyles = {};
|
|
109
|
+
const sheetIdentifier = root.scope.generateUidIdentifier("sheet");
|
|
110
|
+
const firstCommentContents =
|
|
111
|
+
// join because you can join together multiple pragmas
|
|
112
|
+
root.node.body[0]?.leadingComments?.map(comment => comment?.value || " ").join(" ") ?? "";
|
|
113
|
+
const firstComment = firstCommentContents ? `//${firstCommentContents}` : "";
|
|
114
|
+
const {
|
|
115
|
+
shouldPrintDebug,
|
|
116
|
+
shouldDisable
|
|
117
|
+
} = (0, import_getPragmaOptions.getPragmaOptions)({
|
|
118
|
+
source: firstComment,
|
|
119
|
+
path: sourcePath
|
|
120
|
+
});
|
|
121
|
+
if (shouldDisable) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (!options.config && !options.components) {
|
|
125
|
+
tamaguiBuildOptionsLoaded ||= (0, import_loadTamagui.loadTamaguiBuildConfigSync)({});
|
|
126
|
+
}
|
|
112
127
|
const finalOptions = {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
128
|
+
// @ts-ignore just in case they leave it out
|
|
129
|
+
platform: "native",
|
|
130
|
+
...tamaguiBuildOptionsLoaded,
|
|
131
|
+
...options
|
|
132
|
+
};
|
|
133
|
+
const printLog = (0, import_createLogger.createLogger)(sourcePath, finalOptions);
|
|
119
134
|
function addSheetStyle(style, node) {
|
|
120
|
-
|
|
135
|
+
const styleIndex = `${Object.keys(sheetStyles).length}`;
|
|
136
|
+
let key = `${styleIndex}`;
|
|
121
137
|
if (process.env.NODE_ENV === "development") {
|
|
122
138
|
const lineNumbers = node.loc ? node.loc.start.line + (node.loc.start.line !== node.loc.end.line ? `-${node.loc.end.line}` : "") : "";
|
|
123
139
|
key += `:${(0, import_node_path.basename)(sourcePath)}:${lineNumbers}`;
|
|
124
140
|
}
|
|
125
|
-
|
|
141
|
+
sheetStyles[key] = style;
|
|
142
|
+
return readStyleExpr(key);
|
|
126
143
|
}
|
|
127
144
|
function readStyleExpr(key) {
|
|
128
|
-
return (0, import_template.default)(
|
|
145
|
+
return (0, import_template.default)(`SHEET['KEY']`)({
|
|
129
146
|
SHEET: sheetIdentifier.name,
|
|
130
147
|
KEY: key
|
|
131
|
-
})
|
|
148
|
+
})["expression"];
|
|
132
149
|
}
|
|
133
150
|
let res;
|
|
134
151
|
try {
|
|
135
152
|
res = extractor.parseSync(root, {
|
|
136
153
|
importsWhitelist: ["constants.js", "colors.js"],
|
|
137
154
|
excludeProps: /* @__PURE__ */new Set(["className", "userSelect", "whiteSpace", "textOverflow", "cursor", "contain"]),
|
|
155
|
+
// native props that should pass through without preventing extraction
|
|
156
|
+
inlineProps: /* @__PURE__ */new Set(["testID", "nativeID", "accessibilityLabel", "accessibilityHint", "accessibilityRole", "accessibilityState", "accessibilityValue", "accessibilityActions", "accessibilityLabelledBy", "accessibilityLiveRegion", "accessibilityElementsHidden", "accessibilityViewIsModal", "importantForAccessibility", "onAccessibilityAction", "onAccessibilityEscape", "onAccessibilityTap", "onMagicTap", "collapsable", "needsOffscreenAlphaCompositing", "removeClippedSubviews", "renderToHardwareTextureAndroid", "shouldRasterizeIOS", "hitSlop", "pointerEvents"]),
|
|
138
157
|
shouldPrintDebug,
|
|
139
158
|
...finalOptions,
|
|
140
159
|
// disable extracting variables as no native concept of them (only theme values)
|
|
141
|
-
disableExtractVariables:
|
|
160
|
+
disableExtractVariables: false,
|
|
142
161
|
sourcePath,
|
|
143
162
|
// disabling flattening for now
|
|
144
163
|
// it's flattening a plain <Paragraph>hello</Paragraph> which breaks things because themes
|
|
@@ -148,16 +167,20 @@ function getBabelParseDefinition(options) {
|
|
|
148
167
|
getFlattenedNode({
|
|
149
168
|
isTextView
|
|
150
169
|
}) {
|
|
151
|
-
|
|
170
|
+
if (!hasImportedView) {
|
|
171
|
+
hasImportedView = true;
|
|
172
|
+
root.unshiftContainer("body", importNativeView());
|
|
173
|
+
}
|
|
174
|
+
return isTextView ? "__ReactNativeText" : "__ReactNativeView";
|
|
152
175
|
},
|
|
153
176
|
onExtractTag(props) {
|
|
154
177
|
assertValidTag(props.node);
|
|
155
|
-
const stylesExpr = t.arrayExpression([])
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
function getStyleExpression(style) {
|
|
178
|
+
const stylesExpr = t.arrayExpression([]);
|
|
179
|
+
const hocStylesExpr = t.arrayExpression([]);
|
|
180
|
+
const expressions = [];
|
|
181
|
+
const finalAttrs = [];
|
|
182
|
+
const themeKeysUsed = /* @__PURE__ */new Set();
|
|
183
|
+
function getStyleExpression(style, forTernary = false) {
|
|
161
184
|
if (!style) return;
|
|
162
185
|
const {
|
|
163
186
|
plain,
|
|
@@ -165,98 +188,171 @@ function getBabelParseDefinition(options) {
|
|
|
165
188
|
} = splitThemeStyles(style);
|
|
166
189
|
let themeExpr = null;
|
|
167
190
|
if (themed) {
|
|
168
|
-
for (const key in themed)
|
|
191
|
+
for (const key in themed) {
|
|
192
|
+
themeKeysUsed.add(themed[key].split("$")[1]);
|
|
193
|
+
}
|
|
169
194
|
themeExpr = getThemedStyleExpression(themed);
|
|
170
195
|
}
|
|
171
|
-
const
|
|
172
|
-
|
|
196
|
+
const hasPlainKeys = Object.keys(plain).length > 0;
|
|
197
|
+
const ident = hasPlainKeys ? addSheetStyle(plain, props.node) : null;
|
|
198
|
+
if (themeExpr) {
|
|
199
|
+
if (forTernary) {
|
|
200
|
+
if (ident) {
|
|
201
|
+
return t.arrayExpression([ident, themeExpr]);
|
|
202
|
+
}
|
|
203
|
+
return themeExpr;
|
|
204
|
+
}
|
|
205
|
+
if (ident) {
|
|
206
|
+
addStyleExpression(ident);
|
|
207
|
+
addStyleExpression(ident, true);
|
|
208
|
+
}
|
|
209
|
+
return themeExpr;
|
|
210
|
+
}
|
|
211
|
+
return ident;
|
|
173
212
|
}
|
|
174
|
-
function addStyleExpression(expr, HOC =
|
|
175
|
-
Array.isArray(expr)
|
|
213
|
+
function addStyleExpression(expr, HOC = false) {
|
|
214
|
+
if (Array.isArray(expr)) {
|
|
215
|
+
;
|
|
216
|
+
(HOC ? hocStylesExpr : stylesExpr).elements.push(...expr);
|
|
217
|
+
} else {
|
|
218
|
+
;
|
|
219
|
+
(HOC ? hocStylesExpr : stylesExpr).elements.push(expr);
|
|
220
|
+
}
|
|
176
221
|
}
|
|
177
222
|
function getThemedStyleExpression(styles) {
|
|
178
223
|
const themedStylesAst = (0, import_literalToAst.literalToAst)(styles);
|
|
179
|
-
|
|
224
|
+
themedStylesAst.properties.forEach(_ => {
|
|
180
225
|
const prop = _;
|
|
181
226
|
if (prop.value.type === "StringLiteral") {
|
|
182
|
-
const propVal = prop.value.value.slice(1)
|
|
183
|
-
|
|
227
|
+
const propVal = prop.value.value.slice(1);
|
|
228
|
+
const isComputed = !t.isValidIdentifier(propVal);
|
|
184
229
|
prop.value = t.callExpression(t.memberExpression(t.memberExpression(t.identifier("theme"), isComputed ? t.stringLiteral(propVal) : t.identifier(propVal), isComputed), t.identifier("get")), []);
|
|
185
230
|
}
|
|
186
|
-
})
|
|
231
|
+
});
|
|
232
|
+
return themedStylesAst;
|
|
187
233
|
}
|
|
188
|
-
let hasDynamicStyle =
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
234
|
+
let hasDynamicStyle = false;
|
|
235
|
+
let hasMediaKeys = false;
|
|
236
|
+
for (const attr of props.attrs) {
|
|
237
|
+
switch (attr.type) {
|
|
238
|
+
case "style":
|
|
239
|
+
{
|
|
240
|
+
let styleExpr = getStyleExpression(attr.value);
|
|
241
|
+
addStyleExpression(styleExpr);
|
|
242
|
+
addStyleExpression(styleExpr, true);
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
245
|
+
case "ternary":
|
|
246
|
+
{
|
|
247
|
+
const {
|
|
199
248
|
consequent,
|
|
200
249
|
alternate
|
|
201
|
-
} = attr.value
|
|
202
|
-
consExpr = getStyleExpression(consequent)
|
|
203
|
-
altExpr = getStyleExpression(alternate);
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
250
|
+
} = attr.value;
|
|
251
|
+
const consExpr = getStyleExpression(consequent, true);
|
|
252
|
+
const altExpr = getStyleExpression(alternate, true);
|
|
253
|
+
if (attr.value.inlineMediaQuery) {
|
|
254
|
+
hasMediaKeys = true;
|
|
255
|
+
}
|
|
256
|
+
expressions.push(attr.value.test);
|
|
257
|
+
addStyleExpression(t.conditionalExpression(t.identifier(`_expressions[${expressions.length - 1}]`), consExpr || t.nullLiteral(), altExpr || t.nullLiteral()), true);
|
|
258
|
+
const styleExpr = t.conditionalExpression(attr.value.test, consExpr || t.nullLiteral(), altExpr || t.nullLiteral());
|
|
259
|
+
addStyleExpression(styleExpr);
|
|
260
|
+
break;
|
|
261
|
+
}
|
|
262
|
+
case "attr":
|
|
263
|
+
{
|
|
264
|
+
if (t.isJSXSpreadAttribute(attr.value)) {
|
|
265
|
+
if ((0, import_extractHelpers.isSimpleSpread)(attr.value)) {
|
|
266
|
+
stylesExpr.elements.push(t.memberExpression(attr.value.argument, t.identifier("style")));
|
|
267
|
+
hocStylesExpr.elements.push(t.memberExpression(attr.value.argument, t.identifier("style")));
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
finalAttrs.push(attr.value);
|
|
271
|
+
break;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
props.node.attributes = finalAttrs;
|
|
276
|
+
if (themeKeysUsed.size || hocStylesExpr.elements.length > 1 || hasDynamicStyle) {
|
|
277
|
+
if (!hasImportedViewWrapper) {
|
|
278
|
+
root.unshiftContainer("body", importWithStyle);
|
|
279
|
+
hasImportedViewWrapper = true;
|
|
280
|
+
}
|
|
281
|
+
const name = props.flatNodeName || props.node.name["name"];
|
|
282
|
+
const wrapperName = `_${name.replace(/^_+/, "")}Styled${wrapperCount++}`;
|
|
283
|
+
const WrapperIdentifier = t.identifier(wrapperName);
|
|
284
|
+
const WrapperJSXIdentifier = t.jsxIdentifier(wrapperName);
|
|
285
|
+
const hasThemeKeysFlag = themeKeysUsed.size > 0;
|
|
286
|
+
root.pushContainer("body", t.variableDeclaration("const", [t.variableDeclarator(WrapperIdentifier, t.callExpression(t.identifier("_withStableStyle"), [t.identifier(name), t.arrowFunctionExpression([t.identifier("theme"), t.identifier("_expressions")],
|
|
287
|
+
// return styles directly - no useMemo, theme changes must trigger style recalc
|
|
288
|
+
t.arrayExpression([...hocStylesExpr.elements])), t.booleanLiteral(hasThemeKeysFlag), t.booleanLiteral(hasMediaKeys)]))]));
|
|
289
|
+
props.node.name = WrapperJSXIdentifier;
|
|
290
|
+
props.jsxPath.node.openingElement.name = WrapperJSXIdentifier;
|
|
291
|
+
if (props.jsxPath.node.closingElement) {
|
|
292
|
+
props.jsxPath.node.closingElement.name = t.jsxIdentifier(wrapperName);
|
|
293
|
+
}
|
|
294
|
+
if (expressions.length) {
|
|
295
|
+
const safeExpressions = expressions.map(expr => t.isStringLiteral(expr) ? expr : t.unaryExpression("!", t.unaryExpression("!", expr)));
|
|
296
|
+
props.node.attributes.push(t.jsxAttribute(t.jsxIdentifier("_expressions"), t.jsxExpressionContainer(t.arrayExpression(safeExpressions))));
|
|
297
|
+
}
|
|
298
|
+
} else {
|
|
299
|
+
props.node.attributes.push(t.jsxAttribute(t.jsxIdentifier("style"), t.jsxExpressionContainer(stylesExpr.elements.length === 1 ? stylesExpr.elements[0] : stylesExpr)));
|
|
214
300
|
}
|
|
215
|
-
if (props.node.attributes = finalAttrs, themeKeysUsed.size || hocStylesExpr.elements.length > 1 || hasDynamicStyle) {
|
|
216
|
-
hasImportedViewWrapper || (root.unshiftContainer("body", importWithStyle), root.unshiftContainer("body", importReactUseMemo()), hasImportedViewWrapper = !0);
|
|
217
|
-
const name = props.flatNodeName || props.node.name.name,
|
|
218
|
-
wrapperName = `_${name.replace(/^_+/, "")}Styled${wrapperCount++}`,
|
|
219
|
-
WrapperIdentifier = t.identifier(wrapperName),
|
|
220
|
-
WrapperJSXIdentifier = t.jsxIdentifier(wrapperName);
|
|
221
|
-
root.pushContainer("body", t.variableDeclaration("const", [t.variableDeclarator(WrapperIdentifier, t.callExpression(t.identifier("__withStableStyle"), [t.identifier(name), t.arrowFunctionExpression([t.identifier("theme"), t.identifier("_expressions")], t.blockStatement([t.returnStatement(t.callExpression(t.identifier("__ReactUseMemo"), [t.arrowFunctionExpression([], t.blockStatement([t.returnStatement(t.arrayExpression([...hocStylesExpr.elements]))])), t.identifier("_expressions")]))]))]))])), props.node.name = WrapperJSXIdentifier, props.jsxPath.node.openingElement.name = WrapperJSXIdentifier, props.jsxPath.node.closingElement && (props.jsxPath.node.closingElement.name = t.jsxIdentifier(wrapperName)), expressions.length && props.node.attributes.push(t.jsxAttribute(t.jsxIdentifier("_expressions"), t.jsxExpressionContainer(t.arrayExpression(expressions))));
|
|
222
|
-
} else props.node.attributes.push(t.jsxAttribute(t.jsxIdentifier("style"), t.jsxExpressionContainer(stylesExpr.elements.length === 1 ? stylesExpr.elements[0] : stylesExpr)));
|
|
223
301
|
}
|
|
224
302
|
});
|
|
225
303
|
} catch (err) {
|
|
226
304
|
if (err instanceof Error) {
|
|
227
305
|
let message = `${shouldPrintDebug === "verbose" ? err : err.message}`;
|
|
228
|
-
message.includes("Unexpected return value from visitor method")
|
|
306
|
+
if (message.includes("Unexpected return value from visitor method")) {
|
|
307
|
+
message = "Unexpected return value from visitor method";
|
|
308
|
+
}
|
|
309
|
+
console.warn("Error in Tamagui parse, skipping", message, err.stack);
|
|
229
310
|
return;
|
|
230
311
|
}
|
|
231
312
|
}
|
|
232
313
|
if (!Object.keys(sheetStyles).length) {
|
|
233
|
-
|
|
314
|
+
if (shouldPrintDebug) {
|
|
315
|
+
console.info("END no styles");
|
|
316
|
+
}
|
|
317
|
+
if (res) printLog(res);
|
|
234
318
|
return;
|
|
235
319
|
}
|
|
236
|
-
const sheetObject = (0, import_literalToAst.literalToAst)(sheetStyles)
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
sheetOuter.declarations[0].init.arguments[0] = sheetObject
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
320
|
+
const sheetObject = (0, import_literalToAst.literalToAst)(sheetStyles);
|
|
321
|
+
const sheetOuter = (0, import_template.default)("const SHEET = __ReactNativeStyleSheet.create(null)")({
|
|
322
|
+
SHEET: sheetIdentifier.name
|
|
323
|
+
});
|
|
324
|
+
sheetOuter.declarations[0].init.arguments[0] = sheetObject;
|
|
325
|
+
root.unshiftContainer("body", sheetOuter);
|
|
326
|
+
root.unshiftContainer("body", importStyleSheet());
|
|
327
|
+
if (shouldPrintDebug) {
|
|
328
|
+
console.info("\n -------- output code ------- \n");
|
|
329
|
+
console.info((0, import_generator.default)(root.parent).code.split("\n").filter(x => !x.startsWith("//")).join("\n"));
|
|
330
|
+
}
|
|
331
|
+
if (res) printLog(res);
|
|
245
332
|
}
|
|
246
333
|
}
|
|
247
334
|
}
|
|
248
335
|
};
|
|
249
336
|
}
|
|
250
337
|
function assertValidTag(node) {
|
|
251
|
-
node.attributes.find(x => x.type === "JSXAttribute" && x.name.name === "style")
|
|
338
|
+
if (node.attributes.find(x => x.type === "JSXAttribute" && x.name.name === "style")) {
|
|
339
|
+
if (process.env.DEBUG?.startsWith("tamagui")) {
|
|
340
|
+
console.warn("\u26A0\uFE0F Cannot pass style attribute to extracted style");
|
|
341
|
+
}
|
|
342
|
+
}
|
|
252
343
|
}
|
|
253
344
|
function splitThemeStyles(style) {
|
|
254
|
-
const themed = {}
|
|
255
|
-
|
|
256
|
-
let noTheme =
|
|
345
|
+
const themed = {};
|
|
346
|
+
const plain = {};
|
|
347
|
+
let noTheme = true;
|
|
257
348
|
for (const key in style) {
|
|
258
349
|
const val = style[key];
|
|
259
|
-
val && val[0] === "$"
|
|
350
|
+
if (val && val[0] === "$") {
|
|
351
|
+
themed[key] = val;
|
|
352
|
+
noTheme = false;
|
|
353
|
+
} else {
|
|
354
|
+
plain[key] = val;
|
|
355
|
+
}
|
|
260
356
|
}
|
|
261
357
|
return {
|
|
262
358
|
themed: noTheme ? null : themed,
|
|
@@ -3,20 +3,22 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
5
|
var __export = (target, all) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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, {
|
|
13
14
|
get: () => from[key],
|
|
14
15
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
16
|
});
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
18
20
|
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
19
|
-
value:
|
|
21
|
+
value: true
|
|
20
22
|
}), mod);
|
|
21
23
|
var findTopmostFunction_exports = {};
|
|
22
24
|
__export(findTopmostFunction_exports, {
|
|
@@ -26,9 +28,16 @@ module.exports = __toCommonJS(findTopmostFunction_exports);
|
|
|
26
28
|
function findTopmostFunction(jsxPath) {
|
|
27
29
|
const isFunction = path => path.isArrowFunctionExpression() || path.isFunctionDeclaration() || path.isFunctionExpression();
|
|
28
30
|
let compFn = jsxPath.findParent(isFunction);
|
|
29
|
-
|
|
31
|
+
while (compFn) {
|
|
30
32
|
const parent = compFn.findParent(isFunction);
|
|
31
|
-
if (parent)
|
|
33
|
+
if (parent) {
|
|
34
|
+
compFn = parent;
|
|
35
|
+
} else {
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (!compFn) {
|
|
40
|
+
return null;
|
|
32
41
|
}
|
|
33
|
-
return compFn
|
|
42
|
+
return compFn;
|
|
34
43
|
}
|