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

No arrow functions despite harmony flag #2118

Closed
ghost opened this issue Jul 4, 2015 · 6 comments
Closed

No arrow functions despite harmony flag #2118

ghost opened this issue Jul 4, 2015 · 6 comments

Comments

@ghost
Copy link

ghost commented Jul 4, 2015

My main.js file contains this:

app.on('ready', function () {
  app.commandLine.appendSwitch('js-flags', '--harmony');
  // ...
});

Yet arrow functions are unrecognized. Let, const, and classes still work (with "use script").

Using Electron v0.29.1 on Gentoo Linux 2.2

@steelbrain
Copy link
Contributor

How about

var v8 = require('v8')
v8.setFlagsFromString('--harmony-arrow-functions')

https://iojs.org/api/v8.html#v8_setflagsfromstring_string

@steelbrain
Copy link
Contributor

Also --harmony isn't supposed to turn on arrow functions see, https://iojs.org/en/es6.html

@ghost
Copy link
Author

ghost commented Jul 4, 2015

Unfortunately, passing neither --harmony-arrow-functions nor --harmony_arrow_functions into v8.setFlagsFromString is enabling arrow functions.

However,

app.on('ready', function () {
  app.commandLine.appendSwitch('js-flags', '--harmony_arrow_functions');
  // ...
});

now solves the problem. I was not aware arrow functions was masked but now I know that an extra flag is required. Thanks!

@ghost ghost closed this as completed Jul 4, 2015
@0x80
Copy link

0x80 commented Jul 5, 2015

@keizom I've tried your solution but I still get this error when launching electron:

> DEBUG='app:*' HOT=1 NODE_ENV=development electron .

App threw an error when running [SyntaxError: /Users/me/MyApp/main.js:16
tingle.on('open', () => {
                   ^
Unexpected token )]

Am I missing something? I'm using 0.29.1

@ghost
Copy link
Author

ghost commented Jul 5, 2015

@0x80 the code I used enabled arrow functions in a renderer process. Perhaps there is a difference between enabling a renderer process and the main process (?). I do not know electron well enough to know if this is the case.

In the mean time, have you tried @steelbrain's method using v8.setFlagsFromString?

@0x80
Copy link

0x80 commented Jul 5, 2015

@keizom The code in my renderer process runs through webpack and babel so that's not an issue I guess. I found my problem. You can only put ES6 code in a module that you then require. I was putting arrow functions right in the main.js file where also the v8.setFlagsFromString() calls were made. I don't think that's possible since the syntax will be interpreted/parsed before the flag settings have effect. Anyways it's working now! 👍

This issue was closed.
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