This repository has been archived by the owner on Sep 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
plugin.js
111 lines (89 loc) · 1.68 KB
/
plugin.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
const swc = require("../../lib/");
const Visitor = require("../../lib/Visitor").default;
{
const src = `
'use strict';
class Foo {
foo() {}
}
class Bar extends Foo {
foo() {
super.foo();
}
async bar() {}
}
class Baz extends Bar {
foo() {
super.foo();
this.baz()
}
baz() {
}
async other() {
this.baz()
await super.bar()
}
}
function red( color )
{
let foo = 3.14;
return color >> 16;
}
function green( color )
{
return ( color >> 8 ) & 0xFF;
}
/**
* Extract blue color out of a color integer:
*
* 0x00DEAD -> 0xAD
*
* @param {Number} color
* @return {Number}
*/
function blue( color )
{
return color & 0xFF;
}
function intToHex( int )
{
const mask = '#000000';
const hex = int.toString( 16 );
return mask.substring( 0, 7 - hex.length ) + hex;
}
function hexToInt( hex )
{
return parseInt( hex.substring( 1 ), 16 );
}
// Verify that visitor can handle class declaration.
class Prent {}
class Child extends Parent {}
// Verify that visitor can handle new expression.
new Child(foo);
new Child(...foo);
// Verify that visitor can handle call expressions.
call(...foo);
call(foo);
let arr = [elem, , ...foo];
module.exports = {
red,
green,
blue,
intToHex,
hexToInt,
};
`;
it("works", () => {
swc.transformSync(src, {
plugin: m => m
});
});
it("works with visitor", () => {
swc.transformSync(src, {
plugin: m => {
let v = new Visitor();
return v.visitModule(m);
}
});
});
}