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 3 commits into from Jun 27, 2017


Copy link

Qantas94Heavy commented Jun 23, 2017

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" || === "PrivateName") {

This comment has been minimized.

Copy link

Jessidhia Jun 23, 2017


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 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; = class {

This comment has been minimized.

Copy link

hzoo Jun 23, 2017


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

hzoo approved these changes Jun 23, 2017
Copy link

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%)
codecov/project 98.06% (+0.05%) compared to f976bdd
continuous-integration/travis-ci/pr The Travis CI build passed
@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.
None yet
5 participants
You can’t perform that action at this time.