@litsx/babel-preset-litsx 0.8.2 → 0.9.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/index.cjs +6 -5
- package/dist/index.cjs.map +1 -1
- package/dist/internal/transform-litsx-components.cjs +71 -37
- package/dist/internal/transform-litsx-components.cjs.map +1 -1
- package/dist/internal/transform-litsx-hooks.cjs +870 -9
- 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 +77 -8
- package/dist/pipeline.cjs.map +1 -1
- package/dist/shared/{transform-litsx-element-candidates-D0uvqG4Y.cjs → transform-litsx-element-candidates-D8pSZxpL.cjs} +21 -13
- package/dist/shared/transform-litsx-element-candidates-D8pSZxpL.cjs.map +1 -0
- package/package.json +8 -3
- 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 +21 -10
- package/src/internal/transform-litsx-hooks.js +868 -9
- package/src/internal/transform-litsx-static-hoists.js +57 -15
- package/src/internal/transform-litsx-static-ir.js +176 -0
- package/src/pipeline.js +71 -3
- package/dist/shared/transform-litsx-element-candidates-D0uvqG4Y.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
|
}
|
|
@@ -2496,6 +2538,7 @@ function createTransformFunctionToClassPlugin(defaultPluginOptions = {}) {
|
|
|
2496
2538
|
setParamRewriteBabelTypes(t);
|
|
2497
2539
|
setRendererCallsBabelTypes(t);
|
|
2498
2540
|
transformLitsxElementCandidates.setElementCandidatesBabelTypes(t);
|
|
2541
|
+
internal_transformLitsxStaticIr.setStaticIrBabelTypes(t);
|
|
2499
2542
|
setRenderBodyBabelTypes(t);
|
|
2500
2543
|
setProgramBabelTypes(t);
|
|
2501
2544
|
const resolvedPluginOptions = {
|
|
@@ -2799,6 +2842,11 @@ function transformFunction(functionPath, programPath, className, options = {}) {
|
|
|
2799
2842
|
const { node } = functionPath;
|
|
2800
2843
|
const elementCandidates = transformLitsxElementCandidates.getAnnotatedElementCandidates(functionPath, programPath, options);
|
|
2801
2844
|
const importedElementCandidates = transformLitsxElementCandidates.getAnnotatedImportedElementCandidates(functionPath, programPath, options);
|
|
2845
|
+
const staticIr = internal_transformLitsxStaticIr.collectStaticIr({
|
|
2846
|
+
functionPath,
|
|
2847
|
+
elementCandidates,
|
|
2848
|
+
importedElementCandidates,
|
|
2849
|
+
});
|
|
2802
2850
|
let resolvedName = className;
|
|
2803
2851
|
if (!resolvedName && node && node.id && t.isIdentifier(node.id)) {
|
|
2804
2852
|
resolvedName = node.id.name;
|
|
@@ -2820,6 +2868,7 @@ function transformFunction(functionPath, programPath, className, options = {}) {
|
|
|
2820
2868
|
programPath,
|
|
2821
2869
|
options
|
|
2822
2870
|
);
|
|
2871
|
+
internal_transformLitsxStaticIr.setStaticIrInferredProperties(staticIr, propertiesStatic);
|
|
2823
2872
|
|
|
2824
2873
|
assertStaticHoistsStayTopLevel(functionPath);
|
|
2825
2874
|
collectNativeClassNameWarnings(functionPath, options.warn, options);
|
|
@@ -2870,7 +2919,7 @@ function transformFunction(functionPath, programPath, className, options = {}) {
|
|
|
2870
2919
|
node,
|
|
2871
2920
|
renderStatements,
|
|
2872
2921
|
programPath,
|
|
2873
|
-
|
|
2922
|
+
staticIr,
|
|
2874
2923
|
classMembers,
|
|
2875
2924
|
options,
|
|
2876
2925
|
getOrCreateModuleStaticHoistSymbol,
|
|
@@ -2896,25 +2945,10 @@ function transformFunction(functionPath, programPath, className, options = {}) {
|
|
|
2896
2945
|
needsCallbackRef,
|
|
2897
2946
|
});
|
|
2898
2947
|
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
}
|
|
2904
|
-
|
|
2905
|
-
if (classNode && importedElementCandidates.length > 0) {
|
|
2906
|
-
classNode._litsxImportedElementCandidates ||= [];
|
|
2907
|
-
importedElementCandidates.forEach((candidate) => {
|
|
2908
|
-
if (!classNode._litsxImportedElementCandidates.some(
|
|
2909
|
-
(entry) =>
|
|
2910
|
-
entry.sourceFile === candidate.sourceFile &&
|
|
2911
|
-
entry.importedName === candidate.importedName &&
|
|
2912
|
-
entry.tagName === candidate.tagName
|
|
2913
|
-
)) {
|
|
2914
|
-
classNode._litsxImportedElementCandidates.push(candidate);
|
|
2915
|
-
}
|
|
2916
|
-
});
|
|
2917
|
-
}
|
|
2948
|
+
internal_transformLitsxStaticIr.attachStaticIr(classNode, {
|
|
2949
|
+
...staticIr,
|
|
2950
|
+
lightDom: lightDomRequested,
|
|
2951
|
+
});
|
|
2918
2952
|
|
|
2919
2953
|
return classNode;
|
|
2920
2954
|
}
|