Skip to content

Commit

Permalink
fix(compiler): fix the bug 'root level <script> tags will be executed…
Browse files Browse the repository at this point in the history
…' at the compilation level

fix #11483
  • Loading branch information
shadowings-zy committed Jul 3, 2020
1 parent 8ead9d2 commit ef2ec03
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/compiler/codegen/index.js
Expand Up @@ -45,7 +45,7 @@ export function generate (
options: CompilerOptions
): CodegenResult {
const state = new CodegenState(options)
const code = ast ? genElement(ast, state) : '_c("div")'
const code = ast ? (ast.tag === 'script' ? 'null' : genElement(ast, state) ) : '_c("div")'
return {
render: `with(this){return ${code}}`,
staticRenderFns: state.staticRenderFns
Expand Down
13 changes: 13 additions & 0 deletions test/unit/features/component/component.spec.js
Expand Up @@ -426,4 +426,17 @@ describe('Component', () => {
vm.$destroy()
}).then(done)
})

it('render vnode with <script> tag as root element', () => {
const vm = new Vue({
template: '<scriptTest></scriptTest>',
components: {
scriptTest: {
template: '<script>console.log(1)</script>'
}
}
}).$mount()
expect(vm.$el.nodeName).toBe('#comment')
expect('Templates should only be responsible for mapping the state').toHaveBeenWarned()
})
})

0 comments on commit ef2ec03

Please sign in to comment.