JS: Update QL API

This commit is contained in:
Asger F
2019-10-16 18:47:24 +01:00
parent d3302c39c0
commit 57de6382cd
3 changed files with 23 additions and 10 deletions

View File

@@ -409,6 +409,9 @@ class BigIntLiteral extends @bigintliteral, Literal {
*/
class StringLiteral extends @stringliteral, Literal {
override string getStringValue() { result = getValue() }
/** Gets the value of this string literal parsed as a regular expression. */
RegExpTerm asRegExp() { this = result.getParent() }
}
/**

View File

@@ -10,7 +10,8 @@ private import semmle.javascript.dataflow.InferredTypes
/**
* An element containing a regular expression term, that is, either
* a regular expression literal or another regular expression term.
* a regular expression literal, a string literal (parsed as a regular expression),
* or another regular expression term.
*
* Examples:
*
@@ -22,8 +23,7 @@ private import semmle.javascript.dataflow.InferredTypes
class RegExpParent extends Locatable, @regexpparent { }
/**
* A regular expression term, that is, a syntactic part of a regular
* expression literal.
* A regular expression term, that is, a syntactic part of a regular expression.
*
* Examples:
*
@@ -52,7 +52,7 @@ abstract class RegExpTerm extends Locatable, @regexpterm {
*/
RegExpParent getParent() { regexpterm(this, _, result, _, _) }
/** Gets the regular expression literal this term belongs to. */
/** Gets the regular expression literal this term belongs to, if any. */
RegExpLiteral getLiteral() { result = getParent+() }
override string toString() { regexpterm(this, _, _, _, result) }
@@ -141,7 +141,7 @@ abstract class RegExpEscape extends RegExpTerm, @regexp_escape { }
* Example:
*
* ```
* a
* abc
* ```
*/
class RegExpConstant extends RegExpTerm, @regexp_constant {
@@ -209,7 +209,7 @@ class RegExpAlt extends RegExpTerm, @regexp_alt {
* (ECMA|Java)Script
* ```
*
* This is a sequence with elements `(ECMA|Java)`, `S`, `c`, `r`, `i`, `p` and `t`.
* This is a sequence with the elements `(ECMA|Java)` and `Script`.
*/
class RegExpSequence extends RegExpTerm, @regexp_seq {
/** Gets an element of this sequence. */
@@ -472,15 +472,25 @@ class RegExpGroup extends RegExpTerm, @regexp_group {
}
/**
* A normal character without special meaning in a regular expression.
* A sequence of normal characters without special meaning in a regular expression.
*
* Example:
*
* ```
* abc
* ;
* ```
*/
class RegExpNormalChar extends RegExpConstant, @regexp_normal_char { }
class RegExpNormalConstant extends RegExpConstant, @regexp_normal_constant { }
/**
* DEPRECATED. Use `RegExpNormalConstant` instead.
*
* This class used to represent an individual normal character but has been superceded by
* `RegExpNormalConstant`, which represents a sequence of normal characters.
* There is no longer a separate node for each individual character in a constant.
*/
deprecated class RegExpNormalChar = RegExpNormalConstant;
/**
* A hexadecimal character escape in a regular expression.

View File

@@ -832,7 +832,7 @@ case @regexpterm.kind of
| 11 = @regexp_range
| 12 = @regexp_dot
| 13 = @regexp_group
| 14 = @regexp_normal_char
| 14 = @regexp_normal_constant
| 15 = @regexp_hex_escape
| 16 = @regexp_unicode_escape
| 17 = @regexp_dec_escape
@@ -854,7 +854,7 @@ regexpParseErrors (unique int id: @regexp_parse_error,
@regexp_quantifier = @regexp_star | @regexp_plus | @regexp_opt | @regexp_range;
@regexp_escape = @regexp_char_escape | @regexp_char_class_escape | @regexp_unicode_property_escape;
@regexp_char_escape = @regexp_hex_escape | @regexp_unicode_escape | @regexp_dec_escape | @regexp_oct_escape | @regexp_ctrl_escape | @regexp_id_escape;
@regexp_constant = @regexp_normal_char | @regexp_char_escape;
@regexp_constant = @regexp_normal_constant | @regexp_char_escape;
@regexp_lookahead = @regexp_positive_lookahead | @regexp_negative_lookahead;
@regexp_lookbehind = @regexp_positive_lookbehind | @regexp_negative_lookbehind;
@regexp_subpattern = @regexp_lookahead | @regexp_lookbehind;