@tamagui/static 1.0.0-alpha.7 → 1.0.0-beta.172
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/README.md +3 -19
- package/dist/cjs/constants.js +36 -0
- package/dist/cjs/constants.js.map +7 -0
- package/dist/cjs/extractor/accessSafe.js +32 -0
- package/dist/cjs/extractor/accessSafe.js.map +7 -0
- package/dist/cjs/extractor/babelParse.js +51 -0
- package/dist/cjs/extractor/babelParse.js.map +7 -0
- package/dist/cjs/extractor/buildClassName.js +61 -0
- package/dist/cjs/extractor/buildClassName.js.map +7 -0
- package/dist/cjs/extractor/createEvaluator.js +73 -0
- package/dist/cjs/extractor/createEvaluator.js.map +7 -0
- package/dist/cjs/extractor/createExtractor.js +1100 -0
- package/dist/cjs/extractor/createExtractor.js.map +7 -0
- package/dist/cjs/extractor/ensureImportingConcat.js +45 -0
- package/dist/cjs/extractor/ensureImportingConcat.js.map +7 -0
- package/dist/cjs/extractor/evaluateAstNode.js +115 -0
- package/dist/cjs/extractor/evaluateAstNode.js.map +7 -0
- package/dist/cjs/extractor/extractHelpers.js +124 -0
- package/dist/cjs/extractor/extractHelpers.js.map +7 -0
- package/dist/cjs/extractor/extractMediaStyle.js +186 -0
- package/dist/cjs/extractor/extractMediaStyle.js.map +7 -0
- package/dist/cjs/extractor/extractToClassNames.js +324 -0
- package/dist/cjs/extractor/extractToClassNames.js.map +7 -0
- package/dist/cjs/extractor/findTopmostFunction.js +41 -0
- package/dist/cjs/extractor/findTopmostFunction.js.map +7 -0
- package/dist/cjs/extractor/generatedUid.js +49 -0
- package/dist/cjs/extractor/generatedUid.js.map +7 -0
- package/dist/cjs/extractor/getPrefixLogs.js +29 -0
- package/dist/cjs/extractor/getPrefixLogs.js.map +7 -0
- package/dist/cjs/extractor/getPropValueFromAttributes.js +70 -0
- package/dist/cjs/extractor/getPropValueFromAttributes.js.map +7 -0
- package/dist/cjs/extractor/getSourceModule.js +90 -0
- package/dist/cjs/extractor/getSourceModule.js.map +7 -0
- package/dist/cjs/extractor/getStaticBindingsForScope.js +149 -0
- package/dist/cjs/extractor/getStaticBindingsForScope.js.map +7 -0
- package/dist/cjs/extractor/hoistClassNames.js +65 -0
- package/dist/cjs/extractor/hoistClassNames.js.map +7 -0
- package/dist/cjs/extractor/literalToAst.js +114 -0
- package/dist/cjs/extractor/literalToAst.js.map +7 -0
- package/dist/cjs/extractor/loadTamagui.js +83 -0
- package/dist/cjs/extractor/loadTamagui.js.map +7 -0
- package/dist/cjs/extractor/logLines.js +40 -0
- package/dist/cjs/extractor/logLines.js.map +7 -0
- package/dist/cjs/extractor/normalizeTernaries.js +101 -0
- package/dist/cjs/extractor/normalizeTernaries.js.map +7 -0
- package/dist/cjs/extractor/removeUnusedHooks.js +100 -0
- package/dist/cjs/extractor/removeUnusedHooks.js.map +7 -0
- package/dist/cjs/extractor/validHTMLAttributes.js +71 -0
- package/dist/cjs/extractor/validHTMLAttributes.js.map +7 -0
- package/dist/cjs/index.js +34 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/patchReactNativeWeb.js +151 -0
- package/dist/cjs/patchReactNativeWeb.js.map +7 -0
- package/dist/cjs/types.js +16 -0
- package/dist/cjs/types.js.map +7 -0
- package/dist/{constants.js → esm/constants.js} +4 -0
- package/dist/{constants.js.map → esm/constants.js.map} +3 -3
- package/dist/{extractor → esm/extractor}/accessSafe.js +0 -0
- package/dist/{extractor → esm/extractor}/accessSafe.js.map +2 -2
- package/dist/{extractor → esm/extractor}/babelParse.js +0 -0
- package/dist/{extractor → esm/extractor}/babelParse.js.map +2 -2
- package/dist/{extractor → esm/extractor}/buildClassName.js +0 -0
- package/dist/{extractor → esm/extractor}/buildClassName.js.map +2 -2
- package/dist/{extractor → esm/extractor}/createEvaluator.js +3 -2
- package/dist/esm/extractor/createEvaluator.js.map +7 -0
- package/dist/{extractor → esm/extractor}/createExtractor.js +430 -199
- package/dist/esm/extractor/createExtractor.js.map +7 -0
- package/dist/{extractor → esm/extractor}/ensureImportingConcat.js +1 -1
- package/dist/esm/extractor/ensureImportingConcat.js.map +7 -0
- package/dist/{extractor → esm/extractor}/evaluateAstNode.js +0 -0
- package/dist/esm/extractor/evaluateAstNode.js.map +7 -0
- package/dist/{extractor → esm/extractor}/extractHelpers.js +20 -11
- package/dist/esm/extractor/extractHelpers.js.map +7 -0
- package/dist/{extractor → esm/extractor}/extractMediaStyle.js +3 -2
- package/dist/esm/extractor/extractMediaStyle.js.map +7 -0
- package/dist/{extractor → esm/extractor}/extractToClassNames.js +101 -48
- package/dist/esm/extractor/extractToClassNames.js.map +7 -0
- package/dist/{extractor → esm/extractor}/findTopmostFunction.js +0 -0
- package/dist/{extractor → esm/extractor}/findTopmostFunction.js.map +2 -2
- package/dist/{extractor → esm/extractor}/generatedUid.js +0 -0
- package/dist/{extractor → esm/extractor}/generatedUid.js.map +2 -2
- package/dist/esm/extractor/getPrefixLogs.js +12 -0
- package/dist/esm/extractor/getPrefixLogs.js.map +7 -0
- package/dist/{extractor → esm/extractor}/getPropValueFromAttributes.js +0 -0
- package/dist/{extractor → esm/extractor}/getPropValueFromAttributes.js.map +2 -2
- package/dist/{extractor → esm/extractor}/getSourceModule.js +0 -0
- package/dist/{extractor → esm/extractor}/getSourceModule.js.map +2 -2
- package/dist/{extractor → esm/extractor}/getStaticBindingsForScope.js +0 -0
- package/dist/esm/extractor/getStaticBindingsForScope.js.map +7 -0
- package/dist/{extractor → esm/extractor}/hoistClassNames.js +0 -0
- package/dist/{extractor → esm/extractor}/hoistClassNames.js.map +2 -2
- package/dist/esm/extractor/literalToAst.js +80 -0
- package/dist/esm/extractor/literalToAst.js.map +7 -0
- package/dist/{extractor → esm/extractor}/loadTamagui.js +27 -3
- package/dist/esm/extractor/loadTamagui.js.map +7 -0
- package/dist/esm/extractor/logLines.js +22 -0
- package/dist/esm/extractor/logLines.js.map +7 -0
- package/dist/{extractor → esm/extractor}/normalizeTernaries.js +3 -2
- package/dist/esm/extractor/normalizeTernaries.js.map +7 -0
- package/dist/{extractor → esm/extractor}/removeUnusedHooks.js +5 -3
- package/dist/esm/extractor/removeUnusedHooks.js.map +7 -0
- package/dist/esm/extractor/validHTMLAttributes.js +52 -0
- package/dist/esm/extractor/validHTMLAttributes.js.map +7 -0
- package/dist/{index.js → esm/index.js} +0 -0
- package/dist/{index.js.map → esm/index.js.map} +1 -1
- package/dist/{patchReactNativeWeb.js → esm/patchReactNativeWeb.js} +37 -14
- package/dist/esm/patchReactNativeWeb.js.map +7 -0
- package/dist/{types.js → esm/types.js} +0 -0
- package/dist/{types.js.map → esm/types.js.map} +0 -0
- package/dist/jsx/constants.js +13 -0
- package/dist/jsx/extractor/accessSafe.js +10 -0
- package/dist/jsx/extractor/babelParse.js +29 -0
- package/dist/jsx/extractor/buildClassName.js +39 -0
- package/dist/jsx/extractor/createEvaluator.js +51 -0
- package/dist/jsx/extractor/createExtractor.js +1050 -0
- package/dist/jsx/extractor/ensureImportingConcat.js +23 -0
- package/dist/jsx/extractor/evaluateAstNode.js +93 -0
- package/dist/jsx/extractor/extractHelpers.js +102 -0
- package/dist/jsx/extractor/extractMediaStyle.js +151 -0
- package/dist/jsx/extractor/extractToClassNames.js +287 -0
- package/dist/jsx/extractor/findTopmostFunction.js +22 -0
- package/dist/jsx/extractor/generatedUid.js +27 -0
- package/dist/jsx/extractor/getPrefixLogs.js +11 -0
- package/dist/jsx/extractor/getPropValueFromAttributes.js +48 -0
- package/dist/jsx/extractor/getSourceModule.js +68 -0
- package/dist/jsx/extractor/getStaticBindingsForScope.js +127 -0
- package/dist/jsx/extractor/hoistClassNames.js +43 -0
- package/dist/jsx/extractor/literalToAst.js +79 -0
- package/dist/jsx/extractor/loadTamagui.js +64 -0
- package/dist/jsx/extractor/logLines.js +21 -0
- package/dist/jsx/extractor/normalizeTernaries.js +52 -0
- package/dist/jsx/extractor/removeUnusedHooks.js +79 -0
- package/dist/jsx/extractor/validHTMLAttributes.js +51 -0
- package/dist/jsx/index.js +13 -0
- package/{src/patchReactNativeWeb.ts → dist/jsx/patchReactNativeWeb.js} +65 -59
- package/dist/jsx/types.js +0 -0
- package/package.json +26 -22
- package/types/constants.d.ts +6 -0
- package/types/constants.d.ts.map +1 -0
- package/types/extractor/accessSafe.d.ts +3 -0
- package/types/extractor/accessSafe.d.ts.map +1 -0
- package/types/extractor/babelParse.d.ts +5 -0
- package/types/extractor/babelParse.d.ts.map +1 -0
- package/types/extractor/buildClassName.d.ts +4 -0
- package/types/extractor/buildClassName.d.ts.map +1 -0
- package/types/extractor/createEvaluator.d.ts +12 -0
- package/types/extractor/createEvaluator.d.ts.map +1 -0
- package/types/extractor/createExtractor.d.ts +27 -0
- package/types/extractor/createExtractor.d.ts.map +1 -0
- package/types/extractor/ensureImportingConcat.d.ts +4 -0
- package/types/extractor/ensureImportingConcat.d.ts.map +1 -0
- package/types/extractor/evaluateAstNode.d.ts +3 -0
- package/types/extractor/evaluateAstNode.d.ts.map +1 -0
- package/types/extractor/extractHelpers.d.ts +12 -0
- package/types/extractor/extractHelpers.d.ts.map +1 -0
- package/types/extractor/extractMediaStyle.d.ts +10 -0
- package/types/extractor/extractMediaStyle.d.ts.map +1 -0
- package/types/extractor/extractToClassNames.d.ts +23 -0
- package/types/extractor/extractToClassNames.d.ts.map +1 -0
- package/types/extractor/findTopmostFunction.d.ts +4 -0
- package/types/extractor/findTopmostFunction.d.ts.map +1 -0
- package/types/extractor/generatedUid.d.ts +5 -0
- package/types/extractor/generatedUid.d.ts.map +1 -0
- package/types/extractor/getPrefixLogs.d.ts +3 -0
- package/types/extractor/getPrefixLogs.d.ts.map +1 -0
- package/types/extractor/getPropValueFromAttributes.d.ts +3 -0
- package/types/extractor/getPropValueFromAttributes.d.ts.map +1 -0
- package/types/extractor/getSourceModule.d.ts +16 -0
- package/types/extractor/getSourceModule.d.ts.map +1 -0
- package/types/extractor/getStaticBindingsForScope.d.ts +4 -0
- package/types/extractor/getStaticBindingsForScope.d.ts.map +1 -0
- package/types/extractor/hoistClassNames.d.ts +6 -0
- package/types/extractor/hoistClassNames.d.ts.map +1 -0
- package/types/extractor/literalToAst.d.ts +4 -0
- package/types/extractor/literalToAst.d.ts.map +1 -0
- package/types/extractor/loadTamagui.d.ts +9 -0
- package/types/extractor/loadTamagui.d.ts.map +1 -0
- package/types/extractor/logLines.d.ts +2 -0
- package/types/extractor/logLines.d.ts.map +1 -0
- package/types/extractor/normalizeTernaries.d.ts +3 -0
- package/types/extractor/normalizeTernaries.d.ts.map +1 -0
- package/types/extractor/removeUnusedHooks.d.ts +3 -0
- package/types/extractor/removeUnusedHooks.d.ts.map +1 -0
- package/types/extractor/validHTMLAttributes.d.ts +49 -0
- package/types/extractor/validHTMLAttributes.d.ts.map +1 -0
- package/types/index.d.ts +8 -0
- package/types/index.d.ts.map +1 -0
- package/types/patchReactNativeWeb.d.ts +2 -0
- package/types/patchReactNativeWeb.d.ts.map +1 -0
- package/types/types.d.ts +85 -0
- package/types/types.d.ts.map +1 -0
- package/dist/extractor/createEvaluator.js.map +0 -7
- package/dist/extractor/createExtractor.js.map +0 -7
- package/dist/extractor/ensureImportingConcat.js.map +0 -7
- package/dist/extractor/evaluateAstNode.js.map +0 -7
- package/dist/extractor/extractHelpers.js.map +0 -7
- package/dist/extractor/extractMediaStyle.js.map +0 -7
- package/dist/extractor/extractToClassNames.js.map +0 -7
- package/dist/extractor/getStaticBindingsForScope.js.map +0 -7
- package/dist/extractor/literalToAst.js +0 -34
- package/dist/extractor/literalToAst.js.map +0 -7
- package/dist/extractor/loadTamagui.js.map +0 -7
- package/dist/extractor/normalizeTernaries.js.map +0 -7
- package/dist/extractor/removeUnusedHooks.js.map +0 -7
- package/dist/index.cjs +0 -2109
- package/dist/index.cjs.map +0 -7
- package/dist/patchReactNativeWeb.js.map +0 -7
- package/src/constants.ts +0 -10
- package/src/extractor/accessSafe.ts +0 -18
- package/src/extractor/babelParse.ts +0 -27
- package/src/extractor/buildClassName.ts +0 -61
- package/src/extractor/createEvaluator.ts +0 -68
- package/src/extractor/createExtractor.ts +0 -1139
- package/src/extractor/ensureImportingConcat.ts +0 -33
- package/src/extractor/evaluateAstNode.ts +0 -121
- package/src/extractor/extractHelpers.ts +0 -102
- package/src/extractor/extractMediaStyle.ts +0 -191
- package/src/extractor/extractToClassNames.ts +0 -326
- package/src/extractor/findTopmostFunction.ts +0 -22
- package/src/extractor/generatedUid.ts +0 -43
- package/src/extractor/getPropValueFromAttributes.ts +0 -92
- package/src/extractor/getSourceModule.ts +0 -101
- package/src/extractor/getStaticBindingsForScope.ts +0 -173
- package/src/extractor/hoistClassNames.ts +0 -45
- package/src/extractor/literalToAst.ts +0 -32
- package/src/extractor/loadTamagui.ts +0 -61
- package/src/extractor/normalizeTernaries.ts +0 -60
- package/src/extractor/removeUnusedHooks.ts +0 -76
- package/src/index.ts +0 -9
- package/src/types.ts +0 -84
- package/types.d.ts +0 -217
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
import { dirname, extname, resolve } from 'path'
|
|
2
|
-
|
|
3
|
-
import { Binding, NodePath } from '@babel/traverse'
|
|
4
|
-
import * as t from '@babel/types'
|
|
5
|
-
import { existsSync } from 'fs-extra'
|
|
6
|
-
|
|
7
|
-
import { evaluateAstNode } from './evaluateAstNode'
|
|
8
|
-
import { getSourceModule } from './getSourceModule'
|
|
9
|
-
|
|
10
|
-
const isLocalImport = (path: string) => path.startsWith('.') || path.startsWith('/')
|
|
11
|
-
|
|
12
|
-
function resolveImportPath(sourcePath: string, path: string) {
|
|
13
|
-
const sourceDir = dirname(sourcePath)
|
|
14
|
-
if (isLocalImport(path)) {
|
|
15
|
-
if (extname(path) === '') {
|
|
16
|
-
path += '.js'
|
|
17
|
-
}
|
|
18
|
-
return resolve(sourceDir, path)
|
|
19
|
-
}
|
|
20
|
-
return path
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function importModule(path: string) {
|
|
24
|
-
const filenames = [path.replace('.js', '.tsx'), path.replace('.js', '.ts'), path]
|
|
25
|
-
for (const file of filenames) {
|
|
26
|
-
if (existsSync(file)) {
|
|
27
|
-
// TODO we can clear this when we see updates on it later on
|
|
28
|
-
return require(file)
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return null
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function getStaticBindingsForScope(
|
|
35
|
-
scope: NodePath<t.JSXElement>['scope'],
|
|
36
|
-
whitelist: string[] = [],
|
|
37
|
-
sourcePath: string,
|
|
38
|
-
bindingCache: Record<string, string | null>,
|
|
39
|
-
shouldPrintDebug: boolean
|
|
40
|
-
): Record<string, any> {
|
|
41
|
-
const bindings: Record<string, Binding> = scope.getAllBindings() as any
|
|
42
|
-
const ret: Record<string, any> = {}
|
|
43
|
-
|
|
44
|
-
if (shouldPrintDebug) {
|
|
45
|
-
// prettier-ignore
|
|
46
|
-
console.log(' ', Object.keys(bindings).length, 'variables in scope')
|
|
47
|
-
// .map(x => bindings[x].identifier?.name).join(', ')
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// on react native at least it doesnt find some bindings? not sure why
|
|
51
|
-
// lets add in whitelisted imports if they exist
|
|
52
|
-
const program = scope.getProgramParent().block as t.Program
|
|
53
|
-
for (const node of program.body) {
|
|
54
|
-
if (t.isImportDeclaration(node)) {
|
|
55
|
-
const importPath = node.source.value
|
|
56
|
-
if (!node.specifiers.length) continue
|
|
57
|
-
if (!isLocalImport(importPath)) {
|
|
58
|
-
continue
|
|
59
|
-
}
|
|
60
|
-
const moduleName = resolveImportPath(sourcePath, importPath)
|
|
61
|
-
const isOnWhitelist = whitelist.some((test) => moduleName.endsWith(test))
|
|
62
|
-
if (!isOnWhitelist) continue
|
|
63
|
-
const src = importModule(moduleName)
|
|
64
|
-
if (!src) continue
|
|
65
|
-
for (const specifier of node.specifiers) {
|
|
66
|
-
if (t.isImportSpecifier(specifier) && t.isIdentifier(specifier.imported)) {
|
|
67
|
-
if (typeof src[specifier.imported.name] !== 'undefined') {
|
|
68
|
-
const val = src[specifier.local.name]
|
|
69
|
-
ret[specifier.local.name] = val
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (!bindingCache) {
|
|
77
|
-
throw new Error('bindingCache is a required param')
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
for (const k in bindings) {
|
|
81
|
-
const binding = bindings[k]
|
|
82
|
-
|
|
83
|
-
// check to see if the item is a module
|
|
84
|
-
const sourceModule = getSourceModule(k, binding)
|
|
85
|
-
if (sourceModule) {
|
|
86
|
-
if (!sourceModule.sourceModule) {
|
|
87
|
-
continue
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const moduleName = resolveImportPath(sourcePath, sourceModule.sourceModule)
|
|
91
|
-
const isOnWhitelist = whitelist.some((test) => moduleName.endsWith(test))
|
|
92
|
-
|
|
93
|
-
// TODO we could cache this at the file level.. and check if its been touched since
|
|
94
|
-
|
|
95
|
-
if (isOnWhitelist) {
|
|
96
|
-
const src = importModule(moduleName)
|
|
97
|
-
if (!src) {
|
|
98
|
-
console.log(
|
|
99
|
-
`⚠️ missing file ${moduleName} via ${sourcePath} import ${sourceModule.sourceModule}?`
|
|
100
|
-
)
|
|
101
|
-
return {}
|
|
102
|
-
}
|
|
103
|
-
if (sourceModule.destructured) {
|
|
104
|
-
if (sourceModule.imported) {
|
|
105
|
-
ret[k] = src[sourceModule.imported]
|
|
106
|
-
}
|
|
107
|
-
} else {
|
|
108
|
-
// crude esmodule check
|
|
109
|
-
// TODO: make sure this actually works
|
|
110
|
-
// if (src && src.__esModule) {
|
|
111
|
-
// ret[k] = src.default
|
|
112
|
-
// } else {
|
|
113
|
-
ret[k] = src
|
|
114
|
-
// }
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
continue
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
const { parent, parentPath } = binding.path
|
|
121
|
-
|
|
122
|
-
if (!t.isVariableDeclaration(parent) || parent.kind !== 'const') {
|
|
123
|
-
continue
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// pick out the right variable declarator
|
|
127
|
-
const dec = parent.declarations.find((d) => t.isIdentifier(d.id) && d.id.name === k)
|
|
128
|
-
|
|
129
|
-
// if init is not set, there's nothing to evaluate
|
|
130
|
-
// TODO: handle spread syntax
|
|
131
|
-
if (!dec || !dec.init) {
|
|
132
|
-
continue
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// missing start/end will break caching
|
|
136
|
-
if (typeof dec.id.start !== 'number' || typeof dec.id.end !== 'number') {
|
|
137
|
-
console.error('dec.id.start/end is not a number')
|
|
138
|
-
continue
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
if (!t.isIdentifier(dec.id)) {
|
|
142
|
-
console.error('dec is not an identifier')
|
|
143
|
-
continue
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
const cacheKey = `${dec.id.name}_${dec.id.start}-${dec.id.end}`
|
|
147
|
-
|
|
148
|
-
// retrieve value from cache
|
|
149
|
-
if (bindingCache.hasOwnProperty(cacheKey)) {
|
|
150
|
-
ret[k] = bindingCache[cacheKey]
|
|
151
|
-
continue
|
|
152
|
-
}
|
|
153
|
-
// retrieve value from cache
|
|
154
|
-
if (bindingCache.hasOwnProperty(cacheKey)) {
|
|
155
|
-
ret[k] = bindingCache[cacheKey]
|
|
156
|
-
continue
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// evaluate
|
|
160
|
-
try {
|
|
161
|
-
ret[k] = evaluateAstNode(dec.init, undefined, shouldPrintDebug)
|
|
162
|
-
bindingCache[cacheKey] = ret[k]
|
|
163
|
-
continue
|
|
164
|
-
} catch (e) {
|
|
165
|
-
// skip
|
|
166
|
-
// if (shouldPrintDebug) {
|
|
167
|
-
// console.error('[🐇] cant eval, skipping', cacheKey) //, e.message)
|
|
168
|
-
// }
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
return ret
|
|
173
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { NodePath } from '@babel/traverse'
|
|
2
|
-
import * as t from '@babel/types'
|
|
3
|
-
|
|
4
|
-
export function hoistClassNames(
|
|
5
|
-
path: NodePath<t.JSXElement>,
|
|
6
|
-
existing: { [key: string]: t.Identifier },
|
|
7
|
-
expr: t.Expression
|
|
8
|
-
) {
|
|
9
|
-
const hoist = hoistClassNames.bind(null, path, existing)
|
|
10
|
-
if (t.isStringLiteral(expr)) {
|
|
11
|
-
if (expr.value.trim() === '') {
|
|
12
|
-
return expr
|
|
13
|
-
}
|
|
14
|
-
if (existing[expr.value]) {
|
|
15
|
-
return existing[expr.value]
|
|
16
|
-
}
|
|
17
|
-
const identifier = replaceStringWithVariable(expr)
|
|
18
|
-
existing[expr.value] = identifier
|
|
19
|
-
return identifier
|
|
20
|
-
}
|
|
21
|
-
if (t.isBinaryExpression(expr)) {
|
|
22
|
-
return t.binaryExpression(expr.operator, hoist(expr.left), hoist(expr.right))
|
|
23
|
-
}
|
|
24
|
-
if (t.isLogicalExpression(expr)) {
|
|
25
|
-
return t.logicalExpression(expr.operator, hoist(expr.left), hoist(expr.right))
|
|
26
|
-
}
|
|
27
|
-
if (t.isConditionalExpression(expr)) {
|
|
28
|
-
return t.conditionalExpression(expr.test, hoist(expr.consequent), hoist(expr.alternate))
|
|
29
|
-
}
|
|
30
|
-
return expr
|
|
31
|
-
|
|
32
|
-
function replaceStringWithVariable(str: t.StringLiteral): t.Identifier {
|
|
33
|
-
// hoist outside fn!
|
|
34
|
-
const uid = path.scope.generateUidIdentifier('cn')
|
|
35
|
-
const parent = path.findParent((path) => path.isProgram())
|
|
36
|
-
if (!parent) throw new Error(`no program?`)
|
|
37
|
-
const variable = t.variableDeclaration('const', [
|
|
38
|
-
// adding a space for extra safety
|
|
39
|
-
t.variableDeclarator(uid, t.stringLiteral(` ${str.value}`)),
|
|
40
|
-
])
|
|
41
|
-
// @ts-ignore
|
|
42
|
-
parent.unshiftContainer('body', variable)
|
|
43
|
-
return uid
|
|
44
|
-
}
|
|
45
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import * as t from '@babel/types'
|
|
2
|
-
|
|
3
|
-
export function literalToAst(literal: any): t.Expression {
|
|
4
|
-
if (literal === null) {
|
|
5
|
-
return t.nullLiteral()
|
|
6
|
-
}
|
|
7
|
-
switch (typeof literal) {
|
|
8
|
-
case 'function':
|
|
9
|
-
throw new Error('Unsupported')
|
|
10
|
-
case 'number':
|
|
11
|
-
return t.numericLiteral(literal)
|
|
12
|
-
case 'string':
|
|
13
|
-
return t.stringLiteral(literal)
|
|
14
|
-
case 'boolean':
|
|
15
|
-
return t.booleanLiteral(literal)
|
|
16
|
-
case 'undefined':
|
|
17
|
-
return t.unaryExpression('void', t.numericLiteral(0), true)
|
|
18
|
-
default:
|
|
19
|
-
if (Array.isArray(literal)) {
|
|
20
|
-
return t.arrayExpression(literal.map(literalToAst))
|
|
21
|
-
}
|
|
22
|
-
return t.objectExpression(
|
|
23
|
-
Object.keys(literal)
|
|
24
|
-
.filter((k) => {
|
|
25
|
-
return typeof literal[k] !== 'undefined'
|
|
26
|
-
})
|
|
27
|
-
.map((k) => {
|
|
28
|
-
return t.objectProperty(t.stringLiteral(k), literalToAst(literal[k]))
|
|
29
|
-
})
|
|
30
|
-
)
|
|
31
|
-
}
|
|
32
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { join } from 'path'
|
|
2
|
-
|
|
3
|
-
import type { StaticComponent, TamaguiInternalConfig } from '@tamagui/core'
|
|
4
|
-
import { createTamagui } from '@tamagui/core-node'
|
|
5
|
-
|
|
6
|
-
let loadedTamagui: any = null
|
|
7
|
-
|
|
8
|
-
export function loadTamagui(props: { components: string[]; config: string }): {
|
|
9
|
-
components: Record<string, StaticComponent>
|
|
10
|
-
tamaguiConfig: TamaguiInternalConfig
|
|
11
|
-
} {
|
|
12
|
-
if (loadedTamagui) {
|
|
13
|
-
return loadedTamagui
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// lets shim require and avoid importing react-native + react-native-web
|
|
17
|
-
// we just need to read the config around them
|
|
18
|
-
process.env.IS_STATIC = 'is_static'
|
|
19
|
-
const proxyWorm = require('@tamagui/fake-react-native')
|
|
20
|
-
const Mod = require('module')
|
|
21
|
-
const og = Mod.prototype.require
|
|
22
|
-
Mod.prototype.require = function (path: string) {
|
|
23
|
-
if (
|
|
24
|
-
path.startsWith('react-native') &&
|
|
25
|
-
// allow our rnw.tsx imports through
|
|
26
|
-
!path.startsWith('react-native-web/dist/cjs/exports')
|
|
27
|
-
) {
|
|
28
|
-
return proxyWorm
|
|
29
|
-
}
|
|
30
|
-
return og.apply(this, arguments)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// import config
|
|
34
|
-
const configPath = join(process.cwd(), props.config)
|
|
35
|
-
const tamaguiConfigExport = require(configPath)
|
|
36
|
-
// TODO validate its the right config
|
|
37
|
-
const tamaguiConfig = (tamaguiConfigExport['default'] ||
|
|
38
|
-
tamaguiConfigExport) as TamaguiInternalConfig
|
|
39
|
-
|
|
40
|
-
// import components
|
|
41
|
-
const components = {}
|
|
42
|
-
for (const module of props.components) {
|
|
43
|
-
const exported = require(module)
|
|
44
|
-
// TODO check if overwriting and warn
|
|
45
|
-
Object.assign(components, exported)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// undo shims
|
|
49
|
-
process.env.IS_STATIC = undefined
|
|
50
|
-
Mod.prototype.require = og
|
|
51
|
-
|
|
52
|
-
// set up core-node
|
|
53
|
-
createTamagui(tamaguiConfig)
|
|
54
|
-
|
|
55
|
-
loadedTamagui = {
|
|
56
|
-
components,
|
|
57
|
-
tamaguiConfig,
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return loadedTamagui
|
|
61
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import generate from '@babel/generator'
|
|
2
|
-
import * as t from '@babel/types'
|
|
3
|
-
import invariant from 'invariant'
|
|
4
|
-
|
|
5
|
-
import { Ternary } from '../types'
|
|
6
|
-
|
|
7
|
-
export function normalizeTernaries(ternaries: Ternary[]) {
|
|
8
|
-
invariant(Array.isArray(ternaries), 'extractStaticTernaries expects param 1 to be an array of ternaries')
|
|
9
|
-
|
|
10
|
-
if (ternaries.length === 0) {
|
|
11
|
-
return []
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const ternariesByKey: { [key: string]: Ternary } = {}
|
|
15
|
-
|
|
16
|
-
for (let idx = -1, len = ternaries.length; ++idx < len; ) {
|
|
17
|
-
const { test, consequent, alternate, remove, ...rest } = ternaries[idx]
|
|
18
|
-
|
|
19
|
-
let ternaryTest = test
|
|
20
|
-
|
|
21
|
-
// strip parens
|
|
22
|
-
if (t.isExpressionStatement(test)) {
|
|
23
|
-
ternaryTest = (test as any).expression
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// convert `!thing` to `thing` with swapped consequent and alternate
|
|
27
|
-
let shouldSwap = false
|
|
28
|
-
if (t.isUnaryExpression(test) && test.operator === '!') {
|
|
29
|
-
ternaryTest = test.argument
|
|
30
|
-
shouldSwap = true
|
|
31
|
-
} else if (t.isBinaryExpression(test)) {
|
|
32
|
-
if (test.operator === '!==' || test.operator === '!=') {
|
|
33
|
-
ternaryTest = t.binaryExpression(test.operator, test.left, test.right)
|
|
34
|
-
shouldSwap = true
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const key = generate(ternaryTest).code
|
|
39
|
-
|
|
40
|
-
if (!ternariesByKey[key]) {
|
|
41
|
-
ternariesByKey[key] = {
|
|
42
|
-
...rest,
|
|
43
|
-
alternate: {},
|
|
44
|
-
consequent: {},
|
|
45
|
-
test: ternaryTest,
|
|
46
|
-
remove,
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
const altStyle = (shouldSwap ? consequent : alternate) ?? {}
|
|
50
|
-
const consStyle = (shouldSwap ? alternate : consequent) ?? {}
|
|
51
|
-
Object.assign(ternariesByKey[key].alternate, altStyle)
|
|
52
|
-
Object.assign(ternariesByKey[key].consequent, consStyle)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const ternaryExpression = Object.keys(ternariesByKey).map((key) => {
|
|
56
|
-
return ternariesByKey[key]
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
return ternaryExpression
|
|
60
|
-
}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { NodePath } from '@babel/traverse'
|
|
2
|
-
import * as t from '@babel/types'
|
|
3
|
-
|
|
4
|
-
const hooks = {
|
|
5
|
-
useMedia: true,
|
|
6
|
-
useTheme: true,
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function removeUnusedHooks(compFn: NodePath<any>, shouldPrintDebug: boolean) {
|
|
10
|
-
compFn.scope.crawl()
|
|
11
|
-
// check the top level statements
|
|
12
|
-
let bodyStatements = compFn?.get('body')
|
|
13
|
-
if (!bodyStatements) {
|
|
14
|
-
console.log('no body statemnts?', compFn)
|
|
15
|
-
return
|
|
16
|
-
}
|
|
17
|
-
if (!Array.isArray(bodyStatements)) {
|
|
18
|
-
if (bodyStatements.isFunctionExpression()) {
|
|
19
|
-
bodyStatements = bodyStatements.scope.path.get('body')
|
|
20
|
-
} else {
|
|
21
|
-
bodyStatements = bodyStatements.get('body')
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
if (!bodyStatements || !Array.isArray(bodyStatements)) {
|
|
25
|
-
return
|
|
26
|
-
}
|
|
27
|
-
const statements = bodyStatements as NodePath<any>[]
|
|
28
|
-
for (const statement of statements) {
|
|
29
|
-
if (!statement.isVariableDeclaration()) {
|
|
30
|
-
continue
|
|
31
|
-
}
|
|
32
|
-
const declarations = statement.get('declarations')
|
|
33
|
-
if (!Array.isArray(declarations)) {
|
|
34
|
-
continue
|
|
35
|
-
}
|
|
36
|
-
const isBindingReferenced = (name: string) => {
|
|
37
|
-
return !!statement.scope.getBinding(name)?.referenced
|
|
38
|
-
}
|
|
39
|
-
for (const declarator of declarations) {
|
|
40
|
-
const id = declarator.get('id')
|
|
41
|
-
const init = declarator.node.init
|
|
42
|
-
if (Array.isArray(id) || Array.isArray(init)) {
|
|
43
|
-
continue
|
|
44
|
-
}
|
|
45
|
-
const shouldRemove = (() => {
|
|
46
|
-
const isHook =
|
|
47
|
-
t.isCallExpression(init) && t.isIdentifier(init.callee) && hooks[init.callee.name]
|
|
48
|
-
if (!isHook) {
|
|
49
|
-
return false
|
|
50
|
-
}
|
|
51
|
-
if (t.isIdentifier(id.node)) {
|
|
52
|
-
// remove "const media = useMedia()"
|
|
53
|
-
const name = id.node.name
|
|
54
|
-
return !isBindingReferenced(name)
|
|
55
|
-
} else if (t.isObjectPattern(id.node)) {
|
|
56
|
-
// remove "const { sm } = useMedia()"
|
|
57
|
-
const propPaths = id.get('properties') as NodePath<any>[]
|
|
58
|
-
return propPaths.every((prop) => {
|
|
59
|
-
if (!prop.isObjectProperty()) return false
|
|
60
|
-
const value = prop.get('value')
|
|
61
|
-
if (Array.isArray(value) || !value.isIdentifier()) return false
|
|
62
|
-
const name = value.node.name
|
|
63
|
-
return !isBindingReferenced(name)
|
|
64
|
-
})
|
|
65
|
-
}
|
|
66
|
-
return false
|
|
67
|
-
})()
|
|
68
|
-
if (shouldRemove) {
|
|
69
|
-
declarator.remove()
|
|
70
|
-
if (shouldPrintDebug) {
|
|
71
|
-
console.log(` [🪝] removed ${id.node['name'] ?? ''}`)
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
process.env.TAMAGUI_COMPILE_PROCESS = '1'
|
|
2
|
-
|
|
3
|
-
export { TamaguiOptions } from './types'
|
|
4
|
-
export { createExtractor } from './extractor/createExtractor'
|
|
5
|
-
export { literalToAst } from './extractor/literalToAst'
|
|
6
|
-
export * from './constants'
|
|
7
|
-
export * from './extractor/extractToClassNames'
|
|
8
|
-
export * from './extractor/extractHelpers'
|
|
9
|
-
export * from './patchReactNativeWeb'
|
package/src/types.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { NodePath } from '@babel/traverse'
|
|
2
|
-
import * as t from '@babel/types'
|
|
3
|
-
|
|
4
|
-
export type ClassNameObject = t.StringLiteral | t.Expression
|
|
5
|
-
|
|
6
|
-
export interface CacheObject {
|
|
7
|
-
[key: string]: any
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export interface TamaguiOptions {
|
|
11
|
-
// module paths you want to compile with tamagui (for example ['tamagui'])
|
|
12
|
-
components: string[]
|
|
13
|
-
// your tamagui.config.ts
|
|
14
|
-
config?: string
|
|
15
|
-
evaluateVars?: boolean
|
|
16
|
-
importsWhitelist?: string[]
|
|
17
|
-
disableExtraction?: boolean
|
|
18
|
-
disableDebugAttr?: boolean
|
|
19
|
-
disableExtractInlineMedia?: boolean
|
|
20
|
-
exclude?: RegExp
|
|
21
|
-
logTimings?: boolean
|
|
22
|
-
|
|
23
|
-
// probably non user options
|
|
24
|
-
cssPath?: string
|
|
25
|
-
cssData?: any
|
|
26
|
-
deoptProps?: Set<string>
|
|
27
|
-
excludeProps?: string[]
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export type ExtractedAttrAttr = {
|
|
31
|
-
type: 'attr'
|
|
32
|
-
value: t.JSXAttribute | t.JSXSpreadAttribute
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export type ExtractedAttrStyle = { type: 'style'; value: Object }
|
|
36
|
-
|
|
37
|
-
export type ExtractedAttr =
|
|
38
|
-
| ExtractedAttrAttr
|
|
39
|
-
| { type: 'ternary'; value: Ternary }
|
|
40
|
-
| ExtractedAttrStyle
|
|
41
|
-
|
|
42
|
-
export type ExtractTagProps = {
|
|
43
|
-
attrs: ExtractedAttr[]
|
|
44
|
-
node: t.JSXOpeningElement
|
|
45
|
-
attemptEval: (exprNode: t.Node, evalFn?: ((node: t.Node) => any) | undefined) => any
|
|
46
|
-
jsxPath: NodePath<t.JSXElement>
|
|
47
|
-
programPath: NodePath<t.Program>
|
|
48
|
-
originalNodeName: string
|
|
49
|
-
lineNumbers: string
|
|
50
|
-
filePath: string
|
|
51
|
-
isFlattened: boolean
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export type ExtractorParseProps = TamaguiOptions & {
|
|
55
|
-
sourcePath?: string
|
|
56
|
-
shouldPrintDebug?: boolean
|
|
57
|
-
onExtractTag: (props: ExtractTagProps) => void
|
|
58
|
-
getFlattenedNode: (props: { isTextView: boolean; tag: string }) => string
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export interface Ternary {
|
|
62
|
-
test: t.Expression
|
|
63
|
-
// shorthand props that don't use hooks
|
|
64
|
-
inlineMediaQuery?: string
|
|
65
|
-
remove: Function
|
|
66
|
-
consequent: Object | null
|
|
67
|
-
alternate: Object | null
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export type StyleObject = {
|
|
71
|
-
property: string
|
|
72
|
-
value: string
|
|
73
|
-
className: string
|
|
74
|
-
identifier: string
|
|
75
|
-
rules: string[]
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export type ClassNameToStyleObj = {
|
|
79
|
-
[key: string]: StyleObject
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export interface PluginContext {
|
|
83
|
-
write: (path: string, rules: { [key: string]: string }) => any
|
|
84
|
-
}
|