solidity-parser / parser

A Solidity parser for JS built on top of a robust ANTLR4 grammar
MIT License
157 stars 44 forks source link

Some interfaces are incorrectly typed in `ast-types.d.ts` #40

Closed lonelyenvoy closed 3 years ago

lonelyenvoy commented 3 years ago

Thank you for implementing the parser - it's very useful.

I'd like to point out some typing problems in dist/ast-types.d.ts.

The type of BaseASTNode.loc is wrong

export interface BaseASTNode {
    type: ASTNodeTypeString;
    range?: [number, number];
    loc?: Location;
}

I guess the definition of Location is missing? The Location here is an interface in the typescript standard library and has nothing to do with line of code.

The type of ASTNodeTypeString is unsound


export declare type ASTNodeTypeString = 'SourceUnit' | 'PragmaDirective' | 'PragmaName' | 'PragmaValue' | 'ImportDirective' | 'ContractDefinition' | 'InheritanceSpecifier' | 'StateVariableDeclaration' | 'UsingForDeclaration' | 'StructDefinition' | 'ModifierDefinition' | 'ModifierInvocation' | 'FunctionDefinition' | 'EventDefinition' | 'EnumValue' | 'EnumDefinition' | 'VariableDeclaration' | 'UserDefinedTypeName' | 'Mapping' | 'ArrayTypeName' | 'FunctionTypeName' | 'StorageLocation' | 'StateMutability' | 'Block' | 'ExpressionStatement' | 'IfStatement' | 'WhileStatement' | 'ForStatement' | 'InlineAssemblyStatement' | 'DoWhileStatement' | 'ContinueStatement' | 'Break' | 'Continue' | 'BreakStatement' | 'ReturnStatement' | 'EmitStatement' | 'ThrowStatement' | 'VariableDeclarationStatement' | 'IdentifierList' | 'ElementaryTypeName' | 'FunctionCall' | 'AssemblyBlock' | 'AssemblyItem' | 'AssemblyCall' | 'AssemblyLocalDefinition' | 'AssemblyAssignment' | 'AssemblyStackAssignment' | 'LabelDefinition' | 'AssemblySwitch' | 'AssemblyCase' | 'AssemblyFunctionDefinition' | 'AssemblyFunctionReturns' | 'AssemblyFor' | 'AssemblyIf' | 'AssemblyLiteral' | 'SubAssembly' | 'TupleExpression' | 'TypeNameExpression' | 'NameValueExpression' | 'BooleanLiteral' | 'NumberLiteral' | 'Identifier' | 'BinaryOperation' | 'UnaryOperation' | 'NewExpression' | 'Conditional' | 'StringLiteral' | 'HexLiteral' | 'HexNumber' | 'DecimalNumber' | 'MemberAccess' | 'IndexAccess' | 'IndexRangeAccess' | 'NameValueList' | 'UncheckedStatement';

Some node types are missing in this declaration, e.g. 'TryStatement' and 'FileLevelConstant'.

Interfaces of some AST node types derived from BaseASTNode are not given

export interface SourceUnit extends BaseASTNode {
    type: 'SourceUnit';
    children: ASTNode[];
}

The interface like this is very useful, but some are missing, e.g. PragmaName, PragmaValue, StorageLocation, StateMutability, and IdentifierList.

fvictorio commented 3 years ago

Yeah, I tried to improve this but it's still a mess. I want to at some point make things so that the project doesn't compile if the node types are not correct. Sadly I haven't been able to do it yet.

fvictorio commented 3 years ago

I think this is no longer relevant, since the project uses typescript now.