opal 1.0.3 → 1.1.1.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +13 -12
- data/.gitattributes +1 -1
- data/.github/FUNDING.yml +1 -0
- data/.github/workflows/build.yml +90 -0
- data/.jshintrc +1 -1
- data/.overcommit.yml +35 -0
- data/.rubocop.yml +44 -7
- data/{.rubocop_todo.yml → .rubocop/todo.yml} +4 -5
- data/CHANGELOG.md +152 -1
- data/Gemfile +2 -3
- data/HACKING.md +2 -9
- data/LICENSE +1 -1
- data/README.md +21 -18
- data/UNRELEASED.md +4 -2
- data/benchmark-ips/bm_array_pop_1.rb +8 -0
- data/benchmark-ips/bm_array_shift.rb +7 -0
- data/benchmark-ips/bm_js_symbols_vs_strings.rb +7 -2
- data/benchmark-ips/class_shovel_vs_singleton_class.rb +16 -0
- data/bin/build-browser-source-map-support +4 -0
- data/bin/format-filters +54 -0
- data/bin/git-submodule-fast-install +49 -0
- data/bin/remove-filters +39 -0
- data/bin/setup +4 -0
- data/bin/yarn +11 -0
- data/docs/releasing.md +18 -0
- data/docs/roda-sprockets.md +86 -0
- data/docs/sinatra.md +5 -12
- data/examples/rack/Gemfile +1 -0
- data/examples/rack/app/application.rb +3 -0
- data/examples/rack/config.ru +5 -4
- data/exe/opal-repl +2 -83
- data/lib/opal/ast/builder.rb +1 -1
- data/lib/opal/builder.rb +2 -10
- data/lib/opal/builder_processors.rb +1 -1
- data/lib/opal/cli.rb +4 -1
- data/lib/opal/cli_options.rb +11 -3
- data/lib/opal/cli_runners.rb +27 -37
- data/lib/opal/cli_runners/applescript.rb +5 -44
- data/lib/opal/cli_runners/chrome.js +7 -35
- data/lib/opal/cli_runners/chrome.rb +75 -17
- data/lib/opal/cli_runners/compiler.rb +17 -0
- data/lib/opal/cli_runners/nashorn.rb +9 -43
- data/lib/opal/cli_runners/nodejs.rb +18 -47
- data/lib/opal/cli_runners/server.rb +18 -6
- data/lib/opal/cli_runners/source-map-support-browser.js +6449 -0
- data/lib/opal/cli_runners/source-map-support-node.js +3704 -0
- data/lib/opal/cli_runners/source-map-support.js +639 -0
- data/lib/opal/cli_runners/system_runner.rb +45 -0
- data/lib/opal/compiler.rb +57 -29
- data/lib/opal/config.rb +0 -5
- data/lib/opal/erb.rb +1 -1
- data/lib/opal/magic_comments.rb +34 -0
- data/lib/opal/nodes/args/arity_check.rb +2 -1
- data/lib/opal/nodes/base.rb +1 -1
- data/lib/opal/nodes/call.rb +1 -4
- data/lib/opal/nodes/def.rb +2 -0
- data/lib/opal/nodes/iter.rb +1 -1
- data/lib/opal/nodes/literal.rb +19 -14
- data/lib/opal/nodes/logic.rb +5 -80
- data/lib/opal/nodes/masgn.rb +2 -0
- data/lib/opal/nodes/rescue.rb +1 -1
- data/lib/opal/nodes/super.rb +24 -10
- data/lib/opal/nodes/top.rb +5 -4
- data/lib/opal/parser/with_c_lexer.rb +2 -1
- data/lib/opal/parser/with_ruby_lexer.rb +1 -1
- data/lib/opal/path_reader.rb +2 -2
- data/lib/opal/paths.rb +8 -5
- data/lib/opal/repl.rb +103 -0
- data/lib/opal/rewriter.rb +4 -0
- data/lib/opal/rewriters/for_rewriter.rb +1 -1
- data/lib/opal/rewriters/js_reserved_words.rb +7 -7
- data/lib/opal/rewriters/numblocks.rb +31 -0
- data/lib/opal/rewriters/returnable_logic.rb +33 -0
- data/lib/opal/util.rb +11 -48
- data/lib/opal/version.rb +1 -1
- data/opal.gemspec +26 -26
- data/opal/corelib/array.rb +160 -118
- data/opal/corelib/array/pack.rb +5 -3
- data/opal/corelib/basic_object.rb +4 -4
- data/opal/corelib/class.rb +2 -1
- data/opal/corelib/comparable.rb +49 -31
- data/opal/corelib/constants.rb +5 -5
- data/opal/corelib/enumerable.rb +108 -46
- data/opal/corelib/enumerator.rb +27 -12
- data/opal/corelib/file.rb +3 -1
- data/opal/corelib/hash.rb +6 -1
- data/opal/corelib/helpers.rb +8 -28
- data/opal/corelib/io.rb +12 -7
- data/opal/corelib/kernel.rb +45 -14
- data/opal/corelib/kernel/format.rb +3 -1
- data/opal/corelib/math.rb +8 -6
- data/opal/corelib/method.rb +8 -0
- data/opal/corelib/module.rb +17 -2
- data/opal/corelib/number.rb +3 -12
- data/opal/corelib/proc.rb +16 -0
- data/opal/corelib/random/mersenne_twister.rb +147 -0
- data/opal/corelib/range.rb +3 -13
- data/opal/corelib/regexp.rb +10 -6
- data/opal/corelib/runtime.js +208 -81
- data/opal/corelib/string.rb +55 -49
- data/opal/corelib/string/encoding.rb +109 -32
- data/opal/corelib/string/unpack.rb +2 -17
- data/opal/corelib/struct.rb +14 -1
- data/opal/corelib/time.rb +4 -0
- data/opal/opal.rb +1 -1
- data/opal/opal/mini.rb +1 -1
- data/package.json +16 -0
- data/spec/README.md +10 -0
- data/spec/filters/bugs/array.rb +76 -0
- data/spec/filters/bugs/base64.rb +10 -0
- data/spec/filters/bugs/basicobject.rb +12 -0
- data/spec/filters/bugs/bigdecimal.rb +248 -0
- data/spec/filters/bugs/class.rb +12 -0
- data/spec/filters/bugs/complex.rb +7 -0
- data/spec/filters/bugs/date.rb +104 -0
- data/spec/filters/bugs/encoding.rb +259 -0
- data/spec/filters/bugs/enumerable.rb +26 -0
- data/spec/filters/bugs/enumerator.rb +48 -0
- data/spec/filters/bugs/exception.rb +120 -0
- data/spec/filters/bugs/file.rb +48 -0
- data/spec/filters/bugs/float.rb +74 -0
- data/spec/filters/bugs/hash.rb +60 -0
- data/spec/filters/bugs/integer.rb +78 -0
- data/spec/filters/bugs/io.rb +9 -0
- data/spec/filters/bugs/kernel.rb +401 -0
- data/spec/filters/bugs/language.rb +451 -0
- data/spec/filters/bugs/marshal.rb +50 -0
- data/spec/filters/bugs/math.rb +4 -0
- data/spec/filters/bugs/method.rb +79 -0
- data/spec/filters/bugs/module.rb +281 -0
- data/spec/filters/bugs/nilclass.rb +4 -0
- data/spec/filters/bugs/numeric.rb +27 -0
- data/spec/filters/bugs/openstruct.rb +8 -0
- data/spec/filters/bugs/pack_unpack.rb +138 -0
- data/spec/filters/bugs/pathname.rb +9 -0
- data/spec/filters/bugs/proc.rb +80 -0
- data/spec/filters/bugs/random.rb +20 -0
- data/spec/filters/bugs/range.rb +139 -0
- data/spec/filters/bugs/rational.rb +12 -0
- data/spec/filters/bugs/regexp.rb +91 -0
- data/spec/filters/bugs/set.rb +51 -0
- data/spec/filters/bugs/singleton.rb +7 -0
- data/spec/filters/bugs/string.rb +341 -0
- data/spec/filters/bugs/stringscanner.rb +78 -0
- data/spec/filters/bugs/struct.rb +26 -0
- data/spec/filters/bugs/symbol.rb +7 -0
- data/spec/filters/bugs/time.rb +109 -0
- data/spec/filters/bugs/unboundmethod.rb +33 -0
- data/spec/filters/bugs/warnings.rb +30 -0
- data/spec/filters/unsupported/array.rb +168 -0
- data/spec/filters/unsupported/basicobject.rb +15 -0
- data/spec/filters/unsupported/bignum.rb +55 -0
- data/spec/filters/unsupported/class.rb +5 -0
- data/spec/filters/unsupported/delegator.rb +6 -0
- data/spec/filters/unsupported/enumerable.rb +12 -0
- data/spec/filters/unsupported/enumerator.rb +14 -0
- data/spec/filters/unsupported/file.rb +4 -0
- data/spec/filters/unsupported/fixnum.rb +15 -0
- data/spec/filters/unsupported/float.rb +47 -0
- data/spec/filters/unsupported/freeze.rb +259 -0
- data/spec/filters/unsupported/hash.rb +44 -0
- data/spec/filters/unsupported/integer.rb +101 -0
- data/spec/filters/unsupported/kernel.rb +35 -0
- data/spec/filters/unsupported/language.rb +25 -0
- data/spec/filters/unsupported/marshal.rb +44 -0
- data/spec/filters/unsupported/matchdata.rb +63 -0
- data/spec/filters/unsupported/math.rb +4 -0
- data/spec/filters/unsupported/pathname.rb +4 -0
- data/spec/filters/unsupported/privacy.rb +287 -0
- data/spec/filters/unsupported/proc.rb +4 -0
- data/spec/filters/unsupported/random.rb +5 -0
- data/spec/filters/unsupported/range.rb +8 -0
- data/spec/filters/unsupported/regexp.rb +70 -0
- data/spec/filters/unsupported/set.rb +5 -0
- data/spec/filters/unsupported/singleton.rb +7 -0
- data/spec/filters/unsupported/string.rb +687 -0
- data/spec/filters/unsupported/struct.rb +7 -0
- data/spec/filters/unsupported/symbol.rb +21 -0
- data/spec/filters/unsupported/taint.rb +162 -0
- data/spec/filters/unsupported/thread.rb +10 -0
- data/spec/filters/unsupported/time.rb +204 -0
- data/spec/filters/unsupported/usage_of_files.rb +262 -0
- data/spec/lib/builder_processors_spec.rb +44 -0
- data/spec/lib/builder_spec.rb +133 -0
- data/spec/lib/cli_runners/server_spec.rb +25 -0
- data/spec/lib/cli_runners_spec.rb +16 -0
- data/spec/lib/cli_spec.rb +256 -0
- data/spec/lib/compiler_spec.rb +693 -0
- data/spec/lib/config_spec.rb +112 -0
- data/spec/lib/dependency_resolver_spec.rb +43 -0
- data/spec/lib/deprecations_spec.rb +17 -0
- data/spec/lib/fixtures/complex_sprockets.js.rb.erb +4 -0
- data/spec/lib/fixtures/file_with_directives.js +2 -0
- data/spec/lib/fixtures/jst_file.js.jst +1 -0
- data/spec/lib/fixtures/no_requires.rb +1 -0
- data/spec/lib/fixtures/opal_file.rb +2 -0
- data/spec/lib/fixtures/require_tree_test.rb +3 -0
- data/spec/lib/fixtures/required_file.js +1 -0
- data/spec/lib/fixtures/required_tree_test/required_file1.rb +1 -0
- data/spec/lib/fixtures/required_tree_test/required_file2.rb +1 -0
- data/spec/lib/fixtures/requires.rb +7 -0
- data/spec/lib/fixtures/source_location_test.rb +7 -0
- data/spec/lib/fixtures/source_map.rb +1 -0
- data/spec/lib/fixtures/source_map/subfolder/other_file.rb +1 -0
- data/spec/lib/fixtures/sprockets_file.js.rb +3 -0
- data/spec/lib/fixtures/sprockets_require_tree_test.rb +3 -0
- data/spec/lib/path_reader_spec.rb +47 -0
- data/spec/lib/paths_spec.rb +18 -0
- data/spec/lib/repl_spec.rb +28 -0
- data/spec/lib/rewriters/base_spec.rb +68 -0
- data/spec/lib/rewriters/binary_operator_assignment_spec.rb +153 -0
- data/spec/lib/rewriters/block_to_iter_spec.rb +28 -0
- data/spec/lib/rewriters/dot_js_syntax_spec.rb +108 -0
- data/spec/lib/rewriters/explicit_writer_return_spec.rb +186 -0
- data/spec/lib/rewriters/for_rewriter_spec.rb +92 -0
- data/spec/lib/rewriters/hashes/key_duplicates_rewriter_spec.rb +47 -0
- data/spec/lib/rewriters/js_reserved_words_spec.rb +119 -0
- data/spec/lib/rewriters/logical_operator_assignment_spec.rb +202 -0
- data/spec/lib/rewriters/opal_engine_check_spec.rb +84 -0
- data/spec/lib/rewriters/returnable_logic_spec.rb +52 -0
- data/spec/lib/rewriters/rubyspec/filters_rewriter_spec.rb +59 -0
- data/spec/lib/simple_server_spec.rb +56 -0
- data/spec/lib/source_map/file_spec.rb +67 -0
- data/spec/lib/source_map/index_spec.rb +80 -0
- data/spec/lib/spec_helper.rb +105 -0
- data/spec/mspec-opal/formatters.rb +197 -0
- data/spec/mspec-opal/runner.rb +172 -0
- data/spec/opal/compiler/irb_spec.rb +44 -0
- data/spec/opal/compiler/unicode_spec.rb +10 -0
- data/spec/opal/core/array/dup_spec.rb +23 -0
- data/spec/opal/core/array/intersection_spec.rb +38 -0
- data/spec/opal/core/array/minus_spec.rb +38 -0
- data/spec/opal/core/array/union_spec.rb +38 -0
- data/spec/opal/core/array/uniq_spec.rb +49 -0
- data/spec/opal/core/class/inherited_spec.rb +18 -0
- data/spec/opal/core/enumerable/all_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/any_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/collect_break_spec.rb +13 -0
- data/spec/opal/core/enumerable/count_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/detect_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/drop_while_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/each_slice_break_spec.rb +6 -0
- data/spec/opal/core/enumerable/each_with_index_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/each_with_object_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/find_all_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/find_index_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/grep_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/max_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/max_by_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/min_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/min_by_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/none_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/one_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/reduce_break_spec.rb +5 -0
- data/spec/opal/core/enumerable/take_while_break_spec.rb +5 -0
- data/spec/opal/core/enumerator/with_index_spec.rb +6 -0
- data/spec/opal/core/exception_spec.rb +8 -0
- data/spec/opal/core/fixtures/require_tree_files/file 1.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/file 2.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/file 3.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/file 4.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/file 5.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/nested/nested 1.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/nested/nested 2.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_files/other/other 1.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_with_dot/file 1.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_with_dot/file 2.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_with_dot/file 3.rb +1 -0
- data/spec/opal/core/fixtures/require_tree_with_dot/index.rb +3 -0
- data/spec/opal/core/hash/internals_spec.rb +339 -0
- data/spec/opal/core/helpers_spec.rb +14 -0
- data/spec/opal/core/iterable_props_spec.rb +53 -0
- data/spec/opal/core/kernel/at_exit_spec.rb +70 -0
- data/spec/opal/core/kernel/freeze_spec.rb +15 -0
- data/spec/opal/core/kernel/instance_variables_spec.rb +110 -0
- data/spec/opal/core/kernel/methods_spec.rb +25 -0
- data/spec/opal/core/kernel/public_methods_spec.rb +25 -0
- data/spec/opal/core/kernel/require_tree_spec.rb +18 -0
- data/spec/opal/core/kernel/respond_to_spec.rb +15 -0
- data/spec/opal/core/language/DATA/characters_support_spec.rb +9 -0
- data/spec/opal/core/language/DATA/empty___END___spec.rb +7 -0
- data/spec/opal/core/language/DATA/multiple___END___spec.rb +10 -0
- data/spec/opal/core/language/arguments/mlhs_arg_spec.rb +18 -0
- data/spec/opal/core/language/keyword_arguments_spec.rb +9 -0
- data/spec/opal/core/language/numblocks_spec.rb +16 -0
- data/spec/opal/core/language/safe_navigator_spec.rb +7 -0
- data/spec/opal/core/language/while_spec.rb +31 -0
- data/spec/opal/core/language_spec.rb +29 -0
- data/spec/opal/core/marshal/dump_spec.rb +81 -0
- data/spec/opal/core/marshal/load_spec.rb +13 -0
- data/spec/opal/core/module_spec.rb +27 -0
- data/spec/opal/core/object_id_spec.rb +56 -0
- data/spec/opal/core/regexp/interpolation_spec.rb +40 -0
- data/spec/opal/core/regexp/match_spec.rb +78 -0
- data/spec/opal/core/runtime/bridged_classes_spec.rb +123 -0
- data/spec/opal/core/runtime/constants_spec.rb +16 -0
- data/spec/opal/core/runtime/eval_spec.rb +5 -0
- data/spec/opal/core/runtime/exit_spec.rb +29 -0
- data/spec/opal/core/runtime/is_a_spec.rb +48 -0
- data/spec/opal/core/runtime/loaded_spec.rb +20 -0
- data/spec/opal/core/runtime/main_methods_spec.rb +39 -0
- data/spec/opal/core/runtime/method_missing_spec.rb +68 -0
- data/spec/opal/core/runtime/rescue_spec.rb +37 -0
- data/spec/opal/core/runtime/string_spec.rb +25 -0
- data/spec/opal/core/runtime/truthy_spec.rb +61 -0
- data/spec/opal/core/runtime_spec.rb +58 -0
- data/spec/opal/core/string/each_byte_spec.rb +19 -0
- data/spec/opal/core/string/gsub_spec.rb +35 -0
- data/spec/opal/core/string/to_sym_spec.rb +9 -0
- data/spec/opal/core/string_spec.rb +28 -0
- data/spec/opal/core/struct/dup_spec.rb +11 -0
- data/spec/opal/core/time_spec.rb +68 -0
- data/spec/opal/stdlib/erb/erb_spec.rb +30 -0
- data/spec/opal/stdlib/erb/inline_block.opalerb +3 -0
- data/spec/opal/stdlib/erb/quoted.opalerb +1 -0
- data/spec/opal/stdlib/erb/simple.opalerb +1 -0
- data/spec/opal/stdlib/js_spec.rb +72 -0
- data/spec/opal/stdlib/json/ext_spec.rb +55 -0
- data/spec/opal/stdlib/json/parse_spec.rb +37 -0
- data/spec/opal/stdlib/logger/logger_spec.rb +308 -0
- data/spec/opal/stdlib/native/alias_native_spec.rb +27 -0
- data/spec/opal/stdlib/native/array_spec.rb +11 -0
- data/spec/opal/stdlib/native/date_spec.rb +12 -0
- data/spec/opal/stdlib/native/deprecated_include_spec.rb +8 -0
- data/spec/opal/stdlib/native/each_spec.rb +13 -0
- data/spec/opal/stdlib/native/element_reference_spec.rb +16 -0
- data/spec/opal/stdlib/native/exposure_spec.rb +33 -0
- data/spec/opal/stdlib/native/ext_spec.rb +19 -0
- data/spec/opal/stdlib/native/hash_spec.rb +67 -0
- data/spec/opal/stdlib/native/initialize_spec.rb +17 -0
- data/spec/opal/stdlib/native/method_missing_spec.rb +51 -0
- data/spec/opal/stdlib/native/native_alias_spec.rb +26 -0
- data/spec/opal/stdlib/native/native_class_spec.rb +18 -0
- data/spec/opal/stdlib/native/native_module_spec.rb +13 -0
- data/spec/opal/stdlib/native/native_reader_spec.rb +22 -0
- data/spec/opal/stdlib/native/native_writer_spec.rb +30 -0
- data/spec/opal/stdlib/native/new_spec.rb +92 -0
- data/spec/opal/stdlib/native/struct_spec.rb +12 -0
- data/spec/opal/stdlib/pp_spec.rb +5 -0
- data/spec/opal/stdlib/promise/always_spec.rb +49 -0
- data/spec/opal/stdlib/promise/error_spec.rb +15 -0
- data/spec/opal/stdlib/promise/rescue_spec.rb +53 -0
- data/spec/opal/stdlib/promise/then_spec.rb +79 -0
- data/spec/opal/stdlib/promise/trace_spec.rb +51 -0
- data/spec/opal/stdlib/promise/value_spec.rb +15 -0
- data/spec/opal/stdlib/promise/when_spec.rb +34 -0
- data/spec/opal/stdlib/source_map_spec.rb +8 -0
- data/spec/opal/stdlib/strscan/scan_spec.rb +11 -0
- data/spec/opal/stdlib/template/paths_spec.rb +10 -0
- data/spec/opal/stdlib/thread/mutex_spec.rb +40 -0
- data/spec/opal/stdlib/thread/thread_queue_spec.rb +32 -0
- data/spec/opal/stdlib/thread/thread_spec.rb +60 -0
- data/spec/ruby_specs +183 -0
- data/spec/spec_helper.rb +31 -0
- data/spec/support/guard_platform.rb +4 -0
- data/spec/support/match_helpers.rb +57 -0
- data/spec/support/mspec_rspec_adapter.rb +33 -0
- data/spec/support/rewriters_helper.rb +54 -0
- data/spec/support/source_map_helper.rb +190 -0
- data/stdlib/base64.rb +2 -2
- data/stdlib/bigdecimal.rb +15 -3
- data/stdlib/bigdecimal/bignumber.js.rb +1 -1
- data/stdlib/bigdecimal/util.rb +148 -0
- data/stdlib/delegate.rb +8 -0
- data/stdlib/nodejs/fileutils.rb +1 -1
- data/stdlib/nodejs/kernel.rb +0 -13
- data/stdlib/nodejs/stacktrace.rb +4 -179
- data/stdlib/ostruct.rb +5 -0
- data/stdlib/pp.rb +586 -19
- data/stdlib/prettyprint.rb +556 -0
- data/stdlib/rbconfig/sizeof.rb +2 -0
- data/stdlib/securerandom.rb +32 -0
- data/stdlib/set.rb +36 -0
- data/stdlib/strscan.rb +15 -0
- data/tasks/benchmarking.rake +1 -1
- data/tasks/linting.rake +3 -5
- data/tasks/releasing.rake +2 -5
- data/tasks/testing.rake +16 -11
- data/tasks/testing/mspec_special_calls.rb +1 -19
- data/test/nodejs/fixtures/cat.png +0 -0
- data/test/nodejs/fixtures/hello.rb +1 -0
- data/test/nodejs/fixtures/iso88591.txt +1 -0
- data/test/nodejs/fixtures/utf8.txt +1 -0
- data/test/nodejs/fixtures/win1258.txt +1 -0
- data/test/nodejs/test_dir.rb +39 -0
- data/test/nodejs/test_env.rb +62 -0
- data/test/nodejs/test_error.rb +29 -0
- data/test/nodejs/test_file.rb +206 -0
- data/test/nodejs/test_file_encoding.rb +20 -0
- data/test/nodejs/test_io.rb +18 -0
- data/test/nodejs/test_opal_builder.rb +12 -0
- data/test/nodejs/test_pathname.rb +16 -0
- data/test/opal/cat.png +0 -0
- data/test/opal/http_server.rb +52 -0
- data/test/opal/test_base64.rb +115 -0
- data/test/opal/test_keyword.rb +590 -0
- data/test/opal/test_matrix.rb +661 -0
- data/test/opal/test_openuri.rb +53 -0
- data/test/opal/unsupported_and_bugs.rb +39 -0
- data/yarn.lock +1355 -0
- metadata +905 -40
- data/.travis.yml +0 -109
- data/appveyor.yml +0 -35
- data/lib/opal/nodes/runtime_helpers.rb +0 -51
- data/opal/corelib/random/MersenneTwister.js +0 -137
- data/opal/corelib/random/mersenne_twister.js.rb +0 -13
- data/stdlib/bigdecimal/kernel.rb +0 -5
data/lib/opal/nodes/masgn.rb
CHANGED
@@ -51,6 +51,7 @@ module Opal
|
|
51
51
|
|
52
52
|
if post_splat.empty? # trailing splat
|
53
53
|
if part = splat.children[0]
|
54
|
+
helper :slice
|
54
55
|
part = part.dup << s(:js_tmp, "$slice.call(#{array}, #{pre_splat.size})")
|
55
56
|
push ', '
|
56
57
|
push expr(part)
|
@@ -61,6 +62,7 @@ module Opal
|
|
61
62
|
push ", #{tmp} = (#{tmp} < #{pre_splat.size}) ? #{pre_splat.size} : #{tmp}"
|
62
63
|
|
63
64
|
if part = splat.children[0]
|
65
|
+
helper :slice
|
64
66
|
part = part.dup << s(:js_tmp, "$slice.call(#{array}, #{pre_splat.size}, #{tmp})")
|
65
67
|
push ', '
|
66
68
|
push expr(part)
|
data/lib/opal/nodes/rescue.rb
CHANGED
@@ -162,7 +162,7 @@ module Opal
|
|
162
162
|
push 'if (Opal.rescue($err, ', expr(klasses), ')) {'
|
163
163
|
indent do
|
164
164
|
if lvar
|
165
|
-
push expr(lvar
|
165
|
+
push expr(lvar.updated(nil, [*lvar.children, s(:js_tmp, '$err')]))
|
166
166
|
end
|
167
167
|
|
168
168
|
# Need to ensure we clear the current exception out after the rescue block ends
|
data/lib/opal/nodes/super.rb
CHANGED
@@ -25,11 +25,12 @@ module Opal
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def compile_using_send
|
28
|
-
helper :
|
28
|
+
helper :send2
|
29
29
|
|
30
|
-
push '$
|
30
|
+
push '$send2('
|
31
31
|
compile_receiver
|
32
|
-
|
32
|
+
compile_method_body
|
33
|
+
compile_method_name
|
33
34
|
compile_arguments
|
34
35
|
compile_block_pass
|
35
36
|
push ')'
|
@@ -71,12 +72,12 @@ module Opal
|
|
71
72
|
def_scope.identify!(def_scope.mid)
|
72
73
|
end
|
73
74
|
|
75
|
+
def allow_stubs
|
76
|
+
true
|
77
|
+
end
|
78
|
+
|
74
79
|
def super_method_invocation
|
75
|
-
|
76
|
-
"Opal.find_super_dispatcher(self, '#{method_id}', #{def_scope_identity}, #{defined_check_param}, self.$$class.$$prototype)"
|
77
|
-
else
|
78
|
-
"Opal.find_super_dispatcher(self, '#{method_id}', #{def_scope_identity}, #{defined_check_param})"
|
79
|
-
end
|
80
|
+
"Opal.find_super_dispatcher(self, '#{method_id}', #{def_scope_identity}, #{defined_check_param}, #{allow_stubs})"
|
80
81
|
end
|
81
82
|
|
82
83
|
def super_block_invocation
|
@@ -85,7 +86,7 @@ module Opal
|
|
85
86
|
"Opal.find_iter_super_dispatcher(self, #{mid}, (#{trys} || #{cur_defn}), #{defined_check_param}, #{implicit_arguments_param})"
|
86
87
|
end
|
87
88
|
|
88
|
-
def
|
89
|
+
def compile_method_body
|
89
90
|
push ', '
|
90
91
|
if scope.def?
|
91
92
|
push super_method_invocation
|
@@ -95,14 +96,27 @@ module Opal
|
|
95
96
|
raise 'super must be called from method body or block'
|
96
97
|
end
|
97
98
|
end
|
99
|
+
|
100
|
+
def compile_method_name
|
101
|
+
if scope.def?
|
102
|
+
push ", '#{method_id}'"
|
103
|
+
elsif scope.iter?
|
104
|
+
_chain, _cur_defn, mid = scope.super_chain
|
105
|
+
push ", #{mid}"
|
106
|
+
end
|
107
|
+
end
|
98
108
|
end
|
99
109
|
|
100
110
|
class DefinedSuperNode < BaseSuperNode
|
101
111
|
handle :defined_super
|
102
112
|
|
113
|
+
def allow_stubs
|
114
|
+
false
|
115
|
+
end
|
116
|
+
|
103
117
|
def compile
|
104
118
|
compile_receiver
|
105
|
-
|
119
|
+
compile_method_body
|
106
120
|
|
107
121
|
wrap '((', ') != null ? "super" : nil)'
|
108
122
|
end
|
data/lib/opal/nodes/top.rb
CHANGED
@@ -17,6 +17,8 @@ module Opal
|
|
17
17
|
|
18
18
|
opening
|
19
19
|
in_scope do
|
20
|
+
line '"use strict";' if compiler.use_strict?
|
21
|
+
|
20
22
|
body_code = stmt(stmts)
|
21
23
|
body_code = [body_code] unless body_code.is_a?(Array)
|
22
24
|
|
@@ -27,8 +29,8 @@ module Opal
|
|
27
29
|
add_temp '$nesting = []'
|
28
30
|
end
|
29
31
|
add_temp 'nil = Opal.nil'
|
30
|
-
add_temp '$$$ = Opal
|
31
|
-
add_temp '$$ = Opal
|
32
|
+
add_temp '$$$ = Opal.$$$'
|
33
|
+
add_temp '$$ = Opal.$$'
|
32
34
|
|
33
35
|
add_used_helpers
|
34
36
|
add_used_operators
|
@@ -75,8 +77,7 @@ module Opal
|
|
75
77
|
end
|
76
78
|
|
77
79
|
def add_used_helpers
|
78
|
-
|
79
|
-
helpers.to_a.each { |h| add_temp "$#{h} = Opal.#{h}" }
|
80
|
+
compiler.helpers.to_a.each { |h| add_temp "$#{h} = Opal.#{h}" }
|
80
81
|
end
|
81
82
|
|
82
83
|
def add_used_operators
|
@@ -1,9 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# There's no compatible c_lexer for parser 3.0.0.0 at this point...
|
3
4
|
begin
|
4
5
|
require 'c_lexer'
|
5
6
|
rescue LoadError
|
6
|
-
$stderr.puts 'Failed to load WithCLexer, using pure Ruby lexer'
|
7
|
+
$stderr.puts 'Failed to load WithCLexer, using pure Ruby lexer' if $DEBUG
|
7
8
|
end
|
8
9
|
|
9
10
|
if defined? Parser::Ruby25WithWithCLexer
|
data/lib/opal/path_reader.rb
CHANGED
@@ -5,7 +5,7 @@ require 'opal/hike'
|
|
5
5
|
|
6
6
|
module Opal
|
7
7
|
class PathReader
|
8
|
-
RELATIVE_PATH_REGEXP = /#{Opal::REGEXP_START}\.?\.#{Regexp.quote File::SEPARATOR}
|
8
|
+
RELATIVE_PATH_REGEXP = /#{Opal::REGEXP_START}\.?\.#{Regexp.quote File::SEPARATOR}/.freeze
|
9
9
|
DEFAULT_EXTENSIONS = ['.js', '.js.rb', '.rb', '.opalerb'].freeze
|
10
10
|
|
11
11
|
def initialize(paths = Opal.paths, extensions = DEFAULT_EXTENSIONS)
|
@@ -17,7 +17,7 @@ module Opal
|
|
17
17
|
def read(path)
|
18
18
|
full_path = expand(path)
|
19
19
|
return nil if full_path.nil?
|
20
|
-
File.open(full_path, 'rb:UTF-8', &:read)
|
20
|
+
File.open(full_path, 'rb:UTF-8', &:read) if File.exist?(full_path)
|
21
21
|
end
|
22
22
|
|
23
23
|
def expand(path)
|
data/lib/opal/paths.rb
CHANGED
@@ -1,17 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Opal
|
4
|
+
# We use this file from inside Opal as well, and __dir__ is not yet supported.
|
5
|
+
# rubocop:disable Style/ExpandPathArguments
|
4
6
|
def self.gem_dir
|
5
|
-
File.expand_path('../..', __FILE__
|
7
|
+
File.expand_path('../..', __FILE__)
|
6
8
|
end
|
7
9
|
|
8
10
|
def self.core_dir
|
9
|
-
File.expand_path('../../../opal', __FILE__
|
11
|
+
File.expand_path('../../../opal', __FILE__)
|
10
12
|
end
|
11
13
|
|
12
14
|
def self.std_dir
|
13
|
-
File.expand_path('../../../stdlib', __FILE__
|
15
|
+
File.expand_path('../../../stdlib', __FILE__)
|
14
16
|
end
|
17
|
+
# rubocop:enable Style/ExpandPathArguments
|
15
18
|
|
16
19
|
# Add a file path to opals load path. Any gem containing ruby code that Opal
|
17
20
|
# has access to should add a load path through this method. Load paths added
|
@@ -67,13 +70,13 @@ module Opal
|
|
67
70
|
extend UseGem
|
68
71
|
|
69
72
|
def self.paths
|
70
|
-
@paths.
|
73
|
+
@paths.freeze
|
71
74
|
end
|
72
75
|
|
73
76
|
# Resets Opal.paths to the default value
|
74
77
|
# (includes `corelib`, `stdlib`, `opal/lib`, `ast` gem and `parser` gem)
|
75
78
|
def self.reset_paths!
|
76
|
-
@paths = [core_dir
|
79
|
+
@paths = [core_dir, std_dir, gem_dir]
|
77
80
|
if RUBY_ENGINE != 'opal'
|
78
81
|
use_gem 'ast'
|
79
82
|
use_gem 'parser'
|
data/lib/opal/repl.rb
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'opal'
|
4
|
+
|
5
|
+
module Opal
|
6
|
+
class REPL
|
7
|
+
HISTORY_PATH = File.expand_path('~/.opal-repl-history')
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
begin
|
11
|
+
require 'mini_racer'
|
12
|
+
rescue LoadError
|
13
|
+
abort 'opal-repl depends on mini_racer gem, which is not currently installed'
|
14
|
+
end
|
15
|
+
|
16
|
+
begin
|
17
|
+
require 'readline'
|
18
|
+
rescue LoadError
|
19
|
+
abort 'opal-repl depends on readline, which is not currently available'
|
20
|
+
end
|
21
|
+
|
22
|
+
MiniRacer::Platform.set_flags! :harmony
|
23
|
+
|
24
|
+
@history = File.exist?(HISTORY_PATH)
|
25
|
+
end
|
26
|
+
|
27
|
+
def run(filename = nil)
|
28
|
+
load_opal
|
29
|
+
load_file(filename) if filename
|
30
|
+
load_history
|
31
|
+
run_input_loop
|
32
|
+
ensure
|
33
|
+
dump_history
|
34
|
+
end
|
35
|
+
|
36
|
+
def load_file(filename)
|
37
|
+
raise "file does not exist: #{filename}" unless File.exist? filename
|
38
|
+
eval_ruby File.read(filename)
|
39
|
+
end
|
40
|
+
|
41
|
+
def load_opal
|
42
|
+
v8.attach('console.log', method(:puts).to_proc)
|
43
|
+
v8.attach('console.warn', method(:warn).to_proc)
|
44
|
+
v8.eval Opal::Builder.new.build('opal').to_s
|
45
|
+
v8.attach('Opal.exit', method(:exit).to_proc)
|
46
|
+
end
|
47
|
+
|
48
|
+
def run_line(line)
|
49
|
+
result = eval_ruby(line)
|
50
|
+
puts "=> #{result}"
|
51
|
+
end
|
52
|
+
|
53
|
+
def run_input_loop
|
54
|
+
# on SIGINT lets just return from the loop..
|
55
|
+
previous_trap = trap('SIGINT') { return }
|
56
|
+
|
57
|
+
while (line = readline)
|
58
|
+
run_line(line)
|
59
|
+
end
|
60
|
+
|
61
|
+
ensure
|
62
|
+
trap('SIGINT', previous_trap || 'DEFAULT')
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def eval_ruby(code)
|
68
|
+
builder = Opal::Builder.new
|
69
|
+
builder.build_str(code, '(irb)', irb: true, const_missing: true)
|
70
|
+
builder.processed[0...-1].each { |js_code| eval_js js_code.to_s }
|
71
|
+
last_processed_file = builder.processed.last.to_s
|
72
|
+
eval_js <<-JS
|
73
|
+
var $_result = #{last_processed_file};
|
74
|
+
$_result.$inspect()
|
75
|
+
JS
|
76
|
+
rescue => e
|
77
|
+
puts "#{e.message}\n\t#{e.backtrace.join("\n\t")}"
|
78
|
+
end
|
79
|
+
|
80
|
+
def eval_js(code)
|
81
|
+
v8.eval(code)
|
82
|
+
end
|
83
|
+
|
84
|
+
def v8
|
85
|
+
@v8 ||= MiniRacer::Context.new
|
86
|
+
end
|
87
|
+
|
88
|
+
def readline
|
89
|
+
Readline.readline '>> ', true
|
90
|
+
end
|
91
|
+
|
92
|
+
def load_history
|
93
|
+
return unless @history
|
94
|
+
File.read(HISTORY_PATH).lines.each { |line| Readline::HISTORY.push line.strip }
|
95
|
+
end
|
96
|
+
|
97
|
+
def dump_history
|
98
|
+
return unless @history
|
99
|
+
length = Readline::HISTORY.size > 1000 ? 1000 : Readline::HISTORY.size
|
100
|
+
File.write(HISTORY_PATH, Readline::HISTORY.to_a[-length..-1].join("\n"))
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
data/lib/opal/rewriter.rb
CHANGED
@@ -12,6 +12,8 @@ require 'opal/rewriters/hashes/key_duplicates_rewriter'
|
|
12
12
|
require 'opal/rewriters/dump_args'
|
13
13
|
require 'opal/rewriters/mlhs_args'
|
14
14
|
require 'opal/rewriters/inline_args'
|
15
|
+
require 'opal/rewriters/numblocks'
|
16
|
+
require 'opal/rewriters/returnable_logic'
|
15
17
|
|
16
18
|
module Opal
|
17
19
|
class Rewriter
|
@@ -42,6 +44,7 @@ module Opal
|
|
42
44
|
|
43
45
|
use Rewriters::OpalEngineCheck
|
44
46
|
use Rewriters::ForRewriter
|
47
|
+
use Rewriters::Numblocks
|
45
48
|
use Rewriters::BlockToIter
|
46
49
|
use Rewriters::DotJsSyntax
|
47
50
|
use Rewriters::JsReservedWords
|
@@ -49,6 +52,7 @@ module Opal
|
|
49
52
|
use Rewriters::BinaryOperatorAssignment
|
50
53
|
use Rewriters::ExplicitWriterReturn
|
51
54
|
use Rewriters::Hashes::KeyDuplicatesRewriter
|
55
|
+
use Rewriters::ReturnableLogic
|
52
56
|
use Rewriters::DumpArgs
|
53
57
|
use Rewriters::MlhsArgs
|
54
58
|
use Rewriters::InlineArgs
|
@@ -8,25 +8,25 @@ module Opal
|
|
8
8
|
class JsReservedWords < Base
|
9
9
|
# Reserved javascript keywords - we cannot create variables with the
|
10
10
|
# same name (ref: http://stackoverflow.com/a/9337272/601782)
|
11
|
-
ES51_RESERVED_WORD = /#{REGEXP_START}(?:do|if|in|for|let|new|try|var|case|else|enum|eval|false|null|this|true|void|with|break|catch|class|const|super|throw|while|yield|delete|export|import|public|return|static|switch|typeof|default|extends|finally|package|private|continue|debugger|function|arguments|interface|protected|implements|instanceof)#{REGEXP_END}
|
11
|
+
ES51_RESERVED_WORD = /#{REGEXP_START}(?:do|if|in|for|let|new|try|var|case|else|enum|eval|false|null|this|true|void|with|break|catch|class|const|super|throw|while|yield|delete|export|import|public|return|static|switch|typeof|default|extends|finally|package|private|continue|debugger|function|arguments|interface|protected|implements|instanceof)#{REGEXP_END}/.freeze
|
12
12
|
|
13
13
|
# ES3 reserved words that aren’t ES5.1 reserved words
|
14
|
-
ES3_RESERVED_WORD_EXCLUSIVE = /#{REGEXP_START}(?:int|byte|char|goto|long|final|float|short|double|native|throws|boolean|abstract|volatile|transient|synchronized)#{REGEXP_END}
|
14
|
+
ES3_RESERVED_WORD_EXCLUSIVE = /#{REGEXP_START}(?:int|byte|char|goto|long|final|float|short|double|native|throws|boolean|abstract|volatile|transient|synchronized)#{REGEXP_END}/.freeze
|
15
15
|
|
16
16
|
# Prototype special properties.
|
17
|
-
PROTO_SPECIAL_PROPS = /#{REGEXP_START}(?:constructor|displayName|__proto__|__parent__|__noSuchMethod__|__count__)#{REGEXP_END}
|
17
|
+
PROTO_SPECIAL_PROPS = /#{REGEXP_START}(?:constructor|displayName|__proto__|__parent__|__noSuchMethod__|__count__)#{REGEXP_END}/.freeze
|
18
18
|
|
19
19
|
# Prototype special methods.
|
20
|
-
PROTO_SPECIAL_METHODS = /#{REGEXP_START}(?:hasOwnProperty|valueOf)#{REGEXP_END}
|
20
|
+
PROTO_SPECIAL_METHODS = /#{REGEXP_START}(?:hasOwnProperty|valueOf)#{REGEXP_END}/.freeze
|
21
21
|
|
22
22
|
# Immutable properties of the global object
|
23
|
-
IMMUTABLE_PROPS = /#{REGEXP_START}(?:NaN|Infinity|undefined)#{REGEXP_END}
|
23
|
+
IMMUTABLE_PROPS = /#{REGEXP_START}(?:NaN|Infinity|undefined)#{REGEXP_END}/.freeze
|
24
24
|
|
25
25
|
# Doesn't take in account utf8
|
26
|
-
BASIC_IDENTIFIER_RULES = /#{REGEXP_START}[$_a-z][$_a-z\d]*#{REGEXP_END}/i
|
26
|
+
BASIC_IDENTIFIER_RULES = /#{REGEXP_START}[$_a-z][$_a-z\d]*#{REGEXP_END}/i.freeze
|
27
27
|
|
28
28
|
# Defining a local function like Array may break everything
|
29
|
-
RESERVED_FUNCTION_NAMES = /#{REGEXP_START}(?:Array)#{REGEXP_END}
|
29
|
+
RESERVED_FUNCTION_NAMES = /#{REGEXP_START}(?:Array)#{REGEXP_END}/.freeze
|
30
30
|
|
31
31
|
def self.valid_name?(name)
|
32
32
|
BASIC_IDENTIFIER_RULES =~ name && !(
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'opal/rewriters/base'
|
4
|
+
|
5
|
+
module Opal
|
6
|
+
module Rewriters
|
7
|
+
# This rewriter transforms the Ruby 2.7 numblocks to regular blocks:
|
8
|
+
#
|
9
|
+
# proc { _1 }
|
10
|
+
# v
|
11
|
+
# proc { |_1| _1 }
|
12
|
+
class Numblocks < Base
|
13
|
+
def on_numblock(node)
|
14
|
+
left, arg_count, right = node.children
|
15
|
+
|
16
|
+
s(
|
17
|
+
:block,
|
18
|
+
left,
|
19
|
+
s(:args, *gen_args(arg_count)),
|
20
|
+
right
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
def gen_args(arg_count)
|
25
|
+
(1..arg_count).map do |i|
|
26
|
+
s(:arg, :"_#{i}")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'opal/rewriters/base'
|
4
|
+
|
5
|
+
module Opal
|
6
|
+
module Rewriters
|
7
|
+
class ReturnableLogic < Base
|
8
|
+
def next_tmp
|
9
|
+
@counter ||= 0
|
10
|
+
@counter += 1
|
11
|
+
"$ret_or_#{@counter}"
|
12
|
+
end
|
13
|
+
|
14
|
+
def reset_tmp_counter!
|
15
|
+
@counter = nil
|
16
|
+
end
|
17
|
+
|
18
|
+
def on_or(node)
|
19
|
+
lhs, rhs = *node.children
|
20
|
+
lhs_tmp = next_tmp
|
21
|
+
|
22
|
+
node.updated(:if, [s(:lvasgn, lhs_tmp, process(lhs)), s(:js_tmp, lhs_tmp), process(rhs)])
|
23
|
+
end
|
24
|
+
|
25
|
+
def on_and(node)
|
26
|
+
lhs, rhs = *node.children
|
27
|
+
lhs_tmp = next_tmp
|
28
|
+
|
29
|
+
node.updated(:if, [s(:lvasgn, lhs_tmp, process(lhs)), process(rhs), s(:js_tmp, lhs_tmp)])
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|