@litsx/babel-preset-litsx 0.7.0 → 0.8.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 CHANGED
@@ -12,6 +12,7 @@ require('@litsx/babel-plugin-shared-hooks');
12
12
  require('./internal/transform-litsx-hooks.cjs');
13
13
  require('./internal/transform-litsx-renderer-props.cjs');
14
14
  require('@babel/plugin-syntax-jsx');
15
+ require('@litsx/authoring');
15
16
  require('./shared/transform-litsx-element-candidates-JMFlPFXK.cjs');
16
17
  require('@babel/helper-plugin-utils');
17
18
  require('@babel/traverse');
@@ -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":";;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;"}
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;;;;;;;;"}
@@ -5,6 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var jsxSyntaxPlugin = require('@babel/plugin-syntax-jsx');
6
6
  var internal_transformLitsxProperties = require('./transform-litsx-properties.cjs');
7
7
  var transformLitsxElementCandidates = require('../shared/transform-litsx-element-candidates-JMFlPFXK.cjs');
8
+ var authoring = require('@litsx/authoring');
8
9
  require('module');
9
10
  require('@litsx/typescript-session');
10
11
  require('@babel/helper-plugin-utils');
@@ -1615,6 +1616,79 @@ function setParamRewriteBabelTypes(nextTypes) {
1615
1616
  t$4 = nextTypes;
1616
1617
  }
1617
1618
 
1619
+ function getBoundPropName$1(bindingInfo) {
1620
+ if (typeof bindingInfo === "string") {
1621
+ return bindingInfo;
1622
+ }
1623
+
1624
+ if (bindingInfo && typeof bindingInfo === "object") {
1625
+ return bindingInfo.bindKey ?? null;
1626
+ }
1627
+
1628
+ return null;
1629
+ }
1630
+
1631
+ function createDefaultSlotElement() {
1632
+ return t$4.jsxElement(
1633
+ t$4.jsxOpeningElement(t$4.jsxIdentifier("slot"), [], false),
1634
+ t$4.jsxClosingElement(t$4.jsxIdentifier("slot")),
1635
+ [],
1636
+ false
1637
+ );
1638
+ }
1639
+
1640
+ function isDirectJsxChildExpression(expressionPath) {
1641
+ return (
1642
+ expressionPath.listKey === "children" &&
1643
+ (expressionPath.parentPath?.isJSXElement() || expressionPath.parentPath?.isJSXFragment())
1644
+ );
1645
+ }
1646
+
1647
+ function isImplicitChildrenExpression(node, bindings) {
1648
+ if (t$4.isIdentifier(node)) {
1649
+ return getBoundPropName$1(bindings.get(node.name)) === "children";
1650
+ }
1651
+
1652
+ if (
1653
+ t$4.isMemberExpression(node) &&
1654
+ !node.computed &&
1655
+ t$4.isIdentifier(node.object) &&
1656
+ t$4.isIdentifier(node.property, { name: "children" })
1657
+ ) {
1658
+ return bindings.has(node.object.name);
1659
+ }
1660
+
1661
+ return false;
1662
+ }
1663
+
1664
+ function isJsxContainerChildPath(path) {
1665
+ return (
1666
+ path?.parentPath?.isJSXExpressionContainer() &&
1667
+ path.parentPath.listKey === "children" &&
1668
+ (path.parentPath.parentPath?.isJSXElement() || path.parentPath.parentPath?.isJSXFragment())
1669
+ );
1670
+ }
1671
+
1672
+ function isSupportedImplicitChildrenReference(refPath, bindingInfo) {
1673
+ if (typeof bindingInfo === "string") {
1674
+ return bindingInfo === "children" && isJsxContainerChildPath(refPath);
1675
+ }
1676
+
1677
+ if (
1678
+ bindingInfo &&
1679
+ typeof bindingInfo === "object" &&
1680
+ bindingInfo.kind === "alias" &&
1681
+ refPath.parentPath?.isMemberExpression() &&
1682
+ refPath.parentKey === "object" &&
1683
+ !refPath.parentPath.node.computed &&
1684
+ t$4.isIdentifier(refPath.parentPath.node.property, { name: "children" })
1685
+ ) {
1686
+ return isJsxContainerChildPath(refPath.parentPath);
1687
+ }
1688
+
1689
+ return false;
1690
+ }
1691
+
1618
1692
  function createThisMemberExpression$2(propName) {
1619
1693
  return t$4.memberExpression(t$4.thisExpression(), t$4.identifier(propName));
1620
1694
  }
@@ -1624,6 +1698,14 @@ function transformJSXExpressions(jsxPath, bindings, state = null) {
1624
1698
 
1625
1699
  jsxPath.traverse({
1626
1700
  JSXExpressionContainer(expressionPath) {
1701
+ if (
1702
+ isDirectJsxChildExpression(expressionPath) &&
1703
+ isImplicitChildrenExpression(expressionPath.node.expression, bindings)
1704
+ ) {
1705
+ expressionPath.replaceWith(createDefaultSlotElement());
1706
+ return;
1707
+ }
1708
+
1627
1709
  if (t$4.isIdentifier(expressionPath.node.expression)) {
1628
1710
  const name = expressionPath.node.expression.name;
1629
1711
  if (localNames.includes(name)) {
@@ -1707,7 +1789,7 @@ function shouldCapturePropReference(refPath, functionPath) {
1707
1789
  return !functionParent.isArrowFunctionExpression();
1708
1790
  }
1709
1791
 
1710
- function replaceParamReferences(functionPath, bindings, propertyMap = new Map()) {
1792
+ function replaceParamReferences(functionPath, bindings, propertyMap = new Map(), state = null) {
1711
1793
  registerLocalPropAliases(functionPath, bindings);
1712
1794
 
1713
1795
  const capturedPropAliases = new Map();
@@ -1779,6 +1861,13 @@ function replaceParamReferences(functionPath, bindings, propertyMap = new Map())
1779
1861
  targetProp = bindingInfo.bindKey;
1780
1862
  }
1781
1863
 
1864
+ if (
1865
+ targetProp === "children" &&
1866
+ !isSupportedImplicitChildrenReference(refPath, bindingInfo)
1867
+ ) {
1868
+ return;
1869
+ }
1870
+
1782
1871
  if (
1783
1872
  typeof bindingInfo === "string" &&
1784
1873
  refPath.parentPath &&
@@ -1957,6 +2046,29 @@ function createNestedInitializerStatement(pattern, root, defaultValue) {
1957
2046
  ]);
1958
2047
  }
1959
2048
 
2049
+ function throwFirstImplicitChildrenProjectionIssue(functionPath) {
2050
+ const [issue] = authoring.collectImplicitChildrenProjectionIssues(functionPath.node);
2051
+ if (!issue) {
2052
+ return;
2053
+ }
2054
+
2055
+ let issuePath = null;
2056
+ functionPath.traverse({
2057
+ enter(path) {
2058
+ if (path.node === issue.node) {
2059
+ issuePath = path;
2060
+ path.stop();
2061
+ }
2062
+ },
2063
+ });
2064
+
2065
+ if (issuePath) {
2066
+ throw issuePath.buildCodeFrameError(issue.message);
2067
+ }
2068
+
2069
+ throw functionPath.buildCodeFrameError(issue.message);
2070
+ }
2071
+
1960
2072
  function collectReturnStatement(functionPath, bindings, state) {
1961
2073
  let returnStatement = null;
1962
2074
 
@@ -1974,6 +2086,8 @@ function collectReturnStatement(functionPath, bindings, state) {
1974
2086
  }
1975
2087
 
1976
2088
  function prepareComponentRender(functionPath, node, propertyNames, bindings, nestedInitializers, options = {}) {
2089
+ throwFirstImplicitChildrenProjectionIssue(functionPath);
2090
+
1977
2091
  const returnStatement = collectReturnStatement(
1978
2092
  functionPath,
1979
2093
  bindings,
@@ -1987,7 +2101,8 @@ function prepareComponentRender(functionPath, node, propertyNames, bindings, nes
1987
2101
  const capturedPropAliasStatements = replaceParamReferences(
1988
2102
  functionPath,
1989
2103
  bindings,
1990
- propertyNames
2104
+ propertyNames,
2105
+ options.state ?? null
1991
2106
  );
1992
2107
  const prefixStatements = [];
1993
2108