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 | (function () {
|
29 | 'use strict';
|
30 |
|
31 | var query, Registry, pass, post, common;
|
32 |
|
33 | common = require('./common');
|
34 | query = require('./query');
|
35 |
|
36 | Registry = {};
|
37 | Registry.__direct = {};
|
38 |
|
39 |
|
40 |
|
41 | function initialize(kind, passes) {
|
42 | var i, iz, pass;
|
43 | Registry[kind] = {};
|
44 | for (i = 0, iz = passes.length; i < iz; ++i) {
|
45 | pass = passes[i];
|
46 | common.assert(Registry[kind][pass.passName] == null, 'don\'t create duplicate pass names');
|
47 | Registry[kind][pass.passName] = pass;
|
48 | }
|
49 | common.assert(Registry.__direct[pass.passName] == null, 'don\'t create duplicate pass names');
|
50 | Registry.__direct[pass.passName] = pass;
|
51 | }
|
52 |
|
53 | pass = [
|
54 | require('./pass/hoist-variable-to-arguments'),
|
55 | require('./pass/transform-dynamic-to-static-property-access'),
|
56 | require('./pass/transform-dynamic-to-static-property-definition'),
|
57 | require('./pass/transform-immediate-function-call'),
|
58 | require('./pass/transform-logical-association'),
|
59 | require('./pass/reordering-function-declarations'),
|
60 | require('./pass/remove-unused-label'),
|
61 | require('./pass/remove-empty-statement'),
|
62 | require('./pass/remove-wasted-blocks'),
|
63 | require('./pass/transform-to-compound-assignment'),
|
64 | require('./pass/transform-to-sequence-expression'),
|
65 | require('./pass/transform-branch-to-expression'),
|
66 | require('./pass/transform-typeof-undefined'),
|
67 | require('./pass/reduce-sequence-expression'),
|
68 | require('./pass/reduce-branch-jump'),
|
69 | require('./pass/reduce-multiple-if-statements'),
|
70 | require('./pass/dead-code-elimination'),
|
71 | require('./pass/remove-side-effect-free-expressions'),
|
72 | require('./pass/remove-context-sensitive-expressions'),
|
73 | require('./pass/tree-based-constant-folding'),
|
74 | require('./pass/concatenate-variable-definition'),
|
75 | require('./pass/drop-variable-definition'),
|
76 | require('./pass/remove-unreachable-branch'),
|
77 | require('./pass/eliminate-duplicate-function-declarations')
|
78 | ];
|
79 |
|
80 | post = [
|
81 | require('./post/transform-static-to-dynamic-property-access'),
|
82 | require('./post/transform-infinity'),
|
83 | require('./post/rewrite-boolean'),
|
84 | require('./post/rewrite-conditional-expression'),
|
85 | require('./post/omit-parens-in-void-context-iife')
|
86 | ];
|
87 |
|
88 | initialize('pass', pass);
|
89 | initialize('post', post);
|
90 |
|
91 | function passRequire(name) {
|
92 | if (common.Object.has(Registry.__direct, name)) {
|
93 | return Registry.__direct[name];
|
94 | }
|
95 | return query.get(Registry, name.split('/'));
|
96 | }
|
97 |
|
98 | exports.require = passRequire;
|
99 | exports.Registry = Registry;
|
100 |
|
101 |
|
102 |
|
103 | exports.__defaultPipeline = [
|
104 | pass,
|
105 | {
|
106 | once: true,
|
107 | pass: post
|
108 | }
|
109 | ];
|
110 | }());
|