Files
react-native-devtools-frontend/node_modules/micromark/lib/initialize/document.js
T
Tim van der Lippe efb716af67 Update linter packages
- Updates stylelint to 13.8.0
- Updates ESLint to 7.14.0
- Updates @typescript-eslint to 4.9.0

DISABLE_THIRD_PARTY_CHECK=NPM update
R=jacktfranklin@chromium.org

Change-Id: I207e204607ede782710e042c17d6510c7f696905
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2566806
Reviewed-by: Jack Franklin <jacktfranklin@chromium.org>
Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
2020-12-01 16:04:40 +00:00

230 lines
5.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
exports.tokenize = initializeDocument
var codes = require('../character/codes')
var markdownLineEnding = require('../character/markdown-line-ending')
var constants = require('../constant/constants')
var types = require('../constant/types')
var createSpace = require('../tokenize/factory-space')
var blank = require('../tokenize/partial-blank-line')
var container = {tokenize: tokenizeContainer}
var lazyFlow = {tokenize: tokenizeLazyFlow}
function initializeDocument(effects) {
var self = this
var stack = []
var continued = 0
var inspectResult
var childFlow
var childToken
return start
function start(code) {
if (continued < stack.length) {
self.containerState = stack[continued][1]
return effects.attempt(
stack[continued][0].continuation,
documentContinue,
documentContinued
)(code)
}
return documentContinued(code)
}
function documentContinue(code) {
continued++
return start(code)
}
function documentContinued(code) {
// If we’re in a concrete construct (such as when expecting another line of
// HTML, or we resulted in lazy content), we can immediately start flow.
if (inspectResult && inspectResult.flowContinue) {
return flowStart(code)
}
self.interrupt =
childFlow &&
childFlow.currentConstruct &&
childFlow.currentConstruct.interruptible
self.containerState = {}
return effects.attempt(container, containerContinue, flowStart)(code)
}
function containerContinue(code) {
stack.push([self.currentConstruct, self.containerState])
self.containerState = undefined
return documentContinued(code)
}
function flowStart(code) {
if (code === codes.eof) {
exitContainers(0, true)
effects.consume(code)
return
}
childFlow = childFlow || self.parser.flow(self.now())
effects.enter(types.chunkFlow, {
contentType: constants.contentTypeFlow,
previous: childToken,
_tokenizer: childFlow
})
return flowContinue(code)
}
function flowContinue(code) {
if (code === codes.eof) {
continueFlow(effects.exit(types.chunkFlow))
return flowStart(code)
}
if (markdownLineEnding(code)) {
effects.consume(code)
continueFlow(effects.exit(types.chunkFlow))
return effects.check(
{tokenize: tokenizeInspect, partial: true},
documentAfterPeek
)
}
effects.consume(code)
return flowContinue
}
function documentAfterPeek(code) {
exitContainers(
inspectResult.continued,
inspectResult && inspectResult.flowEnd
)
continued = 0
return start(code)
}
function continueFlow(token) {
if (childToken) childToken.next = token
childToken = token
childFlow.lazy = inspectResult && inspectResult.lazy
childFlow.defineSkip(token.start)
childFlow.write(self.sliceStream(token))
}
function exitContainers(size, end) {
var index = stack.length
// Close the flow.
if (childFlow && end) {
childFlow.write([codes.eof])
childToken = childFlow = undefined
}
// Exit open containers.
while (index-- > size) {
self.containerState = stack[index][1]
stack[index][0].exit.call(self, effects)
}
stack.length = size
}
function tokenizeInspect(effects, ok) {
var subcontinued = 0
inspectResult = {}
return inspectStart
function inspectStart(code) {
if (subcontinued < stack.length) {
self.containerState = stack[subcontinued][1]
return effects.attempt(
stack[subcontinued][0].continuation,
inspectContinue,
inspectLess
)(code)
}
// If we’re continued but in a concrete flow, we can’t have more
// containers.
if (childFlow.currentConstruct && childFlow.currentConstruct.concrete) {
inspectResult.flowContinue = true
return inspectDone(code)
}
self.interrupt =
childFlow.currentConstruct && childFlow.currentConstruct.interruptible
self.containerState = {}
return effects.attempt(container, inspectFlowEnd, inspectDone)(code)
}
function inspectContinue(code) {
subcontinued++
return self.containerState._closeFlow
? inspectFlowEnd(code)
: inspectStart(code)
}
function inspectLess(code) {
if (childFlow.currentConstruct && childFlow.currentConstruct.lazy) {
// Maybe another container?
self.containerState = {}
return effects.attempt(
container,
inspectFlowEnd,
// Maybe flow, or a blank line?
effects.attempt(
lazyFlow,
inspectFlowEnd,
effects.check(blank, inspectFlowEnd, inspectLazy)
)
)(code)
}
// Otherwise we’re interrupting.
return inspectFlowEnd(code)
}
function inspectLazy(code) {
// Act as if all containers are continued.
subcontinued = stack.length
inspectResult.lazy = true
inspectResult.flowContinue = true
return inspectDone(code)
}
// We’re done with flow if we have more containers, or an interruption.
function inspectFlowEnd(code) {
inspectResult.flowEnd = true
return inspectDone(code)
}
function inspectDone(code) {
inspectResult.continued = subcontinued
self.interrupt = self.containerState = undefined
return ok(code)
}
}
}
function tokenizeContainer(effects, ok, nok) {
return createSpace(
effects,
effects.attempt(this.parser.constructs.document, ok, nok),
types.linePrefix,
constants.tabSize
)
}
function tokenizeLazyFlow(effects, ok, nok) {
return createSpace(
effects,
effects.lazy(this.parser.constructs.flow, ok, nok),
types.linePrefix,
constants.tabSize
)
}