@oddo/lang 0.0.8 → 0.0.9
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 +57 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +57 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +45 -45
package/dist/index.js
CHANGED
|
@@ -3728,7 +3728,11 @@ var MODIFIER_TRANSFORMATIONS = {
|
|
|
3728
3728
|
transform: (oddoExpr, leftExpr) => {
|
|
3729
3729
|
const allIds = collectOddoIdentifiersOnly(oddoExpr);
|
|
3730
3730
|
const identifiers = allIds.filter((id) => isReactive(id));
|
|
3731
|
+
const savedScope = currentScope;
|
|
3732
|
+
currentScope = Object.create(currentScope);
|
|
3733
|
+
currentScope[reactiveScope] = false;
|
|
3731
3734
|
const valueExpr = convertExpression2(oddoExpr);
|
|
3735
|
+
currentScope = savedScope;
|
|
3732
3736
|
const params = identifiers.map((id) => t.identifier(id));
|
|
3733
3737
|
const deps = identifiers.map((id) => t.identifier(id));
|
|
3734
3738
|
const arrowFunc = t.arrowFunctionExpression(params, valueExpr);
|
|
@@ -3811,6 +3815,9 @@ var MODIFIER_TRANSFORMATIONS = {
|
|
|
3811
3815
|
...stateContainerNames,
|
|
3812
3816
|
...outerDepsArray.filter((id) => !mutableVariables.has(id))
|
|
3813
3817
|
]);
|
|
3818
|
+
const savedScopeMutate = currentScope;
|
|
3819
|
+
currentScope = Object.create(currentScope);
|
|
3820
|
+
currentScope[reactiveScope] = false;
|
|
3814
3821
|
for (const assignment of assignments) {
|
|
3815
3822
|
const rightBabel = convertExpression2(assignment.rightOddo);
|
|
3816
3823
|
const tempFile = t.file(t.program([t.expressionStatement(rightBabel)]));
|
|
@@ -3863,6 +3870,7 @@ var MODIFIER_TRANSFORMATIONS = {
|
|
|
3863
3870
|
);
|
|
3864
3871
|
}
|
|
3865
3872
|
}
|
|
3873
|
+
currentScope = savedScopeMutate;
|
|
3866
3874
|
if (stateContainerNames.length > 0) {
|
|
3867
3875
|
mutateBodyStmts.push(
|
|
3868
3876
|
t.expressionStatement(
|
|
@@ -3916,6 +3924,7 @@ var MODIFIER_TRANSFORMATIONS = {
|
|
|
3916
3924
|
const deps = identifiers.map((id) => t.identifier(id));
|
|
3917
3925
|
const savedScope = currentScope;
|
|
3918
3926
|
currentScope = Object.create(currentScope);
|
|
3927
|
+
currentScope[reactiveScope] = false;
|
|
3919
3928
|
for (const id of identifiers) {
|
|
3920
3929
|
currentScope[id] = { type: "param", reactive: false };
|
|
3921
3930
|
}
|
|
@@ -3948,7 +3957,16 @@ var MODIFIER_TRANSFORMATIONS = {
|
|
|
3948
3957
|
if (leftExpr && t.isIdentifier(leftExpr)) {
|
|
3949
3958
|
mutableVariables.add(leftExpr.name);
|
|
3950
3959
|
const identifiers = collectOddoIdentifiersOnly(oddoExpr);
|
|
3960
|
+
const reactiveDeps = getReactiveDeps(identifiers);
|
|
3961
|
+
const savedScope = currentScope;
|
|
3962
|
+
if (reactiveDeps.length > 0) {
|
|
3963
|
+
currentScope = Object.create(currentScope);
|
|
3964
|
+
currentScope[reactiveScope] = false;
|
|
3965
|
+
}
|
|
3951
3966
|
const valueExpr = convertExpression2(oddoExpr);
|
|
3967
|
+
if (reactiveDeps.length > 0) {
|
|
3968
|
+
currentScope = savedScope;
|
|
3969
|
+
}
|
|
3952
3970
|
const liftedExpr = createLiftedExpr(valueExpr, identifiers);
|
|
3953
3971
|
return t.variableDeclaration("let", [
|
|
3954
3972
|
t.variableDeclarator(leftExpr, liftedExpr || valueExpr)
|
|
@@ -3999,6 +4017,7 @@ var stateSetterMap = /* @__PURE__ */ new Map();
|
|
|
3999
4017
|
var mutableVariables = /* @__PURE__ */ new Set();
|
|
4000
4018
|
var moduleScope = null;
|
|
4001
4019
|
var currentScope = null;
|
|
4020
|
+
var reactiveScope = /* @__PURE__ */ Symbol("reactive-scope");
|
|
4002
4021
|
function declareVariable(name, type) {
|
|
4003
4022
|
const reactive = type === "state" || type === "computed" || type === "param" || type === "import-oddo";
|
|
4004
4023
|
currentScope[name] = { type, reactive };
|
|
@@ -4059,6 +4078,7 @@ function collectOddoIdentifiers(node, names = /* @__PURE__ */ new Set()) {
|
|
|
4059
4078
|
if (!node || typeof node !== "object") return names;
|
|
4060
4079
|
if (node.type === "program") {
|
|
4061
4080
|
moduleScope = /* @__PURE__ */ Object.create(null);
|
|
4081
|
+
moduleScope[reactiveScope] = true;
|
|
4062
4082
|
currentScope = moduleScope;
|
|
4063
4083
|
}
|
|
4064
4084
|
if (node.type === "identifier") {
|
|
@@ -4301,14 +4321,23 @@ function convertExpressionStatement2(stmt) {
|
|
|
4301
4321
|
if (stmt.expression && stmt.expression.type === "variableDeclaration") {
|
|
4302
4322
|
const left = convertExpression2(stmt.expression.left);
|
|
4303
4323
|
const oddoRight = stmt.expression.right;
|
|
4304
|
-
|
|
4305
|
-
let finalExpr = right;
|
|
4324
|
+
let finalExpr;
|
|
4306
4325
|
if (oddoRight.type !== "arrowFunction") {
|
|
4307
4326
|
const identifiers = collectOddoIdentifiersOnly(oddoRight);
|
|
4308
|
-
const
|
|
4309
|
-
|
|
4310
|
-
|
|
4327
|
+
const reactiveDeps = getReactiveDeps(identifiers);
|
|
4328
|
+
const savedScope = currentScope;
|
|
4329
|
+
if (reactiveDeps.length > 0) {
|
|
4330
|
+
currentScope = Object.create(currentScope);
|
|
4331
|
+
currentScope[reactiveScope] = false;
|
|
4332
|
+
}
|
|
4333
|
+
const right = convertExpression2(oddoRight);
|
|
4334
|
+
if (reactiveDeps.length > 0) {
|
|
4335
|
+
currentScope = savedScope;
|
|
4311
4336
|
}
|
|
4337
|
+
const liftedExpr = createLiftedExpr(right, identifiers);
|
|
4338
|
+
finalExpr = liftedExpr || right;
|
|
4339
|
+
} else {
|
|
4340
|
+
finalExpr = convertExpression2(oddoRight);
|
|
4312
4341
|
}
|
|
4313
4342
|
return t.variableDeclaration("const", [
|
|
4314
4343
|
t.variableDeclarator(left, finalExpr)
|
|
@@ -4457,17 +4486,21 @@ function convertArrowFunction2(expr) {
|
|
|
4457
4486
|
if (expr._scope) {
|
|
4458
4487
|
currentScope = expr._scope;
|
|
4459
4488
|
}
|
|
4489
|
+
const inReactiveScope = (savedScope == null ? void 0 : savedScope[reactiveScope]) !== false;
|
|
4460
4490
|
const bodyIdentifiers = collectOddoIdentifiersOnly(expr.body);
|
|
4461
|
-
const reactiveDepsForBody = bodyIdentifiers.filter((id) => {
|
|
4491
|
+
const reactiveDepsForBody = inReactiveScope ? bodyIdentifiers.filter((id) => {
|
|
4462
4492
|
var _a;
|
|
4463
4493
|
const isOwnParam = (_a = expr.parameters) == null ? void 0 : _a.some((p) => p.name === id);
|
|
4464
4494
|
if (isOwnParam) return false;
|
|
4465
4495
|
const varInfo = savedScope == null ? void 0 : savedScope[id];
|
|
4466
4496
|
return (varInfo == null ? void 0 : varInfo.reactive) === true;
|
|
4467
|
-
});
|
|
4497
|
+
}) : [];
|
|
4468
4498
|
for (const dep of reactiveDepsForBody) {
|
|
4469
4499
|
currentScope[dep] = { type: "param", reactive: false };
|
|
4470
4500
|
}
|
|
4501
|
+
if (reactiveDepsForBody.length > 0) {
|
|
4502
|
+
currentScope[reactiveScope] = false;
|
|
4503
|
+
}
|
|
4471
4504
|
const params = expr.parameters.map((param) => {
|
|
4472
4505
|
if (param.type === "restElement") {
|
|
4473
4506
|
return t.restElement(convertExpression2(param.argument));
|
|
@@ -4498,7 +4531,7 @@ function convertArrowFunction2(expr) {
|
|
|
4498
4531
|
body = null;
|
|
4499
4532
|
}
|
|
4500
4533
|
currentScope = savedScope;
|
|
4501
|
-
if (reactiveDepsForBody.length > 0 || params.length > 0) {
|
|
4534
|
+
if (reactiveDepsForBody.length > 0 || params.length > 0 && inReactiveScope) {
|
|
4502
4535
|
usedModifiers.add("liftFn");
|
|
4503
4536
|
const depParams = reactiveDepsForBody.map((id) => t.identifier(id));
|
|
4504
4537
|
const allParams = [...depParams, ...params];
|
|
@@ -4821,7 +4854,11 @@ function convertJSXChild2(child) {
|
|
|
4821
4854
|
if (!text) return null;
|
|
4822
4855
|
return t.stringLiteral(text);
|
|
4823
4856
|
} else if (child.type === "jsxExpression") {
|
|
4857
|
+
const savedScope = currentScope;
|
|
4858
|
+
currentScope = Object.create(currentScope);
|
|
4859
|
+
currentScope[reactiveScope] = false;
|
|
4824
4860
|
const innerExpr = convertExpression2(child.expression);
|
|
4861
|
+
currentScope = savedScope;
|
|
4825
4862
|
return createReactiveExpr(child.expression, innerExpr);
|
|
4826
4863
|
} else if (child.type === "jsxElement") {
|
|
4827
4864
|
return convertJSXElement2(child);
|
|
@@ -4838,6 +4875,9 @@ function convertJSXElement2(expr) {
|
|
|
4838
4875
|
const hasSpread = expr.attributes.some((attr) => attr.type === "jsxSpread");
|
|
4839
4876
|
let propsArg;
|
|
4840
4877
|
if (hasSpread) {
|
|
4878
|
+
const savedScopeSpread = currentScope;
|
|
4879
|
+
currentScope = Object.create(currentScope);
|
|
4880
|
+
currentScope[reactiveScope] = false;
|
|
4841
4881
|
const properties = [];
|
|
4842
4882
|
const oddoExprs = [];
|
|
4843
4883
|
for (const attr of expr.attributes) {
|
|
@@ -4861,6 +4901,7 @@ function convertJSXElement2(expr) {
|
|
|
4861
4901
|
properties.push(t.objectProperty(key, value));
|
|
4862
4902
|
}
|
|
4863
4903
|
}
|
|
4904
|
+
currentScope = savedScopeSpread;
|
|
4864
4905
|
const propsObj = t.objectExpression(properties);
|
|
4865
4906
|
const syntheticOddo = { type: "array", elements: oddoExprs };
|
|
4866
4907
|
propsArg = createReactiveExpr(syntheticOddo, propsObj, true);
|
|
@@ -4876,10 +4917,18 @@ function convertJSXElement2(expr) {
|
|
|
4876
4917
|
} else if (attr.value.type === "string") {
|
|
4877
4918
|
value = t.stringLiteral(attr.value.value);
|
|
4878
4919
|
} else if (attr.value.type === "expression") {
|
|
4920
|
+
const savedScopeAttr = currentScope;
|
|
4921
|
+
currentScope = Object.create(currentScope);
|
|
4922
|
+
currentScope[reactiveScope] = false;
|
|
4879
4923
|
const innerExpr = convertExpression2(attr.value.value);
|
|
4924
|
+
currentScope = savedScopeAttr;
|
|
4880
4925
|
value = createReactiveExpr(attr.value.value, innerExpr, true);
|
|
4881
4926
|
} else {
|
|
4927
|
+
const savedScopeAttr = currentScope;
|
|
4928
|
+
currentScope = Object.create(currentScope);
|
|
4929
|
+
currentScope[reactiveScope] = false;
|
|
4882
4930
|
const innerExpr = convertExpression2(attr.value);
|
|
4931
|
+
currentScope = savedScopeAttr;
|
|
4883
4932
|
value = createReactiveExpr(attr.value, innerExpr, true);
|
|
4884
4933
|
}
|
|
4885
4934
|
properties.push(t.objectProperty(key, value));
|