@tamagui/static 1.0.0-alpha.61 → 1.0.0-alpha.65
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/extractor/createExtractor.js +46 -12
- package/dist/cjs/extractor/createExtractor.js.map +2 -2
- package/dist/cjs/extractor/extractHelpers.js +15 -5
- package/dist/cjs/extractor/extractHelpers.js.map +2 -2
- package/dist/cjs/extractor/extractMediaStyle.js.map +1 -1
- package/dist/cjs/extractor/extractToClassNames.js +27 -17
- package/dist/cjs/extractor/extractToClassNames.js.map +2 -2
- package/dist/cjs/extractor/getPrefixLogs.js +34 -0
- package/dist/cjs/extractor/getPrefixLogs.js.map +7 -0
- package/dist/cjs/extractor/literalToAst.js +59 -0
- package/dist/cjs/extractor/literalToAst.js.map +2 -2
- package/dist/cjs/patchReactNativeWeb.js +1 -1
- package/dist/cjs/patchReactNativeWeb.js.map +1 -1
- package/dist/cjs/types.js.map +1 -1
- package/dist/esm/extractor/createExtractor.js +45 -10
- package/dist/esm/extractor/createExtractor.js.map +2 -2
- package/dist/esm/extractor/extractHelpers.js +16 -5
- package/dist/esm/extractor/extractHelpers.js.map +2 -2
- package/dist/esm/extractor/extractMediaStyle.js.map +1 -1
- package/dist/esm/extractor/extractToClassNames.js +29 -19
- package/dist/esm/extractor/extractToClassNames.js.map +2 -2
- package/dist/esm/extractor/getPrefixLogs.js +12 -0
- package/dist/esm/extractor/getPrefixLogs.js.map +7 -0
- package/dist/esm/extractor/literalToAst.js +46 -0
- package/dist/esm/extractor/literalToAst.js.map +2 -2
- package/dist/esm/patchReactNativeWeb.js +1 -1
- package/dist/esm/patchReactNativeWeb.js.map +1 -1
- package/dist/jsx/extractor/createExtractor.js +45 -10
- package/dist/jsx/extractor/extractHelpers.js +16 -5
- package/dist/jsx/extractor/extractToClassNames.js +29 -19
- package/dist/jsx/extractor/getPrefixLogs.js +11 -0
- package/dist/jsx/extractor/literalToAst.js +46 -0
- package/dist/jsx/patchReactNativeWeb.js +1 -1
- package/package.json +7 -7
- package/types/extractor/createExtractor.d.ts +1 -1
- package/types/extractor/getPrefixLogs.d.ts +3 -0
- package/types/extractor/literalToAst.d.ts +1 -0
- package/types/types.d.ts +2 -0
- package/types/constants.d.ts.map +0 -1
- package/types/extractor/accessSafe.d.ts.map +0 -1
- package/types/extractor/babelParse.d.ts.map +0 -1
- package/types/extractor/buildClassName.d.ts.map +0 -1
- package/types/extractor/createEvaluator.d.ts.map +0 -1
- package/types/extractor/createExtractor.d.ts.map +0 -1
- package/types/extractor/ensureImportingConcat.d.ts.map +0 -1
- package/types/extractor/evaluateAstNode.d.ts.map +0 -1
- package/types/extractor/extractHelpers.d.ts.map +0 -1
- package/types/extractor/extractMediaStyle.d.ts.map +0 -1
- package/types/extractor/extractToClassNames.d.ts.map +0 -1
- package/types/extractor/findTopmostFunction.d.ts.map +0 -1
- package/types/extractor/generatedUid.d.ts.map +0 -1
- package/types/extractor/getPropValueFromAttributes.d.ts.map +0 -1
- package/types/extractor/getSourceModule.d.ts.map +0 -1
- package/types/extractor/getStaticBindingsForScope.d.ts.map +0 -1
- package/types/extractor/hoistClassNames.d.ts.map +0 -1
- package/types/extractor/literalToAst.d.ts.map +0 -1
- package/types/extractor/loadTamagui.d.ts.map +0 -1
- package/types/extractor/logLines.d.ts.map +0 -1
- package/types/extractor/normalizeTernaries.d.ts.map +0 -1
- package/types/extractor/removeUnusedHooks.d.ts.map +0 -1
- package/types/index.d.ts.map +0 -1
- package/types/patchReactNativeWeb.d.ts.map +0 -1
- package/types/types.d.ts.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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 let hasFlattened = false\n\n const res = extractor.parse(ast, {\n sourcePath,\n shouldPrintDebug,\n ...options,\n getFlattenedNode: ({ tag }) => {\n hasFlattened = true\n return tag\n },\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 (!hasFlattened) {\n // not flat\n } else {\n ensureImportingConcat(programPath)\n const simpleSpreads = attrs.filter(\n (x) => t.isJSXSpreadAttribute(x.value) && isSimpleSpread(x.value)\n )\n expr = t.callExpression(t.identifier(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;
|
|
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, Ternary } 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 { getPrefixLogs } from './getPrefixLogs'\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 let hasFlattened = false\n\n const res = extractor.parse(ast, {\n sourcePath,\n shouldPrintDebug,\n ...options,\n getFlattenedNode: ({ tag }) => {\n hasFlattened = true\n return tag\n },\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): StyleObject[] => {\n if (!style) return []\n const styleWithPrev = ensureNeededPrevStyle(style)\n const res = getStylesAtomic(styleWithPrev)\n if (res.length) {\n finalStyles = [...finalStyles, ...res]\n }\n return res\n }\n\n // 1 to start above any :hover styles\n let lastMediaImportance = 1\n for (const attr of attrs) {\n switch (attr.type) {\n case 'style':\n 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 (shouldPrintDebug) {\n // prettier-ignore\n console.log('ternary (mediaStyles)', mediaExtraction?.ternaryWithoutMedia?.inlineMediaQuery ?? '', mediaExtraction?.mediaStyles.map((x) => x.identifier).join('.'))\n }\n if (!mediaExtraction) {\n addTernaryStyle(\n attr.value,\n addStyles(attr.value.consequent),\n addStyles(attr.value.alternate)\n )\n continue\n }\n lastMediaImportance++\n if (mediaExtraction.mediaStyles) {\n finalStyles = [...finalStyles, ...mediaExtraction.mediaStyles]\n }\n if (mediaExtraction.ternaryWithoutMedia) {\n addTernaryStyle(mediaExtraction.ternaryWithoutMedia, mediaExtraction.mediaStyles, [])\n } else {\n finalClassNames = [\n ...finalClassNames,\n ...mediaExtraction.mediaStyles.map((x) => t.stringLiteral(x.identifier)),\n ]\n }\n break\n }\n }\n\n function addTernaryStyle(ternary: Ternary, a: any, b: any) {\n const cCN = a.map((x) => x.identifier).join(' ')\n const aCN = b.map((x) => x.identifier).join(' ')\n if (a.length && b.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 }\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 (!hasFlattened) {\n // not flat\n } else {\n ensureImportingConcat(programPath)\n const simpleSpreads = attrs.filter(\n (x) => t.isJSXSpreadAttribute(x.value) && isSimpleSpread(x.value)\n )\n expr = t.callExpression(t.identifier(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(30)\n const numOptimized = `${res.optimized}`.padStart(4)\n const memory = memUsed > 10 ? `used ${memUsed}MB` : ''\n console.log(\n `${getPrefixLogs(options)} ${path} ${timing}ms \u05C1\u00B7 ${numOptimized} optimized \u00B7 ${\n res.flattened\n } 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;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;AAvDF;AAwDE,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;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AM,QAAO,SAAS,YAAY,SAAS;AAC3C,UAAM,eAAe,GAAG,IAAI,YAAY,SAAS;AACjD,UAAM,SAAS,UAAU,KAAK,QAAQ,cAAc;AACpD,YAAQ,IACN,GAAG,cAAc,YAAY,SAAQ,uBAAe,+BAClD,IAAI,uBACQ;AAAA;AAIlB,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,IAAI,OAAO;AAAA,IACX,KAAK,OAAO;AAAA;AAAA;AAjUA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
function getPrefixLogs(options) {
|
|
4
|
+
var _a;
|
|
5
|
+
const { TAMAGUI_TARGET } = process.env;
|
|
6
|
+
return (_a = options == null ? void 0 : options.prefixLogs) != null ? _a : `[${TAMAGUI_TARGET}] \xBB `;
|
|
7
|
+
}
|
|
8
|
+
__name(getPrefixLogs, "getPrefixLogs");
|
|
9
|
+
export {
|
|
10
|
+
getPrefixLogs
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=getPrefixLogs.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/extractor/getPrefixLogs.ts"],
|
|
4
|
+
"sourcesContent": ["import { TamaguiOptions } from '../types'\n\nexport function getPrefixLogs(options?: TamaguiOptions) {\n const { TAMAGUI_TARGET } = process.env\n return options?.prefixLogs ?? `[${TAMAGUI_TARGET}] \u00BB `\n}\n"],
|
|
5
|
+
"mappings": ";;AAEO,uBAAuB,SAA0B;AAFxD;AAGE,QAAM,EAAE,mBAAmB,QAAQ;AACnC,SAAO,yCAAS,eAAT,YAAuB,IAAI;AAAA;AAFpB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -28,7 +28,53 @@ function literalToAst(literal) {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
__name(literalToAst, "literalToAst");
|
|
31
|
+
const easyPeasies = ["BooleanLiteral", "StringLiteral", "NumericLiteral"];
|
|
32
|
+
function astToLiteral(node) {
|
|
33
|
+
if (!node) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (easyPeasies.includes(node.type)) {
|
|
37
|
+
return node.value;
|
|
38
|
+
}
|
|
39
|
+
if (node.name === "undefined" && !node.value) {
|
|
40
|
+
return void 0;
|
|
41
|
+
}
|
|
42
|
+
if (t.isNullLiteral(node)) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
if (t.isObjectExpression(node)) {
|
|
46
|
+
return computeProps(node.properties);
|
|
47
|
+
}
|
|
48
|
+
if (t.isArrayExpression(node)) {
|
|
49
|
+
return node.elements.reduce((acc, element) => [
|
|
50
|
+
...acc,
|
|
51
|
+
...(element == null ? void 0 : element.type) === "SpreadElement" ? astToLiteral(element.argument) : [astToLiteral(element)]
|
|
52
|
+
], []);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
__name(astToLiteral, "astToLiteral");
|
|
56
|
+
function computeProps(props) {
|
|
57
|
+
return props.reduce((acc, prop) => {
|
|
58
|
+
if (prop.type === "SpreadElement") {
|
|
59
|
+
return {
|
|
60
|
+
...acc,
|
|
61
|
+
...astToLiteral(prop.argument)
|
|
62
|
+
};
|
|
63
|
+
} else if (prop.type !== "ObjectMethod") {
|
|
64
|
+
const val = astToLiteral(prop.value);
|
|
65
|
+
if (val !== void 0) {
|
|
66
|
+
return {
|
|
67
|
+
...acc,
|
|
68
|
+
[prop.key.name]: val
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return acc;
|
|
73
|
+
}, {});
|
|
74
|
+
}
|
|
75
|
+
__name(computeProps, "computeProps");
|
|
31
76
|
export {
|
|
77
|
+
astToLiteral,
|
|
32
78
|
literalToAst
|
|
33
79
|
};
|
|
34
80
|
//# sourceMappingURL=literalToAst.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/extractor/literalToAst.ts"],
|
|
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
|
-
"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;",
|
|
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\nconst easyPeasies = ['BooleanLiteral', 'StringLiteral', 'NumericLiteral']\n\nexport function astToLiteral(node: any) {\n if (!node) {\n return\n }\n if (easyPeasies.includes(node.type)) {\n return node.value\n }\n if (node.name === 'undefined' && !node.value) {\n return undefined\n }\n if (t.isNullLiteral(node)) {\n return null\n }\n if (t.isObjectExpression(node)) {\n return computeProps(node.properties)\n }\n if (t.isArrayExpression(node)) {\n return node.elements.reduce(\n // @ts-ignore\n (acc, element) => [\n ...acc,\n ...(element?.type === 'SpreadElement'\n ? astToLiteral(element.argument)\n : [astToLiteral(element)]),\n ],\n []\n )\n }\n}\n\nfunction computeProps(props) {\n return props.reduce((acc, prop) => {\n if (prop.type === 'SpreadElement') {\n return {\n ...acc,\n ...astToLiteral(prop.argument),\n }\n } else if (prop.type !== 'ObjectMethod') {\n const val = astToLiteral(prop.value)\n if (val !== undefined) {\n return {\n ...acc,\n [prop.key.name]: val,\n }\n }\n }\n return acc\n }, {})\n}\n"],
|
|
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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IvB,WAAO;AAAA,KACN;AAAA;AAjBI;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -16,7 +16,7 @@ function patchReactNativeWeb() {
|
|
|
16
16
|
return res;
|
|
17
17
|
})();
|
|
18
18
|
if (!isEqual) {
|
|
19
|
-
console.log("\
|
|
19
|
+
console.log("\xBB Tamagui patching react-native-web to share atomic styling primitives");
|
|
20
20
|
console.log(" > adding", modulePath);
|
|
21
21
|
console.log(" > adding", cjsPath);
|
|
22
22
|
fs.writeFileSync(modulePath, moduleExports);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/patchReactNativeWeb.ts"],
|
|
4
|
-
"sourcesContent": ["import * as fs from 'fs'\nimport path from 'path'\n\n// were patching react-native-web so we can use some internal methods\n// we do it this way because we need to rely on webpack or bundler config to determine cjs vs esm\n// so we can't just require it all directly\n// would be nice in the future to be able to eject from react-native-web entirely optionally\n\n// keep it sync\nexport function patchReactNativeWeb() {\n const rootDir = require.resolve('react-native-web').replace(/\\/dist.*/, '')\n const modulePath = path.join(rootDir, 'dist', 'tamagui-exports.js')\n const cjsPath = path.join(rootDir, 'dist', 'cjs', 'tamagui-exports.js')\n\n const isEqual = (() => {\n let res = false\n try {\n res =\n fs.readFileSync(modulePath, 'utf-8') === moduleExports &&\n fs.readFileSync(cjsPath, 'utf-8') == cjsExports\n } catch {\n res = false\n }\n return res\n })()\n\n if (!isEqual) {\n console.log('\
|
|
4
|
+
"sourcesContent": ["import * as fs from 'fs'\nimport path from 'path'\n\n// were patching react-native-web so we can use some internal methods\n// we do it this way because we need to rely on webpack or bundler config to determine cjs vs esm\n// so we can't just require it all directly\n// would be nice in the future to be able to eject from react-native-web entirely optionally\n\n// keep it sync\nexport function patchReactNativeWeb() {\n const rootDir = require.resolve('react-native-web').replace(/\\/dist.*/, '')\n const modulePath = path.join(rootDir, 'dist', 'tamagui-exports.js')\n const cjsPath = path.join(rootDir, 'dist', 'cjs', 'tamagui-exports.js')\n\n const isEqual = (() => {\n let res = false\n try {\n res =\n fs.readFileSync(modulePath, 'utf-8') === moduleExports &&\n fs.readFileSync(cjsPath, 'utf-8') == cjsExports\n } catch {\n res = false\n }\n return res\n })()\n\n if (!isEqual) {\n console.log('\u00BB Tamagui patching react-native-web to share atomic styling primitives')\n console.log(' > adding', modulePath)\n console.log(' > adding', cjsPath)\n fs.writeFileSync(modulePath, moduleExports)\n fs.writeFileSync(cjsPath, cjsExports)\n }\n\n // patch to allow className prop\n const classNamePatch = `if (props.dataSet && props.dataSet['__className']) { domProps.className = className ? className + ' ' + props.dataSet['__className'] : props.dataSet['__className']; delete props.dataSet['__className'] }`\n const domPropsPath = ['modules', 'createDOMProps', 'index.js']\n const domPropsModulePath = path.join(rootDir, 'dist', ...domPropsPath)\n const domPropsCjsPath = path.join(rootDir, 'dist', 'cjs', ...domPropsPath)\n const patchClassName = (file: string) => {\n const contents = fs.readFileSync(file, 'utf-8')\n if (!contents.includes(classNamePatch)) {\n const needle = `domProps.className = className`\n const patchLocation = contents.indexOf(needle) + needle.length + 5\n // its far down the file\n if (patchLocation < 100) {\n console.warn(\n `\u26A0\uFE0F Couldn't apply className patch! Maybe using incompatible react-native-web version.`\n )\n } else {\n const before = contents.slice(0, patchLocation)\n const after = contents.slice(patchLocation)\n const patched = before + '\\n' + classNamePatch + '\\n' + after\n console.log(' > adding className support to react-native-web', file)\n fs.writeFileSync(file, patched)\n }\n }\n }\n patchClassName(domPropsModulePath)\n patchClassName(domPropsCjsPath)\n\n // if (props.className) {\n // domProps.className = className ? className + ' ' + props.className : props.className\n // }\n\n // if entry files not patched, patch them:\n const moduleEntry = path.join(rootDir, 'dist', 'index.js')\n const moduleEntrySrc = fs.readFileSync(moduleEntry, 'utf-8')\n if (!moduleEntrySrc.includes('// tamagui-patch-v4')) {\n fs.writeFileSync(\n moduleEntry,\n `${removePatch(moduleEntrySrc)}\n\n// tamagui-patch-v4\nimport * as TExports from './tamagui-exports'\nexport const TamaguiExports = TExports\n// tamagui-patch-end\n`\n )\n }\n const cjsEntry = path.join(rootDir, 'dist', 'cjs', 'index.js')\n const cjsEntrySrc = fs.readFileSync(cjsEntry, 'utf-8')\n if (!cjsEntrySrc.includes('// tamagui-patch-v4')) {\n fs.writeFileSync(\n cjsEntry,\n `${removePatch(cjsEntrySrc)}\n\n// tamagui-patch-v4\nexports.TamaguiExports = _interopRequireDefault(require(\"./tamagui-exports\"));\n// tamagui-patch-end\n`\n )\n }\n}\n\nfunction removePatch(source: string) {\n return source.replace(/\\/\\/ tamagui-patch([.\\s\\S]*)/g, '')\n}\n\n// view exports/View.ts\nconst forwardedPropsObj = `{\n ...fwdProps.defaultProps,\n ...fwdProps.accessibilityProps,\n ...fwdProps.clickProps,\n ...fwdProps.focusProps,\n ...fwdProps.keyboardProps,\n ...fwdProps.mouseProps,\n ...fwdProps.touchProps,\n ...fwdProps.styleProps,\n href: true,\n lang: true,\n onScroll: true,\n onWheel: true,\n pointerEvents: true\n}\n`\n\nconst moduleExports = `\nexport { atomic } from './exports/StyleSheet/compile'\nexport { default as createCompileableStyle } from './exports/StyleSheet/createCompileableStyle'\nexport { default as createReactDOMStyle } from './exports/StyleSheet/createReactDOMStyle'\nexport { default as i18Style } from './exports/StyleSheet/i18nStyle'\nexport { default as createDOMProps } from './modules/createDOMProps'\nexport { default as AccessibilityUtil } from './modules/AccessibilityUtil'\nexport { default as createElement } from './exports/createElement'\nexport { default as css } from './exports/StyleSheet/css'\nexport { default as TextAncestorContext } from './exports/Text/TextAncestorContext'\nexport { default as pick } from './modules/pick'\nexport { default as useElementLayout } from './modules/useElementLayout'\nexport { default as useMergeRefs } from './modules/useMergeRefs'\nexport { default as usePlatformMethods } from './modules/usePlatformMethods'\nexport { default as useResponderEvents } from './modules/useResponderEvents'\nimport * as fwdProps from './modules/forwardedProps'\nexport const forwardedProps = ${forwardedPropsObj}\n`\n\nconst cjsExports = `\nexports.atomic = require('./exports/StyleSheet/compile').atomic\nexports.createCompileableStyle = require('./exports/StyleSheet/createCompileableStyle')\nexports.createReactDOMStyle = require('./exports/StyleSheet/createReactDOMStyle')\nexports.i18Style = require('./exports/StyleSheet/i18nStyle')\nexports.createDOMProps = require('./modules/createDOMProps')\nexports.AccessibilityUtil = require('./modules/AccessibilityUtil')\nexports.createElement = require('./exports/createElement')\nexports.css = require('./exports/StyleSheet/css')\nexports.TextAncestorContext = require('./exports/Text/TextAncestorContext')\nexports.pick = require('./modules/pick')\nexports.useElementLayout = require('./modules/useElementLayout')\nexports.useMergeRefs = require('./modules/useMergeRefs')\nexports.usePlatformMethods = require('./modules/usePlatformMethods')\nexports.useResponderEvents = require('./modules/useResponderEvents')\nconst fwdProps = require('./modules/forwardedProps')\nexports.forwardedProps = ${forwardedPropsObj}\n`\n"],
|
|
5
5
|
"mappings": ";;AAAA;AACA;AAQO,+BAA+B;AACpC,QAAM,UAAU,AAAgB,oCAAoB,QAAQ,YAAY;AACxE,QAAM,aAAa,KAAK,KAAK,SAAS,QAAQ;AAC9C,QAAM,UAAU,KAAK,KAAK,SAAS,QAAQ,OAAO;AAElD,QAAM,UAAW,OAAM;AACrB,QAAI,MAAM;AACV,QAAI;AACF,YACE,GAAG,aAAa,YAAY,aAAa,iBACzC,GAAG,aAAa,SAAS,YAAY;AAAA,YACvC;AACA,YAAM;AAAA;AAER,WAAO;AAAA;AAGT,MAAI,CAAC,SAAS;AACZ,YAAQ,IAAI;AACZ,YAAQ,IAAI,eAAe;AAC3B,YAAQ,IAAI,eAAe;AAC3B,OAAG,cAAc,YAAY;AAC7B,OAAG,cAAc,SAAS;AAAA;AAI5B,QAAM,iBAAiB;AACvB,QAAM,eAAe,CAAC,WAAW,kBAAkB;AACnD,QAAM,qBAAqB,KAAK,KAAK,SAAS,QAAQ,GAAG;AACzD,QAAM,kBAAkB,KAAK,KAAK,SAAS,QAAQ,OAAO,GAAG;AAC7D,QAAM,iBAAiB,wBAAC,SAAiB;AACvC,UAAM,WAAW,GAA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2BAgBQ;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -51,6 +51,7 @@ function createExtractor() {
|
|
|
51
51
|
disableExtractInlineMedia,
|
|
52
52
|
disableExtractVariables,
|
|
53
53
|
disableDebugAttr,
|
|
54
|
+
prefixLogs,
|
|
54
55
|
...props
|
|
55
56
|
}) => {
|
|
56
57
|
if (sourcePath === "") {
|
|
@@ -156,7 +157,7 @@ function createExtractor() {
|
|
|
156
157
|
}
|
|
157
158
|
if (disableExtraction) {
|
|
158
159
|
if (!hasLogged) {
|
|
159
|
-
console.log("
|
|
160
|
+
console.log(prefixLogs, "Tamagui disableExtraction set: no CSS or optimizations will be run");
|
|
160
161
|
hasLogged = true;
|
|
161
162
|
}
|
|
162
163
|
return;
|
|
@@ -325,6 +326,29 @@ function createExtractor() {
|
|
|
325
326
|
if (!t.isObjectProperty(property)) {
|
|
326
327
|
throw new Error("expected object property");
|
|
327
328
|
}
|
|
329
|
+
if (t.isIdentifier(property.key)) {
|
|
330
|
+
const key = property.key.name;
|
|
331
|
+
const mediaQueryKey = key.slice(1);
|
|
332
|
+
const isMediaQuery = key[0] === "$" && mediaQueryConfig[mediaQueryKey];
|
|
333
|
+
if (isMediaQuery) {
|
|
334
|
+
if (t.isExpression(property.value)) {
|
|
335
|
+
const ternaries2 = createTernariesFromObjectProperties(t.stringLiteral(mediaQueryKey), property.value, {
|
|
336
|
+
inlineMediaQuery: mediaQueryKey
|
|
337
|
+
});
|
|
338
|
+
if (ternaries2) {
|
|
339
|
+
return ternaries2.map((value) => ({
|
|
340
|
+
...ternaryPartial,
|
|
341
|
+
...value,
|
|
342
|
+
test: t.logicalExpression("&&", value.test, test)
|
|
343
|
+
}));
|
|
344
|
+
} else {
|
|
345
|
+
console.log("\u26A0\uFE0F no ternaries?", property);
|
|
346
|
+
}
|
|
347
|
+
} else {
|
|
348
|
+
console.log("\u26A0\uFE0F not expression", property);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
328
352
|
if (t.isConditionalExpression(property.value)) {
|
|
329
353
|
const [truthy, falsy] = [
|
|
330
354
|
t.objectExpression([t.objectProperty(property.key, property.value.consequent)]),
|
|
@@ -388,10 +412,16 @@ function createExtractor() {
|
|
|
388
412
|
}
|
|
389
413
|
}
|
|
390
414
|
if (t.isJSXSpreadAttribute(attribute) || !attribute.name || typeof attribute.name.name !== "string") {
|
|
415
|
+
if (shouldPrintDebug) {
|
|
416
|
+
console.log(" ! inlining, spread attr");
|
|
417
|
+
}
|
|
391
418
|
inlinePropCount++;
|
|
392
419
|
return attr;
|
|
393
420
|
}
|
|
394
421
|
const name = attribute.name.name;
|
|
422
|
+
if (name.startsWith("data-")) {
|
|
423
|
+
return attr;
|
|
424
|
+
}
|
|
395
425
|
if (isExcludedProp(name)) {
|
|
396
426
|
return null;
|
|
397
427
|
}
|
|
@@ -452,7 +482,7 @@ function createExtractor() {
|
|
|
452
482
|
if (value) {
|
|
453
483
|
if (value.type === "StringLiteral" && value.value[0] === "$") {
|
|
454
484
|
if (shouldPrintDebug) {
|
|
455
|
-
console.log(`
|
|
485
|
+
console.log(` ! inlining, native disable extract: ${name} =`, value.value);
|
|
456
486
|
}
|
|
457
487
|
inlinePropCount++;
|
|
458
488
|
return attr;
|
|
@@ -470,6 +500,9 @@ function createExtractor() {
|
|
|
470
500
|
}
|
|
471
501
|
for (const key of keys) {
|
|
472
502
|
if (!isStaticAttributeName(key)) {
|
|
503
|
+
if (shouldPrintDebug) {
|
|
504
|
+
console.log(" ! inlining, non-static", key);
|
|
505
|
+
}
|
|
473
506
|
inlinePropCount++;
|
|
474
507
|
}
|
|
475
508
|
}
|
|
@@ -760,6 +793,8 @@ function createExtractor() {
|
|
|
760
793
|
var _a2;
|
|
761
794
|
if (!props2)
|
|
762
795
|
return;
|
|
796
|
+
if (!Object.keys(props2).length)
|
|
797
|
+
return;
|
|
763
798
|
if (!!excludeProps.size) {
|
|
764
799
|
for (const key in props2) {
|
|
765
800
|
if (isExcludedProp(key))
|
|
@@ -769,9 +804,9 @@ function createExtractor() {
|
|
|
769
804
|
const out = postProcessStyles(props2, staticConfig, defaultTheme);
|
|
770
805
|
const next = (_a2 = out == null ? void 0 : out.style) != null ? _a2 : props2;
|
|
771
806
|
if (shouldPrintDebug) {
|
|
772
|
-
console.log("
|
|
773
|
-
console.log("
|
|
774
|
-
console.log("
|
|
807
|
+
console.log(" -- getStyles (viewProps):\n", logLines(objToStr(out.viewProps)));
|
|
808
|
+
console.log(" -- getStyles (props):\n", logLines(objToStr(props2)));
|
|
809
|
+
console.log(" -- getStyles (next):\n", logLines(objToStr(next)));
|
|
775
810
|
}
|
|
776
811
|
for (const key in next) {
|
|
777
812
|
if (staticConfig.validStyles) {
|
|
@@ -800,12 +835,14 @@ function createExtractor() {
|
|
|
800
835
|
}
|
|
801
836
|
}
|
|
802
837
|
if (shouldPrintDebug) {
|
|
803
|
-
console.log(" completeStaticProps
|
|
804
|
-
console.log(" completeStylesProcessed
|
|
838
|
+
console.log(" -- completeStaticProps:\n", logLines(objToStr(completeStaticProps)));
|
|
839
|
+
console.log(" -- completeStylesProcessed:\n", logLines(objToStr(completeStylesProcessed)));
|
|
805
840
|
}
|
|
806
841
|
let getStyleError = null;
|
|
807
842
|
for (const attr of attrs) {
|
|
808
843
|
try {
|
|
844
|
+
if (shouldPrintDebug)
|
|
845
|
+
console.log(" *", attrStr(attr));
|
|
809
846
|
switch (attr.type) {
|
|
810
847
|
case "ternary":
|
|
811
848
|
const a = getStyles(attr.value.alternate);
|
|
@@ -825,8 +862,6 @@ function createExtractor() {
|
|
|
825
862
|
return [keyIn, (_a2 = completeStylesProcessed[keyIn]) != null ? _a2 : attr.value[keyIn]];
|
|
826
863
|
}
|
|
827
864
|
})();
|
|
828
|
-
if (shouldPrintDebug)
|
|
829
|
-
console.log("style", { keyIn, key, value });
|
|
830
865
|
delete attr.value[keyIn];
|
|
831
866
|
attr.value[key] = value;
|
|
832
867
|
}
|
|
@@ -856,7 +891,7 @@ function createExtractor() {
|
|
|
856
891
|
}
|
|
857
892
|
}
|
|
858
893
|
if (shouldPrintDebug) {
|
|
859
|
-
console.log(
|
|
894
|
+
console.log(` \u274A\u274A inline props (${inlinePropCount}):`, shouldDeopt ? " deopted" : "", hasSpread ? " has spread" : "", staticConfig.neverFlatten ? "neverFlatten" : "");
|
|
860
895
|
console.log(" - attrs (end):\n", logLines(attrs.map(attrStr).join(", ")));
|
|
861
896
|
}
|
|
862
897
|
res.optimized++;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
import * as t from "@babel/types";
|
|
4
|
+
import { astToLiteral } from "./literalToAst";
|
|
4
5
|
function isPresent(input) {
|
|
5
6
|
return input != null;
|
|
6
7
|
}
|
|
@@ -13,7 +14,7 @@ const attrStr = /* @__PURE__ */ __name((attr) => {
|
|
|
13
14
|
return attr.type === "attr" ? getNameAttr(attr.value) : attr.type === "ternary" ? `...${ternaryStr(attr.value)}` : `${attr.type}(${objToStr(attr.value)})`;
|
|
14
15
|
}, "attrStr");
|
|
15
16
|
const objToStr = /* @__PURE__ */ __name((obj) => {
|
|
16
|
-
return Object.entries(obj).map(([k, v]) => `${k}:${Array.isArray(v) ? `[...]` : v && typeof v === "object" ? `{${objToStr(v)}}` : v}`).join(", ")
|
|
17
|
+
return `{${Object.entries(obj).map(([k, v]) => `${k}:${Array.isArray(v) ? `[...]` : v && typeof v === "object" ? `{${objToStr(v)}}` : JSON.stringify(v)}`).join(", ")}}`;
|
|
17
18
|
}, "objToStr");
|
|
18
19
|
const getNameAttr = /* @__PURE__ */ __name((attr) => {
|
|
19
20
|
if (t.isJSXSpreadAttribute(attr)) {
|
|
@@ -22,11 +23,21 @@ const getNameAttr = /* @__PURE__ */ __name((attr) => {
|
|
|
22
23
|
return "name" in attr ? attr.name.name : `unknown-${attr["type"]}`;
|
|
23
24
|
}, "getNameAttr");
|
|
24
25
|
const ternaryStr = /* @__PURE__ */ __name((x) => {
|
|
26
|
+
var _a;
|
|
27
|
+
const conditional = t.isIdentifier(x.test) ? x.test.name : t.isMemberExpression(x.test) ? [x.test.object["name"], x.test.property["name"]] : (_a = astToLiteral(x.test)) != null ? _a : [
|
|
28
|
+
x.test["type"],
|
|
29
|
+
astToLiteral(x.test["left"]),
|
|
30
|
+
x.test["operator"],
|
|
31
|
+
astToLiteral(x.test["right"]),
|
|
32
|
+
x.test["value"],
|
|
33
|
+
x.test["name"]
|
|
34
|
+
].filter((x2) => typeof x2 !== "undefined").join(" ");
|
|
25
35
|
return [
|
|
26
|
-
"ternary
|
|
27
|
-
|
|
28
|
-
x.consequent ? `
|
|
29
|
-
x.alternate ? `
|
|
36
|
+
"ternary(",
|
|
37
|
+
conditional,
|
|
38
|
+
x.consequent ? ` ? ${objToStr(x.consequent)}` : " ? \u{1F6AB}",
|
|
39
|
+
x.alternate ? ` : ${objToStr(x.alternate)}` : " : \u{1F6AB}",
|
|
40
|
+
")"
|
|
30
41
|
].flat().join("");
|
|
31
42
|
}, "ternaryStr");
|
|
32
43
|
function findComponentName(scope) {
|
|
@@ -15,6 +15,7 @@ import { buildClassName } from "./buildClassName";
|
|
|
15
15
|
import { ensureImportingConcat } from "./ensureImportingConcat";
|
|
16
16
|
import { isSimpleSpread } from "./extractHelpers";
|
|
17
17
|
import { extractMediaStyle } from "./extractMediaStyle";
|
|
18
|
+
import { getPrefixLogs } from "./getPrefixLogs";
|
|
18
19
|
import { hoistClassNames } from "./hoistClassNames";
|
|
19
20
|
import { logLines } from "./logLines";
|
|
20
21
|
const mergeStyleGroups = {
|
|
@@ -69,6 +70,7 @@ function extractToClassNames({
|
|
|
69
70
|
lineNumbers,
|
|
70
71
|
programPath
|
|
71
72
|
}) => {
|
|
73
|
+
var _a2, _b;
|
|
72
74
|
let finalClassNames = [];
|
|
73
75
|
let finalAttrs = [];
|
|
74
76
|
let finalStyles = [];
|
|
@@ -79,14 +81,14 @@ function extractToClassNames({
|
|
|
79
81
|
}
|
|
80
82
|
}
|
|
81
83
|
const ensureNeededPrevStyle = /* @__PURE__ */ __name((style) => {
|
|
82
|
-
var
|
|
84
|
+
var _a3;
|
|
83
85
|
const keys = Object.keys(style);
|
|
84
86
|
if (!keys.some((key) => mergeStyleGroups[key])) {
|
|
85
87
|
return style;
|
|
86
88
|
}
|
|
87
89
|
for (const k in mergeStyleGroups) {
|
|
88
90
|
if (k in viewStyles) {
|
|
89
|
-
style[k] = (
|
|
91
|
+
style[k] = (_a3 = style[k]) != null ? _a3 : viewStyles[k];
|
|
90
92
|
}
|
|
91
93
|
}
|
|
92
94
|
return style;
|
|
@@ -139,30 +141,38 @@ function extractToClassNames({
|
|
|
139
141
|
break;
|
|
140
142
|
case "ternary":
|
|
141
143
|
const mediaExtraction = extractMediaStyle(attr.value, jsxPath, extractor.getTamagui(), sourcePath, lastMediaImportance, shouldPrintDebug);
|
|
142
|
-
if (
|
|
143
|
-
|
|
144
|
+
if (shouldPrintDebug) {
|
|
145
|
+
console.log("ternary (mediaStyles)", (_b = (_a2 = mediaExtraction == null ? void 0 : mediaExtraction.ternaryWithoutMedia) == null ? void 0 : _a2.inlineMediaQuery) != null ? _b : "", mediaExtraction == null ? void 0 : mediaExtraction.mediaStyles.map((x) => x.identifier).join("."));
|
|
146
|
+
}
|
|
147
|
+
if (!mediaExtraction) {
|
|
148
|
+
addTernaryStyle(attr.value, addStyles(attr.value.consequent), addStyles(attr.value.alternate));
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
lastMediaImportance++;
|
|
152
|
+
if (mediaExtraction.mediaStyles) {
|
|
144
153
|
finalStyles = [...finalStyles, ...mediaExtraction.mediaStyles];
|
|
154
|
+
}
|
|
155
|
+
if (mediaExtraction.ternaryWithoutMedia) {
|
|
156
|
+
addTernaryStyle(mediaExtraction.ternaryWithoutMedia, mediaExtraction.mediaStyles, []);
|
|
157
|
+
} else {
|
|
145
158
|
finalClassNames = [
|
|
146
159
|
...finalClassNames,
|
|
147
160
|
...mediaExtraction.mediaStyles.map((x) => t.stringLiteral(x.identifier))
|
|
148
161
|
];
|
|
149
|
-
if (!mediaExtraction.ternaryWithoutMedia) {
|
|
150
|
-
continue;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
const ternary = (mediaExtraction == null ? void 0 : mediaExtraction.ternaryWithoutMedia) || attr.value;
|
|
154
|
-
const consInfo = addStyles(ternary.consequent);
|
|
155
|
-
const altInfo = addStyles(ternary.alternate);
|
|
156
|
-
const cCN = consInfo.map((x) => x.identifier).join(" ");
|
|
157
|
-
const aCN = altInfo.map((x) => x.identifier).join(" ");
|
|
158
|
-
if (consInfo.length && altInfo.length) {
|
|
159
|
-
finalClassNames.push(t.conditionalExpression(ternary.test, t.stringLiteral(cCN), t.stringLiteral(aCN)));
|
|
160
|
-
} else {
|
|
161
|
-
finalClassNames.push(t.conditionalExpression(ternary.test, t.stringLiteral(" " + cCN), t.stringLiteral(" " + aCN)));
|
|
162
162
|
}
|
|
163
163
|
break;
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
|
+
function addTernaryStyle(ternary, a, b) {
|
|
167
|
+
const cCN = a.map((x) => x.identifier).join(" ");
|
|
168
|
+
const aCN = b.map((x) => x.identifier).join(" ");
|
|
169
|
+
if (a.length && b.length) {
|
|
170
|
+
finalClassNames.push(t.conditionalExpression(ternary.test, t.stringLiteral(cCN), t.stringLiteral(aCN)));
|
|
171
|
+
} else {
|
|
172
|
+
finalClassNames.push(t.conditionalExpression(ternary.test, t.stringLiteral(" " + cCN), t.stringLiteral(" " + aCN)));
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
__name(addTernaryStyle, "addTernaryStyle");
|
|
166
176
|
node.attributes = finalAttrs;
|
|
167
177
|
if (finalClassNames.length) {
|
|
168
178
|
const names = buildClassName(finalClassNames);
|
|
@@ -229,10 +239,10 @@ function extractToClassNames({
|
|
|
229
239
|
if (shouldLogTiming) {
|
|
230
240
|
const memUsed = mem ? Math.round((process.memoryUsage().heapUsed - mem.heapUsed) / 1024 / 1204 * 10) / 10 : 0;
|
|
231
241
|
const timing = `${Date.now() - start}`.padStart(3);
|
|
232
|
-
const path2 = basename(sourcePath).padStart(
|
|
242
|
+
const path2 = basename(sourcePath).padStart(30);
|
|
233
243
|
const numOptimized = `${res.optimized}`.padStart(4);
|
|
234
244
|
const memory = memUsed > 10 ? `used ${memUsed}MB` : "";
|
|
235
|
-
console.log(
|
|
245
|
+
console.log(`${getPrefixLogs(options)} ${path2} ${timing}ms \u05C1\xB7 ${numOptimized} optimized \xB7 ${res.flattened} flattened ${memory}`);
|
|
236
246
|
}
|
|
237
247
|
return {
|
|
238
248
|
ast,
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
function getPrefixLogs(options) {
|
|
4
|
+
var _a;
|
|
5
|
+
const { TAMAGUI_TARGET } = process.env;
|
|
6
|
+
return (_a = options == null ? void 0 : options.prefixLogs) != null ? _a : `[${TAMAGUI_TARGET}] \xBB `;
|
|
7
|
+
}
|
|
8
|
+
__name(getPrefixLogs, "getPrefixLogs");
|
|
9
|
+
export {
|
|
10
|
+
getPrefixLogs
|
|
11
|
+
};
|
|
@@ -28,6 +28,52 @@ function literalToAst(literal) {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
__name(literalToAst, "literalToAst");
|
|
31
|
+
const easyPeasies = ["BooleanLiteral", "StringLiteral", "NumericLiteral"];
|
|
32
|
+
function astToLiteral(node) {
|
|
33
|
+
if (!node) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (easyPeasies.includes(node.type)) {
|
|
37
|
+
return node.value;
|
|
38
|
+
}
|
|
39
|
+
if (node.name === "undefined" && !node.value) {
|
|
40
|
+
return void 0;
|
|
41
|
+
}
|
|
42
|
+
if (t.isNullLiteral(node)) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
if (t.isObjectExpression(node)) {
|
|
46
|
+
return computeProps(node.properties);
|
|
47
|
+
}
|
|
48
|
+
if (t.isArrayExpression(node)) {
|
|
49
|
+
return node.elements.reduce((acc, element) => [
|
|
50
|
+
...acc,
|
|
51
|
+
...(element == null ? void 0 : element.type) === "SpreadElement" ? astToLiteral(element.argument) : [astToLiteral(element)]
|
|
52
|
+
], []);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
__name(astToLiteral, "astToLiteral");
|
|
56
|
+
function computeProps(props) {
|
|
57
|
+
return props.reduce((acc, prop) => {
|
|
58
|
+
if (prop.type === "SpreadElement") {
|
|
59
|
+
return {
|
|
60
|
+
...acc,
|
|
61
|
+
...astToLiteral(prop.argument)
|
|
62
|
+
};
|
|
63
|
+
} else if (prop.type !== "ObjectMethod") {
|
|
64
|
+
const val = astToLiteral(prop.value);
|
|
65
|
+
if (val !== void 0) {
|
|
66
|
+
return {
|
|
67
|
+
...acc,
|
|
68
|
+
[prop.key.name]: val
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return acc;
|
|
73
|
+
}, {});
|
|
74
|
+
}
|
|
75
|
+
__name(computeProps, "computeProps");
|
|
31
76
|
export {
|
|
77
|
+
astToLiteral,
|
|
32
78
|
literalToAst
|
|
33
79
|
};
|
|
@@ -16,7 +16,7 @@ function patchReactNativeWeb() {
|
|
|
16
16
|
return res;
|
|
17
17
|
})();
|
|
18
18
|
if (!isEqual) {
|
|
19
|
-
console.log("\
|
|
19
|
+
console.log("\xBB Tamagui patching react-native-web to share atomic styling primitives");
|
|
20
20
|
console.log(" > adding", modulePath);
|
|
21
21
|
console.log(" > adding", cjsPath);
|
|
22
22
|
fs.writeFileSync(modulePath, moduleExports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/static",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.65",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"typings": "types",
|
|
6
6
|
"main": "dist/cjs",
|
|
@@ -59,11 +59,11 @@
|
|
|
59
59
|
"@babel/traverse": "^7.15.4",
|
|
60
60
|
"@dish/babel-preset": "^0.0.6",
|
|
61
61
|
"@expo/match-media": "^0.1.0",
|
|
62
|
-
"@tamagui/build": "^1.0.0-alpha.
|
|
63
|
-
"@tamagui/core": "^1.0.0-alpha.
|
|
64
|
-
"@tamagui/core-node": "^1.0.0-alpha.
|
|
62
|
+
"@tamagui/build": "^1.0.0-alpha.64",
|
|
63
|
+
"@tamagui/core": "^1.0.0-alpha.64",
|
|
64
|
+
"@tamagui/core-node": "^1.0.0-alpha.64",
|
|
65
65
|
"@tamagui/fake-react-native": "^1.0.0-alpha.17",
|
|
66
|
-
"@tamagui/helpers": "^1.0.0-alpha.
|
|
66
|
+
"@tamagui/helpers": "^1.0.0-alpha.64",
|
|
67
67
|
"babel-literal-to-ast": "^2.1.0",
|
|
68
68
|
"esbuild": "^0.13.12",
|
|
69
69
|
"esbuild-register": "^3.1.2",
|
|
@@ -72,10 +72,10 @@
|
|
|
72
72
|
"invariant": "^2.2.4",
|
|
73
73
|
"loader-utils": "^2.0.0",
|
|
74
74
|
"lodash": "^4.17.21",
|
|
75
|
-
"tamagui": "^1.0.0-alpha.
|
|
75
|
+
"tamagui": "^1.0.0-alpha.65"
|
|
76
76
|
},
|
|
77
77
|
"peerDependencies": {
|
|
78
78
|
"react-native-web": "*"
|
|
79
79
|
},
|
|
80
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "d46048ccedd1de78f6e7a1cca9c5cf0f5bccb675"
|
|
81
81
|
}
|
|
@@ -24,7 +24,7 @@ export declare function createExtractor(): {
|
|
|
24
24
|
[key: string]: string | number;
|
|
25
25
|
};
|
|
26
26
|
}>;
|
|
27
|
-
parse: (fileOrPath: NodePath<t.Program> | t.File, { config, importsWhitelist, evaluateVars, shouldPrintDebug, sourcePath, onExtractTag, getFlattenedNode, disableExtraction, disableExtractInlineMedia, disableExtractVariables, disableDebugAttr, ...props }: ExtractorParseProps) => {
|
|
27
|
+
parse: (fileOrPath: NodePath<t.Program> | t.File, { config, importsWhitelist, evaluateVars, shouldPrintDebug, sourcePath, onExtractTag, getFlattenedNode, disableExtraction, disableExtractInlineMedia, disableExtractVariables, disableDebugAttr, prefixLogs, ...props }: ExtractorParseProps) => {
|
|
28
28
|
flattened: number;
|
|
29
29
|
optimized: number;
|
|
30
30
|
modified: number;
|