Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions src/compiler/transformers/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
11 changes: 11 additions & 0 deletions tests/baselines/reference/parenthesizedArrowExpressionASI.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//// [parenthesizedArrowExpressionASI.ts]
const x = (a: any[]) => (
// comment
undefined as number
);


//// [parenthesizedArrowExpressionASI.js]
var x = function (a) { return (
// comment
undefined); };
11 changes: 11 additions & 0 deletions tests/baselines/reference/parenthesizedArrowExpressionASI.symbols
Original file line number Diff line number Diff line change
@@ -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)

);

14 changes: 14 additions & 0 deletions tests/baselines/reference/parenthesizedArrowExpressionASI.types
Original file line number Diff line number Diff line change
@@ -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 changes: 4 additions & 0 deletions tests/cases/compiler/parenthesizedArrowExpressionASI.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const x = (a: any[]) => (
// comment
undefined as number
);