babel-plugin-vasille 3.2.1 → 4.0.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.
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkOrder = checkOrder;
4
+ const call_1 = require("./call");
5
+ const lib_1 = require("./lib");
6
+ const componentOrder = [
7
+ { nodeType: ["VariableDeclaration"] },
8
+ { calls: ["watch"] },
9
+ { nodeType: ["FunctionDeclaration"] },
10
+ { calls: ["beforeMount"] },
11
+ { nodeType: ["JSXElement", "JSXFragment"] },
12
+ { calls: ["afterMount"] },
13
+ { calls: ["beforeDestroy"] },
14
+ { nodeType: ["ReturnStatement"] },
15
+ ];
16
+ function matchStatement(path, target, internal) {
17
+ const testPath = path.isExpressionStatement() ? path.get("expression") : path;
18
+ if (target.nodeType && testPath.node) {
19
+ return target.nodeType.includes(testPath.node.type);
20
+ }
21
+ if (target.calls && testPath.isExpression()) {
22
+ return (0, call_1.calls)(testPath, target.calls, internal);
23
+ }
24
+ return false;
25
+ }
26
+ function checkOrder(paths, internal) {
27
+ let index = 0;
28
+ for (const path of paths) {
29
+ while (index < componentOrder.length && !matchStatement(path, componentOrder[index], internal)) {
30
+ index++;
31
+ }
32
+ if (index === componentOrder.length) {
33
+ (0, lib_1.err)(lib_1.Errors.RulesOfVasille, path, [
34
+ "Malformed component detected, required component structure is:",
35
+ "1. Variable declarations.",
36
+ "2. Watchers/effects (calls of `watch` function).",
37
+ "3. Function declarations.",
38
+ "4. Before mount hint (call of `beforeMount` function)",
39
+ "5. JSX elements and fragments",
40
+ "6. After mount hint (call of `afterMount` function)",
41
+ "7. Before destroy hint (call of `beforeDestroy` function)",
42
+ "8. Return statement",
43
+ "All steps are optional, but the order is strict.",
44
+ "Unlisted statements are not accepted.",
45
+ ].join("\n"), internal);
46
+ }
47
+ }
48
+ }
@@ -33,23 +33,14 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.trProgram = trProgram;
36
+ exports.transformProgram = transformProgram;
37
37
  const t = __importStar(require("@babel/types"));
38
38
  const internal_js_1 = require("./internal.js");
39
39
  const mesh_js_1 = require("./mesh.js");
40
40
  const css_transformer_js_1 = require("./css-transformer.js");
41
41
  const imports = new Map([["vasille-web", "VasilleWeb"]]);
42
42
  const ignoreMembers = new Set([
43
- "value",
44
- "ref",
45
- "bind",
46
- "calculate",
47
- "watch",
48
- "forward",
49
- "arrayModel",
50
- "mapModel",
51
- "reactiveObject",
52
- "setModel",
43
+ "raw",
53
44
  "theme",
54
45
  "dark",
55
46
  "mobile",
@@ -59,92 +50,141 @@ const ignoreMembers = new Set([
59
50
  "prefersLight",
60
51
  "bridge",
61
52
  "router",
62
- "runOnDestroy",
53
+ "beforeMount",
54
+ "afterMount",
55
+ "beforeDestroy",
56
+ "If",
57
+ "ElseIf",
58
+ "Else",
63
59
  ]);
64
60
  function extractText(node) {
65
61
  // no case found for string literal
66
62
  return node.name;
67
63
  }
68
- function trProgram(path, devMode) {
69
- let id;
70
- let stylesConnected = false;
64
+ // Handles import declarations and updates internal state
65
+ function handleImportDeclaration(statementPath, internal, ids, used, stylesConnected) {
66
+ const statement = statementPath.node;
67
+ const name = imports.get(statement.source.value);
68
+ if (!name)
69
+ return;
70
+ internal.prefix = name;
71
+ for (const specifier of statement.specifiers) {
72
+ /* istanbul ignore else */
73
+ if (t.isImportNamespaceSpecifier(specifier)) {
74
+ internal.global = specifier.local.name;
75
+ stylesConnected.value = true;
76
+ }
77
+ else if (t.isImportSpecifier(specifier)) {
78
+ const imported = extractText(specifier.imported);
79
+ const local = specifier.local.name;
80
+ if (imported === "bind" || imported === "calculate" || imported === "watch") {
81
+ ids.expr = local;
82
+ }
83
+ if (imported in ids) {
84
+ ids[imported] = local;
85
+ }
86
+ internal.mapping.set(local, imported);
87
+ if (imported === "styleSheet") {
88
+ stylesConnected.value = true;
89
+ }
90
+ internal.importStatement = statementPath;
91
+ }
92
+ }
93
+ statement.specifiers = statement.specifiers.filter(spec => {
94
+ if (!t.isImportSpecifier(spec))
95
+ return true;
96
+ return !(ignoreMembers.has(extractText(spec.imported)) ||
97
+ (!internal.devMode && extractText(spec.imported) === "Debug"));
98
+ });
99
+ }
100
+ // Handles mesh and style transformation
101
+ function handleStatement(statementPath, internal, stylesConnected) {
102
+ if (!stylesConnected || !(0, css_transformer_js_1.findStyleInNode)(statementPath, internal)) {
103
+ (0, mesh_js_1.meshStatement)(statementPath, internal);
104
+ }
105
+ }
106
+ // Handles import insertion and cleanup
107
+ function updateImports(path, internal, ids, used) {
108
+ if (used.size > 0 && !internal.importStatement && !internal.global) {
109
+ path.get("body")[0].insertBefore(t.importDeclaration([...used].map(name => t.importSpecifier(t.identifier(ids[name]), t.identifier(name))), t.stringLiteral("vasille-web")));
110
+ }
111
+ if (used.size > 0 && !internal.global && internal.importStatement) {
112
+ const statementPath = internal.importStatement;
113
+ const statement = statementPath.node;
114
+ const specifiers = statement.specifiers.filter(item => {
115
+ /* istanbul ignore else */
116
+ if (t.isImportSpecifier(item) && t.isIdentifier(item.local)) {
117
+ return statementPath.scope.bindings[item.local.name].referenced;
118
+ }
119
+ });
120
+ for (const name of used) {
121
+ if (!specifiers.find(specifier => t.isImportSpecifier(specifier) && [name, ids[name]].includes(extractText(specifier.imported)))) {
122
+ specifiers.push(t.importSpecifier(t.identifier(ids[name]), t.identifier(name)));
123
+ }
124
+ }
125
+ statement.specifiers = specifiers;
126
+ }
127
+ }
128
+ // Main transformer function
129
+ function transformProgram(path, filename, opts) {
130
+ const stylesConnected = { value: false };
131
+ const used = new Set();
132
+ const ids = {
133
+ ref: "VasilleRef",
134
+ expr: "VasilleExpr",
135
+ forward: "VasilleForward",
136
+ backward: "VasilleBackward",
137
+ setModel: "VasilleSetModel",
138
+ mapModel: "VasilleMapModel",
139
+ arrayModel: "VasilleArrayModel",
140
+ ensure: "VasilleEnsure",
141
+ match: "VasilleMatch",
142
+ set: "VasilleSet",
143
+ Switch: "VasilleSwitch",
144
+ };
145
+ function call(key, args) {
146
+ used.add(key);
147
+ if (internal.global) {
148
+ return t.callExpression(t.memberExpression(t.identifier(internal.global), t.identifier(key)), args);
149
+ }
150
+ return t.callExpression(t.identifier(ids[key]), args);
151
+ }
71
152
  const internal = {
72
- get id() {
73
- this.internalUsed = true;
74
- return id;
75
- },
76
- set id(expr) {
77
- id = expr;
78
- },
79
153
  stack: new internal_js_1.StackedStates(),
80
154
  mapping: new Map(),
81
155
  global: "",
82
156
  prefix: "Vasille_",
83
157
  importStatement: null,
84
- internalUsed: false,
85
158
  stateOnly: false,
86
- devMode: devMode,
159
+ filename,
160
+ devMode: opts.devMode,
161
+ strictFolders: opts.strictFolders,
162
+ ref: arg => call("ref", arg ? [arg] : []),
163
+ expr: (func, values) => call("expr", [getCtx(), func, values]),
164
+ forward: arg => call("forward", [getCtx(), arg]),
165
+ setModel: arg => call("setModel", arg ? [getCtx(), arg] : [getCtx()]),
166
+ mapModel: arg => call("mapModel", arg ? [getCtx(), arg] : [getCtx()]),
167
+ arrayModel: arg => call("arrayModel", arg ? [getCtx(), arg] : [getCtx()]),
168
+ ensure: arg => call("ensure", [arg]),
169
+ match: (name, arg) => call("match", arg ? [name, arg] : [name]),
170
+ set: (obj, field, value) => call("set", [obj, field, value]),
171
+ Switch: arg => call("Switch", [arg, internal_js_1.ctx]),
87
172
  };
173
+ function getCtx() {
174
+ if (internal.isComposing)
175
+ return internal_js_1.ctx;
176
+ return t.nullLiteral();
177
+ }
88
178
  for (const statementPath of path.get("body")) {
89
179
  const statement = statementPath.node;
90
180
  if (t.isImportDeclaration(statement)) {
91
- const name = imports.get(statement.source.value);
92
- if (name) {
93
- internal.prefix = name;
94
- for (const specifier of statement.specifiers) {
95
- /* istanbul ignore else */
96
- if (t.isImportNamespaceSpecifier(specifier)) {
97
- internal.global = specifier.local.name;
98
- /* istanbul ignore else */
99
- if (statement.source.value === "vasille-web") {
100
- stylesConnected = true;
101
- }
102
- internal.id = t.memberExpression(t.identifier(internal.global), t.identifier("$"));
103
- }
104
- else if (t.isImportSpecifier(specifier)) {
105
- const imported = extractText(specifier.imported);
106
- const local = specifier.local.name;
107
- internal.mapping.set(local, imported);
108
- if (imported === "styleSheet") {
109
- stylesConnected = true;
110
- }
111
- if (!id) {
112
- internal.id = t.identifier(name);
113
- }
114
- internal.importStatement = statementPath;
115
- }
116
- }
117
- statement.specifiers = statement.specifiers.filter(spec => {
118
- if (!t.isImportSpecifier(spec)) {
119
- return true;
120
- }
121
- else {
122
- return !(ignoreMembers.has(extractText(spec.imported)) ||
123
- (!internal.devMode && extractText(spec.imported) === "Debug"));
124
- }
125
- });
126
- }
181
+ handleImportDeclaration(statementPath, internal, ids, used, stylesConnected);
127
182
  }
128
183
  else {
129
- if (!id) {
130
- return;
131
- }
132
- else if (!stylesConnected || !(0, css_transformer_js_1.findStyleInNode)(statementPath, internal)) {
133
- (0, mesh_js_1.meshStatement)(statementPath, internal);
134
- }
184
+ handleStatement(statementPath, internal, stylesConnected.value);
135
185
  }
136
186
  }
137
- if (internal.internalUsed && !internal.global && internal.importStatement) {
138
- const statementPath = internal.importStatement;
139
- const statement = statementPath.node;
140
- statementPath.replaceWith(t.importDeclaration([
141
- ...statement.specifiers.filter(item => {
142
- /* istanbul ignore else */
143
- if (t.isImportSpecifier(item) && t.isIdentifier(item.local)) {
144
- return statementPath.scope.bindings[item.local.name].referenced;
145
- }
146
- }),
147
- t.importSpecifier(internal.id, t.identifier("$")),
148
- ], statement.source));
149
- }
187
+ updateImports(path, internal, ids, used);
188
+ if (internal.firstError)
189
+ throw internal.firstError;
150
190
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "babel-plugin-vasille",
3
- "version": "3.2.1",
3
+ "version": "4.0.0",
4
4
  "description": "Convert Vasille Meta Language code to pure JavaScript",
5
5
  "main": "lib/index.js",
6
6
  "type": "commonjs",
@@ -12,9 +12,8 @@
12
12
  },
13
13
  "scripts": {
14
14
  "prepack": "cp -f ../README.md ./README.md",
15
- "prettier": "prettier src test/**/*.ts* --write",
15
+ "prettier": "prettier src test/**/*.ts* test/*.ts --write",
16
16
  "build": "tsc --build tsconfig-build.json",
17
- "build-node": "tsc --build tsconfig-build-node.json",
18
17
  "tsc-tests": "tsc --build test/tsconfig.json",
19
18
  "test": "jest",
20
19
  "test-coverage": "jest --coverage"
@@ -40,7 +39,7 @@
40
39
  "@types/babel__core": "^7.20.5",
41
40
  "@types/jest": "^30.0.0",
42
41
  "@types/jsdom": "^21.1.7",
43
- "@types/node": "^24.1.0",
42
+ "@types/node": "^24.2.1",
44
43
  "cross-env": "^10.0.0",
45
44
  "jest": "^30.0.5",
46
45
  "jsdom": "^26.1.0",
@@ -48,8 +47,8 @@
48
47
  "prettier": "^3.6.2",
49
48
  "ts-jest": "^29.4.1",
50
49
  "typescript": "^5.9.2",
51
- "vasille": "^3.2.1",
52
- "vasille-css": "^3.2.1",
53
- "vasille-web": "^3.2.1"
50
+ "vasille": "^4.0.0",
51
+ "vasille-css": "^4.0.0",
52
+ "vasille-web": "^4.0.0"
54
53
  }
55
54
  }
package/lib/bridge.js DELETED
@@ -1,173 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.processBridgeCall = processBridgeCall;
37
- const t = __importStar(require("@babel/types"));
38
- const expression_1 = require("./expression");
39
- const lib_1 = require("./lib");
40
- const mesh_1 = require("./mesh");
41
- const utils_1 = require("./utils");
42
- const bridgeConstName = "bridge";
43
- function processBridgeCall(path, internal, search) {
44
- const node = path.node;
45
- if (t.isCallExpression(node) && t.isMemberExpression(node.callee)) {
46
- const callee = node.callee;
47
- let propName = null;
48
- if (t.isIdentifier(callee.object)) {
49
- const mapped = internal.mapping.get(callee.object.name);
50
- if (mapped && mapped === bridgeConstName && internal.stack.get(callee.object.name) === undefined) {
51
- propName = (0, utils_1.stringify)(callee.property);
52
- }
53
- }
54
- if (t.isMemberExpression(callee.object) && t.isIdentifier(callee.object.object)) {
55
- const rootName = callee.object.object.name;
56
- if (rootName === internal.global &&
57
- internal.stack.get(rootName) === undefined &&
58
- (0, utils_1.stringify)(callee.object.property) === bridgeConstName) {
59
- propName = (0, utils_1.stringify)(callee.property);
60
- }
61
- }
62
- if (propName) {
63
- const getArg = (mesh = true) => {
64
- if (node.arguments.length !== 1 || !t.isExpression(node.arguments[0])) {
65
- throw path.buildCodeFrameError("Vasille: Expected 1 argument");
66
- }
67
- if (mesh) {
68
- (0, mesh_1.meshExpression)(path.get("arguments")[0], internal);
69
- }
70
- return node.arguments[0];
71
- };
72
- const callWithArg = (name) => {
73
- path.replaceWith(t.callExpression(t.memberExpression(internal.id, t.identifier(name)), [getArg()]));
74
- };
75
- const callWithOptionalArg = (name) => {
76
- if (node.arguments.length === 0) {
77
- path.replaceWith(t.callExpression(t.memberExpression(internal.id, t.identifier(name)), []));
78
- }
79
- else {
80
- callWithArg(name);
81
- }
82
- };
83
- switch (propName) {
84
- case "ref": {
85
- callWithArg("r");
86
- break;
87
- }
88
- case "bind": {
89
- const arg = getArg(false);
90
- const result = (0, expression_1.checkNode)(path.get("arguments")[0], internal);
91
- if (result.self) {
92
- path.replaceWith(result.self);
93
- }
94
- else if (result.found.size > 0) {
95
- const found = result.found;
96
- path.replaceWith(t.callExpression(t.memberExpression(internal.id, t.identifier("ex")), [
97
- t.arrowFunctionExpression([...found.keys()].map(expression_1.encodeName), arg),
98
- t.arrayExpression([...found.values()]),
99
- ]));
100
- }
101
- else {
102
- callWithArg("r");
103
- }
104
- break;
105
- }
106
- case "calculate":
107
- case "watch": {
108
- const args = (0, lib_1.processCalculateCall)(path, internal);
109
- path.replaceWith(t.callExpression(t.memberExpression(internal.id, t.identifier("ex")), args));
110
- break;
111
- }
112
- case "arrayModel": {
113
- callWithOptionalArg("sam");
114
- break;
115
- }
116
- case "setModel": {
117
- callWithOptionalArg("ssm");
118
- break;
119
- }
120
- case "mapModel": {
121
- callWithOptionalArg("smm");
122
- break;
123
- }
124
- case "reactiveObject": {
125
- callWithArg("sro");
126
- break;
127
- }
128
- case "value": {
129
- if (!search) {
130
- path.replaceWith(t.memberExpression(getArg(), t.identifier("$")));
131
- }
132
- else {
133
- path.replaceWith(getArg());
134
- }
135
- break;
136
- }
137
- case "setValue": {
138
- if (node.arguments.length !== 2 || !t.isExpression(node.arguments[0]) || !t.isExpression(node.arguments[1])) {
139
- throw path.buildCodeFrameError("Vasille: Expected 2 arguments");
140
- }
141
- (0, mesh_1.meshExpression)(path.get("arguments")[0], internal);
142
- if (search) {
143
- (0, expression_1.checkExpression)(path.get("arguments")[1], search);
144
- }
145
- else {
146
- (0, mesh_1.meshExpression)(path.get("arguments")[1], internal);
147
- }
148
- path.replaceWith(t.assignmentExpression("=", t.memberExpression(node.arguments[0], t.identifier("$")), node.arguments[1]));
149
- break;
150
- }
151
- case "stored": {
152
- const arg = getArg(false);
153
- if ((t.isIdentifier(arg) && (0, expression_1.idIsIValue)(path.get("arguments")[0], internal)) ||
154
- (t.isMemberExpression(arg) && (0, expression_1.memberIsIValue)(arg, internal))) {
155
- path.replaceWith(t.memberExpression(arg, t.identifier("$")));
156
- }
157
- else {
158
- callWithArg("rv");
159
- }
160
- break;
161
- }
162
- case "destroy": {
163
- path.replaceWith(t.callExpression(t.memberExpression(getArg(true), t.identifier("destroy")), []));
164
- break;
165
- }
166
- default:
167
- throw path.buildCodeFrameError(`Vasille: Unknown bridge method "${propName}"`);
168
- }
169
- return propName;
170
- }
171
- }
172
- return false;
173
- }
@@ -1,173 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.processBridgeCall = processBridgeCall;
37
- const t = __importStar(require("@babel/types"));
38
- const expression_1 = require("./expression");
39
- const lib_1 = require("./lib");
40
- const mesh_1 = require("./mesh");
41
- const utils_1 = require("./utils");
42
- const bridgeConstName = "bridge";
43
- function processBridgeCall(path, internal, search) {
44
- const node = path.node;
45
- if (t.isCallExpression(node) && t.isMemberExpression(node.callee)) {
46
- const callee = node.callee;
47
- let propName = null;
48
- if (t.isIdentifier(callee.object)) {
49
- const mapped = internal.mapping.get(callee.object.name);
50
- if (mapped && mapped === bridgeConstName && internal.stack.get(callee.object.name) === undefined) {
51
- propName = (0, utils_1.stringify)(callee.property);
52
- }
53
- }
54
- if (t.isMemberExpression(callee.object) && t.isIdentifier(callee.object.object)) {
55
- const rootName = callee.object.object.name;
56
- if (rootName === internal.global &&
57
- internal.stack.get(rootName) === undefined &&
58
- (0, utils_1.stringify)(callee.object.property) === bridgeConstName) {
59
- propName = (0, utils_1.stringify)(callee.property);
60
- }
61
- }
62
- if (propName) {
63
- const getArg = (mesh = true) => {
64
- if (node.arguments.length !== 1 || !t.isExpression(node.arguments[0])) {
65
- throw path.buildCodeFrameError("Vasille: Expected 1 argument");
66
- }
67
- if (mesh) {
68
- (0, mesh_1.meshExpression)(path.get("arguments")[0], internal);
69
- }
70
- return node.arguments[0];
71
- };
72
- const callWithArg = (name) => {
73
- path.replaceWith(t.callExpression(t.memberExpression(internal.id, t.identifier(name)), [getArg()]));
74
- };
75
- const callWithOptionalArg = (name) => {
76
- if (node.arguments.length === 0) {
77
- path.replaceWith(t.callExpression(t.memberExpression(internal.id, t.identifier(name)), []));
78
- }
79
- else {
80
- callWithArg(name);
81
- }
82
- };
83
- switch (propName) {
84
- case "ref": {
85
- callWithArg("r");
86
- break;
87
- }
88
- case "bind": {
89
- const arg = getArg(false);
90
- const result = (0, expression_1.checkNode)(path.get("arguments")[0], internal);
91
- if (result.self) {
92
- path.replaceWith(result.self);
93
- }
94
- else if (result.found.size > 0) {
95
- const found = result.found;
96
- path.replaceWith(t.callExpression(t.memberExpression(internal.id, t.identifier("ex")), [
97
- t.arrowFunctionExpression([...found.keys()].map(expression_1.encodeName), arg),
98
- t.arrayExpression([...found.values()]),
99
- ]));
100
- }
101
- else {
102
- callWithArg("r");
103
- }
104
- break;
105
- }
106
- case "calculate":
107
- case "watch": {
108
- const args = (0, lib_1.processCalculateCall)(path, internal);
109
- path.replaceWith(t.callExpression(t.memberExpression(internal.id, t.identifier("ex")), args));
110
- break;
111
- }
112
- case "arrayModel": {
113
- callWithOptionalArg("sam");
114
- break;
115
- }
116
- case "setModel": {
117
- callWithOptionalArg("ssm");
118
- break;
119
- }
120
- case "mapModel": {
121
- callWithOptionalArg("smm");
122
- break;
123
- }
124
- case "reactiveObject": {
125
- callWithArg("sro");
126
- break;
127
- }
128
- case "value": {
129
- if (!search) {
130
- path.replaceWith(t.memberExpression(getArg(), t.identifier("$")));
131
- }
132
- else {
133
- path.replaceWith(getArg());
134
- }
135
- break;
136
- }
137
- case "setValue": {
138
- if (node.arguments.length !== 2 || !t.isExpression(node.arguments[0]) || !t.isExpression(node.arguments[1])) {
139
- throw path.buildCodeFrameError("Vasille: Expected 2 arguments");
140
- }
141
- (0, mesh_1.meshExpression)(path.get("arguments")[0], internal);
142
- if (search) {
143
- (0, expression_1.checkExpression)(path.get("arguments")[1], search);
144
- }
145
- else {
146
- (0, mesh_1.meshExpression)(path.get("arguments")[1], internal);
147
- }
148
- path.replaceWith(t.assignmentExpression("=", t.memberExpression(node.arguments[0], t.identifier("$")), node.arguments[1]));
149
- break;
150
- }
151
- case "stored": {
152
- const arg = getArg(false);
153
- if ((t.isIdentifier(arg) && (0, expression_1.idIsIValue)(path.get("arguments")[0], internal)) ||
154
- (t.isMemberExpression(arg) && (0, expression_1.memberIsIValue)(arg, internal))) {
155
- path.replaceWith(t.memberExpression(arg, t.identifier("$")));
156
- }
157
- else {
158
- callWithArg("rv");
159
- }
160
- break;
161
- }
162
- case "destroy": {
163
- path.replaceWith(t.callExpression(t.memberExpression(getArg(true), t.identifier("destroy")), []));
164
- break;
165
- }
166
- default:
167
- throw path.buildCodeFrameError(`Vasille: Unknown bridge method "${propName}"`);
168
- }
169
- return propName;
170
- }
171
- }
172
- return false;
173
- }