fix(codegen): ensure valid types in genreated code when using global directives
fix #4054
This commit is contained in:
parent
12cf9f4ea1
commit
a44d528af1
@ -68,10 +68,7 @@ export interface CodegenResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface CodegenContext
|
export interface CodegenContext
|
||||||
extends Omit<
|
extends Omit<Required<CodegenOptions>, 'bindingMetadata' | 'inline'> {
|
||||||
Required<CodegenOptions>,
|
|
||||||
'bindingMetadata' | 'inline' | 'isTS'
|
|
||||||
> {
|
|
||||||
source: string
|
source: string
|
||||||
code: string
|
code: string
|
||||||
line: number
|
line: number
|
||||||
@ -98,7 +95,8 @@ function createCodegenContext(
|
|||||||
optimizeImports = false,
|
optimizeImports = false,
|
||||||
runtimeGlobalName = `Vue`,
|
runtimeGlobalName = `Vue`,
|
||||||
runtimeModuleName = `vue`,
|
runtimeModuleName = `vue`,
|
||||||
ssr = false
|
ssr = false,
|
||||||
|
isTS = false
|
||||||
}: CodegenOptions
|
}: CodegenOptions
|
||||||
): CodegenContext {
|
): CodegenContext {
|
||||||
const context: CodegenContext = {
|
const context: CodegenContext = {
|
||||||
@ -111,6 +109,7 @@ function createCodegenContext(
|
|||||||
runtimeGlobalName,
|
runtimeGlobalName,
|
||||||
runtimeModuleName,
|
runtimeModuleName,
|
||||||
ssr,
|
ssr,
|
||||||
|
isTS,
|
||||||
source: ast.loc.source,
|
source: ast.loc.source,
|
||||||
code: ``,
|
code: ``,
|
||||||
column: 1,
|
column: 1,
|
||||||
@ -466,7 +465,7 @@ function genModulePreamble(
|
|||||||
function genAssets(
|
function genAssets(
|
||||||
assets: string[],
|
assets: string[],
|
||||||
type: 'component' | 'directive' | 'filter',
|
type: 'component' | 'directive' | 'filter',
|
||||||
{ helper, push, newline }: CodegenContext
|
{ helper, push, newline, isTS }: CodegenContext
|
||||||
) {
|
) {
|
||||||
const resolver = helper(
|
const resolver = helper(
|
||||||
__COMPAT__ && type === 'filter'
|
__COMPAT__ && type === 'filter'
|
||||||
@ -485,7 +484,7 @@ function genAssets(
|
|||||||
push(
|
push(
|
||||||
`const ${toValidAssetId(id, type)} = ${resolver}(${JSON.stringify(id)}${
|
`const ${toValidAssetId(id, type)} = ${resolver}(${JSON.stringify(id)}${
|
||||||
maybeSelfReference ? `, true` : ``
|
maybeSelfReference ? `, true` : ``
|
||||||
})`
|
})${isTS ? `!` : ``}`
|
||||||
)
|
)
|
||||||
if (i < assets.length - 1) {
|
if (i < assets.length - 1) {
|
||||||
newline()
|
newline()
|
||||||
|
Loading…
Reference in New Issue
Block a user