Skip to content

ES6 support #2

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

Closed
chocolateboy opened this issue Mar 21, 2015 · 7 comments
Closed

ES6 support #2

chocolateboy opened this issue Mar 21, 2015 · 7 comments

Comments

@chocolateboy
Copy link

Various ES6 features are unsupported e.g.:

test

var re = require('function-regex')();

var str1 = "function foo ({ bar, baz }) { }";
var str2 = "function foo ([ bar, baz ]) { }";
var str3 = "function foo (bar = 42) { }";
var str4 = "function foo (...bar) { }";

console.log(re.exec(str1));
console.log(re.exec(str2));
console.log(re.exec(str3));
console.log(re.exec(str4));

output

null
null
null
null
@chocolateboy
Copy link
Author

There's also function* (ES6) and async function (ES7).

@jonschlinkert
Copy link
Member

IMHO this qualifies for a different regex. like es6-function-regex

@jonschlinkert
Copy link
Member

technically this shouldn't even be called "function-regex" since it's not. It should be more specific, like: https://github.com/jonschlinkert/parse-code-context/blob/master/index.js#L14-L33

@chocolateboy
Copy link
Author

IMHO this qualifies for a different regex. like es6-function-regex

I agree that this is probably out of scope for this package.

But, come to think of it, a regex will never be able to handle destructured parameters in the general case, since regular languages don't support balanced delimiters.

@chocolateboy
Copy link
Author

https://github.com/jonschlinkert/parse-code-context/blob/master/index.js#L14-L33

FYI: that regex shares several issues with this regex and adds at least one new issue e.g. it doesn't handle:

function  foo () {} // > 1 space

or:

function // newline
foo () {}

@tunnckoCore
Copy link
Member

Yea, I think it should go to something like es6-function-regex because we should also handle arrow functions?

@chocolateboy
Copy link
Author

Closing this, since — as mentioned — a regex can't handle all ES6 function syntax (e.g. destructuring).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants