@@ -31,30 +31,35 @@ export function createParser(
3131
3232 if ( ! result . parseOutput . isValid ( ) )
3333 throw new Error (
34- ' We encoutered the following syntax error:\n\n\t' +
35- result . parseOutput . errors ( ) [ 0 ] . message +
36- ' \n\nBased on the compiler option provided, we inferred your code to be using Solidity version ' +
37- result . parser . languageVersion +
38- ' . If you would like to change that, specify a different version in your `.prettierrc` file.'
34+ ` We encountered the following syntax error:\n\n\t${
35+ result . parseOutput . errors ( ) [ 0 ] . message
36+ } \n\nBased on the compiler option provided, we inferred your code to be using Solidity version ${
37+ result . parser . languageVersion
38+ } . If you would like to change that, specify a different version in your \ `.prettierrc\ ` file.`
3939 ) ;
4040
4141 return result ;
4242 }
4343 const inferredRanges : string [ ] = LanguageFacts . inferLanguageVersions ( text ) ;
4444 const inferredLength = inferredRanges . length ;
4545
46+ if ( inferredLength === 0 ) {
47+ throw new Error (
48+ `We couldn't infer a Solidity version base on the pragma statements in your code. If you would like to change that, update the pragmas in your source file, or specify a version in your \`.prettierrc\` file.`
49+ ) ;
50+ }
4651 const result = parserAndOutput (
4752 text ,
4853 inferredRanges [ inferredLength === supportedLength ? inferredLength - 1 : 0 ]
4954 ) ;
5055
5156 if ( ! result . parseOutput . isValid ( ) )
5257 throw new Error (
53- ' We encoutered the following syntax error:\n\n\t' +
54- result . parseOutput . errors ( ) [ 0 ] . message +
55- ' \n\nBased on the pragma statements, we inferred your code to be using Solidity version ' +
56- result . parser . languageVersion +
57- ' . If you would like to change that, update the pragmas in your source file, or specify a version in your `.prettierrc` file.'
58+ ` We encountered the following syntax error:\n\n\t${
59+ result . parseOutput . errors ( ) [ 0 ] . message
60+ } \n\nBased on the pragma statements, we inferred your code to be using Solidity version ${
61+ result . parser . languageVersion
62+ } . If you would like to change that, update the pragmas in your source file, or specify a version in your \ `.prettierrc\ ` file.`
5863 ) ;
5964
6065 return result ;
0 commit comments