ruby2js 4.1.1 → 4.1.2

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
  SHA256:
3
- metadata.gz: 6b96695d82101133b8d791e19d0f04fa5c6c56c16bb6504b447cf26e0e1291db
4
- data.tar.gz: 9a7711f281076e14e354bcab9fd8f96de5b884153360a9b5fdb57b6fa9c5a792
3
+ metadata.gz: 696f01a3f2781f8821257f1d2d0ed832e45a9fbde25c2f6f9f200ced90b24dab
4
+ data.tar.gz: d4bc6d38fb7146b3615e621e7c86fc8e864895d377d10ecf69599fa60b7808d3
5
5
  SHA512:
6
- metadata.gz: f64daa6dad4b3ed8d475654e588a8f921782fc11aceecb01886b8c039139bdc716f863eb25f57c119410da1a180273cbf9f66992da0555ce66b1131c31deab44
7
- data.tar.gz: f5ffccf5acc15710797fc566ba89730f34d5884492892d4972fa9d4ad6ef785e1875bd4e3ffb25a9cb0148d77c4501aed8ea21e3f1171c55c5ca13104c274f56
6
+ metadata.gz: f82772a1dc3aefde7a5acb6b7ca3b05a083dbb3e4c9bbdcf585387ae950c6d410280dfe069d0be3d5fd5e28a5eb0524f2c35ccac83c3b9789109a45e2ceb29a9
7
+ data.tar.gz: dffb0cd058bc9cdf28b76e99d73cb4916792bd9160ff9516994b3de2bc1b46e22c5d5be9bb772ec0f62c5947f5d73218e9d5fbd69e5e8a28b450875b92940ed7
@@ -359,6 +359,7 @@ require 'ruby2js/converter/kwbegin'
359
359
  require 'ruby2js/converter/literal'
360
360
  require 'ruby2js/converter/logical'
361
361
  require 'ruby2js/converter/masgn'
362
+ require 'ruby2js/converter/match'
362
363
  require 'ruby2js/converter/module'
363
364
  require 'ruby2js/converter/next'
364
365
  require 'ruby2js/converter/nil'
@@ -0,0 +1,7 @@
1
+ module Ruby2JS
2
+ class Converter
3
+ handle :match_pattern do |value, name|
4
+ parse @ast.updated(:lvasgn, [name.children.first, value]), @state
5
+ end
6
+ end
7
+ end
@@ -300,22 +300,29 @@ module Ruby2JS
300
300
  BASE64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
301
301
 
302
302
  # https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit
303
+ # http://sokra.github.io/source-map-visualization/
303
304
  def vlq(*mark)
304
- if @mark[0] == mark[0]
305
- return if @mark[-3..-1] == mark[-3..-1]
306
- @mappings += ',' unless @mappings == ''
305
+ if !@mark
306
+ diffs = mark
307
+ @mark = [0, 0, 0, 0, 0, 0]
308
+ else
309
+ if @mark[0] == mark[0]
310
+ return if @mark[4] == mark[4] and @mark[3] == mark[3]
311
+ @mappings += ',' unless @mappings == ''
312
+ end
313
+
314
+ diffs = mark.zip(@mark).map {|a,b| a-b}
307
315
  end
308
316
 
309
317
  while @mark[0] < mark[0]
310
318
  @mappings += ';'
311
319
  @mark[0] += 1
312
- @mark[1] = 0
320
+ diffs[1] = mark[1]
313
321
  end
314
322
 
315
- diffs = mark.zip(@mark).map {|a,b| a-b}
316
- @mark = mark
323
+ @mark[0...mark.length] = mark
317
324
 
318
- diffs[1..4].each do |diff|
325
+ diffs[1..-1].each do |diff|
319
326
  if diff < 0
320
327
  data = (-diff << 1) + 1
321
328
  else
@@ -345,7 +352,8 @@ module Ruby2JS
345
352
 
346
353
  @mappings = ''
347
354
  sources = []
348
- @mark = [0, 0, 0, 0, 0]
355
+ names = []
356
+ @mark = nil
349
357
 
350
358
  @lines.each_with_index do |line, row|
351
359
  col = line.indent
@@ -361,8 +369,30 @@ module Ruby2JS
361
369
  sources << buffer
362
370
  end
363
371
 
364
- split = buffer.source[0...pos].split("\n")
365
- vlq row, col, source_index, [split.length - 1, 0].max, split.last.to_s.length
372
+ line = buffer.line_for_position(pos) - 1
373
+ column = buffer.column_for_position(pos)
374
+
375
+ name = nil
376
+ if %i{lvasgn lvar}.include? token.ast.type
377
+ name = token.ast.children.first
378
+ elsif %i{casgn const}.include? token.ast.type
379
+ if token.ast.children.first == nil
380
+ name = token.ast.children[1]
381
+ end
382
+ end
383
+
384
+ if name
385
+ index = names.find_index(name)
386
+
387
+ unless index
388
+ index = names.length
389
+ names << name
390
+ end
391
+
392
+ vlq row, col, source_index, line, column, index
393
+ else
394
+ vlq row, col, source_index, line, column
395
+ end
366
396
  end
367
397
  col += token.length
368
398
  end
@@ -372,6 +402,7 @@ module Ruby2JS
372
402
  version: 3,
373
403
  file: @file_name,
374
404
  sources: sources.map(&:name),
405
+ names: names.map(&:to_s),
375
406
  mappings: @mappings
376
407
  }
377
408
  end
@@ -2,7 +2,7 @@ module Ruby2JS
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 4
4
4
  MINOR = 1
5
- TINY = 1
5
+ TINY = 2
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby2js
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.1
4
+ version: 4.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Ruby
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-03-26 00:00:00.000000000 Z
12
+ date: 2021-04-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: parser
@@ -85,6 +85,7 @@ files:
85
85
  - lib/ruby2js/converter/literal.rb
86
86
  - lib/ruby2js/converter/logical.rb
87
87
  - lib/ruby2js/converter/masgn.rb
88
+ - lib/ruby2js/converter/match.rb
88
89
  - lib/ruby2js/converter/module.rb
89
90
  - lib/ruby2js/converter/next.rb
90
91
  - lib/ruby2js/converter/nil.rb