@tamagui/static 1.0.1-beta.59 → 1.0.1-beta.60
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 +18 -1
- package/dist/cjs/extractor/createExtractor.js.map +2 -2
- package/dist/esm/extractor/createExtractor.js +18 -1
- package/dist/esm/extractor/createExtractor.js.map +2 -2
- package/dist/jsx/extractor/createExtractor.js +18 -1
- package/package.json +9 -7
- package/src/constants.ts +13 -0
- package/src/extractor/accessSafe.ts +18 -0
- package/src/extractor/babelParse.ts +27 -0
- package/src/extractor/buildClassName.ts +61 -0
- package/src/extractor/createEvaluator.ts +69 -0
- package/src/extractor/createExtractor.ts +1696 -0
- package/src/extractor/ensureImportingConcat.ts +39 -0
- package/src/extractor/evaluateAstNode.ts +121 -0
- package/src/extractor/extractHelpers.ts +119 -0
- package/src/extractor/extractMediaStyle.ts +190 -0
- package/src/extractor/extractToClassNames.ts +455 -0
- package/src/extractor/findTopmostFunction.ts +22 -0
- package/src/extractor/generatedUid.ts +43 -0
- package/src/extractor/getPrefixLogs.ts +6 -0
- package/src/extractor/getPropValueFromAttributes.ts +92 -0
- package/src/extractor/getSourceModule.ts +101 -0
- package/src/extractor/getStaticBindingsForScope.ts +183 -0
- package/src/extractor/hoistClassNames.ts +45 -0
- package/src/extractor/literalToAst.ts +84 -0
- package/src/extractor/loadTamagui.ts +139 -0
- package/src/extractor/logLines.ts +16 -0
- package/src/extractor/normalizeTernaries.ts +63 -0
- package/src/extractor/removeUnusedHooks.ts +76 -0
- package/src/extractor/timer.ts +18 -0
- package/src/extractor/validHTMLAttributes.ts +99 -0
- package/src/index.ts +9 -0
- package/src/patchReactNativeWeb.ts +165 -0
- package/src/types.ts +97 -0
- package/types/extractor/createExtractor.d.ts +14 -1
- package/types/extractor/createExtractor.d.ts.map +1 -1
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import * as t from '@babel/types'
|
|
2
|
+
|
|
3
|
+
import { ClassNameObject } from '../types'
|
|
4
|
+
|
|
5
|
+
export function buildClassName(
|
|
6
|
+
classNameObjects: ClassNameObject[]
|
|
7
|
+
): t.Expression | t.StringLiteral | null {
|
|
8
|
+
return classNameObjects.reduce<t.Expression | null>((acc, val) => {
|
|
9
|
+
if (acc == null) {
|
|
10
|
+
if (
|
|
11
|
+
// pass conditional expressions through
|
|
12
|
+
t.isConditionalExpression(val) ||
|
|
13
|
+
// pass non-null literals through
|
|
14
|
+
t.isStringLiteral(val) ||
|
|
15
|
+
t.isNumericLiteral(val)
|
|
16
|
+
) {
|
|
17
|
+
return val
|
|
18
|
+
}
|
|
19
|
+
return t.logicalExpression('||', val, t.stringLiteral(''))
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let inner: t.Expression
|
|
23
|
+
if (t.isStringLiteral(val)) {
|
|
24
|
+
if (t.isStringLiteral(acc)) {
|
|
25
|
+
// join adjacent string literals
|
|
26
|
+
return t.stringLiteral(`${acc.value} ${val.value}`)
|
|
27
|
+
}
|
|
28
|
+
inner = t.stringLiteral(` ${val.value}`)
|
|
29
|
+
} else if (t.isLiteral(val)) {
|
|
30
|
+
inner = t.binaryExpression('+', t.stringLiteral(' '), val)
|
|
31
|
+
} else if (t.isConditionalExpression(val) || t.isBinaryExpression(val)) {
|
|
32
|
+
if (t.isStringLiteral(acc)) {
|
|
33
|
+
return t.binaryExpression('+', t.stringLiteral(`${acc.value} `), val)
|
|
34
|
+
}
|
|
35
|
+
inner = t.binaryExpression('+', t.stringLiteral(' '), val)
|
|
36
|
+
} else if (t.isIdentifier(val) || t.isMemberExpression(val)) {
|
|
37
|
+
// identifiers and member expressions make for reasonable ternaries
|
|
38
|
+
inner = t.conditionalExpression(
|
|
39
|
+
val,
|
|
40
|
+
t.binaryExpression('+', t.stringLiteral(' '), val),
|
|
41
|
+
t.stringLiteral('')
|
|
42
|
+
)
|
|
43
|
+
} else {
|
|
44
|
+
if (t.isStringLiteral(acc)) {
|
|
45
|
+
return t.binaryExpression(
|
|
46
|
+
'+',
|
|
47
|
+
t.stringLiteral(`${acc.value} `),
|
|
48
|
+
t.logicalExpression('||', val, t.stringLiteral(''))
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
// use a logical expression for more complex prop values
|
|
52
|
+
inner = t.binaryExpression(
|
|
53
|
+
'+',
|
|
54
|
+
t.stringLiteral(' '),
|
|
55
|
+
t.logicalExpression('||', val, t.stringLiteral(''))
|
|
56
|
+
)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return t.binaryExpression('+', acc, inner)
|
|
60
|
+
}, null)
|
|
61
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import vm from 'vm'
|
|
2
|
+
|
|
3
|
+
import generate from '@babel/generator'
|
|
4
|
+
import { NodePath } from '@babel/traverse'
|
|
5
|
+
import * as t from '@babel/types'
|
|
6
|
+
import type { TamaguiConfig } from '@tamagui/core'
|
|
7
|
+
import { createCSSVariable } from '@tamagui/core-node'
|
|
8
|
+
|
|
9
|
+
import { FAILED_EVAL } from '../constants'
|
|
10
|
+
import { evaluateAstNode } from './evaluateAstNode'
|
|
11
|
+
import { isValidThemeHook } from './extractHelpers'
|
|
12
|
+
|
|
13
|
+
export function createEvaluator({
|
|
14
|
+
tamaguiConfig,
|
|
15
|
+
staticNamespace,
|
|
16
|
+
sourcePath,
|
|
17
|
+
traversePath,
|
|
18
|
+
shouldPrintDebug,
|
|
19
|
+
}: {
|
|
20
|
+
tamaguiConfig: TamaguiConfig
|
|
21
|
+
staticNamespace: Record<string, any>
|
|
22
|
+
sourcePath: string
|
|
23
|
+
traversePath: NodePath<t.JSXElement>
|
|
24
|
+
shouldPrintDebug: boolean | 'verbose'
|
|
25
|
+
}) {
|
|
26
|
+
// called when evaluateAstNode encounters a dynamic-looking prop
|
|
27
|
+
const evalFn = (n: t.Node) => {
|
|
28
|
+
// themes
|
|
29
|
+
if (
|
|
30
|
+
t.isMemberExpression(n) &&
|
|
31
|
+
t.isIdentifier(n.property) &&
|
|
32
|
+
isValidThemeHook(traversePath, n, sourcePath)
|
|
33
|
+
) {
|
|
34
|
+
const key = n.property.name
|
|
35
|
+
if (shouldPrintDebug) {
|
|
36
|
+
console.log(' > found theme prop', key)
|
|
37
|
+
}
|
|
38
|
+
console.log('SHOULD FIND THEME (NESTED NOW)', key) // tamaguiConfig.themes)
|
|
39
|
+
// if (!themeKeys.has(key)) {
|
|
40
|
+
// throw new Error(` > accessing non-existent theme key: ${key}`)
|
|
41
|
+
// }
|
|
42
|
+
return createCSSVariable(key)
|
|
43
|
+
}
|
|
44
|
+
// variable
|
|
45
|
+
if (t.isIdentifier(n) && staticNamespace.hasOwnProperty(n.name)) {
|
|
46
|
+
return staticNamespace[n.name]
|
|
47
|
+
}
|
|
48
|
+
const evalContext = vm.createContext(staticNamespace)
|
|
49
|
+
const code = `(${generate(n as any).code})`
|
|
50
|
+
// if (shouldPrintDebug) {
|
|
51
|
+
// console.log('evaluating', { n, code, evalContext })
|
|
52
|
+
// }
|
|
53
|
+
return vm.runInContext(code, evalContext)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return (n: t.Node) => {
|
|
57
|
+
return evaluateAstNode(n, evalFn)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function createSafeEvaluator(attemptEval: (n: t.Node) => any) {
|
|
62
|
+
return (n: t.Node) => {
|
|
63
|
+
try {
|
|
64
|
+
return attemptEval(n)
|
|
65
|
+
} catch (err) {
|
|
66
|
+
return FAILED_EVAL
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|