You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Sep 27, 2020. It is now read-only.
First of all, thank you so much for this fantastic parser!
The issue I'm facing has to do with the parse function and the loc option set to true, if I pass a file without parseable solidity code in it parse throws an error.
I tested the same scenario with tokenize and it worked fine.
Here is the code to reproduce the scenarios:
constparser=require('solidity-parser-antlr')constemptyFile=''constcommentedFile=`/*pragma solidity ^0.5.3;contract A { uint a; function b() {}}*/`constcontracts=[{ emptyFile },{ commentedFile }]constprocessFile=(parserModule='parse')=>(loc=false)=>contract=>{constcontractName=Object.keys(contract)constlabel=`\n\n=== ${parserModule.toUpperCase()}${contractName} with ${JSON.stringify({ loc })} ===\n`try{constresult=parser[parserModule](contract[contractName],{ loc })console.log(label,JSON.stringify(result,null,2))}catch(e){console.log(label,e)}}constparse=processFile()contracts.forEach(parse(true))contracts.forEach(parse())consttokenize=processFile('tokenize')contracts.forEach(tokenize(true))contracts.forEach(tokenize())
And this is the output of running it:
=== PARSE emptyFile with {"loc": true} ===
TypeError: Cannot read property 'line' of null
at ASTBuilder._loc (/**/solidity-parser-antlr/dist/ASTBuilder.js:1135:22)
at ASTBuilder.meta (/**/solidity-parser-antlr/dist/ASTBuilder.js:1149:29)
at ASTBuilder.createNode (/**/solidity-parser-antlr/dist/ASTBuilder.js:1158:34)
at ASTBuilder.visit (/**/solidity-parser-antlr/dist/ASTBuilder.js:1187:15)
at Object.parse (/**/solidity-parser-antlr/dist/index.js:83:21)
at contract (/**/parse_fails.js:24:40)
at Array.forEach (<anonymous>)
at Object.<anonymous> (/**/parse_fails.js:33:11)
at Module._compile (internal/modules/cjs/loader.js:816:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:827:10)
=== PARSE commentedFile with {"loc": true} ===
TypeError: Cannot read property 'line' of null
at ASTBuilder._loc (/**/solidity-parser-antlr/dist/ASTBuilder.js:1135:22)
at ASTBuilder.meta (/**/solidity-parser-antlr/dist/ASTBuilder.js:1149:29)
at ASTBuilder.createNode (/**/solidity-parser-antlr/dist/ASTBuilder.js:1158:34)
at ASTBuilder.visit (/**/solidity-parser-antlr/dist/ASTBuilder.js:1187:15)
at Object.parse (/**/solidity-parser-antlr/dist/index.js:83:21)
at contract (/**/parse_fails.js:24:40)
at Array.forEach (<anonymous>)
at Object.<anonymous> (/**/parse_fails.js:33:11)
at Module._compile (internal/modules/cjs/loader.js:816:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:827:10)
=== PARSE emptyFile with {"loc": false} ===
{
"type": "SourceUnit",
"children": []
}
=== PARSE commentedFile with {"loc": false} ===
{
"type": "SourceUnit",
"children": []
}
=== TOKENIZE emptyFile with {"loc": true} ===
[]
=== TOKENIZE commentedFile with {"loc": true} ===
[
{
"type": "Keyword",
"value": "/*\npragma solidity ^0.5.3;\n\ncontract A {\n uint a;\n function b() {}\n}\n*/",
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 73
}
}
}
]
=== TOKENIZE emptyFile with {"loc": false} ===
[]
=== TOKENIZE commentedFile with {"loc": false} ===
[
{
"type": "Keyword",
"value": "/*\npragma solidity ^0.5.3;\n\ncontract A {\n uint a;\n function b() {}\n}\n*/"
}
]
The text was updated successfully, but these errors were encountered:
Hello Federico,
First of all, thank you so much for this fantastic parser!
The issue I'm facing has to do with the
parse
function and theloc
option set totrue
, if I pass a file without parseable solidity code in itparse
throws an error.I tested the same scenario with
tokenize
and it worked fine.Here is the code to reproduce the scenarios:
And this is the output of running it:
The text was updated successfully, but these errors were encountered: