-
Notifications
You must be signed in to change notification settings - Fork 24.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(language-service): Omit typechecking for finding directives
Remove unnecessary private method `getDeclarationFromNode` and moved some logic to utils instead so that it can be tested in isolation of the Language Service infrastructure. The use of typechecker to check the directive is also not necessary, since resolve.getNonNormalizedDirectiveMetadata() will check if the directive is actually an Angular entity.
- Loading branch information
Showing
4 changed files
with
141 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* @license | ||
* Copyright Google Inc. All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import * as ts from 'typescript'; | ||
import {getDirectiveClassLike} from '../src/utils'; | ||
|
||
describe('getDirectiveClassLike()', () => { | ||
it('should return a directive class', () => { | ||
const sourceFile = ts.createSourceFile( | ||
'foo.ts', ` | ||
@NgModule({ | ||
declarations: [], | ||
}) | ||
class AppModule {} | ||
`, | ||
ts.ScriptTarget.ES2015); | ||
const result = sourceFile.forEachChild(c => { | ||
const directive = getDirectiveClassLike(c); | ||
if (directive) { | ||
return directive; | ||
} | ||
}); | ||
expect(result).toBeTruthy(); | ||
const {decoratorId, classDecl} = result !; | ||
expect(decoratorId.kind).toBe(ts.SyntaxKind.Identifier); | ||
expect((decoratorId as ts.Identifier).text).toBe('NgModule'); | ||
expect(classDecl.name !.text).toBe('AppModule'); | ||
}); | ||
}); |