Skip to content

Commit 10bb92e

Browse files
Exterskybrettz9
authored andcommitted
fix: check class declarations
* Class declarations were not checked * Added guards symbol exports, which caused errors before class declaration handling was added
1 parent 5b73798 commit 10bb92e

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

src/exportParser.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ const getSymbol = function (node, globals, scope, opt) {
6767
debug('MemberExpression: Missing property ' + node.property.name);
6868

6969
return null;
70-
} case 'FunctionExpression': case 'FunctionDeclaration': case 'ArrowFunctionExpression': {
70+
} case 'ClassDeclaration': case 'FunctionExpression': case 'FunctionDeclaration': case 'ArrowFunctionExpression': {
7171
const val = createNode();
7272
val.props.prototype = createNode();
7373
val.props.prototype.type = 'object';
@@ -115,7 +115,12 @@ createSymbol = function (node, globals, value, scope) {
115115
const block = scope || globals;
116116
let symbol;
117117
switch (node.type) {
118-
case 'Identifier': {
118+
case 'ClassDeclaration': {
119+
if (node.id.type === 'Identifier') {
120+
return createSymbol(node.id, globals, node, globals);
121+
}
122+
break;
123+
} case 'Identifier': {
119124
if (value) {
120125
const valueSymbol = getSymbol(value, globals, block);
121126
if (valueSymbol) {
@@ -204,7 +209,9 @@ const mapVariables = function (node, globals) {
204209
break;
205210
} case 'ExportDefaultDeclaration': {
206211
const symbol = createSymbol(node.declaration, globals, node.declaration);
207-
symbol.exported = true;
212+
if (symbol) {
213+
symbol.exported = true;
214+
}
208215
break;
209216
} case 'ExportNamedDeclaration': {
210217
if (node.declaration) {
@@ -217,7 +224,9 @@ const mapVariables = function (node, globals) {
217224
break;
218225
} case 'ExportSpecifier': {
219226
const symbol = getSymbol(node.local, globals, globals);
220-
symbol.exported = true;
227+
if (symbol) {
228+
symbol.exported = true;
229+
}
221230
break;
222231
} case 'ClassDeclaration': {
223232
createSymbol(node.id, globals, node.body, globals);

test/rules/assertions/requireJsdoc.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,30 @@ export default {
583583
publicFunctionsOnly: true
584584
}
585585
}
586+
},
587+
{
588+
code: `
589+
export default class A {
590+
591+
}
592+
`,
593+
errors: [{
594+
message: 'Missing JSDoc comment.',
595+
type: 'ClassDeclaration'
596+
}],
597+
options: [{
598+
require: {
599+
ClassDeclaration: true
600+
}
601+
}],
602+
parserOptions: {
603+
sourceType: 'module'
604+
},
605+
settings: {
606+
jsdoc: {
607+
publicFunctionsOnly: true
608+
}
609+
}
586610
}
587611
],
588612
valid: [{

0 commit comments

Comments
 (0)