babylon.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. 'use strict';
  8. const babylon = require('@babel/parser');
  9. const defaultOptions = {
  10. sourceType: 'module',
  11. allowImportExportEverywhere: true,
  12. allowReturnOutsideFunction: true,
  13. startLine: 1,
  14. tokens: true,
  15. plugins: [
  16. ['flow', {all: true}],
  17. 'flowComments',
  18. 'jsx',
  19. 'asyncGenerators',
  20. 'bigInt',
  21. 'classProperties',
  22. 'classPrivateProperties',
  23. 'classPrivateMethods',
  24. ['decorators', {decoratorsBeforeExport: false}],
  25. 'doExpressions',
  26. 'dynamicImport',
  27. 'exportDefaultFrom',
  28. 'exportNamespaceFrom',
  29. 'functionBind',
  30. 'functionSent',
  31. 'importMeta',
  32. 'logicalAssignment',
  33. 'nullishCoalescingOperator',
  34. 'numericSeparator',
  35. 'objectRestSpread',
  36. 'optionalCatchBinding',
  37. 'optionalChaining',
  38. ['pipelineOperator', {proposal: 'minimal'}],
  39. 'throwExpressions',
  40. ],
  41. };
  42. /**
  43. * Wrapper to set default options
  44. */
  45. module.exports = function(options=defaultOptions) {
  46. return {
  47. parse(code) {
  48. return babylon.parse(code, options);
  49. },
  50. };
  51. };