@tamagui/static 1.0.1-beta.60 → 1.0.1-beta.63
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/extractor/createEvaluator.js +6 -1
- package/dist/cjs/extractor/createEvaluator.js.map +2 -2
- package/dist/cjs/extractor/createExtractor.js +32 -20
- package/dist/cjs/extractor/createExtractor.js.map +2 -2
- package/dist/cjs/extractor/extractMediaStyle.js +1 -1
- package/dist/cjs/extractor/extractMediaStyle.js.map +2 -2
- package/dist/cjs/extractor/extractToClassNames.js +1 -1
- package/dist/cjs/extractor/extractToClassNames.js.map +2 -2
- package/dist/esm/extractor/createEvaluator.js +6 -1
- package/dist/esm/extractor/createEvaluator.js.map +2 -2
- package/dist/esm/extractor/createExtractor.js +37 -23
- package/dist/esm/extractor/createExtractor.js.map +2 -2
- package/dist/esm/extractor/extractMediaStyle.js +1 -1
- package/dist/esm/extractor/extractMediaStyle.js.map +2 -2
- package/dist/esm/extractor/extractToClassNames.js +1 -1
- package/dist/esm/extractor/extractToClassNames.js.map +2 -2
- package/dist/jsx/extractor/createEvaluator.js +6 -1
- package/dist/jsx/extractor/createExtractor.js +37 -23
- package/dist/jsx/extractor/extractMediaStyle.js +1 -1
- package/dist/jsx/extractor/extractToClassNames.js +1 -1
- package/package.json +7 -7
- package/src/extractor/createEvaluator.ts +9 -4
- package/src/extractor/createExtractor.ts +56 -25
- package/src/extractor/extractMediaStyle.ts +3 -1
- package/src/extractor/extractToClassNames.ts +1 -30
- package/types/extractor/createEvaluator.d.ts.map +1 -1
- package/types/extractor/createExtractor.d.ts.map +1 -1
- package/types/extractor/extractMediaStyle.d.ts.map +1 -1
- package/types/extractor/extractToClassNames.d.ts.map +1 -1
|
@@ -29,6 +29,7 @@ var import_vm = __toESM(require("vm"));
|
|
|
29
29
|
var import_generator = __toESM(require("@babel/generator"));
|
|
30
30
|
var t = __toESM(require("@babel/types"));
|
|
31
31
|
var import_core_node = require("@tamagui/core-node");
|
|
32
|
+
var import_esbuild = __toESM(require("esbuild"));
|
|
32
33
|
var import_constants = require("../constants");
|
|
33
34
|
var import_evaluateAstNode = require("./evaluateAstNode");
|
|
34
35
|
var import_extractHelpers = require("./extractHelpers");
|
|
@@ -52,7 +53,11 @@ function createEvaluator({
|
|
|
52
53
|
return staticNamespace[n.name];
|
|
53
54
|
}
|
|
54
55
|
const evalContext = import_vm.default.createContext(staticNamespace);
|
|
55
|
-
const
|
|
56
|
+
const codeWithTypescriptAnnotations = `(${(0, import_generator.default)(n).code})`;
|
|
57
|
+
const code = import_esbuild.default.transformSync(codeWithTypescriptAnnotations, { loader: "tsx" }).code.replace(/;\n$/, "");
|
|
58
|
+
if (shouldPrintDebug) {
|
|
59
|
+
console.log("evaluating", code);
|
|
60
|
+
}
|
|
56
61
|
return import_vm.default.runInContext(code, evalContext);
|
|
57
62
|
}, "evalFn");
|
|
58
63
|
return (n) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/extractor/createEvaluator.ts"],
|
|
4
|
-
"sourcesContent": ["import vm from 'vm'\n\nimport generate from '@babel/generator'\nimport { NodePath } from '@babel/traverse'\nimport * as t from '@babel/types'\nimport type { TamaguiConfig } from '@tamagui/core'\nimport { createCSSVariable } from '@tamagui/core-node'\n\nimport { FAILED_EVAL } from '../constants'\nimport { evaluateAstNode } from './evaluateAstNode'\nimport { isValidThemeHook } from './extractHelpers'\n\nexport function createEvaluator({\n tamaguiConfig,\n staticNamespace,\n sourcePath,\n traversePath,\n shouldPrintDebug,\n}: {\n tamaguiConfig: TamaguiConfig\n staticNamespace: Record<string, any>\n sourcePath: string\n traversePath: NodePath<t.JSXElement>\n shouldPrintDebug: boolean | 'verbose'\n}) {\n // called when evaluateAstNode encounters a dynamic-looking prop\n const evalFn = (n: t.Node) => {\n // themes\n if (\n t.isMemberExpression(n) &&\n t.isIdentifier(n.property) &&\n isValidThemeHook(traversePath, n, sourcePath)\n ) {\n const key = n.property.name\n if (shouldPrintDebug) {\n console.log(' > found theme prop', key)\n }\n console.log('SHOULD FIND THEME (NESTED NOW)', key) // tamaguiConfig.themes)\n // if (!themeKeys.has(key)) {\n // throw new Error(` > accessing non-existent theme key: ${key}`)\n // }\n return createCSSVariable(key)\n }\n // variable\n if (t.isIdentifier(n) && staticNamespace.hasOwnProperty(n.name)) {\n return staticNamespace[n.name]\n }\n const evalContext = vm.createContext(staticNamespace)\n const
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAe;AAEf,uBAAqB;AAErB,QAAmB;AAEnB,uBAAkC;
|
|
4
|
+
"sourcesContent": ["import vm from 'vm'\n\nimport generate from '@babel/generator'\nimport { NodePath } from '@babel/traverse'\nimport * as t from '@babel/types'\nimport type { TamaguiConfig } from '@tamagui/core'\nimport { createCSSVariable } from '@tamagui/core-node'\nimport esbuild from 'esbuild'\n\nimport { FAILED_EVAL } from '../constants'\nimport { evaluateAstNode } from './evaluateAstNode'\nimport { isValidThemeHook } from './extractHelpers'\n\nexport function createEvaluator({\n tamaguiConfig,\n staticNamespace,\n sourcePath,\n traversePath,\n shouldPrintDebug,\n}: {\n tamaguiConfig: TamaguiConfig\n staticNamespace: Record<string, any>\n sourcePath: string\n traversePath: NodePath<t.JSXElement>\n shouldPrintDebug: boolean | 'verbose'\n}) {\n // called when evaluateAstNode encounters a dynamic-looking prop\n const evalFn = (n: t.Node) => {\n // themes\n if (\n t.isMemberExpression(n) &&\n t.isIdentifier(n.property) &&\n isValidThemeHook(traversePath, n, sourcePath)\n ) {\n const key = n.property.name\n if (shouldPrintDebug) {\n console.log(' > found theme prop', key)\n }\n console.log('SHOULD FIND THEME (NESTED NOW)', key) // tamaguiConfig.themes)\n // if (!themeKeys.has(key)) {\n // throw new Error(` > accessing non-existent theme key: ${key}`)\n // }\n return createCSSVariable(key)\n }\n // variable\n if (t.isIdentifier(n) && staticNamespace.hasOwnProperty(n.name)) {\n return staticNamespace[n.name]\n }\n const evalContext = vm.createContext(staticNamespace)\n const codeWithTypescriptAnnotations = `(${generate(n as any).code})`\n const code = esbuild\n .transformSync(codeWithTypescriptAnnotations, { loader: 'tsx' })\n .code.replace(/;\\n$/, '')\n\n if (shouldPrintDebug) {\n console.log('evaluating', code)\n }\n return vm.runInContext(code, evalContext)\n }\n\n return (n: t.Node) => {\n return evaluateAstNode(n, evalFn)\n }\n}\n\nexport function createSafeEvaluator(attemptEval: (n: t.Node) => any) {\n return (n: t.Node) => {\n try {\n return attemptEval(n)\n } catch (err) {\n return FAILED_EVAL\n }\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAe;AAEf,uBAAqB;AAErB,QAAmB;AAEnB,uBAAkC;AAClC,qBAAoB;AAEpB,uBAA4B;AAC5B,6BAAgC;AAChC,4BAAiC;AAE1B,yBAAyB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,GAOC;AAED,QAAM,SAAS,wBAAC,MAAc;AAE5B,QACE,EAAE,mBAAmB,CAAC,KACtB,EAAE,aAAa,EAAE,QAAQ,KACzB,4CAAiB,cAAc,GAAG,UAAU,GAC5C;AACA,YAAM,MAAM,EAAE,SAAS;AACvB,UAAI,kBAAkB;AACpB,gBAAQ,IAAI,0BAA0B,GAAG;AAAA,MAC3C;AACA,cAAQ,IAAI,kCAAkC,GAAG;AAIjD,aAAO,wCAAkB,GAAG;AAAA,IAC9B;AAEA,QAAI,EAAE,aAAa,CAAC,KAAK,gBAAgB,eAAe,EAAE,IAAI,GAAG;AAC/D,aAAO,gBAAgB,EAAE;AAAA,IAC3B;AACA,UAAM,cAAc,kBAAG,cAAc,eAAe;AACpD,UAAM,gCAAgC,IAAI,8BAAS,CAAQ,EAAE;AAC7D,UAAM,OAAO,uBACV,cAAc,+BAA+B,EAAE,QAAQ,MAAM,CAAC,EAC9D,KAAK,QAAQ,QAAQ,EAAE;AAE1B,QAAI,kBAAkB;AACpB,cAAQ,IAAI,cAAc,IAAI;AAAA,IAChC;AACA,WAAO,kBAAG,aAAa,MAAM,WAAW;AAAA,EAC1C,GA/Be;AAiCf,SAAO,CAAC,MAAc;AACpB,WAAO,4CAAgB,GAAG,MAAM;AAAA,EAClC;AACF;AAlDgB;AAoDT,6BAA6B,aAAiC;AACnE,SAAO,CAAC,MAAc;AACpB,QAAI;AACF,aAAO,YAAY,CAAC;AAAA,IACtB,SAAS,KAAP;AACA,aAAO;AAAA,IACT;AAAA,EACF;AACF;AARgB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -403,7 +403,7 @@ function createExtractor() {
|
|
|
403
403
|
let keys = [name];
|
|
404
404
|
let out = null;
|
|
405
405
|
if (staticConfig.propMapper) {
|
|
406
|
-
out = staticConfig.propMapper(name, styleValue, defaultTheme, staticConfig.defaultProps, { resolveVariablesAs: "auto" });
|
|
406
|
+
out = staticConfig.propMapper(name, styleValue, defaultTheme, staticConfig.defaultProps, { resolveVariablesAs: "auto" }, void 0, shouldPrintDebug);
|
|
407
407
|
if (out) {
|
|
408
408
|
if (!Array.isArray(out)) {
|
|
409
409
|
console.warn(`Error expected array but got`, out);
|
|
@@ -432,7 +432,7 @@ function createExtractor() {
|
|
|
432
432
|
attr: path.node
|
|
433
433
|
};
|
|
434
434
|
}
|
|
435
|
-
if (import_validHTMLAttributes.validHTMLAttributes[key]) {
|
|
435
|
+
if (import_validHTMLAttributes.validHTMLAttributes[key] || key.startsWith("aria-") || key.startsWith("data-")) {
|
|
436
436
|
return attr;
|
|
437
437
|
}
|
|
438
438
|
if (shouldPrintDebug) {
|
|
@@ -838,6 +838,7 @@ function createExtractor() {
|
|
|
838
838
|
console.log("Error extracting attribute", err.message, err.stack);
|
|
839
839
|
console.log("node", path.node);
|
|
840
840
|
}
|
|
841
|
+
inlined.set(`${Math.random()}`, "spread");
|
|
841
842
|
return {
|
|
842
843
|
type: "attr",
|
|
843
844
|
value: path.node
|
|
@@ -1052,32 +1053,43 @@ function createExtractor() {
|
|
|
1052
1053
|
press: false,
|
|
1053
1054
|
pressIn: false
|
|
1054
1055
|
};
|
|
1055
|
-
|
|
1056
|
-
|
|
1056
|
+
let foundStaticProps = {};
|
|
1057
|
+
for (const key in attrs) {
|
|
1058
|
+
const cur = attrs[key];
|
|
1057
1059
|
if (cur.type === "style") {
|
|
1058
1060
|
(0, import_core_node.normalizeStyleObject)(cur.value);
|
|
1059
|
-
|
|
1061
|
+
foundStaticProps = __spreadValues(__spreadValues({}, foundStaticProps), (0, import_core_node.expandStyles)(cur.value));
|
|
1062
|
+
continue;
|
|
1060
1063
|
}
|
|
1061
1064
|
if (cur.type === "attr") {
|
|
1062
1065
|
if (t.isJSXSpreadAttribute(cur.value)) {
|
|
1063
|
-
|
|
1066
|
+
continue;
|
|
1064
1067
|
}
|
|
1065
1068
|
if (!t.isJSXIdentifier(cur.value.name)) {
|
|
1066
|
-
|
|
1069
|
+
continue;
|
|
1067
1070
|
}
|
|
1068
|
-
const
|
|
1071
|
+
const key2 = cur.value.name.name;
|
|
1069
1072
|
const value = attemptEvalSafe(cur.value.value || t.booleanLiteral(true));
|
|
1070
|
-
if (value
|
|
1071
|
-
|
|
1073
|
+
if (value !== import_constants.FAILED_EVAL) {
|
|
1074
|
+
foundStaticProps = __spreadProps(__spreadValues({}, foundStaticProps), {
|
|
1075
|
+
[key2]: value
|
|
1076
|
+
});
|
|
1072
1077
|
}
|
|
1073
|
-
acc[key] = value;
|
|
1074
1078
|
}
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
const
|
|
1079
|
+
}
|
|
1080
|
+
const completeProps = {};
|
|
1081
|
+
for (const key in staticConfig.defaultProps) {
|
|
1082
|
+
if (!(key in foundStaticProps)) {
|
|
1083
|
+
completeProps[key] = staticConfig.defaultProps[key];
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
for (const key in foundStaticProps) {
|
|
1087
|
+
completeProps[key] = foundStaticProps[key];
|
|
1088
|
+
}
|
|
1078
1089
|
if (shouldPrintDebug) {
|
|
1079
1090
|
console.log(" - attrs (combined \u{1F500}): \n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", ")));
|
|
1080
1091
|
console.log(" - defaultProps: \n", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(staticConfig.defaultProps)));
|
|
1092
|
+
console.log(" - foundStaticProps: \n", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(foundStaticProps)));
|
|
1081
1093
|
console.log(" - completeProps: \n", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(completeProps)));
|
|
1082
1094
|
}
|
|
1083
1095
|
const getStyles = /* @__PURE__ */ __name((props2, debugName = "") => {
|
|
@@ -1098,7 +1110,7 @@ function createExtractor() {
|
|
|
1098
1110
|
try {
|
|
1099
1111
|
const out = (0, import_core_node.getSplitStyles)(props2, staticConfig, defaultTheme, __spreadProps(__spreadValues({}, state), {
|
|
1100
1112
|
fallbackProps: completeProps
|
|
1101
|
-
}));
|
|
1113
|
+
}), void 0, props2["debug"]);
|
|
1102
1114
|
const outStyle = __spreadValues(__spreadValues({}, out.style), out.pseudos);
|
|
1103
1115
|
omitInvalidStyles(outStyle);
|
|
1104
1116
|
if (shouldPrintDebug) {
|
|
@@ -1119,7 +1131,7 @@ function createExtractor() {
|
|
|
1119
1131
|
if (!completeStyles) {
|
|
1120
1132
|
throw new Error(`Impossible, no styles`);
|
|
1121
1133
|
}
|
|
1122
|
-
const addInitialStyleKeys = shouldFlatten ? (0, import_lodash.difference)(Object.keys(completeStyles), Object.keys(
|
|
1134
|
+
const addInitialStyleKeys = shouldFlatten ? (0, import_lodash.difference)(Object.keys(completeStyles), Object.keys(foundStaticProps)) : [];
|
|
1123
1135
|
if (addInitialStyleKeys.length) {
|
|
1124
1136
|
const toAdd = (0, import_lodash.pick)(completeStyles, ...addInitialStyleKeys);
|
|
1125
1137
|
const firstGroup = attrs.find((x) => x.type === "style");
|
|
@@ -1135,14 +1147,11 @@ function createExtractor() {
|
|
|
1135
1147
|
}
|
|
1136
1148
|
if (shouldPrintDebug) {
|
|
1137
1149
|
console.log(" -- addInitialStyleKeys", addInitialStyleKeys.join(", "), { shouldFlatten });
|
|
1138
|
-
console.log(" -- completeStaticProps:\n", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(completeStaticProps)));
|
|
1139
1150
|
console.log(" -- completeStyles:\n", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(completeStyles)));
|
|
1140
1151
|
}
|
|
1141
1152
|
let getStyleError = null;
|
|
1142
1153
|
for (const attr of attrs) {
|
|
1143
1154
|
try {
|
|
1144
|
-
if (shouldPrintDebug)
|
|
1145
|
-
console.log(" *", (0, import_extractHelpers.attrStr)(attr));
|
|
1146
1155
|
switch (attr.type) {
|
|
1147
1156
|
case "ternary":
|
|
1148
1157
|
const a = getStyles(attr.value.alternate, "ternary.alternate");
|
|
@@ -1156,7 +1165,7 @@ function createExtractor() {
|
|
|
1156
1165
|
continue;
|
|
1157
1166
|
case "style":
|
|
1158
1167
|
if (shouldPrintDebug)
|
|
1159
|
-
console.log(" * styles in",
|
|
1168
|
+
console.log(" * styles in", attr.value);
|
|
1160
1169
|
const styles = getStyles(attr.value, "style");
|
|
1161
1170
|
if (shouldPrintDebug)
|
|
1162
1171
|
console.log(" * styles out", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(styles)));
|
|
@@ -1169,6 +1178,9 @@ function createExtractor() {
|
|
|
1169
1178
|
getStyleError = err;
|
|
1170
1179
|
}
|
|
1171
1180
|
}
|
|
1181
|
+
if (shouldPrintDebug) {
|
|
1182
|
+
console.log(" - attrs (ternaries/combined):\n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", ")));
|
|
1183
|
+
}
|
|
1172
1184
|
tm.mark("jsx-element-styles", shouldPrintDebug === "verbose");
|
|
1173
1185
|
if (getStyleError) {
|
|
1174
1186
|
console.log(" \u26A0\uFE0F postprocessing error, deopt", getStyleError);
|