From 1a5e5f86a3cb6ced7e364355a0ccac395c60aebc Mon Sep 17 00:00:00 2001 From: Andrew Scott Date: Thu, 19 Nov 2020 13:31:44 -0800 Subject: [PATCH] refactor(compiler-cli): Include pipe `nameSpan` in TCB (#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 #39768 --- .../src/ngtsc/typecheck/src/type_check_block.ts | 7 ++++++- .../src/ngtsc/typecheck/test/span_comments_spec.ts | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/compiler-cli/src/ngtsc/typecheck/src/type_check_block.ts b/packages/compiler-cli/src/ngtsc/typecheck/src/type_check_block.ts index 59e87635b9..898133a63f 100644 --- a/packages/compiler-cli/src/ngtsc/typecheck/src/type_check_block.ts +++ b/packages/compiler-cli/src/ngtsc/typecheck/src/type_check_block.ts @@ -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 ( diff --git a/packages/compiler-cli/src/ngtsc/typecheck/test/span_comments_spec.ts b/packages/compiler-cli/src/ngtsc/typecheck/test/span_comments_spec.ts index 6d8236e23e..0f8267085d 100644 --- a/packages/compiler-cli/src/ngtsc/typecheck/test/span_comments_spec.ts +++ b/packages/compiler-cli/src/ngtsc/typecheck/test/span_comments_spec.ts @@ -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', () => {