1
- import MagicString , {
2
- type SourceMap ,
3
- type SourceMapOptions ,
4
- } from 'magic-string'
5
1
import {
6
2
type ParseResult ,
7
3
parseAst as rolldownParseAst ,
@@ -19,6 +15,7 @@ const parseAstGeneric = (
19
15
sourceType : 'module' ,
20
16
lang : 'js' ,
21
17
preserveParens : false ,
18
+ convertSpanUtf16 : true ,
22
19
...opts ,
23
20
} )
24
21
if ( result . errors . length > 0 ) {
@@ -37,6 +34,7 @@ export const parseAstGenericAsync = async (
37
34
sourceType : 'module' ,
38
35
lang : 'js' ,
39
36
preserveParens : false ,
37
+ convertSpanUtf16 : true ,
40
38
...opts ,
41
39
} )
42
40
if ( result . errors . length > 0 ) {
@@ -46,52 +44,6 @@ export const parseAstGenericAsync = async (
46
44
return result
47
45
}
48
46
49
- export class MagicStringWrapper {
50
- private oxcMs : ParseResult [ 'magicString' ]
51
- private ms : MagicString
52
-
53
- constructor ( s : ParseResult [ 'magicString' ] ) {
54
- this . oxcMs = s
55
- this . ms = new MagicString ( s . toString ( ) )
56
- }
57
-
58
- private getO ( pos : number ) : number {
59
- return this . oxcMs . getUtf16ByteOffset ( pos )
60
- }
61
-
62
- append ( str : string ) : void {
63
- this . ms . append ( str )
64
- }
65
-
66
- appendLeft ( start : number , str : string ) : void {
67
- this . ms . appendLeft ( this . getO ( start ) , str )
68
- }
69
-
70
- prependRight ( start : number , str : string ) : void {
71
- this . ms . prependRight ( this . getO ( start ) , str )
72
- }
73
-
74
- update ( start : number , end : number , str : string ) : void {
75
- this . ms . update ( this . getO ( start ) , this . getO ( end ) , str )
76
- }
77
-
78
- move ( start : number , end : number , index : number ) : void {
79
- this . ms . move ( this . getO ( start ) , this . getO ( end ) , this . getO ( index ) )
80
- }
81
-
82
- remove ( start : number , end : number ) : void {
83
- this . ms . remove ( this . getO ( start ) , this . getO ( end ) )
84
- }
85
-
86
- generateMap ( options : SourceMapOptions ) : SourceMap {
87
- return this . ms . generateMap ( options )
88
- }
89
-
90
- toString ( ) : string {
91
- return this . ms . toString ( )
92
- }
93
- }
94
-
95
47
export const parseAst = ( code : string , opts ?: any , filename ?: string ) : any => {
96
48
return parseAstGeneric ( code , opts , filename ) . program
97
49
}
0 commit comments