opal 0.6.3 → 0.7.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/.spectator +2 -0
- data/.spectator-mspec +3 -0
- data/.travis.yml +8 -11
- data/CHANGELOG.md +33 -0
- data/CONTRIBUTING.md +8 -43
- data/Gemfile +15 -4
- data/Guardfile +77 -0
- data/README.md +15 -9
- data/Rakefile +36 -12
- data/benchmarks/operators.rb +11 -0
- data/bin/opal +10 -13
- data/bin/opal-build +4 -4
- data/bin/opal-mspec +10 -0
- data/bin/opal-repl +4 -3
- data/examples/sinatra/Gemfile +1 -1
- data/examples/sinatra/config.ru +3 -3
- data/lib/mspec/opal/main.rb.erb +2 -2
- data/lib/mspec/opal/rake_task.rb +31 -24
- data/lib/mspec/opal/runner.rb +18 -1
- data/lib/mspec/opal/sprockets.js +17 -0
- data/lib/opal.rb +1 -34
- data/lib/opal/builder.rb +92 -58
- data/lib/opal/builder_processors.rb +165 -0
- data/lib/opal/cli.rb +85 -144
- data/lib/opal/cli_options.rb +136 -90
- 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 +35 -16
- data/lib/opal/erb.rb +29 -15
- data/lib/opal/hike_path_finder.rb +18 -0
- data/lib/opal/nodes.rb +1 -0
- data/lib/opal/nodes/call.rb +107 -26
- data/lib/opal/nodes/call_special.rb +31 -6
- data/lib/opal/nodes/class.rb +2 -2
- data/lib/opal/nodes/constants.rb +5 -20
- data/lib/opal/nodes/def.rb +4 -4
- data/lib/opal/nodes/defined.rb +3 -3
- data/lib/opal/nodes/definitions.rb +1 -1
- data/lib/opal/nodes/for.rb +35 -0
- data/lib/opal/nodes/helpers.rb +2 -2
- data/lib/opal/nodes/iter.rb +3 -3
- data/lib/opal/nodes/literal.rb +10 -2
- data/lib/opal/nodes/masgn.rb +2 -2
- data/lib/opal/nodes/module.rb +2 -2
- data/lib/opal/nodes/scope.rb +1 -0
- data/lib/opal/nodes/singleton_class.rb +2 -2
- data/lib/opal/nodes/super.rb +2 -2
- data/lib/opal/nodes/top.rb +30 -3
- data/lib/opal/parser.rb +15 -1
- data/lib/opal/parser/grammar.rb +2571 -2452
- data/lib/opal/parser/grammar.y +37 -5
- data/lib/opal/parser/keywords.rb +2 -0
- data/lib/opal/parser/lexer.rb +21 -11
- data/lib/opal/path_reader.rb +28 -0
- data/lib/opal/paths.rb +38 -0
- data/lib/opal/source_map.rb +32 -15
- data/lib/opal/sprockets/environment.rb +9 -2
- data/lib/opal/sprockets/erb.rb +1 -2
- data/lib/opal/sprockets/path_reader.rb +34 -0
- data/lib/opal/sprockets/processor.rb +40 -39
- data/lib/opal/sprockets/server.rb +47 -33
- data/lib/opal/version.rb +1 -1
- data/opal.gemspec +10 -5
- data/opal/README.md +6 -0
- data/opal/corelib/array.rb +36 -4
- data/opal/corelib/array/inheritance.rb +6 -6
- data/opal/corelib/basic_object.rb +9 -9
- data/opal/corelib/boolean.rb +1 -1
- data/opal/corelib/class.rb +12 -12
- data/opal/corelib/dir.rb +20 -0
- data/opal/corelib/enumerable.rb +42 -42
- data/opal/corelib/enumerator.rb +1 -1
- data/opal/corelib/error.rb +2 -2
- data/opal/corelib/file.rb +56 -0
- data/opal/corelib/hash.rb +5 -5
- data/opal/corelib/helpers.rb +3 -3
- data/opal/corelib/io.rb +13 -10
- data/opal/corelib/kernel.rb +44 -68
- data/opal/corelib/method.rb +1 -1
- data/opal/corelib/module.rb +89 -114
- data/opal/corelib/nil_class.rb +1 -1
- data/opal/corelib/numeric.rb +27 -23
- data/opal/corelib/proc.rb +5 -5
- data/opal/corelib/range.rb +8 -4
- data/opal/corelib/regexp.rb +5 -5
- data/opal/corelib/runtime.js +589 -272
- data/opal/corelib/string.rb +52 -37
- data/opal/corelib/string/inheritance.rb +5 -5
- data/opal/corelib/time.rb +102 -52
- data/opal/corelib/variables.rb +3 -3
- data/opal/opal.rb +2 -0
- data/package.json +9 -0
- data/spec/filters/bugs/array.rb +0 -6
- data/spec/filters/bugs/language.rb +4 -0
- data/spec/filters/bugs/numeric.rb +7 -6
- data/spec/filters/bugs/opal.rb +2 -0
- data/spec/filters/bugs/regexp.rb +4 -0
- data/spec/filters/bugs/string.rb +0 -7
- data/spec/filters/bugs/stringscanner.rb +4 -1
- data/spec/filters/unsupported/private_methods.rb +2 -0
- data/spec/lib/builder_processors_spec.rb +27 -0
- data/spec/lib/builder_spec.rb +66 -0
- data/spec/{cli → lib}/cli_spec.rb +60 -5
- data/spec/{cli → lib}/compiler_spec.rb +66 -5
- data/spec/{cli → lib}/dependency_resolver_spec.rb +1 -1
- data/spec/lib/fixtures/no_requires.rb +1 -0
- data/spec/{cli → lib}/fixtures/opal_file.rb +0 -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/{cli → lib}/fixtures/sprockets_file.js.rb +0 -0
- data/spec/lib/fixtures/sprockets_require_tree_test.rb +3 -0
- data/spec/lib/hike_path_finder_spec.rb +23 -0
- data/spec/{cli → lib}/lexer_spec.rb +1 -1
- data/spec/{cli → lib}/parser/alias_spec.rb +1 -1
- data/spec/{cli → lib}/parser/and_spec.rb +1 -1
- data/spec/{cli → lib}/parser/attrasgn_spec.rb +1 -1
- data/spec/{cli → lib}/parser/begin_spec.rb +1 -1
- data/spec/{cli → lib}/parser/block_spec.rb +1 -1
- data/spec/{cli → lib}/parser/break_spec.rb +1 -1
- data/spec/{cli → lib}/parser/call_spec.rb +1 -1
- data/spec/{cli → lib}/parser/class_spec.rb +1 -1
- data/spec/{cli → lib}/parser/comments_spec.rb +1 -1
- data/spec/{cli → lib}/parser/def_spec.rb +1 -1
- data/spec/{cli → lib}/parser/if_spec.rb +1 -1
- data/spec/{cli → lib}/parser/iter_spec.rb +1 -1
- data/spec/{cli → lib}/parser/lambda_spec.rb +1 -1
- data/spec/{cli → lib}/parser/literal_spec.rb +1 -1
- data/spec/{cli → lib}/parser/masgn_spec.rb +1 -1
- data/spec/{cli → lib}/parser/module_spec.rb +1 -1
- data/spec/{cli → lib}/parser/not_spec.rb +1 -1
- data/spec/{cli → lib}/parser/op_asgn1_spec.rb +1 -1
- data/spec/{cli → lib}/parser/op_asgn2_spec.rb +1 -1
- data/spec/{cli → lib}/parser/or_spec.rb +1 -1
- data/spec/{cli → lib}/parser/return_spec.rb +1 -1
- data/spec/{cli → lib}/parser/sclass_spec.rb +1 -1
- data/spec/{cli → lib}/parser/string_spec.rb +8 -1
- data/spec/{cli → lib}/parser/super_spec.rb +1 -1
- data/spec/lib/parser/unary_spec.rb +48 -0
- data/spec/{cli → lib}/parser/undef_spec.rb +1 -1
- data/spec/{cli → lib}/parser/unless_spec.rb +1 -1
- data/spec/{cli → lib}/parser/variables_spec.rb +1 -1
- data/spec/{cli → lib}/parser/while_spec.rb +1 -1
- data/spec/{cli → lib}/parser/yield_spec.rb +1 -1
- 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/{cli → lib}/sprockets/erb_spec.rb +1 -1
- data/spec/lib/sprockets/path_reader_spec.rb +25 -0
- data/spec/{cli → lib}/sprockets/processor_spec.rb +9 -2
- data/spec/lib/sprockets/server_spec.rb +20 -0
- data/spec/opal/compiler/irb_spec.rb +11 -11
- 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/require_tree_spec.rb +7 -0
- data/spec/opal/core/kernel/respond_to_spec.rb +2 -2
- data/spec/opal/core/runtime/method_missing_spec.rb +19 -0
- data/spec/opal/core/source_map_spec.rb +2 -2
- data/spec/opal/core/string_spec.rb +11 -0
- data/spec/opal/stdlib/erb/erb_spec.rb +0 -1
- 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 +54 -11
- data/spec/spec_helper.rb +18 -3
- data/spec/support/mspec_rspec_adapter.rb +33 -0
- data/spec/{cli/spec_helper.rb → support/parser_helpers.rb} +10 -10
- data/stdlib/README.md +3 -0
- data/stdlib/benchmark.rb +10 -0
- data/stdlib/date.rb +2 -2
- data/stdlib/dir.rb +1 -5
- data/stdlib/file.rb +1 -7
- data/stdlib/json.rb +10 -1
- data/stdlib/native.rb +5 -5
- 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/opal-parser.rb +1 -2
- data/stdlib/opal-source-maps.rb +2 -0
- data/stdlib/phantomjs.rb +8 -0
- data/stdlib/process.rb +10 -0
- data/stdlib/promise.rb +12 -4
- data/stdlib/set.rb +27 -0
- data/stdlib/source_map.rb +5 -63
- 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 +77 -101
- data/stdlib/sourcemap.rb +1 -0
- data/stdlib/strscan.rb +7 -1
- data/stdlib/template.rb +1 -1
- data/stdlib/thread.rb +147 -7
- metadata +238 -104
- data/lib/mspec/opal/mspec_fixes.rb +0 -87
- data/spec/cli/sprockets/environment_spec.rb +0 -14
- data/spec/filters/bugs/symbol.rb +0 -5
- data/spec/opal/core/kernel/warn_spec.rb +0 -83
- data/spec/opal/core/language/numbers_spec.rb +0 -60
- data/stdlib/opal-source-maps.js.erb +0 -2
- data/stdlib/source_map/generator.rb +0 -251
- data/stdlib/source_map/parser.rb +0 -102
@@ -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
|
data/lib/opal/cli.rb
CHANGED
@@ -1,10 +1,24 @@
|
|
1
1
|
require 'opal'
|
2
2
|
require 'rack'
|
3
|
+
require 'opal/builder'
|
4
|
+
require 'opal/cli_runners'
|
3
5
|
|
4
6
|
module Opal
|
5
7
|
class CLI
|
6
|
-
attr_reader :options, :
|
7
|
-
|
8
|
+
attr_reader :options, :file, :compiler_options, :evals, :load_paths, :argv,
|
9
|
+
:output, :requires, :gems, :stubs, :verbose, :port, :preload
|
10
|
+
|
11
|
+
def compile?
|
12
|
+
@compile
|
13
|
+
end
|
14
|
+
|
15
|
+
def sexp?
|
16
|
+
@sexp
|
17
|
+
end
|
18
|
+
|
19
|
+
def skip_opal_require?
|
20
|
+
@skip_opal_require
|
21
|
+
end
|
8
22
|
|
9
23
|
class << self
|
10
24
|
attr_accessor :stdout
|
@@ -12,193 +26,120 @@ module Opal
|
|
12
26
|
|
13
27
|
def initialize options = nil
|
14
28
|
options ||= {}
|
29
|
+
|
30
|
+
# Runner
|
31
|
+
@runner_type = options.delete(:runner) || :nodejs
|
32
|
+
@port = options.delete(:port) || 3000
|
33
|
+
|
15
34
|
@options = options
|
16
|
-
@
|
17
|
-
@
|
18
|
-
@
|
19
|
-
@
|
20
|
-
@
|
21
|
-
|
35
|
+
@compile = !!options.delete(:compile)
|
36
|
+
@sexp = options.delete(:sexp)
|
37
|
+
@file = options.delete(:file)
|
38
|
+
@argv = options.delete(:argv) || []
|
39
|
+
@evals = options.delete(:evals) || []
|
40
|
+
@requires = options.delete(:requires) || []
|
41
|
+
@load_paths = options.delete(:load_paths) || []
|
42
|
+
@gems = options.delete(:gems) || []
|
43
|
+
@stubs = options.delete(:stubs) || []
|
44
|
+
@preload = options.delete(:preload) || []
|
45
|
+
@output = options.delete(:output) || self.class.stdout || $stdout
|
46
|
+
@verbose = options.fetch(:verbose, false); options.delete(:verbose)
|
47
|
+
@skip_opal_require = options.delete(:skip_opal_require)
|
48
|
+
@compiler_options = Hash[
|
49
|
+
*processor_option_names.map do |option|
|
50
|
+
key = option.to_sym
|
51
|
+
next unless options.has_key? key
|
52
|
+
value = options.delete(key)
|
53
|
+
[key, value]
|
54
|
+
end.compact.flatten
|
55
|
+
]
|
56
|
+
|
57
|
+
raise ArgumentError, "no runnable code provided (evals or file)" if @evals.empty? and @file.nil?
|
58
|
+
raise ArgumentError, "unknown options: #{options.inspect}" unless @options.empty?
|
22
59
|
end
|
23
60
|
|
24
61
|
def run
|
25
|
-
set_processor_options
|
26
|
-
|
27
62
|
case
|
28
|
-
when
|
29
|
-
when
|
30
|
-
|
31
|
-
else run_code
|
63
|
+
when sexp?; show_sexp
|
64
|
+
when compile?; show_compiled_source
|
65
|
+
else run_code
|
32
66
|
end
|
33
67
|
end
|
34
68
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
full_path = nil
|
43
|
-
_path = paths.find do |path|
|
44
|
-
full_path = File.join(path, filename)
|
45
|
-
File.exist? full_path
|
46
|
-
end
|
47
|
-
full_path or raise(ArgumentError, "file: #{filename} not found")
|
48
|
-
end
|
69
|
+
def runner
|
70
|
+
@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)
|
74
|
+
else raise ArgumentError, @runner_type.inspect
|
75
|
+
end
|
49
76
|
end
|
50
77
|
|
51
78
|
def run_code
|
79
|
+
runner.run(compiled_source, argv)
|
80
|
+
end
|
81
|
+
|
82
|
+
def compiled_source
|
52
83
|
Opal.paths.concat load_paths
|
53
|
-
|
54
|
-
builder = Opal::Builder.new
|
55
|
-
full_source = builder.build('opal')
|
56
|
-
|
57
|
-
require 'pathname'
|
58
|
-
requires.each do |path|
|
59
|
-
path = Pathname(path)
|
60
|
-
path = Pathname(path_finder.find(path)) unless path.absolute?
|
61
|
-
full_source << builder.build_str(path.read, :file => path.to_s)
|
62
|
-
end
|
84
|
+
gems.each { |gem_name| Opal.use_gem gem_name }
|
63
85
|
|
64
|
-
|
65
|
-
full_source << builder.build_str(code, :file => "(eval #{index+1})")
|
66
|
-
end
|
86
|
+
builder = Opal::Builder.new stubs: stubs, compiler_options: compiler_options
|
67
87
|
|
68
|
-
|
69
|
-
full_source << builder.build_str(file.read, :file => file.to_s) if file.exist?
|
88
|
+
builder.build 'opal' unless skip_opal_require?
|
70
89
|
|
71
|
-
|
72
|
-
end
|
90
|
+
preload.each { |path| builder.build_require(path) }
|
73
91
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
stdin, stdout, stderr = Open3.popen3('node')
|
78
|
-
rescue Errno::ENOENT
|
79
|
-
raise MissingNodeJS, 'Please install Node.js to be able to run Opal scripts.'
|
92
|
+
# REQUIRES: -r
|
93
|
+
requires.each do |local_require|
|
94
|
+
builder.build_str("require #{local_require.inspect}", 'require')
|
80
95
|
end
|
81
96
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
97
|
+
if evals.any?
|
98
|
+
builder.build_str(evals.join("\n"), '-e')
|
99
|
+
else
|
100
|
+
if file and (file.path != '-' or evals.empty?)
|
101
|
+
builder.build_str(file.read, file.path)
|
102
|
+
end
|
88
103
|
end
|
89
|
-
end
|
90
104
|
|
91
|
-
|
92
|
-
end
|
93
|
-
|
94
|
-
def start_server
|
95
|
-
require 'rack'
|
96
|
-
require 'webrick'
|
97
|
-
require 'logger'
|
98
|
-
|
99
|
-
Rack::Server.start(
|
100
|
-
:app => server,
|
101
|
-
:Port => options[:port] || 3000,
|
102
|
-
:AccessLog => [],
|
103
|
-
:Logger => Logger.new($stdout)
|
104
|
-
)
|
105
|
+
builder.to_s
|
105
106
|
end
|
106
107
|
|
107
108
|
def show_compiled_source
|
108
|
-
|
109
|
-
puts sprockets[filename].to_a.last
|
110
|
-
elsif File.exist?(filename)
|
111
|
-
puts Opal.compile File.read(filename), options
|
112
|
-
else
|
113
|
-
puts Opal.compile(filename, options)
|
114
|
-
end
|
109
|
+
puts compiled_source
|
115
110
|
end
|
116
111
|
|
117
112
|
def show_sexp
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
def set_processor_options
|
126
|
-
processor_options.each do |option|
|
127
|
-
key = option.to_sym
|
128
|
-
next unless options.has_key? key
|
129
|
-
Opal::Processor.send("#{option}=", options[key])
|
113
|
+
if evals.any?
|
114
|
+
sexp = Opal::Parser.new.parse(evals.join("\n"), '-e')
|
115
|
+
else
|
116
|
+
if file and (file.path != '-' or evals.empty?)
|
117
|
+
sexp = Opal::Parser.new.parse(file.read, file.path)
|
118
|
+
end
|
130
119
|
end
|
120
|
+
puts sexp.inspect
|
131
121
|
end
|
132
122
|
|
133
123
|
def map
|
134
|
-
compiler = Opal::Compiler.
|
135
|
-
compiler.compile
|
124
|
+
compiler = Opal::Compiler.compile(file.read, options.merge(:file => file.path))
|
125
|
+
compiler.compile
|
136
126
|
compiler.source_map
|
137
127
|
end
|
138
128
|
|
139
|
-
def
|
140
|
-
File.exist?(filename) ? File.read(filename) : filename
|
141
|
-
end
|
142
|
-
|
143
|
-
def processor_options
|
129
|
+
def processor_option_names
|
144
130
|
%w[
|
145
131
|
method_missing_enabled
|
146
132
|
arity_check_enabled
|
147
|
-
const_missing_enabled
|
148
133
|
dynamic_require_severity
|
149
134
|
source_map_enabled
|
150
135
|
irb_enabled
|
136
|
+
inline_operators
|
151
137
|
]
|
152
138
|
end
|
153
139
|
|
154
|
-
##
|
155
|
-
# SPROCKETS
|
156
|
-
|
157
|
-
def sprockets
|
158
|
-
server.sprockets
|
159
|
-
end
|
160
|
-
|
161
|
-
def server
|
162
|
-
@server ||= Opal::Server.new do |s|
|
163
|
-
load_paths.each do |path|
|
164
|
-
s.append_path path
|
165
|
-
end
|
166
|
-
s.main = File.basename(filename, '.rb')
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
##
|
171
|
-
# OUTPUT
|
172
|
-
|
173
140
|
def puts(*args)
|
174
141
|
output.puts(*args)
|
175
142
|
end
|
176
143
|
|
177
|
-
##
|
178
|
-
# EVALS
|
179
|
-
|
180
|
-
def evals_source
|
181
|
-
evals.inject('', &:<<)
|
182
|
-
end
|
183
|
-
|
184
|
-
def prepare_eval_code
|
185
|
-
if evals.any?
|
186
|
-
require 'tmpdir'
|
187
|
-
path = File.join(Dir.mktmpdir,"opal-#{$$}.js.rb")
|
188
|
-
File.open(path, 'w') do |tempfile|
|
189
|
-
load_paths << File.dirname(path)
|
190
|
-
tempfile.puts 'require "opal"'
|
191
|
-
tempfile.puts evals_source
|
192
|
-
end
|
193
|
-
@filename = File.basename(path)
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
##
|
198
|
-
# SOURCE
|
199
|
-
|
200
|
-
def sexp
|
201
|
-
Opal::Parser.new.parse(source)
|
202
|
-
end
|
203
144
|
end
|
204
145
|
end
|