Skip to content

Commit 6640358

Browse files
committed
chore: remove types
1 parent 575fc50 commit 6640358

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

packages/compiler-core/__tests__/transforms/__snapshots__/transformExpressions.spec.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ exports[`compiler: expression transform > expression with type 1`] = `
1919
2020
return function render(_ctx, _cache) {
2121
return (_openBlock(), _createElementBlock("div", {
22-
onClick: (_ctx.handleClick as any)
22+
onClick: _ctx.handleClick
2323
}, null, 8 /* PROPS */, ["onClick"]))
2424
}"
2525
`;

packages/compiler-core/__tests__/transforms/transformExpressions.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -718,8 +718,10 @@ describe('compiler: expression transform', () => {
718718
})
719719

720720
test('expression with type', () => {
721-
const { code } = compile(`<div @click="handleClick as any"></div>`)
722-
expect(code).toMatch(`onClick: (_ctx.handleClick as any)`)
721+
const { code } = compile(
722+
`<div @click="(<number>handleClick as any)"></div>`,
723+
)
724+
expect(code).toMatch(`onClick: _ctx.handleClick`)
723725
expect(code).toMatchSnapshot()
724726
})
725727
})

packages/compiler-core/src/transforms/transformExpression.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -348,17 +348,18 @@ export function processExpression(
348348
// an ExpressionNode has the `.children` property, it will be used instead of
349349
// `.content`.
350350
const children: CompoundExpressionNode['children'] = []
351-
const shouldWrap = TS_NODE_TYPES.includes(ast.type)
352-
if (shouldWrap) children.push('(')
351+
const isTSNode = TS_NODE_TYPES.includes(ast.type)
353352
ids.sort((a, b) => a.start - b.start)
354353
ids.forEach((id, i) => {
355354
// range is offset by -1 due to the wrapping parens when parsed
356355
const start = id.start - 1
357356
const end = id.end - 1
358357
const last = ids[i - 1]
359-
const leadingText = rawExp.slice(last ? last.end - 1 : 0, start)
360-
if (leadingText.length || id.prefix) {
361-
children.push(leadingText + (id.prefix || ``))
358+
if (!(isTSNode && i === 0)) {
359+
const leadingText = rawExp.slice(last ? last.end - 1 : 0, start)
360+
if (leadingText.length || id.prefix) {
361+
children.push(leadingText + (id.prefix || ``))
362+
}
362363
}
363364
const source = rawExp.slice(start, end)
364365
children.push(
@@ -375,11 +376,10 @@ export function processExpression(
375376
: ConstantTypes.NOT_CONSTANT,
376377
),
377378
)
378-
if (i === ids.length - 1 && end < rawExp.length) {
379+
if (i === ids.length - 1 && end < rawExp.length && !isTSNode) {
379380
children.push(rawExp.slice(end))
380381
}
381382
})
382-
if (shouldWrap) children.push(')')
383383

384384
let ret
385385
if (children.length) {

0 commit comments

Comments
 (0)