From b1ba6627720e9a92026077eb86ca6c0fcc7535c7 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Sat, 6 Jun 2020 21:38:29 +1200 Subject: [PATCH] Fix: ensure that node has `key` property --- lib/utils.js | 4 ++++ tests/lib/utils.js | 1 + 2 files changed, 5 insertions(+) diff --git a/lib/utils.js b/lib/utils.js index 0fd86bd4..c3d96755 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -184,6 +184,10 @@ module.exports = { * @returns {string|null} The key name, or `null` if the name cannot be determined statically. */ getKeyName (property) { + if(!property.key) { + return null; + } + if (!property.computed && property.key.type === 'Identifier') { return property.key.name; } diff --git a/tests/lib/utils.js b/tests/lib/utils.js index fbe78bfc..13830d71 100644 --- a/tests/lib/utils.js +++ b/tests/lib/utils.js @@ -172,6 +172,7 @@ describe('utils', () => { '({ [`foo`]() {} })': 'foo', '({ 5: 1 })': '5', '({ 0x123: 1 })': '291', + '{{ ...{} })': null, '({ [foo]: 1 })': null, '({ [tag`foo`]: 1 })': null, '({ ["foo" + "bar"]: 1 })': null,