feat(compiler): support for singleline, multiline & jsdoc comments (#22715)
PR Close #22715
This commit is contained in:

committed by
Miško Hevery

parent
02e6ac2117
commit
3b167be069
@ -21,5 +21,22 @@ import * as o from '../../src/output/output_ast';
|
||||
expect(o.collectExternalReferences([stmt])).toEqual([ref1, ref2]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('comments', () => {
|
||||
it('different JSDocCommentStmt should not be equivalent', () => {
|
||||
const comment1 = new o.JSDocCommentStmt([{text: 'text'}]);
|
||||
const comment2 = new o.JSDocCommentStmt([{text: 'text2'}]);
|
||||
const comment3 = new o.JSDocCommentStmt([{tagName: o.JSDocTagName.Desc, text: 'text2'}]);
|
||||
const comment4 = new o.JSDocCommentStmt([{text: 'text2'}, {text: 'text3'}]);
|
||||
|
||||
expect(comment1.isEquivalent(comment2)).toBeFalsy();
|
||||
expect(comment1.isEquivalent(comment3)).toBeFalsy();
|
||||
expect(comment1.isEquivalent(comment4)).toBeFalsy();
|
||||
expect(comment2.isEquivalent(comment3)).toBeFalsy();
|
||||
expect(comment2.isEquivalent(comment4)).toBeFalsy();
|
||||
expect(comment3.isEquivalent(comment4)).toBeFalsy();
|
||||
expect(comment1.isEquivalent(comment1)).toBeTruthy();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -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};
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user