Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ed27c8b

Browse files
committed
JS: Add test and fix bug in pipe parser
1 parent 16a2a60 commit ed27c8b

5 files changed

Lines changed: 41 additions & 2 deletions

File tree

javascript/extractor/src/com/semmle/jcorn/AngularExpressionParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ protected Expression buildBinary(
4141
}
4242
SourceLocation loc = new SourceLocation(startLoc);
4343
if (right instanceof Identifier) {
44-
right = new AngularPipeRef(right.getLoc(), (Identifier)right);
44+
right = new AngularPipeRef(new SourceLocation(right.getLoc()), (Identifier)right);
4545
}
46-
return this.finishNode(new CallExpression(loc, right, null, arguments, false, false));
46+
return this.finishNode(new CallExpression(loc, right, new ArrayList<>(), arguments, false, false));
4747
}
4848
return super.buildBinary(startPos, startLoc, left, right, op, logical);
4949
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<other-component
2+
[prop]="foo | bar"
3+
[prop2]="foo | bar:'baz'"
4+
></other-component>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Component } from "@angular/core";
2+
3+
@Component({
4+
selector: "foo-component",
5+
templateUrl: "./foo.component.html"
6+
})
7+
export class Foo {
8+
foo: string;
9+
10+
constructor() {
11+
this.foo = "hello";
12+
}
13+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
pipeRef
2+
| foo.component.html:2:19:2:21 | bar |
3+
| foo.component.html:3:20:3:28 | bar:'baz' |
4+
pipeCall
5+
| foo.component.html:2:13:2:21 | foo \| bar |
6+
| foo.component.html:3:14:3:28 | foo \| bar:'baz' |
7+
pipeCallArg
8+
| 0 | foo.component.html:2:13:2:15 | foo | foo.component.html:2:13:2:21 | foo \| bar |
9+
| 0 | foo.component.html:3:14:3:16 | foo | foo.component.html:3:14:3:28 | foo \| bar:'baz' |
10+
| 1 | foo.component.html:3:24:3:28 | 'baz' | foo.component.html:3:14:3:28 | foo \| bar:'baz' |
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import javascript
2+
3+
query Angular2::PipeRefExpr pipeRef() { any() }
4+
5+
query CallExpr pipeCall() {
6+
result.getCallee() instanceof Angular2::PipeRefExpr
7+
}
8+
9+
query CallExpr pipeCallArg(int i, Expr arg) {
10+
result.getCallee() instanceof Angular2::PipeRefExpr and
11+
result.getArgument(i) = arg
12+
}

0 commit comments

Comments
 (0)