Skip to content

Commit

Permalink
fix: improve dts parsing regex (#396)
Browse files Browse the repository at this point in the history
  • Loading branch information
lishaobos committed Jun 14, 2023
1 parent 809996b commit 4d2bc63
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/ctx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ ${dts}`.trim()}\n`

const multilineCommentsRE = /\/\*.*?\*\//gms
const singlelineCommentsRE = /\/\/.*$/gm
const dtsReg = /declare\s+global\s*{(.*?)}/s
const dtsReg = /declare\s+global\s*{(.*?)[\n\r]}/s
function parseDTS(dts: string) {
dts = dts
.replace(multilineCommentsRE, '')
Expand Down
2 changes: 2 additions & 0 deletions test/dts.increase.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ it('dts', async () => {
expect(dtsContent).toContain('AAA')
expect(dtsContent).toContain('BBB')
expect(dtsContent).toContain('$$')
expect(dtsContent).toContain('customFile')
expect(dtsContent).toContain('customFile1')
})
2 changes: 2 additions & 0 deletions test/tmp/dts.increase.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ declare global {
const $: typeof import('vue/macros')['$']
const AAA: typeof import('xxx/es')['AAA']
const BBB: typeof import('xxx/es')['BBB']
const customFile: typeof import('../src/openapi/system/user/{id}/index')['customFile']
const customFile1: typeof import('../src/openapi/system/user/{ id }/index')['customFile']
}
// for type re-export
declare global {
Expand Down

0 comments on commit 4d2bc63

Please sign in to comment.