-
Notifications
You must be signed in to change notification settings - Fork 2k
Allow computed class properties #5206
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
Changes from all 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.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
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 |
---|---|---|
|
@@ -2007,7 +2007,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 = | ||
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 is the fix for the invalid JS for non-static computed class properties (extracted from #5205) |
||
if base instanceof ComputedPropertyName | ||
new Index base.value | ||
else | ||
new (if base.shouldCache() then Index else Access) base | ||
prototype = new Access new PropertyName 'prototype' | ||
variable = new Value new ThisLiteral(), [ prototype, name ] | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,14 +118,21 @@ exports.Rewriter = class Rewriter | |
# The lexer has tagged the opening bracket of an indexing operation call. | ||
# Match it with its paired close. | ||
closeOpenIndexes: -> | ||
startToken = null | ||
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. Allowing static computed class properties/methods was a bit more complex. In addition to the new grammar rule above, in the rewriter here we first want to make sure that the I believe this is safe because there's not a scenario where an actual |
||
condition = (token, i) -> | ||
token[0] in [']', 'INDEX_END'] | ||
|
||
action = (token, i) -> | ||
token[0] = 'INDEX_END' | ||
if @tokens.length >= i and @tokens[i + 1][0] is ':' | ||
startToken[0] = '[' | ||
token[0] = ']' | ||
else | ||
token[0] = 'INDEX_END' | ||
|
||
@scanTokens (token, i) -> | ||
@detectEnd i + 1, condition, action if token[0] is 'INDEX_START' | ||
if token[0] is 'INDEX_START' | ||
startToken = token | ||
@detectEnd i + 1, condition, action | ||
1 | ||
|
||
# Match tags in token stream starting at `i` with `pattern`. | ||
|
@@ -321,7 +328,12 @@ exports.Rewriter = class Rewriter | |
if tag is ':' | ||
# Go back to the (implicit) start of the object. | ||
s = switch | ||
when @tag(i - 1) in EXPRESSION_END then start[1] | ||
when @tag(i - 1) in EXPRESSION_END | ||
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. Then, we have to make sure that for an implicit object (whether an actual implicit object or a class body) starting with a static computed property eg |
||
[startTag, startIndex] = start | ||
if startTag is '[' and startIndex > 0 and @tag(startIndex - 1) is '@' and not tokens[startIndex - 1].spaced | ||
startIndex - 1 | ||
else | ||
startIndex | ||
when @tag(i - 2) is '@' then i - 2 | ||
else i - 1 | ||
|
||
|
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.
Mostly copied this grammar rule from the rule for
ThisProperty