@@ -73,16 +73,16 @@ import {htmlVoidElements} from 'html-void-elements'
7373import { webNamespaces } from 'web-namespaces'
7474import { zwitch } from 'zwitch'
7575
76- var inTemplateMode = 'IN_TEMPLATE_MODE'
77- var dataState = 'DATA_STATE'
78- var characterToken = 'CHARACTER_TOKEN'
79- var startTagToken = 'START_TAG_TOKEN'
80- var endTagToken = 'END_TAG_TOKEN'
81- var commentToken = 'COMMENT_TOKEN'
82- var doctypeToken = 'DOCTYPE_TOKEN'
76+ const inTemplateMode = 'IN_TEMPLATE_MODE'
77+ const dataState = 'DATA_STATE'
78+ const characterToken = 'CHARACTER_TOKEN'
79+ const startTagToken = 'START_TAG_TOKEN'
80+ const endTagToken = 'END_TAG_TOKEN'
81+ const commentToken = 'COMMENT_TOKEN'
82+ const doctypeToken = 'DOCTYPE_TOKEN'
8383
8484/** @type {P5ParserOptions } */
85- var parseOptions = { sourceCodeLocationInfo : true , scriptingEnabled : false }
85+ const parseOptions = { sourceCodeLocationInfo : true , scriptingEnabled : false }
8686
8787/**
8888 * Given a hast tree and an optional vfile (for positional info), return a new
@@ -93,24 +93,22 @@ var parseOptions = {sourceCodeLocationInfo: true, scriptingEnabled: false}
9393 * @param {Options } [options] Configuration
9494 */
9595export function raw ( tree , file , options ) {
96- var index = - 1
97- var parser = new Parser ( parseOptions )
98- var one = zwitch ( 'type' , {
96+ let index = - 1
97+ const parser = new Parser ( parseOptions )
98+ const one = zwitch ( 'type' , {
9999 handlers : { root, element, text, comment, doctype, raw : handleRaw } ,
100100 unknown
101101 } )
102102 /** @type {boolean } */
103- var stitches
103+ let stitches
104104 /** @type {HiddenTokenizer } */
105- var tokenizer
105+ let tokenizer
106106 /** @type {HiddenPreprocessor } */
107- var preprocessor
107+ let preprocessor
108108 /** @type {HiddenPosTracker } */
109- var posTracker
109+ let posTracker
110110 /** @type {HiddenLocationTracker } */
111- var locationTracker
112- /** @type {Node } */
113- var result
111+ let locationTracker
114112
115113 if ( isOptions ( file ) ) {
116114 options = file
@@ -124,7 +122,7 @@ export function raw(tree, file, options) {
124122 }
125123
126124 // @ts -expect-error: update `vfile`.
127- result = fromParse5 ( documentMode ( tree ) ? document ( ) : fragment ( ) , file )
125+ const result = fromParse5 ( documentMode ( tree ) ? document ( ) : fragment ( ) , file )
128126
129127 if ( stitches ) {
130128 visit ( result , 'comment' , mend )
@@ -156,7 +154,7 @@ export function raw(tree, file, options) {
156154 */
157155 function fragment ( ) {
158156 /** @type {P5Element } */
159- var context = {
157+ const context = {
160158 nodeName : 'template' ,
161159 tagName : 'template' ,
162160 attrs : [ ] ,
@@ -165,7 +163,7 @@ export function raw(tree, file, options) {
165163 parentNode : undefined
166164 }
167165 /** @type {P5Element } */
168- var mock = {
166+ const mock = {
169167 nodeName : 'documentmock' ,
170168 tagName : 'documentmock' ,
171169 attrs : [ ] ,
@@ -174,7 +172,7 @@ export function raw(tree, file, options) {
174172 parentNode : undefined
175173 }
176174 /** @type {P5Fragment } */
177- var doc = { nodeName : '#document-fragment' , childNodes : [ ] }
175+ const doc = { nodeName : '#document-fragment' , childNodes : [ ] }
178176
179177 parser . _bootstrap ( mock , context )
180178 parser . _pushTmplInsertionMode ( inTemplateMode )
@@ -200,7 +198,7 @@ export function raw(tree, file, options) {
200198 */
201199 function document ( ) {
202200 /** @type {P5Document } */
203- var doc = parser . treeAdapter . createDocument ( )
201+ const doc = parser . treeAdapter . createDocument ( )
204202
205203 parser . _bootstrap ( doc , null )
206204 tokenizer = parser . tokenizer
@@ -218,7 +216,7 @@ export function raw(tree, file, options) {
218216 * @returns {void }
219217 */
220218 function all ( nodes ) {
221- var index = - 1
219+ let index = - 1
222220
223221 /* istanbul ignore else - invalid nodes, see rehypejs/rehype-raw#7. */
224222 if ( nodes ) {
@@ -299,12 +297,10 @@ export function raw(tree, file, options) {
299297 * @returns {void }
300298 */
301299 function handleRaw ( node ) {
302- var start = pointStart ( node )
303- var line = start . line || 1
304- var column = start . column || 1
305- var offset = start . offset || 0
306- /** @type {HiddenToken } */
307- var token
300+ const start = pointStart ( node )
301+ const line = start . line || 1
302+ const column = start . column || 1
303+ const offset = start . offset || 0
308304
309305 // Reset preprocessor:
310306 // See: <https://github.com/inikulin/parse5/blob/9c683e1/packages/parse5/lib/tokenizer/preprocessor.js>.
@@ -339,7 +335,7 @@ export function raw(tree, file, options) {
339335 // Process final characters if they’re still there after hibernating.
340336 // Similar to:
341337 // See: <https://github.com/inikulin/parse5/blob/9c683e1/packages/parse5/lib/extensions/location-info/tokenizer-mixin.js#L95>.
342- token = tokenizer . currentCharacterToken
338+ const token = tokenizer . currentCharacterToken
343339
344340 if ( token ) {
345341 token . location . endLine = posTracker . line
@@ -353,7 +349,7 @@ export function raw(tree, file, options) {
353349 * @param {UnistNode } node
354350 */
355351 function stitch ( node ) {
356- var clone = Object . assign ( { } , node )
352+ const clone = Object . assign ( { } , node )
357353
358354 stitches = true
359355
@@ -404,10 +400,10 @@ export function raw(tree, file, options) {
404400 * @returns {HiddenToken }
405401 */
406402function startTag ( node ) {
407- /** @type {unknown } */
408- var location = Object . assign ( createParse5Location ( node ) , {
409- startTag : Object . assign ( { } , location )
410- } )
403+ /** @type {P5Location } */
404+ const location = Object . assign ( createParse5Location ( node ) )
405+ // @ts -ignore extra positional info.
406+ location . startTag = Object . assign ( { } , location )
411407
412408 // Untyped token.
413409 return {
@@ -439,10 +435,10 @@ function attributes(node) {
439435 * @returns {HiddenToken }
440436 */
441437function endTag ( node ) {
442- /** @type {unknown } */
443- var location = Object . assign ( createParse5Location ( node ) , {
444- endTag : Object . assign ( { } , location )
445- } )
438+ /** @type {P5Location } */
439+ const location = Object . assign ( createParse5Location ( node ) )
440+ // @ts -ignore extra positional info.
441+ location . startTag = Object . assign ( { } , location )
446442
447443 // Untyped token.
448444 return {
@@ -466,7 +462,7 @@ function unknown(node) {
466462 * @returns {boolean }
467463 */
468464function documentMode ( node ) {
469- var head = node . type === 'root' ? node . children [ 0 ] : node
465+ const head = node . type === 'root' ? node . children [ 0 ] : node
470466 return Boolean (
471467 head &&
472468 ( head . type === 'doctype' ||
@@ -479,8 +475,8 @@ function documentMode(node) {
479475 * @returns {P5Location }
480476 */
481477function createParse5Location ( node ) {
482- var start = pointStart ( node )
483- var end = pointEnd ( node )
478+ const start = pointStart ( node )
479+ const end = pointEnd ( node )
484480
485481 return {
486482 startLine : start . line ,
0 commit comments