Note: There are a few cases of duplicates in user autocompletion which are being worked on.

Function#toString on a class prints more than it should

RESOLVED FIXED in Firefox 55

Status

()

Core
JavaScript Engine
RESOLVED FIXED
3 months ago
3 months ago

People

(Reporter: mgol, Unassigned)

Tracking

Trunk
mozilla55
Points:
---

Firefox Tracking Flags

(firefox55 fixed)

Details

Attachments

(1 attachment)

(Reporter)

Description

3 months ago
The following code:

(class C {}) + ''

evaluates to:

"class C {})"

instead of the correct:

"class C {}"

This works fine in current Chrome, Safari & Edge.

The bug exists in latest Nightly, i.e. "55.0a1 (2017-04-18)".
Blocks: 1216630
Oh goddammit.
The bug is that for class expressions without constructors, the ClassNode's pn_pos holds the source offsets. For some reason, parsing parenthesized expressions sets the inner expression's end position to include the right paren, which is what manifests this bug.

I'm seeing what happens if we just... don't do that.
Created attachment 8860221 [details] [diff] [review]
Stop changing the end position of parenthesized expression ParseNodes.
Attachment #8860221 - Flags: review?(jwalden+bmo)
Comment on attachment 8860221 [details] [diff] [review]
Stop changing the end position of parenthesized expression ParseNodes.

Review of attachment 8860221 [details] [diff] [review]:
-----------------------------------------------------------------

::: js/src/tests/ecma_6/Class/parenExprToString.js
@@ +1,5 @@
> +// Test that parenthesized class expressions don't get their toString offsets
> +// messed up.
> +
> +assertEq((class {}) + '', "class {}");
> +assertEq(((class {})) + '', "class {}");

Might as well invoke .toString() directly on them for utmost clarity, no?
Attachment #8860221 - Flags: review?(jwalden+bmo) → review+

Comment 5

3 months ago
Pushed by shu@rfrn.org:
https://hg.mozilla.org/integration/mozilla-inbound/rev/e064b7cde203
Stop changing the end position of parenthesized expression ParseNodes. (r=Waldo)
https://hg.mozilla.org/mozilla-central/rev/e064b7cde203
Status: NEW → RESOLVED
Last Resolved: 3 months ago
status-firefox55: affected → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla55
You need to log in before you can comment on or make changes to this bug.