Class: ASTTransform::SourceMap
- Inherits:
-
Object
- Object
- ASTTransform::SourceMap
- Defined in:
- lib/ast_transform/source_map.rb
Instance Attribute Summary collapse
-
#source_file_path ⇒ Object
readonly
Returns the value of attribute source_file_path.
-
#source_map ⇒ Object
readonly
Returns the value of attribute source_map.
-
#transformed_file_path ⇒ Object
readonly
Returns the value of attribute transformed_file_path.
Class Method Summary collapse
-
.for_file_path(file_path) ⇒ SourceMap|nil
Retrieves the SourceMap for the given
file_path. -
.register_source_map(source_map) ⇒ void
Registers the given SourceMap.
Instance Method Summary collapse
-
#initialize(source_file_path, transformed_file_path, source_ranges_ast, transformed_ranges_ast) ⇒ SourceMap
constructor
Constructs a new SourceMap instance.
-
#line(line_number) ⇒ Integer|nil
Retrieves the mapped line number for the given
line_number. -
#line_count ⇒ Integer
Retrieves the line count for the executed code.
Constructor Details
#initialize(source_file_path, transformed_file_path, source_ranges_ast, transformed_ranges_ast) ⇒ SourceMap
Constructs a new SourceMap instance.
Note: source_ranges_ast and transformed_ranges_ast must be equivalent ASTs.
code.
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/ast_transform/source_map.rb', line 44 def initialize(source_file_path, transformed_file_path, source_ranges_ast, transformed_ranges_ast) @source_file_path = source_file_path @transformed_file_path = transformed_file_path @source_ranges_ast = source_ranges_ast @transformed_ranges_ast = transformed_ranges_ast @lines = Hash.new { |hash, key| hash[key] = [] } extract_source_map_data(@transformed_ranges_ast, []) @source_map = build_source_map.freeze end |
Instance Attribute Details
#source_file_path ⇒ Object (readonly)
Returns the value of attribute source_file_path.
55 56 57 |
# File 'lib/ast_transform/source_map.rb', line 55 def source_file_path @source_file_path end |
#source_map ⇒ Object (readonly)
Returns the value of attribute source_map.
55 56 57 |
# File 'lib/ast_transform/source_map.rb', line 55 def source_map @source_map end |
#transformed_file_path ⇒ Object (readonly)
Returns the value of attribute transformed_file_path.
55 56 57 |
# File 'lib/ast_transform/source_map.rb', line 55 def transformed_file_path @transformed_file_path end |
Class Method Details
.for_file_path(file_path) ⇒ SourceMap|nil
Retrieves the SourceMap for the given file_path.
24 25 26 |
# File 'lib/ast_transform/source_map.rb', line 24 def for_file_path(file_path) source_maps[file_path] end |
.register_source_map(source_map) ⇒ void
This method returns an undefined value.
Registers the given SourceMap.
12 13 14 15 16 17 |
# File 'lib/ast_transform/source_map.rb', line 12 def register_source_map(source_map) source_maps[source_map.transformed_file_path] = source_map source_maps[source_map.source_file_path] = source_map nil end |
Instance Method Details
#line(line_number) ⇒ Integer|nil
Retrieves the mapped line number for the given line_number.
62 63 64 |
# File 'lib/ast_transform/source_map.rb', line 62 def line(line_number) @source_map[line_number] end |
#line_count ⇒ Integer
Retrieves the line count for the executed code.
69 70 71 |
# File 'lib/ast_transform/source_map.rb', line 69 def line_count @transformed_ranges_ast&.loc&.expression&.last_line || 0 end |