File tree 3 files changed +7
-8
lines changed
3 files changed +7
-8
lines changed Original file line number Diff line number Diff line change @@ -24,7 +24,6 @@ import {location} from 'vfile-location'
24
24
25
25
const search = / \r ? \n | \r / g
26
26
27
- // To do: return `undefined`.
28
27
// To do: change parameter order, to allow `value` to be missing.
29
28
/**
30
29
* Get the source of a node or at a position.
@@ -33,7 +32,7 @@ const search = /\r?\n|\r/g
33
32
* Value to get.
34
33
* @param {VFile | VFileValue } file
35
34
* File in which `value` exists.
36
- * @returns {string | null }
35
+ * @returns {string | undefined }
37
36
* Source of `value` in `doc`, if available.
38
37
*/
39
38
export function source ( value , file ) {
@@ -47,14 +46,14 @@ export function source(value, file) {
47
46
: undefined
48
47
49
48
if ( ! position ) {
50
- return null
49
+ return undefined
51
50
}
52
51
53
52
const endOffset = loc . toOffset ( position . end )
54
53
let startOffset = loc . toOffset ( position . start )
55
54
56
55
if ( endOffset === undefined || startOffset === undefined ) {
57
- return null
56
+ return undefined
58
57
}
59
58
60
59
/** @type {Array<string> } */
Original file line number Diff line number Diff line change @@ -102,7 +102,7 @@ Get the source of a node or at a position.
102
102
103
103
###### Returns
104
104
105
- Source of ` value ` in ` doc ` , if available (` string ` or ` null ` ).
105
+ Source of ` value ` in ` doc ` , if available (` string ` or ` undefined ` ).
106
106
107
107
## Types
108
108
Original file line number Diff line number Diff line change @@ -70,16 +70,16 @@ test('source', async function (t) {
70
70
value : 'qwe' ,
71
71
position : { start : { line : 0 , column : 0 } , end : { line : 0 , column : 0 } }
72
72
}
73
- assert . equal ( source ( text , file ) , null )
73
+ assert . equal ( source ( text , file ) , undefined )
74
74
} )
75
75
76
76
await t . test ( 'should support a generated node' , async function ( ) {
77
77
const text = { type : 'text' , value : 'qwe' }
78
- assert . equal ( source ( text , file ) , null )
78
+ assert . equal ( source ( text , file ) , undefined )
79
79
} )
80
80
81
81
await t . test ( 'should support a nullish node' , async function ( ) {
82
- assert . equal ( source ( null , file ) , null )
82
+ assert . equal ( source ( null , file ) , undefined )
83
83
} )
84
84
85
85
await t . test ( 'should support cr + lf' , async function ( ) {
You can’t perform that action at this time.
0 commit comments