Skip to content

Commit

Permalink
Fix error parsing typescript files with decoratoes (#1100)
Browse files Browse the repository at this point in the history
  • Loading branch information
jycouet committed May 28, 2023
1 parent cb0310c commit bc96dfb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/few-chicken-sell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'houdini': patch
---

Support projects using `experimentalDecorators: true` flag in there tsconfig.json
19 changes: 18 additions & 1 deletion packages/houdini/src/lib/parse.test.ts
Original file line number Diff line number Diff line change
@@ -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 () {
Expand Down Expand Up @@ -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 {}
`)
})
})
2 changes: 1 addition & 1 deletion packages/houdini/src/lib/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type ParsedFile = Maybe<{ script: Script; start: number; end: number }>
// overload definitions
export function parseJS(str: string, config?: Partial<ParserOptions>): 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)
Expand Down

0 comments on commit bc96dfb

Please sign in to comment.