babel5Compat.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Copyright (c) 2015-present, Facebook, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. *
  9. */
  10. 'use strict';
  11. const babylon = require('babylon');
  12. // These are the options that were the default of the Babel5 parse function
  13. // see https://github.com/babel/babel/blob/5.x/packages/babel/src/api/node.js#L81
  14. const options = {
  15. sourceType: 'module',
  16. allowHashBang: true,
  17. ecmaVersion: Infinity,
  18. allowImportExportEverywhere: true,
  19. allowReturnOutsideFunction: true,
  20. plugins: [
  21. 'estree',
  22. 'jsx',
  23. 'asyncGenerators',
  24. 'classProperties',
  25. 'doExpressions',
  26. 'exportExtensions',
  27. 'functionBind',
  28. 'functionSent',
  29. 'objectRestSpread',
  30. 'dynamicImport',
  31. 'nullishCoalescingOperator',
  32. 'optionalChaining',
  33. ],
  34. };
  35. /**
  36. * Wrapper to set default options
  37. */
  38. exports.parse = function parse (code) {
  39. return babylon.parse(code, options);
  40. };