Proposal: "function-default-params" scope
See original GitHub issueAs the step 27.a of 9.2.12 FunctionDeclarationInstantiation( func, argumentsList ), eslint-scope
should make new scope for the function body only if the parameters has any default value.
It’s similar to function-expression-name
scope which separates the variable of function expression names from function bodies. So I propose new function-default-params
scope which separates the references in default parameters from function bodies.
- If the current function has one or more default parameters in traversing, the referencer defines a
function-default-params
scope instead offunction
scope.- Note: the
function-default-params
scope has implicitarguments
variable except if the function is arrow function expression. - Note: the
function-default-params
scope is the child scope offunction-expression-name
scope if the function is function expression.
- Note: the
- The referencer evaluates the parameters.
- The referencer defines
function
scope. - The referencer copies the all variables from the
function-default-params
scope to thefunction
scope.- Note: those copies handle redeclaration such as
function f(a = 1) { let a }
correctly. - Note: at least,
no-shadow
rule has to handle those copies as special. - Note: I think we should use shallow copy here because
Variable#defs
andVariable#references
should be shared with both scopes butReference#resolved
property cannot have multiple variable objects. For example, infunction f(a, b = a) { g(a) }
case, the two references ofa
should be aggregated into oneVariable#references
array.
- Note: those copies handle redeclaration such as
- The referencer evaluates the function body.
- The referencer closes both
function-default-params
andfunction
scopes at the end of the function.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Default parameters - JavaScript - MDN Web Docs
Default function parameters allow named parameters to be initialized with default values if no value or undefined is passed.
Read more >JS: Default function parameter values and scope
I'm a bit confused about how scope & variable assignment within a function seems to change when assigning a default parameter value for...
Read more >Proposal to change the default ownership for passing parameters ...
Currently the calling convention for non-trivial parameters in swift is that the caller transfers ownership to the callee. In terms of reference counting, ......
Read more >Understanding Default Parameters in JavaScript - DigitalOcean
Function Calls as Default Parameters You can even use built-in methods, like those on the Math object, and use the value returned in...
Read more >Default Parameters - Learn JavaScript: Functions and Scope
Default parameters allow parameters to have a predetermined value in case there is no argument passed into the function or if the argument...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@kaicataldo No. The #33 was a superficial fix because I avoided breaking changes. And this is a follow‐up issue to make the correct scope structure.
But probably I should write an RFC.
I don’t think this issue has been fixed. If I’m understanding correctly, #33 fixed https://github.com/estools/escope/issues/130, which is a separate issue.