Class: ParseJS::FindVars

Inherits:
Visitor show all
Defined in:
lib/parsejs/docs.rb

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from Visitor

#accept, #map, #visit, #visit_ArrayExpression, #visit_AssignmentExpression, #visit_BinaryExpression, #visit_BlockStatement, #visit_BreakStatement, #visit_CallExpression, #visit_CatchClause, #visit_Comment, #visit_CommentedStatement, #visit_ConditionalExpression, #visit_ContinueStatement, #visit_DebuggerStatement, #visit_DoWhileStatement, #visit_EmptyStatement, #visit_ExpressionStatement, #visit_ForInStatement, #visit_ForStatement, #visit_Identifier, #visit_IfStatement, #visit_Literal, #visit_LogicalExpression, #visit_MemberExpression, #visit_NewExpression, #visit_Number, #visit_ObjectExpression, #visit_ParameterList, #visit_Program, #visit_Property, #visit_RegExp, #visit_ReturnStatement, #visit_SequenceExpression, #visit_String, #visit_SwitchCase, #visit_SwitchStatement, #visit_ThisExpression, #visit_ThrowStatement, #visit_TryStatement, #visit_UnaryExpression, #visit_UpdateExpression, #visit_VariableDeclaration, #visit_WhileStatement, #visit_WithStatement

Constructor Details

- (FindVars) initialize

Returns a new instance of FindVars



229
230
231
232
# File 'lib/parsejs/docs.rb', line 229

def initialize(*)
  @variables = Set.new
  super
end

Instance Attribute Details

- (Object) variables (readonly)

Returns the value of attribute variables



227
228
229
# File 'lib/parsejs/docs.rb', line 227

def variables
  @variables
end

Class Method Details

+ (Object) find_variables(ast)



219
220
221
222
223
224
225
# File 'lib/parsejs/docs.rb', line 219

def self.find_variables(ast)
  ast = Marshal.load(Marshal.dump(ast))

  finder = new
  finder.accept(ast)
  finder.variables
end

Instance Method Details

- (Object) visit_FunctionDeclaration



238
239
# File 'lib/parsejs/docs.rb', line 238

def visit_FunctionDeclaration(*)
end

- (Object) visit_FunctionExpression



241
242
# File 'lib/parsejs/docs.rb', line 241

def visit_FunctionExpression(*)
end

- (Object) visit_VariableDeclarator(expr)



234
235
236
# File 'lib/parsejs/docs.rb', line 234

def visit_VariableDeclarator(expr)
  @variables << expr.id.val
end