{"id":16902,"library":"solparse","title":"Solparse","description":"Solparse is a JavaScript library providing a PEG.js-based parser for the Solidity programming language. It is currently at version 2.2.8, with its last major release dating back over seven years, indicating a sporadic and maintenance-driven release cadence. The library was originally a fork of Consensys' `solidity-parser` and is primarily maintained to support `Ethlint`, a Solidity linter. Due to its specific maintenance focus, the developers do not guarantee backward compatibility or new feature support for general use. Users are strongly advised to pin `solparse` as a fixed dependency in production systems. Alternatives like `solparse-exp-jb` (a more recent fork supporting newer Solidity features) or `@solidity-parser/parser` (an ANTLR-based parser) may offer more up-to-date Solidity syntax support.","status":"maintenance","version":"2.2.8","language":"javascript","source_language":"en","source_url":"https://github.com/duaraghav8/solparse","tags":["javascript"],"install":[{"cmd":"npm install solparse","lang":"bash","label":"npm"},{"cmd":"yarn add solparse","lang":"bash","label":"yarn"},{"cmd":"pnpm add solparse","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core parsing engine used to generate the Solidity parser.","package":"pegjs","optional":false},{"reason":"Used for command-line argument parsing, likely for the bundled CLI utility.","package":"yargs","optional":false}],"imports":[{"note":"The 'solparse' package exports the 'parse' function as its default export. For older Node.js or CommonJS environments, use `const parse = require('solparse');`. Named imports like `{ parse }` will not work.","wrong":"import { parse } from 'solparse';\nconst solparse = require('solparse');","symbol":"parse","correct":"import parse from 'solparse';"},{"note":"ParserError is part of the error handling mechanism and is usually an instance of a class or a property on the default export. It is not directly exported as a named symbol.","wrong":"import { ParserError } from 'solparse';","symbol":"ParserError","correct":"import parse from 'solparse';\n// ParserError is typically accessed via the default export if available\n// or caught in a try-catch block and checked with `e instanceof parse.ParserError`"}],"quickstart":{"code":"import parse from 'solparse';\n\nconst solidityCode = `\npragma solidity ^0.8.0;\n\ncontract SimpleStorage {\n    uint256 public storedData;\n\n    function set(uint256 x) public {\n        storedData = x;\n    }\n\n    function get() public view returns (uint256) {\n        return storedData;\n    }\n}\n`;\n\ntry {\n    const ast = parse(solidityCode);\n    console.log('Successfully parsed Solidity code. AST:', JSON.stringify(ast, null, 2));\n    // You can now traverse and analyze the AST\n    console.log('Contract name:', ast.body[0].name);\n} catch (e) {\n    if (e instanceof Error && e.name === 'SyntaxError') {\n        console.error('Parsing error:', e.message);\n    } else {\n        console.error('An unexpected error occurred:', e);\n    }\n}","lang":"typescript","description":"Demonstrates how to parse a basic Solidity contract string using solparse and log the resulting Abstract Syntax Tree (AST), including basic error handling."},"warnings":[{"fix":"Pin `solparse` to a fixed version in your `package.json` (e.g., `\"solparse\": \"2.2.8\"`) and manually test before updating.","message":"Solparse does not guarantee backward compatibility and may introduce breaking changes without major version increments. Its development is tied to `Ethlint`'s needs rather than general public API stability.","severity":"breaking","affected_versions":">=2.x"},{"fix":"For projects requiring support for modern Solidity, consider alternative parsers such as `solparse-exp-jb` or `@solidity-parser/parser` which are actively maintained and support newer language versions.","message":"The package has not been updated in over seven years (last published January 13, 2019) and may not support newer Solidity syntax features (e.g., `emit` syntax introduced in 0.4.21, or features in Solidity 0.5.x, 0.6.x, 0.7.x, 0.8.x and later).","severity":"gotcha","affected_versions":"<=2.2.8"},{"fix":"Use `import parse from 'solparse';` for ESM or `const parse = require('solparse');` for CommonJS to correctly access the parsing function.","message":"The `solparse` package primarily targets CommonJS environments. While Node.js can often import CJS modules, direct named ESM imports will not work as the package exports a single default function.","severity":"gotcha","affected_versions":">=2.x"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Ensure your Solidity code adheres to an older syntax version supported by `solparse` (e.g., pre-0.4.21 for certain features), or migrate to a more current Solidity parser that supports modern syntax.","cause":"This generic syntax error often indicates that the Solidity code being parsed contains syntax elements not recognized by the older `solparse` version. A common example is the `emit` keyword for events, introduced in Solidity 0.4.21.","error":"Syntax error: Expected \"!= \", \"%\", \"%=\", \"&\", \"&&\", \"&=\", \"*\", \"*=\", \"+\", \"++\", \"+\", \",\", \"-\", \"--\", \"-=\", \"/\", \"/*\", \"/=\", \";\", \"<\", \"<<\", \"<<=\", \"<=\", \"=\", \"==\", \">\", \">=\", \">>\", \">>=\", \">>>\", \"?\", \"^\", \"^=\", \"|\", \"|=\", \"||\", comment, end of line, or whitespace but \"(\" found."},{"fix":"Wrap `parse()` calls in a try-catch block to handle `SyntaxError` or `ParserError` gracefully. Inspect the `ast` object structure after successful parsing to ensure it matches expectations before accessing properties. Consider `console.log(JSON.stringify(ast, null, 2))` for debugging.","cause":"Attempting to access properties of the AST object, such as `ast.body[0].name`, when the parsing failed or the AST structure is unexpected for the given Solidity code. This often happens if the input is invalid or a parsing error occurred before the AST could be fully formed.","error":"TypeError: Cannot read properties of undefined (reading 'name')"}],"ecosystem":"npm","meta_description":null}