@tamagui/static 1.14.1 → 1.14.3
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/constants.js +52 -1
- package/dist/cjs/constants.js.map +2 -2
- package/dist/cjs/extractor/accessSafe.js +52 -1
- package/dist/cjs/extractor/accessSafe.js.map +2 -2
- package/dist/cjs/extractor/babelParse.js +66 -1
- package/dist/cjs/extractor/babelParse.js.map +2 -2
- package/dist/cjs/extractor/buildClassName.js +99 -1
- package/dist/cjs/extractor/buildClassName.js.map +2 -2
- package/dist/cjs/extractor/bundle.js +126 -1
- package/dist/cjs/extractor/bundle.js.map +2 -2
- package/dist/cjs/extractor/createEvaluator.js +86 -1
- package/dist/cjs/extractor/createEvaluator.js.map +2 -2
- package/dist/cjs/extractor/createExtractor.js +1630 -15
- package/dist/cjs/extractor/createExtractor.js.map +2 -2
- package/dist/cjs/extractor/ensureImportingConcat.js +64 -1
- package/dist/cjs/extractor/ensureImportingConcat.js.map +2 -2
- package/dist/cjs/extractor/evaluateAstNode.js +130 -1
- package/dist/cjs/extractor/evaluateAstNode.js.map +2 -2
- package/dist/cjs/extractor/extractHelpers.js +207 -1
- package/dist/cjs/extractor/extractHelpers.js.map +2 -2
- package/dist/cjs/extractor/extractMediaStyle.js +193 -1
- package/dist/cjs/extractor/extractMediaStyle.js.map +2 -2
- package/dist/cjs/extractor/extractToClassNames.js +413 -13
- package/dist/cjs/extractor/extractToClassNames.js.map +2 -2
- package/dist/cjs/extractor/findTopmostFunction.js +43 -1
- package/dist/cjs/extractor/findTopmostFunction.js.map +2 -2
- package/dist/cjs/extractor/generatedUid.js +59 -1
- package/dist/cjs/extractor/generatedUid.js.map +2 -2
- package/dist/cjs/extractor/getPrefixLogs.js +31 -1
- package/dist/cjs/extractor/getPrefixLogs.js.map +2 -2
- package/dist/cjs/extractor/getPropValueFromAttributes.js +89 -1
- package/dist/cjs/extractor/getPropValueFromAttributes.js.map +2 -2
- package/dist/cjs/extractor/getSourceModule.js +103 -1
- package/dist/cjs/extractor/getSourceModule.js.map +2 -2
- package/dist/cjs/extractor/getStaticBindingsForScope.js +225 -1
- package/dist/cjs/extractor/getStaticBindingsForScope.js.map +2 -2
- package/dist/cjs/extractor/hoistClassNames.js +74 -1
- package/dist/cjs/extractor/hoistClassNames.js.map +2 -2
- package/dist/cjs/extractor/literalToAst.js +115 -1
- package/dist/cjs/extractor/literalToAst.js.map +2 -2
- package/dist/cjs/extractor/loadFile.js +20 -2
- package/dist/cjs/extractor/loadFile.js.map +2 -2
- package/dist/cjs/extractor/loadTamagui.js +432 -15
- package/dist/cjs/extractor/loadTamagui.js.map +2 -2
- package/dist/cjs/extractor/logLines.js +43 -3
- package/dist/cjs/extractor/logLines.js.map +2 -2
- package/dist/cjs/extractor/normalizeTernaries.js +85 -1
- package/dist/cjs/extractor/normalizeTernaries.js.map +2 -2
- package/dist/cjs/extractor/removeUnusedHooks.js +109 -1
- package/dist/cjs/extractor/removeUnusedHooks.js.map +2 -2
- package/dist/cjs/extractor/timer.js +52 -1
- package/dist/cjs/extractor/timer.js.map +2 -2
- package/dist/cjs/extractor/validHTMLAttributes.js +126 -1
- package/dist/cjs/extractor/validHTMLAttributes.js.map +2 -2
- package/dist/cjs/getPragmaOptions.js +67 -2
- package/dist/cjs/getPragmaOptions.js.map +2 -2
- package/dist/cjs/helpers/memoize.js +45 -1
- package/dist/cjs/helpers/memoize.js.map +2 -2
- package/dist/cjs/index.js +42 -1
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/require.js +81 -5
- package/dist/cjs/require.js.map +2 -2
- package/dist/cjs/types.js +16 -1
- package/dist/cjs/types.js.map +2 -2
- package/dist/cjs/webpackPlugin.js +34 -1
- package/dist/cjs/webpackPlugin.js.map +2 -2
- package/dist/esm/constants.js +14 -1
- package/dist/esm/constants.js.map +2 -2
- package/dist/esm/constants.mjs +14 -1
- package/dist/esm/constants.mjs.map +2 -2
- package/dist/esm/extractor/accessSafe.js +18 -1
- package/dist/esm/extractor/accessSafe.js.map +2 -2
- package/dist/esm/extractor/accessSafe.mjs +18 -1
- package/dist/esm/extractor/accessSafe.mjs.map +2 -2
- package/dist/esm/extractor/babelParse.js +31 -1
- package/dist/esm/extractor/babelParse.js.map +2 -2
- package/dist/esm/extractor/babelParse.mjs +31 -1
- package/dist/esm/extractor/babelParse.mjs.map +2 -2
- package/dist/esm/extractor/buildClassName.js +64 -1
- package/dist/esm/extractor/buildClassName.js.map +2 -2
- package/dist/esm/extractor/buildClassName.mjs +64 -1
- package/dist/esm/extractor/buildClassName.mjs.map +2 -2
- package/dist/esm/extractor/bundle.js +91 -1
- package/dist/esm/extractor/bundle.js.map +2 -2
- package/dist/esm/extractor/bundle.mjs +91 -1
- package/dist/esm/extractor/bundle.mjs.map +2 -2
- package/dist/esm/extractor/createEvaluator.js +51 -1
- package/dist/esm/extractor/createEvaluator.js.map +2 -2
- package/dist/esm/extractor/createEvaluator.mjs +51 -1
- package/dist/esm/extractor/createEvaluator.mjs.map +2 -2
- package/dist/esm/extractor/createExtractor.js +1613 -15
- package/dist/esm/extractor/createExtractor.js.map +2 -2
- package/dist/esm/extractor/createExtractor.mjs +1613 -15
- package/dist/esm/extractor/createExtractor.mjs.map +2 -2
- package/dist/esm/extractor/ensureImportingConcat.js +30 -1
- package/dist/esm/extractor/ensureImportingConcat.js.map +2 -2
- package/dist/esm/extractor/ensureImportingConcat.mjs +30 -1
- package/dist/esm/extractor/ensureImportingConcat.mjs.map +2 -2
- package/dist/esm/extractor/evaluateAstNode.js +96 -1
- package/dist/esm/extractor/evaluateAstNode.js.map +2 -2
- package/dist/esm/extractor/evaluateAstNode.mjs +96 -1
- package/dist/esm/extractor/evaluateAstNode.mjs.map +2 -2
- package/dist/esm/extractor/extractHelpers.js +161 -1
- package/dist/esm/extractor/extractHelpers.js.map +2 -2
- package/dist/esm/extractor/extractHelpers.mjs +161 -1
- package/dist/esm/extractor/extractHelpers.mjs.map +2 -2
- package/dist/esm/extractor/extractMediaStyle.js +158 -1
- package/dist/esm/extractor/extractMediaStyle.js.map +2 -2
- package/dist/esm/extractor/extractMediaStyle.mjs +158 -1
- package/dist/esm/extractor/extractMediaStyle.mjs.map +2 -2
- package/dist/esm/extractor/extractToClassNames.js +379 -13
- package/dist/esm/extractor/extractToClassNames.js.map +2 -2
- package/dist/esm/extractor/extractToClassNames.mjs +379 -13
- package/dist/esm/extractor/extractToClassNames.mjs.map +2 -2
- package/dist/esm/extractor/findTopmostFunction.js +19 -1
- package/dist/esm/extractor/findTopmostFunction.js.map +2 -2
- package/dist/esm/extractor/findTopmostFunction.mjs +19 -1
- package/dist/esm/extractor/findTopmostFunction.mjs.map +2 -2
- package/dist/esm/extractor/generatedUid.js +25 -1
- package/dist/esm/extractor/generatedUid.js.map +2 -2
- package/dist/esm/extractor/generatedUid.mjs +25 -1
- package/dist/esm/extractor/generatedUid.mjs.map +2 -2
- package/dist/esm/extractor/getPrefixLogs.js +7 -1
- package/dist/esm/extractor/getPrefixLogs.js.map +2 -2
- package/dist/esm/extractor/getPrefixLogs.mjs +7 -1
- package/dist/esm/extractor/getPrefixLogs.mjs.map +2 -2
- package/dist/esm/extractor/getPropValueFromAttributes.js +55 -1
- package/dist/esm/extractor/getPropValueFromAttributes.js.map +2 -2
- package/dist/esm/extractor/getPropValueFromAttributes.mjs +55 -1
- package/dist/esm/extractor/getPropValueFromAttributes.mjs.map +2 -2
- package/dist/esm/extractor/getSourceModule.js +69 -1
- package/dist/esm/extractor/getSourceModule.js.map +2 -2
- package/dist/esm/extractor/getSourceModule.mjs +69 -1
- package/dist/esm/extractor/getSourceModule.mjs.map +2 -2
- package/dist/esm/extractor/getStaticBindingsForScope.js +190 -1
- package/dist/esm/extractor/getStaticBindingsForScope.js.map +2 -2
- package/dist/esm/extractor/getStaticBindingsForScope.mjs +190 -1
- package/dist/esm/extractor/getStaticBindingsForScope.mjs.map +2 -2
- package/dist/esm/extractor/hoistClassNames.js +40 -1
- package/dist/esm/extractor/hoistClassNames.js.map +2 -2
- package/dist/esm/extractor/hoistClassNames.mjs +40 -1
- package/dist/esm/extractor/hoistClassNames.mjs.map +2 -2
- package/dist/esm/extractor/literalToAst.js +80 -1
- package/dist/esm/extractor/literalToAst.js.map +2 -2
- package/dist/esm/extractor/literalToAst.mjs +80 -1
- package/dist/esm/extractor/literalToAst.mjs.map +2 -2
- package/dist/esm/extractor/loadFile.js +19 -2
- package/dist/esm/extractor/loadFile.js.map +2 -2
- package/dist/esm/extractor/loadFile.mjs +19 -2
- package/dist/esm/extractor/loadFile.mjs.map +2 -2
- package/dist/esm/extractor/loadTamagui.js +396 -15
- package/dist/esm/extractor/loadTamagui.js.map +2 -2
- package/dist/esm/extractor/loadTamagui.mjs +396 -15
- package/dist/esm/extractor/loadTamagui.mjs.map +2 -2
- package/dist/esm/extractor/logLines.js +19 -3
- package/dist/esm/extractor/logLines.js.map +2 -2
- package/dist/esm/extractor/logLines.mjs +19 -3
- package/dist/esm/extractor/logLines.mjs.map +2 -2
- package/dist/esm/extractor/normalizeTernaries.js +51 -1
- package/dist/esm/extractor/normalizeTernaries.js.map +2 -2
- package/dist/esm/extractor/normalizeTernaries.mjs +51 -1
- package/dist/esm/extractor/normalizeTernaries.mjs.map +2 -2
- package/dist/esm/extractor/removeUnusedHooks.js +75 -1
- package/dist/esm/extractor/removeUnusedHooks.js.map +2 -2
- package/dist/esm/extractor/removeUnusedHooks.mjs +75 -1
- package/dist/esm/extractor/removeUnusedHooks.mjs.map +2 -2
- package/dist/esm/extractor/timer.js +28 -1
- package/dist/esm/extractor/timer.js.map +2 -2
- package/dist/esm/extractor/timer.mjs +28 -1
- package/dist/esm/extractor/timer.mjs.map +2 -2
- package/dist/esm/extractor/validHTMLAttributes.js +101 -1
- package/dist/esm/extractor/validHTMLAttributes.js.map +2 -2
- package/dist/esm/extractor/validHTMLAttributes.mjs +101 -1
- package/dist/esm/extractor/validHTMLAttributes.mjs.map +2 -2
- package/dist/esm/getPragmaOptions.js +43 -2
- package/dist/esm/getPragmaOptions.js.map +2 -2
- package/dist/esm/getPragmaOptions.mjs +43 -2
- package/dist/esm/getPragmaOptions.mjs.map +2 -2
- package/dist/esm/helpers/memoize.js +21 -1
- package/dist/esm/helpers/memoize.js.map +2 -2
- package/dist/esm/helpers/memoize.mjs +21 -1
- package/dist/esm/helpers/memoize.mjs.map +2 -2
- package/dist/esm/index.js +15 -1
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/index.mjs +15 -1
- package/dist/esm/index.mjs.map +2 -2
- package/dist/esm/require.js +55 -5
- package/dist/esm/require.js.map +2 -2
- package/dist/esm/require.mjs +55 -5
- package/dist/esm/require.mjs.map +2 -2
- package/dist/esm/webpackPlugin.js +10 -1
- package/dist/esm/webpackPlugin.js.map +2 -2
- package/dist/esm/webpackPlugin.mjs +10 -1
- package/dist/esm/webpackPlugin.mjs.map +2 -2
- package/package.json +14 -14
|
@@ -1,15 +1,415 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var extractToClassNames_exports = {};
|
|
30
|
+
__export(extractToClassNames_exports, {
|
|
31
|
+
extractToClassNames: () => extractToClassNames
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(extractToClassNames_exports);
|
|
34
|
+
var path = __toESM(require("path"));
|
|
35
|
+
var import_path = require("path");
|
|
36
|
+
var util = __toESM(require("util"));
|
|
37
|
+
var import_generator = __toESM(require("@babel/generator"));
|
|
38
|
+
var t = __toESM(require("@babel/types"));
|
|
39
|
+
var import_core_node = require("@tamagui/core-node");
|
|
40
|
+
var import_helpers = require("@tamagui/helpers");
|
|
41
|
+
var import_babelParse = require("./babelParse.js");
|
|
42
|
+
var import_buildClassName = require("./buildClassName.js");
|
|
43
|
+
var import_ensureImportingConcat = require("./ensureImportingConcat.js");
|
|
44
|
+
var import_extractHelpers = require("./extractHelpers.js");
|
|
45
|
+
var import_extractMediaStyle = require("./extractMediaStyle.js");
|
|
46
|
+
var import_getPrefixLogs = require("./getPrefixLogs.js");
|
|
47
|
+
var import_hoistClassNames = require("./hoistClassNames.js");
|
|
48
|
+
var import_logLines = require("./logLines.js");
|
|
49
|
+
var import_timer = require("./timer.js");
|
|
50
|
+
const mergeStyleGroups = {
|
|
51
|
+
shadowOpacity: true,
|
|
52
|
+
shadowRadius: true,
|
|
53
|
+
shadowColor: true,
|
|
54
|
+
shadowOffset: true
|
|
55
|
+
};
|
|
56
|
+
async function extractToClassNames({
|
|
57
|
+
extractor,
|
|
58
|
+
source,
|
|
59
|
+
sourcePath,
|
|
60
|
+
options,
|
|
61
|
+
shouldPrintDebug
|
|
62
|
+
}) {
|
|
63
|
+
const tm = (0, import_timer.timer)();
|
|
64
|
+
if (shouldPrintDebug) {
|
|
65
|
+
console.log(`--- ${sourcePath} ---
|
|
2
66
|
|
|
3
|
-
`)
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
`)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
67
|
+
`);
|
|
68
|
+
}
|
|
69
|
+
if (typeof source !== "string") {
|
|
70
|
+
throw new Error("`source` must be a string of javascript");
|
|
71
|
+
}
|
|
72
|
+
if (sourcePath && !path.isAbsolute(sourcePath)) {
|
|
73
|
+
throw new Error("`sourcePath` must be an absolute path to a .js file");
|
|
74
|
+
}
|
|
75
|
+
if (!/.[tj]sx?$/i.test(sourcePath || "")) {
|
|
76
|
+
console.log(`${sourcePath == null ? void 0 : sourcePath.slice(0, 100)} - bad filename.`);
|
|
77
|
+
}
|
|
78
|
+
await extractor.loadTamagui(options);
|
|
79
|
+
const shouldLogTiming = options.logTimings ?? true;
|
|
80
|
+
const start = Date.now();
|
|
81
|
+
const mem = shouldLogTiming ? process.memoryUsage() : null;
|
|
82
|
+
let ast;
|
|
83
|
+
try {
|
|
84
|
+
ast = (0, import_babelParse.babelParse)(source);
|
|
85
|
+
} catch (err) {
|
|
86
|
+
console.error("babel parse error:", sourcePath == null ? void 0 : sourcePath.slice(0, 100));
|
|
87
|
+
throw err;
|
|
88
|
+
}
|
|
89
|
+
tm.mark(`babel-parse`, shouldPrintDebug === "verbose");
|
|
90
|
+
const cssMap = /* @__PURE__ */ new Map();
|
|
91
|
+
const existingHoists = {};
|
|
92
|
+
let hasFlattened = false;
|
|
93
|
+
const res = await extractor.parse(ast, {
|
|
94
|
+
shouldPrintDebug,
|
|
95
|
+
...options,
|
|
96
|
+
sourcePath,
|
|
97
|
+
target: "html",
|
|
98
|
+
extractStyledDefinitions: true,
|
|
99
|
+
onStyleRule(identifier, rules) {
|
|
100
|
+
const css = rules.join(";");
|
|
101
|
+
if (shouldPrintDebug) {
|
|
102
|
+
console.log(`adding styled() rule: .${identifier} ${css}`);
|
|
103
|
+
}
|
|
104
|
+
cssMap.set(`.${identifier}`, { css, commentTexts: [] });
|
|
105
|
+
},
|
|
106
|
+
getFlattenedNode: ({ tag }) => {
|
|
107
|
+
hasFlattened = true;
|
|
108
|
+
return tag;
|
|
109
|
+
},
|
|
110
|
+
onExtractTag: ({
|
|
111
|
+
parserProps,
|
|
112
|
+
attrs,
|
|
113
|
+
node,
|
|
114
|
+
attemptEval,
|
|
115
|
+
jsxPath,
|
|
116
|
+
originalNodeName,
|
|
117
|
+
filePath,
|
|
118
|
+
lineNumbers,
|
|
119
|
+
programPath,
|
|
120
|
+
isFlattened,
|
|
121
|
+
completeProps,
|
|
122
|
+
staticConfig
|
|
123
|
+
}) => {
|
|
124
|
+
var _a;
|
|
125
|
+
if (staticConfig.acceptsClassName === false) {
|
|
126
|
+
if (shouldPrintDebug) {
|
|
127
|
+
console.log(`bail, acceptsClassName is false`);
|
|
128
|
+
}
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const didFlattenThisTag = hasFlattened;
|
|
132
|
+
hasFlattened = false;
|
|
133
|
+
let finalClassNames = [];
|
|
134
|
+
const finalAttrs = [];
|
|
135
|
+
let finalStyles = [];
|
|
136
|
+
let viewStyles = {};
|
|
137
|
+
for (const attr of attrs) {
|
|
138
|
+
if (attr.type === "style") {
|
|
139
|
+
viewStyles = {
|
|
140
|
+
...viewStyles,
|
|
141
|
+
...attr.value
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const ensureNeededPrevStyle = (style) => {
|
|
146
|
+
const keys = Object.keys(style);
|
|
147
|
+
if (!keys.some((key) => mergeStyleGroups[key])) {
|
|
148
|
+
return style;
|
|
149
|
+
}
|
|
150
|
+
for (const k in mergeStyleGroups) {
|
|
151
|
+
if (k in viewStyles) {
|
|
152
|
+
style[k] = style[k] ?? viewStyles[k];
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return style;
|
|
156
|
+
};
|
|
157
|
+
const addStyles = (style) => {
|
|
158
|
+
if (!style)
|
|
159
|
+
return [];
|
|
160
|
+
const styleWithPrev = ensureNeededPrevStyle(style);
|
|
161
|
+
const res2 = (0, import_core_node.getStylesAtomic)(styleWithPrev);
|
|
162
|
+
if (res2.length) {
|
|
163
|
+
finalStyles = [...finalStyles, ...res2];
|
|
164
|
+
}
|
|
165
|
+
return res2;
|
|
166
|
+
};
|
|
167
|
+
let lastMediaImportance = 1;
|
|
168
|
+
for (const attr of attrs) {
|
|
169
|
+
switch (attr.type) {
|
|
170
|
+
case "style": {
|
|
171
|
+
if (!isFlattened) {
|
|
172
|
+
const styles2 = (0, import_core_node.getStylesAtomic)(attr.value);
|
|
173
|
+
finalStyles = [...finalStyles, ...styles2];
|
|
174
|
+
for (const style of styles2) {
|
|
175
|
+
const prop = style.pseudo ? `${style.property}-${style.pseudo}` : style.property;
|
|
176
|
+
finalAttrs.push(
|
|
177
|
+
t.jsxAttribute(t.jsxIdentifier(prop), t.stringLiteral(style.identifier))
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
} else {
|
|
181
|
+
const styles2 = addStyles(attr.value);
|
|
182
|
+
const newClassNames = (0, import_helpers.concatClassName)(
|
|
183
|
+
styles2.map((x) => x.identifier).join(" ")
|
|
184
|
+
);
|
|
185
|
+
const existing = finalClassNames.find(
|
|
186
|
+
(x) => x.type == "StringLiteral"
|
|
187
|
+
);
|
|
188
|
+
if (existing) {
|
|
189
|
+
existing.value = `${existing.value} ${newClassNames}`;
|
|
190
|
+
} else {
|
|
191
|
+
finalClassNames = [...finalClassNames, t.stringLiteral(newClassNames)];
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
case "attr": {
|
|
197
|
+
const val = attr.value;
|
|
198
|
+
if (t.isJSXSpreadAttribute(val)) {
|
|
199
|
+
if ((0, import_extractHelpers.isSimpleSpread)(val)) {
|
|
200
|
+
finalClassNames.push(
|
|
201
|
+
t.logicalExpression(
|
|
202
|
+
"&&",
|
|
203
|
+
val.argument,
|
|
204
|
+
t.memberExpression(val.argument, t.identifier("className"))
|
|
205
|
+
)
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
} else if (val.name.name === "className") {
|
|
209
|
+
const value = val.value;
|
|
210
|
+
if (value) {
|
|
211
|
+
try {
|
|
212
|
+
const evaluatedValue = attemptEval(value);
|
|
213
|
+
finalClassNames.push(t.stringLiteral(evaluatedValue));
|
|
214
|
+
} catch (e) {
|
|
215
|
+
finalClassNames.push(value["expression"]);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
finalAttrs.push(val);
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
223
|
+
case "ternary": {
|
|
224
|
+
const mediaExtraction = (0, import_extractMediaStyle.extractMediaStyle)(
|
|
225
|
+
parserProps,
|
|
226
|
+
attr.value,
|
|
227
|
+
jsxPath,
|
|
228
|
+
extractor.getTamagui(),
|
|
229
|
+
sourcePath || "",
|
|
230
|
+
lastMediaImportance,
|
|
231
|
+
shouldPrintDebug
|
|
232
|
+
);
|
|
233
|
+
if (shouldPrintDebug) {
|
|
234
|
+
if (mediaExtraction) {
|
|
235
|
+
console.log(
|
|
236
|
+
"ternary (mediaStyles)",
|
|
237
|
+
((_a = mediaExtraction.ternaryWithoutMedia) == null ? void 0 : _a.inlineMediaQuery) ?? "",
|
|
238
|
+
mediaExtraction.mediaStyles.map((x) => x.identifier).join(".")
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
if (!mediaExtraction) {
|
|
243
|
+
addTernaryStyle(
|
|
244
|
+
attr.value,
|
|
245
|
+
addStyles(attr.value.consequent),
|
|
246
|
+
addStyles(attr.value.alternate)
|
|
247
|
+
);
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
lastMediaImportance++;
|
|
251
|
+
if (mediaExtraction.mediaStyles) {
|
|
252
|
+
finalStyles = [...finalStyles, ...mediaExtraction.mediaStyles];
|
|
253
|
+
}
|
|
254
|
+
if (mediaExtraction.ternaryWithoutMedia) {
|
|
255
|
+
addTernaryStyle(
|
|
256
|
+
mediaExtraction.ternaryWithoutMedia,
|
|
257
|
+
mediaExtraction.mediaStyles,
|
|
258
|
+
[]
|
|
259
|
+
);
|
|
260
|
+
} else {
|
|
261
|
+
finalClassNames = [
|
|
262
|
+
...finalClassNames,
|
|
263
|
+
...mediaExtraction.mediaStyles.map((x) => t.stringLiteral(x.identifier))
|
|
264
|
+
];
|
|
265
|
+
}
|
|
266
|
+
break;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
function addTernaryStyle(ternary, a, b) {
|
|
271
|
+
const cCN = a.map((x) => x.identifier).join(" ");
|
|
272
|
+
const aCN = b.map((x) => x.identifier).join(" ");
|
|
273
|
+
if (a.length && b.length) {
|
|
274
|
+
finalClassNames.push(
|
|
275
|
+
t.conditionalExpression(
|
|
276
|
+
ternary.test,
|
|
277
|
+
t.stringLiteral(cCN),
|
|
278
|
+
t.stringLiteral(aCN)
|
|
279
|
+
)
|
|
280
|
+
);
|
|
281
|
+
} else {
|
|
282
|
+
finalClassNames.push(
|
|
283
|
+
t.conditionalExpression(
|
|
284
|
+
ternary.test,
|
|
285
|
+
t.stringLiteral(" " + cCN),
|
|
286
|
+
t.stringLiteral(" " + aCN)
|
|
287
|
+
)
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
if (shouldPrintDebug) {
|
|
292
|
+
console.log(
|
|
293
|
+
" finalClassNames\n",
|
|
294
|
+
(0, import_logLines.logLines)(finalClassNames.map((x) => x["value"]).join(" "))
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
node.attributes = finalAttrs;
|
|
298
|
+
if (finalClassNames.length) {
|
|
299
|
+
const extraClassNames = (() => {
|
|
300
|
+
let value = "";
|
|
301
|
+
if (!isFlattened) {
|
|
302
|
+
return value;
|
|
303
|
+
}
|
|
304
|
+
if (process.env.TAMAGUI_DEBUG_OPTIMIZATIONS) {
|
|
305
|
+
value += `is_tamagui_flattened`;
|
|
306
|
+
}
|
|
307
|
+
if (staticConfig.componentName) {
|
|
308
|
+
value += ` is_${staticConfig.componentName}`;
|
|
309
|
+
}
|
|
310
|
+
if (staticConfig.isText) {
|
|
311
|
+
let family = completeProps.fontFamily;
|
|
312
|
+
if (family[0] === "$") {
|
|
313
|
+
family = family.slice(1);
|
|
314
|
+
}
|
|
315
|
+
value += ` font_${family}`;
|
|
316
|
+
}
|
|
317
|
+
return value;
|
|
318
|
+
})();
|
|
319
|
+
const names = (0, import_buildClassName.buildClassName)(finalClassNames, extraClassNames);
|
|
320
|
+
const nameExpr = names ? (0, import_hoistClassNames.hoistClassNames)(jsxPath, existingHoists, names) : null;
|
|
321
|
+
let expr = nameExpr;
|
|
322
|
+
if (nameExpr && !t.isIdentifier(nameExpr)) {
|
|
323
|
+
if (!didFlattenThisTag) {
|
|
324
|
+
} else {
|
|
325
|
+
(0, import_ensureImportingConcat.ensureImportingConcat)(programPath);
|
|
326
|
+
const simpleSpreads = attrs.filter(
|
|
327
|
+
(x) => t.isJSXSpreadAttribute(x.value) && (0, import_extractHelpers.isSimpleSpread)(x.value)
|
|
328
|
+
);
|
|
329
|
+
expr = t.callExpression(t.identifier("concatClassName"), [
|
|
330
|
+
expr,
|
|
331
|
+
...simpleSpreads.map((val) => val.value["argument"])
|
|
332
|
+
]);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
node.attributes.push(
|
|
336
|
+
t.jsxAttribute(t.jsxIdentifier("className"), t.jsxExpressionContainer(expr))
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
const comment = util.format(
|
|
340
|
+
"/* %s:%s (%s) */",
|
|
341
|
+
filePath,
|
|
342
|
+
lineNumbers,
|
|
343
|
+
originalNodeName
|
|
344
|
+
);
|
|
345
|
+
for (const { identifier, rules } of finalStyles) {
|
|
346
|
+
const className = `.${identifier}`;
|
|
347
|
+
if (cssMap.has(className)) {
|
|
348
|
+
if (comment) {
|
|
349
|
+
const val = cssMap.get(className);
|
|
350
|
+
val.commentTexts.push(comment);
|
|
351
|
+
cssMap.set(className, val);
|
|
352
|
+
}
|
|
353
|
+
} else if (rules.length) {
|
|
354
|
+
cssMap.set(className, {
|
|
355
|
+
css: rules.join("\n"),
|
|
356
|
+
commentTexts: [comment]
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
if (!res || !res.modified && !res.optimized && !res.flattened && !res.styled) {
|
|
363
|
+
if (shouldPrintDebug) {
|
|
364
|
+
console.log("no res or none modified", res);
|
|
365
|
+
}
|
|
366
|
+
return null;
|
|
367
|
+
}
|
|
368
|
+
const styles = Array.from(cssMap.values()).map((x) => x.css).join("\n").trim();
|
|
369
|
+
const result = (0, import_generator.default)(
|
|
370
|
+
ast,
|
|
371
|
+
{
|
|
372
|
+
concise: false,
|
|
373
|
+
filename: sourcePath,
|
|
374
|
+
// this makes the debug output terrible, and i think sourcemap works already
|
|
375
|
+
retainLines: false,
|
|
376
|
+
sourceFileName: sourcePath,
|
|
377
|
+
sourceMaps: true
|
|
378
|
+
},
|
|
379
|
+
source
|
|
380
|
+
);
|
|
381
|
+
if (shouldPrintDebug) {
|
|
382
|
+
console.log(
|
|
383
|
+
"\n -------- output code ------- \n\n",
|
|
384
|
+
result.code.split("\n").filter((x) => !x.startsWith("//")).join("\n")
|
|
385
|
+
);
|
|
386
|
+
console.log("\n -------- output style -------- \n\n", styles);
|
|
387
|
+
}
|
|
388
|
+
if (shouldLogTiming) {
|
|
389
|
+
const memUsed = mem ? Math.round((process.memoryUsage().heapUsed - mem.heapUsed) / 1024 / 1204 * 10) / 10 : 0;
|
|
390
|
+
const path2 = (0, import_path.basename)(sourcePath || "").replace(/\.[jt]sx?$/, "").slice(0, 22).trim().padStart(24);
|
|
391
|
+
const numStyled = `${res.styled}`.padStart(3);
|
|
392
|
+
const numOptimized = `${res.optimized}`.padStart(3);
|
|
393
|
+
const numFound = `${res.found}`.padStart(3);
|
|
394
|
+
const numFlattened = `${res.flattened}`.padStart(3);
|
|
395
|
+
const memory = process.env.DEBUG && memUsed > 10 ? ` ${memUsed}MB` : "";
|
|
396
|
+
const timing = Date.now() - start;
|
|
397
|
+
const timingStr = `${timing}ms`.padStart(6);
|
|
398
|
+
const pre = (0, import_getPrefixLogs.getPrefixLogs)(options);
|
|
399
|
+
const memStr = memory ? `(${memory})` : "";
|
|
400
|
+
console.log(
|
|
401
|
+
`${pre} ${path2} ${numFound} \xB7 ${numOptimized} \xB7 ${numFlattened} \xB7 ${numStyled} ${timingStr} ${memStr}`
|
|
402
|
+
);
|
|
403
|
+
}
|
|
404
|
+
return {
|
|
405
|
+
ast,
|
|
406
|
+
styles,
|
|
407
|
+
js: result.code,
|
|
408
|
+
map: result.map
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
412
|
+
0 && (module.exports = {
|
|
413
|
+
extractToClassNames
|
|
414
|
+
});
|
|
15
415
|
//# sourceMappingURL=extractToClassNames.js.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/extractor/extractToClassNames.ts"],
|
|
4
4
|
"sourcesContent": ["import * as path from 'path'\nimport { basename } from 'path'\nimport * as util from 'util'\n\nimport generate from '@babel/generator'\nimport * as t from '@babel/types'\nimport { getStylesAtomic } from '@tamagui/core-node'\nimport { concatClassName } from '@tamagui/helpers'\nimport type { ViewStyle } from 'react-native'\n\nimport type { ClassNameObject, StyleObject, TamaguiOptions, Ternary } from '../types.js'\nimport { babelParse } from './babelParse.js'\nimport { buildClassName } from './buildClassName.js'\nimport { Extractor } from './createExtractor.js'\nimport { ensureImportingConcat } from './ensureImportingConcat.js'\nimport { isSimpleSpread } from './extractHelpers.js'\nimport { extractMediaStyle } from './extractMediaStyle.js'\nimport { getPrefixLogs } from './getPrefixLogs.js'\nimport { hoistClassNames } from './hoistClassNames.js'\nimport { logLines } from './logLines.js'\nimport { timer } from './timer.js'\n\nconst mergeStyleGroups = {\n shadowOpacity: true,\n shadowRadius: true,\n shadowColor: true,\n shadowOffset: true,\n}\n\nexport type ExtractedResponse = {\n js: string | Buffer\n styles: string\n stylesPath?: string\n ast: t.File\n map: any // RawSourceMap from 'source-map'\n}\n\nexport type ExtractToClassNamesProps = {\n extractor: Extractor\n source: string | Buffer\n sourcePath?: string\n options: TamaguiOptions\n shouldPrintDebug: boolean | 'verbose'\n}\n\nexport async function extractToClassNames({\n extractor,\n source,\n sourcePath,\n options,\n shouldPrintDebug,\n}: ExtractToClassNamesProps): Promise<ExtractedResponse | null> {\n const tm = timer()\n\n if (shouldPrintDebug) {\n console.log(`--- ${sourcePath} --- \\n\\n`)\n }\n\n if (typeof source !== 'string') {\n throw new Error('`source` must be a string of javascript')\n }\n if (sourcePath && !path.isAbsolute(sourcePath)) {\n throw new Error('`sourcePath` must be an absolute path to a .js file')\n }\n if (!/.[tj]sx?$/i.test(sourcePath || '')) {\n console.log(`${sourcePath?.slice(0, 100)} - bad filename.`)\n }\n\n // dont include loading in timing of parsing (one time cost)\n await extractor.loadTamagui(options)\n\n const shouldLogTiming = options.logTimings ?? true\n const start = Date.now()\n const mem = shouldLogTiming ? process.memoryUsage() : null\n\n // Using a map for (officially supported) guaranteed insertion order\n let ast: t.File\n\n try {\n ast = babelParse(source)\n } catch (err) {\n // eslint-disable-next-line no-console\n console.error('babel parse error:', sourcePath?.slice(0, 100))\n throw err\n }\n\n tm.mark(`babel-parse`, shouldPrintDebug === 'verbose')\n\n const cssMap = new Map<string, { css: string; commentTexts: string[] }>()\n const existingHoists: { [key: string]: t.Identifier } = {}\n\n let hasFlattened = false\n\n const res = await extractor.parse(ast, {\n shouldPrintDebug,\n ...options,\n sourcePath,\n target: 'html',\n extractStyledDefinitions: true,\n onStyleRule(identifier, rules) {\n const css = rules.join(';')\n if (shouldPrintDebug) {\n // eslint-disable-next-line no-console\n console.log(`adding styled() rule: .${identifier} ${css}`)\n }\n cssMap.set(`.${identifier}`, { css, commentTexts: [] })\n },\n getFlattenedNode: ({ tag }) => {\n hasFlattened = true\n return tag\n },\n onExtractTag: ({\n parserProps,\n attrs,\n node,\n attemptEval,\n jsxPath,\n originalNodeName,\n filePath,\n lineNumbers,\n programPath,\n isFlattened,\n completeProps,\n staticConfig,\n }) => {\n // bail out of views that don't accept className (falls back to runtime + style={})\n if (staticConfig.acceptsClassName === false) {\n if (shouldPrintDebug) {\n // eslint-disable-next-line no-console\n console.log(`bail, acceptsClassName is false`)\n }\n return\n }\n\n // reset hasFlattened\n const didFlattenThisTag = hasFlattened\n hasFlattened = false\n\n let finalClassNames: ClassNameObject[] = []\n const finalAttrs: (t.JSXAttribute | t.JSXSpreadAttribute)[] = []\n let finalStyles: StyleObject[] = []\n\n let viewStyles = {}\n for (const attr of attrs) {\n if (attr.type === 'style') {\n viewStyles = {\n ...viewStyles,\n ...attr.value,\n }\n }\n }\n\n const ensureNeededPrevStyle = (style: ViewStyle) => {\n // ensure all group keys are merged\n const keys = Object.keys(style)\n if (!keys.some((key) => mergeStyleGroups[key])) {\n return style\n }\n for (const k in mergeStyleGroups) {\n if (k in viewStyles) {\n style[k] = style[k] ?? viewStyles[k]\n }\n }\n return style\n }\n\n const addStyles = (style: ViewStyle | null): StyleObject[] => {\n if (!style) return []\n const styleWithPrev = ensureNeededPrevStyle(style)\n const res = getStylesAtomic(styleWithPrev)\n if (res.length) {\n finalStyles = [...finalStyles, ...res]\n }\n return res\n }\n\n // 1 to start above any :hover styles\n let lastMediaImportance = 1\n for (const attr of attrs) {\n switch (attr.type) {\n case 'style': {\n if (!isFlattened) {\n const styles = getStylesAtomic(attr.value)\n\n finalStyles = [...finalStyles, ...styles]\n\n for (const style of styles) {\n // leave them as attributes\n const prop = style.pseudo\n ? `${style.property}-${style.pseudo}`\n : style.property\n finalAttrs.push(\n t.jsxAttribute(t.jsxIdentifier(prop), t.stringLiteral(style.identifier))\n )\n }\n } else {\n const styles = addStyles(attr.value)\n const newClassNames = concatClassName(\n styles.map((x) => x.identifier).join(' ')\n )\n const existing = finalClassNames.find(\n (x) => x.type == 'StringLiteral'\n ) as t.StringLiteral | null\n\n if (existing) {\n existing.value = `${existing.value} ${newClassNames}`\n } else {\n finalClassNames = [...finalClassNames, t.stringLiteral(newClassNames)]\n }\n }\n\n break\n }\n case 'attr': {\n const val = attr.value\n if (t.isJSXSpreadAttribute(val)) {\n if (isSimpleSpread(val)) {\n finalClassNames.push(\n t.logicalExpression(\n '&&',\n val.argument,\n t.memberExpression(val.argument, t.identifier('className'))\n )\n )\n }\n } else if (val.name.name === 'className') {\n const value = val.value\n if (value) {\n try {\n const evaluatedValue = attemptEval(value)\n finalClassNames.push(t.stringLiteral(evaluatedValue))\n } catch (e) {\n finalClassNames.push(value['expression'])\n }\n }\n continue\n }\n finalAttrs.push(val)\n break\n }\n case 'ternary': {\n const mediaExtraction = extractMediaStyle(\n parserProps,\n attr.value,\n jsxPath,\n extractor.getTamagui()!,\n sourcePath || '',\n lastMediaImportance,\n shouldPrintDebug\n )\n if (shouldPrintDebug) {\n if (mediaExtraction) {\n // eslint-disable-next-line no-console\n console.log(\n 'ternary (mediaStyles)',\n mediaExtraction.ternaryWithoutMedia?.inlineMediaQuery ?? '',\n mediaExtraction.mediaStyles.map((x) => x.identifier).join('.')\n )\n }\n }\n if (!mediaExtraction) {\n addTernaryStyle(\n attr.value,\n addStyles(attr.value.consequent),\n addStyles(attr.value.alternate)\n )\n continue\n }\n lastMediaImportance++\n if (mediaExtraction.mediaStyles) {\n finalStyles = [...finalStyles, ...mediaExtraction.mediaStyles]\n }\n if (mediaExtraction.ternaryWithoutMedia) {\n addTernaryStyle(\n mediaExtraction.ternaryWithoutMedia,\n mediaExtraction.mediaStyles,\n []\n )\n } else {\n finalClassNames = [\n ...finalClassNames,\n ...mediaExtraction.mediaStyles.map((x) => t.stringLiteral(x.identifier)),\n ]\n }\n break\n }\n }\n }\n\n function addTernaryStyle(ternary: Ternary, a: any, b: any) {\n const cCN = a.map((x) => x.identifier).join(' ')\n const aCN = b.map((x) => x.identifier).join(' ')\n\n if (a.length && b.length) {\n finalClassNames.push(\n t.conditionalExpression(\n ternary.test,\n t.stringLiteral(cCN),\n t.stringLiteral(aCN)\n )\n )\n } else {\n finalClassNames.push(\n t.conditionalExpression(\n ternary.test,\n t.stringLiteral(' ' + cCN),\n t.stringLiteral(' ' + aCN)\n )\n )\n }\n }\n\n if (shouldPrintDebug) {\n // eslint-disable-next-line no-console\n console.log(\n ' finalClassNames\\n',\n logLines(finalClassNames.map((x) => x['value']).join(' '))\n )\n }\n\n node.attributes = finalAttrs\n\n if (finalClassNames.length) {\n const extraClassNames = (() => {\n let value = ''\n if (!isFlattened) {\n return value\n }\n\n // helper to see how many get flattened\n if (process.env.TAMAGUI_DEBUG_OPTIMIZATIONS) {\n value += `is_tamagui_flattened`\n }\n\n // add is_Component className\n if (staticConfig.componentName) {\n value += ` is_${staticConfig.componentName}`\n }\n\n if (staticConfig.isText) {\n let family = completeProps.fontFamily\n if (family[0] === '$') {\n family = family.slice(1)\n }\n value += ` font_${family}`\n }\n\n return value\n })()\n\n // inserts the _cn variable and uses it for className\n const names = buildClassName(finalClassNames, extraClassNames)\n\n const nameExpr = names ? hoistClassNames(jsxPath, existingHoists, names) : null\n let expr = nameExpr\n\n // if has some spreads, use concat helper\n if (nameExpr && !t.isIdentifier(nameExpr)) {\n if (!didFlattenThisTag) {\n // not flat\n } else {\n ensureImportingConcat(programPath)\n const simpleSpreads = attrs.filter(\n (x) => t.isJSXSpreadAttribute(x.value) && isSimpleSpread(x.value)\n )\n expr = t.callExpression(t.identifier('concatClassName'), [\n expr,\n ...simpleSpreads.map((val) => val.value['argument']),\n ])\n }\n }\n\n node.attributes.push(\n t.jsxAttribute(t.jsxIdentifier('className'), t.jsxExpressionContainer(expr))\n )\n }\n\n const comment = util.format(\n '/* %s:%s (%s) */',\n filePath,\n lineNumbers,\n originalNodeName\n )\n\n for (const { identifier, rules } of finalStyles) {\n const className = `.${identifier}`\n if (cssMap.has(className)) {\n if (comment) {\n const val = cssMap.get(className)!\n val.commentTexts.push(comment)\n cssMap.set(className, val)\n }\n } else if (rules.length) {\n cssMap.set(className, {\n css: rules.join('\\n'),\n commentTexts: [comment],\n })\n }\n }\n },\n })\n\n if (!res || (!res.modified && !res.optimized && !res.flattened && !res.styled)) {\n if (shouldPrintDebug) {\n // eslint-disable-next-line no-console\n console.log('no res or none modified', res)\n }\n return null\n }\n\n const styles = Array.from(cssMap.values())\n .map((x) => x.css)\n .join('\\n')\n .trim()\n\n // @ts-ignore\n const result = generate(\n ast as any,\n {\n concise: false,\n filename: sourcePath,\n // this makes the debug output terrible, and i think sourcemap works already\n retainLines: false,\n sourceFileName: sourcePath,\n sourceMaps: true,\n },\n source\n )\n\n if (shouldPrintDebug) {\n // eslint-disable-next-line no-console\n console.log(\n '\\n -------- output code ------- \\n\\n',\n result.code\n .split('\\n')\n .filter((x) => !x.startsWith('//'))\n .join('\\n')\n )\n // eslint-disable-next-line no-console\n console.log('\\n -------- output style -------- \\n\\n', styles)\n }\n\n if (shouldLogTiming) {\n const memUsed = mem\n ? Math.round(((process.memoryUsage().heapUsed - mem.heapUsed) / 1024 / 1204) * 10) /\n 10\n : 0\n const path = basename(sourcePath || '')\n .replace(/\\.[jt]sx?$/, '')\n .slice(0, 22)\n .trim()\n .padStart(24)\n\n const numStyled = `${res.styled}`.padStart(3)\n const numOptimized = `${res.optimized}`.padStart(3)\n const numFound = `${res.found}`.padStart(3)\n const numFlattened = `${res.flattened}`.padStart(3)\n const memory = process.env.DEBUG && memUsed > 10 ? ` ${memUsed}MB` : ''\n const timing = Date.now() - start\n const timingStr = `${timing}ms`.padStart(6)\n const pre = getPrefixLogs(options)\n const memStr = memory ? `(${memory})` : ''\n // eslint-disable-next-line no-console\n console.log(\n `${pre} ${path} ${numFound} \u00B7 ${numOptimized} \u00B7 ${numFlattened} \u00B7 ${numStyled} ${timingStr} ${memStr}`\n )\n }\n\n return {\n ast,\n styles,\n js: result.code,\n map: result.map,\n }\n}\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,WAAsB;AACtB,kBAAyB;AACzB,WAAsB;AAEtB,uBAAqB;AACrB,QAAmB;AACnB,uBAAgC;AAChC,qBAAgC;AAIhC,wBAA2B;AAC3B,4BAA+B;AAE/B,mCAAsC;AACtC,4BAA+B;AAC/B,+BAAkC;AAClC,2BAA8B;AAC9B,6BAAgC;AAChC,sBAAyB;AACzB,mBAAsB;AAEtB,MAAM,mBAAmB;AAAA,EACvB,eAAe;AAAA,EACf,cAAc;AAAA,EACd,aAAa;AAAA,EACb,cAAc;AAChB;AAkBA,eAAsB,oBAAoB;AAAA,EACxC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAgE;AAC9D,QAAM,SAAK,oBAAM;AAEjB,MAAI,kBAAkB;AACpB,YAAQ,IAAI,OAAO;AAAA;AAAA,CAAqB;AAAA,EAC1C;AAEA,MAAI,OAAO,WAAW,UAAU;AAC9B,UAAM,IAAI,MAAM,yCAAyC;AAAA,EAC3D;AACA,MAAI,cAAc,CAAC,KAAK,WAAW,UAAU,GAAG;AAC9C,UAAM,IAAI,MAAM,qDAAqD;AAAA,EACvE;AACA,MAAI,CAAC,aAAa,KAA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9D;AAEA,MAAI,iBAAiB;AACnB,UAAM,UAAU,MACZ,KAAK,OAAQ,QAAQ,YAAY,EAAE,WAAW,IAAI,YAAY,OAAO,OAAQ,EAAE,IAC/E,KACA;AACJ,UAAMC,YAAO,sBAAS,cAAc,EAAE,EACnC,QAAQ,cAAc,EAAE,EACxB,MAAM,GAAG,EAAE,EACX,KAAK,EACL,SAAS,EAAE;AAEd,UAAM,YAAY,GAAG,IAAI,SAAS,SAAS,CAAC;AAC5C,UAAM,eAAe,GAAG,IAAI,YAAY,SAAS,CAAC;AAClD,UAAM,WAAW,GAAG,IAAI,QAAQ,SAAS,CAAC;AAC1C,UAAM,eAAe,GAAG,IAAI,YAAY,SAAS,CAAC;AAClD,UAAM,SAAS,QAAQ,IAAI,SAAS,UAAU,KAAK,IAAI,cAAc;AACrE,UAAM,SAAS,KAAK,IAAI,IAAI;AAC5B,UAAM,YAAY,GAAG,WAAW,SAAS,CAAC;AAC1C,UAAM,UAAM,oCAAc,OAAO;AACjC,UAAM,SAAS,SAAS,IAAI,YAAY;AAExC,YAAQ;AAAA,MACN,GAAG,OAAOA,UAAS,iBAAc,qBAAkB,qBAAkB,cAAc,aAAa;AAAA,IAClG;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,IAAI,OAAO;AAAA,IACX,KAAK,OAAO;AAAA,EACd;AACF;",
|
|
6
|
+
"names": ["res", "styles", "generate", "path"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,44 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var findTopmostFunction_exports = {};
|
|
20
|
+
__export(findTopmostFunction_exports, {
|
|
21
|
+
findTopmostFunction: () => findTopmostFunction
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(findTopmostFunction_exports);
|
|
24
|
+
function findTopmostFunction(jsxPath) {
|
|
25
|
+
const isFunction = (path) => path.isArrowFunctionExpression() || path.isFunctionDeclaration() || path.isFunctionExpression();
|
|
26
|
+
let compFn = jsxPath.findParent(isFunction);
|
|
27
|
+
while (compFn) {
|
|
28
|
+
const parent = compFn.findParent(isFunction);
|
|
29
|
+
if (parent) {
|
|
30
|
+
compFn = parent;
|
|
31
|
+
} else {
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (!compFn) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
return compFn;
|
|
39
|
+
}
|
|
40
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
41
|
+
0 && (module.exports = {
|
|
42
|
+
findTopmostFunction
|
|
43
|
+
});
|
|
2
44
|
//# sourceMappingURL=findTopmostFunction.js.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/extractor/findTopmostFunction.ts"],
|
|
4
4
|
"sourcesContent": ["import { NodePath } from '@babel/traverse'\nimport * as t from '@babel/types'\n\nexport function findTopmostFunction(jsxPath: NodePath<t.JSXElement>) {\n // get topmost fn\n const isFunction = (path: NodePath<any>) =>\n path.isArrowFunctionExpression() || path.isFunctionDeclaration() || path.isFunctionExpression()\n let compFn: NodePath<any> | null = jsxPath.findParent(isFunction)\n while (compFn) {\n const parent = compFn.findParent(isFunction)\n if (parent) {\n compFn = parent\n } else {\n break\n }\n }\n if (!compFn) {\n // console.error(`Couldn't find a topmost function for media query extraction`)\n return null\n }\n return compFn\n}\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": [
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,SAAS,oBAAoB,SAAiC;AAEnE,QAAM,aAAa,CAAC,SAClB,KAAK,0BAA0B,KAAK,KAAK,sBAAsB,KAAK,KAAK,qBAAqB;AAChG,MAAI,SAA+B,QAAQ,WAAW,UAAU;AAChE,SAAO,QAAQ;AACb,UAAM,SAAS,OAAO,WAAW,UAAU;AAC3C,QAAI,QAAQ;AACV,eAAS;AAAA,IACX,OAAO;AACL;AAAA,IACF;AAAA,EACF;AACA,MAAI,CAAC,QAAQ;AAEX,WAAO;AAAA,EACT;AACA,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
7
|
}
|