Registry / web-framework / solparse

solparse

JSON →
library2.2.8jsnpmunverified

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.

npm install solparse
INSTALL
IMPORT
SIG · SOLPARSE
S
solparse
web-frameworkjavascriptv2.2.8
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parse
import parse from 'solparse';
import { parse } from 'solparse'; const solparse = require('solparse');
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.
ParserError
import parse from 'solparse'; // ParserError is typically accessed via the default export if available // or caught in a try-catch block and checked with `e instanceof parse.ParserError`
import { ParserError } from 'solparse';
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.

Demonstrates how to parse a basic Solidity contract string using solparse and log the resulting Abstract Syntax Tree (AST), including basic error handling.

import parse from 'solparse'; const solidityCode = ` pragma solidity ^0.8.0; contract SimpleStorage { uint256 public storedData; function set(uint256 x) public { storedData = x; } function get() public view returns (uint256) { return storedData; } } `; try { const ast = parse(solidityCode); console.log('Successfully parsed Solidity code. AST:', JSON.stringify(ast, null, 2)); // You can now traverse and analyze the AST console.log('Contract name:', ast.body[0].name); } catch (e) { if (e instanceof Error && e.name === 'SyntaxError') { console.error('Parsing error:', e.message); } else { console.error('An unexpected error occurred:', e); } }
Debug
Known issues
breakingSolparse 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.
fix
Pin `solparse` to a fixed version in your `package.json` (e.g., `"solparse": "2.2.8"`) and manually test before updating.
affects: >=2.x
gotchaThe 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).
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.
affects: <=2.2.8
gotchaThe `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.
fix
Use `import parse from 'solparse';` for ESM or `const parse = require('solparse');` for CommonJS to correctly access the parsing function.
affects: >=2.x
Errors
Common errors & fixes
Syntax error: Expected "!= ", "%", "%=", "&", "&&", "&=", "*", "*=", "+", "++", "+", ",", "-", "--", "-=", "/", "/*", "/=", ";", "<", "<<", "<<=", "<=", "=", "==", ">", ">=", ">>", ">>=", ">>>", "?", "^", "^=", "|", "|=", "||", comment, end of line, or whitespace but "(" found.
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.
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.
TypeError: Cannot read properties of undefined (reading 'name')
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.
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.
Upgrade
Version history
2.2.8latest on npm
Audit
Dependencies
pegjsrequiredCore parsing engine used to generate the Solidity parser.
yargsrequiredUsed for command-line argument parsing, likely for the bundled CLI utility.
Agent activity
2 hits · last 30 days
node
2
Resources
solparse — npm install solparse · libregistry