Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Dec 23, 2019
1 parent 349e57d commit 63dd253
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 8 deletions.
3 changes: 2 additions & 1 deletion packages/babel-traverse/src/path/lib/virtual-types.js
Expand Up @@ -64,7 +64,8 @@ export const Expression = {
};

export const Scope = {
types: ["Scopable"],
// When pattern is inside the function params, it is a scope
types: ["Scopable", "Pattern"],
checkPath(path) {
return t.isScope(path.node, path.parent);
},
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-traverse/src/scope/index.js
Expand Up @@ -902,14 +902,14 @@ export default class Scope {
do {
const binding = scope.getOwnBinding(name);
if (binding) {
// When a pattern is a Scope, it is a part of parameter expressions.
// Check if a pattern is a part of parameter expressions.
// 9.2.10.28: The closure created by this expression should not have visibility of
// declarations in the function body. If the binding is not a `param`-kind,
// then it must be defined inside the function body, thus it should be skipped
if (
previousPath &&
previousPath.isPattern() &&
previousPath.isScope() &&
previousPath.parentPath.isFunction() &&
binding.kind !== "param"
) {
// do nothing
Expand Down
3 changes: 1 addition & 2 deletions packages/babel-traverse/src/scope/lib/renamer.js
Expand Up @@ -9,9 +9,8 @@ const renameVisitor = {
}
},

"Pattern|Scope"(path, state) {
Scope(path, state) {
if (
path.isScope() &&
!path.scope.bindingIdentifierEquals(
state.oldName,
state.binding.identifier,
Expand Down
6 changes: 3 additions & 3 deletions packages/babel-traverse/test/scope.js
Expand Up @@ -73,8 +73,8 @@ describe("scope", () => {
).toBe("Identifier");
});

describe("function paramater expression", function() {
it("should not has visibility of declarations inside function body", () => {
describe("function parameter expression", function() {
it("should not have visibility of declarations inside function body", () => {
expect(
getPath(
`var a = "outside"; (function foo(b = a) { let a = "inside" })`,
Expand All @@ -83,7 +83,7 @@ describe("scope", () => {
.scope.getBinding("a").path.node.init.value,
).toBe("outside");
});
it("should has visibility on paramater bindings", () => {
it("should have visibility on parameter bindings", () => {
expect(
getPath(`var a = "outside"; (function foo(b = a, a = "inside") {})`)
.get("body.1.expression.params.0")
Expand Down
2 changes: 2 additions & 0 deletions packages/babel-types/src/validators/isScope.js
Expand Up @@ -19,6 +19,8 @@ export default function isScope(node: Object, parent: Object): boolean {
return false;
}

// If a Pattern is an immediate descendent of a Function, it must be in the params.
// Hence we skipped the parentKey === "params" check
if (isPattern(node) && isFunction(parent)) {
return true;
}
Expand Down

0 comments on commit 63dd253

Please sign in to comment.