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.

33 lines
969 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 JavaScript code with Acorn:
  5. //
  6. // const ast = recast.parse(source, {
  7. // parser: require("recast/parsers/acorn")
  8. // });
  9. //
  10. var util_1 = require("../lib/util");
  11. function parse(source, options) {
  12. var comments = [];
  13. var tokens = [];
  14. var ast = require("acorn").parse(source, {
  15. allowHashBang: true,
  16. allowImportExportEverywhere: true,
  17. allowReturnOutsideFunction: true,
  18. ecmaVersion: util_1.getOption(options, "ecmaVersion", 8),
  19. sourceType: util_1.getOption(options, "sourceType", "module"),
  20. locations: true,
  21. onComment: comments,
  22. onToken: tokens,
  23. });
  24. if (!ast.comments) {
  25. ast.comments = comments;
  26. }
  27. if (!ast.tokens) {
  28. ast.tokens = tokens;
  29. }
  30. return ast;
  31. }
  32. exports.parse = parse;
  33. ;