Skip to content

Commit 6cc5c09

Browse files
committed
Ruby: Simplify ErbOutputDirective
1 parent 11040d6 commit 6cc5c09

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

ruby/ql/lib/codeql/ruby/ast/Erb.qll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ class ErbGraphqlDirective extends ErbDirective {
252252
class ErbOutputDirective extends ErbDirective {
253253
private Erb::OutputDirective g;
254254

255-
ErbOutputDirective() { this = TOutputDirective(g) or this = TRawOutputDirective(g) }
255+
ErbOutputDirective() { this = TOutputDirective(g) }
256256

257257
override ErbCode getToken() { toGenerated(result) = g.getChild() }
258258

@@ -262,7 +262,9 @@ class ErbOutputDirective extends ErbDirective {
262262
* <%== foo %>
263263
* ```
264264
*/
265-
predicate isRaw() { this = TRawOutputDirective(g) }
265+
predicate isRaw() {
266+
exists(Erb::Token t | t.getParentIndex() = 0 and t.getParent() = g and t.getValue() = "<%==")
267+
}
266268

267269
final override string toString() {
268270
this.isRaw() and

ruby/ql/lib/codeql/ruby/ast/internal/Erb.qll

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,12 @@ private module Cached {
99
TCommentDirective(Erb::CommentDirective g) or
1010
TDirective(Erb::Directive g) or
1111
TGraphqlDirective(Erb::GraphqlDirective g) or
12-
TOutputDirective(Erb::OutputDirective g) { getOpeningTag(g) != "<%==" } or
13-
TRawOutputDirective(Erb::OutputDirective g) { getOpeningTag(g) = "<%==" } or
12+
TOutputDirective(Erb::OutputDirective g) or
1413
TTemplate(Erb::Template g) or
1514
TToken(Erb::Token g) or
1615
TComment(Erb::Comment g) or
1716
TCode(Erb::Code g)
1817

19-
private string getOpeningTag(Erb::OutputDirective g) {
20-
erb_tokeninfo(any(Erb::Token t | erb_ast_node_info(t, g, 0, _)), 0, result)
21-
}
22-
2318
/**
2419
* Gets the underlying TreeSitter entity for a given erb AST node.
2520
*/
@@ -29,7 +24,6 @@ private module Cached {
2924
n = TDirective(result) or
3025
n = TGraphqlDirective(result) or
3126
n = TOutputDirective(result) or
32-
n = TRawOutputDirective(result) or
3327
n = TTemplate(result) or
3428
n = TToken(result) or
3529
n = TComment(result) or
@@ -44,7 +38,6 @@ import Cached
4438

4539
TAstNode fromGenerated(Erb::AstNode n) { n = toGenerated(result) }
4640

47-
class TDirectiveNode =
48-
TCommentDirective or TDirective or TGraphqlDirective or TOutputDirective or TRawOutputDirective;
41+
class TDirectiveNode = TCommentDirective or TDirective or TGraphqlDirective or TOutputDirective;
4942

5043
class TTokenNode = TToken or TComment or TCode;

0 commit comments

Comments
 (0)