Skip to content

Support native arrow functions as stateless components#4859

Merged
zpao merged 1 commit intofacebook:masterfrom
zpao:stateless-arrow-functions
Sep 16, 2015
Merged

Support native arrow functions as stateless components#4859
zpao merged 1 commit intofacebook:masterfrom
zpao:stateless-arrow-functions

Conversation

@zpao
Copy link
Copy Markdown
Member

@zpao zpao commented Sep 13, 2015

I tested this with arrow functions in Chrome (just modified the non-transforming basic example).

We could simulate part of the issue with arrow functions in the test (undefined prototype), but not the newable part. So we'll want a proper test when we can switch to node 4 and have some tests that don't transform.

Fixes #4856

@zpao
Copy link
Copy Markdown
Member Author

zpao commented Sep 13, 2015

cc @sebmarkbage @spicyj

@zpao zpao changed the title Support arrow functions as stateless components Support native arrow functions as stateless components Sep 13, 2015
@glenjamin
Copy link
Copy Markdown
Contributor

Native arrow functions have typeof == function, and can never have a prototype property at all, so using 'prototype' in f is probably are a more reliable approach:

> node
> a = () => 1
[Function]
> a
[Function]
> a.prototype
undefined
> 'prototype' in a
false
>
> typeof a
'function'
> b = function(){}
[Function]
> b.prototype
{}
> 'prototype' in b
true
> delete b.prototype
false
> 'prototype' in b
true
> b.prototype = undefined
undefined
> 'prototype' in b
true

@zpao
Copy link
Copy Markdown
Member Author

zpao commented Sep 14, 2015

That's a good point. We won't be able to test at all in that case but perhaps that's ok…

@glenjamin
Copy link
Copy Markdown
Contributor

You could do something like try { eval("() => 1") } catch(ex) {} to detect and test only when arrow functions exist?

I guess that's not as relevant because the testsuite locks itself to v0.10?

@sebmarkbage
Copy link
Copy Markdown
Contributor

Native fn.bind() also gives you a prototype less function. Should be able to use that to test even with transform and older VMs.

@zpao zpao added this to the 0.14 milestone Sep 16, 2015
@zpao
Copy link
Copy Markdown
Member Author

zpao commented Sep 16, 2015

Updated for comments. I didn't say it in a comment but I explicitly used .bind instead of of using an arrow function and letting Babel transform since we don't know what that will do (right now it's not high compliance mode so won't actually call .bind)

@sebmarkbage
Copy link
Copy Markdown
Contributor

lgtm

zpao added a commit that referenced this pull request Sep 16, 2015
Support native arrow functions as stateless components
@zpao zpao merged commit 0fb49fc into facebook:master Sep 16, 2015
@zpao zpao deleted the stateless-arrow-functions branch October 13, 2015 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants