|
| 1 | +import {createTypeChecker} from '#type-checker'; |
| 2 | +import {instrument, getCoverage} from '#type-checker/instrument'; |
| 3 | +import {report} from '#type-checker/report'; |
| 4 | +import {whenTestsEnds} from '#type-checker/when-tests-ends'; |
| 5 | + |
| 6 | +// Simple string type names |
| 7 | +createTypeChecker(['Program', 'BlockStatement'])({type: 'Program'}); |
| 8 | + |
| 9 | +// Predicate function |
| 10 | +const isEmptyBody = (_a: {node: {body: {body: unknown[]}}}) => !_a.node.body.body.length; |
| 11 | +createTypeChecker([isEmptyBody])({node: {body: {body: []}}}); |
| 12 | + |
| 13 | +// Tuple with string |
| 14 | +createTypeChecker([ |
| 15 | + ['-', 'BlockStatement'], |
| 16 | +])({type: 'Program'}); |
| 17 | + |
| 18 | +// DSL string |
| 19 | +createTypeChecker([ |
| 20 | + '+: parentPath -> ExportDefaultDeclaration', |
| 21 | +])({ |
| 22 | + parentPath: {type: 'ExportDefaultDeclaration'}, |
| 23 | +}); |
| 24 | + |
| 25 | +// DSL string with negation |
| 26 | +createTypeChecker([ |
| 27 | + '+: parentPath -> !CallExpression', |
| 28 | +])({}); |
| 29 | + |
| 30 | +// Tuple with DSL and function |
| 31 | +const hasFnBody = (_a: {node: {body: {body: unknown[]}}}) => _a.node.body.body.length; |
| 32 | +createTypeChecker([ |
| 33 | + ['-: parentPath -> !', 'ExportDefaultDeclaration'], |
| 34 | + ['+', hasFnBody], |
| 35 | +])({ |
| 36 | + parentPath: {type: 'ExportDefaultDeclaration'}, |
| 37 | + type: 'BlockStatement', |
| 38 | + node: {body: {body: []}}, |
| 39 | +}); |
| 40 | + |
| 41 | +// Override with instrumentCoverage and instrumentName |
| 42 | +createTypeChecker([ |
| 43 | + '+: -> BlockStatement', |
| 44 | +], { |
| 45 | + instrumentName: 'hello', |
| 46 | +}); |
| 47 | + |
| 48 | +// Call with options |
| 49 | +const hasFnBodyOptions = (_a: unknown, b: Record<string, unknown>) => b.is; |
| 50 | +createTypeChecker([ |
| 51 | + ['+', hasFnBodyOptions], |
| 52 | +])({ |
| 53 | + type: 'FunctionDeclaration', |
| 54 | +}, { |
| 55 | + is: true, |
| 56 | +}); |
| 57 | + |
| 58 | +// instrument function |
| 59 | +instrument(['+: -> StringLiteral'], (_a: unknown) => true, { |
| 60 | + instrumentName: 'TYPE_CHECK', |
| 61 | +})({}); |
| 62 | + |
| 63 | +// getCoverage + report |
| 64 | +report(getCoverage()); |
| 65 | + |
| 66 | +// whenTestsEnds |
| 67 | +whenTestsEnds(); |
0 commit comments