Parenthesize export assignments if needed#19590
Conversation
| node.modifiers = asNodeArray(modifiers); | ||
| node.isExportEquals = isExportEquals; | ||
| node.expression = expression; | ||
| node.expression = parenthesizeBinaryOperand(SyntaxKind.EqualsToken, expression, /*isLeftSideOfBinary*/ false, /*leftOperand*/ undefined); |
There was a problem hiding this comment.
As far as I can tell, export default <expr> binds as tightly as export = <expr>, so this seems appropriate.
There was a problem hiding this comment.
Actually, I think export default may need its own parenthesization logic. Per the spec, export default accepts AssigmentExpression but has a lookahead restriction for function, async function, and class.
Basically, that means you need to parenthesize in the following cases:
- BinaryExpression of CommaToken
- CommaList (synthetic list of multiple comma expressions)
- FunctionExpression
- ClassExpression
| node.modifiers = asNodeArray(modifiers); | ||
| node.isExportEquals = isExportEquals; | ||
| node.expression = expression; | ||
| node.expression = parenthesizeBinaryOperand(SyntaxKind.EqualsToken, expression, /*isLeftSideOfBinary*/ false, /*leftOperand*/ undefined); |
There was a problem hiding this comment.
Actually, I think export default may need its own parenthesization logic. Per the spec, export default accepts AssigmentExpression but has a lookahead restriction for function, async function, and class.
Basically, that means you need to parenthesize in the following cases:
- BinaryExpression of CommaToken
- CommaList (synthetic list of multiple comma expressions)
- FunctionExpression
- ClassExpression
| */ | ||
| export function parenthesizeDefaultExpression(e: Expression) { | ||
| const check = skipPartiallyEmittedExpressions(e); | ||
| return (check.kind === SyntaxKind.ClassExpression || |
There was a problem hiding this comment.
Is parenthesizing FunctionExpression and ClassExpression enough to stop them from being seen as HoistableDeclaration/ClassDeclaration? 🤔
There was a problem hiding this comment.
Yes. Once you add parens, you are no longer in a declaration.
There was a problem hiding this comment.
Should be. Anything that doesn't work that way is parsing incorrectly.
Fixes #19574.