Update to latest typescript

This commit is contained in:
Pieter Vander Vennet 2022-03-17 21:38:02 +01:00
parent 9384e93e94
commit 9f0dd17419
4 changed files with 1393 additions and 1682 deletions

View file

@ -12,7 +12,13 @@ export default class Example0 {
* Example0.get() + 1 // => 43
*/
private static get(){
// a comment
// @ts-ignore
return 42
}
public testMore(){
return ({} as any) ?.xyz?.abc ?? 0
}
}

View file

@ -1,5 +1,5 @@
import * as ts from 'typescript'
import {SyntaxKind} from 'typescript'
import {JSDocComment} from 'typescript'
import * as fs from 'fs'
import * as path from 'path'
@ -31,7 +31,20 @@ export interface Comment {
export function Comments(s: string): Comment[] {
const out: Comment[] = []
function registerComment(context: string | null,comment: string | ts.NodeArray<JSDocComment> | undefined){
if(comment === undefined){
return
}
if(typeof comment === "string"){
out.push({comment: comment || '', context});
}else{
comment.forEach(jsDocComment => {
out.push({comment: jsDocComment.text || '', context});
})
}
}
function traverse(node: ts.Node) {
const jsdocs = (node as any).jsDoc || []
if (jsdocs.length > 0) {
@ -45,18 +58,17 @@ export function Comments(s: string): Comment[] {
context = decls[0].name.escapedText || null
}
} catch (e) {
// console.dir(node)
context = ts.isConstructorDeclaration(node) ? 'constructor' : null
}
}
jsdocs.forEach((doc: ts.JSDoc) => {
out.push({comment: doc.comment || '', context});
registerComment(context, doc.comment)
// A part of the comment might be in the tags; we simply add those too and figure out later if they contain doctests
const tags = doc.tags;
if(tags !== undefined){
tags.forEach(tag => {
out.push({comment: tag.comment || '', context});
registerComment(context, tag.comment)
});
}
})
@ -64,7 +76,7 @@ export function Comments(s: string): Comment[] {
}
ts.forEachChild(node, traverse)
}
const ast = ts.createSourceFile('_.ts', s, ts.ScriptTarget.Latest)
traverse(ast)
@ -228,7 +240,7 @@ function exposePrivates(s: string): string {
const transformed = ts.transform(ast, [transformer]).transformed[0]
const pwoc = ts.createPrinter({removeComments: true})
const pwoc = ts.createPrinter({ removeComments: false})
return pwoc.printNode(ts.EmitHint.Unspecified, transformed, ast)
}

View file

@ -46,7 +46,7 @@ test('modules and namespace', t => {
/** ns */
namespace ns {}
`)
t.deepEqual(cs, [c('m ', 'm'), c('ns ', 'ns')])
t.deepEqual(cs, [c('m', 'm'), c('ns', 'ns')])
})
test('const', t => {
@ -55,7 +55,7 @@ test('const', t => {
/** u */
const u = 1
`)
t.deepEqual(cs, [c('u ', 'u')])
t.deepEqual(cs, [c('u', 'u')])
})
test('const object', t => {
@ -69,7 +69,7 @@ test('const object', t => {
b(x: string) { return x+x }
}
`)
t.deepEqual(cs, [c('k ', 'k'), c('a ', 'a'), c('b ', 'b')])
t.deepEqual(cs, [c('k', 'k'), c('a', 'a'), c('b', 'b')])
})
test('object deconstruction', t => {
@ -78,7 +78,7 @@ test('object deconstruction', t => {
/** hello */
const {u, v} = {u: 1, v: 2}
`)
t.deepEqual(cs, [c('hello ', null)])
t.deepEqual(cs, [c('hello', null)])
})
test('function', t => {
@ -89,7 +89,7 @@ test('function', t => {
return s.length + 1
}
`)
t.deepEqual(cs, [c('v ', 'v')])
t.deepEqual(cs, [c('v', 'v')])
})
test('class', t => {
@ -106,7 +106,7 @@ test('class', t => {
p: Array<number>
}
`)
t.deepEqual(cs, [c('C ', 'C'), c('constructor ', 'constructor'), c('m ', 'm'), c('p ', 'p')])
t.deepEqual(cs, [c('C', 'C'), c('constructor', 'constructor'), c('m', 'm'), c('p', 'p')])
})
test('interface', t => {
@ -120,7 +120,7 @@ test('interface', t => {
j(a: A): string
}
`)
t.deepEqual(cs, [c('I ', 'I'), c('i ', 'i'), c('j ', 'j')])
t.deepEqual(cs, [c('I', 'I'), c('i', 'i'), c('j', 'j')])
})
test('type', t => {
@ -129,7 +129,7 @@ test('type', t => {
/** T */
type T = number
`)
t.deepEqual(cs, [c('T ', 'T')])
t.deepEqual(cs, [c('T', 'T')])
})
test('anywhere', t => {
@ -148,5 +148,5 @@ test('anywhere', t => {
return f(f(w))
}
`)
t.deepEqual(cs, [c('test1 ', 'w'), c('test2 ', 'f')])
t.deepEqual(cs, [c('test1', 'w'), c('test2', 'f'), c('test3', null)])
})

3025
yarn.lock

File diff suppressed because it is too large Load diff