@@ -4,6 +4,7 @@ import { getExtNameFromFilePath } from './libs/extname';
4
4
import createVisitor , { PluckedContent } from './visitor' ;
5
5
import traverse from '@babel/traverse' ;
6
6
import { freeText } from './utils' ;
7
+ import { Source } from 'graphql' ;
7
8
8
9
/**
9
10
* Additional options for determining how a file is parsed.
@@ -128,7 +129,7 @@ export const gqlPluckFromCodeString = async (
128
129
filePath : string ,
129
130
code : string ,
130
131
options : GraphQLTagPluckOptions = { }
131
- ) : Promise < string > => {
132
+ ) : Promise < Source [ ] > => {
132
133
validate ( { code, options } ) ;
133
134
134
135
const fileExt = extractExtension ( filePath ) ;
@@ -137,9 +138,7 @@ export const gqlPluckFromCodeString = async (
137
138
code = await pluckVueFileScript ( code ) ;
138
139
}
139
140
140
- return parseCode ( { code, filePath, options } )
141
- . map ( t => t . content )
142
- . join ( '\n\n' ) ;
141
+ return parseCode ( { code, filePath, options } ) . map ( t => new Source ( t . content , filePath , t . loc . start ) ) ;
143
142
} ;
144
143
145
144
/**
@@ -155,7 +154,7 @@ export const gqlPluckFromCodeStringSync = (
155
154
filePath : string ,
156
155
code : string ,
157
156
options : GraphQLTagPluckOptions = { }
158
- ) : string => {
157
+ ) : Source [ ] => {
159
158
validate ( { code, options } ) ;
160
159
161
160
const fileExt = extractExtension ( filePath ) ;
@@ -164,9 +163,7 @@ export const gqlPluckFromCodeStringSync = (
164
163
code = pluckVueFileScriptSync ( code ) ;
165
164
}
166
165
167
- return parseCode ( { code, filePath, options } )
168
- . map ( t => t . content )
169
- . join ( '\n\n' ) ;
166
+ return parseCode ( { code, filePath, options } ) . map ( t => new Source ( t . content , filePath , t . loc . start ) ) ;
170
167
} ;
171
168
172
169
export function parseCode ( {
0 commit comments