Skip to content

fix(compiler-core): remove types for expressions #13397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ return function render(_ctx, _cache, $props, $setup, $data, $options) {
}"
`;

exports[`compiler: expression transform > expression with type 1`] = `
"const { openBlock: _openBlock, createElementBlock: _createElementBlock } = Vue

return function render(_ctx, _cache) {
return (_openBlock(), _createElementBlock("div", {
onClick: (_ctx.handleClick as any)
}, null, 8 /* PROPS */, ["onClick"]))
}"
`;

exports[`compiler: expression transform > should allow leak of var declarations in for loop 1`] = `
"const { openBlock: _openBlock, createElementBlock: _createElementBlock } = Vue

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -716,4 +716,10 @@ describe('compiler: expression transform', () => {
})
})
})

test('expression with type', () => {
const { code } = compile(`<div @click="handleClick as any"></div>`)
expect(code).toMatch(`onClick: (_ctx.handleClick as any)`)
expect(code).toMatchSnapshot()
})
})
4 changes: 4 additions & 0 deletions packages/compiler-core/src/transforms/transformExpression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
createSimpleExpression,
} from '../ast'
import {
TS_NODE_TYPES,
isInDestructureAssignment,
isInNewExpression,
isStaticProperty,
Expand Down Expand Up @@ -347,6 +348,8 @@ export function processExpression(
// an ExpressionNode has the `.children` property, it will be used instead of
// `.content`.
const children: CompoundExpressionNode['children'] = []
const shouldWrap = TS_NODE_TYPES.includes(ast.type)
if (shouldWrap) children.push('(')
ids.sort((a, b) => a.start - b.start)
ids.forEach((id, i) => {
// range is offset by -1 due to the wrapping parens when parsed
Expand Down Expand Up @@ -376,6 +379,7 @@ export function processExpression(
children.push(rawExp.slice(end))
}
})
if (shouldWrap) children.push(')')

let ret
if (children.length) {
Expand Down