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,6 +31,19 @@ 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 || []
@ -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)
});
}
})
@ -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

@ -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