opal 0.7.0.beta1 → 0.7.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.gitmodules +1 -1
  4. data/.inch.yml +19 -0
  5. data/.travis.yml +10 -7
  6. data/CHANGELOG.md +23 -0
  7. data/README.md +2 -2
  8. data/Rakefile +43 -1
  9. data/bin/opal +6 -1
  10. data/lib/mspec/opal/rake_task.rb +10 -31
  11. data/lib/mspec/opal/runner.rb +44 -1
  12. data/lib/mspec/opal/special_calls.rb +25 -0
  13. data/lib/opal/builder.rb +1 -1
  14. data/lib/opal/builder_processors.rb +4 -23
  15. data/lib/opal/cli.rb +17 -11
  16. data/lib/opal/cli_options.rb +1 -1
  17. data/lib/opal/cli_runners.rb +1 -0
  18. data/lib/opal/cli_runners/apple_script.rb +65 -0
  19. data/lib/opal/cli_runners/nodejs.rb +9 -3
  20. data/lib/opal/cli_runners/phantomjs.rb +2 -2
  21. data/lib/opal/cli_runners/server.rb +7 -5
  22. data/lib/opal/compiler.rb +1 -1
  23. data/lib/opal/nodes/call.rb +3 -2
  24. data/lib/opal/nodes/constants.rb +3 -3
  25. data/lib/opal/nodes/def.rb +7 -7
  26. data/lib/opal/nodes/defined.rb +2 -2
  27. data/lib/opal/nodes/definitions.rb +1 -1
  28. data/lib/opal/nodes/literal.rb +1 -1
  29. data/lib/opal/nodes/logic.rb +1 -1
  30. data/lib/opal/nodes/masgn.rb +1 -1
  31. data/lib/opal/nodes/module.rb +1 -1
  32. data/lib/opal/nodes/rescue.rb +1 -1
  33. data/lib/opal/nodes/scope.rb +1 -1
  34. data/lib/opal/nodes/super.rb +3 -3
  35. data/lib/opal/nodes/top.rb +11 -9
  36. data/lib/opal/nodes/variables.rb +39 -6
  37. data/lib/opal/nodes/yield.rb +3 -3
  38. data/lib/opal/parser.rb +3 -1
  39. data/lib/opal/parser/lexer.rb +8 -2
  40. data/lib/opal/paths.rb +13 -3
  41. data/lib/opal/sprockets/server.rb +1 -1
  42. data/lib/opal/version.rb +1 -1
  43. data/opal.gemspec +1 -1
  44. data/opal/corelib/array.rb +29 -20
  45. data/opal/corelib/array/inheritance.rb +3 -3
  46. data/opal/corelib/basic_object.rb +3 -1
  47. data/opal/corelib/class.rb +1 -1
  48. data/opal/corelib/comparable.rb +6 -5
  49. data/opal/corelib/dir.rb +4 -4
  50. data/opal/corelib/enumerable.rb +25 -25
  51. data/opal/corelib/enumerator.rb +16 -14
  52. data/opal/corelib/error.rb +13 -4
  53. data/opal/corelib/hash.rb +511 -162
  54. data/opal/corelib/helpers.rb +1 -1
  55. data/opal/corelib/kernel.rb +60 -44
  56. data/opal/corelib/match_data.rb +1 -10
  57. data/opal/corelib/method.rb +1 -1
  58. data/opal/corelib/module.rb +62 -32
  59. data/opal/corelib/nil_class.rb +1 -6
  60. data/opal/corelib/numeric.rb +6 -3
  61. data/opal/corelib/proc.rb +1 -1
  62. data/opal/corelib/regexp.rb +15 -6
  63. data/opal/corelib/runtime.js +57 -36
  64. data/opal/corelib/string.rb +38 -2
  65. data/opal/corelib/string/inheritance.rb +3 -3
  66. data/opal/corelib/struct.rb +1 -1
  67. data/opal/corelib/time.rb +46 -3
  68. data/spec/filters/bugs/date.rb +15 -0
  69. data/spec/filters/bugs/enumerator.rb +7 -0
  70. data/spec/filters/bugs/exception.rb +12 -0
  71. data/spec/filters/bugs/hash.rb +0 -18
  72. data/spec/filters/bugs/match_data.rb +13 -0
  73. data/spec/filters/bugs/module.rb +13 -0
  74. data/spec/filters/bugs/numeric.rb +2 -0
  75. data/spec/filters/bugs/regexp.rb +0 -2
  76. data/spec/filters/bugs/stringscanner.rb +8 -0
  77. data/spec/filters/bugs/time.rb +1 -1
  78. data/spec/filters/unsupported/float.rb +1 -0
  79. data/spec/filters/unsupported/symbols.rb +10 -0
  80. data/spec/filters/unsupported/tainted.rb +3 -0
  81. data/spec/filters/unsupported/trusted.rb +3 -0
  82. data/spec/lib/compiler_spec.rb +2 -2
  83. data/spec/lib/parser/call_spec.rb +7 -0
  84. data/spec/opal/core/date_spec.rb +49 -8
  85. data/spec/opal/core/exception_spec.rb +13 -0
  86. data/spec/opal/core/fixtures/require_tree_files/nested/nested 1.rb +1 -0
  87. data/spec/opal/core/fixtures/require_tree_files/nested/nested 2.rb +1 -0
  88. data/spec/opal/core/fixtures/require_tree_files/other/other 1.rb +1 -0
  89. data/spec/opal/core/kernel/require_tree_spec.rb +3 -1
  90. data/spec/opal/core/language/predefined_spec.rb +43 -0
  91. data/spec/opal/stdlib/promise/rescue_spec.rb +9 -0
  92. data/spec/opal/stdlib/promise/then_spec.rb +9 -0
  93. data/spec/opal/stdlib/promise/trace_spec.rb +9 -0
  94. data/spec/rubyspecs +40 -19
  95. data/spec/spec_helper.rb +10 -5
  96. data/stdlib/date.rb +68 -8
  97. data/stdlib/fileutils.rb +0 -0
  98. data/stdlib/iconv.rb +0 -0
  99. data/stdlib/json.rb +16 -3
  100. data/stdlib/native.rb +36 -17
  101. data/stdlib/nodejs.rb +3 -0
  102. data/stdlib/nodejs/dir.rb +1 -1
  103. data/stdlib/nodejs/file.rb +2 -2
  104. data/stdlib/nodejs/io.rb +1 -1
  105. data/stdlib/nodejs/process.rb +2 -2
  106. data/stdlib/nodejs/require.rb +5 -7
  107. data/stdlib/nodejs/runtime.rb +3 -2
  108. data/stdlib/pathname.rb +25 -1
  109. data/stdlib/promise.rb +16 -0
  110. data/stdlib/set.rb +48 -4
  111. data/stdlib/strscan.rb +12 -1
  112. data/stdlib/yaml.rb +1 -0
  113. metadata +27 -7
  114. data/spec/opal/core/language/symbol_spec.rb +0 -40
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3d851c3be15f64dbfc7a60b48889722334c757c0
4
- data.tar.gz: e4e5a13810d7e30f2291aea3b5138e32e72ed15e
3
+ metadata.gz: a9bd47fb47cabeb742adca4e6b377de113225b60
4
+ data.tar.gz: 0dfa5e47116f8d56b3d1a2ff0b9473fa9b563b87
5
5
  SHA512:
6
- metadata.gz: 6673321f15d3acdd817b9eeeefffc87a5cd2e9d9c0a8564ab272fb6096a295415a0243f8e079f10227d4c593ebd022b2b681c17abce715de50b19ebca5c77b08
7
- data.tar.gz: 3ac4adb02d69f45cfa9396cab5814ae4b527dfbdb60b68d42a93c50dcb887d0b1d83c70d78800092e040eeb9f85235100db5b28a316bf1ba7f27c1e62c5631f9
6
+ metadata.gz: 3965105a918d9cfded13bf9526cdda32b73caa31c4ae7e3760f36c205f5cdb1e359604e9d6e4a519d0687ea0b0eced908140b54ddf952b4c7036ef0d0736a2b9
7
+ data.tar.gz: 5764370dc015b931115ab0bdb7e61b1a6699b067179545fdea0d5dd86366929e58b391726ef4257e752d5ebd33d9e9bdb316fd4f09309ec0c3ce24d28225f1b3
data/.gitignore CHANGED
@@ -8,3 +8,4 @@ build/
8
8
  /cdn
9
9
  /node_modules
10
10
  /gh-pages
11
+ /tmp
@@ -1,6 +1,6 @@
1
1
  [submodule "spec/corelib"]
2
2
  path = spec/corelib
3
- url = https://github.com/rubyspec/rubyspec
3
+ url = https://github.com/opal/rubyspec
4
4
  [submodule "spec/stdlib/rubysl-singleton"]
5
5
  path = spec/stdlib/rubysl-singleton
6
6
  url = https://github.com/rubysl/rubysl-singleton
@@ -0,0 +1,19 @@
1
+ # files:
2
+ # # define files included in the analysis (defaults to ["{app,lib}/**/*.rb"])
3
+ # included:
4
+ # - plugins/**/*.rb
5
+ # # define files excluded from the analysis (defaults to [])
6
+ # excluded:
7
+ # # you can use file paths
8
+ # - plugins/vendor/sparkr/sparkr.rb
9
+ # # or globs
10
+ # - plugins/vendor/**/*.rb
11
+ # # or regular expressions
12
+ # - !ruby/regexp /vendor/
13
+
14
+
15
+ files:
16
+ included:
17
+ - lib/**/*.rb
18
+ excluded:
19
+ - lib/opal/parser/grammar.rb
@@ -1,19 +1,23 @@
1
1
  language: ruby
2
2
 
3
- cache: bundler
3
+ cache:
4
+ bundler: true
5
+ directories:
6
+ - node_modules
4
7
 
5
8
  matrix:
6
9
  fast_finish: true
7
10
 
8
11
  include:
9
- - rvm: 2.1.1
10
- env: RUN=default
12
+ - rvm: 2.1
13
+ env: RUN=default TZ="/usr/share/zoneinfo/Pacific/Fiji"
14
+ before_install: test -d node_modules || npm install
11
15
 
12
16
  - rvm: 1.9.3
13
17
  env: RUN=rspec
14
18
 
15
19
  - rvm: 2.0.0
16
- env: RUN=rspec
20
+ env: RUN="rspec mspec"
17
21
 
18
22
  - rvm: rbx
19
23
  env: RUN=rspec
@@ -28,11 +32,10 @@ matrix:
28
32
  - rvm: rbx
29
33
  - rvm: jruby
30
34
 
31
- # Setting TimeZone. We'll need to do this in order to
32
- # have the TZ related failures surface on Travis CI.
33
- # http://stackoverflow.com/a/23374438/601782
35
+
34
36
  before_install:
35
37
  - git submodule update --init
38
+ - npm install
36
39
 
37
40
  script:
38
41
  - "bundle exec rake $RUN"
@@ -1,5 +1,26 @@
1
1
  ## edge (upcoming 0.7)
2
2
 
3
+ * Add `Set` methods `#classify`, `#collect!`, `#map!`, `#subtract` `#replace`,
4
+ `#difference` and `#eql?`
5
+
6
+ * Support `module_function` without args to toggle module functions.
7
+
8
+ * Fix bug where command calls with no space and sym arg were incorrectly parsed.
9
+
10
+ * Add some `StringScanner` methods.
11
+
12
+ * Add `Date#<<` and `Date#>>` implementations.
13
+
14
+ * Support nested directories using `require_tree` directive.
15
+
16
+ * Fix bug where Exception subclasses could not have methods defined on them.
17
+
18
+ * Fix symbols with interpolations `:"#{foo}"`
19
+
20
+ * Implement $1..N matchers and rewrite support for $~, $', $& and $\`.
21
+
22
+ * Implement `Regexp.last_match`.
23
+
3
24
  * Fixed `-@` unary op. precedence with a numeric and followed by a method call (e.g. `-1.foo` was parsed as `-(1.foo)`)
4
25
 
5
26
  * `require_relative` (with strings) is now preprocessed, expanded and added to `Compiler#requires`
@@ -21,6 +42,8 @@
21
42
 
22
43
  * Add initial support for Module#autoload.
23
44
 
45
+ * Fix `Enumerator#with_index`, `Numeric#round`.
46
+
24
47
  ## 0.6.2 2014-04-25
25
48
 
26
49
  * Added Range#size
data/README.md CHANGED
@@ -11,9 +11,9 @@ Opal is [hosted on github](http://github.com/opal/opal), and there
11
11
  is a Freenode IRC channel at [#opal](http://webchat.freenode.net/?channels=opal),
12
12
  ask questions on [stackoverflow (tag #opalrb)](http://stackoverflow.com/questions/ask?tags=opalrb).
13
13
 
14
- [![Stack Overflow](http://img.shields.io/badge/stackoverflow-%23opalrb-orange.svg?style=flat)](http://stackoverflow.com/questions/ask?tags=opalrb)
15
- [![API doc](http://img.shields.io/badge/doc-api-blue.svg?style=flat)](http://opalrb.org/docs/api)
14
+ [![Inline docs](http://inch-ci.org/github/opal/opal.svg?branch=master&style=flat)](http://opalrb.org/docs/api)
16
15
  [![Gitter chat](http://img.shields.io/badge/gitter-opal%2Fopal-009966.svg?style=flat)](https://gitter.im/opal/opal)
16
+ [![Stack Overflow](http://img.shields.io/badge/stackoverflow-%23opalrb-orange.svg?style=flat)](http://stackoverflow.com/questions/ask?tags=opalrb)
17
17
 
18
18
 
19
19
 
data/Rakefile CHANGED
@@ -18,9 +18,51 @@ MSpec::Opal::RakeTask.new(:mspec) do |config|
18
18
  config.basedir = ENV['MSPEC_BASEDIR'] if ENV['MSPEC_BASEDIR']
19
19
  end
20
20
 
21
- task :default => [:rspec, :mspec]
21
+ task :default => [:rspec, :mspec_node]
22
22
 
23
23
 
24
+ task :mspec_node do
25
+ rubyspecs = File.read('spec/rubyspecs').lines.reject do |l|
26
+ l.strip!; l.start_with?('#') || l.empty?
27
+ end.flat_map do |path|
28
+ path = "spec/#{path}"
29
+ File.directory?(path) ? Dir[path+'/*.rb'] : "#{path}.rb"
30
+ end
31
+
32
+ filters = Dir['spec/filters/**/*.rb']
33
+ shared = Dir['spec/{opal,lib/parser}/**/*_spec.rb'] + ['spec/lib/lexer_spec.rb']
34
+
35
+ specs = []
36
+ add_specs = ->(name, new_specs) { p [new_specs.size, name]; specs + new_specs}
37
+
38
+ specs = add_specs.(:filters, filters)
39
+ pattern = ENV['PATTERN']
40
+ whitelist_pattern = !!ENV['RUBYSPECS']
41
+
42
+ if pattern
43
+ custom = Dir[pattern]
44
+ custom &= rubyspecs if whitelist_pattern
45
+ specs = add_specs.(:custom, custom)
46
+ else
47
+ specs = add_specs.(:shared, shared)
48
+ specs = add_specs.(:rubyspecs, rubyspecs)
49
+ end
50
+
51
+ requires = specs.map{|s| "require '#{s.sub(/^spec\//,'')}'"}
52
+ filename = 'tmp/mspec_node.rb'
53
+ mkdir_p File.dirname(filename)
54
+ File.write filename, <<-RUBY
55
+ require 'spec_helper'
56
+ #{requires.join(" \n")}
57
+ OSpecRunner.main.did_finish
58
+ RUBY
59
+
60
+ stubs = " -smspec/helpers/tmp -smspec/helpers/environment -smspec/guards/block_device -smspec/guards/endian"
61
+
62
+ sh 'RUBYOPT="-rbundler/setup -rmspec/opal/special_calls" '\
63
+ "bin/opal -Ispec -Ilib -gmspec #{stubs} -rnodejs -Dwarning -A #{filename}"
64
+ end
65
+
24
66
  require 'opal/version'
25
67
  desc <<-DESC
26
68
  Build *corelib* and *stdlib* to "build/"
data/bin/opal CHANGED
@@ -12,10 +12,15 @@ rescue OptionParser::InvalidOption => e
12
12
  end
13
13
 
14
14
  require 'opal/cli'
15
- cli = Opal::CLI.new options.options.merge(:file => ARGF.file, :argv => ARGV.dup)
15
+ cli = Opal::CLI.new options.options.merge(
16
+ file: ARGF.file,
17
+ filename: ARGF.filename,
18
+ argv: ARGV.dup
19
+ )
16
20
 
17
21
  begin
18
22
  cli.run
23
+ exit cli.exit_status || 0
19
24
  rescue Opal::CliRunners::RunnerError => e
20
25
  $stderr.puts e.message
21
26
  exit 72
@@ -1,30 +1,6 @@
1
- require 'opal/nodes'
2
- class Opal::Nodes::CallNode
3
- # Rubyspec uses this call to load in language specific features at runtime.
4
- # We can't do this at runtime, so handle it during compilation
5
- add_special :language_version do
6
- if meth == :language_version and scope.top?
7
- lang_type = arglist[2][1]
8
- target = "corelib/language/versions/#{lang_type}_1.9"
9
-
10
- if File.exist?(target)
11
- compiler.requires << target
12
- end
13
-
14
- push fragment("nil")
15
- end
16
- end
17
-
18
- add_special :not_supported_on do
19
- unless meth == :not_supported_on and arglist[1][1] == :opal
20
- compile_default!
21
- end
22
- end
23
- end
24
-
25
-
26
1
  require 'rack'
27
2
  require 'webrick'
3
+ require 'mspec/opal/special_calls'
28
4
 
29
5
  module MSpec
30
6
  module Opal
@@ -117,7 +93,7 @@ module MSpec
117
93
  end
118
94
  end
119
95
 
120
- class Environment < ::Opal::Environment
96
+ class Environment < ::Sprockets::Environment
121
97
  attr_reader :basedir, :pattern
122
98
 
123
99
  def initialize(basedir = nil, pattern = nil)
@@ -137,6 +113,8 @@ module MSpec
137
113
  ENV['OPAL_SPEC'] ||= files_to_run(pattern).join(',')
138
114
 
139
115
  super()
116
+
117
+ ::Opal.paths.each { |p| append_path p }
140
118
  end
141
119
 
142
120
  def stubs
@@ -205,16 +183,17 @@ module MSpec
205
183
 
206
184
  if pattern
207
185
  # add custom opal specs from spec/
208
- add_files paths_from_glob(pattern) & rubyspec_white_list, :rubyspec_custom_pattern
209
- add_files paths_from_glob(pattern).grep(/(?!spec\/(corelib|stdlib)\/)/), :other_custom_pattern
186
+ add_files paths_from_glob(pattern) & rubyspec_white_list, :rubyspec_custom
187
+ add_files paths_from_glob(pattern).grep(/(?!spec\/(corelib|stdlib)\/)/), :other_custom
210
188
 
211
189
  else
212
190
  # add opal specific specs
213
- add_files paths_from_glob("#{basedir}/opal/**/*_spec.rb"), 'opal/*'
214
- add_files paths_from_glob("#{basedir}/lib/{lexer_spec.rb,parser/**/*_spec.rb}"), 'lib/{lexer,parser}'
191
+ add_files paths_from_glob("#{basedir}/opal/**/*_spec.rb"), :shared
192
+ add_files paths_from_glob("#{basedir}/lib/lexer_spec.rb"), :lexer
193
+ add_files paths_from_glob("#{basedir}/lib/parser/**/*_spec.rb"), :parser
215
194
 
216
195
  # add any rubyspecs we want to run (defined in spec/rubyspecs)
217
- add_files rubyspec_white_list, :rubyspec_white_list
196
+ add_files rubyspec_white_list, :rubyspecs
218
197
  end
219
198
  end
220
199
 
@@ -107,6 +107,7 @@ class BrowserFormatter
107
107
  @exceptions.each_with_index do |exception, idx|
108
108
  log "\n #{idx + 1}. #{exception.description}"
109
109
  red "\n #{exception.message}"
110
+ log "\n #{`#{exception.exception}.stack`}\n"
110
111
  end
111
112
 
112
113
  log "\nFinished"
@@ -144,13 +145,55 @@ class PhantomFormatter < BrowserFormatter
144
145
  end
145
146
  end
146
147
 
147
- class PhantomDebugFormatter < PhantomFormatter
148
+ class NodeJSFormatter < BrowserFormatter
149
+ def green(str)
150
+ `process.stdout.write("\033[32m"+#{str}+"\033[0m")`
151
+ end
152
+
153
+ def red(str)
154
+ `process.stdout.write("\033[31m"+#{str}+"\033[0m")`
155
+ end
156
+
157
+ def log(str)
158
+ puts str
159
+ end
160
+
161
+ def after(state)
162
+ super
163
+ print_example(state)
164
+ end
165
+
166
+ def print_example(state)
167
+ unless exception?
168
+ green('.')
169
+ else
170
+ red(failure? ? 'F' : 'E')
171
+ end
172
+ end
173
+
174
+ def finish_with_code(code)
175
+ `global.OPAL_SPEC_CODE = code;`
176
+ end
177
+
178
+ def finish_with_code(code)
179
+ puts "\n\n"
180
+ exit(code)
181
+ end
182
+ end
183
+
184
+ class PhantomDocFormatter < PhantomFormatter
148
185
  def after(state = nil)
149
186
  (@exception && state) ? red(state.description) : green(state.description)
150
187
  super
151
188
  end
152
189
  end
153
190
 
191
+ class NodeJSDocFormatter < NodeJSFormatter
192
+ def print_example(state)
193
+ (@exception && state) ? red(state.description+"\n") : green(state.description+"\n")
194
+ end
195
+ end
196
+
154
197
  module MSpec
155
198
  def self.opal_runner
156
199
  @env = Object.new
@@ -0,0 +1,25 @@
1
+ require 'opal/nodes'
2
+ class Opal::Nodes::CallNode
3
+ # Rubyspec uses this call to load in language specific features at runtime.
4
+ # We can't do this at runtime, so handle it during compilation
5
+ add_special :language_version do
6
+ if meth == :language_version and scope.top?
7
+ lang_type = arglist[2][1]
8
+ target = "corelib/language/versions/#{lang_type}_1.9"
9
+
10
+ if File.exist?(target)
11
+ compiler.requires << target
12
+ end
13
+
14
+ push fragment("nil")
15
+ end
16
+ end
17
+
18
+ add_special :not_supported_on do
19
+ unless meth == :not_supported_on and arglist[1][1] == :opal
20
+ compile_default!
21
+ end
22
+ end
23
+ end
24
+
25
+
@@ -76,7 +76,7 @@ module Opal
76
76
  base = paths.find { |p| expanded.start_with?(p) }
77
77
  next [] if base.nil?
78
78
 
79
- globs = extensions.map { |ext| File.join base, tree, "*.#{ext}" }
79
+ globs = extensions.map { |ext| File.join base, tree, '**', "*.#{ext}" }
80
80
 
81
81
  Dir[*globs].map do |file|
82
82
  Pathname(file).relative_path_from(Pathname(base)).to_s.gsub(/(\.js)?(\.(?:#{extensions.join '|'}))$/, '')
@@ -110,7 +110,7 @@ module Opal
110
110
  end
111
111
  end
112
112
 
113
- class ERBProcessor < RubyProcessor
113
+ class OpalERBProcessor < RubyProcessor
114
114
  handles :opalerb
115
115
 
116
116
  def initialize(*args)
@@ -134,31 +134,12 @@ module Opal
134
134
  end
135
135
  end
136
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
137
+ class ERBProcessor < Processor
158
138
  handles :erb
159
139
 
160
140
  def source
161
- "Opal.modules[#{@filename.inspect}] = function() {#{::ERB.new(@source.to_s).result}};"
141
+ result = ::ERB.new(@source.to_s).result
142
+ "Opal.modules[#{@filename.inspect}] = function() {#{result}};"
162
143
  end
163
144
  end
164
145
  end
@@ -6,7 +6,8 @@ require 'opal/cli_runners'
6
6
  module Opal
7
7
  class CLI
8
8
  attr_reader :options, :file, :compiler_options, :evals, :load_paths, :argv,
9
- :output, :requires, :gems, :stubs, :verbose, :port, :preload
9
+ :output, :requires, :gems, :stubs, :verbose, :port, :preload,
10
+ :filename
10
11
 
11
12
  def compile?
12
13
  @compile
@@ -44,9 +45,10 @@ module Opal
44
45
  @preload = options.delete(:preload) || []
45
46
  @output = options.delete(:output) || self.class.stdout || $stdout
46
47
  @verbose = options.fetch(:verbose, false); options.delete(:verbose)
48
+ @filename = options.fetch(:filename) { @file && @file.path }; options.delete(:filename)
47
49
  @skip_opal_require = options.delete(:skip_opal_require)
48
50
  @compiler_options = Hash[
49
- *processor_option_names.map do |option|
51
+ *compiler_option_names.map do |option|
50
52
  key = option.to_sym
51
53
  next unless options.has_key? key
52
54
  value = options.delete(key)
@@ -68,17 +70,21 @@ module Opal
68
70
 
69
71
  def runner
70
72
  @runner ||= case @runner_type
71
- when :server; CliRunners::Server.new(output, port)
72
- when :nodejs; CliRunners::Nodejs.new(output)
73
- when :phantomjs; CliRunners::Phantomjs.new(output)
73
+ when :server; CliRunners::Server.new(output, port)
74
+ when :nodejs; CliRunners::Nodejs.new(output)
75
+ when :phantomjs; CliRunners::Phantomjs.new(output)
76
+ when :applescript; CliRunners::AppleScript.new(output)
74
77
  else raise ArgumentError, @runner_type.inspect
75
78
  end
76
79
  end
77
80
 
78
81
  def run_code
79
82
  runner.run(compiled_source, argv)
83
+ @exit_status = runner.exit_status
80
84
  end
81
85
 
86
+ attr_reader :exit_status
87
+
82
88
  def compiled_source
83
89
  Opal.paths.concat load_paths
84
90
  gems.each { |gem_name| Opal.use_gem gem_name }
@@ -91,14 +97,14 @@ module Opal
91
97
 
92
98
  # REQUIRES: -r
93
99
  requires.each do |local_require|
94
- builder.build_str("require #{local_require.inspect}", 'require')
100
+ builder.build(local_require)
95
101
  end
96
102
 
97
103
  if evals.any?
98
104
  builder.build_str(evals.join("\n"), '-e')
99
105
  else
100
- if file and (file.path != '-' or evals.empty?)
101
- builder.build_str(file.read, file.path)
106
+ if file and (filename != '-' or evals.empty?)
107
+ builder.build_str(file.read, filename)
102
108
  end
103
109
  end
104
110
 
@@ -126,10 +132,10 @@ module Opal
126
132
  compiler.source_map
127
133
  end
128
134
 
129
- def processor_option_names
135
+ def compiler_option_names
130
136
  %w[
131
- method_missing_enabled
132
- arity_check_enabled
137
+ method_missing
138
+ arity_check
133
139
  dynamic_require_severity
134
140
  source_map_enabled
135
141
  irb_enabled