@@ -10,6 +10,29 @@ module HTML {
1010 HtmlFile ( ) { getFileType ( ) .isHtml ( ) }
1111 }
1212
13+ /**
14+ * A file that may contain HTML elements.
15+ *
16+ * This is either an `.html` file or a source code file containing
17+ * embedded HTML snippets.
18+ */
19+ private class FileContainingHtml extends File {
20+ FileContainingHtml ( ) {
21+ getFileType ( ) .isHtml ( )
22+ or
23+ // The file contains an expression containing an HTML element
24+ exists ( Expr e |
25+ e .getFile ( ) = this and
26+ xml_element_parent_expression ( _, e , _)
27+ )
28+ }
29+ }
30+
31+ /** Gets `i`th root node of the HTML fragment embedded in the given expression, if any. */
32+ Element getHtmlElementFromExpr ( Expr e , int i ) {
33+ xml_element_parent_expression ( result , e , i )
34+ }
35+
1336 /**
1437 * An HTML element.
1538 *
@@ -20,7 +43,7 @@ module HTML {
2043 * ```
2144 */
2245 class Element extends Locatable , @xmlelement {
23- Element ( ) { exists ( HtmlFile f | xmlElements ( this , _, _, _, f ) ) }
46+ Element ( ) { exists ( FileContainingHtml f | xmlElements ( this , _, _, _, f ) ) }
2447
2548 override Location getLocation ( ) { xmllocations ( this , result ) }
2649
@@ -84,13 +107,6 @@ module HTML {
84107 override string getAPrimaryQlClass ( ) { result = "HTML::Element" }
85108 }
86109
87- /**
88- * Gets the inline script of the given attribute, if any.
89- */
90- CodeInAttribute getCodeInAttribute ( XMLAttribute attribute ) {
91- toplevel_parent_xml_node ( result , attribute )
92- }
93-
94110 /**
95111 * An attribute of an HTML element.
96112 *
@@ -104,15 +120,15 @@ module HTML {
104120 * ```
105121 */
106122 class Attribute extends Locatable , @xmlattribute {
107- Attribute ( ) { exists ( HtmlFile f | xmlAttrs ( this , _, _, _, _, f ) ) }
123+ Attribute ( ) { exists ( FileContainingHtml f | xmlAttrs ( this , _, _, _, _, f ) ) }
108124
109125 override Location getLocation ( ) { xmllocations ( this , result ) }
110126
111127 /**
112128 * Gets the inline script of this attribute, if any.
113129 */
114130 CodeInAttribute getCodeInAttribute ( ) {
115- result = getCodeInAttribute ( this )
131+ toplevel_parent_xml_node ( result , this )
116132 }
117133
118134 /**
@@ -264,7 +280,7 @@ module HTML {
264280 * Note that instances of this class are only available if extraction is done with `--html all` or `--experimental`.
265281 */
266282 class TextNode extends Locatable , @xmlcharacters {
267- TextNode ( ) { exists ( HtmlFile f | xmlChars ( this , _, _, _, _, f ) ) }
283+ TextNode ( ) { exists ( FileContainingHtml f | xmlChars ( this , _, _, _, _, f ) ) }
268284
269285 override string toString ( ) { result = getText ( ) }
270286
@@ -303,7 +319,7 @@ module HTML {
303319 * ```
304320 */
305321 class CommentNode extends Locatable , @xmlcomment {
306- CommentNode ( ) { exists ( HtmlFile f | xmlComments ( this , _, _, f ) ) }
322+ CommentNode ( ) { exists ( FileContainingHtml f | xmlComments ( this , _, _, f ) ) }
307323
308324 /** Gets the element in which this comment occurs. */
309325 Element getParent ( ) { xmlComments ( this , _, result , _) }
0 commit comments