Skip to content

Commit 1a5e5f8

Browse files
atscottmhevery
authored andcommitted
refactor(compiler-cli): Include pipe nameSpan in TCB (angular#39768)
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
1 parent 82e3f54 commit 1a5e5f8

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

packages/compiler-cli/src/ngtsc/typecheck/src/type_check_block.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1618,7 +1618,12 @@ class TcbExpressionTranslator {
16181618
pipe = NULL_AS_ANY;
16191619
}
16201620
const args = ast.args.map(arg => this.translate(arg));
1621-
const result = tsCallMethod(pipe, 'transform', [expr, ...args]);
1621+
const methodAccess = ts.createPropertyAccess(pipe, 'transform');
1622+
addParseSpanInfo(methodAccess, ast.nameSpan);
1623+
const result = ts.createCall(
1624+
/* expression */ methodAccess,
1625+
/* typeArguments */ undefined,
1626+
/* argumentsArray */[expr, ...args]);
16221627
addParseSpanInfo(result, ast.sourceSpan);
16231628
return result;
16241629
} else if (

packages/compiler-cli/src/ngtsc/typecheck/test/span_comments_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ describe('type check blocks diagnostics', () => {
147147
}];
148148
const block = tcbWithSpans(TEMPLATE, PIPES);
149149
expect(block).toContain(
150-
'((null as TestPipe).transform(((ctx).a /*3,4*/) /*3,4*/, ((ctx).b /*12,13*/) /*12,13*/) /*3,13*/);');
150+
'((null as TestPipe).transform /*7,11*/(((ctx).a /*3,4*/) /*3,4*/, ((ctx).b /*12,13*/) /*12,13*/) /*3,13*/);');
151151
});
152152

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

0 commit comments

Comments
 (0)