Skip to content

Commit

Permalink
fix(codegen): ensure valid types in genreated code when using global …
Browse files Browse the repository at this point in the history
…directives

fix #4054
  • Loading branch information
yyx990803 committed Jul 2, 2021
1 parent 12cf9f4 commit a44d528
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions packages/compiler-core/src/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ export interface CodegenResult {
}

export interface CodegenContext
extends Omit<
Required<CodegenOptions>,
'bindingMetadata' | 'inline' | 'isTS'
> {
extends Omit<Required<CodegenOptions>, 'bindingMetadata' | 'inline'> {
source: string
code: string
line: number
Expand All @@ -98,7 +95,8 @@ function createCodegenContext(
optimizeImports = false,
runtimeGlobalName = `Vue`,
runtimeModuleName = `vue`,
ssr = false
ssr = false,
isTS = false
}: CodegenOptions
): CodegenContext {
const context: CodegenContext = {
Expand All @@ -111,6 +109,7 @@ function createCodegenContext(
runtimeGlobalName,
runtimeModuleName,
ssr,
isTS,
source: ast.loc.source,
code: ``,
column: 1,
Expand Down Expand Up @@ -466,7 +465,7 @@ function genModulePreamble(
function genAssets(
assets: string[],
type: 'component' | 'directive' | 'filter',
{ helper, push, newline }: CodegenContext
{ helper, push, newline, isTS }: CodegenContext
) {
const resolver = helper(
__COMPAT__ && type === 'filter'
Expand All @@ -485,7 +484,7 @@ function genAssets(
push(
`const ${toValidAssetId(id, type)} = ${resolver}(${JSON.stringify(id)}${
maybeSelfReference ? `, true` : ``
})`
})${isTS ? `!` : ``}`
)
if (i < assets.length - 1) {
newline()
Expand Down

0 comments on commit a44d528

Please sign in to comment.