MCPcopy Create free account
hub / github.com/microsoft/typescript-go / EndVariableEnvironment

Method EndVariableEnvironment

internal/printer/emitcontext.go:117–133  ·  view source on GitHub ↗

Ends the current VariableEnvironment, returning a list of statements that should be emitted at the start of the current scope. NOTE: This is the equivalent of `transformContext.endLexicalEnvironment` in Strada.

()

Source from the content-addressed store, hash-verified

115//
116// NOTE: This is the equivalent of `transformContext.endLexicalEnvironment` in Strada.
117func (c *EmitContext) EndVariableEnvironment() []*ast.Statement {
118 scope := c.varScopeStack.Pop()
119 var statements []*ast.Statement
120 if len(scope.functions) > 0 {
121 statements = slices.Clone(scope.functions)
122 }
123 if len(scope.variables) > 0 {
124 varDeclList := c.Factory.NewVariableDeclarationList(c.Factory.NewNodeList(scope.variables), ast.NodeFlagsNone)
125 varStatement := c.Factory.NewVariableStatement(nil /*modifiers*/, varDeclList)
126 c.SetEmitFlags(varStatement, EFCustomPrologue)
127 statements = append(statements, varStatement)
128 }
129 if len(scope.initializationStatements) > 0 {
130 statements = append(statements, scope.initializationStatements...)
131 }
132 return append(statements, c.EndLexicalEnvironment()...)
133}
134
135// Invokes c.EndVariableEnvironment() and merges the results into `statements`
136func (c *EmitContext) EndAndMergeVariableEnvironmentList(statements *ast.StatementList) *ast.StatementList {

Callers 7

VisitFunctionBodyMethod · 0.95
transformClassLikeMethod · 0.80
transformFunctionBodyMethod · 0.80
visitSourceFileMethod · 0.80

Calls 9

SetEmitFlagsMethod · 0.95
EndLexicalEnvironmentMethod · 0.95
lenFunction · 0.85
PopMethod · 0.80
NewNodeListMethod · 0.80
NewVariableStatementMethod · 0.80
CloneMethod · 0.65
appendFunction · 0.50

Tested by

no test coverage detected