Skip to content

Commit

Permalink
fix: prevent adding undefined msgid to messages (#915)
Browse files Browse the repository at this point in the history
  • Loading branch information
amankkg committed Dec 15, 2020
1 parent d5f77d1 commit 3afacec
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
19 changes: 11 additions & 8 deletions packages/babel-plugin-extract-messages/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ function addMessage(
messages,
{ id, message: newDefault, origin, comment, ...props }
) {
// prevent from adding undefined msgid
if (id === undefined) return

if (messages.has(id)) {
const message = messages.get(id)

Expand All @@ -27,15 +30,15 @@ function addMessage(
throw path.buildCodeFrameError(
"Different defaults for the same message ID."
)
} else {
if (newDefault) {
message.message = newDefault
}
}

;[].push.apply(message.origin, origin)
if (comment) {
;[].push.apply(message.extractedComments, [comment])
}
if (newDefault) {
message.message = newDefault
}

;[].push.apply(message.origin, origin)
if (comment) {
;[].push.apply(message.extractedComments, [comment])
}
} else {
const extractedComments = comment ? [comment] : []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ const withTId = t({
id: "ID Some",
message: "Message with id some"
})

const id = 'message id'

const withUnknownId = t({
id: id
})

1 comment on commit 3afacec

@vercel
Copy link

@vercel vercel bot commented on 3afacec Dec 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.