Common AST formats such as TS and Babel do not use a separate node for comments, but instead attach comments to other AST nodes. Previously this was worked around in TS by creating a `NotEmittedStatement` AST node to attach the comment to. But Babel does not have this facility, so it will not be a viable approach for the linker. This commit refactors the output AST, to remove the `CommentStmt` and `JSDocCommentStmt` nodes. Instead statements have a collection of `leadingComments` that are rendered/attached to the final AST nodes when being translated or printed. PR Close #38811
26 lines
771 B
TypeScript
26 lines
771 B
TypeScript
/**
|
|
* @license
|
|
* Copyright Google LLC 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 o from '../../src/output/output_ast';
|
|
|
|
{
|
|
describe('OutputAst', () => {
|
|
describe('collectExternalReferences', () => {
|
|
it('should find expressions of variable types', () => {
|
|
const ref1 = new o.ExternalReference('aModule', 'name1');
|
|
const ref2 = new o.ExternalReference('aModule', 'name2');
|
|
const stmt =
|
|
o.variable('test').set(o.NULL_EXPR).toDeclStmt(o.importType(ref1, [o.importType(ref2)!
|
|
]));
|
|
|
|
expect(o.collectExternalReferences([stmt])).toEqual([ref1, ref2]);
|
|
});
|
|
});
|
|
});
|
|
}
|