@tamagui/static 1.132.16 → 1.132.18
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/extractor/concatClassName.js +69 -0
- package/dist/extractor/concatClassName.js.map +6 -0
- package/dist/extractor/concatClassName.native.js +69 -0
- package/dist/extractor/concatClassName.native.js.map +6 -0
- package/dist/extractor/createEvaluator.js +13 -1
- package/dist/extractor/createEvaluator.js.map +1 -1
- package/dist/extractor/createEvaluator.native.js +6 -1
- package/dist/extractor/createEvaluator.native.js.map +2 -2
- package/dist/extractor/createExtractor.js +60 -114
- package/dist/extractor/createExtractor.js.map +1 -1
- package/dist/extractor/createExtractor.native.js +70 -123
- package/dist/extractor/createExtractor.native.js.map +2 -2
- package/dist/extractor/errors.js +22 -0
- package/dist/extractor/errors.js.map +6 -0
- package/dist/extractor/errors.native.js +119 -0
- package/dist/extractor/errors.native.js.map +6 -0
- package/dist/extractor/extractMediaStyle.js +1 -1
- package/dist/extractor/extractMediaStyle.js.map +1 -1
- package/dist/extractor/extractMediaStyle.native.js +1 -1
- package/dist/extractor/extractMediaStyle.native.js.map +2 -2
- package/dist/extractor/extractToClassNames.js +212 -172
- package/dist/extractor/extractToClassNames.js.map +2 -2
- package/dist/extractor/extractToClassNames.native.js +212 -188
- package/dist/extractor/extractToClassNames.native.js.map +2 -2
- package/dist/extractor/extractToNative.js +47 -78
- package/dist/extractor/extractToNative.js.map +1 -1
- package/dist/extractor/extractToNative.native.js +23 -39
- package/dist/extractor/extractToNative.native.js.map +2 -2
- package/dist/extractor/normalizeTernaries.js +5 -3
- package/dist/extractor/normalizeTernaries.js.map +1 -1
- package/dist/extractor/normalizeTernaries.native.js +5 -3
- package/dist/extractor/normalizeTernaries.native.js.map +2 -2
- package/dist/extractor/propsToFontFamilyCache.js +7 -8
- package/dist/extractor/propsToFontFamilyCache.js.map +1 -1
- package/dist/extractor/propsToFontFamilyCache.native.js +9 -10
- package/dist/extractor/propsToFontFamilyCache.native.js.map +2 -2
- package/dist/registerRequire.js +1 -1
- package/dist/registerRequire.js.map +1 -1
- package/dist/registerRequire.native.js +1 -1
- package/dist/registerRequire.native.js.map +1 -1
- package/dist/types.native.js.map +1 -1
- package/package.json +15 -15
- package/src/extractor/concatClassName.ts +100 -0
- package/src/extractor/createEvaluator.ts +26 -1
- package/src/extractor/createExtractor.ts +108 -194
- package/src/extractor/errors.ts +1 -0
- package/src/extractor/extractMediaStyle.ts +1 -1
- package/src/extractor/extractToClassNames.ts +377 -264
- package/src/extractor/extractToNative.ts +68 -111
- package/src/extractor/normalizeTernaries.ts +10 -3
- package/src/extractor/propsToFontFamilyCache.ts +5 -5
- package/src/registerRequire.ts +1 -1
- package/src/types.ts +10 -13
- package/types/extractor/concatClassName.d.ts +8 -0
- package/types/extractor/concatClassName.d.ts.map +1 -0
- package/types/extractor/createEvaluator.d.ts.map +1 -1
- package/types/extractor/createExtractor.d.ts.map +1 -1
- package/types/extractor/errors.d.ts +3 -0
- package/types/extractor/errors.d.ts.map +1 -0
- package/types/extractor/extractToClassNames.d.ts.map +1 -1
- package/types/extractor/extractToNative.d.ts.map +1 -1
- package/types/extractor/normalizeTernaries.d.ts.map +1 -1
- package/types/extractor/propsToFontFamilyCache.d.ts +2 -2
- package/types/extractor/propsToFontFamilyCache.d.ts.map +1 -1
- package/types/types.d.ts +9 -10
- package/types/types.d.ts.map +1 -1
- package/dist/extractor/buildClassName.js +0 -72
- package/dist/extractor/buildClassName.js.map +0 -6
- package/dist/extractor/buildClassName.native.js +0 -67
- package/dist/extractor/buildClassName.native.js.map +0 -6
- package/dist/extractor/ensureImportingConcat.js +0 -50
- package/dist/extractor/ensureImportingConcat.js.map +0 -6
- package/dist/extractor/ensureImportingConcat.native.js +0 -49
- package/dist/extractor/ensureImportingConcat.native.js.map +0 -6
- package/dist/extractor/hoistClassNames.js +0 -63
- package/dist/extractor/hoistClassNames.js.map +0 -6
- package/dist/extractor/hoistClassNames.native.js +0 -66
- package/dist/extractor/hoistClassNames.native.js.map +0 -6
- package/src/extractor/buildClassName.ts +0 -76
- package/src/extractor/ensureImportingConcat.ts +0 -36
- package/src/extractor/hoistClassNames.ts +0 -52
- package/types/extractor/buildClassName.d.ts +0 -7
- package/types/extractor/buildClassName.d.ts.map +0 -1
- package/types/extractor/ensureImportingConcat.d.ts +0 -4
- package/types/extractor/ensureImportingConcat.d.ts.map +0 -1
- package/types/extractor/hoistClassNames.d.ts +0 -6
- package/types/extractor/hoistClassNames.d.ts.map +0 -1
package/dist/types.native.js.map
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@tamagui/static",
|
3
|
-
"version": "1.132.
|
3
|
+
"version": "1.132.18",
|
4
4
|
"source": "src/index.ts",
|
5
5
|
"types": "./types/index.d.ts",
|
6
6
|
"type": "commonjs",
|
@@ -45,19 +45,19 @@
|
|
45
45
|
"@babel/template": "^7.25.0",
|
46
46
|
"@babel/traverse": "^7.25.4",
|
47
47
|
"@babel/types": "^7.25.4",
|
48
|
-
"@tamagui/cli-color": "1.132.
|
49
|
-
"@tamagui/config-default": "1.132.
|
50
|
-
"@tamagui/core": "1.132.
|
51
|
-
"@tamagui/fake-react-native": "1.132.
|
52
|
-
"@tamagui/generate-themes": "1.132.
|
53
|
-
"@tamagui/helpers": "1.132.
|
54
|
-
"@tamagui/helpers-node": "1.132.
|
55
|
-
"@tamagui/proxy-worm": "1.132.
|
56
|
-
"@tamagui/react-native-web-internals": "1.132.
|
57
|
-
"@tamagui/react-native-web-lite": "1.132.
|
58
|
-
"@tamagui/shorthands": "1.132.
|
59
|
-
"@tamagui/types": "1.132.
|
60
|
-
"@tamagui/web": "1.132.
|
48
|
+
"@tamagui/cli-color": "1.132.18",
|
49
|
+
"@tamagui/config-default": "1.132.18",
|
50
|
+
"@tamagui/core": "1.132.18",
|
51
|
+
"@tamagui/fake-react-native": "1.132.18",
|
52
|
+
"@tamagui/generate-themes": "1.132.18",
|
53
|
+
"@tamagui/helpers": "1.132.18",
|
54
|
+
"@tamagui/helpers-node": "1.132.18",
|
55
|
+
"@tamagui/proxy-worm": "1.132.18",
|
56
|
+
"@tamagui/react-native-web-internals": "1.132.18",
|
57
|
+
"@tamagui/react-native-web-lite": "1.132.18",
|
58
|
+
"@tamagui/shorthands": "1.132.18",
|
59
|
+
"@tamagui/types": "1.132.18",
|
60
|
+
"@tamagui/web": "1.132.18",
|
61
61
|
"babel-literal-to-ast": "^2.1.0",
|
62
62
|
"browserslist": "^4.22.2",
|
63
63
|
"check-dependency-version-consistency": "^4.1.0",
|
@@ -74,7 +74,7 @@
|
|
74
74
|
"devDependencies": {
|
75
75
|
"@babel/plugin-syntax-typescript": "^7.25.4",
|
76
76
|
"@expo/match-media": "^0.4.0",
|
77
|
-
"@tamagui/build": "1.132.
|
77
|
+
"@tamagui/build": "1.132.18",
|
78
78
|
"@types/babel__core": "^7.20.5",
|
79
79
|
"@types/find-root": "^1.1.2",
|
80
80
|
"@types/node": "^22.1.0",
|
@@ -0,0 +1,100 @@
|
|
1
|
+
// perf sensitive so doing some weird stuff
|
2
|
+
|
3
|
+
/**
|
4
|
+
* next - take objects:
|
5
|
+
*
|
6
|
+
* { _shorthand: 'postfix' }
|
7
|
+
*
|
8
|
+
*/
|
9
|
+
|
10
|
+
export function concatClassName(...args: any[]): any
|
11
|
+
export function concatClassName(_cn: Record<string, any> | null | undefined): string {
|
12
|
+
const args = arguments
|
13
|
+
const usedPrefixes: string[] = []
|
14
|
+
let final = ''
|
15
|
+
|
16
|
+
const len = args.length
|
17
|
+
let propObjects: any = null
|
18
|
+
for (let x = len; x >= 0; x--) {
|
19
|
+
const cns = args[x]
|
20
|
+
|
21
|
+
if (!cns) continue
|
22
|
+
if (!Array.isArray(cns) && typeof cns !== 'string') {
|
23
|
+
// is prop object
|
24
|
+
propObjects = propObjects || []
|
25
|
+
propObjects.push(cns)
|
26
|
+
continue
|
27
|
+
}
|
28
|
+
|
29
|
+
const names = Array.isArray(cns) ? cns : cns.split(' ')
|
30
|
+
const numNames = names.length
|
31
|
+
for (let i = numNames - 1; i >= 0; i--) {
|
32
|
+
const name = names[i]
|
33
|
+
|
34
|
+
if (!name || name === ' ') continue
|
35
|
+
if (name[0] !== '_') {
|
36
|
+
// not snack style (todo slightly stronger heuristic)
|
37
|
+
final = name + ' ' + final
|
38
|
+
continue
|
39
|
+
}
|
40
|
+
|
41
|
+
const splitIndex = name.indexOf('-')
|
42
|
+
if (splitIndex < 1) {
|
43
|
+
final = name + ' ' + final
|
44
|
+
// if (shouldDebug) console.log('debug exclude:', name, final)
|
45
|
+
continue
|
46
|
+
}
|
47
|
+
|
48
|
+
const nextChar = name[splitIndex + 1]
|
49
|
+
// synced to static-ui constants
|
50
|
+
// MEDIA_SEP
|
51
|
+
const isMediaQuery = nextChar === '_'
|
52
|
+
// PSEUDO_SEP
|
53
|
+
// commenting out three things to make pseudos override properly
|
54
|
+
// (leave in for a bit to see if other bugs pop up later):
|
55
|
+
// 1. const isPseudoQuery = nextChar === '0'
|
56
|
+
const styleKey = name.slice(1, name.lastIndexOf('-'))
|
57
|
+
// 2. isMediaQuery || isPseudoQuery
|
58
|
+
const mediaKey = isMediaQuery ? name.slice(splitIndex + 2, splitIndex + 7) : null
|
59
|
+
const uid = mediaKey ? styleKey + mediaKey : styleKey
|
60
|
+
// 3. && !isPseudoQuery
|
61
|
+
|
62
|
+
if (usedPrefixes.indexOf(uid) > -1) {
|
63
|
+
// if (shouldDebug) console.log('debug exclude:', usedPrefixes, name)
|
64
|
+
continue
|
65
|
+
}
|
66
|
+
usedPrefixes.push(uid)
|
67
|
+
|
68
|
+
// overrides for full safety
|
69
|
+
const propName = styleKey
|
70
|
+
if (propName && propObjects) {
|
71
|
+
if (
|
72
|
+
propObjects.some((po) => {
|
73
|
+
if (mediaKey) {
|
74
|
+
const propKey = pseudoInvert[mediaKey]
|
75
|
+
return po && po[propKey] && propName in po[propKey] && po[propKey] !== null
|
76
|
+
}
|
77
|
+
const res = po && propName in po && po[propName] !== null
|
78
|
+
return res
|
79
|
+
})
|
80
|
+
) {
|
81
|
+
// if (shouldDebug) console.log('debug exclude:', name)
|
82
|
+
continue
|
83
|
+
}
|
84
|
+
}
|
85
|
+
|
86
|
+
final = name + ' ' + final
|
87
|
+
}
|
88
|
+
}
|
89
|
+
|
90
|
+
return final
|
91
|
+
}
|
92
|
+
|
93
|
+
const pseudoInvert = {
|
94
|
+
hover: 'hoverStyle',
|
95
|
+
focus: 'focusStyle',
|
96
|
+
press: 'pressStyle',
|
97
|
+
focusVisible: 'focusVisibleStyle',
|
98
|
+
focusWithin: 'focusWithinStyle',
|
99
|
+
disabled: 'disabledStyle',
|
100
|
+
}
|
@@ -28,6 +28,7 @@ export function createEvaluator({
|
|
28
28
|
if (t.isIdentifier(n) && typeof staticNamespace[n.name] !== 'undefined') {
|
29
29
|
return staticNamespace[n.name]
|
30
30
|
}
|
31
|
+
|
31
32
|
const evalContext = vm.createContext(staticNamespace)
|
32
33
|
// @ts-ignore
|
33
34
|
const codeWithTypescriptAnnotations = `(${generate(n as any).code})`
|
@@ -38,7 +39,31 @@ export function createEvaluator({
|
|
38
39
|
if (shouldPrintDebug) {
|
39
40
|
console.info('evaluating', code)
|
40
41
|
}
|
41
|
-
|
42
|
+
|
43
|
+
const result1 = vm.runInContext(code, evalContext)
|
44
|
+
const result2 = vm.runInContext(code, evalContext)
|
45
|
+
|
46
|
+
const isDeterministic =
|
47
|
+
Object.is(result1, result2) ||
|
48
|
+
(typeof result1 === 'object' &&
|
49
|
+
typeof result2 === 'object' &&
|
50
|
+
JSON.stringify(result1) === JSON.stringify(result2))
|
51
|
+
|
52
|
+
if (!isDeterministic) {
|
53
|
+
if (shouldPrintDebug) {
|
54
|
+
console.info(
|
55
|
+
'Bailing on non-deterministic expression:',
|
56
|
+
code,
|
57
|
+
'\nFirst result:',
|
58
|
+
result1,
|
59
|
+
'Second result:',
|
60
|
+
result2
|
61
|
+
)
|
62
|
+
}
|
63
|
+
throw new Error(`Non-deterministic value, bailing`)
|
64
|
+
}
|
65
|
+
|
66
|
+
return result1
|
42
67
|
}
|
43
68
|
|
44
69
|
return (n: t.Node) => {
|
@@ -46,9 +46,9 @@ import { loadTamagui, loadTamaguiSync } from './loadTamagui'
|
|
46
46
|
import { logLines } from './logLines'
|
47
47
|
import { normalizeTernaries } from './normalizeTernaries'
|
48
48
|
import { setPropsToFontFamily } from './propsToFontFamilyCache'
|
49
|
-
import { removeUnusedHooks } from './removeUnusedHooks'
|
50
49
|
import { timer } from './timer'
|
51
50
|
import { validHTMLAttributes } from './validHTMLAttributes'
|
51
|
+
import { BailOptimizationError } from './errors'
|
52
52
|
|
53
53
|
const UNTOUCHED_PROPS = {
|
54
54
|
key: true,
|
@@ -164,11 +164,10 @@ export function createExtractor(
|
|
164
164
|
evaluateVars = true,
|
165
165
|
sourcePath = '',
|
166
166
|
onExtractTag,
|
167
|
-
|
167
|
+
onStyledDefinitionRule,
|
168
168
|
getFlattenedNode,
|
169
169
|
disable,
|
170
170
|
disableExtraction,
|
171
|
-
disableExtractInlineMedia,
|
172
171
|
disableExtractVariables,
|
173
172
|
disableDebugAttr,
|
174
173
|
enableDynamicEvaluation = false,
|
@@ -676,7 +675,7 @@ export function createExtractor(
|
|
676
675
|
if (out.rulesToInsert) {
|
677
676
|
for (const key in out.rulesToInsert) {
|
678
677
|
const styleObject = out.rulesToInsert[key]
|
679
|
-
|
678
|
+
onStyledDefinitionRule?.(
|
680
679
|
styleObject[StyleObjectIdentifier],
|
681
680
|
styleObject[StyleObjectRules]
|
682
681
|
)
|
@@ -833,7 +832,7 @@ export function createExtractor(
|
|
833
832
|
console.info(` Start tag ${tagName}`)
|
834
833
|
}
|
835
834
|
|
836
|
-
const
|
835
|
+
const flatNodeName = getFlattenedNode?.({ isTextView, tag: tagName })
|
837
836
|
|
838
837
|
const inlineProps = new Set([
|
839
838
|
// adding some always inline props
|
@@ -1018,12 +1017,9 @@ export function createExtractor(
|
|
1018
1017
|
}
|
1019
1018
|
// split into individual ternaries per object property
|
1020
1019
|
return [
|
1021
|
-
...(
|
1020
|
+
...(flattenNestedTernaries(test, alt) || []),
|
1022
1021
|
...((cons &&
|
1023
|
-
|
1024
|
-
t.unaryExpression('!', test),
|
1025
|
-
cons
|
1026
|
-
)) ||
|
1022
|
+
flattenNestedTernaries(t.unaryExpression('!', test), cons)) ||
|
1027
1023
|
[]),
|
1028
1024
|
].map((ternary) => ({
|
1029
1025
|
type: 'ternary',
|
@@ -1099,18 +1095,9 @@ export function createExtractor(
|
|
1099
1095
|
if (name[0] === '$' && t.isJSXExpressionContainer(attribute?.value)) {
|
1100
1096
|
const shortname = name.slice(1)
|
1101
1097
|
if (mediaQueryConfig[shortname]) {
|
1102
|
-
if (platform === 'native') {
|
1103
|
-
shouldDeopt = true
|
1104
|
-
}
|
1105
|
-
|
1106
|
-
// allow disabling this extraction
|
1107
|
-
if (disableExtractInlineMedia) {
|
1108
|
-
return attr
|
1109
|
-
}
|
1110
|
-
|
1111
1098
|
const expression = attribute.value.expression
|
1112
1099
|
if (!t.isJSXEmptyExpression(expression)) {
|
1113
|
-
const ternaries =
|
1100
|
+
const ternaries = flattenNestedTernaries(
|
1114
1101
|
t.stringLiteral(shortname),
|
1115
1102
|
expression,
|
1116
1103
|
{
|
@@ -1332,17 +1319,6 @@ export function createExtractor(
|
|
1332
1319
|
return { type: 'ternary', value: staticLogical }
|
1333
1320
|
}
|
1334
1321
|
|
1335
|
-
// Disabling: this probably doesn't optimize much and needs to be done a bit differently
|
1336
|
-
if (options.experimentalFlattenDynamicValues) {
|
1337
|
-
if (isValidStyleKey(name, staticConfig)) {
|
1338
|
-
return {
|
1339
|
-
type: 'dynamic-style',
|
1340
|
-
value,
|
1341
|
-
name: tamaguiConfig?.shorthands[name] || name,
|
1342
|
-
}
|
1343
|
-
}
|
1344
|
-
}
|
1345
|
-
|
1346
1322
|
// if we've made it this far, the prop stays inline
|
1347
1323
|
inlined.set(name, true)
|
1348
1324
|
if (shouldPrintDebug) {
|
@@ -1461,7 +1437,7 @@ export function createExtractor(
|
|
1461
1437
|
// => Ternary<test && x, { background: 'red' }, null>
|
1462
1438
|
// => Ternary<test && !x, { background: 'green' }, null>
|
1463
1439
|
// => Ternary<test && '$gtSm', { color: 'green' }, null>
|
1464
|
-
function
|
1440
|
+
function flattenNestedTernaries(
|
1465
1441
|
test: t.Expression,
|
1466
1442
|
side: t.Expression | null,
|
1467
1443
|
ternaryPartial: Partial<Ternary> = {}
|
@@ -1476,34 +1452,6 @@ export function createExtractor(
|
|
1476
1452
|
if (!t.isObjectProperty(property)) {
|
1477
1453
|
throw new Error('expected object property')
|
1478
1454
|
}
|
1479
|
-
// handle media queries inside spread/conditional objects
|
1480
|
-
if (t.isIdentifier(property.key)) {
|
1481
|
-
const key = property.key.name
|
1482
|
-
const mediaQueryKey = key.slice(1)
|
1483
|
-
const isMediaQuery = key[0] === '$' && mediaQueryConfig[mediaQueryKey]
|
1484
|
-
if (isMediaQuery) {
|
1485
|
-
if (t.isExpression(property.value)) {
|
1486
|
-
const ternaries = createTernariesFromObjectProperties(
|
1487
|
-
t.stringLiteral(mediaQueryKey),
|
1488
|
-
property.value,
|
1489
|
-
{
|
1490
|
-
inlineMediaQuery: mediaQueryKey,
|
1491
|
-
}
|
1492
|
-
)
|
1493
|
-
if (ternaries) {
|
1494
|
-
return ternaries.map((value) => ({
|
1495
|
-
...ternaryPartial,
|
1496
|
-
...value,
|
1497
|
-
// ensure media query test stays on left side (see getMediaQueryTernary)
|
1498
|
-
test: t.logicalExpression('&&', value.test, test),
|
1499
|
-
}))
|
1500
|
-
}
|
1501
|
-
logger.info(['⚠️ no ternaries?', property].join(' '))
|
1502
|
-
} else {
|
1503
|
-
logger.info(['⚠️ not expression', property].join(' '))
|
1504
|
-
}
|
1505
|
-
}
|
1506
|
-
}
|
1507
1455
|
// this could be a recurse here if we want to get fancy
|
1508
1456
|
if (t.isConditionalExpression(property.value)) {
|
1509
1457
|
// merge up into the parent conditional, split into two
|
@@ -1596,7 +1544,7 @@ export function createExtractor(
|
|
1596
1544
|
const canFlattenProps = inlined.size === 0
|
1597
1545
|
|
1598
1546
|
let shouldFlatten = Boolean(
|
1599
|
-
|
1547
|
+
flatNodeName &&
|
1600
1548
|
!shouldDeopt &&
|
1601
1549
|
canFlattenProps &&
|
1602
1550
|
!hasSpread &&
|
@@ -1619,66 +1567,78 @@ export function createExtractor(
|
|
1619
1567
|
}
|
1620
1568
|
})
|
1621
1569
|
|
1622
|
-
|
1623
|
-
|
1624
|
-
|
1625
|
-
|
1626
|
-
|
1627
|
-
|
1628
|
-
|
1629
|
-
|
1630
|
-
|
1631
|
-
|
1632
|
-
|
1633
|
-
|
1634
|
-
|
1635
|
-
|
1636
|
-
|
1637
|
-
|
1638
|
-
|
1639
|
-
|
1640
|
-
|
1641
|
-
|
1642
|
-
|
1643
|
-
|
1644
|
-
|
1645
|
-
|
1646
|
-
|
1647
|
-
|
1648
|
-
|
1649
|
-
|
1650
|
-
|
1651
|
-
|
1652
|
-
|
1653
|
-
|
1654
|
-
|
1655
|
-
|
1656
|
-
|
1657
|
-
|
1658
|
-
|
1659
|
-
|
1660
|
-
|
1661
|
-
|
1662
|
-
|
1663
|
-
|
1664
|
-
|
1665
|
-
|
1570
|
+
if (!shouldFlatten) {
|
1571
|
+
// were no longer partially optimizing, it adds a lot of complexity for dubious performance
|
1572
|
+
if (shouldPrintDebug) {
|
1573
|
+
logger.info(
|
1574
|
+
`Deopting ${JSON.stringify({
|
1575
|
+
shouldFlatten,
|
1576
|
+
shouldDeopt,
|
1577
|
+
canFlattenProps,
|
1578
|
+
hasSpread,
|
1579
|
+
neverFlatten: staticConfig.neverFlatten,
|
1580
|
+
})}`
|
1581
|
+
)
|
1582
|
+
}
|
1583
|
+
node.attributes = ogAttributes
|
1584
|
+
return
|
1585
|
+
}
|
1586
|
+
|
1587
|
+
// ensure the default styles are there
|
1588
|
+
let skipMap = false
|
1589
|
+
const defaultStyleAttrs = Object.keys(defaultProps).flatMap((key) => {
|
1590
|
+
if (skipMap) return []
|
1591
|
+
const value = defaultProps[key]
|
1592
|
+
if (key === 'theme' && !themeVal) {
|
1593
|
+
if (platform === 'native') {
|
1594
|
+
shouldFlatten = false
|
1595
|
+
skipMap = true
|
1596
|
+
inlined.set('theme', { value: t.stringLiteral(value) })
|
1597
|
+
}
|
1598
|
+
themeVal = { value: t.stringLiteral(value) }
|
1599
|
+
return []
|
1600
|
+
}
|
1601
|
+
if (!isValidStyleKey(key, staticConfig)) {
|
1602
|
+
return []
|
1603
|
+
}
|
1604
|
+
const name = tamaguiConfig?.shorthands[key] || key
|
1605
|
+
if (value === undefined) {
|
1606
|
+
logger.warn(
|
1607
|
+
`⚠️ Error evaluating default style for component, prop ${key} ${value}`
|
1608
|
+
)
|
1609
|
+
shouldDeopt = true
|
1610
|
+
return
|
1611
|
+
}
|
1612
|
+
if (name[0] === '$' && mediaQueryConfig[name.slice(1)]) {
|
1613
|
+
defaultProps[key] = undefined
|
1614
|
+
return evaluateAttribute({
|
1615
|
+
node: t.jsxAttribute(
|
1616
|
+
t.jsxIdentifier(name),
|
1617
|
+
t.jsxExpressionContainer(
|
1618
|
+
t.objectExpression(
|
1619
|
+
Object.keys(value)
|
1620
|
+
.filter((k) => {
|
1621
|
+
return typeof value[k] !== 'undefined'
|
1622
|
+
})
|
1623
|
+
.map((k) => {
|
1624
|
+
return t.objectProperty(t.identifier(k), literalToAst(value[k]))
|
1625
|
+
})
|
1666
1626
|
)
|
1667
|
-
)
|
1668
|
-
|
1669
|
-
}
|
1670
|
-
|
1671
|
-
|
1672
|
-
|
1673
|
-
|
1674
|
-
}
|
1675
|
-
|
1676
|
-
|
1627
|
+
)
|
1628
|
+
),
|
1629
|
+
} as any)
|
1630
|
+
}
|
1631
|
+
const attr: ExtractedAttrStyle = {
|
1632
|
+
type: 'style',
|
1633
|
+
name,
|
1634
|
+
value: { [name]: value },
|
1635
|
+
}
|
1636
|
+
return attr
|
1637
|
+
}) as ExtractedAttr[]
|
1677
1638
|
|
1678
|
-
|
1679
|
-
|
1680
|
-
|
1681
|
-
}
|
1639
|
+
if (!skipMap) {
|
1640
|
+
if (defaultStyleAttrs.length) {
|
1641
|
+
attrs = [...defaultStyleAttrs, ...attrs]
|
1682
1642
|
}
|
1683
1643
|
}
|
1684
1644
|
|
@@ -1723,10 +1683,9 @@ export function createExtractor(
|
|
1723
1683
|
}, [])
|
1724
1684
|
.flat()
|
1725
1685
|
|
1726
|
-
const shouldWrapTheme = shouldFlatten && themeVal
|
1727
1686
|
// wrap theme around children on flatten
|
1728
1687
|
// account for shouldFlatten could change w the above block "if (disableExtractVariables)"
|
1729
|
-
if (
|
1688
|
+
if (themeVal) {
|
1730
1689
|
if (!programPath) {
|
1731
1690
|
console.warn(
|
1732
1691
|
`No program path found, avoiding importing flattening / importing theme in ${sourcePath}`
|
@@ -1774,38 +1733,6 @@ export function createExtractor(
|
|
1774
1733
|
}
|
1775
1734
|
}
|
1776
1735
|
|
1777
|
-
if (shouldPrintDebug) {
|
1778
|
-
try {
|
1779
|
-
// prettier-ignore
|
1780
|
-
logger.info(
|
1781
|
-
[
|
1782
|
-
' flatten?',
|
1783
|
-
shouldFlatten,
|
1784
|
-
objToStr({
|
1785
|
-
hasSpread,
|
1786
|
-
shouldDeopt,
|
1787
|
-
canFlattenProps,
|
1788
|
-
shouldWrapTheme,
|
1789
|
-
hasOnlyStringChildren,
|
1790
|
-
}),
|
1791
|
-
'inlined',
|
1792
|
-
inlined.size,
|
1793
|
-
[...inlined],
|
1794
|
-
].join(' ')
|
1795
|
-
)
|
1796
|
-
} catch {
|
1797
|
-
// ok
|
1798
|
-
}
|
1799
|
-
}
|
1800
|
-
|
1801
|
-
if (shouldDeopt || !shouldFlatten) {
|
1802
|
-
if (shouldPrintDebug) {
|
1803
|
-
logger.info(`Deopting ${shouldDeopt} ${shouldFlatten}`)
|
1804
|
-
}
|
1805
|
-
node.attributes = ogAttributes
|
1806
|
-
return
|
1807
|
-
}
|
1808
|
-
|
1809
1736
|
if (shouldPrintDebug) {
|
1810
1737
|
logger.info(
|
1811
1738
|
[' - attrs (flattened): \n', logLines(attrs.map(attrStr).join(', '))].join(
|
@@ -2101,12 +2028,10 @@ export function createExtractor(
|
|
2101
2028
|
}
|
2102
2029
|
|
2103
2030
|
// add default props
|
2104
|
-
|
2105
|
-
|
2106
|
-
|
2107
|
-
|
2108
|
-
})
|
2109
|
-
}
|
2031
|
+
attrs.unshift({
|
2032
|
+
type: 'style',
|
2033
|
+
value: defaultProps,
|
2034
|
+
})
|
2110
2035
|
|
2111
2036
|
attrs = attrs.reduce<ExtractedAttr[]>((acc, cur) => {
|
2112
2037
|
if (cur.type === 'style') {
|
@@ -2296,15 +2221,6 @@ export function createExtractor(
|
|
2296
2221
|
}
|
2297
2222
|
}
|
2298
2223
|
}
|
2299
|
-
|
2300
|
-
if (attr.type === 'dynamic-style') {
|
2301
|
-
if (existingStyleKeys.has(attr.name)) {
|
2302
|
-
//@ts-ignore
|
2303
|
-
attrs[i] = undefined
|
2304
|
-
} else {
|
2305
|
-
existingStyleKeys.add(attr.name)
|
2306
|
-
}
|
2307
|
-
}
|
2308
2224
|
}
|
2309
2225
|
|
2310
2226
|
if (options.experimentalFlattenThemesOnNative) {
|
@@ -2337,36 +2253,19 @@ export function createExtractor(
|
|
2337
2253
|
|
2338
2254
|
// delete empty styles:
|
2339
2255
|
attrs = attrs.filter((x) => {
|
2340
|
-
if (
|
2341
|
-
(x.type === 'style' || x.type === 'dynamic-style') &&
|
2342
|
-
Object.keys(x.value).length === 0
|
2343
|
-
) {
|
2256
|
+
if (x.type === 'style' && Object.keys(x.value).length === 0) {
|
2344
2257
|
return false
|
2345
2258
|
}
|
2346
2259
|
return true
|
2347
2260
|
})
|
2348
2261
|
|
2349
|
-
if (shouldFlatten) {
|
2350
|
-
// DO FLATTEN
|
2351
|
-
if (shouldPrintDebug) {
|
2352
|
-
logger.info([' [✅] flattening', originalNodeName, flatNode].join(' '))
|
2353
|
-
}
|
2354
|
-
// @ts-ignore
|
2355
|
-
node.name.name = flatNode
|
2356
|
-
res.flattened++
|
2357
|
-
if (closingElement) {
|
2358
|
-
// @ts-ignore
|
2359
|
-
closingElement.name.name = flatNode
|
2360
|
-
}
|
2361
|
-
}
|
2362
|
-
|
2363
2262
|
const isNativeNotFlat = !shouldFlatten && platform === 'native'
|
2364
2263
|
if (isNativeNotFlat) {
|
2365
2264
|
if (shouldPrintDebug) {
|
2366
2265
|
logger.info(
|
2367
2266
|
`Disabled flattening except for simple cases on native for now: ${JSON.stringify(
|
2368
2267
|
{
|
2369
|
-
flatNode,
|
2268
|
+
flatNode: flatNodeName,
|
2370
2269
|
shouldDeopt,
|
2371
2270
|
canFlattenProps,
|
2372
2271
|
hasSpread,
|
@@ -2394,7 +2293,6 @@ export function createExtractor(
|
|
2394
2293
|
staticConfig.neverFlatten ? 'neverFlatten' : '',
|
2395
2294
|
].join(' ')
|
2396
2295
|
)
|
2397
|
-
logger.info(` - shouldFlatten/isFlattened: ${shouldFlatten}`)
|
2398
2296
|
logger.info(` - attrs (end):\n ${logLines(attrs.map(attrStr).join(', '))}`)
|
2399
2297
|
}
|
2400
2298
|
|
@@ -2405,21 +2303,37 @@ export function createExtractor(
|
|
2405
2303
|
lineNumbers,
|
2406
2304
|
filePath,
|
2407
2305
|
config: tamaguiConfig!,
|
2306
|
+
flatNodeName,
|
2408
2307
|
attemptEval,
|
2409
2308
|
jsxPath: traversePath,
|
2410
2309
|
originalNodeName,
|
2411
|
-
isFlattened: shouldFlatten,
|
2412
2310
|
programPath: programPath!,
|
2413
2311
|
completeProps,
|
2414
2312
|
staticConfig,
|
2415
2313
|
})
|
2314
|
+
|
2315
|
+
if (shouldFlatten) {
|
2316
|
+
if (shouldPrintDebug) {
|
2317
|
+
logger.info([' [✅] flattened', originalNodeName, flatNodeName].join(' '))
|
2318
|
+
}
|
2319
|
+
// @ts-ignore
|
2320
|
+
node.name.name = flatNodeName
|
2321
|
+
res.flattened++
|
2322
|
+
if (closingElement) {
|
2323
|
+
// @ts-ignore
|
2324
|
+
closingElement.name.name = flatNodeName
|
2325
|
+
}
|
2326
|
+
}
|
2416
2327
|
} catch (err: any) {
|
2417
2328
|
node.attributes = ogAttributes
|
2418
|
-
|
2419
|
-
|
2420
|
-
|
2421
|
-
|
2422
|
-
|
2329
|
+
|
2330
|
+
if (!(err instanceof BailOptimizationError)) {
|
2331
|
+
console.error(
|
2332
|
+
`@tamagui/static error, reverting optimization. In ${filePath} ${lineNumbers} on ${originalNodeName}: ${err.message}. For stack trace set environment TAMAGUI_DEBUG=1`
|
2333
|
+
)
|
2334
|
+
if (process.env.TAMAGUI_DEBUG === '1') {
|
2335
|
+
console.error(err.stack)
|
2336
|
+
}
|
2423
2337
|
}
|
2424
2338
|
} finally {
|
2425
2339
|
if (debugPropValue) {
|
@@ -0,0 +1 @@
|
|
1
|
+
export class BailOptimizationError extends Error {}
|
@@ -17,7 +17,7 @@ export function extractMediaStyle(
|
|
17
17
|
importance = 0,
|
18
18
|
shouldPrintDebug: boolean | 'verbose' = false
|
19
19
|
) {
|
20
|
-
const { getCSSStylesAtomic
|
20
|
+
const { getCSSStylesAtomic } = requireTamaguiCore('web')
|
21
21
|
const mt = getMediaQueryTernary(props, ternary, jsxPath, sourcePath)
|
22
22
|
if (!mt) {
|
23
23
|
return null
|