From d43766a87672cb07844815a217db18d094b63ff5 Mon Sep 17 00:00:00 2001 From: Eric Lau Date: Mon, 9 Sep 2024 22:15:49 -0400 Subject: [PATCH] Skip Slang parser for solc versions that it does not support (#1075) --- packages/core/CHANGELOG.md | 4 ++++ packages/core/package.json | 2 +- packages/core/src/utils/make-namespaced.ts | 12 ++++++++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/core/CHANGELOG.md b/packages/core/CHANGELOG.md index 386aced96..2212f40d4 100644 --- a/packages/core/CHANGELOG.md +++ b/packages/core/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 1.37.1 (2024-09-09) + +- Fix Hardhat compile error when using solc version `0.8.27`. ([#1075](https://github.com/OpenZeppelin/openzeppelin-upgrades/pull/1075)) + ## 1.37.0 (2024-08-28) - **Breaking change**: CLI: Disallow self-references for storage layout validations. ([#1067](https://github.com/OpenZeppelin/openzeppelin-upgrades/pull/1067)) diff --git a/packages/core/package.json b/packages/core/package.json index c886955cb..84a50c713 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@openzeppelin/upgrades-core", - "version": "1.37.0", + "version": "1.37.1", "description": "", "repository": "https://github.com/OpenZeppelin/openzeppelin-upgrades/tree/master/packages/core", "license": "MIT", diff --git a/packages/core/src/utils/make-namespaced.ts b/packages/core/src/utils/make-namespaced.ts index cb9ab3721..ef4193fd9 100644 --- a/packages/core/src/utils/make-namespaced.ts +++ b/packages/core/src/utils/make-namespaced.ts @@ -164,7 +164,7 @@ export function makeNamespacedInput(input: SolcInput, output: SolcOutput, solcVe } /** - * If Slang is supported for the current platform and we have the compiler version available, + * If we have the compiler version available and Slang is supported for the current platform and compiler version, * use Slang to parse and remove all NatSpec comments that do not precede a struct definition and return the modified content. * * Otherwise, return the original content. @@ -172,7 +172,7 @@ export function makeNamespacedInput(input: SolcInput, output: SolcOutput, solcVe function tryRemoveNonStructNatSpec(origContent: string, solcVersion: string | undefined): string { const natSpecRemovals: Modification[] = []; - if (solcVersion !== undefined && tryRequire('@nomicfoundation/slang')) { + if (solcVersion !== undefined && tryRequire('@nomicfoundation/slang') && slangSupportsVersion(solcVersion)) { /* eslint-disable @typescript-eslint/no-var-requires */ const { Language } = require('@nomicfoundation/slang/language'); const { NonterminalKind, TerminalKind } = require('@nomicfoundation/slang/kinds'); @@ -217,6 +217,14 @@ function tryRequire(id: string) { return false; } +function slangSupportsVersion(solcVersion: string): boolean { + /* eslint-disable @typescript-eslint/no-var-requires */ + const { Language } = require('@nomicfoundation/slang/language'); + /* eslint-enable @typescript-eslint/no-var-requires */ + + return Language.supportedVersions().includes(solcVersion); +} + interface Modification { start: number; end: number;