Skip to content

Commit

Permalink
Update: add ES2022 class features support (refs eslint/eslint#14343)
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea committed Apr 28, 2021
1 parent 651e204 commit e0cd4d9
Show file tree
Hide file tree
Showing 113 changed files with 20,570 additions and 5 deletions.
3 changes: 2 additions & 1 deletion lib/options.js
Expand Up @@ -17,7 +17,8 @@ const SUPPORTED_VERSIONS = [
9,
10,
11,
12
12,
13
];

/**
Expand Down
4 changes: 4 additions & 0 deletions lib/token-translator.js
Expand Up @@ -20,6 +20,7 @@ const Token = {
Boolean: "Boolean",
EOF: "<end>",
Identifier: "Identifier",
PrivateIdentifier: "PrivateIdentifier",
Keyword: "Keyword",
Null: "Null",
Numeric: "Numeric",
Expand Down Expand Up @@ -114,6 +115,9 @@ TokenTranslator.prototype = {
token.type = Token.Keyword;
}

} else if (type === tt.privateId) {
token.type = Token.PrivateIdentifier;

} else if (type === tt.semi || type === tt.comma ||
type === tt.parenL || type === tt.parenR ||
type === tt.braceL || type === tt.braceR ||
Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -31,9 +31,9 @@
},
"license": "BSD-2-Clause",
"dependencies": {
"acorn": "^8.1.0",
"acorn": "^8.2.1",
"acorn-jsx": "^5.3.1",
"eslint-visitor-keys": "^2.0.0"
"eslint-visitor-keys": "github:eslint/eslint-visitor-keys#908fdf8c0d9a352c696c8c1f4901280d1a0795f7"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^17.1.0",
Expand Down
@@ -0,0 +1,6 @@
export default {
"index": 28,
"lineNumber": 3,
"column": 11,
"message": "Private fields can not be deleted"
};
@@ -0,0 +1,4 @@
class C {
#a;
f() { delete this?.#a }
}
@@ -0,0 +1,6 @@
export default {
"index": 28,
"lineNumber": 3,
"column": 11,
"message": "Private fields can not be deleted"
};
@@ -0,0 +1,4 @@
class C {
#a;
f() { delete this.#a }
}
@@ -0,0 +1,6 @@
export default {
"index": 43,
"lineNumber": 3,
"column": 15,
"message": "Cannot use 'arguments' in class field initializer"
};
@@ -0,0 +1,5 @@
function f() {
class C {
aaa = arguments
}
}
@@ -0,0 +1,6 @@
export default {
"index": 49,
"lineNumber": 3,
"column": 21,
"message": "Cannot use 'arguments' in class field initializer"
};
@@ -0,0 +1,5 @@
function f() {
class C {
aaa = () => arguments
}
}
@@ -0,0 +1,6 @@
export default {
"index": 333,
"lineNumber": 7,
"column": 15,
"message": "The keyword 'yield' is reserved"
};
@@ -0,0 +1,9 @@
function* f() {
class C {
// `yield` is an identifier reference in field initializers even if it's in a generator function.
// But `yield` as identifier references is disallowed in strict mode.
// And the inside of classes is always strict mode.
// Therefore this is a syntax error.
aaa = yield
}
}
@@ -0,0 +1,6 @@
export default {
"index": 41,
"lineNumber": 4,
"column": 14,
"message": "Private field '#b' must be declared in an enclosing class"
};
@@ -0,0 +1,6 @@
class C {
#a;
f() {
this.#b
}
}
@@ -0,0 +1,6 @@
export default {
"index": 49,
"lineNumber": 3,
"column": 17,
"message": "Unexpected token #foo"
};
@@ -0,0 +1,4 @@
class C extends Base {
#foo;
f() { super.#foo }
}
@@ -0,0 +1,6 @@
export default {
"index": 14,
"lineNumber": 2,
"column": 5,
"message": "Classes can't have an element named '#constructor'"
};
@@ -0,0 +1,3 @@
class C {
#constructor = () => {}
}
@@ -0,0 +1,6 @@
export default {
"index": 22,
"lineNumber": 3,
"column": 5,
"message": "Identifier '#a' has already been declared"
};
@@ -0,0 +1,4 @@
class C {
#a;
#a;
}
@@ -0,0 +1,6 @@
export default {
"index": 14,
"lineNumber": 2,
"column": 5,
"message": "Classes can't have a field named 'constructor'"
};
@@ -0,0 +1,3 @@
class C {
constructor = () => {}
}
@@ -0,0 +1,6 @@
export default {
"index": 304,
"lineNumber": 6,
"column": 15,
"message": "Cannot use keyword 'await' outside an async function"
};

0 comments on commit e0cd4d9

Please sign in to comment.