These are chat archives for opal/opal

11th
May 2018
Jan Biedermann
@janbiedermann
May 11 2018 04:00

so when i do this in node:

p = Opal.Opal.$const_get('Compiler').$new('/((::)?([A-Z]\w*)(::[A-Z]\w*)*)$/ =~ e.message')
p.$compile()

i get this:

names: undefined method `names' for /((::)?([A-Z]w*)(::[A-Z]w*)*)$/:Regexp

Looks like Regexp.names not implemented for nodejs?
Or is there something i must require for this to work in node?
Or what can i do?

I tried to find the place where the compiler/parser actually calls names, but i couldnt, where is this coming from?
Ilya Bylich
@iliabylich
May 11 2018 08:39
Our parser uses Regexp#names to handle a =~ node in the AST
And Regexp#names is not implemented in Opal
So I'd suggest to use String#match instead - e.message.match(/((::)?([A-Z]\w*)(::[A-Z]\w*)*)$/)
That's a limitation of opal-parser. Some functionality that is used by the compiler is not implemented in Opal, so it's available only when you parse and compile your code using MRI
Jan Biedermann
@janbiedermann
May 11 2018 18:41

@iliabylich thanks, and here is Regexp.names opal/opal#1822

i intend to always compile my code in opal nodejs, what other functionality is missing or how can i find out?

Ilya Bylich
@iliabylich
May 11 2018 18:53
I don't know. It's not recommended to use opal-parser because it's too slow and may have bugs that we are not aware of.
Theoretically we could try to setup a separate job on CI to compile rubyspecs using opal-parser
But I'm sure that there are more bugs and I'd suggest you to not use it :)
Jan Biedermann
@janbiedermann
May 11 2018 18:57
well, thats interesting, because i work on a opal-webpack-loader, for a better life, without sprockets
i know its slow, but doesnt scare me, because caching and things, so what i have its already on par with my sprockets experience
and will get much better i hope, like for example inline source maps
but thats also kinda a problem
and when i acutally try to run my names patch in opal i get this:
SyntaxError: named captures are not supported in javascript: "\$(?<dollars>\d+)\.(?<cents>\d+)\.(?<microcents>\d+)"
whis is not true, at least in my nodejs version 10
Ilya Bylich
@iliabylich
May 11 2018 19:00
yeah, the latest ecma supports named captures
my chrome also supports it
Jan Biedermann
@janbiedermann
May 11 2018 19:01
it would be very nice, if you would instruct me how to run the compiler tests in nodejs and if you setup the ci for this, maybe its not to much work to fix it
Ilya Bylich
@iliabylich
May 11 2018 19:04
Well, I think the simplest solution is to have a special job that has a patched version of Kernel#require that does eval(File.read(f))
(only for paths starting with spec/ruby)
eiko
@eiko
May 11 2018 19:05
i don't have a lot of experience with nodejs or webpack loaders, but is there anything stopping you from using child_process.exec to compile ruby to javascript directly, instead of trying to do it within nodejs?
Ilya Bylich
@iliabylich
May 11 2018 19:05
Or probably we could inline the content of those files like eval("file-content")
@eiko yeah, it sound much easier
Jan Biedermann
@janbiedermann
May 11 2018 19:07
opal wasnt easy, easy is not the argument, but employing the webpack infrastructure is, with all the things it has to offer
i mean i got the opal-webpack-builder working alright, mostly, except for goodies, source maps and so on
fixing opal cant be wrong
@iliabylich @elia why doesnt opal use the js Opal.Const.Conct.Const but Opal.Const.$get_const('Const').$get_const('Const') ?
Ilya Bylich
@iliabylich
May 11 2018 19:12
It does, on master
Jan Biedermann
@janbiedermann
May 11 2018 19:12
oh, thats great news
next question, what about using some standard js module thing for require?
Jan Biedermann
@janbiedermann
May 11 2018 19:20
or rephrased, what if i add a compiler option, that instead of doing the Opal.modules["my/moduleā€œ] thing, does some js module thing, then i need to also adapt the runtime loader/require methods accordingly, does that sound good? Would there be something in the way?
Ilya Bylich
@iliabylich
May 11 2018 19:53
Take a look at Opal.require (in runtime.js), that's what used under the hood. Not sure how else I could help you, I'm not familiar with the webpack ecosystem
Jan Biedermann
@janbiedermann
May 11 2018 19:58
alright, thanks a lot. now i look at the "named captures not supported" exception", just eliminating it doesnt feel right, just leaving it in place neither, but also opal has no notion of target version, so how to handle?
Ilya Bylich
@iliabylich
May 11 2018 20:02
right now that's impossible
Jan Biedermann
@janbiedermann
May 11 2018 20:09
this where maybe a webpack based build process could help, where you just use the latest ESxx code and let one of the ESxx compilers handle the rest so that it works on all browsers.