CompilerOptions,
baseParse as parse,
transform,
- ErrorCodes
+ ErrorCodes,
+ BindingTypes
} from '../../src'
import {
RESOLVE_COMPONENT,
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({
OPTIONS = 'options'
}
-export interface BindingMetadata {
+export type BindingMetadata = {
[key: string]: BindingTypes | undefined
+} & {
+ __isScriptSetup?: boolean
}
interface SharedTransformCodegenOptions {
function resolveSetupReference(name: string, context: TransformContext) {
const bindings = context.bindingMetadata
- if (!bindings) {
+ if (!bindings || bindings.__isScriptSetup === false) {
return
}
expect(scriptAst).toBeDefined()
})
+
it('recognizes props array declaration', () => {
const { bindings } = compile(`
<script>
foo: BindingTypes.PROPS,
bar: BindingTypes.PROPS
})
+ expect(bindings!.__isScriptSetup).toBe(false)
})
it('recognizes props object declaration', () => {
baz: BindingTypes.PROPS,
qux: BindingTypes.PROPS
})
+ expect(bindings!.__isScriptSetup).toBe(false)
})
it('recognizes setup return', () => {
foo: BindingTypes.SETUP_MAYBE_REF,
bar: BindingTypes.SETUP_MAYBE_REF
})
+ expect(bindings!.__isScriptSetup).toBe(false)
})
it('recognizes async setup return', () => {
foo: BindingTypes.SETUP_MAYBE_REF,
bar: BindingTypes.SETUP_MAYBE_REF
})
+ expect(bindings!.__isScriptSetup).toBe(false)
})
it('recognizes data return', () => {
function analyzeBindingsFromOptions(node: ObjectExpression): BindingMetadata {
const bindings: BindingMetadata = {}
+ // #3270, #3275
+ // mark non-script-setup so we don't resolve components/directives from these
+ Object.defineProperty(bindings, '__isScriptSetup', {
+ enumerable: false,
+ value: false
+ })
for (const property of node.properties) {
if (
property.type === 'ObjectProperty' &&