babel5Compat.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. // These are the options that were the default of the Babel5 parse function
  10. // see https://github.com/babel/babel/blob/5.x/packages/babel/src/api/node.js#L81
  11. const options = {
  12. sourceType: 'module',
  13. allowHashBang: true,
  14. ecmaVersion: Infinity,
  15. allowImportExportEverywhere: true,
  16. allowReturnOutsideFunction: true,
  17. startLine: 1,
  18. tokens: true,
  19. plugins: [
  20. 'estree',
  21. 'jsx',
  22. 'asyncGenerators',
  23. 'classProperties',
  24. 'doExpressions',
  25. 'exportExtensions',
  26. 'functionBind',
  27. 'functionSent',
  28. 'objectRestSpread',
  29. 'dynamicImport',
  30. 'nullishCoalescingOperator',
  31. 'optionalChaining',
  32. ],
  33. };
  34. /**
  35. * Wrapper to set default options. Doesn't accept custom options because in that
  36. * case babylon should be used instead.
  37. */
  38. module.exports = function() {
  39. return {
  40. parse(code) {
  41. return babylon.parse(code, options);
  42. },
  43. };
  44. };