Class: Jade::Frontend::UsageAnalysis::ReferenceIndex
- Inherits:
-
Data
- Object
- Data
- Jade::Frontend::UsageAnalysis::ReferenceIndex
- Defined in:
- lib/jade/frontend/usage_analysis/reference_index.rb
Instance Attribute Summary collapse
-
#references ⇒ Object
readonly
Returns the value of attribute references.
Class Method Summary collapse
- .empty ⇒ Object
-
.key_for(symbol) ⇒ Object
Locals key on ‘decl_span`; module-level symbols on `[module_name, name]`.
Instance Method Summary collapse
- #ever_referenced?(symbol) ⇒ Boolean
- #for(symbol) ⇒ Object
-
#initialize(references: {}) ⇒ ReferenceIndex
constructor
A new instance of ReferenceIndex.
- #passed_as_value?(symbol) ⇒ Boolean
- #references_in(module_name) ⇒ Object
Constructor Details
#initialize(references: {}) ⇒ ReferenceIndex
Returns a new instance of ReferenceIndex.
7 8 9 |
# File 'lib/jade/frontend/usage_analysis/reference_index.rb', line 7 def initialize(references: {}) super end |
Instance Attribute Details
#references ⇒ Object (readonly)
Returns the value of attribute references
6 7 8 |
# File 'lib/jade/frontend/usage_analysis/reference_index.rb', line 6 def references @references end |
Class Method Details
.empty ⇒ Object
11 12 13 |
# File 'lib/jade/frontend/usage_analysis/reference_index.rb', line 11 def self.empty new(references: {}) end |
.key_for(symbol) ⇒ Object
Locals key on ‘decl_span`; module-level symbols on `[module_name, name]`. NOTE: when `:type_annotation` refs land they may point at a `Symbol::Variable` that’s a type variable, which would collide with value-level locals under ‘[:local, decl_span]`. Revisit the keying scheme then —likely split into `[:local_value, …]` vs `[:local_type, …]`.
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/jade/frontend/usage_analysis/reference_index.rb', line 40 def self.key_for(symbol) case symbol in Symbol::Variable [:local, symbol.decl_span] in Symbol::ValueRef | Symbol::TypeRef [symbol.module_name, symbol.name] else [symbol.module_name, symbol.name] end end |
Instance Method Details
#ever_referenced?(symbol) ⇒ Boolean
23 24 25 |
# File 'lib/jade/frontend/usage_analysis/reference_index.rb', line 23 def ever_referenced?(symbol) self.for(symbol).any? end |
#for(symbol) ⇒ Object
15 16 17 |
# File 'lib/jade/frontend/usage_analysis/reference_index.rb', line 15 def for(symbol) references[ReferenceIndex.key_for(symbol)] || [] end |
#passed_as_value?(symbol) ⇒ Boolean
19 20 21 |
# File 'lib/jade/frontend/usage_analysis/reference_index.rb', line 19 def passed_as_value?(symbol) self.for(symbol).any? { it.kind == :as_value } end |
#references_in(module_name) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/jade/frontend/usage_analysis/reference_index.rb', line 27 def references_in(module_name) references .values .flatten .select { it.symbol_key.first == module_name } end |