From 5c442f18921cb04a76e4e5b196b15ba1cda38bd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Thu, 28 May 2020 16:54:14 -0400 Subject: [PATCH 01/10] add class features --- experimental/class-features.md | 61 ++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 experimental/class-features.md diff --git a/experimental/class-features.md b/experimental/class-features.md new file mode 100644 index 0000000..bba874f --- /dev/null +++ b/experimental/class-features.md @@ -0,0 +1,61 @@ + +# Class Features + +This experimental extension covers three class features proposals: +[Class Fields], [Static Class Features] and [Private Methods]. + +## PropertyDefinition + +```js +interface PropertyDefinition <: Node { + type: "PropertyDefinition"; + key: Expression; + value: Expression; + computed: boolean; + static: boolean; +} +``` + +## PrivatePropertyDefinition + +```js +interface PrivatePropertyDefinition <: Node { + type: "PrivatePropertyDefinition"; + key: PrivateName; + value: Expression; + static: boolean; +} +``` + +## PrivateMethodDefinition + +```js +interface PrivateMethodDefinition <: Node { + type: "PrivateMethodDefinition"; + key: PrivateName; + value: FunctionExpression; + kind: "method" | "get" | "set"; + static: boolean; +} +``` + +### PrivateName + +```js +interface PrivateName <: Node { + type: "PrivateName"; + id: Identifier; +} + +extend interface MemberExpression { + property: Expression | PrivateName +} +``` + +A private name refers to private class elements. For a private name `#a`, its `id.name` is `a`. + +When the property of a member expression is a private name, its `computed` is always `false`. + +[Class Fields]: https://github.com/tc39/proposal-class-fields +[Static Class Features]: https://github.com/tc39/proposal-static-class-features/ +[Private Methods]: https://github.com/tc39/proposal-private-methods \ No newline at end of file From 886847c187ce887f8c8d4ac20737b11bd1e75873 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Thu, 4 Jun 2020 23:15:08 -0400 Subject: [PATCH 02/10] Merge PrivateDefinition and PublicDefinition --- experimental/class-features.md | 38 ++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/experimental/class-features.md b/experimental/class-features.md index bba874f..7a5d0fe 100644 --- a/experimental/class-features.md +++ b/experimental/class-features.md @@ -4,41 +4,43 @@ This experimental extension covers three class features proposals: [Class Fields], [Static Class Features] and [Private Methods]. -## PropertyDefinition +## ClassBody ```js -interface PropertyDefinition <: Node { - type: "PropertyDefinition"; - key: Expression; - value: Expression; - computed: boolean; - static: boolean; +extend interface ClassBody <: Node { + body: [ MethodDefinition | PropertyDefinition ]; } ``` -## PrivatePropertyDefinition +## PropertyDefinition ```js -interface PrivatePropertyDefinition <: Node { - type: "PrivatePropertyDefinition"; - key: PrivateName; +interface PropertyDefinition <: Node { + type: "PropertyDefinition"; + key: Expression | PrivateName; value: Expression; + computed: boolean; static: boolean; + private: boolean; } ``` -## PrivateMethodDefinition +- When `private` is `true`, `computed` must be `false` and `key` must be a `PrivateName`. +- When `private` is `false`, `key` must be an `Expression` and can not be a `PrivateName`. + +## MethodDefinition ```js -interface PrivateMethodDefinition <: Node { - type: "PrivateMethodDefinition"; - key: PrivateName; - value: FunctionExpression; - kind: "method" | "get" | "set"; +extend interface MethodDefinition <: Node { + key: Expression | PrivateName; static: boolean; + private: boolean; } ``` +- When `private` is `true`, `computed` must be `false`, `key` must be a `PrivateName`, `kind` can not be `constructor`. +- When `private` is `false`, `key` must be an `Expression` and can not be a `PrivateName`. + ### PrivateName ```js @@ -54,7 +56,7 @@ extend interface MemberExpression { A private name refers to private class elements. For a private name `#a`, its `id.name` is `a`. -When the property of a member expression is a private name, its `computed` is always `false`. +When the `property` of a `MemberExpression` is a `PrivateName`, `computed` is always `false`. [Class Fields]: https://github.com/tc39/proposal-class-fields [Static Class Features]: https://github.com/tc39/proposal-static-class-features/ From ec271024f668698da72f0eee269ab906c096cf9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Fri, 5 Jun 2020 10:52:03 -0400 Subject: [PATCH 03/10] add private: boolean to MemberExpression --- experimental/class-features.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/experimental/class-features.md b/experimental/class-features.md index 7a5d0fe..a0e9121 100644 --- a/experimental/class-features.md +++ b/experimental/class-features.md @@ -48,15 +48,19 @@ interface PrivateName <: Node { type: "PrivateName"; id: Identifier; } +``` -extend interface MemberExpression { - property: Expression | PrivateName +```js +extend interface MemberExpression <: ChainElement { + private: boolean; + property: Expression | PrivateName; } ``` A private name refers to private class elements. For a private name `#a`, its `id.name` is `a`. -When the `property` of a `MemberExpression` is a `PrivateName`, `computed` is always `false`. +- When `private` is `true`, `property` must be a `PrivateName`, `computed` must be `false`. +- When `object` is a `Super`, `private` must be `false`. [Class Fields]: https://github.com/tc39/proposal-class-fields [Static Class Features]: https://github.com/tc39/proposal-static-class-features/ From de6148e32978cb6bc2c9db26e1cbce1bf747834f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Fri, 5 Jun 2020 11:20:56 -0400 Subject: [PATCH 04/10] initializer is optional --- experimental/class-features.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/experimental/class-features.md b/experimental/class-features.md index a0e9121..29389a6 100644 --- a/experimental/class-features.md +++ b/experimental/class-features.md @@ -18,7 +18,7 @@ extend interface ClassBody <: Node { interface PropertyDefinition <: Node { type: "PropertyDefinition"; key: Expression | PrivateName; - value: Expression; + value: Expression | null; computed: boolean; static: boolean; private: boolean; From 0125693db5cdb51e5779de780058bc70096fe7c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Fri, 5 Jun 2020 12:03:45 -0400 Subject: [PATCH 05/10] update PrivateName interface --- experimental/class-features.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/experimental/class-features.md b/experimental/class-features.md index 29389a6..55faeed 100644 --- a/experimental/class-features.md +++ b/experimental/class-features.md @@ -46,7 +46,7 @@ extend interface MethodDefinition <: Node { ```js interface PrivateName <: Node { type: "PrivateName"; - id: Identifier; + name: string; } ``` @@ -57,7 +57,7 @@ extend interface MemberExpression <: ChainElement { } ``` -A private name refers to private class elements. For a private name `#a`, its `id.name` is `a`. +A private name refers to private class elements. For a private name `#a`, its `name` is `a`. - When `private` is `true`, `property` must be a `PrivateName`, `computed` must be `false`. - When `object` is a `Super`, `private` must be `false`. From b1ba831e9d8826d2fd76c6b8c803fdb1b99c6a66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Fri, 5 Jun 2020 12:22:04 -0400 Subject: [PATCH 06/10] refine text --- experimental/class-features.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/experimental/class-features.md b/experimental/class-features.md index 55faeed..b705a84 100644 --- a/experimental/class-features.md +++ b/experimental/class-features.md @@ -38,8 +38,9 @@ extend interface MethodDefinition <: Node { } ``` -- When `private` is `true`, `computed` must be `false`, `key` must be a `PrivateName`, `kind` can not be `constructor`. +- When `private` is `true`, `computed` must be `false`, `key` must be a `PrivateName`, `kind` can not be `"constructor"`. - When `private` is `false`, `key` must be an `Expression` and can not be a `PrivateName`. +- When `static` is `true`, `kind` can not be `"constructor"`. ### PrivateName @@ -50,6 +51,8 @@ interface PrivateName <: Node { } ``` +A private name refers to private class elements. For a private name `#a`, its `name` is `a`. + ```js extend interface MemberExpression <: ChainElement { private: boolean; @@ -57,9 +60,8 @@ extend interface MemberExpression <: ChainElement { } ``` -A private name refers to private class elements. For a private name `#a`, its `name` is `a`. - - When `private` is `true`, `property` must be a `PrivateName`, `computed` must be `false`. +- When `private` is `false`, `property` must be an `Expression` and can not be a `PrivateName`. - When `object` is a `Super`, `private` must be `false`. [Class Fields]: https://github.com/tc39/proposal-class-fields From 083f826451fa83626d5ec2e2343981b4cfeeeac0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Fri, 5 Jun 2020 15:02:31 -0400 Subject: [PATCH 07/10] Update experimental/class-features.md Co-authored-by: Ingvar Stepanyan --- experimental/class-features.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/experimental/class-features.md b/experimental/class-features.md index b705a84..aeb1df3 100644 --- a/experimental/class-features.md +++ b/experimental/class-features.md @@ -31,7 +31,7 @@ interface PropertyDefinition <: Node { ## MethodDefinition ```js -extend interface MethodDefinition <: Node { +extend interface MethodDefinition { key: Expression | PrivateName; static: boolean; private: boolean; @@ -66,4 +66,4 @@ extend interface MemberExpression <: ChainElement { [Class Fields]: https://github.com/tc39/proposal-class-fields [Static Class Features]: https://github.com/tc39/proposal-static-class-features/ -[Private Methods]: https://github.com/tc39/proposal-private-methods \ No newline at end of file +[Private Methods]: https://github.com/tc39/proposal-private-methods From 19f342e1dbb0fb8dc2b2de25a0bbe0dcf8e2350b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Fri, 5 Jun 2020 15:23:45 -0400 Subject: [PATCH 08/10] address review comments --- experimental/class-features.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/experimental/class-features.md b/experimental/class-features.md index aeb1df3..c85dc31 100644 --- a/experimental/class-features.md +++ b/experimental/class-features.md @@ -7,7 +7,7 @@ This experimental extension covers three class features proposals: ## ClassBody ```js -extend interface ClassBody <: Node { +extend interface ClassBody { body: [ MethodDefinition | PropertyDefinition ]; } ``` @@ -33,14 +33,12 @@ interface PropertyDefinition <: Node { ```js extend interface MethodDefinition { key: Expression | PrivateName; - static: boolean; private: boolean; } ``` - When `private` is `true`, `computed` must be `false`, `key` must be a `PrivateName`, `kind` can not be `"constructor"`. - When `private` is `false`, `key` must be an `Expression` and can not be a `PrivateName`. -- When `static` is `true`, `kind` can not be `"constructor"`. ### PrivateName @@ -54,7 +52,7 @@ interface PrivateName <: Node { A private name refers to private class elements. For a private name `#a`, its `name` is `a`. ```js -extend interface MemberExpression <: ChainElement { +extend interface MemberExpression { private: boolean; property: Expression | PrivateName; } From 04a28416d7e2b742acfcd37d03f8555c201a646f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Mon, 8 Jun 2020 09:42:17 -0400 Subject: [PATCH 09/10] PrivateName => PrivateIdentifier --- experimental/class-features.md | 24 ++++++++++++------------ experimental/private-fields-in-in.md | 4 ++-- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/experimental/class-features.md b/experimental/class-features.md index c85dc31..df57435 100644 --- a/experimental/class-features.md +++ b/experimental/class-features.md @@ -17,7 +17,7 @@ extend interface ClassBody { ```js interface PropertyDefinition <: Node { type: "PropertyDefinition"; - key: Expression | PrivateName; + key: Expression | PrivateIdentifier; value: Expression | null; computed: boolean; static: boolean; @@ -25,26 +25,26 @@ interface PropertyDefinition <: Node { } ``` -- When `private` is `true`, `computed` must be `false` and `key` must be a `PrivateName`. -- When `private` is `false`, `key` must be an `Expression` and can not be a `PrivateName`. +- When `private` is `true`, `computed` must be `false` and `key` must be a `PrivateIdentifier`. +- When `private` is `false`, `key` must be an `Expression` and can not be a `PrivateIdentifier`. ## MethodDefinition ```js extend interface MethodDefinition { - key: Expression | PrivateName; + key: Expression | PrivateIdentifier; private: boolean; } ``` -- When `private` is `true`, `computed` must be `false`, `key` must be a `PrivateName`, `kind` can not be `"constructor"`. -- When `private` is `false`, `key` must be an `Expression` and can not be a `PrivateName`. +- When `private` is `true`, `computed` must be `false`, `key` must be a `PrivateIdentifier`, `kind` can not be `"constructor"`. +- When `private` is `false`, `key` must be an `Expression` and can not be a `PrivateIdentifier`. -### PrivateName +### PrivateIdentifier ```js -interface PrivateName <: Node { - type: "PrivateName"; +interface PrivateIdentifier <: Node { + type: "PrivateIdentifier"; name: string; } ``` @@ -54,12 +54,12 @@ A private name refers to private class elements. For a private name `#a`, its `n ```js extend interface MemberExpression { private: boolean; - property: Expression | PrivateName; + property: Expression | PrivateIdentifier; } ``` -- When `private` is `true`, `property` must be a `PrivateName`, `computed` must be `false`. -- When `private` is `false`, `property` must be an `Expression` and can not be a `PrivateName`. +- When `private` is `true`, `property` must be a `PrivateIdentifier`, `computed` must be `false`. +- When `private` is `false`, `property` must be an `Expression` and can not be a `PrivateIdentifier`. - When `object` is a `Super`, `private` must be `false`. [Class Fields]: https://github.com/tc39/proposal-class-fields diff --git a/experimental/private-fields-in-in.md b/experimental/private-fields-in-in.md index 9a680ed..f6e9a1b 100644 --- a/experimental/private-fields-in-in.md +++ b/experimental/private-fields-in-in.md @@ -6,10 +6,10 @@ ```js extend interface BinaryExpression <: Expression { - left: Expression | PrivateName; + left: Expression | PrivateIdentifier; } ``` -- `left` can be a private name (e.g. `#foo`) when `operator` is `"in"`. +- `left` can be a private identifier (e.g. `#foo`) when `operator` is `"in"`. [proposal-private-fields-in-in]: https://github.com/tc39/proposal-private-fields-in-in From 8759fc8bde8ce293cba4d5e44a1e89398e144a54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Mon, 8 Jun 2020 10:00:50 -0400 Subject: [PATCH 10/10] remove `private` property with respect to the Unique philosophy --- experimental/class-features.md | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/experimental/class-features.md b/experimental/class-features.md index df57435..63c37e4 100644 --- a/experimental/class-features.md +++ b/experimental/class-features.md @@ -21,24 +21,20 @@ interface PropertyDefinition <: Node { value: Expression | null; computed: boolean; static: boolean; - private: boolean; } ``` -- When `private` is `true`, `computed` must be `false` and `key` must be a `PrivateIdentifier`. -- When `private` is `false`, `key` must be an `Expression` and can not be a `PrivateIdentifier`. +- When `key` is a `PrivateIdentifier`, `computed` must be `false`. ## MethodDefinition ```js extend interface MethodDefinition { key: Expression | PrivateIdentifier; - private: boolean; } ``` -- When `private` is `true`, `computed` must be `false`, `key` must be a `PrivateIdentifier`, `kind` can not be `"constructor"`. -- When `private` is `false`, `key` must be an `Expression` and can not be a `PrivateIdentifier`. +- When `key` is a `PrivateIdentifier`, `computed` must be `false` and `kind` can not be `"constructor"`. ### PrivateIdentifier @@ -49,18 +45,16 @@ interface PrivateIdentifier <: Node { } ``` -A private name refers to private class elements. For a private name `#a`, its `name` is `a`. +A private identifier refers to private class elements. For a private name `#a`, its `name` is `a`. ```js extend interface MemberExpression { - private: boolean; property: Expression | PrivateIdentifier; } ``` -- When `private` is `true`, `property` must be a `PrivateIdentifier`, `computed` must be `false`. -- When `private` is `false`, `property` must be an `Expression` and can not be a `PrivateIdentifier`. -- When `object` is a `Super`, `private` must be `false`. +- When `property` is a `PrivateIdentifier`, `computed` must be `false`. +- When `object` is a `Super`, `property` can not be a `PrivateIdentifier`. [Class Fields]: https://github.com/tc39/proposal-class-fields [Static Class Features]: https://github.com/tc39/proposal-static-class-features/