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, missing_dynamic_require = @missing_dynamic_require) ⇒ Object
-
#initialize(compiler, sexp, missing_dynamic_require = nil) ⇒ DependencyResolver
constructor
A new instance of DependencyResolver.
- #resolve ⇒ Object
Constructor Details
#initialize(compiler, sexp, missing_dynamic_require = nil) ⇒ DependencyResolver
Returns a new instance of DependencyResolver.
443 444 445 446 447 |
# File 'opal/lib/opal/nodes/call.rb', line 443 def initialize(compiler, sexp, missing_dynamic_require = nil) @compiler = compiler @sexp = sexp @missing_dynamic_require = missing_dynamic_require || @compiler.dynamic_require_severity end |
Instance Method Details
#expand_path(path, base = '') ⇒ Object
491 492 493 494 495 496 497 498 499 500 501 |
# File 'opal/lib/opal/nodes/call.rb', line 491 def (path, base = '') "#{base}/#{path}".split('/').each_with_object([]) do |part, p| if part == '' # we had '//', so ignore elsif part == '..' p.pop else p << part end end.join '/' end |
#handle_part(sexp, missing_dynamic_require = @missing_dynamic_require) ⇒ Object
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 |
# File 'opal/lib/opal/nodes/call.rb', line 453 def handle_part(sexp, missing_dynamic_require = @missing_dynamic_require) if sexp case sexp.type when :str return sexp.children[0] when :dstr return sexp.children.map { |i| handle_part i }.join when :begin return handle_part sexp.children[0] if sexp.children.length == 1 when :send recv, meth, *args = sexp.children parts = args.map { |s| handle_part(s, :ignore) } return nil if parts.include? nil if recv.is_a?(::Opal::AST::Node) && recv.type == :const && recv.children.last == :File if meth == :expand_path return (*parts) elsif meth == :join return parts.join('/') elsif meth == :dirname return parts[0].split('/')[0...-1].join('/') end elsif meth == :__dir__ return File.dirname(Opal::Compiler.module_name(@compiler.file)) end end end case missing_dynamic_require when :error @compiler.error 'Cannot handle dynamic require', @sexp.line when :warning @compiler.warning 'Cannot handle dynamic require', @sexp.line end end |
#resolve ⇒ Object
449 450 451 |
# File 'opal/lib/opal/nodes/call.rb', line 449 def resolve handle_part @sexp end |