Skip to content

Commit

Permalink
refactor(compiler-cli): Include pipe nameSpan in TCB (angular#39768)
Browse files Browse the repository at this point in the history
In order to map the pipe's `transform` method in the type check block
directly back to the pipe name in the template source, we need to
include the `BindingPipe`'s `nameSpan` with the `ts.methodAccess` for
the pipe's transform method.

Note that this is specifically relevant to the Language Service's "find
references" feature. As an example, with something like `-2.5 | number:'1.0-0'`,,
when calling "find references" on the 'number' pipe we want the text
span of the reference to just be `number` rather than the entire binding
pipe's source `-2.5 | number:'1.0-0'`.

PR Close angular#39768
  • Loading branch information
atscott authored and mhevery committed Dec 2, 2020
1 parent 82e3f54 commit 1a5e5f8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1618,7 +1618,12 @@ class TcbExpressionTranslator {
pipe = NULL_AS_ANY;
}
const args = ast.args.map(arg => this.translate(arg));
const result = tsCallMethod(pipe, 'transform', [expr, ...args]);
const methodAccess = ts.createPropertyAccess(pipe, 'transform');
addParseSpanInfo(methodAccess, ast.nameSpan);
const result = ts.createCall(
/* expression */ methodAccess,
/* typeArguments */ undefined,
/* argumentsArray */[expr, ...args]);
addParseSpanInfo(result, ast.sourceSpan);
return result;
} else if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ describe('type check blocks diagnostics', () => {
}];
const block = tcbWithSpans(TEMPLATE, PIPES);
expect(block).toContain(
'((null as TestPipe).transform(((ctx).a /*3,4*/) /*3,4*/, ((ctx).b /*12,13*/) /*12,13*/) /*3,13*/);');
'((null as TestPipe).transform /*7,11*/(((ctx).a /*3,4*/) /*3,4*/, ((ctx).b /*12,13*/) /*12,13*/) /*3,13*/);');
});

describe('attaching multiple comments for multiple references', () => {
Expand Down

0 comments on commit 1a5e5f8

Please sign in to comment.