Skip to content

Commit

Permalink
Ref cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
wcjohnson committed Sep 24, 2017
1 parent c592784 commit 83ff2d1
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/ref.lsc
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import placeAtLoc from 'ast-loc-utils/lib/placeAtLoc'
import span from 'ast-loc-utils/lib/span'

export isSimple(refTarget) ->
refTarget~isa("Identifier") or refTarget~isa("ThisExpression")
refTarget~isa("Identifier") or
refTarget~isa("Super") or
refTarget~isa("ThisExpression")

// Hoist a ref up to the enclosing scope if needed.
export hoistRef(path, refTarget, varName = "ref") ->
if isSimple(refTarget):
if refTarget~isSimple():
{ ref: refTarget, assign: refTarget, isComplex: false }
else:
ref = path.scope.generateDeclaredUidIdentifier(varName)
Expand All @@ -26,7 +28,7 @@ export hoistRef(path, refTarget, varName = "ref") ->
// Create a variable declarator for a ref in the enclosing scope, if
// needed
export undeclaredRef(path, refTarget, varName = "ref") ->
if isSimple(refTarget):
if refTarget~isSimple():
{ ref: refTarget, declarator: null, isComplex: false }
else:
ref = path.scope.generateUidIdentifier(varName)
Expand Down

0 comments on commit 83ff2d1

Please sign in to comment.