Skip to content

Can't use compiler in strict mode #8145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dborstelmann opened this issue May 7, 2018 · 4 comments
Closed

Can't use compiler in strict mode #8145

dborstelmann opened this issue May 7, 2018 · 4 comments

Comments

@dborstelmann
Copy link

dborstelmann commented May 7, 2018

What problem does this feature solve?

We cannot use the compiler in strict mode because it uses the with statement.

https://github.com/vuejs/vue/blob/master/src/compiler/codegen/index.js#L47

I have to compile templates in the browser at run time in strict mode. Anybody have a solution for this?

What does the proposed API look like?

Change all with statements to another solution.

@yyx990803
Copy link
Member

yyx990803 commented May 7, 2018

The compiler works fine in strict mode. Or maybe you mean you have a strict CSP? Either way, you need to provide more information or a reproduction because the in-browser compilation works regardless of strict mode or not.

The below works:

'use strict'
const f = new Function('with (this) { console.log("foo") }')
f() // works

@dborstelmann
Copy link
Author

@yyx990803 I posted this issue before seeing #3832. That gave me much more clarity, and I did the hack that was suggested there which caused my code to work. However I did not try the new Function syntax, does that make strict mode work?

@dborstelmann
Copy link
Author

I’m also working in salesforce on the same problem as described above in the other issue. I am using run-time compilation. I was getting the error because of the with keyword. If I add new Function around the with keyword to the library will that work? And is there a better practice way to do this?

@dborstelmann
Copy link
Author

dborstelmann commented May 8, 2018

@yyx990803 I changed the main Vue code to this:

return {
    render: new Function("with(this){ return " + code + "}"),
    staticRenderFns: state.staticRenderFns
  }

Salesforce still threw an error saying "Strict mode code may not include a with statement"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants