From bc96dfb78e8df7e57c2cca7aee88a32d38c7565e Mon Sep 17 00:00:00 2001 From: JYC Date: Sun, 28 May 2023 08:17:01 +0200 Subject: [PATCH] Fix error parsing typescript files with decoratoes (#1100) --- .changeset/few-chicken-sell.md | 5 +++++ packages/houdini/src/lib/parse.test.ts | 19 ++++++++++++++++++- packages/houdini/src/lib/parse.ts | 2 +- 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 .changeset/few-chicken-sell.md diff --git a/.changeset/few-chicken-sell.md b/.changeset/few-chicken-sell.md new file mode 100644 index 000000000..e542a0f9b --- /dev/null +++ b/.changeset/few-chicken-sell.md @@ -0,0 +1,5 @@ +--- +'houdini': patch +--- + +Support projects using `experimentalDecorators: true` flag in there tsconfig.json diff --git a/packages/houdini/src/lib/parse.test.ts b/packages/houdini/src/lib/parse.test.ts index 3ed5cfcf0..9a53c33ee 100644 --- a/packages/houdini/src/lib/parse.test.ts +++ b/packages/houdini/src/lib/parse.test.ts @@ -1,6 +1,6 @@ import { test, expect, describe } from 'vitest' -import { parseJSON } from './parse' +import { parseJS, parseJSON } from './parse' describe('parse', function () { test('parseJSON without comments', async function () { @@ -72,4 +72,21 @@ describe('parse', function () { }, }) }) + + test('parseJS with decorators', async function () { + const parsed = parseJS(` + const a = 1 + const b = 2 + + @annotation + class Test {} + `) + expect(parsed).toMatchInlineSnapshot(` + const a = 1; + const b = 2; + + @annotation + class Test {} + `) + }) }) diff --git a/packages/houdini/src/lib/parse.ts b/packages/houdini/src/lib/parse.ts index bd08f9989..a8a648237 100644 --- a/packages/houdini/src/lib/parse.ts +++ b/packages/houdini/src/lib/parse.ts @@ -11,7 +11,7 @@ export type ParsedFile = Maybe<{ script: Script; start: number; end: number }> // overload definitions export function parseJS(str: string, config?: Partial): Script { const defaultConfig: ParserOptions = { - plugins: ['typescript', 'importAssertions'], + plugins: ['typescript', 'importAssertions', 'decorators'], sourceType: 'module', } // @ts-ignore: babel doesn't perfectly match recast's types (the comments don't line up)