Skip to content

Commit 8f6bc4e

Browse files
fvictorioJanther
andauthored
Parse with latest compatible solidity version (#1225)
* Parse with latest compatible solidity version * Parse with latest compatible solidity version * Fix tests * using the expected resolution of the compiler instead of forcing it in tests --------- Co-authored-by: Klaus <[email protected]>
1 parent 19c2c28 commit 8f6bc4e

12 files changed

Lines changed: 26 additions & 35 deletions

File tree

src/slang-utils/create-parser.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { NonterminalKind } from '@nomicfoundation/slang/cst';
22
import { Parser } from '@nomicfoundation/slang/parser';
33
import { LanguageFacts } from '@nomicfoundation/slang/utils';
4-
import { minSatisfying } from 'semver';
4+
import { maxSatisfying } from 'semver';
55

66
import type { ParseOutput } from '@nomicfoundation/slang/parser';
77
import type { ParserOptions } from 'prettier';
@@ -34,7 +34,7 @@ export function createParser(
3434
text: string,
3535
options: ParserOptions<AstNode>
3636
): { parser: Parser; parseOutput: ParseOutput } {
37-
const compiler = minSatisfying(supportedVersions, options.compiler);
37+
const compiler = maxSatisfying(supportedVersions, options.compiler);
3838
if (compiler) {
3939
const result = parserAndOutput(text, compiler);
4040

@@ -68,7 +68,10 @@ export function createParser(
6868
return result;
6969
}
7070

71-
const result = parserAndOutput(text, inferredRanges[0]);
71+
const result = parserAndOutput(
72+
text,
73+
inferredRanges[inferredRanges.length - 1]
74+
);
7275

7376
if (!result.parseOutput.isValid())
7477
throw createError(

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

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

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

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

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

3-
exports[`Pragma.sol - {"compiler":"0.8.0"} format 1`] = `
3+
exports[`Pragma.sol format 1`] = `
44
====================================options=====================================
5-
compiler: "0.8.0"
65
parsers: ["slang"]
76
printWidth: 80
87
| printWidth

tests/format/Pragma/format.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
runFormatTest(import.meta, ['slang'], { compiler: '0.8.0' });
1+
runFormatTest(import.meta, ['slang']);

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

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

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

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

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

3-
exports[`BlankLines.sol - {"compiler":"0.5.17"} format 1`] = `
3+
exports[`BlankLines.sol format 1`] = `
44
====================================options=====================================
5-
compiler: "0.5.17"
65
parsers: ["slang"]
76
printWidth: 80
87
| printWidth
@@ -47,9 +46,8 @@ contract A {
4746
================================================================================
4847
`;
4948

50-
exports[`ControlStructures.sol - {"compiler":"0.5.17"} format 1`] = `
49+
exports[`ControlStructures.sol format 1`] = `
5150
====================================options=====================================
52-
compiler: "0.5.17"
5351
parsers: ["slang"]
5452
printWidth: 80
5553
| printWidth
@@ -169,9 +167,8 @@ contract ControlStructures {
169167
================================================================================
170168
`;
171169

172-
exports[`FunctionDeclaration.sol - {"compiler":"0.5.17"} format 1`] = `
170+
exports[`FunctionDeclaration.sol format 1`] = `
173171
====================================options=====================================
174-
compiler: "0.5.17"
175172
parsers: ["slang"]
176173
printWidth: 80
177174
| printWidth
@@ -461,9 +458,8 @@ contract X is B, C, D {
461458
================================================================================
462459
`;
463460

464-
exports[`Mappings.sol - {"compiler":"0.5.17"} format 1`] = `
461+
exports[`Mappings.sol format 1`] = `
465462
====================================options=====================================
466-
compiler: "0.5.17"
467463
parsers: ["slang"]
468464
printWidth: 80
469465
| printWidth
@@ -491,9 +487,8 @@ contract Mappings {
491487
================================================================================
492488
`;
493489

494-
exports[`MaximumLineLength.sol - {"compiler":"0.5.17"} format 1`] = `
490+
exports[`MaximumLineLength.sol format 1`] = `
495491
====================================options=====================================
496-
compiler: "0.5.17"
497492
parsers: ["slang"]
498493
printWidth: 80
499494
| printWidth
@@ -647,9 +642,8 @@ contract EventDefinitionsAndEventEmitters {
647642
================================================================================
648643
`;
649644

650-
exports[`OtherRecommendations.sol - {"compiler":"0.5.17"} format 1`] = `
645+
exports[`OtherRecommendations.sol format 1`] = `
651646
====================================options=====================================
652-
compiler: "0.5.17"
653647
parsers: ["slang"]
654648
printWidth: 80
655649
| printWidth
@@ -715,9 +709,8 @@ contract OtherRecommendations {
715709
================================================================================
716710
`;
717711

718-
exports[`VariableDeclarations.sol - {"compiler":"0.5.17"} format 1`] = `
712+
exports[`VariableDeclarations.sol format 1`] = `
719713
====================================options=====================================
720-
compiler: "0.5.17"
721714
parsers: ["slang"]
722715
printWidth: 80
723716
| printWidth
@@ -739,9 +732,8 @@ contract VariableDeclarations {
739732
================================================================================
740733
`;
741734

742-
exports[`WhitespaceInExpressions.sol - {"compiler":"0.5.17"} format 1`] = `
735+
exports[`WhitespaceInExpressions.sol format 1`] = `
743736
====================================options=====================================
744-
compiler: "0.5.17"
745737
parsers: ["slang"]
746738
printWidth: 80
747739
| printWidth
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
runFormatTest(import.meta, ['slang'], { compiler: '0.5.17' });
1+
runFormatTest(import.meta, ['slang']);

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

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

3-
exports[`strings.sol - {"compiler":"0.4.26"} format 1`] = `
3+
exports[`strings.sol format 1`] = `
44
====================================options=====================================
5-
compiler: "0.4.26"
65
parsers: ["slang"]
76
printWidth: 80
87
| printWidth

0 commit comments

Comments
 (0)