Reduce aggression of parenthesis removal in ts transform (#24073)
This commit is contained in:
parent
560371d7a0
commit
b58e4e1fa1
|
@ -2534,6 +2534,11 @@ namespace ts {
|
|||
// we can safely elide the parentheses here, as a new synthetic
|
||||
// ParenthesizedExpression will be inserted if we remove parentheses too
|
||||
// aggressively.
|
||||
// HOWEVER - if there are leading comments on the expression itself, to handle ASI
|
||||
// correctly for return and throw, we must keep the parenthesis
|
||||
if (length(getLeadingCommentRangesOfNode(expression, currentSourceFile))) {
|
||||
return updateParen(node, expression);
|
||||
}
|
||||
return createPartiallyEmittedExpression(expression, node);
|
||||
}
|
||||
|
||||
|
|
11
tests/baselines/reference/parenthesizedArrowExpressionASI.js
Normal file
11
tests/baselines/reference/parenthesizedArrowExpressionASI.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
//// [parenthesizedArrowExpressionASI.ts]
|
||||
const x = (a: any[]) => (
|
||||
// comment
|
||||
undefined as number
|
||||
);
|
||||
|
||||
|
||||
//// [parenthesizedArrowExpressionASI.js]
|
||||
var x = function (a) { return (
|
||||
// comment
|
||||
undefined); };
|
|
@ -0,0 +1,11 @@
|
|||
=== tests/cases/compiler/parenthesizedArrowExpressionASI.ts ===
|
||||
const x = (a: any[]) => (
|
||||
>x : Symbol(x, Decl(parenthesizedArrowExpressionASI.ts, 0, 5))
|
||||
>a : Symbol(a, Decl(parenthesizedArrowExpressionASI.ts, 0, 11))
|
||||
|
||||
// comment
|
||||
undefined as number
|
||||
>undefined : Symbol(undefined)
|
||||
|
||||
);
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
=== tests/cases/compiler/parenthesizedArrowExpressionASI.ts ===
|
||||
const x = (a: any[]) => (
|
||||
>x : (a: any[]) => number
|
||||
>(a: any[]) => ( // comment undefined as number) : (a: any[]) => number
|
||||
>a : any[]
|
||||
>( // comment undefined as number) : number
|
||||
|
||||
// comment
|
||||
undefined as number
|
||||
>undefined as number : number
|
||||
>undefined : undefined
|
||||
|
||||
);
|
||||
|
4
tests/cases/compiler/parenthesizedArrowExpressionASI.ts
Normal file
4
tests/cases/compiler/parenthesizedArrowExpressionASI.ts
Normal file
|
@ -0,0 +1,4 @@
|
|||
const x = (a: any[]) => (
|
||||
// comment
|
||||
undefined as number
|
||||
);
|
Loading…
Reference in a new issue