@tamagui/static 1.0.1-beta.66 → 1.0.1-beta.69
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/extractor/createEvaluator.js +1 -1
- package/dist/cjs/extractor/createEvaluator.js.map +2 -2
- package/dist/cjs/extractor/createExtractor.js +227 -115
- package/dist/cjs/extractor/createExtractor.js.map +2 -2
- package/dist/cjs/extractor/extractToClassNames.js +16 -20
- package/dist/cjs/extractor/extractToClassNames.js.map +2 -2
- package/dist/cjs/patchReactNativeWeb.js +29 -89
- package/dist/cjs/patchReactNativeWeb.js.map +2 -2
- package/dist/cjs/types.js.map +1 -1
- package/dist/esm/extractor/createEvaluator.js +1 -1
- package/dist/esm/extractor/createEvaluator.js.map +2 -2
- package/dist/esm/extractor/createExtractor.js +232 -119
- package/dist/esm/extractor/createExtractor.js.map +2 -2
- package/dist/esm/extractor/extractToClassNames.js +16 -20
- package/dist/esm/extractor/extractToClassNames.js.map +2 -2
- package/dist/esm/patchReactNativeWeb.js +29 -89
- package/dist/esm/patchReactNativeWeb.js.map +2 -2
- package/dist/jsx/extractor/createEvaluator.js +1 -1
- package/dist/jsx/extractor/createExtractor.js +232 -119
- package/dist/jsx/extractor/extractToClassNames.js +16 -20
- package/dist/jsx/patchReactNativeWeb.js +29 -89
- package/package.json +17 -12
- package/src/extractor/createEvaluator.ts +2 -1
- package/src/extractor/createExtractor.ts +356 -161
- package/src/extractor/extractToClassNames.ts +20 -31
- package/src/patchReactNativeWeb.ts +47 -96
- package/src/types.ts +6 -8
- package/types/extractor/createEvaluator.d.ts +1 -1
- package/types/extractor/createEvaluator.d.ts.map +1 -1
- package/types/extractor/createExtractor.d.ts +2 -1
- package/types/extractor/createExtractor.d.ts.map +1 -1
- package/types/extractor/extractToClassNames.d.ts.map +1 -1
- package/types/patchReactNativeWeb.d.ts.map +1 -1
- package/types/types.d.ts +4 -7
- package/types/types.d.ts.map +1 -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 { ViewStyle } from 'react-native'\nimport { LoaderContext } from 'webpack'\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 { literalToAst } from './literalToAst'\nimport { logLines } from './logLines'\nimport { timer } from './timer'\n\nconst mergeStyleGroups = {\n shadowOpacity: true,\n shadowRadius: true,\n shadowColor: true,\n shadowOffset: true,\n}\n\nexport type ExtractedResponse = {\n js: string | Buffer\n styles: string\n stylesPath?: string\n ast: t.File\n map: any // RawSourceMap from 'source-map'\n}\n\nexport function extractToClassNames({\n loader,\n extractor,\n source,\n sourcePath,\n options,\n shouldPrintDebug,\n cssLoaderPath,\n threaded,\n cssPath,\n}: {\n loader: LoaderContext<any>\n cssLoaderPath: string\n extractor: Extractor\n source: string | Buffer\n sourcePath: string\n options: TamaguiOptions\n shouldPrintDebug: boolean | 'verbose'\n cssPath: string\n threaded?: boolean\n}): ExtractedResponse | null {\n const tm = timer()\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 tm.mark(`babel-parse`, shouldPrintDebug === 'verbose')\n\n const cssMap = new Map<string, { css: string; commentTexts: string[] }>()\n const existingHoists: { [key: string]: t.Identifier } = {}\n\n let hasFlattened = false\n\n const res = extractor.parse(ast, {\n sourcePath,\n shouldPrintDebug,\n ...options,\n target: 'html',\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 isFlattened,\n }) => {\n let finalClassNames: ClassNameObject[] = []\n let finalAttrs: (t.JSXAttribute | t.JSXSpreadAttribute)[] = []\n let finalStyles: StyleObject[] = []\n\n let viewStyles = {}\n for (const attr of attrs) {\n if (attr.type === 'style') {\n viewStyles = {\n ...viewStyles,\n ...attr.value,\n }\n }\n }\n\n const ensureNeededPrevStyle = (style: ViewStyle) => {\n // ensure all group keys are merged\n const keys = Object.keys(style)\n if (!keys.some((key) => mergeStyleGroups[key])) {\n return style\n }\n for (const k in mergeStyleGroups) {\n if (k in viewStyles) {\n style[k] = style[k] ?? viewStyles[k]\n }\n }\n return style\n }\n\n const addStyles = (style: ViewStyle | null): StyleObject[] => {\n if (!style) return []\n const styleWithPrev = ensureNeededPrevStyle(style)\n const res = getStylesAtomic(styleWithPrev)\n if (res.length) {\n finalStyles = [...finalStyles, ...res]\n }\n return res\n }\n\n // 1 to start above any :hover styles\n let lastMediaImportance = 1\n for (const attr of attrs) {\n switch (attr.type) {\n case 'style':\n if (!isFlattened) {\n // only ever one at a time i believe so we can be lazy with this access\n const { hoverStyle, pressStyle, focusStyle } = attr.value\n const pseudos = [\n ['hoverStyle', hoverStyle],\n ['pressStyle', pressStyle],\n ['focusStyle', focusStyle],\n ] as const\n\n const styles = getStylesAtomic(attr.value, {\n splitTransforms: true,\n })\n finalStyles = [...finalStyles, ...styles]\n\n for (const [key, value] of pseudos) {\n if (value && Object.keys(value).length) {\n finalAttrs.push(\n t.jsxAttribute(\n t.jsxIdentifier(key),\n t.jsxExpressionContainer(literalToAst(value))\n )\n )\n }\n }\n\n for (const style of styles) {\n if (style.pseudo) {\n continue\n }\n // leave them as attributes\n finalAttrs.push(\n t.jsxAttribute(t.jsxIdentifier(style.property), t.stringLiteral(style.identifier))\n )\n }\n } else {\n const styles = addStyles(attr.value)\n const newClassNames = concatClassName(styles.map((x) => x.identifier).join(' '))\n const existing = finalClassNames.find(\n (x) => x.type == 'StringLiteral'\n ) as t.StringLiteral | null\n\n if (existing) {\n existing.value = `${existing.value} ${newClassNames}`\n } else {\n finalClassNames = [...finalClassNames, t.stringLiteral(newClassNames)]\n }\n }\n\n break\n 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 if (mediaExtraction) {\n // prettier-ignore\n console.log('ternary (mediaStyles)', mediaExtraction.ternaryWithoutMedia?.inlineMediaQuery ?? '', mediaExtraction.mediaStyles.map((x) => x.identifier).join('.'))\n }\n }\n if (!mediaExtraction) {\n addTernaryStyle(\n attr.value,\n addStyles(attr.value.consequent),\n addStyles(attr.value.alternate)\n )\n continue\n }\n lastMediaImportance++\n if (mediaExtraction.mediaStyles) {\n finalStyles = [...finalStyles, ...mediaExtraction.mediaStyles]\n }\n if (mediaExtraction.ternaryWithoutMedia) {\n addTernaryStyle(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 if (shouldPrintDebug) {\n // prettier-ignore\n console.log(' finalClassNames\\n', logLines(finalClassNames.map(x => x['value']).join(' ')))\n }\n\n node.attributes = finalAttrs\n\n if (finalClassNames.length) {\n // inserts the _cn variable and uses it for className\n let names = buildClassName(finalClassNames)\n if (t.isStringLiteral(names)) {\n names.value = concatClassName(names.value)\n }\n const nameExpr = names ? hoistClassNames(jsxPath, existingHoists, names) : null\n let expr = nameExpr\n\n // if has some spreads, use concat helper\n if (nameExpr && !t.isIdentifier(nameExpr)) {\n if (!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 = loader.remainingRequest\n const importPath = `${cssPath}!=!${cssLoaderPath}?${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 // this makes the debug output terrible, and i think sourcemap works already\n retainLines: false,\n sourceFileName: sourcePath,\n sourceMaps: true,\n },\n source\n )\n\n if (shouldPrintDebug) {\n 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 path = basename(sourcePath)\n .replace(/\\.[jt]sx?$/, '')\n .slice(0, 22)\n .trim()\n .padStart(24)\n const numOptimized = `${res.optimized}`.padStart(3)\n const numFound = `${res.found}`.padStart(3)\n const numFlattened = `${res.flattened}`.padStart(3)\n const memory = process.env.DEBUG && memUsed > 10 ? ` ${memUsed}MB` : ''\n const timing = Date.now() - start\n const timingWarning = timing > 50 ? '\u26A0\uFE0F' : timing > 150 ? '\u2622\uFE0F' : ''\n const timingStr = `${timing}ms${timingWarning}`.padStart(6)\n console.log(\n `${getPrefixLogs(\n options\n )} ${path} ${numFound} \u00B7 ${numOptimized} \u00B7 ${numFlattened} ${timingStr} ${\n memory ? `(${memory})` : ''\n }`\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;AAIA;AAEA;AACA;AAEA;AACA;AACA;AACA;AACA;
|
|
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 { ViewStyle } from 'react-native'\nimport { LoaderContext } from 'webpack'\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 { literalToAst } from './literalToAst'\nimport { logLines } from './logLines'\nimport { timer } from './timer'\n\nconst mergeStyleGroups = {\n shadowOpacity: true,\n shadowRadius: true,\n shadowColor: true,\n shadowOffset: true,\n}\n\nexport type ExtractedResponse = {\n js: string | Buffer\n styles: string\n stylesPath?: string\n ast: t.File\n map: any // RawSourceMap from 'source-map'\n}\n\nexport function extractToClassNames({\n loader,\n extractor,\n source,\n sourcePath,\n options,\n shouldPrintDebug,\n cssLoaderPath,\n threaded,\n cssPath,\n}: {\n loader: LoaderContext<any>\n cssLoaderPath: string\n extractor: Extractor\n source: string | Buffer\n sourcePath: string\n options: TamaguiOptions\n shouldPrintDebug: boolean | 'verbose'\n cssPath: string\n threaded?: boolean\n}): ExtractedResponse | null {\n const tm = timer()\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 tm.mark(`babel-parse`, shouldPrintDebug === 'verbose')\n\n const cssMap = new Map<string, { css: string; commentTexts: string[] }>()\n const existingHoists: { [key: string]: t.Identifier } = {}\n\n let hasFlattened = false\n\n const res = extractor.parse(ast, {\n sourcePath,\n shouldPrintDebug,\n ...options,\n target: 'html',\n extractStyledDefinitions: true,\n onStyleRule(identifier, rules) {\n cssMap.set(`.${identifier}`, { css: rules.join(';'), commentTexts: [] })\n },\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 isFlattened,\n }) => {\n // reset hasFlattened\n const didFlattenThisTag = hasFlattened\n hasFlattened = false\n\n let finalClassNames: ClassNameObject[] = []\n let finalAttrs: (t.JSXAttribute | t.JSXSpreadAttribute)[] = []\n let finalStyles: StyleObject[] = []\n\n let viewStyles = {}\n for (const attr of attrs) {\n if (attr.type === 'style') {\n viewStyles = {\n ...viewStyles,\n ...attr.value,\n }\n }\n }\n\n const ensureNeededPrevStyle = (style: ViewStyle) => {\n // ensure all group keys are merged\n const keys = Object.keys(style)\n if (!keys.some((key) => mergeStyleGroups[key])) {\n return style\n }\n for (const k in mergeStyleGroups) {\n if (k in viewStyles) {\n style[k] = style[k] ?? viewStyles[k]\n }\n }\n return style\n }\n\n const addStyles = (style: ViewStyle | null): StyleObject[] => {\n if (!style) return []\n const styleWithPrev = ensureNeededPrevStyle(style)\n const res = getStylesAtomic(styleWithPrev)\n if (res.length) {\n finalStyles = [...finalStyles, ...res]\n }\n return res\n }\n\n // 1 to start above any :hover styles\n let lastMediaImportance = 1\n for (const attr of attrs) {\n switch (attr.type) {\n case 'style':\n if (!isFlattened) {\n const styles = getStylesAtomic(attr.value, {\n splitTransforms: true,\n })\n\n finalStyles = [...finalStyles, ...styles]\n\n for (const style of styles) {\n // leave them as attributes\n const prop = style.pseudo ? `${style.property}-${style.pseudo}` : style.property\n finalAttrs.push(\n t.jsxAttribute(t.jsxIdentifier(prop), t.stringLiteral(style.identifier))\n )\n }\n } else {\n const styles = addStyles(attr.value)\n const newClassNames = concatClassName(styles.map((x) => x.identifier).join(' '))\n const existing = finalClassNames.find(\n (x) => x.type == 'StringLiteral'\n ) as t.StringLiteral | null\n\n if (existing) {\n existing.value = `${existing.value} ${newClassNames}`\n } else {\n finalClassNames = [...finalClassNames, t.stringLiteral(newClassNames)]\n }\n }\n\n break\n 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 if (mediaExtraction) {\n // prettier-ignore\n console.log('ternary (mediaStyles)', mediaExtraction.ternaryWithoutMedia?.inlineMediaQuery ?? '', mediaExtraction.mediaStyles.map((x) => x.identifier).join('.'))\n }\n }\n if (!mediaExtraction) {\n addTernaryStyle(\n attr.value,\n addStyles(attr.value.consequent),\n addStyles(attr.value.alternate)\n )\n continue\n }\n lastMediaImportance++\n if (mediaExtraction.mediaStyles) {\n finalStyles = [...finalStyles, ...mediaExtraction.mediaStyles]\n }\n if (mediaExtraction.ternaryWithoutMedia) {\n addTernaryStyle(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 if (shouldPrintDebug) {\n // prettier-ignore\n console.log(' finalClassNames\\n', logLines(finalClassNames.map(x => x['value']).join(' ')))\n }\n\n node.attributes = finalAttrs\n\n if (finalClassNames.length) {\n // inserts the _cn variable and uses it for className\n let names = buildClassName(finalClassNames)\n if (t.isStringLiteral(names)) {\n names.value = concatClassName(names.value)\n }\n const nameExpr = names ? hoistClassNames(jsxPath, existingHoists, names) : null\n let expr = nameExpr\n\n // if has some spreads, use concat helper\n if (nameExpr && !t.isIdentifier(nameExpr)) {\n if (!didFlattenThisTag) {\n // not flat\n } else {\n ensureImportingConcat(programPath)\n const simpleSpreads = attrs.filter(\n (x) => t.isJSXSpreadAttribute(x.value) && isSimpleSpread(x.value)\n )\n expr = t.callExpression(t.identifier(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 { identifier, rules } of finalStyles) {\n const className = `.${identifier}`\n if (cssMap.has(className)) {\n if (comment) {\n const val = cssMap.get(className)!\n val.commentTexts.push(comment)\n cssMap.set(className, val)\n }\n } else if (rules.length) {\n 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 && !res.styled)) {\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 = loader.remainingRequest\n const importPath = `${cssPath}!=!${cssLoaderPath}?${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 // this makes the debug output terrible, and i think sourcemap works already\n retainLines: false,\n sourceFileName: sourcePath,\n sourceMaps: true,\n },\n source\n )\n\n if (shouldPrintDebug) {\n 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 path = basename(sourcePath)\n .replace(/\\.[jt]sx?$/, '')\n .slice(0, 22)\n .trim()\n .padStart(24)\n\n const numStyled = `${res.styled}`.padStart(3)\n const numOptimized = `${res.optimized}`.padStart(3)\n const numFound = `${res.found}`.padStart(3)\n const numFlattened = `${res.flattened}`.padStart(3)\n const memory = process.env.DEBUG && memUsed > 10 ? ` ${memUsed}MB` : ''\n const timing = Date.now() - start\n const timingWarning = timing > 50 ? '\u26A0\uFE0F' : timing > 150 ? '\u2622\uFE0F' : ''\n const timingStr = `${timing}ms${timingWarning}`.padStart(6)\n const pre = getPrefixLogs(options)\n const memStr = memory ? `(${memory})` : ''\n console.log(\n `${pre} ${path} ${numFound} \u00B7 ${numOptimized} \u00B7 ${numFlattened} \u00B7 ${numStyled} ${timingStr} ${memStr}`\n )\n }\n\n return {\n ast,\n styles,\n js: result.code,\n map: result.map,\n }\n}\n"],
|
|
5
|
+
"mappings": ";;AAAA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AAIA;AAEA;AACA;AAEA;AACA;AACA;AACA;AACA;AAEA;AACA;AAEA,MAAM,mBAAmB;AAAA,EACvB,eAAe;AAAA,EACf,cAAc;AAAA,EACd,aAAa;AAAA,EACb,cAAc;AAChB;AAUO,6BAA6B;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,GAW2B;AA7D7B;AA8DE,QAAM,KAAK,MAAM;AAEjB,MAAI,OAAO,WAAW,UAAU;AAC9B,UAAM,IAAI,MAAM,yCAAyC;AAAA,EAC3D;AACA,YACE,OAAO,eAAe,YAAY,KAAK,WAAW,UAAU,GAC5D,qDACF;AAEA,QAAM,kBAAkB,cAAQ,eAAR,YAAsB;AAC9C,QAAM,QAAQ,KAAK,IAAI;AACvB,QAAM,MAAM,kBAAkB,QAAQ,YAAY,IAAI;AAGtD,MAAI;AAEJ,MAAI;AAEF,UAAM,WAAW,MAAM;AAAA,EACzB,SAAS,KAAP;AACA,YAAQ,MAAM,sBAAsB,UAAU;AAC9C,UAAM;AAAA,EACR;AAEA,KAAG,KAAK,eAAe,qBAAqB,SAAS;A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AQ,IACN,wCACA,OAAO,KACJ,MAAM,IAAI,EACV,OAAO,CAAC,MAAM,CAAC,EAAE,WAAW,IAAI,CAAC,EACjC,KAAK,IAAI,CACd;AACA,YAAQ,IAAI,0CAA0C,MAAM;AAAA,EAC9D;AAEA,MAAI,iBAAiB;AACnB,UAAM,UAAU,MACZ,KAAK,MAAQ,SAAQ,YAAY,EAAE,WAAW,IAAI,YAAY,OAAO,OAAQ,EAAE,IAAI,KACnF;AACJ,UAAM,QAAO,SAAS,UAAU,EAC7B,QAAQ,cAAc,EAAE,EACxB,MAAM,GAAG,EAAE,EACX,KAAK,EACL,SAAS,EAAE;AAEd,UAAM,YAAY,GAAG,IAAI,SAAS,SAAS,CAAC;AAC5C,UAAM,eAAe,GAAG,IAAI,YAAY,SAAS,CAAC;AAClD,UAAM,WAAW,GAAG,IAAI,QAAQ,SAAS,CAAC;AAC1C,UAAM,eAAe,GAAG,IAAI,YAAY,SAAS,CAAC;AAClD,UAAM,SAAS,QAAQ,IAAI,SAAS,UAAU,KAAK,IAAI,cAAc;AACrE,UAAM,SAAS,KAAK,IAAI,IAAI;AAC5B,UAAM,gBAAgB,SAAS,KAAK,iBAAO,SAAS,MAAM,iBAAO;AACjE,UAAM,YAAY,GAAG,WAAW,gBAAgB,SAAS,CAAC;AAC1D,UAAM,MAAM,cAAc,OAAO;AACjC,UAAM,SAAS,SAAS,IAAI,YAAY;AACxC,YAAQ,IACN,GAAG,OAAO,UAAS,iBAAc,qBAAkB,qBAAkB,cAAc,aAAa,QAClG;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,IAAI,OAAO;AAAA,IACX,KAAK,OAAO;AAAA,EACd;AACF;AArXgB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -2,80 +2,56 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
import path from "path";
|
|
4
4
|
import * as fs from "fs-extra";
|
|
5
|
+
const PATCH_PREFIX = "tamagui-patch-";
|
|
6
|
+
const PATCH_VERSION = `${PATCH_PREFIX}-v5`;
|
|
7
|
+
const PATCH_COMMENT = `// ${PATCH_VERSION}`;
|
|
8
|
+
const PATCH_END_COMMENT = `// tamagui-patch-end`;
|
|
5
9
|
function patchReactNativeWeb(dir = require.resolve("react-native-web")) {
|
|
6
10
|
const rootDir = dir.replace(/[\/\\]dist.*/, "");
|
|
11
|
+
const pkgJSON = fs.readJSONSync(path.join(rootDir, "package.json"));
|
|
12
|
+
if (pkgJSON.version.split(".")[1] !== "18") {
|
|
13
|
+
console.error(`\u26D4\uFE0F Error! Tamagui as of beta 69 only works with react-native-web version 0.18.x`, pkgJSON.version);
|
|
14
|
+
process.exit(1);
|
|
15
|
+
}
|
|
7
16
|
const modulePath = path.join(rootDir, "dist", "tamagui-exports.js");
|
|
8
17
|
const cjsPath = path.join(rootDir, "dist", "cjs", "tamagui-exports.js");
|
|
9
|
-
const
|
|
10
|
-
if (!
|
|
18
|
+
const alreadyPatchedImports = fs.existsSync(modulePath) && fs.readFileSync(modulePath, "utf-8") === moduleExports && fs.existsSync(cjsPath) && fs.readFileSync(cjsPath, "utf-8") === cjsExports;
|
|
19
|
+
if (!alreadyPatchedImports) {
|
|
11
20
|
console.log(" | patch " + path.relative(rootDir, modulePath));
|
|
12
|
-
console.log(" | patch " + path.relative(rootDir, cjsPath));
|
|
13
21
|
fs.writeFileSync(modulePath, moduleExports);
|
|
22
|
+
console.log(" | patch " + path.relative(rootDir, cjsPath));
|
|
14
23
|
fs.writeFileSync(cjsPath, cjsExports);
|
|
15
24
|
}
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
if (props.dataSet && props.dataSet.id) {
|
|
28
|
-
domProps['id'] = props.dataSet.id
|
|
29
|
-
}
|
|
30
|
-
if (dataSet != null) {`
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
id: "forward-props",
|
|
34
|
-
filePath: ["modules", "forwardedProps", "index.js"],
|
|
35
|
-
replacee: `dataSet: true,`,
|
|
36
|
-
replacer: `id: true, dataSet: true,`
|
|
37
|
-
}
|
|
38
|
-
];
|
|
39
|
-
for (const { filePath, replacee, replacer } of patches) {
|
|
40
|
-
const files = [
|
|
41
|
-
path.join(rootDir, "dist", ...filePath),
|
|
42
|
-
path.join(rootDir, "dist", "cjs", ...filePath)
|
|
43
|
-
];
|
|
44
|
-
for (const file of files) {
|
|
45
|
-
const contents = fs.readFileSync(file, "utf-8");
|
|
46
|
-
if (contents.includes(replacer)) {
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
49
|
-
if (!contents.includes(replacee)) {
|
|
50
|
-
console.warn(`\u26A0\uFE0F Error: couldn't apply className patch! Maybe using incompatible react-native-web version.`, {
|
|
51
|
-
replacee,
|
|
52
|
-
contents
|
|
53
|
-
});
|
|
54
|
-
continue;
|
|
55
|
-
}
|
|
56
|
-
console.log(" | patch " + path.relative(rootDir, file));
|
|
57
|
-
fs.writeFileSync(file, contents.replace(replacee, replacer));
|
|
58
|
-
}
|
|
25
|
+
const dpFile = path.join(rootDir, "dist", "modules", "createDOMProps", "index.js");
|
|
26
|
+
const dpPatched = fs.readFileSync(path.join(__dirname, "..", "..", "patches", "18", "createDOMProps.js"), "utf-8");
|
|
27
|
+
const dpFileCJS = path.join(rootDir, "dist", "cjs", "modules", "createDOMProps", "index.js");
|
|
28
|
+
const dpCJSPatched = fs.readFileSync(path.join(__dirname, "..", "..", "patches", "18", "createDOMProps.cjs.js"), "utf-8");
|
|
29
|
+
const alreadyPatchedDOMProps = fs.readFileSync(dpFile, "utf-8") === dpPatched && fs.readFileSync(dpFileCJS, "utf-8") === dpCJSPatched;
|
|
30
|
+
if (!alreadyPatchedDOMProps) {
|
|
31
|
+
console.log(" | patch " + path.relative(rootDir, dpFile));
|
|
32
|
+
fs.writeFileSync(dpFile, dpPatched);
|
|
33
|
+
console.log(" | patch " + path.relative(rootDir, dpFileCJS));
|
|
34
|
+
fs.writeFileSync(dpFileCJS, dpCJSPatched);
|
|
59
35
|
}
|
|
60
36
|
const moduleEntry = path.join(rootDir, "dist", "index.js");
|
|
61
37
|
const moduleEntrySrc = fs.readFileSync(moduleEntry, "utf-8");
|
|
62
|
-
if (!moduleEntrySrc.includes(
|
|
38
|
+
if (!moduleEntrySrc.includes(PATCH_COMMENT)) {
|
|
63
39
|
fs.writeFileSync(moduleEntry, `${removePatch(moduleEntrySrc)}
|
|
64
40
|
|
|
65
|
-
|
|
41
|
+
${PATCH_COMMENT}
|
|
66
42
|
import * as TExports from './tamagui-exports'
|
|
67
43
|
export const TamaguiExports = TExports
|
|
68
|
-
|
|
44
|
+
${PATCH_END_COMMENT}
|
|
69
45
|
`);
|
|
70
46
|
}
|
|
71
47
|
const cjsEntry = path.join(rootDir, "dist", "cjs", "index.js");
|
|
72
48
|
const cjsEntrySrc = fs.readFileSync(cjsEntry, "utf-8");
|
|
73
|
-
if (!cjsEntrySrc.includes(
|
|
49
|
+
if (!cjsEntrySrc.includes(PATCH_COMMENT)) {
|
|
74
50
|
fs.writeFileSync(cjsEntry, `${removePatch(cjsEntrySrc)}
|
|
75
51
|
|
|
76
|
-
|
|
77
|
-
exports.TamaguiExports =
|
|
78
|
-
|
|
52
|
+
${PATCH_COMMENT}
|
|
53
|
+
exports.TamaguiExports = require("./tamagui-exports");
|
|
54
|
+
${PATCH_END_COMMENT}
|
|
79
55
|
`);
|
|
80
56
|
}
|
|
81
57
|
}
|
|
@@ -84,57 +60,21 @@ function removePatch(source) {
|
|
|
84
60
|
return source.replace(/\/\/ tamagui-patch([.\s\S]*)/g, "");
|
|
85
61
|
}
|
|
86
62
|
__name(removePatch, "removePatch");
|
|
87
|
-
const forwardedPropsObj = `{
|
|
88
|
-
...fwdProps.defaultProps,
|
|
89
|
-
...fwdProps.accessibilityProps,
|
|
90
|
-
...fwdProps.clickProps,
|
|
91
|
-
...fwdProps.focusProps,
|
|
92
|
-
...fwdProps.keyboardProps,
|
|
93
|
-
...fwdProps.mouseProps,
|
|
94
|
-
...fwdProps.touchProps,
|
|
95
|
-
...fwdProps.styleProps,
|
|
96
|
-
href: true,
|
|
97
|
-
lang: true,
|
|
98
|
-
onScroll: true,
|
|
99
|
-
onWheel: true,
|
|
100
|
-
pointerEvents: true
|
|
101
|
-
}
|
|
102
|
-
`;
|
|
103
63
|
const moduleExports = `
|
|
104
|
-
export { atomic } from './exports/StyleSheet/compile'
|
|
105
|
-
export { default as createCompileableStyle } from './exports/StyleSheet/createCompileableStyle'
|
|
106
|
-
export { default as createReactDOMStyle } from './exports/StyleSheet/createReactDOMStyle'
|
|
107
|
-
export { default as i18Style } from './exports/StyleSheet/i18nStyle'
|
|
108
64
|
export { default as createDOMProps } from './modules/createDOMProps'
|
|
109
|
-
export { default as AccessibilityUtil } from './modules/AccessibilityUtil'
|
|
110
|
-
export { default as createElement } from './exports/createElement'
|
|
111
|
-
export { default as css } from './exports/StyleSheet/css'
|
|
112
65
|
export { default as TextAncestorContext } from './exports/Text/TextAncestorContext'
|
|
113
|
-
export { default as pick } from './modules/pick'
|
|
114
66
|
export { default as useElementLayout } from './modules/useElementLayout'
|
|
115
67
|
export { default as useMergeRefs } from './modules/useMergeRefs'
|
|
116
68
|
export { default as usePlatformMethods } from './modules/usePlatformMethods'
|
|
117
69
|
export { default as useResponderEvents } from './modules/useResponderEvents'
|
|
118
|
-
import * as fwdProps from './modules/forwardedProps'
|
|
119
|
-
export const forwardedProps = ${forwardedPropsObj}
|
|
120
70
|
`;
|
|
121
71
|
const cjsExports = `
|
|
122
|
-
exports.atomic = require('./exports/StyleSheet/compile').atomic
|
|
123
|
-
exports.createCompileableStyle = require('./exports/StyleSheet/createCompileableStyle')
|
|
124
|
-
exports.createReactDOMStyle = require('./exports/StyleSheet/createReactDOMStyle')
|
|
125
|
-
exports.i18Style = require('./exports/StyleSheet/i18nStyle')
|
|
126
72
|
exports.createDOMProps = require('./modules/createDOMProps')
|
|
127
|
-
exports.AccessibilityUtil = require('./modules/AccessibilityUtil')
|
|
128
|
-
exports.createElement = require('./exports/createElement')
|
|
129
|
-
exports.css = require('./exports/StyleSheet/css')
|
|
130
73
|
exports.TextAncestorContext = require('./exports/Text/TextAncestorContext')
|
|
131
|
-
exports.pick = require('./modules/pick')
|
|
132
74
|
exports.useElementLayout = require('./modules/useElementLayout')
|
|
133
75
|
exports.useMergeRefs = require('./modules/useMergeRefs')
|
|
134
76
|
exports.usePlatformMethods = require('./modules/usePlatformMethods')
|
|
135
77
|
exports.useResponderEvents = require('./modules/useResponderEvents')
|
|
136
|
-
const fwdProps = require('./modules/forwardedProps')
|
|
137
|
-
exports.forwardedProps = ${forwardedPropsObj}
|
|
138
78
|
`;
|
|
139
79
|
export {
|
|
140
80
|
patchReactNativeWeb
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/patchReactNativeWeb.ts"],
|
|
4
|
-
"sourcesContent": ["import path from 'path'\n\nimport * as fs from 'fs-extra'\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(dir: string = require.resolve('react-native-web')) {\n const rootDir = dir.replace(/[\\/\\\\]dist.*/, '')\n const modulePath = path.join(rootDir, 'dist', 'tamagui-exports.js')\n const cjsPath = path.join(rootDir, 'dist', 'cjs', 'tamagui-exports.js')\n const
|
|
5
|
-
"mappings": ";;AAAA;AAEA;
|
|
4
|
+
"sourcesContent": ["import path from 'path'\n\nimport * as fs from 'fs-extra'\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\nconst PATCH_PREFIX = 'tamagui-patch-'\nconst PATCH_VERSION = `${PATCH_PREFIX}-v5`\nconst PATCH_COMMENT = `// ${PATCH_VERSION}`\nconst PATCH_END_COMMENT = `// tamagui-patch-end`\n\n// keep it sync\nexport function patchReactNativeWeb(dir: string = require.resolve('react-native-web')) {\n const rootDir = dir.replace(/[\\/\\\\]dist.*/, '')\n\n const pkgJSON = fs.readJSONSync(path.join(rootDir, 'package.json'))\n if (pkgJSON.version.split('.')[1] !== '18') {\n console.error(\n `\u26D4\uFE0F Error! Tamagui as of beta 69 only works with react-native-web version 0.18.x`,\n pkgJSON.version\n )\n process.exit(1)\n }\n\n // patch exports for tamagui\n const modulePath = path.join(rootDir, 'dist', 'tamagui-exports.js')\n const cjsPath = path.join(rootDir, 'dist', 'cjs', 'tamagui-exports.js')\n const alreadyPatchedImports =\n fs.existsSync(modulePath) &&\n fs.readFileSync(modulePath, 'utf-8') === moduleExports &&\n fs.existsSync(cjsPath) &&\n fs.readFileSync(cjsPath, 'utf-8') === cjsExports\n\n if (!alreadyPatchedImports) {\n console.log(' | patch ' + path.relative(rootDir, modulePath))\n fs.writeFileSync(modulePath, moduleExports)\n console.log(' | patch ' + path.relative(rootDir, cjsPath))\n fs.writeFileSync(cjsPath, cjsExports)\n }\n\n // patch createDOMProps\n const dpFile = path.join(rootDir, 'dist', 'modules', 'createDOMProps', 'index.js')\n const dpPatched = fs.readFileSync(\n path.join(__dirname, '..', '..', 'patches', '18', 'createDOMProps.js'),\n 'utf-8'\n )\n const dpFileCJS = path.join(rootDir, 'dist', 'cjs', 'modules', 'createDOMProps', 'index.js')\n const dpCJSPatched = fs.readFileSync(\n path.join(__dirname, '..', '..', 'patches', '18', 'createDOMProps.cjs.js'),\n 'utf-8'\n )\n const alreadyPatchedDOMProps =\n fs.readFileSync(dpFile, 'utf-8') === dpPatched &&\n fs.readFileSync(dpFileCJS, 'utf-8') === dpCJSPatched\n\n if (!alreadyPatchedDOMProps) {\n console.log(' | patch ' + path.relative(rootDir, dpFile))\n fs.writeFileSync(dpFile, dpPatched)\n console.log(' | patch ' + path.relative(rootDir, dpFileCJS))\n fs.writeFileSync(dpFileCJS, dpCJSPatched)\n }\n\n // export tamagui exports from root\n const moduleEntry = path.join(rootDir, 'dist', 'index.js')\n const moduleEntrySrc = fs.readFileSync(moduleEntry, 'utf-8')\n if (!moduleEntrySrc.includes(PATCH_COMMENT)) {\n fs.writeFileSync(\n moduleEntry,\n `${removePatch(moduleEntrySrc)}\n\n${PATCH_COMMENT}\nimport * as TExports from './tamagui-exports'\nexport const TamaguiExports = TExports\n${PATCH_END_COMMENT}\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(PATCH_COMMENT)) {\n fs.writeFileSync(\n cjsEntry,\n `${removePatch(cjsEntrySrc)}\n\n${PATCH_COMMENT}\nexports.TamaguiExports = require(\"./tamagui-exports\");\n${PATCH_END_COMMENT}\n`\n )\n }\n}\n\nfunction removePatch(source: string) {\n return source.replace(/\\/\\/ tamagui-patch([.\\s\\S]*)/g, '')\n}\n\nconst moduleExports = `\nexport { default as createDOMProps } from './modules/createDOMProps'\nexport { default as TextAncestorContext } from './exports/Text/TextAncestorContext'\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'\n`\n\nconst cjsExports = `\nexports.createDOMProps = require('./modules/createDOMProps')\nexports.TextAncestorContext = require('./exports/Text/TextAncestorContext')\nexports.useElementLayout = require('./modules/useElementLayout')\nexports.useMergeRefs = require('./modules/useMergeRefs')\nexports.usePlatformMethods = require('./modules/usePlatformMethods')\nexports.useResponderEvents = require('./modules/useResponderEvents')\n`\n"],
|
|
5
|
+
"mappings": ";;AAAA;AAEA;AAOA,MA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AC,wBAAwB;AAC3B,YAAQ,IAAI,mBAAmB,KAAK,SAAS,SAAS,MAAM,CAAC;AAC7D,OAAG,cAAc,QAAQ,SAAS;AAClC,YAAQ,IAAI,mBAAmB,KAAK,SAAS,SAAS,SAAS,CAAC;AAChE,OAAG,cAAc,WAAW,YAAY;AAAA,EAC1C;AAGA,QAAM,cAAc,KAAK,KAAK,SAAS,QAAQ,UAAU;AACzD,QAAM,iBAAiB,GAAG,aAAa,aAAa,OAAO;AAC3D,MAAI,CAAC,eAAe,SAAS,aAAa,GAAG;AAC3C,OAAG,cACD,aACA,GAAG,YAAY,cAAc;AAAA;AAAA,EAEjC;AAAA;AAAA;AAAA,EAGA;AAAA,CAEE;AAAA,EACF;AACA,QAAM,WAAW,KAAK,KAAK,SAAS,QAAQ,OAAO,UAAU;AAC7D,QAAM,cAAc,GAAG,aAAa,UAAU,OAAO;AACrD,MAAI,CAAC,YAAY,SAAS,aAAa,GAAG;AACxC,OAAG,cACD,UACA,GAAG,YAAY,WAAW;AAAA;AAAA,EAE9B;AAAA;AAAA,EAEA;AAAA,CAEE;AAAA,EACF;AACF;AA9EgB;AAgFhB,qBAAqB,QAAgB;AACnC,SAAO,OAAO,QAAQ,iCAAiC,EAAE;AAC3D;AAFS;AAIT,MAAM,gBAAgB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAStB,MAAM,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -16,7 +16,7 @@ function createEvaluator({
|
|
|
16
16
|
shouldPrintDebug
|
|
17
17
|
}) {
|
|
18
18
|
const evalFn = /* @__PURE__ */ __name((n) => {
|
|
19
|
-
if (t.isMemberExpression(n) && t.isIdentifier(n.property) && isValidThemeHook(traversePath, n, sourcePath)) {
|
|
19
|
+
if (t.isMemberExpression(n) && t.isIdentifier(n.property) && traversePath && isValidThemeHook(traversePath, n, sourcePath)) {
|
|
20
20
|
const key = n.property.name;
|
|
21
21
|
if (shouldPrintDebug) {
|
|
22
22
|
console.log(" > found theme prop", key);
|