Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tpoikela opened this issue May 11, 2023 · 1 comment

Comments

@tpoikela
Copy link

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
Copy link

boorbajones commented Jul 3, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants