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

106 lines
2.4 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 = tokenizeCodeIndented
exports.resolve = resolveCodeIndented
var assert = require('assert')
var codes = require('../character/codes')
var markdownLineEnding = require('../character/markdown-line-ending')
var constants = require('../constant/constants')
var types = require('../constant/types')
var chunkedSplice = require('../util/chunked-splice')
var prefixSize = require('../util/prefix-size')
var createSpace = require('./factory-space')
var continuedIndent = {tokenize: tokenizeContinuedIndent, partial: true}
function resolveCodeIndented(events, context) {
var code = {
type: types.codeIndented,
start: events[0][1].start,
end: events[events.length - 1][1].end
}
chunkedSplice(events, 0, 0, [['enter', code, context]])
chunkedSplice(events, events.length, 0, [['exit', code, context]])
return events
}
function tokenizeCodeIndented(effects, ok, nok) {
var self = this
return createSpace(
effects,
afterInitial,
types.linePrefix,
constants.tabSize + 1
)
function afterInitial(code) {
// Flow checks blank lines first, so we don’t have EOL/EOF.
assert(
code !== codes.eof && !markdownLineEnding(code),
'expected no eol or eof'
)
if (prefixSize(self.events, types.linePrefix) < constants.tabSize) {
return nok(code)
}
effects.enter(types.codeFlowValue)
return content(code)
}
function afterPrefix(code) {
if (code === codes.eof) {
return ok(code)
}
if (markdownLineEnding(code)) {
return effects.attempt(continuedIndent, afterPrefix, ok)(code)
}
effects.enter(types.codeFlowValue)
return content(code)
}
function content(code) {
if (code === codes.eof || markdownLineEnding(code)) {
effects.exit(types.codeFlowValue)
return afterPrefix(code)
}
effects.consume(code)
return content
}
}
function tokenizeContinuedIndent(effects, ok, nok) {
var self = this
return createSpace(
effects,
afterPrefix,
types.linePrefix,
constants.tabSize + 1
)
function afterPrefix(code) {
if (markdownLineEnding(code)) {
effects.enter(types.lineEnding)
effects.consume(code)
effects.exit(types.lineEnding)
return createSpace(
effects,
afterPrefix,
types.linePrefix,
constants.tabSize + 1
)
}
return prefixSize(self.events, types.linePrefix) < constants.tabSize
? nok(code)
: ok(code)
}
}