@@ -5,10 +5,17 @@ import { tryCombinations } from "../../utils/try-combinations.js";
55import postprocess from "./postprocess/index.js" ;
66import createParser from "./utils/create-parser.js" ;
77import jsxRegexp from "./utils/jsx-regexp.evaluate.js" ;
8- import { getSourceType } from "./utils/source-types.js" ;
8+ import {
9+ getSourceType ,
10+ SOURCE_TYPE_COMMONJS ,
11+ SOURCE_TYPE_SCRIPT ,
12+ } from "./utils/source-types.js" ;
913
1014/** @import {ParseResult, ParserOptions as ParserOptionsWithoutExperimentalRawTransfer} from "oxc-parser" */
11- /** @typedef {ParserOptionsWithoutExperimentalRawTransfer & {experimentalRawTransfer?: boolean} } ParserOptions */
15+ /** @typedef {Omit<ParserOptionsWithoutExperimentalRawTransfer, "sourceType"> & {
16+ sourceType?: ParserOptionsWithoutExperimentalRawTransfer["sourceType"] | "commonjs",
17+ experimentalRawTransfer?: boolean,
18+ }} ParserOptions */
1219
1320function createParseError ( error , { text } ) {
1421 /* c8 ignore next 3 */
@@ -41,10 +48,17 @@ function createParseError(error, { text }) {
4148@returns {Promise<ParseResult> }
4249*/
4350async function parseWithOptions ( filepath , text , options ) {
51+ let { sourceType } = options ;
52+ // https://github.com/oxc-project/oxc/issues/16200
53+ if ( sourceType === SOURCE_TYPE_COMMONJS ) {
54+ sourceType = SOURCE_TYPE_SCRIPT ;
55+ }
56+
4457 const result = await oxcParse ( filepath , text , {
4558 preserveParens : true ,
4659 showSemanticErrors : false ,
4760 ...options ,
61+ sourceType,
4862 } ) ;
4963
5064 const { errors } = result ;
0 commit comments