diff --git a/package.json b/package.json index bcf7b5dfcbf..8a3ac46d41a 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "ruling-parametrized": "node tools/prepare-ruling.js && SONAR_RULING_SETTINGS=../settings.js jest ./packages/ruling/tests/projects/*.ruling.test.ts", "ruling-sync": "rsync -avh packages/ruling/tests/actual/jsts/ its/ruling/src/test/expected/jsts/ --delete", "update-ruling-data": "mvn -f sonar-plugin/sonar-javascript-plugin/pom.xml compile && ts-node packages/ruling/tests/tools/parseRulesData.ts", - "bridge:compile": "tsc -b packages profiling && npm run _:bridge:copy-protofile", + "bridge:compile": "tsc -b packages profiling && npm run _:bridge:copy-protofiles", "bridge:test": "jest --maxWorkers=8 --coverage --testPathIgnorePatterns=/packages/ruling/tests/", "bridge:build": "npm run bridge:build:fast && npm run bridge:test", "bridge:build:fast": "npm ci && cd packages/jsts/src/rules && npm ci && cd ../../../../ && npm run _:bridge:clear && npm run bridge:compile", @@ -27,7 +27,7 @@ "prepare": "husky install", "precommit": "pretty-quick --staged", "count-rules": "node tools/count-rules.js", - "_:bridge:copy-protofile": "node tools/estree/copy-to-lib.js", + "_:bridge:copy-protofiles": "cpy --flat packages/jsts/src/parsers/estree.proto sonar-plugin/bridge/src/main/protobuf && cpy --flat packages/jsts/src/parsers/estree.proto lib/jsts/src/parsers", "_:bridge:clear": "rimraf lib/*", "_:plugin:prepare-bridge": "npm pack && node tools/check-distribution-filepath-length.js && npm run _:plugin:copy-bridge && npm run generate-rules-list", "_:plugin-fetch-node": "node tools/fetch-node/scripts/wrapper.mjs", diff --git a/sonar-plugin/bridge/src/main/protobuf/.gitignore b/sonar-plugin/bridge/src/main/protobuf/.gitignore new file mode 100644 index 00000000000..2176df11b3d --- /dev/null +++ b/sonar-plugin/bridge/src/main/protobuf/.gitignore @@ -0,0 +1 @@ +estree.proto \ No newline at end of file diff --git a/sonar-plugin/bridge/src/main/protobuf/estree.proto b/sonar-plugin/bridge/src/main/protobuf/estree.proto deleted file mode 100644 index 6a1e198f998..00000000000 --- a/sonar-plugin/bridge/src/main/protobuf/estree.proto +++ /dev/null @@ -1,475 +0,0 @@ -syntax = "proto3"; -// Generated for @types/estree version: 1.0.5 -// Note: this file was manually modified, to reach a working state faster. -// We should eventually adapt the generator once we are happy with the exact structure. -option java_package="org.sonar.plugins.javascript.bridge.protobuf"; -option java_multiple_files = true; - -message SourceLocation { - string source = 1; - Position start = 2; - Position end = 3; -} -message Position { - int32 line = 1; - int32 column = 2; -} - -enum NodeType { - ProgramType = 0; - ExportAllDeclarationType = 1; - IdentifierType = 2; - ExportDefaultDeclarationType = 3; - YieldExpressionType = 4; - UpdateExpressionType = 5; - UnaryExpressionType = 6; - ThisExpressionType = 7; - TemplateLiteralType = 8; - TaggedTemplateExpressionType = 9; - SequenceExpressionType = 10; - ObjectExpressionType = 11; - SpreadElementType = 12; - PropertyType = 13; - AssignmentPatternType = 14; - RestElementType = 15; - ArrayPatternType = 16; - ObjectPatternType = 17; - PrivateIdentifierType = 18; - NewExpressionType = 19; - SuperType = 20; - MetaPropertyType = 21; - MemberExpressionType = 22; - LogicalExpressionType = 23; - ImportExpressionType = 24; - BlockStatementType = 25; - ConditionalExpressionType = 26; - ClassExpressionType = 27; - ClassBodyType = 28; - StaticBlockType = 29; - PropertyDefinitionType = 30; - MethodDefinitionType = 31; - ChainExpressionType = 32; - CallExpressionType = 33; - BinaryExpressionType = 34; - AwaitExpressionType = 35; - AssignmentExpressionType = 36; - ArrowFunctionExpressionType = 37; - ArrayExpressionType = 38; - ClassDeclarationType = 39; - FunctionDeclarationType = 40; - ExportNamedDeclarationType = 41; - ExportSpecifierType = 42; - VariableDeclarationType = 43; - VariableDeclaratorType = 44; - ImportDeclarationType = 45; - ImportNamespaceSpecifierType = 46; - ImportDefaultSpecifierType = 47; - ImportSpecifierType = 48; - ForOfStatementType = 49; - ForInStatementType = 50; - ForStatementType = 51; - DoWhileStatementType = 52; - WhileStatementType = 53; - TryStatementType = 54; - CatchClauseType = 55; - ThrowStatementType = 56; - SwitchStatementType = 57; - SwitchCaseType = 58; - IfStatementType = 59; - ContinueStatementType = 60; - BreakStatementType = 61; - LabeledStatementType = 62; - ReturnStatementType = 63; - WithStatementType = 64; - DebuggerStatementType = 65; - EmptyStatementType = 66; - ExpressionStatementType = 67; - LiteralType = 68; - TemplateElementType = 69; - FunctionExpressionType = 70; - UnknownNodeType = 1000; -} -message Node { - NodeType type = 1; - SourceLocation loc = 2; - oneof node { - Program program = 3; - ExportAllDeclaration exportAllDeclaration = 4; - Identifier identifier = 5; - ExportDefaultDeclaration exportDefaultDeclaration = 6; - YieldExpression yieldExpression = 7; - UpdateExpression updateExpression = 8; - UnaryExpression unaryExpression = 9; - ThisExpression thisExpression = 10; - TemplateLiteral templateLiteral = 11; - TaggedTemplateExpression taggedTemplateExpression = 12; - SequenceExpression sequenceExpression = 13; - ObjectExpression objectExpression = 14; - SpreadElement spreadElement = 15; - Property property = 16; - AssignmentPattern assignmentPattern = 17; - RestElement restElement = 18; - ArrayPattern arrayPattern = 19; - ObjectPattern objectPattern = 20; - PrivateIdentifier privateIdentifier = 21; - NewExpression newExpression = 22; - Super super = 23; - MetaProperty metaProperty = 24; - MemberExpression memberExpression = 25; - LogicalExpression logicalExpression = 26; - ImportExpression importExpression = 27; - BlockStatement blockStatement = 28; - ConditionalExpression conditionalExpression = 29; - ClassExpression classExpression = 30; - ClassBody classBody = 31; - StaticBlock staticBlock = 32; - PropertyDefinition propertyDefinition = 33; - MethodDefinition methodDefinition = 34; - ChainExpression chainExpression = 35; - CallExpression callExpression = 36; - BinaryExpression binaryExpression = 37; - AwaitExpression awaitExpression = 38; - AssignmentExpression assignmentExpression = 39; - ArrowFunctionExpression arrowFunctionExpression = 40; - ArrayExpression arrayExpression = 41; - ClassDeclaration classDeclaration = 42; - FunctionDeclaration functionDeclaration = 43; - ExportNamedDeclaration exportNamedDeclaration = 44; - ExportSpecifier exportSpecifier = 45; - VariableDeclaration variableDeclaration = 46; - VariableDeclarator variableDeclarator = 47; - ImportDeclaration importDeclaration = 48; - ImportNamespaceSpecifier importNamespaceSpecifier = 49; - ImportDefaultSpecifier importDefaultSpecifier = 50; - ImportSpecifier importSpecifier = 51; - ForOfStatement forOfStatement = 52; - ForInStatement forInStatement = 53; - ForStatement forStatement = 54; - DoWhileStatement doWhileStatement = 55; - WhileStatement whileStatement = 56; - TryStatement tryStatement = 57; - CatchClause catchClause = 58; - ThrowStatement throwStatement = 59; - SwitchStatement switchStatement = 60; - SwitchCase switchCase = 61; - IfStatement ifStatement = 62; - ContinueStatement continueStatement = 63; - BreakStatement breakStatement = 64; - LabeledStatement labeledStatement = 65; - ReturnStatement returnStatement = 66; - WithStatement withStatement = 67; - DebuggerStatement debuggerStatement = 68; - EmptyStatement emptyStatement = 69; - ExpressionStatement expressionStatement = 70; - Literal literal = 71; - TemplateElement templateElement = 72; - FunctionExpression functionExpression = 73; - UnknownNode unknownNode = 1000; - } -} -message Program { - string sourceType = 1; - repeated Node body = 2; -} -message ExportAllDeclaration { - optional Node exported = 1; - Node source = 2; -} -message Literal { - string raw = 1; - optional string bigint = 2; - optional string pattern = 3; - optional string flags = 4; - oneof value { - string valueString = 5; - bool valueBoolean = 6; - int32 valueNumber = 7; - } -} -message Identifier { - string name = 1; -} -message ExportDefaultDeclaration { - Node declaration = 1; -} -message YieldExpression { - optional Node argument = 1; - bool delegate = 2; -} -message UpdateExpression { - string operator = 1; - Node argument = 2; - bool prefix = 3; -} -message UnaryExpression { - string operator = 1; - bool prefix = 2; - Node argument = 3; -} -message ThisExpression { -} -message TemplateLiteral { - repeated Node quasis = 1; - repeated Node expressions = 2; -} -message TaggedTemplateExpression { - Node tag = 1; - Node quasi = 2; -} -message SequenceExpression { - repeated Node expressions = 1; -} -message ObjectExpression { - repeated Node properties = 1; -} -message SpreadElement { - Node argument = 1; -} -message Property { - Node key = 1; - Node value = 2; - string kind = 3; - bool method = 4; - bool shorthand = 5; - bool computed = 6; -} -message AssignmentPattern { - Node left = 1; - Node right = 2; -} -message RestElement { - Node argument = 1; -} -message ArrayPattern { - repeated ArrayElement elements = 1; -} -message ObjectPattern { - repeated Node properties = 1; -} -message PrivateIdentifier { - string name = 1; -} -message NewExpression { - Node callee = 1; - repeated Node arguments = 2; -} -message Super { -} -message MetaProperty { - Node meta = 1; - Node property = 2; -} -message MemberExpression { - Node object = 1; - Node property = 2; - bool computed = 3; - bool optional = 4; -} -message LogicalExpression { - string operator = 1; - Node left = 2; - Node right = 3; -} -message ImportExpression { - Node source = 1; -} -message BlockStatement { - repeated Node body = 1; -} -message ConditionalExpression { - Node test = 1; - Node alternate = 2; - Node consequent = 3; -} -message ClassExpression { - optional Node id = 1; - optional Node superClass = 2; - Node body = 3; -} -message ClassBody { - repeated Node body = 1; -} -message StaticBlock { - repeated Node body = 1; -} -message PropertyDefinition { - Node key = 1; - optional Node value = 2; - bool computed = 3; - bool static = 4; -} -message MethodDefinition { - Node key = 1; - Node value = 2; - string kind = 3; - bool computed = 4; - bool static = 5; -} -message ChainExpression { - Node expression = 1; -} -message CallExpression { - bool optional = 1; - Node callee = 2; - repeated Node arguments = 3; -} -message BinaryExpression { - string operator = 1; - Node left = 2; - Node right = 3; -} -message AwaitExpression { - Node argument = 1; -} -message AssignmentExpression { - string operator = 1; - Node left = 2; - Node right = 3; -} -message ArrowFunctionExpression { - bool expression = 1; - Node body = 2; - repeated Node params = 3; - optional bool generator = 4; - optional bool async = 5; -} -message ArrayExpression { - repeated ArrayElement elements = 1; -} -message ArrayElement { - optional Node element = 1; -} -message ClassDeclaration { - optional Node id = 1; - optional Node superClass = 2; - Node body = 3; -} -message FunctionDeclaration { - Node id = 1; - Node body = 2; - repeated Node params = 3; - optional bool generator = 4; - optional bool async = 5; -} -message ExportNamedDeclaration { - optional Node declaration = 1; - repeated Node specifiers = 2; - optional Node source = 3; -} -message ExportSpecifier { - Node exported = 1; - Node local = 2; -} -message VariableDeclaration { - repeated Node declarations = 1; - string kind = 2; -} -message VariableDeclarator { - Node id = 1; - optional Node init = 2; -} -message ImportDeclaration { - repeated Node specifiers = 1; - Node source = 2; -} -message ImportNamespaceSpecifier { - Node local = 1; -} -message ImportDefaultSpecifier { - Node local = 1; -} -message ImportSpecifier { - Node imported = 1; - Node local = 2; -} -message ForOfStatement { - bool await = 1; - Node left = 2; - Node right = 3; - Node body = 4; -} -message ForInStatement { - Node left = 1; - Node right = 2; - Node body = 3; -} -message ForStatement { - optional Node init = 1; - optional Node test = 2; - optional Node update = 3; - Node body = 4; -} -message DoWhileStatement { - Node body = 1; - Node test = 2; -} -message WhileStatement { - Node test = 1; - Node body = 2; -} -message TryStatement { - Node block = 1; - optional Node handler = 2; - optional Node finalizer = 3; -} -message CatchClause { - optional Node param = 1; - Node body = 2; -} -message ThrowStatement { - Node argument = 1; -} -message SwitchStatement { - Node discriminant = 1; - repeated Node cases = 2; -} -message SwitchCase { - optional Node test = 1; - repeated Node consequent = 2; -} -message IfStatement { - Node test = 1; - Node consequent = 2; - optional Node alternate = 3; -} -message ContinueStatement { - optional Node label = 1; -} -message BreakStatement { - optional Node label = 1; -} -message LabeledStatement { - Node label = 1; - Node body = 2; -} -message ReturnStatement { - optional Node argument = 1; -} -message WithStatement { - Node object = 1; - Node body = 2; -} -message DebuggerStatement { -} -message EmptyStatement { -} -message ExpressionStatement { - Node expression = 1; - optional string directive = 2; -} -message TemplateElement { - bool tail = 1; - optional string cooked = 2; - string raw = 3; -} -message FunctionExpression { - optional Node id = 1; - Node body = 2; - repeated Node params = 3; - optional bool generator = 4; - optional bool async = 5; -} - -message UnknownNode { - string rawType = 1; -} diff --git a/tools/estree/copy-to-lib.js b/tools/estree/copy-to-lib.js deleted file mode 100644 index a9242271c35..00000000000 --- a/tools/estree/copy-to-lib.js +++ /dev/null @@ -1,11 +0,0 @@ -const fs = require('node:fs'); -const path = require('node:path'); - -fs.copyFileSync( - path.join(__dirname, 'output', 'estree.proto'), - path.join(__dirname, '..', '..', 'lib', 'jsts', 'src', 'parsers', 'estree.proto'), -); -fs.copyFileSync( - path.join(__dirname, 'output', 'estree.proto'), - path.join(__dirname, '..', '..', 'packages', 'jsts', 'src', 'parsers', 'estree.proto'), -); diff --git a/tools/estree/generate-java-ast.ts b/tools/estree/generate-java-ast.ts deleted file mode 100644 index 71d9fd363e9..00000000000 --- a/tools/estree/generate-java-ast.ts +++ /dev/null @@ -1,366 +0,0 @@ -/* - * SonarQube JavaScript Plugin - * Copyright (C) 2011-2024 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -import fs from 'node:fs'; -import { - ArrayLikeFieldValue, - ESTreeNode, - NodeField, - NodeFieldValue, - UnionFieldValue, -} from './get-estree-nodes'; - -const HEADER = `/* - * SonarQube JavaScript Plugin - * Copyright (C) 2011-2024 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -`; - -const NODE_INTERFACE = `public sealed interface Node { - Location loc(); - } - - public record Position(int line, int column) {} - public record Location(Position start, Position end) {} -`; - -const SHARED_FIELDS = ['Location loc']; - -const OPERATORS = ` public interface Operator { - String raw(); - } - - public enum UnaryOperator implements Operator { - MINUS("-"), PLUS("+"), LOGICAL_NOT("!"), BITWISE_NOT("~"), TYPEOF("typeof"), VOID("void"), DELETE("delete"); - - private final String raw; - - UnaryOperator(String raw) { - this.raw = raw; - } - - @Override - public String raw() { - return raw; - } - } - - public enum BinaryOperator implements Operator { - EQUAL("=="), - NOT_EQUAL("!="), - STRICT_EQUAL("==="), - STRICT_NOT_EQUAL("!=="), - LESS_THAN("<"), - LESS_THAN_OR_EQUAL("<="), - GREATER_THAN(">"), - GREATER_THAN_OR_EQUAL(">="), - LEFT_SHIFT("<<"), - RIGHT_SHIFT(">>"), - UNSIGNED_RIGHT_SHIFT(">>>"), - PLUS("+"), - MINUS("-"), - MULTIPLY("*"), - DIVIDE("/"), - MODULO("%"), - EXPONENTIATION("**"), - BITWISE_AND("&"), - BITWISE_OR("|"), - BITWISE_XOR("^"), - IN("in"), - INSTANCEOF("instanceof"); - - private final String raw; - - BinaryOperator(String raw) { - this.raw = raw; - } - - @Override - public String raw() { - return raw; - } - } - - public enum LogicalOperator implements Operator { - AND("&&"), OR("||"), NULLISH_COALESCING("??"); - - private final String raw; - - LogicalOperator(String raw) { - this.raw = raw; - } - - @Override - public String raw() { - return raw; - } - } - - public enum AssignmentOperator implements Operator { - ASSIGN("="), - PLUS_ASSIGN("+="), - MINUS_ASSIGN("-="), - MULTIPLY_ASSIGN("*="), - DIVIDE_ASSIGN("/="), - MODULO_ASSIGN("%="), - EXPONENTIATION_ASSIGN("**="), - LEFT_SHIFT_ASSIGN("<<="), - RIGHT_SHIFT_ASSIGN(">>="), - UNSIGNED_RIGHT_SHIFT_ASSIGN(">>>="), - BITWISE_OR_ASSIGN("|="), - BITWISE_XOR_ASSIGN("^="), - BITWISE_AND_ASSIGN("&="), - LOGICAL_OR_ASSIGN("||="), - LOGICAL_AND_ASSIGN("&&="), - NULLISH_COALESCING_ASSIGN("??=") - ; - - private final String raw; - - AssignmentOperator(String raw) { - this.raw = raw; - } - - @Override - public String raw() { - return raw; - } - } - - public enum UpdateOperator implements Operator { - INCREMENT("++"), DECREMENT("--"); - - private final String raw; - - UpdateOperator(String raw) { - this.raw = raw; - } - - @Override - public String raw() { - return raw; - } - }`; - -function isUnionNode(node: ESTreeNode) { - return node.fields.length === 1 && 'unionElements' in node.fields[0].fieldValue; -} - -function isPrimitive(f: NodeField) { - const fv = f.fieldValue; - return 'type' in fv && ['string', 'int32', 'bool'].some(s => s === fv.type); -} - -export function writeJavaClassesToDir(nodes: Record, output: string) { - // remove operators, they are hardcoded as enums - [ - 'UnaryOperator', - 'BinaryOperator', - 'LogicalOperator', - 'AssignmentOperator', - 'UpdateOperator', - ].forEach(o => delete nodes[o]); - - const entries = Object.entries(nodes).sort(([a], [b]) => (a < b ? -1 : 1)); - const ifaces = entries.filter(([, n]) => isUnionNode(n)).map(([name]) => name); - - const impl = new Map(); - ifaces - .filter(i => isUnionNode(nodes[i])) - .forEach(iface => { - //@ts-ignore - const union = nodes[iface].fields[0].fieldValue.unionElements.map(e => - upperCaseFirstLetter(e.name), - ); - for (const u of union) { - if (impl.has(u)) { - impl.set(u, impl.get(u)!.concat(iface)); - } else { - impl.set(u, [iface]); - } - } - }); - - nodes['Literal'].fields = [ - { - name: 'raw', - fieldValue: { type: 'string' }, - }, - ]; - nodes['ChainElement'].fields = [ - { - name: 'optional', - fieldValue: { type: 'bool' }, - }, - ]; - nodes['CallExpression'].fields = [ - { - name: 'callee', - fieldValue: { type: 'ExpressionOrSuper' }, // more precise type is Expression | Super, but we can't represent union types in Java easily - }, - { - name: 'arguments', - fieldValue: { type: `List` }, - }, - ]; - nodes['BigIntLiteral'].fields[0].fieldValue = { type: 'BigInteger' }; - - const records = []; - const ifaceSrc: string[] = []; - const unionIfaces: string[] = []; - for (const [name, node] of entries) { - if (!ifaces.includes(name)) { - const fields = [...SHARED_FIELDS]; - for (const field of node.fields) { - if (field.name === 'type') { - // ignore 'type' field - continue; - } - fields.push(`${javaType(field.fieldValue)} ${javaName(field.name)}`); - } - records.push( - ` public record ${name}(${fields.join(', ')}) implements ${implementsClause(impl, node)} {}`, - ); - } - } - - ifaces.forEach(iface => { - const ext = implementsClause(impl, nodes[iface]); - const fields = ifaceFields(nodes[iface]); - ifaceSrc.push(` public sealed interface ${iface} extends ${ext} {\n${fields}\n }`); - }); - - function javaType(fieldValue: NodeFieldValue): string { - if ('type' in fieldValue) { - switch (fieldValue.type) { - case 'string': - return 'String'; - case 'int32': - return 'int'; - case 'bool': - return 'boolean'; - case 'BaseNodeWithoutComments': - return 'Node'; - } - return fieldValue.type; - } - if (isArray(fieldValue)) { - return `List<${javaType(fieldValue.elementValue)}>`; - } - if ('unionElements' in fieldValue && !fieldValue.unionElements.some(isPrimitive)) { - let unionIface = fieldValue.unionElements - .map(e => upperCaseFirstLetter(e.name)) - .sort() - .join('Or'); - fieldValue.unionElements.forEach(e => - impl.set( - upperCaseFirstLetter(e.name), - [unionIface].concat(impl.get(upperCaseFirstLetter(e.name)) || []), - ), - ); - unionIfaces.push(unionIface); - return unionIface; - } - return 'Node'; - } - - function javaName(name: string) { - if (name === 'static') { - return 'isStatic'; - } - return name; - } - - function ifaceFields(node: ESTreeNode) { - return node.fields - .filter(f => !('unionElements' in f.fieldValue)) - .map(f => ` ${javaType(f.fieldValue)} ${javaName(f.name)}();`) - .join('\n'); - } - - function implementsClause(impl: Map, node: ESTreeNode) { - const ifaces = []; - if (impl.has(node.name)) { - ifaces.push(...impl.get(node.name)!); - } else { - ifaces.push('Node'); - } - return unique(ifaces).join(', '); - } - - const estree = `${HEADER} -package org.sonar.plugins.javascript.api.estree; - -import java.math.BigInteger; -import java.util.List; - -/** - This file is generated. Do not modify it manually. Look at tools/estree instead. - - This is !EXPERIMENTAL UNSUPPORTED INTERNAL API! It can be modified or removed without prior notice. -*/ -public class ESTree { - - private ESTree() { - // shouldn't be instantiated, used only as a namespace - } - - ${NODE_INTERFACE} -${ifaceSrc.join('\n')} - -${unique(unionIfaces) - .map(i => ` public sealed interface ${i} extends Node {}`) - .join('\n')} - -${records.join('\n')} - -${OPERATORS} -} - -`; - fs.writeFileSync(output, estree, 'utf-8'); -} - -function upperCaseFirstLetter(s: string) { - return s.charAt(0).toUpperCase() + s.slice(1); -} - -function isArray(fieldValue: NodeFieldValue): fieldValue is ArrayLikeFieldValue { - return 'elementValue' in fieldValue; -} - -function unique(arr: T[]): T[] { - return arr.filter((v, i, self) => self.indexOf(v) === i); -} diff --git a/tools/estree/generate-proto-file.ts b/tools/estree/generate-proto-file.ts deleted file mode 100644 index 42fa01d0c2d..00000000000 --- a/tools/estree/generate-proto-file.ts +++ /dev/null @@ -1,115 +0,0 @@ -/* - * SonarQube JavaScript Plugin - * Copyright (C) 2011-2024 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -/** - * This script is out of date - * We have modified the `estree.proto` file by hand - */ - -import fs from 'node:fs'; -import path from 'node:path'; -import { ESTreeNode, lowerCaseFirstLetter, PrimitiveFieldValue } from './get-estree-nodes'; - -const packageJson = require(path.join('..', '..', 'package.json')); -const typesVersion = packageJson.devDependencies['@types/estree']; - -export function writeMessagesToDir(messages: Record, outputDir: string) { - // When serializing the AST to protobuf, we only need the concrete types (leafs of the AST). - const concreteMessages = Object.values(messages).filter(m => m.fields[0].name === 'type'); - - fs.writeFileSync( - path.join(outputDir, 'estree.proto'), - addPrefix(translateToProtoFormat(concreteMessages)), - ); - /** - * Translate the messages to a protobuf file format. - */ - function translateToProtoFormat(messages: ESTreeNode[]): string { - const lines: string[] = []; - lines.push('enum NodeType {'); - let index = 0; - for (const message of messages) { - lines.push(` ${message.name} = ${index};`); - index++; - } - lines.push('}'); - - lines.push('message Node {'); - lines.push(' NodeType type = 1;'); - lines.push(' SourceLocation loc = 2;'); - index = 3; - lines.push(' oneof node {'); - for (const message of messages) { - lines.push(` ${message.name} ${lowerCaseFirstLetter(message.name)} = ${index};`); - index++; - } - lines.push(' }'); - lines.push('}'); - - for (const message of Object.values(messages)) { - let index = 1; - lines.push(`message ${message.name} {`); - for (const field of message.fields) { - if (field.name === 'type') { - continue; - } - if ('elementValue' in field.fieldValue) { - lines.push( - ` repeated ${getType((field.fieldValue.elementValue as PrimitiveFieldValue).type)} ${field.name} = ${index};`, - ); - } else if ('unionElements' in field.fieldValue) { - lines.push(` Node ${field.name} = ${index};`); - } else { - lines.push(` ${getType(field.fieldValue.type)} ${field.name} = ${index};`); - } - index++; - } - lines.push('}'); - } - return lines.join('\n'); - } - - function getType(t: string) { - if (t === 'string' || t === 'bool' || t === 'int32' || t === 'Position') { - return t; - } - return 'Node'; - } - - function addPrefix(protoData: string) { - return `syntax = "proto3"; -// Generated for @types/estree version: ${typesVersion} -option java_package="org.sonar.plugins.javascript.bridge.protobuf"; -option java_multiple_files = true; - -message SourceLocation { - string source = 1; - Position start = 2; - Position end = 3; -} -message Position { - int32 line = 1; - int32 end = 2; -} - -${protoData} -`; - } -} diff --git a/tools/estree/get-estree-nodes.ts b/tools/estree/get-estree-nodes.ts deleted file mode 100644 index 61abf9f2353..00000000000 --- a/tools/estree/get-estree-nodes.ts +++ /dev/null @@ -1,304 +0,0 @@ -import ts from 'typescript'; - -// Types representing Protobuf messages. -export type ESTreeNode = { - name: string; - fields: NodeField[]; -}; - -export type NodeField = { - name: string; - fieldValue: NodeFieldValue; -}; - -export type NodeFieldValue = PrimitiveFieldValue | ArrayLikeFieldValue | UnionFieldValue; - -export type PrimitiveFieldValue = { - type: string; -}; - -export type ArrayLikeFieldValue = { - elementValue: NodeFieldValue; -}; - -export type UnionFieldValue = { - unionElements: NodeField[]; -}; - -export type Declaration = ts.InterfaceDeclaration | ts.TypeAliasDeclaration; - -export const TOP_LEVEL_NODE = 'Node'; - -const IGNORED_MEMBERS: Set = new Set([ - // The "type" member is redundant in our context. - 'comments', - 'innerComments', -]); - -// Some types follow a different structure than the others, instead of adding special logic for them, we create them manually. -const HAND_WRITTEN_TYPES: Set = new Set([ - // RegExpLiteral declare RegExp, wich we can not map to Protobuf type. - 'RegExpLiteral', - // TemplateElement is not following the common structure of the other nodes. - 'TemplateElement', -]); - -export function getEstreeNodes(file: ts.SourceFile) { - const declarations = declarationsFromFile(file); - - const messages: Record = {}; - - // Create node manually for 'RegExpLiteral' and 'TemplateElement'. - messages['RegExpLiteral'] = { - name: 'RegExpLiteral', - fields: [ - { name: 'pattern', fieldValue: { type: 'string' } }, - { name: 'flags', fieldValue: { type: 'string' } }, - { name: 'raw', fieldValue: { type: 'string' } }, - ], - }; - - messages['TemplateElement'] = { - name: 'TemplateElement', - fields: [ - { name: 'tail', fieldValue: { type: 'bool' } }, - { name: 'cooked', fieldValue: { type: 'string' } }, - { name: 'raw', fieldValue: { type: 'string' } }, - ], - }; - - const requestedTypes: string[] = ['Program']; - while (requestedTypes.length) { - const requestedType = requestedTypes.pop()!; - const declaration = declarations[requestedType]; - - if (!declaration) { - console.log('Missing declaration for', requestedType); - continue; - } - - if (ts.isInterfaceDeclaration(declaration)) { - const typeHierarchy = extractTypeHierarchy(declaration, file, declarations).reverse(); - - let messageFields: NodeField[] = []; - for (const currentType of typeHierarchy) { - const currentDeclaration = declarations[currentType] as ts.InterfaceDeclaration; - const currentFields = getFieldValues(currentDeclaration, messageFields, file); - messageFields = messageFields.concat(currentFields); - } - - messages[requestedType] = { - name: requestedType, - fields: messageFields, - }; - } else if (ts.isTypeAliasDeclaration(declaration)) { - messages[requestedType] = { - name: requestedType, - fields: [ - { - name: lowerCaseFirstLetter(declaration.name.getText(file)), - fieldValue: getFieldValueFromType(declaration.type), - }, - ], - }; - } else { - throw new Error(`Unexpected declaration for ${requestedType}`); - } - } - - function requestType(type: string): PrimitiveFieldValue { - if (!(type in messages) && !requestedTypes.includes(type) && !HAND_WRITTEN_TYPES.has(type)) { - requestedTypes.push(type); - } - - return { type }; - } - - function getFieldValues( - declaration: ts.InterfaceDeclaration, - messageFields: NodeField[], - file: ts.SourceFile, - ) { - return declaration.members - .filter(ts.isPropertySignature) - .filter(signature => signature.type && !IGNORED_MEMBERS.has(signature.name.getText(file))) - .filter(signature => !isAlreadyThere(messageFields, signature, file)) - .map(signature => { - return { - name: signature.name.getText(file), - fieldValue: getFieldValueFromType(signature.type as ts.TypeNode), - }; - }); - } - - function getFieldValueFromType(typeNode: ts.TypeNode): NodeFieldValue { - // The type is of shape "A[]", we want to generate repeated A - if (ts.isArrayTypeNode(typeNode)) { - return { - elementValue: flattenRepeatedNodeInOneOf(getFieldValueFromType(typeNode.elementType)), - }; - } - - // The type is of shape "A | B", we want to generate oneof name {A a, B b} - if (ts.isUnionTypeNode(typeNode)) { - if (typeNode.types.every(t => ts.isLiteralTypeNode(t) && ts.isStringLiteral(t.literal))) { - // Case similar to "kind: "init" | "get" | "set";". - // In this case, we don't want to create one field per alternative, it is enough to create one single string field of type string. - // Note that we loose the potential exhaustiveness compiler check, but adding more code to have this feature is currently overkill compared to the usefulness. - return { type: 'string' }; - } - - const interestingTypes = typeNode.types - // We don't need to explicitly say that a value can be undefined or null, if it is the case during serialization, we will simply not put anything. - .filter(t => !isNullOrUndefined(t)); - - if (interestingTypes.length === 1) { - return getFieldValueFromType(interestingTypes[0]); - } - - return { - unionElements: interestingTypes.map(t => { - return { - name: lowerCaseFirstLetter(t.getText(file)), - fieldValue: getFieldValueFromType(t), - }; - }), - }; - } - - if (ts.isLiteralTypeNode(typeNode)) { - if (ts.isStringLiteral(typeNode.literal)) { - return { type: 'string' }; - } - if ( - typeNode.literal.kind === ts.SyntaxKind.TrueKeyword || - typeNode.literal.kind === ts.SyntaxKind.FalseKeyword - ) { - return { type: 'bool' }; - } - throw new Error( - `unexpected literal type: ${ts.SyntaxKind[typeNode.literal.kind]} (${typeNode.literal.getText(file)})`, - ); - } - - if (ts.isTypeReferenceNode(typeNode)) { - const name = typeNode.typeName.getText(file); - if (name === 'Array' && typeNode.typeArguments?.length === 1) { - // The type is of shape "Array", we want to generate repeated A - return { - elementValue: getFieldValueFromType(typeNode.typeArguments[0]), - }; - } - return requestType(typeNode.typeName.getText(file)); - } - - // The type is a primitve type - switch (typeNode.kind) { - case ts.SyntaxKind.StringKeyword: - return { type: 'string' }; - case ts.SyntaxKind.NumberKeyword: - case ts.SyntaxKind.BigIntKeyword: - return { type: 'int32' }; - case ts.SyntaxKind.BooleanKeyword: - return { type: 'bool' }; - } - - if (ts.isIndexedAccessTypeNode(typeNode)) { - // Specific case for "ExpressionMap", as it is declared with a "keyof" logic. - const keyOfDeclaration = declarations[ - typeNode.objectType.getText(file) - ] as ts.InterfaceDeclaration; - return { - unionElements: keyOfDeclaration.members - .filter(ts.isPropertySignature) - .filter(signature => signature.type) - .map(s => { - return { - name: lowerCaseFirstLetter((s.type as ts.TypeNode).getText(file)), - fieldValue: getFieldValueFromType(s.type as ts.TypeNode), - }; - }), - }; - } - throw new Error(`Cannot generate Protobuf field Value for typeNode ${typeNode.getText(file)}`); - } - - return messages; -} - -function declarationsFromFile(file: ts.SourceFile) { - const declarations: Record = {}; - for (const statement of file.statements) { - // The "index.d.ts" file contains only interfaces and type aliases. - const declaration = statement as Declaration; - declarations[declaration.name.getText(file)] = declaration; - } - return declarations; -} - -function isNullOrUndefined(node: ts.TypeNode): boolean { - if (ts.isLiteralTypeNode(node)) { - return ( - node.literal.kind === ts.SyntaxKind.NullKeyword || - node.literal.kind === ts.SyntaxKind.UndefinedKeyword - ); - } - return node.kind === ts.SyntaxKind.NullKeyword || node.kind === ts.SyntaxKind.UndefinedKeyword; -} - -function flattenRepeatedNodeInOneOf(field: NodeFieldValue): NodeFieldValue { - // Protobuf does not support oneof with repeated fields, so we need to flatten them. - if ('unionElements' in field) { - // We naively put the value to be a Top Level Node. We loose a bit of compiler safety check - // (example: "Literal | Identifier" will be flattened to a Top Level Node, meaning that one could put any "Expression" in it, which is not correct) - // but it is a tradeoff we are willing to make for now. - return { type: TOP_LEVEL_NODE }; - } - return field; -} - -function isAlreadyThere( - messageFields: { name: string; fieldValue: NodeFieldValue }[], - signature: ts.PropertySignature, - file: ts.SourceFile, -) { - for (const field of messageFields) { - if (field.name === signature.name.getText(file)) { - return true; - } - } - return false; -} - -/** - * Returns the type hierarchy from top to bottom - * Example: [BaseStatement, BaseForXStatement, ForInStatement] - */ -function extractTypeHierarchy( - declaration: ts.InterfaceDeclaration, - file: ts.SourceFile, - declarations: Record, -): string[] { - const inheritedTypes = declaration?.heritageClauses - ?.flatMap(hc => hc.types) - ?.flatMap(t => { - const typeName = t.getText(file); - const parentDeclaration = declarations[t.getText(file)]; - // We stop at BaseNode, we will handle it manually. - if (parentDeclaration && typeName !== 'BaseNode') { - return extractTypeHierarchy( - parentDeclaration as ts.InterfaceDeclaration, - file, - declarations, - ); - } - return []; - }); - const ret: string[] = inheritedTypes || []; - ret.push(declaration.name.getText(file)); - return ret; -} - -export function lowerCaseFirstLetter(str: string) { - return str.charAt(0).toLowerCase() + str.slice(1); -} diff --git a/tools/estree/load-proto.ts b/tools/estree/load-proto.ts deleted file mode 100644 index 6315aab62d6..00000000000 --- a/tools/estree/load-proto.ts +++ /dev/null @@ -1,22 +0,0 @@ -/* - * SonarQube JavaScript Plugin - * Copyright (C) 2011-2024 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import protobuf from 'protobufjs'; - -const proto = protobuf.loadSync('output/estree.proto'); diff --git a/tools/estree/main.ts b/tools/estree/main.ts deleted file mode 100644 index d2b9211b6da..00000000000 --- a/tools/estree/main.ts +++ /dev/null @@ -1,47 +0,0 @@ -/* - * SonarQube JavaScript Plugin - * Copyright (C) 2011-2024 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import path from 'node:path'; -import ts from 'typescript'; -import fs from 'node:fs'; -import { writeMessagesToDir } from './generate-proto-file'; -import { writeJavaClassesToDir } from './generate-java-ast'; -import { getEstreeNodes } from './get-estree-nodes'; - -const TYPES_PATH = path.join('..', '..', 'node_modules', '@types', 'estree', 'index.d.ts'); -const file = ts.createSourceFile( - TYPES_PATH, - fs.readFileSync(TYPES_PATH, 'utf-8'), - ts.ScriptTarget.ESNext, -); - -const nodes = getEstreeNodes(file); - -const arg = process.argv[2]; -const output = 'output'; - -fs.mkdirSync(output, { recursive: true }); -if (arg === 'proto') { - writeMessagesToDir(nodes, output); -} else if (arg === 'java') { - writeJavaClassesToDir(nodes, path.join(output, 'ESTree.java')); -} else { - console.error('Error: Argument should be "proto" or "java"'); - process.exit(1); // Exit with a failure code -} diff --git a/tools/estree/output/estree.proto b/tools/estree/output/estree.proto deleted file mode 100644 index 6a1e198f998..00000000000 --- a/tools/estree/output/estree.proto +++ /dev/null @@ -1,475 +0,0 @@ -syntax = "proto3"; -// Generated for @types/estree version: 1.0.5 -// Note: this file was manually modified, to reach a working state faster. -// We should eventually adapt the generator once we are happy with the exact structure. -option java_package="org.sonar.plugins.javascript.bridge.protobuf"; -option java_multiple_files = true; - -message SourceLocation { - string source = 1; - Position start = 2; - Position end = 3; -} -message Position { - int32 line = 1; - int32 column = 2; -} - -enum NodeType { - ProgramType = 0; - ExportAllDeclarationType = 1; - IdentifierType = 2; - ExportDefaultDeclarationType = 3; - YieldExpressionType = 4; - UpdateExpressionType = 5; - UnaryExpressionType = 6; - ThisExpressionType = 7; - TemplateLiteralType = 8; - TaggedTemplateExpressionType = 9; - SequenceExpressionType = 10; - ObjectExpressionType = 11; - SpreadElementType = 12; - PropertyType = 13; - AssignmentPatternType = 14; - RestElementType = 15; - ArrayPatternType = 16; - ObjectPatternType = 17; - PrivateIdentifierType = 18; - NewExpressionType = 19; - SuperType = 20; - MetaPropertyType = 21; - MemberExpressionType = 22; - LogicalExpressionType = 23; - ImportExpressionType = 24; - BlockStatementType = 25; - ConditionalExpressionType = 26; - ClassExpressionType = 27; - ClassBodyType = 28; - StaticBlockType = 29; - PropertyDefinitionType = 30; - MethodDefinitionType = 31; - ChainExpressionType = 32; - CallExpressionType = 33; - BinaryExpressionType = 34; - AwaitExpressionType = 35; - AssignmentExpressionType = 36; - ArrowFunctionExpressionType = 37; - ArrayExpressionType = 38; - ClassDeclarationType = 39; - FunctionDeclarationType = 40; - ExportNamedDeclarationType = 41; - ExportSpecifierType = 42; - VariableDeclarationType = 43; - VariableDeclaratorType = 44; - ImportDeclarationType = 45; - ImportNamespaceSpecifierType = 46; - ImportDefaultSpecifierType = 47; - ImportSpecifierType = 48; - ForOfStatementType = 49; - ForInStatementType = 50; - ForStatementType = 51; - DoWhileStatementType = 52; - WhileStatementType = 53; - TryStatementType = 54; - CatchClauseType = 55; - ThrowStatementType = 56; - SwitchStatementType = 57; - SwitchCaseType = 58; - IfStatementType = 59; - ContinueStatementType = 60; - BreakStatementType = 61; - LabeledStatementType = 62; - ReturnStatementType = 63; - WithStatementType = 64; - DebuggerStatementType = 65; - EmptyStatementType = 66; - ExpressionStatementType = 67; - LiteralType = 68; - TemplateElementType = 69; - FunctionExpressionType = 70; - UnknownNodeType = 1000; -} -message Node { - NodeType type = 1; - SourceLocation loc = 2; - oneof node { - Program program = 3; - ExportAllDeclaration exportAllDeclaration = 4; - Identifier identifier = 5; - ExportDefaultDeclaration exportDefaultDeclaration = 6; - YieldExpression yieldExpression = 7; - UpdateExpression updateExpression = 8; - UnaryExpression unaryExpression = 9; - ThisExpression thisExpression = 10; - TemplateLiteral templateLiteral = 11; - TaggedTemplateExpression taggedTemplateExpression = 12; - SequenceExpression sequenceExpression = 13; - ObjectExpression objectExpression = 14; - SpreadElement spreadElement = 15; - Property property = 16; - AssignmentPattern assignmentPattern = 17; - RestElement restElement = 18; - ArrayPattern arrayPattern = 19; - ObjectPattern objectPattern = 20; - PrivateIdentifier privateIdentifier = 21; - NewExpression newExpression = 22; - Super super = 23; - MetaProperty metaProperty = 24; - MemberExpression memberExpression = 25; - LogicalExpression logicalExpression = 26; - ImportExpression importExpression = 27; - BlockStatement blockStatement = 28; - ConditionalExpression conditionalExpression = 29; - ClassExpression classExpression = 30; - ClassBody classBody = 31; - StaticBlock staticBlock = 32; - PropertyDefinition propertyDefinition = 33; - MethodDefinition methodDefinition = 34; - ChainExpression chainExpression = 35; - CallExpression callExpression = 36; - BinaryExpression binaryExpression = 37; - AwaitExpression awaitExpression = 38; - AssignmentExpression assignmentExpression = 39; - ArrowFunctionExpression arrowFunctionExpression = 40; - ArrayExpression arrayExpression = 41; - ClassDeclaration classDeclaration = 42; - FunctionDeclaration functionDeclaration = 43; - ExportNamedDeclaration exportNamedDeclaration = 44; - ExportSpecifier exportSpecifier = 45; - VariableDeclaration variableDeclaration = 46; - VariableDeclarator variableDeclarator = 47; - ImportDeclaration importDeclaration = 48; - ImportNamespaceSpecifier importNamespaceSpecifier = 49; - ImportDefaultSpecifier importDefaultSpecifier = 50; - ImportSpecifier importSpecifier = 51; - ForOfStatement forOfStatement = 52; - ForInStatement forInStatement = 53; - ForStatement forStatement = 54; - DoWhileStatement doWhileStatement = 55; - WhileStatement whileStatement = 56; - TryStatement tryStatement = 57; - CatchClause catchClause = 58; - ThrowStatement throwStatement = 59; - SwitchStatement switchStatement = 60; - SwitchCase switchCase = 61; - IfStatement ifStatement = 62; - ContinueStatement continueStatement = 63; - BreakStatement breakStatement = 64; - LabeledStatement labeledStatement = 65; - ReturnStatement returnStatement = 66; - WithStatement withStatement = 67; - DebuggerStatement debuggerStatement = 68; - EmptyStatement emptyStatement = 69; - ExpressionStatement expressionStatement = 70; - Literal literal = 71; - TemplateElement templateElement = 72; - FunctionExpression functionExpression = 73; - UnknownNode unknownNode = 1000; - } -} -message Program { - string sourceType = 1; - repeated Node body = 2; -} -message ExportAllDeclaration { - optional Node exported = 1; - Node source = 2; -} -message Literal { - string raw = 1; - optional string bigint = 2; - optional string pattern = 3; - optional string flags = 4; - oneof value { - string valueString = 5; - bool valueBoolean = 6; - int32 valueNumber = 7; - } -} -message Identifier { - string name = 1; -} -message ExportDefaultDeclaration { - Node declaration = 1; -} -message YieldExpression { - optional Node argument = 1; - bool delegate = 2; -} -message UpdateExpression { - string operator = 1; - Node argument = 2; - bool prefix = 3; -} -message UnaryExpression { - string operator = 1; - bool prefix = 2; - Node argument = 3; -} -message ThisExpression { -} -message TemplateLiteral { - repeated Node quasis = 1; - repeated Node expressions = 2; -} -message TaggedTemplateExpression { - Node tag = 1; - Node quasi = 2; -} -message SequenceExpression { - repeated Node expressions = 1; -} -message ObjectExpression { - repeated Node properties = 1; -} -message SpreadElement { - Node argument = 1; -} -message Property { - Node key = 1; - Node value = 2; - string kind = 3; - bool method = 4; - bool shorthand = 5; - bool computed = 6; -} -message AssignmentPattern { - Node left = 1; - Node right = 2; -} -message RestElement { - Node argument = 1; -} -message ArrayPattern { - repeated ArrayElement elements = 1; -} -message ObjectPattern { - repeated Node properties = 1; -} -message PrivateIdentifier { - string name = 1; -} -message NewExpression { - Node callee = 1; - repeated Node arguments = 2; -} -message Super { -} -message MetaProperty { - Node meta = 1; - Node property = 2; -} -message MemberExpression { - Node object = 1; - Node property = 2; - bool computed = 3; - bool optional = 4; -} -message LogicalExpression { - string operator = 1; - Node left = 2; - Node right = 3; -} -message ImportExpression { - Node source = 1; -} -message BlockStatement { - repeated Node body = 1; -} -message ConditionalExpression { - Node test = 1; - Node alternate = 2; - Node consequent = 3; -} -message ClassExpression { - optional Node id = 1; - optional Node superClass = 2; - Node body = 3; -} -message ClassBody { - repeated Node body = 1; -} -message StaticBlock { - repeated Node body = 1; -} -message PropertyDefinition { - Node key = 1; - optional Node value = 2; - bool computed = 3; - bool static = 4; -} -message MethodDefinition { - Node key = 1; - Node value = 2; - string kind = 3; - bool computed = 4; - bool static = 5; -} -message ChainExpression { - Node expression = 1; -} -message CallExpression { - bool optional = 1; - Node callee = 2; - repeated Node arguments = 3; -} -message BinaryExpression { - string operator = 1; - Node left = 2; - Node right = 3; -} -message AwaitExpression { - Node argument = 1; -} -message AssignmentExpression { - string operator = 1; - Node left = 2; - Node right = 3; -} -message ArrowFunctionExpression { - bool expression = 1; - Node body = 2; - repeated Node params = 3; - optional bool generator = 4; - optional bool async = 5; -} -message ArrayExpression { - repeated ArrayElement elements = 1; -} -message ArrayElement { - optional Node element = 1; -} -message ClassDeclaration { - optional Node id = 1; - optional Node superClass = 2; - Node body = 3; -} -message FunctionDeclaration { - Node id = 1; - Node body = 2; - repeated Node params = 3; - optional bool generator = 4; - optional bool async = 5; -} -message ExportNamedDeclaration { - optional Node declaration = 1; - repeated Node specifiers = 2; - optional Node source = 3; -} -message ExportSpecifier { - Node exported = 1; - Node local = 2; -} -message VariableDeclaration { - repeated Node declarations = 1; - string kind = 2; -} -message VariableDeclarator { - Node id = 1; - optional Node init = 2; -} -message ImportDeclaration { - repeated Node specifiers = 1; - Node source = 2; -} -message ImportNamespaceSpecifier { - Node local = 1; -} -message ImportDefaultSpecifier { - Node local = 1; -} -message ImportSpecifier { - Node imported = 1; - Node local = 2; -} -message ForOfStatement { - bool await = 1; - Node left = 2; - Node right = 3; - Node body = 4; -} -message ForInStatement { - Node left = 1; - Node right = 2; - Node body = 3; -} -message ForStatement { - optional Node init = 1; - optional Node test = 2; - optional Node update = 3; - Node body = 4; -} -message DoWhileStatement { - Node body = 1; - Node test = 2; -} -message WhileStatement { - Node test = 1; - Node body = 2; -} -message TryStatement { - Node block = 1; - optional Node handler = 2; - optional Node finalizer = 3; -} -message CatchClause { - optional Node param = 1; - Node body = 2; -} -message ThrowStatement { - Node argument = 1; -} -message SwitchStatement { - Node discriminant = 1; - repeated Node cases = 2; -} -message SwitchCase { - optional Node test = 1; - repeated Node consequent = 2; -} -message IfStatement { - Node test = 1; - Node consequent = 2; - optional Node alternate = 3; -} -message ContinueStatement { - optional Node label = 1; -} -message BreakStatement { - optional Node label = 1; -} -message LabeledStatement { - Node label = 1; - Node body = 2; -} -message ReturnStatement { - optional Node argument = 1; -} -message WithStatement { - Node object = 1; - Node body = 2; -} -message DebuggerStatement { -} -message EmptyStatement { -} -message ExpressionStatement { - Node expression = 1; - optional string directive = 2; -} -message TemplateElement { - bool tail = 1; - optional string cooked = 2; - string raw = 3; -} -message FunctionExpression { - optional Node id = 1; - Node body = 2; - repeated Node params = 3; - optional bool generator = 4; - optional bool async = 5; -} - -message UnknownNode { - string rawType = 1; -} diff --git a/tools/estree/package.json b/tools/estree/package.json deleted file mode 100644 index da9b24971a2..00000000000 --- a/tools/estree/package.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "name": "protobuf", - "version": "1.0.0", - "description": "", - "main": "index.js", - "scripts": { - "generate-proto": "ts-node main.ts proto", - "generate-java": "ts-node main.ts java", - "load": "ts-node load-proto.ts", - "compile": "tsc" - }, - "author": "", - "license": "ISC" -} diff --git a/tools/estree/tsconfig.json b/tools/estree/tsconfig.json deleted file mode 100644 index bb2f7f66251..00000000000 --- a/tools/estree/tsconfig.json +++ /dev/null @@ -1,109 +0,0 @@ -{ - "compilerOptions": { - /* Visit https://aka.ms/tsconfig to read more about this file */ - - /* Projects */ - // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */ - // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ - // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */ - // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */ - // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ - // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ - - /* Language and Environment */ - "target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, - // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ - // "jsx": "preserve", /* Specify what JSX code is generated. */ - // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */ - // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ - // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */ - // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ - // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */ - // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ - // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ - // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ - // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ - - /* Modules */ - "module": "commonjs" /* Specify what module code is generated. */, - // "rootDir": "./", /* Specify the root folder within your source files. */ - // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */ - // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ - // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ - // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ - // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ - // "types": [], /* Specify type package names to be included without being referenced in a source file. */ - // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ - // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ - // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */ - // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ - // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ - // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ - // "resolveJsonModule": true, /* Enable importing .json files. */ - // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */ - // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ - - /* JavaScript Support */ - // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ - // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ - // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ - - /* Emit */ - // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ - // "declarationMap": true, /* Create sourcemaps for d.ts files. */ - // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ - // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ - // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ - // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ - // "outDir": "./", /* Specify an output folder for all emitted files. */ - // "removeComments": true, /* Disable emitting comments. */ - // "noEmit": true, /* Disable emitting files from a compilation. */ - // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ - // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */ - // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ - // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ - // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ - // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ - // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ - // "newLine": "crlf", /* Set the newline character for emitting files. */ - // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */ - // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */ - // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ - // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */ - // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ - // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ - - /* Interop Constraints */ - // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ - // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ - // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ - "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */, - // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ - "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */, - - /* Type Checking */ - "strict": true /* Enable all strict type-checking options. */, - // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ - // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ - // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ - // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */ - // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ - // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */ - // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */ - // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ - // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */ - // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */ - // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ - // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ - // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ - // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */ - // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ - // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */ - // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ - // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ - - /* Completeness */ - // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ - "skipLibCheck": true /* Skip type checking all .d.ts files. */ - } -}