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.
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ast_transform/source_map.rb', line 43 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.
54 55 56 |
# File 'lib/ast_transform/source_map.rb', line 54 def source_file_path @source_file_path end |
#source_map ⇒ Object (readonly)
Returns the value of attribute source_map.
54 55 56 |
# File 'lib/ast_transform/source_map.rb', line 54 def source_map @source_map end |
#transformed_file_path ⇒ Object (readonly)
Returns the value of attribute transformed_file_path.
54 55 56 |
# File 'lib/ast_transform/source_map.rb', line 54 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.
23 24 25 |
# File 'lib/ast_transform/source_map.rb', line 23 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 |
# File 'lib/ast_transform/source_map.rb', line 12 def register_source_map(source_map) source_maps[source_map.transformed_file_path] = source_map nil end |
Instance Method Details
#line(line_number) ⇒ Integer|nil
Retrieves the mapped line number for the given line_number.
61 62 63 |
# File 'lib/ast_transform/source_map.rb', line 61 def line(line_number) @source_map[line_number] end |
#line_count ⇒ Integer
Retrieves the line count for the executed code.
68 69 70 |
# File 'lib/ast_transform/source_map.rb', line 68 def line_count @transformed_ranges_ast&.loc&.expression.last_line || 0 end |