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

The scope of the arguments default value is different from what was expected in ES2015 (参数默认值的作用域与 ES2015 的预期结果不同) #9947

Open
Yangfan2016 opened this issue May 6, 2019 · 1 comment

Comments

Projects
None yet
2 participants
@Yangfan2016
Copy link

commented May 6, 2019

Bug Report

Current Behavior
The scope of the arguments default value is different from what was expected in ES2015

Input Code

online view

This is source code of ES2015:

let foo = 'outer';

function bar(func = () => foo) {
  let foo = 'inner';
  console.log(func());
}

bar(); // outer

The result of run it:

outer

This is transform code by babel:

"use strict";

var foo = 'outer';

function bar() {
  var func = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {
    return foo;
  };
  var foo = 'inner';
  console.log(func());
}

bar(); // outer

The result of run it:

inner

Expected behavior/code

Expect the results of the Babel conversion to be consistent with ES2015 performance

Babel Configuration (.babelrc, package.json, cli command)

Environment

  • Babel version(s): [v7.4.4]
  • Node/npm version: [Node 8.9/npm 5]
  • OS: [Windows 10]
  • Monorepo: [no]
  • How you are using Babel: [babeljs.io]

Possible Solution

"use strict";

var foo = 'outer';

function bar() {
    var func = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function() {
        return foo;
    }
    ;
    (function() {

        var foo = 'inner';
        console.log(func());

    }())
}

bar();

Additional context/Screenshots
Add any other context about the problem here. If applicable, add screenshots to help explain.

@babel-bot

This comment has been minimized.

Copy link
Collaborator

commented May 6, 2019

Hey @Yangfan2016! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community
that typically always has someone willing to help. You can sign-up here
for an invite.

@Yangfan2016 Yangfan2016 changed the title The scope of the parameter default value is different from what was expected in ES2015 (参数默认值的作用域与 ES2015 的预期结果不同) The scope of the arguments default value is different from what was expected in ES2015 (参数默认值的作用域与 ES2015 的预期结果不同) May 6, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.