@tamagui/static 1.0.0-beta.189 → 1.0.0-beta.205
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/extractor/createExtractor.js +134 -64
- package/dist/cjs/extractor/createExtractor.js.map +2 -2
- package/dist/cjs/extractor/extractMediaStyle.js +2 -2
- package/dist/cjs/extractor/extractMediaStyle.js.map +2 -2
- package/dist/cjs/extractor/extractToClassNames.js +0 -3
- package/dist/cjs/extractor/extractToClassNames.js.map +2 -2
- package/dist/cjs/extractor/loadTamagui.js.map +2 -2
- package/dist/esm/extractor/createExtractor.js +137 -67
- package/dist/esm/extractor/createExtractor.js.map +2 -2
- package/dist/esm/extractor/extractMediaStyle.js +2 -2
- package/dist/esm/extractor/extractMediaStyle.js.map +2 -2
- package/dist/esm/extractor/extractToClassNames.js +0 -3
- package/dist/esm/extractor/extractToClassNames.js.map +2 -2
- package/dist/esm/extractor/loadTamagui.js.map +2 -2
- package/dist/jsx/extractor/createExtractor.js +137 -67
- package/dist/jsx/extractor/extractMediaStyle.js +2 -2
- package/dist/jsx/extractor/extractToClassNames.js +0 -3
- package/package.json +7 -7
- package/types/extractor/createExtractor.d.ts.map +1 -1
- package/types/extractor/extractToClassNames.d.ts.map +1 -1
- package/types/extractor/loadTamagui.d.ts +2 -2
- package/types/extractor/loadTamagui.d.ts.map +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/extractor/loadTamagui.ts"],
|
|
4
|
-
"sourcesContent": ["import { join } from 'path'\n\nimport type {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAqB;AAGrB,uBAA8B;AAE9B,IAAI,gBAAqB;AAElB,qBAAqB,OAG1B;AACA,MAAI,eAAe;AACjB,WAAO;AAAA,EACT;AAIA,UAAQ,IAAI,YAAY;AACxB,QAA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amaguiComponent, TamaguiInternalConfig } from '@tamagui/core'\nimport { createTamagui } from '@tamagui/core-node'\n\nlet loadedTamagui: any = null\n\nexport function loadTamagui(props: { components: string[]; config: string }): {\n components: Record<string, TamaguiComponent>\n tamaguiConfig: TamaguiInternalConfig\n} {\n if (loadedTamagui) {\n return loadedTamagui\n }\n\n // lets shim require and avoid importing react-native + react-native-web\n // we just need to read the config around them\n process.env.IS_STATIC = 'is_static'\n const proxyWorm = require('@tamagui/proxy-worm')\n const rnw = require('react-native-web')\n const Mod = require('module')\n const og = Mod.prototype.require\n Mod.prototype.require = function (path: string) {\n if (path.endsWith('.css')) {\n return {}\n }\n if (path === '@gorhom/bottom-sheet' || path.startsWith('react-native-reanimated')) {\n return proxyWorm\n }\n if (\n path.startsWith('react-native') &&\n // allow our rnw.tsx imports through\n !path.startsWith('react-native-web/dist/cjs/exports')\n ) {\n return rnw\n }\n try {\n return og.apply(this, arguments)\n } catch (err: any) {\n console.error('Tamagui error loading file:\\n')\n console.log(' ', path, '\\n')\n console.log(err.message)\n console.log(err.stack)\n // avoid infinite loops\n process.exit(1)\n }\n }\n\n // import config\n const configPath = join(process.cwd(), props.config)\n const tamaguiConfigExport = require(configPath)\n const tamaguiConfig = (tamaguiConfigExport['default'] ||\n tamaguiConfigExport) as TamaguiInternalConfig\n\n if (!tamaguiConfig || !tamaguiConfig.parsed) {\n try {\n const confPath = require.resolve(configPath)\n console.log(`Received:`, tamaguiConfigExport)\n throw new Error(`Can't find valid config in ${confPath}`)\n } catch (err) {\n throw err\n }\n }\n\n // import components\n const components = {}\n for (const module of props.components) {\n const exported = require(module)\n Object.assign(components, exported)\n }\n\n // undo shims\n process.env.IS_STATIC = undefined\n Mod.prototype.require = og\n\n // set up core-node\n createTamagui(tamaguiConfig as any)\n\n loadedTamagui = {\n components,\n tamaguiConfig,\n }\n\n return loadedTamagui\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;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WAAO,OAAO,YAAY,QAAQ;AAAA,EACpC;AAGA,UAAQ,IAAI,YAAY;AACxB,MAAI,UAAU,UAAU;AAGxB,sCAAc,aAAoB;AAElC,kBAAgB;AAAA,IACd;AAAA,IACA;AAAA,EACF;AAEA,SAAO;AACT;AA7EgB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -26,6 +26,15 @@ const UNTOUCHED_PROPS = {
|
|
|
26
26
|
style: true,
|
|
27
27
|
className: true
|
|
28
28
|
};
|
|
29
|
+
const INLINE_EXTRACTABLE = {
|
|
30
|
+
ref: "ref",
|
|
31
|
+
key: "key",
|
|
32
|
+
onPress: "onClick",
|
|
33
|
+
onHoverIn: "onMouseEnter",
|
|
34
|
+
onHoverOut: "onMouseLeave",
|
|
35
|
+
onPressIn: "onMouseDown",
|
|
36
|
+
onPressOut: "onMouseUp"
|
|
37
|
+
};
|
|
29
38
|
const isAttr = /* @__PURE__ */ __name((x) => x.type === "attr", "isAttr");
|
|
30
39
|
const validHooks = {
|
|
31
40
|
useMedia: true,
|
|
@@ -33,6 +42,10 @@ const validHooks = {
|
|
|
33
42
|
};
|
|
34
43
|
const createTernary = /* @__PURE__ */ __name((x) => x, "createTernary");
|
|
35
44
|
function createExtractor() {
|
|
45
|
+
if (!process.env.TAMAGUI_TARGET) {
|
|
46
|
+
console.log('\u26A0\uFE0F Please set process.env.TAMAGUI_TARGET to either "web" or "native"');
|
|
47
|
+
process.exit(1);
|
|
48
|
+
}
|
|
36
49
|
const shouldAddDebugProp = !process.env.npm_package_dependencies_next && process.env.TAMAGUI_TARGET !== "native" && process.env.IDENTIFY_TAGS !== "false" && (process.env.NODE_ENV === "development" || process.env.DEBUG || process.env.IDENTIFY_TAGS);
|
|
37
50
|
require("esbuild-register/dist/node").register({
|
|
38
51
|
target: "es2019",
|
|
@@ -88,6 +101,7 @@ function createExtractor() {
|
|
|
88
101
|
return obj;
|
|
89
102
|
}, {});
|
|
90
103
|
let doesUseValidImport = false;
|
|
104
|
+
let hasImportedTheme = false;
|
|
91
105
|
for (const bodyPath of body) {
|
|
92
106
|
if (bodyPath.type !== "ImportDeclaration")
|
|
93
107
|
continue;
|
|
@@ -156,16 +170,17 @@ function createExtractor() {
|
|
|
156
170
|
}
|
|
157
171
|
const originalNodeName = node.name.name;
|
|
158
172
|
res.found++;
|
|
173
|
+
const filePath = sourcePath.replace(process.cwd(), ".");
|
|
174
|
+
const lineNumbers = node.loc ? node.loc.start.line + (node.loc.start.line !== node.loc.end.line ? `-${node.loc.end.line}` : "") : "";
|
|
175
|
+
const preName = componentName ? `${componentName}.` : "";
|
|
176
|
+
const tagId = `${preName}${node.name.name}@${filePath.replace("./", "")}:${lineNumbers}`;
|
|
159
177
|
if (shouldPrintDebug) {
|
|
160
178
|
console.log(`
|
|
161
|
-
<${originalNodeName}
|
|
179
|
+
<${originalNodeName} /> (${tagId})`);
|
|
162
180
|
}
|
|
163
|
-
const filePath = sourcePath.replace(process.cwd(), ".");
|
|
164
|
-
const lineNumbers = node.loc ? node.loc.start.line + (node.loc.start.line !== node.loc.end.line ? `-${node.loc.end.line}` : "") : "";
|
|
165
181
|
if (shouldAddDebugProp && !disableDebugAttr) {
|
|
166
|
-
const preName = componentName ? `${componentName}.` : "";
|
|
167
182
|
res.modified++;
|
|
168
|
-
node.attributes.unshift(t.jsxAttribute(t.jsxIdentifier("data-is"), t.stringLiteral(
|
|
183
|
+
node.attributes.unshift(t.jsxAttribute(t.jsxIdentifier("data-is"), t.stringLiteral(tagId)));
|
|
169
184
|
}
|
|
170
185
|
const shouldLog = !hasLogged;
|
|
171
186
|
if (shouldLog) {
|
|
@@ -202,6 +217,7 @@ function createExtractor() {
|
|
|
202
217
|
...staticConfig.inlineProps || []
|
|
203
218
|
]);
|
|
204
219
|
const deoptProps = /* @__PURE__ */ new Set([
|
|
220
|
+
"animation",
|
|
205
221
|
...props.deoptProps || [],
|
|
206
222
|
...staticConfig.deoptProps || []
|
|
207
223
|
]);
|
|
@@ -280,7 +296,7 @@ function createExtractor() {
|
|
|
280
296
|
}
|
|
281
297
|
let attrs = [];
|
|
282
298
|
let shouldDeopt = false;
|
|
283
|
-
|
|
299
|
+
const inlined = /* @__PURE__ */ new Map();
|
|
284
300
|
let hasSetOptimized = false;
|
|
285
301
|
attrs = traversePath.get("openingElement").get("attributes").flatMap((path) => {
|
|
286
302
|
try {
|
|
@@ -332,7 +348,7 @@ function createExtractor() {
|
|
|
332
348
|
if (shouldPrintDebug) {
|
|
333
349
|
console.log(" ! inlining, spread attr");
|
|
334
350
|
}
|
|
335
|
-
|
|
351
|
+
inlined.set(`${Math.random()}`, "spread");
|
|
336
352
|
return attr;
|
|
337
353
|
}
|
|
338
354
|
const name = attribute.name.name;
|
|
@@ -343,7 +359,7 @@ function createExtractor() {
|
|
|
343
359
|
return null;
|
|
344
360
|
}
|
|
345
361
|
if (inlineProps.has(name)) {
|
|
346
|
-
|
|
362
|
+
inlined.set(name, name);
|
|
347
363
|
if (shouldPrintDebug) {
|
|
348
364
|
console.log(" ! inlining, inline prop", name);
|
|
349
365
|
}
|
|
@@ -351,7 +367,7 @@ function createExtractor() {
|
|
|
351
367
|
}
|
|
352
368
|
if (deoptProps.has(name)) {
|
|
353
369
|
shouldDeopt = true;
|
|
354
|
-
|
|
370
|
+
inlined.set(name, name);
|
|
355
371
|
if (shouldPrintDebug) {
|
|
356
372
|
console.log(" ! inlining, deopted prop", name);
|
|
357
373
|
}
|
|
@@ -360,6 +376,10 @@ function createExtractor() {
|
|
|
360
376
|
if (UNTOUCHED_PROPS[name]) {
|
|
361
377
|
return attr;
|
|
362
378
|
}
|
|
379
|
+
if (INLINE_EXTRACTABLE[name]) {
|
|
380
|
+
inlined.set(name, INLINE_EXTRACTABLE[name]);
|
|
381
|
+
return attr;
|
|
382
|
+
}
|
|
363
383
|
if (name.startsWith("data-")) {
|
|
364
384
|
return attr;
|
|
365
385
|
}
|
|
@@ -397,7 +417,7 @@ function createExtractor() {
|
|
|
397
417
|
if (shouldPrintDebug) {
|
|
398
418
|
console.log(" ! inlining, ref", name);
|
|
399
419
|
}
|
|
400
|
-
|
|
420
|
+
inlined.set("ref", "ref");
|
|
401
421
|
return attr;
|
|
402
422
|
}
|
|
403
423
|
if (name === "tag") {
|
|
@@ -412,7 +432,7 @@ function createExtractor() {
|
|
|
412
432
|
if (shouldPrintDebug) {
|
|
413
433
|
console.log(` ! inlining, native disable extract: ${name} =`, value.value);
|
|
414
434
|
}
|
|
415
|
-
|
|
435
|
+
inlined.set(name, true);
|
|
416
436
|
return attr;
|
|
417
437
|
}
|
|
418
438
|
}
|
|
@@ -422,26 +442,56 @@ function createExtractor() {
|
|
|
422
442
|
let keys = [name];
|
|
423
443
|
let out = null;
|
|
424
444
|
if (staticConfig.propMapper) {
|
|
425
|
-
out = staticConfig.propMapper(name, styleValue, defaultTheme, staticConfig.defaultProps,
|
|
445
|
+
out = staticConfig.propMapper(name, styleValue, defaultTheme, staticConfig.defaultProps, "auto");
|
|
426
446
|
if (out) {
|
|
427
447
|
out = rnw.createDOMProps(isTextView ? "span" : "div", out);
|
|
428
448
|
delete out.className;
|
|
429
449
|
keys = Object.keys(out);
|
|
430
450
|
}
|
|
431
451
|
}
|
|
452
|
+
let didInline = false;
|
|
432
453
|
const attributes = keys.map((key) => {
|
|
433
454
|
const val = out[key];
|
|
434
|
-
if (
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
455
|
+
if (key === "theme") {
|
|
456
|
+
inlined.set(key, val);
|
|
457
|
+
return attr;
|
|
458
|
+
}
|
|
459
|
+
if (isValidStyleKey(key)) {
|
|
460
|
+
return {
|
|
461
|
+
type: "style",
|
|
462
|
+
value: { [name]: styleValue },
|
|
463
|
+
name,
|
|
464
|
+
attr: path.node
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
if (validHTMLAttributes[key]) {
|
|
468
|
+
return attr;
|
|
469
|
+
}
|
|
470
|
+
if (shouldPrintDebug) {
|
|
471
|
+
console.log(" ! inlining, non-static", key);
|
|
472
|
+
}
|
|
473
|
+
didInline = true;
|
|
474
|
+
inlined.set(key, val);
|
|
475
|
+
return val;
|
|
476
|
+
});
|
|
477
|
+
if (didInline) {
|
|
478
|
+
if (shouldPrintDebug) {
|
|
479
|
+
console.log(" bailing flattening due to attributes", attributes);
|
|
480
|
+
}
|
|
481
|
+
return attr;
|
|
482
|
+
}
|
|
483
|
+
return attributes;
|
|
484
|
+
}
|
|
485
|
+
if (styleValue !== FAILED_EVAL) {
|
|
486
|
+
if (isValidStyleKey(name)) {
|
|
487
|
+
if (shouldPrintDebug) {
|
|
488
|
+
console.log(` style: ${name} =`, styleValue);
|
|
489
|
+
}
|
|
490
|
+
if (!(name in staticConfig.defaultProps)) {
|
|
491
|
+
if (!hasSetOptimized) {
|
|
492
|
+
res.optimized++;
|
|
493
|
+
hasSetOptimized = true;
|
|
443
494
|
}
|
|
444
|
-
inlinePropCount++;
|
|
445
495
|
}
|
|
446
496
|
return {
|
|
447
497
|
type: "style",
|
|
@@ -449,28 +499,10 @@ function createExtractor() {
|
|
|
449
499
|
name,
|
|
450
500
|
attr: path.node
|
|
451
501
|
};
|
|
452
|
-
}
|
|
453
|
-
|
|
502
|
+
} else {
|
|
503
|
+
inlined.set(name, true);
|
|
454
504
|
return attr;
|
|
455
505
|
}
|
|
456
|
-
return attributes;
|
|
457
|
-
}
|
|
458
|
-
if (styleValue !== FAILED_EVAL) {
|
|
459
|
-
if (shouldPrintDebug) {
|
|
460
|
-
console.log(` style: ${name} =`, styleValue);
|
|
461
|
-
}
|
|
462
|
-
if (!(name in staticConfig.defaultProps)) {
|
|
463
|
-
if (!hasSetOptimized) {
|
|
464
|
-
res.optimized++;
|
|
465
|
-
hasSetOptimized = true;
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
return {
|
|
469
|
-
type: "style",
|
|
470
|
-
value: { [name]: styleValue },
|
|
471
|
-
name,
|
|
472
|
-
attr: path.node
|
|
473
|
-
};
|
|
474
506
|
}
|
|
475
507
|
if (t.isBinaryExpression(value)) {
|
|
476
508
|
if (shouldPrintDebug) {
|
|
@@ -495,7 +527,7 @@ function createExtractor() {
|
|
|
495
527
|
if (shouldPrintDebug) {
|
|
496
528
|
console.log(` evalBinaryExpression cant extract`);
|
|
497
529
|
}
|
|
498
|
-
|
|
530
|
+
inlined.set(name, true);
|
|
499
531
|
return attr;
|
|
500
532
|
}
|
|
501
533
|
const staticConditional = getStaticConditional(value);
|
|
@@ -512,12 +544,9 @@ function createExtractor() {
|
|
|
512
544
|
}
|
|
513
545
|
return { type: "ternary", value: staticLogical };
|
|
514
546
|
}
|
|
547
|
+
inlined.set(name, true);
|
|
515
548
|
if (shouldPrintDebug) {
|
|
516
|
-
console.log(
|
|
517
|
-
}
|
|
518
|
-
inlinePropCount++;
|
|
519
|
-
if (shouldPrintDebug) {
|
|
520
|
-
console.log(` inlining ${name} = `, value);
|
|
549
|
+
console.log(` ! inline no match ${name}`, value);
|
|
521
550
|
}
|
|
522
551
|
return attr;
|
|
523
552
|
function addBinaryConditional(operator, staticExpr, cond) {
|
|
@@ -750,7 +779,28 @@ function createExtractor() {
|
|
|
750
779
|
};
|
|
751
780
|
const hasSpread = node.attributes.some((x) => t.isJSXSpreadAttribute(x));
|
|
752
781
|
const hasOnlyStringChildren = !hasSpread && (node.selfClosing || traversePath.node.children && traversePath.node.children.every((x) => x.type === "JSXText"));
|
|
753
|
-
const
|
|
782
|
+
const themeVal = inlined.get("theme");
|
|
783
|
+
inlined.delete("theme");
|
|
784
|
+
const allOtherPropsExtractable = [...inlined].every(([k, v]) => INLINE_EXTRACTABLE[k]);
|
|
785
|
+
const shouldWrapInnerTheme = allOtherPropsExtractable && !!(hasOnlyStringChildren && themeVal);
|
|
786
|
+
const canFlattenProps = inlined.size === 0 || shouldWrapInnerTheme || allOtherPropsExtractable;
|
|
787
|
+
let shouldFlatten = !shouldDeopt && canFlattenProps && !hasSpread && staticConfig.neverFlatten !== true && (staticConfig.neverFlatten === "jsx" ? hasOnlyStringChildren : true);
|
|
788
|
+
if (shouldFlatten && shouldWrapInnerTheme) {
|
|
789
|
+
if (typeof themeVal !== "string") {
|
|
790
|
+
console.warn("??");
|
|
791
|
+
return;
|
|
792
|
+
}
|
|
793
|
+
if (shouldPrintDebug) {
|
|
794
|
+
console.log(" - wrapping theme", allOtherPropsExtractable, themeVal);
|
|
795
|
+
}
|
|
796
|
+
if (!hasImportedTheme) {
|
|
797
|
+
hasImportedTheme = true;
|
|
798
|
+
programPath.node.body.push(t.importDeclaration([t.importSpecifier(t.identifier("_TamaguiTheme"), t.identifier("Theme"))], t.stringLiteral("@tamagui/core")));
|
|
799
|
+
}
|
|
800
|
+
traversePath.replaceWith(t.jsxElement(t.jsxOpeningElement(t.jsxIdentifier("_TamaguiTheme"), [
|
|
801
|
+
t.jsxAttribute(t.jsxIdentifier("name"), t.stringLiteral(`${themeVal}`))
|
|
802
|
+
]), t.jsxClosingElement(t.jsxIdentifier("_TamaguiTheme")), [traversePath.node]));
|
|
803
|
+
}
|
|
754
804
|
if (shouldFlatten && staticConfig.defaultProps) {
|
|
755
805
|
const defaultStyleAttrs = Object.keys(staticConfig.defaultProps).flatMap((key) => {
|
|
756
806
|
if (!isValidStyleKey(key)) {
|
|
@@ -805,8 +855,12 @@ function createExtractor() {
|
|
|
805
855
|
if (!cur) {
|
|
806
856
|
return acc;
|
|
807
857
|
}
|
|
808
|
-
if (
|
|
809
|
-
|
|
858
|
+
if (cur.type === "attr" && !t.isJSXSpreadAttribute(cur.value)) {
|
|
859
|
+
if (shouldFlatten) {
|
|
860
|
+
if (cur.value.name.name === "tag") {
|
|
861
|
+
return acc;
|
|
862
|
+
}
|
|
863
|
+
}
|
|
810
864
|
}
|
|
811
865
|
if (cur.type !== "style") {
|
|
812
866
|
acc.push(cur);
|
|
@@ -884,6 +938,10 @@ function createExtractor() {
|
|
|
884
938
|
if (shouldPrintDebug) {
|
|
885
939
|
console.log(" - attrs (combined \u{1F500}): \n", logLines(attrs.map(attrStr).join(", ")));
|
|
886
940
|
}
|
|
941
|
+
const completeProps = {
|
|
942
|
+
...staticConfig.defaultProps,
|
|
943
|
+
...completeStaticProps
|
|
944
|
+
};
|
|
887
945
|
const getStyles = /* @__PURE__ */ __name((props2, debugName = "") => {
|
|
888
946
|
if (!props2)
|
|
889
947
|
return;
|
|
@@ -897,12 +955,25 @@ function createExtractor() {
|
|
|
897
955
|
}
|
|
898
956
|
}
|
|
899
957
|
const out = getSplitStyles(props2, staticConfig, defaultTheme, {
|
|
900
|
-
noClassNames: true
|
|
958
|
+
noClassNames: true,
|
|
959
|
+
fallbackProps: completeProps,
|
|
960
|
+
focus: false,
|
|
961
|
+
hover: false,
|
|
962
|
+
mounted: true,
|
|
963
|
+
press: false,
|
|
964
|
+
pressIn: false
|
|
901
965
|
});
|
|
902
966
|
const outStyle = {
|
|
903
967
|
...out.style,
|
|
904
968
|
...out.pseudos
|
|
905
969
|
};
|
|
970
|
+
for (const key in outStyle) {
|
|
971
|
+
if (staticConfig.validStyles) {
|
|
972
|
+
if (!staticConfig.validStyles[key] && !pseudos[key]) {
|
|
973
|
+
delete outStyle[key];
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
}
|
|
906
977
|
if (shouldPrintDebug === "verbose") {
|
|
907
978
|
console.log(` getStyles ${debugName} (props):
|
|
908
979
|
`, logLines(objToStr(props2)));
|
|
@@ -911,19 +982,9 @@ function createExtractor() {
|
|
|
911
982
|
console.log(` getStyles ${debugName} (out.style):
|
|
912
983
|
`, logLines(objToStr(outStyle || {}), true));
|
|
913
984
|
}
|
|
914
|
-
for (const key in outStyle) {
|
|
915
|
-
if (staticConfig.validStyles) {
|
|
916
|
-
if (!staticConfig.validStyles[key] && !pseudos[key]) {
|
|
917
|
-
delete outStyle[key];
|
|
918
|
-
}
|
|
919
|
-
}
|
|
920
|
-
}
|
|
921
985
|
return outStyle;
|
|
922
986
|
}, "getStyles");
|
|
923
|
-
const completeStylesProcessed = getStyles(
|
|
924
|
-
...staticConfig.defaultProps,
|
|
925
|
-
...completeStaticProps
|
|
926
|
-
}, "completeStylesProcessed");
|
|
987
|
+
const completeStylesProcessed = getStyles(completeProps, "completeStylesProcessed");
|
|
927
988
|
if (!completeStylesProcessed) {
|
|
928
989
|
throw new Error(`Impossible, no styles`);
|
|
929
990
|
}
|
|
@@ -982,6 +1043,18 @@ function createExtractor() {
|
|
|
982
1043
|
const existingStyleKeys = /* @__PURE__ */ new Set();
|
|
983
1044
|
for (let i = attrs.length - 1; i >= 0; i--) {
|
|
984
1045
|
const attr = attrs[i];
|
|
1046
|
+
if (shouldFlatten && canFlattenProps) {
|
|
1047
|
+
if (attr.type === "attr") {
|
|
1048
|
+
if (t.isJSXAttribute(attr.value)) {
|
|
1049
|
+
if (t.isJSXIdentifier(attr.value.name)) {
|
|
1050
|
+
const name = attr.value.name.name;
|
|
1051
|
+
if (INLINE_EXTRACTABLE[name]) {
|
|
1052
|
+
attr.value.name.name = INLINE_EXTRACTABLE[name];
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
985
1058
|
if (attr.type === "style") {
|
|
986
1059
|
for (const key in attr.value) {
|
|
987
1060
|
if (existingStyleKeys.has(key)) {
|
|
@@ -992,9 +1065,6 @@ function createExtractor() {
|
|
|
992
1065
|
}
|
|
993
1066
|
}
|
|
994
1067
|
}
|
|
995
|
-
if (shouldPrintDebug) {
|
|
996
|
-
console.log(" - attrs (after):\n", logLines(attrs.map(attrStr).join(", ")));
|
|
997
|
-
}
|
|
998
1068
|
if (shouldFlatten) {
|
|
999
1069
|
if (shouldPrintDebug) {
|
|
1000
1070
|
console.log(" [\u2705] flattening", originalNodeName, flatNode);
|
|
@@ -1006,7 +1076,7 @@ function createExtractor() {
|
|
|
1006
1076
|
}
|
|
1007
1077
|
}
|
|
1008
1078
|
if (shouldPrintDebug) {
|
|
1009
|
-
console.log(` \u274A\u274A inline props (${
|
|
1079
|
+
console.log(` \u274A\u274A inline props (${inlined.size}):`, shouldDeopt ? " deopted" : "", hasSpread ? " has spread" : "", staticConfig.neverFlatten ? "neverFlatten" : "");
|
|
1010
1080
|
console.log(" - attrs (end):\n", logLines(attrs.map(attrStr).join(", ")));
|
|
1011
1081
|
}
|
|
1012
1082
|
onExtractTag({
|