Skip to content

Commit

Permalink
Support for continues nested in switches nested in loops.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregor Richards authored and Gregor Richards committed Apr 18, 2011
1 parent b0cc62c commit a142a48
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions lib/jsparse.js
Expand Up @@ -93,6 +93,7 @@ Narcissus.parser = (function() {
this.allLabels = new Stack();
this.currentLabels = new Stack();
this.labeledTargets = new Stack();
this.defaultLoopTarget = null;
this.defaultTarget = null;
this.blackList = blackLists[Narcissus.options.version];
Narcissus.options.ecma3OnlyMode && (this.ecma3OnlyMode = true);
Expand Down Expand Up @@ -120,12 +121,13 @@ Narcissus.parser = (function() {
allLabels: this.allLabels.push(label) });
},
pushTarget: function(target) {
var isDefaultTarget = target.isLoop || target.type === SWITCH;
var isDefaultLoopTarget = target.isLoop;
var isDefaultTarget = isDefaultLoopTarget || target.type === SWITCH;

if (this.currentLabels.isEmpty()) {
return isDefaultTarget
? this.update({ defaultTarget: target })
: this;
if (isDefaultLoopTarget) this.update({ defaultLoopTarget: target });
if (isDefaultTarget) this.update({ defaultTarget: target });
return this;
}

target.labels = new StringMap();
Expand All @@ -134,6 +136,9 @@ Narcissus.parser = (function() {
});
return this.update({ currentLabels: new Stack(),
labeledTargets: this.labeledTargets.push(target),
defaultLoopTarget: isDefaultLoopTarget
? target
: this.defaultLoopTarget,
defaultTarget: isDefaultTarget
? target
: this.defaultTarget });
Expand Down Expand Up @@ -646,9 +651,13 @@ Narcissus.parser = (function() {
n.label = t.token.value;
}

n.target = n.label
? x2.labeledTargets.find(function(target) { return target.labels.has(n.label) })
: x2.defaultTarget;
if (n.label) {
n.target = x2.labeledTargets.find(function(target) { return target.labels.has(n.label) });
} else if (tt === CONTINUE) {
n.target = x2.defaultLoopTarget;
} else {
n.target = x2.defaultTarget;
}

if (!n.target)
throw t.newSyntaxError("Invalid " + ((tt === BREAK) ? "break" : "continue"));
Expand Down

0 comments on commit a142a48

Please sign in to comment.