Give up on trying to get diagnostics for the doctest snippet
This commit is contained in:
parent
2bc463153d
commit
72b22b99ea
1 changed files with 7 additions and 7 deletions
14
src/main.ts
14
src/main.ts
|
|
@ -130,10 +130,9 @@ function generateDocumentation(program: ts.Program, filenames: string[]): Top {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function script(program: ts.Program, filename: string, s: string): string[] {
|
function script(filename: string, s: string): string[] {
|
||||||
const pwoc = ts.createPrinter({removeComments: true})
|
const pwoc = ts.createPrinter({removeComments: true})
|
||||||
const f = ts.createSourceFile('_doctest_' + filename, s, ts.ScriptTarget.ES5, true, ts.ScriptKind.TS)
|
const f = ts.createSourceFile('_doctest_' + filename, s, ts.ScriptTarget.ES5, true, ts.ScriptKind.TS)
|
||||||
ts.getPreEmitDiagnostics(program, f)
|
|
||||||
const out =
|
const out =
|
||||||
f.statements.map(
|
f.statements.map(
|
||||||
(now, i) => {
|
(now, i) => {
|
||||||
|
|
@ -153,7 +152,7 @@ function script(program: ts.Program, filename: string, s: string): string[] {
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_script_one(program: ts.Program, filename: string, d: Def): string[] {
|
function test_script_one(filename: string, d: Def): string[] {
|
||||||
const out = [] as string[]
|
const out = [] as string[]
|
||||||
let tests = 0
|
let tests = 0
|
||||||
d.doc.split(/\n\n+/m).map(s => {
|
d.doc.split(/\n\n+/m).map(s => {
|
||||||
|
|
@ -161,7 +160,7 @@ function test_script_one(program: ts.Program, filename: string, d: Def): string[
|
||||||
// todo: typecheck s now
|
// todo: typecheck s now
|
||||||
out.push(
|
out.push(
|
||||||
'test(' + JSON.stringify(d.name + ' ' + ++tests) + ', assert => {',
|
'test(' + JSON.stringify(d.name + ' ' + ++tests) + ', assert => {',
|
||||||
...script(program, filename, s).map(l => ' ' + l),
|
...script(filename, s).map(l => ' ' + l),
|
||||||
' assert.end()',
|
' assert.end()',
|
||||||
'})',
|
'})',
|
||||||
''
|
''
|
||||||
|
|
@ -171,9 +170,9 @@ function test_script_one(program: ts.Program, filename: string, d: Def): string[
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_script(program: ts.Program, top: Top) {
|
function test_script(top: Top) {
|
||||||
return ["import * as test from 'tape'"].concat(...top.map(
|
return ["import * as test from 'tape'"].concat(...top.map(
|
||||||
({filename, defs}) => walk(defs, (d) => test_script_one(program, filename, d)))
|
({filename, defs}) => walk(defs, (d) => test_script_one(filename, d)))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -234,10 +233,11 @@ const outputs = [] as ((top: Top) => string[])[]
|
||||||
|
|
||||||
{
|
{
|
||||||
let program: ts.Program
|
let program: ts.Program
|
||||||
|
let verbose = false
|
||||||
for (let i = 0; i < argv.length; i++) {
|
for (let i = 0; i < argv.length; i++) {
|
||||||
const arg = argv[i]
|
const arg = argv[i]
|
||||||
if (arg == '-t' || arg == '--test-script') {
|
if (arg == '-t' || arg == '--test-script') {
|
||||||
outputs.push(top => test_script(program, top))
|
outputs.push(test_script)
|
||||||
} else if (arg == '-d' || arg == '--doc') {
|
} else if (arg == '-d' || arg == '--doc') {
|
||||||
outputs.push(doc)
|
outputs.push(doc)
|
||||||
} else if (arg == '--toc' || arg == '--toc') {
|
} else if (arg == '--toc' || arg == '--toc') {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue