You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
819 B

5 years ago
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. // This module is suitable for passing as options.parser when calling
  4. // recast.parse to process ECMAScript code with Esprima:
  5. //
  6. // const ast = recast.parse(source, {
  7. // parser: require("recast/parsers/esprima")
  8. // });
  9. //
  10. var util_1 = require("../lib/util");
  11. function parse(source, options) {
  12. var comments = [];
  13. var ast = require("esprima").parse(source, {
  14. loc: true,
  15. locations: true,
  16. comment: true,
  17. onComment: comments,
  18. range: util_1.getOption(options, "range", false),
  19. tolerant: util_1.getOption(options, "tolerant", true),
  20. tokens: true
  21. });
  22. if (!Array.isArray(ast.comments)) {
  23. ast.comments = comments;
  24. }
  25. return ast;
  26. }
  27. exports.parse = parse;
  28. ;