olum-compiler 1.9.4 → 1.9.6
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/bin/bundle.js +2 -0
- package/bin/copySrc.js +6 -1
- package/lib/changes.txt +8 -8
- package/lib/events.js +9 -7
- package/lib/helpers.js +3 -3
- package/lib/parser.js +8 -12
- package/package.json +1 -1
- package/tests/compiler.test.js +7 -2
package/bin/bundle.js
CHANGED
package/bin/copySrc.js
CHANGED
|
@@ -31,9 +31,14 @@ function injectIndexHtml(indexHtmlPath) {
|
|
|
31
31
|
|
|
32
32
|
const importMapTag =
|
|
33
33
|
process.env.NODE_ENV === "production" ? "" : `${importMap(entryPoint)}\n`;
|
|
34
|
+
|
|
35
|
+
const devFlagTag =
|
|
36
|
+
process.env.NODE_ENV === "production"
|
|
37
|
+
? ""
|
|
38
|
+
: `<script>globalThis.__OLUM_DEV__ = true;</script>\n`;
|
|
34
39
|
indexHtmlContent = indexHtmlContent.replace(
|
|
35
40
|
/<\/body>/,
|
|
36
|
-
`\n<div id="app"></div>\n${importMapTag}<script defer type="module" src="../src/main.js"></script>\n${devtoolScriptContent}</body>`,
|
|
41
|
+
`\n<div id="app"></div>\n${devFlagTag}${importMapTag}<script defer type="module" src="../src/main.js"></script>\n${devtoolScriptContent}</body>`,
|
|
37
42
|
);
|
|
38
43
|
fs.writeFileSync(indexHtmlPath, indexHtmlContent);
|
|
39
44
|
}
|
package/lib/changes.txt
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
change /tmp/olum-dev-test-
|
|
2
|
-
change /tmp/olum-dev-test-
|
|
3
|
-
addDir /tmp/olum-dev-test-
|
|
4
|
-
add /tmp/olum-dev-test-
|
|
5
|
-
unlink /tmp/olum-dev-test-
|
|
6
|
-
unlinkDir /tmp/olum-dev-test-
|
|
7
|
-
change /tmp/olum-dev-test-
|
|
8
|
-
change /tmp/olum-dev-test-
|
|
1
|
+
change /tmp/olum-dev-test-bTmY24/src/page.html
|
|
2
|
+
change /tmp/olum-dev-test-bTmY24/public/main.css
|
|
3
|
+
addDir /tmp/olum-dev-test-bTmY24/src/blog
|
|
4
|
+
add /tmp/olum-dev-test-bTmY24/src/blog/page.html
|
|
5
|
+
unlink /tmp/olum-dev-test-bTmY24/src/blog/page.html
|
|
6
|
+
unlinkDir /tmp/olum-dev-test-bTmY24/src/blog
|
|
7
|
+
change /tmp/olum-dev-test-bTmY24/src/util.js
|
|
8
|
+
change /tmp/olum-dev-test-bTmY24/src/page.html
|
package/lib/events.js
CHANGED
|
@@ -134,19 +134,21 @@ function handleEvents(body, counter, filePath, anonHandlers, propsAliases) {
|
|
|
134
134
|
return str.replace(/\$event/g, "'$event'");
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
+
const encodeArgs = (args) =>
|
|
138
|
+
"${encodeURIComponent(JSON.stringify([" +
|
|
139
|
+
args +
|
|
140
|
+
"])).replace(/'/g,'%27')}";
|
|
141
|
+
|
|
137
142
|
let chain = e + "|";
|
|
138
143
|
methodsNames.forEach((item, index) => {
|
|
139
144
|
if (index === methodsNames.length - 1)
|
|
140
145
|
return (chain +=
|
|
141
146
|
item +
|
|
142
|
-
"
|
|
143
|
-
handle$event(methodsArgs[index]) +
|
|
144
|
-
"
|
|
147
|
+
"=" +
|
|
148
|
+
encodeArgs(handle$event(methodsArgs[index])) +
|
|
149
|
+
"-]]-");
|
|
145
150
|
chain +=
|
|
146
|
-
item +
|
|
147
|
-
"=${JSON.stringify([" +
|
|
148
|
-
handle$event(methodsArgs[index]) +
|
|
149
|
-
"])}&";
|
|
151
|
+
item + "=" + encodeArgs(handle$event(methodsArgs[index])) + "&";
|
|
150
152
|
});
|
|
151
153
|
|
|
152
154
|
chain = chain.replace(/{/g, "<-olum->");
|
package/lib/helpers.js
CHANGED
|
@@ -312,7 +312,7 @@ function createScopeHandler({
|
|
|
312
312
|
if (hasState && isFullArr(stateProps)) {
|
|
313
313
|
let fragments = stateProps.map((prop) => prop + ": state." + prop);
|
|
314
314
|
arr.push(
|
|
315
|
-
`get state(){return
|
|
315
|
+
`get state(){return olum.proxyHandlerForScope(${"{" + fragments.join(",") + "}"}, state);}`,
|
|
316
316
|
);
|
|
317
317
|
}
|
|
318
318
|
return arr;
|
|
@@ -365,7 +365,7 @@ function createScopeHandler({
|
|
|
365
365
|
(prop) => prop + ": state." + prop,
|
|
366
366
|
);
|
|
367
367
|
arr.push(
|
|
368
|
-
`get state(){return
|
|
368
|
+
`get state(){return olum.proxyHandlerForScope(${"{" + fragments.join(",") + "}"}, state);}`,
|
|
369
369
|
);
|
|
370
370
|
}
|
|
371
371
|
}
|
|
@@ -407,7 +407,7 @@ function createScopeHandler({
|
|
|
407
407
|
(prop) => prop + ": state." + prop,
|
|
408
408
|
);
|
|
409
409
|
arr.push(
|
|
410
|
-
`get state(){return
|
|
410
|
+
`get state(){return olum.proxyHandlerForScope(${"{" + fragments.join(",") + "}"}, state);}`,
|
|
411
411
|
);
|
|
412
412
|
}
|
|
413
413
|
}
|
package/lib/parser.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
const isDev = true;
|
|
2
|
-
|
|
3
1
|
const splitSFC = require("./sfc");
|
|
4
2
|
const htmlParser = require("./htmlParser");
|
|
5
3
|
const cssParser = require("./cssParser");
|
|
@@ -21,6 +19,8 @@ const createSourceMap = require("./sourcemap");
|
|
|
21
19
|
const liveProps = require("./liveProps");
|
|
22
20
|
const usage = require("./usage");
|
|
23
21
|
|
|
22
|
+
const RUNTIME_IMPORT = `import __olumPkg from "olum";const olum=__olumPkg.__olum||window.olum;`;
|
|
23
|
+
|
|
24
24
|
const parser = (str, counter, filePath) => {
|
|
25
25
|
const sfc = splitSFC(str, filePath);
|
|
26
26
|
|
|
@@ -202,15 +202,11 @@ const parser = (str, counter, filePath) => {
|
|
|
202
202
|
__OLUM__: olum_${currentID},
|
|
203
203
|
el: el_${currentID},
|
|
204
204
|
methodsRef: methods_${currentID},
|
|
205
|
-
|
|
206
|
-
${
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
.map((name) => `get ${name}(){return ${name}}`)
|
|
211
|
-
.join(",")}},`
|
|
212
|
-
: ""
|
|
213
|
-
}
|
|
205
|
+
stateProps: ${hasState ? "state" : "null"},
|
|
206
|
+
localsRef: {${globalProps
|
|
207
|
+
.filter((name) => name !== "state")
|
|
208
|
+
.map((name) => `get ${name}(){return ${name}}`)
|
|
209
|
+
.join(",")}},
|
|
214
210
|
hooks: {
|
|
215
211
|
mounted: typeof mounted !== "undefined" ? mounted : null,
|
|
216
212
|
unMounted: null,
|
|
@@ -218,7 +214,7 @@ const parser = (str, counter, filePath) => {
|
|
|
218
214
|
isUnMounted: false,
|
|
219
215
|
}
|
|
220
216
|
};
|
|
221
|
-
}
|
|
217
|
+
};${RUNTIME_IMPORT}`;
|
|
222
218
|
|
|
223
219
|
try {
|
|
224
220
|
out = liveProps(out);
|
package/package.json
CHANGED
package/tests/compiler.test.js
CHANGED
|
@@ -22,6 +22,10 @@ function compile(template) {
|
|
|
22
22
|
function parses(out) {
|
|
23
23
|
const body = out
|
|
24
24
|
.replace(/^\s*import .*$/gm, "")
|
|
25
|
+
.replace(
|
|
26
|
+
/import __olumPkg from "olum";const olum=__olumPkg\.__olum\|\|window\.olum;/g,
|
|
27
|
+
"",
|
|
28
|
+
)
|
|
25
29
|
.replace(/^\s*export\s+default\s+/m, "const __x=");
|
|
26
30
|
new Function(body);
|
|
27
31
|
return true;
|
|
@@ -277,8 +281,9 @@ check(
|
|
|
277
281
|
"$event is forwarded to the handler",
|
|
278
282
|
comp(`<input oninput="setVal($event)" />`, `const setVal = (e) => 0;`),
|
|
279
283
|
(out) =>
|
|
280
|
-
/oninput\|setVal=\$\{JSON\.stringify\(\['\$event'\]\)\
|
|
281
|
-
|
|
284
|
+
/oninput\|setVal=\$\{encodeURIComponent\(JSON\.stringify\(\['\$event'\]\)\)/.test(
|
|
285
|
+
tmpl(out),
|
|
286
|
+
) && parses(out),
|
|
282
287
|
);
|
|
283
288
|
check(
|
|
284
289
|
"inline arrow handler becomes a named __olumAnon_ method",
|