babel-plugin-vasille 0.99.5 → 3.1.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.
@@ -1,17 +1,15 @@
1
1
  import * as t from "@babel/types";
2
- import { StackedStates } from "./internal";
3
- import { meshStatement } from "./mesh";
4
- import { findStyleInNode } from "./css-transformer";
5
- const imports = new Map([
6
- ["vasille-dx", "VasilleDX"],
7
- ["vasille-web", "VasilleWeb"],
8
- ]);
2
+ import { StackedStates } from "./internal.js";
3
+ import { meshStatement } from "./mesh.js";
4
+ import { findStyleInNode } from "./css-transformer.js";
5
+ const imports = new Map([["vasille-web", "VasilleWeb"]]);
9
6
  const ignoreMembers = new Set([
10
7
  "value",
11
8
  "ref",
12
9
  "bind",
13
10
  "calculate",
14
11
  "watch",
12
+ "forward",
15
13
  "arrayModel",
16
14
  "mapModel",
17
15
  "reactiveObject",
@@ -23,9 +21,11 @@ const ignoreMembers = new Set([
23
21
  "laptop",
24
22
  "prefersDark",
25
23
  "prefersLight",
24
+ "state",
26
25
  ]);
27
26
  function extractText(node) {
28
- return t.isIdentifier(node) ? node.name : node.value;
27
+ // no case found for string literal
28
+ return node.name;
29
29
  }
30
30
  export function trProgram(path, devMode) {
31
31
  let id;
@@ -41,10 +41,10 @@ export function trProgram(path, devMode) {
41
41
  stack: new StackedStates(),
42
42
  mapping: new Map(),
43
43
  global: "",
44
- cssGlobal: "",
45
44
  prefix: "Vasille_",
46
45
  importStatement: null,
47
46
  internalUsed: false,
47
+ stateOnly: false,
48
48
  devMode: devMode,
49
49
  };
50
50
  for (const statementPath of path.get("body")) {
@@ -52,25 +52,24 @@ export function trProgram(path, devMode) {
52
52
  if (t.isImportDeclaration(statement)) {
53
53
  const name = imports.get(statement.source.value);
54
54
  if (name) {
55
- internal.prefix = `${name}_`;
55
+ internal.prefix = name;
56
56
  for (const specifier of statement.specifiers) {
57
57
  if (t.isImportNamespaceSpecifier(specifier)) {
58
58
  internal.global = specifier.local.name;
59
59
  if (statement.source.value === "vasille-web") {
60
- internal.cssGlobal = internal.global;
61
60
  stylesConnected = true;
62
61
  }
63
- id = t.memberExpression(t.identifier(internal.global), t.identifier("$"));
62
+ internal.id = t.memberExpression(t.identifier(internal.global), t.identifier("$"));
64
63
  }
65
64
  else if (t.isImportSpecifier(specifier)) {
66
65
  const imported = extractText(specifier.imported);
67
66
  const local = specifier.local.name;
68
67
  internal.mapping.set(local, imported);
69
- if (imported === "webStyleSheet") {
68
+ if (imported === "styleSheet") {
70
69
  stylesConnected = true;
71
70
  }
72
71
  if (!id) {
73
- id = t.identifier(name);
72
+ internal.id = t.identifier(name);
74
73
  }
75
74
  internal.importStatement = statementPath;
76
75
  }
@@ -80,38 +79,15 @@ export function trProgram(path, devMode) {
80
79
  return true;
81
80
  }
82
81
  else {
83
- return !ignoreMembers.has(extractText(spec.imported));
82
+ return !(ignoreMembers.has(extractText(spec.imported)) ||
83
+ (!internal.devMode && extractText(spec.imported) === "Debug"));
84
84
  }
85
85
  });
86
86
  }
87
- else if (statement.source.value === "vasille-css") {
88
- for (const specifier of statement.specifiers) {
89
- if (t.isImportSpecifier(specifier)) {
90
- internal.mapping.set(specifier.local.name, extractText(specifier.imported));
91
- }
92
- else if (t.isImportNamespaceSpecifier(specifier)) {
93
- internal.cssGlobal = specifier.local.name;
94
- }
95
- }
96
- statement.specifiers = statement.specifiers.filter(spec => {
97
- if (!t.isImportSpecifier(spec)) {
98
- return true;
99
- }
100
- else {
101
- return !ignoreMembers.has(extractText(spec.imported));
102
- }
103
- });
104
- stylesConnected = true;
105
- }
106
87
  }
107
88
  else {
108
89
  if (!id) {
109
- if (stylesConnected) {
110
- findStyleInNode(statementPath, internal);
111
- }
112
- else {
113
- return;
114
- }
90
+ return;
115
91
  }
116
92
  else if (!stylesConnected || !findStyleInNode(statementPath, internal)) {
117
93
  meshStatement(statementPath, internal);
package/lib-node/call.js CHANGED
@@ -15,24 +15,35 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
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
- };
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
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
36
  exports.requiresContext = exports.styleOnly = exports.composeOnly = void 0;
27
37
  exports.calls = calls;
28
38
  const t = __importStar(require("@babel/types"));
29
- const internal_1 = require("./internal");
39
+ const internal_js_1 = require("./internal.js");
30
40
  exports.composeOnly = [
31
41
  "forward",
32
42
  "watch",
33
43
  "ref",
34
44
  "bind",
35
45
  "value",
46
+ "awaited",
36
47
  "arrayModel",
37
48
  "mapModel",
38
49
  "setModel",
@@ -46,9 +57,9 @@ exports.styleOnly = [
46
57
  "laptop",
47
58
  "prefersDark",
48
59
  "prefersLight",
49
- "webStyleSheet",
60
+ "styleSheet",
50
61
  ];
51
- exports.requiresContext = ["awaited", "forward"];
62
+ exports.requiresContext = ["awaited"];
52
63
  const requiresContextSet = new Set(exports.requiresContext);
53
64
  function calls(node, names, internal) {
54
65
  const set = new Set(names);
@@ -58,34 +69,35 @@ function calls(node, names, internal) {
58
69
  const mapped = internal.mapping.get(callee.name);
59
70
  if (mapped && set.has(mapped) && internal.stack.get(callee.name) === undefined) {
60
71
  if (requiresContextSet.has(callee.name) && t.isCallExpression(node)) {
61
- node.arguments.unshift(internal_1.ctx);
72
+ node.arguments.unshift(internal_js_1.ctx);
73
+ }
74
+ if (mapped === "state") {
75
+ internal.stateOnly = true;
76
+ }
77
+ if (mapped === "compose" || mapped === "extend") {
78
+ internal.stateOnly = false;
62
79
  }
63
80
  return mapped;
64
81
  }
65
82
  return false;
66
83
  }
67
84
  const global = internal.stack.get(internal.global) === undefined;
68
- const cssGlobal = internal.stack.get(internal.cssGlobal) === undefined;
69
- if (!global && !cssGlobal) {
70
- return;
85
+ let propName = null;
86
+ if (t.isMemberExpression(callee)) {
87
+ if (t.isIdentifier(callee.property)) {
88
+ propName = callee.property.name;
89
+ }
90
+ else if (t.isStringLiteral(callee.property)) {
91
+ propName = callee.property.value;
92
+ }
71
93
  }
72
- const propName = t.isMemberExpression(callee)
73
- ? t.isIdentifier(callee.property)
74
- ? callee.property.name
75
- : t.isStringLiteral(callee.property)
76
- ? callee.property.value
77
- : null
78
- : null;
79
94
  if (t.isMemberExpression(callee) && t.isIdentifier(callee.object) && propName) {
80
95
  if (global && callee.object.name === internal.global && set.has(propName)) {
81
- if (requiresContextSet.has(callee.object.name) && t.isCallExpression(node)) {
82
- node.arguments.unshift(internal_1.ctx);
96
+ if (requiresContextSet.has(propName) && t.isCallExpression(node)) {
97
+ node.arguments.unshift(internal_js_1.ctx);
83
98
  }
84
99
  return callee.object.name;
85
100
  }
86
- if (cssGlobal && callee.object.name === internal.cssGlobal && set.has(propName)) {
87
- return callee.object.name;
88
- }
89
101
  }
90
102
  }
91
103
  return false;
@@ -15,32 +15,42 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
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
- };
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
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
36
  exports.findStyleInNode = findStyleInNode;
27
37
  const t = __importStar(require("@babel/types"));
28
- const call_1 = require("./call");
38
+ const call_js_1 = require("./call.js");
29
39
  function tryProcessProp(path, pseudo, media, internal) {
30
40
  if (t.isObjectMethod(path.node)) {
31
- throw path.buildCodeFrameError("Object methods not supported here");
41
+ throw path.buildCodeFrameError("Vasille: Object methods not supported here");
32
42
  }
33
43
  if (t.isSpreadElement(path.node)) {
34
- throw path.buildCodeFrameError("Spread element not suppored here");
44
+ throw path.buildCodeFrameError("Vasille: Spread element not supported here");
35
45
  }
36
46
  return processProp(path, pseudo, media, internal);
37
47
  }
38
48
  const mediaDefaults = ["mobile", "tablet", "laptop", "prefersDark", "prefersLight"];
39
49
  function processValue(name, path, pseudo, theme, media, mediaDefault, allowFallback, internal) {
40
- if ((0, call_1.calls)(path.node, ["theme"], internal)) {
50
+ if ((0, call_js_1.calls)(path.node, ["theme"], internal)) {
41
51
  const call = path.node;
42
52
  if (theme) {
43
- throw path.buildCodeFrameError("Vasille: Theme seem the be defined twince");
53
+ throw path.buildCodeFrameError("Vasille: The theme seems the be defined twice");
44
54
  }
45
55
  if (t.isStringLiteral(call.arguments[0])) {
46
56
  return processValue(name, path.get("arguments")[1], pseudo, `body.${call.arguments[0].value}`, media, mediaDefault, false, internal);
@@ -51,14 +61,14 @@ function processValue(name, path, pseudo, theme, media, mediaDefault, allowFallb
51
61
  .buildCodeFrameError("Vasille: Expected string literal");
52
62
  }
53
63
  }
54
- if ((0, call_1.calls)(path.node, ["dark"], internal)) {
64
+ if ((0, call_js_1.calls)(path.node, ["dark"], internal)) {
55
65
  if (theme) {
56
- throw path.buildCodeFrameError("Vasille: Theme seem the be defined twince");
66
+ throw path.buildCodeFrameError("Vasille: The theme seem the be defined twice");
57
67
  }
58
68
  return processValue(name, path.get("arguments")[0], pseudo, `.dark`, media, mediaDefault, false, internal);
59
69
  }
60
70
  let callee;
61
- if ((callee = (0, call_1.calls)(path.node, mediaDefaults, internal))) {
71
+ if ((callee = (0, call_js_1.calls)(path.node, mediaDefaults, internal))) {
62
72
  const index = mediaDefaults.indexOf(callee) + 1;
63
73
  if (mediaDefault.includes(index)) {
64
74
  return processValue(name, path.get("arguments")[0], pseudo, theme, media, mediaDefault, false, internal);
@@ -105,32 +115,32 @@ function processValue(name, path, pseudo, theme, media, mediaDefault, allowFallb
105
115
  return processValue(name, path, pseudo, theme, media, mediaDefault, false, internal);
106
116
  }
107
117
  else {
108
- throw path.buildCodeFrameError("Vasille: Exprected expression");
118
+ throw path.buildCodeFrameError("Vasille: Expected expression");
109
119
  }
110
120
  })
111
121
  .flat(1),
112
122
  ];
113
123
  }
114
124
  else {
115
- throw path.buildCodeFrameError("Vasille: Only numbers arrays are suppored here");
125
+ throw path.buildCodeFrameError("Vasille: Only numbers arrays are supported here");
116
126
  }
117
127
  }
118
128
  throw path.buildCodeFrameError("Vasille: Failed o parse value, it is not a string, number or array");
119
129
  }
120
130
  function processProp(path, pseudo, media, internal) {
121
131
  let name;
122
- if (t.isIdentifier(path.node.key)) {
132
+ if (t.isIdentifier(path.node.key) && !path.node.computed) {
123
133
  name = path.node.key.name;
124
134
  }
125
135
  else if (t.isStringLiteral(path.node.key)) {
126
136
  name = path.node.key.value;
127
137
  }
128
138
  else {
129
- throw path.get("key").buildCodeFrameError("Vasille: Incompaible key, exprect idenifier or string literal");
139
+ throw path.get("key").buildCodeFrameError("Vasille: Incompatible key, expect identifier or string literal");
130
140
  }
131
141
  if (name.startsWith("@")) {
132
142
  if (media || pseudo) {
133
- throw path.get("key").buildCodeFrameError("Vasille: Media queries allowed inly in the root of style");
143
+ throw path.get("key").buildCodeFrameError("Vasille: Media queries allowed only in the root of style");
134
144
  }
135
145
  if (t.isObjectExpression(path.node.value)) {
136
146
  return path.get("value")
@@ -141,12 +151,12 @@ function processProp(path, pseudo, media, internal) {
141
151
  .flat(1);
142
152
  }
143
153
  else {
144
- throw path.get("value").buildCodeFrameError("Vasille: Exprected object expression");
154
+ throw path.get("value").buildCodeFrameError("Vasille: Expected object expression");
145
155
  }
146
156
  }
147
157
  if (name.startsWith(":")) {
148
158
  if (pseudo) {
149
- throw path.get("key").buildCodeFrameError("Recursive pseudo classes are restriced");
159
+ throw path.get("key").buildCodeFrameError("Vasille: Recursive pseudo classes are restricted");
150
160
  }
151
161
  if (t.isObjectExpression(path.node.value)) {
152
162
  return path.get("value")
@@ -157,31 +167,28 @@ function processProp(path, pseudo, media, internal) {
157
167
  .flat(1);
158
168
  }
159
169
  else {
160
- throw path.get("value").buildCodeFrameError("Vasille: Exprected object expression");
170
+ throw path.get("value").buildCodeFrameError("Vasille: Expected object expression");
161
171
  }
162
172
  }
163
173
  return processValue(name, path.get("value"), pseudo, "", media, [], true, internal);
164
174
  }
165
175
  function findStyleInNode(path, internal) {
166
- if (t.isExpressionStatement(path.node)) {
167
- return findStyleInNode(path.get("expression"), internal);
168
- }
169
176
  if (t.isExportNamedDeclaration(path.node)) {
170
177
  return findStyleInNode(path.get("declaration"), internal);
171
178
  }
172
179
  if (t.isVariableDeclaration(path.node) &&
173
180
  path.node.declarations.length === 1 &&
174
- (0, call_1.calls)(path.node.declarations[0].init, ["webStyleSheet"], internal)) {
181
+ (0, call_js_1.calls)(path.node.declarations[0].init, ["styleSheet"], internal)) {
175
182
  const call = path.node.declarations[0].init;
176
183
  const callPath = path
177
184
  .get("declarations")[0]
178
185
  .get("init");
179
186
  const objPath = callPath.get("arguments")[0];
180
187
  if (call.arguments.length !== 1) {
181
- throw callPath.buildCodeFrameError("Vasille: webStyleSheet function has 1 parameter");
188
+ throw callPath.buildCodeFrameError("Vasille: styleSheet function has 1 parameter");
182
189
  }
183
190
  if (!t.isObjectExpression(call.arguments[0])) {
184
- throw objPath.buildCodeFrameError("Vasille: expected object expression");
191
+ throw objPath.buildCodeFrameError("Vasille: Expected object expression");
185
192
  }
186
193
  for (const path of objPath.get("properties")) {
187
194
  if (!t.isObjectProperty(path.node)) {
@@ -189,9 +196,9 @@ function findStyleInNode(path, internal) {
189
196
  }
190
197
  const prop = path;
191
198
  if (!t.isObjectExpression(prop.node.value)) {
192
- throw prop.get("value").buildCodeFrameError("Vasille: Exprected object expression");
199
+ throw prop.get("value").buildCodeFrameError("Vasille: Expected object expression");
193
200
  }
194
- if (!(t.isIdentifier(prop.node.key) || t.isStringLiteral(prop.node.key))) {
201
+ if (!((t.isIdentifier(prop.node.key) && !prop.node.computed) || t.isStringLiteral(prop.node.key))) {
195
202
  throw prop.get("key").buildCodeFrameError("Vasille: Expected identifier of string literal");
196
203
  }
197
204
  const unsorted = [];