Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

micromark-util-subtokenize

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

micromark-util-subtokenize - npm Package Compare versions

Comparing version 1.0.0-alpha.3 to 1.0.0-beta.1

83

dev/index.js

@@ -135,4 +135,3 @@ /**

function subcontent(events, eventIndex) {
/** @type {Token} */
let token = events[eventIndex][1]
const token = events[eventIndex][1]
const context = events[eventIndex][2]

@@ -154,13 +153,8 @@ let startPosition = eventIndex - 1

let previous
/** @type {number} */
let index
/** @type {boolean|undefined} */
let entered
/** @type {number|undefined} */
let end
/** @type {number} */
let adjust
let index = -1
/** @type {Token|undefined} */
let current = token
let adjust = 0
let start = 0
const breaks = [start]

@@ -212,38 +206,50 @@ // Loop forward through the linked tokens to pass them in order to the

// parts belong where.
// @ts-expect-error Assume at least one `previous` is set.
token = previous
index = childEvents.length
current = token
while (index--) {
// Make sure we’ve at least seen something (final eol is part of the last
// token).
if (childEvents[index][0] === 'enter') {
entered = true
} else if (
while (++index < childEvents.length) {
if (
// Find a void token that includes a break.
entered &&
childEvents[index][0] === 'exit' &&
childEvents[index - 1][0] === 'enter' &&
childEvents[index][1].type === childEvents[index - 1][1].type &&
childEvents[index][1].start.line !== childEvents[index][1].end.line
) {
add(childEvents.slice(index + 1, end))
assert(token.previous, 'expected a previous token')
assert(current, 'expected a current token')
start = index + 1
breaks.push(start)
// Help GC.
token._tokenizer = undefined
token.next = undefined
token = token.previous
end = index + 1
current._tokenizer = undefined
current.previous = undefined
current = current.next
}
}
assert(!token.previous, 'expected no previous token')
// Help GC.
tokenizer.events = []
token._tokenizer = undefined
token.next = undefined
// Do head:
add(childEvents.slice(0, end))
// If there’s one more token (which is the cases for lines that end in an
// EOF), that’s perfect: the last point we found starts it.
// If there isn’t then make sure any remaining content is added to it.
if (current) {
// Help GC.
current._tokenizer = undefined
current.previous = undefined
assert(!current.next, 'expected no next token')
} else {
breaks.pop()
}
// Now splice the events from the subtokenizer into the current events,
// moving back to front so that splice indices aren’t affected.
index = breaks.length
while (index--) {
const slice = childEvents.slice(breaks[index], breaks[index + 1])
const start = startPositions.pop()
assert(start !== undefined, 'expected a start position when splicing')
jumps.unshift([start, start + slice.length - 1])
splice(events, start, 2, slice)
}
index = -1
adjust = 0

@@ -256,13 +262,2 @@ while (++index < jumps.length) {

return gaps
/**
* @param {Event[]} slice
* @returns {void}
*/
function add(slice) {
const start = startPositions.pop()
assert(start !== undefined, 'expected a start position when calling `add`')
jumps.unshift([start, start + slice.length - 1])
splice(events, start, 2, slice)
}
}

@@ -133,4 +133,3 @@ /**

function subcontent(events, eventIndex) {
/** @type {Token} */
let token = events[eventIndex][1]
const token = events[eventIndex][1]
const context = events[eventIndex][2]

@@ -156,17 +155,9 @@ let startPosition = eventIndex - 1

let previous
/** @type {number} */
let index
/** @type {boolean|undefined} */
let entered
/** @type {number|undefined} */
let end
/** @type {number} */
let adjust
let index = -1
/** @type {Token|undefined} */
let current = token // Loop forward through the linked tokens to pass them in order to the
let current = token
let adjust = 0
let start = 0
const breaks = [start] // Loop forward through the linked tokens to pass them in order to the
// subtokenizer.

@@ -208,35 +199,45 @@

// parts belong where.
// @ts-expect-error Assume at least one `previous` is set.
token = previous
index = childEvents.length
current = token
while (index--) {
// Make sure we’ve at least seen something (final eol is part of the last
// token).
if (childEvents[index][0] === 'enter') {
entered = true
} else if (
while (++index < childEvents.length) {
if (
// Find a void token that includes a break.
entered &&
childEvents[index][0] === 'exit' &&
childEvents[index - 1][0] === 'enter' &&
childEvents[index][1].type === childEvents[index - 1][1].type &&
childEvents[index][1].start.line !== childEvents[index][1].end.line
) {
add(childEvents.slice(index + 1, end))
// Help GC.
token._tokenizer = undefined
token.next = undefined
token = token.previous
end = index + 1
start = index + 1
breaks.push(start) // Help GC.
current._tokenizer = undefined
current.previous = undefined
current = current.next
}
} // Help GC.
tokenizer.events = [] // If there’s one more token (which is the cases for lines that end in an
// EOF), that’s perfect: the last point we found starts it.
// If there isn’t then make sure any remaining content is added to it.
if (current) {
// Help GC.
current._tokenizer = undefined
current.previous = undefined
} else {
breaks.pop()
} // Now splice the events from the subtokenizer into the current events,
// moving back to front so that splice indices aren’t affected.
index = breaks.length
while (index--) {
const slice = childEvents.slice(breaks[index], breaks[index + 1])
const start = startPositions.pop()
jumps.unshift([start, start + slice.length - 1])
splice(events, start, 2, slice)
}
// Help GC.
tokenizer.events = []
token._tokenizer = undefined
token.next = undefined // Do head:
add(childEvents.slice(0, end))
index = -1
adjust = 0

@@ -249,12 +250,2 @@ while (++index < jumps.length) {

return gaps
/**
* @param {Event[]} slice
* @returns {void}
*/
function add(slice) {
const start = startPositions.pop()
jumps.unshift([start, start + slice.length - 1])
splice(events, start, 2, slice)
}
}
{
"name": "micromark-util-subtokenize",
"version": "1.0.0-alpha.3",
"version": "1.0.0-beta.1",
"description": "micromark utility to tokenize subtokens",

@@ -42,5 +42,5 @@ "license": "MIT",

"dependencies": {
"micromark-util-chunked": "^1.0.0-alpha.3",
"micromark-util-symbol": "^1.0.0-alpha.3",
"micromark-util-types": "1.0.0-alpha.3"
"micromark-util-chunked": "^1.0.0-beta.1",
"micromark-util-symbol": "^1.0.0-beta.1",
"micromark-util-types": "1.0.0-beta.1"
},

@@ -47,0 +47,0 @@ "scripts": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc