babel5Compat.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. ['decorators', {decoratorsBeforeExport: false}],
  33. ],
  34. };
  35. /**
  36. * Wrapper to set default options. Doesn't accept custom options because in that
  37. * case babylon should be used instead.
  38. */
  39. module.exports = function() {
  40. return {
  41. parse(code) {
  42. return babylon.parse(code, options);
  43. },
  44. };
  45. };