Remove bindings of removed paths from scope

This commit is contained in:
Nicolò Ribaudo
2018-02-04 13:37:44 +01:00
parent 22555cd15d
commit 4887d81929
8 changed files with 101 additions and 0 deletions

View File

@@ -189,11 +189,13 @@ export default function(api, opts) {
let ref = this.originalPath.node.init;
const refPropertyPath = [];
let kind;
path.findParent(path => {
if (path.isObjectProperty()) {
refPropertyPath.unshift(path.node.key.name);
} else if (path.isVariableDeclarator()) {
kind = path.parentPath.node.kind;
return true;
}
});
@@ -223,6 +225,8 @@ export default function(api, opts) {
insertionPath = insertionPath.getSibling(insertionPath.key + 1);
path.scope.registerBinding(kind, insertionPath);
if (objectPatternPath.node.properties.length === 0) {
objectPatternPath
.findParent(

View File

@@ -0,0 +1,3 @@
export default class {
method ({ ...object }) {}
}

View File

@@ -0,0 +1,14 @@
{
"presets": [
["env", {
"shippedProposals": true,
"targets": {
"node": 8
},
"useBuiltIns": "usage"
}]
],
"plugins": [
"external-helpers"
]
}

View File

@@ -0,0 +1,15 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
class _default {
method(_ref) {
let object = babelHelpers.objectWithoutProperties(_ref, []);
}
}
exports.default = _default;

View File

@@ -0,0 +1,5 @@
async function foo() {
(async function (number) {
const tmp = number
})
}

View File

@@ -0,0 +1,12 @@
{
"presets": [
["env", {
"targets": {
"chrome": "62",
"edge": "15",
"firefox": "52",
"safari": "11"
}
}]
]
}

View File

@@ -0,0 +1,42 @@
function foo() {
return _foo.apply(this, arguments);
}
function _foo() {
_foo = babelHelpers.asyncToGenerator(
/*#__PURE__*/
regeneratorRuntime.mark(function _callee2() {
return regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) switch (_context2.prev = _context2.next) {
case 0:
/*#__PURE__*/
(function () {
var _ref = babelHelpers.asyncToGenerator(
/*#__PURE__*/
regeneratorRuntime.mark(function _callee(number) {
var tmp;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
tmp = number;
case 1:
case "end":
return _context.stop();
}
}, _callee, this);
}));
return function (_x) {
return _ref.apply(this, arguments);
};
})();
case 1:
case "end":
return _context2.stop();
}
}, _callee2, this);
}));
return _foo.apply(this, arguments);
}

View File

@@ -6,6 +6,7 @@ export function remove() {
this._assertUnremoved();
this.resync();
this._removeFromScope();
if (this._callRemovalHooks()) {
this._markRemoved();
@@ -17,6 +18,11 @@ export function remove() {
this._markRemoved();
}
export function _removeFromScope() {
const bindings = this.getBindingIdentifiers();
Object.keys(bindings).forEach(name => this.scope.removeBinding(name));
}
export function _callRemovalHooks() {
for (const fn of (hooks: Array<Function>)) {
if (fn(this, this.parentPath)) return true;