@@ -11,7 +11,7 @@ import {
11
11
isFunctionType ,
12
12
walkIdentifiers
13
13
} from '@vue/compiler-dom'
14
- import { SFCDescriptor , SFCScriptBlock } from './parse'
14
+ import { DEFAULT_FILENAME , SFCDescriptor , SFCScriptBlock } from './parse'
15
15
import { parse as _parse , ParserOptions , ParserPlugin } from '@babel/parser'
16
16
import { camelize , capitalize , generateCodeFrame , makeMap } from '@vue/shared'
17
17
import {
@@ -263,6 +263,7 @@ export function compileScript(
263
263
let hasDefinePropsCall = false
264
264
let hasDefineEmitCall = false
265
265
let hasDefineExposeCall = false
266
+ let hasDefaultExportName = false
266
267
let propsRuntimeDecl : Node | undefined
267
268
let propsRuntimeDefaults : ObjectExpression | undefined
268
269
let propsDestructureDecl : Node | undefined
@@ -811,6 +812,25 @@ export function compileScript(
811
812
} else if ( node . type === 'ExportDefaultDeclaration' ) {
812
813
// export default
813
814
defaultExport = node
815
+
816
+ // check if user has manually specified `name` option in export default
817
+ // if yes, skip infer later
818
+ let optionProperties
819
+ if ( defaultExport . declaration . type === 'ObjectExpression' ) {
820
+ optionProperties = defaultExport . declaration . properties
821
+ } else if (
822
+ defaultExport . declaration . type === 'CallExpression' &&
823
+ defaultExport . declaration . arguments [ 0 ] . type === 'ObjectExpression'
824
+ ) {
825
+ optionProperties = defaultExport . declaration . arguments [ 0 ] . properties
826
+ }
827
+ hasDefaultExportName = ! ! optionProperties ?. some (
828
+ s =>
829
+ s . type === 'ObjectProperty' &&
830
+ s . key . type === 'Identifier' &&
831
+ s . key . name === 'name'
832
+ )
833
+
814
834
// export default { ... } --> const __default__ = { ... }
815
835
const start = node . start ! + scriptStartOffset !
816
836
const end = node . declaration . start ! + scriptStartOffset !
@@ -1364,6 +1384,12 @@ export function compileScript(
1364
1384
1365
1385
// 11. finalize default export
1366
1386
let runtimeOptions = ``
1387
+ if ( ! hasDefaultExportName && filename && filename !== DEFAULT_FILENAME ) {
1388
+ const match = filename . match ( / ( [ ^ / \\ ] + ) \. \w + $ / )
1389
+ if ( match ) {
1390
+ runtimeOptions += `\n name: '${ match [ 1 ] } ',`
1391
+ }
1392
+ }
1367
1393
if ( hasInlinedSsrRenderFn ) {
1368
1394
runtimeOptions += `\n __ssrInlineRender: true,`
1369
1395
}
0 commit comments