Skip to content
This repository was archived by the owner on Jan 18, 2022. It is now read-only.

Commit b3b4c3d

Browse files
committed
Replace with statements before returning them
1 parent 3f488e3 commit b3b4c3d

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ export default function vue(options = {}) {
2727
// Component javascript with inlined html template
2828
return js;
2929
},
30-
ongenerate(opts) {
30+
ongenerate(opts, rendered) {
31+
// Put with statements back
32+
rendered.code = rendered.code.replace(/if\s*\("__VUE_WITH__"\)/g, 'with(this)');
3133
if (options.css === false) {
3234
return;
3335
}

src/vueTransform.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ function injectRender(script, render) {
5050
const matches = /(export default[^{]*\{)/g.exec(script);
5151
if (matches) {
5252
function toFunction (code) {
53-
return `function(){${code}}`;
53+
// Replace with(this) by something that works on strict mode
54+
// https://github.com/vuejs/vue-template-es2015-compiler/blob/master/index.js
55+
return `function(){${code.replace(/with\(this\)/g, 'if("__VUE_WITH__")')}}`;
5456
}
5557
return script.split(matches[1])
5658
.join(`${matches[1]} render: ${toFunction(render.render)}, staticRenderFns: [${render.staticRenderFns.map(toFunction).join(',')}],`);

0 commit comments

Comments
 (0)