class Opal::Nodes::CallNode::DependencyResolver
def expand_path(path, base = '')
def expand_path(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
def handle_part(sexp)
def handle_part(sexp) type = sexp.type if type == :str return sexp.children[0] elsif type == :send recv, meth, *args = sexp.children parts = args.map { |s| handle_part s } if recv.is_a?(::Opal::AST::Node) && recv.type == :const && recv.children.last == :File if meth == :expand_path return expand_path(*parts) elsif meth == :join return expand_path parts.join('/') elsif meth == :dirname return expand_path 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
def initialize(compiler, sexp)
def initialize(compiler, sexp) @compiler = compiler @sexp = sexp end
def resolve
def resolve handle_part @sexp end