mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-11 06:04:55 +08:00
- 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>
228 lines
5.7 KiB
JavaScript
228 lines
5.7 KiB
JavaScript
exports.tokenize = tokenizeListStart
|
||
exports.continuation = {tokenize: tokenizeListContinuation}
|
||
exports.exit = tokenizeListEnd
|
||
|
||
var assert = require('assert')
|
||
var codes = require('../character/codes')
|
||
var markdownSpace = require('../character/markdown-space')
|
||
var asciiDigit = require('../character/ascii-digit')
|
||
var constants = require('../constant/constants')
|
||
var types = require('../constant/types')
|
||
var prefixSize = require('../util/prefix-size')
|
||
var sizeChunks = require('../util/size-chunks')
|
||
var thematicBreak = require('./thematic-break')
|
||
var createSpace = require('./factory-space')
|
||
var blank = require('./partial-blank-line')
|
||
|
||
function tokenizeListStart(effects, ok, nok) {
|
||
var self = this
|
||
var initialSize = prefixSize(self.events, types.linePrefix)
|
||
var valueSize
|
||
|
||
return start
|
||
|
||
function start(code) {
|
||
if (
|
||
(code === codes.asterisk ||
|
||
code === codes.plusSign ||
|
||
code === codes.dash) &&
|
||
(!self.containerState.marker || code === self.containerState.marker)
|
||
) {
|
||
return code === codes.asterisk || code === codes.dash
|
||
? effects.check(thematicBreak, nok, unordered)(code)
|
||
: unordered(code)
|
||
}
|
||
|
||
if (
|
||
asciiDigit(code) &&
|
||
(!self.containerState.type ||
|
||
self.containerState.type === types.listOrdered)
|
||
) {
|
||
return ordered(code)
|
||
}
|
||
|
||
return nok(code)
|
||
}
|
||
|
||
function unordered(code) {
|
||
if (!self.containerState.type) {
|
||
self.containerState.type = types.listUnordered
|
||
effects.enter(self.containerState.type, {_container: true})
|
||
}
|
||
|
||
effects.enter(types.listItemPrefix)
|
||
return atMarker(code)
|
||
}
|
||
|
||
function ordered(code) {
|
||
if (self.containerState.type || !self.interrupt || code === codes.digit1) {
|
||
if (!self.containerState.type) {
|
||
self.containerState.type = types.listOrdered
|
||
effects.enter(self.containerState.type, {_container: true})
|
||
}
|
||
|
||
effects.enter(types.listItemPrefix)
|
||
effects.enter(types.listItemValue)
|
||
effects.consume(code)
|
||
valueSize = 1
|
||
return self.interrupt ? afterValue : inside
|
||
}
|
||
|
||
return nok(code)
|
||
}
|
||
|
||
function inside(code) {
|
||
if (asciiDigit(code) && ++valueSize < constants.listItemValueSizeMax) {
|
||
effects.consume(code)
|
||
return inside
|
||
}
|
||
|
||
return afterValue(code)
|
||
}
|
||
|
||
function afterValue(code) {
|
||
effects.exit(types.listItemValue)
|
||
|
||
return code === codes.rightParenthesis || code === codes.dot
|
||
? atMarker(code)
|
||
: nok(code)
|
||
}
|
||
|
||
function atMarker(code) {
|
||
assert(
|
||
code === codes.asterisk ||
|
||
code === codes.plusSign ||
|
||
code === codes.dash ||
|
||
code === codes.rightParenthesis ||
|
||
code === codes.dot,
|
||
'expected list marker'
|
||
)
|
||
|
||
self.containerState.marker = self.containerState.marker || code
|
||
|
||
if (code === self.containerState.marker) {
|
||
effects.enter(types.listItemMarker)
|
||
effects.consume(code)
|
||
effects.exit(types.listItemMarker)
|
||
return effects.check(
|
||
blank,
|
||
// Can’t be empty when interrupting.
|
||
self.interrupt ? nok : onBlank,
|
||
effects.attempt(
|
||
{tokenize: tokenizeListItemPrefixWhitespace, partial: true},
|
||
endOfPrefix,
|
||
otherPrefix
|
||
)
|
||
)
|
||
}
|
||
|
||
return nok(code)
|
||
}
|
||
|
||
function onBlank(code) {
|
||
self.containerState.initialBlankLine = true
|
||
initialSize++
|
||
return endOfPrefix(code)
|
||
}
|
||
|
||
function otherPrefix(code) {
|
||
if (markdownSpace(code)) {
|
||
effects.enter(types.listItemPrefixWhitespace)
|
||
effects.consume(code)
|
||
effects.exit(types.listItemPrefixWhitespace)
|
||
return endOfPrefix
|
||
}
|
||
|
||
return nok(code)
|
||
}
|
||
|
||
function endOfPrefix(code) {
|
||
self.containerState.size =
|
||
initialSize +
|
||
sizeChunks(self.sliceStream(effects.exit(types.listItemPrefix)))
|
||
return ok(code)
|
||
}
|
||
}
|
||
|
||
function tokenizeListContinuation(effects, ok, nok) {
|
||
var self = this
|
||
|
||
self.containerState._closeFlow = undefined
|
||
|
||
return effects.check(blank, onBlank, notBlank)
|
||
|
||
function onBlank(code) {
|
||
self.containerState.furtherBlankLines =
|
||
self.containerState.furtherBlankLines ||
|
||
self.containerState.initialBlankLine
|
||
return ok(code)
|
||
}
|
||
|
||
function notBlank(code) {
|
||
if (self.containerState.furtherBlankLines || !markdownSpace(code)) {
|
||
self.containerState.furtherBlankLines = self.containerState.initialBlankLine = undefined
|
||
return notInCurrentItem(code)
|
||
}
|
||
|
||
self.containerState.furtherBlankLines = self.containerState.initialBlankLine = undefined
|
||
return effects.attempt(
|
||
{tokenize: tokenizeIndent, partial: true},
|
||
ok,
|
||
notInCurrentItem
|
||
)(code)
|
||
}
|
||
|
||
function notInCurrentItem(code) {
|
||
// While we do continue, we signal that the flow should be closed.
|
||
self.containerState._closeFlow = true
|
||
// As we’re closing flow, we’re no longer interrupting
|
||
self.interrupt = undefined
|
||
return createSpace(
|
||
effects,
|
||
effects.attempt(exports, ok, nok),
|
||
types.linePrefix,
|
||
constants.tabSize
|
||
)(code)
|
||
}
|
||
}
|
||
|
||
function tokenizeIndent(effects, ok, nok) {
|
||
var self = this
|
||
|
||
return createSpace(
|
||
effects,
|
||
afterPrefix,
|
||
types.listItemIndent,
|
||
self.containerState.size + 1
|
||
)
|
||
|
||
function afterPrefix(code) {
|
||
return prefixSize(self.events, types.listItemIndent) ===
|
||
self.containerState.size
|
||
? ok(code)
|
||
: nok(code)
|
||
}
|
||
}
|
||
|
||
function tokenizeListEnd(effects) {
|
||
effects.exit(this.containerState.type)
|
||
}
|
||
|
||
function tokenizeListItemPrefixWhitespace(effects, ok, nok) {
|
||
var self = this
|
||
|
||
return createSpace(
|
||
effects,
|
||
afterPrefix,
|
||
types.listItemPrefixWhitespace,
|
||
constants.tabSize + 1
|
||
)
|
||
|
||
function afterPrefix(code) {
|
||
return markdownSpace(code) ||
|
||
!prefixSize(self.events, types.listItemPrefixWhitespace)
|
||
? nok(code)
|
||
: ok(code)
|
||
}
|
||
}
|