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

Bug - Quokka parser reports SyntaxError when optional chaining and eval are used #582

Closed
keith0305 opened this issue Feb 12, 2021 · 2 comments

Comments

@keith0305
Copy link

keith0305 commented Feb 12, 2021

Issue description or question

I was writing a function to create Javascript object (anything contained inside { } are to be made part of the object) from string.

Sample code

function extractObj(str) {
	const matchStr = str.match(/(\{.*?\})/)?.[1]?.trim(); //?
	
	/* Quokka reports SyntaxError on the statement above but if the next 2 lines are commented the statement above works fine */
	const obj = eval(`(() => (${matchStr}))()`);
	return obj;
}

extractObj(`arbitrary text { country: 'Malaysia', city: 'Kuala Lumpur' } arbitrary text`);

// the code above works fine in browser

Sample repository link

(N/A)

Quokka.js Console Output

Quokka 'Untitled-2.js' (node: v15.3.0)​​​​
 
.\quokka.js:4 
    const matchStr = ($_$w(1, 0, $_$c), $_$wv(1, 0, '1,0', $_$c, 'str.match(/(\\{.*?\\})/)?.[1]?.trim()', str.match(/(\{.*?\})/)?.[1]?.trim(), '$_$ne', 0, 0)); 
                                                                                                                                 ^ 
 
SyntaxError: Invalid or unexpected token 
    at new Promise (<anonymous>) 

Code editor version

Visual Studio Code v1.53.2

OS name and version

Windows 10

@ArtemGovorov
Copy link
Member

The issue is not related to Quokka parser, it is an issue in esm package that Quokka is using by default to support ES imports and top level await. You may turn off esm package by specifying:

{
    ...
    "stdEsm": false
}

in your Quokka configuration.

@keith0305
Copy link
Author

Okay got it. Pardon my ignorance on the internals of Quokka. Cheers.

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