mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-01 01:38:07 +08:00
This reverts commit2b4a9df2d9. Reason for revert: subsequent presubmit uploads should be fixed now. Original change's description: > Revert "Reland "Update stylelint to 14.0.1"" > > This reverts commitf2ea2c940d. > > Reason for revert: https://ci.chromium.org/ui/p/devtools-frontend/builders/try/dtf_presubmit_linux/b8831129368825517985/overview > > Original change's description: > > Reland "Update stylelint to 14.0.1" > > > > This reverts commit6c0f161c95. > > > > Reason for revert: the prerequisite CL (https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3259703) has landed > > > > Original change's description: > > > Revert "Update stylelint to 14.0.1" > > > > > > This reverts commit1e08ee816b. > > > > > > Reason for revert: tree is closed due to errors https://ci.chromium.org/ui/p/devtools-frontend/builders/ci/Stand-alone%20Linux/8169/overview > > > > > > Original change's description: > > > > Update stylelint to 14.0.1 > > > > > > > > This also upgrades PostCSS to 8.3.11. > > > > > > > > DISABLE_THIRD_PARTY_CHECK=Updating Stylelint configuration > > > > R=szuend@chromium.org > > > > > > > > Bug: none > > > > Change-Id: I606540b03509d7c6e73f3d490327cd4174e03d31 > > > > Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3259541 > > > > Reviewed-by: Simon Zünd <szuend@chromium.org> > > > > Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org> > > > > > > Bug: none > > > Change-Id: Icb1c02b41dbccc3b4fc5760f5dd0b78eca078b61 > > > No-Presubmit: true > > > No-Tree-Checks: true > > > No-Try: true > > > Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3263399 > > > Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com> > > > Owners-Override: Alex Rudenko <alexrudenko@chromium.org> > > > Commit-Queue: Alex Rudenko <alexrudenko@chromium.org> > > > > DISABLE_THIRD_PARTY_CHECK=Updating Stylelint configuration > > > > Bug: none > > Change-Id: If132a67ee4253d27114caedd66c5ee61c774a6c7 > > Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3264206 > > Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org> > > Reviewed-by: Simon Zünd <szuend@chromium.org> > > Reviewed-by: Alex Rudenko <alexrudenko@chromium.org> > > Bug: none > Change-Id: Idc6c9f5cc1e225c752799461eb0344e94b4ad1e5 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3264222 > Auto-Submit: Tim van der Lippe <tvanderlippe@chromium.org> > Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com> > Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com> DISABLE_THIRD_PARTY_CHECK=Updating Stylelint configuration Bug: none Change-Id: I609941d48b46bfcf454b03dcc75a76d460fbe674 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3264223 Reviewed-by: Jack Franklin <jacktfranklin@chromium.org> Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
267 lines
6.4 KiB
JavaScript
267 lines
6.4 KiB
JavaScript
'use strict'
|
|
|
|
const SINGLE_QUOTE = "'".charCodeAt(0)
|
|
const DOUBLE_QUOTE = '"'.charCodeAt(0)
|
|
const BACKSLASH = '\\'.charCodeAt(0)
|
|
const SLASH = '/'.charCodeAt(0)
|
|
const NEWLINE = '\n'.charCodeAt(0)
|
|
const SPACE = ' '.charCodeAt(0)
|
|
const FEED = '\f'.charCodeAt(0)
|
|
const TAB = '\t'.charCodeAt(0)
|
|
const CR = '\r'.charCodeAt(0)
|
|
const OPEN_SQUARE = '['.charCodeAt(0)
|
|
const CLOSE_SQUARE = ']'.charCodeAt(0)
|
|
const OPEN_PARENTHESES = '('.charCodeAt(0)
|
|
const CLOSE_PARENTHESES = ')'.charCodeAt(0)
|
|
const OPEN_CURLY = '{'.charCodeAt(0)
|
|
const CLOSE_CURLY = '}'.charCodeAt(0)
|
|
const SEMICOLON = ';'.charCodeAt(0)
|
|
const ASTERISK = '*'.charCodeAt(0)
|
|
const COLON = ':'.charCodeAt(0)
|
|
const AT = '@'.charCodeAt(0)
|
|
|
|
const RE_AT_END = /[\t\n\f\r "#'()/;[\\\]{}]/g
|
|
const RE_WORD_END = /[\t\n\f\r !"#'():;@[\\\]{}]|\/(?=\*)/g
|
|
const RE_BAD_BRACKET = /.[\n"'(/\\]/
|
|
const RE_HEX_ESCAPE = /[\da-f]/i
|
|
|
|
module.exports = function tokenizer(input, options = {}) {
|
|
let css = input.css.valueOf()
|
|
let ignore = options.ignoreErrors
|
|
|
|
let code, next, quote, content, escape
|
|
let escaped, escapePos, prev, n, currentToken
|
|
|
|
let length = css.length
|
|
let pos = 0
|
|
let buffer = []
|
|
let returned = []
|
|
|
|
function position() {
|
|
return pos
|
|
}
|
|
|
|
function unclosed(what) {
|
|
throw input.error('Unclosed ' + what, pos)
|
|
}
|
|
|
|
function endOfFile() {
|
|
return returned.length === 0 && pos >= length
|
|
}
|
|
|
|
function nextToken(opts) {
|
|
if (returned.length) return returned.pop()
|
|
if (pos >= length) return
|
|
|
|
let ignoreUnclosed = opts ? opts.ignoreUnclosed : false
|
|
|
|
code = css.charCodeAt(pos)
|
|
|
|
switch (code) {
|
|
case NEWLINE:
|
|
case SPACE:
|
|
case TAB:
|
|
case CR:
|
|
case FEED: {
|
|
next = pos
|
|
do {
|
|
next += 1
|
|
code = css.charCodeAt(next)
|
|
} while (
|
|
code === SPACE ||
|
|
code === NEWLINE ||
|
|
code === TAB ||
|
|
code === CR ||
|
|
code === FEED
|
|
)
|
|
|
|
currentToken = ['space', css.slice(pos, next)]
|
|
pos = next - 1
|
|
break
|
|
}
|
|
|
|
case OPEN_SQUARE:
|
|
case CLOSE_SQUARE:
|
|
case OPEN_CURLY:
|
|
case CLOSE_CURLY:
|
|
case COLON:
|
|
case SEMICOLON:
|
|
case CLOSE_PARENTHESES: {
|
|
let controlChar = String.fromCharCode(code)
|
|
currentToken = [controlChar, controlChar, pos]
|
|
break
|
|
}
|
|
|
|
case OPEN_PARENTHESES: {
|
|
prev = buffer.length ? buffer.pop()[1] : ''
|
|
n = css.charCodeAt(pos + 1)
|
|
if (
|
|
prev === 'url' &&
|
|
n !== SINGLE_QUOTE &&
|
|
n !== DOUBLE_QUOTE &&
|
|
n !== SPACE &&
|
|
n !== NEWLINE &&
|
|
n !== TAB &&
|
|
n !== FEED &&
|
|
n !== CR
|
|
) {
|
|
next = pos
|
|
do {
|
|
escaped = false
|
|
next = css.indexOf(')', next + 1)
|
|
if (next === -1) {
|
|
if (ignore || ignoreUnclosed) {
|
|
next = pos
|
|
break
|
|
} else {
|
|
unclosed('bracket')
|
|
}
|
|
}
|
|
escapePos = next
|
|
while (css.charCodeAt(escapePos - 1) === BACKSLASH) {
|
|
escapePos -= 1
|
|
escaped = !escaped
|
|
}
|
|
} while (escaped)
|
|
|
|
currentToken = ['brackets', css.slice(pos, next + 1), pos, next]
|
|
|
|
pos = next
|
|
} else {
|
|
next = css.indexOf(')', pos + 1)
|
|
content = css.slice(pos, next + 1)
|
|
|
|
if (next === -1 || RE_BAD_BRACKET.test(content)) {
|
|
currentToken = ['(', '(', pos]
|
|
} else {
|
|
currentToken = ['brackets', content, pos, next]
|
|
pos = next
|
|
}
|
|
}
|
|
|
|
break
|
|
}
|
|
|
|
case SINGLE_QUOTE:
|
|
case DOUBLE_QUOTE: {
|
|
quote = code === SINGLE_QUOTE ? "'" : '"'
|
|
next = pos
|
|
do {
|
|
escaped = false
|
|
next = css.indexOf(quote, next + 1)
|
|
if (next === -1) {
|
|
if (ignore || ignoreUnclosed) {
|
|
next = pos + 1
|
|
break
|
|
} else {
|
|
unclosed('string')
|
|
}
|
|
}
|
|
escapePos = next
|
|
while (css.charCodeAt(escapePos - 1) === BACKSLASH) {
|
|
escapePos -= 1
|
|
escaped = !escaped
|
|
}
|
|
} while (escaped)
|
|
|
|
currentToken = ['string', css.slice(pos, next + 1), pos, next]
|
|
pos = next
|
|
break
|
|
}
|
|
|
|
case AT: {
|
|
RE_AT_END.lastIndex = pos + 1
|
|
RE_AT_END.test(css)
|
|
if (RE_AT_END.lastIndex === 0) {
|
|
next = css.length - 1
|
|
} else {
|
|
next = RE_AT_END.lastIndex - 2
|
|
}
|
|
|
|
currentToken = ['at-word', css.slice(pos, next + 1), pos, next]
|
|
|
|
pos = next
|
|
break
|
|
}
|
|
|
|
case BACKSLASH: {
|
|
next = pos
|
|
escape = true
|
|
while (css.charCodeAt(next + 1) === BACKSLASH) {
|
|
next += 1
|
|
escape = !escape
|
|
}
|
|
code = css.charCodeAt(next + 1)
|
|
if (
|
|
escape &&
|
|
code !== SLASH &&
|
|
code !== SPACE &&
|
|
code !== NEWLINE &&
|
|
code !== TAB &&
|
|
code !== CR &&
|
|
code !== FEED
|
|
) {
|
|
next += 1
|
|
if (RE_HEX_ESCAPE.test(css.charAt(next))) {
|
|
while (RE_HEX_ESCAPE.test(css.charAt(next + 1))) {
|
|
next += 1
|
|
}
|
|
if (css.charCodeAt(next + 1) === SPACE) {
|
|
next += 1
|
|
}
|
|
}
|
|
}
|
|
|
|
currentToken = ['word', css.slice(pos, next + 1), pos, next]
|
|
|
|
pos = next
|
|
break
|
|
}
|
|
|
|
default: {
|
|
if (code === SLASH && css.charCodeAt(pos + 1) === ASTERISK) {
|
|
next = css.indexOf('*/', pos + 2) + 1
|
|
if (next === 0) {
|
|
if (ignore || ignoreUnclosed) {
|
|
next = css.length
|
|
} else {
|
|
unclosed('comment')
|
|
}
|
|
}
|
|
|
|
currentToken = ['comment', css.slice(pos, next + 1), pos, next]
|
|
pos = next
|
|
} else {
|
|
RE_WORD_END.lastIndex = pos + 1
|
|
RE_WORD_END.test(css)
|
|
if (RE_WORD_END.lastIndex === 0) {
|
|
next = css.length - 1
|
|
} else {
|
|
next = RE_WORD_END.lastIndex - 2
|
|
}
|
|
|
|
currentToken = ['word', css.slice(pos, next + 1), pos, next]
|
|
buffer.push(currentToken)
|
|
pos = next
|
|
}
|
|
|
|
break
|
|
}
|
|
}
|
|
|
|
pos++
|
|
return currentToken
|
|
}
|
|
|
|
function back(token) {
|
|
returned.push(token)
|
|
}
|
|
|
|
return {
|
|
back,
|
|
nextToken,
|
|
endOfFile,
|
|
position
|
|
}
|
|
}
|