File tree Expand file tree Collapse file tree 1 file changed +4
-24
lines changed Expand file tree Collapse file tree 1 file changed +4
-24
lines changed Original file line number Diff line number Diff line change 2222
2323import { location } from 'vfile-location'
2424
25- const search = / \r ? \n | \r / g
26-
2725/**
2826 * Get the source of a node or at a position.
2927 *
@@ -49,27 +47,9 @@ export function source(file, value) {
4947 }
5048
5149 const endOffset = loc . toOffset ( position . end )
52- let startOffset = loc . toOffset ( position . start )
53-
54- if ( endOffset === undefined || startOffset === undefined ) {
55- return undefined
56- }
57-
58- /** @type {Array<string> } */
59- const results = [ ]
60-
61- while ( startOffset < endOffset ) {
62- search . lastIndex = startOffset
63- const match = search . exec ( doc )
64- const end = match && match . index < endOffset ? match . index : endOffset
65- results . push ( doc . slice ( startOffset , end ) )
66- startOffset = end
67-
68- if ( match && match . index < endOffset ) {
69- startOffset += match [ 0 ] . length
70- results . push ( match [ 0 ] )
71- }
72- }
50+ const startOffset = loc . toOffset ( position . start )
7351
74- return results . join ( '' )
52+ return endOffset === undefined || startOffset === undefined
53+ ? undefined
54+ : doc . slice ( startOffset , endOffset )
7555}
You can’t perform that action at this time.
0 commit comments