Skip to content

Commit a48c29a

Browse files
committed
Fix typos and adding a check for an empty array
1 parent ff18c5d commit a48c29a

1 file changed

Lines changed: 15 additions & 10 deletions

File tree

src/slang-utils/create-parser.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)