feat(compiler): support for singleline, multiline & jsdoc comments (#22715)

PR Close #22715
This commit is contained in:
Olivier Combe
2018-03-12 15:34:03 +01:00
committed by Miško Hevery
parent 02e6ac2117
commit 3b167be069
8 changed files with 215 additions and 31 deletions

View File

@ -414,10 +414,38 @@ const externalModuleIdentifier = new o.ExternalReference(anotherModuleUrl, 'some
.toEqual('var a:{[key: string]:number} = (null as any);');
});
it('should support a preamble', () => {
expect(emitStmt(o.variable('a').toStmt(), '/* SomePreamble */')).toBe([
'/* SomePreamble */', 'a;'
].join('\n'));
describe('comments', () => {
it('should support a preamble', () => {
expect(emitStmt(o.variable('a').toStmt(), '/* SomePreamble */')).toBe([
'/* SomePreamble */', 'a;'
].join('\n'));
});
it('should support singleline comments', () => {
expect(emitStmt(new o.CommentStmt('Simple comment'))).toBe('// Simple comment');
});
it('should support multiline comments', () => {
expect(emitStmt(new o.CommentStmt('Multiline comment', true)))
.toBe('/* Multiline comment */');
expect(emitStmt(new o.CommentStmt(`Multiline\ncomment`, true)))
.toBe(`/* Multiline\ncomment */`);
});
it('should support JSDoc comments', () => {
expect(emitStmt(new o.JSDocCommentStmt([{text: 'Intro comment'}])))
.toBe(`/**\n * Intro comment\n */`);
expect(emitStmt(new o.JSDocCommentStmt([
{tagName: o.JSDocTagName.Desc, text: 'description'}
]))).toBe(`/**\n * @desc description\n */`);
expect(emitStmt(new o.JSDocCommentStmt([
{text: 'Intro comment'},
{tagName: o.JSDocTagName.Desc, text: 'description'},
{tagName: o.JSDocTagName.Id, text: '{number} identifier 123'},
])))
.toBe(
`/**\n * Intro comment\n * @desc description\n * @id {number} identifier 123\n */`);
});
});
describe('emitter context', () => {
@ -461,4 +489,4 @@ function calculateLineCol(text: string, offset: number): {line: number, col: num
cur = next;
}
return {line, col: 0};
}
}