|
1 | 1 | import loggerSpec from 'react-server-module-tagger';
|
2 | 2 | import path from 'path';
|
3 | 3 |
|
4 |
| -module.exports = function({types: t }) { |
5 |
| - return { |
6 |
| - visitor: { |
7 |
| - Identifier(p, state) { |
8 |
| - const {node} = p; |
9 |
| - const {name, type} = node; |
| 4 | +module.exports = function() { |
| 5 | + return { |
| 6 | + visitor: { |
| 7 | + Identifier(p, state) { |
| 8 | + const {node} = p; |
| 9 | + const {name} = node; |
10 | 10 |
|
11 |
| - const config = { trim: state.opts.trim }; |
12 |
| - const parent = path.resolve(path.join(process.cwd(), '..')) + path.sep; |
13 |
| - const fp = this.file.opts.filename.replace(parent, ''); |
14 |
| - const file = { path: fp }; |
15 |
| - //TODO: Support labels |
16 |
| - const moduleTag = loggerSpec.bind({ file, config })(fp); |
| 11 | + const config = { trim: state.opts.trim }; |
| 12 | + const parent = path.resolve(path.join(process.cwd(), '..')) + path.sep; |
| 13 | + const fp = this.file.opts.filename.replace(parent, ''); |
| 14 | + const file = { path: fp }; |
17 | 15 |
|
18 |
| - let tokens; |
19 |
| - if (state.opts.tokens) { |
20 |
| - tokens = new Set(state.opts.tokens); |
21 |
| - } else { |
22 |
| - tokens = new Set(["__LOGGER__", "__CHANNEL__", "__CACHE__"]); |
23 |
| - } |
| 16 | + //TODO: Support labels |
| 17 | + const moduleTag = loggerSpec.bind({ file, config })(fp); |
24 | 18 |
|
25 |
| - if (tokens.has(name)) { |
26 |
| - // this strikes me as a dirty, nasty hack. I think it would be better |
27 |
| - // to parse the object as json and coerce it to an array of |
28 |
| - // ObjectProperties to construct an ObjectExpression |
29 |
| - p.node.name = moduleTag; |
30 |
| - } |
31 |
| - } |
32 |
| - } |
33 |
| - }; |
| 19 | + let tokens; |
| 20 | + if (state.opts.tokens) { |
| 21 | + tokens = new Set(state.opts.tokens); |
| 22 | + } else { |
| 23 | + tokens = new Set(["__LOGGER__", "__CHANNEL__", "__CACHE__"]); |
| 24 | + } |
| 25 | + |
| 26 | + if (tokens.has(name)) { |
| 27 | + // this strikes me as a dirty, nasty hack. I think it would be better |
| 28 | + // to parse the object as json and coerce it to an array of |
| 29 | + // ObjectProperties to construct an ObjectExpression |
| 30 | + p.node.name = moduleTag; |
| 31 | + } |
| 32 | + }, |
| 33 | + }, |
| 34 | + }; |
34 | 35 | }
|
0 commit comments