Skip to content

Commit

Permalink
fixup super support
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Apr 18, 2020
1 parent cb06fde commit 80311c8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
8 changes: 8 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ function maybeParseFieldValue(field) {
}

module.exports = function(Parser) {
/*const getter = Object.getOwnPropertyDescriptor(Parser, 'allowSuper').get;
Object.defineProperty(Parser, 'allowSuper', {
get () {
return getter() || fi
}
})*/
Parser = privateClassElements(Parser)
return class extends Parser {
// Parse fields
Expand All @@ -41,7 +47,9 @@ module.exports = function(Parser) {
(node.key.type === "Literal" && node.key.value === "constructor")) {
this.raise(node.key.start, "Classes may not have a field called constructor")
}
this.enterScope(67);
maybeParseFieldValue.call(this, node)
this.exitScope();
this.finishNode(node, "FieldDefinition")
this.semicolon()
return node
Expand Down
22 changes: 21 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ function testFail(text, expectedResult, additionalOptions) {
const newNode = (start, props) => Object.assign(new acorn.Node({options: {}}, start), props)

describe("acorn-class-fields", function () {
test(`class P extends Q {
x = super.x
}`)

test(`class Counter extends HTMLElement {
x = 0;
Expand All @@ -38,6 +42,22 @@ describe("acorn-class-fields", function () {
}
}`)

test(`
class AsyncIterPipe{
static get [ Symbol.species](){
return Promise
}
static get Closing(){
return Closing
}
static get controllerSignals(){ return controllerSignals}
static get listenerBinding(){ return listenerBinding}
// state
done= false
}
`)

test(`class Counter extends HTMLElement {
#x = 0;
Expand All @@ -58,7 +78,7 @@ describe("acorn-class-fields", function () {
testFail("class A { constructor = 4 }", "Classes may not have a field called constructor (1:10)")
testFail("class A { #constructor = 4 }", "Classes may not have a private element named constructor (1:10)")
testFail("class A { a = () => arguments }", "A class field initializer may not contain arguments (1:20)")
testFail("class A { a = () => super() }", "'super' keyword outside a method (1:20)")
testFail("class A { a = () => super() }", "super() call outside constructor of a subclass (1:20)")
testFail("class A { # a }", "Unexpected token (1:10)")
testFail("class A { #a; a() { this.# a } }", "Unexpected token (1:27)")

Expand Down

0 comments on commit 80311c8

Please sign in to comment.