From 10c8e439d8c4d2228412cf1ad936742f16098784 Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Sat, 10 Feb 2024 17:20:02 -0800 Subject: [PATCH] Parse multi-line event definitions --- README.md | 1 - index.html | 12 ++++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) 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); -- 2.47.3