-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
113 lines (108 loc) · 2.29 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
// @flow
'use strict';
const {simplifyModule} = require('./');
const createBabylonOptions = require('babylon-options');
const pluginTester = require('babel-plugin-tester');
const printAST = require('ast-pretty-print');
const plugin = function({types: t}) {
const VISITED = Symbol('visited');
let getOutput = path => {
let printed = printAST(path) + '\n';
return t.expressionStatement(
t.templateLiteral([
t.templateElement({ raw: printed }, true)
], [])
);
};
return {
name: 'test-plugin',
visitor: {
Program(path) {
if (path[VISITED]) return;
simplifyModule(path);
path[VISITED] = true;
path.pushContainer('body', getOutput(path));
},
},
};
};
pluginTester({
plugin: plugin,
babelOptions: {
parserOpts: createBabylonOptions({
stage: 0,
plugins: ['flow'],
}),
},
snapshot: true,
tests: [
{
title: 'statement',
code: 'var a = 1;',
},
{
title: 'statement rewriting',
code: 'var a = 1, b = 2;',
},
{
title: 'export named',
code: 'export var a = 1;',
},
{
title: 'export default',
code: 'export default 1;',
},
{
title: 'export named from',
code: 'export { a } from "b";',
},
{
title: 'export default from',
code: 'export default from "b";',
},
{
title: 'export all from',
code: 'export * from "b";',
},
{
title: 'import default',
code: 'import a from "b";',
},
{
title: 'import named',
code: 'import { a } from "b";',
},
{
title: 'import namespace',
code: 'import * as a from "b";',
},
{
title: 'import type default',
code: 'import type a from "b";',
},
{
title: 'import type named',
code: 'import type { a } from "b";',
},
{
title: 'import type inner',
code: 'import { type a } from "b";',
},
{
title: 'import typeof default',
code: 'import typeof a from "b";',
},
{
title: 'import typeof named',
code: 'import typeof { a } from "b";',
},
{
title: 'import typeof inner',
code: 'import { typeof a } from "b";',
},
{
title: 'import side effects',
code: 'import "b";',
},
],
});