Class: JSObfu::ECMANoWhitespaceVisitor

Inherits:
RKelly::Visitors::ECMAVisitor
  • Object
show all
Defined in:
lib/jsobfu/ecma_tight.rb

Overview

Implements an ECMAVisitor with minimal whitespace and indentation.

Mostly a line-by-line copy of RKelly::Visitors::ECMAVisitor with the whitespace trimmed out.

Direct Known Subclasses

Obfuscator

Instance Method Summary (collapse)

Instance Method Details

- (Object) function_params_and_body(o)

Helper for all the various function nodes



277
278
279
280
# File 'lib/jsobfu/ecma_tight.rb', line 277

def function_params_and_body(o)
  "(#{o.arguments.map { |x| x.accept(self) }.join(',')})" +
    "#{o.function_body.accept(self)}"
end

- (Object) visit_ArgumentsNode(o)



77
78
79
# File 'lib/jsobfu/ecma_tight.rb', line 77

def visit_ArgumentsNode(o)
  o.value.map { |x| x.accept(self) }.join(',')
end

- (Object) visit_ArrayNode(o)



141
142
143
# File 'lib/jsobfu/ecma_tight.rb', line 141

def visit_ArrayNode(o)
  "[#{o.value.map { |x| x ? x.accept(self) : '' }.join(',')}]"
end

- (Object) visit_AssignExprNode(o)



29
30
31
# File 'lib/jsobfu/ecma_tight.rb', line 29

def visit_AssignExprNode(o)
  "=#{o.value.accept(self)}"
end

- (Object) visit_BitwiseNotNode(o)



133
134
135
# File 'lib/jsobfu/ecma_tight.rb', line 133

def visit_BitwiseNotNode(o)
  "~#{o.value.accept(self)}"
end

- (Object) visit_BlockNode(o)



61
62
63
# File 'lib/jsobfu/ecma_tight.rb', line 61

def visit_BlockNode(o)
  "{#{o.value.accept(self)}}"
end

- (Object) visit_BracketAccessorNode(o)



308
309
310
# File 'lib/jsobfu/ecma_tight.rb', line 308

def visit_BracketAccessorNode(o)
  "#{o.value.accept(self)}[#{o.accessor.accept(self)}]"
end

- (Object) visit_BreakNode(o)



101
102
103
# File 'lib/jsobfu/ecma_tight.rb', line 101

def visit_BreakNode(o)
  "break" + (o.value ? " #{o.value}" : '') + ';'
end

- (Object) visit_CaseBlockNode(o)



229
230
231
# File 'lib/jsobfu/ecma_tight.rb', line 229

def visit_CaseBlockNode(o)
  "{" + (o.value ? o.value.map { |x| x.accept(self) }.join('') : '') + "}"
end

- (Object) visit_CaseClauseNode(o)



233
234
235
236
237
238
239
240
241
# File 'lib/jsobfu/ecma_tight.rb', line 233

def visit_CaseClauseNode(o)
  if o.left
    case_code = "case #{o.left.accept(self)}:"
  else
    case_code = "default:"
  end
  case_code += "#{o.value.accept(self)}"
  case_code
end

- (Object) visit_CommaNode(o)



282
283
284
# File 'lib/jsobfu/ecma_tight.rb', line 282

def visit_CommaNode(o)
  "#{o.left.accept(self)},#{o.value.accept(self)}"
end

- (Object) visit_ConditionalNode(o)



291
292
293
294
# File 'lib/jsobfu/ecma_tight.rb', line 291

def visit_ConditionalNode(o)
  "#{o.conditions.accept(self)}?#{o.value.accept(self)}:" +
    "#{o.else.accept(self)}"
end

- (Object) visit_ConstStatementNode(o)



21
22
23
# File 'lib/jsobfu/ecma_tight.rb', line 21

def visit_ConstStatementNode(o)
  "const #{o.value.map { |x| x.accept(self) }.join(',')};"
end

- (Object) visit_ContinueNode(o)



105
106
107
# File 'lib/jsobfu/ecma_tight.rb', line 105

def visit_ContinueNode(o)
  "continue" + (o.value ? " #{o.value}" : '') + ';'
end

- (Object) visit_DeleteNode(o)



137
138
139
# File 'lib/jsobfu/ecma_tight.rb', line 137

def visit_DeleteNode(o)
  "delete #{o.value.accept(self)}"
end

- (Object) visit_DotAccessorNode(o)



125
126
127
# File 'lib/jsobfu/ecma_tight.rb', line 125

def visit_DotAccessorNode(o)
  "#{o.value.accept(self)}.#{o.accessor}"
end

- (Object) visit_DoWhileNode(o)



243
244
245
# File 'lib/jsobfu/ecma_tight.rb', line 243

def visit_DoWhileNode(o)
  "do#{o.left.accept(self)}while(#{o.value.accept(self)});"
end

- (Object) visit_ElementNode(o)



145
146
147
# File 'lib/jsobfu/ecma_tight.rb', line 145

def visit_ElementNode(o)
  o.value.accept(self)
end

- (Object) visit_EmptyStatementNode(o)



117
118
119
# File 'lib/jsobfu/ecma_tight.rb', line 117

def visit_EmptyStatementNode(o)
  ';'
end

- (Object) visit_ExpressionStatementNode(o)



65
66
67
# File 'lib/jsobfu/ecma_tight.rb', line 65

def visit_ExpressionStatementNode(o)
  "#{o.value.accept(self)};"
end

- (Object) visit_FalseNode(o)



113
114
115
# File 'lib/jsobfu/ecma_tight.rb', line 113

def visit_FalseNode(o)
  "false"
end

- (Object) visit_ForInNode(o)



296
297
298
299
300
# File 'lib/jsobfu/ecma_tight.rb', line 296

def visit_ForInNode(o)
  var = o.left.is_a?(RKelly::Nodes::VarDeclNode) ? 'var ' : ''
  "for(#{var}#{o.left.accept(self)} in #{o.right.accept(self)})" +
    "#{o.value.accept(self)}"
end

- (Object) visit_ForNode(o)



37
38
39
40
41
42
43
# File 'lib/jsobfu/ecma_tight.rb', line 37

def visit_ForNode(o)
  init    = o.init ? o.init.accept(self) : ';'
  init    << ';' unless init.end_with? ';' # make sure it has a ;
  test    = o.test ? o.test.accept(self) : ''
  counter = o.counter ? o.counter.accept(self) : ''
  "for(#{init}#{test};#{counter})#{o.value.accept(self)}"
end

- (Object) visit_FunctionBodyNode(o)



97
98
99
# File 'lib/jsobfu/ecma_tight.rb', line 97

def visit_FunctionBodyNode(o)
  "{#{o.value.accept(self)}}"
end

- (Object) visit_FunctionCallNode(o)



73
74
75
# File 'lib/jsobfu/ecma_tight.rb', line 73

def visit_FunctionCallNode(o)
  "#{o.value.accept(self)}(#{o.arguments.accept(self)})"
end

- (Object) visit_FunctionDeclNode(o)



89
90
91
# File 'lib/jsobfu/ecma_tight.rb', line 89

def visit_FunctionDeclNode(o)
  "function #{o.value}" + function_params_and_body(o)
end

- (Object) visit_FunctionExprNode(o)



271
272
273
274
# File 'lib/jsobfu/ecma_tight.rb', line 271

def visit_FunctionExprNode(o)
  name = (o.value == 'function') ? '' : ' '+o.value
  "function" + name + function_params_and_body(o)
end

- (Object) visit_GetterPropertyNode(o)



263
264
265
# File 'lib/jsobfu/ecma_tight.rb', line 263

def visit_GetterPropertyNode(o)
  "get #{o.name}" + function_params_and_body(o.value)
end

- (Object) visit_IfNode(o)



286
287
288
289
# File 'lib/jsobfu/ecma_tight.rb', line 286

def visit_IfNode(o)
  "if(#{o.conditions.accept(self)})#{o.value.accept(self)}" +
    (o.else ? "else #{o.else.accept(self)}" : '')
end

- (Object) visit_LabelNode(o)



251
252
253
# File 'lib/jsobfu/ecma_tight.rb', line 251

def visit_LabelNode(o)
  "#{o.name}:#{o.value.accept(self)}"
end

- (Object) visit_LessNode(o)



45
46
47
# File 'lib/jsobfu/ecma_tight.rb', line 45

def visit_LessNode(o)
  "#{o.left.accept(self)}<#{o.value.accept(self)}"
end

- (Object) visit_LogicalNotNode(o)



149
150
151
# File 'lib/jsobfu/ecma_tight.rb', line 149

def visit_LogicalNotNode(o)
  "!#{o.value.accept(self)}"
end

- (Object) visit_NewExprNode(o)



312
313
314
# File 'lib/jsobfu/ecma_tight.rb', line 312

def visit_NewExprNode(o)
  "new #{o.value.accept(self)}(#{o.arguments.accept(self)})"
end

- (Object) visit_NullNode(o)



85
86
87
# File 'lib/jsobfu/ecma_tight.rb', line 85

def visit_NullNode(o)
  "null"
end

- (Object) visit_NumberNode(o)



33
34
35
# File 'lib/jsobfu/ecma_tight.rb', line 33

def visit_NumberNode(o)
  o.value.to_s
end

- (Object) visit_ObjectLiteralNode(o)



255
256
257
# File 'lib/jsobfu/ecma_tight.rb', line 255

def visit_ObjectLiteralNode(o)
  "{" + o.value.map { |x| x.accept(self) }.join(",\n") + '}'
end

- (Object) visit_OpEqualNode(o)



69
70
71
# File 'lib/jsobfu/ecma_tight.rb', line 69

def visit_OpEqualNode(o)
  "#{o.left.accept(self)}=#{o.value.accept(self)}"
end

- (Object) visit_ParameterNode(o)



93
94
95
# File 'lib/jsobfu/ecma_tight.rb', line 93

def visit_ParameterNode(o)
  o.value
end

- (Object) visit_ParentheticalNode(o)



9
10
11
# File 'lib/jsobfu/ecma_tight.rb', line 9

def visit_ParentheticalNode(o)
  "(#{o.value.accept(self)})"
end

- (Object) visit_PostfixNode(o)



53
54
55
# File 'lib/jsobfu/ecma_tight.rb', line 53

def visit_PostfixNode(o)
  "#{o.operand.accept(self)}#{o.value}"
end

- (Object) visit_PrefixNode(o)



57
58
59
# File 'lib/jsobfu/ecma_tight.rb', line 57

def visit_PrefixNode(o)
  "#{o.value}#{o.operand.accept(self)}"
end

- (Object) visit_PropertyNode(o)



259
260
261
# File 'lib/jsobfu/ecma_tight.rb', line 259

def visit_PropertyNode(o)
  "#{o.name}:#{o.value.accept(self)}"
end

- (Object) visit_RegexpNode(o)



121
122
123
# File 'lib/jsobfu/ecma_tight.rb', line 121

def visit_RegexpNode(o)
  o.value
end

- (Object) visit_ResolveNode(o)



49
50
51
# File 'lib/jsobfu/ecma_tight.rb', line 49

def visit_ResolveNode(o)
  o.value
end

- (Object) visit_ReturnNode(o)



161
162
163
# File 'lib/jsobfu/ecma_tight.rb', line 161

def visit_ReturnNode(o)
  "return" + (o.value ? " #{o.value.accept(self)}" : '') + ';'
end

- (Object) visit_SetterPropertyNode(o)



267
268
269
# File 'lib/jsobfu/ecma_tight.rb', line 267

def visit_SetterPropertyNode(o)
  "set #{o.name}" + function_params_and_body(o.value)
end

- (Object) visit_SourceElementsNode(o)



13
14
15
# File 'lib/jsobfu/ecma_tight.rb', line 13

def visit_SourceElementsNode(o)
  o.value.map { |x| "#{x.accept(self)}" }.join
end

- (Object) visit_StringNode(o)



81
82
83
# File 'lib/jsobfu/ecma_tight.rb', line 81

def visit_StringNode(o)
  o.value
end

- (Object) visit_SwitchNode(o)



225
226
227
# File 'lib/jsobfu/ecma_tight.rb', line 225

def visit_SwitchNode(o)
  "switch(#{o.left.accept(self)})#{o.value.accept(self)}"
end

- (Object) visit_ThisNode(o)



129
130
131
# File 'lib/jsobfu/ecma_tight.rb', line 129

def visit_ThisNode(o)
  "this"
end

- (Object) visit_ThrowNode(o)



165
166
167
# File 'lib/jsobfu/ecma_tight.rb', line 165

def visit_ThrowNode(o)
  "throw #{o.value.accept(self)};"
end

- (Object) visit_TrueNode(o)



109
110
111
# File 'lib/jsobfu/ecma_tight.rb', line 109

def visit_TrueNode(o)
  "true"
end

- (Object) visit_TryNode(o)



302
303
304
305
306
# File 'lib/jsobfu/ecma_tight.rb', line 302

def visit_TryNode(o)
  "try#{o.value.accept(self)}" +
    (o.catch_block ? " catch(#{o.catch_var})#{o.catch_block.accept(self)}" : '') +
    (o.finally_block ? " finally#{o.finally_block.accept(self)}" : '')
end

- (Object) visit_TypeOfNode(o)



169
170
171
# File 'lib/jsobfu/ecma_tight.rb', line 169

def visit_TypeOfNode(o)
  "typeof #{o.value.accept(self)}"
end

- (Object) visit_UnaryMinusNode(o)



153
154
155
# File 'lib/jsobfu/ecma_tight.rb', line 153

def visit_UnaryMinusNode(o)
  "-#{o.value.accept(self)}"
end

- (Object) visit_UnaryPlusNode(o)



157
158
159
# File 'lib/jsobfu/ecma_tight.rb', line 157

def visit_UnaryPlusNode(o)
  "+#{o.value.accept(self)}"
end

- (Object) visit_VarDeclNode(o)



25
26
27
# File 'lib/jsobfu/ecma_tight.rb', line 25

def visit_VarDeclNode(o)
  "#{o.name}#{o.value ? o.value.accept(self) : nil}"
end

- (Object) visit_VarStatementNode(o)



17
18
19
# File 'lib/jsobfu/ecma_tight.rb', line 17

def visit_VarStatementNode(o)
  "var #{o.value.map { |x| x.accept(self) }.join(',')};"
end

- (Object) visit_VoidNode(o)



173
174
175
# File 'lib/jsobfu/ecma_tight.rb', line 173

def visit_VoidNode(o)
  "void(#{o.value.accept(self)})"
end

- (Object) visit_WhileNode(o)



221
222
223
# File 'lib/jsobfu/ecma_tight.rb', line 221

def visit_WhileNode(o)
  "while(#{o.left.accept(self)})#{o.value.accept(self)}"
end

- (Object) visit_WithNode(o)



247
248
249
# File 'lib/jsobfu/ecma_tight.rb', line 247

def visit_WithNode(o)
  "with(#{o.left.accept(self)})#{o.value.accept(self)}"
end