Skip to content

Commit acb5d81

Browse files
committed
Refactor code-style
1 parent 2e0420d commit acb5d81

File tree

1 file changed

+4
-24
lines changed

1 file changed

+4
-24
lines changed

lib/index.js

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222

2323
import {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
}

0 commit comments

Comments
 (0)