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
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'tempfile'
|
4
|
+
|
5
|
+
# Generic runner that will resort to calling an external program.
|
6
|
+
#
|
7
|
+
# @option :options [Hash,nil] :env a hash of options to be used as env in the
|
8
|
+
# call to system.
|
9
|
+
# @option :options [true,false] :debug enabling debug mode will write the
|
10
|
+
# compiled JavaScript file in the current working directory.
|
11
|
+
# @yield tempfile [File] Gives a file to the block, its #path can be used to
|
12
|
+
# construct the command
|
13
|
+
# @yieldreturn command [Array<String>] the command to be used in the system call
|
14
|
+
SystemRunner = ->(data, &block) {
|
15
|
+
options = data[:options] || {}
|
16
|
+
builder = data.fetch(:builder)
|
17
|
+
output = data.fetch(:output)
|
18
|
+
|
19
|
+
env = options.fetch(:env, {})
|
20
|
+
debug = options.fetch(:debug, false)
|
21
|
+
|
22
|
+
code = builder.to_s + "\n" + builder.source_map.to_data_uri_comment
|
23
|
+
|
24
|
+
tempfile =
|
25
|
+
if debug
|
26
|
+
File.new('opal-nodejs-runner.js', 'w')
|
27
|
+
else
|
28
|
+
Tempfile.new('opal-system-runner-')
|
29
|
+
end
|
30
|
+
|
31
|
+
tempfile.write code
|
32
|
+
cmd = block.call tempfile
|
33
|
+
tempfile.close
|
34
|
+
|
35
|
+
# JRuby (v9.2) doesn't support using `out:` to redirect output.
|
36
|
+
if IO.try_convert(output) && RUBY_PLATFORM != 'java'
|
37
|
+
system(env, *cmd, out: output)
|
38
|
+
$?.exitstatus
|
39
|
+
else
|
40
|
+
require 'open3'
|
41
|
+
captured_output, status = Open3.capture2(env, *cmd)
|
42
|
+
output.write captured_output
|
43
|
+
status.exitstatus
|
44
|
+
end
|
45
|
+
}
|
data/lib/opal/compiler.rb
CHANGED
@@ -6,6 +6,7 @@ require 'opal/fragment'
|
|
6
6
|
require 'opal/nodes'
|
7
7
|
require 'opal/eof_content'
|
8
8
|
require 'opal/errors'
|
9
|
+
require 'opal/magic_comments'
|
9
10
|
|
10
11
|
module Opal
|
11
12
|
# Compile a string of ruby code into javascript.
|
@@ -57,18 +58,38 @@ module Opal
|
|
57
58
|
Pathname(path).cleanpath.to_s
|
58
59
|
end
|
59
60
|
|
60
|
-
#
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
61
|
+
# Defines a compiler option.
|
62
|
+
# @option as: [Symbol] uses a different method name, e.g. with a question mark for booleans
|
63
|
+
# @option default: [Object] the default value for the option
|
64
|
+
# @option magic_comment: [Bool] allows magic-comments to override the option value
|
65
|
+
def self.compiler_option(name, config = {})
|
66
|
+
method_name = config.fetch(:as, name)
|
67
|
+
define_method(method_name) { option_value(name, config) }
|
68
|
+
end
|
69
|
+
|
70
|
+
# Fetches and memoizes the value for an option.
|
71
|
+
def option_value(name, config)
|
72
|
+
return @option_values[name] if @option_values.key? name
|
73
|
+
|
74
|
+
default_value = config[:default]
|
75
|
+
valid_values = config[:valid_values]
|
76
|
+
magic_comment = config[:magic_comment]
|
77
|
+
|
78
|
+
value = @options.fetch(name, default_value)
|
79
|
+
|
80
|
+
if magic_comment && @magic_comments.key?(name)
|
81
|
+
value = @magic_comments.fetch(name)
|
82
|
+
end
|
83
|
+
|
84
|
+
if valid_values && !valid_values.include?(value)
|
85
|
+
raise(
|
86
|
+
ArgumentError,
|
87
|
+
"invalid value #{value.inspect} for option #{name.inspect} " \
|
88
|
+
"(valid values: #{valid_values.inspect})"
|
89
|
+
)
|
71
90
|
end
|
91
|
+
|
92
|
+
@option_values[name] = value
|
72
93
|
end
|
73
94
|
|
74
95
|
# @!method file
|
@@ -77,21 +98,21 @@ module Opal
|
|
77
98
|
# as well as finding relative require()
|
78
99
|
#
|
79
100
|
# @return [String]
|
80
|
-
compiler_option :file, '(file)'
|
101
|
+
compiler_option :file, default: '(file)'
|
81
102
|
|
82
103
|
# @!method method_missing?
|
83
104
|
#
|
84
105
|
# adds method stubs for all used methods in file
|
85
106
|
#
|
86
107
|
# @return [Boolean]
|
87
|
-
compiler_option :method_missing, true, as: :method_missing?
|
108
|
+
compiler_option :method_missing, default: true, as: :method_missing?
|
88
109
|
|
89
110
|
# @!method arity_check?
|
90
111
|
#
|
91
112
|
# adds an arity check to every method definition
|
92
113
|
#
|
93
114
|
# @return [Boolean]
|
94
|
-
compiler_option :arity_check, false, as: :arity_check?
|
115
|
+
compiler_option :arity_check, default: false, as: :arity_check?
|
95
116
|
|
96
117
|
# @deprecated
|
97
118
|
# @!method freezing?
|
@@ -99,45 +120,44 @@ module Opal
|
|
99
120
|
# stubs out #freeze and #frozen?
|
100
121
|
#
|
101
122
|
# @return [Boolean]
|
102
|
-
compiler_option :freezing, true, as: :freezing?
|
103
|
-
|
104
|
-
# @deprecated
|
105
|
-
# @!method tainting?
|
106
|
-
#
|
107
|
-
# stubs out #taint, #untaint and #tainted?
|
108
|
-
compiler_option :tainting, true, as: :tainting?
|
123
|
+
compiler_option :freezing, default: true, as: :freezing?
|
109
124
|
|
110
125
|
# @!method irb?
|
111
126
|
#
|
112
127
|
# compile top level local vars with support for irb style vars
|
113
|
-
compiler_option :irb, false, as: :irb?
|
128
|
+
compiler_option :irb, default: false, as: :irb?
|
114
129
|
|
115
130
|
# @!method dynamic_require_severity
|
116
131
|
#
|
117
132
|
# how to handle dynamic requires (:error, :warning, :ignore)
|
118
|
-
compiler_option :dynamic_require_severity, :ignore, valid_values: %i[error warning ignore]
|
133
|
+
compiler_option :dynamic_require_severity, default: :ignore, valid_values: %i[error warning ignore]
|
119
134
|
|
120
135
|
# @!method requirable?
|
121
136
|
#
|
122
137
|
# Prepare the code for future requires
|
123
|
-
compiler_option :requirable, false, as: :requirable?
|
138
|
+
compiler_option :requirable, default: false, as: :requirable?
|
124
139
|
|
125
140
|
# @!method inline_operators?
|
126
141
|
#
|
127
142
|
# are operators compiled inline
|
128
|
-
compiler_option :inline_operators, true, as: :inline_operators?
|
143
|
+
compiler_option :inline_operators, default: true, as: :inline_operators?
|
129
144
|
|
130
|
-
compiler_option :eval, false, as: :eval?
|
145
|
+
compiler_option :eval, default: false, as: :eval?
|
131
146
|
|
132
147
|
# @!method enable_source_location?
|
133
148
|
#
|
134
149
|
# Adds source_location for every method definition
|
135
|
-
compiler_option :enable_source_location, false, as: :enable_source_location?
|
150
|
+
compiler_option :enable_source_location, default: false, as: :enable_source_location?
|
151
|
+
|
152
|
+
# @!method use_strict?
|
153
|
+
#
|
154
|
+
# Adds source_location for every method definition
|
155
|
+
compiler_option :use_strict, default: false, as: :use_strict?, magic_comment: true
|
136
156
|
|
137
157
|
# @!method parse_comments?
|
138
158
|
#
|
139
159
|
# Adds comments for every method definition
|
140
|
-
compiler_option :parse_comments, false, as: :parse_comments?
|
160
|
+
compiler_option :parse_comments, default: false, as: :parse_comments?
|
141
161
|
|
142
162
|
# @return [String] The compiled ruby code
|
143
163
|
attr_reader :result
|
@@ -157,6 +177,9 @@ module Opal
|
|
157
177
|
# Comments from the source code
|
158
178
|
attr_reader :comments
|
159
179
|
|
180
|
+
# Magic comment flags extracted from the leading comments
|
181
|
+
attr_reader :magic_comments
|
182
|
+
|
160
183
|
def initialize(source, options = {})
|
161
184
|
@source = source
|
162
185
|
@indent = ''
|
@@ -164,6 +187,8 @@ module Opal
|
|
164
187
|
@options = options
|
165
188
|
@comments = Hash.new([])
|
166
189
|
@case_stmt = nil
|
190
|
+
@option_values = {}
|
191
|
+
@magic_comments = {}
|
167
192
|
end
|
168
193
|
|
169
194
|
# Compile some ruby code to a string.
|
@@ -188,6 +213,7 @@ module Opal
|
|
188
213
|
|
189
214
|
@sexp = s(:top, sexp || s(:nil))
|
190
215
|
@comments = ::Parser::Source::Comment.associate_locations(sexp, comments)
|
216
|
+
@magic_comments = MagicComments.parse(sexp, comments)
|
191
217
|
@eof_content = EofContent.new(tokens, @source).eof
|
192
218
|
end
|
193
219
|
|
@@ -206,7 +232,9 @@ module Opal
|
|
206
232
|
#
|
207
233
|
# @return [Set<Symbol>]
|
208
234
|
def helpers
|
209
|
-
@helpers ||= Set.new(
|
235
|
+
@helpers ||= Set.new(
|
236
|
+
magic_comments[:helpers].to_s.split(',').map { |h| h.strip.to_sym }
|
237
|
+
)
|
210
238
|
end
|
211
239
|
|
212
240
|
# Operator helpers
|
data/lib/opal/config.rb
CHANGED
@@ -93,11 +93,6 @@ module Opal
|
|
93
93
|
# @return [true, false]
|
94
94
|
config_option :freezing_stubs_enabled, true, compiler_option: :freezing
|
95
95
|
|
96
|
-
# Add stubs for methods related to tainting objects (for compatibility).
|
97
|
-
#
|
98
|
-
# @return [true, false]
|
99
|
-
config_option :tainting_stubs_enabled, true, compiler_option: :tainting
|
100
|
-
|
101
96
|
# Set the error severity for when a require can't be parsed at compile time.
|
102
97
|
#
|
103
98
|
# @example
|
data/lib/opal/erb.rb
CHANGED
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Opal::MagicComments
|
4
|
+
MAGIC_COMMENT_RE = /\A# *(\w+) *: *(\S+.*?) *$/.freeze
|
5
|
+
EMACS_MAGIC_COMMENT_RE = /\A# *-\*- *(\w+) *: *(\S+.*?) *-\*- *$/.freeze
|
6
|
+
|
7
|
+
def self.parse(sexp, comments)
|
8
|
+
flags = {}
|
9
|
+
|
10
|
+
# We have an upper limit at the first line of code
|
11
|
+
if sexp
|
12
|
+
first_line = sexp.loc.line
|
13
|
+
comments = comments.take(first_line)
|
14
|
+
end
|
15
|
+
|
16
|
+
comments.each do |comment|
|
17
|
+
next if first_line && comment.loc.line >= first_line
|
18
|
+
|
19
|
+
if (parts = comment.text.scan(MAGIC_COMMENT_RE)).any? ||
|
20
|
+
(parts = comment.text.scan(EMACS_MAGIC_COMMENT_RE)).any?
|
21
|
+
parts.each do |key, value|
|
22
|
+
flags[key.to_sym] =
|
23
|
+
case value
|
24
|
+
when 'true' then true
|
25
|
+
when 'false' then false
|
26
|
+
else value
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
flags
|
33
|
+
end
|
34
|
+
end
|
@@ -29,9 +29,10 @@ module Opal
|
|
29
29
|
return unless compiler.arity_check?
|
30
30
|
|
31
31
|
unless arity_checks.empty?
|
32
|
+
helper :ac
|
32
33
|
meth = scope.mid.to_s.inspect
|
33
34
|
line 'var $arity = arguments.length;'
|
34
|
-
push " if (#{arity_checks.join(' || ')}) {
|
35
|
+
push " if (#{arity_checks.join(' || ')}) { $ac($arity, #{arity}, this, #{meth}); }"
|
35
36
|
end
|
36
37
|
end
|
37
38
|
|
data/lib/opal/nodes/base.rb
CHANGED
data/lib/opal/nodes/call.rb
CHANGED
@@ -3,7 +3,6 @@
|
|
3
3
|
require 'set'
|
4
4
|
require 'pathname'
|
5
5
|
require 'opal/nodes/base'
|
6
|
-
require 'opal/nodes/runtime_helpers'
|
7
6
|
require 'opal/rewriters/break_finder'
|
8
7
|
|
9
8
|
module Opal
|
@@ -75,7 +74,7 @@ module Opal
|
|
75
74
|
# @see #compile_arguments
|
76
75
|
#
|
77
76
|
# When a method takes a block we have to calculate all arguments
|
78
|
-
# **before**
|
77
|
+
# **before** assigning '$$p' property (that stores a passed block)
|
79
78
|
# to a method body. This is some kind of protection from method calls
|
80
79
|
# like 'a(a {}) { 1 }'.
|
81
80
|
def invoke_using_send?
|
@@ -190,8 +189,6 @@ module Opal
|
|
190
189
|
if SPECIALS.include? meth
|
191
190
|
method = method("handle_#{meth}")
|
192
191
|
method.arity == 1 ? method[compile_default] : method[]
|
193
|
-
elsif RuntimeHelpers.compatible?(recvr, meth)
|
194
|
-
push(RuntimeHelpers.new(sexp_with_arglist, @level, @compiler).compile)
|
195
192
|
else
|
196
193
|
yield # i.e. compile_default.call
|
197
194
|
end
|
data/lib/opal/nodes/def.rb
CHANGED
data/lib/opal/nodes/iter.rb
CHANGED
data/lib/opal/nodes/literal.rb
CHANGED
@@ -41,7 +41,7 @@ module Opal
|
|
41
41
|
'e' => '\\u001b'
|
42
42
|
}.freeze
|
43
43
|
|
44
|
-
ESCAPE_REGEX = /(\\+)([#{ ESCAPE_CHARS.keys.join('') }])
|
44
|
+
ESCAPE_REGEX = /(\\+)([#{ ESCAPE_CHARS.keys.join('') }])/.freeze
|
45
45
|
|
46
46
|
def translate_escape_chars(inspect_string)
|
47
47
|
inspect_string.gsub(ESCAPE_REGEX) do |original|
|
@@ -55,8 +55,6 @@ module Opal
|
|
55
55
|
|
56
56
|
def compile
|
57
57
|
string_value = value
|
58
|
-
encoding = string_value.encoding
|
59
|
-
should_encode = encoding != Encoding::UTF_8
|
60
58
|
|
61
59
|
sanitized_value = string_value.inspect.gsub(/\\u\{([0-9a-f]+)\}/) do
|
62
60
|
code_point = Regexp.last_match(1).to_i(16)
|
@@ -64,8 +62,13 @@ module Opal
|
|
64
62
|
end
|
65
63
|
push translate_escape_chars(sanitized_value)
|
66
64
|
|
67
|
-
if
|
68
|
-
|
65
|
+
if RUBY_ENGINE != 'opal'
|
66
|
+
encoding = string_value.encoding
|
67
|
+
|
68
|
+
unless encoding == Encoding::UTF_8
|
69
|
+
helper :enc
|
70
|
+
wrap "$enc(", ", \"#{encoding.name}\")"
|
71
|
+
end
|
69
72
|
end
|
70
73
|
end
|
71
74
|
|
@@ -104,7 +107,7 @@ module Opal
|
|
104
107
|
attr_accessor :value, :flags
|
105
108
|
|
106
109
|
# https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp
|
107
|
-
SUPPORTED_FLAGS = /[gimuy]
|
110
|
+
SUPPORTED_FLAGS = /[gimuy]/.freeze
|
108
111
|
|
109
112
|
def initialize(*)
|
110
113
|
super
|
@@ -121,20 +124,22 @@ module Opal
|
|
121
124
|
end
|
122
125
|
end
|
123
126
|
|
124
|
-
|
125
|
-
when :dstr, :begin
|
126
|
-
compile_dynamic_regexp
|
127
|
-
when :str
|
127
|
+
if value.type == :str
|
128
128
|
compile_static_regexp
|
129
|
+
else
|
130
|
+
compile_dynamic_regexp
|
129
131
|
end
|
130
132
|
end
|
131
133
|
|
132
134
|
def compile_dynamic_regexp
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
push
|
135
|
+
push 'Opal.regexp(['
|
136
|
+
value.children.each_with_index do |v, index|
|
137
|
+
push ', ' unless index.zero?
|
138
|
+
push expr(v)
|
137
139
|
end
|
140
|
+
push ']'
|
141
|
+
push ", '#{flags.join}'" if flags.any?
|
142
|
+
push ")"
|
138
143
|
end
|
139
144
|
|
140
145
|
def compile_static_regexp
|
data/lib/opal/nodes/logic.rb
CHANGED
@@ -10,9 +10,10 @@ module Opal
|
|
10
10
|
def compile
|
11
11
|
if in_while?
|
12
12
|
push 'continue;'
|
13
|
+
elsif scope.iter?
|
14
|
+
push 'return ', expr_or_nil(value), ';'
|
13
15
|
else
|
14
|
-
|
15
|
-
wrap 'return ', ';'
|
16
|
+
error 'Invalid next'
|
16
17
|
end
|
17
18
|
end
|
18
19
|
|
@@ -85,6 +86,7 @@ module Opal
|
|
85
86
|
end
|
86
87
|
|
87
88
|
def compile_iter
|
89
|
+
helper :slice
|
88
90
|
push "return #{scope.identity}.apply(null, $slice.call(arguments))"
|
89
91
|
end
|
90
92
|
end
|
@@ -107,83 +109,6 @@ module Opal
|
|
107
109
|
end
|
108
110
|
end
|
109
111
|
|
110
|
-
class BinaryOp < Base
|
111
|
-
def compile
|
112
|
-
if rhs.type == :break
|
113
|
-
compile_if
|
114
|
-
else
|
115
|
-
compile_ternary
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
def compile_ternary
|
120
|
-
raise NotImplementedError
|
121
|
-
end
|
122
|
-
|
123
|
-
def compile_if
|
124
|
-
raise NotImplementedError
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
class OrNode < BinaryOp
|
129
|
-
handle :or
|
130
|
-
|
131
|
-
children :lhs, :rhs
|
132
|
-
|
133
|
-
def compile_ternary
|
134
|
-
helper :truthy
|
135
|
-
|
136
|
-
with_temp do |tmp|
|
137
|
-
push "($truthy(#{tmp} = ", expr(lhs), ") ? #{tmp} : ", expr(rhs), ')'
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
def compile_if
|
142
|
-
helper :truthy
|
143
|
-
|
144
|
-
with_temp do |tmp|
|
145
|
-
push "if ($truthy(#{tmp} = ", expr(lhs), ')) {'
|
146
|
-
indent { line tmp }
|
147
|
-
line '} else {'
|
148
|
-
indent { line expr(rhs) }
|
149
|
-
line '}'
|
150
|
-
end
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
class AndNode < BinaryOp
|
155
|
-
handle :and
|
156
|
-
|
157
|
-
children :lhs, :rhs
|
158
|
-
|
159
|
-
def compile_ternary
|
160
|
-
truthy_opt = nil
|
161
|
-
|
162
|
-
with_temp do |tmp|
|
163
|
-
if truthy_opt = js_truthy_optimize(lhs)
|
164
|
-
push "((#{tmp} = ", truthy_opt
|
165
|
-
push ') ? '
|
166
|
-
push expr(rhs)
|
167
|
-
push ' : ', expr(lhs), ')'
|
168
|
-
else
|
169
|
-
helper :truthy
|
170
|
-
|
171
|
-
push "($truthy(#{tmp} = ", expr(lhs), ') ? ', expr(rhs), " : #{tmp})"
|
172
|
-
end
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
def compile_if
|
177
|
-
helper :truthy
|
178
|
-
condition = js_truthy_optimize(lhs) || expr(lhs)
|
179
|
-
|
180
|
-
line 'if ($truthy(', condition, ')) {'
|
181
|
-
indent { line expr(rhs) }
|
182
|
-
line '} else {'
|
183
|
-
indent { line expr(lhs) }
|
184
|
-
line '}'
|
185
|
-
end
|
186
|
-
end
|
187
112
|
|
188
113
|
class ReturnNode < Base
|
189
114
|
handle :return
|
@@ -221,7 +146,7 @@ module Opal
|
|
221
146
|
elsif stmt?
|
222
147
|
push 'return ', return_val
|
223
148
|
else
|
224
|
-
|
149
|
+
error 'void value expression: cannot return as an expression'
|
225
150
|
end
|
226
151
|
end
|
227
152
|
end
|