Fix parsing of nested classes with private fields

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.
This commit is contained in:
Karl Cheng
2017-06-23 16:14:41 +10:00
parent 43dba7e7c1
commit b4e06aa279
6 changed files with 3404 additions and 5 deletions

View File

@@ -0,0 +1,40 @@
class Point {
#x = 1;
#y = 2;
constructor(x = 0, y = 0) {
#x = +x;
#y = +y;
this.foo = class {
#x = 1;
#y = 2;
constructor(x = 0, y = 0) {
#x = +x;
#y = +y;
}
get x() { return #x }
set x(value) { #x = +value }
get y() { return #y }
set y(value) { #y = +value }
equals(p) { return #x === p.#x && #y === p.#y }
toString() { return `Point<${ #x },${ #y }>` }
};
}
get x() { return #x }
set x(value) { #x = +value }
get y() { return #y }
set y(value) { #y = +value }
equals(p) { return #x === p.#x && #y === p.#y }
toString() { return `Point<${ #x },${ #y }>` }
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,3 @@
{
"plugins": ["classProperties", "classPrivateProperties"]
}