jsc 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.bnsignore +18 -0
- data/.gitignore +23 -3
- data/History.txt +14 -0
- data/LICENSE +20 -0
- data/README.rdoc +15 -27
- data/Rakefile +46 -20
- data/TODO.org +5 -11
- data/VERSION +1 -0
- data/bin/jsc +18 -6
- data/features/run_command.feature +67 -0
- data/features/support/env.rb +8 -0
- data/lib/jsc.rb +1 -1
- data/lib/jsc/closure_compiler.rb +48 -26
- data/lib/jsc/parser.rb +75 -0
- data/spec/jsc_spec.rb +7 -7
- metadata +39 -44
- data/js/extra/alcadialer_im.js +0 -559
- data/js/extra/strophe.js +0 -3543
- data/jsc.gemspec +0 -66
- data/rdoc/classes/JSCompiler.html +0 -649
- data/rdoc/classes/String.html +0 -118
- data/rdoc/created.rid +0 -1
- data/rdoc/files/README_rdoc.html +0 -234
- data/rdoc/files/lib/jsc/closure_compiler_rb.html +0 -151
- data/rdoc/files/lib/jsc_rb.html +0 -101
- data/rdoc/fr_class_index.html +0 -28
- data/rdoc/fr_file_index.html +0 -29
- data/rdoc/fr_method_index.html +0 -38
- data/rdoc/index.html +0 -26
- data/rdoc/rdoc-style.css +0 -208
- data/tmp/aruba/js/compiled_code.js +0 -4
- data/tmp/aruba/js/errors.js +0 -4
- data/tmp/aruba/js/warnings.js +0 -5
data/.bnsignore
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# The list of files that should be ignored by Mr Bones.
|
2
|
+
# Lines that start with '#' are comments.
|
3
|
+
#
|
4
|
+
# A .gitignore file can be used instead by setting it as the ignore
|
5
|
+
# file in your Rakefile:
|
6
|
+
#
|
7
|
+
# Bones {
|
8
|
+
# ignore_file '.gitignore'
|
9
|
+
# }
|
10
|
+
#
|
11
|
+
# For a project with a C extension, the following would be a good set of
|
12
|
+
# exclude patterns (uncomment them if you want to use them):
|
13
|
+
# *.[oa]
|
14
|
+
# *~
|
15
|
+
announcement.txt
|
16
|
+
coverage
|
17
|
+
doc
|
18
|
+
pkg
|
data/.gitignore
CHANGED
@@ -1,7 +1,27 @@
|
|
1
|
-
|
1
|
+
## MAC OS
|
2
|
+
.DS_Store
|
3
|
+
|
4
|
+
## TEXTMATE
|
5
|
+
*.tmproj
|
6
|
+
tmtags
|
7
|
+
|
8
|
+
## EMACS
|
2
9
|
*~
|
10
|
+
\#*
|
11
|
+
.\#*
|
12
|
+
|
13
|
+
## VIM
|
14
|
+
*.swp
|
15
|
+
|
16
|
+
## PROJECT::GENERAL
|
17
|
+
coverage
|
18
|
+
rdoc
|
19
|
+
pkg
|
20
|
+
|
21
|
+
## PROJECT::SPECIFIC
|
3
22
|
pkg/
|
4
|
-
*#
|
5
|
-
.#*
|
6
23
|
spec/wip_spec.rb
|
7
24
|
doc/
|
25
|
+
tmp/
|
26
|
+
js/extra/
|
27
|
+
jsc.gemspec
|
data/History.txt
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
== 0.2.2 / 2010-02-27
|
2
|
+
added support for different types of formatters with a new parser module
|
3
|
+
added --flymake option to return a flymake compatible output
|
4
|
+
|
5
|
+
== 0.2.1 / 2010-02-25
|
6
|
+
FIX: user ActiveSupport JSON decoding (JSON.parse fail randomly)
|
7
|
+
moved from bones to jeweler
|
8
|
+
term/ansicolor module configured as Mixin for strings
|
9
|
+
return error messages in red
|
10
|
+
added support for cucumber and aruba
|
11
|
+
now require rubygems in rakefile
|
12
|
+
--debug option added to bin command
|
13
|
+
LICENSE file added
|
14
|
+
|
1
15
|
== 0.2.0 / 2009-12-14
|
2
16
|
|
3
17
|
added -a, -v, -c options
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Davide Saurino
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
+
== jsc
|
2
|
+
|
1
3
|
jsc, JavaScript Compiler
|
2
4
|
by Davide Saurino
|
3
5
|
http://github.com/sub/jsc
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
-
Simple Ruby API to Google Closure Compiler Web service.
|
7
|
+
Ruby API to Google Closure Compiler Web service.
|
8
8
|
|
9
|
-
==
|
9
|
+
== Features
|
10
10
|
|
11
11
|
With <b>jsc</b> you can compile your JavaScript code throught {Google Closure Compiler REST service}[http://code.google.com/closure/compiler/].
|
12
12
|
|
@@ -25,33 +25,33 @@ More in details:
|
|
25
25
|
|
26
26
|
Check {Google API Reference}[http://code.google.com/intl/it-IT/closure/compiler/docs/api-ref.html] for more info about accepted parameters.
|
27
27
|
|
28
|
-
==
|
28
|
+
== Synopsis
|
29
29
|
|
30
30
|
Get compiled code, if no errors are found:
|
31
31
|
|
32
|
-
|
32
|
+
jsc js/compiled_code.js
|
33
33
|
|
34
34
|
Compile a file, check for errors:
|
35
35
|
|
36
|
-
|
36
|
+
jsc js/errors.js -e
|
37
37
|
|
38
38
|
Compile a file, check for warnings:
|
39
39
|
|
40
|
-
|
40
|
+
jsc js/warnings.js -w
|
41
41
|
|
42
42
|
Compile a file and get compression stats:
|
43
43
|
|
44
|
-
|
44
|
+
jsc js/compiled_code.js -s
|
45
45
|
|
46
46
|
Compile a piece of code, check for errors:
|
47
47
|
|
48
|
-
|
48
|
+
jsc -e -c "function("
|
49
49
|
|
50
50
|
Compile a file and get compiled code if no errors or warnings are found:
|
51
51
|
|
52
|
-
|
52
|
+
jsc js/compiled_code.js -a
|
53
53
|
|
54
|
-
==
|
54
|
+
== Emacs Snippet
|
55
55
|
|
56
56
|
Wants to compile your code right from Emacs?
|
57
57
|
|
@@ -65,24 +65,12 @@ Now, select the code to compile and run:
|
|
65
65
|
* <em>CcJe</em> to check for errors
|
66
66
|
* <em>CcJw</em> to check for warnings.
|
67
67
|
|
68
|
-
==
|
69
|
-
|
70
|
-
jsc requires the {bones}[http://gemcutter.org/gems/bones] gem.
|
71
|
-
|
72
|
-
== INSTALL:
|
68
|
+
== Install
|
73
69
|
|
74
70
|
If you have gemcutter in your gem sources, run:
|
75
71
|
|
76
72
|
[sudo] gem install jsc
|
77
73
|
|
78
|
-
==
|
79
|
-
|
80
|
-
(The MIT License)
|
81
|
-
|
82
|
-
Copyright © 2009 Davide Saurino
|
83
|
-
|
84
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
85
|
-
|
86
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
74
|
+
== Copyright
|
87
75
|
|
88
|
-
|
76
|
+
Copyright (c) 2010 Davide Saurino. See LICENSE for details.
|
data/Rakefile
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'rubygems'
|
1
2
|
require 'rake'
|
2
3
|
require 'rake/testtask'
|
3
4
|
require 'rake/rdoctask'
|
@@ -5,34 +6,59 @@ require 'rake/rdoctask'
|
|
5
6
|
require 'lib/jsc.rb'
|
6
7
|
#require 'lib/jsc/tasks'
|
7
8
|
|
8
|
-
|
9
|
+
## START Jeweler gem config
|
10
|
+
begin
|
11
|
+
require 'jeweler'
|
12
|
+
Jeweler::Tasks.new do |gemspec|
|
13
|
+
gemspec.name = "jsc"
|
14
|
+
gemspec.summary = "Ruby API to Google Closure Compiler Web service"
|
15
|
+
# gemspec.description = ""
|
16
|
+
gemspec.email = "davide.saurino@gmail.com"
|
17
|
+
gemspec.homepage = "http://github.com/sub/jsc"
|
18
|
+
gemspec.authors = ["Davide Saurino"]
|
19
|
+
# gemspec.version = JSCompiler::VERSION
|
9
20
|
|
10
|
-
|
11
|
-
class << self
|
12
|
-
include Term::ANSIColor
|
21
|
+
gemspec.add_dependency 'term-ansicolor', '1.0.4'
|
13
22
|
end
|
23
|
+
|
24
|
+
Jeweler::GemcutterTasks.new
|
25
|
+
|
26
|
+
rescue LoadError
|
27
|
+
puts "Jeweler not available. Install it with: gem install jeweler"
|
28
|
+
end
|
29
|
+
|
30
|
+
require 'rake/testtask'
|
31
|
+
Rake::TestTask.new(:test) do |test|
|
32
|
+
test.libs << 'lib' << 'test'
|
33
|
+
test.pattern = 'test/**/test_*.rb'
|
34
|
+
test.verbose = true
|
14
35
|
end
|
15
36
|
|
16
|
-
## Mr.Bones config
|
17
37
|
begin
|
18
|
-
require '
|
38
|
+
require 'rcov/rcovtask'
|
39
|
+
Rcov::RcovTask.new do |test|
|
40
|
+
test.libs << 'test'
|
41
|
+
test.pattern = 'test/**/test_*.rb'
|
42
|
+
test.verbose = true
|
43
|
+
end
|
19
44
|
rescue LoadError
|
20
|
-
|
45
|
+
task :rcov do
|
46
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
47
|
+
end
|
21
48
|
end
|
22
49
|
|
23
|
-
|
24
|
-
require 'jsc'
|
50
|
+
task :test => :check_dependencies
|
25
51
|
|
26
|
-
task :default =>
|
27
|
-
task 'gem:release' => 'test:run'
|
52
|
+
task :default => :test
|
28
53
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
version
|
35
|
-
|
36
|
-
|
37
|
-
|
54
|
+
require 'rake/rdoctask'
|
55
|
+
Rake::RDocTask.new do |rdoc|
|
56
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
57
|
+
|
58
|
+
rdoc.rdoc_dir = 'rdoc'
|
59
|
+
rdoc.title = "jsc #{version}"
|
60
|
+
rdoc.rdoc_files.include('README*')
|
61
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
62
|
+
end
|
38
63
|
|
64
|
+
## END Jeweler config
|
data/TODO.org
CHANGED
@@ -1,12 +1,6 @@
|
|
1
1
|
* jsc
|
2
|
-
**
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
(15:02:23) @jabber.org: guarda le features di rake-compiler
|
8
|
-
(15:02:28) @jabber.org: sono scritte bene
|
9
|
-
(15:02:29) @jabber.org: oppure
|
10
|
-
(15:02:36) @jabber.org: quelle di ffi-swig-generator
|
11
|
-
oppure con aruba http://github.com/aslakhellesoy/aruba
|
12
|
-
** newgem http://newgem.rubyforge.org/ o jeweler http://github.com/technicalpickles/jeweler
|
2
|
+
** implement use of optional parameters of API
|
3
|
+
*** FUTURE
|
4
|
+
**** OptionParser to parse command input
|
5
|
+
http://www.ruby-doc.org/stdlib/libdoc/optparse/rdoc/classes/OptionParser.htmlb
|
6
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.2.2
|
data/bin/jsc
CHANGED
@@ -40,6 +40,12 @@ jsc [options] ... ARG
|
|
40
40
|
--version, -v:
|
41
41
|
show version
|
42
42
|
|
43
|
+
--debug:
|
44
|
+
activate debug mode
|
45
|
+
|
46
|
+
--flymake, -f:
|
47
|
+
call flymake formatter
|
48
|
+
|
43
49
|
--help, -h:
|
44
50
|
this help
|
45
51
|
|
@@ -61,11 +67,13 @@ opts = GetoptLong.new(
|
|
61
67
|
[ '--warns', '-w', GetoptLong::NO_ARGUMENT ],
|
62
68
|
[ '--stats', '-s', GetoptLong::NO_ARGUMENT ],
|
63
69
|
[ '--all', '-a', GetoptLong::NO_ARGUMENT ],
|
64
|
-
[ '--level','-l', GetoptLong::REQUIRED_ARGUMENT ]
|
70
|
+
[ '--level','-l', GetoptLong::REQUIRED_ARGUMENT ],
|
71
|
+
[ '--debug', GetoptLong::NO_ARGUMENT ],
|
72
|
+
[ '--flymake','-f', GetoptLong::NO_ARGUMENT ]
|
65
73
|
)
|
66
74
|
|
67
75
|
file = true
|
68
|
-
output_info, level, code = ""
|
76
|
+
output_info, level, code, type = ""
|
69
77
|
|
70
78
|
opts.each do |opt, arg|
|
71
79
|
case opt
|
@@ -75,6 +83,8 @@ opts.each do |opt, arg|
|
|
75
83
|
when '--version'
|
76
84
|
puts JSCompiler::VERSION
|
77
85
|
exit 0
|
86
|
+
when '--debug'
|
87
|
+
$debug = true
|
78
88
|
when '--code'
|
79
89
|
file = false
|
80
90
|
code = arg
|
@@ -92,6 +102,8 @@ opts.each do |opt, arg|
|
|
92
102
|
output_info = "statistics"
|
93
103
|
when '--all'
|
94
104
|
output_info = "all"
|
105
|
+
when '--flymake'
|
106
|
+
type = "flymake"
|
95
107
|
end
|
96
108
|
end
|
97
109
|
|
@@ -104,14 +116,14 @@ end
|
|
104
116
|
arg = code.blank? ? ARGV.shift : code
|
105
117
|
|
106
118
|
if output_info.eql?("all")
|
107
|
-
puts JSCompiler.full_compile(arg, file, level)
|
119
|
+
puts JSCompiler.full_compile(arg, file, level, type)
|
108
120
|
elsif output_info.blank?
|
109
|
-
errors_output = JSCompiler.compile(arg, file, "errors", level)
|
121
|
+
errors_output = JSCompiler.compile(arg, file, "errors", level, type)
|
110
122
|
unless errors_output.eql?("No errors")
|
111
123
|
puts errors_output
|
112
124
|
else
|
113
|
-
puts JSCompiler.compile(arg, file, "", level)
|
125
|
+
puts JSCompiler.compile(arg, file, "", level, type)
|
114
126
|
end
|
115
127
|
else
|
116
|
-
puts JSCompiler.compile(arg, file, output_info, level)
|
128
|
+
puts JSCompiler.compile(arg, file, output_info, level, type)
|
117
129
|
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
Feature: Run jsc command
|
2
|
+
|
3
|
+
In order to improve my development process
|
4
|
+
As a Javascript programmer using jsc
|
5
|
+
I should get the correct software output
|
6
|
+
|
7
|
+
Background:
|
8
|
+
Given a file named "js/errors.js" with:
|
9
|
+
"""
|
10
|
+
functiont hello(name) {
|
11
|
+
alert('Hello, ' + name)
|
12
|
+
}
|
13
|
+
hello('New user');
|
14
|
+
"""
|
15
|
+
And a file named "js/warnings.js" with:
|
16
|
+
"""
|
17
|
+
function hello(name) {
|
18
|
+
return;
|
19
|
+
alert('Hello, ' + name)
|
20
|
+
}
|
21
|
+
hello('New user');
|
22
|
+
"""
|
23
|
+
And a file named "js/compiled_code.js" with:
|
24
|
+
"""
|
25
|
+
function hello(name) {
|
26
|
+
alert('Hello, ' + name)
|
27
|
+
}
|
28
|
+
hello('New user');
|
29
|
+
"""
|
30
|
+
|
31
|
+
Scenario: Missing params
|
32
|
+
When I run "jsc"
|
33
|
+
Then I should see exactly "Missing any argument (try --help)\n"
|
34
|
+
And the exit status should be 0
|
35
|
+
|
36
|
+
Scenario: Get help
|
37
|
+
When I run "jsc --help"
|
38
|
+
Then I should see "== Usage"
|
39
|
+
And the exit status should be 0
|
40
|
+
|
41
|
+
Scenario: Detect error if file not found
|
42
|
+
When I run "jsc something.js"
|
43
|
+
Then I should see "No such file or directory - something.js"
|
44
|
+
|
45
|
+
Scenario: Get version
|
46
|
+
When I run "jsc --version"
|
47
|
+
Then I should see "0.2.2"
|
48
|
+
And the exit status should be 0
|
49
|
+
|
50
|
+
# Scenario: Get compiled code
|
51
|
+
Scenario: Compile file and get errors
|
52
|
+
When I run "jsc js/errors.js -e"
|
53
|
+
Then I should see "You've got 2 errors"
|
54
|
+
|
55
|
+
Scenario: Compile file and get warnings
|
56
|
+
When I run "jsc js/warnings.js -w"
|
57
|
+
Then I should see "You've got 1 warnings"
|
58
|
+
|
59
|
+
Scenario: Compile file and get statistics
|
60
|
+
When I run "jsc js/compiled_code.js -s"
|
61
|
+
Then I should see "Original Size:"
|
62
|
+
And I should see "Compiled Size:"
|
63
|
+
|
64
|
+
Scenario: Compile with flymake mode
|
65
|
+
When I run "jsc js/errors.js -e --flymake"
|
66
|
+
Then I should see "js/errors.js:3: error: JSC_PARSE_ERROR: Parse error. syntax error"
|
67
|
+
Then I should not see "You've got 2 errors"
|
data/lib/jsc.rb
CHANGED
data/lib/jsc/closure_compiler.rb
CHANGED
@@ -6,17 +6,28 @@ require 'active_support/core_ext/integer/inflections'
|
|
6
6
|
#require 'json'
|
7
7
|
require 'net/http'
|
8
8
|
|
9
|
+
require 'term/ansicolor'
|
10
|
+
|
9
11
|
# Link to Google Closure Compiler service
|
10
12
|
GOOGLE_SERVICE_ADDRESS = "http://closure-compiler.appspot.com/compile"
|
11
13
|
# Default output_info parameter
|
12
14
|
DEFAULT_SERVICE = "compiled_code"
|
13
15
|
# Default compilation_level parameter
|
14
16
|
DEFAULT_LEVEL = "SIMPLE_OPTIMIZATIONS"
|
17
|
+
# Default formatting type parameter
|
18
|
+
DEFAULT_TYPE = "default"
|
19
|
+
|
20
|
+
class String
|
21
|
+
include Term::ANSIColor
|
22
|
+
end
|
15
23
|
|
16
24
|
module JSCompiler
|
17
25
|
|
18
26
|
class << self
|
19
27
|
|
28
|
+
attr_reader :op, :level, :format_type, :file
|
29
|
+
attr_writer :op, :level, :format_type, :file
|
30
|
+
|
20
31
|
# Creates the <em>JSON</em> hash for the request and returns the hash to send along with the request
|
21
32
|
#
|
22
33
|
# Accepted parameters:
|
@@ -25,9 +36,9 @@ module JSCompiler
|
|
25
36
|
def create_json_request(code)
|
26
37
|
parameters = {
|
27
38
|
"code" => code,
|
28
|
-
"level" =>
|
39
|
+
"level" => self.level,
|
29
40
|
"format" => "json",
|
30
|
-
"info" =>
|
41
|
+
"info" => self.op
|
31
42
|
}
|
32
43
|
end
|
33
44
|
|
@@ -40,6 +51,13 @@ module JSCompiler
|
|
40
51
|
'output_format' => data["format"],
|
41
52
|
'output_info' => data["info"]
|
42
53
|
}
|
54
|
+
|
55
|
+
if $debug
|
56
|
+
puts "#DEBUG post_args \n"
|
57
|
+
p post_args
|
58
|
+
puts "\n"
|
59
|
+
end
|
60
|
+
|
43
61
|
# send the request
|
44
62
|
resp, data = Net::HTTP.post_form(URI.parse(GOOGLE_SERVICE_ADDRESS), post_args)
|
45
63
|
end
|
@@ -52,18 +70,29 @@ module JSCompiler
|
|
52
70
|
# 1 => arg is a file path
|
53
71
|
# * <b>op</b>: output_info parameter
|
54
72
|
# * <b>level</b>: compilation_level parameter
|
55
|
-
|
56
|
-
|
57
|
-
|
73
|
+
# * <b>type</b>: the type of parsing requested
|
74
|
+
def compile(arg, is_file, op, level, type)
|
75
|
+
self.op = op.blank? ? DEFAULT_SERVICE : op
|
76
|
+
self.level = level.blank? ? DEFAULT_LEVEL : level
|
77
|
+
self.format_type = type.blank? ? DEFAULT_TYPE : type
|
78
|
+
self.file = ""
|
58
79
|
value = true
|
59
80
|
|
60
81
|
begin
|
61
82
|
if is_file
|
62
83
|
js_code = read_file(arg)
|
84
|
+
self.file = arg
|
63
85
|
else
|
64
86
|
js_code = arg
|
65
87
|
end
|
66
88
|
resp, data = post_to_cc(create_json_request(js_code))
|
89
|
+
|
90
|
+
if $debug
|
91
|
+
puts "#DEBUG data \n"
|
92
|
+
p data
|
93
|
+
puts "\n"
|
94
|
+
end
|
95
|
+
|
67
96
|
rescue StandardError => e
|
68
97
|
return e
|
69
98
|
end
|
@@ -79,9 +108,9 @@ module JSCompiler
|
|
79
108
|
# * <b>file</b>: 0 => arg is code
|
80
109
|
# 1 => arg is a file path
|
81
110
|
# * <b>level</b>: compilation_level parameter
|
82
|
-
def full_compile(arg, file, level)
|
111
|
+
def full_compile(arg, file, level, type)
|
83
112
|
['errors', 'warnings','compiled_code'].each do |x|
|
84
|
-
str = JSCompiler.compile(arg, file, x, level)
|
113
|
+
str = JSCompiler.compile(arg, file, x, level, type)
|
85
114
|
return str unless str.eql?("No " + x)
|
86
115
|
end
|
87
116
|
end
|
@@ -113,10 +142,13 @@ module JSCompiler
|
|
113
142
|
|
114
143
|
if parsed_response.has_key?("serverErrors")
|
115
144
|
result = parsed_response['serverErrors']
|
116
|
-
|
145
|
+
error_message = "Server Error: #{result[0]['error']} \n"
|
146
|
+
error_message << "Error Code: #{result[0]['code']}"
|
147
|
+
return error_message.red
|
148
|
+
# return red, bold, error_message, reset
|
117
149
|
end
|
118
150
|
|
119
|
-
case
|
151
|
+
case self.op
|
120
152
|
when "compiled_code"
|
121
153
|
out = parsed_response['compiledCode']
|
122
154
|
when "statistics"
|
@@ -125,23 +157,13 @@ module JSCompiler
|
|
125
157
|
else "errors"
|
126
158
|
#case for errors or warnings
|
127
159
|
begin
|
128
|
-
result = parsed_response[
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
out << "\n#{@op.singularize.capitalize} n.#{i}\n"
|
136
|
-
out << "\t#{message['type']}: " + message[@op.singularize] + " at line #{message['lineno']} character #{message['charno']}\n"
|
137
|
-
out << "\t" + message['line'] + "\n" unless message['line'].nil?
|
138
|
-
end
|
139
|
-
return out
|
140
|
-
else
|
141
|
-
return "No #{@op}"
|
142
|
-
end
|
143
|
-
rescue
|
144
|
-
out = "Error parsing JSON output...Check your output"
|
160
|
+
result = parsed_response[self.op]
|
161
|
+
# call parser
|
162
|
+
# return parse(result)
|
163
|
+
JSCompiler::Parser.parse(result)
|
164
|
+
rescue StandardError => e
|
165
|
+
out = e
|
166
|
+
out << "Error parsing JSON output...Check it."
|
145
167
|
end
|
146
168
|
end
|
147
169
|
end
|