Skip to content

Commit

Permalink
fix: types
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Apr 16, 2024
1 parent 6f20847 commit 07d38fc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import type { Node } from '@babel/types'
export * from 'magic-string'
export { MagicStringBase }

// @ts-expect-error
export class MagicString implements MagicStringBase {
// @ts-expect-error whatever
class MagicStringImpl implements MagicStringBase {
offset: number
s: MagicStringBase

Expand All @@ -19,7 +19,6 @@ export class MagicString implements MagicStringBase {
offset?: number
},
) {
// super(str, options)
this.s = new MagicStringBase(str, options)
this.offset = options?.offset ?? 0
return new Proxy(this.s, {
Expand Down Expand Up @@ -89,6 +88,12 @@ export class MagicString implements MagicStringBase {
}
}

export const MagicString = MagicStringImpl as any as {
new (
...args: ConstructorParameters<typeof MagicStringImpl>
): MagicStringImpl & MagicStringBase
}

function isEmptyNodes(nodes: Node | Node[]) {
return Array.isArray(nodes) && nodes.length === 0
}
Expand Down
3 changes: 2 additions & 1 deletion tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { MagicString, MagicStringBase } from '../src'

test('basic', () => {
const s = new MagicString('foo')
expect(s.toString()).toBe('foo')
s.append('hello')
expect(s.toString()).toBe('foohello')
expect(s instanceof MagicStringBase).toBe(true)
})

Expand Down

0 comments on commit 07d38fc

Please sign in to comment.