Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions packages/babel-traverse/src/scope/binding.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ import type NodePath from "../path";

export default class Binding {
constructor({ existing, identifier, scope, path, kind }) {
// this if condition is true only if the re-binding does not result in an error
// e.g. if rebinding kind is 'var' or 'hoisted', and previous was 'param'
if (existing) {
// we maintain the original binding but update constantViolations
existing.constantViolations = existing.constantViolations.concat(path);
return existing;
}

this.identifier = identifier;
this.scope = scope;
this.path = path;
Expand All @@ -26,14 +34,6 @@ export default class Binding {
this.references = 0;

this.clearValue();

if (existing) {
this.constantViolations = [].concat(
existing.path,
existing.constantViolations,
this.constantViolations,
);
}
}

constantViolations: Array<NodePath>;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function f(a, b) {
var a = "redeclared";
return b;
}

function g(a) {
function a() {
return "function, redeclared";
}
return a();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function f(z, b) {
var z = "redeclared";
return b;
}

function g(z) {
function z() {
return "function, redeclared";
}

return z();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"plugins": ["./plugin"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = function() {
return {
visitor: {
Function(path) {
path.scope.rename("a", "z");
}
}
};
}