UNPKG

babel-plugin-root-import

Version:
54 lines (40 loc) 1.96 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var CallExpressionTester = function () { function CallExpressionTester(babelTypes, options) { var _this = this; _classCallCheck(this, CallExpressionTester); this.types = babelTypes; this.simpleFunctions = ['require']; this.memberFunctions = ['require.resolve']; if ('functions' in options) { options.functions.forEach(function (func) { var parts = func.split('.'); if (parts.length === 1) { _this.simpleFunctions.push(func); } else if (parts.length === 2) { _this.memberFunctions.push(func); } }); } } _createClass(CallExpressionTester, [{ key: 'test', value: function test(path) { var callee = path.node.callee; if (this.types.isIdentifier(callee) && this.simpleFunctions.includes(callee.name)) { return true; } if (this.types.isImport(callee)) { return true; } return this.types.isMemberExpression(path.node.callee) && this.memberFunctions.includes(callee.object.name + '.' + callee.property.name); } }]); return CallExpressionTester; }(); exports.default = CallExpressionTester;