@litsx/babel-preset-litsx 0.8.1 → 0.9.0
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/index.cjs +6 -5
- package/dist/index.cjs.map +1 -1
- package/dist/internal/transform-litsx-components.cjs +126 -38
- package/dist/internal/transform-litsx-components.cjs.map +1 -1
- package/dist/internal/transform-litsx-hooks.cjs +648 -6
- package/dist/internal/transform-litsx-hooks.cjs.map +1 -1
- package/dist/internal/transform-litsx-renderer-props.cjs +2 -1
- package/dist/internal/transform-litsx-renderer-props.cjs.map +1 -1
- package/dist/internal/transform-litsx-static-ir.cjs +189 -0
- package/dist/internal/transform-litsx-static-ir.cjs.map +1 -0
- package/dist/pipeline.cjs +15 -7
- package/dist/pipeline.cjs.map +1 -1
- package/dist/shared/{transform-litsx-element-candidates-JMFlPFXK.cjs → transform-litsx-element-candidates-D8pSZxpL.cjs} +106 -14
- package/dist/shared/transform-litsx-element-candidates-D8pSZxpL.cjs.map +1 -0
- package/package.json +10 -5
- package/src/internal/transform-litsx-class-generation.js +0 -1
- package/src/internal/transform-litsx-components.js +18 -20
- package/src/internal/transform-litsx-element-candidates.js +106 -11
- package/src/internal/transform-litsx-hooks.js +646 -6
- package/src/internal/transform-litsx-param-rewrites.js +55 -1
- package/src/internal/transform-litsx-static-hoists.js +57 -15
- package/src/internal/transform-litsx-static-ir.js +176 -0
- package/src/pipeline.js +9 -2
- package/dist/shared/transform-litsx-element-candidates-JMFlPFXK.cjs.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -10,16 +10,17 @@ require('@litsx/babel-plugin-transform-litsx-scoped-elements');
|
|
|
10
10
|
require('./internal/transform-litsx-dom-refs.cjs');
|
|
11
11
|
require('@litsx/babel-plugin-shared-hooks');
|
|
12
12
|
require('./internal/transform-litsx-hooks.cjs');
|
|
13
|
+
require('node:fs');
|
|
14
|
+
require('node:path');
|
|
15
|
+
require('@babel/traverse');
|
|
16
|
+
require('@litsx/babel-parser');
|
|
13
17
|
require('./internal/transform-litsx-renderer-props.cjs');
|
|
14
18
|
require('@babel/plugin-syntax-jsx');
|
|
15
19
|
require('@litsx/authoring');
|
|
16
|
-
require('./shared/transform-litsx-element-candidates-
|
|
20
|
+
require('./shared/transform-litsx-element-candidates-D8pSZxpL.cjs');
|
|
17
21
|
require('@babel/helper-plugin-utils');
|
|
18
|
-
require('@babel/traverse');
|
|
19
|
-
require('@litsx/babel-parser');
|
|
20
|
-
require('node:fs');
|
|
21
|
-
require('node:path');
|
|
22
22
|
require('@litsx/typescript-session');
|
|
23
|
+
require('./internal/transform-litsx-static-ir.cjs');
|
|
23
24
|
require('module');
|
|
24
25
|
|
|
25
26
|
function litsxPreset(api, options = {}) {
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/index.js"],"sourcesContent":["import { createLitsxPresetPlugins } from \"./pipeline.js\";\n\nexport { createLitsxPresetPlugins, detectLitsxSourceFeatures } from \"./pipeline.js\";\nexport {\n createTransformLitsxComponentsPlugin,\n setTypescriptModule,\n} from \"./pipeline.js\";\n\nexport default function litsxPreset(api, options = {}) {\n api.assertVersion?.(7);\n\n return {\n plugins: createLitsxPresetPlugins(options),\n };\n}\n"],"names":["createLitsxPresetPlugins"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/index.js"],"sourcesContent":["import { createLitsxPresetPlugins } from \"./pipeline.js\";\n\nexport { createLitsxPresetPlugins, detectLitsxSourceFeatures } from \"./pipeline.js\";\nexport {\n createTransformLitsxComponentsPlugin,\n setTypescriptModule,\n} from \"./pipeline.js\";\n\nexport default function litsxPreset(api, options = {}) {\n api.assertVersion?.(7);\n\n return {\n plugins: createLitsxPresetPlugins(options),\n };\n}\n"],"names":["createLitsxPresetPlugins"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAQe,SAAS,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,EAAE,EAAE;AACvD,EAAE,GAAG,CAAC,aAAa,GAAG,CAAC,CAAC;;AAExB,EAAE,OAAO;AACT,IAAI,OAAO,EAAEA,iCAAwB,CAAC,OAAO,CAAC;AAC9C,GAAG;AACH;;;;;;;;"}
|
|
@@ -4,7 +4,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var jsxSyntaxPlugin = require('@babel/plugin-syntax-jsx');
|
|
6
6
|
var internal_transformLitsxProperties = require('./transform-litsx-properties.cjs');
|
|
7
|
-
var transformLitsxElementCandidates = require('../shared/transform-litsx-element-candidates-
|
|
7
|
+
var transformLitsxElementCandidates = require('../shared/transform-litsx-element-candidates-D8pSZxpL.cjs');
|
|
8
|
+
var internal_transformLitsxStaticIr = require('./transform-litsx-static-ir.cjs');
|
|
8
9
|
var authoring = require('@litsx/authoring');
|
|
9
10
|
require('module');
|
|
10
11
|
require('@litsx/typescript-session');
|
|
@@ -248,6 +249,46 @@ function mergeStaticPropsIntoProperties(propertiesStatic, staticProps) {
|
|
|
248
249
|
});
|
|
249
250
|
}
|
|
250
251
|
|
|
252
|
+
function normalizePropertiesIr(staticIr, renderStatements) {
|
|
253
|
+
const properties = {
|
|
254
|
+
inferred: (staticIr?.properties?.inferred || []).map((entry, index) => ({
|
|
255
|
+
index: entry.index ?? index,
|
|
256
|
+
expression: entry.expression ? t$9.cloneNode(entry.expression) : null,
|
|
257
|
+
})),
|
|
258
|
+
authored: (staticIr?.properties?.authored || []).map((entry, index) => ({
|
|
259
|
+
index: entry.index ?? index,
|
|
260
|
+
expression: entry.expression ? t$9.cloneNode(entry.expression) : null,
|
|
261
|
+
})),
|
|
262
|
+
legacy: (staticIr?.properties?.legacy || []).map((entry, index) => ({
|
|
263
|
+
index: entry.index ?? index,
|
|
264
|
+
expression: entry.expression ? t$9.cloneNode(entry.expression) : null,
|
|
265
|
+
})),
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
if (!staticIr && Array.isArray(renderStatements)) {
|
|
269
|
+
renderStatements.forEach((statement, index) => {
|
|
270
|
+
const propertyOptions = getStaticPropsExpression(statement);
|
|
271
|
+
if (!propertyOptions) return;
|
|
272
|
+
|
|
273
|
+
if (propertyOptions.__litsxHoistedProperties) {
|
|
274
|
+
properties.authored.push({
|
|
275
|
+
index,
|
|
276
|
+
expression: propertyOptions.expression,
|
|
277
|
+
});
|
|
278
|
+
} else {
|
|
279
|
+
properties.legacy.push({
|
|
280
|
+
index,
|
|
281
|
+
expression: propertyOptions,
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
properties.authored.sort((left, right) => left.index - right.index);
|
|
288
|
+
properties.legacy.sort((left, right) => left.index - right.index);
|
|
289
|
+
return properties;
|
|
290
|
+
}
|
|
291
|
+
|
|
251
292
|
function normalizeStylesTemplate(argument, functionPath) {
|
|
252
293
|
if (t$9.isTemplateLiteral(argument)) {
|
|
253
294
|
if (
|
|
@@ -625,28 +666,30 @@ function processStaticHoists({
|
|
|
625
666
|
node,
|
|
626
667
|
renderStatements,
|
|
627
668
|
programPath,
|
|
628
|
-
|
|
669
|
+
staticIr = null,
|
|
629
670
|
classMembers,
|
|
630
671
|
options = {},
|
|
631
672
|
getOrCreateModuleStaticHoistSymbol,
|
|
632
673
|
}) {
|
|
633
674
|
const staticStyles = [];
|
|
634
|
-
const
|
|
635
|
-
const
|
|
675
|
+
const propertiesIr = normalizePropertiesIr(staticIr, renderStatements);
|
|
676
|
+
const effectivePropertiesStatic = propertiesIr.inferred
|
|
677
|
+
.map((entry) => entry.expression)
|
|
678
|
+
.filter(Boolean);
|
|
679
|
+
const staticProps = propertiesIr.legacy
|
|
680
|
+
.map((entry) => entry.expression)
|
|
681
|
+
.filter(Boolean);
|
|
682
|
+
const staticHoists = propertiesIr.authored
|
|
683
|
+
.map((entry) => ({
|
|
684
|
+
name: "properties",
|
|
685
|
+
expression: entry.expression,
|
|
686
|
+
}));
|
|
636
687
|
let lightDomRequested = options.defaultDomMode === "light";
|
|
637
688
|
|
|
638
689
|
if (t$9.isBlockStatement(node.body)) {
|
|
639
690
|
for (let index = renderStatements.length - 1; index >= 0; index -= 1) {
|
|
640
691
|
const propertyOptions = getStaticPropsExpression(renderStatements[index]);
|
|
641
692
|
if (propertyOptions) {
|
|
642
|
-
if (propertyOptions.__litsxHoistedProperties) {
|
|
643
|
-
staticHoists.unshift({
|
|
644
|
-
name: "properties",
|
|
645
|
-
expression: propertyOptions.expression,
|
|
646
|
-
});
|
|
647
|
-
} else {
|
|
648
|
-
staticProps.unshift(propertyOptions);
|
|
649
|
-
}
|
|
650
693
|
renderStatements.splice(index, 1);
|
|
651
694
|
continue;
|
|
652
695
|
}
|
|
@@ -688,14 +731,14 @@ function processStaticHoists({
|
|
|
688
731
|
}
|
|
689
732
|
|
|
690
733
|
if (staticProps.length > 0) {
|
|
691
|
-
mergeStaticPropsIntoProperties(
|
|
734
|
+
mergeStaticPropsIntoProperties(effectivePropertiesStatic, staticProps);
|
|
692
735
|
}
|
|
693
736
|
|
|
694
737
|
const hasHoistedProperties = staticHoists.some((entry) => entry.name === "properties");
|
|
695
|
-
if (
|
|
738
|
+
if (effectivePropertiesStatic.length > 0 && !hasHoistedProperties) {
|
|
696
739
|
const classProperties = t$9.classProperty(
|
|
697
740
|
t$9.identifier("properties"),
|
|
698
|
-
t$9.objectExpression(
|
|
741
|
+
t$9.objectExpression(effectivePropertiesStatic),
|
|
699
742
|
null,
|
|
700
743
|
[],
|
|
701
744
|
false
|
|
@@ -739,7 +782,7 @@ function processStaticHoists({
|
|
|
739
782
|
return createStaticHoistGetter(
|
|
740
783
|
"properties",
|
|
741
784
|
symbolId,
|
|
742
|
-
createPropertiesHoistResolver(
|
|
785
|
+
createPropertiesHoistResolver(effectivePropertiesStatic, staticProps, hoist.expression)
|
|
743
786
|
);
|
|
744
787
|
}
|
|
745
788
|
|
|
@@ -1605,7 +1648,6 @@ function createComponentClass({
|
|
|
1605
1648
|
|
|
1606
1649
|
classNode._needsCss = needsCss;
|
|
1607
1650
|
classNode._needsUnsafeCss = needsUnsafeCss;
|
|
1608
|
-
classNode._litsxLightDom = lightDomRequested;
|
|
1609
1651
|
classNode._needsCallbackRef = needsCallbackRef;
|
|
1610
1652
|
return classNode;
|
|
1611
1653
|
}
|
|
@@ -1693,6 +1735,42 @@ function createThisMemberExpression$2(propName) {
|
|
|
1693
1735
|
return t$4.memberExpression(t$4.thisExpression(), t$4.identifier(propName));
|
|
1694
1736
|
}
|
|
1695
1737
|
|
|
1738
|
+
function createPropsObjectExpression(bindingInfo, propertyMap = new Map()) {
|
|
1739
|
+
if (
|
|
1740
|
+
bindingInfo &&
|
|
1741
|
+
typeof bindingInfo !== "object" &&
|
|
1742
|
+
bindingInfo !== "props"
|
|
1743
|
+
) {
|
|
1744
|
+
return null;
|
|
1745
|
+
}
|
|
1746
|
+
|
|
1747
|
+
const propNames = new Set([
|
|
1748
|
+
...(bindingInfo && typeof bindingInfo === "object" && bindingInfo.kind === "alias"
|
|
1749
|
+
? Array.from(bindingInfo.properties?.keys?.() || [])
|
|
1750
|
+
: []),
|
|
1751
|
+
...Array.from(propertyMap.keys?.() || []),
|
|
1752
|
+
]);
|
|
1753
|
+
const properties = Array.from(propNames)
|
|
1754
|
+
.filter((propName) => typeof propName === "string" && propName.length > 0)
|
|
1755
|
+
.sort()
|
|
1756
|
+
.map((propName) =>
|
|
1757
|
+
t$4.objectProperty(
|
|
1758
|
+
t$4.isValidIdentifier(propName) ? t$4.identifier(propName) : t$4.stringLiteral(propName),
|
|
1759
|
+
createThisMemberExpression$2(propName)
|
|
1760
|
+
)
|
|
1761
|
+
);
|
|
1762
|
+
|
|
1763
|
+
return t$4.objectExpression(properties);
|
|
1764
|
+
}
|
|
1765
|
+
|
|
1766
|
+
function isObjectDestructuringInitializer(refPath) {
|
|
1767
|
+
return (
|
|
1768
|
+
refPath.parentPath?.isVariableDeclarator() &&
|
|
1769
|
+
refPath.parentKey === "init" &&
|
|
1770
|
+
t$4.isObjectPattern(refPath.parentPath.node.id)
|
|
1771
|
+
);
|
|
1772
|
+
}
|
|
1773
|
+
|
|
1696
1774
|
function transformJSXExpressions(jsxPath, bindings, state = null) {
|
|
1697
1775
|
const localNames = Array.from(bindings.keys());
|
|
1698
1776
|
|
|
@@ -1830,10 +1908,20 @@ function replaceParamReferences(functionPath, bindings, propertyMap = new Map(),
|
|
|
1830
1908
|
refPath.parentPath.isObjectProperty({ shorthand: true }) &&
|
|
1831
1909
|
refPath.parentKey === "value"
|
|
1832
1910
|
) {
|
|
1911
|
+
const propsObject = createPropsObjectExpression(bindingInfo, propertyMap);
|
|
1912
|
+
if (propsObject) {
|
|
1913
|
+
refPath.parentPath.node.shorthand = false;
|
|
1914
|
+
refPath.replaceWith(propsObject);
|
|
1915
|
+
return;
|
|
1916
|
+
}
|
|
1833
1917
|
return;
|
|
1834
1918
|
}
|
|
1835
1919
|
|
|
1836
|
-
refPath.replaceWith(
|
|
1920
|
+
refPath.replaceWith(
|
|
1921
|
+
isObjectDestructuringInitializer(refPath)
|
|
1922
|
+
? t$4.thisExpression()
|
|
1923
|
+
: createPropsObjectExpression(bindingInfo, propertyMap) ?? t$4.thisExpression()
|
|
1924
|
+
);
|
|
1837
1925
|
return;
|
|
1838
1926
|
}
|
|
1839
1927
|
|
|
@@ -1915,6 +2003,14 @@ function replaceParamReferences(functionPath, bindings, propertyMap = new Map(),
|
|
|
1915
2003
|
}
|
|
1916
2004
|
}
|
|
1917
2005
|
|
|
2006
|
+
if (localName === "props") {
|
|
2007
|
+
const propsObject = createPropsObjectExpression(bindingInfo, propertyMap);
|
|
2008
|
+
if (propsObject) {
|
|
2009
|
+
refPath.replaceWith(propsObject);
|
|
2010
|
+
return;
|
|
2011
|
+
}
|
|
2012
|
+
}
|
|
2013
|
+
|
|
1918
2014
|
refPath.replaceWith(getReplacementForProp(targetProp || localName, refPath));
|
|
1919
2015
|
});
|
|
1920
2016
|
});
|
|
@@ -2442,6 +2538,7 @@ function createTransformFunctionToClassPlugin(defaultPluginOptions = {}) {
|
|
|
2442
2538
|
setParamRewriteBabelTypes(t);
|
|
2443
2539
|
setRendererCallsBabelTypes(t);
|
|
2444
2540
|
transformLitsxElementCandidates.setElementCandidatesBabelTypes(t);
|
|
2541
|
+
internal_transformLitsxStaticIr.setStaticIrBabelTypes(t);
|
|
2445
2542
|
setRenderBodyBabelTypes(t);
|
|
2446
2543
|
setProgramBabelTypes(t);
|
|
2447
2544
|
const resolvedPluginOptions = {
|
|
@@ -2745,6 +2842,11 @@ function transformFunction(functionPath, programPath, className, options = {}) {
|
|
|
2745
2842
|
const { node } = functionPath;
|
|
2746
2843
|
const elementCandidates = transformLitsxElementCandidates.getAnnotatedElementCandidates(functionPath, programPath, options);
|
|
2747
2844
|
const importedElementCandidates = transformLitsxElementCandidates.getAnnotatedImportedElementCandidates(functionPath, programPath, options);
|
|
2845
|
+
const staticIr = internal_transformLitsxStaticIr.collectStaticIr({
|
|
2846
|
+
functionPath,
|
|
2847
|
+
elementCandidates,
|
|
2848
|
+
importedElementCandidates,
|
|
2849
|
+
});
|
|
2748
2850
|
let resolvedName = className;
|
|
2749
2851
|
if (!resolvedName && node && node.id && t.isIdentifier(node.id)) {
|
|
2750
2852
|
resolvedName = node.id.name;
|
|
@@ -2766,6 +2868,7 @@ function transformFunction(functionPath, programPath, className, options = {}) {
|
|
|
2766
2868
|
programPath,
|
|
2767
2869
|
options
|
|
2768
2870
|
);
|
|
2871
|
+
internal_transformLitsxStaticIr.setStaticIrInferredProperties(staticIr, propertiesStatic);
|
|
2769
2872
|
|
|
2770
2873
|
assertStaticHoistsStayTopLevel(functionPath);
|
|
2771
2874
|
collectNativeClassNameWarnings(functionPath, options.warn, options);
|
|
@@ -2816,7 +2919,7 @@ function transformFunction(functionPath, programPath, className, options = {}) {
|
|
|
2816
2919
|
node,
|
|
2817
2920
|
renderStatements,
|
|
2818
2921
|
programPath,
|
|
2819
|
-
|
|
2922
|
+
staticIr,
|
|
2820
2923
|
classMembers,
|
|
2821
2924
|
options,
|
|
2822
2925
|
getOrCreateModuleStaticHoistSymbol,
|
|
@@ -2842,25 +2945,10 @@ function transformFunction(functionPath, programPath, className, options = {}) {
|
|
|
2842
2945
|
needsCallbackRef,
|
|
2843
2946
|
});
|
|
2844
2947
|
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
}
|
|
2850
|
-
|
|
2851
|
-
if (classNode && importedElementCandidates.length > 0) {
|
|
2852
|
-
classNode._litsxImportedElementCandidates ||= [];
|
|
2853
|
-
importedElementCandidates.forEach((candidate) => {
|
|
2854
|
-
if (!classNode._litsxImportedElementCandidates.some(
|
|
2855
|
-
(entry) =>
|
|
2856
|
-
entry.sourceFile === candidate.sourceFile &&
|
|
2857
|
-
entry.importedName === candidate.importedName &&
|
|
2858
|
-
entry.tagName === candidate.tagName
|
|
2859
|
-
)) {
|
|
2860
|
-
classNode._litsxImportedElementCandidates.push(candidate);
|
|
2861
|
-
}
|
|
2862
|
-
});
|
|
2863
|
-
}
|
|
2948
|
+
internal_transformLitsxStaticIr.attachStaticIr(classNode, {
|
|
2949
|
+
...staticIr,
|
|
2950
|
+
lightDom: lightDomRequested,
|
|
2951
|
+
});
|
|
2864
2952
|
|
|
2865
2953
|
return classNode;
|
|
2866
2954
|
}
|