You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As of recently, we do not allow references to 'arguments' in an arrow function. So the following code will error:
functionfoo(){()=>{arguments;}}
Here is what the ES6 spec has to say in section 14.2.16:
An ArrowFunction does not define local bindings for arguments, super, this, or new.target. Any reference to arguments, super, or this within an ArrowFunction must resolve to a binding in a lexically enclosing environment. Typically this will be the Function Environment of an immediately enclosing function.
From reading this, it seems that the reference to arguments should resolve to the arguments of foo, and should not be an error in ES6. This does not match our current semantics because we error, and our ES5 emit causes arguments to reference the arguments of the inner function.
Here are the questions:
Should we error in ES5?
Should we error in ES6?
Should we change the ES5 emit to match ES6 semantics (emit an arguments capture similar to a this capture)?
Any solution will be some combination of yesses and noes to those 3 questions. Here are some options worth discussing:
Today's behavior - always error in ES5 and ES6, and don't change the ES5 emit.
Cons: ES6 users will get an error on perfectly valid ES6 code. ES5 users get an error even though their code worked before.
Error in ES5, but not in ES6. Keep the ES5 code binding to the arrow function.
Pros: Valid ES6 code works correctly, with no errors. ES5 behavior is preserved for users who want it, but they are warned that it will not work the same in ES6. So as long as they upgrade to ES6 after upgrading to our new compiler, they will have time and notice to update their code.
Cons: ES5 and ES6 have different semantics.
Error in ES5, but change the emit to match the ES6 semantics.
Pros: ES5 and ES6 have the same semantics. ES5 users who exhibit a sudden change in behavior will get a nice error notifying them of the behavior change.
Cons: ES5 users will have to change code that was working fine before.
No errors, keep the ES5 emit how it is.
Cons: ES5 and ES6 have different semantics with no user notification. The user will upgrade to -t es6 and suddenly get different behavior.
No errors, change the ES5 emit to match ES6 semantics.
Pros: ES5 and ES6 have the same semantics.
Cons: When the user upgrades to TS 1.5, but keeps -t es5, they will get a sudden change in semantics with no notification.
Needless to say, every single one of these is a breaking change.
The text was updated successfully, but these errors were encountered:
As of recently, we do not allow references to 'arguments' in an arrow function. So the following code will error:
Here is what the ES6 spec has to say in section 14.2.16:
From reading this, it seems that the reference to arguments should resolve to the arguments of foo, and should not be an error in ES6. This does not match our current semantics because we error, and our ES5 emit causes
arguments
to reference the arguments of the inner function.Here are the questions:
Any solution will be some combination of yesses and noes to those 3 questions. Here are some options worth discussing:
-t es6
and suddenly get different behavior.-t es5
, they will get a sudden change in semantics with no notification.Needless to say, every single one of these is a breaking change.
The text was updated successfully, but these errors were encountered: