Skip to content

Commit

Permalink
Check slang supports version
Browse files Browse the repository at this point in the history
  • Loading branch information
ericglau committed Sep 9, 2024
1 parent 034feb9 commit a1d7379
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions packages/core/src/utils/make-namespaced.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,15 @@ 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.
*/
function tryRemoveNonStructNatSpec(origContent: string, solcVersion: string | undefined): string {
const natSpecRemovals: Modification[] = [];

if (solcVersion !== undefined && tryRequire('@nomicfoundation/slang')) {
if (solcVersion !== undefined && slangSupportsPlatformAndVersion(solcVersion)) {
/* eslint-disable @typescript-eslint/no-var-requires */
const { Language } = require('@nomicfoundation/slang/language');
const { NonterminalKind, TerminalKind } = require('@nomicfoundation/slang/kinds');
Expand Down Expand Up @@ -217,6 +217,21 @@ function tryRequire(id: string) {
return false;
}

/**
* Whether Slang is supported for the current platform and the given compiler version.
*/
function slangSupportsPlatformAndVersion(solcVersion: string): boolean {
if (tryRequire('@nomicfoundation/slang')) {
/* 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);
} else {
return false;
}
}

interface Modification {
start: number;
end: number;
Expand Down

0 comments on commit a1d7379

Please sign in to comment.