first
This commit is contained in:
129
node_modules/@babel/eslint-parser/lib/convert/convertAST.cjs
generated
vendored
Normal file
129
node_modules/@babel/eslint-parser/lib/convert/convertAST.cjs
generated
vendored
Normal file
@ -0,0 +1,129 @@
|
||||
const ESLINT_VERSION = require("../utils/eslint-version.cjs");
|
||||
function* it(children) {
|
||||
if (Array.isArray(children)) yield* children;else yield children;
|
||||
}
|
||||
function traverse(node, visitorKeys, visitor) {
|
||||
const {
|
||||
type
|
||||
} = node;
|
||||
if (!type) return;
|
||||
const keys = visitorKeys[type];
|
||||
if (!keys) return;
|
||||
for (const key of keys) {
|
||||
for (const child of it(node[key])) {
|
||||
if (child && typeof child === "object") {
|
||||
visitor.enter(child);
|
||||
traverse(child, visitorKeys, visitor);
|
||||
visitor.exit(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const convertNodesVisitor = {
|
||||
enter(node) {
|
||||
if (node.innerComments) {
|
||||
delete node.innerComments;
|
||||
}
|
||||
if (node.trailingComments) {
|
||||
delete node.trailingComments;
|
||||
}
|
||||
if (node.leadingComments) {
|
||||
delete node.leadingComments;
|
||||
}
|
||||
},
|
||||
exit(node) {
|
||||
if (node.extra) {
|
||||
delete node.extra;
|
||||
}
|
||||
if (node.loc.identifierName) {
|
||||
delete node.loc.identifierName;
|
||||
}
|
||||
if (node.type === "TypeParameter") {
|
||||
node.type = "Identifier";
|
||||
node.typeAnnotation = node.bound;
|
||||
delete node.bound;
|
||||
}
|
||||
if (node.type === "QualifiedTypeIdentifier") {
|
||||
delete node.id;
|
||||
}
|
||||
if (node.type === "ObjectTypeProperty") {
|
||||
delete node.key;
|
||||
}
|
||||
if (node.type === "ObjectTypeIndexer") {
|
||||
delete node.id;
|
||||
}
|
||||
if (node.type === "FunctionTypeParam") {
|
||||
delete node.name;
|
||||
}
|
||||
if (node.type === "ImportDeclaration") {
|
||||
delete node.isType;
|
||||
}
|
||||
if (node.type === "TemplateLiteral") {
|
||||
for (let i = 0; i < node.quasis.length; i++) {
|
||||
const q = node.quasis[i];
|
||||
q.range[0] -= 1;
|
||||
if (q.tail) {
|
||||
q.range[1] += 1;
|
||||
} else {
|
||||
q.range[1] += 2;
|
||||
}
|
||||
q.loc.start.column -= 1;
|
||||
if (q.tail) {
|
||||
q.loc.end.column += 1;
|
||||
} else {
|
||||
q.loc.end.column += 2;
|
||||
}
|
||||
if (ESLINT_VERSION >= 8) {
|
||||
q.start -= 1;
|
||||
if (q.tail) {
|
||||
q.end += 1;
|
||||
} else {
|
||||
q.end += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
function convertNodes(ast, visitorKeys) {
|
||||
traverse(ast, visitorKeys, convertNodesVisitor);
|
||||
}
|
||||
function convertProgramNode(ast) {
|
||||
ast.type = "Program";
|
||||
ast.sourceType = ast.program.sourceType;
|
||||
ast.body = ast.program.body;
|
||||
delete ast.program;
|
||||
delete ast.errors;
|
||||
if (ast.comments.length) {
|
||||
const lastComment = ast.comments[ast.comments.length - 1];
|
||||
if (ast.tokens.length) {
|
||||
const lastToken = ast.tokens[ast.tokens.length - 1];
|
||||
if (lastComment.end > lastToken.end) {
|
||||
ast.range[1] = lastToken.end;
|
||||
ast.loc.end.line = lastToken.loc.end.line;
|
||||
ast.loc.end.column = lastToken.loc.end.column;
|
||||
if (ESLINT_VERSION >= 8) {
|
||||
ast.end = lastToken.end;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!ast.tokens.length) {
|
||||
ast.loc.start.line = 1;
|
||||
ast.loc.end.line = 1;
|
||||
}
|
||||
}
|
||||
if (ast.body && ast.body.length > 0) {
|
||||
ast.loc.start.line = ast.body[0].loc.start.line;
|
||||
ast.range[0] = ast.body[0].start;
|
||||
if (ESLINT_VERSION >= 8) {
|
||||
ast.start = ast.body[0].start;
|
||||
}
|
||||
}
|
||||
}
|
||||
module.exports = function convertAST(ast, visitorKeys) {
|
||||
convertNodes(ast, visitorKeys);
|
||||
convertProgramNode(ast);
|
||||
};
|
||||
|
||||
//# sourceMappingURL=convertAST.cjs.map
|
1
node_modules/@babel/eslint-parser/lib/convert/convertAST.cjs.map
generated
vendored
Normal file
1
node_modules/@babel/eslint-parser/lib/convert/convertAST.cjs.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
14
node_modules/@babel/eslint-parser/lib/convert/convertComments.cjs
generated
vendored
Normal file
14
node_modules/@babel/eslint-parser/lib/convert/convertComments.cjs
generated
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
module.exports = function convertComments(comments) {
|
||||
for (const comment of comments) {
|
||||
if (comment.type === "CommentBlock") {
|
||||
comment.type = "Block";
|
||||
} else if (comment.type === "CommentLine") {
|
||||
comment.type = "Line";
|
||||
}
|
||||
if (!comment.range) {
|
||||
comment.range = [comment.start, comment.end];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//# sourceMappingURL=convertComments.cjs.map
|
1
node_modules/@babel/eslint-parser/lib/convert/convertComments.cjs.map
generated
vendored
Normal file
1
node_modules/@babel/eslint-parser/lib/convert/convertComments.cjs.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"names":["module","exports","convertComments","comments","comment","type","range","start","end"],"sources":["../../src/convert/convertComments.cjs"],"sourcesContent":["module.exports = function convertComments(comments) {\n for (const comment of comments) {\n if (comment.type === \"CommentBlock\") {\n comment.type = \"Block\";\n } else if (comment.type === \"CommentLine\") {\n comment.type = \"Line\";\n }\n // sometimes comments don't get ranges computed,\n // even with options.ranges === true\n if (!comment.range) {\n comment.range = [comment.start, comment.end];\n }\n }\n};\n"],"mappings":"AAAAA,MAAM,CAACC,OAAO,GAAG,SAASC,eAAeA,CAACC,QAAQ,EAAE;EAClD,KAAK,MAAMC,OAAO,IAAID,QAAQ,EAAE;IAC9B,IAAIC,OAAO,CAACC,IAAI,KAAK,cAAc,EAAE;MACnCD,OAAO,CAACC,IAAI,GAAG,OAAO;IACxB,CAAC,MAAM,IAAID,OAAO,CAACC,IAAI,KAAK,aAAa,EAAE;MACzCD,OAAO,CAACC,IAAI,GAAG,MAAM;IACvB;IAGA,IAAI,CAACD,OAAO,CAACE,KAAK,EAAE;MAClBF,OAAO,CAACE,KAAK,GAAG,CAACF,OAAO,CAACG,KAAK,EAAEH,OAAO,CAACI,GAAG,CAAC;IAC9C;EACF;AACF,CAAC"}
|
159
node_modules/@babel/eslint-parser/lib/convert/convertTokens.cjs
generated
vendored
Normal file
159
node_modules/@babel/eslint-parser/lib/convert/convertTokens.cjs
generated
vendored
Normal file
@ -0,0 +1,159 @@
|
||||
const ESLINT_VERSION = require("../utils/eslint-version.cjs");
|
||||
function convertTemplateType(tokens, tl) {
|
||||
let curlyBrace = null;
|
||||
let templateTokens = [];
|
||||
const result = [];
|
||||
function addTemplateType() {
|
||||
const start = templateTokens[0];
|
||||
const end = templateTokens[templateTokens.length - 1];
|
||||
const value = templateTokens.reduce((result, token) => {
|
||||
if (token.value) {
|
||||
result += token.value;
|
||||
} else if (token.type.label !== tl.template) {
|
||||
result += token.type.label;
|
||||
}
|
||||
return result;
|
||||
}, "");
|
||||
result.push({
|
||||
type: "Template",
|
||||
value: value,
|
||||
start: start.start,
|
||||
end: end.end,
|
||||
loc: {
|
||||
start: start.loc.start,
|
||||
end: end.loc.end
|
||||
}
|
||||
});
|
||||
templateTokens = [];
|
||||
}
|
||||
tokens.forEach(token => {
|
||||
switch (token.type.label) {
|
||||
case tl.backQuote:
|
||||
if (curlyBrace) {
|
||||
result.push(curlyBrace);
|
||||
curlyBrace = null;
|
||||
}
|
||||
templateTokens.push(token);
|
||||
if (templateTokens.length > 1) {
|
||||
addTemplateType();
|
||||
}
|
||||
break;
|
||||
case tl.dollarBraceL:
|
||||
templateTokens.push(token);
|
||||
addTemplateType();
|
||||
break;
|
||||
case tl.braceR:
|
||||
if (curlyBrace) {
|
||||
result.push(curlyBrace);
|
||||
}
|
||||
curlyBrace = token;
|
||||
break;
|
||||
case tl.template:
|
||||
if (curlyBrace) {
|
||||
templateTokens.push(curlyBrace);
|
||||
curlyBrace = null;
|
||||
}
|
||||
templateTokens.push(token);
|
||||
break;
|
||||
default:
|
||||
if (curlyBrace) {
|
||||
result.push(curlyBrace);
|
||||
curlyBrace = null;
|
||||
}
|
||||
result.push(token);
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
function convertToken(token, source, tl) {
|
||||
const {
|
||||
type
|
||||
} = token;
|
||||
const {
|
||||
label
|
||||
} = type;
|
||||
token.range = [token.start, token.end];
|
||||
if (label === tl.name) {
|
||||
if (token.value === "static") {
|
||||
token.type = "Keyword";
|
||||
} else {
|
||||
token.type = "Identifier";
|
||||
}
|
||||
} else if (label === tl.semi || label === tl.comma || label === tl.parenL || label === tl.parenR || label === tl.braceL || label === tl.braceR || label === tl.slash || label === tl.dot || label === tl.bracketL || label === tl.bracketR || label === tl.ellipsis || label === tl.arrow || label === tl.pipeline || label === tl.star || label === tl.incDec || label === tl.colon || label === tl.question || label === tl.template || label === tl.backQuote || label === tl.dollarBraceL || label === tl.at || label === tl.logicalOR || label === tl.logicalAND || label === tl.nullishCoalescing || label === tl.bitwiseOR || label === tl.bitwiseXOR || label === tl.bitwiseAND || label === tl.equality || label === tl.relational || label === tl.bitShift || label === tl.plusMin || label === tl.modulo || label === tl.exponent || label === tl.bang || label === tl.tilde || label === tl.doubleColon || label === tl.hash || label === tl.questionDot || label === tl.braceHashL || label === tl.braceBarL || label === tl.braceBarR || label === tl.bracketHashL || label === tl.bracketBarL || label === tl.bracketBarR || label === tl.doubleCaret || label === tl.doubleAt || type.isAssign) {
|
||||
var _token$value;
|
||||
token.type = "Punctuator";
|
||||
(_token$value = token.value) != null ? _token$value : token.value = label;
|
||||
} else if (label === tl.jsxTagStart) {
|
||||
token.type = "Punctuator";
|
||||
token.value = "<";
|
||||
} else if (label === tl.jsxTagEnd) {
|
||||
token.type = "Punctuator";
|
||||
token.value = ">";
|
||||
} else if (label === tl.jsxName) {
|
||||
token.type = "JSXIdentifier";
|
||||
} else if (label === tl.jsxText) {
|
||||
token.type = "JSXText";
|
||||
} else if (type.keyword === "null") {
|
||||
token.type = "Null";
|
||||
} else if (type.keyword === "false" || type.keyword === "true") {
|
||||
token.type = "Boolean";
|
||||
} else if (type.keyword) {
|
||||
token.type = "Keyword";
|
||||
} else if (label === tl.num) {
|
||||
token.type = "Numeric";
|
||||
token.value = source.slice(token.start, token.end);
|
||||
} else if (label === tl.string) {
|
||||
token.type = "String";
|
||||
token.value = source.slice(token.start, token.end);
|
||||
} else if (label === tl.regexp) {
|
||||
token.type = "RegularExpression";
|
||||
const value = token.value;
|
||||
token.regex = {
|
||||
pattern: value.pattern,
|
||||
flags: value.flags
|
||||
};
|
||||
token.value = `/${value.pattern}/${value.flags}`;
|
||||
} else if (label === tl.bigint) {
|
||||
token.type = "Numeric";
|
||||
token.value = `${token.value}n`;
|
||||
} else if (label === tl.privateName) {
|
||||
token.type = "PrivateIdentifier";
|
||||
} else if (label === tl.templateNonTail || label === tl.templateTail) {
|
||||
token.type = "Template";
|
||||
}
|
||||
if (typeof token.type !== "string") {
|
||||
delete token.type.rightAssociative;
|
||||
}
|
||||
}
|
||||
module.exports = function convertTokens(tokens, code, tl) {
|
||||
const result = [];
|
||||
const templateTypeMergedTokens = convertTemplateType(tokens, tl);
|
||||
for (let i = 0, {
|
||||
length
|
||||
} = templateTypeMergedTokens; i < length - 1; i++) {
|
||||
const token = templateTypeMergedTokens[i];
|
||||
const tokenType = token.type;
|
||||
if (tokenType === "CommentLine" || tokenType === "CommentBlock") {
|
||||
continue;
|
||||
}
|
||||
{
|
||||
if (ESLINT_VERSION >= 8 && i + 1 < length && tokenType.label === tl.hash) {
|
||||
const nextToken = templateTypeMergedTokens[i + 1];
|
||||
if (nextToken.type.label === tl.name && token.end === nextToken.start) {
|
||||
i++;
|
||||
nextToken.type = "PrivateIdentifier";
|
||||
nextToken.start -= 1;
|
||||
nextToken.loc.start.column -= 1;
|
||||
nextToken.range = [nextToken.start, nextToken.end];
|
||||
result.push(nextToken);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
convertToken(token, code, tl);
|
||||
result.push(token);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
//# sourceMappingURL=convertTokens.cjs.map
|
1
node_modules/@babel/eslint-parser/lib/convert/convertTokens.cjs.map
generated
vendored
Normal file
1
node_modules/@babel/eslint-parser/lib/convert/convertTokens.cjs.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
18
node_modules/@babel/eslint-parser/lib/convert/index.cjs
generated
vendored
Normal file
18
node_modules/@babel/eslint-parser/lib/convert/index.cjs
generated
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
const convertTokens = require("./convertTokens.cjs");
|
||||
const convertComments = require("./convertComments.cjs");
|
||||
const convertAST = require("./convertAST.cjs");
|
||||
exports.ast = function convert(ast, code, tokLabels, visitorKeys) {
|
||||
ast.tokens = convertTokens(ast.tokens, code, tokLabels);
|
||||
convertComments(ast.comments);
|
||||
convertAST(ast, visitorKeys);
|
||||
return ast;
|
||||
};
|
||||
exports.error = function convertError(err) {
|
||||
if (err instanceof SyntaxError) {
|
||||
err.lineNumber = err.loc.line;
|
||||
err.column = err.loc.column;
|
||||
}
|
||||
return err;
|
||||
};
|
||||
|
||||
//# sourceMappingURL=index.cjs.map
|
1
node_modules/@babel/eslint-parser/lib/convert/index.cjs.map
generated
vendored
Normal file
1
node_modules/@babel/eslint-parser/lib/convert/index.cjs.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"names":["convertTokens","require","convertComments","convertAST","exports","ast","convert","code","tokLabels","visitorKeys","tokens","comments","error","convertError","err","SyntaxError","lineNumber","loc","line","column"],"sources":["../../src/convert/index.cjs"],"sourcesContent":["const convertTokens = require(\"./convertTokens.cjs\");\nconst convertComments = require(\"./convertComments.cjs\");\nconst convertAST = require(\"./convertAST.cjs\");\n\nexports.ast = function convert(ast, code, tokLabels, visitorKeys) {\n ast.tokens = convertTokens(ast.tokens, code, tokLabels);\n convertComments(ast.comments);\n convertAST(ast, visitorKeys);\n return ast;\n};\n\nexports.error = function convertError(err) {\n if (err instanceof SyntaxError) {\n err.lineNumber = err.loc.line;\n err.column = err.loc.column;\n }\n return err;\n};\n"],"mappings":"AAAA,MAAMA,aAAa,GAAGC,OAAO,CAAC,qBAAqB,CAAC;AACpD,MAAMC,eAAe,GAAGD,OAAO,CAAC,uBAAuB,CAAC;AACxD,MAAME,UAAU,GAAGF,OAAO,CAAC,kBAAkB,CAAC;AAE9CG,OAAO,CAACC,GAAG,GAAG,SAASC,OAAOA,CAACD,GAAG,EAAEE,IAAI,EAAEC,SAAS,EAAEC,WAAW,EAAE;EAChEJ,GAAG,CAACK,MAAM,GAAGV,aAAa,CAACK,GAAG,CAACK,MAAM,EAAEH,IAAI,EAAEC,SAAS,CAAC;EACvDN,eAAe,CAACG,GAAG,CAACM,QAAQ,CAAC;EAC7BR,UAAU,CAACE,GAAG,EAAEI,WAAW,CAAC;EAC5B,OAAOJ,GAAG;AACZ,CAAC;AAEDD,OAAO,CAACQ,KAAK,GAAG,SAASC,YAAYA,CAACC,GAAG,EAAE;EACzC,IAAIA,GAAG,YAAYC,WAAW,EAAE;IAC9BD,GAAG,CAACE,UAAU,GAAGF,GAAG,CAACG,GAAG,CAACC,IAAI;IAC7BJ,GAAG,CAACK,MAAM,GAAGL,GAAG,CAACG,GAAG,CAACE,MAAM;EAC7B;EACA,OAAOL,GAAG;AACZ,CAAC"}
|
Reference in New Issue
Block a user