Skip to content

Commit ee2a107

Browse files
AST: Refactor marking nodes that return (#5275)
AST: Refactor marking nodes that return
2 parents b2b2f97 + 8fb5c1b commit ee2a107

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

lib/coffeescript/nodes.js

Lines changed: 9 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/nodes.coffee

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,16 @@ exports.Base = class Base
281281
# **WARNING: DO NOT OVERRIDE THIS METHOD IN CHILD CLASSES.**
282282
# Only override the component `ast*` methods as needed.
283283
ast: (o, level) ->
284+
# Merge `level` into `o` and perform other universal checks.
284285
o = @astInitialize o, level
286+
# Create serializable representation of this node.
285287
astNode = @astNode o
286-
@astAddReturns astNode
288+
# Mark AST nodes that correspond to expressions that (implicitly) return.
289+
# We can’t do this as part of `astNode` because we need to assemble child
290+
# nodes first before marking the parent being returned.
291+
if @astNode? and @canBeReturned
292+
Object.assign astNode, {returns: yes}
293+
astNode
287294

288295
astInitialize: (o, level) ->
289296
o = Object.assign {}, o
@@ -318,12 +325,6 @@ exports.Base = class Base
318325
astLocationData: ->
319326
jisonLocationDataToAstLocationData @locationData
320327

321-
# Mark AST nodes that correspond to expressions that (implicitly) return.
322-
astAddReturns: (ast) ->
323-
return ast unless ast?
324-
ast.returns = yes if @canBeReturned
325-
ast
326-
327328
# Determines whether an AST node needs an `ExpressionStatement` wrapper.
328329
# Typically matches our `isStatement()` logic but this allows overriding.
329330
isStatementAst: (o) ->

0 commit comments

Comments
 (0)