babel-plugin-vasille 3.1.5 → 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.
- package/README.md +9 -17
- package/lib/call.js +45 -34
- package/lib/css-transformer.js +45 -47
- package/lib/expression.js +147 -139
- package/lib/index.js +4 -1
- package/lib/internal.js +4 -19
- package/lib/jsx-detect.js +3 -54
- package/lib/jsx.js +253 -123
- package/lib/lib.js +116 -80
- package/lib/mesh.js +580 -400
- package/lib/order-check.js +48 -0
- package/lib/router.js +41 -0
- package/lib/transformer.js +121 -75
- package/{lib-node/internal.js → lib/utils.js} +10 -37
- package/package.json +12 -14
- package/lib-node/call.js +0 -104
- package/lib-node/css-transformer.js +0 -248
- package/lib-node/expression.js +0 -573
- package/lib-node/index.js +0 -14
- package/lib-node/jsx-detect.js +0 -100
- package/lib-node/jsx.js +0 -439
- package/lib-node/lib.js +0 -153
- package/lib-node/mesh.js +0 -919
- package/lib-node/transformer.js +0 -144
|
@@ -1,248 +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.findStyleInNode = findStyleInNode;
|
|
37
|
-
const t = __importStar(require("@babel/types"));
|
|
38
|
-
const call_js_1 = require("./call.js");
|
|
39
|
-
function tryProcessProp(path, pseudo, media, internal) {
|
|
40
|
-
if (t.isObjectMethod(path.node)) {
|
|
41
|
-
throw path.buildCodeFrameError("Vasille: Object methods not supported here");
|
|
42
|
-
}
|
|
43
|
-
if (t.isSpreadElement(path.node)) {
|
|
44
|
-
throw path.buildCodeFrameError("Vasille: Spread element not supported here");
|
|
45
|
-
}
|
|
46
|
-
return processProp(path, pseudo, media, internal);
|
|
47
|
-
}
|
|
48
|
-
const mediaDefaults = ["mobile", "tablet", "laptop", "prefersDark", "prefersLight"];
|
|
49
|
-
function processValue(name, path, pseudo, theme, media, mediaDefault, allowFallback, internal) {
|
|
50
|
-
if ((0, call_js_1.calls)(path.node, ["theme"], internal)) {
|
|
51
|
-
const call = path.node;
|
|
52
|
-
if (theme) {
|
|
53
|
-
throw path.buildCodeFrameError("Vasille: The theme seems the be defined twice");
|
|
54
|
-
}
|
|
55
|
-
if (t.isStringLiteral(call.arguments[0])) {
|
|
56
|
-
return processValue(name, path.get("arguments")[1], pseudo, `body.${call.arguments[0].value}`, media, mediaDefault, false, internal);
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
throw path
|
|
60
|
-
.get("arguments")[0]
|
|
61
|
-
.buildCodeFrameError("Vasille: Expected string literal");
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
if ((0, call_js_1.calls)(path.node, ["dark"], internal)) {
|
|
65
|
-
if (theme) {
|
|
66
|
-
throw path.buildCodeFrameError("Vasille: The theme seem the be defined twice");
|
|
67
|
-
}
|
|
68
|
-
return processValue(name, path.get("arguments")[0], pseudo, `.dark`, media, mediaDefault, false, internal);
|
|
69
|
-
}
|
|
70
|
-
let callee;
|
|
71
|
-
if ((callee = (0, call_js_1.calls)(path.node, mediaDefaults, internal))) {
|
|
72
|
-
const index = mediaDefaults.indexOf(callee) + 1;
|
|
73
|
-
if (mediaDefault.includes(index)) {
|
|
74
|
-
return processValue(name, path.get("arguments")[0], pseudo, theme, media, mediaDefault, false, internal);
|
|
75
|
-
}
|
|
76
|
-
return processValue(name, path.get("arguments")[0], pseudo, theme, media, [...mediaDefault, index], false, internal);
|
|
77
|
-
}
|
|
78
|
-
function composeRules(value) {
|
|
79
|
-
return mediaDefault.length
|
|
80
|
-
? mediaDefault.map(index => {
|
|
81
|
-
return {
|
|
82
|
-
defaultMediaRule: index,
|
|
83
|
-
mediaRule: media,
|
|
84
|
-
pseudo: pseudo,
|
|
85
|
-
theme: theme,
|
|
86
|
-
rule: `${name}:${value}`,
|
|
87
|
-
};
|
|
88
|
-
})
|
|
89
|
-
: [
|
|
90
|
-
{
|
|
91
|
-
defaultMediaRule: 0,
|
|
92
|
-
mediaRule: media,
|
|
93
|
-
pseudo: pseudo,
|
|
94
|
-
theme: theme,
|
|
95
|
-
rule: `${name}:${value}`,
|
|
96
|
-
},
|
|
97
|
-
];
|
|
98
|
-
}
|
|
99
|
-
if (t.isStringLiteral(path.node)) {
|
|
100
|
-
return composeRules(path.node.value);
|
|
101
|
-
}
|
|
102
|
-
if (t.isNumericLiteral(path.node)) {
|
|
103
|
-
return composeRules(`${path.node.value}px`);
|
|
104
|
-
}
|
|
105
|
-
if (t.isArrayExpression(path.node)) {
|
|
106
|
-
if (path.node.elements.every(item => t.isNumericLiteral(item))) {
|
|
107
|
-
return composeRules(path.node.elements.map(item => `${item.value}px`).join(" "));
|
|
108
|
-
}
|
|
109
|
-
else if (allowFallback) {
|
|
110
|
-
return [
|
|
111
|
-
...path
|
|
112
|
-
.get("elements")
|
|
113
|
-
.map(path => {
|
|
114
|
-
if (t.isExpression(path.node)) {
|
|
115
|
-
return processValue(name, path, pseudo, theme, media, mediaDefault, false, internal);
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
throw path.buildCodeFrameError("Vasille: Expected expression");
|
|
119
|
-
}
|
|
120
|
-
})
|
|
121
|
-
.flat(1),
|
|
122
|
-
];
|
|
123
|
-
}
|
|
124
|
-
else {
|
|
125
|
-
throw path.buildCodeFrameError("Vasille: Only numbers arrays are supported here");
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
throw path.buildCodeFrameError("Vasille: Failed o parse value, it is not a string, number or array");
|
|
129
|
-
}
|
|
130
|
-
function processProp(path, pseudo, media, internal) {
|
|
131
|
-
let name;
|
|
132
|
-
if (t.isIdentifier(path.node.key) && !path.node.computed) {
|
|
133
|
-
name = path.node.key.name;
|
|
134
|
-
}
|
|
135
|
-
else if (t.isStringLiteral(path.node.key)) {
|
|
136
|
-
name = path.node.key.value;
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
throw path.get("key").buildCodeFrameError("Vasille: Incompatible key, expect identifier or string literal");
|
|
140
|
-
}
|
|
141
|
-
if (name.startsWith("@")) {
|
|
142
|
-
if (media || pseudo) {
|
|
143
|
-
throw path.get("key").buildCodeFrameError("Vasille: Media queries allowed only in the root of style");
|
|
144
|
-
}
|
|
145
|
-
if (t.isObjectExpression(path.node.value)) {
|
|
146
|
-
return path.get("value")
|
|
147
|
-
.get("properties")
|
|
148
|
-
.map(item => {
|
|
149
|
-
return tryProcessProp(item, "", name, internal);
|
|
150
|
-
})
|
|
151
|
-
.flat(1);
|
|
152
|
-
}
|
|
153
|
-
else {
|
|
154
|
-
throw path.get("value").buildCodeFrameError("Vasille: Expected object expression");
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
if (name.startsWith(":")) {
|
|
158
|
-
if (pseudo) {
|
|
159
|
-
throw path.get("key").buildCodeFrameError("Vasille: Recursive pseudo classes are restricted");
|
|
160
|
-
}
|
|
161
|
-
if (t.isObjectExpression(path.node.value)) {
|
|
162
|
-
return path.get("value")
|
|
163
|
-
.get("properties")
|
|
164
|
-
.map(item => {
|
|
165
|
-
return tryProcessProp(item, name, media, internal);
|
|
166
|
-
})
|
|
167
|
-
.flat(1);
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
throw path.get("value").buildCodeFrameError("Vasille: Expected object expression");
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
return processValue(name, path.get("value"), pseudo, "", media, [], true, internal);
|
|
174
|
-
}
|
|
175
|
-
function findStyleInNode(path, internal) {
|
|
176
|
-
if (t.isExportNamedDeclaration(path.node)) {
|
|
177
|
-
return findStyleInNode(path.get("declaration"), internal);
|
|
178
|
-
}
|
|
179
|
-
if (t.isVariableDeclaration(path.node) &&
|
|
180
|
-
path.node.declarations.length === 1 &&
|
|
181
|
-
(0, call_js_1.calls)(path.node.declarations[0].init, ["styleSheet"], internal)) {
|
|
182
|
-
const call = path.node.declarations[0].init;
|
|
183
|
-
const callPath = path
|
|
184
|
-
.get("declarations")[0]
|
|
185
|
-
.get("init");
|
|
186
|
-
const objPath = callPath.get("arguments")[0];
|
|
187
|
-
if (call.arguments.length !== 1) {
|
|
188
|
-
throw callPath.buildCodeFrameError("Vasille: styleSheet function has 1 parameter");
|
|
189
|
-
}
|
|
190
|
-
if (!t.isObjectExpression(call.arguments[0])) {
|
|
191
|
-
throw objPath.buildCodeFrameError("Vasille: Expected object expression");
|
|
192
|
-
}
|
|
193
|
-
for (const path of objPath.get("properties")) {
|
|
194
|
-
if (!t.isObjectProperty(path.node)) {
|
|
195
|
-
throw path.buildCodeFrameError("Vasille: Expected object property");
|
|
196
|
-
}
|
|
197
|
-
const prop = path;
|
|
198
|
-
if (!t.isObjectExpression(prop.node.value)) {
|
|
199
|
-
throw prop.get("value").buildCodeFrameError("Vasille: Expected object expression");
|
|
200
|
-
}
|
|
201
|
-
if (!((t.isIdentifier(prop.node.key) && !prop.node.computed) || t.isStringLiteral(prop.node.key))) {
|
|
202
|
-
throw prop.get("key").buildCodeFrameError("Vasille: Expected identifier of string literal");
|
|
203
|
-
}
|
|
204
|
-
const unsorted = [];
|
|
205
|
-
const sorted = {};
|
|
206
|
-
for (const path of prop.get("value").get("properties")) {
|
|
207
|
-
unsorted.push(...tryProcessProp(path, "", "", internal));
|
|
208
|
-
}
|
|
209
|
-
for (const rule of unsorted) {
|
|
210
|
-
if (!sorted[rule.defaultMediaRule]) {
|
|
211
|
-
sorted[rule.defaultMediaRule] = {};
|
|
212
|
-
}
|
|
213
|
-
const defaultMediaRule = sorted[rule.defaultMediaRule];
|
|
214
|
-
if (!defaultMediaRule[rule.mediaRule]) {
|
|
215
|
-
defaultMediaRule[rule.mediaRule] = {};
|
|
216
|
-
}
|
|
217
|
-
const mediaRule = defaultMediaRule[rule.mediaRule];
|
|
218
|
-
if (!mediaRule[rule.theme]) {
|
|
219
|
-
mediaRule[rule.theme] = {};
|
|
220
|
-
}
|
|
221
|
-
const theme = mediaRule[rule.theme];
|
|
222
|
-
if (!theme[rule.pseudo]) {
|
|
223
|
-
theme[rule.pseudo] = [];
|
|
224
|
-
}
|
|
225
|
-
theme[rule.pseudo].push(rule.rule);
|
|
226
|
-
}
|
|
227
|
-
const expressions = [];
|
|
228
|
-
for (const defaultMediaRule in sorted) {
|
|
229
|
-
for (const mediaRule in sorted[defaultMediaRule]) {
|
|
230
|
-
for (const theme in sorted[defaultMediaRule][mediaRule]) {
|
|
231
|
-
for (const pseudo in sorted[defaultMediaRule][mediaRule][theme]) {
|
|
232
|
-
const rulePack = sorted[defaultMediaRule][mediaRule][theme][pseudo].join(";");
|
|
233
|
-
const pseudoPack = pseudo ? `.{}${pseudo}{${rulePack}}` : `.{}{${rulePack}}`;
|
|
234
|
-
const themePack = theme ? `${theme} ${pseudoPack}` : pseudoPack;
|
|
235
|
-
const mediaRulePack = t.stringLiteral(mediaRule ? `${mediaRule}{${themePack}}` : themePack);
|
|
236
|
-
expressions.push(defaultMediaRule !== "0"
|
|
237
|
-
? t.arrayExpression([t.numericLiteral(parseInt(defaultMediaRule)), mediaRulePack])
|
|
238
|
-
: mediaRulePack);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
prop.get("value").replaceWith(t.arrayExpression(expressions));
|
|
244
|
-
}
|
|
245
|
-
return true;
|
|
246
|
-
}
|
|
247
|
-
return false;
|
|
248
|
-
}
|