Skip to content

Commit 85481c7

Browse files
committed
cleanup
1 parent ad1194e commit 85481c7

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

packages/sveltekit/src/vite/autoInstrument.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import * as fs from 'fs';
22
import * as path from 'path';
3-
import type { ExportNamedDeclaration } from '@babel/types';
43
import * as recast from 'recast';
54
import t = recast.types.namedTypes;
5+
import type { ParserPlugin } from '@babel/parser';
66
import { parse as babelParse } from '@babel/parser';
77
import type { Plugin } from 'vite';
88
import { WRAPPED_MODULE_SUFFIX } from '../common/utils';
@@ -103,7 +103,9 @@ export async function canWrapLoad(id: string, debug: boolean): Promise<boolean>
103103

104104
const code = (await fs.promises.readFile(id, 'utf8')).toString();
105105

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
107109
const parser = {
108110
parse: (source: string) =>
109111
babelParse(source, {
@@ -124,6 +126,7 @@ export async function canWrapLoad(id: string, debug: boolean): Promise<boolean>
124126
'functionBind',
125127
'functionSent',
126128
'importAssertions',
129+
'exportExtensions' as ParserPlugin,
127130
'importMeta',
128131
'nullishCoalescingOperator',
129132
'numericSeparator',
@@ -187,7 +190,7 @@ export async function canWrapLoad(id: string, debug: boolean): Promise<boolean>
187190
return exportDecl.specifiers.find(specifier => {
188191
return (
189192
(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
191194
// This plugin adds support for exporting something as a string literal (see comment above)
192195
// Doing this to avoid adding another babel plugin dependency
193196
((specifier.exported.type as 'StringLiteral' | '') === 'StringLiteral' &&

0 commit comments

Comments
 (0)