Skip to content
This repository has been archived by the owner on Jun 8, 2019. It is now read-only.

Commit

Permalink
Make plugin idempotent by not removing description
Browse files Browse the repository at this point in the history
Fixes #22
Fixes #25
Fixes #26
  • Loading branch information
ericf committed Dec 28, 2015
1 parent b41d947 commit 4ba9be7
Showing 1 changed file with 1 addition and 20 deletions.
21 changes: 1 addition & 20 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const FUNCTION_NAMES = [

const DESCRIPTOR_PROPS = new Set(['id', 'description', 'defaultMessage']);

export default function ({types: t}) {
export default function () {
function getModuleSourceName(opts) {
return opts.moduleSourceName || 'react-intl';
}
Expand Down Expand Up @@ -205,14 +205,6 @@ export default function ({types: t}) {
// checked.
if (descriptor.defaultMessage) {
storeMessage(descriptor, path, state);

attributes
.filter((attr) => {
let keyPath = attr.get('name');
let key = getMessageDescriptorKey(keyPath);
return key === 'description';
})
.forEach((attr) => attr.remove());
}
}
},
Expand Down Expand Up @@ -245,17 +237,6 @@ export default function ({types: t}) {
}

storeMessage(descriptor, path, state);

messageObj.replaceWith(t.objectExpression([
t.objectProperty(
t.stringLiteral('id'),
t.stringLiteral(descriptor.id)
),
t.objectProperty(
t.stringLiteral('defaultMessage'),
t.stringLiteral(descriptor.defaultMessage)
),
]));
}

let callee = path.get('callee');
Expand Down

2 comments on commit 4ba9be7

@STRML
Copy link
Contributor

@STRML STRML commented on 4ba9be7 Aug 19, 2016

Choose a reason for hiding this comment

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

Thinking about splitting this into another plugin to remove the description & (optionally) defaultMessage entirely. Noticing there's definitely some cruft we could remove from our production builds.

@ericf
Copy link
Collaborator Author

@ericf ericf commented on 4ba9be7 Aug 19, 2016

Choose a reason for hiding this comment

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

The main issue is that Babel 6 makes it easy for people to accidentally run the same plugin multiple times. So what was happening is the translator message description props were pruned automatically and the option to enforce them was set. So the second time the plugin ran it would error.

Even if you moved this to a separate plugin, we'd still have that same issue unless we marked the nodes as being process in the AST. This would work for a single plugin pass, but if passPerPreset: true is set then I'm not sure it would be seeing the same AST nodes or not — it probably does, but I haven't tested it.

If you'd like to send a PR to add back the auto pruning of translator description props and a new option which when set removes the defaultMessage props that would be cool!

Please sign in to comment.