UNPKG

616 BJavaScriptView Raw
1// adds `window.foo = "default";` at the top of the module
2// will repleace "default" with the content of options.text
3module.exports = function(babel) {
4 var t = babel.types;
5
6 return {
7 visitor: {
8 Program: function(path, state) {
9 var options = state.opts;
10
11 path.unshiftContainer("body", [
12 t.expressionStatement(
13 t.assignmentExpression(
14 "=",
15 t.memberExpression(t.identifier("window"), t.identifier("foo")),
16 t.stringLiteral(options.text ? options.text : "default")
17 )
18 )
19 ]);
20 }
21 }
22 };
23};