UNPKG

774 BJavaScriptView Raw
1"use strict"
2exports.__esModule = true
3
4const moduleRequire = require('./module-require').default
5
6exports.default = function parse(content, context) {
7
8 if (context == null) throw new Error("need context to parse properly")
9
10 let parserOptions = context.parserOptions
11 , parserPath = context.parserPath
12
13 if (!parserPath) throw new Error("parserPath is required!")
14
15 // hack: espree blows up with frozen options
16 parserOptions = Object.assign({}, parserOptions)
17 parserOptions.ecmaFeatures = Object.assign({}, parserOptions.ecmaFeatures)
18
19 // always attach comments
20 parserOptions.attachComment = true
21
22 // require the parser relative to the main module (i.e., ESLint)
23 const parser = moduleRequire(parserPath)
24
25 return parser.parse(content, parserOptions)
26}