|
| 1 | +// This babel parser config is taken from recast's typescript parser config, specifically from these two files: |
| 2 | +// see: https://github.com/benjamn/recast/blob/master/parsers/_babel_options.ts |
| 3 | +// see: https://github.com/benjamn/recast/blob/master/parsers/babel-ts.ts |
| 4 | +// |
| 5 | +// Changes: |
| 6 | +// - we don't add the 'jsx' plugin, to correctly parse TypeScript angle bracket type assertions |
| 7 | +// (see https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#type-assertions) |
| 8 | +// - minor import and export changes |
| 9 | +// - merged the two files linked above into one for simplicity |
| 10 | + |
| 11 | +// Date of access: 2025-03-04 |
| 12 | +// Commit: https://github.com/benjamn/recast/commit/ba5132174894b496285da9d001f1f2524ceaed3a |
| 13 | + |
| 14 | +// Recast license: |
| 15 | + |
| 16 | +// Copyright (c) 2012 Ben Newman <[email protected]> |
| 17 | + |
| 18 | +// Permission is hereby granted, free of charge, to any person obtaining |
| 19 | +// a copy of this software and associated documentation files (the |
| 20 | +// "Software"), to deal in the Software without restriction, including |
| 21 | +// without limitation the rights to use, copy, modify, merge, publish, |
| 22 | +// distribute, sublicense, and/or sell copies of the Software, and to |
| 23 | +// permit persons to whom the Software is furnished to do so, subject to |
| 24 | +// the following conditions: |
| 25 | + |
| 26 | +// The above copyright notice and this permission notice shall be |
| 27 | +// included in all copies or substantial portions of the Software. |
| 28 | + |
| 29 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 30 | +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 31 | +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 32 | +// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 33 | +// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 34 | +// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 35 | +// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 36 | + |
| 37 | +import type { ParserPlugin } from '@babel/parser'; |
| 38 | +import { parse as babelParse } from '@babel/parser'; |
| 39 | + |
| 40 | +export const parser = { |
| 41 | + parse: (source: string) => |
| 42 | + babelParse(source, { |
| 43 | + plugins: [ |
| 44 | + 'typescript', |
| 45 | + 'asyncGenerators', |
| 46 | + 'bigInt', |
| 47 | + 'classPrivateMethods', |
| 48 | + 'classPrivateProperties', |
| 49 | + 'classProperties', |
| 50 | + 'classStaticBlock', |
| 51 | + 'decimal', |
| 52 | + 'decorators-legacy', |
| 53 | + 'doExpressions', |
| 54 | + 'dynamicImport', |
| 55 | + 'exportDefaultFrom', |
| 56 | + 'exportNamespaceFrom', |
| 57 | + 'functionBind', |
| 58 | + 'functionSent', |
| 59 | + 'importAssertions', |
| 60 | + 'exportExtensions' as ParserPlugin, |
| 61 | + 'importMeta', |
| 62 | + 'nullishCoalescingOperator', |
| 63 | + 'numericSeparator', |
| 64 | + 'objectRestSpread', |
| 65 | + 'optionalCatchBinding', |
| 66 | + 'optionalChaining', |
| 67 | + [ |
| 68 | + 'pipelineOperator', |
| 69 | + { |
| 70 | + proposal: 'minimal', |
| 71 | + }, |
| 72 | + ], |
| 73 | + [ |
| 74 | + 'recordAndTuple', |
| 75 | + { |
| 76 | + syntaxType: 'hash', |
| 77 | + }, |
| 78 | + ], |
| 79 | + 'throwExpressions', |
| 80 | + 'topLevelAwait', |
| 81 | + 'v8intrinsic', |
| 82 | + ], |
| 83 | + sourceType: 'module', |
| 84 | + }), |
| 85 | +}; |
0 commit comments