babel-plugin-vasille 4.0.0 → 4.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.
- package/README.md +11 -1
- package/lib/index.js +3 -0
- package/lib/jsx.js +3 -0
- package/lib/transformer.js +16 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -97,10 +97,20 @@ All of these are supported:
|
|
|
97
97
|
* [x] `100%` Test Coverage fot babel plugin.
|
|
98
98
|
* [x] Add CSS support (define styles in components).
|
|
99
99
|
* [x] Add router.
|
|
100
|
-
* [
|
|
100
|
+
* [x] Add SSG (static site generation).
|
|
101
101
|
* [ ] Add SSR (server side rendering).
|
|
102
102
|
* [ ] Develop tools extension for debugging.
|
|
103
103
|
|
|
104
|
+
## Change log
|
|
105
|
+
|
|
106
|
+
### 4.1.0
|
|
107
|
+
|
|
108
|
+
Added SSG (static site generation) as build option `vasille-web build static`.
|
|
109
|
+
|
|
110
|
+
### 4.0.0
|
|
111
|
+
|
|
112
|
+
Initial version of the framework with file based routing and building scripts (`vasille-web dev` and `vasille-web build spa`).
|
|
113
|
+
|
|
104
114
|
## Questions
|
|
105
115
|
|
|
106
116
|
If you have questions, feel free to contact the maintainer of the project:
|
package/lib/index.js
CHANGED
|
@@ -10,6 +10,9 @@ function default_1() {
|
|
|
10
10
|
(0, transformer_js_1.transformProgram)(path, params.file.opts.filename, {
|
|
11
11
|
devMode: params.opts.devMode !== false,
|
|
12
12
|
strictFolders: params.opts.strictFolders !== false,
|
|
13
|
+
replaceWeb: typeof params.opts.replaceWeb === "string" ? params.opts.replaceWeb : undefined,
|
|
14
|
+
headTag: !!params.opts.headTag,
|
|
15
|
+
bodyTag: !!params.opts.bodyTag,
|
|
13
16
|
});
|
|
14
17
|
},
|
|
15
18
|
},
|
package/lib/jsx.js
CHANGED
|
@@ -209,6 +209,9 @@ function processConditions(conditions, internal, _default) {
|
|
|
209
209
|
function transformJsxElement(path, conditions, internal) {
|
|
210
210
|
const name = path.node.openingElement.name;
|
|
211
211
|
if (t.isJSXIdentifier(name) && name.name[0].toLowerCase() === name.name[0]) {
|
|
212
|
+
if ((name.name === "head" && !internal.headTag) || (name.name === "body" && !internal.bodyTag)) {
|
|
213
|
+
return [];
|
|
214
|
+
}
|
|
212
215
|
const opening = path.get("openingElement");
|
|
213
216
|
const attrs = [];
|
|
214
217
|
const events = [];
|
package/lib/transformer.js
CHANGED
|
@@ -62,17 +62,21 @@ function extractText(node) {
|
|
|
62
62
|
return node.name;
|
|
63
63
|
}
|
|
64
64
|
// Handles import declarations and updates internal state
|
|
65
|
-
function handleImportDeclaration(statementPath, internal, ids
|
|
65
|
+
function handleImportDeclaration(statementPath, internal, ids) {
|
|
66
66
|
const statement = statementPath.node;
|
|
67
67
|
const name = imports.get(statement.source.value);
|
|
68
68
|
if (!name)
|
|
69
69
|
return;
|
|
70
|
+
// replace the web import if is required
|
|
71
|
+
if (name === "VasilleWeb" && internal.replaceWeb) {
|
|
72
|
+
statement.source.value = internal.replaceWeb;
|
|
73
|
+
}
|
|
70
74
|
internal.prefix = name;
|
|
71
75
|
for (const specifier of statement.specifiers) {
|
|
72
76
|
/* istanbul ignore else */
|
|
73
77
|
if (t.isImportNamespaceSpecifier(specifier)) {
|
|
74
78
|
internal.global = specifier.local.name;
|
|
75
|
-
stylesConnected
|
|
79
|
+
internal.stylesConnected = true;
|
|
76
80
|
}
|
|
77
81
|
else if (t.isImportSpecifier(specifier)) {
|
|
78
82
|
const imported = extractText(specifier.imported);
|
|
@@ -85,7 +89,7 @@ function handleImportDeclaration(statementPath, internal, ids, used, stylesConne
|
|
|
85
89
|
}
|
|
86
90
|
internal.mapping.set(local, imported);
|
|
87
91
|
if (imported === "styleSheet") {
|
|
88
|
-
stylesConnected
|
|
92
|
+
internal.stylesConnected = true;
|
|
89
93
|
}
|
|
90
94
|
internal.importStatement = statementPath;
|
|
91
95
|
}
|
|
@@ -98,15 +102,15 @@ function handleImportDeclaration(statementPath, internal, ids, used, stylesConne
|
|
|
98
102
|
});
|
|
99
103
|
}
|
|
100
104
|
// Handles mesh and style transformation
|
|
101
|
-
function handleStatement(statementPath, internal
|
|
102
|
-
if (!stylesConnected || !(0, css_transformer_js_1.findStyleInNode)(statementPath, internal)) {
|
|
105
|
+
function handleStatement(statementPath, internal) {
|
|
106
|
+
if (!internal.stylesConnected || !(0, css_transformer_js_1.findStyleInNode)(statementPath, internal)) {
|
|
103
107
|
(0, mesh_js_1.meshStatement)(statementPath, internal);
|
|
104
108
|
}
|
|
105
109
|
}
|
|
106
110
|
// Handles import insertion and cleanup
|
|
107
111
|
function updateImports(path, internal, ids, used) {
|
|
108
112
|
if (used.size > 0 && !internal.importStatement && !internal.global) {
|
|
109
|
-
path.get("body")[0].insertBefore(t.importDeclaration([...used].map(name => t.importSpecifier(t.identifier(ids[name]), t.identifier(name))), t.stringLiteral("vasille-web")));
|
|
113
|
+
path.get("body")[0].insertBefore(t.importDeclaration([...used].map(name => t.importSpecifier(t.identifier(ids[name]), t.identifier(name))), t.stringLiteral(internal.replaceWeb ?? "vasille-web")));
|
|
110
114
|
}
|
|
111
115
|
if (used.size > 0 && !internal.global && internal.importStatement) {
|
|
112
116
|
const statementPath = internal.importStatement;
|
|
@@ -127,7 +131,6 @@ function updateImports(path, internal, ids, used) {
|
|
|
127
131
|
}
|
|
128
132
|
// Main transformer function
|
|
129
133
|
function transformProgram(path, filename, opts) {
|
|
130
|
-
const stylesConnected = { value: false };
|
|
131
134
|
const used = new Set();
|
|
132
135
|
const ids = {
|
|
133
136
|
ref: "VasilleRef",
|
|
@@ -157,8 +160,12 @@ function transformProgram(path, filename, opts) {
|
|
|
157
160
|
importStatement: null,
|
|
158
161
|
stateOnly: false,
|
|
159
162
|
filename,
|
|
163
|
+
stylesConnected: false,
|
|
160
164
|
devMode: opts.devMode,
|
|
161
165
|
strictFolders: opts.strictFolders,
|
|
166
|
+
replaceWeb: opts.replaceWeb,
|
|
167
|
+
headTag: opts.headTag,
|
|
168
|
+
bodyTag: opts.bodyTag,
|
|
162
169
|
ref: arg => call("ref", arg ? [arg] : []),
|
|
163
170
|
expr: (func, values) => call("expr", [getCtx(), func, values]),
|
|
164
171
|
forward: arg => call("forward", [getCtx(), arg]),
|
|
@@ -178,10 +185,10 @@ function transformProgram(path, filename, opts) {
|
|
|
178
185
|
for (const statementPath of path.get("body")) {
|
|
179
186
|
const statement = statementPath.node;
|
|
180
187
|
if (t.isImportDeclaration(statement)) {
|
|
181
|
-
handleImportDeclaration(statementPath, internal, ids
|
|
188
|
+
handleImportDeclaration(statementPath, internal, ids);
|
|
182
189
|
}
|
|
183
190
|
else {
|
|
184
|
-
handleStatement(statementPath, internal
|
|
191
|
+
handleStatement(statementPath, internal);
|
|
185
192
|
}
|
|
186
193
|
}
|
|
187
194
|
updateImports(path, internal, ids, used);
|