Files
react-native-devtools-frontend/node_modules/micromark/lib/tokenize/definition.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

116 lines
2.9 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 = tokenizeDefinition
var assert = require('assert')
var markdownLineEnding = require('../character/markdown-line-ending')
var markdownLineEndingOrSpace = require('../character/markdown-line-ending-or-space')
var normalizeIdentifier = require('../util/normalize-identifier')
var codes = require('../character/codes')
var types = require('../constant/types')
var createDestination = require('./factory-destination')
var createLabel = require('./factory-label')
var createSpace = require('./factory-space')
var createWhitespace = require('./factory-whitespace')
var createTitle = require('./factory-title')
function tokenizeDefinition(effects, ok, nok) {
var self = this
var destinationAfter = effects.attempt(
{tokenize: tokenizeTitle, partial: true},
createSpace(effects, after, types.whitespace),
createSpace(effects, after, types.whitespace)
)
var identifier
return start
function start(code) {
assert(code === codes.leftSquareBracket, 'expected `[`')
effects.enter(types.definition)
return createLabel.call(
self,
effects,
labelAfter,
nok,
types.definitionLabel,
types.definitionLabelMarker,
types.definitionLabelString
)(code)
}
function labelAfter(code) {
identifier = normalizeIdentifier(
self.sliceSerialize(self.events[self.events.length - 1][1]).slice(1, -1)
)
if (code === codes.colon) {
effects.enter(types.definitionMarker)
effects.consume(code)
effects.exit(types.definitionMarker)
// Note: blank lines can’t exist in content.
return createWhitespace(
effects,
createDestination(
effects,
destinationAfter,
nok,
types.definitionDestination,
types.definitionDestinationLiteral,
types.definitionDestinationLiteralMarker,
types.definitionDestinationRaw,
types.definitionDestinationString
)
)
}
return nok(code)
}
function after(code) {
if (code === codes.eof || markdownLineEnding(code)) {
effects.exit(types.definition)
if (self.parser.defined.indexOf(identifier) < 0) {
self.parser.defined.push(identifier)
}
return ok(code)
}
return nok(code)
}
}
function tokenizeTitle(effects, ok, nok) {
return start
function start(code) {
return markdownLineEndingOrSpace(code)
? createWhitespace(effects, before)(code)
: nok(code)
}
function before(code) {
if (
code === codes.quotationMark ||
code === codes.apostrophe ||
code === codes.leftParenthesis
) {
return createTitle(
effects,
createSpace(effects, after, types.whitespace),
nok,
types.definitionTitle,
types.definitionTitleMarker,
types.definitionTitleString
)(code)
}
return nok(code)
}
function after(code) {
return code === codes.eof || markdownLineEnding(code) ? ok(code) : nok(code)
}
}