fix(tl-utils): do not break @link tags
This commit is contained in:
parent
b34a90ec30
commit
e3dbe3b7d1
2 changed files with 91 additions and 62 deletions
|
@ -10,9 +10,12 @@ export const camelToPascal = (s: string): string =>
|
||||||
export function jsComment(s: string): string {
|
export function jsComment(s: string): string {
|
||||||
return (
|
return (
|
||||||
'/**' +
|
'/**' +
|
||||||
|
// awesome hack not to break up {@link} links
|
||||||
s
|
s
|
||||||
|
.replace(/{@link (.*?)}/g, '{@link$1}')
|
||||||
.replace(/(?![^\n]{1,60}$)([^\n]{1,60})\s/g, '$1\n')
|
.replace(/(?![^\n]{1,60}$)([^\n]{1,60})\s/g, '$1\n')
|
||||||
.replace(/\n|^/g, '\n * ') +
|
.replace(/\n|^/g, '\n * ')
|
||||||
|
.replace(/{@link(.*)?}/, '{@link $1}') +
|
||||||
'\n */'
|
'\n */'
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,66 +65,92 @@ describe('generateTypescriptDefinitionsForTlEntry', () => {
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('adds comments', () => {
|
describe('comments', () => {
|
||||||
test(
|
it('adds tl style comments', () => {
|
||||||
'// This is a test constructor\ntest = Test;',
|
test(
|
||||||
'/**',
|
'// This is a test constructor\n' + 'test = Test;',
|
||||||
' * This is a test constructor',
|
'/**',
|
||||||
' */',
|
' * This is a test constructor',
|
||||||
'interface RawTest {',
|
' */',
|
||||||
" _: 'test';",
|
'interface RawTest {',
|
||||||
'}'
|
" _: 'test';",
|
||||||
)
|
'}'
|
||||||
test(
|
)
|
||||||
'// @description This is a test constructor\n' +
|
test(
|
||||||
'// @field Some field\n' +
|
'---functions---\n' +
|
||||||
'test field:int = Test;',
|
'// This is a test method\n' +
|
||||||
'/**',
|
'test = Test;',
|
||||||
' * This is a test constructor',
|
'/**',
|
||||||
' */',
|
' * This is a test method',
|
||||||
'interface RawTest {',
|
' * ',
|
||||||
" _: 'test';",
|
' * RPC method returns {@link tl.TypeTest}',
|
||||||
' /**',
|
' */',
|
||||||
' * Some field',
|
'interface RawTestRequest {',
|
||||||
' */',
|
" _: 'test';",
|
||||||
' field: number;',
|
'}'
|
||||||
'}'
|
)
|
||||||
)
|
})
|
||||||
test(
|
|
||||||
'---functions---\n// This is a test method\ntest = Test;',
|
|
||||||
'/**',
|
|
||||||
' * This is a test method',
|
|
||||||
' * ',
|
|
||||||
' * RPC method returns {@see tl.TypeTest}',
|
|
||||||
' */',
|
|
||||||
'interface RawTestRequest {',
|
|
||||||
" _: 'test';",
|
|
||||||
'}'
|
|
||||||
)
|
|
||||||
|
|
||||||
test(
|
it('adds tdlib style comments', () => {
|
||||||
'// This is a test constructor with a very very very very very very very very long comment\ntest = Test;',
|
test(
|
||||||
'/**',
|
'// @description This is a test constructor\n' +
|
||||||
' * This is a test constructor with a very very very very very',
|
'// @field Some field\n' +
|
||||||
' * very very very long comment',
|
'test field:int = Test;',
|
||||||
' */',
|
'/**',
|
||||||
'interface RawTest {',
|
' * This is a test constructor',
|
||||||
" _: 'test';",
|
' */',
|
||||||
'}'
|
'interface RawTest {',
|
||||||
)
|
" _: 'test';",
|
||||||
|
' /**',
|
||||||
|
' * Some field',
|
||||||
|
' */',
|
||||||
|
' field: number;',
|
||||||
|
'}'
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
test(
|
it('wraps long comments', () => {
|
||||||
'---functions---\n// This is a test method with a very very very very very very very very long comment\ntest = Test;',
|
test(
|
||||||
'/**',
|
'// This is a test constructor with a very very very very very very very very long comment\n' +
|
||||||
' * This is a test method with a very very very very very very',
|
'test = Test;',
|
||||||
' * very very long comment',
|
'/**',
|
||||||
' * ',
|
' * This is a test constructor with a very very very very very',
|
||||||
' * RPC method returns {@see tl.TypeTest}',
|
' * very very very long comment',
|
||||||
' */',
|
' */',
|
||||||
'interface RawTestRequest {',
|
'interface RawTest {',
|
||||||
" _: 'test';",
|
" _: 'test';",
|
||||||
'}'
|
'}'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
test(
|
||||||
|
'---functions---\n' +
|
||||||
|
'// This is a test method with a very very very very very very very very long comment\n' +
|
||||||
|
'test = Test;',
|
||||||
|
'/**',
|
||||||
|
' * This is a test method with a very very very very very very',
|
||||||
|
' * very very long comment',
|
||||||
|
' * ',
|
||||||
|
' * RPC method returns {@link tl.TypeTest}',
|
||||||
|
' */',
|
||||||
|
'interface RawTestRequest {',
|
||||||
|
" _: 'test';",
|
||||||
|
'}'
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should not break @link tags', () => {
|
||||||
|
test(
|
||||||
|
'// This is a test constructor with a very long comment {@link whatever} more text\n' +
|
||||||
|
'test = Test;',
|
||||||
|
'/**',
|
||||||
|
' * This is a test constructor with a very long comment',
|
||||||
|
' * {@link whatever} more text',
|
||||||
|
' */',
|
||||||
|
'interface RawTest {',
|
||||||
|
" _: 'test';",
|
||||||
|
'}'
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('writes generic types', () => {
|
it('writes generic types', () => {
|
||||||
|
@ -242,7 +268,7 @@ describe('generateTypescriptDefinitionsForTlSchema', () => {
|
||||||
" _: 'test';",
|
" _: 'test';",
|
||||||
'}',
|
'}',
|
||||||
'/**',
|
'/**',
|
||||||
' * RPC method returns {@see tl.TypeTest}',
|
' * RPC method returns {@link tl.TypeTest}',
|
||||||
' */',
|
' */',
|
||||||
'interface RawGetTestRequest {',
|
'interface RawGetTestRequest {',
|
||||||
" _: 'getTest';",
|
" _: 'getTest';",
|
||||||
|
@ -284,7 +310,7 @@ interface RawTest2 {
|
||||||
_: 'test2';
|
_: 'test2';
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* RPC method returns {@see tl.TypeTest}
|
* RPC method returns {@link tl.TypeTest}
|
||||||
*/
|
*/
|
||||||
interface RawGetTestRequest {
|
interface RawGetTestRequest {
|
||||||
_: 'getTest';
|
_: 'getTest';
|
||||||
|
@ -303,7 +329,7 @@ namespace test {
|
||||||
_: 'test.test2';
|
_: 'test.test2';
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* RPC method returns {@see tl.test.TypeTest}
|
* RPC method returns {@link tl.test.TypeTest}
|
||||||
*/
|
*/
|
||||||
interface RawGetTestRequest {
|
interface RawGetTestRequest {
|
||||||
_: 'test.getTest';
|
_: 'test.getTest';
|
||||||
|
|
Loading…
Reference in a new issue