diff --git a/src/slang-utils/create-parser.ts b/src/slang-utils/create-parser.ts index 088676e00..f5cd9ffc6 100644 --- a/src/slang-utils/create-parser.ts +++ b/src/slang-utils/create-parser.ts @@ -1,7 +1,7 @@ import { NonterminalKind } from '@nomicfoundation/slang/cst'; import { Parser } from '@nomicfoundation/slang/parser'; import { LanguageFacts } from '@nomicfoundation/slang/utils'; -import { minSatisfying } from 'semver'; +import { maxSatisfying } from 'semver'; import type { ParseOutput } from '@nomicfoundation/slang/parser'; import type { ParserOptions } from 'prettier'; @@ -34,7 +34,7 @@ export function createParser( text: string, options: ParserOptions ): { parser: Parser; parseOutput: ParseOutput } { - const compiler = minSatisfying(supportedVersions, options.compiler); + const compiler = maxSatisfying(supportedVersions, options.compiler); if (compiler) { const result = parserAndOutput(text, compiler); @@ -68,7 +68,10 @@ export function createParser( return result; } - const result = parserAndOutput(text, inferredRanges[0]); + const result = parserAndOutput( + text, + inferredRanges[inferredRanges.length - 1] + ); if (!result.parseOutput.isValid()) throw createError( diff --git a/tests/format/MemberAccess/__snapshots__/format.test.js.snap b/tests/format/MemberAccess/__snapshots__/format.test.js.snap index f3d07202b..a3c80c392 100644 --- a/tests/format/MemberAccess/__snapshots__/format.test.js.snap +++ b/tests/format/MemberAccess/__snapshots__/format.test.js.snap @@ -1,8 +1,7 @@ // Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing -exports[`MemberAccess.sol - {"compiler":"0.6.12"} format 1`] = ` +exports[`MemberAccess.sol format 1`] = ` ====================================options===================================== -compiler: "0.6.12" parsers: ["slang"] printWidth: 80 | printWidth diff --git a/tests/format/MemberAccess/format.test.js b/tests/format/MemberAccess/format.test.js index 569e4c7b0..6021bbb0d 100644 --- a/tests/format/MemberAccess/format.test.js +++ b/tests/format/MemberAccess/format.test.js @@ -1 +1 @@ -runFormatTest(import.meta, ['slang'], { compiler: '0.6.12' }); +runFormatTest(import.meta, ['slang']); diff --git a/tests/format/Pragma/__snapshots__/format.test.js.snap b/tests/format/Pragma/__snapshots__/format.test.js.snap index 383f623d6..2585c9843 100644 --- a/tests/format/Pragma/__snapshots__/format.test.js.snap +++ b/tests/format/Pragma/__snapshots__/format.test.js.snap @@ -1,8 +1,7 @@ // Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing -exports[`Pragma.sol - {"compiler":"0.8.0"} format 1`] = ` +exports[`Pragma.sol format 1`] = ` ====================================options===================================== -compiler: "0.8.0" parsers: ["slang"] printWidth: 80 | printWidth diff --git a/tests/format/Pragma/format.test.js b/tests/format/Pragma/format.test.js index 875eca87d..6021bbb0d 100644 --- a/tests/format/Pragma/format.test.js +++ b/tests/format/Pragma/format.test.js @@ -1 +1 @@ -runFormatTest(import.meta, ['slang'], { compiler: '0.8.0' }); +runFormatTest(import.meta, ['slang']); diff --git a/tests/format/SimpleStorage/__snapshots__/format.test.js.snap b/tests/format/SimpleStorage/__snapshots__/format.test.js.snap index 99944356e..fd37d2458 100644 --- a/tests/format/SimpleStorage/__snapshots__/format.test.js.snap +++ b/tests/format/SimpleStorage/__snapshots__/format.test.js.snap @@ -1,8 +1,7 @@ // Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing -exports[`SimpleStorage.sol - {"compiler":"0.4.26"} format 1`] = ` +exports[`SimpleStorage.sol format 1`] = ` ====================================options===================================== -compiler: "0.4.26" parsers: ["slang"] printWidth: 80 | printWidth diff --git a/tests/format/SimpleStorage/format.test.js b/tests/format/SimpleStorage/format.test.js index 85c6f9a33..6021bbb0d 100644 --- a/tests/format/SimpleStorage/format.test.js +++ b/tests/format/SimpleStorage/format.test.js @@ -1 +1 @@ -runFormatTest(import.meta, ['slang'], { compiler: '0.4.26' }); +runFormatTest(import.meta, ['slang']); diff --git a/tests/format/StyleGuide/__snapshots__/format.test.js.snap b/tests/format/StyleGuide/__snapshots__/format.test.js.snap index 8ceed378d..cb3816eb7 100644 --- a/tests/format/StyleGuide/__snapshots__/format.test.js.snap +++ b/tests/format/StyleGuide/__snapshots__/format.test.js.snap @@ -1,8 +1,7 @@ // Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing -exports[`BlankLines.sol - {"compiler":"0.5.17"} format 1`] = ` +exports[`BlankLines.sol format 1`] = ` ====================================options===================================== -compiler: "0.5.17" parsers: ["slang"] printWidth: 80 | printWidth @@ -47,9 +46,8 @@ contract A { ================================================================================ `; -exports[`ControlStructures.sol - {"compiler":"0.5.17"} format 1`] = ` +exports[`ControlStructures.sol format 1`] = ` ====================================options===================================== -compiler: "0.5.17" parsers: ["slang"] printWidth: 80 | printWidth @@ -169,9 +167,8 @@ contract ControlStructures { ================================================================================ `; -exports[`FunctionDeclaration.sol - {"compiler":"0.5.17"} format 1`] = ` +exports[`FunctionDeclaration.sol format 1`] = ` ====================================options===================================== -compiler: "0.5.17" parsers: ["slang"] printWidth: 80 | printWidth @@ -461,9 +458,8 @@ contract X is B, C, D { ================================================================================ `; -exports[`Mappings.sol - {"compiler":"0.5.17"} format 1`] = ` +exports[`Mappings.sol format 1`] = ` ====================================options===================================== -compiler: "0.5.17" parsers: ["slang"] printWidth: 80 | printWidth @@ -491,9 +487,8 @@ contract Mappings { ================================================================================ `; -exports[`MaximumLineLength.sol - {"compiler":"0.5.17"} format 1`] = ` +exports[`MaximumLineLength.sol format 1`] = ` ====================================options===================================== -compiler: "0.5.17" parsers: ["slang"] printWidth: 80 | printWidth @@ -647,9 +642,8 @@ contract EventDefinitionsAndEventEmitters { ================================================================================ `; -exports[`OtherRecommendations.sol - {"compiler":"0.5.17"} format 1`] = ` +exports[`OtherRecommendations.sol format 1`] = ` ====================================options===================================== -compiler: "0.5.17" parsers: ["slang"] printWidth: 80 | printWidth @@ -715,9 +709,8 @@ contract OtherRecommendations { ================================================================================ `; -exports[`VariableDeclarations.sol - {"compiler":"0.5.17"} format 1`] = ` +exports[`VariableDeclarations.sol format 1`] = ` ====================================options===================================== -compiler: "0.5.17" parsers: ["slang"] printWidth: 80 | printWidth @@ -739,9 +732,8 @@ contract VariableDeclarations { ================================================================================ `; -exports[`WhitespaceInExpressions.sol - {"compiler":"0.5.17"} format 1`] = ` +exports[`WhitespaceInExpressions.sol format 1`] = ` ====================================options===================================== -compiler: "0.5.17" parsers: ["slang"] printWidth: 80 | printWidth diff --git a/tests/format/StyleGuide/format.test.js b/tests/format/StyleGuide/format.test.js index 80d418f68..6021bbb0d 100644 --- a/tests/format/StyleGuide/format.test.js +++ b/tests/format/StyleGuide/format.test.js @@ -1 +1 @@ -runFormatTest(import.meta, ['slang'], { compiler: '0.5.17' }); +runFormatTest(import.meta, ['slang']); diff --git a/tests/format/strings/__snapshots__/format.test.js.snap b/tests/format/strings/__snapshots__/format.test.js.snap index 09408f084..d1374d40c 100644 --- a/tests/format/strings/__snapshots__/format.test.js.snap +++ b/tests/format/strings/__snapshots__/format.test.js.snap @@ -1,8 +1,7 @@ // Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing -exports[`strings.sol - {"compiler":"0.4.26"} format 1`] = ` +exports[`strings.sol format 1`] = ` ====================================options===================================== -compiler: "0.4.26" parsers: ["slang"] printWidth: 80 | printWidth diff --git a/tests/format/strings/format.test.js b/tests/format/strings/format.test.js index 85c6f9a33..6021bbb0d 100644 --- a/tests/format/strings/format.test.js +++ b/tests/format/strings/format.test.js @@ -1 +1 @@ -runFormatTest(import.meta, ['slang'], { compiler: '0.4.26' }); +runFormatTest(import.meta, ['slang']); diff --git a/tests/unit/slang-utils/create-parser.test.js b/tests/unit/slang-utils/create-parser.test.js index ed318b31e..cc28ce06a 100644 --- a/tests/unit/slang-utils/create-parser.test.js +++ b/tests/unit/slang-utils/create-parser.test.js @@ -9,7 +9,7 @@ describe('inferLanguage', function () { { description: 'Caret range', source: `pragma solidity ^0.7.0;`, - version: '0.7.0' + version: '0.7.6' }, { description: 'Pinned version', @@ -106,8 +106,8 @@ describe('inferLanguage', function () { })); expect(parser.languageVersion).toEqual('0.8.2'); - ({ parser } = createParser(`pragma solidity ^0.8.0;`, {})); - expect(parser.languageVersion).toEqual('0.8.0'); + ({ parser } = createParser(`pragma solidity ^0.7.0;`, {})); + expect(parser.languageVersion).toEqual('0.7.6'); }); test('should throw if compiler option does not match the syntax', function () {