opal 0.11.4 → 1.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +42 -10
- data/.rubocop.yml +398 -0
- data/.rubocop_todo.yml +44 -0
- data/.travis.yml +28 -34
- data/CHANGELOG.md +363 -142
- data/CONTRIBUTING.md +3 -5
- data/Gemfile +17 -12
- data/Guardfile +0 -1
- data/HACKING.md +1 -35
- data/LICENSE +2 -2
- data/README.md +42 -13
- data/Rakefile +1 -4
- data/UNRELEASED.md +133 -0
- data/benchmark-ips/README.md +6 -0
- data/benchmark-ips/bm_block_vs_yield.rb +21 -0
- data/benchmark-ips/bm_js_symbols_vs_strings.rb +28 -0
- data/benchmark-ips/bm_while_true_vs_loop.rb +19 -0
- data/bin/console +14 -0
- data/bin/opal +0 -1
- data/bin/opal-benchmark-ips +8 -0
- data/bin/opal-mspec +9 -1
- data/bin/opal-repl +2 -1
- data/bin/rake +7 -0
- data/bin/setup +8 -0
- data/docs/compiled_ruby.md +89 -8
- data/docs/compiler.md +3 -20
- data/docs/jquery.md +44 -11
- data/docs/promises.md +1 -1
- data/docs/rails.md +16 -12
- data/docs/sinatra.md +15 -8
- data/docs/using_sprockets.md +16 -11
- data/examples/rack/config.ru +1 -0
- data/examples/sinatra/Gemfile +1 -0
- data/examples/sinatra/config.ru +2 -11
- data/exe/opal-repl +3 -11
- data/lib/opal.rb +1 -0
- data/lib/opal/ast/builder.rb +4 -1
- data/lib/opal/ast/node.rb +1 -0
- data/lib/opal/builder.rb +84 -63
- data/lib/opal/builder_processors.rb +41 -56
- data/lib/opal/cli.rb +33 -49
- data/lib/opal/cli_options.rb +27 -17
- data/lib/opal/cli_runners.rb +73 -16
- data/lib/opal/cli_runners/applescript.rb +4 -4
- data/lib/opal/cli_runners/chrome.rb +29 -17
- data/lib/opal/cli_runners/nashorn.rb +5 -4
- data/lib/opal/cli_runners/nodejs.rb +8 -6
- data/lib/opal/cli_runners/server.rb +12 -11
- data/lib/opal/compiler.rb +85 -103
- data/lib/opal/config.rb +3 -3
- data/lib/opal/deprecations.rb +2 -1
- data/lib/opal/eof_content.rb +2 -2
- data/lib/opal/erb.rb +8 -7
- data/lib/opal/errors.rb +72 -1
- data/lib/opal/fragment.rb +23 -3
- data/lib/opal/hike.rb +305 -0
- data/lib/opal/nodes.rb +5 -10
- data/lib/opal/nodes/arglist.rb +7 -6
- data/lib/opal/nodes/args.rb +36 -0
- data/lib/opal/nodes/args/arg.rb +22 -0
- data/lib/opal/nodes/args/arity_check.rb +151 -0
- data/lib/opal/nodes/args/ensure_kwargs_are_kwargs.rb +28 -0
- data/lib/opal/nodes/args/extract_block_arg.rb +34 -0
- data/lib/opal/nodes/args/extract_kwarg.rb +32 -0
- data/lib/opal/nodes/args/extract_kwargs.rb +28 -0
- data/lib/opal/nodes/args/extract_kwoptarg.rb +35 -0
- data/lib/opal/nodes/args/extract_kwrestarg.rb +35 -0
- data/lib/opal/nodes/args/extract_optarg.rb +35 -0
- data/lib/opal/nodes/args/extract_post_arg.rb +28 -0
- data/lib/opal/nodes/args/extract_post_optarg.rb +41 -0
- data/lib/opal/nodes/args/extract_restarg.rb +40 -0
- data/lib/opal/nodes/args/fake_arg.rb +26 -0
- data/lib/opal/nodes/args/initialize_iterarg.rb +28 -0
- data/lib/opal/nodes/args/initialize_shadowarg.rb +24 -0
- data/lib/opal/nodes/args/parameters.rb +63 -0
- data/lib/opal/nodes/args/prepare_post_args.rb +22 -0
- data/lib/opal/nodes/array.rb +9 -8
- data/lib/opal/nodes/base.rb +20 -11
- data/lib/opal/nodes/call.rb +24 -25
- data/lib/opal/nodes/call_special.rb +4 -3
- data/lib/opal/nodes/case.rb +24 -26
- data/lib/opal/nodes/class.rb +4 -5
- data/lib/opal/nodes/constants.rb +8 -7
- data/lib/opal/nodes/csend.rb +2 -3
- data/lib/opal/nodes/def.rb +28 -74
- data/lib/opal/nodes/defined.rb +36 -36
- data/lib/opal/nodes/definitions.rb +10 -7
- data/lib/opal/nodes/defs.rb +8 -16
- data/lib/opal/nodes/hash.rb +5 -4
- data/lib/opal/nodes/helpers.rb +8 -8
- data/lib/opal/nodes/if.rb +10 -8
- data/lib/opal/nodes/iter.rb +16 -103
- data/lib/opal/nodes/lambda.rb +18 -0
- data/lib/opal/nodes/literal.rb +29 -63
- data/lib/opal/nodes/logic.rb +25 -24
- data/lib/opal/nodes/masgn.rb +8 -6
- data/lib/opal/nodes/module.rb +4 -4
- data/lib/opal/nodes/node_with_args.rb +14 -208
- data/lib/opal/nodes/rescue.rb +32 -32
- data/lib/opal/nodes/runtime_helpers.rb +5 -4
- data/lib/opal/nodes/scope.rb +18 -29
- data/lib/opal/nodes/singleton_class.rb +3 -3
- data/lib/opal/nodes/super.rb +12 -18
- data/lib/opal/nodes/top.rb +10 -8
- data/lib/opal/nodes/variables.rb +6 -6
- data/lib/opal/nodes/while.rb +7 -6
- data/lib/opal/nodes/x_string.rb +139 -0
- data/lib/opal/nodes/yield.rb +10 -7
- data/lib/opal/parser.rb +9 -46
- data/lib/opal/parser/default_config.rb +50 -0
- data/lib/opal/parser/patch.rb +26 -0
- data/lib/opal/parser/source_buffer.rb +11 -0
- data/lib/opal/parser/with_c_lexer.rb +14 -0
- data/lib/opal/parser/with_ruby_lexer.rb +6 -0
- data/lib/opal/path_reader.rb +6 -5
- data/lib/opal/paths.rb +9 -6
- data/lib/opal/regexp_anchors.rb +6 -5
- data/lib/opal/rewriter.rb +7 -0
- data/lib/opal/rewriters/arguments.rb +58 -0
- data/lib/opal/rewriters/base.rb +32 -12
- data/lib/opal/rewriters/binary_operator_assignment.rb +20 -20
- data/lib/opal/rewriters/block_to_iter.rb +2 -1
- data/lib/opal/rewriters/break_finder.rb +2 -0
- data/lib/opal/rewriters/dot_js_syntax.rb +3 -2
- data/lib/opal/rewriters/dump_args.rb +28 -0
- data/lib/opal/rewriters/explicit_writer_return.rb +4 -3
- data/lib/opal/rewriters/for_rewriter.rb +12 -12
- data/lib/opal/rewriters/hashes/key_duplicates_rewriter.rb +2 -1
- data/lib/opal/rewriters/inline_args.rb +220 -0
- data/lib/opal/rewriters/js_reserved_words.rb +21 -17
- data/lib/opal/rewriters/logical_operator_assignment.rb +24 -14
- data/lib/opal/rewriters/mlhs_args.rb +128 -0
- data/lib/opal/rewriters/opal_engine_check.rb +11 -6
- data/lib/opal/rewriters/rubyspec/filters_rewriter.rb +3 -2
- data/lib/opal/server.rb +1 -0
- data/lib/opal/simple_server.rb +15 -23
- data/lib/opal/source_map.rb +7 -70
- data/lib/opal/source_map/file.rb +199 -0
- data/lib/opal/source_map/index.rb +83 -0
- data/lib/opal/source_map/map.rb +26 -0
- data/lib/opal/source_map/vlq.rb +98 -0
- data/lib/opal/util.rb +7 -5
- data/lib/opal/version.rb +2 -1
- data/lib/tilt/opal.rb +3 -3
- data/opal.gemspec +18 -9
- data/opal/corelib/array.rb +135 -117
- data/opal/corelib/array/pack.rb +446 -0
- data/opal/corelib/basic_object.rb +23 -9
- data/opal/corelib/boolean.rb +3 -3
- data/opal/corelib/class.rb +4 -10
- data/opal/corelib/comparable.rb +36 -23
- data/opal/corelib/complex.rb +108 -14
- data/opal/corelib/constants.rb +4 -4
- data/opal/corelib/enumerable.rb +132 -135
- data/opal/corelib/enumerator.rb +47 -50
- data/opal/corelib/error.rb +65 -8
- data/opal/corelib/file.rb +37 -32
- data/opal/corelib/hash.rb +90 -21
- data/opal/corelib/helpers.rb +7 -6
- data/opal/corelib/kernel.rb +53 -586
- data/opal/corelib/kernel/format.rb +544 -0
- data/opal/corelib/marshal.rb +1 -13
- data/opal/corelib/marshal/read_buffer.rb +20 -23
- data/opal/corelib/marshal/write_buffer.rb +23 -15
- data/opal/corelib/math.rb +12 -16
- data/opal/corelib/method.rb +5 -3
- data/opal/corelib/module.rb +80 -109
- data/opal/corelib/nil.rb +2 -2
- data/opal/corelib/number.rb +177 -43
- data/opal/corelib/numeric.rb +22 -16
- data/opal/corelib/pack_unpack/format_string_parser.rb +135 -0
- data/opal/corelib/proc.rb +3 -4
- data/opal/corelib/process.rb +1 -1
- data/opal/corelib/random.rb +24 -16
- data/opal/corelib/random/MersenneTwister.js +137 -0
- data/opal/corelib/random/math_random.js.rb +9 -0
- data/opal/corelib/random/mersenne_twister.js.rb +13 -0
- data/opal/corelib/random/seedrandom.js.rb +12 -0
- data/opal/corelib/range.rb +25 -26
- data/opal/corelib/rational.rb +57 -17
- data/opal/corelib/regexp.rb +39 -43
- data/opal/corelib/runtime.js +806 -683
- data/opal/corelib/string.rb +213 -112
- data/opal/corelib/string/encoding.rb +14 -17
- data/opal/corelib/string/unpack.rb +793 -0
- data/opal/corelib/struct.rb +40 -24
- data/opal/corelib/time.rb +14 -15
- data/opal/corelib/unsupported.rb +26 -4
- data/opal/opal.rb +2 -1
- data/opal/opal/full.rb +2 -0
- data/stdlib/base64.rb +1 -1
- data/stdlib/bigdecimal.rb +11 -13
- data/stdlib/buffer.rb +9 -8
- data/stdlib/buffer/array.rb +46 -48
- data/stdlib/buffer/view.rb +85 -47
- data/stdlib/console.rb +18 -18
- data/stdlib/date.rb +85 -66
- data/stdlib/delegate.rb +2 -2
- data/stdlib/e2mmap.rb +176 -0
- data/stdlib/encoding.rb +1 -1
- data/stdlib/erb.rb +1 -1
- data/stdlib/forwardable.rb +14 -14
- data/stdlib/json.rb +1 -2
- data/stdlib/logger.rb +112 -0
- data/stdlib/math.rb +1 -1
- data/stdlib/matrix.rb +2169 -0
- data/stdlib/matrix/eigenvalue_decomposition.rb +883 -0
- data/stdlib/matrix/lup_decomposition.rb +219 -0
- data/stdlib/nashorn/file.rb +7 -9
- data/stdlib/native.rb +69 -63
- data/stdlib/nodejs.rb +3 -0
- data/stdlib/nodejs/dir.rb +25 -4
- data/stdlib/nodejs/env.rb +40 -0
- data/stdlib/nodejs/file.rb +184 -34
- data/stdlib/nodejs/fileutils.rb +4 -4
- data/stdlib/nodejs/io.rb +4 -46
- data/stdlib/nodejs/irb.rb +27 -29
- data/stdlib/nodejs/kernel.rb +2 -11
- data/stdlib/nodejs/node_modules/balanced-match/.npmignore +5 -0
- data/stdlib/nodejs/node_modules/balanced-match/LICENSE.md +21 -0
- data/stdlib/nodejs/node_modules/{glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match → balanced-match}/README.md +13 -2
- data/stdlib/nodejs/node_modules/balanced-match/index.js +59 -0
- data/stdlib/nodejs/node_modules/{glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match → balanced-match}/package.json +46 -42
- data/stdlib/nodejs/node_modules/brace-expansion/LICENSE +21 -0
- data/stdlib/nodejs/node_modules/{glob/node_modules/minimatch/node_modules/brace-expansion → brace-expansion}/README.md +9 -1
- data/stdlib/nodejs/node_modules/{glob/node_modules/minimatch/node_modules/brace-expansion → brace-expansion}/index.js +12 -2
- data/stdlib/nodejs/node_modules/{glob/node_modules/minimatch/node_modules/brace-expansion → brace-expansion}/package.json +48 -48
- data/stdlib/nodejs/node_modules/{glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map → concat-map}/.travis.yml +0 -0
- data/stdlib/nodejs/node_modules/{glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map → concat-map}/LICENSE +0 -0
- data/stdlib/nodejs/node_modules/{glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map → concat-map}/README.markdown +0 -0
- data/stdlib/nodejs/node_modules/{glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map → concat-map}/example/map.js +0 -0
- data/stdlib/nodejs/node_modules/{glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map → concat-map}/index.js +0 -0
- data/stdlib/nodejs/node_modules/{glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map → concat-map}/package.json +47 -42
- data/stdlib/nodejs/node_modules/{glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/concat-map → concat-map}/test/map.js +0 -0
- data/stdlib/nodejs/node_modules/fs.realpath/LICENSE +43 -0
- data/stdlib/nodejs/node_modules/fs.realpath/README.md +33 -0
- data/stdlib/nodejs/node_modules/fs.realpath/index.js +66 -0
- data/stdlib/nodejs/node_modules/fs.realpath/old.js +303 -0
- data/stdlib/nodejs/node_modules/fs.realpath/package.json +59 -0
- data/stdlib/nodejs/node_modules/glob/README.md +57 -46
- data/stdlib/nodejs/node_modules/glob/changelog.md +67 -0
- data/stdlib/nodejs/node_modules/glob/common.js +91 -28
- data/stdlib/nodejs/node_modules/glob/glob.js +196 -55
- data/stdlib/nodejs/node_modules/glob/package.json +55 -51
- data/stdlib/nodejs/node_modules/glob/sync.js +116 -39
- data/stdlib/nodejs/node_modules/{glob/node_modules/inflight → inflight}/LICENSE +0 -0
- data/stdlib/nodejs/node_modules/{glob/node_modules/inflight → inflight}/README.md +0 -0
- data/stdlib/nodejs/node_modules/inflight/inflight.js +54 -0
- data/stdlib/nodejs/node_modules/inflight/package.json +58 -0
- data/stdlib/nodejs/node_modules/{glob/node_modules/inherits → inherits}/LICENSE +0 -0
- data/stdlib/nodejs/node_modules/{glob/node_modules/inherits → inherits}/README.md +0 -0
- data/stdlib/nodejs/node_modules/inherits/inherits.js +7 -0
- data/stdlib/nodejs/node_modules/{glob/node_modules/inherits → inherits}/inherits_browser.js +0 -0
- data/stdlib/nodejs/node_modules/inherits/package.json +61 -0
- data/stdlib/nodejs/node_modules/{glob/node_modules/inflight/node_modules/wrappy → minimatch}/LICENSE +0 -0
- data/stdlib/nodejs/node_modules/{glob/node_modules/minimatch → minimatch}/README.md +2 -9
- data/stdlib/nodejs/node_modules/{glob/node_modules/minimatch → minimatch}/minimatch.js +284 -206
- data/stdlib/nodejs/node_modules/minimatch/package.json +63 -0
- data/stdlib/nodejs/node_modules/{glob/node_modules/once/node_modules/wrappy → once}/LICENSE +0 -0
- data/stdlib/nodejs/node_modules/{glob/node_modules/once → once}/README.md +28 -0
- data/stdlib/nodejs/node_modules/once/once.js +42 -0
- data/stdlib/nodejs/node_modules/once/package.json +67 -0
- data/stdlib/nodejs/node_modules/path-is-absolute/index.js +20 -0
- data/stdlib/nodejs/node_modules/path-is-absolute/license +21 -0
- data/stdlib/nodejs/node_modules/path-is-absolute/package.json +75 -0
- data/stdlib/nodejs/node_modules/path-is-absolute/readme.md +59 -0
- data/stdlib/nodejs/node_modules/unxhr/LICENSE +22 -0
- data/stdlib/nodejs/node_modules/unxhr/README.md +41 -0
- data/stdlib/nodejs/node_modules/unxhr/lib/XMLHttpRequest.js +598 -0
- data/stdlib/nodejs/node_modules/unxhr/lib/browser.js +2 -0
- data/stdlib/nodejs/node_modules/unxhr/lib/request.js +63 -0
- data/stdlib/nodejs/node_modules/unxhr/package.json +75 -0
- data/stdlib/nodejs/node_modules/wrappy/LICENSE +15 -0
- data/stdlib/nodejs/node_modules/{glob/node_modules/inflight/node_modules/wrappy → wrappy}/README.md +0 -0
- data/stdlib/nodejs/node_modules/wrappy/package.json +59 -0
- data/stdlib/nodejs/node_modules/{glob/node_modules/inflight/node_modules/wrappy → wrappy}/wrappy.js +0 -0
- data/stdlib/nodejs/open-uri.rb +26 -0
- data/stdlib/nodejs/package-lock.json +88 -0
- data/stdlib/nodejs/package.json +2 -1
- data/stdlib/nodejs/pathname.rb +20 -0
- data/stdlib/nodejs/require.rb +3 -3
- data/stdlib/nodejs/stacktrace.rb +1 -1
- data/stdlib/nodejs/yaml.rb +1 -1
- data/stdlib/opal-builder.rb +1 -0
- data/stdlib/opal-parser.rb +4 -1
- data/stdlib/opal-platform.rb +8 -10
- data/stdlib/opal-source-maps.rb +0 -1
- data/stdlib/open-uri.rb +349 -0
- data/stdlib/ostruct.rb +19 -17
- data/stdlib/pathname.rb +22 -22
- data/stdlib/pp.rb +5 -5
- data/stdlib/promise.rb +30 -26
- data/stdlib/rbconfig/sizeof.rb +50 -0
- data/stdlib/securerandom.rb +1 -1
- data/stdlib/set.rb +21 -23
- data/stdlib/singleton.rb +3 -4
- data/stdlib/stringio.rb +33 -0
- data/stdlib/strscan.rb +55 -55
- data/stdlib/template.rb +1 -2
- data/stdlib/thread.rb +6 -7
- data/tasks/benchmarking.rake +1 -1
- data/tasks/building.rake +4 -12
- data/tasks/linting.rake +17 -2
- data/tasks/releasing.rake +84 -0
- data/tasks/testing.rake +57 -15
- data/tasks/testing/mspec_special_calls.rb +23 -4
- data/vendored-minitest/minitest.rb +1 -1
- metadata +169 -168
- data/bin/opal-build +0 -3
- data/exe/opal-mspec +0 -10
- data/lib/opal/nodes/args/initialize_kwargs.rb +0 -29
- data/lib/opal/nodes/args/kwarg.rb +0 -31
- data/lib/opal/nodes/args/kwoptarg.rb +0 -34
- data/lib/opal/nodes/args/kwrestarg.rb +0 -39
- data/lib/opal/nodes/args/mlhsarg.rb +0 -78
- data/lib/opal/nodes/args/normarg.rb +0 -29
- data/lib/opal/nodes/args/optarg.rb +0 -25
- data/lib/opal/nodes/args/post_args.rb +0 -201
- data/lib/opal/nodes/args/post_kwargs.rb +0 -32
- data/lib/opal/nodes/args/restarg.rb +0 -38
- data/lib/opal/nodes/inline_args.rb +0 -60
- data/opal/corelib/string/inheritance.rb +0 -123
- data/stdlib/nodejs/node_modules/glob/node_modules/inflight/.eslintrc +0 -17
- data/stdlib/nodejs/node_modules/glob/node_modules/inflight/inflight.js +0 -44
- data/stdlib/nodejs/node_modules/glob/node_modules/inflight/node_modules/wrappy/package.json +0 -52
- data/stdlib/nodejs/node_modules/glob/node_modules/inflight/node_modules/wrappy/test/basic.js +0 -51
- data/stdlib/nodejs/node_modules/glob/node_modules/inflight/package.json +0 -61
- data/stdlib/nodejs/node_modules/glob/node_modules/inflight/test.js +0 -97
- data/stdlib/nodejs/node_modules/glob/node_modules/inherits/inherits.js +0 -1
- data/stdlib/nodejs/node_modules/glob/node_modules/inherits/package.json +0 -51
- data/stdlib/nodejs/node_modules/glob/node_modules/inherits/test.js +0 -25
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/.npmignore +0 -1
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/.travis.yml +0 -4
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/LICENSE +0 -23
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/benchmark.js +0 -15
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/browser.js +0 -1181
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/.npmignore +0 -2
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/.travis.yml +0 -3
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/example.js +0 -8
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/.npmignore +0 -2
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/.travis.yml +0 -4
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/Makefile +0 -6
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/example.js +0 -5
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/index.js +0 -38
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/node_modules/balanced-match/test/balanced.js +0 -56
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/bash-comparison.js +0 -32
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/bash-results.txt +0 -1075
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/cases.txt +0 -182
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/dollar.js +0 -9
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/empty-option.js +0 -10
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/generate.sh +0 -24
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/negative-increment.js +0 -15
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/nested.js +0 -16
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/order.js +0 -10
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/pad.js +0 -13
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/same-type.js +0 -7
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/node_modules/brace-expansion/test/sequence.js +0 -50
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/package.json +0 -60
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/test/basic.js +0 -399
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/test/brace-expand.js +0 -45
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/test/defaults.js +0 -274
- data/stdlib/nodejs/node_modules/glob/node_modules/minimatch/test/extglob-ending-with-state-char.js +0 -8
- data/stdlib/nodejs/node_modules/glob/node_modules/once/LICENSE +0 -27
- data/stdlib/nodejs/node_modules/glob/node_modules/once/node_modules/wrappy/README.md +0 -36
- data/stdlib/nodejs/node_modules/glob/node_modules/once/node_modules/wrappy/package.json +0 -52
- data/stdlib/nodejs/node_modules/glob/node_modules/once/node_modules/wrappy/test/basic.js +0 -51
- data/stdlib/nodejs/node_modules/glob/node_modules/once/node_modules/wrappy/wrappy.js +0 -33
- data/stdlib/nodejs/node_modules/glob/node_modules/once/once.js +0 -21
- data/stdlib/nodejs/node_modules/glob/node_modules/once/package.json +0 -60
- data/stdlib/nodejs/node_modules/glob/node_modules/once/test/once.js +0 -23
- data/stdlib/nodejs/rubygems.rb +0 -68
- data/stdlib/source_map.rb +0 -5
- data/stdlib/source_map/map.rb +0 -220
- data/stdlib/source_map/mapping.rb +0 -26
- data/stdlib/source_map/offset.rb +0 -88
- data/stdlib/source_map/version.rb +0 -3
- data/stdlib/source_map/vlq.rb +0 -99
- data/stdlib/sourcemap.rb +0 -1
data/opal/corelib/string.rb
CHANGED
@@ -4,7 +4,18 @@ require 'corelib/regexp'
|
|
4
4
|
class String < `String`
|
5
5
|
include Comparable
|
6
6
|
|
7
|
-
|
7
|
+
%x{
|
8
|
+
Opal.defineProperty(#{self}.$$prototype, '$$is_string', true);
|
9
|
+
|
10
|
+
Opal.defineProperty(#{self}.$$prototype, '$$cast', function(string) {
|
11
|
+
var klass = this.$$class;
|
12
|
+
if (klass.$$constructor === String) {
|
13
|
+
return string;
|
14
|
+
} else {
|
15
|
+
return new klass.$$constructor(string);
|
16
|
+
}
|
17
|
+
});
|
18
|
+
}
|
8
19
|
|
9
20
|
def __id__
|
10
21
|
`self.toString()`
|
@@ -18,7 +29,7 @@ class String < `String`
|
|
18
29
|
|
19
30
|
def self.new(str = '')
|
20
31
|
str = Opal.coerce_to(str, String, :to_str)
|
21
|
-
`new
|
32
|
+
`new self.$$constructor(str)`
|
22
33
|
end
|
23
34
|
|
24
35
|
def initialize(str = undefined)
|
@@ -47,7 +58,7 @@ class String < `String`
|
|
47
58
|
}
|
48
59
|
|
49
60
|
if (count === 0) {
|
50
|
-
return '';
|
61
|
+
return self.$$cast('');
|
51
62
|
}
|
52
63
|
|
53
64
|
var result = '',
|
@@ -72,7 +83,7 @@ class String < `String`
|
|
72
83
|
string += string;
|
73
84
|
}
|
74
85
|
|
75
|
-
return result;
|
86
|
+
return self.$$cast(result);
|
76
87
|
}
|
77
88
|
end
|
78
89
|
|
@@ -157,7 +168,7 @@ class String < `String`
|
|
157
168
|
length = 0;
|
158
169
|
}
|
159
170
|
|
160
|
-
return self.substr(index, length);
|
171
|
+
return self.$$cast(self.substr(index, length));
|
161
172
|
}
|
162
173
|
|
163
174
|
|
@@ -165,7 +176,7 @@ class String < `String`
|
|
165
176
|
if (length != null) {
|
166
177
|
#{raise TypeError}
|
167
178
|
}
|
168
|
-
return self.indexOf(index) !== -1 ? index : nil;
|
179
|
+
return self.indexOf(index) !== -1 ? self.$$cast(index) : nil;
|
169
180
|
}
|
170
181
|
|
171
182
|
|
@@ -180,17 +191,17 @@ class String < `String`
|
|
180
191
|
#{$~ = MatchData.new(`index`, `match`)}
|
181
192
|
|
182
193
|
if (length == null) {
|
183
|
-
return match[0];
|
194
|
+
return self.$$cast(match[0]);
|
184
195
|
}
|
185
196
|
|
186
197
|
length = #{Opal.coerce_to(`length`, Integer, :to_int)};
|
187
198
|
|
188
199
|
if (length < 0 && -length < match.length) {
|
189
|
-
return match[length += match.length];
|
200
|
+
return self.$$cast(match[length += match.length]);
|
190
201
|
}
|
191
202
|
|
192
203
|
if (length >= 0 && length < match.length) {
|
193
|
-
return match[length];
|
204
|
+
return self.$$cast(match[length]);
|
194
205
|
}
|
195
206
|
|
196
207
|
return nil;
|
@@ -207,7 +218,7 @@ class String < `String`
|
|
207
218
|
if (index >= size || index < 0) {
|
208
219
|
return nil;
|
209
220
|
}
|
210
|
-
return self.substr(index, 1);
|
221
|
+
return self.$$cast(self.substr(index, 1));
|
211
222
|
}
|
212
223
|
|
213
224
|
length = #{Opal.coerce_to(`length`, Integer, :to_int)};
|
@@ -220,17 +231,22 @@ class String < `String`
|
|
220
231
|
return nil;
|
221
232
|
}
|
222
233
|
|
223
|
-
return self.substr(index, length);
|
234
|
+
return self.$$cast(self.substr(index, length));
|
224
235
|
}
|
225
236
|
end
|
226
237
|
|
227
238
|
alias byteslice []
|
228
239
|
|
240
|
+
def b
|
241
|
+
force_encoding('binary')
|
242
|
+
end
|
243
|
+
|
229
244
|
def capitalize
|
230
|
-
`self.charAt(0).toUpperCase() + self.substr(1).toLowerCase()`
|
245
|
+
`self.$$cast(self.charAt(0).toUpperCase() + self.substr(1).toLowerCase())`
|
231
246
|
end
|
232
247
|
|
233
248
|
def casecmp(other)
|
249
|
+
return nil unless other.respond_to?(:to_str)
|
234
250
|
other = Opal.coerce_to(other, String, :to_str).to_s
|
235
251
|
%x{
|
236
252
|
var ascii_only = /^[\x00-\x7F]*$/;
|
@@ -242,6 +258,17 @@ class String < `String`
|
|
242
258
|
self <=> other
|
243
259
|
end
|
244
260
|
|
261
|
+
def casecmp?(other)
|
262
|
+
%x{
|
263
|
+
var cmp = #{casecmp(other)};
|
264
|
+
if (cmp === nil) {
|
265
|
+
return nil;
|
266
|
+
} else {
|
267
|
+
return cmp === 0;
|
268
|
+
}
|
269
|
+
}
|
270
|
+
end
|
271
|
+
|
245
272
|
def center(width, padstr = ' ')
|
246
273
|
width = Opal.coerce_to(width, Integer, :to_int)
|
247
274
|
padstr = Opal.coerce_to(padstr, String, :to_str).to_s
|
@@ -253,10 +280,10 @@ class String < `String`
|
|
253
280
|
return self if `width <= self.length`
|
254
281
|
|
255
282
|
%x{
|
256
|
-
var ljustified = #{ljust ((width +
|
257
|
-
rjustified = #{rjust ((width +
|
283
|
+
var ljustified = #{ljust ((width + `self.length`) / 2).ceil, padstr},
|
284
|
+
rjustified = #{rjust ((width + `self.length`) / 2).floor, padstr};
|
258
285
|
|
259
|
-
return rjustified + ljustified.slice(self.length);
|
286
|
+
return self.$$cast(rjustified + ljustified.slice(self.length));
|
260
287
|
}
|
261
288
|
end
|
262
289
|
|
@@ -272,19 +299,25 @@ class String < `String`
|
|
272
299
|
separator = Opal.coerce_to!(separator, String, :to_str).to_s
|
273
300
|
|
274
301
|
%x{
|
302
|
+
var result;
|
303
|
+
|
275
304
|
if (separator === "\n") {
|
276
|
-
|
305
|
+
result = self.replace(/\r?\n?$/, '');
|
277
306
|
}
|
278
307
|
else if (separator === "") {
|
279
|
-
|
308
|
+
result = self.replace(/(\r?\n)+$/, '');
|
280
309
|
}
|
281
|
-
else if (self.length
|
310
|
+
else if (self.length >= separator.length) {
|
282
311
|
var tail = self.substr(self.length - separator.length, separator.length);
|
283
312
|
|
284
313
|
if (tail === separator) {
|
285
|
-
|
314
|
+
result = self.substr(0, self.length - separator.length);
|
286
315
|
}
|
287
316
|
}
|
317
|
+
|
318
|
+
if (result != null) {
|
319
|
+
return self.$$cast(result);
|
320
|
+
}
|
288
321
|
}
|
289
322
|
|
290
323
|
self
|
@@ -292,18 +325,17 @@ class String < `String`
|
|
292
325
|
|
293
326
|
def chop
|
294
327
|
%x{
|
295
|
-
var length = self.length;
|
328
|
+
var length = self.length, result;
|
296
329
|
|
297
330
|
if (length <= 1) {
|
298
|
-
|
331
|
+
result = "";
|
332
|
+
} else if (self.charAt(length - 1) === "\n" && self.charAt(length - 2) === "\r") {
|
333
|
+
result = self.substr(0, length - 2);
|
334
|
+
} else {
|
335
|
+
result = self.substr(0, length - 1);
|
299
336
|
}
|
300
337
|
|
301
|
-
|
302
|
-
return self.substr(0, length - 2);
|
303
|
-
}
|
304
|
-
else {
|
305
|
-
return self.substr(0, length - 1);
|
306
|
-
}
|
338
|
+
return self.$$cast(result);
|
307
339
|
}
|
308
340
|
end
|
309
341
|
|
@@ -327,7 +359,7 @@ class String < `String`
|
|
327
359
|
def count(*sets)
|
328
360
|
%x{
|
329
361
|
if (sets.length === 0) {
|
330
|
-
#{raise ArgumentError,
|
362
|
+
#{raise ArgumentError, 'ArgumentError: wrong number of arguments (0 for 1+)'}
|
331
363
|
}
|
332
364
|
var char_class = char_class_from_char_sets(sets);
|
333
365
|
if (char_class === null) {
|
@@ -340,22 +372,50 @@ class String < `String`
|
|
340
372
|
def delete(*sets)
|
341
373
|
%x{
|
342
374
|
if (sets.length === 0) {
|
343
|
-
#{raise ArgumentError,
|
375
|
+
#{raise ArgumentError, 'ArgumentError: wrong number of arguments (0 for 1+)'}
|
344
376
|
}
|
345
377
|
var char_class = char_class_from_char_sets(sets);
|
346
378
|
if (char_class === null) {
|
347
379
|
return self;
|
348
380
|
}
|
349
|
-
return self.replace(new RegExp(char_class, 'g'), '');
|
381
|
+
return self.$$cast(self.replace(new RegExp(char_class, 'g'), ''));
|
382
|
+
}
|
383
|
+
end
|
384
|
+
|
385
|
+
def delete_prefix(prefix)
|
386
|
+
%x{
|
387
|
+
if (!prefix.$$is_string) {
|
388
|
+
#{prefix = Opal.coerce_to(prefix, String, :to_str)}
|
389
|
+
}
|
390
|
+
|
391
|
+
if (self.slice(0, prefix.length) === prefix) {
|
392
|
+
return self.$$cast(self.slice(prefix.length));
|
393
|
+
} else {
|
394
|
+
return self;
|
395
|
+
}
|
396
|
+
}
|
397
|
+
end
|
398
|
+
|
399
|
+
def delete_suffix(suffix)
|
400
|
+
%x{
|
401
|
+
if (!suffix.$$is_string) {
|
402
|
+
#{suffix = Opal.coerce_to(suffix, String, :to_str)}
|
403
|
+
}
|
404
|
+
|
405
|
+
if (self.slice(self.length - suffix.length) === suffix) {
|
406
|
+
return self.$$cast(self.slice(0, self.length - suffix.length));
|
407
|
+
} else {
|
408
|
+
return self;
|
409
|
+
}
|
350
410
|
}
|
351
411
|
end
|
352
412
|
|
353
413
|
def downcase
|
354
|
-
`self.toLowerCase()`
|
414
|
+
`self.$$cast(self.toLowerCase())`
|
355
415
|
end
|
356
416
|
|
357
417
|
def each_char(&block)
|
358
|
-
return enum_for(:each_char){
|
418
|
+
return enum_for(:each_char) { size } unless block_given?
|
359
419
|
|
360
420
|
%x{
|
361
421
|
for (var i = 0, length = self.length; i < length; i++) {
|
@@ -383,7 +443,8 @@ class String < `String`
|
|
383
443
|
if (separator.length === 0) {
|
384
444
|
for (a = self.split(/(\n{2,})/), i = 0, n = a.length; i < n; i += 2) {
|
385
445
|
if (a[i] || a[i + 1]) {
|
386
|
-
|
446
|
+
var value = (a[i] || "") + (a[i + 1] || "");
|
447
|
+
Opal.yield1(block, self.$$cast(value));
|
387
448
|
}
|
388
449
|
}
|
389
450
|
|
@@ -396,10 +457,10 @@ class String < `String`
|
|
396
457
|
|
397
458
|
for (i = 0, length = splitted.length; i < length; i++) {
|
398
459
|
if (i < length - 1 || trailing) {
|
399
|
-
Opal.yield1(block, splitted[i] + separator);
|
460
|
+
Opal.yield1(block, self.$$cast(splitted[i] + separator));
|
400
461
|
}
|
401
462
|
else {
|
402
|
-
Opal.yield1(block, splitted[i]);
|
463
|
+
Opal.yield1(block, self.$$cast(splitted[i]));
|
403
464
|
}
|
404
465
|
}
|
405
466
|
}
|
@@ -426,7 +487,6 @@ class String < `String`
|
|
426
487
|
false
|
427
488
|
end
|
428
489
|
|
429
|
-
alias eql? ==
|
430
490
|
alias equal? ===
|
431
491
|
|
432
492
|
def gsub(pattern, replacement = undefined, &block)
|
@@ -438,12 +498,13 @@ class String < `String`
|
|
438
498
|
var result = '', match_data = nil, index = 0, match, _replacement;
|
439
499
|
|
440
500
|
if (pattern.$$is_regexp) {
|
441
|
-
pattern =
|
501
|
+
pattern = Opal.global_multiline_regexp(pattern);
|
442
502
|
} else {
|
443
503
|
pattern = #{Opal.coerce_to(`pattern`, String, :to_str)};
|
444
504
|
pattern = new RegExp(pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'gm');
|
445
505
|
}
|
446
506
|
|
507
|
+
var lastIndex;
|
447
508
|
while (true) {
|
448
509
|
match = pattern.exec(self);
|
449
510
|
|
@@ -456,7 +517,9 @@ class String < `String`
|
|
456
517
|
match_data = #{MatchData.new `pattern`, `match`};
|
457
518
|
|
458
519
|
if (replacement === undefined) {
|
520
|
+
lastIndex = pattern.lastIndex;
|
459
521
|
_replacement = block(match[0]);
|
522
|
+
pattern.lastIndex = lastIndex; // save and restore lastIndex
|
460
523
|
}
|
461
524
|
else if (replacement.$$is_hash) {
|
462
525
|
_replacement = #{`replacement`[`match[0]`].to_s};
|
@@ -496,7 +559,7 @@ class String < `String`
|
|
496
559
|
}
|
497
560
|
|
498
561
|
#{$~ = `match_data`}
|
499
|
-
return result;
|
562
|
+
return self.$$cast(result);
|
500
563
|
}
|
501
564
|
end
|
502
565
|
|
@@ -536,7 +599,7 @@ class String < `String`
|
|
536
599
|
}
|
537
600
|
|
538
601
|
if (search.$$is_regexp) {
|
539
|
-
regex =
|
602
|
+
regex = Opal.global_multiline_regexp(search);
|
540
603
|
while (true) {
|
541
604
|
match = regex.exec(self);
|
542
605
|
if (match === null) {
|
@@ -587,7 +650,7 @@ class String < `String`
|
|
587
650
|
end
|
588
651
|
|
589
652
|
def intern
|
590
|
-
self
|
653
|
+
`self.toString()`
|
591
654
|
end
|
592
655
|
|
593
656
|
def lines(separator = $/, &block)
|
@@ -619,7 +682,7 @@ class String < `String`
|
|
619
682
|
result += padstr;
|
620
683
|
}
|
621
684
|
|
622
|
-
return self + result.slice(0, width);
|
685
|
+
return self.$$cast(self + result.slice(0, width));
|
623
686
|
}
|
624
687
|
end
|
625
688
|
|
@@ -643,11 +706,23 @@ class String < `String`
|
|
643
706
|
pattern.match(self, pos, &block)
|
644
707
|
end
|
645
708
|
|
709
|
+
def match?(pattern, pos = undefined)
|
710
|
+
if String === pattern || pattern.respond_to?(:to_str)
|
711
|
+
pattern = Regexp.new(pattern.to_str)
|
712
|
+
end
|
713
|
+
|
714
|
+
unless Regexp === pattern
|
715
|
+
raise TypeError, "wrong argument type #{pattern.class} (expected Regexp)"
|
716
|
+
end
|
717
|
+
|
718
|
+
pattern.match?(self, pos)
|
719
|
+
end
|
720
|
+
|
646
721
|
def next
|
647
722
|
%x{
|
648
723
|
var i = self.length;
|
649
724
|
if (i === 0) {
|
650
|
-
return '';
|
725
|
+
return self.$$cast('');
|
651
726
|
}
|
652
727
|
var result = self;
|
653
728
|
var first_alphanum_char_index = self.search(/[a-zA-Z0-9]/);
|
@@ -709,7 +784,7 @@ class String < `String`
|
|
709
784
|
break;
|
710
785
|
}
|
711
786
|
}
|
712
|
-
return result;
|
787
|
+
return self.$$cast(result);
|
713
788
|
}
|
714
789
|
end
|
715
790
|
|
@@ -812,7 +887,7 @@ class String < `String`
|
|
812
887
|
|
813
888
|
if (search.$$is_regexp) {
|
814
889
|
m = null;
|
815
|
-
r =
|
890
|
+
r = Opal.global_multiline_regexp(search);
|
816
891
|
while (true) {
|
817
892
|
_m = r.exec(self);
|
818
893
|
if (_m === null || _m.index > offset) {
|
@@ -853,7 +928,7 @@ class String < `String`
|
|
853
928
|
result = Array(patterns + 1).join(padstr),
|
854
929
|
remaining = chars - result.length;
|
855
930
|
|
856
|
-
return result + padstr.slice(0, remaining) + self;
|
931
|
+
return self.$$cast(result + padstr.slice(0, remaining) + self);
|
857
932
|
}
|
858
933
|
end
|
859
934
|
|
@@ -863,7 +938,7 @@ class String < `String`
|
|
863
938
|
|
864
939
|
if (sep.$$is_regexp) {
|
865
940
|
m = null;
|
866
|
-
r =
|
941
|
+
r = Opal.global_multiline_regexp(sep);
|
867
942
|
|
868
943
|
while (true) {
|
869
944
|
_m = r.exec(self);
|
@@ -910,7 +985,7 @@ class String < `String`
|
|
910
985
|
match;
|
911
986
|
|
912
987
|
if (pattern.$$is_regexp) {
|
913
|
-
pattern =
|
988
|
+
pattern = Opal.global_multiline_regexp(pattern);
|
914
989
|
} else {
|
915
990
|
pattern = #{Opal.coerce_to(`pattern`, String, :to_str)};
|
916
991
|
pattern = new RegExp(pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'gm');
|
@@ -964,7 +1039,7 @@ class String < `String`
|
|
964
1039
|
i, ii;
|
965
1040
|
|
966
1041
|
if (pattern.$$is_regexp) {
|
967
|
-
pattern =
|
1042
|
+
pattern = Opal.global_multiline_regexp(pattern);
|
968
1043
|
} else {
|
969
1044
|
pattern = #{Opal.coerce_to(pattern, String, :to_str).to_s};
|
970
1045
|
if (pattern === ' ') {
|
@@ -978,17 +1053,24 @@ class String < `String`
|
|
978
1053
|
result = string.split(pattern);
|
979
1054
|
|
980
1055
|
if (result.length === 1 && result[0] === string) {
|
981
|
-
return result;
|
1056
|
+
return [self.$$cast(result[0])];
|
982
1057
|
}
|
983
1058
|
|
984
1059
|
while ((i = result.indexOf(undefined)) !== -1) {
|
985
1060
|
result.splice(i, 1);
|
986
1061
|
}
|
987
1062
|
|
1063
|
+
function castResult() {
|
1064
|
+
for (i = 0; i < result.length; i++) {
|
1065
|
+
result[i] = self.$$cast(result[i]);
|
1066
|
+
}
|
1067
|
+
}
|
1068
|
+
|
988
1069
|
if (limit === 0) {
|
989
1070
|
while (result[result.length - 1] === '') {
|
990
1071
|
result.length -= 1;
|
991
1072
|
}
|
1073
|
+
castResult();
|
992
1074
|
return result;
|
993
1075
|
}
|
994
1076
|
|
@@ -1000,15 +1082,18 @@ class String < `String`
|
|
1000
1082
|
result.push('');
|
1001
1083
|
}
|
1002
1084
|
}
|
1085
|
+
castResult();
|
1003
1086
|
return result;
|
1004
1087
|
}
|
1005
1088
|
|
1006
1089
|
if (match !== null && match[0] === '') {
|
1007
1090
|
result.splice(limit - 1, result.length - 1, result.slice(limit - 1).join(''));
|
1091
|
+
castResult();
|
1008
1092
|
return result;
|
1009
1093
|
}
|
1010
1094
|
|
1011
1095
|
if (limit >= result.length) {
|
1096
|
+
castResult();
|
1012
1097
|
return result;
|
1013
1098
|
}
|
1014
1099
|
|
@@ -1022,6 +1107,7 @@ class String < `String`
|
|
1022
1107
|
match = pattern.exec(string);
|
1023
1108
|
}
|
1024
1109
|
result.splice(limit - 1, result.length - 1, string.slice(index));
|
1110
|
+
castResult();
|
1025
1111
|
return result;
|
1026
1112
|
}
|
1027
1113
|
end
|
@@ -1029,13 +1115,13 @@ class String < `String`
|
|
1029
1115
|
def squeeze(*sets)
|
1030
1116
|
%x{
|
1031
1117
|
if (sets.length === 0) {
|
1032
|
-
return self.replace(/(.)\1+/g, '$1');
|
1118
|
+
return self.$$cast(self.replace(/(.)\1+/g, '$1'));
|
1033
1119
|
}
|
1034
1120
|
var char_class = char_class_from_char_sets(sets);
|
1035
1121
|
if (char_class === null) {
|
1036
1122
|
return self;
|
1037
1123
|
}
|
1038
|
-
return self.replace(new RegExp('(' + char_class + ')\\1+', 'g'), '$1');
|
1124
|
+
return self.$$cast(self.replace(new RegExp('(' + char_class + ')\\1+', 'g'), '$1'));
|
1039
1125
|
}
|
1040
1126
|
end
|
1041
1127
|
|
@@ -1064,48 +1150,53 @@ class String < `String`
|
|
1064
1150
|
pattern = new RegExp(pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'));
|
1065
1151
|
}
|
1066
1152
|
|
1067
|
-
var result = pattern.exec(self);
|
1153
|
+
var result, match = pattern.exec(self);
|
1068
1154
|
|
1069
|
-
if (
|
1155
|
+
if (match === null) {
|
1070
1156
|
#{$~ = nil}
|
1071
|
-
|
1072
|
-
}
|
1157
|
+
result = self.toString();
|
1158
|
+
} else {
|
1159
|
+
#{MatchData.new `pattern`, `match`}
|
1073
1160
|
|
1074
|
-
|
1161
|
+
if (replacement === undefined) {
|
1075
1162
|
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1080
|
-
return self.slice(0, result.index) + block(result[0]) + self.slice(result.index + result[0].length);
|
1081
|
-
}
|
1163
|
+
if (block === nil) {
|
1164
|
+
#{raise ArgumentError, 'wrong number of arguments (1 for 2)'}
|
1165
|
+
}
|
1166
|
+
result = self.slice(0, match.index) + block(match[0]) + self.slice(match.index + match[0].length);
|
1082
1167
|
|
1083
|
-
|
1084
|
-
return self.slice(0, result.index) + #{`replacement`[`result[0]`].to_s} + self.slice(result.index + result[0].length);
|
1085
|
-
}
|
1168
|
+
} else if (replacement.$$is_hash) {
|
1086
1169
|
|
1087
|
-
|
1170
|
+
result = self.slice(0, match.index) + #{`replacement`[`match[0]`].to_s} + self.slice(match.index + match[0].length);
|
1088
1171
|
|
1089
|
-
|
1090
|
-
|
1091
|
-
|
1092
|
-
|
1093
|
-
|
1094
|
-
|
1095
|
-
|
1096
|
-
if (result[i] !== undefined) {
|
1097
|
-
return slashes.slice(1) + result[i];
|
1172
|
+
} else {
|
1173
|
+
|
1174
|
+
replacement = #{Opal.coerce_to(`replacement`, String, :to_str)};
|
1175
|
+
|
1176
|
+
replacement = replacement.replace(/([\\]+)([0-9+&`'])/g, function (original, slashes, command) {
|
1177
|
+
if (slashes.length % 2 === 0) {
|
1178
|
+
return original;
|
1098
1179
|
}
|
1099
|
-
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1180
|
+
switch (command) {
|
1181
|
+
case "+":
|
1182
|
+
for (var i = match.length - 1; i > 0; i--) {
|
1183
|
+
if (match[i] !== undefined) {
|
1184
|
+
return slashes.slice(1) + match[i];
|
1185
|
+
}
|
1186
|
+
}
|
1187
|
+
return '';
|
1188
|
+
case "&": return slashes.slice(1) + match[0];
|
1189
|
+
case "`": return slashes.slice(1) + self.slice(0, match.index);
|
1190
|
+
case "'": return slashes.slice(1) + self.slice(match.index + match[0].length);
|
1191
|
+
default: return slashes.slice(1) + (match[command] || '');
|
1192
|
+
}
|
1193
|
+
}).replace(/\\\\/g, '\\');
|
1194
|
+
|
1195
|
+
result = self.slice(0, match.index) + replacement + self.slice(match.index + match[0].length);
|
1105
1196
|
}
|
1106
|
-
}
|
1197
|
+
}
|
1107
1198
|
|
1108
|
-
return self
|
1199
|
+
return self.$$cast(result);
|
1109
1200
|
}
|
1110
1201
|
end
|
1111
1202
|
|
@@ -1222,16 +1313,33 @@ class String < `String`
|
|
1222
1313
|
end
|
1223
1314
|
|
1224
1315
|
def to_proc
|
1225
|
-
|
1316
|
+
method_name = '$' + `self.valueOf()`
|
1226
1317
|
|
1227
1318
|
proc do |*args, &block|
|
1228
1319
|
%x{
|
1229
1320
|
if (args.length === 0) {
|
1230
|
-
#{raise ArgumentError,
|
1321
|
+
#{raise ArgumentError, 'no receiver given'}
|
1322
|
+
}
|
1323
|
+
|
1324
|
+
var recv = args[0];
|
1325
|
+
|
1326
|
+
if (recv == null) recv = nil;
|
1327
|
+
|
1328
|
+
var body = recv[#{method_name}];
|
1329
|
+
|
1330
|
+
if (!body) {
|
1331
|
+
return recv.$method_missing.apply(recv, args);
|
1332
|
+
}
|
1333
|
+
|
1334
|
+
if (typeof block === 'function') {
|
1335
|
+
body.$$p = block;
|
1336
|
+
}
|
1337
|
+
|
1338
|
+
if (args.length === 1) {
|
1339
|
+
return body.call(recv);
|
1340
|
+
} else {
|
1341
|
+
return body.apply(recv, args.slice(1));
|
1231
1342
|
}
|
1232
|
-
var obj = args.shift();
|
1233
|
-
if (obj == null) obj = nil;
|
1234
|
-
return Opal.send(obj, sym, args, block);
|
1235
1343
|
}
|
1236
1344
|
end
|
1237
1345
|
end
|
@@ -1384,7 +1492,7 @@ class String < `String`
|
|
1384
1492
|
new_str += (sub != null ? sub : ch);
|
1385
1493
|
}
|
1386
1494
|
}
|
1387
|
-
return new_str;
|
1495
|
+
return self.$$cast(new_str);
|
1388
1496
|
}
|
1389
1497
|
end
|
1390
1498
|
|
@@ -1546,12 +1654,12 @@ class String < `String`
|
|
1546
1654
|
}
|
1547
1655
|
}
|
1548
1656
|
}
|
1549
|
-
return new_str;
|
1657
|
+
return self.$$cast(new_str);
|
1550
1658
|
}
|
1551
1659
|
end
|
1552
1660
|
|
1553
1661
|
def upcase
|
1554
|
-
`self.toUpperCase()`
|
1662
|
+
`self.$$cast(self.toUpperCase())`
|
1555
1663
|
end
|
1556
1664
|
|
1557
1665
|
def upto(stop, excl = false, &block)
|
@@ -1698,30 +1806,23 @@ class String < `String`
|
|
1698
1806
|
end
|
1699
1807
|
|
1700
1808
|
def self._load(*args)
|
1701
|
-
|
1809
|
+
new(*args)
|
1702
1810
|
end
|
1703
1811
|
|
1704
|
-
def
|
1705
|
-
|
1706
|
-
|
1707
|
-
var i,
|
1708
|
-
singleByte,
|
1709
|
-
l = string.length,
|
1710
|
-
result = [];
|
1812
|
+
def unicode_normalize(form = undefined)
|
1813
|
+
`self.toString()`
|
1814
|
+
end
|
1711
1815
|
|
1712
|
-
|
1713
|
-
|
1714
|
-
|
1715
|
-
|
1716
|
-
|
1717
|
-
|
1718
|
-
|
1719
|
-
|
1720
|
-
|
1721
|
-
|
1722
|
-
else
|
1723
|
-
raise NotImplementedError
|
1724
|
-
end
|
1816
|
+
def unicode_normalized?(form = undefined)
|
1817
|
+
true
|
1818
|
+
end
|
1819
|
+
|
1820
|
+
def unpack(format)
|
1821
|
+
raise "To use String#unpack, you must first require 'corelib/string/unpack'."
|
1822
|
+
end
|
1823
|
+
|
1824
|
+
def unpack1(format)
|
1825
|
+
raise "To use String#unpack1, you must first require 'corelib/string/unpack'."
|
1725
1826
|
end
|
1726
1827
|
end
|
1727
1828
|
|