diff --git a/lib/compiler/passes/report-duplicate-labels.js b/lib/compiler/passes/report-duplicate-labels.js index a027bd9..7614594 100644 --- a/lib/compiler/passes/report-duplicate-labels.js +++ b/lib/compiler/passes/report-duplicate-labels.js @@ -1,13 +1,22 @@ "use strict"; let GrammarError = require("../../grammar-error"), - objects = require("../../utils/objects"), visitor = require("../visitor"); /* Checks that each label is defined only once within each scope. */ function reportDuplicateLabels(ast) { + function cloneEnv(env) { + let clone = {}; + + Object.keys(env).forEach(name => { + clone[name] = env[name]; + }); + + return clone; + } + function checkExpressionWithClonedEnv(node, env) { - check(node.expression, objects.clone(env)); + check(node.expression, cloneEnv(env)); } let check = visitor.build({ @@ -17,7 +26,7 @@ function reportDuplicateLabels(ast) { choice: function(node, env) { node.alternatives.forEach(alternative => { - check(alternative, objects.clone(env)); + check(alternative, cloneEnv(env)); }); },