UNPKG

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