Skip to content

Commit 56325d3

Browse files
committed
Update parse5
1 parent 71e1fc8 commit 56325d3

File tree

3 files changed

+25
-21
lines changed

3 files changed

+25
-21
lines changed

Diff for: index.js

+15-11
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var one = zwitch('type')
1313
var all = mapz(one, {key: 'children', indices: false})
1414

1515
var customProps = [
16-
'__location',
16+
'sourceCodeLocation',
1717
'childNodes',
1818
'content',
1919
'parentNode',
@@ -108,8 +108,8 @@ function doctype(node) {
108108
return wrap(node, {
109109
nodeName: '#documentType',
110110
name: node.name,
111-
publicId: node.public || null,
112-
systemId: node.system || null
111+
publicId: node.public || '',
112+
systemId: node.system || ''
113113
})
114114
}
115115

@@ -129,12 +129,16 @@ function comment(node) {
129129

130130
/* Patch position. */
131131
function wrap(node, ast, content) {
132-
if (node.position && node.position.start && node.position.end) {
133-
ast.__location = {
134-
line: node.position.start.line,
135-
col: node.position.start.column,
136-
startOffset: node.position.start.offset,
137-
endOffset: node.position.end.offset
132+
var position = node.position
133+
134+
if (position && position.start && position.end) {
135+
ast.sourceCodeLocation = {
136+
startLine: position.start.line,
137+
startCol: position.start.column,
138+
startOffset: position.start.offset,
139+
endLine: position.end.line,
140+
endCol: position.end.column,
141+
endOffset: position.end.offset
138142
}
139143
}
140144

@@ -148,7 +152,7 @@ function wrap(node, ast, content) {
148152
/* Patch a tree recursively, by adding namespaces
149153
* and parent references where needed. */
150154
function patch(node, parent, ns) {
151-
var location = node.__location
155+
var location = node.sourceCodeLocation
152156
var children = node.childNodes
153157
var name = node.tagName
154158
var replacement = {}
@@ -189,7 +193,7 @@ function patch(node, parent, ns) {
189193
}
190194

191195
if (location) {
192-
replacement.__location = location
196+
replacement.sourceCodeLocation = location
193197
}
194198

195199
return replacement

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"browserify": "^16.0.0",
3030
"esmangle": "^1.0.1",
3131
"nyc": "^12.0.0",
32-
"parse5": "^3.0.0",
32+
"parse5": "^5.0.0",
3333
"prettier": "^1.13.5",
3434
"remark-cli": "^5.0.0",
3535
"remark-preset-wooorm": "^4.0.0",

Diff for: test/position.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ var parse5 = require('parse5')
66
var toParse5 = require('..')
77

88
test('position', function(t) {
9-
var node = parse5.parseFragment('<h1>Alpha', {locationInfo: true})
9+
var node = parse5.parseFragment('<h1>Alpha', {sourceCodeLocationInfo: true})
1010

1111
node = node.childNodes[0]
1212
delete node.parentNode
13-
delete node.__location
13+
14+
/* Not possible yet to map this one. */
15+
delete node.sourceCodeLocation.startTag
1416

1517
t.deepEqual(
1618
inspect(
@@ -26,13 +28,11 @@ test('position', function(t) {
2628
end: {line: 1, column: 10, offset: 9}
2729
}
2830
}
29-
]
30-
// Hidden for now, see https://github.com/inikulin/parse5/issues/224.
31-
// ,
32-
// position: {
33-
// start: {line: 1, column: 1, offset: 0},
34-
// end: {line: 1, column: 10, offset: 9}
35-
// }
31+
],
32+
position: {
33+
start: {line: 1, column: 1, offset: 0},
34+
end: {line: 1, column: 10, offset: 9}
35+
}
3636
}),
3737
{depth: null}
3838
),

0 commit comments

Comments
 (0)