-
Notifications
You must be signed in to change notification settings - Fork 694
fix(1632): erase const enums after inlining #1639
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
798d12b
to
c5a62a9
Compare
441cca9
to
ded3fa0
Compare
...ference/submodule/compiler/blockScopedEnumVariablesUseBeforeDef_verbatimModuleSyntax.js.diff
Outdated
Show resolved
Hide resolved
testdata/baselines/reference/submodule/compiler/constEnumErrors.js.diff
Outdated
Show resolved
Hide resolved
testdata/baselines/reference/submodule/conformance/constEnum4.js.diff
Outdated
Show resolved
Hide resolved
if (1) | ||
else if (2) | ||
else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I commented on the diff (I usually only look at those), but this is the problematic transform I was pointing out.
I suspect this comes down to the emit for if/else/similar needing to ensure that bodies are still printed out if missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jakebailey I’m currently investigating this case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems EmbeddedStatement
doesn’t treat NotEmittedStatement
as an empty statement the way Strada does.
As a result, when updating a statement (for example, an if
), a NotEmittedStatement
is returned and the ;
is skipped.
typescript-go/internal/printer/printer.go
Lines 3895 to 3899 in 52f2ee4
if node.Kind == ast.KindEmptyStatement { | |
p.emitEmptyStatement(node.AsEmptyStatement(), true /*isEmbeddedStatement*/) | |
} else { | |
p.emitStatement(node) | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, does that mean the fix should be elsewhere?
...baselines/reference/submodule/compiler/elidedEmbeddedStatementsReplacedWithSemicolon.js.diff
Outdated
Show resolved
Hide resolved
@@ -961,3 +962,14 @@ func (c *EmitContext) GetSyntheticTrailingComments(node *ast.Node) []Synthesized | |||
} | |||
return nil | |||
} | |||
|
|||
func (c *EmitContext) VisitEmbeddedStatement(node *ast.Statement, visitor *ast.NodeVisitor) *ast.Statement { | |||
updated := visitor.VisitEmbeddedStatement(node) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sort of surprised by this, given I thought the default was to do this already...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like it doesn’t by default
typescript-go/internal/ast/visitor.go
Lines 74 to 84 in 52f2ee4
func (v *NodeVisitor) VisitEmbeddedStatement(node *Statement) *Statement { | |
if node == nil || v.Visit == nil { | |
return node | |
} | |
if v.Visit != nil { | |
return v.liftToBlock(v.Visit(node)) | |
} | |
return node | |
} |
typescript-go/internal/ast/visitor.go
Lines 201 to 209 in 52f2ee4
func (v *NodeVisitor) visitEmbeddedStatement(node *Node) *Node { | |
if v.Hooks.VisitEmbeddedStatement != nil { | |
return v.Hooks.VisitEmbeddedStatement(node, v) | |
} | |
if v.Hooks.VisitNode != nil { | |
return v.liftToBlock(v.Hooks.VisitNode(node, v)) | |
} | |
return v.VisitEmbeddedStatement(node) | |
} |
I’m not convinced the visitor is the right place for this - WDYT? Also, the change can be implemented via a transformer-level hook or in the emitter.
Fixes #1632