module Preact::ComponentResolution if RUBY_ENGINE == 'opal' unless method_defined?(:_preact_component_resolution_original_method_missing) alias _preact_component_resolution_original_method_missing method_missing end def method_missing(component_name, *args, &block) # Further on it must check for modules, because $const_get does not take # the full nesting into account, as usually its called via $$ with the # nesting provided by the compiler. %x{ let constant; let sc = self.$class(); try { constant = sc.$const_get(component_name); } catch(err) { let module_names = sc.$to_s().split("::"); let module_name; for (let i = module_names.length - 1; i > 0; i--) { module_name = module_names.slice(0, i).join('::'); try { constant = sc.$const_get(module_name).$const_get(component_name, false); break; } catch(err) { } } } if (constant) { let last = args[args.length-1]; #{`Opal.Preact`._render_element(`constant`, `(last === undefined || last === null) ? nil : last`, &block)}; return nil; } return #{_preact_component_resolution_original_method_missing(component_name, *args, block)}; } end else unless method_defined?(:_preact_component_resolution_original_method_missing) alias _preact_component_resolution_original_method_missing method_missing end def method_missing(component_name, *args, &block) # Further on it must check for modules, because const_get does not take # the full nesting into account constant = nil if self.is_a?(Module) constant = const_get(component_name) rescue nil else begin constant = self.class.const_get(component_name) rescue module_names = self.class.to_s.split('::') module_names.each_index do |i| module_name = module_names[0..i].join('::') constant = self.class.const_get(module_name).const_get(component_name, false) rescue nil break if constant end end end if constant Preact._render_element(constant, args.last, &block) nil else _preact_component_resolution_original_method_missing(component_name, *args, block) end end end end