22
22
import { embedded } from 'hast-util-embedded'
23
23
import { convertElement } from 'hast-util-is-element'
24
24
import { phrasing } from 'hast-util-phrasing'
25
+ // @ts -expect-error: to do type.
25
26
import toString from 'hast-util-to-string'
26
27
import { whitespace } from 'hast-util-whitespace'
27
28
import { toString as nlcstToString } from 'nlcst-to-string'
28
29
import { pointStart } from 'unist-util-position'
29
30
import vfileLocation from 'vfile-location'
30
31
31
- const push = [ ] . push
32
-
33
32
const source = convertElement ( [ 'code' , dataNlcstSourced ] )
34
33
const ignore = convertElement ( [
35
34
'script' ,
@@ -181,7 +180,7 @@ export function toNlcst(tree, file, Parser) {
181
180
function implicit ( children ) {
182
181
let index = - 1
183
182
let start = - 1
184
- /** @type {boolean } */
183
+ /** @type {boolean|undefined } */
185
184
let viable
186
185
187
186
while ( ++ index <= children . length ) {
@@ -203,7 +202,7 @@ export function toNlcst(tree, file, Parser) {
203
202
find ( child )
204
203
}
205
204
206
- viable = null
205
+ viable = undefined
207
206
start = - 1
208
207
}
209
208
}
@@ -213,12 +212,12 @@ export function toNlcst(tree, file, Parser) {
213
212
* Convert `node` (hast) to nlcst.
214
213
*
215
214
* @param {Node } node
216
- * @returns {Array.<UnistNode> }
215
+ * @returns {Array.<UnistNode>|undefined }
217
216
*/
218
217
function one ( node ) {
219
- /** @type {Array.<UnistNode> } */
218
+ /** @type {Array.<UnistNode>|undefined } */
220
219
let replacement
221
- /** @type {boolean } */
220
+ /** @type {boolean|undefined } */
222
221
let change
223
222
224
223
if ( node . type === 'text' ) {
@@ -239,7 +238,7 @@ export function toNlcst(tree, file, Parser) {
239
238
}
240
239
}
241
240
242
- return change
241
+ return change && replacement
243
242
? patch ( replacement , location , location . toOffset ( pointStart ( node ) ) )
244
243
: replacement
245
244
}
@@ -256,7 +255,7 @@ export function toNlcst(tree, file, Parser) {
256
255
let index = - 1
257
256
258
257
while ( ++ index < children . length ) {
259
- push . apply ( results , one ( children [ index ] ) || [ ] )
258
+ results . push ( ... ( one ( children [ index ] ) || [ ] ) )
260
259
}
261
260
262
261
return results
@@ -306,13 +305,13 @@ export function toNlcst(tree, file, Parser) {
306
305
* @returns {boolean }
307
306
*/
308
307
function dataNlcstSourced ( node ) {
309
- return node . properties . dataNlcst === 'source'
308
+ return Boolean ( node . properties && node . properties . dataNlcst === 'source' )
310
309
}
311
310
312
311
/**
313
312
* @param {Element } node
314
313
* @returns {boolean }
315
314
*/
316
315
function dataNlcstIgnore ( node ) {
317
- return node . properties . dataNlcst === 'ignore'
316
+ return Boolean ( node . properties && node . properties . dataNlcst === 'ignore' )
318
317
}
0 commit comments