-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
89 lines (86 loc) · 2.7 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
// @flow
'use strict';
const {isReactComponentClass} = require('./');
const pluginTester = require('babel-plugin-tester');
const plugin = function({types: t}) {
return {
name: 'test-plugin',
visitor: {
ClassDeclaration(path) {
if (isReactComponentClass(path)) {
path.replaceWith(t.identifier('MATCHED'));
}
},
},
};
};
pluginTester({
plugin: plugin,
babelOptions: {
parserOpts: {plugins: ['flow']},
},
tests: [
{
title: 'dont match no super class',
code: 'class Foo {}',
output: 'class Foo {}',
},
{
title: 'dont match super class not react',
code: 'class Foo extends Bar {}',
output: 'class Foo extends Bar {}',
},
{
title: 'dont match super class member expression not react',
code: 'class Foo extends Bar.Baz {}',
output: 'class Foo extends Bar.Baz {}',
},
{
title: 'dont match super class member expression react not component',
code: 'class Foo extends React.Baz {}',
output: 'class Foo extends React.Baz {}',
},
{
title: 'match super class member expression react component',
code: 'class Foo extends React.Component {}',
output: `MATCHED;`,
},
{
title: 'match super class member expression react pure component',
code: `class Foo extends React.PureComponent {}`,
output: `MATCHED;`,
},
{
title: 'dont match React if binding not correct import',
code: `let React = {};\nclass Foo extends React.Component {}`,
},
{
title: 'match React if binding correct default import',
code: `import React from "react";\nclass Foo extends React.Component {}`,
output: `import React from "react";\nMATCHED;`,
},
{
title: 'match React if binding correct namespace import',
code: `import * as React from "react";\nclass Foo extends React.Component {}`,
output: `import * as React from "react";\nMATCHED;`,
},
{
title: 'match React if binding correct named import',
code: `import { Component } from "react";\nclass Foo extends Component {}`,
output: `import { Component } from "react";\nMATCHED;`,
},
{
title: 'dont match React if binding incorrect named import',
code: `import { x } from "react";\nclass Foo extends x {}`,
},
{
title: 'match React if binding correct renamed named import',
code: `import { Component as x } from "react";\nclass Foo extends x {}`,
output: `import { Component as x } from "react";\nMATCHED;`,
},
{
title: 'dont match React if binding incorrect renamed named import',
code: `import { x as Component } from 'react';\nclass Foo extends Component {}`,
},
],
});