File tree Expand file tree Collapse file tree 5 files changed +23
-8
lines changed Expand file tree Collapse file tree 5 files changed +23
-8
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,8 @@ module Phlex
2727 CACHED_FILES = Set . new
2828 ATTRIBUTE_CACHE = FIFO . new
2929
30+ UNBOUND_INSTANCE_METHOD_METHOD = Module . instance_method ( :instance_method )
31+
3032 def self . __expand_attribute_cache__ ( file_path )
3133 unless CACHED_FILES . include? ( file_path )
3234 CACHED_FILES << file_path
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ def self.compile_file(path)
2727
2828 starting_line = last_line + 1
2929
30- results = FileCompiler . new . compile ( refract )
30+ results = FileCompiler . new ( path ) . compile ( refract )
3131
3232 result = Refract ::StatementsNode . new (
3333 body : results . map do |result |
Original file line number Diff line number Diff line change 11# frozen_string_literal: true
22
33class Phlex ::Compiler ::ClassCompiler < Refract ::Visitor
4- def initialize ( component )
4+ def initialize ( component , path )
55 super ( )
66 @component = component
7+ @path = path
78 @compiled_snippets = [ ]
89 end
910
@@ -16,6 +17,17 @@ def compile(node)
1617 return if node . name == :initialize
1718 return if node . receiver
1819
20+ method = begin
21+ Phlex ::UNBOUND_INSTANCE_METHOD_METHOD . bind_call ( @component , node . name )
22+ rescue NameError
23+ nil
24+ end
25+
26+ return unless method
27+ path , lineno = method . source_location
28+ return unless @path == path
29+ return unless node . start_line == lineno
30+
1931 @compiled_snippets << Phlex ::Compiler ::MethodCompiler . new (
2032 @component
2133 ) . compile ( node )
Original file line number Diff line number Diff line change 33class Phlex ::Compiler ::FileCompiler < Refract ::Visitor
44 Result = Data . define ( :namespace , :compiled_snippets )
55
6- def initialize
7- super
6+ def initialize ( path )
7+ super ( )
8+ @path = path
89 @current_namespace = [ ]
910 @results = [ ]
1011 end
@@ -32,7 +33,7 @@ def compile(node)
3233 if Class === const && Phlex ::SGML > const
3334 @results << Result . new (
3435 namespace : @current_namespace . dup . freeze ,
35- compiled_snippets : Phlex ::Compiler ::ClassCompiler . new ( const ) . compile ( node )
36+ compiled_snippets : Phlex ::Compiler ::ClassCompiler . new ( const , @path ) . compile ( node )
3637 )
3738 else
3839 super ( node )
Original file line number Diff line number Diff line change @@ -430,7 +430,7 @@ def compile_raw_helper(node)
430430
431431 private def standard_element? ( node )
432432 if ( tag = Phlex ::HTML ::StandardElements . __registered_elements__ [ node . name ] ) &&
433- ( Phlex ::HTML ::StandardElements == @component . instance_method ( node . name ) . owner )
433+ ( Phlex ::HTML ::StandardElements == Phlex :: UNBOUND_INSTANCE_METHOD_METHOD . bind_call ( @component , node . name ) . owner )
434434
435435 tag
436436 else
@@ -440,7 +440,7 @@ def compile_raw_helper(node)
440440
441441 private def void_element? ( node )
442442 if ( tag = Phlex ::HTML ::VoidElements . __registered_elements__ [ node . name ] ) &&
443- ( Phlex ::HTML ::VoidElements == @component . instance_method ( node . name ) . owner )
443+ ( Phlex ::HTML ::VoidElements == Phlex :: UNBOUND_INSTANCE_METHOD_METHOD . bind_call ( @component , node . name ) . owner )
444444
445445 tag
446446 else
@@ -506,7 +506,7 @@ def compile_raw_helper(node)
506506
507507 ALLOWED_OWNERS = Set [ Phlex ::SGML , Phlex ::HTML , Phlex ::SVG ]
508508 private def own_method_without_scope? ( node )
509- ALLOWED_OWNERS . include? ( @component . instance_method ( node . name ) . owner )
509+ ALLOWED_OWNERS . include? ( Phlex :: UNBOUND_INSTANCE_METHOD_METHOD . bind_call ( @component , node . name ) . owner )
510510 end
511511
512512 private def state_local
You can’t perform that action at this time.
0 commit comments