Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds the
accessor
modifier to public and private class properties.
This is the first part of the implementation of the latest version of the decorators proposal: https://github.com/tc39/proposal-decorators The keyword is outlined here in the README: https://github.com/tc39/proposal-decorators#class-auto-accessors
- Loading branch information
Showing
14 changed files
with
253 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
...abel-parser/test/fixtures/experimental/decorators-modern/accessor/basic-accessor/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Foo { | ||
accessor bar; | ||
} |
42 changes: 42 additions & 0 deletions
42
...l-parser/test/fixtures/experimental/decorators-modern/accessor/basic-accessor/output.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":29,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":29,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"sourceType": "script", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ClassDeclaration", | ||
"start":0,"end":29,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":6,"end":9,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":9},"identifierName":"Foo"}, | ||
"name": "Foo" | ||
}, | ||
"superClass": null, | ||
"body": { | ||
"type": "ClassBody", | ||
"start":10,"end":29,"loc":{"start":{"line":1,"column":10},"end":{"line":3,"column":1}}, | ||
"body": [ | ||
{ | ||
"type": "ClassProperty", | ||
"start":14,"end":27,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":15}}, | ||
"static": false, | ||
"key": { | ||
"type": "Identifier", | ||
"start":23,"end":26,"loc":{"start":{"line":2,"column":11},"end":{"line":2,"column":14},"identifierName":"bar"}, | ||
"name": "bar" | ||
}, | ||
"computed": false, | ||
"accessor": true, | ||
"value": null | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...arser/test/fixtures/experimental/decorators-modern/accessor/field-named-accessor/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Foo { | ||
accessor = 123; | ||
} |
50 changes: 50 additions & 0 deletions
50
...er/test/fixtures/experimental/decorators-modern/accessor/field-named-accessor/output.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":31,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":31,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"sourceType": "script", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ClassDeclaration", | ||
"start":0,"end":31,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":6,"end":9,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":9},"identifierName":"Foo"}, | ||
"name": "Foo" | ||
}, | ||
"superClass": null, | ||
"body": { | ||
"type": "ClassBody", | ||
"start":10,"end":31,"loc":{"start":{"line":1,"column":10},"end":{"line":3,"column":1}}, | ||
"body": [ | ||
{ | ||
"type": "ClassProperty", | ||
"start":14,"end":29,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":17}}, | ||
"static": false, | ||
"key": { | ||
"type": "Identifier", | ||
"start":14,"end":22,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":10},"identifierName":"accessor"}, | ||
"name": "accessor" | ||
}, | ||
"computed": false, | ||
"accessor": false, | ||
"value": { | ||
"type": "NumericLiteral", | ||
"start":25,"end":28,"loc":{"start":{"line":2,"column":13},"end":{"line":2,"column":16}}, | ||
"extra": { | ||
"rawValue": 123, | ||
"raw": "123" | ||
}, | ||
"value": 123 | ||
} | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...rser/test/fixtures/experimental/decorators-modern/accessor/method-named-accessor/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Foo { | ||
accessor() {} | ||
} |
51 changes: 51 additions & 0 deletions
51
...r/test/fixtures/experimental/decorators-modern/accessor/method-named-accessor/output.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":29,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":29,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"sourceType": "script", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ClassDeclaration", | ||
"start":0,"end":29,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":6,"end":9,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":9},"identifierName":"Foo"}, | ||
"name": "Foo" | ||
}, | ||
"superClass": null, | ||
"body": { | ||
"type": "ClassBody", | ||
"start":10,"end":29,"loc":{"start":{"line":1,"column":10},"end":{"line":3,"column":1}}, | ||
"body": [ | ||
{ | ||
"type": "ClassMethod", | ||
"start":14,"end":27,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":15}}, | ||
"static": false, | ||
"key": { | ||
"type": "Identifier", | ||
"start":14,"end":22,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":10},"identifierName":"accessor"}, | ||
"name": "accessor" | ||
}, | ||
"computed": false, | ||
"kind": "method", | ||
"id": null, | ||
"generator": false, | ||
"async": false, | ||
"params": [], | ||
"body": { | ||
"type": "BlockStatement", | ||
"start":25,"end":27,"loc":{"start":{"line":2,"column":13},"end":{"line":2,"column":15}}, | ||
"body": [], | ||
"directives": [] | ||
} | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...ser/test/fixtures/experimental/decorators-modern/accessor/not-allowed-on-methods/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class Foo { | ||
accessor bar() { | ||
|
||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...test/fixtures/experimental/decorators-modern/accessor/not-allowed-on-methods/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"throws": "Unexpected token (2:14)" | ||
} |
3 changes: 3 additions & 0 deletions
3
...el-parser/test/fixtures/experimental/decorators-modern/accessor/private-accessor/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Foo { | ||
accessor #bar; | ||
} |
46 changes: 46 additions & 0 deletions
46
...parser/test/fixtures/experimental/decorators-modern/accessor/private-accessor/output.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"type": "File", | ||
"start":0,"end":30,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"program": { | ||
"type": "Program", | ||
"start":0,"end":30,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"sourceType": "script", | ||
"interpreter": null, | ||
"body": [ | ||
{ | ||
"type": "ClassDeclaration", | ||
"start":0,"end":30,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":6,"end":9,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":9},"identifierName":"Foo"}, | ||
"name": "Foo" | ||
}, | ||
"superClass": null, | ||
"body": { | ||
"type": "ClassBody", | ||
"start":10,"end":30,"loc":{"start":{"line":1,"column":10},"end":{"line":3,"column":1}}, | ||
"body": [ | ||
{ | ||
"type": "ClassPrivateProperty", | ||
"start":14,"end":28,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":16}}, | ||
"static": false, | ||
"key": { | ||
"type": "PrivateName", | ||
"start":23,"end":27,"loc":{"start":{"line":2,"column":11},"end":{"line":2,"column":15}}, | ||
"id": { | ||
"type": "Identifier", | ||
"start":24,"end":27,"loc":{"start":{"line":2,"column":12},"end":{"line":2,"column":15},"identifierName":"bar"}, | ||
"name": "bar" | ||
} | ||
}, | ||
"computed": false, | ||
"accessor": true, | ||
"value": null | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"directives": [] | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/babel-parser/test/fixtures/experimental/decorators-modern/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"plugins": [["decorators", { "decoratorsBeforeExport": false, "version": "modern" }]] | ||
} |