@@ -25,19 +25,34 @@ export function createParser(
2525 options : ParserOptions < AstNode >
2626) : { parser : Parser ; parseOutput : ParseOutput } {
2727 const compiler = maxSatisfying ( supportedVersions , options . compiler ) ;
28- if ( compiler ) return parserAndOutput ( text , compiler ) ;
28+ if ( compiler ) {
29+ const result = parserAndOutput ( text , compiler ) ;
2930
31+ if ( ! result . parseOutput . isValid ( ) )
32+ throw new Error (
33+ 'We encoutered the following syntax error:\n\n\t' +
34+ result . parseOutput . errors ( ) [ 0 ] . message +
35+ '\n\nBased on the compiler option provided, we inferred your code to be using Solidity version ' +
36+ result . parser . languageVersion +
37+ '. If you would like to change that, specify a different version in your `.prettierrc` file.'
38+ ) ;
39+
40+ return result ;
41+ }
3042 const inferredRanges : string [ ] = LanguageFacts . inferLanguageVersions ( text ) ;
3143
3244 const result = parserAndOutput (
3345 text ,
3446 inferredRanges [ inferredRanges . length - 1 ]
3547 ) ;
48+
3649 if ( ! result . parseOutput . isValid ( ) )
3750 throw new Error (
38- `Based on the pragma statements, we inferred your code to be using Solidity version ${
39- result . parser . languageVersion
40- } . If you would like to change that, update the pragmas in your source file, or specify a version in \`.prettierrc\` or VSCode's \`settings.json\`.`
51+ 'We encoutered the following syntax error:\n\n\t' +
52+ result . parseOutput . errors ( ) [ 0 ] . message +
53+ '\n\nBased on the pragma statements, we inferred your code to be using Solidity version ' +
54+ result . parser . languageVersion +
55+ '. If you would like to change that, update the pragmas in your source file, or specify a version in your `.prettierrc` file.'
4156 ) ;
4257
4358 return result ;
0 commit comments