Skip to content

Commit 486beda

Browse files
committed
JS: Factor out common regexp in AccessPathToken
1 parent d33200e commit 486beda

File tree

1 file changed

+4
-2
lines changed
  • javascript/ql/lib/semmle/javascript/frameworks/data/internal

1 file changed

+4
-2
lines changed

javascript/ql/lib/semmle/javascript/frameworks/data/internal/Shared.qll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,14 +437,16 @@ private API::Node getNodeFromInputOutputPath(API::InvokeNode baseNode, AccessPat
437437
class AccessPathToken extends string {
438438
AccessPathToken() { this = any(AccessPath path).getRawToken(_) }
439439

440+
private string getPart(int part) { result = this.regexpCapture("([^\\[]+)(?:\\[([^\\]]*)\\])?", part) }
441+
440442
/** Gets the name of the token, such as `Member` from `Member[x]` */
441-
string getName() { result = this.regexpCapture("(.+?)(?:\\[.*?\\])?", 1) }
443+
string getName() { result = getPart(1) }
442444

443445
/**
444446
* Gets the argument list, such as `1,2` from `Member[1,2]`,
445447
* or has no result if there are no arguments.
446448
*/
447-
string getArgumentList() { result = this.regexpCapture(".+?\\[(.*?)\\]", 1) }
449+
string getArgumentList() { result = getPart(2) }
448450

449451
/** Gets the `n`th argument to this token, such as `x` or `y` from `Member[x,y]`. */
450452
string getArgument(int n) { result = getArgumentList().splitAt(",", n) }

0 commit comments

Comments
 (0)