nilac 0.0.4.3.9.7.1 → 0.0.4.3.9.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -2
  3. data/Rakefile +1 -1
  4. data/cookbook/case_insensitive_compare.js +13 -0
  5. data/cookbook/case_insensitive_compare.nila +7 -0
  6. data/cookbook/compare_strings.js +13 -0
  7. data/cookbook/compare_strings.nila +7 -0
  8. data/cookbook/concat11.js +13 -0
  9. data/cookbook/concat11.nila +4 -0
  10. data/cookbook/concat12.js +23 -0
  11. data/cookbook/concat12.nila +15 -0
  12. data/cookbook/find_substring.js +15 -0
  13. data/cookbook/find_substring.nila +5 -0
  14. data/cookbook/string_interpolation.js +7 -0
  15. data/cookbook/string_interpolation.nila +1 -0
  16. data/cookbook/substring_extract.js +21 -0
  17. data/cookbook/substring_extract.nila +8 -0
  18. data/examples/my_file.js +5 -0
  19. data/examples/repl.js +0 -33
  20. data/examples/repl.nila +36 -8
  21. data/examples/temp_nila.nila +63 -0
  22. data/lib/nilac.rb +83 -68
  23. data/lib/nilac/add_line_numbers.rb +17 -0
  24. data/lib/nilac/add_semicolons.rb +13 -3
  25. data/lib/nilac/compile_arrays.rb +38 -5
  26. data/lib/nilac/compile_blocks.rb +87 -25
  27. data/lib/nilac/compile_case_statement.rb +4 -0
  28. data/lib/nilac/compile_chained_comparison.rb +35 -0
  29. data/lib/nilac/compile_comments.rb +9 -0
  30. data/lib/nilac/compile_conditional_structures.rb +26 -3
  31. data/lib/nilac/compile_custom_function_map.rb +24 -2
  32. data/lib/nilac/compile_hashes.rb +3 -1
  33. data/lib/nilac/compile_heredocs.rb +2 -0
  34. data/lib/nilac/compile_inline_for.rb +13 -0
  35. data/lib/nilac/compile_interpolated_strings.rb +184 -5
  36. data/lib/nilac/compile_lambdas.rb +24 -8
  37. data/lib/nilac/compile_new_keyword.rb +37 -0
  38. data/lib/nilac/compile_nilac_options.rb +79 -0
  39. data/lib/nilac/compile_parallel_assignment.rb +3 -1
  40. data/lib/nilac/compile_ranges.rb +60 -0
  41. data/lib/nilac/compile_require_statements.rb +4 -2
  42. data/lib/nilac/compile_ruby_math.rb +20 -0
  43. data/lib/nilac/compile_ruby_methods.rb +49 -0
  44. data/lib/nilac/compile_whitespace_delimited_functions.rb +15 -1
  45. data/lib/nilac/extract_paranthesis_contents.rb +37 -0
  46. data/lib/nilac/extract_strings.rb +63 -0
  47. data/lib/nilac/fix_javascript_traps.rb +89 -0
  48. data/lib/nilac/friendly_errors.rb +128 -0
  49. data/lib/nilac/get_variables.rb +48 -14
  50. data/lib/nilac/lexical_scoped_function_variables.rb +1 -3
  51. data/lib/nilac/optimizer.rb +13 -0
  52. data/lib/nilac/paranthesis_compactor.rb +3 -1
  53. data/lib/nilac/parse_arguments.rb +21 -7
  54. data/lib/nilac/pretty_print_javascript.rb +152 -18
  55. data/lib/nilac/pretty_print_nila.rb +17 -0
  56. data/lib/nilac/replace_comparison_operators.rb +25 -0
  57. data/lib/nilac/replace_multiline_comments.rb +4 -0
  58. data/lib/nilac/replace_singleline_comments.rb +23 -0
  59. data/lib/nilac/replace_strings.rb +3 -3
  60. data/lib/nilac/rollblocks.rb +7 -3
  61. data/lib/nilac/split_semicolon_seperated_expressions.rb +3 -17
  62. data/lib/nilac/square_brackets_compactor.rb +37 -0
  63. data/lib/nilac/version.rb +1 -1
  64. data/shark/features/arrays.feature +11 -0
  65. data/shark/features/builtin_new.feature +11 -0
  66. data/shark/features/comments.feature +11 -0
  67. data/shark/features/fix_newlines.feature +1 -1
  68. data/shark/features/variables.feature +11 -0
  69. data/shark/test_files/array_string_indexing.nila +5 -1
  70. data/shark/test_files/arrays.nila +3 -0
  71. data/shark/test_files/blocks.nila +10 -0
  72. data/shark/test_files/builtin_new.nila +3 -0
  73. data/shark/test_files/case.nila +8 -0
  74. data/shark/test_files/chained_comparison.nila +19 -0
  75. data/shark/test_files/comments.nila +15 -0
  76. data/shark/test_files/correct.js +1 -1
  77. data/shark/test_files/correct_arrays.js +7 -0
  78. data/shark/test_files/correct_blocks.js +14 -1
  79. data/shark/test_files/correct_builtin_new.js +9 -0
  80. data/shark/test_files/correct_case.js +10 -2
  81. data/shark/test_files/correct_comments.js +19 -0
  82. data/shark/test_files/correct_conditional_assignment.js +1 -1
  83. data/shark/test_files/correct_default_parameters.js +1 -1
  84. data/shark/test_files/correct_for.js +1 -1
  85. data/shark/test_files/correct_hashes.js +1 -1
  86. data/shark/test_files/correct_heredoc.js +6 -2
  87. data/shark/test_files/correct_if_then_else.js +5 -1
  88. data/shark/test_files/correct_indexing.js +7 -3
  89. data/shark/test_files/correct_initialization.js +1 -1
  90. data/shark/test_files/correct_javascript_methods.js +1 -1
  91. data/shark/test_files/correct_loop.js +1 -1
  92. data/shark/test_files/correct_monkey_patch.js +1 -1
  93. data/shark/test_files/correct_multiline_array.js +1 -1
  94. data/shark/test_files/correct_multiple_return.js +1 -1
  95. data/shark/test_files/correct_numbers.js +1 -1
  96. data/shark/test_files/correct_operators.js +1 -1
  97. data/shark/test_files/correct_regular_if.js +1 -1
  98. data/shark/test_files/correct_regular_while.js +1 -1
  99. data/shark/test_files/correct_required_module.js +1 -1
  100. data/shark/test_files/correct_return.js +1 -1
  101. data/shark/test_files/correct_ruby_methods.js +1 -1
  102. data/shark/test_files/correct_single_return.js +1 -1
  103. data/shark/test_files/{perfect.js → correct_spacing.js} +1 -1
  104. data/shark/test_files/correct_splats.js +1 -2
  105. data/shark/test_files/correct_string_interpolation.js +8 -2
  106. data/shark/test_files/correct_string_operators.js +1 -1
  107. data/shark/test_files/correct_times.js +1 -1
  108. data/shark/test_files/correct_unless_until.js +2 -4
  109. data/shark/test_files/correct_variables.js +13 -0
  110. data/shark/test_files/correct_whitespace_delimiter.js +1 -1
  111. data/shark/test_files/existential_operators.nila +7 -0
  112. data/shark/test_files/expression.nila +6 -0
  113. data/shark/test_files/global_variables_client.nila +5 -0
  114. data/shark/test_files/heredoc.nila +11 -1
  115. data/shark/test_files/if_then_else.nila +3 -1
  116. data/shark/test_files/inline_for.nila +5 -0
  117. data/shark/test_files/no_return.js +11 -0
  118. data/shark/test_files/parseInt_trap.nila +3 -0
  119. data/shark/test_files/single_return.js +11 -0
  120. data/shark/test_files/string_interpolation.nila +7 -1
  121. data/shark/test_files/variables.nila +7 -0
  122. metadata +54 -3
@@ -92,4 +92,132 @@ module FriendlyErrors
92
92
 
93
93
  end
94
94
 
95
+ def check_comments(file_contents)
96
+
97
+ def word_counter(input_string,word)
98
+
99
+ string_split = input_string.split(word)
100
+
101
+ return string_split.length-1
102
+
103
+ end
104
+
105
+ proceed = true
106
+
107
+ joined_file_contents = file_contents.join
108
+
109
+ joined_file_contents = replace_strings(joined_file_contents).gsub("_","")
110
+
111
+ unless joined_file_contents.scan(/=\s+begin\n/).empty?
112
+
113
+ puts "SyntaxWarning: Improper Whitespace\n\n"
114
+
115
+ puts "I detected that you have used one or more spaces between '=' and 'begin' in your file. This is not allowed.\n\n"
116
+
117
+ puts "But this is a very small mistake. So I am assuming you meant `=begin` and I will continue to compile.\n\n"
118
+
119
+ puts "Please correct it before next time or else you will see this warning again!\n\n"
120
+
121
+ puts "If you have any questions, please refer to the documentation at \n\nhttps://adhithyan15.github.io/nila/documentation.html#comments\n"
122
+
123
+ joined_file_contents = joined_file_contents.gsub(/=\s+begin/,"=begin")
124
+
125
+ end
126
+
127
+ unless joined_file_contents.scan(/=\s+end\n/).empty?
128
+
129
+ puts "SyntaxWarning: Improper Whitespace\n\n"
130
+
131
+ puts "I detected that you have used one or more spaces between '=' and 'end' in your file. This is not allowed.\n\n"
132
+
133
+ puts "But this is a very small mistake. So I am assuming you meant `=end` and I will continue to compile.\n\n"
134
+
135
+ puts "Please correct it before next time or else you will see this warning again!\n\n"
136
+
137
+ puts "If you have any questions, please refer to the documentation at \n\nhttps://adhithyan15.github.io/nila/documentation.html#comments\n"
138
+
139
+ joined_file_contents = joined_file_contents.gsub(/=\s+end/,"=end")
140
+
141
+ end
142
+
143
+ block_comments = []
144
+
145
+ while joined_file_contents.include?("=begin\n") or joined_file_contents.include?("=end\n")
146
+
147
+ begin
148
+
149
+ comment_start = joined_file_contents.index("=begin\n")
150
+
151
+ comment_end = joined_file_contents.index("=end\n")
152
+
153
+ block_comments << joined_file_contents[comment_start..comment_end]
154
+
155
+ joined_file_contents[comment_start..comment_end] = ""
156
+
157
+ rescue ArgumentError
158
+
159
+ if comment_start == nil
160
+
161
+ extracted_contents = joined_file_contents[0..comment_end].reverse
162
+
163
+ line_number_match = extracted_contents.match(/>>>\d*<<</)
164
+
165
+ line_number_match = line_number_match.to_a
166
+
167
+ line_number_extract = line_number_match[0].split(">>>")[1].split("<<<")[0]
168
+
169
+ puts "SyntaxError: Unexpected =end\n\n"
170
+
171
+ puts "It seems like there is a problem with your multiline comment. I am checking where that happened! Give me a few seconds..... \n\n"
172
+
173
+ puts "In line number #{line_number_extract}, I detected an `=end` statement. But no matching `=begin` statement was found! Please fix it immediately!\n\n"
174
+
175
+ puts "I cannot proceed with out it!\n\n"
176
+
177
+ puts "If you have any questions, please refer to the documentation at \n\nhttps://adhithyan15.github.io/nila/documentation.html#comments\n"
178
+
179
+ exit
180
+
181
+ end
182
+
183
+ if comment_end == nil
184
+
185
+ extracted_contents = joined_file_contents[0..comment_start].reverse
186
+
187
+ line_number_match = extracted_contents.match(/>>>\d*<<</)
188
+
189
+ line_number_match = line_number_match.to_a
190
+
191
+ line_number_extract = line_number_match[0].split(">>>")[1].split("<<<")[0]
192
+
193
+ puts "SyntaxError: Unexpected =begin\n\n"
194
+
195
+ puts "It seems like there is a problem with your multiline comment. I am checking where that happened! Give me a few seconds..... \n\n"
196
+
197
+ puts "In line number #{line_number_extract}, I detected a `=begin` statement. But no matching `=end` statement was found! Please fix it immediately!\n\n"
198
+
199
+ puts "I cannot proceed with out it!\n\n"
200
+
201
+ puts "If you have any questions, please refer to the documentation at \n\nhttps://adhithyan15.github.io/nila/documentation.html#comments\n"
202
+
203
+ exit
204
+
205
+ end
206
+
207
+ end
208
+
209
+ end
210
+
211
+ return proceed
212
+
213
+ end
214
+
215
+ def check_heredoc_syntax(input_file_contents)
216
+
217
+ proceed = true
218
+
219
+
220
+
221
+ end
222
+
95
223
  end
@@ -1,6 +1,7 @@
1
1
  require_relative 'replace_strings'
2
2
  require_relative 'read_file_line_by_line'
3
3
  require_relative 'paranthesis_compactor'
4
+ require_relative 'extract_paranthesis_contents'
4
5
 
5
6
  def get_variables(input_file_contents, temporary_nila_file, *loop_variables)
6
7
 
@@ -52,34 +53,67 @@ require_relative 'paranthesis_compactor'
52
53
 
53
54
  current_row = current_row.rstrip + "\n"
54
55
 
55
- current_row_split = current_row.split("=")
56
+ if current_row.count("=") > 1
56
57
 
57
- for y in 0...current_row_split.length
58
+ if compact_paranthesis(current_row).count("=") > 1
58
59
 
59
- current_row_split[y] = current_row_split[y].strip
60
+ current_row_split = current_row.split("=")
60
61
 
62
+ current_row_split[0...-1].each do |split|
61
63
 
62
- end
64
+ variables << split.strip
63
65
 
64
- if current_row_split[0].include?("[") or current_row_split[0].include?("(")
66
+ end
65
67
 
66
- current_row_split[0] = current_row_split[0][0...current_row_split[0].index("[")]
68
+ else
67
69
 
68
- end
70
+ paranthesis_contents = extract_paranthesis_contents(current_row)
71
+
72
+ paranthesis_contents = paranthesis_contents.reject {|element| !replace_strings(element).include?("=")}
73
+
74
+ paranthesis_contents.each do |element|
75
+
76
+ string_extract = element.strip[1...-1]
69
77
 
70
- current_row_split[0] = current_row_split[0].split(".",2)[0].strip if current_row_split[0].include?(".")
78
+ variables << string_extract.split("=").collect {|element| element.strip}[0]
71
79
 
72
- if current_row_split[0].include?(" ")
80
+ end
73
81
 
74
- variable_name = current_row_split[0].split
82
+ if compact_paranthesis(current_row).include?("=")
75
83
 
76
- variable_name = variable_name.join("_")
84
+ variables << current_row.split("=",2).collect {|element| element.strip}[0]
77
85
 
78
- modified_file_contents[modified_file_contents.index(original_row)] = modified_file_contents[modified_file_contents.index(original_row)].gsub(current_row_split[0],variable_name)
86
+ end
87
+
88
+ end
79
89
 
80
90
  else
81
91
 
82
- variable_name = current_row_split[0]
92
+ current_row_split = current_row.split("=")
93
+
94
+ current_row_split = current_row_split.collect {|element| element.strip}
95
+
96
+ if current_row_split[0].include?("[") or current_row_split[0].include?("(")
97
+
98
+ current_row_split[0] = current_row_split[0][0...current_row_split[0].index("[")]
99
+
100
+ end
101
+
102
+ current_row_split[0] = current_row_split[0].split(".",2)[0].strip if current_row_split[0].include?(".")
103
+
104
+ if current_row_split[0].include?(" ")
105
+
106
+ variable_name = current_row_split[0].split
107
+
108
+ variable_name = variable_name.join("_")
109
+
110
+ modified_file_contents[modified_file_contents.index(original_row)] = modified_file_contents[modified_file_contents.index(original_row)].gsub(current_row_split[0],variable_name)
111
+
112
+ else
113
+
114
+ variable_name = current_row_split[0]
115
+
116
+ end
83
117
 
84
118
  end
85
119
 
@@ -145,6 +179,6 @@ require_relative 'paranthesis_compactor'
145
179
 
146
180
  line_by_line_contents = line_by_line_contents.collect { |element| element.gsub("lessyequal", "<=") }
147
181
 
148
- return variables.uniq, line_by_line_contents
182
+ return variables.uniq.compact, line_by_line_contents
149
183
 
150
184
  end
@@ -51,8 +51,6 @@ def lexical_scoped_variables(input_function_block)
51
51
 
52
52
  end
53
53
 
54
- input_function_block = input_function_block.collect {|element| replace_strings(element)}
55
-
56
54
  controlregexp = /(if |Euuf |for |while |def |function |function\()/
57
55
 
58
56
  variables = []
@@ -65,7 +63,7 @@ def lexical_scoped_variables(input_function_block)
65
63
 
66
64
  input_function_block.each do |line|
67
65
 
68
- if line.include? "=" and line.index(controlregexp).nil?
66
+ if replace_strings(line).include? "=" and replace_strings(line).index(controlregexp).nil?
69
67
 
70
68
  current_line_split = line.strip.split("=")
71
69
 
@@ -0,0 +1,13 @@
1
+ module Optimizer
2
+
3
+ # This module will be used to optimize Nila code to remove unnecessary paranthesis and calculations
4
+
5
+ # This module will be fully operational by 0.0.5.0.0
6
+
7
+ def optimize_nila_code(input_file_contents)
8
+
9
+
10
+
11
+ end
12
+
13
+ end
@@ -1,3 +1,5 @@
1
+ require_relative 'square_brackets_compactor'
2
+
1
3
  def compact_paranthesis(input_string)
2
4
 
3
5
  string_extract = input_string.reverse
@@ -32,6 +34,6 @@ def compact_paranthesis(input_string)
32
34
 
33
35
  end
34
36
 
35
- return string_extract.reverse
37
+ return compact_square_brackets(string_extract.reverse)
36
38
 
37
39
  end
@@ -9,15 +9,11 @@ def parse_arguments(input_argv)
9
9
  %w{h help} => "help",
10
10
 
11
11
  %w{v version} => "version",
12
-
13
- %w{b build} => "build",
14
-
12
+
15
13
  %w{u update} => "update",
16
14
 
17
- %w{re release} => "release",
18
-
19
15
  }
20
-
16
+
21
17
  output_hash = {}
22
18
 
23
19
  argument_map.each do |key,val|
@@ -33,7 +29,25 @@ def parse_arguments(input_argv)
33
29
  output_hash[val.to_sym] = nil
34
30
 
35
31
  end
36
-
32
+
33
+ end
34
+
35
+ if output_hash.values.compact.empty? and !input_argv.empty?
36
+
37
+ if input_argv[0].include?(".nila")
38
+
39
+ output_hash[:run] = [input_argv[0]]
40
+
41
+ elsif File.directory?(input_argv[0])
42
+
43
+ puts "\nSorry! Nilac cannot compile and run folders full of source files at this time.\n\n"
44
+
45
+ puts "Check out the documentation at https://adhithyan15.github.io/nila#cli-options\nif you have any questions\n\n"
46
+
47
+ exit
48
+
49
+ end
50
+
37
51
  end
38
52
 
39
53
  return output_hash
@@ -1,8 +1,9 @@
1
1
  require_relative 'find_all_matching_indices'
2
2
  require_relative 'read_file_line_by_line'
3
3
  require_relative 'replace_strings'
4
+ require_relative 'strToArray'
4
5
 
5
- def pretty_print_javascript(javascript_file_contents, temporary_nila_file,declarable_variables)
6
+ def pretty_print_javascript(javascript_file_contents, temporary_nila_file,declarable_variables,options)
6
7
 
7
8
  def reset_tabs(input_file_contents)
8
9
 
@@ -48,7 +49,7 @@ require_relative 'replace_strings'
48
49
 
49
50
  modified_block = input_block.reject {|element| element.strip.eql?("")}
50
51
 
51
- modified_block = modified_block.collect {|element| element.rstrip + "\n"}
52
+ modified_block = modified_block.collect {|element| (element.rstrip + "\n") unless element[0..1].eql?("//")}
52
53
 
53
54
  return modified_block
54
55
 
@@ -104,7 +105,21 @@ require_relative 'replace_strings'
104
105
 
105
106
  remaining_contents = remaining_contents.reject {|element| element.strip.eql?("")}
106
107
 
107
- remaining_contents = [remaining_contents[0]] + remaining_contents[1...-1].collect {|element| element + "\n"} + [remaining_contents[-1]]
108
+ remaining_contents[1...-1] = remaining_contents[1...-1].collect do |element|
109
+
110
+ if !replace_strings(element).split("//")[0].eql?("")
111
+
112
+ (element + "\n")
113
+
114
+ else
115
+
116
+ element
117
+
118
+ end
119
+
120
+ end
121
+
122
+ remaining_contents = [remaining_contents[0]] + remaining_contents[1...-1] + [remaining_contents[-1]]
108
123
 
109
124
  main_block_numbers.each do |number|
110
125
 
@@ -122,7 +137,21 @@ require_relative 'replace_strings'
122
137
 
123
138
  remaining_contents = block_compactor(file_contents)
124
139
 
125
- remaining_contents = [remaining_contents[0]] + remaining_contents[1...-1].collect {|element| element + "\n"} + [remaining_contents[-1]]
140
+ remaining_contents[1...-1] = remaining_contents[1...-1].collect do |element|
141
+
142
+ if !replace_strings(element).split("//")[0].eql?("")
143
+
144
+ (element + "\n")
145
+
146
+ else
147
+
148
+ element
149
+
150
+ end
151
+
152
+ end
153
+
154
+ remaining_contents = [remaining_contents[0]] + remaining_contents[1...-1] + [remaining_contents[-1]]
126
155
 
127
156
  end
128
157
 
@@ -198,7 +227,7 @@ require_relative 'replace_strings'
198
227
 
199
228
  array_extract.each_with_index do |line|
200
229
 
201
- break if line.index(controlregexp) != nil
230
+ break if replace_strings(line).index(controlregexp) != nil
202
231
 
203
232
  index_counter += 1
204
233
 
@@ -252,11 +281,15 @@ require_relative 'replace_strings'
252
281
 
253
282
  fixableregexp = /(else |elsuf )/
254
283
 
255
- need_fixes = input_file_contents.reject { |line| line.index(fixableregexp).nil? }
284
+ if input_file_contents.join.index(fixableregexp)
285
+
286
+ need_fixes = input_file_contents.reject { |line| line.index(fixableregexp).nil? }
256
287
 
257
- need_fixes.each do |fix|
288
+ need_fixes.each do |fix|
258
289
 
259
- input_file_contents[input_file_contents.index(fix)] = input_file_contents[input_file_contents.index(fix)].sub(" ", "")
290
+ input_file_contents[input_file_contents.index(fix)] = input_file_contents[input_file_contents.index(fix)].sub(" ", "")
291
+
292
+ end
260
293
 
261
294
  end
262
295
 
@@ -280,7 +313,87 @@ require_relative 'replace_strings'
280
313
 
281
314
  end
282
315
 
283
- javascript_regexp = /(if |for |while |case |default:|switch\(|\(function\(|= function\(|((=|:)\s+\{))/
316
+ def comment_fix(input_file_contents)
317
+
318
+ def compress_block_comments(input_file_contents)
319
+
320
+ joined_file_contents = input_file_contents.join
321
+
322
+ block_comments = []
323
+
324
+ while joined_file_contents.include?("/*")
325
+
326
+ start_index = joined_file_contents.index(" /*")
327
+
328
+ end_index = joined_file_contents.index(" */\n\n")
329
+
330
+ if end_index > start_index
331
+
332
+ block_comments << joined_file_contents[start_index..end_index + 5]
333
+
334
+ joined_file_contents[start_index..end_index + 5] = ""
335
+
336
+ end
337
+
338
+ end
339
+
340
+ block_comments.each do |comment|
341
+
342
+ converted_array = strToArray(comment)
343
+
344
+ converted_array = converted_array.reject {|element| element.strip.eql?("")}.collect {|element| element + "\n"}
345
+
346
+ replacement_array = converted_array.collect {|element| element.rstrip + "\n"}
347
+
348
+ replacement_array[-1] = replacement_array[-1] + "\n"
349
+
350
+ replacement_array[1...-1] = replacement_array[1...-1].collect {|element| " " + element}
351
+
352
+ input_file_contents[input_file_contents.index(converted_array[0])..input_file_contents.index(converted_array[-1])] = replacement_array
353
+
354
+ end
355
+
356
+ return input_file_contents
357
+
358
+ end
359
+
360
+ input_file_contents = input_file_contents.collect do |element|
361
+
362
+ line_counter = input_file_contents.index(element)
363
+
364
+ if element[0..3].eql?(" //")
365
+
366
+ if input_file_contents[line_counter+1].include?("//")
367
+
368
+ element.rstrip + "\n"
369
+
370
+ else
371
+
372
+ element
373
+
374
+ end
375
+
376
+ else
377
+
378
+ element
379
+
380
+ end
381
+
382
+ end
383
+
384
+ input_file_contents = compress_block_comments(input_file_contents)
385
+
386
+ return input_file_contents
387
+
388
+ end
389
+
390
+ def fix_spacing_issues(input_file_contents)
391
+
392
+ # This method fixes all the spacing issues that causes jsHint errors.
393
+
394
+ end
395
+
396
+ javascript_regexp = /(if |for |while |case |default:|switch\(|\(function\(|= function\(|,\s*function\(|((=|:)\s+\{))/
284
397
 
285
398
  if declarable_variables.length > 0
286
399
 
@@ -302,7 +415,7 @@ require_relative 'replace_strings'
302
415
 
303
416
  javascript_file_contents.each_with_index do |line, index|
304
417
 
305
- if line.index(javascript_regexp) != nil
418
+ if replace_strings(line).index(javascript_regexp) != nil and !line.lstrip.split("//")[0].eql?("")
306
419
 
307
420
  starting_locations << index
308
421
 
@@ -396,7 +509,21 @@ require_relative 'replace_strings'
396
509
 
397
510
  end
398
511
 
399
- remaining_file_contents = ["(function() {\n", remaining_file_contents, "\n}).call(this);"].flatten
512
+ if options[:strict_mode]
513
+
514
+ remaining_file_contents = [" \"use strict\";\n",remaining_file_contents].flatten
515
+
516
+ end
517
+
518
+ if options[:bare]
519
+
520
+ remaining_file_contents = remaining_file_contents
521
+
522
+ else
523
+
524
+ remaining_file_contents = ["(function () {\n", remaining_file_contents, "\n}).call(this);"].flatten
525
+
526
+ end
400
527
 
401
528
  main_blocks.each_with_index do |block_id, index|
402
529
 
@@ -412,7 +539,7 @@ require_relative 'replace_strings'
412
539
 
413
540
  remaining_file_contents = remaining_file_contents.collect { |element| " " + element }
414
541
 
415
- remaining_file_contents = ["(function() {\n", remaining_file_contents, "\n}).call(this);"].flatten
542
+ remaining_file_contents = ["(function () {\n", remaining_file_contents, "\n}).call(this);"].flatten
416
543
 
417
544
  joined_file_contents = remaining_file_contents.join
418
545
 
@@ -430,22 +557,29 @@ require_relative 'replace_strings'
430
557
 
431
558
  line_by_line_contents = fix_newlines(line_by_line_contents,main_block_numbers)
432
559
 
433
- removable_indices = line_by_line_contents.each_index.select {|index| line_by_line_contents[index].strip == "%$%$;" }
560
+ if line_by_line_contents.join.include?("%$%$")
434
561
 
435
- while line_by_line_contents.join.include?("%$%$;")
562
+ removable_indices = line_by_line_contents.each_index.select {|index| line_by_line_contents[index].strip == "%$%$;" }
436
563
 
437
- line_by_line_contents.delete_at(removable_indices[0])
564
+ while line_by_line_contents.join.include?("%$%$;")
438
565
 
439
- line_by_line_contents.delete_at(removable_indices[0])
566
+ line_by_line_contents.delete_at(removable_indices[0])
440
567
 
441
- removable_indices = line_by_line_contents.each_index.select {|index| line_by_line_contents[index].strip == "%$%$;" }
568
+ line_by_line_contents.delete_at(removable_indices[0])
569
+
570
+ removable_indices = line_by_line_contents.each_index.select {|index| line_by_line_contents[index].strip == "%$%$;" }
571
+
572
+ end
442
573
 
443
574
  end
444
575
 
445
- line_by_line_contents = fix_syntax_indentation(line_by_line_contents)
576
+
577
+ line_by_line_contents = fix_syntax_indentation(line_by_line_contents).compact
446
578
 
447
579
  line_by_line_contents = line_by_line_contents.collect { |element| replace_ignored_words(element) }
448
580
 
581
+ line_by_line_contents = comment_fix(line_by_line_contents)
582
+
449
583
  return line_by_line_contents
450
584
 
451
585
  end