Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore template literals in i18nKey and ns attributes of Trans nodes #162

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -521,24 +521,21 @@ class Parser {
return;
}

const staticAttrs = [i18nKey, 'ns'];
const attr = ensureArray(node.openingElement.attributes)
.reduce((acc, attribute) => {
if (attribute.type !== 'JSXAttribute' || attribute.name.type !== 'JSXIdentifier') {
return acc;
}

const { name } = attribute.name;
const needsStaticValue = staticAttrs.includes(name);

if (attribute.value.type === 'Literal') {
acc[name] = attribute.value.value;
} else if (attribute.value.type === 'JSXExpressionContainer') {
const expression = attribute.value.expression;

// Identifier
if (expression.type === 'Identifier') {
acc[name] = expression.name;
}

// Literal
if (expression.type === 'Literal') {
acc[name] = expression.value;
Expand All @@ -550,7 +547,7 @@ class Parser {
acc[name] = properties.reduce((obj, property) => {
if (property.value.type === 'Literal') {
obj[property.key.name] = property.value.value;
} else if (property.value.type === 'TemplateLiteral') {
} else if (property.value.type === 'TemplateLiteral' && !needsStaticValue) {
obj[property.key.name] = property.value.quasis
.map(element => element.value.cooked)
.join('');
Expand All @@ -564,7 +561,7 @@ class Parser {
}

// Template Literal
if (expression.type === 'TemplateLiteral') {
if (expression.type === 'TemplateLiteral' && !needsStaticValue) {
acc[name] = expression.quasis
.map(element => element.value.cooked)
.join('');
Expand Down