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

Not work with Babel #22

Closed
bySabi opened this issue Jul 11, 2017 · 5 comments
Closed

Not work with Babel #22

bySabi opened this issue Jul 11, 2017 · 5 comments

Comments

@bySabi
Copy link
Contributor

bySabi commented Jul 11, 2017

Transformed code with Babel not work.

Probably is due this is not set: from js-function-reflector doc:

var functionReflector = require('js-function-reflector');
// If you are using babel transpiler
functionReflector = reflector.compiler('babel-preset-es2015');
@bySabi
Copy link
Contributor Author

bySabi commented Jul 11, 2017

I think this must be solve explicitly:

const matcher = require('z')    // native ES6

AND

var matcher = require('z/babel')   // Babel compliant

@leonardiwagner
Copy link
Member

leonardiwagner commented Jul 11, 2017

@bySabi I didn't start to work on babel, and I don't know to work with him yet, I have a question:

when you write a match like this:

matches(1)(
  (x = { name: String})  => console.log('hey!'),
  (x = Number) => console.log('ya!')
)

it'll transpile as:

matches(1)(function () {
  var x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { name: String };
  return console.log('hey!');
}, function () {
  var x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : Number;
  return console.log('ya!');
});

since internal transpiled functions doesn't have parameters, z can't read'em as patterns

is there a way to receive the written code instead the transpiled one in z?

@bySabi
Copy link
Contributor Author

bySabi commented Jul 11, 2017

is there a way to receive the written code instead the transpiled one in z?

I'm afraid this is not posible, maybe with a babel-plugin and making annotations in matches function patterns. But I think is not worth it.
The js-function-reflector approach is more simple, babel-preset-es2015-reflector parse tranformed functions and extract default params.

z need the fastest function parameter extraction code. The performance of this library will relay on this part. We must create a customized function parameter parser, aka reflector, and left current solution, js-function-reflector

I started to coding one from scratch with benchmark comparison vs current reflector. It will cover babel case too.

@leonardiwagner
Copy link
Member

@bySabi ok, I wasn't aware howbabel-preset-es2015 works, I'm gonna take a look later on this too, thank you.

@bySabi
Copy link
Contributor Author

bySabi commented Jul 13, 2017

I will follow another path where Babel is not a problem.

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

2 participants