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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff515ae6bc72607dd216a1889d5e246d390c2c6bc2ccb9a3662509bac6b2a678
|
4
|
+
data.tar.gz: 7b4fc0bb7d5b5a6c79201f8dfb3ba94c6aef8e3d27fb0187f20d19df86fe72cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f19644fbd69e00c3145263430e7425f9f0b2b843a34fa1feba5c71c5b4ae816ffef764c10650e75a77e71bf9d00be509fb31a56940387083a4a53205d273d93
|
7
|
+
data.tar.gz: 0f346607cc9e18bd54e546c1e725ef5e925ab90f02fbcf1d17c37846c44497040696620644362fd6d02ba00e5bcb3f321ba584e6cabbe8653326e3d5727a96c4
|
data/lib/dead_code_terminator.rb
CHANGED
@@ -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(
|
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
|
-
#
|
7
|
-
#
|
8
|
-
# s(:
|
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 != :
|
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
|
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.
|
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:
|