UNPKG

2.05 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7var _macros = require('./lib/utils/macros');
8
9var _macros2 = _interopRequireDefault(_macros);
10
11var _fs = require('fs');
12
13var _path = require('path');
14
15var _normalizeOptions = require('./lib/utils/normalize-options');
16
17function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
19function macros(babel) {
20 var t = babel.types;
21
22 var macroBuilder = void 0;
23 var options = void 0;
24
25 return {
26 name: "babel-feature-flags-and-debug-macros",
27 visitor: {
28
29 Program: {
30 enter(path, state) {
31 var _this = this;
32
33 options = (0, _normalizeOptions.normalizeOptions)(state.opts);
34 this.macroBuilder = new _macros2.default(t, options);
35
36 var body = path.get('body');
37
38 body.forEach(function (item) {
39 if (item.isImportDeclaration()) {
40 var importPath = item.node.source.value;
41
42 var _options = options,
43 featureSources = _options.featureSources,
44 debugToolsImport = _options.debugTools.debugToolsImport,
45 _options$envFlags = _options.envFlags,
46 envFlagsImport = _options$envFlags.envFlagsImport,
47 flags = _options$envFlags.flags;
48
49
50 var isFeaturesImport = featureSources.indexOf(importPath) > -1;
51
52 if (debugToolsImport && debugToolsImport === importPath) {
53 _this.macroBuilder.collectDebugToolsSpecifiers(item.get('specifiers'));
54 }if (envFlagsImport && envFlagsImport === importPath) {
55 _this.macroBuilder.collectEnvFlagSpecifiers(item.get('specifiers'));
56 }
57 }
58 });
59 },
60
61 exit(path) {
62 this.macroBuilder.expand(path);
63 }
64 },
65
66 ExpressionStatement(path) {
67 this.macroBuilder.build(path);
68 }
69 }
70 };
71}
72
73macros.baseDir = function () {
74 return (0, _path.dirname)(__dirname);
75};
76
77exports.default = macros;
\No newline at end of file