MCPcopy Index your code
hub / github.com/microsoft/typescript-go / emitExpressionStatement

Method emitExpressionStatement

internal/printer/printer.go:3402–3431  ·  view source on GitHub ↗
(node *ast.ExpressionStatement)

Source from the content-addressed store, hash-verified

3400}
3401
3402func (p *Printer) emitExpressionStatement(node *ast.ExpressionStatement) {
3403 state := p.enterNode(node.AsNode())
3404
3405 if p.currentSourceFile != nil && p.currentSourceFile.ScriptKind == core.ScriptKindJSON {
3406 // !!! In strada, this was handled by an undefined parenthesizerRule, so this is a hack.
3407 p.emitExpression(node.Expression, ast.OperatorPrecedenceComma)
3408 } else if isImmediatelyInvokedFunctionExpressionOrArrowFunction(node.Expression) {
3409 // For IIFEs, parenthesize just the callee (not the whole call), matching TypeScript's
3410 // parenthesizeExpressionOfExpressionStatement which wraps the function/arrow in parens:
3411 // (function() { })() -- not (function() { }())
3412 p.emitIIFEWithParenthesizedCallee(node.Expression)
3413 } else {
3414 switch ast.GetLeftmostExpression(node.Expression, false /*stopAtCallExpression*/).Kind {
3415 case ast.KindFunctionExpression, ast.KindObjectLiteralExpression:
3416 p.emitExpression(node.Expression, ast.OperatorPrecedenceParentheses)
3417 default:
3418 p.emitExpression(node.Expression, ast.OperatorPrecedenceComma)
3419 }
3420 }
3421
3422 // Emit semicolon in non json files
3423 // or if json file that created synthesized expression(eg.define expression statement when --out and amd code generation)
3424 if p.currentSourceFile == nil ||
3425 p.currentSourceFile.ScriptKind != core.ScriptKindJSON ||
3426 ast.NodeIsSynthesized(node.Expression) {
3427 p.writeTrailingSemicolon()
3428 }
3429
3430 p.exitNode(node.AsNode(), state)
3431}
3432
3433// emitIIFEWithParenthesizedCallee emits a call expression that is an IIFE,
3434// wrapping just the callee in parens rather than the entire call expression.

Callers 1

emitStatementMethod · 0.95

Calls 9

enterNodeMethod · 0.95
emitExpressionMethod · 0.95
exitNodeMethod · 0.95
GetLeftmostExpressionFunction · 0.92
NodeIsSynthesizedFunction · 0.92
AsNodeMethod · 0.65

Tested by

no test coverage detected