Skip to content

Commit

Permalink
drop non essential props on production
Browse files Browse the repository at this point in the history
  • Loading branch information
timofei-iatsenko committed Mar 13, 2023
1 parent 0466e02 commit 2c07bd2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 19 deletions.
8 changes: 7 additions & 1 deletion src/js_macro_folder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,15 @@ impl<'a> JsMacroFolder<'a> {

let mut props: Vec<PropOrSpread> = vec![
create_key_value_prop("id", generate_message_id(&parsed.message_str, "").into()),
create_key_value_prop("message", parsed.message),

];

if !self.ctx.options.strip_non_essential_fields {
props.push(
create_key_value_prop("message", parsed.message),
);
}

if let Some(v) = parsed.values {
props.push(
create_key_value_prop("values", v),
Expand Down
21 changes: 13 additions & 8 deletions src/tests/js_define_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,27 @@ to!(

to!(
production,
should_kept_only_essential_props,
should_kept_only_essential_props,
r#"
import { defineMessage } from '@lingui/macro'
const msg = defineMessage({
const message1 = defineMessage`Message`;
const message2 = defineMessage({
message: `Hello ${name}`,
id: 'msgId',
comment: 'description for translators',
context: 'My Context',
})
"#,
r#"
const msg = {
id: "msgId",
values: {
name: name,
},
};
const message1 = {
id: "xDAtGP",
};
const message2 = {
id: "msgId",
values: {
name: name,
},
};
"#
);
25 changes: 15 additions & 10 deletions src/tests/js_t.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,22 +204,27 @@ to!(
js_should_kept_only_essential_props,
r#"
import { t } from '@lingui/macro'
const msg = t({
const msg1 = t`Message`
const msg2 = t({
message: `Hello ${name}`,
id: 'msgId',
comment: 'description for translators',
context: 'My Context',
})
"#,
r#"
import { i18n } from "@lingui/core";
const msg = i18n._({
id: "msgId",
values: {
name: name,
},
});
"#
r#"
import { i18n } from "@lingui/core";
const msg1 = i18n._({
id: "xDAtGP"
});
const msg2 = i18n._({
id: "msgId",
values: {
name: name,
},
});
"#
);

to!(
Expand Down

0 comments on commit 2c07bd2

Please sign in to comment.