-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[CS2] Docs: Need to add breaking changes info about =>
differences in CS2
#4593
Comments
That's correct:
|
@vendethiel - I understand what happens. I'm saying that this is not consistent with what one would expect from CoffeeScript. There are only anonymous functions in CoffeeScript which means that I can never get the real Again, I'm saying that CoffeeScript should compile lamba functions that use |
We've adopted ES2015 semantics for fat arrow functions to reduce the barrier for users working in both languages. The best way to achieve this now would be to use a splat: (args...) => console.log args |
This probably needs to be documented as a breaking change if it's not already. Edit: looks like it's not. |
I don't think it is, I checked the documentation. I could have missed it though. But this is kind of bad... another example: originalWindowError = window.onerror
window.onerror = (messageOrEvent, source, lineNumber, columnNumber, error) => # general window errors
@_notify(error)
originalWindowError?(arguments...) How can I achieve the same effect with |
Yes, thank you. I agree it's weird that |
If anything, it doesn't seem to be documented on /v2 |
We could go down the route of normalising that, but there are quite a few cases to consider as arrow functions also behave differently with respect to class A extends B
f: ->
setImmediate(=> super arguments...) This would need to account for the fact that var A
A = class A extends B {
f () {
return setImmediate((...args) => {
return super.f(...args)
})
}
} As you note, it gets even more interesting with arguments. For functions with We could choose instead to take the breaking change (possibly with a compiler error for |
Re: your example @boris-petrov, I guess a workaround for now would be destructuring: window.onerror = (args...) =>
[ messageOrEvent, source, lineNumber, columnNumber, error ] = args
@_notify(error)
originalWindowError?(args...) |
@connec - I agree, what you propose would fix my specific usecase, but if I were designing the language, I would strongly disagree with the idea that What I would do is I would preserve I'm not the one to make decisions, but again - if it were up to me, I wouldn't take the P.S. Also, I think this will break a lot of code. Lots more than anything else that isn't backwards-compatible. I spent 10 minutes today fixing backwards-incompatible things (which were "compile"-time errors) and one or two hours going after the arrow stupidity of ES6. |
When I was implementing the change to use the ES var a = function (b, c) {
var d = () => console.log(arguments);
d();
}
a(1, 2);
// [1, 2] So we can’t simply throw an error if we see a variable named What we should do is document this under http://coffeescript.org/v2/#breaking-changes, along with any other differences between the CS1 |
arguments
in arrow function=>
differences in CS2
@GeoffreyBooth - I'm not sure what you mean by "or else code like the above won’t behave as it should". You are designing the language which means that you could make the code behave any way you want. :) Nobody says that But anyway, I see that nobody likes my idea. :D If you prefer to leave it working as it is now, then yes, you should at least document it, as this is a big breaking change I think. |
I’ll add it to the docs. I hear your point that we’re designing the language, but in many ways we’re not—if we want to be able to interoperate with ES2015 classes, for example, we need to use the |
The "just JavaScript" idea has always been one of the very few things I don't like about CoffeeScript. :D But you are right that you have your mission statement and you have to follow it! Thank you for everyone's time! We all appreciate your work on CoffeeScript! :) |
Thanks for bringing it to our attention, and for the well-reasoned, civil discourse 😄 |
* Don’t confuse the syntax highlighter * Comment Assign::compilePatternMatch a bit * Assignment expressions in conditionals are a bad practice * Rename `wrapInBraces` to `wrapInParentheses`, to set the stage for future `wrapInBraces` that uses `{` and `wrapInBrackets` that uses `[` * Correct comment * object destructuring * Allow custom position of the rest element. * Output simple array destructuring assignments to ES2015 * Output simple object destructured assignments to ES2015 * Compile shorthand object properties to ES2015 shorthand properties This dramatically improves the appearance of destructured imports. * Don’t confuse the syntax highlighter * Comment Assign::compilePatternMatch a bit * Assignment expressions in conditionals are a bad practice * Rename `wrapInBraces` to `wrapInParentheses`, to set the stage for future `wrapInBraces` that uses `{` and `wrapInBrackets` that uses `[` * object destructuring * Allow custom position of the rest element. * rest element in object destructuring * rest element in object destructuring * fix string interpolation * merging * fixing splats in object literal * Rest element in parameter destructuring * merging with CS2 * merged with CS2 * Add support for the object spread initializer. https://github.com/tc39/proposal-object-rest-spread/blob/master/Spread.md * Fix misspellings, trailing whitespace, other minor details * merging with beta2 * refactor object spread properties * small fix * - Fixed object spread function parameters. - Clean up "Assign" and moved all logic for object rest properties in single method (compileObjectDestruct). - Add helper function "objectWithoutKeys" to the "UTILITIES" for use with object rest properties, e.g. {a, b, r...} = obj => {a, b} = obj, r = objectWithoutKeys(...) - Clean up "Obj" and moved all logic for object spread properties in single method (compileSpread). - Clean up "Code". - Add method "hasSplat" to "Obj" and "Value" for checking if Obj contains the splat. - Enable placing spread syntax triple dots on either right or left, per #85 (coffeescript6/discuss#85) * Fixed typos * Remove unused code * Removed dots (e.g. splat) on the left side from the grammar * Initial release for deep spread properties, e.g. obj2 = {obj.b..., a: 1} or {obj[b][c]..., d: 7} Tests need to be prepared! * 1. Object literal spread properties Object literals: - obj = { {b:{c:{d:1}}}..., a:1 } Parenthetical: - obj = { ( body ), a:1 } - obj = { ( body )..., a:1 } Invocation: - obj = { ( (args) -> ... )(params), a:1 } - obj = { ( (args) -> ... )(params)..., a:1 } - obj = { foo(), a:1 } - obj = { foo()..., a:1 } 2. Refactor, cleanup & other optimizations. * Merged with 2.0 * Cleanup * Some more cleanup. * Fixed error with freeVariable and object destructuring. * Fixed errors with object spread properties. * Improvements, fixed errors. * Minor improvement. * Minor improvements. * Typo. * Remove unnecessary whitespace. * Remove unnecessary whitespace. * Changed few "assertErrorFormat" tests since parentheses are now allowed in the Obj. * Whitespace cleanup * Comments cleanup * fix destructured obj param declarations * refine fix; add test * Refactor function args ({a, b...}) * Additional tests for object destructuring in function argument. * Minor improvement for object destructuring variable declaration. * refactor function args ({a, b...}) and ({a, b...} = {}); Obj And Param cleanup * fix comment * Fix object destructuring variable declaration. * more tests with default values * fix typo * Fixed default values in object destructuring. * small fix * Babel’s tests for object rest spread * Style: spaces after colons in object declarations * Cleanup comments * Simplify Babel tests * Fix comments * Fix destructuring with splats in multiple objects * Add test for default values in detsructuring assignment with splats * Handle default values when assigning to object splats * Rewrite traverseRest to fix handling of dynamic keys * Fix double parens around destructuring with splats * Update compileObjectDestruct comments * Improve formatting of top-level destructures with splats and tidy parens * Added a bigger destructuring-with-defaults test and fixed a bug * Refactor destructuring grammar to allow additional forms * Add a missing case to ObjSpreadExpr * These tests shouldn’t run in the browser * Fix test.html * Fix docs scroll position getting screwed up by CodeMirror initialization * Breaking change documentation about => (fixes #4593) * Spread/rest syntax documentation * Documentation about bound class methods * 2.0.0-beta3 changelog * Add note about ‘lib’ * Fix accidentally converting this to tabs * Bump version to 2.0.0-beta3 * Update annotated source and test.html
Is compile to:
But according to this, arrow functions do not have their own
arguments
. I think this is a bug inCoffeeScript 2
. Wheneverarguments
are used, that function should not compile to anarrow
function. Or do you have some... um... arguments against that? :)The text was updated successfully, but these errors were encountered: