File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- import { provider } from 'std-env'
1+ // Adapted from https://github.com/nuxt/nuxt/blob/6d85c15fb1783b003bb5d7cdefdd22b54f871f9d/packages/nuxt/src/core/utils/parse.ts
22
33export let parseSync : typeof import ( 'oxc-parser' ) . parseSync
44
55export async function initParser ( ) {
6- parseSync = await (
7- provider === 'stackblitz'
8- ? ( import ( '@oxc-parser/wasm' ) as unknown as Promise < typeof import ( 'oxc-parser' ) > )
9- : import ( 'oxc-parser' )
10- ) . then ( r => r . parseSync )
6+ try {
7+ parseSync = await import ( 'oxc-parser' ) . then ( r => r . parseSync )
8+ } catch ( _ ) {
9+ console . warn ( '[nuxt-i18n]: Unable to import `oxc-parser`, falling back to `@oxc-parser/wasm`.' )
10+
11+ const { parseSync : parse } = await import ( '@oxc-parser/wasm' )
12+ parseSync = ( filename , sourceText , options ) =>
13+ // @ts -expect-error sourceType property conflict
14+ parse ( sourceText , {
15+ ...( options || { } ) ,
16+ sourceFilename : filename . replace ( / \? .* $ / , '' ) + `.${ options ?. lang || 'ts' } ` ,
17+ sourceType : 'module'
18+ } )
19+ }
1120}
You can’t perform that action at this time.
0 commit comments