UNPKG

bit-bin

Version:

<a href="https://opensource.org/licenses/Apache-2.0"><img alt="apache" src="https://img.shields.io/badge/License-Apache%202.0-blue.svg"></a> <a href="https://github.com/teambit/bit/blob/master/CONTRIBUTING.md"><img alt="prs" src="https://img.shields.io/b

53 lines (42 loc) 1.89 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getDependenciesFromMemberExpression = getDependenciesFromMemberExpression; exports.getDependenciesFromCallExpression = getDependenciesFromCallExpression; exports.getSpecifierValueForImportDeclaration = getSpecifierValueForImportDeclaration; function getDependenciesFromMemberExpression(node) { if (node.object.type === 'CallExpression' && node.object.callee.type === 'Identifier' && node.object.callee.name === 'require' && node.object.arguments && node.object.arguments.length) { return getStringValue(node.object.arguments[0]); } return null; } function getDependenciesFromCallExpression(node) { if (node.callee.type === 'Import' && node.arguments.length && node.arguments[0].value) { return node.arguments[0].value; } if (node.callee.type === 'Identifier' && // taken from detective-cjs node.callee.name === 'require' && node.arguments && node.arguments.length) { return getStringValue(node.arguments[0]); } return null; } function getSpecifierValueForImportDeclaration(specifier) { return { isDefault: specifier.type === 'ImportDefaultSpecifier', // syntax of `import x from 'file'` doesn't have specifier.imported, only specifier.local // syntax of `import { x as y } from 'file'`, has `x` as specifier.imported and `y` as // specifier.local. we interested in `x` in this case. name: specifier.imported ? specifier.imported.name : specifier.local.name }; } function getStringValue(node) { // using single or double quotes (', ") if (node.type === 'Literal' || node.type === 'StringLiteral') { return node.value; } // using apostrophe (`) if (node.type === 'TemplateLiteral' && node.quasis && node.quasis.length && node.quasis[0].type === 'TemplateElement') { return node.quasis[0].value.raw; } return null; }