Skip to content
This repository has been archived by the owner. It is now read-only.

Add delete check and fix nested class parsing for private fields #589

Merged
merged 3 commits into from Jun 27, 2017

Conversation

@Qantas94Heavy
Copy link
Member

Qantas94Heavy commented Jun 23, 2017

Q A
Bug fix? yes
Breaking change? no
New feature? no
Deprecations? no
Spec compliancy? yes
Tests added/pass? yes
Fixed tickets N/A
License MIT

This PR adds a check to make sure the delete operator is not applied to a private field (spec).

This also fixes an issue where private fields fail to be parsed when a method within the class contains a nested class.

@Qantas94Heavy Qantas94Heavy force-pushed the Qantas94Heavy:fix-private-fields branch from 8c54227 to 9d5b9db Jun 23, 2017
if (arg.type === "Identifier") {
this.raise(node.start, "Deleting local variable in strict mode");
} else if (this.hasPlugin("classPrivateProperties")) {
if (arg.type === "PrivateName" || arg.property.type === "PrivateName") {

This comment has been minimized.

Copy link
@Jessidhia

Jessidhia Jun 23, 2017

Member

Is the argument always guaranteed to be Identifier, PrivateName or MemberExpression?

If it happens to be neither PrivateName or MemberExpression in this branch it could throw TypeError.

This comment has been minimized.

Copy link
@Qantas94Heavy

Qantas94Heavy Jun 23, 2017

Author Member

Right -- I'll add a check for MemberExpression.

Given that private fields can only be used within classes, any code
using them must be in a strict mode context. As private fields cannot
be deleted, throw an early SyntaxError.
The parsing of private fields checks whether or not it is within a
class to determine if it is valid or not. However, the state.inClass
property is incorrect as it marks it as outside a class when the inner
class is closed.

This commit fixes this problem by replacing the state.inClass property
with a class nesting counter.
@Qantas94Heavy Qantas94Heavy force-pushed the Qantas94Heavy:fix-private-fields branch from 9d5b9db to 44d842c Jun 23, 2017
#y = +y;


this.foo = class {

This comment has been minimized.

Copy link
@hzoo

hzoo Jun 23, 2017

Member

I'm already like why would you ever do this 🙂 but ok.

@hzoo
hzoo approved these changes Jun 23, 2017
Copy link
Member

existentialism left a comment

Nice work!

@hzoo hzoo merged commit 994cde6 into babel:master Jun 27, 2017
3 checks passed
3 checks passed
codecov/patch 100% of diff hit (target 98%)
Details
codecov/project 98.06% (+0.05%) compared to f976bdd
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@hzoo hzoo added the Tag: Bug Fix label Jun 27, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
5 participants
You can’t perform that action at this time.