1import { type absFileDirPath } from '../../ptDirF.mts'2import { PtErr } from '../../sharedF/throwErrorF/sharedErrF.mts'3import * as acorn from 'acorn'4import acornJsx from 'acorn-jsx'6const acorn2 = acorn.Parser.extend(acornJsx())8export const acornParse = ({contents, ptPath} : {contents: string, ptPath: absFileDirPath}) => {9 try {10 return acorn2.parse(11 contents, {12 ecmaVersion: 'latest',13 sourceType: 'module',14 allowAwaitOutsideFunction: true,15 locations: true,16 }17 ) 18 } catch (err: any) {19 // Re-throw with file path in message for debuggability20 const loc = err.loc ? `:${err.loc.line}:${err.loc.column}` : ''21 err.message = `${ptPath}${loc} - ${err.message}`22 throw err23 }24}