|
|
@@ -11,7 +11,7 @@ import {
|
|
|
isFunctionType,
|
|
|
walkIdentifiers
|
|
|
} from '@vue/compiler-dom'
|
|
|
-import { SFCDescriptor, SFCScriptBlock } from './parse'
|
|
|
+import { DEFAULT_FILENAME, SFCDescriptor, SFCScriptBlock } from './parse'
|
|
|
import { parse as _parse, ParserOptions, ParserPlugin } from '@babel/parser'
|
|
|
import { camelize, capitalize, generateCodeFrame, makeMap } from '@vue/shared'
|
|
|
import {
|
|
|
@@ -263,6 +263,7 @@ export function compileScript(
|
|
|
let hasDefinePropsCall = false
|
|
|
let hasDefineEmitCall = false
|
|
|
let hasDefineExposeCall = false
|
|
|
+ let hasDefaultExportName = false
|
|
|
let propsRuntimeDecl: Node | undefined
|
|
|
let propsRuntimeDefaults: ObjectExpression | undefined
|
|
|
let propsDestructureDecl: Node | undefined
|
|
|
@@ -811,6 +812,25 @@ export function compileScript(
|
|
|
} else if (node.type === 'ExportDefaultDeclaration') {
|
|
|
// export default
|
|
|
defaultExport = node
|
|
|
+
|
|
|
+ // check if user has manually specified `name` option in export default
|
|
|
+ // if yes, skip infer later
|
|
|
+ let optionProperties
|
|
|
+ if (defaultExport.declaration.type === 'ObjectExpression') {
|
|
|
+ optionProperties = defaultExport.declaration.properties
|
|
|
+ } else if (
|
|
|
+ defaultExport.declaration.type === 'CallExpression' &&
|
|
|
+ defaultExport.declaration.arguments[0].type === 'ObjectExpression'
|
|
|
+ ) {
|
|
|
+ optionProperties = defaultExport.declaration.arguments[0].properties
|
|
|
+ }
|
|
|
+ hasDefaultExportName = !!optionProperties?.some(
|
|
|
+ s =>
|
|
|
+ s.type === 'ObjectProperty' &&
|
|
|
+ s.key.type === 'Identifier' &&
|
|
|
+ s.key.name === 'name'
|
|
|
+ )
|
|
|
+
|
|
|
// export default { ... } --> const __default__ = { ... }
|
|
|
const start = node.start! + scriptStartOffset!
|
|
|
const end = node.declaration.start! + scriptStartOffset!
|
|
|
@@ -1364,6 +1384,12 @@ export function compileScript(
|
|
|
|
|
|
// 11. finalize default export
|
|
|
let runtimeOptions = ``
|
|
|
+ if (!hasDefaultExportName && filename && filename !== DEFAULT_FILENAME) {
|
|
|
+ const match = filename.match(/([^/\\]+)\.\w+$/)
|
|
|
+ if (match) {
|
|
|
+ runtimeOptions += `\n name: '${match[1]}',`
|
|
|
+ }
|
|
|
+ }
|
|
|
if (hasInlinedSsrRenderFn) {
|
|
|
runtimeOptions += `\n __ssrInlineRender: true,`
|
|
|
}
|