@oddo/lang 0.0.9 → 0.0.10
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.js +23 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +23 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3586,7 +3586,7 @@ var traverse = _traverse3.default.default || _traverse3.default;
|
|
|
3586
3586
|
function isValidJSIdentifier(name) {
|
|
3587
3587
|
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
|
|
3588
3588
|
}
|
|
3589
|
-
function wrapDependenciesWithCalls(arrowFunc, deps) {
|
|
3589
|
+
function wrapDependenciesWithCalls(arrowFunc, deps, prefix = "") {
|
|
3590
3590
|
const depSet = new Set(deps);
|
|
3591
3591
|
const locals = /* @__PURE__ */ new Set();
|
|
3592
3592
|
const tempFile = t.file(t.program([t.expressionStatement(arrowFunc)]));
|
|
@@ -3602,6 +3602,14 @@ function wrapDependenciesWithCalls(arrowFunc, deps) {
|
|
|
3602
3602
|
const shorthandToExpand = [];
|
|
3603
3603
|
traverse(tempFile, {
|
|
3604
3604
|
noScope: true,
|
|
3605
|
+
// Skip already-processed reactive expression calls - don't modify their deps arrays
|
|
3606
|
+
// These have the pattern: _x(fn, deps) or _computed(fn, deps) or similar
|
|
3607
|
+
CallExpression(path) {
|
|
3608
|
+
const callee = path.node.callee;
|
|
3609
|
+
if (t.isIdentifier(callee) && callee.name.startsWith("_") && path.node.arguments.length === 2 && t.isArrowFunctionExpression(path.node.arguments[0]) && t.isArrayExpression(path.node.arguments[1])) {
|
|
3610
|
+
path.skip();
|
|
3611
|
+
}
|
|
3612
|
+
},
|
|
3605
3613
|
Identifier(path) {
|
|
3606
3614
|
var _a;
|
|
3607
3615
|
if (t.isArrowFunctionExpression(path.parent) && path.parent.params.includes(path.node)) {
|
|
@@ -3631,9 +3639,9 @@ function wrapDependenciesWithCalls(arrowFunc, deps) {
|
|
|
3631
3639
|
});
|
|
3632
3640
|
shorthandToExpand.forEach(({ prop, name }) => {
|
|
3633
3641
|
prop.shorthand = false;
|
|
3634
|
-
prop.value = t.callExpression(t.identifier(name), []);
|
|
3642
|
+
prop.value = t.callExpression(t.identifier(prefix + name), []);
|
|
3635
3643
|
});
|
|
3636
|
-
toReplace.forEach((p) => p.replaceWith(t.callExpression(t.identifier(p.node.name), [])));
|
|
3644
|
+
toReplace.forEach((p) => p.replaceWith(t.callExpression(t.identifier(prefix + p.node.name), [])));
|
|
3637
3645
|
}
|
|
3638
3646
|
function getReactiveDeps(identifiers) {
|
|
3639
3647
|
return identifiers.filter((id) => {
|
|
@@ -3670,7 +3678,7 @@ function createLiftedExpr(valueExpr, identifiers) {
|
|
|
3670
3678
|
);
|
|
3671
3679
|
}
|
|
3672
3680
|
function createReactiveExpr(oddoExpr, valueExpr, attrExpression = false) {
|
|
3673
|
-
const allIdentifiers = collectOddoIdentifiersOnly(oddoExpr);
|
|
3681
|
+
const allIdentifiers = collectOddoIdentifiersOnly(oddoExpr, /* @__PURE__ */ new Set(), true);
|
|
3674
3682
|
const identifiers = allIdentifiers.filter((id) => isReactive(id));
|
|
3675
3683
|
const pragma = attrExpression ? "computed" : "x";
|
|
3676
3684
|
if (identifiers.length === 0) {
|
|
@@ -3685,10 +3693,10 @@ function createReactiveExpr(oddoExpr, valueExpr, attrExpression = false) {
|
|
|
3685
3693
|
);
|
|
3686
3694
|
}
|
|
3687
3695
|
usedModifiers.add(pragma);
|
|
3688
|
-
const params = identifiers.map((id) => t.identifier(id));
|
|
3696
|
+
const params = identifiers.map((id) => t.identifier("_" + id));
|
|
3689
3697
|
const deps = identifiers.map((id) => t.identifier(id));
|
|
3690
3698
|
const arrowFunc = t.arrowFunctionExpression(params, valueExpr);
|
|
3691
|
-
wrapDependenciesWithCalls(arrowFunc, identifiers);
|
|
3699
|
+
wrapDependenciesWithCalls(arrowFunc, identifiers, "_");
|
|
3692
3700
|
return t.callExpression(
|
|
3693
3701
|
t.identifier(modifierAliases[pragma]),
|
|
3694
3702
|
[arrowFunc, t.arrayExpression(deps)]
|
|
@@ -4019,7 +4027,7 @@ var moduleScope = null;
|
|
|
4019
4027
|
var currentScope = null;
|
|
4020
4028
|
var reactiveScope = /* @__PURE__ */ Symbol("reactive-scope");
|
|
4021
4029
|
function declareVariable(name, type) {
|
|
4022
|
-
const reactive = type === "state" || type === "computed" || type === "param" || type === "import-oddo";
|
|
4030
|
+
const reactive = type === "state" || type === "computed" || type === "reactive-param" || type === "import-oddo";
|
|
4023
4031
|
currentScope[name] = { type, reactive };
|
|
4024
4032
|
}
|
|
4025
4033
|
function isDeclared(name) {
|
|
@@ -4596,17 +4604,20 @@ function convertReactiveContainer(expr) {
|
|
|
4596
4604
|
currentScope = savedScope;
|
|
4597
4605
|
return t.functionExpression(null, params, body);
|
|
4598
4606
|
}
|
|
4599
|
-
function collectOddoIdentifiersOnly(node, names = /* @__PURE__ */ new Set()) {
|
|
4607
|
+
function collectOddoIdentifiersOnly(node, names = /* @__PURE__ */ new Set(), stopAtJsxExpressions = false) {
|
|
4600
4608
|
if (!node || typeof node !== "object") return Array.from(names);
|
|
4609
|
+
if (stopAtJsxExpressions && node.type === "jsxExpression") {
|
|
4610
|
+
return Array.from(names);
|
|
4611
|
+
}
|
|
4601
4612
|
if (node.type === "identifier") {
|
|
4602
4613
|
names.add(node.name);
|
|
4603
4614
|
}
|
|
4604
4615
|
if (node.type === "property") {
|
|
4605
4616
|
if (node.computed && node.key) {
|
|
4606
|
-
collectOddoIdentifiersOnly(node.key, names);
|
|
4617
|
+
collectOddoIdentifiersOnly(node.key, names, stopAtJsxExpressions);
|
|
4607
4618
|
}
|
|
4608
4619
|
if (node.value) {
|
|
4609
|
-
collectOddoIdentifiersOnly(node.value, names);
|
|
4620
|
+
collectOddoIdentifiersOnly(node.value, names, stopAtJsxExpressions);
|
|
4610
4621
|
}
|
|
4611
4622
|
return Array.from(names);
|
|
4612
4623
|
}
|
|
@@ -4614,9 +4625,9 @@ function collectOddoIdentifiersOnly(node, names = /* @__PURE__ */ new Set()) {
|
|
|
4614
4625
|
if (key === "type") continue;
|
|
4615
4626
|
const val = node[key];
|
|
4616
4627
|
if (Array.isArray(val)) {
|
|
4617
|
-
val.forEach((item) => collectOddoIdentifiersOnly(item, names));
|
|
4628
|
+
val.forEach((item) => collectOddoIdentifiersOnly(item, names, stopAtJsxExpressions));
|
|
4618
4629
|
} else if (val && typeof val === "object") {
|
|
4619
|
-
collectOddoIdentifiersOnly(val, names);
|
|
4630
|
+
collectOddoIdentifiersOnly(val, names, stopAtJsxExpressions);
|
|
4620
4631
|
}
|
|
4621
4632
|
}
|
|
4622
4633
|
return Array.from(names);
|