Registry / serialization / solidity-parser

solidity-parser

JSON →
library0.1.1jsnpmunverified

PEG.js-based Solidity parser for JavaScript. Current stable version is 0.4.0, released as pre-alpha software. Provides parse() and parseFile() functions to convert Solidity source code into a structured JSON AST, with an optional 'imports' mode to extract imported file paths. Intended for tooling that needs to analyze or transform Solidity code without relying on heavy preprocessors. The AST structure is unstable and incomplete, and the parser may silently skip unsupported Solidity constructs. Not recommended for production use.

npm install solidity-parser
INSTALL
IMPORT
SIG · SOLIDITY-PARSER
S
solidity-parser
serializationjavascriptv0.1.1
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.

default
const SolidityParser = require('solidity-parser');
import SolidityParser from 'solidity-parser';
This package does not provide ESM exports; use CommonJS require.
parse
SolidityParser.parse(code);
SolidityParser.parse(code, {});
parse() accepts a string and an optional options object (not well documented).
parseFile
SolidityParser.parseFile('./path/to/file.sol');
SolidityParser.parseFile('./path/to/file.sol', 'ast');
Second argument can be 'imports' to extract imported files; 'ast' is the default.

Shows basic parse and parseFile usage with CommonJS require.

const SolidityParser = require('solidity-parser'); const solidityCode = ` contract Test { uint256 public value; } `; const ast = SolidityParser.parse(solidityCode); console.log(JSON.stringify(ast, null, 2)); // Extract imports from a file const imports = SolidityParser.parseFile('./path/to/file.sol', 'imports'); console.log(imports);
Debug
Known issues
breakingThe AST structure is unstable and changes between versions.
fix
Do not rely on specific AST shapes; always test after upgrading.
affects: >=0.1.0
deprecatedThis package is in pre-alpha and no longer actively maintained.
fix
Consider using @solidity-parser/parser or other alternatives.
affects: >=0.4.0
gotchaThe parser silently ignores unsupported Solidity constructs.
fix
Validate parsed output for completeness; use a more robust parser for production.
affects: >=0.1.0
deprecatedPEG.js dependency is outdated and may cause security vulnerabilities.
fix
Upgrade to a parser built on a modern parser generator.
affects: >=0.1.0
gotchaparseFile requires the file to exist and be readable; no error handling for missing files.
fix
Ensure file exists before calling parseFile.
affects: >=0.1.0
gotchaOutput format may vary; documentation examples may not match actual output.
fix
Inspect the actual returned JSON to understand the structure.
affects: >=0.4.0
Errors
Common errors & fixes
Error: Cannot find module 'pegjs'
Missing pegjs dependency when using package directly from GitHub or without proper install.
fix
Run 'npm install' in the project directory, or install pegjs globally with 'npm install -g pegjs'.
SyntaxError: Unexpected token
Solidity code contains constructs not supported by the parser (e.g., newer Solidity syntax).
fix
Simplify or update the Solidity code to match older syntax; consider using a more modern parser like @solidity-parser/parser.
TypeError: SolidityParser.parse is not a function
Using ES6 import style instead of CommonJS require.
fix
Use const SolidityParser = require('solidity-parser'); instead of import.
Upgrade
Version history
0.1.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
12 hits · last 30 days
node
8
Amazon
1
Resources
solidity-parser — npm install solidity-parser · libregistry