babel-plugin-vasille 0.99.1 → 0.99.2

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
@@ -47,7 +47,7 @@ $ npx degit vasille-js/example-javascript my-project
47
47
 
48
48
  ### Examples
49
49
  * [TypeScript Example](https://github.com/vasille-js/example-typescript)
50
- * [JavaScript Example](https://github.com/vas[README.md](..%2Ftest%2Fmy-app%2FREADME.md)ille-js/example-javascript)
50
+ * [JavaScript Example](https://github.com/vasille-js/example-javascript)
51
51
 
52
52
  <hr>
53
53
 
package/lib/call.js CHANGED
@@ -1,6 +1,33 @@
1
- import * as t from "@babel/types";
2
- import { ctx } from "./internal.js";
3
- export const composeOnly = [
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 (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.requiresContext = exports.composeOnly = void 0;
27
+ exports.calls = calls;
28
+ const t = __importStar(require("@babel/types"));
29
+ const internal_1 = require("./internal");
30
+ exports.composeOnly = [
4
31
  "forward",
5
32
  "watch",
6
33
  "ref",
@@ -11,9 +38,9 @@ export const composeOnly = [
11
38
  "setModel",
12
39
  "reactiveObject",
13
40
  ];
14
- export const requiresContext = ["awaited", "forward"];
15
- const requiresContextSet = new Set(requiresContext);
16
- export function calls(node, names, internal) {
41
+ exports.requiresContext = ["awaited", "forward"];
42
+ const requiresContextSet = new Set(exports.requiresContext);
43
+ function calls(node, names, internal) {
17
44
  const set = new Set(names);
18
45
  const callee = t.isCallExpression(node) ? node.callee : null;
19
46
  if (callee) {
@@ -21,7 +48,7 @@ export function calls(node, names, internal) {
21
48
  const mapped = internal.mapping.get(callee.name);
22
49
  if (mapped && set.has(mapped) && internal.stack.get(callee.name) === undefined) {
23
50
  if (requiresContextSet.has(callee.name) && t.isCallExpression(node)) {
24
- node.arguments.unshift(ctx);
51
+ node.arguments.unshift(internal_1.ctx);
25
52
  }
26
53
  return mapped;
27
54
  }
@@ -41,7 +68,7 @@ export function calls(node, names, internal) {
41
68
  if (t.isMemberExpression(callee) && t.isIdentifier(callee.object) && propName) {
42
69
  if (callee.object.name === internal.global && set.has(propName)) {
43
70
  if (requiresContextSet.has(callee.object.name) && t.isCallExpression(node)) {
44
- node.arguments.unshift(ctx);
71
+ node.arguments.unshift(internal_1.ctx);
45
72
  }
46
73
  return callee.object.name;
47
74
  }
package/lib/expression.js CHANGED
@@ -1,6 +1,41 @@
1
- import * as t from "@babel/types";
2
- import { StackedStates } from "./internal.js";
3
- export function encodeName(name) {
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 (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.encodeName = encodeName;
27
+ exports.checkNode = checkNode;
28
+ exports.checkOrIgnoreAllExpressions = checkOrIgnoreAllExpressions;
29
+ exports.checkAllExpressions = checkAllExpressions;
30
+ exports.checkAllUnknown = checkAllUnknown;
31
+ exports.chekOrIgnoreExpression = chekOrIgnoreExpression;
32
+ exports.checkExpression = checkExpression;
33
+ exports.checkStatements = checkStatements;
34
+ exports.checkStatement = checkStatement;
35
+ exports.checkFunction = checkFunction;
36
+ const t = __importStar(require("@babel/types"));
37
+ const internal_1 = require("./internal");
38
+ function encodeName(name) {
4
39
  return t.identifier(`Vasille_${name}`);
5
40
  }
6
41
  function addIdentifier(path, search) {
@@ -84,12 +119,12 @@ function meshLValue(path, internal) {
84
119
  });
85
120
  }
86
121
  }
87
- export function checkNode(path, internal) {
122
+ function checkNode(path, internal) {
88
123
  const search = {
89
124
  external: internal,
90
125
  found: new Map(),
91
126
  self: null,
92
- stack: new StackedStates(),
127
+ stack: new internal_1.StackedStates(),
93
128
  };
94
129
  if (t.isIdentifier(path.node)) {
95
130
  const state = internal.stack.get(path.node.name);
@@ -114,19 +149,19 @@ export function checkNode(path, internal) {
114
149
  }
115
150
  return search;
116
151
  }
117
- export function checkOrIgnoreAllExpressions(nodePaths, search) {
152
+ function checkOrIgnoreAllExpressions(nodePaths, search) {
118
153
  for (const path of nodePaths) {
119
154
  if (t.isExpression(path.node)) {
120
155
  checkExpression(path, search);
121
156
  }
122
157
  }
123
158
  }
124
- export function checkAllExpressions(nodePaths, search) {
159
+ function checkAllExpressions(nodePaths, search) {
125
160
  for (const path of nodePaths) {
126
161
  checkExpression(path, search);
127
162
  }
128
163
  }
129
- export function checkAllUnknown(paths, internal) {
164
+ function checkAllUnknown(paths, internal) {
130
165
  for (const path of paths) {
131
166
  if (t.isSpreadElement(path.node)) {
132
167
  checkExpression(path.get("argument"), internal);
@@ -136,12 +171,12 @@ export function checkAllUnknown(paths, internal) {
136
171
  }
137
172
  }
138
173
  }
139
- export function chekOrIgnoreExpression(path, search) {
174
+ function chekOrIgnoreExpression(path, search) {
140
175
  if (t.isExpression(path.node)) {
141
176
  checkExpression(path, search);
142
177
  }
143
178
  }
144
- export function checkExpression(nodePath, search) {
179
+ function checkExpression(nodePath, search) {
145
180
  const expr = nodePath.node;
146
181
  if (!expr) {
147
182
  return;
@@ -342,7 +377,7 @@ export function checkExpression(nodePath, search) {
342
377
  }
343
378
  }
344
379
  }
345
- export function checkStatements(paths, search) {
380
+ function checkStatements(paths, search) {
346
381
  for (const path of paths) {
347
382
  checkStatement(path, search);
348
383
  }
@@ -377,7 +412,7 @@ function ignoreLocals(val, search) {
377
412
  }
378
413
  }
379
414
  }
380
- export function checkStatement(path, search) {
415
+ function checkStatement(path, search) {
381
416
  const statement = path.node;
382
417
  if (!statement) {
383
418
  return;
@@ -505,7 +540,7 @@ export function checkStatement(path, search) {
505
540
  }
506
541
  }
507
542
  }
508
- export function checkFunction(path, search) {
543
+ function checkFunction(path, search) {
509
544
  const node = path.node;
510
545
  if (t.isExpression(node.body)) {
511
546
  checkExpression(path.get("body"), search);
package/lib/index.js CHANGED
@@ -1,10 +1,13 @@
1
- import { trProgram } from "./transformer.js";
2
- export default function () {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = default_1;
4
+ const transformer_1 = require("./transformer");
5
+ function default_1() {
3
6
  return {
4
7
  name: "Vasille",
5
8
  visitor: {
6
9
  Program(path, params) {
7
- trProgram(path, params.devMode !== false);
10
+ (0, transformer_1.trProgram)(path, params.opts.devMode !== false);
8
11
  },
9
12
  },
10
13
  };
package/lib/internal.js CHANGED
@@ -1,5 +1,31 @@
1
- import * as t from "@babel/types";
2
- export class StackedStates {
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 (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.ctx = exports.StackedStates = void 0;
27
+ const t = __importStar(require("@babel/types"));
28
+ class StackedStates {
3
29
  constructor() {
4
30
  this.maps = [];
5
31
  this.push();
@@ -22,4 +48,5 @@ export class StackedStates {
22
48
  this.maps[this.maps.length - 1].set(name, state);
23
49
  }
24
50
  }
25
- export const ctx = t.identifier("Vasille");
51
+ exports.StackedStates = StackedStates;
52
+ exports.ctx = t.identifier("Vasille");
package/lib/jsx-detect.js CHANGED
@@ -1,5 +1,33 @@
1
- import * as t from "@babel/types";
2
- export function exprHasJsx(node) {
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 (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.exprHasJsx = exprHasJsx;
27
+ exports.statementHasJsx = statementHasJsx;
28
+ exports.bodyHasJsx = bodyHasJsx;
29
+ const t = __importStar(require("@babel/types"));
30
+ function exprHasJsx(node) {
3
31
  if (t.isBinaryExpression(node)) {
4
32
  return (t.isExpression(node.left) && exprHasJsx(node.left)) || exprHasJsx(node.right);
5
33
  }
@@ -20,7 +48,7 @@ export function exprHasJsx(node) {
20
48
  }
21
49
  return t.isJSXElement(node) || t.isJSXFragment(node);
22
50
  }
23
- export function statementHasJsx(statement) {
51
+ function statementHasJsx(statement) {
24
52
  if (t.isExpressionStatement(statement)) {
25
53
  return exprHasJsx(statement.expression);
26
54
  }
@@ -52,7 +80,7 @@ export function statementHasJsx(statement) {
52
80
  }
53
81
  return false;
54
82
  }
55
- export function bodyHasJsx(node) {
83
+ function bodyHasJsx(node) {
56
84
  if (t.isExpression(node)) {
57
85
  return exprHasJsx(node);
58
86
  }
package/lib/jsx.js CHANGED
@@ -1,15 +1,42 @@
1
- import * as t from "@babel/types";
2
- import { ctx } from "./internal.js";
3
- import { exprCall } from "./lib.js";
4
- import { compose, meshExpression } from "./mesh.js";
5
- import { bodyHasJsx } from "./jsx-detect.js";
6
- export function transformJsx(path, internal) {
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 (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.transformJsx = transformJsx;
27
+ exports.transformJsxArray = transformJsxArray;
28
+ const t = __importStar(require("@babel/types"));
29
+ const internal_1 = require("./internal");
30
+ const lib_1 = require("./lib");
31
+ const mesh_1 = require("./mesh");
32
+ const jsx_detect_1 = require("./jsx-detect");
33
+ function transformJsx(path, internal) {
7
34
  if (t.isJSXElement(path.node)) {
8
35
  return [transformJsxElement(path, internal)];
9
36
  }
10
37
  return transformJsxArray(path.get("children"), internal);
11
38
  }
12
- export function transformJsxArray(paths, internal) {
39
+ function transformJsxArray(paths, internal) {
13
40
  const result = [];
14
41
  for (const path of paths) {
15
42
  if (t.isJSXElement(path.node) || t.isJSXFragment(path.node)) {
@@ -21,12 +48,31 @@ export function transformJsxArray(paths, internal) {
21
48
  .replace(/\n\s+$/m, "")
22
49
  .replace(/^\s*\n\s+/m, "")
23
50
  .replace(/\s*\n\s*/gm, "\n");
24
- result.push(t.expressionStatement(t.callExpression(t.memberExpression(ctx, t.identifier("text")), [t.stringLiteral(fixed)])));
51
+ const call = t.callExpression(t.memberExpression(internal_1.ctx, t.identifier("text")), [t.stringLiteral(fixed)]);
52
+ call.loc = path.node.loc;
53
+ if (call.loc) {
54
+ for (const char of path.node.value) {
55
+ if (!/\s/.test(char)) {
56
+ break;
57
+ }
58
+ if (char === "\n") {
59
+ call.loc.start.column = 0;
60
+ call.loc.start.line++;
61
+ }
62
+ else {
63
+ call.loc.start.column++;
64
+ }
65
+ call.loc.start.index++;
66
+ }
67
+ }
68
+ result.push(t.expressionStatement(call));
25
69
  }
26
70
  }
27
71
  else if (t.isJSXExpressionContainer(path.node)) {
28
72
  const value = transformJsxExpressionContainer(path, internal, false, false);
29
- result.push(t.expressionStatement(t.callExpression(t.memberExpression(ctx, t.identifier("text")), [value])));
73
+ const call = t.callExpression(t.memberExpression(internal_1.ctx, t.identifier("text")), [value]);
74
+ call.loc = value.loc;
75
+ result.push(t.expressionStatement(call));
30
76
  }
31
77
  else {
32
78
  throw path.buildCodeFrameError("Vasille: Spread child is not supported");
@@ -38,40 +84,51 @@ function transformJsxExpressionContainer(path, internal, acceptSlots, isInternal
38
84
  if (!t.isExpression(path.node.expression)) {
39
85
  return t.booleanLiteral(true);
40
86
  }
87
+ const loc = path.node.expression.loc;
41
88
  if (acceptSlots &&
42
89
  (t.isFunctionExpression(path.node.expression) || t.isArrowFunctionExpression(path.node.expression)) &&
43
- bodyHasJsx(path.node.expression.body)) {
44
- compose(path.get("expression"), internal, isInternalSlot);
90
+ (0, jsx_detect_1.bodyHasJsx)(path.node.expression.body)) {
91
+ (0, mesh_1.compose)(path.get("expression"), internal, isInternalSlot);
45
92
  if (!isInternalSlot) {
46
93
  if (path.node.expression.params.length < 1) {
47
94
  path.node.expression.params.push(t.identifier(internal.prefix));
48
95
  }
49
- path.node.expression.params.push(ctx);
96
+ path.node.expression.params.push(internal_1.ctx);
50
97
  }
51
98
  else {
52
- path.node.expression.params.unshift(ctx);
99
+ path.node.expression.params.unshift(internal_1.ctx);
53
100
  }
101
+ path.node.expression.loc = loc;
54
102
  return path.node.expression;
55
103
  }
56
104
  else if (isInternalSlot &&
57
105
  (t.isFunctionExpression(path.node.expression) || t.isArrowFunctionExpression(path.node.expression))) {
58
- path.node.expression.params.unshift(ctx);
106
+ path.node.expression.params.unshift(internal_1.ctx);
59
107
  }
60
- let call = exprCall(path.get("expression"), path.node.expression, internal);
108
+ let call = (0, lib_1.exprCall)(path.get("expression"), path.node.expression, internal);
61
109
  if (!call &&
62
110
  t.isIdentifier(path.node.expression) &&
63
111
  internal.stack.get(path.node.expression.name) === 3 /* VariableState.ReactiveObject */) {
64
112
  call = t.callExpression(t.memberExpression(internal.id, t.identifier("rop")), [path.node.expression]);
65
113
  }
66
- return call !== null && call !== void 0 ? call : path.node.expression;
114
+ const result = call !== null && call !== void 0 ? call : path.node.expression;
115
+ result.loc = loc;
116
+ return result;
67
117
  }
68
- function id(str) {
118
+ function idToProp(id, value, from) {
119
+ let str = t.isIdentifier(id) || t.isJSXIdentifier(id) ? id.name : id.value;
120
+ let expr;
121
+ if (from) {
122
+ str = str.substring(from);
123
+ }
69
124
  if (/^[\w_]+$/.test(str)) {
70
- return t.identifier(str);
125
+ expr = t.identifier(str);
71
126
  }
72
127
  else {
73
- return t.stringLiteral(str);
128
+ expr = t.stringLiteral(str);
74
129
  }
130
+ expr.loc = id.loc;
131
+ return t.objectProperty(expr, value);
75
132
  }
76
133
  function transformJsxElement(path, internal) {
77
134
  var _a, _b;
@@ -95,9 +152,9 @@ function transformJsxElement(path, internal) {
95
152
  if (t.isJSXExpressionContainer(attr.value) && t.isExpression(attr.value.expression)) {
96
153
  const path = attrPath.get("value");
97
154
  if (t.isExpression(path.node.expression)) {
98
- meshExpression(path.get("expression"), internal);
155
+ (0, mesh_1.meshExpression)(path.get("expression"), internal);
99
156
  }
100
- events.push(t.objectProperty(id(name.name.substring(2)), path.node.expression));
157
+ events.push(idToProp(name, path.node.expression, 2));
101
158
  }
102
159
  else {
103
160
  throw attrPath
@@ -115,8 +172,8 @@ function transformJsxElement(path, internal) {
115
172
  if (t.isExpression(item)) {
116
173
  // class={[cond && "string"]}
117
174
  if (t.isLogicalExpression(item) && item.operator === "&&" && t.isStringLiteral(item.right)) {
118
- const call = exprCall(elementPath.get("left"), item.left, internal);
119
- classObject.push(t.objectProperty(id(item.right.value), call !== null && call !== void 0 ? call : item.left));
175
+ const call = (0, lib_1.exprCall)(elementPath.get("left"), item.left, internal);
176
+ classObject.push(idToProp(item.right, call !== null && call !== void 0 ? call : item.left));
120
177
  }
121
178
  // class={[{..}]}
122
179
  else if (t.isObjectExpression(item)) {
@@ -124,9 +181,9 @@ function transformJsxElement(path, internal) {
124
181
  // class={[{a: b}]}
125
182
  if (t.isObjectProperty(propPath.node)) {
126
183
  const prop = propPath;
127
- const value = (_a = exprCall(prop.get("value"), prop.node.value, internal)) !== null && _a !== void 0 ? _a : prop.node.value;
184
+ const value = (_a = (0, lib_1.exprCall)(prop.get("value"), prop.node.value, internal)) !== null && _a !== void 0 ? _a : prop.node.value;
128
185
  if (t.isExpression(prop.node.key) && !t.isIdentifier(prop.node.key)) {
129
- meshExpression(prop.get("key"), internal);
186
+ (0, mesh_1.meshExpression)(prop.get("key"), internal);
130
187
  }
131
188
  classObject.push(t.objectProperty(prop.node.key, value));
132
189
  }
@@ -142,11 +199,11 @@ function transformJsxElement(path, internal) {
142
199
  }
143
200
  // class={[".."]}
144
201
  else if (t.isStringLiteral(elementPath.node)) {
145
- classStatic.push(elementPath.node.value);
202
+ classStatic.push(elementPath.node);
146
203
  }
147
204
  // class={[..]}
148
205
  else {
149
- const call = exprCall(elementPath, item, internal);
206
+ const call = (0, lib_1.exprCall)(elementPath, item, internal);
150
207
  classElements.push(call !== null && call !== void 0 ? call : item);
151
208
  }
152
209
  }
@@ -164,7 +221,7 @@ function transformJsxElement(path, internal) {
164
221
  else if (t.isJSXExpressionContainer(attr.value) && t.isTemplateLiteral(attr.value.expression)) {
165
222
  const jsxAttrPath = attrPath;
166
223
  const jsxContainerPath = jsxAttrPath.get("value");
167
- const value = exprCall(jsxContainerPath.get("expression"), attr.value.expression, internal);
224
+ const value = (0, lib_1.exprCall)(jsxContainerPath.get("expression"), attr.value.expression, internal);
168
225
  attrs.push(t.objectProperty(t.identifier("class"), value !== null && value !== void 0 ? value : attr.value.expression));
169
226
  if (value) {
170
227
  console.warn(attrPath.buildCodeFrameError("Vasille: This will slow down your application"));
@@ -172,10 +229,7 @@ function transformJsxElement(path, internal) {
172
229
  }
173
230
  // class="a b"
174
231
  else if (t.isStringLiteral(attr.value)) {
175
- const splitted = attr.value.value.split(" ");
176
- for (const item of splitted) {
177
- classStatic.push(item);
178
- }
232
+ classStatic.push(attr.value);
179
233
  }
180
234
  // class=<div/>
181
235
  else {
@@ -191,9 +245,9 @@ function transformJsxElement(path, internal) {
191
245
  // style={{a: b}}
192
246
  if (t.isObjectProperty(propPath.node)) {
193
247
  const prop = propPath;
194
- const value = (_b = exprCall(prop.get("value"), prop.node.value, internal)) !== null && _b !== void 0 ? _b : prop.node.value;
248
+ const value = (_b = (0, lib_1.exprCall)(prop.get("value"), prop.node.value, internal)) !== null && _b !== void 0 ? _b : prop.node.value;
195
249
  if (t.isExpression(prop.node.key) && !t.isIdentifier(prop.node.key)) {
196
- meshExpression(prop.get("key"), internal);
250
+ (0, mesh_1.meshExpression)(prop.get("key"), internal);
197
251
  }
198
252
  // style={{a: "b"}} -> static in compile time
199
253
  if (t.isIdentifier(prop.node.key) && t.isStringLiteral(prop.node.value)) {
@@ -240,7 +294,7 @@ function transformJsxElement(path, internal) {
240
294
  const jsxAttrPath = attrPath;
241
295
  const jsxContainerPath = jsxAttrPath.get("value");
242
296
  const literalPath = jsxContainerPath.get("expression");
243
- const value = exprCall(literalPath, attr.value.expression, internal);
297
+ const value = (0, lib_1.exprCall)(literalPath, attr.value.expression, internal);
244
298
  attrs.push(t.objectProperty(t.identifier("style"), value !== null && value !== void 0 ? value : attr.value.expression));
245
299
  if (value) {
246
300
  console.warn(attrPath.buildCodeFrameError("Vasille: This will slow down your application"));
@@ -253,10 +307,10 @@ function transformJsxElement(path, internal) {
253
307
  }
254
308
  else {
255
309
  if (t.isJSXExpressionContainer(attr.value)) {
256
- attrs.push(t.objectProperty(id(name.name), t.isExpression(attr.value.expression) ? attr.value.expression : t.booleanLiteral(true)));
310
+ attrs.push(idToProp(name, t.isExpression(attr.value.expression) ? attr.value.expression : t.booleanLiteral(true)));
257
311
  }
258
312
  else if (t.isStringLiteral(attr.value)) {
259
- attrs.push(t.objectProperty(id(name.name), attr.value));
313
+ attrs.push(idToProp(name, attr.value));
260
314
  }
261
315
  else {
262
316
  throw attrPath.buildCodeFrameError("Vasille: Value of bind must be an expression or string");
@@ -267,12 +321,12 @@ function transformJsxElement(path, internal) {
267
321
  if (name.namespace.name === "bind") {
268
322
  if (t.isJSXExpressionContainer(attr.value)) {
269
323
  const value = t.isExpression(attr.value.expression)
270
- ? exprCall(attrPath.get("value"), attr.value.expression, internal)
324
+ ? (0, lib_1.exprCall)(attrPath.get("value"), attr.value.expression, internal)
271
325
  : undefined;
272
- bind.push(t.objectProperty(id(name.name.name), value !== null && value !== void 0 ? value : (t.isExpression(attr.value.expression) ? attr.value.expression : t.booleanLiteral(true))));
326
+ bind.push(idToProp(name.name, value !== null && value !== void 0 ? value : (t.isExpression(attr.value.expression) ? attr.value.expression : t.booleanLiteral(true))));
273
327
  }
274
328
  else if (t.isStringLiteral(attr.value)) {
275
- bind.push(t.objectProperty(id(name.name.name), attr.value));
329
+ bind.push(idToProp(name.name, attr.value));
276
330
  }
277
331
  else {
278
332
  throw attrPath.buildCodeFrameError("Vasille: Value of bind must be an expression or string");
@@ -288,13 +342,16 @@ function transformJsxElement(path, internal) {
288
342
  }
289
343
  }
290
344
  if (classStatic.length > 0) {
291
- attrs.push(t.objectProperty(t.identifier("class"), t.stringLiteral(classStatic.join(" "))));
345
+ const first = classStatic[0];
346
+ const value = classStatic.length === 1 ? classStatic[0] : t.stringLiteral(classStatic.map(item => item.value).join(" "));
347
+ value.loc = first.loc;
348
+ attrs.push(t.objectProperty(t.identifier("class"), value));
292
349
  }
293
350
  if (styleStatic.length > 0) {
294
351
  attrs.push(t.objectProperty(t.identifier("style"), t.stringLiteral(styleStatic.map(([id, value]) => `${id.name}:${value.value}`).join(";"))));
295
352
  }
296
353
  const statements = transformJsxArray(path.get("children"), internal);
297
- return t.expressionStatement(t.callExpression(t.memberExpression(ctx, t.identifier("tag")), [
354
+ const call = t.callExpression(t.memberExpression(internal_1.ctx, t.identifier("tag")), [
298
355
  t.stringLiteral(name.name),
299
356
  t.objectExpression([
300
357
  ...(attrs.length > 0 ? [t.objectProperty(t.identifier("attr"), t.objectExpression(attrs))] : []),
@@ -310,27 +367,33 @@ function transformJsxElement(path, internal) {
310
367
  : []),
311
368
  ...(styleObject.length > 0 ? [t.objectProperty(t.identifier("style"), t.objectExpression(styleObject))] : []),
312
369
  ]),
313
- ...(statements.length > 0 ? [t.arrowFunctionExpression([ctx], t.blockStatement(statements))] : []),
314
- ]));
370
+ ...(statements.length > 0 ? [t.arrowFunctionExpression([internal_1.ctx], t.blockStatement(statements))] : []),
371
+ ]);
372
+ call.loc = path.node.loc;
373
+ return t.expressionStatement(call);
315
374
  }
316
375
  if (t.isJSXIdentifier(name)) {
317
376
  const element = path.node;
318
377
  const opening = path.get("openingElement");
319
378
  const props = [];
320
379
  let run;
380
+ const mapped = internal.mapping.get(name.name);
381
+ if (mapped === "Debug" && internal.stack.get(name.name) === undefined && !internal.devMode) {
382
+ return t.emptyStatement();
383
+ }
321
384
  for (const attrPath of opening.get("attributes")) {
322
385
  const attr = attrPath.node;
323
386
  // <A prop=../>
324
387
  if (t.isJSXAttribute(attr) && t.isJSXIdentifier(attr.name)) {
325
388
  // <A prop=".."/>
326
389
  if (t.isStringLiteral(attr.value)) {
327
- props.push(t.objectProperty(id(attr.name.name), attr.value));
390
+ props.push(idToProp(attr.name, attr.value));
328
391
  }
329
392
  // <A prop={..}/>
330
393
  else if (t.isJSXExpressionContainer(attr.value)) {
331
394
  const isSystem = internal.mapping.has(name.name);
332
395
  const value = transformJsxExpressionContainer(attrPath.get("value"), internal, !isSystem || attr.name.name === "slot", isSystem && attr.name.name === "slot");
333
- props.push(t.objectProperty(id(attr.name.name), value));
396
+ props.push(idToProp(attr.name, value));
334
397
  }
335
398
  else {
336
399
  throw attrPath.buildCodeFrameError("Vasille: JSX Elements/Fragments are not supported here");
@@ -350,15 +413,17 @@ function transformJsxElement(path, internal) {
350
413
  (t.isFunctionExpression(element.children[0].expression) ||
351
414
  t.isArrowFunctionExpression(element.children[0].expression))) {
352
415
  run = element.children[0].expression;
353
- run.params.push(ctx);
416
+ run.params.push(internal_1.ctx);
354
417
  }
355
418
  else {
356
419
  const statements = transformJsxArray(path.get("children"), internal);
357
420
  if (statements.length > 0) {
358
- run = t.arrowFunctionExpression([ctx], t.blockStatement(statements));
421
+ run = t.arrowFunctionExpression([internal_1.ctx], t.blockStatement(statements));
359
422
  }
360
423
  }
361
- return t.expressionStatement(t.callExpression(t.identifier(name.name), [ctx, t.objectExpression(props), ...(run ? [run] : [])]));
424
+ const call = t.callExpression(t.identifier(name.name), [internal_1.ctx, t.objectExpression(props), ...(run ? [run] : [])]);
425
+ call.loc = path.node.loc;
426
+ return t.expressionStatement(call);
362
427
  }
363
428
  throw path.buildCodeFrameError("Vasille: Unsupported tag detected, html lowercase tagnames and components are accepted");
364
429
  }