Skip to content

Commit 9734b31

Browse files
committed
fix(sfc): avoid auto name inference leading to unwanted recursion
fix #5965 fix #6027 fix #6029
1 parent 11e17a1 commit 9734b31

File tree

5 files changed

+15
-7
lines changed

5 files changed

+15
-7
lines changed

Diff for: packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
exports[`SFC analyze <script> bindings auto name inference basic 1`] = `
44
"export default {
5-
name: 'FooBar',
5+
__name: 'FooBar',
66
setup(__props, { expose }) {
77
expose();
88
const a = 1

Diff for: packages/compiler-sfc/__tests__/compileScript.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1650,7 +1650,7 @@ describe('SFC analyze <script> bindings', () => {
16501650
}
16511651
)
16521652
expect(content).toMatch(`export default {
1653-
name: 'FooBar'`)
1653+
__name: 'FooBar'`)
16541654
assertCode(content)
16551655
})
16561656

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1463,7 +1463,7 @@ export function compileScript(
14631463
if (!hasDefaultExportName && filename && filename !== DEFAULT_FILENAME) {
14641464
const match = filename.match(/([^/\\]+)\.\w+$/)
14651465
if (match) {
1466-
runtimeOptions += `\n name: '${match[1]}',`
1466+
runtimeOptions += `\n __name: '${match[1]}',`
14671467
}
14681468
}
14691469
if (hasInlinedSsrRenderFn) {

Diff for: packages/runtime-core/src/component.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ export interface ComponentInternalOptions {
106106
* This one should be exposed so that devtools can make use of it
107107
*/
108108
__file?: string
109+
/**
110+
* name inferred from filename
111+
*/
112+
__name?: string
109113
}
110114

111115
export interface FunctionalComponent<P = {}, E extends EmitsOptions = {}>
@@ -949,11 +953,12 @@ const classify = (str: string): string =>
949953
str.replace(classifyRE, c => c.toUpperCase()).replace(/[-_]/g, '')
950954

951955
export function getComponentName(
952-
Component: ConcreteComponent
953-
): string | undefined {
956+
Component: ConcreteComponent,
957+
includeInferred = true
958+
): string | false | undefined {
954959
return isFunction(Component)
955960
? Component.displayName || Component.name
956-
: Component.name
961+
: Component.name || (includeInferred && Component.__name)
957962
}
958963

959964
/* istanbul ignore next */

Diff for: packages/runtime-core/src/helpers/resolveAssets.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ function resolveAsset(
8686

8787
// explicit self name has highest priority
8888
if (type === COMPONENTS) {
89-
const selfName = getComponentName(Component)
89+
const selfName = getComponentName(
90+
Component,
91+
false /* do not include inferred name to avoid breaking existing code */
92+
)
9093
if (
9194
selfName &&
9295
(selfName === name ||

0 commit comments

Comments
 (0)