From 11b7a3dc26f4d509fe6ea3f58da0f56878663d83 Mon Sep 17 00:00:00 2001 From: Mike Pastore Date: Thu, 6 Jul 2017 19:44:48 -0500 Subject: [PATCH] Guard against key-less nodes. Fixes #71 --- lib/rules/no-2.0.0-hooks.js | 6 ++++-- lib/utils/imports.js | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/rules/no-2.0.0-hooks.js b/lib/rules/no-2.0.0-hooks.js index 6142903..c890aa2 100644 --- a/lib/rules/no-2.0.0-hooks.js +++ b/lib/rules/no-2.0.0-hooks.js @@ -3,6 +3,8 @@ */ 'use strict'; +const { get } = require('../utils/get'); + // TODO // Write docs for this once we feel it should be recommended. const MESSAGE = 'Do not use the 2.0.0 hooks as they are not conducive to the programming model.'; @@ -21,8 +23,8 @@ module.exports = { return { ObjectExpression(node) { node.properties.forEach((property) => { - let name = property.key.name; - if (MISTAKE_HOOKS.indexOf(name) > -1) { + let name = get(property, 'key.name'); + if (name && MISTAKE_HOOKS.indexOf(name) > -1) { context.report(property, MESSAGE); } }); diff --git a/lib/utils/imports.js b/lib/utils/imports.js index 31fe365..b4b021a 100644 --- a/lib/utils/imports.js +++ b/lib/utils/imports.js @@ -7,7 +7,8 @@ function collectImportBindings(node, imports) { if (sourceName) { return node.specifiers.filter((specifier) => { - return 'ImportSpecifier' === specifier.type && importedBindings.includes(specifier.imported.name); + let name = get(specifier, 'imported.name'); + return 'ImportSpecifier' === specifier.type && name && importedBindings.includes(name); }).map((specifier) => specifier.local.name); }