-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathissue-3.ts
59 lines (52 loc) · 2.29 KB
/
issue-3.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
/**
* Fixes https://github.com/woutervh-/typescript-is/issues/3
*/
import * as assert from 'assert';
import * as path from 'path';
import * as ts from 'typescript';
import { transformNode } from '../lib/transform-inline/transform-node';
import { PartialVisitorContext } from '../lib/transform-inline/visitor-context';
const configFilename = path.resolve('tsconfig.json');
const content = ts.sys.readFile(configFilename);
if (content === undefined) {
throw new Error('Could not read config file.');
}
const configFile = ts.parseConfigFileTextToJson(configFilename, content);
const configParseResult = ts.parseJsonConfigFileContent(configFile.config, ts.sys, path.dirname(configFilename), {}, path.basename(configFilename));
configParseResult.options.noEmit = true;
delete configParseResult.options.out;
delete configParseResult.options.outDir;
delete configParseResult.options.outFile;
delete configParseResult.options.declaration;
describe('visitor', () => {
describe('visitor test-fixtures/issue-3.ts', () => {
const inFile = path.resolve(__dirname, '..', 'test-fixtures', 'issue-3.ts');
const program = ts.createProgram([inFile], configParseResult.options);
const visitorContext: PartialVisitorContext = {
checker: program.getTypeChecker(),
program,
compilerOptions: program.getCompilerOptions(),
options: {
ignoreClasses: false,
ignoreMethods: false,
functionBehavior: 'error',
shortCircuit: false,
disallowSuperfluousObjectProperties: false,
transformNonNullExpressions: false,
emitDetailedErrors: 'auto'
},
typeMapperStack: [],
previousTypeReference: null,
canonicalPaths: new Map()
};
function visitNodeAndChildren(node: ts.Node) {
ts.forEachChild(transformNode(node, visitorContext), visitNodeAndChildren);
}
const expectedMessageRegExp = /Classes cannot be validated\. https:\/\/github\.com\/woutervh-\/typescript-is\/issues\/3$/;
it('should throw an error for classes', () => {
assert.throws(() => {
visitNodeAndChildren(program.getSourceFile(inFile)!);
}, expectedMessageRegExp);
});
});
});