Skip to content

Commit

Permalink
[[FIX]] Labels shadowing within a function is a syntax error
Browse files Browse the repository at this point in the history
Fixes #2419
  • Loading branch information
lukeapage authored and jugglinmike committed Jul 17, 2015
1 parent 97c188b commit 124e00f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/scope-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,10 @@ var scopeManager = function(state, predefined, exported, declared) {

addBreakLabel: function(labelName, opts) {
var token = opts.token;
if (state.option.shadow === "outer") {
if (scopeManagerInst.funct.hasBreakLabel(labelName)) {
warning("E011", token, labelName);
}
else if (state.option.shadow === "outer") {
if (scopeManagerInst.funct.has(labelName)) {
warning("W004", token, labelName);
} else {
Expand Down
8 changes: 7 additions & 1 deletion tests/unit/fixtures/redef-es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,4 +358,10 @@ function zzg(zzh, zzi, zzj) {
var zzn = null;
const zzo = null;
let zzp = null;
}());
}());

zj: while(true) {
zj: while(true) {
break zj;
}
}
8 changes: 4 additions & 4 deletions tests/unit/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,12 @@ exports.shadowEs6 = function (test) {
[276, "'zb' has already been declared."],
[286, "'zd' has already been declared."],
[301, "'zf' has already been declared."],
[317, "'zi' has already been declared."],
[344, "'zzi' has already been declared."],
[345, "'zzj' has already been declared."],
[349, "'zzl' has already been declared."],
[350, "'zzm' has already been declared."]
[350, "'zzm' has already been declared."],
[364, "'zj' has already been declared."]
];

var innerErrors = [
Expand Down Expand Up @@ -171,9 +173,7 @@ exports.shadowEs6 = function (test) {
[335, "'zzd' is already defined in outer scope."],
[336, "'zze' is already defined in outer scope."],
[337, "'zzf' is already defined in outer scope."],
[358, "'zzn' is already defined in outer scope."],
/* labels */
[317, "'zi' is already defined in outer scope."] // should always error
[358, "'zzn' is already defined in outer scope."]
];

var testRun = TestRun(test);
Expand Down

0 comments on commit 124e00f

Please sign in to comment.