Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const stream = require('stream');
const cp = require('child_process');
//npm
const async = require('async');
const builtinModules = require('builtin-modules');
const chmodr = require('chmodr');
//project
const _suman = global.__suman = (global.__suman || {});
const su = require('suman-utils');
const nfsa = require('./nfsa');
//////////////////////////////////////////////////////////
const coreModuleMatches = new RegExp(`("|')(${ builtinModules.join('|') })\\1`);
const preserveFunctionNames = true;
const regexes = {
matchesStdFnWith0Args: /function\s*(\S*)\(\s*\)\s*\{/, // function foo ( ) {
matchesStdFnWith1Arg: /function\s*(\S*)\s*\(\s*(\S+)\s*\)\s*\{/, ///function\s*\(\s*\S+\s*\)\s*\{/, // function foo ( ) {
matchesStdFnWithAnyNumberOfArgs: /function\s*(\S*)\s*\(.*\)\s*\{/, ///function\s*\(\s*\S+\s*\)\s*\{/, // function foo ( ) {
matchesArrowFnWith0Args: /\(\s*\)\s*=>\s*\{/,
matchesArrowFnWith1Arg: /\(\s*\(?\s*(\S+)\s*\)?\s*=>\s*\{/, // () are optional for one arg
matchesDescribe: /^\s*describe\s*\(/,
matchesContext: /^\s*context\s*\(/,
matchesDescribeSkip: /^\s*describe.skip\s*\(/,
matchesContextSkip: /^\s*context.skip\s*\(/,
matchesIt: /^\s*it\s*\(/,
matchesItSkip: /^\s*it.skip\s*\(/,
const fs = require('fs');
const path = require('path');
const stream = require('stream');
//npm
const builtinModules = require('builtin-modules');
const chmodr = require('chmodr');
//project
const _suman = global.__suman = (global.__suman || {});
const su = require('suman-utils');
const nfsa = require('./nfsa');
//////////////////////////////////////////////////////////
const coreModuleMatches = new RegExp(`("|')(${ builtinModules.join('|') })\\1`);
const preserveFunctionNames = true;
const regexes = {
matchesStdFnWith0Args: /function\s*(\S*)\(\s*\)\s*\{/, // function foo ( ) {
matchesStdFnWith1Arg: /function\s*(\S*)\s*\(\s*(\S+)\s*\)\s*\{/, ///function\s*\(\s*\S+\s*\)\s*\{/, // function foo ( ) {
matchesStdFnWithAnyNumberOfArgs: /function\s*(\S*)\s*\(.*\)\s*\{/, ///function\s*\(\s*\S+\s*\)\s*\{/, // function foo ( ) {
matchesArrowFnWith0Args: /\(\s*\)\s*=>\s*\{/,
matchesArrowFnWith1Arg: /\(\s*\(?\s*(\S+)\s*\)?\s*=>\s*\{/, // () are optional for one arg
matchesDescribe: /^\s*describe\s*\(/,
matchesContext: /^\s*context\s*\(/,
matchesDescribeSkip: /^\s*describe.skip\s*\(/,
matchesContextSkip: /^\s*context.skip\s*\(/,
matchesIt: /^\s*it\s*\(/,
matchesItSkip: /^\s*it.skip\s*\(/,
const lines = String(file).split('\n'); //replace all lines but new line chars
console.log(lines);
const result = [];
//const coreModuleMatches = /'^(var|const|,)[a-z\$\_]{1,}=require\((\'|")(assert|fs|path)(\'|")\)[;|,]{0,1}$/;
//const coreModuleMatches = '^\s*(?:var|const|,)\s*([a-z$_]+\s*=\s*require\((\'|")(?:(' + builtinModules.join('|') + '))\2\),?[\n\r\t\s]*)*;$';
//const coreModuleMatches = `^\s*(var|const|,)\s*[a-zA-Z\_\$]+\s*=\s*require\(('|")(${builtinModules.join('|')})('|")\)`;
//const coreModuleMatches = new RegExp(`require\(('|")(${builtinModules.join('|')})('|")\)`);
const coreModuleMatches = new RegExp(`("|')(${ builtinModules.join('|') })\\1`);
//let rgxStr = 'require\(("|\')' + builtinModules.join('|') + '("|\')\)\\1';
console.log('rgxStr:', coreModuleMatches);
//let coreModuleMatches = new RegExp(rgxStr);
const coreModules = [];
let firstDescribeMatch = false;
const indexes = {
'index_of_top_level_describe': null
};
lines.forEach(function (line, index) {