dead_code_terminator 0.3.0 → 0.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: 30f177ea46b025d82a1647deb392a82ea79bf7d188180b01db1d3b7c9914772f
4
- data.tar.gz: a1e654d7c848fea862cf3c3fdbf07e42096457e4994beb76f7b8c0fe6b83580a
3
+ metadata.gz: ff515ae6bc72607dd216a1889d5e246d390c2c6bc2ccb9a3662509bac6b2a678
4
+ data.tar.gz: 7b4fc0bb7d5b5a6c79201f8dfb3ba94c6aef8e3d27fb0187f20d19df86fe72cd
5
5
  SHA512:
6
- metadata.gz: 01d433228fbd4f63be908d7b0841d42514442f6fdf4d5c1ba54c241b4746284a430594d19061eb2a4926c0e7639cdc5694cdf12b16a498f41bb131ce2ff0bdc4
7
- data.tar.gz: 4405404ec2c1e561177c7a3780d8b8511fbae3a1545d02231bc5b261845d4eb1925e081f1a1f439d482314785868ee9b2b7dacd8a472e9e9b698f855d13f26b5
6
+ metadata.gz: 5f19644fbd69e00c3145263430e7425f9f0b2b843a34fa1feba5c71c5b4ae816ffef764c10650e75a77e71bf9d00be509fb31a56940387083a4a53205d273d93
7
+ data.tar.gz: 0f346607cc9e18bd54e546c1e725ef5e925ab90f02fbcf1d17c37846c44497040696620644362fd6d02ba00e5bcb3f321ba584e6cabbe8653326e3d5727a96c4
@@ -26,5 +26,4 @@ Gem::Specification.new do |spec|
26
26
  spec.require_paths = ["lib"]
27
27
 
28
28
  spec.add_dependency "parser", ">= 2.5.0.0"
29
- spec.add_dependency "unparser", "~> 0.6"
30
29
  end
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "parser/current"
4
- require "unparser"
5
4
  require_relative "dead_code_terminator/version"
6
5
  require_relative "dead_code_terminator/ast"
7
6
  require_relative "dead_code_terminator/cond"
@@ -14,7 +13,7 @@ module DeadCodeTerminator
14
13
  class Error < StandardError; end
15
14
 
16
15
  def self.strip(io, env: {})
17
- replaces = on_node(Unparser.parse(io)) do |ast|
16
+ replaces = on_node(Parser::CurrentRuby.parse(io)) do |ast|
18
17
  Ast.new(env: env, ast: ast).process if ast.type == :if
19
18
  end
20
19
 
@@ -3,23 +3,28 @@
3
3
  module DeadCodeTerminator
4
4
  module Cond
5
5
  # ENV['PRODUCTION']
6
- # s(:index,
7
- # s(:const, nil, :ENV),
8
- # s(:str, "PRODUCTION"))
6
+ #
7
+ # s(:send,
8
+ # s(:const, nil, :ENV), :[],
9
+ # s(:str, "FLAG"))
9
10
  class EnvIndex < Base
10
11
  def value
11
- return if ast.type != :index
12
+ return if ast.type != :send
13
+
14
+ hash, bracket_meth, *args = ast.children
12
15
 
13
- hash, key = ast.children
14
16
  return if hash != s(:const, nil, :ENV)
15
17
 
18
+ return if bracket_meth != :[]
19
+
20
+ return if args.size != 1
21
+
22
+ key = args[0]
16
23
  return unless (matched_env_key = given_env_key(key))
17
24
 
18
25
  env[matched_env_key] ? THEN : ELSE
19
26
  end
20
27
 
21
- private
22
-
23
28
  def given_env_key(ast)
24
29
  env.keys.detect { |key| ast == s(:str, key) }
25
30
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DeadCodeTerminator
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dead_code_terminator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vlad Bokov
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 2.5.0.0
27
- - !ruby/object:Gem::Dependency
28
- name: unparser
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '0.6'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '0.6'
41
27
  description: Statically remove dead conditional branches, acts like webpack's DefinePlugin
42
28
  and minifier
43
29
  email: