@tamagui/static 1.82.8 → 1.83.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cjs/extractor/createExtractor.js +43 -34
- package/dist/cjs/extractor/createExtractor.js.map +1 -1
- package/dist/cjs/extractor/createExtractor.native.js +43 -34
- package/dist/cjs/extractor/createExtractor.native.js.map +1 -1
- package/dist/esm/extractor/createExtractor.js +43 -34
- package/dist/esm/extractor/createExtractor.js.map +1 -1
- package/dist/esm/extractor/createExtractor.native.js +43 -34
- package/dist/esm/extractor/createExtractor.native.js.map +1 -1
- package/package.json +15 -15
- package/src/extractor/createExtractor.ts +76 -65
- package/types/extractor/createExtractor.d.ts.map +1 -1
@@ -1533,7 +1533,7 @@ export function createExtractor(
|
|
1533
1533
|
(traversePath.node.children &&
|
1534
1534
|
traversePath.node.children.every((x) => x.type === 'JSXText')))
|
1535
1535
|
|
1536
|
-
|
1536
|
+
let themeVal = inlined.get('theme')
|
1537
1537
|
|
1538
1538
|
// on native we can't flatten when theme prop is set
|
1539
1539
|
if (platform !== 'native') {
|
@@ -1562,9 +1562,7 @@ export function createExtractor(
|
|
1562
1562
|
(staticConfig.neverFlatten === 'jsx' ? hasOnlyStringChildren : true)
|
1563
1563
|
)
|
1564
1564
|
|
1565
|
-
const shouldWrapTheme = shouldFlatten && themeVal
|
1566
1565
|
const usedThemeKeys = new Set<string>()
|
1567
|
-
|
1568
1566
|
// if it accesses any theme values during evaluation
|
1569
1567
|
themeAccessListeners.add((key) => {
|
1570
1568
|
if (options.experimentalFlattenThemesOnNative) {
|
@@ -1579,72 +1577,24 @@ export function createExtractor(
|
|
1579
1577
|
}
|
1580
1578
|
})
|
1581
1579
|
|
1582
|
-
if (shouldPrintDebug) {
|
1583
|
-
try {
|
1584
|
-
// prettier-ignore
|
1585
|
-
logger.info([' flatten?', shouldFlatten, objToStr({ hasSpread, shouldDeopt, canFlattenProps, shouldWrapTheme, hasOnlyStringChildren }), 'inlined', inlined.size, [...inlined]].join(' '))
|
1586
|
-
} catch {
|
1587
|
-
// ok
|
1588
|
-
}
|
1589
|
-
}
|
1590
|
-
|
1591
|
-
// wrap theme around children on flatten
|
1592
|
-
// TODO move this to bottom and re-check shouldFlatten
|
1593
|
-
// account for shouldFlatten could change w the above block "if (disableExtractVariables)"
|
1594
|
-
if (shouldFlatten && shouldWrapTheme) {
|
1595
|
-
if (!programPath) {
|
1596
|
-
console.warn(
|
1597
|
-
`No program path found, avoiding importing flattening / importing theme in ${sourcePath}`
|
1598
|
-
)
|
1599
|
-
} else {
|
1600
|
-
if (shouldPrintDebug) {
|
1601
|
-
logger.info([' - wrapping theme', themeVal].join(' '))
|
1602
|
-
}
|
1603
|
-
|
1604
|
-
// remove theme attribute from flattened node
|
1605
|
-
attrs = attrs.filter((x) =>
|
1606
|
-
x.type === 'attr' &&
|
1607
|
-
t.isJSXAttribute(x.value) &&
|
1608
|
-
x.value.name.name === 'theme'
|
1609
|
-
? false
|
1610
|
-
: true
|
1611
|
-
)
|
1612
|
-
|
1613
|
-
// add import
|
1614
|
-
if (!hasImportedTheme) {
|
1615
|
-
hasImportedTheme = true
|
1616
|
-
programPath.node.body.push(
|
1617
|
-
t.importDeclaration(
|
1618
|
-
[
|
1619
|
-
t.importSpecifier(
|
1620
|
-
t.identifier('_TamaguiTheme'),
|
1621
|
-
t.identifier('Theme')
|
1622
|
-
),
|
1623
|
-
],
|
1624
|
-
t.stringLiteral('@tamagui/web')
|
1625
|
-
)
|
1626
|
-
)
|
1627
|
-
}
|
1628
|
-
|
1629
|
-
traversePath.replaceWith(
|
1630
|
-
t.jsxElement(
|
1631
|
-
t.jsxOpeningElement(t.jsxIdentifier('_TamaguiTheme'), [
|
1632
|
-
t.jsxAttribute(t.jsxIdentifier('name'), themeVal.value),
|
1633
|
-
]),
|
1634
|
-
t.jsxClosingElement(t.jsxIdentifier('_TamaguiTheme')),
|
1635
|
-
[traversePath.node]
|
1636
|
-
)
|
1637
|
-
)
|
1638
|
-
}
|
1639
|
-
}
|
1640
|
-
|
1641
1580
|
// only if we flatten, ensure the default styles are there
|
1642
1581
|
if (shouldFlatten) {
|
1582
|
+
let skipMap = false
|
1643
1583
|
const defaultStyleAttrs = Object.keys(defaultProps).flatMap((key) => {
|
1584
|
+
if (skipMap) return []
|
1585
|
+
const value = defaultProps[key]
|
1586
|
+
if (key === 'theme' && !themeVal) {
|
1587
|
+
if (platform === 'native') {
|
1588
|
+
shouldFlatten = false
|
1589
|
+
skipMap = true
|
1590
|
+
inlined.set('theme', { value: t.stringLiteral(value) })
|
1591
|
+
}
|
1592
|
+
themeVal = { value: t.stringLiteral(value) }
|
1593
|
+
return []
|
1594
|
+
}
|
1644
1595
|
if (!isValidStyleKey(key, staticConfig)) {
|
1645
1596
|
return []
|
1646
1597
|
}
|
1647
|
-
const value = defaultProps[key]
|
1648
1598
|
const name = tamaguiConfig?.shorthands[key] || key
|
1649
1599
|
if (value === undefined) {
|
1650
1600
|
logger.warn(
|
@@ -1683,8 +1633,10 @@ export function createExtractor(
|
|
1683
1633
|
return attr
|
1684
1634
|
}) as ExtractedAttr[]
|
1685
1635
|
|
1686
|
-
if (
|
1687
|
-
|
1636
|
+
if (!skipMap) {
|
1637
|
+
if (defaultStyleAttrs.length) {
|
1638
|
+
attrs = [...defaultStyleAttrs, ...attrs]
|
1639
|
+
}
|
1688
1640
|
}
|
1689
1641
|
}
|
1690
1642
|
|
@@ -1729,6 +1681,65 @@ export function createExtractor(
|
|
1729
1681
|
}, [])
|
1730
1682
|
.flat()
|
1731
1683
|
|
1684
|
+
const shouldWrapTheme = shouldFlatten && themeVal
|
1685
|
+
// wrap theme around children on flatten
|
1686
|
+
// account for shouldFlatten could change w the above block "if (disableExtractVariables)"
|
1687
|
+
if (shouldWrapTheme) {
|
1688
|
+
if (!programPath) {
|
1689
|
+
console.warn(
|
1690
|
+
`No program path found, avoiding importing flattening / importing theme in ${sourcePath}`
|
1691
|
+
)
|
1692
|
+
} else {
|
1693
|
+
if (shouldPrintDebug) {
|
1694
|
+
logger.info([' - wrapping theme', themeVal].join(' '))
|
1695
|
+
}
|
1696
|
+
|
1697
|
+
// remove theme attribute from flattened node
|
1698
|
+
attrs = attrs.filter((x) =>
|
1699
|
+
x.type === 'attr' &&
|
1700
|
+
t.isJSXAttribute(x.value) &&
|
1701
|
+
x.value.name.name === 'theme'
|
1702
|
+
? false
|
1703
|
+
: true
|
1704
|
+
)
|
1705
|
+
|
1706
|
+
// add import
|
1707
|
+
if (!hasImportedTheme) {
|
1708
|
+
hasImportedTheme = true
|
1709
|
+
programPath.node.body.push(
|
1710
|
+
t.importDeclaration(
|
1711
|
+
[
|
1712
|
+
t.importSpecifier(
|
1713
|
+
t.identifier('_TamaguiTheme'),
|
1714
|
+
t.identifier('Theme')
|
1715
|
+
),
|
1716
|
+
],
|
1717
|
+
t.stringLiteral('@tamagui/web')
|
1718
|
+
)
|
1719
|
+
)
|
1720
|
+
}
|
1721
|
+
|
1722
|
+
traversePath.replaceWith(
|
1723
|
+
t.jsxElement(
|
1724
|
+
t.jsxOpeningElement(t.jsxIdentifier('_TamaguiTheme'), [
|
1725
|
+
t.jsxAttribute(t.jsxIdentifier('name'), themeVal.value),
|
1726
|
+
]),
|
1727
|
+
t.jsxClosingElement(t.jsxIdentifier('_TamaguiTheme')),
|
1728
|
+
[traversePath.node]
|
1729
|
+
)
|
1730
|
+
)
|
1731
|
+
}
|
1732
|
+
}
|
1733
|
+
|
1734
|
+
if (shouldPrintDebug) {
|
1735
|
+
try {
|
1736
|
+
// prettier-ignore
|
1737
|
+
logger.info([' flatten?', shouldFlatten, objToStr({ hasSpread, shouldDeopt, canFlattenProps, shouldWrapTheme, hasOnlyStringChildren }), 'inlined', inlined.size, [...inlined]].join(' '))
|
1738
|
+
} catch {
|
1739
|
+
// ok
|
1740
|
+
}
|
1741
|
+
}
|
1742
|
+
|
1732
1743
|
if (shouldDeopt || !shouldFlatten) {
|
1733
1744
|
if (shouldPrintDebug) {
|
1734
1745
|
logger.info(`Deopting ${shouldDeopt} ${shouldFlatten}`)
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"createExtractor.d.ts","sourceRoot":"","sources":["../../src/extractor/createExtractor.ts"],"names":[],"mappings":"AAGA,OAAiB,EAAE,QAAQ,EAAmB,MAAM,iBAAiB,CAAA;AACrE,OAAO,KAAK,CAAC,MAAM,cAAc,CAAA;AAcjC,OAAO,KAAK,EAGV,gBAAgB,EAChB,mBAAmB,EACnB,cAAc,EAGf,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAcnD,OAAO,EAAE,iBAAiB,EAA6B,MAAM,6BAA6B,CAAA;AAmC1F,MAAM,MAAM,SAAS,GAAG,UAAU,CAAC,OAAO,eAAe,CAAC,CAAA;AAE1D,KAAK,UAAU,GAAG,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,CAAA;AAQ9C,wBAAgB,eAAe,CAC7B,EAAE,MAAgB,EAAE,GAAE,gBAAsC;;;;;yBA0CjC,cAAc;6BAPhB,cAAc;;mBAwBtB,UAAU,SAAS,mBAAmB;;;;;;;eAIpC,UAAU,SAAS,mBAAmB;;;;;;;
|
1
|
+
{"version":3,"file":"createExtractor.d.ts","sourceRoot":"","sources":["../../src/extractor/createExtractor.ts"],"names":[],"mappings":"AAGA,OAAiB,EAAE,QAAQ,EAAmB,MAAM,iBAAiB,CAAA;AACrE,OAAO,KAAK,CAAC,MAAM,cAAc,CAAA;AAcjC,OAAO,KAAK,EAGV,gBAAgB,EAChB,mBAAmB,EACnB,cAAc,EAGf,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAcnD,OAAO,EAAE,iBAAiB,EAA6B,MAAM,6BAA6B,CAAA;AAmC1F,MAAM,MAAM,SAAS,GAAG,UAAU,CAAC,OAAO,eAAe,CAAC,CAAA;AAE1D,KAAK,UAAU,GAAG,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,CAAA;AAQ9C,wBAAgB,eAAe,CAC7B,EAAE,MAAgB,EAAE,GAAE,gBAAsC;;;;;yBA0CjC,cAAc;6BAPhB,cAAc;;mBAwBtB,UAAU,SAAS,mBAAmB;;;;;;;eAIpC,UAAU,SAAS,mBAAmB;;;;;;;EA0pE1D"}
|