Skip to content

Commit bd8409b

Browse files
committed
wip: fix component resolution check
1 parent aa2b1f4 commit bd8409b

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

Diff for: packages/compiler-sfc/src/prefixIdentifiers.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ export function prefixIdentifiers(
3939
plugins
4040
})
4141

42+
const isScriptSetup = bindings && bindings.__isScriptSetup !== false
43+
4244
walkIdentifiers(
4345
ast,
4446
ident => {
@@ -47,7 +49,7 @@ export function prefixIdentifiers(
4749
return
4850
}
4951

50-
if (!bindings) {
52+
if (!isScriptSetup) {
5153
s.prependRight(ident.start!, '_vm.')
5254
return
5355
}
@@ -62,7 +64,7 @@ export function prefixIdentifiers(
6264
s.prependRight(
6365
node.start!,
6466
`var _vm=this,_c=_vm._self._c${
65-
bindings ? `,_setup=_vm._setupProxy;` : `;`
67+
isScriptSetup ? `,_setup=_vm._setupProxy;` : `;`
6668
}`
6769
)
6870
}

Diff for: src/compiler/codegen/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export function genElement(el: ASTElement, state: CodegenState): string {
102102
let tag: string | undefined
103103
// check if this is a component in <script setup>
104104
const bindings = state.options.bindings
105-
if (bindings && !bindings.__isScriptSetup) {
105+
if (bindings && bindings.__isScriptSetup !== false) {
106106
tag =
107107
checkBindingType(bindings, el.tag) ||
108108
checkBindingType(bindings, camelize(el.tag)) ||

Diff for: test/unit/modules/compiler/codegen.spec.ts

+20-6
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import { generate } from 'compiler/codegen'
44
import { isObject, isFunction, extend } from 'shared/util'
55
import { isReservedTag } from 'web/util/index'
66
import { baseOptions } from 'web/compiler/options'
7+
import { BindingTypes } from '../../../../packages/compiler-sfc/src/types'
78

89
function assertCodegen(template, generatedCode, ...args) {
9-
let staticRenderFnCodes = []
10+
let staticRenderFnCodes: string[] = []
1011
let generateOptions = baseOptions
11-
let proc = null
12+
let proc: Function | null = null
1213
let len = args.length
1314
while (len--) {
1415
const arg = args[len]
@@ -28,7 +29,6 @@ function assertCodegen(template, generatedCode, ...args) {
2829
expect(res.staticRenderFns).toEqual(staticRenderFnCodes)
2930
}
3031

31-
/* eslint-disable quotes */
3232
describe('codegen', () => {
3333
it('generate directive', () => {
3434
assertCodegen(
@@ -624,7 +624,7 @@ describe('codegen', () => {
624624
expect(
625625
'Inline-template components must have exactly one child element.'
626626
).toHaveBeenWarned()
627-
expect(console.error.mock.calls.length).toBe(3)
627+
expect((console.error as any).mock.calls.length).toBe(3)
628628
})
629629

630630
it('generate static trees inside v-for', () => {
@@ -689,7 +689,7 @@ describe('codegen', () => {
689689
})
690690

691691
it('not specified ast type', () => {
692-
const res = generate(null, baseOptions)
692+
const res = generate(undefined, baseOptions)
693693
expect(res.render).toBe(`with(this){return _c("div")}`)
694694
expect(res.staticRenderFns).toEqual([])
695695
})
@@ -709,5 +709,19 @@ describe('codegen', () => {
709709
`with(this){return _c('div',[(ok)?_l((1),function(i){return _c('foo',{key:i})}):_e()],2)}`
710710
)
711711
})
712+
713+
it('component with bindings ', () => {
714+
const ast = parse(`<div><Foo/><foo-bar></foo-bar></div>`, baseOptions)
715+
optimize(ast, baseOptions)
716+
const res = generate(ast, {
717+
...baseOptions,
718+
bindings: {
719+
Foo: BindingTypes.SETUP_CONST,
720+
FooBar: BindingTypes.SETUP_CONST
721+
}
722+
})
723+
expect(res.render).toMatchInlineSnapshot(
724+
'"with(this){return _c(\'div\',[_c(Foo),_c(FooBar)],1)}"'
725+
)
726+
})
712727
})
713-
/* eslint-enable quotes */

0 commit comments

Comments
 (0)