Skip to content

Commit

Permalink
fix: renameVisitor should skip when a pattern is a scope
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Dec 23, 2019
1 parent 4cc6349 commit fb4125a
Show file tree
Hide file tree
Showing 41 changed files with 245 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/babel-traverse/src/scope/lib/renamer.js
Expand Up @@ -9,8 +9,9 @@ const renameVisitor = {
}
},

Scope(path, state) {
"Pattern|Scope"(path, state) {
if (
path.isScope() &&
!path.scope.bindingIdentifierEquals(
state.oldName,
state.binding.identifier,
Expand Down
@@ -0,0 +1,7 @@
let a = "outside";

function f(g = () => a) {
let a = "inside";
return g();
}

@@ -0,0 +1,3 @@
{
"plugins": ["./plugin"]
}
@@ -0,0 +1,6 @@
let a = "outside";

function f(g = () => a) {
let z = "inside";
return g();
}
@@ -0,0 +1,9 @@
module.exports = function() {
return {
visitor: {
FunctionDeclaration(path) {
path.scope.rename("a", "z");
}
}
};
};
@@ -0,0 +1,5 @@
let a = "outside";

function r({ a: b }, { [a]: { c } = a }) {
g(a);
}
@@ -0,0 +1,3 @@
{
"plugins": ["./plugin"]
}
@@ -0,0 +1,11 @@
let z = "outside";

function r({
a: b
}, {
[z]: {
c
} = z
}) {
g(z);
}
@@ -0,0 +1,9 @@
module.exports = function() {
return {
visitor: {
FunctionDeclaration(path) {
path.scope.rename("a", "z");
}
}
};
};
@@ -0,0 +1,5 @@
let a = "outside";

function h(a, g = () => a) {
return g();
}
@@ -0,0 +1,3 @@
{
"plugins": ["./plugin"]
}
@@ -0,0 +1,5 @@
let a = "outside";

function h(z, g = () => z) {
return g();
}
@@ -0,0 +1,9 @@
module.exports = function() {
return {
visitor: {
FunctionDeclaration(path) {
path.scope.rename("a", "z");
}
}
};
};
@@ -0,0 +1,6 @@
let a = "outside";

function j(g = a) {
let a = "inside";
return g;
}
@@ -0,0 +1,3 @@
{
"plugins": ["./plugin"]
}
@@ -0,0 +1,6 @@
let a = "outside";

function j(g = a) {
let z = "inside";
return g;
}
@@ -0,0 +1,9 @@
module.exports = function() {
return {
visitor: {
FunctionDeclaration(path) {
path.scope.rename("a", "z");
}
}
};
};
@@ -0,0 +1,8 @@
let a = "outside";

function k([{
g = a
}]) {
let a = "inside";
return g;
}
@@ -0,0 +1,3 @@
{
"plugins": ["./plugin"]
}
@@ -0,0 +1,8 @@
let a = "outside";

function k([{
g = a
}]) {
let z = "inside";
return g;
}
@@ -0,0 +1,9 @@
module.exports = function() {
return {
visitor: {
FunctionDeclaration(path) {
path.scope.rename("a", "z");
}
}
};
};
@@ -0,0 +1,8 @@
let a = "outside";

function f([{
[a]: g
}]) {
let a = "inside";
return g;
}
@@ -0,0 +1,3 @@
{
"plugins": ["./plugin"]
}
@@ -0,0 +1,8 @@
let a = "outside";

function f([{
[a]: g
}]) {
let z = "inside";
return g;
}
@@ -0,0 +1,9 @@
module.exports = function() {
return {
visitor: {
FunctionDeclaration(path) {
path.scope.rename("a", "z");
}
}
};
};
@@ -0,0 +1,5 @@
let a = "outside";

function n(g = (a = a) => {}) {
let a = "inside";
}
@@ -0,0 +1,3 @@
{
"plugins": ["./plugin"]
}
@@ -0,0 +1,5 @@
let a = "outside";

function n(g = (a = a) => {}) {
let z = "inside";
}
@@ -0,0 +1,9 @@
module.exports = function() {
return {
visitor: {
FunctionDeclaration(path) {
path.scope.rename("a", "z");
}
}
};
};
@@ -0,0 +1,5 @@
let a = "outside";

function n(a, g = (a = a) => {}) {
a = "inside";
}
@@ -0,0 +1,3 @@
{
"plugins": ["./plugin"]
}
@@ -0,0 +1,5 @@
let a = "outside";

function n(z, g = (a = a) => {}) {
z = "inside";
}
@@ -0,0 +1,9 @@
module.exports = function() {
return {
visitor: {
FunctionDeclaration(path) {
path.scope.rename("a", "z");
}
}
};
};
@@ -0,0 +1,5 @@
let a = "outside";

function q(a, g = (b = a) => b) {
g(a);
}
@@ -0,0 +1,3 @@
{
"plugins": ["./plugin"]
}
@@ -0,0 +1,5 @@
let a = "outside";

function q(z, g = (b = z) => b) {
g(z);
}
@@ -0,0 +1,9 @@
module.exports = function() {
return {
visitor: {
FunctionDeclaration(path) {
path.scope.rename("a", "z");
}
}
};
};
@@ -0,0 +1,5 @@
let a = "outside";

function r(a, g = (a, b = a) => a) {
g(a);
}
@@ -0,0 +1,3 @@
{
"plugins": ["./plugin"]
}
@@ -0,0 +1,5 @@
let a = "outside";

function r(z, g = (a, b = a) => a) {
g(z);
}
@@ -0,0 +1,9 @@
module.exports = function() {
return {
visitor: {
FunctionDeclaration(path) {
path.scope.rename("a", "z");
}
}
};
};

0 comments on commit fb4125a

Please sign in to comment.