Skip to content
Permalink
Browse files

fix(language-service): function.bind() should not be an error (#34041) (

#34046)

When performing diagnostic checks or completions, we should take into
account members and properties in the base class, if any. Otherwise, the
language service will produce a false error.

PR closes angular/vscode-ng-language-service#93

PR Close #34041

(cherry picked from commit 7cd16b9)

PR Close #34046
  • Loading branch information
kyliau authored and matsko committed Nov 25, 2019
1 parent bbc8b0f commit d22f3d6f85e2dce5ef8d6ff31e5ce0b50c500737
@@ -271,7 +271,11 @@ class TypeWrapper implements Symbol {
}

members(): SymbolTable {
return new SymbolTableWrapper(this.tsType.getProperties(), this.context);
// Should call getApparentProperties() instead of getProperties() because
// the former includes properties on the base class whereas the latter does
// not. This provides properties like .bind(), .call(), .apply(), etc for
// functions.
return new SymbolTableWrapper(this.tsType.getApparentProperties(), this.context);
}

signatures(): Signature[] { return signaturesOf(this.tsType, this.context); }
@@ -119,6 +119,14 @@ describe('diagnostics', () => {
expect(diagnostics).toEqual([]);
});

it('should not produce errors on function.bind()', () => {
mockHost.override(TEST_TEMPLATE, `
<test-comp (test)="myClick.bind(this)">
</test-comp>`);
const diags = ngLS.getDiagnostics(TEST_TEMPLATE);
expect(diags).toEqual([]);
});

describe('in expression-cases.ts', () => {
it('should report access to an unknown field', () => {
const diags = ngLS.getDiagnostics(EXPRESSION_CASES).map(d => d.messageText);

0 comments on commit d22f3d6

Please sign in to comment.
You can’t perform that action at this time.