forked from babel/babel
/
plugin.js
38 lines (32 loc) · 901 Bytes
/
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
module.exports = function (babel) {
const { types: t } = babel;
return {
visitor: {
Program(path) {
const { file } = this;
const { sourceFileName } = file.opts.generatorOpts;
// This injects the sourcesContent, though I don't imagine anyone's
// doing it.
file.code = {
[sourceFileName]: file.code,
'test.js': '<bar />',
};
},
CallExpression(path) {
const callee = path.node;
const { loc } = callee;
// This filename will cause a second source file to be generated in the
// output sourcemap.
loc.filename = "test.js";
loc.start.column = 1;
loc.end.column = 4;
const node = t.stringLiteral('bar');
node.loc = loc;
path.replaceWith(node);
},
Function(path) {
path.remove();
},
},
};
};