Skip to content

Commit 71682dc

Browse files
committed
removing the logic that added issues for maintainance
1 parent 6d940bb commit 71682dc

12 files changed

Lines changed: 31 additions & 71 deletions

File tree

src/slang-utils/create-parser.ts

Lines changed: 9 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -9,50 +9,6 @@ import type { AstNode } from '../slang-nodes/types.js';
99

1010
const 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-
5612
function 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
}

tests/format/AllSolidityFeaturesV0.4.26/__snapshots__/format.test.js.snap

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

3-
exports[`AllSolidityFeatures.sol format 1`] = `
3+
exports[`AllSolidityFeatures.sol - {"compiler":"0.4.26"} format 1`] = `
44
====================================options=====================================
5+
compiler: "0.4.26"
56
parsers: ["slang"]
67
printWidth: 80
78
| printWidth
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
runFormatTest(import.meta, ['slang']);
1+
runFormatTest(import.meta, ['slang'], { compiler: '0.4.26' });

tests/format/BasicIterator/__snapshots__/format.test.js.snap

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

3-
exports[`BasicIterator.sol format 1`] = `
3+
exports[`BasicIterator.sol - {"compiler":"0.4.26"} format 1`] = `
44
====================================options=====================================
5+
compiler: "0.4.26"
56
parsers: ["slang"]
67
printWidth: 80
78
| printWidth
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
runFormatTest(import.meta, ['slang']);
1+
runFormatTest(import.meta, ['slang'], { compiler: '0.4.26' });

tests/format/FunctionDefinitionsV0.5.0/__snapshots__/format.test.js.snap

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

3-
exports[`FunctionDefinitions.sol format 1`] = `
3+
exports[`FunctionDefinitions.sol - {"compiler":"0.5.17"} format 1`] = `
44
====================================options=====================================
5+
compiler: "0.5.17"
56
parsers: ["slang"]
67
printWidth: 80
78
| printWidth
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
runFormatTest(import.meta, ['slang']);
1+
runFormatTest(import.meta, ['slang'], { compiler: '0.5.17' });

tests/format/FunctionDefinitionsv0.5.0/__snapshots__/format.test.js.snap

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

3-
exports[`FunctionDefinitions.sol format 1`] = `
3+
exports[`FunctionDefinitions.sol - {"compiler":"0.5.17"} format 1`] = `
44
====================================options=====================================
5+
compiler: "0.5.17"
56
parsers: ["slang"]
67
printWidth: 80
78
| printWidth
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
runFormatTest(import.meta, ['slang']);
1+
runFormatTest(import.meta, ['slang'], { compiler: '0.5.17' });

tests/format/IndexOf/__snapshots__/format.test.js.snap

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

3-
exports[`IndexOf.sol format 1`] = `
3+
exports[`IndexOf.sol - {"compiler":"0.4.26"} format 1`] = `
44
====================================options=====================================
5+
compiler: "0.4.26"
56
parsers: ["slang"]
67
printWidth: 80
78
| printWidth

0 commit comments

Comments
 (0)