Class: Opal::Nodes::CallNode::DependencyResolver
- Inherits:
- 
      Object
      
        - Object
- Opal::Nodes::CallNode::DependencyResolver
 
- Defined in:
- opal/lib/opal/nodes/call.rb
Instance Method Summary collapse
- #expand_path(path, base = '') ⇒ Object
- #handle_part(sexp) ⇒ Object
- 
  
    
      #initialize(compiler, sexp)  ⇒ DependencyResolver 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of DependencyResolver. 
- #resolve ⇒ Object
Constructor Details
#initialize(compiler, sexp) ⇒ DependencyResolver
Returns a new instance of DependencyResolver
| 236 237 238 239 | # File 'opal/lib/opal/nodes/call.rb', line 236 def initialize(compiler, sexp) @compiler = compiler @sexp = sexp end | 
Instance Method Details
#expand_path(path, base = '') ⇒ Object
| 275 276 277 278 279 280 281 282 283 284 285 286 287 | # File 'opal/lib/opal/nodes/call.rb', line 275 def (path, base = '') "#{base}/#{path}".split("/").inject([]) do |p, part| if part == '' # we had '//', so ignore elsif part == '..' p.pop else p << part end p end.join "/" end | 
#handle_part(sexp) ⇒ Object
| 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | # File 'opal/lib/opal/nodes/call.rb', line 245 def handle_part(sexp) type = sexp.type if type == :str return sexp[1] elsif type == :call _, recv, meth, args = sexp parts = args[1..-1].map { |s| handle_part s } if recv == [:const, :File] if meth == :expand_path return (*parts) elsif meth == :join return parts.join('/') elsif meth == :dirname return parts[0].split('/')[0...-1].join('/') end end end msg = "Cannot handle dynamic require" case @compiler.dynamic_require_severity when :error @compiler.error msg, @sexp.line when :warning @compiler.warning msg, @sexp.line end end | 
#resolve ⇒ Object
| 241 242 243 | # File 'opal/lib/opal/nodes/call.rb', line 241 def resolve handle_part @sexp end |