@@ -9,50 +9,6 @@ import type { AstNode } from '../slang-nodes/types.js';
99
1010const supportedVersions = LanguageFacts . allVersions ( ) ;
1111
12- // This list was retrieved from Slang's documentation.
13- // https://nomicfoundation.github.io/slang/latest/solidity-grammar/supported-versions/
14- // TODO: use the run-time functionality if NomicFoundation decides to expose
15- // this information directly.
16- const milestoneVersions = [
17- '0.4.14' ,
18- '0.4.16' ,
19- '0.4.21' ,
20- '0.4.22' ,
21- '0.4.25' ,
22- '0.5.0' ,
23- '0.5.3' ,
24- '0.5.5' ,
25- '0.5.8' ,
26- '0.5.10' ,
27- '0.5.14' ,
28- '0.6.0' ,
29- '0.6.2' ,
30- '0.6.5' ,
31- '0.6.7' ,
32- '0.6.8' ,
33- '0.6.11' ,
34- '0.7.0' ,
35- '0.7.1' ,
36- '0.7.4' ,
37- '0.8.0' ,
38- '0.8.4' ,
39- '0.8.8' ,
40- '0.8.13' ,
41- '0.8.18' ,
42- '0.8.19' ,
43- '0.8.22' ,
44- '0.8.27' ,
45- '0.8.29'
46- ] . map (
47- // Since we are aiming to find the highest compatible Language version, we
48- // define a milestone as the highest possible supported version that is
49- // smaller than the original milestone taken from the documentation.
50- // This has an extra cost in execution time and the actual list could be
51- // hardcoded, but the calculation is done only once and it's easier to
52- // maintain.
53- ( milestone ) => maxSatisfying ( supportedVersions , `<${ milestone } ` ) !
54- ) ;
55-
5612function parserAndOutput (
5713 text : string ,
5814 version : string
@@ -73,17 +29,16 @@ export function createParser(
7329
7430 const inferredRanges : string [ ] = LanguageFacts . inferLanguageVersions ( text ) ;
7531
76- let result = parserAndOutput ( text , inferredRanges [ inferredRanges . length - 1 ] ) ;
77- if ( result . parseOutput . isValid ( ) ) return result ;
78-
79- const inferredMilestones = milestoneVersions . filter ( ( milestone ) =>
80- inferredRanges . includes ( milestone )
32+ const result = parserAndOutput (
33+ text ,
34+ inferredRanges [ inferredRanges . length - 1 ]
8135 ) ;
82-
83- for ( let i = inferredMilestones . length - 1 ; i >= 0 ; i -= 1 ) {
84- result = parserAndOutput ( text , inferredMilestones [ i ] ) ;
85- if ( result . parseOutput . isValid ( ) ) break ;
86- }
36+ if ( ! result . parseOutput . isValid ( ) )
37+ 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\`.`
41+ ) ;
8742
8843 return result ;
8944}
0 commit comments