Skip to content

Commit

Permalink
fix(codegen): script setup should not attempt to resolve native eleme…
Browse files Browse the repository at this point in the history
…nts as component

fix #12674
  • Loading branch information
yyx990803 committed Jul 16, 2022
1 parent 67760f8 commit e8d3a7d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/compiler/codegen/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,15 @@ export function genElement(el: ASTElement, state: CodegenState): string {
code = genComponent(el.component, el, state)
} else {
let data
if (!el.plain || (el.pre && state.maybeComponent(el))) {
const maybeComponent = state.maybeComponent(el)
if (!el.plain || (el.pre && maybeComponent)) {
data = genData(el, state)
}

let tag: string | undefined
// check if this is a component in <script setup>
const bindings = state.options.bindings
if (bindings && bindings.__isScriptSetup !== false) {
if (maybeComponent && bindings && bindings.__isScriptSetup !== false) {
tag =
checkBindingType(bindings, el.tag) ||
checkBindingType(bindings, camelize(el.tag)) ||
Expand Down
16 changes: 16 additions & 0 deletions test/unit/modules/compiler/codegen.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -724,4 +724,20 @@ describe('codegen', () => {
'"with(this){return _c(\'div\',[_c(Foo),_c(FooBar)],1)}"'
)
})

// #12674
it('component with bindings: should not resolve native elements', () => {
const ast = parse(`<div><form>{{ n }}</form></div>`, baseOptions)
optimize(ast, baseOptions)
const res = generate(ast, {
...baseOptions,
bindings: {
form: BindingTypes.SETUP_CONST
}
})
expect(res.render).toMatch(`_c('form'`)
expect(res.render).toMatchInlineSnapshot(
"\"with(this){return _c('div',[_c('form',[_v(_s(n))])])}\""
)
})
})

0 comments on commit e8d3a7d

Please sign in to comment.