1- 'use strict'
2-
3- var Parser = require ( 'parse5/lib/parser' )
4- var pos = require ( 'unist-util-position' )
5- var visit = require ( 'unist-util-visit' )
6- var fromParse5 = require ( 'hast-util-from-parse5' )
7- var toParse5 = require ( 'hast-util-to-parse5' )
8- var voids = require ( 'html-void-elements' )
9- var ns = require ( 'web-namespaces' )
10- var zwitch = require ( 'zwitch' )
11- var xtend = require ( 'xtend' )
12-
13- module . exports = wrap
1+ import Parser from 'parse5/lib/parser/index.js'
2+ import { pointStart , pointEnd } from 'unist-util-position'
3+ import { visit } from 'unist-util-visit'
4+ import { fromParse5 } from 'hast-util-from-parse5'
5+ import { toParse5 } from 'hast-util-to-parse5'
6+ import { htmlVoidElements } from 'html-void-elements'
7+ import { webNamespaces } from 'web-namespaces'
8+ import { zwitch } from 'zwitch'
149
1510var inTemplateMode = 'IN_TEMPLATE_MODE'
1611var dataState = 'DATA_STATE'
@@ -22,18 +17,18 @@ var doctypeToken = 'DOCTYPE_TOKEN'
2217
2318var parseOptions = { sourceCodeLocationInfo : true , scriptingEnabled : false }
2419
25- function wrap ( tree , file , options ) {
20+ export function raw ( tree , file , options ) {
2621 var parser = new Parser ( parseOptions )
2722 var one = zwitch ( 'type' , {
2823 handlers : {
29- root : root ,
30- element : element ,
31- text : text ,
32- comment : comment ,
33- doctype : doctype ,
34- raw : raw
24+ root,
25+ element,
26+ text,
27+ comment,
28+ doctype,
29+ raw : handleRaw
3530 } ,
36- unknown : unknown
31+ unknown
3732 } )
3833 var stitches
3934 var tokenizer
@@ -81,14 +76,14 @@ function wrap(tree, file, options) {
8176 nodeName : 'template' ,
8277 tagName : 'template' ,
8378 attrs : [ ] ,
84- namespaceURI : ns . html ,
79+ namespaceURI : webNamespaces . html ,
8580 childNodes : [ ]
8681 }
8782 var mock = {
8883 nodeName : 'documentmock' ,
8984 tagName : 'documentmock' ,
9085 attrs : [ ] ,
91- namespaceURI : ns . html ,
86+ namespaceURI : webNamespaces . html ,
9287 childNodes : [ ]
9388 }
9489 var doc = { nodeName : '#document-fragment' , childNodes : [ ] }
@@ -143,11 +138,11 @@ function wrap(tree, file, options) {
143138
144139 function element ( node ) {
145140 resetTokenizer ( )
146- parser . _processToken ( startTag ( node ) , ns . html )
141+ parser . _processToken ( startTag ( node ) , webNamespaces . html )
147142
148143 all ( node . children )
149144
150- if ( voids . indexOf ( node . tagName ) < 0 ) {
145+ if ( ! htmlVoidElements . includes ( node . tagName ) ) {
151146 resetTokenizer ( )
152147 parser . _processToken ( endTag ( node ) )
153148 }
@@ -184,8 +179,8 @@ function wrap(tree, file, options) {
184179 } )
185180 }
186181
187- function raw ( node ) {
188- var start = pos . start ( node )
182+ function handleRaw ( node ) {
183+ var start = pointStart ( node )
189184 var line = start . line || 1
190185 var column = start . column || 1
191186 var offset = start . offset || 0
@@ -242,7 +237,7 @@ function wrap(tree, file, options) {
242237 // Recurse, because to somewhat handle `[<x>]</x>` (where `[]` denotes the
243238 // passed through node).
244239 if ( node . children ) {
245- clone . children = wrap (
240+ clone . children = raw (
246241 { type : 'root' , children : node . children } ,
247242 file ,
248243 options
@@ -280,14 +275,14 @@ function wrap(tree, file, options) {
280275function startTag ( node ) {
281276 var location = createParse5Location ( node )
282277
283- location . startTag = xtend ( location )
278+ location . startTag = Object . assign ( { } , location )
284279
285280 return {
286281 type : startTagToken ,
287282 tagName : node . tagName ,
288283 selfClosing : false ,
289284 attrs : attributes ( node ) ,
290- location : location
285+ location
291286 }
292287}
293288
@@ -302,13 +297,13 @@ function attributes(node) {
302297function endTag ( node ) {
303298 var location = createParse5Location ( node )
304299
305- location . endTag = xtend ( location )
300+ location . endTag = Object . assign ( { } , location )
306301
307302 return {
308303 type : endTagToken ,
309304 tagName : node . tagName ,
310305 attrs : [ ] ,
311- location : location
306+ location
312307 }
313308}
314309
@@ -323,8 +318,8 @@ function documentMode(node) {
323318}
324319
325320function createParse5Location ( node ) {
326- var start = pos . start ( node )
327- var end = pos . end ( node )
321+ var start = pointStart ( node )
322+ var end = pointEnd ( node )
328323
329324 return {
330325 startLine : start . line ,
0 commit comments