opal 1.3.2 → 1.4.0.alpha1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (222) hide show
  1. checksums.yaml +4 -4
  2. data/.eslintrc.js +1 -0
  3. data/.github/workflows/build.yml +0 -3
  4. data/.rubocop.yml +5 -1
  5. data/UNRELEASED.md +66 -2
  6. data/benchmark-ips/bm_truthy.rb +30 -0
  7. data/bin/opal-mspec +1 -3
  8. data/bin/opal-repl +1 -2
  9. data/bin/remove-filters +1 -4
  10. data/docs/compiled_ruby.md +10 -6
  11. data/exe/opal-repl +1 -3
  12. data/lib/opal/ast/builder.rb +1 -1
  13. data/lib/opal/cli.rb +2 -2
  14. data/lib/opal/cli_runners/nodejs.rb +9 -2
  15. data/lib/opal/cli_runners/source-map-support-browser.js +80 -216
  16. data/lib/opal/cli_runners/source-map-support-node.js +80 -216
  17. data/lib/opal/cli_runners/source-map-support.js +5 -1
  18. data/lib/opal/cli_runners/system_runner.rb +10 -4
  19. data/lib/opal/compiler.rb +3 -5
  20. data/lib/opal/fragment.rb +5 -1
  21. data/lib/opal/nodes/args/extract_block_arg.rb +1 -8
  22. data/lib/opal/nodes/args/extract_kwoptarg.rb +1 -3
  23. data/lib/opal/nodes/args/extract_optarg.rb +1 -3
  24. data/lib/opal/nodes/args/extract_post_arg.rb +2 -5
  25. data/lib/opal/nodes/args/extract_post_optarg.rb +2 -7
  26. data/lib/opal/nodes/args/initialize_iterarg.rb +1 -3
  27. data/lib/opal/nodes/args/prepare_post_args.rb +5 -1
  28. data/lib/opal/nodes/base.rb +3 -2
  29. data/lib/opal/nodes/call.rb +20 -9
  30. data/lib/opal/nodes/call_special.rb +50 -0
  31. data/lib/opal/nodes/class.rb +24 -15
  32. data/lib/opal/nodes/constants.rb +23 -5
  33. data/lib/opal/nodes/def.rb +20 -23
  34. data/lib/opal/nodes/defined.rb +5 -5
  35. data/lib/opal/nodes/definitions.rb +2 -2
  36. data/lib/opal/nodes/defs.rb +2 -5
  37. data/lib/opal/nodes/helpers.rb +48 -18
  38. data/lib/opal/nodes/if.rb +109 -8
  39. data/lib/opal/nodes/iter.rb +23 -16
  40. data/lib/opal/nodes/literal.rb +18 -4
  41. data/lib/opal/nodes/logic.rb +2 -1
  42. data/lib/opal/nodes/masgn.rb +4 -9
  43. data/lib/opal/nodes/module.rb +29 -19
  44. data/lib/opal/nodes/node_with_args.rb +1 -7
  45. data/lib/opal/nodes/scope.rb +54 -15
  46. data/lib/opal/nodes/singleton_class.rb +5 -3
  47. data/lib/opal/nodes/super.rb +3 -3
  48. data/lib/opal/nodes/top.rb +34 -31
  49. data/lib/opal/nodes/variables.rb +2 -2
  50. data/lib/opal/nodes/x_string.rb +3 -0
  51. data/lib/opal/nodes.rb +0 -1
  52. data/lib/opal/parser/patch.rb +75 -0
  53. data/lib/opal/parser/with_ruby_lexer.rb +1 -1
  54. data/lib/opal/regexp_anchors.rb +7 -7
  55. data/lib/opal/requires.rb +19 -0
  56. data/lib/opal/rewriters/pattern_matching.rb +1 -1
  57. data/lib/opal/rewriters/returnable_logic.rb +102 -4
  58. data/lib/opal/util.rb +2 -2
  59. data/lib/opal/version.rb +1 -1
  60. data/lib/opal.rb +1 -17
  61. data/opal/corelib/array/pack.rb +11 -11
  62. data/opal/corelib/array.rb +193 -152
  63. data/opal/corelib/basic_object.rb +14 -14
  64. data/opal/corelib/binding.rb +7 -7
  65. data/opal/corelib/boolean.rb +12 -15
  66. data/opal/corelib/class.rb +23 -1
  67. data/opal/corelib/comparable.rb +8 -8
  68. data/opal/corelib/complex/base.rb +2 -2
  69. data/opal/corelib/complex.rb +79 -88
  70. data/opal/corelib/constants.rb +9 -9
  71. data/opal/corelib/dir.rb +4 -3
  72. data/opal/corelib/enumerable.rb +140 -127
  73. data/opal/corelib/enumerator/arithmetic_sequence.rb +177 -0
  74. data/opal/corelib/enumerator/chain.rb +42 -0
  75. data/opal/corelib/enumerator/generator.rb +35 -0
  76. data/opal/corelib/enumerator/lazy.rb +243 -0
  77. data/opal/corelib/enumerator/yielder.rb +36 -0
  78. data/opal/corelib/enumerator.rb +45 -300
  79. data/opal/corelib/error/errno.rb +47 -0
  80. data/opal/corelib/error.rb +62 -60
  81. data/opal/corelib/file.rb +26 -12
  82. data/opal/corelib/hash.rb +98 -107
  83. data/opal/corelib/helpers.rb +62 -13
  84. data/opal/corelib/io.rb +47 -34
  85. data/opal/corelib/kernel/format.rb +29 -29
  86. data/opal/corelib/kernel.rb +86 -83
  87. data/opal/corelib/main.rb +14 -12
  88. data/opal/corelib/marshal/read_buffer.rb +15 -15
  89. data/opal/corelib/marshal/write_buffer.rb +45 -44
  90. data/opal/corelib/marshal.rb +3 -3
  91. data/opal/corelib/math.rb +50 -50
  92. data/opal/corelib/method.rb +12 -8
  93. data/opal/corelib/module.rb +96 -79
  94. data/opal/corelib/nil.rb +9 -11
  95. data/opal/corelib/number.rb +113 -118
  96. data/opal/corelib/numeric.rb +37 -33
  97. data/opal/corelib/object_space.rb +11 -10
  98. data/opal/corelib/pack_unpack/format_string_parser.rb +3 -3
  99. data/opal/corelib/pattern_matching/base.rb +7 -7
  100. data/opal/corelib/pattern_matching.rb +1 -1
  101. data/opal/corelib/proc.rb +15 -16
  102. data/opal/corelib/process/base.rb +2 -2
  103. data/opal/corelib/process/status.rb +21 -0
  104. data/opal/corelib/process.rb +5 -5
  105. data/opal/corelib/random/formatter.rb +11 -11
  106. data/opal/corelib/random/math_random.js.rb +1 -1
  107. data/opal/corelib/random/mersenne_twister.rb +3 -3
  108. data/opal/corelib/random/seedrandom.js.rb +3 -3
  109. data/opal/corelib/random.rb +17 -17
  110. data/opal/corelib/range.rb +51 -35
  111. data/opal/corelib/rational/base.rb +4 -4
  112. data/opal/corelib/rational.rb +61 -62
  113. data/opal/corelib/regexp.rb +47 -38
  114. data/opal/corelib/runtime.js +245 -139
  115. data/opal/corelib/string/encoding.rb +21 -21
  116. data/opal/corelib/string/unpack.rb +19 -14
  117. data/opal/corelib/string.rb +135 -128
  118. data/opal/corelib/struct.rb +59 -46
  119. data/opal/corelib/time.rb +47 -57
  120. data/opal/corelib/trace_point.rb +2 -2
  121. data/opal/corelib/unsupported.rb +31 -120
  122. data/opal/corelib/variables.rb +3 -3
  123. data/opal/opal/base.rb +9 -8
  124. data/opal/opal/full.rb +8 -8
  125. data/opal/opal/mini.rb +17 -17
  126. data/opal/opal.rb +17 -18
  127. data/opal.gemspec +1 -1
  128. data/spec/filters/bugs/array.rb +4 -24
  129. data/spec/filters/bugs/bigdecimal.rb +0 -23
  130. data/spec/filters/bugs/binding.rb +0 -1
  131. data/spec/filters/bugs/boolean.rb +3 -0
  132. data/spec/filters/bugs/class.rb +2 -0
  133. data/spec/filters/bugs/date.rb +0 -5
  134. data/spec/filters/bugs/encoding.rb +8 -50
  135. data/spec/filters/bugs/enumerable.rb +4 -1
  136. data/spec/filters/bugs/enumerator.rb +3 -36
  137. data/spec/filters/bugs/exception.rb +0 -2
  138. data/spec/filters/bugs/file.rb +0 -2
  139. data/spec/filters/bugs/float.rb +0 -3
  140. data/spec/filters/bugs/hash.rb +5 -3
  141. data/spec/filters/bugs/integer.rb +2 -3
  142. data/spec/filters/bugs/kernel.rb +2 -31
  143. data/spec/filters/bugs/language.rb +29 -49
  144. data/spec/filters/bugs/main.rb +0 -2
  145. data/spec/filters/bugs/marshal.rb +2 -3
  146. data/spec/filters/bugs/matrix.rb +0 -36
  147. data/spec/filters/bugs/module.rb +7 -61
  148. data/spec/filters/bugs/numeric.rb +0 -7
  149. data/spec/filters/bugs/objectspace.rb +1 -1
  150. data/spec/filters/bugs/pack_unpack.rb +0 -4
  151. data/spec/filters/bugs/proc.rb +0 -9
  152. data/spec/filters/bugs/random.rb +0 -5
  153. data/spec/filters/bugs/range.rb +1 -6
  154. data/spec/filters/bugs/regexp.rb +0 -3
  155. data/spec/filters/bugs/set.rb +8 -1
  156. data/spec/filters/bugs/string.rb +9 -34
  157. data/spec/filters/bugs/stringscanner.rb +8 -7
  158. data/spec/filters/bugs/struct.rb +2 -3
  159. data/spec/filters/bugs/symbol.rb +0 -1
  160. data/spec/filters/bugs/time.rb +0 -8
  161. data/spec/filters/bugs/unboundmethod.rb +0 -8
  162. data/spec/filters/bugs/warnings.rb +1 -7
  163. data/spec/filters/unsupported/freeze.rb +24 -0
  164. data/spec/filters/unsupported/integer.rb +1 -0
  165. data/spec/filters/unsupported/kernel.rb +12 -0
  166. data/spec/filters/unsupported/privacy.rb +3 -0
  167. data/spec/filters/unsupported/string.rb +2 -0
  168. data/spec/lib/builder_spec.rb +2 -2
  169. data/spec/lib/cli_spec.rb +1 -1
  170. data/spec/lib/compiler_spec.rb +37 -37
  171. data/spec/lib/simple_server_spec.rb +2 -2
  172. data/spec/lib/source_map/file_spec.rb +1 -1
  173. data/spec/opal/compiler/irb_spec.rb +2 -2
  174. data/spec/opal/core/kernel/puts_spec.rb +90 -0
  175. data/spec/opal/core/language/super_spec.rb +24 -0
  176. data/spec/ruby_specs +4 -2
  177. data/spec/support/rewriters_helper.rb +1 -1
  178. data/stdlib/bigdecimal.rb +7 -11
  179. data/stdlib/buffer/view.rb +2 -2
  180. data/stdlib/buffer.rb +2 -2
  181. data/stdlib/date.rb +5 -6
  182. data/stdlib/erb.rb +1 -0
  183. data/stdlib/js.rb +2 -1
  184. data/stdlib/native.rb +7 -8
  185. data/stdlib/nodejs/argf.rb +4 -4
  186. data/stdlib/nodejs/base.rb +29 -0
  187. data/stdlib/nodejs/dir.rb +1 -1
  188. data/stdlib/nodejs/env.rb +6 -9
  189. data/stdlib/nodejs/file.rb +23 -17
  190. data/stdlib/nodejs/fileutils.rb +3 -3
  191. data/stdlib/nodejs/io.rb +2 -20
  192. data/stdlib/nodejs/irb.rb +0 -0
  193. data/stdlib/nodejs/kernel.rb +2 -37
  194. data/stdlib/nodejs.rb +1 -3
  195. data/stdlib/opal/miniracer.rb +2 -0
  196. data/stdlib/opal/platform.rb +6 -13
  197. data/stdlib/opal/replutils.rb +16 -5
  198. data/stdlib/opal-parser.rb +2 -2
  199. data/stdlib/optparse/ac.rb +54 -0
  200. data/stdlib/optparse/date.rb +14 -0
  201. data/stdlib/optparse/kwargs.rb +22 -0
  202. data/stdlib/optparse/shellwords.rb +7 -0
  203. data/stdlib/optparse/time.rb +15 -0
  204. data/stdlib/optparse/uri.rb +7 -0
  205. data/stdlib/optparse/version.rb +69 -0
  206. data/stdlib/optparse.rb +2279 -0
  207. data/stdlib/pathname.rb +5 -6
  208. data/stdlib/pp.rb +18 -2
  209. data/stdlib/promise/v2.rb +18 -22
  210. data/stdlib/promise.rb +15 -21
  211. data/stdlib/set.rb +32 -32
  212. data/stdlib/shellwords.rb +240 -0
  213. data/stdlib/stringio.rb +3 -6
  214. data/stdlib/strscan.rb +5 -8
  215. data/stdlib/template.rb +2 -2
  216. data/stdlib/thread.rb +7 -9
  217. data/tasks/performance.rake +5 -2
  218. data/tasks/testing/mspec_special_calls.rb +0 -12
  219. data/tasks/testing.rake +55 -37
  220. data/test/nodejs/test_file.rb +11 -0
  221. metadata +55 -10
  222. data/lib/opal/nodes/case.rb +0 -114
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2b87866d518e2345b4aa120b4f8d457dad6f86ed9f365974161efad2e2f0dde9
4
- data.tar.gz: a3dac2be866ce053470b56377131f7615f0ff6bc3dc7a1d567ce77a8efff5278
3
+ metadata.gz: a891400c1e60680daab2289df6be2148d87aaf7e007210797a963c68af671e82
4
+ data.tar.gz: 4315f9771bd13282d378ae1ec2b564864945cf94e780c17288d53af8f38dfc91
5
5
  SHA512:
6
- metadata.gz: 161e91aa69fc166adf4719b56724251e97239de73dba172916a3de5c744e4d7166a33b0fdc97f9fb68079c0627815a5ae00aba0cbedb137b35a6fc34191979ac
7
- data.tar.gz: ec37e385c55325552d2b7a82fc4c9ec4cd2a98aa3be966a6f9c193e483d0278f58ac8241eec65e12d9e965ea4eda17454430ae284352526ce408e7bc69729ad3
6
+ metadata.gz: 3342a7d52885c1cab9b7371d72a758ce0e13aa97bae741ce549111245422366d5965b36d3eeda91b56b8d0ac733e2a3492c7d6c80190b27a9528aa77f12bfc84
7
+ data.tar.gz: 1f71da4662d1218e4561154cc042ac2e643f097b119b048f35fc0f6d7c566b3b9321a3d4eb0a7020c83b197a32818379a7e7662aa82684a51c4b33e870be2a9a
data/.eslintrc.js CHANGED
@@ -30,5 +30,6 @@ module.exports = {
30
30
  "globalThis": "readonly",
31
31
  "Uint8Array": "readonly",
32
32
  "Promise": "readonly",
33
+ "WeakRef": "readonly",
33
34
  }
34
35
  };
@@ -71,9 +71,6 @@ jobs:
71
71
  uses: ruby/setup-ruby@v1
72
72
  with:
73
73
  ruby-version: ${{ matrix.combo.ruby }}
74
- # NOTE: Bundler 2.2.0 fails to install libv8
75
- # https://github.com/rubyjs/libv8/issues/310
76
- bundler: "2.1.4"
77
74
  bundler-cache: false
78
75
  - run: ruby bin/git-submodule-fast-install
79
76
  - run: bundle lock
data/.rubocop.yml CHANGED
@@ -2,7 +2,7 @@ require: rubocop-performance
2
2
  inherit_from: .rubocop/todo.yml
3
3
 
4
4
  AllCops:
5
- TargetRubyVersion: 2.5
5
+ TargetRubyVersion: 2.6
6
6
  Exclude:
7
7
  - CHANGELOG.md
8
8
  - CONDUCT.md
@@ -52,6 +52,10 @@ AllCops:
52
52
  - 'stdlib/matrix/*.rb'
53
53
  - 'stdlib/pp.rb'
54
54
  - 'stdlib/prettyprint.rb'
55
+ - 'stdlib/optparse.rb'
56
+ - 'stdlib/optparse/*.rb'
57
+ - 'stdlib/tmpdir.rb'
58
+ - 'stdlib/tempfile.rb'
55
59
 
56
60
  inherit_mode:
57
61
  merge:
data/UNRELEASED.md CHANGED
@@ -1,7 +1,71 @@
1
- <!--
1
+ ### Added
2
+
3
+ - Implement `chomp:` option for `String#each_line` and `#lines` (#2355)
4
+ - Ruby 3.1 support and some older Ruby features we missed (#2347)
5
+ - Use parser in 3.1 mode to support new language-level features like hashes/kwargs value omission, the pin operator for pattern matching
6
+ - `Array#intersect?`
7
+ - `String#strip` and `String#lstrip` to also remove NUL bytes
8
+ - `Integer.try_convert`
9
+ - `public`, `private`, `protected`, `module_function` now return their arguments
10
+ - `Class#descendants`, `Class#subclasses`
11
+ - (<=1.8) `Kernel#local_variables`
12
+ - (<=2.3) Set local variables for regexp named captures (`/(?<b>a)/ =~ 'a'` => `b = 'a'`)
13
+ - Remove deprecated `NIL`, `TRUE`, `FALSE` constants
14
+ - `String#unpack` and `String#unpack1` to support an `offset:` kwarg
15
+ - `MatchData#match`, `MatchData#match_length`
16
+ - Enumerable modernization
17
+ - `Enumerable#tally` to support an optional hash accumulator
18
+ - `Enumerable#each_{cons,slice}` to return self
19
+ - `Enumerable#compact`
20
+ - `Refinement` becomes its own class now
21
+ - `Struct#keyword_init?`
22
+ - (pre-3.1) Large Enumerator rework
23
+ - Introduce `Enumerator::ArithmeticSequence`
24
+ - Introduce `Enumerator::Chain`
25
+ - Introduce `Enumerator#+` to create `Enumerator::Chain`s
26
+ - `Enumerator#{rewind,peek,peek_values,next,next_values}`
27
+ - Improve corelib support for beginless/endless ranges and `ArithmeticSequences`
28
+ - `String#[]`, `Array#[]`, `Array#[]=`, `Array#fill`, `Array#values_at`
29
+ - `Range#step` and `Numeric#step` return an `ArithmeticSequence` when `Numeric` values are in play
30
+ - Introduce `Range#%`
31
+ - `Enumerator::Yielder#to_proc`
32
+ - Fix #2367
33
+ - (2.7) `UnboundMethod#bind_call`
34
+ - (Opal) `{Kernel,BasicObject}#{inspect,p,pp,method_missing}` may work with JS native values now, also they now correctly report cycles
35
+ - `Enumerable#sum` uses Kahan's summation algorithm to reduce error with floating point values
36
+ - `File.dirname` supports a new `level` argument
37
+ - Vendor in `optparse` and `shellwords` (#2326)
38
+ - Preliminary support for compiling the whole `bin/opal` with Opal (#2326)
39
+
2
40
  ### Fixed
41
+
42
+ - Fix defining multiple methods with the same block (#2345)
43
+ - Fix coertion for `Array#drop` (#2371)
44
+ - Fix coertion for `File.absolute_path` (#2372)
45
+ - Fix some `IO#puts` edge cases (no args, empty array, nested array, …) (#2372)
46
+ - Preserve UNC path prefix on File.join (#2366)
47
+ - Methods on `Kernel`, `BasicObject`, `Boolean` will never return boxed values anymore (#2293)
48
+ - `false.tap{}` will now correctly return a JS value of `false`, not `Object(false)`
49
+ - opal-parser doesn't break on `<<~END` strings anymore (#2364)
50
+ - Fix error reporting at the early stage of loading (#2326)
51
+
3
52
  ### Changed
4
- ### Deprecated
53
+
54
+ - Various outputted code size optimizations - 19% improvement for minified unmangled AsciiDoctor bundle - see: https://opalrb.com/blog/2021/11/24/optimizing-opal-output-for-size/ (#2356)
55
+ - Second round of code size optimizations - 3% improvement for AsciiDoctor bundle on top of the first round - 23% total - see: https://github.com/opal/opal/pull/2365/commits (#2365)
56
+ - The calls to `==`, `!=` and `===` changed their semantics slightly: it's impossible to monkey patch those calls for `String` and `Number`, but on other classes they can now return `nil` and it will be handled correctly
57
+ - The calls to `!` changed their semantics slightly: it's impossible to monkey patch this call for `Boolean` or `NilClass`.
58
+ - Refactored the structure of the internal `stdlib/nodejs` folder (#2374)
59
+ - Added `nodejs/base` with just I/O, exit, and ARGV management
60
+ - Moved `Process::Status` to corelib
61
+ - Fixed requires to be more robust
62
+
5
63
  ### Removed
64
+
65
+ - Removed `nodejs/irb` from stdlib as it's been broken for some time (#2374)
66
+ - Removed `Kernel#node_require` from `nodejs/kernel` as it's been deprecated for a long time (#2374)
67
+
68
+ <!--
69
+ ### Deprecated
6
70
  ### Internal
7
71
  -->
@@ -0,0 +1,30 @@
1
+ Benchmark.ips do |x|
2
+ %x{
3
+ // Old version truthy logic
4
+ var old_version = function(x) { return x !== nil && x != null && (!x.$$is_boolean || x == true); }
5
+
6
+ // New version truthy logic
7
+ var new_version_1 = function(val) { return undefined !== val && null !== val && false !== val && nil !== val && (!(val instanceof Boolean) || true === val.valueOf()); }
8
+
9
+ // Alternative new version truthy logic
10
+ var new_version_2 = function(val) { return undefined !== val && null !== val && false !== val && nil !== val && !(val instanceof Boolean && false === val.valueOf()); }
11
+
12
+ // Alternative new version, nil&false first
13
+ var new_version_3 = function(val) { return false !== val && nil !== val && undefined !== val && null !== val && !(val instanceof Boolean && false === val.valueOf()); }
14
+
15
+ // Alternative new version truthy logic that unsupports boxed booleans
16
+ var new_unboxed = function(val) { return undefined !== val && null !== val && false !== val && nil !== val; }
17
+ }
18
+
19
+ values = [123,243,35,"sd",false,nil,123413234,120412,0,1234.1234,0.34,false,false,true,"sadfasf","","0",13,123,nil,Object.new,[]]
20
+
21
+ x.time = 32
22
+
23
+ x.report('old_version') { values.map(&`old_version`) }
24
+ x.report('new_version_1') { values.map(&`new_version_1`) }
25
+ x.report('new_version_2') { values.map(&`new_version_2`) }
26
+ x.report('new_version_3') { values.map(&`new_version_3`) }
27
+ x.report('new_unboxed') { values.map(&`new_unboxed`) }
28
+
29
+ x.compare!
30
+ end
data/bin/opal-mspec CHANGED
@@ -7,7 +7,5 @@ specs = ARGV.map do |s|
7
7
  end
8
8
 
9
9
  env = {}
10
- env['MSPEC_PATTERN'] = "{#{specs.join(',')}}" if specs.any?
10
+ env['PATTERN'] = "{#{specs.join(',')}}" if specs.any?
11
11
  exec env, 'rake', 'mspec'
12
-
13
- # RUBYOPT="-rbundler/setup -rmspec/opal/special_calls" bundle exec mspec run -t opal -pspec/ruby/spec_helper spec/ruby/core/true/*
data/bin/opal-repl CHANGED
@@ -1,4 +1,3 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'bundler/setup'
4
- load "#{__dir__}/../exe/opal-repl"
3
+ exec "#{__dir__}/opal", '--repl', *ARGV
data/bin/remove-filters CHANGED
@@ -15,10 +15,7 @@
15
15
  # 5) "Set#filter! returns nil when self was not modified"
16
16
 
17
17
  filters = $stdin.read.split("\n").map do |i|
18
- # This special example should be rather moved to unsupported for now...
19
- next if i =~ /formats the local time following the pattern/
20
-
21
- i.scan(/\d+\) (".*")/).first.first
18
+ i.scan(/(?:\d+\)|fails) (".*")/).first.first
22
19
  end.compact
23
20
  filters = Regexp.union(*filters)
24
21
 
@@ -178,15 +178,19 @@ puts "foo"
178
178
  This would compile directly into:
179
179
 
180
180
  ```javascript
181
- (function(Opal) {
182
- var self = Opal.top, $nesting = [], nil = Opal.nil, $breaker = Opal.breaker, $slice = Opal.slice;
181
+ Opal.queue(function(Opal) {
182
+ var self = Opal.top, nil = Opal.nil;
183
183
 
184
- Opal.add_stubs(['$puts']);
184
+ Opal.add_stubs('puts');
185
185
  return self.$puts("foo")
186
- })(Opal);
186
+ });
187
187
  ```
188
188
 
189
- **TIP:** you can see the compiled code with this command: `opal --compile --no-exit --no-opal --eval 'puts "foo"'`
189
+ **TIP:**
190
+
191
+ you can see the compiled code with this command: `opal --compile --no-exit --no-opal --eval 'puts "foo"'`
192
+ or, more briefly: `opal -cEO -e 'puts "foo"'`
193
+
190
194
 
191
195
  ### Using compiled sources
192
196
 
@@ -667,7 +671,7 @@ It is obvious from here, that unless an object defines any given method, it will
667
671
  To optimise the generated code slightly, we reduce the code output from the compiler into the following JavaScript:
668
672
 
669
673
  ```javascript
670
- Opal.add_stubs(["first", "second", "to_sym"]);
674
+ Opal.add_stubs("first,second,to_sym"]);
671
675
  ```
672
676
 
673
677
  You will see this at the top of all your generated JavaScript files. This will add a stub method for all methods used in your file.
data/exe/opal-repl CHANGED
@@ -1,5 +1,3 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- ARGV << "--repl"
4
-
5
- load __dir__+"/opal"
3
+ exec "#{__dir__}/opal", '--repl', *ARGV
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'opal/ast/node'
4
- require 'parser/ruby30'
4
+ require 'parser/ruby31'
5
5
 
6
6
  module Opal
7
7
  module AST
data/lib/opal/cli.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'opal'
3
+ require 'opal/requires'
4
4
  require 'opal/builder'
5
5
  require 'opal/cli_runners'
6
6
 
@@ -128,7 +128,7 @@ module Opal
128
128
  evals_or_file { |source, filename| builder.build_str(source, filename) }
129
129
 
130
130
  # --no-exit
131
- builder.build_str 'Kernel.exit', '(exit)' unless no_exit
131
+ builder.build_str '::Kernel.exit', '(exit)' unless no_exit
132
132
 
133
133
  builder
134
134
  end
@@ -7,7 +7,14 @@ require 'opal/cli_runners/system_runner'
7
7
  module Opal
8
8
  module CliRunners
9
9
  class Nodejs
10
- NODE_PATH = File.expand_path('../stdlib/nodejs/node_modules', ::Opal.gem_dir)
10
+ if RUBY_ENGINE == 'opal'
11
+ # We can't rely on Opal.gem_dir for now...
12
+ NODE_PATH = 'stdlib/nodejs/node_modules'
13
+ DIR = './lib/opal/cli_runners'
14
+ else
15
+ NODE_PATH = File.expand_path('../stdlib/nodejs/node_modules', ::Opal.gem_dir)
16
+ DIR = __dir__
17
+ end
11
18
 
12
19
  def self.call(data)
13
20
  (data[:options] ||= {})[:env] = { 'NODE_PATH' => node_modules }
@@ -20,7 +27,7 @@ module Opal
20
27
  SystemRunner.call(data) do |tempfile|
21
28
  [
22
29
  'node',
23
- '--require', "#{__dir__}/source-map-support-node",
30
+ '--require', "#{DIR}/source-map-support-node",
24
31
  *opts,
25
32
  tempfile.path,
26
33
  *argv