Skip to content

Commit e237ce5

Browse files
committed
Fix: Labeled statement ref counting (refs #33)
1 parent f869148 commit e237ce5

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/referencer.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,9 @@ export default class Referencer extends esrecurse.Visitor {
420420

421421
ContinueStatement() {}
422422

423-
LabeledStatement() {}
423+
LabeledStatement(node) {
424+
this.visit(node.body);
425+
}
424426

425427
ForStatement(node) {
426428
// Create ForStatement declaration.

test/label.coffee

+20
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,24 @@ describe 'label', ->
4747
expect(scope.isArgumentsMaterialized()).to.be.false
4848
expect(scope.references).to.have.length 0
4949

50+
it 'should count child node references', ->
51+
ast = esprima.parse """
52+
var foo = 5;
53+
54+
label: while (true) {
55+
console.log(foo);
56+
break;
57+
}
58+
"""
59+
60+
scopeManager = escope.analyze ast
61+
expect(scopeManager.scopes).to.have.length 1
62+
globalScope = scopeManager.scopes[0]
63+
expect(globalScope.type).to.be.equal 'global'
64+
expect(globalScope.variables).to.have.length 1
65+
expect(globalScope.variables[0].name).to.be.equal 'foo'
66+
expect(globalScope.through.length).to.be.equal 3
67+
expect(globalScope.through[2].identifier.name).to.be.equal 'foo'
68+
expect(globalScope.through[2].isRead()).to.be.true
69+
5070
# vim: set sw=4 ts=4 et tw=80 :

0 commit comments

Comments
 (0)