import_js 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0c2841cf4974c8a53e788a4ec74e78091948e470
4
- data.tar.gz: 97e8905dc410a022a31522585054fda588a622c9
3
+ metadata.gz: 8482eba183609eed41a5a8a9564c4d81f8047875
4
+ data.tar.gz: 4c4b4d506a28dcbeab5ee3f29b21be24afa67750
5
5
  SHA512:
6
- metadata.gz: a0c6a2f736161c17bf7ad89b0921c36295618930f1b598c565e748e25ea74837662b78d835c9801464ced440bb8c2e52461942e75c598c3a80294229b5858603
7
- data.tar.gz: 9695778534d541cf215728512635f7d78b01e4f2c72ab315021e2d5b2900170e5db7379a4205e06b9ec7c1393b2ca31527519235a7a167670f31267e7856411d
6
+ metadata.gz: 73dd6ae7d9b26f4c03aa2cb37160bcb3eb48f1f7d27aa2642a830a7e83a5081290ea62bbda3865ea9ac99ab2561efcde9125182e53b699dfadd1592a827f4746
7
+ data.tar.gz: a991d45c0496e466fb36a13abfdfb006157e444a835b872b44373a5bda1a5a9fbecaecda4ebb754a78054358a3f7361677f293a1f3cf51f13c45fc0aee0cf752
@@ -71,7 +71,7 @@ module ImportJS
71
71
  # @param value [String]
72
72
  def set_default_variable(value)
73
73
  @default_variable = value
74
- @original_import_string = nil # clear import string cache if there was one
74
+ clear_import_string_cache
75
75
  end
76
76
 
77
77
  # Injects a new variable into an already existing set of destructured
@@ -82,7 +82,7 @@ module ImportJS
82
82
  destructured_variables << variable_name
83
83
  destructured_variables.sort!.uniq!
84
84
 
85
- @original_import_string = nil # clear import string cache if there was one
85
+ clear_import_string_cache
86
86
  end
87
87
 
88
88
  # Deletes a variable from an already existing default variable or set of
@@ -92,7 +92,7 @@ module ImportJS
92
92
  @default_variable = nil if default_variable == variable_name
93
93
  @destructured_variables.delete(variable_name) unless destructured_variables.nil?
94
94
 
95
- @original_import_string = nil # clear import string cache if there was one
95
+ clear_import_string_cache
96
96
  end
97
97
 
98
98
  # @return [Boolean] true if there are destructured variables
@@ -156,6 +156,22 @@ module ImportJS
156
156
  end
157
157
  end
158
158
 
159
+ # Merge another ImportStatement into this one.
160
+ # @param import_statement [ImportJS::ImportStatement]
161
+ def merge(import_statement)
162
+ unless import_statement.default_variable.nil?
163
+ @default_variable = import_statement.default_variable
164
+ clear_import_string_cache
165
+ end
166
+
167
+ if import_statement.destructured?
168
+ @destructured_variables ||= []
169
+ @destructured_variables.concat(import_statement.destructured_variables)
170
+ @destructured_variables.sort!.uniq!
171
+ clear_import_string_cache
172
+ end
173
+ end
174
+
159
175
  private
160
176
 
161
177
  # @return [String]
@@ -176,5 +192,9 @@ module ImportJS
176
192
  "#{declaration} #{value}"
177
193
  end
178
194
  end
195
+
196
+ def clear_import_string_cache
197
+ @original_import_string = nil
198
+ end
179
199
  end
180
200
  end
@@ -212,16 +212,7 @@ module ImportJS
212
212
  if imports[import_statement.path]
213
213
  # Import already exists, so this line is likely one of a destructuring
214
214
  # pair. Combine it into the same ImportStatement.
215
- unless import_statement.default_variable.nil?
216
- imports[import_statement.path].default_variable =
217
- import_statement.default_variable
218
- end
219
-
220
- if import_statement.destructured?
221
- imports[import_statement.path].destructured_variables ||= []
222
- imports[import_statement.path].destructured_variables
223
- .concat(import_statement.destructured_variables)
224
- end
215
+ imports[import_statement.path].merge(import_statement)
225
216
  else
226
217
  # This is a new import, so we just add it to the hash.
227
218
  imports[import_statement.path] = import_statement
@@ -1,4 +1,4 @@
1
1
  # Defines the gem version.
2
2
  module ImportJS
3
- VERSION = '0.2.3'
3
+ VERSION = '0.2.4'
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: import_js
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henric Trotzig