Class: TypeScript::Merge::NodeWrapper
- Inherits:
-
Object
- Object
- TypeScript::Merge::NodeWrapper
- Defined in:
- lib/typescript/merge/node_wrapper.rb,
sig/typescript/merge.rbs
Overview
Structural identity and source-range adapter for one top-level TypeScript owner. rubocop:disable Metrics/AbcSize, Metrics/ClassLength, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity -- TypeScript declaration forms share one structural identity boundary
Constant Summary collapse
- DECLARATION_TYPES =
%w[ ambient_declaration class_declaration enum_declaration expression_statement export_statement function_declaration function_signature import_statement interface_declaration internal_module lexical_declaration type_alias_declaration variable_declaration ].freeze
- NAMED_DECLARATIONS =
{ 'class_declaration' => [:class, %w[type_identifier identifier]], 'enum_declaration' => [:enum, %w[identifier type_identifier]], 'interface_declaration' => [:interface, %w[type_identifier identifier]], 'type_alias_declaration' => [:type, %w[type_identifier identifier]], 'internal_module' => [:namespace, %w[identifier string nested_identifier]], 'function_declaration' => [:function, %w[identifier]], 'function_signature' => [:function, %w[identifier]] }.freeze
Instance Attribute Summary collapse
-
#leading_comments ⇒ Array[untyped]
readonly
Returns the value of attribute leading_comments.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
-
#source ⇒ String
readonly
Returns the value of attribute source.
-
#trailing_comments ⇒ Array[untyped]
readonly
Returns the value of attribute trailing_comments.
Instance Method Summary collapse
- #attach_trailing_comment!(comment) ⇒ Object
- #end_byte ⇒ Integer
- #end_line ⇒ Integer
- #grouped? ⇒ Boolean
-
#initialize(node, source:, leading_comments: []) ⇒ NodeWrapper
constructor
A new instance of NodeWrapper.
- #membership_signature ⇒ Array[untyped]
- #semantic_tree ⇒ Array[untyped]
- #signature ⇒ Array[untyped]
- #source_text ⇒ String
- #start_byte ⇒ Integer
- #start_line ⇒ Integer
Constructor Details
#initialize(node, source:, leading_comments: []) ⇒ NodeWrapper
Returns a new instance of NodeWrapper.
35 36 37 38 39 40 |
# File 'lib/typescript/merge/node_wrapper.rb', line 35 def initialize(node, source:, leading_comments: []) @node = node @source = source @leading_comments = leading_comments.freeze @trailing_comments = [] end |
Instance Attribute Details
#leading_comments ⇒ Array[untyped] (readonly)
Returns the value of attribute leading_comments.
33 34 35 |
# File 'lib/typescript/merge/node_wrapper.rb', line 33 def leading_comments @leading_comments end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
33 34 35 |
# File 'lib/typescript/merge/node_wrapper.rb', line 33 def node @node end |
#source ⇒ String (readonly)
Returns the value of attribute source.
33 34 35 |
# File 'lib/typescript/merge/node_wrapper.rb', line 33 def source @source end |
#trailing_comments ⇒ Array[untyped] (readonly)
Returns the value of attribute trailing_comments.
33 34 35 |
# File 'lib/typescript/merge/node_wrapper.rb', line 33 def trailing_comments @trailing_comments end |
Instance Method Details
#attach_trailing_comment!(comment) ⇒ Object
63 |
# File 'lib/typescript/merge/node_wrapper.rb', line 63 def attach_trailing_comment!(comment) = trailing_comments << comment |
#end_byte ⇒ Integer
59 |
# File 'lib/typescript/merge/node_wrapper.rb', line 59 def end_byte = trailing_comments.last&.end_byte || node.end_byte |
#end_line ⇒ Integer
61 |
# File 'lib/typescript/merge/node_wrapper.rb', line 61 def end_line = line_for_byte(end_byte.zero? ? 0 : end_byte - 1) |
#grouped? ⇒ Boolean
56 |
# File 'lib/typescript/merge/node_wrapper.rb', line 56 def grouped? = variable_declaration?(node) |
#membership_signature ⇒ Array[untyped]
52 53 54 |
# File 'lib/typescript/merge/node_wrapper.rb', line 52 def membership_signature signature end |
#semantic_tree ⇒ Array[untyped]
64 |
# File 'lib/typescript/merge/node_wrapper.rb', line 64 def semantic_tree = semantic_node(node) |
#signature ⇒ Array[untyped]
42 43 44 45 46 47 48 49 50 |
# File 'lib/typescript/merge/node_wrapper.rb', line 42 def signature return expression_statement_signature if node.type == 'expression_statement' return import_signature if node.type == 'import_statement' return export_signature if node.type == 'export_statement' return variable_signature(node) if variable_declaration?(node) return ambient_signature if node.type == 'ambient_declaration' named_signature(node) end |
#source_text ⇒ String
62 |
# File 'lib/typescript/merge/node_wrapper.rb', line 62 def source_text = source.byteslice(start_byte...end_byte).to_s |
#start_byte ⇒ Integer
58 |
# File 'lib/typescript/merge/node_wrapper.rb', line 58 def start_byte = leading_comments.first&.start_byte || node.start_byte |
#start_line ⇒ Integer
60 |
# File 'lib/typescript/merge/node_wrapper.rb', line 60 def start_line = line_for_byte(start_byte) |