fix(compiler-sfc): do not resolve assets from setup bindings
when not using script setup fix #3270, fix #3275
This commit is contained in:
@@ -2,7 +2,8 @@ import {
|
||||
CompilerOptions,
|
||||
baseParse as parse,
|
||||
transform,
|
||||
ErrorCodes
|
||||
ErrorCodes,
|
||||
BindingTypes
|
||||
} from '../../src'
|
||||
import {
|
||||
RESOLVE_COMPONENT,
|
||||
@@ -78,6 +79,28 @@ describe('compiler: element transform', () => {
|
||||
expect(root.components).toContain(`Example__self`)
|
||||
})
|
||||
|
||||
test('resolve component from setup bindings', () => {
|
||||
const { root, node } = parseWithElementTransform(`<Example/>`, {
|
||||
bindingMetadata: {
|
||||
Example: BindingTypes.SETUP_MAYBE_REF
|
||||
}
|
||||
})
|
||||
expect(root.helpers).not.toContain(RESOLVE_COMPONENT)
|
||||
expect(node.tag).toBe(`$setup["Example"]`)
|
||||
})
|
||||
|
||||
test('do not resolve component from non-script-setup bindings', () => {
|
||||
const bindingMetadata = {
|
||||
Example: BindingTypes.SETUP_MAYBE_REF
|
||||
}
|
||||
Object.defineProperty(bindingMetadata, '__isScriptSetup', { value: false })
|
||||
const { root } = parseWithElementTransform(`<Example/>`, {
|
||||
bindingMetadata
|
||||
})
|
||||
expect(root.helpers).toContain(RESOLVE_COMPONENT)
|
||||
expect(root.components).toContain(`Example`)
|
||||
})
|
||||
|
||||
test('static props', () => {
|
||||
const { node } = parseWithElementTransform(`<div id="foo" class="bar" />`)
|
||||
expect(node).toMatchObject({
|
||||
|
||||
@@ -94,8 +94,10 @@ export const enum BindingTypes {
|
||||
OPTIONS = 'options'
|
||||
}
|
||||
|
||||
export interface BindingMetadata {
|
||||
export type BindingMetadata = {
|
||||
[key: string]: BindingTypes | undefined
|
||||
} & {
|
||||
__isScriptSetup?: boolean
|
||||
}
|
||||
|
||||
interface SharedTransformCodegenOptions {
|
||||
|
||||
@@ -286,7 +286,7 @@ export function resolveComponentType(
|
||||
|
||||
function resolveSetupReference(name: string, context: TransformContext) {
|
||||
const bindings = context.bindingMetadata
|
||||
if (!bindings) {
|
||||
if (!bindings || bindings.__isScriptSetup === false) {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user