diff --git a/src/core/index.ts b/src/core/index.ts index f3039ce..53b0e9c 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -24,7 +24,9 @@ export function transformQuansync( id: string, ): CodeTransform | undefined { const lang = getLang(id) - const program = babelParse(code, lang) + const program = babelParse(code, lang, { + createParenthesizedExpressions: true, + }) const imports: Record = Object.create(null) for (const node of program.body) { diff --git a/tests/__snapshots__/transform.test.ts.snap b/tests/__snapshots__/transform.test.ts.snap index 071195d..f6fe890 100644 --- a/tests/__snapshots__/transform.test.ts.snap +++ b/tests/__snapshots__/transform.test.ts.snap @@ -154,7 +154,7 @@ export const echo = quansync({ const echoNewLine = quansync( /** @param {string|Promise} v */ function* (v) { -return ((yield echo(yield v))) + '\\n' +return (yield echo(yield v)) + '\\n' }, ) @@ -169,3 +169,13 @@ export default async () => { } " `; + +exports[`transform > ./fixtures/parens.js 1`] = ` +"import { quansync } from 'quansync/macro' + +const parens = quansync(function* (obj) { + const config = yield (obj + 1) + return config +}) +" +`; diff --git a/tests/fixtures/parens.js b/tests/fixtures/parens.js new file mode 100644 index 0000000..0120502 --- /dev/null +++ b/tests/fixtures/parens.js @@ -0,0 +1,6 @@ +import { quansync } from 'quansync/macro' + +const parens = quansync(async (obj) => { + const config = await (obj + 1) + return config +}) diff --git a/tests/transform.test.ts b/tests/transform.test.ts index 48c4d99..44d932a 100644 --- a/tests/transform.test.ts +++ b/tests/transform.test.ts @@ -21,7 +21,7 @@ describe('transform', async () => { const filePath = path.resolve(dirname, `temp/${path.basename(id)}`) await writeFile(filePath, result) const mod = await import(`${pathToFileURL(filePath).href}?${Date.now()}`) - await mod.default() + await mod.default?.() return result },