Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve dts parsing regex #396

Merged
merged 1 commit into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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