From 9ae258aa892e5618b15b6c57444f16024f7f1cd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damian=20Go=C5=82ojuch?= Date: Thu, 23 Apr 2020 15:02:24 +0200 Subject: [PATCH] Including cases with RestElement in properties. --- src/index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 17d1dd2..92a3594 100644 --- a/src/index.js +++ b/src/index.js @@ -2,11 +2,13 @@ import checkValidOptions from './options' const findOrAddDataProperty = (t, properties, identifier, attribute) => { for (const prop of properties) { - if (prop.key.type === 'StringLiteral' && prop.key.value === attribute) { + if (prop.key && prop.key.type === 'StringLiteral' && prop.key.value === attribute) { return prop.value; } } - properties.push(t.objectProperty( + + // It's better to unshift instead of push, because last property may be a RestElement (...restProps). + properties.unshift(t.objectProperty( t.stringLiteral(attribute), identifier, true,