babel-plugin-vasille 4.3.3 → 5.0.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
@@ -1,19 +1,32 @@
1
- # Vasille
1
+ # Steel Frame
2
2
 
3
- ![Vasille.js logo](https://raw.githubusercontent.com/vasille-js/vasille-js/refs/heads/v4/doc/img/logo.png)
3
+ ![Vasille.js logo](https://raw.githubusercontent.com/vasille-js/vasille-js/refs/heads/v5/doc/img/logo.png)
4
4
 
5
- `Vasille Web` is a front-end framework, which is developed to provide bulletproof frontends.
5
+ `SteelFrameKit` is a front-end development kit, which is developed to provide fault tolerant web applications.
6
6
 
7
- [![npm](https://img.shields.io/npm/v/vasille?style=flat-square)](https://www.npmjs.com/package/vasille)
7
+ [![npm](https://img.shields.io/npm/v/steel-frame?style=flat-square)](https://www.npmjs.com/package/steel-frame)
8
+ [![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/vasille-js/steel-frame)
9
+ [![Coverage Status](https://coveralls.io/repos/github/vasille-js/steel-frame/badge.svg?branch=v5)](https://coveralls.io/github/vasille-js/steel-frame?branch=v5)
8
10
 
9
11
  ## Table of content
10
12
 
11
- * [Installation](#installation)
12
- * [How to use Vasille](#how-to-use-vasille)
13
- * [How SAFE is Vasille](#how-safe-is-vasille)
14
- * [How INTUITIVE is Vasille](#how-intuitive-is-vasille)
15
- * [How POWERFUL is Vasille](#how-powerful-is-vasille)
16
- * [Road Map](#road-map)
13
+ - [Steel Frame](#steel-frame)
14
+ - [Table of content](#table-of-content)
15
+ - [Installation](#installation)
16
+ - [How to use SteelFramekit](#how-to-use-steelframekit)
17
+ - [Full documentation:](#full-documentation)
18
+ - [Examples](#examples)
19
+ - [How SAFE is SteelFrameKit](#how-safe-is-steelframekit)
20
+ - [How INTUITIVE is SteelFrameKit](#how-intuitive-is-steelframekit)
21
+ - [How POWERFUL is SteelFrameKit](#how-powerful-is-steelframekit)
22
+ - [Road map](#road-map)
23
+ - [Change log](#change-log)
24
+ - [5.0](#50)
25
+ - [4.0 - 4.3](#40---43)
26
+ - [3.0 - 3.2](#30---32)
27
+ - [2.0 - 2.3](#20---23)
28
+ - [1.0 - 1.2](#10---12)
29
+ - [Questions](#questions)
17
30
 
18
31
 
19
32
  <hr>
@@ -21,21 +34,22 @@
21
34
  ## Installation
22
35
 
23
36
  ```
24
- npm install vasille-web --save
37
+ npm install steel-frame --save
25
38
  ```
26
39
 
27
- ## How to use Vasille
40
+ ## How to use SteelFramekit
28
41
 
29
42
  Create an app from a template
30
43
 
31
44
  ```bash
32
- $ npm create vasille
45
+ $ npm create steel-frame
33
46
  ```
34
47
 
35
48
  ### Full documentation:
36
- * [Learn `Vasille` in 5 minutes](https://github.com/vasille-js/vasille-js/blob/v4/doc/V4-API.md)
37
- * [Vasille Router Documentation](https://github.com/vasille-js/vasille-js/blob/v4/doc/Router-API.md)
38
- * [Vasille Compostion function](https://github.com/vasille-js/vasille-js/blob/v4/doc/Compositions.md)
49
+ * [Learn `SteelFrameKit` in 5 minutes](https://github.com/vasille-js/vasille-js/blob/v5/doc/V4-API.md)
50
+ * [Router Documentation](https://github.com/vasille-js/vasille-js/blob/v5/doc/Router-API.md)
51
+ * [Compostion functions](https://github.com/vasille-js/vasille-js/blob/v5/doc/Compositions.md)
52
+ * [Dependency injection](https://github.com/vasille-js/vasille-js/blob/v5/doc/Context.md)
39
53
 
40
54
  ### Examples
41
55
  * [TypeScript Example](https://github.com/vasille-js/example-typescript)
@@ -43,14 +57,14 @@ $ npm create vasille
43
57
 
44
58
  <hr>
45
59
 
46
- ## How SAFE is Vasille
60
+ ## How SAFE is SteelFrameKit
47
61
 
48
62
  The safe of your application is ensured by
49
63
  * `100%` coverage of code by unit tests.
50
64
  Each function, each branch is working as designed.
51
65
  * OOP, DRY, KISS and SOLID principles are applied.
52
66
  * `strong typing` makes your javascript/typescript code safe as C++ code.
53
- All entities of `vasille` core library are strongly typed, including:
67
+ All entities of `SteelFrameKit` core library are strongly typed, including:
54
68
  * data fields & properties.
55
69
  * computed properties (function parameters and result).
56
70
  * methods.
@@ -60,11 +74,11 @@ All entities of `vasille` core library are strongly typed, including:
60
74
  * references to children.
61
75
  * No asynchronous code, when the line of code is executed, the DOM and reactive things are already synced.
62
76
 
63
- ## How INTUITIVE is Vasille
77
+ ## How INTUITIVE is SteelFrameKit
64
78
 
65
79
  There is the "Hello World":
66
80
  ```typescript jsx
67
- import { compose, mount } from "vasille-dx";
81
+ import { compose, mount } from "steel-frame";
68
82
 
69
83
  const App = compose(() => {
70
84
  <p>Hello world</p>;
@@ -73,60 +87,76 @@ const App = compose(() => {
73
87
  mount(document.body, App, {});
74
88
  ```
75
89
 
76
- ## How POWERFUL is Vasille
90
+ ## How POWERFUL is SteelFrameKit
77
91
 
78
92
  All of these are supported:
79
93
  * Components.
80
94
  * Reactive values (observables).
81
95
  * Inline computed values.
82
96
  * Multiline computed values.
83
- * HTML & SVG tags.
97
+ * HTML tags.
84
98
  * Component custom slots.
85
99
  * 2-way data binding in components.
86
100
  * Logic block (if, else).
87
101
  * Loops (array, map, set).
102
+ * Dependency injection.
88
103
 
89
104
  <hr>
90
105
 
91
106
  ## Road map
92
107
 
93
- * [x] Update the `Vasille Core` library to version 3.0.
94
108
  * [x] `100%` Test Coverage for core Library v3.
95
- * [x] Develop the `Vasille JSX` library.
109
+ * [x] Develop the `JSX` library.
96
110
  * [x] `100%` Test Coverage for the JSX library.
97
- * [x] Develop the `Vasille Babel Plugin`.
111
+ * [x] Develop the `Babel Plugin`.
98
112
  * [x] `100%` Test Coverage fot babel plugin.
99
113
  * [x] Add CSS support (define styles in components).
100
114
  * [x] Add router.
101
115
  * [x] Add SSG (static site generation).
116
+ * [ ] Develop tools extension for debugging (WIP).
102
117
  * [ ] Add SSR (server side rendering).
103
- * [ ] Develop tools extension for debugging.
104
118
 
105
119
  ## Change log
106
120
 
107
- ### 4.3.0
121
+ We respect semantic versioning:
122
+ - Major version is increased when we make incompatible API changes.
123
+ - Minor version is increased when we add functionality.
124
+ - Patch version is increased when we fix bugs.
108
125
 
109
- Add new function `safe` which make functions safe, errors are reported automatically.
126
+ ### 5.0
110
127
 
111
- ### 4.2.0
128
+ - Add support for context and dependencies injection.
129
+ - New developement direction: `fault tolerant`.
130
+ - Renamed to `steel-frame`. **[API change]**
131
+ - Removed `forward` and `backward` functions. **[API change]**
132
+ - Removed `Debug` component. **[API change]**
112
133
 
113
- Add support for inlined conditions in JSX, binary `&&` and ternary `?:` operator.
134
+ ### 4.0 - 4.3
114
135
 
115
- ### 4.1.0
136
+ - Initial version of the framework with file based routing and building scripts (`web dev` and `web build spa`).
137
+ - Reactive values naming switched to `$` prefix. **[API change]**
138
+ - `4.1` Added SSG (static site generation) as build option `web build static`.
139
+ - `4.2` Add support for inlined conditions in JSX, binary `&&` and ternary `?:` operator.
140
+ - `4.3` Add new function `safe` which make functions safe, errors are reported automatically.
116
141
 
117
- Added SSG (static site generation) as build option `vasille-web build static`.
142
+ ### 3.0 - 3.2
118
143
 
119
- ### 4.0.0
144
+ - Switch to a babel plugin to compile components code. **[API change]**
145
+ - 100% of code has been covered with unit tests.
146
+ - New developement direction: `keep it simple`.
120
147
 
121
- Initial version of the framework with file based routing and building scripts (`vasille-web dev` and `vasille-web build spa`).
148
+ ### 2.0 - 2.3
149
+
150
+ - Introduces components compilation via a typescript plugin. **[API change]**
151
+ - New developement direction: `write less, do more`.
152
+
153
+ ### 1.0 - 1.2
154
+
155
+ - Initial version of core library.
156
+ - Developemnt direction: `performance-first`.
122
157
 
123
158
  ## Questions
124
159
 
125
160
  If you have questions, feel free to contact the maintainer of the project:
126
161
 
127
162
  * [Author's Email](mailto:vas.lixcode@gmail.com)
128
- * [Author's Telegram](https://t.me/lixcode)
129
-
130
- <hr>
131
-
132
- **Made in Moldova** 🇲🇩
package/lib/call.js CHANGED
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.hintFunctions = exports.styleOnly = exports.composeOnly = exports.boundaryFunctions = exports.modelFunctions = exports.bindFunctions = exports.reactivityFunctions = exports.composeFunctions = void 0;
36
+ exports.hintFunctions = exports.dependencyInjections = exports.styleOnly = exports.composeOnly = exports.modelFunctions = exports.bindFunctions = exports.asyncFunctions = exports.refFunctions = exports.composeFunctions = void 0;
37
37
  exports.calls = calls;
38
38
  const t = __importStar(require("@babel/types"));
39
39
  exports.composeFunctions = [
@@ -47,10 +47,10 @@ exports.composeFunctions = [
47
47
  "prompt",
48
48
  "screen",
49
49
  ];
50
- exports.reactivityFunctions = ["ref", "awaited"];
50
+ exports.refFunctions = ["ref"];
51
+ exports.asyncFunctions = ["awaited"];
51
52
  exports.bindFunctions = ["watch", "calculate", "bind"];
52
53
  exports.modelFunctions = ["arrayModel", "mapModel", "setModel"];
53
- exports.boundaryFunctions = ["forward", "backward"];
54
54
  exports.composeOnly = ["router", "beforeMount", "afterMount", "beforeDestroy"];
55
55
  exports.styleOnly = [
56
56
  "theme",
@@ -62,14 +62,17 @@ exports.styleOnly = [
62
62
  "prefersLight",
63
63
  "styleSheet",
64
64
  ];
65
+ exports.dependencyInjections = ["share", "receive", "impute"];
65
66
  exports.hintFunctions = [
66
- ...exports.reactivityFunctions,
67
+ ...exports.refFunctions,
68
+ ...exports.asyncFunctions,
67
69
  ...exports.composeFunctions,
68
70
  ...exports.bindFunctions,
69
71
  ...exports.modelFunctions,
70
72
  ...exports.composeOnly,
71
73
  ...exports.styleOnly,
72
- ...exports.boundaryFunctions,
74
+ ...exports.dependencyInjections,
75
+ "raw",
73
76
  ];
74
77
  function checkCall(name, internal) {
75
78
  if (name === "store" || name === "model") {
package/lib/expression.js CHANGED
@@ -33,64 +33,55 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.encodeName = encodeName;
37
36
  exports.idIsIValue = idIsIValue;
38
37
  exports.memberIsIValue = memberIsIValue;
38
+ exports.memberIsIValueInExpr = memberIsIValueInExpr;
39
39
  exports.exprIsSure = exprIsSure;
40
40
  exports.checkNode = checkNode;
41
41
  exports.checkOrIgnoreAllExpressions = checkOrIgnoreAllExpressions;
42
42
  exports.checkAllExpressions = checkAllExpressions;
43
43
  exports.checkAllUnknown = checkAllUnknown;
44
44
  exports.checkOrIgnoreExpression = checkOrIgnoreExpression;
45
- exports.assignToSetCall = assignToSetCall;
46
45
  exports.checkExpression = checkExpression;
47
46
  exports.checkStatements = checkStatements;
48
47
  exports.checkStatement = checkStatement;
49
48
  exports.checkFunction = checkFunction;
50
49
  const t = __importStar(require("@babel/types"));
51
50
  const call_js_1 = require("./call.js");
51
+ const internal_js_1 = require("./internal.js");
52
52
  const lib_1 = require("./lib");
53
53
  const mesh_1 = require("./mesh");
54
54
  const router_1 = require("./router");
55
55
  const utils_1 = require("./utils");
56
- function encodeName(name) {
57
- return insertName(name);
58
- }
59
56
  function insertName(name, search) {
60
- const id = t.identifier(`Vasille_${name}`);
57
+ const id = t.identifier(name);
61
58
  search?.inserted.add(id);
62
59
  return id;
63
60
  }
64
- function addIdentifier(path, search) {
65
- const name = unprefixedName(path.node.name);
66
- if (!search.found.has(name)) {
67
- search.found.set(name, path.node);
68
- }
69
- path.replaceWith(insertName(name, search));
70
- }
71
- function unprefixedName(name) {
72
- return name[0] === "$" ? name.slice(1) : name;
73
- }
74
- function extractMemberName(path, search) {
75
- const names = [];
76
- let it = path.node;
77
- while (t.isMemberExpression(it)) {
78
- names.push((0, utils_1.stringify)(it.property));
79
- it = it.object;
61
+ function addExpression(path, search) {
62
+ const name = path
63
+ .getSource()
64
+ .trim()
65
+ .replace(/\s*\n\s*/g, "");
66
+ const found = search.found.get(name);
67
+ if (path.isMemberExpression()) {
68
+ let it = path.node;
69
+ while (t.isMemberExpression(it) || t.isIdentifier(it)) {
70
+ const name = (0, utils_1.stringify)(t.isMemberExpression(it) ? it.property : it);
71
+ if (it !== path.node && name.startsWith("$")) {
72
+ (0, lib_1.err)(lib_1.Errors.RulesOfVasille, path, "The reactive/observable value is nested", search.external, null);
73
+ }
74
+ it = t.isMemberExpression(it) ? it.object : null;
75
+ }
80
76
  }
81
- names.push((0, utils_1.stringify)(it));
82
- if (names.filter(name => name.startsWith("$")).length > 1) {
83
- (0, lib_1.err)(lib_1.Errors.RulesOfVasille, path, "The reactive/observable value is nested", search.external, null);
77
+ if (!found) {
78
+ const paramName = insertName(`Vasille_${search.found.size}`, search);
79
+ search.found.set(name, { node: path.node, paramName: paramName });
80
+ path.replaceWith(paramName);
84
81
  }
85
- return names.reverse().map(unprefixedName).join("_");
86
- }
87
- function addMemberExpr(path, search) {
88
- const name = extractMemberName(path, search);
89
- /* istanbul ignore else */
90
- if (!search.found.has(name)) {
91
- search.found.set(name, path.node);
82
+ else {
83
+ path.replaceWith(found.paramName);
92
84
  }
93
- path.replaceWith(insertName(name, search));
94
85
  }
95
86
  function meshIdentifier(path) {
96
87
  if (idIsIValue(path)) {
@@ -105,10 +96,25 @@ function memberIsIValue(node) {
105
96
  return ((t.isIdentifier(node.property) && node.property.name.startsWith("$")) ||
106
97
  (t.isStringLiteral(node.property) && node.property.value.startsWith("$")));
107
98
  }
99
+ function memberIsIValueInExpr(path, search) {
100
+ const node = path.node;
101
+ const isIValue = memberIsIValue(node);
102
+ if (isIValue) {
103
+ let it = node;
104
+ while (t.isMemberExpression(it) || t.isOptionalMemberExpression(it)) {
105
+ it = it.object;
106
+ }
107
+ if (t.isIdentifier(it) && search.stack.get(it.name, true)) {
108
+ (0, lib_1.err)(lib_1.Errors.RulesOfVasille, path, "This value looks like a reactive but is not. Move code to standalone function or wrap value in raw call.", search.external);
109
+ }
110
+ }
111
+ return isIValue;
112
+ }
108
113
  function exprIsSure(path, internal) {
109
- if (path.isMemberExpression() &&
114
+ if ((path.isMemberExpression() &&
110
115
  path.node.computed &&
111
- (!t.isStringLiteral(path.node.property) || /^\d+$/.test(path.node.property.value))) {
116
+ (!t.isStringLiteral(path.node.property) || /^\d+$/.test(path.node.property.value))) ||
117
+ path.isOptionalMemberExpression()) {
112
118
  return false;
113
119
  }
114
120
  if (!path.isMemberExpression() || !(0, utils_1.stringify)(path.node.property).startsWith("$")) {
@@ -153,7 +159,7 @@ function meshLValue(path, internal) {
153
159
  meshLValue(path.get("argument"), internal);
154
160
  }
155
161
  }
156
- function checkNode(path, internal) {
162
+ function checkNode(path, internal, area, name) {
157
163
  const search = {
158
164
  external: internal,
159
165
  found: new Map(),
@@ -166,19 +172,21 @@ function checkNode(path, internal) {
166
172
  search.self = path.node;
167
173
  }
168
174
  }
169
- if (path.isMemberExpression()) {
175
+ if (path.isMemberExpression() || path.isOptionalMemberExpression()) {
170
176
  if (memberIsIValue(path.node)) {
171
177
  search.self = path.node;
172
178
  }
173
179
  }
174
180
  if (path.isExpression() && (0, call_js_1.calls)(path, ["ref"], internal)) {
181
+ const refValue = path.node.arguments[0];
175
182
  (0, mesh_1.meshAllUnknown)(path.get("arguments"), internal);
183
+ path.replaceWith((0, lib_1.ref)(refValue, internal, area, name));
176
184
  search.self = path.node;
177
185
  }
178
186
  if (search.self) {
179
187
  return search;
180
188
  }
181
- internal.stack.push();
189
+ internal.stack.push(true);
182
190
  /* istanbul ignore else */
183
191
  if (path.isExpression()) {
184
192
  checkExpression(path, search);
@@ -216,12 +224,6 @@ function checkOrIgnoreExpression(path, search) {
216
224
  checkExpression(path, search);
217
225
  }
218
226
  }
219
- function assignToSetCall(path, internal, left, right) {
220
- const property = left.property;
221
- path.replaceWith(internal.set(left.object, !left.computed && t.isIdentifier(property) ? t.stringLiteral(property.name) : property, path.node.operator === "="
222
- ? right
223
- : t.binaryExpression(path.node.operator.slice(0, path.node.operator.length - 1), internal.extract(left), right)));
224
- }
225
227
  function checkExpression(nodePath, search) {
226
228
  const expr = nodePath.node;
227
229
  switch (expr && expr.type) {
@@ -240,7 +242,7 @@ function checkExpression(nodePath, search) {
240
242
  /* istanbul ignore else */
241
243
  if (expr && nodePath.isIdentifier()) {
242
244
  if (idIsIValue(nodePath)) {
243
- addIdentifier(nodePath, search);
245
+ addExpression(nodePath, search);
244
246
  }
245
247
  }
246
248
  break;
@@ -260,6 +262,16 @@ function checkExpression(nodePath, search) {
260
262
  (0, lib_1.err)(lib_1.Errors.IncompatibleContext, path, "The router is not available in stores", search.external, null);
261
263
  }
262
264
  }
265
+ else if ((0, call_js_1.calls)(path, ["raw"], search.external) &&
266
+ path.node.arguments.length === 1 &&
267
+ t.isExpression(path.node.arguments[0])) {
268
+ (0, mesh_1.meshExpression)(path.get("arguments")[0], search.external);
269
+ path.replaceWith(path.node.arguments[0]);
270
+ }
271
+ else if (!search.external.stateOnly && (0, call_js_1.calls)(path, call_js_1.dependencyInjections, search.external)) {
272
+ (0, mesh_1.meshAllUnknown)(path.get("arguments"), search.external);
273
+ path.node.arguments.unshift(internal_js_1.ctx);
274
+ }
263
275
  else {
264
276
  if ((0, call_js_1.calls)(path, call_js_1.hintFunctions, search.external)) {
265
277
  (0, lib_1.err)(lib_1.Errors.IncompatibleContext, path, "Usage of hints is restricted here", search.external, null);
@@ -285,7 +297,7 @@ function checkExpression(nodePath, search) {
285
297
  checkExpression(right, search);
286
298
  /* istanbul ignore else */
287
299
  if (!t.isPrivateName(property)) {
288
- assignToSetCall(path, search.external, left.node, right.node);
300
+ path.replaceWith(search.external.set(left.node.object, !left.node.computed && t.isIdentifier(property) ? t.stringLiteral(property.name) : property, right.node, path.node));
289
301
  }
290
302
  }
291
303
  else {
@@ -297,9 +309,8 @@ function checkExpression(nodePath, search) {
297
309
  case "MemberExpression":
298
310
  case "OptionalMemberExpression": {
299
311
  const path = nodePath;
300
- const node = path.node;
301
- if (memberIsIValue(node)) {
302
- addMemberExpr(path, search);
312
+ if (memberIsIValueInExpr(path, search)) {
313
+ addExpression(path, search);
303
314
  }
304
315
  else {
305
316
  checkExpression(path.get("object"), search);
package/lib/index.js CHANGED
@@ -8,7 +8,7 @@ function default_1() {
8
8
  visitor: {
9
9
  Program(path, params) {
10
10
  (0, transformer_js_1.transformProgram)(path, params.file.opts.filename, {
11
- devMode: params.opts.devMode !== false,
11
+ devLayer: params.opts.devLayer === true,
12
12
  strictFolders: params.opts.strictFolders !== false,
13
13
  replaceWeb: typeof params.opts.replaceWeb === "string" ? params.opts.replaceWeb : undefined,
14
14
  headTag: !!params.opts.headTag,
package/lib/internal.js CHANGED
@@ -33,21 +33,25 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.ctx = exports.StackedStates = void 0;
36
+ exports.inspector = exports.runner = exports.ctx = exports.StackedStates = void 0;
37
37
  const t = __importStar(require("@babel/types"));
38
38
  class StackedStates {
39
39
  maps = [];
40
+ checkingIndex = 0;
40
41
  constructor() {
41
42
  this.push();
42
43
  }
43
- push() {
44
+ push(startChecking) {
45
+ if (startChecking) {
46
+ this.checkingIndex = this.maps.length;
47
+ }
44
48
  this.maps.push(new Map());
45
49
  }
46
50
  pop() {
47
51
  this.maps.pop();
48
52
  }
49
- get(name) {
50
- for (let i = this.maps.length - 1; i >= 0; i--) {
53
+ get(name, checkingContextOnly) {
54
+ for (let i = this.maps.length - 1; i >= (checkingContextOnly ? this.checkingIndex : 0); i--) {
51
55
  if (this.maps[i].has(name)) {
52
56
  return this.maps[i].get(name);
53
57
  }
@@ -60,3 +64,5 @@ class StackedStates {
60
64
  }
61
65
  exports.StackedStates = StackedStates;
62
66
  exports.ctx = t.identifier("Vasille");
67
+ exports.runner = t.memberExpression(exports.ctx, t.identifier("runner"));
68
+ exports.inspector = t.memberExpression(exports.runner, t.identifier("inspector"));