Remove bindings of removed paths from scope
This commit is contained in:
@@ -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(
|
||||
|
||||
3
packages/babel-plugin-proposal-object-rest-spread/test/fixtures/regression/gh-7304/input.js
vendored
Normal file
3
packages/babel-plugin-proposal-object-rest-spread/test/fixtures/regression/gh-7304/input.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
export default class {
|
||||
method ({ ...object }) {}
|
||||
}
|
||||
14
packages/babel-plugin-proposal-object-rest-spread/test/fixtures/regression/gh-7304/options.json
vendored
Normal file
14
packages/babel-plugin-proposal-object-rest-spread/test/fixtures/regression/gh-7304/options.json
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"presets": [
|
||||
["env", {
|
||||
"shippedProposals": true,
|
||||
"targets": {
|
||||
"node": 8
|
||||
},
|
||||
"useBuiltIns": "usage"
|
||||
}]
|
||||
],
|
||||
"plugins": [
|
||||
"external-helpers"
|
||||
]
|
||||
}
|
||||
15
packages/babel-plugin-proposal-object-rest-spread/test/fixtures/regression/gh-7304/output.js
vendored
Normal file
15
packages/babel-plugin-proposal-object-rest-spread/test/fixtures/regression/gh-7304/output.js
vendored
Normal 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;
|
||||
5
packages/babel-plugin-transform-async-to-generator/test/fixtures/regression/gh-6923/input.js
vendored
Normal file
5
packages/babel-plugin-transform-async-to-generator/test/fixtures/regression/gh-6923/input.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
async function foo() {
|
||||
(async function (number) {
|
||||
const tmp = number
|
||||
})
|
||||
}
|
||||
12
packages/babel-plugin-transform-async-to-generator/test/fixtures/regression/gh-6923/options.json
vendored
Normal file
12
packages/babel-plugin-transform-async-to-generator/test/fixtures/regression/gh-6923/options.json
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"presets": [
|
||||
["env", {
|
||||
"targets": {
|
||||
"chrome": "62",
|
||||
"edge": "15",
|
||||
"firefox": "52",
|
||||
"safari": "11"
|
||||
}
|
||||
}]
|
||||
]
|
||||
}
|
||||
42
packages/babel-plugin-transform-async-to-generator/test/fixtures/regression/gh-6923/output.js
vendored
Normal file
42
packages/babel-plugin-transform-async-to-generator/test/fixtures/regression/gh-6923/output.js
vendored
Normal 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);
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user