From: Ardis Lu Date: Sun, 11 Feb 2024 01:20:02 +0000 (-0800) Subject: Parse multi-line event definitions X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=10c8e439d8c4d2228412cf1ad936742f16098784;p=event-hashes Parse multi-line event definitions --- diff --git a/README.md b/README.md index 1bbca9e..2a872b7 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,6 @@ This is a minimal web utility to calculate the `keccak256` hashes of the normali > [!WARNING]
> **Known issues:** > - This tool won't work with [user-defined value types](https://docs.soliditylang.org/en/latest/types.html#user-defined-value-types). For events that include these types, you must manually convert the user-defined value type into its equivalent primitive type. -> - This tool won't work with multi-line event definitions. For events that span multiple lines, you must manually collapse the definition into one line. ## Example diff --git a/index.html b/index.html index 0197bf8..2707025 100644 --- a/index.html +++ b/index.html @@ -270,6 +270,18 @@ strict = true; continue; } + // Basic lookahead for event definitions that span multiple lines + if ((line.match(/\(/g)?.length ?? 0) > (line.match(/\)/g)?.length ?? 0)) { + const start = code.indexOf(line); + const end = code.indexOf(')', start); + const lookaheadLine = code.substring(start, end + 1).replaceAll('\n', ''); + try { + const normalizedEvent = normalizeEvent(lookaheadLine, strict); + events.add(normalizedEvent); + } + catch { } + continue; + } try { const normalizedEvent = normalizeEvent(line, strict); events.add(normalizedEvent);