Skip to content

Commit

Permalink
fix: check class declarations
Browse files Browse the repository at this point in the history
* Class declarations were not checked
* Added guards symbol exports, which caused errors before class declaration handling was added
  • Loading branch information
Extersky authored and brettz9 committed Jun 19, 2019
1 parent 5b73798 commit 10bb92e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/exportParser.js
Expand Up @@ -67,7 +67,7 @@ const getSymbol = function (node, globals, scope, opt) {
debug('MemberExpression: Missing property ' + node.property.name);

return null;
} case 'FunctionExpression': case 'FunctionDeclaration': case 'ArrowFunctionExpression': {
} case 'ClassDeclaration': case 'FunctionExpression': case 'FunctionDeclaration': case 'ArrowFunctionExpression': {
const val = createNode();
val.props.prototype = createNode();
val.props.prototype.type = 'object';
Expand Down Expand Up @@ -115,7 +115,12 @@ createSymbol = function (node, globals, value, scope) {
const block = scope || globals;
let symbol;
switch (node.type) {
case 'Identifier': {
case 'ClassDeclaration': {
if (node.id.type === 'Identifier') {
return createSymbol(node.id, globals, node, globals);
}
break;
} case 'Identifier': {
if (value) {
const valueSymbol = getSymbol(value, globals, block);
if (valueSymbol) {
Expand Down Expand Up @@ -204,7 +209,9 @@ const mapVariables = function (node, globals) {
break;
} case 'ExportDefaultDeclaration': {
const symbol = createSymbol(node.declaration, globals, node.declaration);
symbol.exported = true;
if (symbol) {
symbol.exported = true;
}
break;
} case 'ExportNamedDeclaration': {
if (node.declaration) {
Expand All @@ -217,7 +224,9 @@ const mapVariables = function (node, globals) {
break;
} case 'ExportSpecifier': {
const symbol = getSymbol(node.local, globals, globals);
symbol.exported = true;
if (symbol) {
symbol.exported = true;
}
break;
} case 'ClassDeclaration': {
createSymbol(node.id, globals, node.body, globals);
Expand Down
24 changes: 24 additions & 0 deletions test/rules/assertions/requireJsdoc.js
Expand Up @@ -583,6 +583,30 @@ export default {
publicFunctionsOnly: true
}
}
},
{
code: `
export default class A {
}
`,
errors: [{
message: 'Missing JSDoc comment.',
type: 'ClassDeclaration'
}],
options: [{
require: {
ClassDeclaration: true
}
}],
parserOptions: {
sourceType: 'module'
},
settings: {
jsdoc: {
publicFunctionsOnly: true
}
}
}
],
valid: [{
Expand Down

0 comments on commit 10bb92e

Please sign in to comment.