wavedrom / cli

CLI for WaveDrom
https://wavedrom.com
MIT License
61 stars 12 forks source link

Javascript Immediately Invoked Function Expression (IIFE) is not supported #23

Open tpoikela opened 1 year ago

tpoikela commented 1 year ago

Wavedrom GUI supports IIFE, but wavedrom-cli does not. It would be good to have better compatibility between the 2 tools, to avoid having to convert existing .js files to .json5.

This is the output when trying to convert .js files:

Error:
SyntaxError: JSON5: invalid character '(' at 1:1
    at syntaxError (C:\Users\XYZI\Apps_DONT_DELETE\node-v18.15.0-win-x64\node_modules\wavedrom-cli\node_modules\json5\lib\parse.js:1110:17)

Expected result: IIFE would be evaluated first, then its returned result would be used to create the waveform.

boorbajones commented 5 months ago

I have a very similar result with recent (July 2024) wavedrom-cli.js; to reproduce, try it with the Hitchhiker's Guide closing example (that features an IIFE): on Web editor it works fine, with the downloaded wavedrom-cli.js it does not (error very similar to that reported by tpoikeka). Other Hitchhikers' examples I tried worked fine.

To reproduce:

Error message:

$HOME/node_modules/json5/lib/parse.js:309 throw invalidChar(read()) ^

SyntaxError: JSON5: invalid character '(' at 1:1 at syntaxError ($HOME/node_modules/json5/lib/parse.js:1110:17) at invalidChar ($HOME/node_modules/json5/lib/parse.js:1055:12) at Object.value ($HOME/node_modules/json5/lib/parse.js:309:15) at lex ($HOME/node_modules/json5/lib/parse.js:100:42) at Object.parse ($HOME/node_modules/json5/lib/parse.js:25:17) at $HOME/misc/wavedrom/git/wavedrom-cli.js:37:24 at $HOME/node_modules/graceful-fs/graceful-fs.js:123:16 at FSReqCallback.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:63:3) { lineNumber: 1, columnNumber: 1 }

Code:

(function (P,F,T) { var i,data = []; for (i = 0; i < P; i++) { data.push(String.fromCharCode(F.charCodeAt(0)+i)) }; data.push(T); return {signal: [ {name: 'clk', wave: "p"+".".repeat(P-1)+"|p."}, {name: 'bin', wave: '='.repeat(P)+"|=x", data: data} ]}; })(5,"d","z")

Working fine with

https://wavedrom.com/editor.html

OS: The issue happens on CentOS 7.9

Version: wavedrom-cli --version

3.2.0