opal-cj 0.7.0.beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.gitmodules +27 -0
- data/.rspec +3 -0
- data/.spectator +2 -0
- data/.spectator-mspec +3 -0
- data/.travis.yml +45 -0
- data/CHANGELOG.md +406 -0
- data/CONTRIBUTING.md +41 -0
- data/Gemfile +27 -0
- data/Guardfile +77 -0
- data/LICENSE +19 -0
- data/README.md +178 -0
- data/Rakefile +116 -0
- data/benchmarks/operators.rb +11 -0
- data/bin/opal +22 -0
- data/bin/opal-build +77 -0
- data/bin/opal-mspec +10 -0
- data/bin/opal-repl +72 -0
- data/config.ru +14 -0
- data/examples/rack/Gemfile +3 -0
- data/examples/rack/app/application.rb +13 -0
- data/examples/rack/app/user.rb +21 -0
- data/examples/rack/config.ru +7 -0
- data/examples/rack/index.html.erb +10 -0
- data/examples/sinatra/Gemfile +4 -0
- data/examples/sinatra/app/application.rb +7 -0
- data/examples/sinatra/config.ru +28 -0
- data/lib/mspec/opal/main.rb.erb +9 -0
- data/lib/mspec/opal/rake_task.rb +278 -0
- data/lib/mspec/opal/runner.rb +206 -0
- data/lib/mspec/opal/sprockets.js +57 -0
- data/lib/opal.rb +11 -0
- data/lib/opal/builder.rb +135 -0
- data/lib/opal/builder_processors.rb +165 -0
- data/lib/opal/cli.rb +145 -0
- data/lib/opal/cli_options.rb +149 -0
- data/lib/opal/cli_runners.rb +10 -0
- data/lib/opal/cli_runners/nodejs.rb +56 -0
- data/lib/opal/cli_runners/phantom.js +35 -0
- data/lib/opal/cli_runners/phantomjs.rb +28 -0
- data/lib/opal/cli_runners/server.rb +54 -0
- data/lib/opal/compiler.rb +307 -0
- data/lib/opal/erb.rb +64 -0
- data/lib/opal/fragment.rb +41 -0
- data/lib/opal/hike_path_finder.rb +18 -0
- data/lib/opal/nodes.rb +26 -0
- data/lib/opal/nodes/arglist.rb +56 -0
- data/lib/opal/nodes/array.rb +54 -0
- data/lib/opal/nodes/base.rb +151 -0
- data/lib/opal/nodes/call.rb +283 -0
- data/lib/opal/nodes/call_special.rb +178 -0
- data/lib/opal/nodes/case.rb +96 -0
- data/lib/opal/nodes/class.rb +42 -0
- data/lib/opal/nodes/constants.rb +78 -0
- data/lib/opal/nodes/def.rb +157 -0
- data/lib/opal/nodes/defined.rb +113 -0
- data/lib/opal/nodes/definitions.rb +168 -0
- data/lib/opal/nodes/for.rb +35 -0
- data/lib/opal/nodes/hash.rb +67 -0
- data/lib/opal/nodes/helpers.rb +114 -0
- data/lib/opal/nodes/if.rb +67 -0
- data/lib/opal/nodes/iter.rb +131 -0
- data/lib/opal/nodes/literal.rb +230 -0
- data/lib/opal/nodes/logic.rb +217 -0
- data/lib/opal/nodes/masgn.rb +62 -0
- data/lib/opal/nodes/module.rb +46 -0
- data/lib/opal/nodes/rescue.rb +135 -0
- data/lib/opal/nodes/runtime_helpers.rb +45 -0
- data/lib/opal/nodes/scope.rb +293 -0
- data/lib/opal/nodes/singleton_class.rb +25 -0
- data/lib/opal/nodes/super.rb +97 -0
- data/lib/opal/nodes/top.rb +101 -0
- data/lib/opal/nodes/variables.rb +158 -0
- data/lib/opal/nodes/while.rb +65 -0
- data/lib/opal/nodes/yield.rb +95 -0
- data/lib/opal/parser.rb +658 -0
- data/lib/opal/parser/grammar.rb +5452 -0
- data/lib/opal/parser/grammar.y +1684 -0
- data/lib/opal/parser/keywords.rb +66 -0
- data/lib/opal/parser/lexer.rb +1208 -0
- data/lib/opal/parser/parser_scope.rb +25 -0
- data/lib/opal/parser/sexp.rb +75 -0
- data/lib/opal/path_reader.rb +28 -0
- data/lib/opal/paths.rb +38 -0
- data/lib/opal/source_map.rb +70 -0
- data/lib/opal/sprockets.rb +4 -0
- data/lib/opal/sprockets/cache_key_fix.rb +17 -0
- data/lib/opal/sprockets/environment.rb +37 -0
- data/lib/opal/sprockets/erb.rb +37 -0
- data/lib/opal/sprockets/path_reader.rb +34 -0
- data/lib/opal/sprockets/processor.rb +124 -0
- data/lib/opal/sprockets/server.rb +180 -0
- data/lib/opal/util.rb +64 -0
- data/lib/opal/version.rb +3 -0
- data/opal.gemspec +36 -0
- data/opal/README.md +6 -0
- data/opal/corelib/array.rb +1556 -0
- data/opal/corelib/array/inheritance.rb +113 -0
- data/opal/corelib/basic_object.rb +73 -0
- data/opal/corelib/boolean.rb +41 -0
- data/opal/corelib/class.rb +55 -0
- data/opal/corelib/comparable.rb +56 -0
- data/opal/corelib/complex.rb +3 -0
- data/opal/corelib/dir.rb +20 -0
- data/opal/corelib/enumerable.rb +1132 -0
- data/opal/corelib/enumerator.rb +422 -0
- data/opal/corelib/error.rb +63 -0
- data/opal/corelib/file.rb +56 -0
- data/opal/corelib/hash.rb +728 -0
- data/opal/corelib/helpers.rb +102 -0
- data/opal/corelib/io.rb +59 -0
- data/opal/corelib/kernel.rb +569 -0
- data/opal/corelib/main.rb +7 -0
- data/opal/corelib/match_data.rb +114 -0
- data/opal/corelib/method.rb +58 -0
- data/opal/corelib/module.rb +462 -0
- data/opal/corelib/nil_class.rb +62 -0
- data/opal/corelib/numeric.rb +532 -0
- data/opal/corelib/proc.rb +52 -0
- data/opal/corelib/range.rb +116 -0
- data/opal/corelib/rational.rb +3 -0
- data/opal/corelib/regexp.rb +133 -0
- data/opal/corelib/runtime.js +1240 -0
- data/opal/corelib/string.rb +1212 -0
- data/opal/corelib/string/inheritance.rb +78 -0
- data/opal/corelib/struct.rb +141 -0
- data/opal/corelib/time.rb +584 -0
- data/opal/corelib/variables.rb +24 -0
- data/opal/opal.rb +32 -0
- data/package.json +9 -0
- data/spec/filters/bugs/array.rb +232 -0
- data/spec/filters/bugs/basic_object.rb +14 -0
- data/spec/filters/bugs/class.rb +21 -0
- data/spec/filters/bugs/enumerable.rb +69 -0
- data/spec/filters/bugs/enumerator.rb +3 -0
- data/spec/filters/bugs/hash.rb +128 -0
- data/spec/filters/bugs/kernel.rb +10 -0
- data/spec/filters/bugs/language.rb +415 -0
- data/spec/filters/bugs/math.rb +95 -0
- data/spec/filters/bugs/module.rb +14 -0
- data/spec/filters/bugs/nil.rb +7 -0
- data/spec/filters/bugs/numeric.rb +20 -0
- data/spec/filters/bugs/opal.rb +14 -0
- data/spec/filters/bugs/regexp.rb +11 -0
- data/spec/filters/bugs/set.rb +7 -0
- data/spec/filters/bugs/singleton.rb +6 -0
- data/spec/filters/bugs/string.rb +360 -0
- data/spec/filters/bugs/stringscanner.rb +22 -0
- data/spec/filters/bugs/struct.rb +45 -0
- data/spec/filters/bugs/time.rb +177 -0
- data/spec/filters/bugs/unknown.rb +11 -0
- data/spec/filters/unsupported/encoding.rb +95 -0
- data/spec/filters/unsupported/enumerator.rb +14 -0
- data/spec/filters/unsupported/float.rb +5 -0
- data/spec/filters/unsupported/frozen.rb +90 -0
- data/spec/filters/unsupported/hash_compare_by_identity.rb +16 -0
- data/spec/filters/unsupported/integer_size.rb +7 -0
- data/spec/filters/unsupported/method_added.rb +10 -0
- data/spec/filters/unsupported/mutable_strings.rb +361 -0
- data/spec/filters/unsupported/private_constants.rb +30 -0
- data/spec/filters/unsupported/private_methods.rb +44 -0
- data/spec/filters/unsupported/random.rb +4 -0
- data/spec/filters/unsupported/ruby_exe.rb +5 -0
- data/spec/filters/unsupported/tainted.rb +155 -0
- data/spec/filters/unsupported/time.rb +21 -0
- data/spec/filters/unsupported/trusted.rb +80 -0
- data/spec/lib/builder_processors_spec.rb +27 -0
- data/spec/lib/builder_spec.rb +66 -0
- data/spec/lib/cli_spec.rb +134 -0
- data/spec/lib/compiler_spec.rb +197 -0
- data/spec/lib/dependency_resolver_spec.rb +40 -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_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/sprockets_file.js.rb +3 -0
- data/spec/lib/fixtures/sprockets_require_tree_test.rb +3 -0
- data/spec/lib/hike_path_finder_spec.rb +23 -0
- data/spec/lib/lexer_spec.rb +110 -0
- data/spec/lib/parser/alias_spec.rb +26 -0
- data/spec/lib/parser/and_spec.rb +13 -0
- data/spec/lib/parser/attrasgn_spec.rb +28 -0
- data/spec/lib/parser/begin_spec.rb +42 -0
- data/spec/lib/parser/block_spec.rb +12 -0
- data/spec/lib/parser/break_spec.rb +17 -0
- data/spec/lib/parser/call_spec.rb +139 -0
- data/spec/lib/parser/class_spec.rb +35 -0
- data/spec/lib/parser/comments_spec.rb +11 -0
- data/spec/lib/parser/def_spec.rb +61 -0
- data/spec/lib/parser/if_spec.rb +26 -0
- data/spec/lib/parser/iter_spec.rb +59 -0
- data/spec/lib/parser/lambda_spec.rb +64 -0
- data/spec/lib/parser/literal_spec.rb +118 -0
- data/spec/lib/parser/masgn_spec.rb +37 -0
- data/spec/lib/parser/module_spec.rb +27 -0
- data/spec/lib/parser/not_spec.rb +27 -0
- data/spec/lib/parser/op_asgn1_spec.rb +23 -0
- data/spec/lib/parser/op_asgn2_spec.rb +23 -0
- data/spec/lib/parser/or_spec.rb +13 -0
- data/spec/lib/parser/return_spec.rb +17 -0
- data/spec/lib/parser/sclass_spec.rb +21 -0
- data/spec/lib/parser/string_spec.rb +276 -0
- data/spec/lib/parser/super_spec.rb +20 -0
- data/spec/lib/parser/unary_spec.rb +48 -0
- data/spec/lib/parser/undef_spec.rb +15 -0
- data/spec/lib/parser/unless_spec.rb +13 -0
- data/spec/lib/parser/variables_spec.rb +92 -0
- data/spec/lib/parser/while_spec.rb +15 -0
- data/spec/lib/parser/yield_spec.rb +20 -0
- data/spec/lib/path_reader_spec.rb +24 -0
- data/spec/lib/shared/path_finder_shared.rb +19 -0
- data/spec/lib/shared/path_reader_shared.rb +31 -0
- data/spec/lib/spec_helper.rb +9 -0
- data/spec/lib/sprockets/environment_spec.rb +30 -0
- data/spec/lib/sprockets/erb_spec.rb +25 -0
- data/spec/lib/sprockets/path_reader_spec.rb +25 -0
- data/spec/lib/sprockets/processor_spec.rb +35 -0
- data/spec/lib/sprockets/server_spec.rb +20 -0
- data/spec/opal/compiler/irb_spec.rb +44 -0
- data/spec/opal/core/array/select_spec.rb +14 -0
- data/spec/opal/core/array/set_range_to_array_spec.rb +7 -0
- data/spec/opal/core/date_spec.rb +122 -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.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/fixtures/class.rb +124 -0
- data/spec/opal/core/fixtures/class_variables.rb +0 -0
- data/spec/opal/core/fixtures/constants.rb +33 -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/kernel/Array_spec.rb +10 -0
- data/spec/opal/core/kernel/block_given_spec.rb +30 -0
- data/spec/opal/core/kernel/class_spec.rb +6 -0
- data/spec/opal/core/kernel/define_singleton_method_spec.rb +21 -0
- data/spec/opal/core/kernel/equal_value_spec.rb +12 -0
- data/spec/opal/core/kernel/extend_spec.rb +21 -0
- data/spec/opal/core/kernel/format_spec.rb +122 -0
- data/spec/opal/core/kernel/freeze_spec.rb +15 -0
- data/spec/opal/core/kernel/instance_eval_spec.rb +28 -0
- data/spec/opal/core/kernel/instance_variable_defined_spec.rb +15 -0
- data/spec/opal/core/kernel/instance_variable_get_spec.rb +14 -0
- data/spec/opal/core/kernel/instance_variable_set_spec.rb +10 -0
- data/spec/opal/core/kernel/loop_spec.rb +23 -0
- data/spec/opal/core/kernel/match_spec.rb +5 -0
- data/spec/opal/core/kernel/method_spec.rb +31 -0
- data/spec/opal/core/kernel/methods_spec.rb +25 -0
- data/spec/opal/core/kernel/nil_spec.rb +7 -0
- data/spec/opal/core/kernel/p_spec.rb +15 -0
- data/spec/opal/core/kernel/printf_spec.rb +11 -0
- data/spec/opal/core/kernel/proc_spec.rb +13 -0
- data/spec/opal/core/kernel/rand_spec.rb +23 -0
- data/spec/opal/core/kernel/require_tree_spec.rb +7 -0
- data/spec/opal/core/kernel/respond_to_spec.rb +41 -0
- data/spec/opal/core/kernel/send_spec.rb +56 -0
- data/spec/opal/core/kernel/sprintf_spec.rb +5 -0
- data/spec/opal/core/language/block_spec.rb +538 -0
- data/spec/opal/core/language/fixtures/array.rb +11 -0
- data/spec/opal/core/language/fixtures/block.rb +57 -0
- data/spec/opal/core/language/fixtures/break.rb +240 -0
- data/spec/opal/core/language/fixtures/ensure.rb +72 -0
- data/spec/opal/core/language/fixtures/literal_lambda.rb +7 -0
- data/spec/opal/core/language/fixtures/metaclass.rb +33 -0
- data/spec/opal/core/language/fixtures/module.rb +24 -0
- data/spec/opal/core/language/fixtures/next.rb +128 -0
- data/spec/opal/core/language/fixtures/return.rb +118 -0
- data/spec/opal/core/language/fixtures/send.rb +110 -0
- data/spec/opal/core/language/fixtures/send_1.9.rb +22 -0
- data/spec/opal/core/language/fixtures/super.rb +308 -0
- data/spec/opal/core/language/fixtures/variables.rb +58 -0
- data/spec/opal/core/language/fixtures/yield.rb +28 -0
- data/spec/opal/core/language/predefined_spec.rb +85 -0
- data/spec/opal/core/language/proc_spec.rb +263 -0
- data/spec/opal/core/language/regexp_spec.rb +20 -0
- data/spec/opal/core/language/send_spec.rb +225 -0
- data/spec/opal/core/language/string_spec.rb +44 -0
- data/spec/opal/core/language/symbol_spec.rb +40 -0
- data/spec/opal/core/language/variables_spec.rb +1366 -0
- data/spec/opal/core/language/versions/array_1.9.rb +39 -0
- data/spec/opal/core/language/versions/block_1.9.rb +0 -0
- data/spec/opal/core/language/versions/break_1.9.rb +0 -0
- data/spec/opal/core/language/versions/case_1.9.rb +20 -0
- data/spec/opal/core/language/versions/hash_1.9.rb +18 -0
- data/spec/opal/core/language/versions/literal_lambda_1.9.rb +143 -0
- data/spec/opal/core/language/versions/not_1.9.rb +22 -0
- data/spec/opal/core/language/versions/send_1.9.rb +241 -0
- data/spec/opal/core/language/versions/symbol_1.9.rb +15 -0
- data/spec/opal/core/language/versions/variables_1.9.rb +8 -0
- data/spec/opal/core/module/alias_method_spec.rb +28 -0
- data/spec/opal/core/module/ancestors_spec.rb +11 -0
- data/spec/opal/core/module/append_features_spec.rb +14 -0
- data/spec/opal/core/module/attr_accessor_spec.rb +26 -0
- data/spec/opal/core/module/const_defined_spec.rb +85 -0
- data/spec/opal/core/module/const_get_spec.rb +85 -0
- data/spec/opal/core/module/const_missing_spec.rb +17 -0
- data/spec/opal/core/module/const_set_spec.rb +64 -0
- data/spec/opal/core/module/constants_spec.rb +49 -0
- data/spec/opal/core/module/fixtures/classes.rb +434 -0
- data/spec/opal/core/module/method_defined_spec.rb +48 -0
- data/spec/opal/core/module/module_function_spec.rb +25 -0
- data/spec/opal/core/module/name_spec.rb +52 -0
- data/spec/opal/core/module/public_method_defined_spec.rb +18 -0
- data/spec/opal/core/module/remove_const_spec.rb +22 -0
- data/spec/opal/core/module/undef_method_spec.rb +66 -0
- data/spec/opal/core/numeric/bit_and_spec.rb +7 -0
- data/spec/opal/core/numeric/bit_or_spec.rb +8 -0
- data/spec/opal/core/numeric/bit_xor_spec.rb +6 -0
- data/spec/opal/core/numeric/ceil_spec.rb +8 -0
- data/spec/opal/core/numeric/chr_spec.rb +8 -0
- data/spec/opal/core/numeric/comparison_spec.rb +24 -0
- data/spec/opal/core/numeric/complement_spec.rb +8 -0
- data/spec/opal/core/numeric/divide_spec.rb +10 -0
- data/spec/opal/core/numeric/eql_spec.rb +9 -0
- data/spec/opal/core/numeric/exponent_spec.rb +33 -0
- data/spec/opal/core/numeric/floor_spec.rb +8 -0
- data/spec/opal/core/numeric/gt_spec.rb +11 -0
- data/spec/opal/core/numeric/gte_spec.rb +12 -0
- data/spec/opal/core/numeric/integer_spec.rb +9 -0
- data/spec/opal/core/numeric/left_shift_spec.rb +21 -0
- data/spec/opal/core/numeric/lt_spec.rb +11 -0
- data/spec/opal/core/numeric/lte_spec.rb +12 -0
- data/spec/opal/core/numeric/minus_spec.rb +8 -0
- data/spec/opal/core/numeric/modulo_spec.rb +19 -0
- data/spec/opal/core/numeric/multiply_spec.rb +9 -0
- data/spec/opal/core/numeric/next_spec.rb +9 -0
- data/spec/opal/core/numeric/ord_spec.rb +9 -0
- data/spec/opal/core/numeric/plus_spec.rb +8 -0
- data/spec/opal/core/numeric/pred_spec.rb +7 -0
- data/spec/opal/core/numeric/right_shift_spec.rb +25 -0
- data/spec/opal/core/numeric/step_spec.rb +11 -0
- data/spec/opal/core/numeric/succ_spec.rb +9 -0
- data/spec/opal/core/numeric/times_spec.rb +36 -0
- data/spec/opal/core/numeric/to_f_spec.rb +7 -0
- data/spec/opal/core/numeric/to_i_spec.rb +7 -0
- data/spec/opal/core/numeric/to_json_spec.rb +8 -0
- data/spec/opal/core/numeric/to_s_spec.rb +26 -0
- data/spec/opal/core/numeric/uminus_spec.rb +9 -0
- data/spec/opal/core/numeric/upto_spec.rb +19 -0
- data/spec/opal/core/numeric/zero_spec.rb +7 -0
- data/spec/opal/core/proc/call_spec.rb +21 -0
- data/spec/opal/core/proc/element_reference_spec.rb +21 -0
- data/spec/opal/core/proc/proc_tricks_spec.rb +7 -0
- data/spec/opal/core/runtime/begin_spec.rb +39 -0
- data/spec/opal/core/runtime/block_send_spec.rb +28 -0
- data/spec/opal/core/runtime/block_spec.rb +23 -0
- data/spec/opal/core/runtime/bridged_classes_spec.rb +64 -0
- data/spec/opal/core/runtime/constants_spec.rb +13 -0
- data/spec/opal/core/runtime/eval_spec.rb +5 -0
- data/spec/opal/core/runtime/main_methods_spec.rb +27 -0
- data/spec/opal/core/runtime/method_missing_spec.rb +62 -0
- data/spec/opal/core/runtime/method_spec.rb +31 -0
- data/spec/opal/core/runtime/operator_call_spec.rb +13 -0
- data/spec/opal/core/runtime/paren_spec.rb +14 -0
- data/spec/opal/core/runtime/rescue_spec.rb +38 -0
- data/spec/opal/core/runtime/return_spec.rb +38 -0
- data/spec/opal/core/runtime/send_spec.rb +34 -0
- data/spec/opal/core/runtime/singleton_class_spec.rb +13 -0
- data/spec/opal/core/runtime/super_spec.rb +212 -0
- data/spec/opal/core/runtime/truthy_spec.rb +23 -0
- data/spec/opal/core/runtime/variables_spec.rb +20 -0
- data/spec/opal/core/source_map_spec.rb +15 -0
- data/spec/opal/core/string_spec.rb +11 -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/json/ext_spec.rb +48 -0
- data/spec/opal/stdlib/json/parse_spec.rb +33 -0
- data/spec/opal/stdlib/native/alias_native_spec.rb +27 -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/initialize_spec.rb +17 -0
- data/spec/opal/stdlib/native/method_missing_spec.rb +51 -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 +8 -0
- data/spec/opal/stdlib/promise/error_spec.rb +15 -0
- data/spec/opal/stdlib/promise/rescue_spec.rb +35 -0
- data/spec/opal/stdlib/promise/then_spec.rb +54 -0
- data/spec/opal/stdlib/promise/trace_spec.rb +35 -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/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/rubyspecs +329 -0
- data/spec/spec_helper.rb +42 -0
- data/spec/support/mspec_rspec_adapter.rb +33 -0
- data/spec/support/parser_helpers.rb +37 -0
- data/stdlib/README.md +3 -0
- data/stdlib/base64.rb +152 -0
- data/stdlib/benchmark.rb +10 -0
- data/stdlib/buffer.rb +40 -0
- data/stdlib/buffer/array.rb +66 -0
- data/stdlib/buffer/view.rb +70 -0
- data/stdlib/date.rb +170 -0
- data/stdlib/delegate.rb +29 -0
- data/stdlib/dir.rb +1 -0
- data/stdlib/encoding.rb +166 -0
- data/stdlib/enumerator.rb +1 -0
- data/stdlib/erb.rb +16 -0
- data/stdlib/file.rb +1 -0
- data/stdlib/forwardable.rb +71 -0
- data/stdlib/json.rb +182 -0
- data/stdlib/math.rb +370 -0
- data/stdlib/native.rb +530 -0
- data/stdlib/nodejs.rb +5 -0
- data/stdlib/nodejs/dir.rb +13 -0
- data/stdlib/nodejs/file.rb +98 -0
- data/stdlib/nodejs/fileutils.rb +26 -0
- data/stdlib/nodejs/io.rb +2 -0
- data/stdlib/nodejs/irb.rb +45 -0
- data/stdlib/nodejs/process.rb +16 -0
- data/stdlib/nodejs/require.rb +32 -0
- data/stdlib/nodejs/rubygems.rb +68 -0
- data/stdlib/nodejs/runtime.rb +25 -0
- data/stdlib/nodejs/yaml.rb +11 -0
- data/stdlib/observer.rb +202 -0
- data/stdlib/opal-parser.rb +53 -0
- data/stdlib/opal-source-maps.rb +2 -0
- data/stdlib/ostruct.rb +69 -0
- data/stdlib/pathname.rb +31 -0
- data/stdlib/phantomjs.rb +8 -0
- data/stdlib/pp.rb +12 -0
- data/stdlib/process.rb +10 -0
- data/stdlib/promise.rb +300 -0
- data/stdlib/racc/parser.rb +215 -0
- data/stdlib/rbconfig.rb +20 -0
- data/stdlib/securerandom.rb +12 -0
- data/stdlib/set.rb +116 -0
- data/stdlib/singleton.rb +40 -0
- data/stdlib/source_map.rb +5 -0
- data/stdlib/source_map/map.rb +220 -0
- data/stdlib/source_map/mapping.rb +26 -0
- data/stdlib/source_map/offset.rb +88 -0
- data/stdlib/source_map/version.rb +3 -0
- data/stdlib/source_map/vlq.rb +98 -0
- data/stdlib/sourcemap.rb +1 -0
- data/stdlib/stringio.rb +181 -0
- data/stdlib/strscan.rb +155 -0
- data/stdlib/template.rb +46 -0
- data/stdlib/thread.rb +160 -0
- data/stdlib/time.rb +9 -0
- data/tasks/github.rake +19 -0
- metadata +690 -0
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
class OSpecFilter
|
|
2
|
+
def self.main
|
|
3
|
+
@main ||= self.new
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
def initialize
|
|
7
|
+
@filters = Set.new
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def register
|
|
11
|
+
MSpec.register :exclude, self
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def ===(description)
|
|
15
|
+
@filters.include? description
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def register_filters(description, block)
|
|
19
|
+
instance_eval(&block)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def fails(description)
|
|
23
|
+
@filters << description
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
class Object
|
|
28
|
+
def opal_filter(description, &block)
|
|
29
|
+
OSpecFilter.main.register_filters(description, block)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
class BrowserFormatter
|
|
34
|
+
def initialize(out=nil)
|
|
35
|
+
@exception = @failure = false
|
|
36
|
+
@exceptions = []
|
|
37
|
+
@count = 0
|
|
38
|
+
@examples = 0
|
|
39
|
+
|
|
40
|
+
@current_state = nil
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def register
|
|
44
|
+
MSpec.register :exception, self
|
|
45
|
+
MSpec.register :before, self
|
|
46
|
+
MSpec.register :after, self
|
|
47
|
+
MSpec.register :start, self
|
|
48
|
+
MSpec.register :finish, self
|
|
49
|
+
MSpec.register :abort, self
|
|
50
|
+
MSpec.register :enter, self
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def green(str)
|
|
54
|
+
`console.info(str)`
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def red(str)
|
|
58
|
+
`console.error(str)`
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def log(str)
|
|
62
|
+
`console.log(str)`
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def exception?
|
|
66
|
+
@exception
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def failure?
|
|
70
|
+
@failure
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def enter(describe); end
|
|
74
|
+
|
|
75
|
+
def before(state=nil)
|
|
76
|
+
@current_state = nil
|
|
77
|
+
@failure = @exception = false
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def exception(exception)
|
|
81
|
+
@count += 1
|
|
82
|
+
@failure = @exception ? @failure && exception.failure? : exception.failure?
|
|
83
|
+
@exception = true
|
|
84
|
+
@exceptions << exception
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def after(state = nil)
|
|
88
|
+
@current_state = nil
|
|
89
|
+
@examples += 1
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def start
|
|
93
|
+
@start_time = Time.now.to_f
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def finish
|
|
97
|
+
time = Time.now.to_f - @start_time
|
|
98
|
+
|
|
99
|
+
if @exceptions.empty?
|
|
100
|
+
log "\nFinished"
|
|
101
|
+
green "#{@examples} examples, #{@count} failures (time taken: #{time})"
|
|
102
|
+
|
|
103
|
+
finish_with_code 0
|
|
104
|
+
else
|
|
105
|
+
log "\nFailures:"
|
|
106
|
+
|
|
107
|
+
@exceptions.each_with_index do |exception, idx|
|
|
108
|
+
log "\n #{idx + 1}. #{exception.description}"
|
|
109
|
+
red "\n #{exception.message}"
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
log "\nFinished"
|
|
113
|
+
red "#{@examples} examples, #{@count} failures (time taken: #{time})"
|
|
114
|
+
|
|
115
|
+
finish_with_code(1)
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def finish_with_code(code)
|
|
120
|
+
`window.OPAL_SPEC_CODE = code;`
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
class PhantomFormatter < BrowserFormatter
|
|
125
|
+
def green(str)
|
|
126
|
+
`console.log('\033[32m' + str + '\033[0m')`
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def red(str)
|
|
130
|
+
`console.log('\033[31m' + str + '\033[0m')`
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def log(str)
|
|
134
|
+
`console.log(str)`
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def after(state)
|
|
138
|
+
super
|
|
139
|
+
unless exception?
|
|
140
|
+
print '.'
|
|
141
|
+
else
|
|
142
|
+
print failure? ? 'F' : 'E'
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
class PhantomDebugFormatter < PhantomFormatter
|
|
148
|
+
def after(state = nil)
|
|
149
|
+
(@exception && state) ? red(state.description) : green(state.description)
|
|
150
|
+
super
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
module MSpec
|
|
155
|
+
def self.opal_runner
|
|
156
|
+
@env = Object.new
|
|
157
|
+
@env.extend MSpec
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
class OSpecRunner
|
|
162
|
+
def self.main(formatter_class = BrowserFormatter)
|
|
163
|
+
@main ||= self.new formatter_class
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
def initialize(formatter_class)
|
|
167
|
+
@formatter_class = formatter_class
|
|
168
|
+
register
|
|
169
|
+
run
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
def register
|
|
173
|
+
formatter = @formatter_class.new
|
|
174
|
+
formatter.register
|
|
175
|
+
|
|
176
|
+
OSpecFilter.main.register
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
def run
|
|
180
|
+
MSpec.opal_runner
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
def will_start
|
|
184
|
+
MSpec.actions :start
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
def did_finish
|
|
188
|
+
MSpec.actions :finish
|
|
189
|
+
end
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
module OutputSilencer
|
|
193
|
+
def silence_stdout
|
|
194
|
+
original_stdout = $stdout
|
|
195
|
+
new_stdout = IO.new
|
|
196
|
+
new_stdout.extend IO::Writable
|
|
197
|
+
new_stdout.write_proc = ->s{}
|
|
198
|
+
|
|
199
|
+
begin
|
|
200
|
+
$stdout = new_stdout
|
|
201
|
+
yield
|
|
202
|
+
ensure
|
|
203
|
+
$stdout = original_stdout
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Test runner for phantomjs
|
|
3
|
+
*/
|
|
4
|
+
var args = phantom.args;
|
|
5
|
+
var page = require('webpage').create();
|
|
6
|
+
|
|
7
|
+
page.onConsoleMessage = function(msg) {
|
|
8
|
+
console.log(msg);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
page.onInitialized = function() {
|
|
12
|
+
page.evaluate(function () {
|
|
13
|
+
window.OPAL_SPEC_PHANTOM = true;
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
var system = require('system');
|
|
18
|
+
page.onCallback = function(data) {
|
|
19
|
+
switch (data[0]) {
|
|
20
|
+
case 'exit':
|
|
21
|
+
var status = data[1] || 0;
|
|
22
|
+
phantom.exit(status);
|
|
23
|
+
case 'stdout':
|
|
24
|
+
system.stdout.write(data[1] || '');
|
|
25
|
+
break;
|
|
26
|
+
case 'stderr':
|
|
27
|
+
system.stderr.write(data[1] || '');
|
|
28
|
+
break;
|
|
29
|
+
default:
|
|
30
|
+
console.error('Unknown callback data: ', data);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
page.open(args[0], function(status) {
|
|
35
|
+
if (status !== 'success') {
|
|
36
|
+
console.error("Cannot load: " + args[0]);
|
|
37
|
+
phantom.exit(1);
|
|
38
|
+
} else {
|
|
39
|
+
var timeout = parseInt(args[1] || 60000, 10);
|
|
40
|
+
var start = Date.now();
|
|
41
|
+
var interval = setInterval(function() {
|
|
42
|
+
if (Date.now() > start + timeout) {
|
|
43
|
+
console.error("Specs timed out");
|
|
44
|
+
phantom.exit(124);
|
|
45
|
+
} else {
|
|
46
|
+
var code = page.evaluate(function() {
|
|
47
|
+
return window.OPAL_SPEC_CODE;
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
if (code === 0 || code === 1) {
|
|
51
|
+
clearInterval(interval);
|
|
52
|
+
phantom.exit(code);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}, 500);
|
|
56
|
+
}
|
|
57
|
+
});
|
data/lib/opal.rb
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
require 'opal/compiler'
|
|
2
|
+
require 'opal/builder'
|
|
3
|
+
require 'opal/erb'
|
|
4
|
+
require 'opal/sprockets'
|
|
5
|
+
require 'opal/paths'
|
|
6
|
+
require 'opal/version'
|
|
7
|
+
|
|
8
|
+
# Opal is a ruby to javascript compiler, with a runtime for running
|
|
9
|
+
# in any javascript environment.
|
|
10
|
+
module Opal
|
|
11
|
+
end
|
data/lib/opal/builder.rb
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
require 'opal/path_reader'
|
|
2
|
+
require 'opal/builder_processors'
|
|
3
|
+
require 'set'
|
|
4
|
+
|
|
5
|
+
module Opal
|
|
6
|
+
class Builder
|
|
7
|
+
include BuilderProcessors
|
|
8
|
+
|
|
9
|
+
def initialize(options = nil)
|
|
10
|
+
(options || {}).each_pair do |k,v|
|
|
11
|
+
public_send("#{k}=", v)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
@compiler_options ||= {}
|
|
15
|
+
@default_processor ||= RubyProcessor
|
|
16
|
+
@processors ||= DEFAULT_PROCESSORS
|
|
17
|
+
@stubs ||= []
|
|
18
|
+
@preload ||= []
|
|
19
|
+
@prerequired ||= []
|
|
20
|
+
@path_reader ||= PathReader.new
|
|
21
|
+
|
|
22
|
+
@processed = []
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def self.build(*args, &block)
|
|
26
|
+
new.build(*args, &block)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def build(path, options = {})
|
|
30
|
+
source = read(path)
|
|
31
|
+
build_str(source, path, options)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def build_str source, filename, options = {}
|
|
35
|
+
path = path_reader.expand(filename).to_s unless stub?(filename)
|
|
36
|
+
asset = processor_for(source, filename, path, options)
|
|
37
|
+
requires = preload + asset.requires + tree_requires(asset, path)
|
|
38
|
+
requires.map { |r| process_require(r, options) }
|
|
39
|
+
processed << asset
|
|
40
|
+
self
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def build_require(path, options = {})
|
|
44
|
+
process_require(path, options)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def to_s
|
|
48
|
+
processed.map(&:to_s).join("\n")
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def source_map
|
|
52
|
+
processed.map(&:source_map).reduce(:+).as_json.to_json
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
attr_reader :processed
|
|
56
|
+
|
|
57
|
+
attr_accessor :processors, :default_processor, :path_reader,
|
|
58
|
+
:compiler_options, :stubs, :prerequired, :preload
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
private
|
|
64
|
+
|
|
65
|
+
def tree_requires(asset, path)
|
|
66
|
+
if path.nil? or path.empty?
|
|
67
|
+
dirname = Dir.pwd
|
|
68
|
+
else
|
|
69
|
+
dirname = File.dirname(File.expand_path(path))
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
paths = path_reader.paths.map{|p| File.expand_path(p)}
|
|
73
|
+
|
|
74
|
+
asset.required_trees.flat_map do |tree|
|
|
75
|
+
expanded = File.expand_path(tree, dirname)
|
|
76
|
+
base = paths.find { |p| expanded.start_with?(p) }
|
|
77
|
+
next [] if base.nil?
|
|
78
|
+
|
|
79
|
+
globs = extensions.map { |ext| File.join base, tree, "*.#{ext}" }
|
|
80
|
+
|
|
81
|
+
Dir[*globs].map do |file|
|
|
82
|
+
Pathname(file).relative_path_from(Pathname(base)).to_s.gsub(/(\.js)?(\.(?:#{extensions.join '|'}))$/, '')
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def processor_for(source, filename, path, options)
|
|
88
|
+
processor = processors.find { |p| p.match? path }
|
|
89
|
+
processor ||= default_processor
|
|
90
|
+
return processor.new(source, filename, compiler_options.merge(options))
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def read(path)
|
|
94
|
+
path_reader.read(path) or
|
|
95
|
+
raise ArgumentError, "can't find file: #{path.inspect} in #{path_reader.paths.inspect}"
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def process_require(filename, options)
|
|
99
|
+
return if prerequired.include?(filename)
|
|
100
|
+
return if already_processed.include?(filename)
|
|
101
|
+
already_processed << filename
|
|
102
|
+
|
|
103
|
+
source = stub?(filename) ? '' : read(filename)
|
|
104
|
+
|
|
105
|
+
if source.nil?
|
|
106
|
+
message = "can't find file: #{filename.inspect}"
|
|
107
|
+
case @compiler_options[:dynamic_require_severity]
|
|
108
|
+
when :error then raise LoadError, message
|
|
109
|
+
when :warning then warn "can't find file: #{filename.inspect}"
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
path = path_reader.expand(filename).to_s unless stub?(filename)
|
|
114
|
+
asset = processor_for(source, filename, path, options.merge(requirable: true))
|
|
115
|
+
process_requires(asset.requires+tree_requires(asset, path), options)
|
|
116
|
+
processed << asset
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def process_requires(requires, options)
|
|
120
|
+
requires.map { |r| process_require(r, options) }
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def already_processed
|
|
124
|
+
@already_processed ||= Set.new
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def stub? filename
|
|
128
|
+
stubs.include?(filename)
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def extensions
|
|
132
|
+
@extensions ||= DEFAULT_PROCESSORS.flat_map(&:extensions).compact
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
end
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
require 'opal/compiler'
|
|
2
|
+
require 'opal/erb'
|
|
3
|
+
require 'source_map'
|
|
4
|
+
|
|
5
|
+
module Opal
|
|
6
|
+
module BuilderProcessors
|
|
7
|
+
DEFAULT_PROCESSORS = []
|
|
8
|
+
|
|
9
|
+
class Processor
|
|
10
|
+
def self.inherited(processor)
|
|
11
|
+
DEFAULT_PROCESSORS << processor
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def initialize(source, filename, options = {})
|
|
15
|
+
@source, @filename, @options = source, filename, options
|
|
16
|
+
@requires = []
|
|
17
|
+
@required_trees = []
|
|
18
|
+
end
|
|
19
|
+
attr_reader :source, :filename, :options, :requires, :required_trees
|
|
20
|
+
|
|
21
|
+
def to_s
|
|
22
|
+
source.to_s
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def self.handles(*extensions)
|
|
26
|
+
@extensions = extensions
|
|
27
|
+
matches = extensions.join('|')
|
|
28
|
+
matches = "(#{matches})" if extensions.size == 1
|
|
29
|
+
|
|
30
|
+
@match_regexp = Regexp.new "\\.#{matches}$"
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def self.extensions
|
|
34
|
+
@extensions
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def self.match? other
|
|
38
|
+
(other.is_a?(String) and other.match(match_regexp))
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def self.match_regexp
|
|
42
|
+
@match_regexp or raise NotImplementedError
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def source_map
|
|
46
|
+
@source_map ||= begin
|
|
47
|
+
mappings = []
|
|
48
|
+
source_file = filename+'.js'
|
|
49
|
+
line = source.count("\n")
|
|
50
|
+
column = source.scan("\n[^\n]*$").size
|
|
51
|
+
offset = ::SourceMap::Offset.new(line, column)
|
|
52
|
+
mappings << ::SourceMap::Mapping.new(source_file, offset, offset)
|
|
53
|
+
|
|
54
|
+
# Ensure mappings isn't empty: https://github.com/maccman/sourcemap/issues/11
|
|
55
|
+
unless mappings.any?
|
|
56
|
+
zero_offset = ::SourceMap::Offset.new(0,0)
|
|
57
|
+
mappings = [::SourceMap::Mapping.new(source_file,zero_offset,zero_offset)]
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
::SourceMap::Map.new(mappings)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def mark_as_required(filename)
|
|
65
|
+
"Opal.mark_as_loaded(Opal.normalize_loadable_path(#{filename.to_s.inspect}));"
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
class JsProcessor < Processor
|
|
70
|
+
handles :js
|
|
71
|
+
|
|
72
|
+
def source
|
|
73
|
+
@source.to_s + mark_as_required(@filename)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
class RubyProcessor < Processor
|
|
78
|
+
handles :rb, :opal
|
|
79
|
+
|
|
80
|
+
def source
|
|
81
|
+
compiled.result
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def source_map
|
|
85
|
+
compiled.source_map.map
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def compiled
|
|
89
|
+
@compiled ||= begin
|
|
90
|
+
compiler = compiler_for(@source, file: @filename)
|
|
91
|
+
compiler.compile
|
|
92
|
+
compiler
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def compiler_for(source, options = {})
|
|
97
|
+
compiler_class.new(source, @options.merge(options))
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def requires
|
|
101
|
+
compiled.requires
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def required_trees
|
|
105
|
+
compiled.required_trees
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def compiler_class
|
|
109
|
+
::Opal::Compiler
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
class ERBProcessor < RubyProcessor
|
|
114
|
+
handles :opalerb
|
|
115
|
+
|
|
116
|
+
def initialize(*args)
|
|
117
|
+
super
|
|
118
|
+
@source = prepare(@source, @filename)
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def requires
|
|
122
|
+
['erb']+super
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
private
|
|
126
|
+
|
|
127
|
+
def erb_compiler_class
|
|
128
|
+
::Opal::ERB::Compiler
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def prepare(source, path)
|
|
132
|
+
erb_compiler = erb_compiler_class.new(source, path)
|
|
133
|
+
erb_compiler.prepared_source
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
class HamlProcessor < RubyProcessor
|
|
138
|
+
handles :haml
|
|
139
|
+
|
|
140
|
+
def initialize(*args)
|
|
141
|
+
super
|
|
142
|
+
@source = prepare(@source, @filename)
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def requires
|
|
146
|
+
['opal-haml'] + super
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
def prepare(source, path)
|
|
150
|
+
haml = ::Haml::Engine.new(source, :ugly => true).precompiled
|
|
151
|
+
haml = haml.gsub('_hamlout.buffer', '_hamlout')
|
|
152
|
+
|
|
153
|
+
::Opal::Haml.wrap haml, path
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
class ERB_Processor < Processor
|
|
158
|
+
handles :erb
|
|
159
|
+
|
|
160
|
+
def source
|
|
161
|
+
"Opal.modules[#{@filename.inspect}] = function() {#{::ERB.new(@source.to_s).result}};"
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
end
|