@tamagui/static 1.0.1-beta.99 → 1.0.1-rc.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{cjs/constants.js → constants.js} +9 -4
- package/dist/constants.js.map +7 -0
- package/dist/{cjs/extractor → extractor}/accessSafe.js +14 -2
- package/dist/{esm/extractor → extractor}/accessSafe.js.map +2 -2
- package/dist/{cjs/extractor → extractor}/babelParse.js +5 -1
- package/dist/extractor/babelParse.js.map +7 -0
- package/dist/{cjs/extractor → extractor}/buildClassName.js +40 -9
- package/dist/extractor/buildClassName.js.map +7 -0
- package/dist/extractor/bundle.js +117 -0
- package/dist/extractor/bundle.js.map +7 -0
- package/dist/{cjs/extractor → extractor}/createEvaluator.js +11 -8
- package/dist/extractor/createEvaluator.js.map +7 -0
- package/dist/extractor/createExtractor.js +1623 -0
- package/dist/extractor/createExtractor.js.map +7 -0
- package/dist/{cjs/extractor → extractor}/ensureImportingConcat.js +18 -6
- package/dist/extractor/ensureImportingConcat.js.map +7 -0
- package/dist/{cjs/extractor → extractor}/evaluateAstNode.js +14 -4
- package/dist/extractor/evaluateAstNode.js.map +7 -0
- package/dist/{cjs/extractor → extractor}/extractHelpers.js +83 -12
- package/dist/extractor/extractHelpers.js.map +7 -0
- package/dist/{cjs/extractor → extractor}/extractMediaStyle.js +46 -42
- package/dist/extractor/extractMediaStyle.js.map +7 -0
- package/dist/{cjs/extractor → extractor}/extractToClassNames.js +144 -73
- package/dist/extractor/extractToClassNames.js.map +7 -0
- package/dist/{cjs/extractor → extractor}/findTopmostFunction.js +1 -0
- package/dist/{cjs/extractor → extractor}/findTopmostFunction.js.map +2 -2
- package/dist/{cjs/extractor → extractor}/generatedUid.js +9 -2
- package/dist/{cjs/extractor → extractor}/generatedUid.js.map +3 -3
- package/dist/{cjs/extractor → extractor}/getPrefixLogs.js +1 -0
- package/dist/extractor/getPrefixLogs.js.map +7 -0
- package/dist/{cjs/extractor → extractor}/getPropValueFromAttributes.js +24 -13
- package/dist/extractor/getPropValueFromAttributes.js.map +7 -0
- package/dist/{cjs/extractor → extractor}/getSourceModule.js +5 -1
- package/dist/{esm/extractor → extractor}/getSourceModule.js.map +3 -3
- package/dist/{cjs/extractor → extractor}/getStaticBindingsForScope.js +89 -35
- package/dist/extractor/getStaticBindingsForScope.js.map +7 -0
- package/dist/{cjs/extractor → extractor}/hoistClassNames.js +5 -1
- package/dist/{jsx/extractor → extractor}/hoistClassNames.js.map +3 -3
- package/dist/{cjs/extractor → extractor}/literalToAst.js +26 -30
- package/dist/{jsx/extractor → extractor}/literalToAst.js.map +2 -2
- package/dist/extractor/loadFile.js +21 -0
- package/dist/extractor/loadFile.js.map +7 -0
- package/dist/extractor/loadTamagui.js +427 -0
- package/dist/extractor/loadTamagui.js.map +7 -0
- package/dist/{cjs/extractor → extractor}/logLines.js +2 -1
- package/dist/extractor/logLines.js.map +7 -0
- package/dist/{cjs/extractor → extractor}/normalizeTernaries.js +13 -34
- package/dist/extractor/normalizeTernaries.js.map +7 -0
- package/dist/{cjs/extractor → extractor}/removeUnusedHooks.js +5 -1
- package/dist/extractor/removeUnusedHooks.js.map +7 -0
- package/dist/{cjs/extractor → extractor}/timer.js +9 -1
- package/dist/extractor/timer.js.map +7 -0
- package/dist/{cjs/extractor → extractor}/validHTMLAttributes.js +1 -0
- package/dist/{jsx/extractor → extractor}/validHTMLAttributes.js.map +2 -2
- package/dist/getPragmaOptions.js +68 -0
- package/dist/getPragmaOptions.js.map +7 -0
- package/dist/helpers/memoize.js +46 -0
- package/dist/helpers/memoize.js.map +7 -0
- package/dist/{cjs/index.js → index.js} +10 -8
- package/dist/index.js.map +7 -0
- package/dist/require.js +86 -0
- package/dist/require.js.map +7 -0
- package/dist/{cjs/types.js → types.js} +1 -0
- package/dist/types.js.map +7 -0
- package/dist/webpackPlugin.js +35 -0
- package/dist/webpackPlugin.js.map +7 -0
- package/package.json +40 -36
- package/src/constants.ts +2 -1
- package/src/extractor/babelParse.ts +3 -2
- package/src/extractor/buildClassName.ts +21 -5
- package/src/extractor/bundle.ts +110 -0
- package/src/extractor/createEvaluator.ts +10 -12
- package/src/extractor/createExtractor.ts +1702 -1523
- package/src/extractor/ensureImportingConcat.ts +4 -11
- package/src/extractor/evaluateAstNode.ts +1 -1
- package/src/extractor/extractHelpers.ts +93 -10
- package/src/extractor/extractMediaStyle.ts +18 -11
- package/src/extractor/extractToClassNames.ts +104 -47
- package/src/extractor/getPrefixLogs.ts +1 -1
- package/src/extractor/getPropValueFromAttributes.ts +4 -3
- package/src/extractor/getSourceModule.ts +2 -0
- package/src/extractor/getStaticBindingsForScope.ts +90 -46
- package/src/extractor/loadFile.ts +17 -0
- package/src/extractor/loadTamagui.ts +448 -103
- package/src/extractor/logLines.ts +1 -1
- package/src/extractor/normalizeTernaries.ts +2 -2
- package/src/extractor/removeUnusedHooks.ts +2 -0
- package/src/extractor/timer.ts +12 -1
- package/src/getPragmaOptions.ts +53 -0
- package/src/helpers/memoize.ts +21 -0
- package/src/index.ts +9 -8
- package/src/require.ts +103 -0
- package/src/types.ts +33 -31
- package/src/webpackPlugin.ts +9 -0
- package/tamagui.tsconfig.json +5 -0
- package/types/constants.d.ts +6 -0
- package/types/extractor/accessSafe.d.ts +3 -0
- package/types/extractor/babelParse.d.ts +6 -0
- package/types/extractor/buildClassName.d.ts +5 -2
- package/types/extractor/bundle.d.ts +13 -0
- package/types/extractor/createEvaluator.d.ts +3 -3
- package/types/extractor/createExtractor.d.ts +25 -9
- package/types/extractor/ensureImportingConcat.d.ts +4 -0
- package/types/extractor/evaluateAstNode.d.ts +3 -0
- package/types/extractor/extractHelpers.d.ts +15 -3
- package/types/extractor/extractMediaStyle.d.ts +3 -3
- package/types/extractor/extractToClassNames.d.ts +5 -4
- package/types/extractor/findTopmostFunction.d.ts +4 -0
- package/types/extractor/generatedUid.d.ts +5 -0
- package/types/extractor/getPrefixLogs.d.ts +1 -1
- package/types/extractor/getPropValueFromAttributes.d.ts +19 -0
- package/types/extractor/getSourceModule.d.ts +16 -0
- package/types/extractor/getStaticBindingsForScope.d.ts +5 -0
- package/types/extractor/hoistClassNames.d.ts +6 -0
- package/types/extractor/literalToAst.d.ts +4 -0
- package/types/extractor/loadFile.d.ts +1 -0
- package/types/extractor/loadTamagui.d.ts +15 -5
- package/types/extractor/logLines.d.ts +2 -0
- package/types/extractor/normalizeTernaries.d.ts +1 -1
- package/types/extractor/removeUnusedHooks.d.ts +3 -0
- package/types/extractor/timer.d.ts +5 -0
- package/types/extractor/validHTMLAttributes.d.ts +98 -0
- package/types/getPragmaOptions.d.ts +9 -0
- package/types/helpers/memoize.d.ts +8 -0
- package/types/index.d.ts +9 -8
- package/types/require.d.ts +4 -0
- package/types/types.d.ts +28 -27
- package/types/webpackPlugin.d.ts +4 -0
- package/dist/cjs/constants.js.map +0 -7
- package/dist/cjs/extractor/accessSafe.js.map +0 -7
- package/dist/cjs/extractor/babelParse.js.map +0 -7
- package/dist/cjs/extractor/buildClassName.js.map +0 -7
- package/dist/cjs/extractor/createEvaluator.js.map +0 -7
- package/dist/cjs/extractor/createExtractor.js +0 -1394
- package/dist/cjs/extractor/createExtractor.js.map +0 -7
- package/dist/cjs/extractor/ensureImportingConcat.js.map +0 -7
- package/dist/cjs/extractor/evaluateAstNode.js.map +0 -7
- package/dist/cjs/extractor/extractHelpers.js.map +0 -7
- package/dist/cjs/extractor/extractMediaStyle.js.map +0 -7
- package/dist/cjs/extractor/extractToClassNames.js.map +0 -7
- package/dist/cjs/extractor/getPrefixLogs.js.map +0 -7
- package/dist/cjs/extractor/getPropValueFromAttributes.js.map +0 -7
- package/dist/cjs/extractor/getSourceModule.js.map +0 -7
- package/dist/cjs/extractor/getStaticBindingsForScope.js.map +0 -7
- package/dist/cjs/extractor/hoistClassNames.js.map +0 -7
- package/dist/cjs/extractor/literalToAst.js.map +0 -7
- package/dist/cjs/extractor/loadTamagui.js +0 -139
- package/dist/cjs/extractor/loadTamagui.js.map +0 -7
- package/dist/cjs/extractor/logLines.js.map +0 -7
- package/dist/cjs/extractor/normalizeTernaries.js.map +0 -7
- package/dist/cjs/extractor/removeUnusedHooks.js.map +0 -7
- package/dist/cjs/extractor/timer.js.map +0 -7
- package/dist/cjs/extractor/validHTMLAttributes.js.map +0 -7
- package/dist/cjs/index.js.map +0 -7
- package/dist/cjs/types.js.map +0 -7
- package/dist/esm/constants.js +0 -14
- package/dist/esm/constants.js.map +0 -7
- package/dist/esm/extractor/accessSafe.js +0 -8
- package/dist/esm/extractor/babelParse.js +0 -28
- package/dist/esm/extractor/babelParse.js.map +0 -7
- package/dist/esm/extractor/buildClassName.js +0 -37
- package/dist/esm/extractor/buildClassName.js.map +0 -7
- package/dist/esm/extractor/createEvaluator.js +0 -53
- package/dist/esm/extractor/createEvaluator.js.map +0 -7
- package/dist/esm/extractor/createExtractor.js +0 -1379
- package/dist/esm/extractor/createExtractor.js.map +0 -7
- package/dist/esm/extractor/ensureImportingConcat.js +0 -21
- package/dist/esm/extractor/ensureImportingConcat.js.map +0 -7
- package/dist/esm/extractor/evaluateAstNode.js +0 -91
- package/dist/esm/extractor/evaluateAstNode.js.map +0 -7
- package/dist/esm/extractor/extractHelpers.js +0 -97
- package/dist/esm/extractor/extractHelpers.js.map +0 -7
- package/dist/esm/extractor/extractMediaStyle.js +0 -161
- package/dist/esm/extractor/extractMediaStyle.js.map +0 -7
- package/dist/esm/extractor/extractToClassNames.js +0 -294
- package/dist/esm/extractor/extractToClassNames.js.map +0 -7
- package/dist/esm/extractor/findTopmostFunction.js +0 -20
- package/dist/esm/extractor/findTopmostFunction.js.map +0 -7
- package/dist/esm/extractor/generatedUid.js +0 -25
- package/dist/esm/extractor/generatedUid.js.map +0 -7
- package/dist/esm/extractor/getPrefixLogs.js +0 -8
- package/dist/esm/extractor/getPrefixLogs.js.map +0 -7
- package/dist/esm/extractor/getPropValueFromAttributes.js +0 -46
- package/dist/esm/extractor/getPropValueFromAttributes.js.map +0 -7
- package/dist/esm/extractor/getSourceModule.js +0 -66
- package/dist/esm/extractor/getStaticBindingsForScope.js +0 -132
- package/dist/esm/extractor/getStaticBindingsForScope.js.map +0 -7
- package/dist/esm/extractor/hoistClassNames.js +0 -40
- package/dist/esm/extractor/hoistClassNames.js.map +0 -7
- package/dist/esm/extractor/literalToAst.js +0 -90
- package/dist/esm/extractor/literalToAst.js.map +0 -7
- package/dist/esm/extractor/loadTamagui.js +0 -117
- package/dist/esm/extractor/loadTamagui.js.map +0 -7
- package/dist/esm/extractor/logLines.js +0 -20
- package/dist/esm/extractor/logLines.js.map +0 -7
- package/dist/esm/extractor/normalizeTernaries.js +0 -79
- package/dist/esm/extractor/normalizeTernaries.js.map +0 -7
- package/dist/esm/extractor/removeUnusedHooks.js +0 -76
- package/dist/esm/extractor/removeUnusedHooks.js.map +0 -7
- package/dist/esm/extractor/timer.js +0 -22
- package/dist/esm/extractor/timer.js.map +0 -7
- package/dist/esm/extractor/validHTMLAttributes.js +0 -102
- package/dist/esm/extractor/validHTMLAttributes.js.map +0 -7
- package/dist/esm/index.js +0 -15
- package/dist/esm/index.js.map +0 -7
- package/dist/esm/types.js +0 -1
- package/dist/esm/types.js.map +0 -7
- package/dist/jsx/constants.js +0 -14
- package/dist/jsx/constants.js.map +0 -7
- package/dist/jsx/extractor/accessSafe.js +0 -8
- package/dist/jsx/extractor/accessSafe.js.map +0 -7
- package/dist/jsx/extractor/babelParse.js +0 -28
- package/dist/jsx/extractor/babelParse.js.map +0 -7
- package/dist/jsx/extractor/buildClassName.js +0 -37
- package/dist/jsx/extractor/buildClassName.js.map +0 -7
- package/dist/jsx/extractor/createEvaluator.js +0 -53
- package/dist/jsx/extractor/createEvaluator.js.map +0 -7
- package/dist/jsx/extractor/createExtractor.js +0 -1343
- package/dist/jsx/extractor/createExtractor.js.map +0 -7
- package/dist/jsx/extractor/ensureImportingConcat.js +0 -21
- package/dist/jsx/extractor/ensureImportingConcat.js.map +0 -7
- package/dist/jsx/extractor/evaluateAstNode.js +0 -91
- package/dist/jsx/extractor/evaluateAstNode.js.map +0 -7
- package/dist/jsx/extractor/extractHelpers.js +0 -97
- package/dist/jsx/extractor/extractHelpers.js.map +0 -7
- package/dist/jsx/extractor/extractMediaStyle.js +0 -146
- package/dist/jsx/extractor/extractMediaStyle.js.map +0 -7
- package/dist/jsx/extractor/extractToClassNames.js +0 -280
- package/dist/jsx/extractor/extractToClassNames.js.map +0 -7
- package/dist/jsx/extractor/findTopmostFunction.js +0 -20
- package/dist/jsx/extractor/findTopmostFunction.js.map +0 -7
- package/dist/jsx/extractor/generatedUid.js +0 -25
- package/dist/jsx/extractor/generatedUid.js.map +0 -7
- package/dist/jsx/extractor/getPrefixLogs.js +0 -9
- package/dist/jsx/extractor/getPrefixLogs.js.map +0 -7
- package/dist/jsx/extractor/getPropValueFromAttributes.js +0 -46
- package/dist/jsx/extractor/getPropValueFromAttributes.js.map +0 -7
- package/dist/jsx/extractor/getSourceModule.js +0 -66
- package/dist/jsx/extractor/getSourceModule.js.map +0 -7
- package/dist/jsx/extractor/getStaticBindingsForScope.js +0 -132
- package/dist/jsx/extractor/getStaticBindingsForScope.js.map +0 -7
- package/dist/jsx/extractor/hoistClassNames.js +0 -40
- package/dist/jsx/extractor/literalToAst.js +0 -75
- package/dist/jsx/extractor/loadTamagui.js +0 -102
- package/dist/jsx/extractor/loadTamagui.js.map +0 -7
- package/dist/jsx/extractor/logLines.js +0 -20
- package/dist/jsx/extractor/logLines.js.map +0 -7
- package/dist/jsx/extractor/normalizeTernaries.js +0 -50
- package/dist/jsx/extractor/normalizeTernaries.js.map +0 -7
- package/dist/jsx/extractor/removeUnusedHooks.js +0 -77
- package/dist/jsx/extractor/removeUnusedHooks.js.map +0 -7
- package/dist/jsx/extractor/timer.js +0 -22
- package/dist/jsx/extractor/timer.js.map +0 -7
- package/dist/jsx/extractor/validHTMLAttributes.js +0 -102
- package/dist/jsx/index.js +0 -15
- package/dist/jsx/index.js.map +0 -7
- package/dist/jsx/types.js +0 -1
- package/dist/jsx/types.js.map +0 -7
- 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/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/getPrefixLogs.d.ts.map +0 -1
- package/types/extractor/loadTamagui.d.ts.map +0 -1
- package/types/extractor/normalizeTernaries.d.ts.map +0 -1
- package/types/index.d.ts.map +0 -1
- package/types/types.d.ts.map +0 -1
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { NodePath } from '@babel/traverse'
|
|
2
2
|
import * as t from '@babel/types'
|
|
3
3
|
|
|
4
|
-
import { CONCAT_CLASSNAME_IMPORT } from '../constants'
|
|
5
|
-
|
|
6
4
|
const importConcatPkg = '@tamagui/helpers'
|
|
7
5
|
|
|
8
6
|
export function ensureImportingConcat(path: NodePath<t.Program>) {
|
|
@@ -11,8 +9,8 @@ export function ensureImportingConcat(path: NodePath<t.Program>) {
|
|
|
11
9
|
(x) => x.isImportDeclaration() && x.node.source.value === importConcatPkg
|
|
12
10
|
) as any
|
|
13
11
|
const importSpecifier = t.importSpecifier(
|
|
14
|
-
t.identifier(
|
|
15
|
-
t.identifier(
|
|
12
|
+
t.identifier('concatClassName'),
|
|
13
|
+
t.identifier('concatClassName')
|
|
16
14
|
)
|
|
17
15
|
|
|
18
16
|
if (!imported) {
|
|
@@ -23,17 +21,12 @@ export function ensureImportingConcat(path: NodePath<t.Program>) {
|
|
|
23
21
|
const specifiers = imported.node.specifiers
|
|
24
22
|
const alreadyImported = specifiers.some(
|
|
25
23
|
(x) =>
|
|
26
|
-
t.isImportSpecifier(x) &&
|
|
27
|
-
t.isIdentifier(x.imported) &&
|
|
28
|
-
x.imported.name === CONCAT_CLASSNAME_IMPORT
|
|
24
|
+
t.isImportSpecifier(x) && t.isIdentifier(x.imported) && x.imported.name === 'concatClassName'
|
|
29
25
|
)
|
|
30
26
|
|
|
31
27
|
if (!alreadyImported) {
|
|
32
28
|
specifiers.push(
|
|
33
|
-
t.importSpecifier(
|
|
34
|
-
t.identifier(CONCAT_CLASSNAME_IMPORT),
|
|
35
|
-
t.identifier(CONCAT_CLASSNAME_IMPORT)
|
|
36
|
-
)
|
|
29
|
+
t.importSpecifier(t.identifier('concatClassName'), t.identifier('concatClassName'))
|
|
37
30
|
)
|
|
38
31
|
}
|
|
39
32
|
}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
+
import { basename, relative } from 'path'
|
|
2
|
+
|
|
1
3
|
import generate from '@babel/generator'
|
|
2
4
|
import type { NodePath } from '@babel/traverse'
|
|
3
5
|
import * as t from '@babel/types'
|
|
6
|
+
import findRoot from 'find-root'
|
|
7
|
+
|
|
8
|
+
import { memoize } from '../helpers/memoize.js'
|
|
9
|
+
import type { ExtractedAttr, TamaguiOptionsWithFileInfo, Ternary } from '../types.js'
|
|
4
10
|
|
|
5
|
-
import {
|
|
6
|
-
import { astToLiteral } from './literalToAst'
|
|
11
|
+
// import { astToLiteral } from './literalToAst'
|
|
7
12
|
|
|
8
13
|
export function isPresent<T extends Object>(input: null | void | undefined | T): input is T {
|
|
9
14
|
return input != null
|
|
@@ -53,7 +58,7 @@ export const ternaryStr = (x: Ternary) => {
|
|
|
53
58
|
? x.test.name
|
|
54
59
|
: t.isMemberExpression(x.test)
|
|
55
60
|
? [x.test.object['name'], x.test.property['name']]
|
|
56
|
-
: generate(x.test).code
|
|
61
|
+
: generate(x.test as any).code
|
|
57
62
|
return [
|
|
58
63
|
'ternary(',
|
|
59
64
|
conditional,
|
|
@@ -68,7 +73,7 @@ export const ternaryStr = (x: Ternary) => {
|
|
|
68
73
|
const isFilledObj = (obj: any) => obj && Object.keys(obj).length
|
|
69
74
|
|
|
70
75
|
export function findComponentName(scope) {
|
|
71
|
-
|
|
76
|
+
const componentName = ''
|
|
72
77
|
let cur = scope.path
|
|
73
78
|
while (cur.parentPath && !t.isProgram(cur.parentPath.parent)) {
|
|
74
79
|
cur = cur.parentPath
|
|
@@ -90,6 +95,7 @@ export function findComponentName(scope) {
|
|
|
90
95
|
}
|
|
91
96
|
|
|
92
97
|
export function isValidThemeHook(
|
|
98
|
+
props: TamaguiOptionsWithFileInfo,
|
|
93
99
|
jsxPath: NodePath<t.JSXElement>,
|
|
94
100
|
n: t.MemberExpression,
|
|
95
101
|
sourcePath: string
|
|
@@ -106,14 +112,91 @@ export function isValidThemeHook(
|
|
|
106
112
|
if (init.callee.name !== 'useTheme') return false
|
|
107
113
|
const importNode = binding.scope.getBinding('useTheme')?.path.parent
|
|
108
114
|
if (!t.isImportDeclaration(importNode)) return false
|
|
109
|
-
if (
|
|
110
|
-
|
|
111
|
-
return false
|
|
112
|
-
}
|
|
115
|
+
if (!isValidImport(props, sourcePath)) {
|
|
116
|
+
return false
|
|
113
117
|
}
|
|
114
118
|
return true
|
|
115
119
|
}
|
|
116
120
|
|
|
117
|
-
export const
|
|
118
|
-
return
|
|
121
|
+
export const isInsideComponentPackage = (props: TamaguiOptionsWithFileInfo, moduleName: string) => {
|
|
122
|
+
return getValidComponentsPaths(props).some((path) => {
|
|
123
|
+
return moduleName.startsWith(path)
|
|
124
|
+
})
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export const isComponentPackage = (props: TamaguiOptionsWithFileInfo, srcName: string) => {
|
|
128
|
+
return getValidComponentsPaths(props).some((path) => {
|
|
129
|
+
return srcName.startsWith(path)
|
|
130
|
+
})
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function getValidComponent(
|
|
134
|
+
props: TamaguiOptionsWithFileInfo,
|
|
135
|
+
moduleName: string,
|
|
136
|
+
componentName: string
|
|
137
|
+
) {
|
|
138
|
+
// must be uppercase of course
|
|
139
|
+
if (componentName[0].toUpperCase() !== componentName[0]) {
|
|
140
|
+
return false
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
for (const loaded of props.allLoadedComponents) {
|
|
144
|
+
if (!loaded) continue
|
|
145
|
+
const isInModule = moduleName === '*' || moduleName.startsWith(loaded.moduleName)
|
|
146
|
+
const foundComponent = loaded.nameToInfo[componentName]
|
|
147
|
+
// eslint-disable-next-line no-console
|
|
148
|
+
if (isInModule && foundComponent) {
|
|
149
|
+
return foundComponent
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return null
|
|
119
154
|
}
|
|
155
|
+
|
|
156
|
+
export const isValidModule = (props: TamaguiOptionsWithFileInfo, moduleName: string) => {
|
|
157
|
+
if (typeof moduleName !== 'string') {
|
|
158
|
+
throw new Error(`No module name`)
|
|
159
|
+
}
|
|
160
|
+
const isLocal = moduleName.startsWith('.')
|
|
161
|
+
return {
|
|
162
|
+
isLocal,
|
|
163
|
+
isValid: isLocal
|
|
164
|
+
? isInsideComponentPackage(props, moduleName)
|
|
165
|
+
: isComponentPackage(props, moduleName),
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export const getValidImport = (
|
|
170
|
+
props: TamaguiOptionsWithFileInfo,
|
|
171
|
+
moduleName: string,
|
|
172
|
+
componentName?: string
|
|
173
|
+
) => {
|
|
174
|
+
const { isValid, isLocal } = isValidModule(props, moduleName)
|
|
175
|
+
if (!isValid || !componentName) {
|
|
176
|
+
return null
|
|
177
|
+
}
|
|
178
|
+
return getValidComponent(props, isLocal ? '*' : moduleName, componentName) || null
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export const isValidImport = (
|
|
182
|
+
props: TamaguiOptionsWithFileInfo,
|
|
183
|
+
moduleName: string,
|
|
184
|
+
componentName?: string
|
|
185
|
+
) => {
|
|
186
|
+
if (!componentName) {
|
|
187
|
+
return isValidModule(props, moduleName).isValid
|
|
188
|
+
}
|
|
189
|
+
return Boolean(getValidImport(props, moduleName, componentName))
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const getValidComponentPackages = memoize((props: TamaguiOptionsWithFileInfo) => {
|
|
193
|
+
// just always look for `tamagui` and `@tamagui/core`
|
|
194
|
+
return [...new Set(['@tamagui/core', 'tamagui', ...props.components])]
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
const getValidComponentsPaths = memoize((props: TamaguiOptionsWithFileInfo) => {
|
|
198
|
+
return getValidComponentPackages(props).map((pkg) => {
|
|
199
|
+
const root = findRoot(pkg)
|
|
200
|
+
return basename(root)
|
|
201
|
+
})
|
|
202
|
+
})
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { NodePath } from '@babel/traverse'
|
|
2
2
|
import * as t from '@babel/types'
|
|
3
3
|
import { TamaguiInternalConfig, getStylesAtomic, mediaObjectToString } from '@tamagui/core-node'
|
|
4
|
-
import { ViewStyle } from 'react-native'
|
|
4
|
+
import type { ViewStyle } from 'react-native'
|
|
5
5
|
|
|
6
|
-
import { MEDIA_SEP } from '../constants'
|
|
7
|
-
import { StyleObject, Ternary } from '../types'
|
|
8
|
-
import {
|
|
6
|
+
import { MEDIA_SEP } from '../constants.js'
|
|
7
|
+
import type { StyleObject, TamaguiOptionsWithFileInfo, Ternary } from '../types.js'
|
|
8
|
+
import { isPresent, isValidImport } from './extractHelpers.js'
|
|
9
9
|
|
|
10
10
|
export function extractMediaStyle(
|
|
11
|
+
props: TamaguiOptionsWithFileInfo,
|
|
11
12
|
ternary: Ternary,
|
|
12
13
|
jsxPath: NodePath<t.JSXElement>,
|
|
13
14
|
tamaguiConfig: TamaguiInternalConfig,
|
|
@@ -15,13 +16,14 @@ export function extractMediaStyle(
|
|
|
15
16
|
importance = 0,
|
|
16
17
|
shouldPrintDebug: boolean | 'verbose' = false
|
|
17
18
|
) {
|
|
18
|
-
const mt = getMediaQueryTernary(ternary, jsxPath, sourcePath)
|
|
19
|
+
const mt = getMediaQueryTernary(props, ternary, jsxPath, sourcePath)
|
|
19
20
|
if (!mt) {
|
|
20
21
|
return null
|
|
21
22
|
}
|
|
22
23
|
const { key } = mt
|
|
23
24
|
const mq = tamaguiConfig.media[key]
|
|
24
25
|
if (!mq) {
|
|
26
|
+
// eslint-disable-next-line no-console
|
|
25
27
|
console.error(`Media query "${key}" not found: ${Object.keys(tamaguiConfig.media)}`)
|
|
26
28
|
return null
|
|
27
29
|
}
|
|
@@ -33,6 +35,7 @@ export function extractMediaStyle(
|
|
|
33
35
|
getStyleObj(ternary.alternate, true),
|
|
34
36
|
].filter(isPresent)
|
|
35
37
|
if (shouldPrintDebug && !styleOpts.length) {
|
|
38
|
+
// eslint-disable-next-line no-console
|
|
36
39
|
console.log(' media query, no styles?')
|
|
37
40
|
return null
|
|
38
41
|
}
|
|
@@ -80,6 +83,7 @@ export function extractMediaStyle(
|
|
|
80
83
|
})
|
|
81
84
|
if (shouldPrintDebug === 'verbose') {
|
|
82
85
|
// prettier-ignore
|
|
86
|
+
// eslint-disable-next-line no-console
|
|
83
87
|
console.log(' media styles:', importance, styleObj, singleMediaStyles.map(x => x.identifier).join(', '))
|
|
84
88
|
}
|
|
85
89
|
// add to output
|
|
@@ -91,6 +95,7 @@ export function extractMediaStyle(
|
|
|
91
95
|
}
|
|
92
96
|
|
|
93
97
|
function getMediaQueryTernary(
|
|
98
|
+
props: TamaguiOptionsWithFileInfo,
|
|
94
99
|
ternary: Ternary,
|
|
95
100
|
jsxPath: NodePath<t.JSXElement>,
|
|
96
101
|
sourcePath: string
|
|
@@ -104,6 +109,7 @@ function getMediaQueryTernary(
|
|
|
104
109
|
if (t.isLogicalExpression(ternary.test) && ternary.test.operator === '&&') {
|
|
105
110
|
// *should* be normalized to always be on left side
|
|
106
111
|
const mediaLeft = getMediaInfoFromExpression(
|
|
112
|
+
props,
|
|
107
113
|
ternary.test.left,
|
|
108
114
|
jsxPath,
|
|
109
115
|
sourcePath,
|
|
@@ -122,6 +128,7 @@ function getMediaQueryTernary(
|
|
|
122
128
|
// const media = useMedia()
|
|
123
129
|
// ... media.sm
|
|
124
130
|
const result = getMediaInfoFromExpression(
|
|
131
|
+
props,
|
|
125
132
|
ternary.test,
|
|
126
133
|
jsxPath,
|
|
127
134
|
sourcePath,
|
|
@@ -137,6 +144,7 @@ function getMediaQueryTernary(
|
|
|
137
144
|
}
|
|
138
145
|
|
|
139
146
|
function getMediaInfoFromExpression(
|
|
147
|
+
props: TamaguiOptionsWithFileInfo,
|
|
140
148
|
test: t.Expression,
|
|
141
149
|
jsxPath: NodePath<t.JSXElement>,
|
|
142
150
|
sourcePath: string,
|
|
@@ -156,20 +164,21 @@ function getMediaInfoFromExpression(
|
|
|
156
164
|
if (!binding) return false
|
|
157
165
|
const bindingNode = binding.path?.node
|
|
158
166
|
if (!t.isVariableDeclarator(bindingNode) || !bindingNode.init) return false
|
|
159
|
-
if (!isValidMediaCall(jsxPath, bindingNode.init, sourcePath)) return false
|
|
167
|
+
if (!isValidMediaCall(props, jsxPath, bindingNode.init, sourcePath)) return false
|
|
160
168
|
return { key, bindingName: name }
|
|
161
169
|
}
|
|
162
170
|
if (t.isIdentifier(test)) {
|
|
163
171
|
const key = test.name
|
|
164
172
|
const node = jsxPath.scope.getBinding(test.name)?.path?.node
|
|
165
173
|
if (!t.isVariableDeclarator(node)) return false
|
|
166
|
-
if (!node.init || !isValidMediaCall(jsxPath, node.init, sourcePath)) return false
|
|
174
|
+
if (!node.init || !isValidMediaCall(props, jsxPath, node.init, sourcePath)) return false
|
|
167
175
|
return { key, bindingName: key }
|
|
168
176
|
}
|
|
169
177
|
return null
|
|
170
178
|
}
|
|
171
179
|
|
|
172
180
|
export function isValidMediaCall(
|
|
181
|
+
props: TamaguiOptionsWithFileInfo,
|
|
173
182
|
jsxPath: NodePath<t.JSXElement>,
|
|
174
183
|
init: t.Expression,
|
|
175
184
|
sourcePath: string
|
|
@@ -183,10 +192,8 @@ export function isValidMediaCall(
|
|
|
183
192
|
if (!mediaBinding) return false
|
|
184
193
|
const useMediaImport = mediaBinding.path.parent
|
|
185
194
|
if (!t.isImportDeclaration(useMediaImport)) return false
|
|
186
|
-
if (
|
|
187
|
-
|
|
188
|
-
return false
|
|
189
|
-
}
|
|
195
|
+
if (!isValidImport(props, sourcePath)) {
|
|
196
|
+
return false
|
|
190
197
|
}
|
|
191
198
|
return true
|
|
192
199
|
}
|
|
@@ -7,20 +7,19 @@ import * as t from '@babel/types'
|
|
|
7
7
|
import { getStylesAtomic } from '@tamagui/core-node'
|
|
8
8
|
import { concatClassName } from '@tamagui/helpers'
|
|
9
9
|
import invariant from 'invariant'
|
|
10
|
-
import { ViewStyle } from 'react-native'
|
|
11
|
-
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import { timer } from './timer'
|
|
10
|
+
import type { ViewStyle } from 'react-native'
|
|
11
|
+
|
|
12
|
+
import type { ClassNameObject, StyleObject, TamaguiOptions, Ternary } from '../types.js'
|
|
13
|
+
import { babelParse } from './babelParse.js'
|
|
14
|
+
import { buildClassName } from './buildClassName.js'
|
|
15
|
+
import { Extractor } from './createExtractor.js'
|
|
16
|
+
import { ensureImportingConcat } from './ensureImportingConcat.js'
|
|
17
|
+
import { isSimpleSpread } from './extractHelpers.js'
|
|
18
|
+
import { extractMediaStyle } from './extractMediaStyle.js'
|
|
19
|
+
import { getPrefixLogs } from './getPrefixLogs.js'
|
|
20
|
+
import { hoistClassNames } from './hoistClassNames.js'
|
|
21
|
+
import { logLines } from './logLines.js'
|
|
22
|
+
import { timer } from './timer.js'
|
|
24
23
|
|
|
25
24
|
const mergeStyleGroups = {
|
|
26
25
|
shadowOpacity: true,
|
|
@@ -37,19 +36,21 @@ export type ExtractedResponse = {
|
|
|
37
36
|
map: any // RawSourceMap from 'source-map'
|
|
38
37
|
}
|
|
39
38
|
|
|
40
|
-
export
|
|
41
|
-
extractor,
|
|
42
|
-
source,
|
|
43
|
-
sourcePath,
|
|
44
|
-
options,
|
|
45
|
-
shouldPrintDebug,
|
|
46
|
-
}: {
|
|
39
|
+
export type ExtractToClassNamesProps = {
|
|
47
40
|
extractor: Extractor
|
|
48
41
|
source: string | Buffer
|
|
49
42
|
sourcePath: string
|
|
50
43
|
options: TamaguiOptions
|
|
51
44
|
shouldPrintDebug: boolean | 'verbose'
|
|
52
|
-
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export async function extractToClassNames({
|
|
48
|
+
extractor,
|
|
49
|
+
source,
|
|
50
|
+
sourcePath,
|
|
51
|
+
options,
|
|
52
|
+
shouldPrintDebug,
|
|
53
|
+
}: ExtractToClassNamesProps): Promise<ExtractedResponse | null> {
|
|
53
54
|
const tm = timer()
|
|
54
55
|
|
|
55
56
|
if (typeof source !== 'string') {
|
|
@@ -60,6 +61,9 @@ export function extractToClassNames({
|
|
|
60
61
|
'`sourcePath` must be an absolute path to a .js file'
|
|
61
62
|
)
|
|
62
63
|
|
|
64
|
+
// dont include loading in timing of parsing (one time cost)
|
|
65
|
+
await extractor.loadTamagui(options)
|
|
66
|
+
|
|
63
67
|
const shouldLogTiming = options.logTimings ?? true
|
|
64
68
|
const start = Date.now()
|
|
65
69
|
const mem = shouldLogTiming ? process.memoryUsage() : null
|
|
@@ -70,6 +74,7 @@ export function extractToClassNames({
|
|
|
70
74
|
try {
|
|
71
75
|
ast = babelParse(source)
|
|
72
76
|
} catch (err) {
|
|
77
|
+
// eslint-disable-next-line no-console
|
|
73
78
|
console.error('babel parse error:', sourcePath)
|
|
74
79
|
throw err
|
|
75
80
|
}
|
|
@@ -81,20 +86,26 @@ export function extractToClassNames({
|
|
|
81
86
|
|
|
82
87
|
let hasFlattened = false
|
|
83
88
|
|
|
84
|
-
const res = extractor.parse(ast, {
|
|
85
|
-
sourcePath,
|
|
89
|
+
const res = await extractor.parse(ast, {
|
|
86
90
|
shouldPrintDebug,
|
|
87
91
|
...options,
|
|
92
|
+
sourcePath,
|
|
88
93
|
target: 'html',
|
|
89
94
|
extractStyledDefinitions: true,
|
|
90
95
|
onStyleRule(identifier, rules) {
|
|
91
|
-
|
|
96
|
+
const css = rules.join(';')
|
|
97
|
+
if (shouldPrintDebug) {
|
|
98
|
+
// eslint-disable-next-line no-console
|
|
99
|
+
console.log(`adding styled() rule: .${identifier} ${css}`)
|
|
100
|
+
}
|
|
101
|
+
cssMap.set(`.${identifier}`, { css, commentTexts: [] })
|
|
92
102
|
},
|
|
93
103
|
getFlattenedNode: ({ tag }) => {
|
|
94
104
|
hasFlattened = true
|
|
95
105
|
return tag
|
|
96
106
|
},
|
|
97
107
|
onExtractTag: ({
|
|
108
|
+
parserProps,
|
|
98
109
|
attrs,
|
|
99
110
|
node,
|
|
100
111
|
attemptEval,
|
|
@@ -104,13 +115,24 @@ export function extractToClassNames({
|
|
|
104
115
|
lineNumbers,
|
|
105
116
|
programPath,
|
|
106
117
|
isFlattened,
|
|
118
|
+
completeProps,
|
|
119
|
+
staticConfig,
|
|
107
120
|
}) => {
|
|
121
|
+
// bail out of views that don't accept className (falls back to runtime + style={})
|
|
122
|
+
if (staticConfig.acceptsClassName === false) {
|
|
123
|
+
if (shouldPrintDebug) {
|
|
124
|
+
// eslint-disable-next-line no-console
|
|
125
|
+
console.log(`bail, acceptsClassName is false`)
|
|
126
|
+
}
|
|
127
|
+
return
|
|
128
|
+
}
|
|
129
|
+
|
|
108
130
|
// reset hasFlattened
|
|
109
131
|
const didFlattenThisTag = hasFlattened
|
|
110
132
|
hasFlattened = false
|
|
111
133
|
|
|
112
134
|
let finalClassNames: ClassNameObject[] = []
|
|
113
|
-
|
|
135
|
+
const finalAttrs: (t.JSXAttribute | t.JSXSpreadAttribute)[] = []
|
|
114
136
|
let finalStyles: StyleObject[] = []
|
|
115
137
|
|
|
116
138
|
let viewStyles = {}
|
|
@@ -151,7 +173,7 @@ export function extractToClassNames({
|
|
|
151
173
|
let lastMediaImportance = 1
|
|
152
174
|
for (const attr of attrs) {
|
|
153
175
|
switch (attr.type) {
|
|
154
|
-
case 'style':
|
|
176
|
+
case 'style': {
|
|
155
177
|
if (!isFlattened) {
|
|
156
178
|
const styles = getStylesAtomic(attr.value)
|
|
157
179
|
|
|
@@ -179,7 +201,8 @@ export function extractToClassNames({
|
|
|
179
201
|
}
|
|
180
202
|
|
|
181
203
|
break
|
|
182
|
-
|
|
204
|
+
}
|
|
205
|
+
case 'attr': {
|
|
183
206
|
const val = attr.value
|
|
184
207
|
if (t.isJSXSpreadAttribute(val)) {
|
|
185
208
|
if (isSimpleSpread(val)) {
|
|
@@ -205,19 +228,25 @@ export function extractToClassNames({
|
|
|
205
228
|
}
|
|
206
229
|
finalAttrs.push(val)
|
|
207
230
|
break
|
|
208
|
-
|
|
231
|
+
}
|
|
232
|
+
case 'ternary': {
|
|
209
233
|
const mediaExtraction = extractMediaStyle(
|
|
234
|
+
parserProps,
|
|
210
235
|
attr.value,
|
|
211
236
|
jsxPath,
|
|
212
|
-
extractor.getTamagui()
|
|
237
|
+
extractor.getTamagui()!,
|
|
213
238
|
sourcePath,
|
|
214
239
|
lastMediaImportance,
|
|
215
240
|
shouldPrintDebug
|
|
216
241
|
)
|
|
217
242
|
if (shouldPrintDebug) {
|
|
218
243
|
if (mediaExtraction) {
|
|
219
|
-
//
|
|
220
|
-
console.log(
|
|
244
|
+
// eslint-disable-next-line no-console
|
|
245
|
+
console.log(
|
|
246
|
+
'ternary (mediaStyles)',
|
|
247
|
+
mediaExtraction.ternaryWithoutMedia?.inlineMediaQuery ?? '',
|
|
248
|
+
mediaExtraction.mediaStyles.map((x) => x.identifier).join('.')
|
|
249
|
+
)
|
|
221
250
|
}
|
|
222
251
|
}
|
|
223
252
|
if (!mediaExtraction) {
|
|
@@ -241,6 +270,7 @@ export function extractToClassNames({
|
|
|
241
270
|
]
|
|
242
271
|
}
|
|
243
272
|
break
|
|
273
|
+
}
|
|
244
274
|
}
|
|
245
275
|
}
|
|
246
276
|
|
|
@@ -263,18 +293,46 @@ export function extractToClassNames({
|
|
|
263
293
|
}
|
|
264
294
|
|
|
265
295
|
if (shouldPrintDebug) {
|
|
266
|
-
//
|
|
267
|
-
console.log(
|
|
296
|
+
// eslint-disable-next-line no-console
|
|
297
|
+
console.log(
|
|
298
|
+
' finalClassNames\n',
|
|
299
|
+
logLines(finalClassNames.map((x) => x['value']).join(' '))
|
|
300
|
+
)
|
|
268
301
|
}
|
|
269
302
|
|
|
270
303
|
node.attributes = finalAttrs
|
|
271
304
|
|
|
272
305
|
if (finalClassNames.length) {
|
|
306
|
+
const extraClassNames = (() => {
|
|
307
|
+
let value = ''
|
|
308
|
+
if (!isFlattened) {
|
|
309
|
+
return value
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// helper to see how many get flattened
|
|
313
|
+
if (process.env.TAMAGUI_DEBUG_OPTIMIZATIONS) {
|
|
314
|
+
value += `is_tamagui_flattened`
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// add is_Component className
|
|
318
|
+
if (staticConfig.componentName) {
|
|
319
|
+
value += ` is_${staticConfig.componentName}`
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
if (staticConfig.isText) {
|
|
323
|
+
let family = completeProps.fontFamily
|
|
324
|
+
if (family[0] === '$') {
|
|
325
|
+
family = family.slice(1)
|
|
326
|
+
}
|
|
327
|
+
value += ` font_${family}`
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
return value
|
|
331
|
+
})()
|
|
332
|
+
|
|
273
333
|
// inserts the _cn variable and uses it for className
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
names.value = concatClassName(names.value)
|
|
277
|
-
}
|
|
334
|
+
const names = buildClassName(finalClassNames, extraClassNames)
|
|
335
|
+
|
|
278
336
|
const nameExpr = names ? hoistClassNames(jsxPath, existingHoists, names) : null
|
|
279
337
|
let expr = nameExpr
|
|
280
338
|
|
|
@@ -287,7 +345,7 @@ export function extractToClassNames({
|
|
|
287
345
|
const simpleSpreads = attrs.filter(
|
|
288
346
|
(x) => t.isJSXSpreadAttribute(x.value) && isSimpleSpread(x.value)
|
|
289
347
|
)
|
|
290
|
-
expr = t.callExpression(t.identifier(
|
|
348
|
+
expr = t.callExpression(t.identifier('concatClassName'), [
|
|
291
349
|
expr,
|
|
292
350
|
...simpleSpreads.map((val) => val.value['argument']),
|
|
293
351
|
])
|
|
@@ -310,12 +368,8 @@ export function extractToClassNames({
|
|
|
310
368
|
cssMap.set(className, val)
|
|
311
369
|
}
|
|
312
370
|
} else if (rules.length) {
|
|
313
|
-
if (rules.length > 1) {
|
|
314
|
-
console.log(' rules error', { rules })
|
|
315
|
-
throw new Error(`Shouldn't have more than one rule`)
|
|
316
|
-
}
|
|
317
371
|
cssMap.set(className, {
|
|
318
|
-
css: rules
|
|
372
|
+
css: rules.join('\n'),
|
|
319
373
|
commentTexts: [comment],
|
|
320
374
|
})
|
|
321
375
|
}
|
|
@@ -325,6 +379,7 @@ export function extractToClassNames({
|
|
|
325
379
|
|
|
326
380
|
if (!res || (!res.modified && !res.optimized && !res.flattened && !res.styled)) {
|
|
327
381
|
if (shouldPrintDebug) {
|
|
382
|
+
// eslint-disable-next-line no-console
|
|
328
383
|
console.log('no res or none modified', res)
|
|
329
384
|
}
|
|
330
385
|
return null
|
|
@@ -336,7 +391,7 @@ export function extractToClassNames({
|
|
|
336
391
|
.trim()
|
|
337
392
|
|
|
338
393
|
const result = generate(
|
|
339
|
-
ast,
|
|
394
|
+
ast as any,
|
|
340
395
|
{
|
|
341
396
|
concise: false,
|
|
342
397
|
filename: sourcePath,
|
|
@@ -349,6 +404,7 @@ export function extractToClassNames({
|
|
|
349
404
|
)
|
|
350
405
|
|
|
351
406
|
if (shouldPrintDebug) {
|
|
407
|
+
// eslint-disable-next-line no-console
|
|
352
408
|
console.log(
|
|
353
409
|
'\n -------- output code ------- \n\n',
|
|
354
410
|
result.code
|
|
@@ -356,6 +412,7 @@ export function extractToClassNames({
|
|
|
356
412
|
.filter((x) => !x.startsWith('//'))
|
|
357
413
|
.join('\n')
|
|
358
414
|
)
|
|
415
|
+
// eslint-disable-next-line no-console
|
|
359
416
|
console.log('\n -------- output style -------- \n\n', styles)
|
|
360
417
|
}
|
|
361
418
|
|
|
@@ -375,10 +432,10 @@ export function extractToClassNames({
|
|
|
375
432
|
const numFlattened = `${res.flattened}`.padStart(3)
|
|
376
433
|
const memory = process.env.DEBUG && memUsed > 10 ? ` ${memUsed}MB` : ''
|
|
377
434
|
const timing = Date.now() - start
|
|
378
|
-
const
|
|
379
|
-
const timingStr = `${timing}ms ${timingWarning}`.padStart(6)
|
|
435
|
+
const timingStr = `${timing}ms`.padStart(6)
|
|
380
436
|
const pre = getPrefixLogs(options)
|
|
381
437
|
const memStr = memory ? `(${memory})` : ''
|
|
438
|
+
// eslint-disable-next-line no-console
|
|
382
439
|
console.log(
|
|
383
440
|
`${pre} ${path} ${numFound} · ${numOptimized} · ${numFlattened} · ${numStyled} ${timingStr} ${memStr}`
|
|
384
441
|
)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import generate from '@babel/generator'
|
|
2
2
|
import * as t from '@babel/types'
|
|
3
3
|
|
|
4
|
-
import { accessSafe } from './accessSafe'
|
|
4
|
+
import { accessSafe } from './accessSafe.js'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* getPropValueFromAttributes gets a prop by name from a list of attributes and accounts for potential spread operators.
|
|
@@ -23,7 +23,7 @@ export function getPropValueFromAttributes(
|
|
|
23
23
|
propName: string,
|
|
24
24
|
attrs: (t.JSXAttribute | t.JSXSpreadAttribute)[]
|
|
25
25
|
): t.Expression | null {
|
|
26
|
-
let propIndex
|
|
26
|
+
let propIndex = -1
|
|
27
27
|
let jsxAttr: t.JSXAttribute | null = null
|
|
28
28
|
for (let idx = -1, len = attrs.length; ++idx < len; ) {
|
|
29
29
|
const attr = attrs[idx]
|
|
@@ -52,6 +52,7 @@ export function getPropValueFromAttributes(
|
|
|
52
52
|
|
|
53
53
|
// TODO how to handle this??
|
|
54
54
|
if (t.isJSXEmptyExpression(propValue)) {
|
|
55
|
+
// eslint-disable-next-line no-console
|
|
55
56
|
console.error('encountered JSXEmptyExpression')
|
|
56
57
|
return null
|
|
57
58
|
}
|
|
@@ -70,7 +71,7 @@ export function getPropValueFromAttributes(
|
|
|
70
71
|
return false
|
|
71
72
|
}
|
|
72
73
|
throw new Error(
|
|
73
|
-
`unsupported spread of type "${attr.argument.type}": ${generate(attr).code}`
|
|
74
|
+
`unsupported spread of type "${attr.argument.type}": ${generate(attr as any).code}`
|
|
74
75
|
)
|
|
75
76
|
}
|
|
76
77
|
return false
|
|
@@ -80,10 +80,12 @@ export function getSourceModule(
|
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
if (!local || !imported) {
|
|
83
|
+
// eslint-disable-next-line no-console
|
|
83
84
|
console.error('could not find prop with value `%s`', itemName)
|
|
84
85
|
return null
|
|
85
86
|
}
|
|
86
87
|
} else {
|
|
88
|
+
// eslint-disable-next-line no-console
|
|
87
89
|
console.error('Unhandled id type: %s', itemNode.id.type)
|
|
88
90
|
return null
|
|
89
91
|
}
|