@tamagui/static 1.0.0-alpha.5 → 1.0.0-alpha.50
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 +43 -0
- package/dist/cjs/constants.js.map +7 -0
- package/dist/cjs/extractor/accessSafe.js +39 -0
- package/dist/cjs/extractor/accessSafe.js.map +7 -0
- package/dist/cjs/extractor/babelParse.js +58 -0
- package/dist/cjs/extractor/babelParse.js.map +7 -0
- package/dist/cjs/extractor/buildClassName.js +68 -0
- package/dist/cjs/extractor/buildClassName.js.map +7 -0
- package/dist/cjs/extractor/createEvaluator.js +79 -0
- package/dist/cjs/extractor/createEvaluator.js.map +7 -0
- package/dist/cjs/extractor/createExtractor.js +919 -0
- package/dist/cjs/extractor/createExtractor.js.map +7 -0
- package/dist/cjs/extractor/ensureImportingConcat.js +52 -0
- package/dist/cjs/extractor/ensureImportingConcat.js.map +7 -0
- package/dist/cjs/extractor/evaluateAstNode.js +122 -0
- package/dist/cjs/extractor/evaluateAstNode.js.map +7 -0
- package/dist/cjs/extractor/extractHelpers.js +124 -0
- package/dist/cjs/extractor/extractHelpers.js.map +7 -0
- package/dist/cjs/extractor/extractMediaStyle.js +193 -0
- package/dist/cjs/extractor/extractMediaStyle.js.map +7 -0
- package/dist/cjs/extractor/extractToClassNames.js +289 -0
- package/dist/cjs/extractor/extractToClassNames.js.map +7 -0
- package/dist/cjs/extractor/findTopmostFunction.js +46 -0
- package/dist/cjs/extractor/findTopmostFunction.js.map +7 -0
- package/dist/cjs/extractor/generatedUid.js +56 -0
- package/dist/cjs/extractor/generatedUid.js.map +7 -0
- package/dist/cjs/extractor/getPropValueFromAttributes.js +77 -0
- package/dist/cjs/extractor/getPropValueFromAttributes.js.map +7 -0
- package/dist/cjs/extractor/getSourceModule.js +97 -0
- package/dist/cjs/extractor/getSourceModule.js.map +7 -0
- package/dist/cjs/extractor/getStaticBindingsForScope.js +156 -0
- package/dist/cjs/extractor/getStaticBindingsForScope.js.map +7 -0
- package/dist/cjs/extractor/hoistClassNames.js +72 -0
- package/dist/cjs/extractor/hoistClassNames.js.map +7 -0
- package/dist/cjs/extractor/literalToAst.js +62 -0
- package/dist/cjs/extractor/literalToAst.js.map +7 -0
- package/dist/cjs/extractor/loadTamagui.js +64 -0
- package/dist/cjs/extractor/loadTamagui.js.map +7 -0
- package/dist/cjs/extractor/logLines.js +40 -0
- package/dist/cjs/extractor/logLines.js.map +7 -0
- package/dist/cjs/extractor/normalizeTernaries.js +108 -0
- package/dist/cjs/extractor/normalizeTernaries.js.map +7 -0
- package/dist/cjs/extractor/removeUnusedHooks.js +107 -0
- package/dist/cjs/extractor/removeUnusedHooks.js.map +7 -0
- package/dist/cjs/index.js +38 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/patchReactNativeWeb.js +157 -0
- package/dist/cjs/patchReactNativeWeb.js.map +7 -0
- package/dist/cjs/types.js +21 -0
- package/dist/cjs/types.js.map +7 -0
- package/dist/{constants.js → esm/constants.js} +4 -0
- package/dist/{constants.js.map → esm/constants.js.map} +3 -3
- package/dist/{extractor → esm/extractor}/accessSafe.js +0 -0
- package/dist/{extractor → esm/extractor}/accessSafe.js.map +1 -1
- package/dist/{extractor → esm/extractor}/babelParse.js +0 -0
- package/dist/{extractor → esm/extractor}/babelParse.js.map +1 -1
- package/dist/{extractor → esm/extractor}/buildClassName.js +0 -0
- package/dist/{extractor → esm/extractor}/buildClassName.js.map +1 -1
- package/dist/{extractor → esm/extractor}/createEvaluator.js +1 -1
- package/dist/esm/extractor/createEvaluator.js.map +7 -0
- package/dist/{extractor → esm/extractor}/createExtractor.js +128 -76
- package/dist/esm/extractor/createExtractor.js.map +7 -0
- package/dist/{extractor → esm/extractor}/ensureImportingConcat.js +1 -1
- package/dist/esm/extractor/ensureImportingConcat.js.map +7 -0
- package/dist/{extractor → esm/extractor}/evaluateAstNode.js +0 -0
- package/dist/{extractor → esm/extractor}/evaluateAstNode.js.map +1 -1
- package/dist/{extractor → esm/extractor}/extractHelpers.js +6 -4
- package/dist/{extractor → esm/extractor}/extractHelpers.js.map +3 -3
- package/dist/{extractor → esm/extractor}/extractMediaStyle.js +3 -2
- package/dist/{extractor → esm/extractor}/extractMediaStyle.js.map +2 -2
- package/dist/{extractor → esm/extractor}/extractToClassNames.js +38 -35
- package/dist/esm/extractor/extractToClassNames.js.map +7 -0
- package/dist/{extractor → esm/extractor}/findTopmostFunction.js +0 -0
- package/dist/{extractor → esm/extractor}/findTopmostFunction.js.map +1 -1
- package/dist/{extractor → esm/extractor}/generatedUid.js +0 -0
- package/dist/{extractor → esm/extractor}/generatedUid.js.map +1 -1
- package/dist/{extractor → esm/extractor}/getPropValueFromAttributes.js +0 -0
- package/dist/{extractor → esm/extractor}/getPropValueFromAttributes.js.map +1 -1
- package/dist/{extractor → esm/extractor}/getSourceModule.js +0 -0
- package/dist/{extractor → esm/extractor}/getSourceModule.js.map +1 -1
- package/dist/{extractor → esm/extractor}/getStaticBindingsForScope.js +0 -0
- package/dist/{extractor → esm/extractor}/getStaticBindingsForScope.js.map +1 -1
- package/dist/{extractor → esm/extractor}/hoistClassNames.js +0 -0
- package/dist/{extractor → esm/extractor}/hoistClassNames.js.map +1 -1
- package/dist/{extractor → esm/extractor}/literalToAst.js +0 -0
- package/dist/{extractor → esm/extractor}/literalToAst.js.map +1 -1
- package/dist/{extractor → esm/extractor}/loadTamagui.js +1 -1
- package/dist/esm/extractor/loadTamagui.js.map +7 -0
- package/dist/esm/extractor/logLines.js +17 -0
- package/dist/esm/extractor/logLines.js.map +7 -0
- package/dist/{extractor → esm/extractor}/normalizeTernaries.js +3 -2
- package/dist/{extractor → esm/extractor}/normalizeTernaries.js.map +2 -2
- package/dist/{extractor → esm/extractor}/removeUnusedHooks.js +5 -3
- package/dist/{extractor → esm/extractor}/removeUnusedHooks.js.map +2 -2
- package/dist/{index.js → esm/index.js} +0 -0
- package/dist/{index.js.map → esm/index.js.map} +1 -1
- package/dist/{patchReactNativeWeb.js → esm/patchReactNativeWeb.js} +40 -3
- package/dist/esm/patchReactNativeWeb.js.map +7 -0
- package/dist/{types.js → esm/types.js} +0 -0
- package/dist/{types.js.map → esm/types.js.map} +0 -0
- package/dist/jsx/constants.js +13 -0
- package/dist/jsx/extractor/accessSafe.js +10 -0
- package/dist/jsx/extractor/babelParse.js +29 -0
- package/dist/jsx/extractor/buildClassName.js +39 -0
- package/dist/jsx/extractor/createEvaluator.js +50 -0
- package/dist/jsx/extractor/createExtractor.js +856 -0
- package/dist/jsx/extractor/ensureImportingConcat.js +23 -0
- package/dist/jsx/extractor/evaluateAstNode.js +93 -0
- package/dist/jsx/extractor/extractHelpers.js +95 -0
- package/dist/jsx/extractor/extractMediaStyle.js +151 -0
- package/dist/jsx/extractor/extractToClassNames.js +245 -0
- package/dist/jsx/extractor/findTopmostFunction.js +22 -0
- package/dist/jsx/extractor/generatedUid.js +27 -0
- package/dist/jsx/extractor/getPropValueFromAttributes.js +48 -0
- package/dist/jsx/extractor/getSourceModule.js +68 -0
- package/dist/jsx/extractor/getStaticBindingsForScope.js +127 -0
- package/dist/jsx/extractor/hoistClassNames.js +43 -0
- package/dist/jsx/extractor/literalToAst.js +33 -0
- package/dist/jsx/extractor/loadTamagui.js +40 -0
- package/dist/jsx/extractor/logLines.js +16 -0
- package/dist/jsx/extractor/normalizeTernaries.js +52 -0
- package/dist/jsx/extractor/removeUnusedHooks.js +79 -0
- package/dist/jsx/index.js +13 -0
- package/dist/jsx/patchReactNativeWeb.js +128 -0
- package/dist/jsx/types.js +0 -0
- package/package.json +24 -18
- package/types/constants.d.ts +6 -0
- package/types/constants.d.ts.map +1 -0
- package/types/extractor/accessSafe.d.ts +3 -0
- package/types/extractor/accessSafe.d.ts.map +1 -0
- package/types/extractor/babelParse.d.ts +5 -0
- package/types/extractor/babelParse.d.ts.map +1 -0
- package/types/extractor/buildClassName.d.ts +4 -0
- package/types/extractor/buildClassName.d.ts.map +1 -0
- package/types/extractor/createEvaluator.d.ts +12 -0
- package/types/extractor/createEvaluator.d.ts.map +1 -0
- package/types/extractor/createExtractor.d.ts +33 -0
- package/types/extractor/createExtractor.d.ts.map +1 -0
- package/types/extractor/ensureImportingConcat.d.ts +4 -0
- package/types/extractor/ensureImportingConcat.d.ts.map +1 -0
- package/types/extractor/evaluateAstNode.d.ts +3 -0
- package/types/extractor/evaluateAstNode.d.ts.map +1 -0
- package/types/extractor/extractHelpers.d.ts +12 -0
- package/types/extractor/extractHelpers.d.ts.map +1 -0
- package/types/extractor/extractMediaStyle.d.ts +10 -0
- package/types/extractor/extractMediaStyle.d.ts.map +1 -0
- package/types/extractor/extractToClassNames.d.ts +21 -0
- package/types/extractor/extractToClassNames.d.ts.map +1 -0
- package/types/extractor/findTopmostFunction.d.ts +4 -0
- package/types/extractor/findTopmostFunction.d.ts.map +1 -0
- package/types/extractor/generatedUid.d.ts +5 -0
- package/types/extractor/generatedUid.d.ts.map +1 -0
- package/types/extractor/getPropValueFromAttributes.d.ts +3 -0
- package/types/extractor/getPropValueFromAttributes.d.ts.map +1 -0
- package/types/extractor/getSourceModule.d.ts +16 -0
- package/types/extractor/getSourceModule.d.ts.map +1 -0
- package/types/extractor/getStaticBindingsForScope.d.ts +4 -0
- package/types/extractor/getStaticBindingsForScope.d.ts.map +1 -0
- package/types/extractor/hoistClassNames.d.ts +6 -0
- package/types/extractor/hoistClassNames.d.ts.map +1 -0
- package/types/extractor/literalToAst.d.ts +3 -0
- package/types/extractor/literalToAst.d.ts.map +1 -0
- package/types/extractor/loadTamagui.d.ts +9 -0
- package/types/extractor/loadTamagui.d.ts.map +1 -0
- package/types/extractor/logLines.d.ts +2 -0
- package/types/extractor/logLines.d.ts.map +1 -0
- package/types/extractor/normalizeTernaries.d.ts +3 -0
- package/types/extractor/normalizeTernaries.d.ts.map +1 -0
- package/types/extractor/removeUnusedHooks.d.ts +3 -0
- package/types/extractor/removeUnusedHooks.d.ts.map +1 -0
- package/types/index.d.ts +8 -0
- package/types/index.d.ts.map +1 -0
- package/types/patchReactNativeWeb.d.ts +2 -0
- package/types/patchReactNativeWeb.d.ts.map +1 -0
- package/types/types.d.ts +79 -0
- package/types/types.d.ts.map +1 -0
- package/dist/extractor/createEvaluator.js.map +0 -7
- package/dist/extractor/createExtractor.js.map +0 -7
- package/dist/extractor/ensureImportingConcat.js.map +0 -7
- package/dist/extractor/extractToClassNames.js.map +0 -7
- package/dist/extractor/loadTamagui.js.map +0 -7
- package/dist/index.cjs +0 -2085
- package/dist/index.cjs.map +0 -7
- package/dist/patchReactNativeWeb.js.map +0 -7
- package/src/constants.ts +0 -10
- package/src/extractor/accessSafe.ts +0 -18
- package/src/extractor/babelParse.ts +0 -27
- package/src/extractor/buildClassName.ts +0 -61
- package/src/extractor/createEvaluator.ts +0 -68
- package/src/extractor/createExtractor.ts +0 -1116
- package/src/extractor/ensureImportingConcat.ts +0 -33
- package/src/extractor/evaluateAstNode.ts +0 -121
- package/src/extractor/extractHelpers.ts +0 -102
- package/src/extractor/extractMediaStyle.ts +0 -191
- package/src/extractor/extractToClassNames.ts +0 -337
- package/src/extractor/findTopmostFunction.ts +0 -22
- package/src/extractor/generatedUid.ts +0 -43
- package/src/extractor/getPropValueFromAttributes.ts +0 -92
- package/src/extractor/getSourceModule.ts +0 -101
- package/src/extractor/getStaticBindingsForScope.ts +0 -173
- package/src/extractor/hoistClassNames.ts +0 -45
- package/src/extractor/literalToAst.ts +0 -32
- package/src/extractor/loadTamagui.ts +0 -61
- package/src/extractor/normalizeTernaries.ts +0 -60
- package/src/extractor/removeUnusedHooks.ts +0 -76
- package/src/index.ts +0 -9
- package/src/patchReactNativeWeb.ts +0 -107
- package/src/types.ts +0 -80
- package/types.d.ts +0 -210
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/extractor/ensureImportingConcat.ts"],
|
|
4
|
+
"sourcesContent": ["import { NodePath } from '@babel/traverse'\nimport * as t from '@babel/types'\n\nimport { CONCAT_CLASSNAME_IMPORT } from '../constants'\n\nconst importConcatPkg = '@tamagui/helpers'\n\nexport function ensureImportingConcat(path: NodePath<t.Program>) {\n const bodyPath = path.get('body')\n const imported: NodePath<t.ImportDeclaration> | undefined = bodyPath.find(\n (x) => x.isImportDeclaration() && x.node.source.value === importConcatPkg\n ) as any\n const importSpecifier = t.importSpecifier(\n t.identifier(CONCAT_CLASSNAME_IMPORT),\n t.identifier(CONCAT_CLASSNAME_IMPORT)\n )\n\n if (!imported) {\n path.node.body.push(t.importDeclaration([importSpecifier], t.stringLiteral(importConcatPkg)))\n return\n }\n\n const specifiers = imported.node.specifiers\n const alreadyImported = specifiers.some(\n (x) =>\n t.isImportSpecifier(x) &&\n t.isIdentifier(x.imported) &&\n x.imported.name === CONCAT_CLASSNAME_IMPORT\n )\n\n if (!alreadyImported) {\n specifiers.push(\n t.importSpecifier(\n t.identifier(CONCAT_CLASSNAME_IMPORT),\n t.identifier(CONCAT_CLASSNAME_IMPORT)\n )\n )\n }\n}\n"],
|
|
5
|
+
"mappings": ";;AACA;AAEA;AAEA,MAAM,kBAAkB;AAEjB,+BAA+B,MAA2B;AAC/D,QAAM,WAAW,KAAK,IAAI;AAC1B,QAAM,WAAsD,SAAS,KACnE,CAAC,MAAM,EAAE,yBAAyB,EAAE,KAAK,OAAO,UAAU;AAE5D,QAAM,kBAAkB,EAAE,gBACxB,EAAE,WAAW,0BACb,EAAE,WAAW;AAGf,MAAI,CAAC,UAAU;AACb,SAAK,KAAK,KAAK,KAAK,EAAE,kBAAkB,CAAC,kBAAkB,EAAE,cAAc;AAC3E;AAAA;AAGF,QAAM,aAAa,SAAS,KAAK;AACjC,QAAM,kBAAkB,WAAW,KACjC,CAAC,MACC,EAAE,kBAAkB,MACpB,EAAE,aAAa,EAAE,aACjB,EAAE,SAAS,SAAS;AAGxB,MAAI,CAAC,iBAAiB;AACpB,eAAW,KACT,EAAE,gBACA,EAAE,WAAW,0BACb,EAAE,WAAW;AAAA;AAAA;AA3BL;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
File without changes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["
|
|
3
|
+
"sources": ["../../../src/extractor/evaluateAstNode.ts"],
|
|
4
4
|
"sourcesContent": ["import * as t from '@babel/types'\n\nexport function evaluateAstNode(\n exprNode: t.Node | undefined | null,\n evalFn?: (node: t.Node) => any,\n shouldPrintDebug?: boolean\n): any {\n if (exprNode === undefined) {\n return undefined\n }\n\n // null === boolean true (at least in our use cases for jsx eval)\n if (exprNode === null) {\n return true\n }\n\n if (t.isJSXExpressionContainer(exprNode)) {\n return evaluateAstNode(exprNode.expression)\n }\n\n // loop through ObjectExpression keys\n if (t.isObjectExpression(exprNode)) {\n const ret: Record<string, any> = {}\n for (let idx = -1, len = exprNode.properties.length; ++idx < len; ) {\n const value = exprNode.properties[idx]\n\n if (!t.isObjectProperty(value)) {\n throw new Error('evaluateAstNode can only evaluate object properties')\n }\n\n let key: string | number | null | undefined | boolean\n if (value.computed) {\n if (typeof evalFn !== 'function') {\n throw new Error(\n 'evaluateAstNode does not support computed keys unless an eval function is provided'\n )\n }\n key = evaluateAstNode(value.key, evalFn)\n } else if (t.isIdentifier(value.key)) {\n key = value.key.name\n } else if (t.isStringLiteral(value.key) || t.isNumericLiteral(value.key)) {\n key = value.key.value\n } else {\n throw new Error('Unsupported key type: ' + value.key.type)\n }\n\n if (typeof key !== 'string' && typeof key !== 'number') {\n throw new Error('key must be either a string or a number')\n }\n\n ret[key] = evaluateAstNode(value.value, evalFn)\n }\n return ret\n }\n\n if (t.isArrayExpression(exprNode)) {\n return exprNode.elements.map((x) => {\n return evaluateAstNode(x as any, evalFn)\n })\n }\n\n if (t.isUnaryExpression(exprNode) && exprNode.operator === '-') {\n const ret = evaluateAstNode(exprNode.argument, evalFn)\n if (ret == null) {\n return null\n }\n return -ret\n }\n\n if (t.isTemplateLiteral(exprNode)) {\n if (typeof evalFn !== 'function') {\n throw new Error(\n 'evaluateAstNode does not support template literals unless an eval function is provided'\n )\n }\n\n let ret: string = ''\n for (let idx = -1, len = exprNode.quasis.length; ++idx < len; ) {\n const quasi = exprNode.quasis[idx]\n const expr = exprNode.expressions[idx]\n ret += quasi.value.raw\n if (expr) {\n ret += evaluateAstNode(expr, evalFn)\n }\n }\n return ret\n }\n\n // In the interest of representing the \"evaluated\" prop\n // as the user intended, we support negative null. Why not.\n if (t.isNullLiteral(exprNode)) {\n return null\n }\n\n if (t.isNumericLiteral(exprNode) || t.isStringLiteral(exprNode) || t.isBooleanLiteral(exprNode)) {\n // In the interest of representing the \"evaluated\" prop\n // as the user intended, we support negative null. Why not.\n return exprNode.value\n }\n\n if (t.isBinaryExpression(exprNode)) {\n if (exprNode.operator === '+') {\n return evaluateAstNode(exprNode.left, evalFn) + evaluateAstNode(exprNode.right, evalFn)\n } else if (exprNode.operator === '-') {\n return evaluateAstNode(exprNode.left, evalFn) - evaluateAstNode(exprNode.right, evalFn)\n } else if (exprNode.operator === '*') {\n return evaluateAstNode(exprNode.left, evalFn) * evaluateAstNode(exprNode.right, evalFn)\n } else if (exprNode.operator === '/') {\n return evaluateAstNode(exprNode.left, evalFn) / evaluateAstNode(exprNode.right, evalFn)\n }\n }\n\n // if we've made it this far, the value has to be evaluated\n if (typeof evalFn !== 'function') {\n throw new Error(\n 'evaluateAstNode does not support non-literal values unless an eval function is provided'\n )\n }\n\n return evalFn(exprNode)\n}\n"],
|
|
5
5
|
"mappings": ";;AAAA;AAEO,yBACL,UACA,QACA,kBACK;AACL,MAAI,aAAa,QAAW;AAC1B,WAAO;AAAA;AAIT,MAAI,aAAa,MAAM;AACrB,WAAO;AAAA;AAGT,MAAI,EAAE,yBAAyB,WAAW;AACxC,WAAO,gBAAgB,SAAS;AAAA;AAIlC,MAAI,EAAE,mBAAmB,WAAW;AAClC,UAAM,MAA2B;AACjC,aAAS,MAAM,IAAI,MAAM,SAAS,WAAW,QAAQ,EAAE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,cAAc,WAAW;AAC7B,WAAO;AAAA;AAGT,MAAI,EAAE,iBAAiB,aAAa,EAAE,gBAAgB,aAAa,EAAE,iBAAiB,WAAW;AAG/F,WAAO,SAAS;AAAA;AAGlB,MAAI,EAAE,mBAAmB,WAAW;AAClC,QAAI,SAAS,aAAa,KAAK;AAC7B,aAAO,gBAAgB,SAAS,MAAM,UAAU,gBAAgB,SAAS,OAAO;AAAA,eACvE,SAAS,aAAa,KAAK;AACpC,aAAO,gBAAgB,SAAS,MAAM,UAAU,gBAAgB,SAAS,OAAO;AAAA,eACvE,SAAS,aAAa,KAAK;AACpC,aAAO,gBAAgB,SAAS,MAAM,UAAU,gBAAgB,SAAS,OAAO;AAAA,eACvE,SAAS,aAAa,KAAK;AACpC,aAAO,gBAAgB,SAAS,MAAM,UAAU,gBAAgB,SAAS,OAAO;AAAA;AAAA;AAKpF,MAAI,OAAO,WAAW,YAAY;AAChC,UAAM,IAAI,MACR;AAAA;AAIJ,SAAO,OAAO;AAAA;AArHA;",
|
|
6
6
|
"names": []
|
|
@@ -30,6 +30,7 @@ const ternaryStr = /* @__PURE__ */ __name((x) => {
|
|
|
30
30
|
].flat().join("");
|
|
31
31
|
}, "ternaryStr");
|
|
32
32
|
function findComponentName(scope) {
|
|
33
|
+
var _a;
|
|
33
34
|
let componentName = "";
|
|
34
35
|
let cur = scope.path;
|
|
35
36
|
while (cur.parentPath && !t.isProgram(cur.parentPath.parent)) {
|
|
@@ -46,17 +47,18 @@ function findComponentName(scope) {
|
|
|
46
47
|
}
|
|
47
48
|
}
|
|
48
49
|
if (t.isFunctionDeclaration(node)) {
|
|
49
|
-
return node.id
|
|
50
|
+
return (_a = node.id) == null ? void 0 : _a.name;
|
|
50
51
|
}
|
|
51
52
|
return componentName;
|
|
52
53
|
}
|
|
53
54
|
__name(findComponentName, "findComponentName");
|
|
54
55
|
function isValidThemeHook(jsxPath, n, sourcePath) {
|
|
56
|
+
var _a;
|
|
55
57
|
if (!t.isIdentifier(n.object) || !t.isIdentifier(n.property))
|
|
56
58
|
return false;
|
|
57
59
|
const bindings = jsxPath.scope.getAllBindings();
|
|
58
60
|
const binding = bindings[n.object.name];
|
|
59
|
-
if (!binding
|
|
61
|
+
if (!(binding == null ? void 0 : binding.path))
|
|
60
62
|
return false;
|
|
61
63
|
if (!binding.path.isVariableDeclarator())
|
|
62
64
|
return false;
|
|
@@ -67,7 +69,7 @@ function isValidThemeHook(jsxPath, n, sourcePath) {
|
|
|
67
69
|
return false;
|
|
68
70
|
if (init.callee.name !== "useTheme")
|
|
69
71
|
return false;
|
|
70
|
-
const importNode = binding.scope.getBinding("useTheme")
|
|
72
|
+
const importNode = (_a = binding.scope.getBinding("useTheme")) == null ? void 0 : _a.path.parent;
|
|
71
73
|
if (!t.isImportDeclaration(importNode))
|
|
72
74
|
return false;
|
|
73
75
|
if (importNode.source.value !== "tamagui") {
|
|
@@ -79,7 +81,7 @@ function isValidThemeHook(jsxPath, n, sourcePath) {
|
|
|
79
81
|
}
|
|
80
82
|
__name(isValidThemeHook, "isValidThemeHook");
|
|
81
83
|
const isInsideTamagui = /* @__PURE__ */ __name((srcName) => {
|
|
82
|
-
return srcName.includes("/
|
|
84
|
+
return srcName.includes("/dist/jsx") || srcName.includes("/core/src");
|
|
83
85
|
}, "isInsideTamagui");
|
|
84
86
|
export {
|
|
85
87
|
attrStr,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["
|
|
4
|
-
"sourcesContent": ["import type { NodePath } from '@babel/traverse'\nimport * as t from '@babel/types'\n\nimport { ExtractedAttr, Ternary } from '../types'\n\nexport function isPresent<T extends Object>(input: null | void | undefined | T): input is T {\n return input != null\n}\n\nexport function isSimpleSpread(node: t.JSXSpreadAttribute) {\n return t.isIdentifier(node.argument) || t.isMemberExpression(node.argument)\n}\n\nexport const attrStr = (attr: ExtractedAttr) => {\n return attr.type === 'attr'\n ? getNameAttr(attr.value)\n : attr.type === 'ternary'\n ? `...${ternaryStr(attr.value)}`\n : `${attr.type}(${objToStr(attr.value)})`\n}\n\nexport const objToStr = (obj: any) => {\n return Object.entries(obj)\n .map(\n ([k, v]) =>\n `${k}:${Array.isArray(v) ? `[...]` : v && typeof v === 'object' ? `{${objToStr(v)}}` : v}`\n )\n .join(', ')\n}\n\nconst getNameAttr = (attr: t.JSXAttribute | t.JSXSpreadAttribute) => {\n if (t.isJSXSpreadAttribute(attr)) {\n return `...${attr.argument['name']}`\n }\n return 'name' in attr ? attr.name.name : `unknown-${attr['type']}`\n}\n\nexport const ternaryStr = (x: Ternary) => {\n return [\n 'ternary:',\n t.isIdentifier(x.test)\n ? x.test.name\n : t.isMemberExpression(x.test)\n ? [x.test.object['name'], x.test.property['name']]\n : x.test,\n x.consequent ? ` ? ${objToStr(x.consequent)}` : ' ? \u26AB\uFE0F',\n x.alternate ? ` : ${objToStr(x.alternate)}` : ' : \u26AB\uFE0F',\n ]\n .flat()\n .join('')\n}\n\nexport function findComponentName(scope) {\n let componentName = ''\n let cur = scope.path\n while (cur.parentPath && !t.isProgram(cur.parentPath.parent)) {\n cur = cur.parentPath\n }\n let node = cur.parent\n if (t.isExportNamedDeclaration(node)) {\n node = node.declaration\n }\n if (t.isVariableDeclaration(node)) {\n const [dec] = node.declarations\n if (t.isVariableDeclarator(dec) && t.isIdentifier(dec.id)) {\n return dec.id.name\n }\n }\n if (t.isFunctionDeclaration(node)) {\n return node.id?.name\n }\n return componentName\n}\n\nexport function isValidThemeHook(\n jsxPath: NodePath<t.JSXElement>,\n n: t.MemberExpression,\n sourcePath: string\n) {\n if (!t.isIdentifier(n.object) || !t.isIdentifier(n.property)) return false\n const bindings = jsxPath.scope.getAllBindings()\n const binding = bindings[n.object.name]\n if (!binding?.path) return false\n if (!binding.path.isVariableDeclarator()) return false\n const init = binding.path.node.init\n if (!t.isCallExpression(init)) return false\n if (!t.isIdentifier(init.callee)) return false\n // TODO could support renaming useTheme by looking up import first\n if (init.callee.name !== 'useTheme') return false\n const importNode = binding.scope.getBinding('useTheme')?.path.parent\n if (!t.isImportDeclaration(importNode)) return false\n if (importNode.source.value !== 'tamagui') {\n if (!isInsideTamagui(sourcePath)) {\n return false\n }\n }\n return true\n}\n\nexport const isInsideTamagui = (srcName: string) => {\n return srcName.includes('/
|
|
5
|
-
"mappings": ";;AACA;AAIO,mBAAqC,OAAgD;AAC1F,SAAO,SAAS;AAAA;AADF;AAIT,wBAAwB,MAA4B;AACzD,SAAO,EAAE,aAAa,KAAK,aAAa,EAAE,mBAAmB,KAAK;AAAA;AADpD;AAIT,MAAM,UAAU,wBAAC,SAAwB;AAC9C,SAAO,KAAK,SAAS,SACjB,YAAY,KAAK,SACjB,KAAK,SAAS,YACd,MAAM,WAAW,KAAK,WACtB,GAAG,KAAK,QAAQ,SAAS,KAAK;AAAA,GALb;AAQhB,MAAM,WAAW,wBAAC,QAAa;AACpC,SAAO,OAAO,QAAQ,KACnB,IACC,CAAC,CAAC,GAAG,OACH,GAAG,KAAK,MAAM,QAAQ,KAAK,UAAU,KAAK,OAAO,MAAM,WAAW,IAAI,SAAS,QAAQ,KAE1F,KAAK;AAAA,GANc;AASxB,MAAM,cAAc,wBAAC,SAAgD;AACnE,MAAI,EAAE,qBAAqB,OAAO;AAChC,WAAO,MAAM,KAAK,SAAS;AAAA;AAE7B,SAAO,UAAU,OAAO,KAAK,KAAK,OAAO,WAAW,KAAK;AAAA,GAJvC;AAOb,MAAM,aAAa,wBAAC,MAAe;AACxC,SAAO;AAAA,IACL;AAAA,IACA,EAAE,aAAa,EAAE,QACb,EAAE,KAAK,OACP,EAAE,mBAAmB,EAAE,QACvB,CAAC,EAAE,KAAK,OAAO,SAAS,EAAE,KAAK,SAAS,WACxC,EAAE;AAAA,IACN,EAAE,aAAa,OAAO,SAAS,EAAE,gBAAgB;AAAA,IACjD,EAAE,YAAY,OAAO,SAAS,EAAE,eAAe;AAAA,IAE9C,OACA,KAAK;AAAA,GAZgB;AAenB,2BAA2B,OAAO;
|
|
3
|
+
"sources": ["../../../src/extractor/extractHelpers.ts"],
|
|
4
|
+
"sourcesContent": ["import type { NodePath } from '@babel/traverse'\nimport * as t from '@babel/types'\n\nimport { ExtractedAttr, Ternary } from '../types'\n\nexport function isPresent<T extends Object>(input: null | void | undefined | T): input is T {\n return input != null\n}\n\nexport function isSimpleSpread(node: t.JSXSpreadAttribute) {\n return t.isIdentifier(node.argument) || t.isMemberExpression(node.argument)\n}\n\nexport const attrStr = (attr: ExtractedAttr) => {\n return attr.type === 'attr'\n ? getNameAttr(attr.value)\n : attr.type === 'ternary'\n ? `...${ternaryStr(attr.value)}`\n : `${attr.type}(${objToStr(attr.value)})`\n}\n\nexport const objToStr = (obj: any) => {\n return Object.entries(obj)\n .map(\n ([k, v]) =>\n `${k}:${Array.isArray(v) ? `[...]` : v && typeof v === 'object' ? `{${objToStr(v)}}` : v}`\n )\n .join(', ')\n}\n\nconst getNameAttr = (attr: t.JSXAttribute | t.JSXSpreadAttribute) => {\n if (t.isJSXSpreadAttribute(attr)) {\n return `...${attr.argument['name']}`\n }\n return 'name' in attr ? attr.name.name : `unknown-${attr['type']}`\n}\n\nexport const ternaryStr = (x: Ternary) => {\n return [\n 'ternary:',\n t.isIdentifier(x.test)\n ? x.test.name\n : t.isMemberExpression(x.test)\n ? [x.test.object['name'], x.test.property['name']]\n : x.test,\n x.consequent ? ` ? ${objToStr(x.consequent)}` : ' ? \u26AB\uFE0F',\n x.alternate ? ` : ${objToStr(x.alternate)}` : ' : \u26AB\uFE0F',\n ]\n .flat()\n .join('')\n}\n\nexport function findComponentName(scope) {\n let componentName = ''\n let cur = scope.path\n while (cur.parentPath && !t.isProgram(cur.parentPath.parent)) {\n cur = cur.parentPath\n }\n let node = cur.parent\n if (t.isExportNamedDeclaration(node)) {\n node = node.declaration\n }\n if (t.isVariableDeclaration(node)) {\n const [dec] = node.declarations\n if (t.isVariableDeclarator(dec) && t.isIdentifier(dec.id)) {\n return dec.id.name\n }\n }\n if (t.isFunctionDeclaration(node)) {\n return node.id?.name\n }\n return componentName\n}\n\nexport function isValidThemeHook(\n jsxPath: NodePath<t.JSXElement>,\n n: t.MemberExpression,\n sourcePath: string\n) {\n if (!t.isIdentifier(n.object) || !t.isIdentifier(n.property)) return false\n const bindings = jsxPath.scope.getAllBindings()\n const binding = bindings[n.object.name]\n if (!binding?.path) return false\n if (!binding.path.isVariableDeclarator()) return false\n const init = binding.path.node.init\n if (!t.isCallExpression(init)) return false\n if (!t.isIdentifier(init.callee)) return false\n // TODO could support renaming useTheme by looking up import first\n if (init.callee.name !== 'useTheme') return false\n const importNode = binding.scope.getBinding('useTheme')?.path.parent\n if (!t.isImportDeclaration(importNode)) return false\n if (importNode.source.value !== 'tamagui') {\n if (!isInsideTamagui(sourcePath)) {\n return false\n }\n }\n return true\n}\n\nexport const isInsideTamagui = (srcName: string) => {\n return srcName.includes('/dist/jsx') || srcName.includes('/core/src')\n}\n"],
|
|
5
|
+
"mappings": ";;AACA;AAIO,mBAAqC,OAAgD;AAC1F,SAAO,SAAS;AAAA;AADF;AAIT,wBAAwB,MAA4B;AACzD,SAAO,EAAE,aAAa,KAAK,aAAa,EAAE,mBAAmB,KAAK;AAAA;AADpD;AAIT,MAAM,UAAU,wBAAC,SAAwB;AAC9C,SAAO,KAAK,SAAS,SACjB,YAAY,KAAK,SACjB,KAAK,SAAS,YACd,MAAM,WAAW,KAAK,WACtB,GAAG,KAAK,QAAQ,SAAS,KAAK;AAAA,GALb;AAQhB,MAAM,WAAW,wBAAC,QAAa;AACpC,SAAO,OAAO,QAAQ,KACnB,IACC,CAAC,CAAC,GAAG,OACH,GAAG,KAAK,MAAM,QAAQ,KAAK,UAAU,KAAK,OAAO,MAAM,WAAW,IAAI,SAAS,QAAQ,KAE1F,KAAK;AAAA,GANc;AASxB,MAAM,cAAc,wBAAC,SAAgD;AACnE,MAAI,EAAE,qBAAqB,OAAO;AAChC,WAAO,MAAM,KAAK,SAAS;AAAA;AAE7B,SAAO,UAAU,OAAO,KA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aAAa,KAAK;AAAS,WAAO;AAEzC,MAAI,KAAK,OAAO,SAAS;AAAY,WAAO;AAC5C,QAAM,aAAa,cAAQ,MAAM,WAAW,gBAAzB,mBAAsC,KAAK;AAC9D,MAAI,CAAC,EAAE,oBAAoB;AAAa,WAAO;AAC/C,MAAI,WAAW,OAAO,UAAU,WAAW;AACzC,QAAI,CAAC,gBAAgB,aAAa;AAChC,aAAO;AAAA;AAAA;AAGX,SAAO;AAAA;AAtBO;AAyBT,MAAM,kBAAkB,wBAAC,YAAoB;AAClD,SAAO,QAAQ,SAAS,gBAAgB,QAAQ,SAAS;AAAA,GAD5B;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -90,6 +90,7 @@ function getMediaQueryTernary(ternary, jsxPath, sourcePath) {
|
|
|
90
90
|
}
|
|
91
91
|
__name(getMediaQueryTernary, "getMediaQueryTernary");
|
|
92
92
|
function getMediaInfoFromExpression(test, jsxPath, sourcePath, inlineMediaQuery) {
|
|
93
|
+
var _a, _b, _c;
|
|
93
94
|
if (inlineMediaQuery) {
|
|
94
95
|
return {
|
|
95
96
|
key: inlineMediaQuery,
|
|
@@ -103,7 +104,7 @@ function getMediaInfoFromExpression(test, jsxPath, sourcePath, inlineMediaQuery)
|
|
|
103
104
|
const binding = bindings[name];
|
|
104
105
|
if (!binding)
|
|
105
106
|
return false;
|
|
106
|
-
const bindingNode = binding.path
|
|
107
|
+
const bindingNode = (_a = binding.path) == null ? void 0 : _a.node;
|
|
107
108
|
if (!t.isVariableDeclarator(bindingNode) || !bindingNode.init)
|
|
108
109
|
return false;
|
|
109
110
|
if (!isValidMediaCall(jsxPath, bindingNode.init, sourcePath))
|
|
@@ -112,7 +113,7 @@ function getMediaInfoFromExpression(test, jsxPath, sourcePath, inlineMediaQuery)
|
|
|
112
113
|
}
|
|
113
114
|
if (t.isIdentifier(test)) {
|
|
114
115
|
const key = test.name;
|
|
115
|
-
const node = jsxPath.scope.getBinding(test.name)
|
|
116
|
+
const node = (_c = (_b = jsxPath.scope.getBinding(test.name)) == null ? void 0 : _b.path) == null ? void 0 : _c.node;
|
|
116
117
|
if (!t.isVariableDeclarator(node))
|
|
117
118
|
return false;
|
|
118
119
|
if (!node.init || !isValidMediaCall(jsxPath, node.init, sourcePath))
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["
|
|
3
|
+
"sources": ["../../../src/extractor/extractMediaStyle.ts"],
|
|
4
4
|
"sourcesContent": ["import { NodePath } from '@babel/traverse'\nimport * as t from '@babel/types'\nimport type { TamaguiInternalConfig } from '@tamagui/core'\nimport { getStylesAtomic, mediaObjectToString } from '@tamagui/core-node'\nimport { ViewStyle } from 'react-native'\n\nimport { MEDIA_SEP } from '../constants'\nimport { StyleObject, Ternary } from '../types'\nimport { isInsideTamagui, isPresent } from './extractHelpers'\n\nexport function extractMediaStyle(\n ternary: Ternary,\n jsxPath: NodePath<t.JSXElement>,\n tamaguiConfig: TamaguiInternalConfig,\n sourcePath: string,\n importance = 0,\n shouldPrintDebug = false\n) {\n const mt = getMediaQueryTernary(ternary, jsxPath, sourcePath)\n if (!mt) {\n return null\n }\n const { key } = mt\n const mq = tamaguiConfig.media[key]\n if (!mq) {\n console.error(`Media query \"${key}\" not found: ${Object.keys(tamaguiConfig.media)}`)\n return null\n }\n const getStyleObj = (styleObj: ViewStyle | null, negate = false) => {\n return styleObj ? { styleObj, negate } : null\n }\n const styleOpts = [\n getStyleObj(ternary.consequent, false),\n getStyleObj(ternary.alternate, true),\n ].filter(isPresent)\n if (shouldPrintDebug && !styleOpts.length) {\n console.log(' media query, no styles?')\n return null\n }\n // for now order first strongest\n const mediaKeys = Object.keys(tamaguiConfig.media)\n const mediaKeyPrecendence = mediaKeys.reduce((acc, cur, i) => {\n acc[cur] = new Array(importance + 1).fill(':root').join('')\n return acc\n }, {})\n let mediaStyles: StyleObject[] = []\n for (const { styleObj, negate } of styleOpts) {\n const styles = getStylesAtomic(styleObj)\n const singleMediaStyles = styles.map((style) => {\n const negKey = negate ? '0' : ''\n const ogPrefix = style.identifier.slice(0, style.identifier.indexOf('-') + 1)\n // adds an extra separator before and after to detect later in concatClassName\n // so it goes from: \"_f-[hash]\"\n // to: \"_f-_sm0_[hash]\" or \"_f-_sm_[hash]\"\n const identifier = `${style.identifier.replace(\n ogPrefix,\n `${ogPrefix}${MEDIA_SEP}${key}${negKey}${MEDIA_SEP}`\n )}`\n const className = `.${identifier}`\n const mediaSelector = mediaObjectToString(tamaguiConfig.media[key])\n const screenStr = negate ? 'not all' : 'screen'\n const mediaQuery = `${screenStr} and ${mediaSelector}`\n const precendencePrefix = mediaKeyPrecendence[key]\n const styleInner = style.rules[0].replace(style.identifier, identifier)\n // combines media queries if they already exist\n let styleRule = ''\n if (styleInner.includes('@media')) {\n // combine\n styleRule = styleInner.replace('{', ` and ${mediaQuery} {`)\n } else {\n styleRule = `@media ${mediaQuery} { ${precendencePrefix} ${styleInner} }`\n }\n return {\n ...style,\n identifier,\n className,\n rules: [styleRule],\n }\n })\n if (shouldPrintDebug) {\n // prettier-ignore\n console.log(' media styles:', importance, singleMediaStyles.map(x => x.identifier).join(', '))\n }\n // add to output\n mediaStyles = [...mediaStyles, ...singleMediaStyles]\n }\n // filter out\n ternary.remove()\n return { mediaStyles, ternaryWithoutMedia: mt.ternaryWithoutMedia }\n}\n\nfunction getMediaQueryTernary(\n ternary: Ternary,\n jsxPath: NodePath<t.JSXElement>,\n sourcePath: string\n): null | {\n key: string\n bindingName: string\n ternaryWithoutMedia: Ternary | null\n} {\n // this handles unwrapping logical && media query ternarys\n // first, unwrap if it has media logicalExpression\n if (t.isLogicalExpression(ternary.test) && ternary.test.operator === '&&') {\n // *should* be normalized to always be on left side, TODO verify\n const mediaLeft = getMediaInfoFromExpression(\n ternary.test.left,\n jsxPath,\n sourcePath,\n ternary.inlineMediaQuery\n )\n if (mediaLeft) {\n return {\n ...mediaLeft,\n ternaryWithoutMedia: {\n ...ternary,\n test: ternary.test.right,\n },\n }\n }\n }\n // const media = useMedia()\n // ... media.sm\n const result = getMediaInfoFromExpression(\n ternary.test,\n jsxPath,\n sourcePath,\n ternary.inlineMediaQuery\n )\n if (result) {\n return {\n ...result,\n ternaryWithoutMedia: null,\n }\n }\n return null\n}\n\nfunction getMediaInfoFromExpression(\n test: t.Expression,\n jsxPath: NodePath<t.JSXElement>,\n sourcePath: string,\n inlineMediaQuery?: string\n) {\n if (inlineMediaQuery) {\n return {\n key: inlineMediaQuery,\n bindingName: inlineMediaQuery,\n }\n }\n if (t.isMemberExpression(test) && t.isIdentifier(test.object) && t.isIdentifier(test.property)) {\n const name = test.object['name']\n const key = test.property['name']\n const bindings = jsxPath.scope.getAllBindings()\n const binding = bindings[name]\n if (!binding) return false\n const bindingNode = binding.path?.node\n if (!t.isVariableDeclarator(bindingNode) || !bindingNode.init) return false\n if (!isValidMediaCall(jsxPath, bindingNode.init, sourcePath)) return false\n return { key, bindingName: name }\n }\n if (t.isIdentifier(test)) {\n const key = test.name\n const node = jsxPath.scope.getBinding(test.name)?.path?.node\n if (!t.isVariableDeclarator(node)) return false\n if (!node.init || !isValidMediaCall(jsxPath, node.init, sourcePath)) return false\n return { key, bindingName: key }\n }\n return null\n}\n\nexport function isValidMediaCall(\n jsxPath: NodePath<t.JSXElement>,\n init: t.Expression,\n sourcePath: string\n) {\n if (!t.isCallExpression(init)) return false\n if (!t.isIdentifier(init.callee)) return false\n // TODO could support renaming useMedia by looking up import first\n if (init.callee.name !== 'useMedia') return false\n const bindings = jsxPath.scope.getAllBindings()\n const mediaBinding = bindings['useMedia']\n if (!mediaBinding) return false\n const useMediaImport = mediaBinding.path.parent\n if (!t.isImportDeclaration(useMediaImport)) return false\n if (useMediaImport.source.value !== 'tamagui') {\n if (!isInsideTamagui(sourcePath)) {\n return false\n }\n }\n return true\n}\n"],
|
|
5
|
-
"mappings": ";;AACA;AAEA;AAGA;AAEA;AAEO,2BACL,SACA,SACA,eACA,YACA,aAAa,GAC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KAAK,UAA9B,mBAAqC,SAArC,mBAA2C;AACxD,QAAI,CAAC,EAAE,qBAAqB;AAAO,aAAO;AAC1C,QAAI,CAAC,KAAK,QAAQ,CAAC,iBAAiB,SAAS,KAAK,MAAM;AAAa,aAAO;AAC5E,WAAO,EAAE,KAAK,aAAa;AAAA;AAE7B,SAAO;AAAA;AA9BA;AAiCF,0BACL,SACA,MACA,YACA;AACA,MAAI,CAAC,EAAE,iBAAiB;AAAO,WAAO;AACtC,MAAI,CAAC,EAAE,aAAa,KAAK;AAAS,WAAO;AAEzC,MAAI,KAAK,OAAO,SAAS;AAAY,WAAO;AAC5C,QAAM,WAAW,QAAQ,MAAM;AAC/B,QAAM,eAAe,SAAS;AAC9B,MAAI,CAAC;AAAc,WAAO;AAC1B,QAAM,iBAAiB,aAAa,KAAK;AACzC,MAAI,CAAC,EAAE,oBAAoB;AAAiB,WAAO;AACnD,MAAI,eAAe,OAAO,UAAU,WAAW;AAC7C,QAAI,CAAC,gBAAgB,aAAa;AAChC,aAAO;AAAA;AAAA;AAGX,SAAO;AAAA;AAnBO;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -9,13 +9,14 @@ import { getStylesAtomic } from "@tamagui/core-node";
|
|
|
9
9
|
import { concatClassName } from "@tamagui/helpers";
|
|
10
10
|
import invariant from "invariant";
|
|
11
11
|
import { getRemainingRequest } from "loader-utils";
|
|
12
|
+
import { CONCAT_CLASSNAME_IMPORT } from "../constants";
|
|
12
13
|
import { babelParse } from "./babelParse";
|
|
13
14
|
import { buildClassName } from "./buildClassName";
|
|
14
15
|
import { ensureImportingConcat } from "./ensureImportingConcat";
|
|
15
16
|
import { isSimpleSpread } from "./extractHelpers";
|
|
16
17
|
import { extractMediaStyle } from "./extractMediaStyle";
|
|
17
18
|
import { hoistClassNames } from "./hoistClassNames";
|
|
18
|
-
|
|
19
|
+
import { logLines } from "./logLines";
|
|
19
20
|
const mergeStyleGroups = {
|
|
20
21
|
shadowOpacity: true,
|
|
21
22
|
shadowRadius: true,
|
|
@@ -32,11 +33,12 @@ function extractToClassNames({
|
|
|
32
33
|
threaded,
|
|
33
34
|
cssPath
|
|
34
35
|
}) {
|
|
36
|
+
var _a;
|
|
35
37
|
if (typeof source !== "string") {
|
|
36
38
|
throw new Error("`source` must be a string of javascript");
|
|
37
39
|
}
|
|
38
40
|
invariant(typeof sourcePath === "string" && path.isAbsolute(sourcePath), "`sourcePath` must be an absolute path to a .js file");
|
|
39
|
-
const shouldLogTiming =
|
|
41
|
+
const shouldLogTiming = (_a = options.logTimings) != null ? _a : true;
|
|
40
42
|
const start = Date.now();
|
|
41
43
|
const mem = shouldLogTiming ? process.memoryUsage() : null;
|
|
42
44
|
let ast;
|
|
@@ -46,18 +48,13 @@ function extractToClassNames({
|
|
|
46
48
|
console.error("babel parse error:", sourcePath);
|
|
47
49
|
throw err;
|
|
48
50
|
}
|
|
49
|
-
const cssMap = new Map();
|
|
51
|
+
const cssMap = /* @__PURE__ */ new Map();
|
|
50
52
|
const existingHoists = {};
|
|
51
|
-
|
|
52
|
-
let optimized = 0;
|
|
53
|
-
extractor.parse(ast, {
|
|
53
|
+
const res = extractor.parse(ast, {
|
|
54
54
|
sourcePath,
|
|
55
55
|
shouldPrintDebug,
|
|
56
56
|
...options,
|
|
57
57
|
getFlattenedNode: ({ tag }) => tag,
|
|
58
|
-
onDidFlatten() {
|
|
59
|
-
flattened++;
|
|
60
|
-
},
|
|
61
58
|
onExtractTag: ({
|
|
62
59
|
attrs,
|
|
63
60
|
node,
|
|
@@ -68,7 +65,6 @@ function extractToClassNames({
|
|
|
68
65
|
lineNumbers,
|
|
69
66
|
programPath
|
|
70
67
|
}) => {
|
|
71
|
-
optimized++;
|
|
72
68
|
let finalClassNames = [];
|
|
73
69
|
let finalAttrs = [];
|
|
74
70
|
let finalStyles = [];
|
|
@@ -79,13 +75,14 @@ function extractToClassNames({
|
|
|
79
75
|
}
|
|
80
76
|
}
|
|
81
77
|
const ensureNeededPrevStyle = /* @__PURE__ */ __name((style) => {
|
|
78
|
+
var _a2;
|
|
82
79
|
const keys = Object.keys(style);
|
|
83
80
|
if (!keys.some((key) => mergeStyleGroups[key])) {
|
|
84
81
|
return style;
|
|
85
82
|
}
|
|
86
83
|
for (const k in mergeStyleGroups) {
|
|
87
84
|
if (k in viewStyles) {
|
|
88
|
-
style[k] = style[k]
|
|
85
|
+
style[k] = (_a2 = style[k]) != null ? _a2 : viewStyles[k];
|
|
89
86
|
}
|
|
90
87
|
}
|
|
91
88
|
return style;
|
|
@@ -94,11 +91,11 @@ function extractToClassNames({
|
|
|
94
91
|
if (!style)
|
|
95
92
|
return [];
|
|
96
93
|
const styleWithPrev = ensureNeededPrevStyle(style);
|
|
97
|
-
const
|
|
98
|
-
if (
|
|
99
|
-
finalStyles = [...finalStyles, ...
|
|
94
|
+
const res2 = getStylesAtomic(styleWithPrev);
|
|
95
|
+
if (res2.length) {
|
|
96
|
+
finalStyles = [...finalStyles, ...res2];
|
|
100
97
|
}
|
|
101
|
-
return
|
|
98
|
+
return res2;
|
|
102
99
|
}, "addStyles");
|
|
103
100
|
let lastMediaImportance = 1;
|
|
104
101
|
for (const attr of attrs) {
|
|
@@ -106,9 +103,6 @@ function extractToClassNames({
|
|
|
106
103
|
case "style":
|
|
107
104
|
const styles2 = addStyles(attr.value);
|
|
108
105
|
const newClassNames = concatClassName(styles2.map((x) => x.identifier).join(" "));
|
|
109
|
-
if (shouldPrintDebug) {
|
|
110
|
-
console.log(" classnames", newClassNames, finalClassNames);
|
|
111
|
-
}
|
|
112
106
|
const existing = finalClassNames.find((x) => x.type == "StringLiteral");
|
|
113
107
|
if (existing) {
|
|
114
108
|
existing.value = `${existing.value} ${newClassNames}`;
|
|
@@ -116,7 +110,7 @@ function extractToClassNames({
|
|
|
116
110
|
finalClassNames = [...finalClassNames, t.stringLiteral(newClassNames)];
|
|
117
111
|
}
|
|
118
112
|
if (shouldPrintDebug) {
|
|
119
|
-
console.log(" classnames (after)", finalClassNames.map((x) => x["value"]).join(" "));
|
|
113
|
+
console.log(" classnames (after)\n", logLines(finalClassNames.map((x) => x["value"]).join(" ")));
|
|
120
114
|
}
|
|
121
115
|
break;
|
|
122
116
|
case "attr":
|
|
@@ -140,7 +134,7 @@ function extractToClassNames({
|
|
|
140
134
|
finalAttrs.push(val);
|
|
141
135
|
break;
|
|
142
136
|
case "ternary":
|
|
143
|
-
const mediaExtraction = extractMediaStyle(attr.value, jsxPath, extractor.
|
|
137
|
+
const mediaExtraction = extractMediaStyle(attr.value, jsxPath, extractor.getTamagui(), sourcePath, lastMediaImportance, shouldPrintDebug);
|
|
144
138
|
if (mediaExtraction) {
|
|
145
139
|
lastMediaImportance++;
|
|
146
140
|
finalStyles = [...finalStyles, ...mediaExtraction.mediaStyles];
|
|
@@ -152,7 +146,7 @@ function extractToClassNames({
|
|
|
152
146
|
continue;
|
|
153
147
|
}
|
|
154
148
|
}
|
|
155
|
-
const ternary = mediaExtraction
|
|
149
|
+
const ternary = (mediaExtraction == null ? void 0 : mediaExtraction.ternaryWithoutMedia) || attr.value;
|
|
156
150
|
const consInfo = addStyles(ternary.consequent);
|
|
157
151
|
const altInfo = addStyles(ternary.alternate);
|
|
158
152
|
const cCN = consInfo.map((x) => x.identifier).join(" ");
|
|
@@ -171,12 +165,17 @@ function extractToClassNames({
|
|
|
171
165
|
const nameExpr = names ? hoistClassNames(jsxPath, existingHoists, names) : null;
|
|
172
166
|
let expr = nameExpr;
|
|
173
167
|
if (nameExpr && !t.isIdentifier(nameExpr)) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
168
|
+
if (!(res == null ? void 0 : res.flattened)) {
|
|
169
|
+
console.log("not flat");
|
|
170
|
+
} else {
|
|
171
|
+
console.log("flat");
|
|
172
|
+
ensureImportingConcat(programPath);
|
|
173
|
+
const simpleSpreads = attrs.filter((x) => t.isJSXSpreadAttribute(x.value) && isSimpleSpread(x.value));
|
|
174
|
+
expr = t.callExpression(t.identifier(CONCAT_CLASSNAME_IMPORT), [
|
|
175
|
+
expr,
|
|
176
|
+
...simpleSpreads.map((val) => val.value["argument"])
|
|
177
|
+
]);
|
|
178
|
+
}
|
|
180
179
|
}
|
|
181
180
|
node.attributes.push(t.jsxAttribute(t.jsxIdentifier("className"), t.jsxExpressionContainer(expr)));
|
|
182
181
|
}
|
|
@@ -201,12 +200,13 @@ function extractToClassNames({
|
|
|
201
200
|
}
|
|
202
201
|
}
|
|
203
202
|
});
|
|
204
|
-
if (!optimized) {
|
|
203
|
+
if (!res || !res.modified && !res.optimized && !res.flattened) {
|
|
204
|
+
if (shouldPrintDebug) {
|
|
205
|
+
console.log("no res or none modified", res);
|
|
206
|
+
}
|
|
205
207
|
return null;
|
|
206
208
|
}
|
|
207
|
-
const styles = Array.from(cssMap.values()).map((x) =>
|
|
208
|
-
return x.css;
|
|
209
|
-
}).join("\n").trim();
|
|
209
|
+
const styles = Array.from(cssMap.values()).map((x) => x.css).join("\n").trim();
|
|
210
210
|
if (styles) {
|
|
211
211
|
const cssQuery = threaded ? `cssData=${Buffer.from(styles).toString("base64")}` : `cssPath=${cssPath}`;
|
|
212
212
|
const remReq = getRemainingRequest(loader);
|
|
@@ -224,9 +224,13 @@ function extractToClassNames({
|
|
|
224
224
|
console.log("\n -------- output code ------- \n\n", result.code.split("\n").filter((x) => !x.startsWith("//")).join("\n"));
|
|
225
225
|
console.log("\n -------- output style -------- \n\n", styles);
|
|
226
226
|
}
|
|
227
|
-
if (shouldLogTiming
|
|
228
|
-
const memUsed = Math.round((process.memoryUsage().heapUsed - mem.heapUsed) / 1024 / 1204 * 10) / 10;
|
|
229
|
-
|
|
227
|
+
if (shouldLogTiming) {
|
|
228
|
+
const memUsed = mem ? Math.round((process.memoryUsage().heapUsed - mem.heapUsed) / 1024 / 1204 * 10) / 10 : 0;
|
|
229
|
+
const timing = `${Date.now() - start}`.padStart(3);
|
|
230
|
+
const path2 = basename(sourcePath).padStart(40);
|
|
231
|
+
const numOptimized = `${res.optimized}`.padStart(4);
|
|
232
|
+
const memory = memUsed > 10 ? `used ${memUsed}MB` : "";
|
|
233
|
+
console.log(` \u{1F95A} ${path2} ${timing}ms \u05C1\xB7 ${numOptimized} optimized \xB7 ${res.flattened} flattened ${memory}`);
|
|
230
234
|
}
|
|
231
235
|
return {
|
|
232
236
|
ast,
|
|
@@ -237,7 +241,6 @@ function extractToClassNames({
|
|
|
237
241
|
}
|
|
238
242
|
__name(extractToClassNames, "extractToClassNames");
|
|
239
243
|
export {
|
|
240
|
-
CONCAT_CLASSNAME_IMPORT,
|
|
241
244
|
extractToClassNames
|
|
242
245
|
};
|
|
243
246
|
//# sourceMappingURL=extractToClassNames.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/extractor/extractToClassNames.ts"],
|
|
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 invariant from 'invariant'\nimport { getRemainingRequest } from 'loader-utils'\nimport { ViewStyle } from 'react-native'\n\nimport { CONCAT_CLASSNAME_IMPORT } from '../constants'\nimport { ClassNameObject, StyleObject, TamaguiOptions } from '../types'\nimport { babelParse } from './babelParse'\nimport { buildClassName } from './buildClassName'\nimport { Extractor } from './createExtractor'\nimport { ensureImportingConcat } from './ensureImportingConcat'\nimport { isSimpleSpread } from './extractHelpers'\nimport { extractMediaStyle } from './extractMediaStyle'\nimport { hoistClassNames } from './hoistClassNames'\nimport { logLines } from './logLines'\n\nconst mergeStyleGroups = {\n shadowOpacity: true,\n shadowRadius: true,\n shadowColor: true,\n shadowOffset: true,\n}\n\nexport function extractToClassNames({\n loader,\n extractor,\n source,\n sourcePath,\n options,\n shouldPrintDebug,\n threaded,\n cssPath,\n}: {\n loader: any\n extractor: Extractor\n source: string | Buffer\n sourcePath: string\n options: TamaguiOptions\n shouldPrintDebug: boolean\n cssPath: string\n threaded?: boolean\n}): null | {\n js: string | Buffer\n styles: string\n stylesPath?: string\n ast: t.File\n map: any // RawSourceMap from 'source-map'\n} {\n if (typeof source !== 'string') {\n throw new Error('`source` must be a string of javascript')\n }\n invariant(\n typeof sourcePath === 'string' && path.isAbsolute(sourcePath),\n '`sourcePath` must be an absolute path to a .js file'\n )\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 // @ts-ignore\n ast = babelParse(source)\n } catch (err) {\n console.error('babel parse error:', sourcePath)\n throw err\n }\n\n const cssMap = new Map<string, { css: string; commentTexts: string[] }>()\n const existingHoists: { [key: string]: t.Identifier } = {}\n\n const res = extractor.parse(ast, {\n sourcePath,\n shouldPrintDebug,\n ...options,\n getFlattenedNode: ({ tag }) => tag,\n onExtractTag: ({\n attrs,\n node,\n attemptEval,\n jsxPath,\n originalNodeName,\n filePath,\n lineNumbers,\n programPath,\n }) => {\n let finalClassNames: ClassNameObject[] = []\n let finalAttrs: (t.JSXAttribute | t.JSXSpreadAttribute)[] = []\n let finalStyles: StyleObject[] = []\n\n const viewStyles = {}\n for (const attr of attrs) {\n if (attr.type === 'style') {\n Object.assign(viewStyles, attr.value)\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) => {\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 const styles = addStyles(attr.value)\n const newClassNames = concatClassName(styles.map((x) => x.identifier).join(' '))\n // prettier-ignore\n const existing = finalClassNames.find((x) => x.type == 'StringLiteral') as t.StringLiteral | null\n if (existing) {\n existing.value = `${existing.value} ${newClassNames}`\n } else {\n finalClassNames = [...finalClassNames, t.stringLiteral(newClassNames)]\n }\n if (shouldPrintDebug) {\n // prettier-ignore\n console.log(' classnames (after)\\n', logLines(finalClassNames.map(x => x['value']).join(' ')))\n }\n break\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 case 'ternary':\n const mediaExtraction = extractMediaStyle(\n attr.value,\n jsxPath,\n extractor.getTamagui(),\n sourcePath,\n lastMediaImportance,\n shouldPrintDebug\n )\n if (mediaExtraction) {\n lastMediaImportance++\n finalStyles = [...finalStyles, ...mediaExtraction.mediaStyles]\n finalClassNames = [\n ...finalClassNames,\n ...mediaExtraction.mediaStyles.map((x) => t.stringLiteral(x.identifier)),\n ]\n if (!mediaExtraction.ternaryWithoutMedia) {\n continue\n }\n }\n const ternary = mediaExtraction?.ternaryWithoutMedia || attr.value\n const consInfo = addStyles(ternary.consequent)\n const altInfo = addStyles(ternary.alternate)\n const cCN = consInfo.map((x) => x.identifier).join(' ')\n const aCN = altInfo.map((x) => x.identifier).join(' ')\n if (consInfo.length && altInfo.length) {\n finalClassNames.push(\n t.conditionalExpression(ternary.test, t.stringLiteral(cCN), t.stringLiteral(aCN))\n )\n } else {\n finalClassNames.push(\n t.conditionalExpression(\n ternary.test,\n t.stringLiteral(' ' + cCN),\n t.stringLiteral(' ' + aCN)\n )\n )\n }\n break\n }\n }\n\n node.attributes = finalAttrs\n\n if (finalClassNames.length) {\n // inserts the _cn variable and uses it for className\n const names = buildClassName(finalClassNames)\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 (!res?.flattened) {\n console.log('not flat')\n } else {\n console.log('flat')\n ensureImportingConcat(programPath)\n const simpleSpreads = attrs.filter(\n (x) => t.isJSXSpreadAttribute(x.value) && isSimpleSpread(x.value)\n )\n expr = t.callExpression(t.identifier(CONCAT_CLASSNAME_IMPORT), [\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('/* %s:%s (%s) */', filePath, lineNumbers, originalNodeName)\n\n for (const { className, rules } of finalStyles) {\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 if (rules.length > 1) {\n console.log(' rules error', { rules })\n throw new Error(`Shouldn't have more than one rule`)\n }\n cssMap.set(className, {\n css: rules[0],\n commentTexts: [comment],\n })\n }\n }\n },\n })\n\n if (!res || (!res.modified && !res.optimized && !res.flattened)) {\n if (shouldPrintDebug) {\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 if (styles) {\n const cssQuery = threaded\n ? `cssData=${Buffer.from(styles).toString('base64')}`\n : `cssPath=${cssPath}`\n const remReq = getRemainingRequest(loader)\n const importPath = `${cssPath}!=!tamagui-loader?${cssQuery}!${remReq}`\n ast.program.body.unshift(t.importDeclaration([], t.stringLiteral(importPath)))\n }\n\n const result = generate(\n ast,\n {\n concise: false,\n filename: sourcePath,\n retainLines: false,\n sourceFileName: sourcePath,\n sourceMaps: true,\n },\n source\n )\n\n if (shouldPrintDebug) {\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 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) / 10\n : 0\n const timing = `${Date.now() - start}`.padStart(3)\n const path = basename(sourcePath).padStart(40)\n const numOptimized = `${res.optimized}`.padStart(4)\n const memory = memUsed > 10 ? `used ${memUsed}MB` : ''\n console.log(\n ` \uD83E\uDD5A ${path} ${timing}ms \u05C1\u00B7 ${numOptimized} optimized \u00B7 ${res.flattened} flattened ${memory}`\n )\n }\n\n return {\n ast,\n styles,\n js: result.code,\n map: result.map,\n }\n}\n"],
|
|
5
|
+
"mappings": ";;AAAA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AAGA;AAEA;AACA;AAEA;AACA;AACA;AACA;AACA;AAEA,MAAM,mBAAmB;AAAA,EACvB,eAAe;AAAA,EACf,cAAc;AAAA,EACd,aAAa;AAAA,EACb,cAAc;AAAA;AAGT,6BAA6B;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,GAgBA;AAtDF;AAuDE,MAAI,OAAO,WAAW,UAAU;AAC9B,UAAM,IAAI,MAAM;AAAA;AAElB,YACE,OAAO,eAAe,YAAY,KAAK,WAAW,aAClD;AAGF,QAAM,kBAAkB,cAAQ,eAAR,YAAsB;AAC9C,QAAM,QAAQ,KAAK;AACnB,QAAM,MAAM,kBAAkB,QAAQ,gBAAgB;AAGtD,MAAI;AAEJ,MAAI;AAEF,UAAM,WAAW;AAAA,WACV,KAAP;AACA,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
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
File without changes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["
|
|
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
5
|
"mappings": ";;AAGO,6BAA6B,SAAiC;AAEnE,QAAM,aAAa,wBAAC,SAClB,KAAK,+BAA+B,KAAK,2BAA2B,KAAK,wBADxD;AAEnB,MAAI,SAA+B,QAAQ,WAAW;AACtD,SAAO,QAAQ;AACb,UAAM,SAAS,OAAO,WAAW;AACjC,QAAI,QAAQ;AACV,eAAS;AAAA,WACJ;AACL;AAAA;AAAA;AAGJ,MAAI,CAAC,QAAQ;AAEX,WAAO;AAAA;AAET,SAAO;AAAA;AAjBO;",
|
|
6
6
|
"names": []
|
|
File without changes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["
|
|
3
|
+
"sources": ["../../../src/extractor/generatedUid.ts"],
|
|
4
4
|
"sourcesContent": ["import * as t from '@babel/types'\nimport invariant from 'invariant'\n\n// TODO: open a PR upstream\ndeclare module '@babel/types' {\n export function toIdentifier(input: string): string\n}\n\n// A clone of path.scope.generateUid that doesn't prepend underscores\nexport function generateUid(scope: any, name: string): string {\n invariant(typeof scope === 'object', 'generateUid expects a scope object as its first parameter')\n invariant(\n typeof name === 'string' && name !== '',\n 'generateUid expects a valid name as its second parameter'\n )\n\n name = t\n .toIdentifier(name)\n .replace(/^_+/, '')\n .replace(/[0-9]+$/g, '')\n\n let uid\n let i = 0\n do {\n if (i > 1) {\n uid = name + i\n } else {\n uid = name\n }\n i++\n } while (\n scope.hasLabel(uid) ||\n scope.hasBinding(uid) ||\n scope.hasGlobal(uid) ||\n scope.hasReference(uid)\n )\n\n const program = scope.getProgramParent()\n program.references[uid] = true\n program.uids[uid] = true\n\n return uid\n}\n"],
|
|
5
5
|
"mappings": ";;AAAA;AACA;AAQO,qBAAqB,OAAY,MAAsB;AAC5D,YAAU,OAAO,UAAU,UAAU;AACrC,YACE,OAAO,SAAS,YAAY,SAAS,IACrC;AAGF,SAAO,EACJ,aAAa,MACb,QAAQ,OAAO,IACf,QAAQ,YAAY;AAEvB,MAAI;AACJ,MAAI,IAAI;AACR,KAAG;AACD,QAAI,IAAI,GAAG;AACT,YAAM,OAAO;AAAA,WACR;AACL,YAAM;AAAA;AAER;AAAA,WAEA,MAAM,SAAS,QACf,MAAM,WAAW,QACjB,MAAM,UAAU,QAChB,MAAM,aAAa;AAGrB,QAAM,UAAU,MAAM;AACtB,UAAQ,WAAW,OAAO;AAC1B,UAAQ,KAAK,OAAO;AAEpB,SAAO;AAAA;AAhCO;",
|
|
6
6
|
"names": []
|
|
File without changes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["
|
|
3
|
+
"sources": ["../../../src/extractor/getPropValueFromAttributes.ts"],
|
|
4
4
|
"sourcesContent": ["import generate from '@babel/generator'\nimport * as t from '@babel/types'\n\nimport { accessSafe } from './accessSafe'\n\n/**\n * getPropValueFromAttributes gets a prop by name from a list of attributes and accounts for potential spread operators.\n * Here's an example. Given this component:\n * ```\n * <Block coolProp=\"wow\" {...spread1} neatProp=\"ok\" {...spread2} />```\n * getPropValueFromAttributes will return the following:\n * - for propName `coolProp`:\n * ```\n * accessSafe(spread1, 'coolProp') || accessSafe(spread2, 'coolProp') || 'wow'```\n * - for propName `neatProp`:\n * ```\n * accessSafe(spread2, 'neatProp') || 'ok'```\n * - for propName `notPresent`: `null`\n *\n * The returned value should (obviously) be placed after spread operators.\n */\nexport function getPropValueFromAttributes(\n propName: string,\n attrs: (t.JSXAttribute | t.JSXSpreadAttribute)[]\n): t.Expression | null {\n let propIndex: number = -1\n let jsxAttr: t.JSXAttribute | null = null\n for (let idx = -1, len = attrs.length; ++idx < len; ) {\n const attr = attrs[idx]\n if (t.isJSXAttribute(attr) && attr.name && attr.name.name === propName) {\n propIndex = idx\n jsxAttr = attr\n break\n }\n }\n\n if (!jsxAttr || jsxAttr.value == null) {\n return null\n }\n\n let propValue:\n | t.JSXElement\n | t.JSXFragment\n | t.StringLiteral\n | t.JSXExpressionContainer\n | t.JSXEmptyExpression\n | t.Expression = jsxAttr.value\n\n if (t.isJSXExpressionContainer(propValue)) {\n propValue = propValue.expression\n }\n\n // TODO how to handle this??\n if (t.isJSXEmptyExpression(propValue)) {\n console.error('encountered JSXEmptyExpression')\n return null\n }\n\n // filter out spread props that occur before propValue\n const applicableSpreads = attrs\n .filter(\n // 1. idx is greater than propValue prop index\n // 2. attr is a spread operator\n (attr, idx): attr is t.JSXSpreadAttribute => {\n if (t.isJSXSpreadAttribute(attr)) {\n if (t.isIdentifier(attr.argument) || t.isMemberExpression(attr.argument)) {\n return idx > propIndex\n }\n if (t.isLogicalExpression(attr.argument)) {\n return false\n }\n throw new Error(\n `unsupported spread of type \"${attr.argument.type}\": ${generate(attr).code}`\n )\n }\n return false\n }\n )\n .map((attr) => attr.argument)\n\n // if spread operators occur after propValue, create a binary expression for each operator\n // i.e. before1.propValue || before2.propValue || propValue\n // TODO: figure out how to do this without all the extra parens\n if (applicableSpreads.length > 0) {\n propValue = applicableSpreads.reduce<t.Expression>(\n (acc, val) => t.logicalExpression('||', accessSafe(val, propName), acc),\n propValue\n )\n }\n\n return propValue\n}\n"],
|
|
5
5
|
"mappings": ";;AAAA;AACA;AAEA;AAkBO,oCACL,UACA,OACqB;AACrB,MAAI,YAAoB;AACxB,MAAI,UAAiC;AACrC,WAAS,MAAM,IAAI,MAAM,MAAM,QAAQ,EAAE,MAAM,OAAO;AACpD,UAAM,OAAO,MAAM;AACnB,QAAI,EAAE,eAAe,SAAS,KAAK,QAAQ,KAAK,KAAK,SAAS,UAAU;AACtE,kBAAY;AACZ,gBAAU;AACV;AAAA;AAAA;AAIJ,MAAI,CAAC,WAAW,QAAQ,SAAS,MAAM;AACrC,WAAO;AAAA;AAGT,MAAI,YAMe,QAAQ;AAE3B,MAAI,EAAE,yBAAyB,YAAY;AACzC,gBAAY,UAAU;AAAA;AAIxB,MAAI,EAAE,qBAAqB,YAAY;AACrC,YAAQ,MAAM;AACd,WAAO;AAAA;AAIT,QAAM,oBAAoB,MACvB,OAGC,CAAC,MAAM,QAAsC;AAC3C,QAAI,EAAE,qBAAqB,OAAO;AAChC,UAAI,EAAE,aAAa,KAAK,aAAa,EAAE,mBAAmB,KAAK,WAAW;AACxE,eAAO,MAAM;AAAA;AAEf,UAAI,EAAE,oBAAoB,KAAK,WAAW;AACxC,eAAO;AAAA;AAET,YAAM,IAAI,MACR,+BAA+B,KAAK,SAAS,UAAU,SAAS,MAAM;AAAA;AAG1E,WAAO;AAAA,KAGV,IAAI,CAAC,SAAS,KAAK;AAKtB,MAAI,kBAAkB,SAAS,GAAG;AAChC,gBAAY,kBAAkB,OAC5B,CAAC,KAAK,QAAQ,EAAE,kBAAkB,MAAM,WAAW,KAAK,WAAW,MACnE;AAAA;AAIJ,SAAO;AAAA;AArEO;",
|
|
6
6
|
"names": []
|
|
File without changes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["
|
|
3
|
+
"sources": ["../../../src/extractor/getSourceModule.ts"],
|
|
4
4
|
"sourcesContent": ["import * as t from '@babel/types'\n\nexport interface SourceModule {\n sourceModule?: string\n imported?: string\n local?: string\n destructured?: boolean\n usesImportSyntax: boolean\n}\n\nexport function getSourceModule(\n itemName: string,\n itemBinding: {\n constant?: boolean\n path: { node: t.Node; parent: any }\n }\n): SourceModule | null {\n // TODO: deal with reassignment\n if (!itemBinding.constant) {\n return null\n }\n\n let sourceModule: string | undefined\n let imported: string | undefined\n let local: string | undefined\n let destructured: boolean | undefined\n let usesImportSyntax = false\n\n const itemNode = itemBinding.path.node\n\n if (\n // import x from 'y';\n t.isImportDefaultSpecifier(itemNode) ||\n // import {x} from 'y';\n t.isImportSpecifier(itemNode)\n ) {\n if (t.isImportDeclaration(itemBinding.path.parent)) {\n sourceModule = itemBinding.path.parent.source.value\n local = itemNode.local.name\n usesImportSyntax = true\n if (t.isImportSpecifier(itemNode)) {\n imported = itemNode.imported['name']\n destructured = true\n } else {\n imported = itemNode.local.name\n destructured = false\n }\n }\n } else if (\n t.isVariableDeclarator(itemNode) &&\n itemNode.init != null &&\n t.isCallExpression(itemNode.init) &&\n t.isIdentifier(itemNode.init.callee) &&\n itemNode.init.callee.name === 'require' &&\n itemNode.init.arguments.length === 1\n ) {\n const firstArg = itemNode.init.arguments[0]\n if (!t.isStringLiteral(firstArg)) {\n return null\n }\n sourceModule = firstArg.value\n\n if (t.isIdentifier(itemNode.id)) {\n local = itemNode.id.name\n imported = itemNode.id.name\n destructured = false\n } else if (t.isObjectPattern(itemNode.id)) {\n for (const objProp of itemNode.id.properties) {\n if (\n t.isObjectProperty(objProp) &&\n t.isIdentifier(objProp.value) &&\n objProp.value.name === itemName\n ) {\n local = objProp.value.name\n // @ts-ignore TODO remove this is only an issue on CI\n imported = objProp.key.name\n destructured = true\n break\n }\n }\n\n if (!local || !imported) {\n console.error('could not find prop with value `%s`', itemName)\n return null\n }\n } else {\n console.error('Unhandled id type: %s', itemNode.id.type)\n return null\n }\n } else {\n return null\n }\n\n return {\n destructured,\n imported,\n local,\n sourceModule,\n usesImportSyntax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AAAA,WAEJ;AACL,cAAQ,MAAM,yBAAyB,SAAS,GAAG;AACnD,aAAO;AAAA;AAAA,SAEJ;AACL,WAAO;AAAA;AAGT,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA;AAAA;AAxFY;",
|
|
6
6
|
"names": []
|
|
File without changes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["
|
|
3
|
+
"sources": ["../../../src/extractor/getStaticBindingsForScope.ts"],
|
|
4
4
|
"sourcesContent": ["import { dirname, extname, resolve } from 'path'\n\nimport { Binding, NodePath } from '@babel/traverse'\nimport * as t from '@babel/types'\nimport { existsSync } from 'fs-extra'\n\nimport { evaluateAstNode } from './evaluateAstNode'\nimport { getSourceModule } from './getSourceModule'\n\nconst isLocalImport = (path: string) => path.startsWith('.') || path.startsWith('/')\n\nfunction resolveImportPath(sourcePath: string, path: string) {\n const sourceDir = dirname(sourcePath)\n if (isLocalImport(path)) {\n if (extname(path) === '') {\n path += '.js'\n }\n return resolve(sourceDir, path)\n }\n return path\n}\n\nfunction importModule(path: string) {\n const filenames = [path.replace('.js', '.tsx'), path.replace('.js', '.ts'), path]\n for (const file of filenames) {\n if (existsSync(file)) {\n // TODO we can clear this when we see updates on it later on\n return require(file)\n }\n }\n return null\n}\n\nexport function getStaticBindingsForScope(\n scope: NodePath<t.JSXElement>['scope'],\n whitelist: string[] = [],\n sourcePath: string,\n bindingCache: Record<string, string | null>,\n shouldPrintDebug: boolean\n): Record<string, any> {\n const bindings: Record<string, Binding> = scope.getAllBindings() as any\n const ret: Record<string, any> = {}\n\n if (shouldPrintDebug) {\n // prettier-ignore\n console.log(' ', Object.keys(bindings).length, 'variables in scope')\n // .map(x => bindings[x].identifier?.name).join(', ')\n }\n\n // on react native at least it doesnt find some bindings? not sure why\n // lets add in whitelisted imports if they exist\n const program = scope.getProgramParent().block as t.Program\n for (const node of program.body) {\n if (t.isImportDeclaration(node)) {\n const importPath = node.source.value\n if (!node.specifiers.length) continue\n if (!isLocalImport(importPath)) {\n continue\n }\n const moduleName = resolveImportPath(sourcePath, importPath)\n const isOnWhitelist = whitelist.some((test) => moduleName.endsWith(test))\n if (!isOnWhitelist) continue\n const src = importModule(moduleName)\n if (!src) continue\n for (const specifier of node.specifiers) {\n if (t.isImportSpecifier(specifier) && t.isIdentifier(specifier.imported)) {\n if (typeof src[specifier.imported.name] !== 'undefined') {\n const val = src[specifier.local.name]\n ret[specifier.local.name] = val\n }\n }\n }\n }\n }\n\n if (!bindingCache) {\n throw new Error('bindingCache is a required param')\n }\n\n for (const k in bindings) {\n const binding = bindings[k]\n\n // check to see if the item is a module\n const sourceModule = getSourceModule(k, binding)\n if (sourceModule) {\n if (!sourceModule.sourceModule) {\n continue\n }\n\n const moduleName = resolveImportPath(sourcePath, sourceModule.sourceModule)\n const isOnWhitelist = whitelist.some((test) => moduleName.endsWith(test))\n\n // TODO we could cache this at the file level.. and check if its been touched since\n\n if (isOnWhitelist) {\n const src = importModule(moduleName)\n if (!src) {\n console.log(\n `\u26A0\uFE0F missing file ${moduleName} via ${sourcePath} import ${sourceModule.sourceModule}?`\n )\n return {}\n }\n if (sourceModule.destructured) {\n if (sourceModule.imported) {\n ret[k] = src[sourceModule.imported]\n }\n } else {\n // crude esmodule check\n // TODO: make sure this actually works\n // if (src && src.__esModule) {\n // ret[k] = src.default\n // } else {\n ret[k] = src\n // }\n }\n }\n continue\n }\n\n const { parent, parentPath } = binding.path\n\n if (!t.isVariableDeclaration(parent) || parent.kind !== 'const') {\n continue\n }\n\n // pick out the right variable declarator\n const dec = parent.declarations.find((d) => t.isIdentifier(d.id) && d.id.name === k)\n\n // if init is not set, there's nothing to evaluate\n // TODO: handle spread syntax\n if (!dec || !dec.init) {\n continue\n }\n\n // missing start/end will break caching\n if (typeof dec.id.start !== 'number' || typeof dec.id.end !== 'number') {\n console.error('dec.id.start/end is not a number')\n continue\n }\n\n if (!t.isIdentifier(dec.id)) {\n console.error('dec is not an identifier')\n continue\n }\n\n const cacheKey = `${dec.id.name}_${dec.id.start}-${dec.id.end}`\n\n // retrieve value from cache\n if (bindingCache.hasOwnProperty(cacheKey)) {\n ret[k] = bindingCache[cacheKey]\n continue\n }\n // retrieve value from cache\n if (bindingCache.hasOwnProperty(cacheKey)) {\n ret[k] = bindingCache[cacheKey]\n continue\n }\n\n // evaluate\n try {\n ret[k] = evaluateAstNode(dec.init, undefined, shouldPrintDebug)\n bindingCache[cacheKey] = ret[k]\n continue\n } catch (e) {\n // skip\n // if (shouldPrintDebug) {\n // console.error('[\uD83D\uDC07] cant eval, skipping', cacheKey) //, e.message)\n // }\n }\n }\n\n return ret\n}\n"],
|
|
5
5
|
"mappings": ";;AAAA;AAGA;AACA;AAEA;AACA;AAEA,MAAM,gBAAgB,wBAAC,SAAiB,KAAK,WAAW,QAAQ,KAAK,WAAW,MAA1D;AAEtB,2BAA2B,YAAoB,MAAc;AAC3D,QAAM,YAAY,QAAQ;AAC1B,MAAI,cAAc,OAAO;AACvB,QAAI,QAAQ,UAAU,IAAI;AACxB,cAAQ;AAAA;AAEV,WAAO,QAAQ,WAAW;AAAA;AAE5B,SAAO;AAAA;AARA;AAWT,sBAAsB,MAAc;AAClC,QAAM,YAAY,CAAC,KAAK,QAAQ,OAAO,SAAS,KAAK,QAAQ,OAAO,QAAQ;AAC5E,aAAW,QAAQ,WAAW;AAC5B,QAAI,WAAW,OAAO;AAEpB,aAAO,QAAQ;AAAA;AAAA;AAGnB,SAAO;AAAA;AARA;AAWF,mCACL,OACA,YAAsB,IACtB,YACA,cACA,kBACqB;AACrB,QAAM,WAAoC,MAAM;AAChD,QAAM,MAA2B;AAEjC,MAAI,kBAAkB;AAEpB,YAAQ,IAAI,MAAM,OAAO,KAAK,UAAU,QAAQ;AAAA;AAMlD,QAAM,UAAU,MAAM,mBAAmB;AACzC,aAAW,QAAQ,QAAQ,MAAM;AAC/B,QAAI,EAAE,oBAAoB,O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CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,GAAG,SAAS;AAIlF,QAAI,CAAC,OAAO,CAAC,IAAI,MAAM;AACrB;AAAA;AAIF,QAAI,OAAO,IAAI,GAAG,UAAU,YAAY,OAAO,IAAI,GAAG,QAAQ,UAAU;AACtE,cAAQ,MAAM;AACd;AAAA;AAGF,QAAI,CAAC,EAAE,aAAa,IAAI,KAAK;AAC3B,cAAQ,MAAM;AACd;AAAA;AAGF,UAAM,WAAW,GAAG,IAAI,GAAG,QAAQ,IAAI,GAAG,SAAS,IAAI,GAAG;AAG1D,QAAI,aAAa,eAAe,WAAW;AACzC,UAAI,KAAK,aAAa;AACtB;AAAA;AAGF,QAAI,aAAa,eAAe,WAAW;AACzC,UAAI,KAAK,aAAa;AACtB;AAAA;AAIF,QAAI;AACF,UAAI,KAAK,gBAAgB,IAAI,MAAM,QAAW;AAC9C,mBAAa,YAAY,IAAI;AAC7B;AAAA,aACO,GAAP;AAAA;AAAA;AAQJ,SAAO;AAAA;AA1IO;",
|
|
6
6
|
"names": []
|
|
File without changes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["
|
|
3
|
+
"sources": ["../../../src/extractor/hoistClassNames.ts"],
|
|
4
4
|
"sourcesContent": ["import { NodePath } from '@babel/traverse'\nimport * as t from '@babel/types'\n\nexport function hoistClassNames(\n path: NodePath<t.JSXElement>,\n existing: { [key: string]: t.Identifier },\n expr: t.Expression\n) {\n const hoist = hoistClassNames.bind(null, path, existing)\n if (t.isStringLiteral(expr)) {\n if (expr.value.trim() === '') {\n return expr\n }\n if (existing[expr.value]) {\n return existing[expr.value]\n }\n const identifier = replaceStringWithVariable(expr)\n existing[expr.value] = identifier\n return identifier\n }\n if (t.isBinaryExpression(expr)) {\n return t.binaryExpression(expr.operator, hoist(expr.left), hoist(expr.right))\n }\n if (t.isLogicalExpression(expr)) {\n return t.logicalExpression(expr.operator, hoist(expr.left), hoist(expr.right))\n }\n if (t.isConditionalExpression(expr)) {\n return t.conditionalExpression(expr.test, hoist(expr.consequent), hoist(expr.alternate))\n }\n return expr\n\n function replaceStringWithVariable(str: t.StringLiteral): t.Identifier {\n // hoist outside fn!\n const uid = path.scope.generateUidIdentifier('cn')\n const parent = path.findParent((path) => path.isProgram())\n if (!parent) throw new Error(`no program?`)\n const variable = t.variableDeclaration('const', [\n // adding a space for extra safety\n t.variableDeclarator(uid, t.stringLiteral(` ${str.value}`)),\n ])\n // @ts-ignore\n parent.unshiftContainer('body', variable)\n return uid\n }\n}\n"],
|
|
5
5
|
"mappings": ";;AACA;AAEO,yBACL,MACA,UACA,MACA;AACA,QAAM,QAAQ,gBAAgB,KAAK,MAAM,MAAM;AAC/C,MAAI,EAAE,gBAAgB,OAAO;AAC3B,QAAI,KAAK,MAAM,WAAW,IAAI;AAC5B,aAAO;AAAA;AAET,QAAI,SAAS,KAAK,QAAQ;AACxB,aAAO,SAAS,KAAK;AAAA;AAEvB,UAAM,aAAa,0BAA0B;AAC7C,aAAS,KAAK,SAAS;AACvB,WAAO;AAAA;AAET,MAAI,EAAE,mBAAmB,OAAO;AAC9B,WAAO,EAAE,iBAAiB,KAAK,UAAU,MAAM,KAAK,OAAO,MAAM,KAAK;AAAA;AAExE,MAAI,EAAE,oBAAoB,OAAO;AAC/B,WAAO,EAAE,kBAAkB,KAAK,UAAU,MAAM,KAAK,OAAO,MAAM,KAAK;AAAA;AAEzE,MAAI,EAAE,wBAAwB,OAAO;AACnC,WAAO,EAAE,sBAAsB,KAAK,MAAM,MAAM,KAAK,aAAa,MAAM,KAAK;AAAA;AAE/E,SAAO;AAEP,qCAAmC,KAAoC;AAErE,UAAM,MAAM,KAAK,MAAM,sBAAsB;AAC7C,UAAM,SAAS,KAAK,WAAW,CAAC,UAAS,MAAK;AAC9C,QAAI,CAAC;AAAQ,YAAM,IAAI,MAAM;AAC7B,UAAM,WAAW,EAAE,oBAAoB,SAAS;AAAA,MAE9C,EAAE,mBAAmB,KAAK,EAAE,cAAc,IAAI,IAAI;AAAA;AAGpD,WAAO,iBAAiB,QAAQ;AAChC,WAAO;AAAA;AAXA;AAAA;AA5BK;",
|
|
6
6
|
"names": []
|
|
File without changes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["
|
|
3
|
+
"sources": ["../../../src/extractor/literalToAst.ts"],
|
|
4
4
|
"sourcesContent": ["import * as t from '@babel/types'\n\nexport function literalToAst(literal: any): t.Expression {\n if (literal === null) {\n return t.nullLiteral()\n }\n switch (typeof literal) {\n case 'function':\n throw new Error('Unsupported')\n case 'number':\n return t.numericLiteral(literal)\n case 'string':\n return t.stringLiteral(literal)\n case 'boolean':\n return t.booleanLiteral(literal)\n case 'undefined':\n return t.unaryExpression('void', t.numericLiteral(0), true)\n default:\n if (Array.isArray(literal)) {\n return t.arrayExpression(literal.map(literalToAst))\n }\n return t.objectExpression(\n Object.keys(literal)\n .filter((k) => {\n return typeof literal[k] !== 'undefined'\n })\n .map((k) => {\n return t.objectProperty(t.stringLiteral(k), literalToAst(literal[k]))\n })\n )\n }\n}\n"],
|
|
5
5
|
"mappings": ";;AAAA;AAEO,sBAAsB,SAA4B;AACvD,MAAI,YAAY,MAAM;AACpB,WAAO,EAAE;AAAA;AAEX,UAAQ,OAAO;AAAA,SACR;AACH,YAAM,IAAI,MAAM;AAAA,SACb;AACH,aAAO,EAAE,eAAe;AAAA,SACrB;AACH,aAAO,EAAE,cAAc;AAAA,SACpB;AACH,aAAO,EAAE,eAAe;AAAA,SACrB;AACH,aAAO,EAAE,gBAAgB,QAAQ,EAAE,eAAe,IAAI;AAAA;AAEtD,UAAI,MAAM,QAAQ,UAAU;AAC1B,eAAO,EAAE,gBAAgB,QAAQ,IAAI;AAAA;AAEvC,aAAO,EAAE,iBACP,OAAO,KAAK,SACT,OAAO,CAAC,MAAM;AACb,eAAO,OAAO,QAAQ,OAAO;AAAA,SAE9B,IAAI,CAAC,MAAM;AACV,eAAO,EAAE,eAAe,EAAE,cAAc,IAAI,aAAa,QAAQ;AAAA;AAAA;AAAA;AAzB7D;",
|
|
6
6
|
"names": []
|
|
@@ -8,7 +8,7 @@ function loadTamagui(props) {
|
|
|
8
8
|
return loadedTamagui;
|
|
9
9
|
}
|
|
10
10
|
process.env.IS_STATIC = "is_static";
|
|
11
|
-
const proxyWorm = require("
|
|
11
|
+
const proxyWorm = require("react-native-web");
|
|
12
12
|
const Mod = require("module");
|
|
13
13
|
const og = Mod.prototype.require;
|
|
14
14
|
Mod.prototype.require = function(path) {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/extractor/loadTamagui.ts"],
|
|
4
|
+
"sourcesContent": ["import { join } from 'path'\n\nimport type { StaticComponent, TamaguiInternalConfig } from '@tamagui/core'\nimport { createTamagui } from '@tamagui/core-node'\n\nlet loadedTamagui: any = null\n\nexport function loadTamagui(props: { components: string[]; config: string }): {\n components: Record<string, StaticComponent>\n tamaguiConfig: TamaguiInternalConfig\n} {\n if (loadedTamagui) {\n return loadedTamagui\n }\n\n // lets shim require and avoid importing react-native + react-native-web\n // we just need to read the config around them\n process.env.IS_STATIC = 'is_static'\n const proxyWorm = require('react-native-web')\n const Mod = require('module')\n const og = Mod.prototype.require\n Mod.prototype.require = function (path: string) {\n if (\n path.startsWith('react-native') &&\n // allow our rnw.tsx imports through\n !path.startsWith('react-native-web/dist/cjs/exports')\n ) {\n return proxyWorm\n }\n return og.apply(this, arguments)\n }\n\n // import config\n const configPath = join(process.cwd(), props.config)\n const tamaguiConfigExport = require(configPath)\n const tamaguiConfig = (tamaguiConfigExport['default'] ||\n tamaguiConfigExport) as TamaguiInternalConfig\n\n // import components\n const components = {}\n for (const module of props.components) {\n const exported = require(module)\n Object.assign(components, exported)\n }\n\n // undo shims\n process.env.IS_STATIC = undefined\n Mod.prototype.require = og\n\n // set up core-node\n createTamagui(tamaguiConfig)\n\n loadedTamagui = {\n components,\n tamaguiConfig,\n }\n\n return loadedTamagui\n}\n"],
|
|
5
|
+
"mappings": ";;AAAA;AAGA;AAEA,IAAI,gBAAqB;AAElB,qBAAqB,OAG1B;AACA,MAAI,eAAe;AACjB,WAAO;AAAA;AAKT,UAAQ,IAAI,YAAY;AACxB,QAAM,YAAY,QAAQ;AAC1B,QAAM,MAAM,QAAQ;AACpB,QAAM,KAAK,IAAI,UAAU;AACzB,MAAI,UAAU,UAAU,SAAU,MAAc;AAC9C,QACE,KAAK,WAAW,mBAEhB,CAAC,KAAK,WAAW,sCACjB;AACA,aAAO;AAAA;AAET,WAAO,GAAG,MAAM,MAAM;AAAA;AAIxB,QAAM,aAAa,KAAK,QAAQ,OAAO,MAAM;AAC7C,QAAM,sBAAsB,QAAQ;AACpC,QAAM,gBAAiB,oBAAoB,cACzC;AAGF,QAAM,aAAa;AACnB,aAAW,UAAU,MAAM,YAAY;AACrC,UAAM,WAAW,QAAQ;AACzB,WAAO,OAAO,YAAY;AAAA;AAI5B,UAAQ,IAAI,YAAY;AACxB,MAAI,UAAU,UAAU;AAGxB,gBAAc;AAEd,kBAAgB;AAAA,IACd;AAAA,IACA;AAAA;AAGF,SAAO;AAAA;AAlDO;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
const logLines = /* @__PURE__ */ __name((str) => {
|
|
4
|
+
let lines = [""];
|
|
5
|
+
const items = str.split(" ");
|
|
6
|
+
for (const item of items) {
|
|
7
|
+
if (item.length + lines[lines.length - 1].length > 100) {
|
|
8
|
+
lines.push("");
|
|
9
|
+
}
|
|
10
|
+
lines[lines.length - 1] += item + " ";
|
|
11
|
+
}
|
|
12
|
+
return lines.map((line, i) => " " + (i == 0 ? "" : " ") + line.trim()).join("\n");
|
|
13
|
+
}, "logLines");
|
|
14
|
+
export {
|
|
15
|
+
logLines
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=logLines.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/extractor/logLines.ts"],
|
|
4
|
+
"sourcesContent": ["export const logLines = (str: string) => {\n let lines: string[] = ['']\n const items = str.split(' ')\n for (const item of items) {\n if (item.length + lines[lines.length - 1].length > 100) {\n lines.push('')\n }\n lines[lines.length - 1] += item + ' '\n }\n return lines.map((line, i) => ' ' + (i == 0 ? '' : ' ') + line.trim()).join('\\n')\n}\n"],
|
|
5
|
+
"mappings": ";;AAAO,MAAM,WAAW,wBAAC,QAAgB;AACvC,MAAI,QAAkB,CAAC;AACvB,QAAM,QAAQ,IAAI,MAAM;AACxB,aAAW,QAAQ,OAAO;AACxB,QAAI,KAAK,SAAS,MAAM,MAAM,SAAS,GAAG,SAAS,KAAK;AACtD,YAAM,KAAK;AAAA;AAEb,UAAM,MAAM,SAAS,MAAM,OAAO;AAAA;AAEpC,SAAO,MAAM,IAAI,CAAC,MAAM,MAAM,gBAAiB,MAAK,IAAI,KAAK,OAAO,KAAK,QAAQ,KAAK;AAAA,GAThE;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -4,6 +4,7 @@ import generate from "@babel/generator";
|
|
|
4
4
|
import * as t from "@babel/types";
|
|
5
5
|
import invariant from "invariant";
|
|
6
6
|
function normalizeTernaries(ternaries) {
|
|
7
|
+
var _a, _b;
|
|
7
8
|
invariant(Array.isArray(ternaries), "extractStaticTernaries expects param 1 to be an array of ternaries");
|
|
8
9
|
if (ternaries.length === 0) {
|
|
9
10
|
return [];
|
|
@@ -35,8 +36,8 @@ function normalizeTernaries(ternaries) {
|
|
|
35
36
|
remove
|
|
36
37
|
};
|
|
37
38
|
}
|
|
38
|
-
const altStyle = (shouldSwap ? consequent : alternate)
|
|
39
|
-
const consStyle = (shouldSwap ? alternate : consequent)
|
|
39
|
+
const altStyle = (_a = shouldSwap ? consequent : alternate) != null ? _a : {};
|
|
40
|
+
const consStyle = (_b = shouldSwap ? alternate : consequent) != null ? _b : {};
|
|
40
41
|
Object.assign(ternariesByKey[key].alternate, altStyle);
|
|
41
42
|
Object.assign(ternariesByKey[key].consequent, consStyle);
|
|
42
43
|
}
|