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.
- checksums.yaml +4 -4
- data/.eslintrc.js +1 -0
- data/.github/workflows/build.yml +0 -3
- data/.rubocop.yml +5 -1
- data/UNRELEASED.md +66 -2
- data/benchmark-ips/bm_truthy.rb +30 -0
- data/bin/opal-mspec +1 -3
- data/bin/opal-repl +1 -2
- data/bin/remove-filters +1 -4
- data/docs/compiled_ruby.md +10 -6
- data/exe/opal-repl +1 -3
- data/lib/opal/ast/builder.rb +1 -1
- data/lib/opal/cli.rb +2 -2
- data/lib/opal/cli_runners/nodejs.rb +9 -2
- data/lib/opal/cli_runners/source-map-support-browser.js +80 -216
- data/lib/opal/cli_runners/source-map-support-node.js +80 -216
- data/lib/opal/cli_runners/source-map-support.js +5 -1
- data/lib/opal/cli_runners/system_runner.rb +10 -4
- data/lib/opal/compiler.rb +3 -5
- data/lib/opal/fragment.rb +5 -1
- data/lib/opal/nodes/args/extract_block_arg.rb +1 -8
- data/lib/opal/nodes/args/extract_kwoptarg.rb +1 -3
- data/lib/opal/nodes/args/extract_optarg.rb +1 -3
- data/lib/opal/nodes/args/extract_post_arg.rb +2 -5
- data/lib/opal/nodes/args/extract_post_optarg.rb +2 -7
- data/lib/opal/nodes/args/initialize_iterarg.rb +1 -3
- data/lib/opal/nodes/args/prepare_post_args.rb +5 -1
- data/lib/opal/nodes/base.rb +3 -2
- data/lib/opal/nodes/call.rb +20 -9
- data/lib/opal/nodes/call_special.rb +50 -0
- data/lib/opal/nodes/class.rb +24 -15
- data/lib/opal/nodes/constants.rb +23 -5
- data/lib/opal/nodes/def.rb +20 -23
- data/lib/opal/nodes/defined.rb +5 -5
- data/lib/opal/nodes/definitions.rb +2 -2
- data/lib/opal/nodes/defs.rb +2 -5
- data/lib/opal/nodes/helpers.rb +48 -18
- data/lib/opal/nodes/if.rb +109 -8
- data/lib/opal/nodes/iter.rb +23 -16
- data/lib/opal/nodes/literal.rb +18 -4
- data/lib/opal/nodes/logic.rb +2 -1
- data/lib/opal/nodes/masgn.rb +4 -9
- data/lib/opal/nodes/module.rb +29 -19
- data/lib/opal/nodes/node_with_args.rb +1 -7
- data/lib/opal/nodes/scope.rb +54 -15
- data/lib/opal/nodes/singleton_class.rb +5 -3
- data/lib/opal/nodes/super.rb +3 -3
- data/lib/opal/nodes/top.rb +34 -31
- data/lib/opal/nodes/variables.rb +2 -2
- data/lib/opal/nodes/x_string.rb +3 -0
- data/lib/opal/nodes.rb +0 -1
- data/lib/opal/parser/patch.rb +75 -0
- data/lib/opal/parser/with_ruby_lexer.rb +1 -1
- data/lib/opal/regexp_anchors.rb +7 -7
- data/lib/opal/requires.rb +19 -0
- data/lib/opal/rewriters/pattern_matching.rb +1 -1
- data/lib/opal/rewriters/returnable_logic.rb +102 -4
- data/lib/opal/util.rb +2 -2
- data/lib/opal/version.rb +1 -1
- data/lib/opal.rb +1 -17
- data/opal/corelib/array/pack.rb +11 -11
- data/opal/corelib/array.rb +193 -152
- data/opal/corelib/basic_object.rb +14 -14
- data/opal/corelib/binding.rb +7 -7
- data/opal/corelib/boolean.rb +12 -15
- data/opal/corelib/class.rb +23 -1
- data/opal/corelib/comparable.rb +8 -8
- data/opal/corelib/complex/base.rb +2 -2
- data/opal/corelib/complex.rb +79 -88
- data/opal/corelib/constants.rb +9 -9
- data/opal/corelib/dir.rb +4 -3
- data/opal/corelib/enumerable.rb +140 -127
- data/opal/corelib/enumerator/arithmetic_sequence.rb +177 -0
- data/opal/corelib/enumerator/chain.rb +42 -0
- data/opal/corelib/enumerator/generator.rb +35 -0
- data/opal/corelib/enumerator/lazy.rb +243 -0
- data/opal/corelib/enumerator/yielder.rb +36 -0
- data/opal/corelib/enumerator.rb +45 -300
- data/opal/corelib/error/errno.rb +47 -0
- data/opal/corelib/error.rb +62 -60
- data/opal/corelib/file.rb +26 -12
- data/opal/corelib/hash.rb +98 -107
- data/opal/corelib/helpers.rb +62 -13
- data/opal/corelib/io.rb +47 -34
- data/opal/corelib/kernel/format.rb +29 -29
- data/opal/corelib/kernel.rb +86 -83
- data/opal/corelib/main.rb +14 -12
- data/opal/corelib/marshal/read_buffer.rb +15 -15
- data/opal/corelib/marshal/write_buffer.rb +45 -44
- data/opal/corelib/marshal.rb +3 -3
- data/opal/corelib/math.rb +50 -50
- data/opal/corelib/method.rb +12 -8
- data/opal/corelib/module.rb +96 -79
- data/opal/corelib/nil.rb +9 -11
- data/opal/corelib/number.rb +113 -118
- data/opal/corelib/numeric.rb +37 -33
- data/opal/corelib/object_space.rb +11 -10
- data/opal/corelib/pack_unpack/format_string_parser.rb +3 -3
- data/opal/corelib/pattern_matching/base.rb +7 -7
- data/opal/corelib/pattern_matching.rb +1 -1
- data/opal/corelib/proc.rb +15 -16
- data/opal/corelib/process/base.rb +2 -2
- data/opal/corelib/process/status.rb +21 -0
- data/opal/corelib/process.rb +5 -5
- data/opal/corelib/random/formatter.rb +11 -11
- data/opal/corelib/random/math_random.js.rb +1 -1
- data/opal/corelib/random/mersenne_twister.rb +3 -3
- data/opal/corelib/random/seedrandom.js.rb +3 -3
- data/opal/corelib/random.rb +17 -17
- data/opal/corelib/range.rb +51 -35
- data/opal/corelib/rational/base.rb +4 -4
- data/opal/corelib/rational.rb +61 -62
- data/opal/corelib/regexp.rb +47 -38
- data/opal/corelib/runtime.js +245 -139
- data/opal/corelib/string/encoding.rb +21 -21
- data/opal/corelib/string/unpack.rb +19 -14
- data/opal/corelib/string.rb +135 -128
- data/opal/corelib/struct.rb +59 -46
- data/opal/corelib/time.rb +47 -57
- data/opal/corelib/trace_point.rb +2 -2
- data/opal/corelib/unsupported.rb +31 -120
- data/opal/corelib/variables.rb +3 -3
- data/opal/opal/base.rb +9 -8
- data/opal/opal/full.rb +8 -8
- data/opal/opal/mini.rb +17 -17
- data/opal/opal.rb +17 -18
- data/opal.gemspec +1 -1
- data/spec/filters/bugs/array.rb +4 -24
- data/spec/filters/bugs/bigdecimal.rb +0 -23
- data/spec/filters/bugs/binding.rb +0 -1
- data/spec/filters/bugs/boolean.rb +3 -0
- data/spec/filters/bugs/class.rb +2 -0
- data/spec/filters/bugs/date.rb +0 -5
- data/spec/filters/bugs/encoding.rb +8 -50
- data/spec/filters/bugs/enumerable.rb +4 -1
- data/spec/filters/bugs/enumerator.rb +3 -36
- data/spec/filters/bugs/exception.rb +0 -2
- data/spec/filters/bugs/file.rb +0 -2
- data/spec/filters/bugs/float.rb +0 -3
- data/spec/filters/bugs/hash.rb +5 -3
- data/spec/filters/bugs/integer.rb +2 -3
- data/spec/filters/bugs/kernel.rb +2 -31
- data/spec/filters/bugs/language.rb +29 -49
- data/spec/filters/bugs/main.rb +0 -2
- data/spec/filters/bugs/marshal.rb +2 -3
- data/spec/filters/bugs/matrix.rb +0 -36
- data/spec/filters/bugs/module.rb +7 -61
- data/spec/filters/bugs/numeric.rb +0 -7
- data/spec/filters/bugs/objectspace.rb +1 -1
- data/spec/filters/bugs/pack_unpack.rb +0 -4
- data/spec/filters/bugs/proc.rb +0 -9
- data/spec/filters/bugs/random.rb +0 -5
- data/spec/filters/bugs/range.rb +1 -6
- data/spec/filters/bugs/regexp.rb +0 -3
- data/spec/filters/bugs/set.rb +8 -1
- data/spec/filters/bugs/string.rb +9 -34
- data/spec/filters/bugs/stringscanner.rb +8 -7
- data/spec/filters/bugs/struct.rb +2 -3
- data/spec/filters/bugs/symbol.rb +0 -1
- data/spec/filters/bugs/time.rb +0 -8
- data/spec/filters/bugs/unboundmethod.rb +0 -8
- data/spec/filters/bugs/warnings.rb +1 -7
- data/spec/filters/unsupported/freeze.rb +24 -0
- data/spec/filters/unsupported/integer.rb +1 -0
- data/spec/filters/unsupported/kernel.rb +12 -0
- data/spec/filters/unsupported/privacy.rb +3 -0
- data/spec/filters/unsupported/string.rb +2 -0
- data/spec/lib/builder_spec.rb +2 -2
- data/spec/lib/cli_spec.rb +1 -1
- data/spec/lib/compiler_spec.rb +37 -37
- data/spec/lib/simple_server_spec.rb +2 -2
- data/spec/lib/source_map/file_spec.rb +1 -1
- data/spec/opal/compiler/irb_spec.rb +2 -2
- data/spec/opal/core/kernel/puts_spec.rb +90 -0
- data/spec/opal/core/language/super_spec.rb +24 -0
- data/spec/ruby_specs +4 -2
- data/spec/support/rewriters_helper.rb +1 -1
- data/stdlib/bigdecimal.rb +7 -11
- data/stdlib/buffer/view.rb +2 -2
- data/stdlib/buffer.rb +2 -2
- data/stdlib/date.rb +5 -6
- data/stdlib/erb.rb +1 -0
- data/stdlib/js.rb +2 -1
- data/stdlib/native.rb +7 -8
- data/stdlib/nodejs/argf.rb +4 -4
- data/stdlib/nodejs/base.rb +29 -0
- data/stdlib/nodejs/dir.rb +1 -1
- data/stdlib/nodejs/env.rb +6 -9
- data/stdlib/nodejs/file.rb +23 -17
- data/stdlib/nodejs/fileutils.rb +3 -3
- data/stdlib/nodejs/io.rb +2 -20
- data/stdlib/nodejs/irb.rb +0 -0
- data/stdlib/nodejs/kernel.rb +2 -37
- data/stdlib/nodejs.rb +1 -3
- data/stdlib/opal/miniracer.rb +2 -0
- data/stdlib/opal/platform.rb +6 -13
- data/stdlib/opal/replutils.rb +16 -5
- data/stdlib/opal-parser.rb +2 -2
- data/stdlib/optparse/ac.rb +54 -0
- data/stdlib/optparse/date.rb +14 -0
- data/stdlib/optparse/kwargs.rb +22 -0
- data/stdlib/optparse/shellwords.rb +7 -0
- data/stdlib/optparse/time.rb +15 -0
- data/stdlib/optparse/uri.rb +7 -0
- data/stdlib/optparse/version.rb +69 -0
- data/stdlib/optparse.rb +2279 -0
- data/stdlib/pathname.rb +5 -6
- data/stdlib/pp.rb +18 -2
- data/stdlib/promise/v2.rb +18 -22
- data/stdlib/promise.rb +15 -21
- data/stdlib/set.rb +32 -32
- data/stdlib/shellwords.rb +240 -0
- data/stdlib/stringio.rb +3 -6
- data/stdlib/strscan.rb +5 -8
- data/stdlib/template.rb +2 -2
- data/stdlib/thread.rb +7 -9
- data/tasks/performance.rake +5 -2
- data/tasks/testing/mspec_special_calls.rb +0 -12
- data/tasks/testing.rake +55 -37
- data/test/nodejs/test_file.rb +11 -0
- metadata +55 -10
- data/lib/opal/nodes/case.rb +0 -114
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a891400c1e60680daab2289df6be2148d87aaf7e007210797a963c68af671e82
|
4
|
+
data.tar.gz: 4315f9771bd13282d378ae1ec2b564864945cf94e780c17288d53af8f38dfc91
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3342a7d52885c1cab9b7371d72a758ce0e13aa97bae741ce549111245422366d5965b36d3eeda91b56b8d0ac733e2a3492c7d6c80190b27a9528aa77f12bfc84
|
7
|
+
data.tar.gz: 1f71da4662d1218e4561154cc042ac2e643f097b119b048f35fc0f6d7c566b3b9321a3d4eb0a7020c83b197a32818379a7e7662aa82684a51c4b33e870be2a9a
|
data/.eslintrc.js
CHANGED
data/.github/workflows/build.yml
CHANGED
@@ -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
|
+
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
|
-
|
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['
|
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
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
|
-
|
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
|
|
data/docs/compiled_ruby.md
CHANGED
@@ -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,
|
181
|
+
Opal.queue(function(Opal) {
|
182
|
+
var self = Opal.top, nil = Opal.nil;
|
183
183
|
|
184
|
-
Opal.add_stubs(
|
184
|
+
Opal.add_stubs('puts');
|
185
185
|
return self.$puts("foo")
|
186
|
-
})
|
186
|
+
});
|
187
187
|
```
|
188
188
|
|
189
|
-
**TIP:**
|
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(
|
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
data/lib/opal/ast/builder.rb
CHANGED
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
|
-
|
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', "#{
|
30
|
+
'--require', "#{DIR}/source-map-support-node",
|
24
31
|
*opts,
|
25
32
|
tempfile.path,
|
26
33
|
*argv
|