1
1
import * as fs from 'fs' ;
2
2
import * as path from 'path' ;
3
- import type { ExportNamedDeclaration } from '@babel/types' ;
4
3
import * as recast from 'recast' ;
5
4
import t = recast . types . namedTypes ;
5
+ import type { ParserPlugin } from '@babel/parser' ;
6
6
import { parse as babelParse } from '@babel/parser' ;
7
7
import type { Plugin } from 'vite' ;
8
8
import { WRAPPED_MODULE_SUFFIX } from '../common/utils' ;
@@ -103,7 +103,9 @@ export async function canWrapLoad(id: string, debug: boolean): Promise<boolean>
103
103
104
104
const code = ( await fs . promises . readFile ( id , 'utf8' ) ) . toString ( ) ;
105
105
106
- // Taken from recast's typescript parser config
106
+ // Taken from recast's typescript parser config, minus the JSX plugin
107
+ // see: https://github.com/benjamn/recast/blob/master/parsers/_babel_options.ts
108
+ // see: https://github.com/benjamn/recast/blob/master/parsers/babel-ts.ts
107
109
const parser = {
108
110
parse : ( source : string ) =>
109
111
babelParse ( source , {
@@ -124,6 +126,7 @@ export async function canWrapLoad(id: string, debug: boolean): Promise<boolean>
124
126
'functionBind' ,
125
127
'functionSent' ,
126
128
'importAssertions' ,
129
+ 'exportExtensions' as ParserPlugin ,
127
130
'importMeta' ,
128
131
'nullishCoalescingOperator' ,
129
132
'numericSeparator' ,
@@ -187,7 +190,7 @@ export async function canWrapLoad(id: string, debug: boolean): Promise<boolean>
187
190
return exportDecl . specifiers . find ( specifier => {
188
191
return (
189
192
( specifier . exported . type === 'Identifier' && specifier . exported . name === 'load' ) ||
190
- // Type casting here because babel by default doesn 't include the 'exportExtensions' plugin
193
+ // Type casting here because somehow the 'exportExtensions' plugin isn 't reflected in the possible types
191
194
// This plugin adds support for exporting something as a string literal (see comment above)
192
195
// Doing this to avoid adding another babel plugin dependency
193
196
( ( specifier . exported . type as 'StringLiteral' | '' ) === 'StringLiteral' &&
0 commit comments