babel-plugin-vasille 0.99.1 → 0.99.3

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/lib-node/mesh.js CHANGED
@@ -41,11 +41,11 @@ exports.composeStatements = composeStatements;
41
41
  exports.composeStatement = composeStatement;
42
42
  exports.compose = compose;
43
43
  const t = __importStar(require("@babel/types"));
44
- const call_js_1 = require("./call.js");
45
- const internal_js_1 = require("./internal.js");
46
- const jsx_detect_js_1 = require("./jsx-detect.js");
47
- const lib_js_1 = require("./lib.js");
48
- const jsx_js_1 = require("./jsx.js");
44
+ const call_1 = require("./call");
45
+ const internal_1 = require("./internal");
46
+ const jsx_detect_1 = require("./jsx-detect");
47
+ const lib_1 = require("./lib");
48
+ const jsx_1 = require("./jsx");
49
49
  function meshOrIgnoreAllExpressions(nodePaths, internal) {
50
50
  for (const path of nodePaths) {
51
51
  if (t.isExpression(path.node)) {
@@ -65,7 +65,7 @@ function meshComposeCall(call, name, nodePath, internal) {
65
65
  }
66
66
  const fnPath = nodePath.get("arguments")[0];
67
67
  compose(fnPath, internal, false);
68
- arg.params.unshift(internal_js_1.ctx);
68
+ arg.params.unshift(internal_1.ctx);
69
69
  if (t.isArrowFunctionExpression(arg) && internal.devMode) {
70
70
  fnPath.replaceWith(t.functionExpression(t.identifier(internal.prefix + (name ? name.name : "Default")), arg.params, t.isBlockStatement(arg.body) ? arg.body : t.blockStatement([t.returnStatement(arg.body)]), false, arg.async));
71
71
  }
@@ -104,7 +104,7 @@ function meshExpression(nodePath, internal) {
104
104
  if (!expr) {
105
105
  return;
106
106
  }
107
- if ((0, call_js_1.calls)(expr, ["compose", "extend"], internal)) {
107
+ if ((0, call_1.calls)(expr, ["compose", "extend"], internal)) {
108
108
  meshComposeCall(expr, null, nodePath, internal);
109
109
  return;
110
110
  }
@@ -139,15 +139,24 @@ function meshExpression(nodePath, internal) {
139
139
  meshAllUnknown(path.get("elements"), internal);
140
140
  break;
141
141
  }
142
- case "CallExpression": {
142
+ case "CallExpression":
143
+ case "OptionalCallExpression": {
143
144
  const path = nodePath;
144
- const callsFn = (0, call_js_1.calls)(path.node, call_js_1.composeOnly, internal);
145
+ const callsFn = (0, call_1.calls)(path.node, call_1.composeOnly, internal);
146
+ const callsStyleHint = (0, call_1.calls)(path.node, call_1.styleOnly, internal);
147
+ const callsStyleCreate = (0, call_1.calls)(path.node, ["webStyleSheet"], internal);
145
148
  if (callsFn) {
146
- throw path.buildCodeFrameError(`Vasille: Usage of function "${callsFn}" is restricted here`);
149
+ throw path.buildCodeFrameError(`Vasille: Usage of hint "${callsFn}" is restricted here`);
150
+ }
151
+ if (callsStyleHint) {
152
+ throw path.buildCodeFrameError(`Vasille: Usage of style hint "${callsStyleHint}" is restricted here`);
153
+ }
154
+ if (callsStyleCreate) {
155
+ throw path.buildCodeFrameError("Vasille: Styles can be created in moldule level code only");
147
156
  }
148
157
  meshOrIgnoreExpression(path.get("callee"), internal);
149
158
  meshAllUnknown(path.get("arguments"), internal);
150
- if ((0, call_js_1.calls)(path.node, ["calculate"], internal)) {
159
+ if ((0, call_1.calls)(path.node, ["calculate"], internal)) {
151
160
  if (path.node.arguments.length !== 1 && !t.isExpression(path.node.arguments[0])) {
152
161
  throw path.buildCodeFrameError("Vasille: Incorrect calculate argument");
153
162
  }
@@ -155,18 +164,12 @@ function meshExpression(nodePath, internal) {
155
164
  }
156
165
  break;
157
166
  }
158
- case "OptionalCallExpression": {
159
- const path = nodePath;
160
- meshExpression(path.get("callee"), internal);
161
- meshAllUnknown(path.get("arguments"), internal);
162
- break;
163
- }
164
167
  case "AssignmentExpression": {
165
168
  const path = nodePath;
166
169
  const left = path.node.left;
167
170
  meshLValue(path.get("left"), internal);
168
171
  if (t.isIdentifier(left) && internal.stack.get(left.name) === 4 /* VariableState.ReactivePointer */) {
169
- const replaceWith = (0, lib_js_1.forwardOnlyExpr)(path.get("right"), path.node.right, internal);
172
+ const replaceWith = (0, lib_1.forwardOnlyExpr)(path.get("right"), path.node.right, internal);
170
173
  if (replaceWith) {
171
174
  path.get("right").replaceWith(replaceWith);
172
175
  }
@@ -513,7 +516,7 @@ function meshStatement(path, internal) {
513
516
  for (const declaration of _path.get("declarations")) {
514
517
  const expr = declaration.node.init;
515
518
  let ignore = true;
516
- if (expr && t.isIdentifier(declaration.node.id) && (0, call_js_1.calls)(expr, ["compose", "extend"], internal)) {
519
+ if (expr && t.isIdentifier(declaration.node.id) && (0, call_1.calls)(expr, ["compose", "extend"], internal)) {
517
520
  meshComposeCall(expr, declaration.node.id, declaration.get("init"), internal);
518
521
  }
519
522
  else {
@@ -607,7 +610,7 @@ function composeExpression(path, internal) {
607
610
  switch (expr.type) {
608
611
  case "AssignmentExpression": {
609
612
  const assign = expr;
610
- if ((0, call_js_1.calls)(assign.right, ["awaited"], internal)) {
613
+ if ((0, call_1.calls)(assign.right, ["awaited"], internal)) {
611
614
  reactiveArrayPattern(assign.left, internal);
612
615
  }
613
616
  else {
@@ -619,27 +622,27 @@ function composeExpression(path, internal) {
619
622
  case "OptionalCallExpression": {
620
623
  const call = expr;
621
624
  let replaced = false;
622
- if ((0, call_js_1.calls)(call, ["watch"], internal)) {
623
- const args = (0, lib_js_1.parseCalculateCall)(path, internal);
625
+ if ((0, call_1.calls)(call, ["watch"], internal)) {
626
+ const args = (0, lib_1.parseCalculateCall)(path, internal);
624
627
  if (args) {
625
- path.replaceWith(t.callExpression(t.memberExpression(internal_js_1.ctx, t.identifier("watch")), args));
628
+ path.replaceWith(t.callExpression(t.memberExpression(internal_1.ctx, t.identifier("watch")), args));
626
629
  replaced = true;
627
630
  }
628
631
  }
629
- else if ((0, call_js_1.calls)(call, ["arrayModel"], internal)) {
632
+ else if ((0, call_1.calls)(call, ["arrayModel"], internal)) {
630
633
  const value = call.arguments[0];
631
634
  if (t.isArrayExpression(value)) {
632
- path.replaceWith((0, lib_js_1.arrayModel)(value, internal));
635
+ path.replaceWith((0, lib_1.arrayModel)(value, internal));
633
636
  replaced = true;
634
637
  }
635
638
  else {
636
639
  path.buildCodeFrameError(`Vasille: arrayModel requires array expression as argument`);
637
640
  }
638
641
  }
639
- else if ((0, call_js_1.calls)(call, ["mapModel", "setModel"], internal)) {
642
+ else if ((0, call_1.calls)(call, ["mapModel", "setModel"], internal)) {
640
643
  const args = call.arguments;
641
- const name = (0, call_js_1.calls)(call, ["mapModel", "setModel"], internal);
642
- path.replaceWith(name === "mapModel" ? (0, lib_js_1.mapModel)(args, internal) : (0, lib_js_1.setModel)(args, internal));
644
+ const name = (0, call_1.calls)(call, ["mapModel", "setModel"], internal);
645
+ path.replaceWith(name === "mapModel" ? (0, lib_1.mapModel)(args, internal) : (0, lib_1.setModel)(args, internal));
643
646
  replaced = true;
644
647
  }
645
648
  if (!replaced) {
@@ -649,7 +652,7 @@ function composeExpression(path, internal) {
649
652
  }
650
653
  case "JSXElement":
651
654
  case "JSXFragment":
652
- path.replaceWithMultiple((0, jsx_js_1.transformJsx)(path, internal));
655
+ path.replaceWithMultiple((0, jsx_1.transformJsx)(path, internal));
653
656
  break;
654
657
  default:
655
658
  meshExpression(path, internal);
@@ -669,7 +672,7 @@ function composeStatement(path, internal) {
669
672
  case "FunctionDeclaration": {
670
673
  const _path = path;
671
674
  const fn = _path.node;
672
- if ((0, jsx_detect_js_1.bodyHasJsx)(fn.body)) {
675
+ if ((0, jsx_detect_1.bodyHasJsx)(fn.body)) {
673
676
  compose(_path, internal, false);
674
677
  }
675
678
  else {
@@ -771,7 +774,7 @@ function composeStatement(path, internal) {
771
774
  const id = declaration.node.id;
772
775
  let meshInit = true;
773
776
  ignoreParams(declaration.node.id, internal);
774
- if ((0, call_js_1.calls)(declaration.node.init, ["awaited"], internal)) {
777
+ if ((0, call_1.calls)(declaration.node.init, ["awaited"], internal)) {
775
778
  reactiveArrayPattern(declaration.node.id, internal);
776
779
  meshAllUnknown(declaration.get("init").get("arguments"), internal);
777
780
  meshInit = false;
@@ -779,20 +782,20 @@ function composeStatement(path, internal) {
779
782
  else if (t.isIdentifier(id)) {
780
783
  internal.stack.set(id.name, declares);
781
784
  const init = declaration.node.init;
782
- if ((0, call_js_1.calls)(init, ["value"], internal)) {
785
+ if ((0, call_1.calls)(init, ["value"], internal)) {
783
786
  internal.stack.set(id.name, 1 /* VariableState.Ignored */);
784
787
  declaration.get("init").replaceWith(init.arguments[0]);
785
788
  _path.node.kind = kind;
786
789
  }
787
- else if ((0, call_js_1.calls)(init, ["bind"], internal)) {
790
+ else if ((0, call_1.calls)(init, ["bind"], internal)) {
788
791
  const argument = init.arguments[0];
789
792
  const replaceWith = declares === 2 /* VariableState.Reactive */
790
- ? (0, lib_js_1.forwardOnlyExpr)(declaration.get("init"), argument, internal)
791
- : (0, lib_js_1.exprCall)(declaration.get("init"), argument, internal);
792
- let insertNode = replaceWith !== null && replaceWith !== void 0 ? replaceWith : (0, lib_js_1.ref)(t.isExpression(argument) ? argument : null);
793
+ ? (0, lib_1.forwardOnlyExpr)(declaration.get("init"), argument, internal)
794
+ : (0, lib_1.exprCall)(declaration.get("init"), argument, internal);
795
+ let insertNode = replaceWith !== null && replaceWith !== void 0 ? replaceWith : (0, lib_1.ref)(t.isExpression(argument) ? argument : null);
793
796
  if (declares === 2 /* VariableState.Reactive */) {
794
797
  internal.stack.set(id.name, 4 /* VariableState.ReactivePointer */);
795
- insertNode = (0, lib_js_1.own)(insertNode);
798
+ insertNode = (0, lib_1.own)(insertNode);
796
799
  }
797
800
  else {
798
801
  internal.stack.set(id.name, 2 /* VariableState.Reactive */);
@@ -800,58 +803,58 @@ function composeStatement(path, internal) {
800
803
  declaration.get("init").replaceWith(insertNode);
801
804
  meshInit = !replaceWith;
802
805
  }
803
- else if ((0, call_js_1.calls)(init, ["ref"], internal)) {
806
+ else if ((0, call_1.calls)(init, ["ref"], internal)) {
804
807
  const argument = init.arguments[0];
805
808
  internal.stack.set(id.name, 2 /* VariableState.Reactive */);
806
- declaration.get("init").replaceWith((0, lib_js_1.ref)(t.isExpression(argument) ? argument : null));
809
+ declaration.get("init").replaceWith((0, lib_1.ref)(t.isExpression(argument) ? argument : null));
807
810
  }
808
- else if ((0, call_js_1.calls)(init, ["reactiveObject"], internal)) {
811
+ else if ((0, call_1.calls)(init, ["reactiveObject"], internal)) {
809
812
  const value = init.arguments[0];
810
813
  if (kind !== "const") {
811
814
  declaration.buildCodeFrameError(`Vasille: Reactive objects must be must be declared as constants`);
812
815
  }
813
816
  if (t.isObjectExpression(value)) {
814
- declaration.get("init").replaceWith((0, lib_js_1.reactiveObject)(value, internal));
817
+ declaration.get("init").replaceWith((0, lib_1.reactiveObject)(value, internal));
815
818
  internal.stack.set(id.name, 3 /* VariableState.ReactiveObject */);
816
819
  }
817
820
  else {
818
821
  declaration.buildCodeFrameError(`Vasille: reactiveObject requires object expression as argument`);
819
822
  }
820
823
  }
821
- else if ((0, call_js_1.calls)(init, ["arrayModel"], internal)) {
824
+ else if ((0, call_1.calls)(init, ["arrayModel"], internal)) {
822
825
  const value = init.arguments[0];
823
826
  if (kind !== "const") {
824
827
  declaration.buildCodeFrameError(`Vasille: Array models must be must be declared as constants`);
825
828
  }
826
829
  if (t.isArrayExpression(value)) {
827
- declaration.get("init").replaceWith((0, lib_js_1.arrayModel)(value, internal));
830
+ declaration.get("init").replaceWith((0, lib_1.arrayModel)(value, internal));
828
831
  }
829
832
  else {
830
833
  declaration.buildCodeFrameError(`Vasille: arrayModel requires array expression as argument`);
831
834
  }
832
835
  }
833
- else if ((0, call_js_1.calls)(init, ["mapModel", "setModel"], internal)) {
836
+ else if ((0, call_1.calls)(init, ["mapModel", "setModel"], internal)) {
834
837
  const args = init.arguments;
835
- const name = (0, call_js_1.calls)(init, ["mapModel", "setModel"], internal);
838
+ const name = (0, call_1.calls)(init, ["mapModel", "setModel"], internal);
836
839
  if (kind !== "const") {
837
840
  declaration.buildCodeFrameError(`Vasille: ${name === "mapModel" ? "Map" : "Set"} models must be declared as constants`);
838
841
  }
839
842
  declaration
840
843
  .get("init")
841
- .replaceWith(name === "mapModel" ? (0, lib_js_1.mapModel)(args, internal) : (0, lib_js_1.setModel)(args, internal));
844
+ .replaceWith(name === "mapModel" ? (0, lib_1.mapModel)(args, internal) : (0, lib_1.setModel)(args, internal));
842
845
  }
843
846
  else if (t.isObjectExpression(init)) {
844
847
  if (kind !== "const") {
845
848
  declaration.buildCodeFrameError(`Vasille: Objects must be must be declared as constants`);
846
849
  }
847
- declaration.get("init").replaceWith((0, lib_js_1.reactiveObject)(init, internal));
850
+ declaration.get("init").replaceWith((0, lib_1.reactiveObject)(init, internal));
848
851
  internal.stack.set(id.name, 3 /* VariableState.ReactiveObject */);
849
852
  }
850
853
  else if (t.isArrayExpression(init)) {
851
854
  if (kind !== "const") {
852
855
  declaration.buildCodeFrameError(`Vasille: Arrays must be must be declared as constants`);
853
856
  }
854
- declaration.get("init").replaceWith((0, lib_js_1.arrayModel)(init, internal));
857
+ declaration.get("init").replaceWith((0, lib_1.arrayModel)(init, internal));
855
858
  }
856
859
  else if (t.isNewExpression(init) && t.isIdentifier(init.callee)) {
857
860
  if (init.callee.name === "Map" || init.callee.name === "Set") {
@@ -860,17 +863,17 @@ function composeStatement(path, internal) {
860
863
  }
861
864
  declaration
862
865
  .get("init")
863
- .replaceWith(init.callee.name === "Map" ? (0, lib_js_1.mapModel)(init.arguments, internal) : (0, lib_js_1.setModel)(init.arguments, internal));
866
+ .replaceWith(init.callee.name === "Map" ? (0, lib_1.mapModel)(init.arguments, internal) : (0, lib_1.setModel)(init.arguments, internal));
864
867
  }
865
868
  }
866
869
  else if (declares === 2 /* VariableState.Reactive */) {
867
- const replaceWith = (0, lib_js_1.forwardOnlyExpr)(declaration.get("init"), declaration.node.init, internal);
870
+ const replaceWith = (0, lib_1.forwardOnlyExpr)(declaration.get("init"), declaration.node.init, internal);
868
871
  meshInit = !replaceWith;
869
872
  internal.stack.set(id.name, replaceWith ? 4 /* VariableState.ReactivePointer */ : 2 /* VariableState.Reactive */);
870
- declaration.get("init").replaceWith(replaceWith ? (0, lib_js_1.own)(replaceWith) : (0, lib_js_1.ref)(declaration.node.init));
873
+ declaration.get("init").replaceWith(replaceWith ? (0, lib_1.own)(replaceWith) : (0, lib_1.ref)(declaration.node.init));
871
874
  }
872
875
  else {
873
- const replaceWith = (0, lib_js_1.exprCall)(declaration.get("init"), declaration.node.init, internal);
876
+ const replaceWith = (0, lib_1.exprCall)(declaration.get("init"), declaration.node.init, internal);
874
877
  if (replaceWith) {
875
878
  declaration.get("init").replaceWith(replaceWith);
876
879
  }
@@ -25,9 +25,13 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.trProgram = trProgram;
27
27
  const t = __importStar(require("@babel/types"));
28
- const internal_js_1 = require("./internal.js");
29
- const mesh_js_1 = require("./mesh.js");
30
- const imports = new Map([["vasille-dx", "VasilleDX"], ["vasille-web", "VasilleWeb"]]);
28
+ const internal_1 = require("./internal");
29
+ const mesh_1 = require("./mesh");
30
+ const css_transformer_1 = require("./css-transformer");
31
+ const imports = new Map([
32
+ ["vasille-dx", "VasilleDX"],
33
+ ["vasille-web", "VasilleWeb"],
34
+ ]);
31
35
  const ignoreMembers = new Set([
32
36
  "value",
33
37
  "ref",
@@ -38,12 +42,20 @@ const ignoreMembers = new Set([
38
42
  "mapModel",
39
43
  "reactiveObject",
40
44
  "setModel",
45
+ "theme",
46
+ "dark",
47
+ "mobile",
48
+ "tablet",
49
+ "laptop",
50
+ "prefersDark",
51
+ "prefersLight",
41
52
  ]);
42
53
  function extractText(node) {
43
54
  return t.isIdentifier(node) ? node.name : node.value;
44
55
  }
45
56
  function trProgram(path, devMode) {
46
57
  let id;
58
+ let stylesConnected = false;
47
59
  const internal = {
48
60
  get id() {
49
61
  this.internalUsed = true;
@@ -52,9 +64,10 @@ function trProgram(path, devMode) {
52
64
  set id(expr) {
53
65
  id = expr;
54
66
  },
55
- stack: new internal_js_1.StackedStates(),
67
+ stack: new internal_1.StackedStates(),
56
68
  mapping: new Map(),
57
69
  global: "",
70
+ cssGlobal: "",
58
71
  prefix: "Vasille_",
59
72
  importStatement: null,
60
73
  internalUsed: false,
@@ -69,12 +82,19 @@ function trProgram(path, devMode) {
69
82
  for (const specifier of statement.specifiers) {
70
83
  if (t.isImportNamespaceSpecifier(specifier)) {
71
84
  internal.global = specifier.local.name;
85
+ if (statement.source.value === "vasille-web") {
86
+ internal.cssGlobal = internal.global;
87
+ stylesConnected = true;
88
+ }
72
89
  id = t.memberExpression(t.identifier(internal.global), t.identifier("$"));
73
90
  }
74
91
  else if (t.isImportSpecifier(specifier)) {
75
92
  const imported = extractText(specifier.imported);
76
93
  const local = specifier.local.name;
77
94
  internal.mapping.set(local, imported);
95
+ if (imported === "webStyleSheet") {
96
+ stylesConnected = true;
97
+ }
78
98
  if (!id) {
79
99
  id = t.identifier(name);
80
100
  }
@@ -90,12 +110,36 @@ function trProgram(path, devMode) {
90
110
  }
91
111
  });
92
112
  }
113
+ else if (statement.source.value === "vasille-css") {
114
+ for (const specifier of statement.specifiers) {
115
+ if (t.isImportSpecifier(specifier)) {
116
+ internal.mapping.set(specifier.local.name, extractText(specifier.imported));
117
+ }
118
+ else if (t.isImportNamespaceSpecifier(specifier)) {
119
+ internal.cssGlobal = specifier.local.name;
120
+ }
121
+ }
122
+ statement.specifiers = statement.specifiers.filter(spec => {
123
+ if (!t.isImportSpecifier(spec)) {
124
+ return true;
125
+ }
126
+ else {
127
+ return !ignoreMembers.has(extractText(spec.imported));
128
+ }
129
+ });
130
+ stylesConnected = true;
131
+ }
93
132
  }
94
133
  else {
95
134
  if (!id) {
135
+ if (stylesConnected) {
136
+ (0, css_transformer_1.findStyleInNode)(statementPath, internal);
137
+ }
96
138
  return;
97
139
  }
98
- (0, mesh_js_1.meshStatement)(statementPath, internal);
140
+ if (!stylesConnected || !(0, css_transformer_1.findStyleInNode)(statementPath, internal)) {
141
+ (0, mesh_1.meshStatement)(statementPath, internal);
142
+ }
99
143
  }
100
144
  }
101
145
  if (internal.internalUsed && !internal.global && internal.importStatement) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "babel-plugin-vasille",
3
- "version": "0.99.1",
4
- "description": "",
3
+ "version": "0.99.3",
4
+ "description": "Convert Vasille Meta Language code to pure JavaScript",
5
5
  "main": "lib-node/index.js",
6
6
  "type": "commonjs",
7
7
  "exports": {
@@ -21,7 +21,9 @@
21
21
  "keywords": [
22
22
  "front-end",
23
23
  "framework",
24
- "dx"
24
+ "web",
25
+ "compiler",
26
+ "babel"
25
27
  ],
26
28
  "author": "lixcode",
27
29
  "license": "MIT",
@@ -29,9 +31,6 @@
29
31
  "url": "https://github.com/vasille-js/vasille-js/issues"
30
32
  },
31
33
  "homepage": "https://github.com/vasille-js/vasille-js#readme",
32
- "dependencies": {
33
- "vasille-dx": "^3.0.1"
34
- },
35
34
  "devDependencies": {
36
35
  "@babel/parser": "^7.26.1",
37
36
  "@babel/plugin-syntax-jsx": "^7.25.9",
@@ -46,6 +45,8 @@
46
45
  "path": "^0.12.7",
47
46
  "prettier": "^3.3.3",
48
47
  "ts-jest": "^29.2.5",
49
- "typescript": "^5.6.3"
48
+ "typescript": "^5.6.3",
49
+ "vasille-css": "^3.0.3",
50
+ "vasille-dx": "^3.0.3"
50
51
  }
51
52
  }