forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathskipJSDocParsing.ts
76 lines (68 loc) · 2.26 KB
/
skipJSDocParsing.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import * as Harness from "../_namespaces/Harness.js";
import * as ts from "../_namespaces/ts.js";
import * as Utils from "../_namespaces/Utils.js";
describe("unittests:: skipJSDocParsing", () => {
const Diff = require("diff");
const kinds = [
ts.JSDocParsingMode.ParseAll,
ts.JSDocParsingMode.ParseForTypeErrors,
ts.JSDocParsingMode.ParseForTypeInfo,
ts.JSDocParsingMode.ParseNone,
];
const filenames = [
"file.ts",
"file.js",
];
function diffSourceFiles(name: string, content: string) {
for (const jsDocParsingMode of kinds) {
const kindName = ts.Debug.formatEnum(jsDocParsingMode, (ts as any).JSDocParsingMode);
for (const filename of filenames) {
const testName = `${name}-${kindName}-${filename}`;
it(testName, () => {
const sourceFile = ts.createSourceFile(filename, content, { languageVersion: ts.ScriptTarget.ESNext, jsDocParsingMode: undefined });
assert.isTrue(sourceFile && sourceFile.parseDiagnostics.length === 0, "no errors issued");
const sourceFileSkipped = ts.createSourceFile(filename, content, { languageVersion: ts.ScriptTarget.ESNext, jsDocParsingMode });
assert.isTrue(sourceFileSkipped && sourceFileSkipped.parseDiagnostics.length === 0, "no errors issued");
const patch = Diff.createTwoFilesPatch("default", kindName, Utils.sourceFileToJSON(sourceFile), Utils.sourceFileToJSON(sourceFileSkipped));
Harness.Baseline.runBaseline("skipJSDocParsing/" + testName + ".diff", patch);
});
}
}
}
diffSourceFiles(
"deprecated",
`
/** @deprecated */
function imDeprecated() {}
imDeprecated()
/**
* {@see imDeprecated}
* @deprecated
*/
function imDeprecated2() {}
imDeprecated2()
`,
);
diffSourceFiles(
"see",
`
/**
* @typedef {any} A
*/
/**
* @see {@link A}
* @see {@linkcode A}
* @see {@linkplain A}
*/
let foo;
`,
);
diffSourceFiles(
"link",
`
import type { A } from "./a";
/** {@link A} */
export interface B {}
`,
);
});