format: prettify entire project
This commit is contained in:
241
node_modules/@babel/helper-string-parser/lib/index.js
generated
vendored
241
node_modules/@babel/helper-string-parser/lib/index.js
generated
vendored
@ -1,7 +1,7 @@
|
||||
"use strict";
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
Object.defineProperty(exports, '__esModule', {
|
||||
value: true,
|
||||
});
|
||||
exports.readCodePoint = readCodePoint;
|
||||
exports.readInt = readInt;
|
||||
@ -11,24 +11,23 @@ var _isDigit = function isDigit(code) {
|
||||
};
|
||||
const forbiddenNumericSeparatorSiblings = {
|
||||
decBinOct: new Set([46, 66, 69, 79, 95, 98, 101, 111]),
|
||||
hex: new Set([46, 88, 95, 120])
|
||||
hex: new Set([46, 88, 95, 120]),
|
||||
};
|
||||
const isAllowedNumericSeparatorSibling = {
|
||||
bin: ch => ch === 48 || ch === 49,
|
||||
oct: ch => ch >= 48 && ch <= 55,
|
||||
dec: ch => ch >= 48 && ch <= 57,
|
||||
hex: ch => ch >= 48 && ch <= 57 || ch >= 65 && ch <= 70 || ch >= 97 && ch <= 102
|
||||
bin: (ch) => ch === 48 || ch === 49,
|
||||
oct: (ch) => ch >= 48 && ch <= 55,
|
||||
dec: (ch) => ch >= 48 && ch <= 57,
|
||||
hex: (ch) =>
|
||||
(ch >= 48 && ch <= 57) || (ch >= 65 && ch <= 70) || (ch >= 97 && ch <= 102),
|
||||
};
|
||||
function readStringContents(type, input, pos, lineStart, curLine, errors) {
|
||||
const initialPos = pos;
|
||||
const initialLineStart = lineStart;
|
||||
const initialCurLine = curLine;
|
||||
let out = "";
|
||||
let out = '';
|
||||
let firstInvalidLoc = null;
|
||||
let chunkStart = pos;
|
||||
const {
|
||||
length
|
||||
} = input;
|
||||
const { length } = input;
|
||||
for (;;) {
|
||||
if (pos >= length) {
|
||||
errors.unterminated(initialPos, initialLineStart, initialCurLine);
|
||||
@ -42,29 +41,32 @@ function readStringContents(type, input, pos, lineStart, curLine, errors) {
|
||||
}
|
||||
if (ch === 92) {
|
||||
out += input.slice(chunkStart, pos);
|
||||
const res = readEscapedChar(input, pos, lineStart, curLine, type === "template", errors);
|
||||
const res = readEscapedChar(
|
||||
input,
|
||||
pos,
|
||||
lineStart,
|
||||
curLine,
|
||||
type === 'template',
|
||||
errors
|
||||
);
|
||||
if (res.ch === null && !firstInvalidLoc) {
|
||||
firstInvalidLoc = {
|
||||
pos,
|
||||
lineStart,
|
||||
curLine
|
||||
curLine,
|
||||
};
|
||||
} else {
|
||||
out += res.ch;
|
||||
}
|
||||
({
|
||||
pos,
|
||||
lineStart,
|
||||
curLine
|
||||
} = res);
|
||||
({ pos, lineStart, curLine } = res);
|
||||
chunkStart = pos;
|
||||
} else if (ch === 8232 || ch === 8233) {
|
||||
++pos;
|
||||
++curLine;
|
||||
lineStart = pos;
|
||||
} else if (ch === 10 || ch === 13) {
|
||||
if (type === "template") {
|
||||
out += input.slice(chunkStart, pos) + "\n";
|
||||
if (type === 'template') {
|
||||
out += input.slice(chunkStart, pos) + '\n';
|
||||
++pos;
|
||||
if (ch === 13 && input.charCodeAt(pos) === 10) {
|
||||
++pos;
|
||||
@ -84,56 +86,64 @@ function readStringContents(type, input, pos, lineStart, curLine, errors) {
|
||||
firstInvalidLoc,
|
||||
lineStart,
|
||||
curLine,
|
||||
containsInvalid: !!firstInvalidLoc
|
||||
containsInvalid: !!firstInvalidLoc,
|
||||
};
|
||||
}
|
||||
function isStringEnd(type, ch, input, pos) {
|
||||
if (type === "template") {
|
||||
return ch === 96 || ch === 36 && input.charCodeAt(pos + 1) === 123;
|
||||
if (type === 'template') {
|
||||
return ch === 96 || (ch === 36 && input.charCodeAt(pos + 1) === 123);
|
||||
}
|
||||
return ch === (type === "double" ? 34 : 39);
|
||||
return ch === (type === 'double' ? 34 : 39);
|
||||
}
|
||||
function readEscapedChar(input, pos, lineStart, curLine, inTemplate, errors) {
|
||||
const throwOnInvalid = !inTemplate;
|
||||
pos++;
|
||||
const res = ch => ({
|
||||
const res = (ch) => ({
|
||||
pos,
|
||||
ch,
|
||||
lineStart,
|
||||
curLine
|
||||
curLine,
|
||||
});
|
||||
const ch = input.charCodeAt(pos++);
|
||||
switch (ch) {
|
||||
case 110:
|
||||
return res("\n");
|
||||
return res('\n');
|
||||
case 114:
|
||||
return res("\r");
|
||||
case 120:
|
||||
{
|
||||
let code;
|
||||
({
|
||||
code,
|
||||
pos
|
||||
} = readHexChar(input, pos, lineStart, curLine, 2, false, throwOnInvalid, errors));
|
||||
return res(code === null ? null : String.fromCharCode(code));
|
||||
}
|
||||
case 117:
|
||||
{
|
||||
let code;
|
||||
({
|
||||
code,
|
||||
pos
|
||||
} = readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors));
|
||||
return res(code === null ? null : String.fromCodePoint(code));
|
||||
}
|
||||
return res('\r');
|
||||
case 120: {
|
||||
let code;
|
||||
({ code, pos } = readHexChar(
|
||||
input,
|
||||
pos,
|
||||
lineStart,
|
||||
curLine,
|
||||
2,
|
||||
false,
|
||||
throwOnInvalid,
|
||||
errors
|
||||
));
|
||||
return res(code === null ? null : String.fromCharCode(code));
|
||||
}
|
||||
case 117: {
|
||||
let code;
|
||||
({ code, pos } = readCodePoint(
|
||||
input,
|
||||
pos,
|
||||
lineStart,
|
||||
curLine,
|
||||
throwOnInvalid,
|
||||
errors
|
||||
));
|
||||
return res(code === null ? null : String.fromCodePoint(code));
|
||||
}
|
||||
case 116:
|
||||
return res("\t");
|
||||
return res('\t');
|
||||
case 98:
|
||||
return res("\b");
|
||||
return res('\b');
|
||||
case 118:
|
||||
return res("\u000b");
|
||||
return res('\u000b');
|
||||
case 102:
|
||||
return res("\f");
|
||||
return res('\f');
|
||||
case 13:
|
||||
if (input.charCodeAt(pos) === 10) {
|
||||
++pos;
|
||||
@ -143,7 +153,7 @@ function readEscapedChar(input, pos, lineStart, curLine, inTemplate, errors) {
|
||||
++curLine;
|
||||
case 8232:
|
||||
case 8233:
|
||||
return res("");
|
||||
return res('');
|
||||
case 56:
|
||||
case 57:
|
||||
if (inTemplate) {
|
||||
@ -163,7 +173,7 @@ function readEscapedChar(input, pos, lineStart, curLine, inTemplate, errors) {
|
||||
}
|
||||
pos += octalStr.length - 1;
|
||||
const next = input.charCodeAt(pos);
|
||||
if (octalStr !== "0" || next === 56 || next === 57) {
|
||||
if (octalStr !== '0' || next === 56 || next === 57) {
|
||||
if (inTemplate) {
|
||||
return res(null);
|
||||
} else {
|
||||
@ -175,13 +185,30 @@ function readEscapedChar(input, pos, lineStart, curLine, inTemplate, errors) {
|
||||
return res(String.fromCharCode(ch));
|
||||
}
|
||||
}
|
||||
function readHexChar(input, pos, lineStart, curLine, len, forceLen, throwOnInvalid, errors) {
|
||||
function readHexChar(
|
||||
input,
|
||||
pos,
|
||||
lineStart,
|
||||
curLine,
|
||||
len,
|
||||
forceLen,
|
||||
throwOnInvalid,
|
||||
errors
|
||||
) {
|
||||
const initialPos = pos;
|
||||
let n;
|
||||
({
|
||||
n,
|
||||
pos
|
||||
} = readInt(input, pos, lineStart, curLine, 16, len, forceLen, false, errors, !throwOnInvalid));
|
||||
({ n, pos } = readInt(
|
||||
input,
|
||||
pos,
|
||||
lineStart,
|
||||
curLine,
|
||||
16,
|
||||
len,
|
||||
forceLen,
|
||||
false,
|
||||
errors,
|
||||
!throwOnInvalid
|
||||
));
|
||||
if (n === null) {
|
||||
if (throwOnInvalid) {
|
||||
errors.invalidEscapeSequence(initialPos, lineStart, curLine);
|
||||
@ -191,32 +218,57 @@ function readHexChar(input, pos, lineStart, curLine, len, forceLen, throwOnInval
|
||||
}
|
||||
return {
|
||||
code: n,
|
||||
pos
|
||||
pos,
|
||||
};
|
||||
}
|
||||
function readInt(input, pos, lineStart, curLine, radix, len, forceLen, allowNumSeparator, errors, bailOnError) {
|
||||
function readInt(
|
||||
input,
|
||||
pos,
|
||||
lineStart,
|
||||
curLine,
|
||||
radix,
|
||||
len,
|
||||
forceLen,
|
||||
allowNumSeparator,
|
||||
errors,
|
||||
bailOnError
|
||||
) {
|
||||
const start = pos;
|
||||
const forbiddenSiblings = radix === 16 ? forbiddenNumericSeparatorSiblings.hex : forbiddenNumericSeparatorSiblings.decBinOct;
|
||||
const isAllowedSibling = radix === 16 ? isAllowedNumericSeparatorSibling.hex : radix === 10 ? isAllowedNumericSeparatorSibling.dec : radix === 8 ? isAllowedNumericSeparatorSibling.oct : isAllowedNumericSeparatorSibling.bin;
|
||||
const forbiddenSiblings =
|
||||
radix === 16 ?
|
||||
forbiddenNumericSeparatorSiblings.hex
|
||||
: forbiddenNumericSeparatorSiblings.decBinOct;
|
||||
const isAllowedSibling =
|
||||
radix === 16 ? isAllowedNumericSeparatorSibling.hex
|
||||
: radix === 10 ? isAllowedNumericSeparatorSibling.dec
|
||||
: radix === 8 ? isAllowedNumericSeparatorSibling.oct
|
||||
: isAllowedNumericSeparatorSibling.bin;
|
||||
let invalid = false;
|
||||
let total = 0;
|
||||
for (let i = 0, e = len == null ? Infinity : len; i < e; ++i) {
|
||||
const code = input.charCodeAt(pos);
|
||||
let val;
|
||||
if (code === 95 && allowNumSeparator !== "bail") {
|
||||
if (code === 95 && allowNumSeparator !== 'bail') {
|
||||
const prev = input.charCodeAt(pos - 1);
|
||||
const next = input.charCodeAt(pos + 1);
|
||||
if (!allowNumSeparator) {
|
||||
if (bailOnError) return {
|
||||
n: null,
|
||||
pos
|
||||
};
|
||||
if (bailOnError)
|
||||
return {
|
||||
n: null,
|
||||
pos,
|
||||
};
|
||||
errors.numericSeparatorInEscapeSequence(pos, lineStart, curLine);
|
||||
} else if (Number.isNaN(next) || !isAllowedSibling(next) || forbiddenSiblings.has(prev) || forbiddenSiblings.has(next)) {
|
||||
if (bailOnError) return {
|
||||
n: null,
|
||||
pos
|
||||
};
|
||||
} else if (
|
||||
Number.isNaN(next) ||
|
||||
!isAllowedSibling(next) ||
|
||||
forbiddenSiblings.has(prev) ||
|
||||
forbiddenSiblings.has(next)
|
||||
) {
|
||||
if (bailOnError)
|
||||
return {
|
||||
n: null,
|
||||
pos,
|
||||
};
|
||||
errors.unexpectedNumericSeparator(pos, lineStart, curLine);
|
||||
}
|
||||
++pos;
|
||||
@ -235,9 +287,12 @@ function readInt(input, pos, lineStart, curLine, radix, len, forceLen, allowNumS
|
||||
if (val <= 9 && bailOnError) {
|
||||
return {
|
||||
n: null,
|
||||
pos
|
||||
pos,
|
||||
};
|
||||
} else if (val <= 9 && errors.invalidDigit(pos, lineStart, curLine, radix)) {
|
||||
} else if (
|
||||
val <= 9 &&
|
||||
errors.invalidDigit(pos, lineStart, curLine, radix)
|
||||
) {
|
||||
val = 0;
|
||||
} else if (forceLen) {
|
||||
val = 0;
|
||||
@ -249,15 +304,15 @@ function readInt(input, pos, lineStart, curLine, radix, len, forceLen, allowNumS
|
||||
++pos;
|
||||
total = total * radix + val;
|
||||
}
|
||||
if (pos === start || len != null && pos - start !== len || invalid) {
|
||||
if (pos === start || (len != null && pos - start !== len) || invalid) {
|
||||
return {
|
||||
n: null,
|
||||
pos
|
||||
pos,
|
||||
};
|
||||
}
|
||||
return {
|
||||
n: total,
|
||||
pos
|
||||
pos,
|
||||
};
|
||||
}
|
||||
function readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors) {
|
||||
@ -265,10 +320,16 @@ function readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors) {
|
||||
let code;
|
||||
if (ch === 123) {
|
||||
++pos;
|
||||
({
|
||||
code,
|
||||
pos
|
||||
} = readHexChar(input, pos, lineStart, curLine, input.indexOf("}", pos) - pos, true, throwOnInvalid, errors));
|
||||
({ code, pos } = readHexChar(
|
||||
input,
|
||||
pos,
|
||||
lineStart,
|
||||
curLine,
|
||||
input.indexOf('}', pos) - pos,
|
||||
true,
|
||||
throwOnInvalid,
|
||||
errors
|
||||
));
|
||||
++pos;
|
||||
if (code !== null && code > 0x10ffff) {
|
||||
if (throwOnInvalid) {
|
||||
@ -276,19 +337,25 @@ function readCodePoint(input, pos, lineStart, curLine, throwOnInvalid, errors) {
|
||||
} else {
|
||||
return {
|
||||
code: null,
|
||||
pos
|
||||
pos,
|
||||
};
|
||||
}
|
||||
}
|
||||
} else {
|
||||
({
|
||||
code,
|
||||
pos
|
||||
} = readHexChar(input, pos, lineStart, curLine, 4, false, throwOnInvalid, errors));
|
||||
({ code, pos } = readHexChar(
|
||||
input,
|
||||
pos,
|
||||
lineStart,
|
||||
curLine,
|
||||
4,
|
||||
false,
|
||||
throwOnInvalid,
|
||||
errors
|
||||
));
|
||||
}
|
||||
return {
|
||||
code,
|
||||
pos
|
||||
pos,
|
||||
};
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user