Skip to content

Commit 48a1218

Browse files
committed
Supports ES2022 (Class Fileds)
1 parent 7e5f2e9 commit 48a1218

12 files changed

+250
-25
lines changed

.vscode/settings.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,9 @@
99
"vue"
1010
],
1111
"typescript.tsdk": "node_modules/typescript/lib",
12-
"vetur.validation.script": false
12+
"vetur.validation.script": false,
13+
"[typescript]": {
14+
"editor.formatOnSave": true,
15+
"editor.defaultFormatter": "esbenp.prettier-vscode"
16+
},
1317
}

lib/rules/require-slots-as-functions.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module.exports = {
3434
/**
3535
* Verify the given node
3636
* @param {MemberExpression | Identifier | ChainExpression} node The node to verify
37-
* @param {Expression} reportNode The node to report
37+
* @param {Expression | PrivateIdentifier} reportNode The node to report
3838
*/
3939
function verify(node, reportNode) {
4040
const parent = node.parent
@@ -83,7 +83,7 @@ module.exports = {
8383
/**
8484
* Verify the references of the given node.
8585
* @param {Identifier} node The node to verify
86-
* @param {Expression} reportNode The node to report
86+
* @param {Expression | PrivateIdentifier} reportNode The node to report
8787
*/
8888
function verifyReferences(node, reportNode) {
8989
const variable = findVariable(context.getScope(), node)

lib/utils/indent-common.js

+14-5
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@ const KNOWN_NODES = new Set([
6060
'NewExpression',
6161
'ObjectExpression',
6262
'ObjectPattern',
63+
'PrivateIdentifier',
6364
'Program',
6465
'Property',
66+
'PropertyDefinition',
6567
'RestElement',
6668
'ReturnStatement',
6769
'SequenceExpression',
@@ -667,7 +669,7 @@ module.exports.defineVisitor = function create(
667669
/**
668670
* Collect prefix tokens of the given property.
669671
* The prefix includes `async`, `get`, `set`, `static`, and `*`.
670-
* @param {Property|MethodDefinition} node The property node to collect prefix tokens.
672+
* @param {Property|MethodDefinition|PropertyDefinition} node The property node to collect prefix tokens.
671673
*/
672674
function getPrefixTokens(node) {
673675
const prefixes = []
@@ -1759,9 +1761,8 @@ module.exports.defineVisitor = function create(
17591761
setOffset([dotToken, propertyToken], 1, objectToken)
17601762
}
17611763
},
1762-
/** @param {MethodDefinition | Property} node */
1763-
'MethodDefinition, Property'(node) {
1764-
const isMethod = node.type === 'MethodDefinition' || node.method === true
1764+
/** @param {MethodDefinition | Property | PropertyDefinition} node */
1765+
'MethodDefinition, Property, PropertyDefinition'(node) {
17651766
const prefixTokens = getPrefixTokens(node)
17661767
const hasPrefix = prefixTokens.length >= 1
17671768

@@ -1795,7 +1796,10 @@ module.exports.defineVisitor = function create(
17951796
}
17961797
}
17971798

1798-
if (isMethod) {
1799+
if (
1800+
node.type === 'MethodDefinition' ||
1801+
(node.type === 'Property' && node.method === true)
1802+
) {
17991803
const leftParenToken = tokenStore.getTokenAfter(lastKeyToken)
18001804

18011805
setOffset(leftParenToken, 1, lastKeyToken)
@@ -1804,6 +1808,11 @@ module.exports.defineVisitor = function create(
18041808
const valueToken = tokenStore.getTokenAfter(colonToken)
18051809

18061810
setOffset([colonToken, valueToken], 1, lastKeyToken)
1811+
} else if (node.type === 'PropertyDefinition' && node.value != null) {
1812+
const eqToken = tokenStore.getTokenAfter(lastKeyToken)
1813+
const initToken = tokenStore.getTokenAfter(eqToken)
1814+
1815+
setOffset([eqToken, initToken], 1, lastKeyToken)
18071816
}
18081817
},
18091818
/** @param {NewExpression} node */

lib/utils/index.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1798,23 +1798,24 @@ function skipChainExpression(node) {
17981798
*/
17991799
function getStaticPropertyName(node) {
18001800
if (node.type === 'Property' || node.type === 'MethodDefinition') {
1801-
const key = node.key
1802-
18031801
if (!node.computed) {
1802+
const key = node.key
18041803
if (key.type === 'Identifier') {
18051804
return key.name
18061805
}
18071806
}
1807+
const key = node.key
18081808
// @ts-expect-error
18091809
return getStringLiteralValue(key)
18101810
} else if (node.type === 'MemberExpression') {
1811-
const property = node.property
18121811
if (!node.computed) {
1812+
const property = node.property
18131813
if (property.type === 'Identifier') {
18141814
return property.name
18151815
}
18161816
return null
18171817
}
1818+
const property = node.property
18181819
// @ts-expect-error
18191820
return getStringLiteralValue(property)
18201821
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<!--{}-->
2+
<script>
3+
class Counter {
4+
get
5+
#x
6+
(
7+
)
8+
{
9+
}
10+
set
11+
#x
12+
(
13+
value
14+
) {
15+
}
16+
static
17+
get
18+
#y
19+
(
20+
) {
21+
}
22+
static
23+
set
24+
#y
25+
(
26+
value
27+
) {
28+
}
29+
inc() {
30+
this
31+
.#inc
32+
(
33+
)
34+
this.
35+
#inc
36+
(
37+
)
38+
}
39+
#inc
40+
(
41+
) {
42+
this
43+
.#x++;
44+
this.
45+
#x++;
46+
Counter
47+
.#staticInc
48+
(
49+
)
50+
Counter.
51+
#staticInc(
52+
)
53+
}
54+
static
55+
#staticInc
56+
(
57+
) {
58+
Counter
59+
.#y++;
60+
Counter.
61+
#y++;
62+
}
63+
}
64+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!--{}-->
2+
<script>
3+
class Counter {
4+
#x
5+
=
6+
0;
7+
static
8+
#y
9+
=
10+
0;
11+
inc() {
12+
this
13+
.#x++;
14+
this.
15+
#x++;
16+
Counter
17+
.#y++;
18+
Counter.
19+
#y++;
20+
}
21+
}
22+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!--{}-->
2+
<script>
3+
class Counter {
4+
[
5+
x
6+
]
7+
=
8+
0;
9+
static
10+
[
11+
y
12+
]
13+
=
14+
0;
15+
}
16+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!--{}-->
2+
<script>
3+
class Counter {
4+
x
5+
=
6+
0;
7+
static
8+
y
9+
=
10+
0;
11+
}
12+
</script>

tests/lib/rules/script-indent.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ function unIndent(strings) {
114114
const tester = new RuleTester({
115115
parser: require.resolve('vue-eslint-parser'),
116116
parserOptions: {
117-
ecmaVersion: 2020,
117+
ecmaVersion: 2022,
118118
sourceType: 'module'
119119
}
120120
})

typings/eslint-plugin-vue/global.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ declare global {
7171
// ---- ES Nodes ----
7272

7373
type Identifier = VAST.Identifier
74+
type PrivateIdentifier = VAST.PrivateIdentifier
7475
type Literal = VAST.Literal
7576
type Program = VAST.Program
7677
type SwitchCase = VAST.SwitchCase
@@ -135,6 +136,7 @@ declare global {
135136
type AssignmentPattern = VAST.AssignmentPattern
136137
type ClassBody = VAST.ClassBody
137138
type MethodDefinition = VAST.MethodDefinition
139+
type PropertyDefinition = VAST.PropertyDefinition
138140
type ModuleDeclaration = VAST.ModuleDeclaration
139141
type ImportDeclaration = VAST.ImportDeclaration
140142
type ExportNamedDeclaration = VAST.ExportNamedDeclaration

typings/eslint-plugin-vue/util-types/ast/ast.ts

+4
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ export type NodeListenerMap = {
179179
export type ESNodeListenerMap = {
180180
Identifier: ES.Identifier
181181
'Identifier:exit': ES.Identifier
182+
PrivateIdentifier: ES.PrivateIdentifier
183+
'PrivateIdentifier:exit': ES.PrivateIdentifier
182184
Literal: ES.Literal
183185
'Literal:exit': ES.Literal
184186
Program: ES.Program
@@ -317,6 +319,8 @@ export type ESNodeListenerMap = {
317319
'ClassBody:exit': ES.ClassBody
318320
MethodDefinition: ES.MethodDefinition
319321
'MethodDefinition:exit': ES.MethodDefinition
322+
PropertyDefinition: ES.PropertyDefinition
323+
'PropertyDefinition:exit': ES.PropertyDefinition
320324
ImportDeclaration: ES.ImportDeclaration
321325
'ImportDeclaration:exit': ES.ImportDeclaration
322326
ExportNamedDeclaration: ES.ExportNamedDeclaration

0 commit comments

Comments
 (0)