Class: FrontCompiler::JavaScript
Defined Under Namespace
Modules: LogicCompactor, NamesCompactor, SelfBuilder
Constant Summary
Constants included
from SelfBuilder
SelfBuilder::MAXIMUM_DICTIONARY_SIZE, SelfBuilder::MINUMUM_REPLACEABLE_TOKEN_SIZE
Instance Method Summary
collapse
#compact_logic!
#compact_names!
#create_self_build
Methods inherited from SourceCode
#compact, #initialize
Instance Method Details
#check_semicolons_in(src) ⇒ Object
checks if there’s ommited semicolons in the code
116
117
118
119
120
121
122
123
|
# File 'lib/front_compiler/java_script/logic_compactor.rb', line 116
def check_semicolons_in(src)
src[/\s*\Z/m] = ";#{src[/\s*\Z/m]}" unless src.strip[-1,1].match(/[;\}]/)
src.gsub!(/(\A\s*function\s*.*?\(.*?\)\s*\{.*?\});(\s*\Z)/im) do
$1 + $2
end
end
|
#compact! ⇒ Object
13
14
15
16
17
18
19
20
21
|
# File 'lib/front_compiler/java_script.rb', line 13
def compact!
string_safely do
.
compact_logic!.
compact_names!.
remove_empty_lines!.
remove_trailing_spaces!
end
end
|
#fix_missed_semicolons! ⇒ Object
125
126
127
128
129
130
131
132
133
|
# File 'lib/front_compiler/java_script/logic_compactor.rb', line 125
def fix_missed_semicolons!
gsub! /([^{}()|\[&;:=,\s])([ \t]*?\n\s*?(return|if|function|while|try|do)[^a-zA-Z_$])/, '\1;\2'
gsub! /(\}\)\([^)]*\))([ \t]*?\n\s*?(return|if|function|while|try|do)[^a-zA-Z_$])/, '\1;\2'
gsub! /([^a-zA-Z_$](else|do));(\s+(if|while|do|try)[^a-zA-Z_$])/, '\1\3'
end
|
23
24
25
26
27
28
|
# File 'lib/front_compiler/java_script.rb', line 23
def
string_safely do
gsub!(/\/\*.*?\*\//im, '')
gsub!(/\/\/.*?($)/, '\1')
end
end
|
#remove_empty_lines! ⇒ Object
30
31
32
33
34
|
# File 'lib/front_compiler/java_script.rb', line 30
def remove_empty_lines!
string_safely do
gsub!(/\n\s*\n/m, "\n")
end
end
|
#remove_trailing_spaces! ⇒ Object
36
37
38
39
40
41
42
43
44
|
# File 'lib/front_compiler/java_script.rb', line 36
def remove_trailing_spaces!
string_safely do
gsub!(/\s+/im, ' ') gsub!(/\s*(=|\+|\-|<|>|\?|\|\||&&|\!|\{|\}|,|\)|\(|;|\]|\[|:|\*|\/)\s*/im, '\1')
gsub!(/;(\})/, '\1') gsub!(/([^a-z\d_\$]typeof)\(([^\)]+)\)\s*/im, '\1 \2') strip!
end
end
|