jsobfu 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZTRlMThkN2MyNTFlMDE0MjcxY2M3ZWZlYzJhNjI3MjA1MWExMzMwMQ==
4
+ NGMzMzBiOTBjMWE5OThjNzQyOWU3OThjZjFmOTlmNGE3ZmYwMzI5YQ==
5
5
  data.tar.gz: !binary |-
6
- MTJkYmNkOTQzZjZkNTM3NTc4YWVlYTk5NTlkNWUwZWNkYWY0MmI1ZA==
6
+ NDM0ZmU2ZDk4OWRkMjU3YjEzNmEyZjRhOTYwYmE2OTIxZDZiNjlkZQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YTlkYWMzYmVhMzA5N2E0Y2FjNGFjODRjOWI1ZDRlZTU0NTZhMmEwNzM1MDky
10
- YzhmNTFhMjEwODI0M2VmZWIyMmU2MGJhNjM0ZWUzY2ExNzE2ZDY2NzEzODlk
11
- NzRhOGZlNjkxYzZlZGJiYjg3MGIyZmRkMTNmODkxZGNmZWNkZDE=
9
+ MjRlNWFmZGYyN2VmNzA1YmZiM2UzYTc5ZWY1NjhiYmI4ZTllZmRiZGVjOGNl
10
+ MjNmMmViZTkxOTExOGU1MjlmNWQ0MzU5OGFkZjlmNzA4MDIwY2QwMWEzYTli
11
+ ZmRlZTc1OWZkNTlhMDRlYzhlM2FiYmQyMjBhMTg1ZmVjMmRlMDI=
12
12
  data.tar.gz: !binary |-
13
- Y2ZiNTE2OGUxZTAyZTc0MzRmZTMwM2E1MjFlNDMwYThmMGM2MmY1MjQ2NDkx
14
- MjI5YjE0NGM2NzM3MzI5NTIzYzgzMDNkYjMwZjZiMWZiOWM0Y2Y5OWY1ZjJi
15
- MTEyZTZiNDVkODIwM2VhYWVlZTE2MjYxN2E5OTIxMzgyYjdiMTc=
13
+ Mjg5ZTYwODcyNjg2ODU3OTgyNjA1NTQ1MWI3MTE0YzMzZmIwYmMwMTllMGMw
14
+ YTE3NGYxOTdlYzk3NDBiMWFhMDhmZDFiNWFkODI3MTVjMTNjODkxNDA0Nzcy
15
+ YzQ2OTA0M2NlNmM1YWQ1YzhjNzY5OGQ3Y2M3MTE1NDE4MjgzZWE=
@@ -3,6 +3,9 @@
3
3
  # root scope, which is useful for "hoisting" var and function
4
4
  # declaration to the top of the function.
5
5
  #
6
+ # Although the auto-hoisting is no longer used, this class is used
7
+ # to "discover" a function's variables and scope.
8
+ #
6
9
  class JSObfu::Hoister < RKelly::Visitors::Visitor
7
10
 
8
11
  # @return [Hash] the scope maintained while walking the ast
@@ -11,12 +14,14 @@ class JSObfu::Hoister < RKelly::Visitors::Visitor
11
14
  # @return [Array<String>] the function names in the first level of this closure
12
15
  attr_reader :functions
13
16
 
17
+ # @param opts [Hash] the options hash
18
+ # @option opts [Integer] :max_depth the maximum depth to hoist (1)
19
+ # @option opts [Scope] :parent_scope the owner's scope
14
20
  def initialize(opts={})
15
21
  @parent_scope = opts.fetch(:parent_scope, nil)
16
22
  @max_depth = 1
17
23
  @depth = 0
18
24
  @scope = {}
19
- @resolves = []
20
25
  @functions = []
21
26
  super()
22
27
  end
@@ -33,7 +38,7 @@ class JSObfu::Hoister < RKelly::Visitors::Visitor
33
38
  end
34
39
 
35
40
  def visit_FunctionDeclNode(o)
36
- @functions << o.value
41
+ functions << o.value
37
42
  scope[o.value] = o
38
43
  end
39
44
 
@@ -69,16 +74,14 @@ class JSObfu::Hoister < RKelly::Visitors::Visitor
69
74
  keys = keys.shuffle
70
75
  end
71
76
 
72
- keys.delete_if { |k| @functions.include? k }
77
+ keys.delete_if { |k| functions.include? k }
73
78
 
74
79
  if @parent_scope
75
80
  keys.delete_if { |k| @parent_scope.has_key? k }
76
81
  keys.map! { |k| @parent_scope.renames[k.to_s] || k }
77
82
  end
78
83
 
79
- str = if keys.empty? then '' else "var #{keys.join(",")};" end
80
- # puts str if str.length>0
81
- str
84
+ if keys.empty? then '' else "var #{keys.join(",")};" end
82
85
  end
83
86
 
84
87
  end
@@ -42,7 +42,6 @@ class JSObfu::Obfuscator < JSObfu::ECMANoWhitespaceVisitor
42
42
  end
43
43
 
44
44
  ret = super
45
- ret = hoister.scope_declaration + ret
46
45
 
47
46
  scope.pop!
48
47
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsobfu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Lee