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

Emit arrow function es6 #1627

Merged
merged 30 commits into from
Feb 2, 2015
Merged

Emit arrow function es6 #1627

merged 30 commits into from
Feb 2, 2015

Conversation

yuit
Copy link
Contributor

@yuit yuit commented Jan 9, 2015

Emit Arrow function natively in ES6 and capture "this"

@@ -3210,6 +3210,13 @@ module ts {
emitTrailingComments(node);
}

function isES6ArrowFunction(node: FunctionLikeDeclaration): boolean {
if (node.kind === SyntaxKind.ArrowFunction && compilerOptions.target >= ScriptTarget.ES6) {
Copy link
Contributor

Choose a reason for hiding this comment

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

return node.kind === ... && compilerOptions.target ...;

@@ -0,0 +1,29 @@
//// [emitArrowFunction.ts]
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be really helpful if the baseline stated the target, just like the original test.

@DanielRosenwasser
Copy link
Member

Are you still working off of this branch @yuit?

@yuit
Copy link
Contributor Author

yuit commented Jan 27, 2015

@DanielRosenwasser Yes. Fixing up thing now. Almost done

@yuit
Copy link
Contributor Author

yuit commented Jan 29, 2015

Address #1609. I think we should address this issue about arguments in Typescript Spec and align it with ES6

// arguments objects will be inner bound while emitting arrow function natively in ES6, arguments objects
// will be bound to non-arrow function that contain this arrow function. This results in inconsistent bahaviour.
// To avoid that we will give an error to users if they use arguments objects in arrow function so that they
// can explicitly bound arguments objects
Copy link
Member

Choose a reason for hiding this comment

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

Tabs -> Spaces

needToCaptureLexicalThis = true;

// When targeting es6, arrow function lexically bind "this" so we do not need to do the work of binding "this" in emitted code
if (compilerOptions.target >= ScriptTarget.ES6) {
Copy link
Member

Choose a reason for hiding this comment

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

Reduce this to one branch, it's already set to false.

Copy link
Contributor

Choose a reason for hiding this comment

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

needToCaptureLexicalThis = compilerOptions.target >= ScriptTarget.ES6

@@ -3263,6 +3263,10 @@ module ts {
emitTrailingComments(node);
}

function isES6ArrowFunction(node: FunctionLikeDeclaration): boolean {
Copy link
Member

Choose a reason for hiding this comment

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

Just consolidate this into a local variable.
Never mind, that's not feasible.

function emitSignatureParametersES6(node: FunctionLikeDeclaration) {
// Check the node's parameters whether it contains flags indicating that it has no parenthesis around the parameters
// Preserver no-parenthesis
if (node && node.flags & NodeFlags.SimpleArrowFunction) {
Copy link
Member

Choose a reason for hiding this comment

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

Parens around the & expression please

Copy link
Member

Choose a reason for hiding this comment

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

Also why would node be undefined?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree with you on that. I just check to make sure but you are right this shouldn't happen

@@ -3303,6 +3313,20 @@ module ts {
decreaseIndent();
}

function emitSignatureParametersForArrow(node: FunctionLikeDeclaration) {
// Check whether the parameter list needs parentheses and preserve no-parenthesis
if (node.flags & NodeFlags.SimpleArrowFunction) {
Copy link
Contributor

Choose a reason for hiding this comment

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

i do not think you need this flag.

@DanielRosenwasser
Copy link
Member

diagnosticMessages.json is all tabs, in master it's all spaces, you might want to pull in from master and make sure there are no tabs.

@yuit
Copy link
Contributor Author

yuit commented Jan 31, 2015

@DanielRosenwasser Yes they are tabs

@JsonFreeman
Copy link
Contributor

👍

@yuit
Copy link
Contributor Author

yuit commented Jan 31, 2015

@basarat I have updated the error message in the last few commits

@basarat
Copy link
Contributor

basarat commented Jan 31, 2015

I have updated the error message in the last few commits

sorry. my bad.

@yuit
Copy link
Contributor Author

yuit commented Feb 2, 2015

@basarat no worry :) Thanks for code reviewing!

yuit pushed a commit that referenced this pull request Feb 2, 2015
@yuit yuit merged commit eed1576 into master Feb 2, 2015
@yuit yuit deleted the emitArrowFunctionES6 branch February 2, 2015 19:31
@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants