| 62 | }), output); |
| 63 | |
| 64 | function finish (src) { |
| 65 | var pos = 0; |
| 66 | src = String(src); |
| 67 | |
| 68 | moduleBindings.forEach(function (binding) { |
| 69 | if (binding.isReferenced()) { |
| 70 | return; |
| 71 | } |
| 72 | var node = binding.initializer; |
| 73 | if (node.type === 'VariableDeclarator') { |
| 74 | var i = node.parent.declarations.indexOf(node); |
| 75 | if (node.parent.declarations.length === 1) { |
| 76 | // remove the entire declaration |
| 77 | updates.push({ |
| 78 | start: node.parent.start, |
| 79 | offset: node.parent.end - node.parent.start, |
| 80 | stream: st() |
| 81 | }); |
| 82 | } else if (i === node.parent.declarations.length - 1) { |
| 83 | updates.push({ |
| 84 | // remove ", a = 1" |
| 85 | start: node.parent.declarations[i - 1].end, |
| 86 | offset: node.end - node.parent.declarations[i - 1].end, |
| 87 | stream: st() |
| 88 | }); |
| 89 | } else { |
| 90 | updates.push({ |
| 91 | // remove "a = 1, " |
| 92 | start: node.start, |
| 93 | offset: node.parent.declarations[i + 1].start - node.start, |
| 94 | stream: st() |
| 95 | }); |
| 96 | } |
| 97 | } else if (node.parent.type === 'SequenceExpression' && node.parent.expressions.length > 1) { |
| 98 | var i = node.parent.expressions.indexOf(node); |
| 99 | if (i === node.parent.expressions.length - 1) { |
| 100 | updates.push({ |
| 101 | // remove ", a = 1" |
| 102 | start: node.parent.expressions[i - 1].end, |
| 103 | offset: node.end - node.parent.expressions[i - 1].end, |
| 104 | stream: st() |
| 105 | }); |
| 106 | } else { |
| 107 | updates.push({ |
| 108 | // remove "a = 1, " |
| 109 | start: node.start, |
| 110 | offset: node.parent.expressions[i + 1].start - node.start, |
| 111 | stream: st() |
| 112 | }); |
| 113 | } |
| 114 | } else { |
| 115 | if (node.parent.type === 'ExpressionStatement') node = node.parent; |
| 116 | updates.push({ |
| 117 | start: node.start, |
| 118 | offset: node.end - node.start, |
| 119 | stream: st() |
| 120 | }); |
| 121 | } |