babel-plugin-vasille 4.2.5 → 4.3.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/README.md CHANGED
@@ -104,6 +104,10 @@ All of these are supported:
104
104
 
105
105
  ## Change log
106
106
 
107
+ ### 4.3.0
108
+
109
+ Add new function `safe` which make functions safe, errors are reported automatically.
110
+
107
111
  ### 4.2.0
108
112
 
109
113
  Add support for inlined conditions in JSX, binary `&&` and ternary `?:` operator.
package/lib/mesh.js CHANGED
@@ -874,6 +874,7 @@ function composeExpression(path, internal) {
874
874
  switch (expr && expr.type) {
875
875
  case "CallExpression":
876
876
  case "OptionalCallExpression": {
877
+ /* istanbul ignore else */
877
878
  if ((0, call_js_1.calls)(path, ["watch"], internal)) {
878
879
  (0, lib_js_1.parseCalculateCall)(path, internal);
879
880
  const args = path.node.arguments;
@@ -887,16 +888,8 @@ function composeExpression(path, internal) {
887
888
  else if ((0, call_js_1.calls)(path, ["beforeMount", "afterMount"], internal)) {
888
889
  const arg = path.get("arguments")[0];
889
890
  if (arg && (arg.isFunctionExpression() || arg.isArrowFunctionExpression())) {
890
- const body = arg.isFunctionExpression() ? arg.get("body") : arg.get("body");
891
- /* istanbul ignore else */
892
- if (body.isBlockStatement()) {
893
- composeStatements(body.get("body"), internal);
894
- path.replaceWith(t.callExpression(arg.node, []));
895
- }
896
- else if (body.isExpression()) {
897
- composeExpression(body, internal);
898
- path.replaceWith(body);
899
- }
891
+ meshFunction(arg, internal);
892
+ path.replaceWith(t.callExpression(internal.safe(arg.node), []));
900
893
  }
901
894
  else {
902
895
  (0, lib_js_1.err)(lib_js_1.Errors.IncorrectArguments, path, "Incorrect hint argument", internal);
@@ -908,9 +901,6 @@ function composeExpression(path, internal) {
908
901
  }
909
902
  path.get("callee").replaceWith(t.memberExpression(internal_js_1.ctx, t.identifier("runOnDestroy")));
910
903
  }
911
- else {
912
- meshExpression(path, internal);
913
- }
914
904
  break;
915
905
  }
916
906
  case "JSXElement":
@@ -1050,13 +1040,12 @@ function composeStatement(path, internal) {
1050
1040
  (0, lib_js_1.checkNonReactiveName)(idPath, internal);
1051
1041
  }
1052
1042
  // const s = new Set(), const m = new Map()
1053
- else if (initPath.isNewExpression() && t.isIdentifier(initPath.node.callee)) {
1054
- const name = initPath.node.callee.name;
1055
- if (name === "Map" || name === "Set") {
1056
- (0, lib_js_1.processModelCall)(initPath, name, kind === "const", internal, idName());
1057
- meshInit = false;
1058
- (0, lib_js_1.checkNonReactiveName)(idPath, internal);
1059
- }
1043
+ else if (initPath.isNewExpression() &&
1044
+ t.isIdentifier(initPath.node.callee) &&
1045
+ ["Set", "Map"].includes(initPath.node.callee.name)) {
1046
+ (0, lib_js_1.processModelCall)(initPath, initPath.node.callee.name, kind === "const", internal, idName());
1047
+ meshInit = false;
1048
+ (0, lib_js_1.checkNonReactiveName)(idPath, internal);
1060
1049
  }
1061
1050
  else if (kind === "let") {
1062
1051
  meshExpression(declaration.get("init"), internal);
@@ -145,6 +145,7 @@ function transformProgram(path, filename, opts) {
145
145
  match: "VasilleMatch",
146
146
  set: "VasilleSet",
147
147
  Switch: "VasilleSwitch",
148
+ safe: "VasilleSafe",
148
149
  };
149
150
  function call(key, args) {
150
151
  used.add(key);
@@ -177,6 +178,7 @@ function transformProgram(path, filename, opts) {
177
178
  match: (name, arg) => call("match", arg ? [name, arg] : [name]),
178
179
  set: (obj, field, value) => call("set", [obj, field, value]),
179
180
  Switch: arg => call("Switch", [arg, internal_js_1.ctx]),
181
+ safe: (arg) => call("safe", [arg]),
180
182
  };
181
183
  function getCtx() {
182
184
  if (internal.isComposing)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "babel-plugin-vasille",
3
- "version": "4.2.5",
3
+ "version": "4.3.1",
4
4
  "description": "Convert Vasille Meta Language code to pure JavaScript",
5
5
  "main": "lib/index.js",
6
6
  "type": "commonjs",
@@ -47,8 +47,8 @@
47
47
  "prettier": "^3.6.2",
48
48
  "ts-jest": "^29.4.1",
49
49
  "typescript": "^5.9.2",
50
- "vasille": "^4.0.0",
51
- "vasille-css": "^4.0.0",
52
- "vasille-web": "^4.0.0"
50
+ "vasille": "^4.3.1",
51
+ "vasille-css": "^4.1.0",
52
+ "vasille-web": "^4.3.1"
53
53
  }
54
54
  }