mirror of https://github.com/vuejs/core.git
fix(compiler-sfc): fix dev regression for dot / namespace component usage
close #9947
This commit is contained in:
parent
63c3e621ce
commit
dce99c12df
|
@ -79,6 +79,21 @@ return { get FooBar() { return FooBar }, get foo() { return foo }, get bar() { r
|
|||
})"
|
||||
`;
|
||||
|
||||
exports[`import namespace 1`] = `
|
||||
"import { defineComponent as _defineComponent } from 'vue'
|
||||
import * as Foo from './foo'
|
||||
|
||||
export default /*#__PURE__*/_defineComponent({
|
||||
setup(__props, { expose: __expose }) {
|
||||
__expose();
|
||||
|
||||
|
||||
return { get Foo() { return Foo } }
|
||||
}
|
||||
|
||||
})"
|
||||
`;
|
||||
|
||||
exports[`js template string interpolations 1`] = `
|
||||
"import { defineComponent as _defineComponent } from 'vue'
|
||||
import { VAR, VAR2, VAR3 } from './x'
|
||||
|
|
|
@ -219,3 +219,17 @@ test('property access (whitespace)', () => {
|
|||
expect(content).toMatch('return { get Foo() { return Foo } }')
|
||||
assertCode(content)
|
||||
})
|
||||
|
||||
// #9974
|
||||
test('namespace / dot component usage', () => {
|
||||
const { content } = compile(`
|
||||
<script setup lang="ts">
|
||||
import * as Foo from './foo'
|
||||
</script>
|
||||
<template>
|
||||
<Foo.Bar />
|
||||
</template>
|
||||
`)
|
||||
expect(content).toMatch('return { get Foo() { return Foo } }')
|
||||
assertCode(content)
|
||||
})
|
||||
|
|
|
@ -16,12 +16,12 @@ import { camelize, capitalize, isBuiltInDirective } from '@vue/shared'
|
|||
* when not using inline mode.
|
||||
*/
|
||||
export function isImportUsed(local: string, sfc: SFCDescriptor): boolean {
|
||||
return resolveTemplateUsageCheckString(sfc).has(local)
|
||||
return resolveTemplateUsedIdentifiers(sfc).has(local)
|
||||
}
|
||||
|
||||
const templateUsageCheckCache = createCache<Set<string>>()
|
||||
|
||||
function resolveTemplateUsageCheckString(sfc: SFCDescriptor) {
|
||||
function resolveTemplateUsedIdentifiers(sfc: SFCDescriptor): Set<string> {
|
||||
const { content, ast } = sfc.template!
|
||||
const cached = templateUsageCheckCache.get(content)
|
||||
if (cached) {
|
||||
|
@ -35,12 +35,14 @@ function resolveTemplateUsageCheckString(sfc: SFCDescriptor) {
|
|||
function walk(node: TemplateChildNode) {
|
||||
switch (node.type) {
|
||||
case NodeTypes.ELEMENT:
|
||||
let tag = node.tag
|
||||
if (tag.includes('.')) tag = tag.split('.')[0].trim()
|
||||
if (
|
||||
!parserOptions.isNativeTag!(node.tag) &&
|
||||
!parserOptions.isBuiltInComponent!(node.tag)
|
||||
!parserOptions.isNativeTag!(tag) &&
|
||||
!parserOptions.isBuiltInComponent!(tag)
|
||||
) {
|
||||
ids.add(camelize(node.tag))
|
||||
ids.add(capitalize(camelize(node.tag)))
|
||||
ids.add(camelize(tag))
|
||||
ids.add(capitalize(camelize(tag)))
|
||||
}
|
||||
for (let i = 0; i < node.props.length; i++) {
|
||||
const prop = node.props[i]
|
||||
|
|
Loading…
Reference in New Issue