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,112 @@
|
|
1
|
+
require 'lib/spec_helper'
|
2
|
+
require 'opal/config'
|
3
|
+
|
4
|
+
RSpec.describe Opal::Config do
|
5
|
+
before { described_class.reset! }
|
6
|
+
after { described_class.reset! }
|
7
|
+
|
8
|
+
describe '.default_config' do
|
9
|
+
it 'is new each time' do
|
10
|
+
default_config1 = described_class.default_config
|
11
|
+
default_config2 = described_class.default_config
|
12
|
+
expect(default_config1).to eq(default_config2)
|
13
|
+
expect(default_config1).not_to equal(default_config2)
|
14
|
+
described_class.default_config[:stubbed_files] << :foo
|
15
|
+
expect(described_class.default_config[:stubbed_files]).to eq(Set.new)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'has expected default values' do
|
20
|
+
expect(described_class.method_missing_enabled).to eq(true)
|
21
|
+
expect(described_class.const_missing_enabled).to eq(true)
|
22
|
+
expect(described_class.arity_check_enabled).to eq(false)
|
23
|
+
expect(described_class.freezing_stubs_enabled).to eq(true)
|
24
|
+
expect(described_class.dynamic_require_severity).to eq(:warning)
|
25
|
+
expect(described_class.missing_require_severity).to eq(:error)
|
26
|
+
expect(described_class.irb_enabled).to eq(false)
|
27
|
+
expect(described_class.inline_operators_enabled).to eq(true)
|
28
|
+
expect(described_class.source_map_enabled).to eq(true)
|
29
|
+
expect(described_class.stubbed_files).to eq(Set.new)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'raises an ArgumentError if provided with an unexpected value' do
|
33
|
+
expect{ described_class.method_missing_enabled = :foobar }.to raise_error(ArgumentError)
|
34
|
+
expect{ described_class.const_missing_enabled = :foobar }.to raise_error(ArgumentError)
|
35
|
+
expect{ described_class.arity_check_enabled = :foobar }.to raise_error(ArgumentError)
|
36
|
+
expect{ described_class.freezing_stubs_enabled = :foobar }.to raise_error(ArgumentError)
|
37
|
+
expect{ described_class.dynamic_require_severity = :foobar }.to raise_error(ArgumentError)
|
38
|
+
expect{ described_class.missing_require_severity = :foobar }.to raise_error(ArgumentError)
|
39
|
+
expect{ described_class.irb_enabled = :foobar }.to raise_error(ArgumentError)
|
40
|
+
expect{ described_class.inline_operators_enabled = :foobar }.to raise_error(ArgumentError)
|
41
|
+
expect{ described_class.source_map_enabled = :foobar }.to raise_error(ArgumentError)
|
42
|
+
expect{ described_class.stubbed_files = :foobar }.to raise_error(ArgumentError)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'does not raises errors if provided with an expected value' do
|
46
|
+
expect{ described_class.arity_check_enabled = false }.not_to raise_error
|
47
|
+
expect(described_class.arity_check_enabled).to eq(false)
|
48
|
+
|
49
|
+
expect{ described_class.arity_check_enabled = true }.not_to raise_error
|
50
|
+
expect(described_class.arity_check_enabled).to eq(true)
|
51
|
+
|
52
|
+
expect{ described_class.const_missing_enabled = false }.not_to raise_error
|
53
|
+
expect(described_class.const_missing_enabled).to eq(false)
|
54
|
+
|
55
|
+
expect{ described_class.const_missing_enabled = true }.not_to raise_error
|
56
|
+
expect(described_class.const_missing_enabled).to eq(true)
|
57
|
+
|
58
|
+
expect{ described_class.dynamic_require_severity = :error }.not_to raise_error
|
59
|
+
expect(described_class.dynamic_require_severity).to eq(:error)
|
60
|
+
|
61
|
+
expect{ described_class.dynamic_require_severity = :ignore }.not_to raise_error
|
62
|
+
expect(described_class.dynamic_require_severity).to eq(:ignore)
|
63
|
+
|
64
|
+
expect{ described_class.dynamic_require_severity = :warning }.not_to raise_error
|
65
|
+
expect(described_class.dynamic_require_severity).to eq(:warning)
|
66
|
+
|
67
|
+
expect{ described_class.missing_require_severity = :error }.not_to raise_error
|
68
|
+
expect(described_class.missing_require_severity).to eq(:error)
|
69
|
+
|
70
|
+
expect{ described_class.missing_require_severity = :ignore }.not_to raise_error
|
71
|
+
expect(described_class.missing_require_severity).to eq(:ignore)
|
72
|
+
|
73
|
+
expect{ described_class.missing_require_severity = :warning }.not_to raise_error
|
74
|
+
expect(described_class.missing_require_severity).to eq(:warning)
|
75
|
+
|
76
|
+
expect{ described_class.freezing_stubs_enabled = false }.not_to raise_error
|
77
|
+
expect(described_class.freezing_stubs_enabled).to eq(false)
|
78
|
+
|
79
|
+
expect{ described_class.freezing_stubs_enabled = true }.not_to raise_error
|
80
|
+
expect(described_class.freezing_stubs_enabled).to eq(true)
|
81
|
+
|
82
|
+
expect{ described_class.inline_operators_enabled = false }.not_to raise_error
|
83
|
+
expect(described_class.inline_operators_enabled).to eq(false)
|
84
|
+
|
85
|
+
expect{ described_class.inline_operators_enabled = true }.not_to raise_error
|
86
|
+
expect(described_class.inline_operators_enabled).to eq(true)
|
87
|
+
|
88
|
+
expect{ described_class.irb_enabled = false }.not_to raise_error
|
89
|
+
expect(described_class.irb_enabled).to eq(false)
|
90
|
+
|
91
|
+
expect{ described_class.irb_enabled = true }.not_to raise_error
|
92
|
+
expect(described_class.irb_enabled).to eq(true)
|
93
|
+
|
94
|
+
expect{ described_class.method_missing_enabled = false }.not_to raise_error
|
95
|
+
expect(described_class.method_missing_enabled).to eq(false)
|
96
|
+
|
97
|
+
expect{ described_class.method_missing_enabled = true }.not_to raise_error
|
98
|
+
expect(described_class.method_missing_enabled).to eq(true)
|
99
|
+
|
100
|
+
expect{ described_class.source_map_enabled = false }.not_to raise_error
|
101
|
+
expect(described_class.source_map_enabled).to eq(false)
|
102
|
+
|
103
|
+
expect{ described_class.source_map_enabled = true }.not_to raise_error
|
104
|
+
expect(described_class.source_map_enabled).to eq(true)
|
105
|
+
|
106
|
+
expect{ described_class.stubbed_files << 'foo' }.not_to raise_error
|
107
|
+
expect(described_class.stubbed_files).to eq(['foo'].to_set)
|
108
|
+
|
109
|
+
expect{ described_class.stubbed_files = %w[foo bar].to_set }.not_to raise_error
|
110
|
+
expect(described_class.stubbed_files).to eq(%w[foo bar].to_set)
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'lib/spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Opal::Nodes::CallNode::DependencyResolver do
|
4
|
+
let(:compiler) { double(:compiler, dynamic_require_severity: :warning) }
|
5
|
+
|
6
|
+
it "resolves simple strings to themselves" do
|
7
|
+
expect(resolve s(:str, 'foo')).to eq('foo')
|
8
|
+
end
|
9
|
+
|
10
|
+
context "using a dynamic segment not supported" do
|
11
|
+
it "raises a compiler error when severity is :error" do
|
12
|
+
compiler = double(:compiler, dynamic_require_severity: :error)
|
13
|
+
expect(compiler).to receive(:dynamic_require_severity).once
|
14
|
+
expect(compiler).not_to receive(:warning)
|
15
|
+
expect(compiler).to receive(:error).once
|
16
|
+
described_class.new(compiler, s(:self)).resolve
|
17
|
+
end
|
18
|
+
|
19
|
+
it "produces a compiler warning when severity is :warning" do
|
20
|
+
compiler = double(:compiler, dynamic_require_severity: :warning)
|
21
|
+
expect(compiler).to receive(:dynamic_require_severity).once
|
22
|
+
expect(compiler).to receive(:warning).once
|
23
|
+
expect(compiler).not_to receive(:error)
|
24
|
+
described_class.new(compiler, s(:self)).resolve
|
25
|
+
end
|
26
|
+
|
27
|
+
it "does not produce a warning when severity is :ignore" do
|
28
|
+
compiler = double(:compiler, dynamic_require_severity: :ignore)
|
29
|
+
expect(compiler).to receive(:dynamic_require_severity).once
|
30
|
+
expect(compiler).not_to receive(:warning)
|
31
|
+
expect(compiler).not_to receive(:error)
|
32
|
+
described_class.new(compiler, s(:self)).resolve
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def s(type, *children)
|
37
|
+
::Opal::AST::Node.new(type, children)
|
38
|
+
end
|
39
|
+
|
40
|
+
def resolve(sexp)
|
41
|
+
described_class.new(compiler, sexp).resolve
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'lib/spec_helper'
|
2
|
+
require 'opal/deprecations'
|
3
|
+
|
4
|
+
RSpec.describe Opal::Deprecations do
|
5
|
+
subject { Object.new.extend described_class }
|
6
|
+
|
7
|
+
it 'defaults to warn' do
|
8
|
+
expect(subject).to receive(:warn)
|
9
|
+
subject.deprecation "there's a new api!"
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'can be set to raise' do
|
13
|
+
subject.raise_on_deprecation = true
|
14
|
+
expect(subject).to receive(:raise)
|
15
|
+
subject.deprecation "there's a new api!"
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
#= require sprockets_file
|
@@ -0,0 +1 @@
|
|
1
|
+
puts 'hi there'
|
@@ -0,0 +1 @@
|
|
1
|
+
console.log('required file');
|
@@ -0,0 +1 @@
|
|
1
|
+
p 1
|
@@ -0,0 +1 @@
|
|
1
|
+
p 2
|
@@ -0,0 +1 @@
|
|
1
|
+
puts 'smap!'
|
@@ -0,0 +1 @@
|
|
1
|
+
puts 'other!'
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'lib/spec_helper'
|
2
|
+
require 'opal/path_reader'
|
3
|
+
|
4
|
+
RSpec.describe Opal::PathReader do
|
5
|
+
subject(:path_reader) { described_class.new }
|
6
|
+
let(:path) { 'opal_file' }
|
7
|
+
let(:full_path) { File.expand_path('../fixtures/opal_file.rb', __FILE__) }
|
8
|
+
let(:contents) { File.read(full_path, mode: "rb:UTF-8") }
|
9
|
+
|
10
|
+
before do
|
11
|
+
allow_any_instance_of(Opal::Hike::Trail).to receive(:find) {|path| nil}
|
12
|
+
allow_any_instance_of(Opal::Hike::Trail).to receive(:find).with(path).and_return(full_path)
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#paths' do
|
16
|
+
it 'is an Enumberable' do
|
17
|
+
expect(path_reader.paths).to be_an(Enumerable)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'includes Opal.paths' do
|
21
|
+
paths = path_reader.paths.to_a
|
22
|
+
Opal.paths.each { |path| expect(paths).to include(path) }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#read' do
|
27
|
+
it 'reads the contents from the path' do
|
28
|
+
expect(path_reader.read(path)).to eq(contents)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'returns nil if the file is missing' do
|
32
|
+
expect(path_reader.read('unexpected-path!')).to be_nil
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'works with absolute paths' do
|
37
|
+
expect(path_reader.read(File.expand_path(__FILE__))).not_to be_nil
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'works with relative paths starting with ./' do
|
41
|
+
expect(path_reader.read('./spec/lib/spec_helper.rb')).not_to be_nil
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'works with absolute paths' do
|
45
|
+
expect(path_reader.read("../#{File.basename(Dir.pwd)}/spec/lib/spec_helper.rb")).not_to be_nil
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'lib/spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe 'Opal.use_gem' do
|
4
|
+
# Coverage probably should be improved
|
5
|
+
|
6
|
+
it 'adds require_paths of a gem to Opal paths' do
|
7
|
+
begin
|
8
|
+
Opal.use_gem 'rake'
|
9
|
+
rescue Opal::GemNotFound => e
|
10
|
+
raise(e) unless e.gem_name == 'rake'
|
11
|
+
skip %(Will fail if GEM_HOME has "rake" in the path, that's ok)
|
12
|
+
end
|
13
|
+
|
14
|
+
added_rake_paths = Opal.paths.grep(/rake/)
|
15
|
+
expect(added_rake_paths.size).to eq(1)
|
16
|
+
expect(added_rake_paths.first).to match(%r{/rake-[\d\.]+/lib$})
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'lib/spec_helper'
|
2
|
+
require 'opal/repl'
|
3
|
+
|
4
|
+
RSpec.describe Opal::REPL, skip: RUBY_PLATFORM != 'ruby' do
|
5
|
+
describe '#eval_ruby' do
|
6
|
+
let(:input_and_output) { {
|
7
|
+
'puts 5' => "5\n=> nil\n",
|
8
|
+
'a = 1' => "=> 1\n",
|
9
|
+
'a += 1' => "=> 2\n",
|
10
|
+
'a + 3' => "=> 5\n",
|
11
|
+
'puts a + 3' => "5\n=> nil\n",
|
12
|
+
'"#{a} + 3"' => "=> \"2 + 3\"\n",
|
13
|
+
'puts "#{a} + 3"' => "2 + 3\n=> nil\n",
|
14
|
+
} }
|
15
|
+
|
16
|
+
subject(:repl) { described_class.new }
|
17
|
+
|
18
|
+
it 'evaluates user inputs' do
|
19
|
+
repl.load_opal
|
20
|
+
|
21
|
+
input_and_output.each do |input, output|
|
22
|
+
expect { repl.run_line(input) }.to output(output).to_stdout
|
23
|
+
end
|
24
|
+
|
25
|
+
repl.finish
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'lib/spec_helper'
|
2
|
+
require 'support/rewriters_helper'
|
3
|
+
require 'opal/rewriters/base'
|
4
|
+
|
5
|
+
RSpec.describe Opal::Rewriters::Base do
|
6
|
+
include RewritersHelper
|
7
|
+
|
8
|
+
def body_ast_of(method_source)
|
9
|
+
def_ast = parse_without_rewriting(method_source)
|
10
|
+
_, _, body_ast = *def_ast
|
11
|
+
body_ast
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:node) { ast_of('INJECTED') } # s(:const, nil, :INJECTED)
|
15
|
+
let(:rewriter) { described_class.new }
|
16
|
+
|
17
|
+
describe '#prepend_to_body' do
|
18
|
+
context 'for empty body' do
|
19
|
+
it 'replaces body with provided node' do
|
20
|
+
body = body_ast_of('def m(a); end')
|
21
|
+
rewritten = rewriter.prepend_to_body(body, node)
|
22
|
+
expect(rewritten).to eq(body_ast_of('def m; INJECTED; end'))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'for single-line body' do
|
27
|
+
it 'prepends a node to the body and wraps it with begin; end' do
|
28
|
+
body = body_ast_of('def m; 1; end')
|
29
|
+
rewritten = rewriter.prepend_to_body(body, node)
|
30
|
+
expect(rewritten).to eq(body_ast_of('def m; INJECTED; 1; end'))
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'for multi-line body' do
|
35
|
+
it 'prepends a node to the body' do
|
36
|
+
body = body_ast_of('def m(a); 1; 2; end')
|
37
|
+
rewritten = rewriter.prepend_to_body(body, node)
|
38
|
+
expect(rewritten).to eq(body_ast_of('def m; INJECTED; 1; 2; end'))
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '#append_to_body' do
|
44
|
+
context 'for empty body' do
|
45
|
+
it 'replaces body with provided node' do
|
46
|
+
body = body_ast_of('def m(a); end')
|
47
|
+
rewritten = rewriter.append_to_body(body, node)
|
48
|
+
expect(rewritten).to eq(body_ast_of('def m; INJECTED; end'))
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'for single-line body' do
|
53
|
+
it 'appends a node to the body and wraps it with begin; end' do
|
54
|
+
body = body_ast_of('def m(a); 1; end')
|
55
|
+
rewritten = rewriter.append_to_body(body, node)
|
56
|
+
expect(rewritten).to eq(body_ast_of('def m; 1; INJECTED; end'))
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'for multi-line body' do
|
61
|
+
it 'appends a node to the body' do
|
62
|
+
body = body_ast_of('def m(a); 1; 2; end')
|
63
|
+
rewritten = rewriter.append_to_body(body, node)
|
64
|
+
expect(rewritten).to eq(body_ast_of('def m; 1; 2; INJECTED; end'))
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,153 @@
|
|
1
|
+
require 'lib/spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Opal::Rewriters::BinaryOperatorAssignment do
|
4
|
+
def s(type, *children)
|
5
|
+
::Opal::AST::Node.new(type, children)
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:rewriter) { Opal::Rewriters::BinaryOperatorAssignment.new }
|
9
|
+
|
10
|
+
def parse(source)
|
11
|
+
parser = Opal::Parser.default_parser
|
12
|
+
buffer = ::Opal::Parser::SourceBuffer.new('(eval)')
|
13
|
+
buffer.source = source
|
14
|
+
parser.parse(buffer)
|
15
|
+
end
|
16
|
+
|
17
|
+
def rewrite(ast)
|
18
|
+
rewriter.process(ast)
|
19
|
+
end
|
20
|
+
|
21
|
+
around(:each) do |e|
|
22
|
+
Opal::Rewriters::BinaryOperatorAssignment.reset_tmp_counter!
|
23
|
+
Opal::Rewriter.disable { e.run }
|
24
|
+
end
|
25
|
+
let(:cache_tmp_name) { :$binary_op_recvr_tmp_1 }
|
26
|
+
let(:cached) { s(:js_tmp, cache_tmp_name) }
|
27
|
+
|
28
|
+
shared_examples 'it rewrites' do |from, to|
|
29
|
+
it "rewrites #{from.inspect} to #{to.inspect}" do
|
30
|
+
input = parse(from)
|
31
|
+
rewritten = rewrite(input)
|
32
|
+
expected = parse(to)
|
33
|
+
|
34
|
+
expect(rewritten).to eq(expected)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'rewriting or_asgn and and_asgn nodes' do
|
39
|
+
context 'local variable' do
|
40
|
+
include_examples 'it rewrites', 'a = 1; a += 2', 'a = 1; a = a + 2'
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'instance variable' do
|
44
|
+
include_examples 'it rewrites', '@a += 1', '@a = @a + 1'
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'constant' do
|
48
|
+
include_examples 'it rewrites', 'CONST += 1', 'CONST = CONST + 1'
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'global variable' do
|
52
|
+
include_examples 'it rewrites', '$g += 1', '$g = $g + 1'
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'class variable' do
|
56
|
+
include_examples 'it rewrites', '@@a += 1', '@@a = @@a + 1'
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'simple method call' do
|
60
|
+
include_examples 'it rewrites', 'recvr = 1; recvr.meth += rhs', 'recvr = 1; recvr.meth = recvr.meth + rhs'
|
61
|
+
end
|
62
|
+
|
63
|
+
context '[] / []= method call' do
|
64
|
+
include_examples 'it rewrites', 'recvr = 1; recvr[idx] += rhs', 'recvr = 1; recvr[idx] = recvr[idx] + rhs'
|
65
|
+
end
|
66
|
+
|
67
|
+
context '[] / []= method call with multiple arguments' do
|
68
|
+
include_examples 'it rewrites',
|
69
|
+
'recvr = 1; recvr[idx1, idx2] += rhs',
|
70
|
+
'recvr = 1; recvr[idx1, idx2] = recvr[idx1, idx2] + rhs'
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'chain of method calls' do
|
74
|
+
it 'rewrites += by caching receiver to a temporary local variable' do
|
75
|
+
input = parse('recvr.a.b += rhs')
|
76
|
+
rewritten = rewrite(input)
|
77
|
+
|
78
|
+
expected = s(:begin,
|
79
|
+
s(:lvasgn, cache_tmp_name, parse('recvr.a')), # cached = recvr.a
|
80
|
+
s(:send, cached, :b=,
|
81
|
+
s(:send,
|
82
|
+
s(:send, cached, :b),
|
83
|
+
:+,
|
84
|
+
parse('rhs'))))
|
85
|
+
|
86
|
+
expect(rewritten).to eq(expected)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context 'method call using safe nafigator' do
|
91
|
+
it 'rewrites += by caching receiver and rewriting it to if and or_asgn' do
|
92
|
+
input = parse('recvr&.meth += rhs')
|
93
|
+
rewritten = rewrite(input)
|
94
|
+
|
95
|
+
expected = s(:begin,
|
96
|
+
s(:lvasgn, cache_tmp_name, parse('recvr')), # cached = recvr
|
97
|
+
s(:if, s(:send, cached, :nil?), # if cached.nil?
|
98
|
+
s(:nil), # nil
|
99
|
+
# else
|
100
|
+
s(:send, cached, :meth=, # cached.meth =
|
101
|
+
s(:send,
|
102
|
+
s(:send, cached, :meth), # cached.meth +
|
103
|
+
:+,
|
104
|
+
parse('rhs'))) # rhs
|
105
|
+
)) # end
|
106
|
+
|
107
|
+
expect(rewritten).to eq(expected)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
context 'rewriting defined?(or_asgn) and defined?(and_asgn)' do
|
113
|
+
context 'local variable' do
|
114
|
+
include_examples 'it rewrites', 'a = nil; defined?(a += 1)', 'a = nil; "assignment"'
|
115
|
+
end
|
116
|
+
|
117
|
+
context 'instance variable' do
|
118
|
+
include_examples 'it rewrites', 'defined?(@a += 1)', %q("assignment")
|
119
|
+
end
|
120
|
+
|
121
|
+
context 'constant' do
|
122
|
+
include_examples 'it rewrites', 'defined?(CONST += 1)', %q("assignment")
|
123
|
+
end
|
124
|
+
|
125
|
+
context 'global variable' do
|
126
|
+
include_examples 'it rewrites', 'defined?($g += 1)', %q("assignment")
|
127
|
+
end
|
128
|
+
|
129
|
+
context 'class variable' do
|
130
|
+
include_examples 'it rewrites', 'defined?(@@a += 1)', %q("assignment")
|
131
|
+
end
|
132
|
+
|
133
|
+
context 'simple method call' do
|
134
|
+
include_examples 'it rewrites', 'defined?(recvr.meth += rhs)', %q("assignment")
|
135
|
+
end
|
136
|
+
|
137
|
+
context '[] / []= method call' do
|
138
|
+
include_examples 'it rewrites', 'defined?(recvr[idx] += rhs)', %q("assignment")
|
139
|
+
end
|
140
|
+
|
141
|
+
context '[] / []= method call with multiple arguments' do
|
142
|
+
include_examples 'it rewrites', 'defined?(recvr[idx1, idx2] += rhs)', %q("assignment")
|
143
|
+
end
|
144
|
+
|
145
|
+
context 'chain of method calls' do
|
146
|
+
include_examples 'it rewrites', 'defined?(recvr.a.b.c += rhs)', %q("assignment")
|
147
|
+
end
|
148
|
+
|
149
|
+
context 'method call using safe nafigator' do
|
150
|
+
include_examples 'it rewrites', 'defined?(recvr&.meth += rhs)', %q("assignment")
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|