This repository has been archived by the owner on Dec 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support require statements with apostrophes (#103)
* fix teambit/bit#1708, support require statements with apostrophes * bump version
- Loading branch information
1 parent
2d7c990
commit d4807c1
Showing
8 changed files
with
86 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
export 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; | ||
} | ||
|
||
export 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 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; | ||
} |