Class: Js2coffee::JsCompiler
Class Method Summary
collapse
Methods inherited from Compiler
compile, compile_file, source, source=
Class Method Details
.compiler ⇒ Object
27
28
29
|
# File 'lib/js2coffee/js_compiler.rb', line 27
def compiler
@coffee ||= ExecJS.compile("var window = {}; #{source}")
end
|
.watch_file(file) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/js2coffee/js_compiler.rb', line 31
def watch_file(file)
file_path = Pathname(file)
source_code = file_path.read
target_file, target_map = Js2coffee::PathHelper.new(file_path).create_target_path!
result = compiler.call(wrapper, source_code)
target_file.write(result['code'])
target_map.write(result['sourceMap'])
puts "[1m[32m==>[0m #{target_file}"
target_file
rescue ExecJS::RuntimeError
error_msg = "[#{file_path}]: #{$!.message}"
`notify-send "#{error_msg}" -t 5000` if system 'which notify-send &>/dev/null'
puts error_msg
end
|
.wrapper ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/js2coffee/js_compiler.rb', line 9
def wrapper
<<-WRAPPER
(function(script, options) {
try {
var result;
result = window.js2coffee.build(script, options);
return {code: result.code, sourceMap: result.map, warnings: result.warnings};
} catch (err) {
if (err instanceof SyntaxError && err.location) {
throw new SyntaxError([options.filename, err.location.first_line + 1, err.location.first_column + 1].join(":") + ": " + err.message)
} else {
throw err;
}
}
})
WRAPPER
end
|