Skip to content

Commit bc50a01

Browse files
authored
Fix to set vfile.value if a vfile@5 is given
Closes GH-143.
1 parent 60de570 commit bc50a01

File tree

5 files changed

+36
-1
lines changed

5 files changed

+36
-1
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ jobs:
2020
- ubuntu-latest
2121
- windows-latest
2222
node:
23-
- lts/dubnium
23+
- lts/erbium
2424
- node

index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ function pipelineStringify(p, ctx) {
4343
if (result === undefined || result === null) {
4444
// Empty.
4545
} else if (typeof result === 'string' || buffer(result)) {
46+
if ('value' in ctx.file) {
47+
ctx.file.value = result
48+
}
49+
4650
ctx.file.contents = result
4751
} else {
4852
ctx.file.result = result

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"vfile": "^4.0.0"
6060
},
6161
"devDependencies": {
62+
"vfile5": "npm:vfile@5",
6263
"browserify": "^17.0.0",
6364
"c8": "^7.0.0",
6465
"dtslint": "^4.0.0",

test/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require('./parse.js')
99
require('./run.js')
1010
require('./stringify.js')
1111
require('./process.js')
12+
require('./vfile-5.js')
1213

1314
var asyncfunctions = false
1415

test/vfile-5.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict'
2+
3+
var test = require('tape')
4+
var simple = require('./util/simple.js')
5+
var unified = require('..')
6+
7+
test('vfile@5', async function (t) {
8+
t.plan(2)
9+
10+
var pipeline = unified().use(function () {
11+
this.Parser = simple.Parser
12+
this.Compiler = () => 'bravo'
13+
})
14+
var {VFile} = await import('vfile5')
15+
var file = new VFile('alpha')
16+
17+
pipeline.processSync(file)
18+
19+
t.equal(
20+
file.value,
21+
'bravo',
22+
'should set `file.value` when a vfile@5 is passed'
23+
)
24+
t.equal(
25+
file.contents,
26+
'bravo',
27+
'should also set `file.contents` when a vfile@5 is passed'
28+
)
29+
})

0 commit comments

Comments
 (0)