Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't resolve shadowed arguments variables from functions #14036

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,7 +1,9 @@
var _arguments2 = 1;
var _arguments2 = typeof arguments === "undefined" ? void 0 : arguments;

var arguments = 1;

function fn() {
var _arguments = _arguments2;
var _arguments = arguments;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for self and others: this is correct, the test was previously broken — fn should not see the outer arguments, because it was not an arrow function in input.js


var foo = function () {
return _arguments;
Expand Down
@@ -1,3 +1,5 @@
var _arguments6 = typeof arguments === "undefined" ? void 0 : arguments;

function one() {
var _arguments = arguments;

Expand Down Expand Up @@ -83,26 +85,27 @@ function six(obj) {
six();

var seven = function () {
var _arguments6 = 1;
var arguments = 1;
return _arguments6;
};

seven();

var eight = function () {
var _arguments7 = 1;
var arguments = 1;
return function () {
return _arguments7;
return _arguments6;
};
};

eight();

function nine() {
var _arguments8 = 1;
var _arguments7 = arguments;
var arguments = 1;

var foo = function () {
return _arguments8;
return _arguments7;
};
}

Expand All @@ -111,9 +114,9 @@ nine();
var eleven = function () {
var arguments = 2;
return function () {
var _arguments9 = arguments;
var _arguments8 = arguments;
return function () {
return _arguments9;
return _arguments8;
};
};
};
Expand All @@ -124,9 +127,9 @@ var twelve = function () {
var arguments = 2;
return class {
m() {
var _arguments10 = arguments;
var _arguments9 = arguments;
return function () {
return _arguments10;
return _arguments9;
};
}

Expand Down
2 changes: 1 addition & 1 deletion packages/babel-traverse/src/path/conversion.ts
Expand Up @@ -635,7 +635,7 @@ const getScopeInformationVisitor = mergeVisitors<{

let curr = child.scope;
do {
if (curr.hasOwnBinding("arguments")) {
if (curr.hasOwnBinding("arguments") && !curr.hasBinding("arguments")) {
The-x-Theorist marked this conversation as resolved.
Show resolved Hide resolved
curr.rename("arguments");
return;
}
Expand Down
@@ -0,0 +1,11 @@
var arguments = [1, 2, 3];
var arr = () => arguments[0];

arr(); // 1
The-x-Theorist marked this conversation as resolved.
Show resolved Hide resolved

function foo(n) {
var f = () => arguments[0] + n; // foo's implicit arguments binding. arguments[0] is n
return f();
}

expect(foo(3)).toStrictEqual(6)
@@ -0,0 +1,10 @@
var arguments = [1, 2, 3];
var arr = () => arguments[0];

arr(); // 1

function foo(n) {
var f = () => arguments[0] + n; // foo's implicit arguments binding. arguments[0] is n
return f();
}

@@ -0,0 +1,4 @@
{
"sourceType": "unambiguous",
"presets": ["env"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Babel 8 tests are failing because you didn't specify any target here. Could you move this test in the arrow functions plugin, and enable the plugin instead of the preset?
Also, please specify "sourceType": "script" since this is specific to loose mode.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I can do that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the same as you said.

}
@@ -0,0 +1,20 @@
var _arguments = typeof arguments === "undefined" ? void 0 : arguments;

var arguments = [1, 2, 3];

var arr = function arr() {
return _arguments[0];
The-x-Theorist marked this conversation as resolved.
Show resolved Hide resolved
};

arr(); // 1

function foo(n) {
var _arguments2 = arguments;

var f = function f() {
return _arguments2[0] + n;
}; // foo's implicit arguments binding. arguments[0] is n


return f();
}