Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Ghost
@ghost~59874280d73408ce4f704e9c
yes, so it get quickly ugly in this area
Ilya Bylich
@iliabylich
To handle such cases we need a JS parser :smile:
Ghost
@ghost~59874280d73408ce4f704e9c
yes, thats what i thought too, or maybe just a convention, like: inline blocks are executed as function and must 'return' a value, if so desired
Ilya Bylich
@iliabylich
I'm not sure about it, Opal generates anonymous utility functions in a couple of places. If Opal wraps your code into JS function you as a developer have to add explicit return (even if it's not obvious for Ruby developer).
For example:
a = if true
  `true`
else
  `false`
end
A rule like "Opal never adds 'return' to your x-strings" requires developers to write return true and return false
Ghost
@ghost~59874280d73408ce4f704e9c
maybe only for multiline blocks then?
Ilya Bylich
@iliabylich
That's the current behavior (after fixing an issue with multiline x-strings detection) :smile:
Ghost
@ghost~59874280d73408ce4f704e9c
just tried your strs.length > 1, fixes the latter case of the added return, but does not fix the first case of the missing return
makes 6 specs fail. Ok, a progress made, latter case fixed with beauty, ill digg on
Ilya Bylich
@iliabylich
Because it has a return inside
In the anonymous function
Wait, are you talking about opal/opal-activesupport#16 ?
Ghost
@ghost~59874280d73408ce4f704e9c
yes
Ilya Bylich
@iliabylich
Yes, that's it, similar to
def m
  `'return'`
end
# or
def m
  `(function() { return 1})()`
end
We can't fix it
Or even this :smile:
def m
  `#{"return"}`
end
Ghost
@ghost~59874280d73408ce4f704e9c
Then the fix is documentation, i guess: if you use anonymous functions with return in a inlined js block, you must explicitly return a value from the inlined block
Ghost
@ghost~59874280d73408ce4f704e9c
no wait, its worse, it would also hit a return_ticket_price = #{total_ticket_price - to_ticket_price}
Ghost
@ghost~59874280d73408ce4f704e9c

makes 6 specs fail

is actually not true, works perfectly with mulitline = strs > 0, was my debugging output leftover that made tests fail

Ghost
@ghost~59874280d73408ce4f704e9c

@iliabylich now this multiline patch breaks for example:

  def self.find(selector)
    `$(#{selector})`
  end

from opal-query, which is now considered a multiline, so no return is added, leading to:

  return Opal.defs(self, '$find', TMP_find_1 = function $$find(selector) {
    var self = this;

    $(selector)
  }, TMP_find_1.$$arity = 1)
chaning it to multiline = strs.any? { |str| str.end_with?("\n") }does seem to do the right thing
Simon George
@sfcgeorge
Kinda makes sense as semicolons are optional in JS, checking for newlines would do what it says on the tin I guess.
Ilya Bylich
@iliabylich
I guess it does handle
def m
  %x{
    1 + 1
  }
end
Simon George
@sfcgeorge
I'd assume there's a strip somewhere
Ilya Bylich
@iliabylich
That's an AST, not a string with the source code
Simon George
@sfcgeorge
Yeah, an AST usually doesn't have whitespace in
Ghost
@ghost~59874280d73408ce4f704e9c
but thats a ruby ast, where the inline js is just a string
or many strings
interrupted by ruby ast, if you js #{ ruby } more js
and the problem is exactly there, to understand js without parsing it :(
Simon George
@sfcgeorge
If the JS is just a string then surely you can strip it, so that wouldn't mistakenly be treated as multiline.
Ghost
@ghost~59874280d73408ce4f704e9c
and the ruby ast in between?
so its still ast nodes, of type :str, containing partial js
thats a :str
oh, ok, so for this case:
`$(#{selector})`
there is a tree :xstr with children:
:str (first part of js) :begin (ruby ast) :str (last part of js)
that are :strs
Ghost
@ghost~59874280d73408ce4f704e9c
so the 'mulitline' her is not the whitespace in the :strbut multiple :str, was, now with above fix, to look in the :str for a \nmulitline js is detected.
But @sfcgeorge you have a point, as minified js is minified to one line strings with no whitespace, but how would that stripping of whitespace benefit the situation here?
Mitch VanDuyn
@catmando
@/all question just came up... there is a Promise.when which could be called Promise.when_all, so why is there not a Promise.when_any?
G. Gibson
@mistergibson
So, is it impossilbe to work with a string that is ASCII8BIT ?
G. Gibson
@mistergibson
oh - got it - nevermind
G. Gibson
@mistergibson
Does anyone know of some example code for working with Buffer class?
Jamie Gaskins
@jgaskins
@catmando Bowser has a PR open for an implementation of ES6-style promises including Promise.race, which sounds like what you're looking for clearwater-rb/bowser#9
I just rewrote it a few weeks ago and rebased, so it's not actually an 18-month-old implementation I just haven't merged yet. :-) I've been considering merging it for a long time, but it removes all of Bowser's use of Opal's Promise implementation in favor of an API closer to what newer browsers offer natively, which is kinda scary.
Ghost
@ghost~59874280d73408ce4f704e9c
@elia @iliabylich and everybody else working on opal, opal 0.11 is a blessing! Its a giant step forward to ruby on the client! Its just amazing what bugs i find in existing 0.10 code and do keep wondering, "How did this ever work at all?"
I am amzed, fantastic :+1: :+1: :+1: :smile:
Elia Schito
@elia
@janbiedermann :smile: printed and framed! :laughing:
G. Gibson
@mistergibson
@elia : even though I've been into Opal a short time, I can second that sentiment. Opal is truly amazing and it has taken me in a whole new direction.
Elia Schito
@elia
@mistergibson I should add a "praise" section to the home page :smile:
G. Gibson
@mistergibson
lol, yeah