"use strict";
import { getOption } from "../lib/util";
export function parse(source: string, options?: any) {
const comments: any[] = [];
const ast = require("esprima").parse(source, {
loc: true,
locations: true,
comment: true,
onComment: comments,
range: getOption(options, "range", false),
tolerant: getOption(options, "tolerant", true),
tokens: true,
jsx: getOption(options, "jsx", false),
sourceType: getOption(options, "sourceType", "module"),
});
if (!Array.isArray(ast.comments)) {
ast.comments = comments;
}
return ast;
}