Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support Class field declarations #438

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions escodegen.js
Original file line number Diff line number Diff line change
Expand Up @@ -2161,6 +2161,26 @@
return join(result, fragment);
},

FieldDefinition: function(expr, precedence, flags) {
var result;
if (expr['static']) {
result = ['static' + space];
}
else {
result = [];
}
var fragment = [
this.generatePropertyKey(expr.key, expr.computed),
space + '=' +space,
this.generateExpression(expr.value, Precedence.Assignment, E_TTT)
];
return join(result, fragment);
},

PrivateName: function(expr, precedence, flags) {
return toSourceNodeWhenNeeded('#' + expr.name, expr);
},

Property: function (expr, precedence, flags) {
if (expr.kind === 'get' || expr.kind === 'set') {
return [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class FieldDeclarations{
a = 1
}
class PrivateFields{
#a = 1
}

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class FieldDeclarations{a=1}class PrivateFields{#a=1}
7 changes: 7 additions & 0 deletions test/compare-acorn-es2019/class-field-declarations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class FieldDeclarations{
a = 1
}
class PrivateFields{
#a = 1
}