-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Class prototype property AST #5205
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2694,6 +2694,8 @@ exports.Class = class Class extends Base | |
@addInitializerMethod node | ||
else if not o.compiling and @validClassProperty node | ||
@addClassProperty node | ||
else if not o.compiling and @validClassPrototypeProperty node | ||
@addClassPrototypeProperty node | ||
else | ||
null | ||
|
||
|
@@ -2736,6 +2738,17 @@ exports.Class = class Class extends Base | |
operatorToken | ||
}).withLocationDataFrom assign | ||
|
||
validClassPrototypeProperty: (node) -> | ||
return no unless node instanceof Assign | ||
node.context is 'object' and not node.variable.hasProperties() | ||
|
||
addClassPrototypeProperty: (assign) -> | ||
{variable, value} = assign | ||
new ClassPrototypeProperty({ | ||
name: variable.base | ||
value | ||
}).withLocationDataFrom assign | ||
|
||
makeDefaultConstructor: -> | ||
ctor = @addInitializerMethod new Assign (new Value new PropertyName 'constructor'), new Code | ||
@body.unshift ctor | ||
|
@@ -2883,7 +2896,11 @@ exports.ExecutableClassBody = class ExecutableClassBody extends Base | |
# The class scope is not available yet, so return the assignment to update later | ||
assign = @externalCtor = new Assign new Value, value | ||
else if not assign.variable.this | ||
name = new (if base.shouldCache() then Index else Access) base | ||
name = | ||
if base instanceof ComputedPropertyName | ||
new Index base.value | ||
else | ||
new (if base.shouldCache() then Index else Access) base | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you remove the conditional logic here (so just |
||
prototype = new Access new PropertyName 'prototype' | ||
variable = new Value new ThisLiteral(), [ prototype, name ] | ||
|
||
|
@@ -2911,6 +2928,20 @@ exports.ClassProperty = class ClassProperty extends Base | |
operator: @operatorToken?.value ? '=' | ||
staticClassName: @staticClassName?.ast(o) ? null | ||
|
||
exports.ClassPrototypeProperty = class ClassPrototypeProperty extends Base | ||
constructor: ({@name, @value}) -> | ||
super() | ||
|
||
children: ['name', 'value'] | ||
|
||
isStatement: YES | ||
|
||
astProperties: (o) -> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This mimics the properties of Babel AST types like |
||
return | ||
key: @name.ast o, LEVEL_LIST | ||
value: @value.ast o, LEVEL_LIST | ||
computed: @name instanceof ComputedPropertyName | ||
|
||
#### Import and Export | ||
|
||
exports.ModuleDeclaration = class ModuleDeclaration extends Base | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the fix for #5204