Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ function validate( opts, options ) {
if ( hasOwnProp( options, 'token' ) ) {
opts.token = options.token;
if ( !isString( opts.token ) ) {
return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'token', opts.token ) );
return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'token', opts.token ) );
}
}
if ( hasOwnProp( options, 'useragent' ) ) {
opts.useragent = options.useragent;
if ( !isString( opts.useragent ) ) {
return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'useragent', opts.useragent ) );
return new TypeError( format( 'invalid option. `%s` option must be a string. Option: `%s`.', 'useragent', opts.useragent ) );
}
}
return null;
Expand Down
108 changes: 73 additions & 35 deletions lib/node_modules/@stdlib/_tools/scripts/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,74 @@ var ERROR_NAMES = [

// MAIN //

/**
* Tests whether a variable declaration is for the `@stdlib/string-format` require.
*
* @private
* @param {Object} path - AST node path
* @returns {boolean} boolean indicating whether a variable declaration is for
* the `@stdlib/string-format` require
*/
function onStringFormat( path ) {
var node = path.node;
return node.init &&
node.init.type === 'CallExpression' &&
node.init.callee.name === 'require' &&
node.init.arguments[0].value === '@stdlib/string-format';
}
/**
* Returns false if the node index is equal to zero and true otherwise.
*
* @private
* @param {Object} path - AST node path
* @param {number} idx - node index
* @returns {boolean} boolean indicating whether to keep the node
*/
function dropFirst( path, idx ) {
return idx !== 0;
}
/**
* Deletes the comments associated with a given node.
*
* @private
* @param {Object} path - AST node path
* @returns {void}
*/
function deleteComment( path ) {
var i;
if ( path.node.comments ) {
for ( i = 0; i < path.node.comments.length; i++ ) {
if ( contains( path.node.comments[ i ].value, '@license Apache-2.0' ) ) {
path.node.comments[ i ].value = '* @license Apache-2.0 ';
}
}
}
}
/**
* Rewrites a `require` statement to include the `/dist` directory if the.
* module being required starts with `@stdlib`.
*
* @private
* @param {Object} path - AST node path
* @returns {void}
*/
function rewriteRequire( path ) {
if ( startsWith( path.value.arguments[0].value, '@stdlib' ) ) {
path.value.arguments[0].value += '/dist';
}
}
/**
* Tests whether a path is a require call for `@stdlib/error-tools-fmtprodmsg`.
*
* @private
* @param {Object} path - AST node path
* @returns {boolean} boolean indicating whether a path is a require call for
* `@stdlib/error-tools-fmtprodmsg`
*/
function hasRequire( path ) {
return path.value.callee.name === 'require' &&
path.value.arguments[ 0 ].value === '@stdlib/error-tools-fmtprodmsg';
}
/**
* Transforms a file for a production build.
*
Expand All @@ -61,7 +129,7 @@ var ERROR_NAMES = [
*
* @param {Object} fileInfo - file information
* @param {Object} api - JSCodeshift API
* @returns {Object} transformed file
* @returns {string} transformed file
*/
function transformer( fileInfo, api ) {
var formatRequire;
Expand Down Expand Up @@ -128,13 +196,6 @@ function transformer( fileInfo, api ) {
* @param {Object} path - AST node path
* @returns {boolean} boolean indicating whether a variable declaration is for the `@stdlib/string-format` require
*/
function onStringFormat( path ) {
var node = path.node;
return node.init &&
node.init.type === 'CallExpression' &&
node.init.callee.name === 'require' &&
node.init.arguments[0].value === '@stdlib/string-format';
}

/**
* Assigns the variable name for the `@stdlib/string-format` require.
Expand All @@ -155,9 +216,6 @@ function transformer( fileInfo, api ) {
* @param {number} idx - node index
* @returns {boolean} boolean indicating whether to keep the node
*/
function dropFirst( path, idx ) {
return idx !== 0;
}

/**
* Deletes the comments associated with a given node.
Expand All @@ -166,16 +224,6 @@ function transformer( fileInfo, api ) {
* @param {Object} path - AST node path
* @returns {void}
*/
function deleteComment( path ) {
var i;
if ( path.node.comments ) {
for ( i = 0; i < path.node.comments.length; i++ ) {
if ( contains( path.node.comments[ i ].value, '@license Apache-2.0' ) ) {
path.node.comments[ i ].value = '* @license Apache-2.0 ';
}
}
}
}

/**
* Rewrites a `require` statement to include the `/dist` directory if the module being required starts with `@stdlib`.
Expand All @@ -184,11 +232,6 @@ function transformer( fileInfo, api ) {
* @param {Object} path - AST node path
* @returns {void}
*/
function rewriteRequire( path ) {
if ( startsWith( path.value.arguments[0].value, '@stdlib' ) ) {
path.value.arguments[0].value += '/dist';
}
}

/**
* Callback invoked upon finding a string literal.
Expand Down Expand Up @@ -237,13 +280,12 @@ function transformer( fileInfo, api ) {
nRequires = requires.size();
debug( 'Found ' + nRequires + ' `require` calls...' );
if ( !requires.some( hasRequire ) ) {
formatRequire = j.variableDeclaration('var', [
j.variableDeclarator(j.identifier( formatVar ), j.callExpression(j.identifier( 'require' ), [
j.stringLiteral( '@stdlib/error-tools-fmtprodmsg' )
]))
formatRequire = j.variableDeclaration( 'var', [
j.variableDeclarator( j.identifier( formatVar ), j.callExpression( j.identifier( 'require' ), [ j.stringLiteral( '@stdlib/error-tools-fmtprodmsg' ) ]) )
]);
debug( 'Adding `require` call to `@stdlib/error-tools-fmtprodmsg`...' );
j( root.find( j.Declaration ).at( 0 ).get() ).insertBefore( formatRequire );
j( root.find( j.Declaration ).at( 0 ).get() )
.insertBefore( formatRequire );
}
}
}
Expand All @@ -256,10 +298,6 @@ function transformer( fileInfo, api ) {
* @param {Object} path - AST node path
* @returns {boolean} boolean indicating whether a path is a require call for `@stdlib/error-tools-fmtprodmsg`
*/
function hasRequire( path ) {
return path.value.callee.name === 'require' &&
path.value.arguments[ 0 ].value === '@stdlib/error-tools-fmtprodmsg';
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function funseqAsync() {

// Copy arguments which should be provided to the first invoked function...
args = [];
for ( i = 0; i < nargs; i++ ) {
for ( i = 0; i < arguments.length - 1; i++ ) {
args.push( arguments[ i ] );
}
// Append the callback an invoked function should call upon completion:
Expand Down