How to use the parseScript function from esprima

Find comprehensive JavaScript esprima.parseScript code examples handpicked from public code repositorys.

221
222
223
224
225
226
227
228
229
230
  tolerant: true
}

logger.log(`[ast] analyzing script path=${path}`)

esprima.parseScript(source, opts, function(node) {
  if (_isSuspiciousCall(host, node, path)) {
    if (results.suspicious_script_hosts.indexOf(host) < 0) {
      results.suspicious_script_hosts.push(host)
    }
fork icon1
star icon11
watch icon0

1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
  }
}

if (_.isString(this.caps[capName])) {
  try {
    esprima.parseScript(this.caps[capName])
    debug(`Loaded Capability ${capName} function as javascript`)

    return (container, browser) => {
      debug(`Running ${capName} function from inline javascript ...`)
fork icon5
star icon4
watch icon0

569
570
571
572
573
574
575
576
577
578
579
};


const rewrite = (mocksMap, recipesMap, scriptName, scriptSrc, trace, policy = null) => {
  let script;
  try {
    script = esprima.parseScript(scriptSrc, { loc: true, range: true, source: scriptName });
  } catch {
    console.log(`Parse error for script ${scriptName}! Ignoring...`)
    return null;
  }
fork icon4
star icon34
watch icon0

308
309
310
311
312
313
314
315
316
317
});

//----------------------------------------------
// Lexical analysis, Parsing to AST
//----------------------------------------------
const ast = esprisma.parseScript(G.script).body
out("AST----------------------------------AST")
out(ast);

//----------------------------------------------
fork icon0
star icon2
watch icon0

33
34
35
36
37
38
39
40
41
42
43
44
45


console.log('Trivialize v0.0.1 (c) Anvbis');
console.log('https://github.com/anvbis/trivialize');


let script = fs.readFileSync(options.script, 'utf-8');
let tree = esprima.parseScript(script);


let executor = new Executor(options.executable);
let minimizer = new Minimizer(tree, executor);

fork icon0
star icon1
watch icon0

182
183
184
185
186
187
188
189
190
191
192
193
194


const TRANSLATOR_COMMENT_REGEX = /^\s*translator:\s?(.*)$/i;


for (const path of JS_FILES) {
  const file = fs.readFileSync(path).toString();
  const script = esprima.parseScript(file, { range: true, comment: true });


  const translatableStrings = script.body
    .map(findTranslationCalls)
    .flat()
fork icon0
star icon1
watch icon0

56
57
58
59
60
61
62
63
64
65
PO.load(pofile, (error, pofile) => {
  if (error) {
    callback(error);
  } else {
    let contents = file.contents.toString();
    const script = esprima.parseScript(contents, { range: true });
    const translationCalls = script.body
      .map(findTranslationCalls)
      .flat()
      .sort((a, b) => a.range.start - b.range.start);
fork icon0
star icon1
watch icon0

228
229
230
231
232
233
234
235
236
237
        return [tokens, inferred_type, word_index];
    }
}
function ignoredElements(file_name) {
    var contents = readfile(file_name);
    let parsed = es.parseScript(contents, { range: true, tokens: true });
    let tokens = parsed.tokens;
    for (let i = 0; i < tokens.length; i++) {
        checkElement(tokens[i], i, tokens);
    }
fork icon0
star icon0
watch icon0

+ 2 other calls in file

3
4
5
6
7
8
9
10
11
12
13
const esprima = require('esprima')
const estraverse = require('estraverse')
const escodegen = require('escodegen')


let code = 'const a = 1'
const ast = esprima.parseScript(code)
estraverse.traverse(ast, {
  enter: function (node) {
    node.kind = 'var'
  },
fork icon0
star icon0
watch icon0