Skip to content

Commit

Permalink
Fix: Labeled statement ref counting (refs #33)
Browse files Browse the repository at this point in the history
  • Loading branch information
nzakas committed Jan 31, 2015
1 parent f869148 commit e237ce5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/referencer.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,9 @@ export default class Referencer extends esrecurse.Visitor {

ContinueStatement() {}

LabeledStatement() {}
LabeledStatement(node) {
this.visit(node.body);
}

ForStatement(node) {
// Create ForStatement declaration.
Expand Down
20 changes: 20 additions & 0 deletions test/label.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,24 @@ describe 'label', ->
expect(scope.isArgumentsMaterialized()).to.be.false
expect(scope.references).to.have.length 0

it 'should count child node references', ->
ast = esprima.parse """
var foo = 5;
label: while (true) {
console.log(foo);
break;
}
"""

scopeManager = escope.analyze ast
expect(scopeManager.scopes).to.have.length 1
globalScope = scopeManager.scopes[0]
expect(globalScope.type).to.be.equal 'global'
expect(globalScope.variables).to.have.length 1
expect(globalScope.variables[0].name).to.be.equal 'foo'
expect(globalScope.through.length).to.be.equal 3
expect(globalScope.through[2].identifier.name).to.be.equal 'foo'
expect(globalScope.through[2].isRead()).to.be.true

# vim: set sw=4 ts=4 et tw=80 :

0 comments on commit e237ce5

Please sign in to comment.