aboutsummaryrefslogtreecommitdiff
path: root/test/compress/imports.js
blob: cdc239cd579deb093b58c31509f56f10ac413376 (about) (plain)
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
118
119
120
121
122
123
nought: {
    input: {
        import "foo";
    }
    expect_exact: 'import"foo";'
}

default_only: {
    input: {
        import foo from "bar";
    }
    expect_exact: 'import foo from"bar";'
}

all_only: {
    input: {
        import * as foo from "bar";
    }
    expect_exact: 'import*as foo from"bar";'
}

keys_only: {
    input: {
        import { as as foo, bar, delete as baz } from "moo";
    }
    expect_exact: 'import{as as foo,bar as bar,delete as baz}from"moo";'
}

default_all: {
    input: {
        import foo, * as bar from "baz";
    }
    expect_exact: 'import foo,*as bar from"baz";'
}

default_keys: {
    input: {
        import foo, { bar } from "baz";
    }
    expect_exact: 'import foo,{bar as bar}from"baz";'
}

dynamic: {
    input: {
        (async a => await import(a))("foo").then(bar);
    }
    expect_exact: '(async a=>await import(a))("foo").then(bar);'
}

import_meta: {
    input: {
        console.log(import.meta, import.meta.url);
    }
    expect_exact: "console.log(import.meta,import.meta.url);"
}

same_quotes: {
    beautify = {
        beautify: true,
        quote_style: 3,
    }
    input: {
        import 'foo';
        import "bar";
    }
    expect_exact: [
        "import 'foo';",
        "",
        'import "bar";',
    ]
}

drop_unused: {
    options = {
        imports: true,
        toplevel: true,
        unused: true,
    }
    input: {
        import a, * as b from "foo";
        import { c, bar as d } from "baz";
        console.log(c);
    }
    expect: {
        import "foo";
        import { c as c } from "baz";
        console.log(c);
    }
}

mangle: {
    rename = false
    mangle = {
        toplevel: true,
    }
    input: {
        import foo, { bar } from "baz";
        consoe.log(moo);
        import * as moo from "moz";
    }
    expect: {
        import o, { bar as m } from "baz";
        consoe.log(r);
        import * as r from "moz";
    }
}

rename_mangle: {
    rename = true
    mangle = {
        toplevel: true,
    }
    input: {
        import foo, { bar } from "baz";
        consoe.log(moo);
        import * as moo from "moz";
    }
    expect: {
        import o, { bar as m } from "baz";
        consoe.log(r);
        import * as r from "moz";
    }
}