-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
117 lines (113 loc) · 2.1 KB
/
test.js
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
'use strict';
// @flow
const pluginTester = require('babel-plugin-tester');
const createBabylonOptions = require('babylon-options');
const {isFlowIdentifier} = require('./');
const babelOptions = {
parserOpts: createBabylonOptions({
stage: 0,
plugins: ['flow', 'jsx'],
}),
};
function plugin() {
return {
name: 'test-plugin',
visitor: {
Identifier(path, state) {
if (path.node.name !== 'TEST') return;
if (state.opts.flow !== isFlowIdentifier(path)) {
throw path.buildCodeFrameError('Expected: ' + state.opts.flow);
}
}
}
};
};
pluginTester({
plugin,
babelOptions,
pluginOptions: {
flow: false,
},
tests: [
{
title: 'js identifier',
code: 'TEST;',
},
{
title: 'object property',
code: 'obj.TEST;',
},
{
title: 'function name',
code: 'function TEST() {}',
},
{
title: 'class name',
code: 'class TEST {}',
},
{
title: 'value default import',
code: 'import TEST from "./module";',
},
{
title: 'value named import',
code: 'import { TEST } from "./module";',
},
{
title: 'value reference import',
code: `
import TEST from "./module";
type b = TEST;
`
},
{
title: 'value reference class',
code: `
class TEST {}
type b = TEST;
`
},
{
title: 'typeof',
code: 'type A = typeof TEST;',
},
]
});
pluginTester({
plugin,
babelOptions,
pluginOptions: {
flow: true,
},
tests: [
{
title: 'type alias',
code: 'type TEST = number;',
},
{
title: 'type param',
code: 'type a<TEST> = number;',
},
{
title: 'type reference',
code: `
type TEST = number;
type b = TEST;
`,
},
{
title: 'type reference import',
code: `
import type TEST from './module';
type b = TEST;
`,
},
{
title: 'type reference export type',
code: `
export type TEST = number;
type b = TEST;
`,
},
]
});