UNPKG

analyze-es6-modules

Version:

Performs static analysis of ES6 modules in your codebase.

156 lines (138 loc) 4.05 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 Module = function () { function Module(path) { _classCallCheck(this, Module); this.path = path; this.imports = []; this.exports = []; } _createClass(Module, [{ key: 'addNamedImport', value: function addNamedImport(_ref) { var exportName = _ref.exportName; var sourcePath = _ref.sourcePath; var rawSourcePath = _ref.rawSourcePath; var lineNumber = _ref.lineNumber; this.imports.push({ type: 'named', exportName: exportName, exportingModule: { raw: rawSourcePath, resolved: sourcePath }, lineNumber: lineNumber }); } }, { key: 'addDefaultImport', value: function addDefaultImport(_ref2) { var sourcePath = _ref2.sourcePath; var rawSourcePath = _ref2.rawSourcePath; var lineNumber = _ref2.lineNumber; this.imports.push({ type: 'default', exportingModule: { raw: rawSourcePath, resolved: sourcePath }, lineNumber: lineNumber }); } }, { key: 'addBatchImport', value: function addBatchImport(_ref3) { var sourcePath = _ref3.sourcePath; var rawSourcePath = _ref3.rawSourcePath; var lineNumber = _ref3.lineNumber; this.imports.push({ type: 'batch', exportingModule: { raw: rawSourcePath, resolved: sourcePath }, lineNumber: lineNumber }); } }, { key: 'addSideEffectImport', value: function addSideEffectImport(_ref4) { var sourcePath = _ref4.sourcePath; var rawSourcePath = _ref4.rawSourcePath; var lineNumber = _ref4.lineNumber; this.imports.push({ type: 'sideEffect', exportingModule: { raw: rawSourcePath, resolved: sourcePath }, lineNumber: lineNumber }); } }, { key: 'addBatchExport', value: function addBatchExport(_ref5) { var sourcePath = _ref5.sourcePath; var rawSourcePath = _ref5.rawSourcePath; var lineNumber = _ref5.lineNumber; this.exports.push({ type: 'batch', exportingModule: { raw: rawSourcePath, resolved: sourcePath }, lineNumber: lineNumber }); } }, { key: 'addReExport', value: function addReExport(_ref6) { var exportedName = _ref6.exportedName; var importedName = _ref6.importedName; var sourcePath = _ref6.sourcePath; var rawSourcePath = _ref6.rawSourcePath; var lineNumber = _ref6.lineNumber; this.addNamedImport({ exportName: importedName, sourcePath: sourcePath, rawSourcePath: rawSourcePath }); if (exportedName === 'default') { this.addDefaultExport({ lineNumber: lineNumber }); } else { this.addNamedExport({ name: exportedName, lineNumber: lineNumber }); } } }, { key: 'addNamedExport', value: function addNamedExport(_ref7) { var exportName = _ref7.exportName; var lineNumber = _ref7.lineNumber; this.exports.push({ type: 'named', exportName: exportName, lineNumber: lineNumber }); } }, { key: 'addDefaultExport', value: function addDefaultExport(_ref8) { var lineNumber = _ref8.lineNumber; this.exports.push({ type: 'default', lineNumber: lineNumber }); } }, { key: 'toJSON', value: function toJSON() { return { path: this.path, imports: this.imports, exports: this.exports }; } }]); return Module; }(); exports.default = Module;