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

"SyntaxError: Unexpected identifier" thrown if traced computed property contains multi-line comments #1850

Closed
miluoshi opened this issue Dec 20, 2018 · 3 comments
Labels

Comments

@miluoshi
Copy link

miluoshi commented Dec 20, 2018

The trace function with last argument set to true enables to enter the debugger when re-evaluating traced derivation. If we trace a computed property with it's getter function body containing a multiline comment /* */, the browser throws SyntaxError: Unexpected identifier error.

The logTraceInfo function is reponsible for injecting an anonymous function containing the debugger statement generated from a string. If we use trace to trace a computed value, the computed value's getter function body is converted into a string with derivation.derivation.toString() and then inserted into a comment of the generated function. By not escaping the generated string a multi-line comment is inserted as-is, thus early closing a comment in the generated function.

Example of generated string from the attached sandbox:

debugger;
/*
Tracing '[email protected]'

You are entering this break point because derivation '[email protected]' is being traced and '[email protected]' is now forcing it to update.
Just follow the stacktrace you should now see in the devtools to see precisely what piece of your code is causing this update
The stackframe you are looking for is at least ~6-8 stack-frames up.

get fullName() {
        /* multi-line comment */ <---------------- early closed comment
        return `${this.firstName} ${this.lastName}`;
    }

The dependencies for this derivation are:

[email protected]
	[email protected]
	[email protected]
*/

Sandbox to reproduce the issue:

https://codesandbox.io/s/v83p7xk80l

Suggested fix:

Escape (somehow) comments in the getter function's body string.
Inserting a space between closing comment tag (* /) should be enough.
derivation.derivation.toString() -> derivation.derivation.toString().replace(/\*\//g, '* /')

@mweststrate
Copy link
Member

Confirmed! Thanks for tracking this, I think we can fix this with a simple regex.

@mweststrate
Copy link
Member

Fixed and released in 4.9.0 / 5.9.0

@lock
Copy link

lock bot commented Jul 21, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs or questions.

@lock lock bot locked as resolved and limited conversation to collaborators Jul 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants