Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

TypeError: Cannot read property 'length' of undefined (Caused by arrow functions in module) #1078

Closed
PaddeK opened this issue Feb 20, 2017 · 5 comments

Comments

@PaddeK
Copy link

PaddeK commented Feb 20, 2017

If i use arrow functions in a module i get an error while uploading the code via send button from WebIDE to espruino (wifi).

The error is:
TypeError: Cannot read property 'length' of undefined

Minimal test module (test.js):

'use strict';

let Test;

Test = function () {
    this.mtFn = () => {};
};
module.exports = Test;

Simply require the module and upload code to espruino will trigger the error.

Right hand side of WebIDE:

let Test = require('test');

If i replace the arrow function this.mtFn with a 'normal' function this.mtFn = function () {}; i get no error.

@gfwilliams
Copy link
Member

Where does this error come from? The Web IDE? I guess it's not from Espruino itself as there is no use of .length in the code

Unfortunately Espruino doesn't support all of ES6 so let won't work correctly, but that shouldn't actually be your problem.

@PaddeK
Copy link
Author

PaddeK commented Feb 21, 2017

Yes it comes from the Web IDE and as far as i can tell the uploaded code works fine so far.

@gfwilliams
Copy link
Member

Looks like it's a bug inside the esprima minification library that's being used.

If you turn off module minification in settings, or turn it to the online minification, it should work

@PaddeK
Copy link
Author

PaddeK commented Feb 21, 2017

Both suggestions work. I will use the online closure minifier for now.
Thank you!

@gfwilliams
Copy link
Member

Closing this - as moved to EspruinoTools now: espruino/EspruinoTools#58

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

No branches or pull requests

2 participants