mumuki-javascript-runner 1.3.4 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/javascript_runner.rb +1 -0
- data/lib/query_hook.rb +70 -9
- data/lib/try_hook.rb +48 -0
- data/lib/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb2c3425cccd2c1dd04911c424109da786ab4cd9a6969904f168db188f625045
|
4
|
+
data.tar.gz: e849e9592b35944b138969f9596004471574bfea4eae1612fbaf53bd3f0a8a2e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 875f71c53f6566579d4efe71dfe4e2522e3286f538d80957d5bfadf4875a8d003a536db763a20e3fa283af80bea54a351d6a5a3f27693549e610e8fe9ff050f5
|
7
|
+
data.tar.gz: 162afef619eaff6248339f5c8d9703816434174bb65de82b25e7fed7de6572b1663c7f6ec447b1f929cd407e5d32bc8d9756365d9ff2f60b3d8eb448b46fabac
|
data/lib/javascript_runner.rb
CHANGED
data/lib/query_hook.rb
CHANGED
@@ -1,18 +1,27 @@
|
|
1
1
|
class JavascriptQueryHook < Mumukit::Templates::FileHook
|
2
|
+
with_error_patterns
|
2
3
|
isolated true
|
3
4
|
|
5
|
+
VAR_REGEXP = /^ *(?:var|let) +([a-zA-Z_$][a-zA-Z_$0-9]*)/
|
6
|
+
VAR_ASSIGN_REGEXP = /^ *(?:var|let) +([a-zA-Z_$][a-zA-Z_$0-9]*) *=/
|
7
|
+
CONST_ASSIGN_REGEXP = /^ *const +([a-zA-Z_$][a-zA-Z_$0-9]*) *=/
|
8
|
+
|
4
9
|
def tempfile_extension
|
5
10
|
'.js'
|
6
11
|
end
|
7
12
|
|
8
|
-
|
9
13
|
def compile_file_content(r)
|
14
|
+
"#{compile_file_header(r)}\n#{compile_query(r.query)}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def compile_file_header(r)
|
10
18
|
<<javascript
|
11
19
|
'use strict';
|
12
20
|
|
13
21
|
function mumukiConsolePrettyPrint(e) {
|
14
22
|
if (e instanceof Function) return '<function>';
|
15
|
-
|
23
|
+
const json = JSON.stringify(e);
|
24
|
+
return json && json.replace(/"(\\w+)"\s*:/g, '$1:');
|
16
25
|
}
|
17
26
|
|
18
27
|
#{r.extra}
|
@@ -20,25 +29,77 @@ function mumukiConsolePrettyPrint(e) {
|
|
20
29
|
#{r.content}
|
21
30
|
|
22
31
|
#{compile_cookie(r.cookie)}
|
23
|
-
|
24
|
-
#{compile_query(r.query)}
|
25
32
|
javascript
|
26
33
|
end
|
27
34
|
|
28
|
-
def compile_query(query)
|
29
|
-
if
|
30
|
-
"#{query}\nconsole.log('
|
35
|
+
def compile_query(query, output_prefix = "=> ", output_var = "__mumuki_query_result__")
|
36
|
+
if ['var', 'let', 'const'].any? { |type| query.start_with? "#{type} " }
|
37
|
+
"#{query}\nconsole.log('#{output_prefix}undefined')"
|
31
38
|
else
|
32
|
-
"var
|
39
|
+
"var #{output_var} = #{query};\nconsole.log('#{output_prefix}' + mumukiConsolePrettyPrint(#{output_var}))"
|
33
40
|
end
|
34
41
|
end
|
35
42
|
|
36
43
|
def compile_cookie(cookie)
|
37
44
|
return if cookie.blank?
|
38
|
-
|
45
|
+
|
46
|
+
compile_statements(cookie).join "\n"
|
39
47
|
end
|
40
48
|
|
41
49
|
def command_line(filename)
|
42
50
|
"node #{filename}"
|
43
51
|
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def compile_statements(cookie)
|
56
|
+
reject_duplicated_statements wrap_statements(cookie)
|
57
|
+
end
|
58
|
+
|
59
|
+
def wrap_statements(cookie)
|
60
|
+
cookie.map do |query|
|
61
|
+
case query
|
62
|
+
when CONST_ASSIGN_REGEXP
|
63
|
+
declaration_with_assignment 'const', CONST_ASSIGN_REGEXP, $1, query
|
64
|
+
when VAR_ASSIGN_REGEXP
|
65
|
+
declaration_with_assignment 'var', VAR_ASSIGN_REGEXP, $1, query
|
66
|
+
when VAR_REGEXP
|
67
|
+
"var #{$1}"
|
68
|
+
else
|
69
|
+
"try { #{query} } catch (e) {}"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def reject_duplicated_statements(sentences)
|
75
|
+
sentences.select.with_index do |line, index|
|
76
|
+
next line if !line.match(VAR_ASSIGN_REGEXP) && !line.match(VAR_REGEXP) && !line.match(CONST_ASSIGN_REGEXP)
|
77
|
+
name = $1
|
78
|
+
sentences.slice(0, index).none? { |previous_line| declaration? previous_line, name }
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def declaration_with_assignment(type, type_pattern, name, expression)
|
83
|
+
"#{type} #{name} = (function() { try { return #{expression.gsub(type_pattern, '')} } catch(e) { return undefined } })()"
|
84
|
+
end
|
85
|
+
|
86
|
+
def declaration?(line, name)
|
87
|
+
declaration_of_type?(VAR_REGEXP, line, name) ||
|
88
|
+
declaration_of_type?(VAR_ASSIGN_REGEXP, line, name) ||
|
89
|
+
declaration_of_type?(CONST_ASSIGN_REGEXP, line, name)
|
90
|
+
end
|
91
|
+
|
92
|
+
def declaration_of_type?(type_pattern, line, name)
|
93
|
+
line.match(type_pattern) && $1 == name
|
94
|
+
end
|
95
|
+
|
96
|
+
def error_patterns
|
97
|
+
[
|
98
|
+
Mumukit::ErrorPattern::Errored.new(syntax_error_regexp)
|
99
|
+
]
|
100
|
+
end
|
101
|
+
|
102
|
+
def syntax_error_regexp
|
103
|
+
/(?=\X*SyntaxError)(solution.*\n)|SyntaxError.*\n\K at \X*/
|
104
|
+
end
|
44
105
|
end
|
data/lib/try_hook.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
class JavascriptTryHook < Mumukit::Templates::TryHook
|
2
|
+
isolated true
|
3
|
+
attr_reader :query_hook
|
4
|
+
|
5
|
+
def initialize(config = nil)
|
6
|
+
super config
|
7
|
+
@query_hook = JavascriptQueryHook.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def compile_file_content(r)
|
11
|
+
<<js
|
12
|
+
#{@query_hook.compile_file_header(r)}
|
13
|
+
console.log("#{query_separator}");
|
14
|
+
#{@query_hook.compile_query(r.query, '')}
|
15
|
+
console.log("#{goal_separator}");
|
16
|
+
#{@query_hook.compile_query(r.goal.with_indifferent_access[:query] || 'null', '', '__mumuki_goal_query_result__')}
|
17
|
+
js
|
18
|
+
end
|
19
|
+
|
20
|
+
delegate :tempfile_extension, to: :query_hook
|
21
|
+
delegate :command_line, to: :query_hook
|
22
|
+
|
23
|
+
def query_separator
|
24
|
+
'!!!MUMUKI-QUERY-START!!!'
|
25
|
+
end
|
26
|
+
|
27
|
+
def goal_separator
|
28
|
+
'!!!MUMUKI-GOAL-START!!!'
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_structured_results(_file, result, status)
|
32
|
+
/#{query_separator}
|
33
|
+
?(.*)
|
34
|
+
#{goal_separator}
|
35
|
+
?(.*)
|
36
|
+
/m =~ result
|
37
|
+
|
38
|
+
{
|
39
|
+
query: to_query_result($1, status),
|
40
|
+
goal: $2,
|
41
|
+
status: status
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
def to_query_result(result, status)
|
46
|
+
{ result: result, status: status }
|
47
|
+
end
|
48
|
+
end
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mumuki-javascript-runner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Franco Leonardo Bulgarelli
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mumukit
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '2.
|
19
|
+
version: '2.30'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '2.
|
26
|
+
version: '2.30'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -106,6 +106,7 @@ files:
|
|
106
106
|
- lib/metadata_hook.rb
|
107
107
|
- lib/query_hook.rb
|
108
108
|
- lib/test_hook.rb
|
109
|
+
- lib/try_hook.rb
|
109
110
|
- lib/validation_hook.rb
|
110
111
|
- lib/version.rb
|
111
112
|
homepage: http://github.com/mumuki/mumuki-javascript-server
|
@@ -127,8 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
128
|
- !ruby/object:Gem::Version
|
128
129
|
version: '0'
|
129
130
|
requirements: []
|
130
|
-
|
131
|
-
rubygems_version: 2.7.7
|
131
|
+
rubygems_version: 3.0.2
|
132
132
|
signing_key:
|
133
133
|
specification_version: 4
|
134
134
|
summary: Javascript Runner for Mumuki
|