UNPKG

380 BJavaScriptView Raw
1const esprima = require('esprima')
2
3class JSParser {
4 constructor (opts = {}) {
5 this.setLocation = !!opts.setLocation
6 this.setRange = !!opts.setRange
7 this.comments = !!opts.comments
8 }
9
10 parse (str) {
11 return esprima.parseModule(str, {
12 loc: this.setLocation,
13 range: this.setRange,
14 comment: this.comments
15 })
16 }
17}
18
19module.exports = JSParser