@tamagui/static 1.0.1-beta.190 → 1.0.1-beta.192
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/constants.js +0 -3
- package/dist/constants.js.map +2 -2
- package/dist/extractor/buildClassName.js +20 -5
- package/dist/extractor/buildClassName.js.map +2 -2
- package/dist/extractor/createEvaluator.js +3 -3
- package/dist/extractor/createEvaluator.js.map +2 -2
- package/dist/extractor/createExtractor.js +72 -49
- package/dist/extractor/createExtractor.js.map +3 -3
- package/dist/extractor/ensureImportingConcat.js +4 -8
- package/dist/extractor/ensureImportingConcat.js.map +2 -2
- package/dist/extractor/extractHelpers.js +37 -9
- package/dist/extractor/extractHelpers.js.map +3 -3
- package/dist/extractor/extractMediaStyle.js +11 -11
- package/dist/extractor/extractMediaStyle.js.map +2 -2
- package/dist/extractor/extractToClassNames.js +5 -17
- package/dist/extractor/extractToClassNames.js.map +2 -2
- package/dist/extractor/getStaticBindingsForScope.js +3 -3
- package/dist/extractor/getStaticBindingsForScope.js.map +2 -2
- package/dist/extractor/loadTamagui.js +7 -5
- package/dist/extractor/loadTamagui.js.map +2 -2
- package/dist/types.js.map +1 -1
- package/package.json +16 -14
- package/src/constants.ts +0 -1
- package/src/extractor/buildClassName.ts +20 -4
- package/src/extractor/createEvaluator.ts +5 -5
- package/src/extractor/createExtractor.ts +53 -33
- package/src/extractor/ensureImportingConcat.ts +4 -11
- package/src/extractor/extractHelpers.ts +41 -7
- package/src/extractor/extractMediaStyle.ts +17 -10
- package/src/extractor/extractToClassNames.ts +6 -20
- package/src/extractor/getStaticBindingsForScope.ts +4 -4
- package/src/extractor/loadTamagui.ts +9 -7
- package/src/types.ts +5 -2
- package/types/constants.d.ts +0 -1
- package/types/extractor/buildClassName.d.ts +4 -1
- package/types/extractor/createEvaluator.d.ts +3 -3
- package/types/extractor/createExtractor.d.ts +1 -1
- package/types/extractor/extractHelpers.d.ts +5 -3
- package/types/extractor/extractMediaStyle.d.ts +3 -3
- package/types/types.d.ts +4 -2
package/dist/constants.js
CHANGED
|
@@ -24,7 +24,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
24
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
25
|
var constants_exports = {};
|
|
26
26
|
__export(constants_exports, {
|
|
27
|
-
CONCAT_CLASSNAME_IMPORT: () => CONCAT_CLASSNAME_IMPORT,
|
|
28
27
|
CSS_FILE_NAME: () => CSS_FILE_NAME,
|
|
29
28
|
FAILED_EVAL: () => FAILED_EVAL,
|
|
30
29
|
MEDIA_SEP: () => MEDIA_SEP,
|
|
@@ -38,11 +37,9 @@ const CSS_FILE_NAME = "__snack.css";
|
|
|
38
37
|
const MEDIA_SEP = "_";
|
|
39
38
|
const cacheDir = (0, import_find_cache_dir.default)({ name: "tamagui", create: true });
|
|
40
39
|
const FAILED_EVAL = Symbol("failed_style_eval");
|
|
41
|
-
const CONCAT_CLASSNAME_IMPORT = "concatClassName";
|
|
42
40
|
const SHOULD_DEBUG = process.env.DEBUG === "*" || ((_a = process.env.DEBUG) == null ? void 0 : _a.startsWith("tamagui"));
|
|
43
41
|
// Annotate the CommonJS export names for ESM import in node:
|
|
44
42
|
0 && (module.exports = {
|
|
45
|
-
CONCAT_CLASSNAME_IMPORT,
|
|
46
43
|
CSS_FILE_NAME,
|
|
47
44
|
FAILED_EVAL,
|
|
48
45
|
MEDIA_SEP,
|
package/dist/constants.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/constants.ts"],
|
|
4
|
-
"sourcesContent": ["import findCacheDir from 'find-cache-dir'\n\nexport const CSS_FILE_NAME = '__snack.css'\n\n// ENSURE THIS ISNT THE SAME AS THE SEPARATOR USED FOR STYLE KEYS\n// SEE matching one in concatClassName\nexport const MEDIA_SEP = '_'\n\n// ensure cache dir\nexport const cacheDir = findCacheDir({ name: 'tamagui', create: true })\n\nexport const FAILED_EVAL = Symbol('failed_style_eval')\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA
|
|
4
|
+
"sourcesContent": ["import findCacheDir from 'find-cache-dir'\n\nexport const CSS_FILE_NAME = '__snack.css'\n\n// ENSURE THIS ISNT THE SAME AS THE SEPARATOR USED FOR STYLE KEYS\n// SEE matching one in concatClassName\nexport const MEDIA_SEP = '_'\n\n// ensure cache dir\nexport const cacheDir = findCacheDir({ name: 'tamagui', create: true })\n\nexport const FAILED_EVAL = Symbol('failed_style_eval')\n\nexport const SHOULD_DEBUG = process.env.DEBUG === '*' || process.env.DEBUG?.startsWith('tamagui')\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAAyB;AAAzB;AAEO,MAAM,gBAAgB;AAItB,MAAM,YAAY;AAGlB,MAAM,eAAW,sBAAAA,SAAa,EAAE,MAAM,WAAW,QAAQ,KAAK,CAAC;AAE/D,MAAM,cAAc,OAAO,mBAAmB;AAE9C,MAAM,eAAe,QAAQ,IAAI,UAAU,SAAO,aAAQ,IAAI,UAAZ,mBAAmB,WAAW;",
|
|
6
6
|
"names": ["findCacheDir"]
|
|
7
7
|
}
|
|
@@ -24,12 +24,26 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
24
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
25
|
var buildClassName_exports = {};
|
|
26
26
|
__export(buildClassName_exports, {
|
|
27
|
-
buildClassName: () => buildClassName
|
|
27
|
+
buildClassName: () => buildClassName,
|
|
28
|
+
buildClassNameLogic: () => buildClassNameLogic
|
|
28
29
|
});
|
|
29
30
|
module.exports = __toCommonJS(buildClassName_exports);
|
|
30
31
|
var t = __toESM(require("@babel/types"));
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
var import_helpers = require("@tamagui/helpers");
|
|
33
|
+
const buildClassName = (objectsIn, extras = "") => {
|
|
34
|
+
let objects = buildClassNameLogic(objectsIn);
|
|
35
|
+
if (!objects)
|
|
36
|
+
return null;
|
|
37
|
+
if (t.isStringLiteral(objects)) {
|
|
38
|
+
objects.value = (0, import_helpers.concatClassName)(objects.value);
|
|
39
|
+
objects.value = `${extras} ${objects.value}`;
|
|
40
|
+
} else {
|
|
41
|
+
objects = t.binaryExpression("+", t.stringLiteral(extras), objects);
|
|
42
|
+
}
|
|
43
|
+
return objects;
|
|
44
|
+
};
|
|
45
|
+
const buildClassNameLogic = (objects) => {
|
|
46
|
+
return objects.reduce((acc, val) => {
|
|
33
47
|
if (acc == null) {
|
|
34
48
|
if (t.isConditionalExpression(val) || t.isStringLiteral(val) || t.isNumericLiteral(val)) {
|
|
35
49
|
return val;
|
|
@@ -71,9 +85,10 @@ function buildClassName(classNameObjects) {
|
|
|
71
85
|
}
|
|
72
86
|
return t.binaryExpression("+", acc, inner);
|
|
73
87
|
}, null);
|
|
74
|
-
}
|
|
88
|
+
};
|
|
75
89
|
// Annotate the CommonJS export names for ESM import in node:
|
|
76
90
|
0 && (module.exports = {
|
|
77
|
-
buildClassName
|
|
91
|
+
buildClassName,
|
|
92
|
+
buildClassNameLogic
|
|
78
93
|
});
|
|
79
94
|
//# sourceMappingURL=buildClassName.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/extractor/buildClassName.ts"],
|
|
4
|
-
"sourcesContent": ["import * as t from '@babel/types'\n\nimport type { ClassNameObject } from '../types.js'\n\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,QAAmB;
|
|
4
|
+
"sourcesContent": ["import * as t from '@babel/types'\nimport { concatClassName } from '@tamagui/helpers'\n\nimport type { ClassNameObject } from '../types.js'\n\ntype Builder = (\n objects: ClassNameObject[],\n extras?: string\n) => t.Expression | t.StringLiteral | null\n\nexport const buildClassName: Builder = (objectsIn, extras = '') => {\n let objects = buildClassNameLogic(objectsIn)\n if (!objects) return null\n if (t.isStringLiteral(objects)) {\n objects.value = concatClassName(objects.value)\n objects.value = `${extras} ${objects.value}`\n } else {\n objects = t.binaryExpression('+', t.stringLiteral(extras), objects)\n }\n return objects\n}\n\nexport const buildClassNameLogic: Builder = (objects) => {\n return objects.reduce<t.Expression | null>((acc, val) => {\n if (acc == null) {\n if (\n // pass conditional expressions through\n t.isConditionalExpression(val) ||\n // pass non-null literals through\n t.isStringLiteral(val) ||\n t.isNumericLiteral(val)\n ) {\n return val\n }\n return t.logicalExpression('||', val, t.stringLiteral(''))\n }\n\n let inner: t.Expression\n if (t.isStringLiteral(val)) {\n if (t.isStringLiteral(acc)) {\n // join adjacent string literals\n return t.stringLiteral(`${acc.value} ${val.value}`)\n }\n inner = t.stringLiteral(` ${val.value}`)\n } else if (t.isLiteral(val)) {\n inner = t.binaryExpression('+', t.stringLiteral(' '), val)\n } else if (t.isConditionalExpression(val) || t.isBinaryExpression(val)) {\n if (t.isStringLiteral(acc)) {\n return t.binaryExpression('+', t.stringLiteral(`${acc.value} `), val)\n }\n inner = t.binaryExpression('+', t.stringLiteral(' '), val)\n } else if (t.isIdentifier(val) || t.isMemberExpression(val)) {\n // identifiers and member expressions make for reasonable ternaries\n inner = t.conditionalExpression(\n val,\n t.binaryExpression('+', t.stringLiteral(' '), val),\n t.stringLiteral('')\n )\n } else {\n if (t.isStringLiteral(acc)) {\n return t.binaryExpression(\n '+',\n t.stringLiteral(`${acc.value} `),\n t.logicalExpression('||', val, t.stringLiteral(''))\n )\n }\n // use a logical expression for more complex prop values\n inner = t.binaryExpression(\n '+',\n t.stringLiteral(' '),\n t.logicalExpression('||', val, t.stringLiteral(''))\n )\n }\n\n return t.binaryExpression('+', acc, inner)\n }, null)\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,QAAmB;AACnB,qBAAgC;AASzB,MAAM,iBAA0B,CAAC,WAAW,SAAS,OAAO;AACjE,MAAI,UAAU,oBAAoB,SAAS;AAC3C,MAAI,CAAC;AAAS,WAAO;AACrB,MAAI,EAAE,gBAAgB,OAAO,GAAG;AAC9B,YAAQ,YAAQ,gCAAgB,QAAQ,KAAK;AAC7C,YAAQ,QAAQ,GAAG,UAAU,QAAQ;AAAA,EACvC,OAAO;AACL,cAAU,EAAE,iBAAiB,KAAK,EAAE,cAAc,MAAM,GAAG,OAAO;AAAA,EACpE;AACA,SAAO;AACT;AAEO,MAAM,sBAA+B,CAAC,YAAY;AACvD,SAAO,QAAQ,OAA4B,CAAC,KAAK,QAAQ;AACvD,QAAI,OAAO,MAAM;AACf,UAEE,EAAE,wBAAwB,GAAG,KAE7B,EAAE,gBAAgB,GAAG,KACrB,EAAE,iBAAiB,GAAG,GACtB;AACA,eAAO;AAAA,MACT;AACA,aAAO,EAAE,kBAAkB,MAAM,KAAK,EAAE,cAAc,EAAE,CAAC;AAAA,IAC3D;AAEA,QAAI;AACJ,QAAI,EAAE,gBAAgB,GAAG,GAAG;AAC1B,UAAI,EAAE,gBAAgB,GAAG,GAAG;AAE1B,eAAO,EAAE,cAAc,GAAG,IAAI,SAAS,IAAI,OAAO;AAAA,MACpD;AACA,cAAQ,EAAE,cAAc,IAAI,IAAI,OAAO;AAAA,IACzC,WAAW,EAAE,UAAU,GAAG,GAAG;AAC3B,cAAQ,EAAE,iBAAiB,KAAK,EAAE,cAAc,GAAG,GAAG,GAAG;AAAA,IAC3D,WAAW,EAAE,wBAAwB,GAAG,KAAK,EAAE,mBAAmB,GAAG,GAAG;AACtE,UAAI,EAAE,gBAAgB,GAAG,GAAG;AAC1B,eAAO,EAAE,iBAAiB,KAAK,EAAE,cAAc,GAAG,IAAI,QAAQ,GAAG,GAAG;AAAA,MACtE;AACA,cAAQ,EAAE,iBAAiB,KAAK,EAAE,cAAc,GAAG,GAAG,GAAG;AAAA,IAC3D,WAAW,EAAE,aAAa,GAAG,KAAK,EAAE,mBAAmB,GAAG,GAAG;AAE3D,cAAQ,EAAE;AAAA,QACR;AAAA,QACA,EAAE,iBAAiB,KAAK,EAAE,cAAc,GAAG,GAAG,GAAG;AAAA,QACjD,EAAE,cAAc,EAAE;AAAA,MACpB;AAAA,IACF,OAAO;AACL,UAAI,EAAE,gBAAgB,GAAG,GAAG;AAC1B,eAAO,EAAE;AAAA,UACP;AAAA,UACA,EAAE,cAAc,GAAG,IAAI,QAAQ;AAAA,UAC/B,EAAE,kBAAkB,MAAM,KAAK,EAAE,cAAc,EAAE,CAAC;AAAA,QACpD;AAAA,MACF;AAEA,cAAQ,EAAE;AAAA,QACR;AAAA,QACA,EAAE,cAAc,GAAG;AAAA,QACnB,EAAE,kBAAkB,MAAM,KAAK,EAAE,cAAc,EAAE,CAAC;AAAA,MACpD;AAAA,IACF;AAEA,WAAO,EAAE,iBAAiB,KAAK,KAAK,KAAK;AAAA,EAC3C,GAAG,IAAI;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -37,21 +37,21 @@ var import_constants = require("../constants.js");
|
|
|
37
37
|
var import_evaluateAstNode = require("./evaluateAstNode.js");
|
|
38
38
|
var import_extractHelpers = require("./extractHelpers.js");
|
|
39
39
|
function createEvaluator({
|
|
40
|
-
|
|
40
|
+
props,
|
|
41
41
|
staticNamespace,
|
|
42
42
|
sourcePath,
|
|
43
43
|
traversePath,
|
|
44
44
|
shouldPrintDebug
|
|
45
45
|
}) {
|
|
46
46
|
const evalFn = (n) => {
|
|
47
|
-
if (t.isMemberExpression(n) && t.isIdentifier(n.property) && traversePath && (0, import_extractHelpers.isValidThemeHook)(traversePath, n, sourcePath)) {
|
|
47
|
+
if (t.isMemberExpression(n) && t.isIdentifier(n.property) && traversePath && (0, import_extractHelpers.isValidThemeHook)(props, traversePath, n, sourcePath)) {
|
|
48
48
|
const key = n.property.name;
|
|
49
49
|
if (shouldPrintDebug) {
|
|
50
50
|
console.log(" > found theme prop", key);
|
|
51
51
|
}
|
|
52
52
|
return (0, import_core_node.createCSSVariable)(key);
|
|
53
53
|
}
|
|
54
|
-
if (t.isIdentifier(n) && staticNamespace
|
|
54
|
+
if (t.isIdentifier(n) && typeof staticNamespace[n.name] !== "undefined") {
|
|
55
55
|
return staticNamespace[n.name];
|
|
56
56
|
}
|
|
57
57
|
const evalContext = import_vm.default.createContext(staticNamespace);
|
|
@@ -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
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAe;AAEf,uBAAqB;AAErB,QAAmB;
|
|
4
|
+
"sourcesContent": ["import vm from 'vm'\n\nimport generate from '@babel/generator'\nimport { NodePath } from '@babel/traverse'\nimport * as t from '@babel/types'\nimport { createCSSVariable } from '@tamagui/core-node'\nimport esbuild from 'esbuild'\n\nimport { FAILED_EVAL } from '../constants.js'\nimport { TamaguiOptionsWithFileInfo } from '../types.js'\nimport { evaluateAstNode } from './evaluateAstNode.js'\nimport { isValidThemeHook } from './extractHelpers.js'\n\nexport function createEvaluator({\n props,\n staticNamespace,\n sourcePath,\n traversePath,\n shouldPrintDebug,\n}: {\n props: TamaguiOptionsWithFileInfo\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 traversePath &&\n isValidThemeHook(props, traversePath, n, sourcePath)\n ) {\n const key = n.property.name\n if (shouldPrintDebug) {\n // eslint-disable-next-line no-console\n console.log(' > found theme prop', key)\n }\n return createCSSVariable(key)\n }\n // variable\n if (t.isIdentifier(n) && typeof staticNamespace[n.name] !== 'undefined') {\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 // eslint-disable-next-line no-console\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;AACnB,uBAAkC;AAClC,qBAAoB;AAEpB,uBAA4B;AAE5B,6BAAgC;AAChC,4BAAiC;AAE1B,SAAS,gBAAgB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAMG;AAED,QAAM,SAAS,CAAC,MAAc;AAE5B,QACE,EAAE,mBAAmB,CAAC,KACtB,EAAE,aAAa,EAAE,QAAQ,KACzB,oBACA,wCAAiB,OAAO,cAAc,GAAG,UAAU,GACnD;AACA,YAAM,MAAM,EAAE,SAAS;AACvB,UAAI,kBAAkB;AAEpB,gBAAQ,IAAI,0BAA0B,GAAG;AAAA,MAC3C;AACA,iBAAO,oCAAkB,GAAG;AAAA,IAC9B;AAEA,QAAI,EAAE,aAAa,CAAC,KAAK,OAAO,gBAAgB,EAAE,UAAU,aAAa;AACvE,aAAO,gBAAgB,EAAE;AAAA,IAC3B;AACA,UAAM,cAAc,UAAAA,QAAG,cAAc,eAAe;AACpD,UAAM,gCAAgC,QAAI,iBAAAC,SAAS,CAAQ,EAAE;AAC7D,UAAM,OAAO,eAAAC,QACV,cAAc,+BAA+B,EAAE,QAAQ,MAAM,CAAC,EAC9D,KAAK,QAAQ,QAAQ,EAAE;AAE1B,QAAI,kBAAkB;AAEpB,cAAQ,IAAI,cAAc,IAAI;AAAA,IAChC;AACA,WAAO,UAAAF,QAAG,aAAa,MAAM,WAAW;AAAA,EAC1C;AAEA,SAAO,CAAC,MAAc;AACpB,eAAO,wCAAgB,GAAG,MAAM;AAAA,EAClC;AACF;AAEO,SAAS,oBAAoB,aAAiC;AACnE,SAAO,CAAC,MAAc;AACpB,QAAI;AACF,aAAO,YAAY,CAAC;AAAA,IACtB,SAAS,KAAP;AACA,aAAO;AAAA,IACT;AAAA,EACF;AACF;",
|
|
6
6
|
"names": ["vm", "generate", "esbuild"]
|
|
7
7
|
}
|
|
@@ -131,7 +131,7 @@ function createExtractor({ logger = console } = { logger: console }) {
|
|
|
131
131
|
prefixLogs,
|
|
132
132
|
excludeProps,
|
|
133
133
|
target,
|
|
134
|
-
...
|
|
134
|
+
...restProps
|
|
135
135
|
} = options;
|
|
136
136
|
let shouldPrintDebug = options.shouldPrintDebug || false;
|
|
137
137
|
if (disable) {
|
|
@@ -146,13 +146,23 @@ function createExtractor({ logger = console } = { logger: console }) {
|
|
|
146
146
|
const isTargetingHTML = target === "html";
|
|
147
147
|
const ogDebug = shouldPrintDebug;
|
|
148
148
|
const tm = (0, import_timer.timer)();
|
|
149
|
+
const propsWithFileInfo = {
|
|
150
|
+
...options,
|
|
151
|
+
sourcePath
|
|
152
|
+
};
|
|
149
153
|
if (shouldPrintDebug === "verbose") {
|
|
150
154
|
console.log("tamagui.config.ts:", { components, config });
|
|
151
155
|
}
|
|
152
156
|
tm.mark("load-tamagui", !!shouldPrintDebug);
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
)
|
|
157
|
+
const firstThemeName = Object.keys(tamaguiConfig.themes)[0];
|
|
158
|
+
const firstTheme = tamaguiConfig.themes[firstThemeName];
|
|
159
|
+
if (!firstTheme || typeof firstTheme !== "object") {
|
|
160
|
+
console.error(`Missing theme, an error occurred when importing your config`);
|
|
161
|
+
console.log(`Got themes:`, tamaguiConfig.themes);
|
|
162
|
+
console.log(`Looking for theme:`, firstThemeName);
|
|
163
|
+
process.exit(0);
|
|
164
|
+
}
|
|
165
|
+
const proxiedTheme = (0, import_core_node.proxyThemeVariables)(firstTheme);
|
|
156
166
|
const themeAccessListeners = /* @__PURE__ */ new Set();
|
|
157
167
|
const defaultTheme = new Proxy(proxiedTheme, {
|
|
158
168
|
get(target2, key) {
|
|
@@ -163,9 +173,6 @@ function createExtractor({ logger = console } = { logger: console }) {
|
|
|
163
173
|
}
|
|
164
174
|
});
|
|
165
175
|
const body = fileOrPath.type === "Program" ? fileOrPath.get("body") : fileOrPath.program.body;
|
|
166
|
-
const isInternalImport = (importStr) => {
|
|
167
|
-
return (0, import_extractHelpers.isInsideTamagui)(sourcePath) && importStr[0] === ".";
|
|
168
|
-
};
|
|
169
176
|
const validComponents = Object.keys(components).filter((key) => {
|
|
170
177
|
var _a;
|
|
171
178
|
return key[0].toUpperCase() === key[0] && !!((_a = components[key]) == null ? void 0 : _a.staticConfig);
|
|
@@ -189,9 +196,9 @@ function createExtractor({ logger = console } = { logger: console }) {
|
|
|
189
196
|
continue;
|
|
190
197
|
const node = "node" in bodyPath ? bodyPath.node : bodyPath;
|
|
191
198
|
const from = node.source.value;
|
|
192
|
-
const
|
|
199
|
+
const valid = (0, import_extractHelpers.isValidImport)(propsWithFileInfo, from);
|
|
193
200
|
if (extractStyledDefinitions) {
|
|
194
|
-
if (
|
|
201
|
+
if (valid) {
|
|
195
202
|
if (node.specifiers.some((specifier) => {
|
|
196
203
|
return specifier.local.name === "styled";
|
|
197
204
|
})) {
|
|
@@ -200,7 +207,7 @@ function createExtractor({ logger = console } = { logger: console }) {
|
|
|
200
207
|
}
|
|
201
208
|
}
|
|
202
209
|
}
|
|
203
|
-
if (
|
|
210
|
+
if (valid) {
|
|
204
211
|
const names = node.specifiers.map((specifier) => specifier.local.name);
|
|
205
212
|
const isValidComponent = names.some((name) => !!(validComponents[name] || validHooks[name]));
|
|
206
213
|
if (shouldPrintDebug === "verbose") {
|
|
@@ -237,20 +244,20 @@ function createExtractor({ logger = console } = { logger: console }) {
|
|
|
237
244
|
};
|
|
238
245
|
callTraverse({
|
|
239
246
|
Program: {
|
|
240
|
-
enter(
|
|
241
|
-
programPath =
|
|
247
|
+
enter(path2) {
|
|
248
|
+
programPath = path2;
|
|
242
249
|
}
|
|
243
250
|
},
|
|
244
|
-
CallExpression(
|
|
251
|
+
CallExpression(path2) {
|
|
245
252
|
var _a, _b;
|
|
246
253
|
if (disable || disableExtraction || extractStyledDefinitions === false) {
|
|
247
254
|
return;
|
|
248
255
|
}
|
|
249
|
-
if (!t.isIdentifier(
|
|
256
|
+
if (!t.isIdentifier(path2.node.callee) || path2.node.callee.name !== "styled") {
|
|
250
257
|
return;
|
|
251
258
|
}
|
|
252
|
-
const name = t.isVariableDeclarator(
|
|
253
|
-
const definition =
|
|
259
|
+
const name = t.isVariableDeclarator(path2.parent) && t.isIdentifier(path2.parent.id) ? path2.parent.id.name : "unknown";
|
|
260
|
+
const definition = path2.node.arguments[1];
|
|
254
261
|
if (!name || !definition || !t.isObjectExpression(definition)) {
|
|
255
262
|
return;
|
|
256
263
|
}
|
|
@@ -273,11 +280,13 @@ function createExtractor({ logger = console } = { logger: console }) {
|
|
|
273
280
|
logger.info([`Loaded`, Object.keys(out2.components).join(", "), !!Component].join(" "));
|
|
274
281
|
}
|
|
275
282
|
} catch (err) {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
283
|
+
if (shouldPrintDebug) {
|
|
284
|
+
logger.info(
|
|
285
|
+
`${(0, import_getPrefixLogs.getPrefixLogs)(
|
|
286
|
+
options
|
|
287
|
+
)} skip optimize styled(${name}), unable to pre-process (DEBUG=tamagui for more)`
|
|
288
|
+
);
|
|
289
|
+
}
|
|
281
290
|
if (process.env.DEBUG === "tamagui") {
|
|
282
291
|
logger.info(
|
|
283
292
|
` Disable this with "disableExtractFoundComponents" in your build-time configuration.
|
|
@@ -302,14 +311,14 @@ function createExtractor({ logger = console } = { logger: console }) {
|
|
|
302
311
|
const skipped = [];
|
|
303
312
|
const styles = {};
|
|
304
313
|
const staticNamespace = (0, import_getStaticBindingsForScope.getStaticBindingsForScope)(
|
|
305
|
-
|
|
314
|
+
path2.scope,
|
|
306
315
|
importsWhitelist,
|
|
307
316
|
sourcePath,
|
|
308
317
|
bindingCache,
|
|
309
318
|
shouldPrintDebug
|
|
310
319
|
);
|
|
311
320
|
const attemptEval = !evaluateVars ? import_evaluateAstNode.evaluateAstNode : (0, import_createEvaluator.createEvaluator)({
|
|
312
|
-
|
|
321
|
+
props: options,
|
|
313
322
|
staticNamespace,
|
|
314
323
|
sourcePath,
|
|
315
324
|
shouldPrintDebug
|
|
@@ -379,18 +388,32 @@ function createExtractor({ logger = console } = { logger: console }) {
|
|
|
379
388
|
const binding = traversePath.scope.getBinding(node.name.name);
|
|
380
389
|
if (binding) {
|
|
381
390
|
if (!t.isImportDeclaration(binding.path.parent)) {
|
|
391
|
+
if (shouldPrintDebug) {
|
|
392
|
+
logger.info(` - Binding not import declaration, skip`);
|
|
393
|
+
}
|
|
382
394
|
return;
|
|
383
395
|
}
|
|
384
396
|
const source = binding.path.parent.source;
|
|
385
|
-
if (!
|
|
397
|
+
if (!(0, import_extractHelpers.isValidImport)(propsWithFileInfo, source.value)) {
|
|
398
|
+
if (shouldPrintDebug) {
|
|
399
|
+
logger.info(` - Binding not internal import or from components ${source.value}`);
|
|
400
|
+
}
|
|
386
401
|
return;
|
|
387
402
|
}
|
|
388
403
|
if (!validComponents[binding.identifier.name]) {
|
|
404
|
+
if (shouldPrintDebug) {
|
|
405
|
+
logger.info(
|
|
406
|
+
` - Binding not valid component (binding.identifier.name) ${binding.identifier.name}`
|
|
407
|
+
);
|
|
408
|
+
}
|
|
389
409
|
return;
|
|
390
410
|
}
|
|
391
411
|
}
|
|
392
412
|
const component = validComponents[node.name.name];
|
|
393
413
|
if (!component || !component.staticConfig) {
|
|
414
|
+
if (shouldPrintDebug) {
|
|
415
|
+
logger.info(` - No Tamagui conf on this: ${node.name.name}`);
|
|
416
|
+
}
|
|
394
417
|
return;
|
|
395
418
|
}
|
|
396
419
|
const originalNodeName = node.name.name;
|
|
@@ -438,8 +461,8 @@ function createExtractor({ logger = console } = { logger: console }) {
|
|
|
438
461
|
return;
|
|
439
462
|
}
|
|
440
463
|
try {
|
|
441
|
-
let evaluateAttribute2 = function(
|
|
442
|
-
const attribute =
|
|
464
|
+
let evaluateAttribute2 = function(path2) {
|
|
465
|
+
const attribute = path2.node;
|
|
443
466
|
const attr = { type: "attr", value: attribute };
|
|
444
467
|
if (t.isJSXSpreadAttribute(attribute)) {
|
|
445
468
|
const arg = attribute.argument;
|
|
@@ -528,9 +551,9 @@ function createExtractor({ logger = console } = { logger: console }) {
|
|
|
528
551
|
}
|
|
529
552
|
const [value, valuePath] = (() => {
|
|
530
553
|
if (t.isJSXExpressionContainer(attribute == null ? void 0 : attribute.value)) {
|
|
531
|
-
return [attribute.value.expression,
|
|
554
|
+
return [attribute.value.expression, path2.get("value")];
|
|
532
555
|
} else {
|
|
533
|
-
return [attribute.value,
|
|
556
|
+
return [attribute.value, path2.get("value")];
|
|
534
557
|
}
|
|
535
558
|
})();
|
|
536
559
|
const remove = () => {
|
|
@@ -546,7 +569,7 @@ function createExtractor({ logger = console } = { logger: console }) {
|
|
|
546
569
|
if (name === "tag") {
|
|
547
570
|
return {
|
|
548
571
|
type: "attr",
|
|
549
|
-
value:
|
|
572
|
+
value: path2.node
|
|
550
573
|
};
|
|
551
574
|
}
|
|
552
575
|
if (disableExtractVariables === true) {
|
|
@@ -605,10 +628,10 @@ function createExtractor({ logger = console } = { logger: console }) {
|
|
|
605
628
|
type: "style",
|
|
606
629
|
value: { [key]: styleValue },
|
|
607
630
|
name: key,
|
|
608
|
-
attr:
|
|
631
|
+
attr: path2.node
|
|
609
632
|
};
|
|
610
633
|
}
|
|
611
|
-
if (import_validHTMLAttributes.validHTMLAttributes[key] || key.startsWith("aria-") || key.startsWith("data-")) {
|
|
634
|
+
if (import_validHTMLAttributes.validHTMLAttributes[key] || key.startsWith("aria-") || key.startsWith("data-") || key === "__source" || key === "__self") {
|
|
612
635
|
return attr;
|
|
613
636
|
}
|
|
614
637
|
if (shouldPrintDebug) {
|
|
@@ -644,7 +667,7 @@ function createExtractor({ logger = console } = { logger: console }) {
|
|
|
644
667
|
type: "style",
|
|
645
668
|
value: { [name]: styleValue },
|
|
646
669
|
name,
|
|
647
|
-
attr:
|
|
670
|
+
attr: path2.node
|
|
648
671
|
};
|
|
649
672
|
} else {
|
|
650
673
|
if (variants[name]) {
|
|
@@ -899,8 +922,8 @@ function createExtractor({ logger = console } = { logger: console }) {
|
|
|
899
922
|
const isTextView = staticConfig.isText || false;
|
|
900
923
|
const validStyles = (staticConfig == null ? void 0 : staticConfig.validStyles) ?? {};
|
|
901
924
|
let tagName = staticConfig.defaultProps.tag ?? (isTextView ? "span" : "div");
|
|
902
|
-
traversePath.get("openingElement").get("attributes").forEach((
|
|
903
|
-
const attr =
|
|
925
|
+
traversePath.get("openingElement").get("attributes").forEach((path2) => {
|
|
926
|
+
const attr = path2.node;
|
|
904
927
|
if (t.isJSXSpreadAttribute(attr))
|
|
905
928
|
return;
|
|
906
929
|
if (attr.name.name !== "tag")
|
|
@@ -912,12 +935,12 @@ function createExtractor({ logger = console } = { logger: console }) {
|
|
|
912
935
|
});
|
|
913
936
|
const flatNode = getFlattenedNode == null ? void 0 : getFlattenedNode({ isTextView, tag: tagName });
|
|
914
937
|
const inlineProps = /* @__PURE__ */ new Set([
|
|
915
|
-
...
|
|
938
|
+
...restProps.inlineProps || [],
|
|
916
939
|
...staticConfig.inlineProps || []
|
|
917
940
|
]);
|
|
918
941
|
const deoptProps = /* @__PURE__ */ new Set([
|
|
919
942
|
"animation",
|
|
920
|
-
...
|
|
943
|
+
...restProps.deoptProps || [],
|
|
921
944
|
...staticConfig.deoptProps || []
|
|
922
945
|
]);
|
|
923
946
|
const inlineWhenUnflattened = /* @__PURE__ */ new Set([...staticConfig.inlineWhenUnflattened || []]);
|
|
@@ -929,7 +952,7 @@ function createExtractor({ logger = console } = { logger: console }) {
|
|
|
929
952
|
shouldPrintDebug
|
|
930
953
|
);
|
|
931
954
|
const attemptEval = !evaluateVars ? import_evaluateAstNode.evaluateAstNode : (0, import_createEvaluator.createEvaluator)({
|
|
932
|
-
|
|
955
|
+
props: options,
|
|
933
956
|
staticNamespace,
|
|
934
957
|
sourcePath,
|
|
935
958
|
traversePath,
|
|
@@ -940,8 +963,8 @@ function createExtractor({ logger = console } = { logger: console }) {
|
|
|
940
963
|
logger.info(` staticNamespace ${Object.keys(staticNamespace).join(", ")}`);
|
|
941
964
|
}
|
|
942
965
|
const flattenedAttrs = [];
|
|
943
|
-
traversePath.get("openingElement").get("attributes").forEach((
|
|
944
|
-
const attr =
|
|
966
|
+
traversePath.get("openingElement").get("attributes").forEach((path2) => {
|
|
967
|
+
const attr = path2.node;
|
|
945
968
|
if (!t.isJSXSpreadAttribute(attr)) {
|
|
946
969
|
flattenedAttrs.push(attr);
|
|
947
970
|
return;
|
|
@@ -995,13 +1018,13 @@ function createExtractor({ logger = console } = { logger: console }) {
|
|
|
995
1018
|
const variantValues = /* @__PURE__ */ new Map();
|
|
996
1019
|
let hasSetOptimized = false;
|
|
997
1020
|
const inlineWhenUnflattenedOGVals = {};
|
|
998
|
-
attrs = traversePath.get("openingElement").get("attributes").flatMap((
|
|
1021
|
+
attrs = traversePath.get("openingElement").get("attributes").flatMap((path2) => {
|
|
999
1022
|
var _a2;
|
|
1000
1023
|
try {
|
|
1001
|
-
const res2 = evaluateAttribute2(
|
|
1024
|
+
const res2 = evaluateAttribute2(path2);
|
|
1002
1025
|
tm.mark("jsx-element-evaluate-attr", !!shouldPrintDebug);
|
|
1003
1026
|
if (!res2) {
|
|
1004
|
-
|
|
1027
|
+
path2.remove();
|
|
1005
1028
|
}
|
|
1006
1029
|
return res2;
|
|
1007
1030
|
} catch (err) {
|
|
@@ -1014,13 +1037,13 @@ function createExtractor({ logger = console } = { logger: console }) {
|
|
|
1014
1037
|
].join(" ")
|
|
1015
1038
|
);
|
|
1016
1039
|
if (shouldPrintDebug === "verbose") {
|
|
1017
|
-
logger.info(`node ${(_a2 =
|
|
1040
|
+
logger.info(`node ${(_a2 = path2.node) == null ? void 0 : _a2.type}`);
|
|
1018
1041
|
}
|
|
1019
1042
|
}
|
|
1020
1043
|
inlined.set(`${Math.random()}`, "spread");
|
|
1021
1044
|
return {
|
|
1022
1045
|
type: "attr",
|
|
1023
|
-
value:
|
|
1046
|
+
value: path2.node
|
|
1024
1047
|
};
|
|
1025
1048
|
}
|
|
1026
1049
|
}).flat(4).filter(import_extractHelpers.isPresent);
|
|
@@ -1375,24 +1398,24 @@ function createExtractor({ logger = console } = { logger: console }) {
|
|
|
1375
1398
|
logger.info([" - foundStaticProps: \n", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(foundStaticProps))].join(" "));
|
|
1376
1399
|
logger.info([" - completeProps: \n", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(completeProps))].join(" "));
|
|
1377
1400
|
}
|
|
1378
|
-
const getStyles = (
|
|
1379
|
-
if (!
|
|
1401
|
+
const getStyles = (props, debugName = "") => {
|
|
1402
|
+
if (!props || !Object.keys(props).length) {
|
|
1380
1403
|
if (shouldPrintDebug)
|
|
1381
1404
|
logger.info([" getStyles() no props"].join(" "));
|
|
1382
1405
|
return {};
|
|
1383
1406
|
}
|
|
1384
1407
|
if (excludeProps && !!excludeProps.size) {
|
|
1385
|
-
for (const key in
|
|
1408
|
+
for (const key in props) {
|
|
1386
1409
|
if (excludeProps.has(key)) {
|
|
1387
1410
|
if (shouldPrintDebug)
|
|
1388
1411
|
logger.info([" delete excluded", key].join(" "));
|
|
1389
|
-
delete
|
|
1412
|
+
delete props[key];
|
|
1390
1413
|
}
|
|
1391
1414
|
}
|
|
1392
1415
|
}
|
|
1393
1416
|
try {
|
|
1394
1417
|
const out = (0, import_core_node.getSplitStyles)(
|
|
1395
|
-
|
|
1418
|
+
props,
|
|
1396
1419
|
staticConfig,
|
|
1397
1420
|
defaultTheme,
|
|
1398
1421
|
{
|