js_regex 3.3.0 → 3.4.0

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: 0f418197d1c8fea37bd549b701049f1130bfca486c5a11ba25e56d7d0cf990f8
4
- data.tar.gz: 8679277fb51aca528933f4727cd0e70f1e1204c78acaf4e20da48d6b790ea7be
3
+ metadata.gz: 76344824ca1ba10360b72c42fce4fe6b667dd01761665a9b36c4ab071bbaecba
4
+ data.tar.gz: 37ceeda59137c6871be4d3782110d06c93e0f6be85c0332bad9a8afad0831d71
5
5
  SHA512:
6
- metadata.gz: ddeadbe690e2928c068d8c2962d80e88c50f5fef46304e46fa98e8dc215c6c57c7790e9ef7ba8b1f640e71c3ca834b7233449c9b7d68466ac76581de73c7ffe3
7
- data.tar.gz: 9c10d4e6a529ec54385ed55b34e4a910d354d7665f0831bc65b65bc20f176f4e46f9aa90cff2b36ea8f1306dfa65f7e42f4a93516ab228f206e74db7d708b779
6
+ metadata.gz: 2199e2674f5187352a9e7a428266e4d35290630e4111c24c4f2f2514d2e64f46fc98512c62d5c97831c3719ca3dd90cccb7dabacb9285faa8c2d8087af94d2ea
7
+ data.tar.gz: 235c68de51d6dc365f49354a5e79aa73f616ebd6e7386a7a596a3c09817a7a1b242a31024af3eae7206cf89395a8eadfce9c0819a14a62b56104a2c851850082
@@ -13,25 +13,27 @@ class JsRegex
13
13
  require_relative 'second_pass'
14
14
 
15
15
  class << self
16
- def of(ruby_regex, options: nil)
17
- source, warnings = convert_source(ruby_regex)
18
- options_string = convert_options(ruby_regex, options)
16
+ def of(input, options: nil)
17
+ source, warnings = convert_source(input)
18
+ options_string = convert_options(input, options)
19
19
  [source, options_string, warnings]
20
20
  end
21
21
 
22
22
  private
23
23
 
24
- def convert_source(ruby_regex)
25
- tree = Regexp::Parser.parse(ruby_regex)
24
+ def convert_source(input)
25
+ tree = Regexp::Parser.parse(input)
26
26
  context = Converter::Context.new(case_insensitive_root: tree.i?)
27
27
  converted_tree = Converter.convert(tree, context)
28
28
  final_tree = SecondPass.call(converted_tree)
29
29
  [final_tree.to_s, context.warnings]
30
30
  end
31
31
 
32
- def convert_options(ruby_regex, custom_options)
32
+ def convert_options(input, custom_options)
33
33
  options = custom_options.to_s.scan(/[gimuy]/)
34
- options << 'i' if (ruby_regex.options & Regexp::IGNORECASE).nonzero?
34
+ if input.is_a?(Regexp) && (input.options & Regexp::IGNORECASE).nonzero?
35
+ options << 'i'
36
+ end
35
37
  options.uniq.sort.join
36
38
  end
37
39
  end
@@ -32,18 +32,10 @@ class JsRegex
32
32
  MAP[expression.type].new
33
33
  end
34
34
 
35
- # Limit the number of generated surrogate pairs, else the output might
36
- # get to large for certain applications. The chosen number is somewhat
37
- # arbitrary. 100 pairs make for about 1 KB, uncompressed. The median char
38
- # count of all properties supported by Ruby is 92. 75% are below 300 chars.
39
- #
40
- # Set this to nil if you need full unicode matches and size doesn't matter.
41
- attr_writer :surrogate_pair_limit
42
-
43
- def in_surrogate_pair_limit?(&pair_count)
44
- @surrogate_pair_limit.nil? || @surrogate_pair_limit >= pair_count.call
35
+ # Legacy method. Remove in v4.0.0.
36
+ def surrogate_pair_limit=(_arg)
37
+ warn '#surrogate_pair_limit= is deprecated and has no effect anymore.'
45
38
  end
46
39
  end
47
- self.surrogate_pair_limit = 300
48
40
  end
49
41
  end
@@ -15,35 +15,15 @@ class JsRegex
15
15
  private
16
16
 
17
17
  def convert_data
18
- content = character_set_of_property
18
+ content = CharacterSet.of_expression(expression)
19
19
 
20
- if expression.negative?
21
- if content.astral_part?
22
- warn_of_unsupported_feature('astral plane negation by property')
23
- end
24
- elsif Converter.in_surrogate_pair_limit? { content.astral_part.size }
25
- return content.to_s_with_surrogate_alternation
26
- else
27
- warn_of_unsupported_feature('large astral plane match of property')
28
- end
29
-
30
- limit_to_bmp_part(content)
31
- end
32
-
33
- def character_set_of_property
34
- character_set = CharacterSet.of_property(subtype)
35
20
  if expression.case_insensitive? && !context.case_insensitive_root
36
- character_set.case_insensitive
37
- else
38
- character_set
21
+ content = content.case_insensitive
22
+ elsif !expression.case_insensitive? && context.case_insensitive_root
23
+ warn_of_unsupported_feature('nested case-sensitive property')
39
24
  end
40
- end
41
-
42
- def limit_to_bmp_part(content)
43
- bmp_part = content.bmp_part
44
- return drop if bmp_part.empty?
45
25
 
46
- "[#{'^' if expression.negative?}#{bmp_part}]"
26
+ content.to_s_with_surrogate_ranges
47
27
  end
48
28
  end
49
29
  end
@@ -28,11 +28,7 @@ class JsRegex
28
28
  warn_of_unsupported_feature('nested case-sensitive set')
29
29
  end
30
30
 
31
- if Converter.in_surrogate_pair_limit? { content.astral_part.size }
32
- content.to_s_with_surrogate_alternation
33
- else
34
- limit_to_bmp_part_with_warning(content)
35
- end
31
+ content.to_s_with_surrogate_ranges
36
32
  end
37
33
 
38
34
  def directly_compatible?
@@ -66,13 +62,9 @@ class JsRegex
66
62
  end
67
63
 
68
64
  def pass_through_with_escaping
69
- expression.to_s(:base).gsub(%r{\\?([\f\n\r\t])}) { Regexp.escape($1) }
70
- end
71
-
72
- def limit_to_bmp_part_with_warning(content)
73
- warn_of_unsupported_feature('large astral plane match of set')
74
- bmp_part = content.bmp_part
75
- bmp_part.empty? ? drop : bmp_part.to_s(in_brackets: true)
65
+ expression.to_s(:base).gsub(%r{([\f\n\r\t])|(/)}) do
66
+ $1 ? Regexp.escape($1) : "\\#{$2}"
67
+ end
76
68
  end
77
69
  end
78
70
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class JsRegex
4
- VERSION = '3.3.0'
4
+ VERSION = '3.4.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: js_regex
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.0
4
+ version: 3.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Janosch Müller
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-26 00:00:00.000000000 Z
11
+ date: 2019-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: character_set
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.3'
19
+ version: '1.4'
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: '1.3'
26
+ version: '1.4'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: regexp_parser
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -122,6 +122,34 @@ dependencies:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0.12'
125
+ - !ruby/object:Gem::Dependency
126
+ name: codecov
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '0.1'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.1'
139
+ - !ruby/object:Gem::Dependency
140
+ name: mutant-rspec
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '0.8'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '0.8'
125
153
  description: JsRegex converts Ruby's native regular expressions for JavaScript, taking
126
154
  care of various incompatibilities and returning warnings for unsolvable differences.
127
155
  email: