Current Dev State

This commit is contained in:
Tim Lorsbach
2025-06-23 20:13:54 +02:00
parent b4f9bb277d
commit ded50edaa2
22617 changed files with 4345095 additions and 174 deletions

View File

@ -0,0 +1,98 @@
/**
* @fileoverview The AST node types produced by the parser.
* @author Nicholas C. Zakas
*/
"use strict";
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
// None!
//------------------------------------------------------------------------------
// Public
//------------------------------------------------------------------------------
module.exports = {
AssignmentExpression: "AssignmentExpression",
AssignmentPattern: "AssignmentPattern",
ArrayExpression: "ArrayExpression",
ArrayPattern: "ArrayPattern",
ArrowFunctionExpression: "ArrowFunctionExpression",
AwaitExpression: "AwaitExpression",
BlockStatement: "BlockStatement",
BinaryExpression: "BinaryExpression",
BreakStatement: "BreakStatement",
CallExpression: "CallExpression",
CatchClause: "CatchClause",
ClassBody: "ClassBody",
ClassDeclaration: "ClassDeclaration",
ClassExpression: "ClassExpression",
ConditionalExpression: "ConditionalExpression",
ContinueStatement: "ContinueStatement",
DoWhileStatement: "DoWhileStatement",
DebuggerStatement: "DebuggerStatement",
EmptyStatement: "EmptyStatement",
ExperimentalRestProperty: "ExperimentalRestProperty",
ExperimentalSpreadProperty: "ExperimentalSpreadProperty",
ExpressionStatement: "ExpressionStatement",
ForStatement: "ForStatement",
ForInStatement: "ForInStatement",
ForOfStatement: "ForOfStatement",
FunctionDeclaration: "FunctionDeclaration",
FunctionExpression: "FunctionExpression",
Identifier: "Identifier",
IfStatement: "IfStatement",
Literal: "Literal",
LabeledStatement: "LabeledStatement",
LogicalExpression: "LogicalExpression",
MemberExpression: "MemberExpression",
MetaProperty: "MetaProperty",
MethodDefinition: "MethodDefinition",
NewExpression: "NewExpression",
ObjectExpression: "ObjectExpression",
ObjectPattern: "ObjectPattern",
Program: "Program",
Property: "Property",
RestElement: "RestElement",
ReturnStatement: "ReturnStatement",
SequenceExpression: "SequenceExpression",
SpreadElement: "SpreadElement",
Super: "Super",
SwitchCase: "SwitchCase",
SwitchStatement: "SwitchStatement",
TaggedTemplateExpression: "TaggedTemplateExpression",
TemplateElement: "TemplateElement",
TemplateLiteral: "TemplateLiteral",
ThisExpression: "ThisExpression",
ThrowStatement: "ThrowStatement",
TryStatement: "TryStatement",
UnaryExpression: "UnaryExpression",
UpdateExpression: "UpdateExpression",
VariableDeclaration: "VariableDeclaration",
VariableDeclarator: "VariableDeclarator",
WhileStatement: "WhileStatement",
WithStatement: "WithStatement",
YieldExpression: "YieldExpression",
JSXIdentifier: "JSXIdentifier",
JSXNamespacedName: "JSXNamespacedName",
JSXMemberExpression: "JSXMemberExpression",
JSXEmptyExpression: "JSXEmptyExpression",
JSXExpressionContainer: "JSXExpressionContainer",
JSXElement: "JSXElement",
JSXClosingElement: "JSXClosingElement",
JSXOpeningElement: "JSXOpeningElement",
JSXAttribute: "JSXAttribute",
JSXSpreadAttribute: "JSXSpreadAttribute",
JSXText: "JSXText",
ExportDefaultDeclaration: "ExportDefaultDeclaration",
ExportNamedDeclaration: "ExportNamedDeclaration",
ExportAllDeclaration: "ExportAllDeclaration",
ExportSpecifier: "ExportSpecifier",
ImportDeclaration: "ImportDeclaration",
ImportSpecifier: "ImportSpecifier",
ImportDefaultSpecifier: "ImportDefaultSpecifier",
ImportNamespaceSpecifier: "ImportNamespaceSpecifier"
};

View File

@ -0,0 +1,175 @@
/**
* @fileoverview Attaches comments to the AST.
* @author Nicholas C. Zakas
*/
"use strict";
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
var astNodeTypes = require("./ast-node-types");
//------------------------------------------------------------------------------
// Private
//------------------------------------------------------------------------------
var extra = {
trailingComments: [],
leadingComments: [],
bottomRightStack: [],
previousNode: null
};
//------------------------------------------------------------------------------
// Public
//------------------------------------------------------------------------------
module.exports = {
reset: function() {
extra.trailingComments = [];
extra.leadingComments = [];
extra.bottomRightStack = [];
extra.previousNode = null;
},
addComment: function(comment) {
extra.trailingComments.push(comment);
extra.leadingComments.push(comment);
},
processComment: function(node) {
var lastChild,
trailingComments,
i,
j;
if (node.type === astNodeTypes.Program) {
if (node.body.length > 0) {
return;
}
}
if (extra.trailingComments.length > 0) {
/*
* If the first comment in trailingComments comes after the
* current node, then we're good - all comments in the array will
* come after the node and so it's safe to add then as official
* trailingComments.
*/
if (extra.trailingComments[0].range[0] >= node.range[1]) {
trailingComments = extra.trailingComments;
extra.trailingComments = [];
} else {
/*
* Otherwise, if the first comment doesn't come after the
* current node, that means we have a mix of leading and trailing
* comments in the array and that leadingComments contains the
* same items as trailingComments. Reset trailingComments to
* zero items and we'll handle this by evaluating leadingComments
* later.
*/
extra.trailingComments.length = 0;
}
} else {
if (extra.bottomRightStack.length > 0 &&
extra.bottomRightStack[extra.bottomRightStack.length - 1].trailingComments &&
extra.bottomRightStack[extra.bottomRightStack.length - 1].trailingComments[0].range[0] >= node.range[1]) {
trailingComments = extra.bottomRightStack[extra.bottomRightStack.length - 1].trailingComments;
delete extra.bottomRightStack[extra.bottomRightStack.length - 1].trailingComments;
}
}
// Eating the stack.
while (extra.bottomRightStack.length > 0 && extra.bottomRightStack[extra.bottomRightStack.length - 1].range[0] >= node.range[0]) {
lastChild = extra.bottomRightStack.pop();
}
if (lastChild) {
if (lastChild.leadingComments) {
if (lastChild.leadingComments[lastChild.leadingComments.length - 1].range[1] <= node.range[0]) {
node.leadingComments = lastChild.leadingComments;
delete lastChild.leadingComments;
} else {
// A leading comment for an anonymous class had been stolen by its first MethodDefinition,
// so this takes back the leading comment.
// See Also: https://github.com/eslint/espree/issues/158
for (i = lastChild.leadingComments.length - 2; i >= 0; --i) {
if (lastChild.leadingComments[i].range[1] <= node.range[0]) {
node.leadingComments = lastChild.leadingComments.splice(0, i + 1);
break;
}
}
}
}
} else if (extra.leadingComments.length > 0) {
if (extra.leadingComments[extra.leadingComments.length - 1].range[1] <= node.range[0]) {
if (extra.previousNode) {
for (j = 0; j < extra.leadingComments.length; j++) {
if (extra.leadingComments[j].end < extra.previousNode.end) {
extra.leadingComments.splice(j, 1);
j--;
}
}
}
if (extra.leadingComments.length > 0) {
node.leadingComments = extra.leadingComments;
extra.leadingComments = [];
}
} else {
// https://github.com/eslint/espree/issues/2
/*
* In special cases, such as return (without a value) and
* debugger, all comments will end up as leadingComments and
* will otherwise be eliminated. This extra step runs when the
* bottomRightStack is empty and there are comments left
* in leadingComments.
*
* This loop figures out the stopping point between the actual
* leading and trailing comments by finding the location of the
* first comment that comes after the given node.
*/
for (i = 0; i < extra.leadingComments.length; i++) {
if (extra.leadingComments[i].range[1] > node.range[0]) {
break;
}
}
/*
* Split the array based on the location of the first comment
* that comes after the node. Keep in mind that this could
* result in an empty array, and if so, the array must be
* deleted.
*/
node.leadingComments = extra.leadingComments.slice(0, i);
if (node.leadingComments.length === 0) {
delete node.leadingComments;
}
/*
* Similarly, trailing comments are attached later. The variable
* must be reset to null if there are no trailing comments.
*/
trailingComments = extra.leadingComments.slice(i);
if (trailingComments.length === 0) {
trailingComments = null;
}
}
}
extra.previousNode = node;
if (trailingComments) {
node.trailingComments = trailingComments;
}
extra.bottomRightStack.push(node);
}
};

32
static/js/ketcher2/node_modules/espree/lib/features.js generated vendored Normal file
View File

@ -0,0 +1,32 @@
/**
* @fileoverview The list of feature flags supported by the parser and their default
* settings.
* @author Nicholas C. Zakas
*/
"use strict";
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
// None!
//------------------------------------------------------------------------------
// Public
//------------------------------------------------------------------------------
module.exports = {
// React JSX parsing
jsx: false,
// allow return statement in global scope
globalReturn: false,
// allow implied strict mode
impliedStrict: false,
// allow experimental object rest/spread
experimentalObjectRestSpread: false
};

View File

@ -0,0 +1,258 @@
/**
* @fileoverview Translates tokens between Acorn format and Esprima format.
* @author Nicholas C. Zakas
*/
/* eslint no-underscore-dangle: 0 */
"use strict";
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
// none!
//------------------------------------------------------------------------------
// Private
//------------------------------------------------------------------------------
// Esprima Token Types
var Token = {
Boolean: "Boolean",
EOF: "<end>",
Identifier: "Identifier",
Keyword: "Keyword",
Null: "Null",
Numeric: "Numeric",
Punctuator: "Punctuator",
String: "String",
RegularExpression: "RegularExpression",
Template: "Template",
JSXIdentifier: "JSXIdentifier",
JSXText: "JSXText"
};
/**
* Converts part of a template into an Esprima token.
* @param {AcornToken[]} tokens The Acorn tokens representing the template.
* @param {string} code The source code.
* @returns {EsprimaToken} The Esprima equivalent of the template token.
* @private
*/
function convertTemplatePart(tokens, code) {
var firstToken = tokens[0],
lastTemplateToken = tokens[tokens.length - 1];
var token = {
type: Token.Template,
value: code.slice(firstToken.start, lastTemplateToken.end)
};
if (firstToken.loc) {
token.loc = {
start: firstToken.loc.start,
end: lastTemplateToken.loc.end
};
}
if (firstToken.range) {
token.start = firstToken.range[0];
token.end = lastTemplateToken.range[1];
token.range = [token.start, token.end];
}
return token;
}
/**
* Contains logic to translate Acorn tokens into Esprima tokens.
* @param {Object} acornTokTypes The Acorn token types.
* @param {string} code The source code Acorn is parsing. This is necessary
* to correct the "value" property of some tokens.
* @constructor
*/
function TokenTranslator(acornTokTypes, code) {
// token types
this._acornTokTypes = acornTokTypes;
// token buffer for templates
this._tokens = [];
// track the last curly brace
this._curlyBrace = null;
// the source code
this._code = code;
}
TokenTranslator.prototype = {
constructor: TokenTranslator,
/**
* Translates a single Esprima token to a single Acorn token. This may be
* inaccurate due to how templates are handled differently in Esprima and
* Acorn, but should be accurate for all other tokens.
* @param {AcornToken} token The Acorn token to translate.
* @param {Object} extra Espree extra object.
* @returns {EsprimaToken} The Esprima version of the token.
*/
translate: function(token, extra) {
var type = token.type,
tt = this._acornTokTypes;
if (type === tt.name) {
token.type = Token.Identifier;
// TODO: See if this is an Acorn bug
if (token.value === "static") {
token.type = Token.Keyword;
}
if (extra.ecmaVersion > 5 && (token.value === "yield" || token.value === "let")) {
token.type = Token.Keyword;
}
} else if (type === tt.semi || type === tt.comma ||
type === tt.parenL || type === tt.parenR ||
type === tt.braceL || type === tt.braceR ||
type === tt.dot || type === tt.bracketL ||
type === tt.colon || type === tt.question ||
type === tt.bracketR || type === tt.ellipsis ||
type === tt.arrow || type === tt.jsxTagStart ||
type === tt.incDec || type === tt.starstar ||
type === tt.jsxTagEnd || type === tt.prefix ||
(type.binop && !type.keyword) ||
type.isAssign) {
token.type = Token.Punctuator;
token.value = this._code.slice(token.start, token.end);
} else if (type === tt.jsxName) {
token.type = Token.JSXIdentifier;
} else if (type.label === "jsxText" || type === tt.jsxAttrValueToken) {
token.type = Token.JSXText;
} else if (type.keyword) {
if (type.keyword === "true" || type.keyword === "false") {
token.type = Token.Boolean;
} else if (type.keyword === "null") {
token.type = Token.Null;
} else {
token.type = Token.Keyword;
}
} else if (type === tt.num) {
token.type = Token.Numeric;
token.value = this._code.slice(token.start, token.end);
} else if (type === tt.string) {
if (extra.jsxAttrValueToken) {
extra.jsxAttrValueToken = false;
token.type = Token.JSXText;
} else {
token.type = Token.String;
}
token.value = this._code.slice(token.start, token.end);
} else if (type === tt.regexp) {
token.type = Token.RegularExpression;
var value = token.value;
token.regex = {
flags: value.flags,
pattern: value.pattern
};
token.value = "/" + value.pattern + "/" + value.flags;
}
return token;
},
/**
* Function to call during Acorn's onToken handler.
* @param {AcornToken} token The Acorn token.
* @param {Object} extra The Espree extra object.
* @returns {void}
*/
onToken: function(token, extra) {
var that = this,
tt = this._acornTokTypes,
tokens = extra.tokens,
templateTokens = this._tokens;
/**
* Flushes the buffered template tokens and resets the template
* tracking.
* @returns {void}
* @private
*/
function translateTemplateTokens() {
tokens.push(convertTemplatePart(that._tokens, that._code));
that._tokens = [];
}
if (token.type === tt.eof) {
// might be one last curlyBrace
if (this._curlyBrace) {
tokens.push(this.translate(this._curlyBrace, extra));
}
return;
}
if (token.type === tt.backQuote) {
// if there's already a curly, it's not part of the template
if (this._curlyBrace) {
tokens.push(this.translate(this._curlyBrace, extra));
this._curlyBrace = null;
}
templateTokens.push(token);
// it's the end
if (templateTokens.length > 1) {
translateTemplateTokens();
}
return;
} else if (token.type === tt.dollarBraceL) {
templateTokens.push(token);
translateTemplateTokens();
return;
} else if (token.type === tt.braceR) {
// if there's already a curly, it's not part of the template
if (this._curlyBrace) {
tokens.push(this.translate(this._curlyBrace, extra));
}
// store new curly for later
this._curlyBrace = token;
return;
} else if (token.type === tt.template || token.type === tt.invalidTemplate) {
if (this._curlyBrace) {
templateTokens.push(this._curlyBrace);
this._curlyBrace = null;
}
templateTokens.push(token);
return;
}
if (this._curlyBrace) {
tokens.push(this.translate(this._curlyBrace, extra));
this._curlyBrace = null;
}
tokens.push(this.translate(token, extra));
}
};
//------------------------------------------------------------------------------
// Public
//------------------------------------------------------------------------------
module.exports = TokenTranslator;

View File

@ -0,0 +1,127 @@
/**
* @fileoverview The visitor keys for the node types Espree supports
* @author Nicholas C. Zakas
*
* This file contains code from estraverse-fb.
*
* The MIT license. Copyright (c) 2014 Ingvar Stepanyan
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
"use strict";
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
// None!
//------------------------------------------------------------------------------
// Public
//------------------------------------------------------------------------------
module.exports = {
// ECMAScript
AssignmentExpression: ["left", "right"],
AssignmentPattern: ["left", "right"],
ArrayExpression: ["elements"],
ArrayPattern: ["elements"],
ArrowFunctionExpression: ["params", "body"],
BlockStatement: ["body"],
BinaryExpression: ["left", "right"],
BreakStatement: ["label"],
CallExpression: ["callee", "arguments"],
CatchClause: ["param", "body"],
ClassBody: ["body"],
ClassDeclaration: ["id", "superClass", "body"],
ClassExpression: ["id", "superClass", "body"],
ConditionalExpression: ["test", "consequent", "alternate"],
ContinueStatement: ["label"],
DebuggerStatement: [],
DirectiveStatement: [],
DoWhileStatement: ["body", "test"],
EmptyStatement: [],
ExportAllDeclaration: ["source"],
ExportDefaultDeclaration: ["declaration"],
ExportNamedDeclaration: ["declaration", "specifiers", "source"],
ExportSpecifier: ["exported", "local"],
ExpressionStatement: ["expression"],
ForStatement: ["init", "test", "update", "body"],
ForInStatement: ["left", "right", "body"],
ForOfStatement: ["left", "right", "body"],
FunctionDeclaration: ["id", "params", "body"],
FunctionExpression: ["id", "params", "body"],
Identifier: [],
IfStatement: ["test", "consequent", "alternate"],
ImportDeclaration: ["specifiers", "source"],
ImportDefaultSpecifier: ["local"],
ImportNamespaceSpecifier: ["local"],
ImportSpecifier: ["imported", "local"],
Literal: [],
LabeledStatement: ["label", "body"],
LogicalExpression: ["left", "right"],
MemberExpression: ["object", "property"],
MetaProperty: ["meta", "property"],
MethodDefinition: ["key", "value"],
ModuleSpecifier: [],
NewExpression: ["callee", "arguments"],
ObjectExpression: ["properties"],
ObjectPattern: ["properties"],
Program: ["body"],
Property: ["key", "value"],
RestElement: [ "argument" ],
ReturnStatement: ["argument"],
SequenceExpression: ["expressions"],
SpreadElement: ["argument"],
Super: [],
SwitchStatement: ["discriminant", "cases"],
SwitchCase: ["test", "consequent"],
TaggedTemplateExpression: ["tag", "quasi"],
TemplateElement: [],
TemplateLiteral: ["quasis", "expressions"],
ThisExpression: [],
ThrowStatement: ["argument"],
TryStatement: ["block", "handler", "finalizer"],
UnaryExpression: ["argument"],
UpdateExpression: ["argument"],
VariableDeclaration: ["declarations"],
VariableDeclarator: ["id", "init"],
WhileStatement: ["test", "body"],
WithStatement: ["object", "body"],
YieldExpression: ["argument"],
// JSX
JSXIdentifier: [],
JSXNamespacedName: ["namespace", "name"],
JSXMemberExpression: ["object", "property"],
JSXEmptyExpression: [],
JSXExpressionContainer: ["expression"],
JSXElement: ["openingElement", "closingElement", "children"],
JSXClosingElement: ["name"],
JSXOpeningElement: ["name", "attributes"],
JSXAttribute: ["name", "value"],
JSXText: null,
JSXSpreadAttribute: ["argument"],
// Experimental features
ExperimentalRestProperty: ["argument"],
ExperimentalSpreadProperty: ["argument"]
};