Ruby: Simplify ErbOutputDirective

This commit is contained in:
Harry Maclean
2024-02-12 17:53:57 +00:00
parent 11040d628b
commit 6cc5c09769
2 changed files with 6 additions and 11 deletions

View File

@@ -252,7 +252,7 @@ class ErbGraphqlDirective extends ErbDirective {
class ErbOutputDirective extends ErbDirective {
private Erb::OutputDirective g;
ErbOutputDirective() { this = TOutputDirective(g) or this = TRawOutputDirective(g) }
ErbOutputDirective() { this = TOutputDirective(g) }
override ErbCode getToken() { toGenerated(result) = g.getChild() }
@@ -262,7 +262,9 @@ class ErbOutputDirective extends ErbDirective {
* <%== foo %>
* ```
*/
predicate isRaw() { this = TRawOutputDirective(g) }
predicate isRaw() {
exists(Erb::Token t | t.getParentIndex() = 0 and t.getParent() = g and t.getValue() = "<%==")
}
final override string toString() {
this.isRaw() and

View File

@@ -9,17 +9,12 @@ private module Cached {
TCommentDirective(Erb::CommentDirective g) or
TDirective(Erb::Directive g) or
TGraphqlDirective(Erb::GraphqlDirective g) or
TOutputDirective(Erb::OutputDirective g) { getOpeningTag(g) != "<%==" } or
TRawOutputDirective(Erb::OutputDirective g) { getOpeningTag(g) = "<%==" } or
TOutputDirective(Erb::OutputDirective g) or
TTemplate(Erb::Template g) or
TToken(Erb::Token g) or
TComment(Erb::Comment g) or
TCode(Erb::Code g)
private string getOpeningTag(Erb::OutputDirective g) {
erb_tokeninfo(any(Erb::Token t | erb_ast_node_info(t, g, 0, _)), 0, result)
}
/**
* Gets the underlying TreeSitter entity for a given erb AST node.
*/
@@ -29,7 +24,6 @@ private module Cached {
n = TDirective(result) or
n = TGraphqlDirective(result) or
n = TOutputDirective(result) or
n = TRawOutputDirective(result) or
n = TTemplate(result) or
n = TToken(result) or
n = TComment(result) or
@@ -44,7 +38,6 @@ import Cached
TAstNode fromGenerated(Erb::AstNode n) { n = toGenerated(result) }
class TDirectiveNode =
TCommentDirective or TDirective or TGraphqlDirective or TOutputDirective or TRawOutputDirective;
class TDirectiveNode = TCommentDirective or TDirective or TGraphqlDirective or TOutputDirective;
class TTokenNode = TToken or TComment or TCode;