Debian Codegraph @

packages/babel-core/test/fixtures/transformation/source-maps/input-source-map-sources-complete-replace/plugin.js

raw
1 module.exports = function (babel) {
2 const { types: t } = babel;
3
4 return {
5 visitor: {
6 Program(path) {
7 const { file } = this;
8 const { sourceFileName } = file.opts.generatorOpts;
9
10 // This injects the sourcesContent, though I don't imagine anyone's
11 // doing it.
12 file.code = {
13 [sourceFileName]: file.code,
14 'test.js': '<bar />',
15 };
16 },
17
18 CallExpression(path) {
19 const callee = path.node;
20 const { loc } = callee;
21
22 // This filename will cause a second source file to be generated in the
23 // output sourcemap.
24 loc.filename = "test.js";
25 loc.start.column = 1;
26 loc.end.column = 4;
27
28 const node = t.stringLiteral('bar');
29 node.loc = loc;
30 path.replaceWith(node);
31 },
32
33 Function(path) {
34 path.remove();
35 },
36 },
37 };
38 };