How to use the esprima.tokenize function in esprima

To help you get started, we’ve selected a few esprima examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github darlanalves / angular-di-annotations / test / Generator.spec.js View on Github external
}];

				// AngularStub creates this variable to check the injections
				lib.constants.MODULE = '$module';

				var node = TestHelper.createFunctionNode(this.functionName, this.functionParams, annotationTags);
				var code = Generator.generateCodeForNode(node);
				var expectedParams = '[\'%1\']'.replace('%1', this.functionParams.join('\',\''));
				var expectedCode = "%module.%type('%name', %value);\n%value.$inject=%injection;"
					.replace('%module', '$module')
					.replace('%type', dependencyType)
					.replace('%name', this.dependencyName)
					.replace(/%value/g, this.functionName)
					.replace('%injection', expectedParams);

				var codeTokens = esprima.tokenize(code),
					expectedTokens = esprima.tokenize(expectedCode);

				compareTokens(codeTokens, expectedTokens);
			}
		});
github alxolr / redosy / lib / redos-scanner.js View on Github external
function handleFile(err, file) {
      try {
        esprima.tokenize(file, { loc: true, range: true, comment: true }, handleToken(instance, filePath));
      } catch (err) { } // eslint-disable-line
      next();
    }
  }
github naturalness / sensibility / sensibility / language / javascript / index.js View on Github external
function tokenize(source) {
  source = removeShebangLine(source);

  /* TODO: retry on illegal tokens. */
  const sourceType = deduceSourceType(source);
  const tokens = esprima.tokenize(source, {
    sourceType,
    loc: true,
    tolerant: true
  });

  return tokens;
}
github naturalness / sensibility / sensibility / tokenize-js / index.js View on Github external
function tokenize(source) {
  source = removeShebangLine(source);

  /* TODO: retry on illegal tokens. */

  const sourceType = deduceSourceType(source);
  const tokens = esprima.tokenize(source, {
    sourceType,
    loc: true,
    tolerant: true
  });

  return tokens;
}
github mikrovvelle / mlxprs / client / marklogicClient.ts View on Github external
export function parseQueryForOverrides(queryText: string): Record {
    const tokens: esprima.Token[] = esprima.tokenize(queryText, {comment: true})
    let overrides: Record = {}
    if (tokens.length > 0 && tokens[0].type === 'BlockComment') {
        const firstBlockComment: string = tokens[0].value
        const firstBlockCommentLine: string =
            firstBlockComment.split(/\n+/)[0]
                .replace(/\t+/g, '')
                .trim()
        if (firstBlockCommentLine.match(MLSETTINGSFLAG)) {
            const overridePayload: string = firstBlockComment
                .replace(MLSETTINGSFLAG, '')
                .trim()
            overrides = JSON.parse(overridePayload)
        }
    }
    return overrides
}
github officert / mongotron / src / lib / modules / expression / index.js View on Github external
return new Promise((resolve, reject) => {
      if (!expression) return reject(new Error('Expression - eval() - expression is required'));

      let astTokens = esprima.tokenize(expression);

      let startTime = process.hrtime();

      _eval(expression, scope)
        .then(result => {
          let time = _getTime(startTime);

          let expressionResult = {
            result: result,
            time: time,
            mongoMethodName: _getMongoMethodName(astTokens),
            mongoCollectionName: _getMongoCollectionName(expression, astTokens)
          };

          if (_.isArray(expressionResult.result)) {
            expressionResult.keyValueResults = keyValueUtils.convert(expressionResult.result);
github littlstar / stardux / src / index.js View on Github external
function getTokens (string) {
  let tokens = null
  try { tokens = esprima.tokenize('`'+ string +'`') }
  catch (e) { tokens = [] }
  return tokens
}
github twskj / pretty-swag / pretty-swag.js View on Github external
}
                }
                else {
                    return '["' + context.items.type + '"]';
                }
            }
            else {
                return "[]";
            }
        }
        else {
            return schema;
        }
    }
    var src = "a=" + resolveNested(schema, def, required);
    var tokens = esprima.tokenize(src, { comment: true });
    tmp = format(tokens, indent_num);
    return unEscapeComment(tmp);
}
github computers-are-fast / computers-are-fast.github.io / jspm_packages / npm / js-tokens@1.0.1 / esprima-compare.js View on Github external
function getEsprimaTokens(code) {
    var tokens = esprima.tokenize(code, {loc: true});
    tokens.forEach(function(token) {
      token.type = typeMap[token.type];
    });
    return tokens;
  }
  function jsTokensTokenize(string) {