@@ -23,9 +23,14 @@ const isDeclarationOfExportDefaultDeclaration = node =>
2323 node . parent . type === 'ExportDefaultDeclaration' &&
2424 node . parent . declaration === node ;
2525
26+ // https://github.com/estree/estree/blob/master/stage3/class-features.md#propertydefinition
27+ const isPropertyDefinition = node => node . type === 'PropertyDefinition' ||
28+ // Legacy node type
29+ node . type === 'ClassProperty' ;
30+ const isMethodDefinition = node => node . type === 'MethodDefinition' ;
31+
2632function isStaticMember ( node ) {
2733 const {
28- type,
2934 private : isPrivate ,
3035 static : isStatic ,
3136 declare : isDeclare ,
@@ -37,7 +42,7 @@ function isStaticMember(node) {
3742
3843 // Avoid matching unexpected node. For example: https://github.com/tc39/proposal-class-static-block
3944 /* istanbul ignore next */
40- if ( type !== 'ClassProperty' && type !== 'MethodDefinition' ) {
45+ if ( ! isPropertyDefinition ( node ) && ! isMethodDefinition ( node ) ) {
4146 return false ;
4247 }
4348
@@ -60,8 +65,6 @@ function isStaticMember(node) {
6065}
6166
6267function * switchClassMemberToObjectProperty ( node , sourceCode , fixer ) {
63- const { type} = node ;
64-
6568 const staticToken = sourceCode . getFirstToken ( node ) ;
6669 assertToken ( staticToken , {
6770 expected : [
@@ -75,12 +78,12 @@ function * switchClassMemberToObjectProperty(node, sourceCode, fixer) {
7578 yield fixer . remove ( staticToken ) ;
7679 yield removeSpacesAfter ( staticToken , sourceCode , fixer ) ;
7780
78- const maybeSemicolonToken = type === 'ClassProperty' ?
81+ const maybeSemicolonToken = isPropertyDefinition ( node ) ?
7982 sourceCode . getLastToken ( node ) :
8083 sourceCode . getTokenAfter ( node ) ;
8184 const hasSemicolonToken = isSemicolonToken ( maybeSemicolonToken ) ;
8285
83- if ( type === 'ClassProperty' ) {
86+ if ( isPropertyDefinition ( node ) ) {
8487 const { key, value} = node ;
8588
8689 if ( value ) {
@@ -132,11 +135,11 @@ function switchClassToObject(node, sourceCode) {
132135
133136 for ( const node of body . body ) {
134137 if (
135- node . type === 'ClassProperty' &&
138+ isPropertyDefinition ( node ) &&
136139 (
137140 node . typeAnnotation ||
138- // This is a stupid way to check if `value` of `ClassProperty ` uses `this`
139- ( node . value && sourceCode . getText ( node ) . includes ( 'this' ) )
141+ // This is a stupid way to check if `value` of `PropertyDefinition ` uses `this`
142+ ( node . value && sourceCode . getText ( node . value ) . includes ( 'this' ) )
140143 )
141144 ) {
142145 return ;
0 commit comments