diff options
author | Florian Dold <florian.dold@gmail.com> | 2016-11-03 01:33:53 +0100 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2016-11-03 01:33:53 +0100 |
commit | d1291f67551c58168af43698a359cb5ddfd266b0 (patch) | |
tree | 55a13ed29fe1915e3f42f1b1b7038dafa2e975a7 /node_modules/babel-traverse/lib/scope/index.js | |
parent | d0a0695fb5d34996850723f7d4b1b59c3df909c2 (diff) |
node_modules
Diffstat (limited to 'node_modules/babel-traverse/lib/scope/index.js')
-rw-r--r-- | node_modules/babel-traverse/lib/scope/index.js | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/node_modules/babel-traverse/lib/scope/index.js b/node_modules/babel-traverse/lib/scope/index.js index a1146e3ab..36cfb3429 100644 --- a/node_modules/babel-traverse/lib/scope/index.js +++ b/node_modules/babel-traverse/lib/scope/index.js @@ -10,6 +10,10 @@ var _create = require("babel-runtime/core-js/object/create"); var _create2 = _interopRequireDefault(_create); +var _map = require("babel-runtime/core-js/map"); + +var _map2 = _interopRequireDefault(_map); + var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck"); var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); @@ -234,6 +238,8 @@ var Scope = function () { this.parentBlock = path.parent; this.block = path.node; this.path = path; + + this.labels = new _map2.default(); } Scope.prototype.traverse = function traverse(node, opts, state) { @@ -241,7 +247,7 @@ var Scope = function () { }; Scope.prototype.generateDeclaredUidIdentifier = function generateDeclaredUidIdentifier() { - var name = arguments.length <= 0 || arguments[0] === undefined ? "temp" : arguments[0]; + var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "temp"; var id = this.generateUidIdentifier(name); this.push({ id: id }); @@ -249,13 +255,13 @@ var Scope = function () { }; Scope.prototype.generateUidIdentifier = function generateUidIdentifier() { - var name = arguments.length <= 0 || arguments[0] === undefined ? "temp" : arguments[0]; + var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "temp"; return t.identifier(this.generateUid(name)); }; Scope.prototype.generateUid = function generateUid() { - var name = arguments.length <= 0 || arguments[0] === undefined ? "temp" : arguments[0]; + var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "temp"; name = t.toIdentifier(name).replace(/^_+/, "").replace(/[0-9]+$/g, ""); @@ -264,7 +270,7 @@ var Scope = function () { do { uid = this._generateUid(name, i); i++; - } while (this.hasBinding(uid) || this.hasGlobal(uid) || this.hasReference(uid)); + } while (this.hasLabel(uid) || this.hasBinding(uid) || this.hasGlobal(uid) || this.hasReference(uid)); var program = this.getProgramParent(); program.references[uid] = true; @@ -459,9 +465,21 @@ var Scope = function () { return t.callExpression(file.addHelper(helperName), args); }; + Scope.prototype.hasLabel = function hasLabel(name) { + return !!this.getLabel(name); + }; + + Scope.prototype.getLabel = function getLabel(name) { + return this.labels.get(name); + }; + + Scope.prototype.registerLabel = function registerLabel(path) { + this.labels.set(path.node.label.name, path); + }; + Scope.prototype.registerDeclaration = function registerDeclaration(path) { if (path.isLabeledStatement()) { - this.registerBinding("label", path); + this.registerLabel(path); } else if (path.isFunctionDeclaration()) { this.registerBinding("hoisted", path.get("id"), path); } else if (path.isVariableDeclaration()) { @@ -529,7 +547,7 @@ var Scope = function () { }; Scope.prototype.registerBinding = function registerBinding(kind, path) { - var bindingPath = arguments.length <= 2 || arguments[2] === undefined ? path : arguments[2]; + var bindingPath = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : path; if (!kind) throw new ReferenceError("no `kind`"); |