Wrong variable in literal strings
See original GitHub issueDescribe the bug Lingui confuses variables (?)
To Reproduce Try this code:
import React from 'react'
import { t } from '@lingui/macro'
export default class MyComponent extends React.Component {
render () {
const totalPrice = 10
let message
if (totalPrice > 0) {
const limit = 50
message = i18n._(t`This is the great limit ${limit}`)
} else if (totalPrice <= 0) {
const limit = 10
message = i18n._(
t`This is the small limit ${limit}`
)
}
return message
}
}
Now use babel to transpile it, you will get this:
...snip...
if (totalPrice > 0) {
var limit = 50;
message = i18n._( /*i18n*/{
id: 'This is the great limit {limit}',
values: {
limit: limit
}
});
} else if (totalPrice <= 0) {
var _limit = 10;
message = i18n._( /*i18n*/{
id: 'This is the small limit {limit}',
values: {
limit: limit
}
});
}
return message;
...snip...
As you can see the second “limit” variable is still limit
Expected behavior The second snip code should use _limit variable as follow:
var _limit = 10;
message = i18n._( /*i18n*/{
id: 'This is the small limit {limit}',
values: {
limit: _limit
}
Additional context
- jsLingui version
2.7.4
- Babel version
project@2.0.1 /myhome/project-test
├─┬ babel-cli@6.26.0
│ ├── babel-core@6.26.3 deduped
│ └─┬ babel-register@6.26.0
│ └── babel-core@6.26.3 deduped
└── babel-core@6.26.3
- .babelrc:
{
"presets": ["es2015", "stage-0", "react"],
"plugins":[
"macros",
]
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:15 (8 by maintainers)
Top Results From Across the Web
How to Handle the Unclosed String Literal Error in Java - Rollbar
Python unclosed string literal error refers to the Java compiler failing to interpret a string literal due to the missing of a double...
Read more >Using string variables instead of string literals causes error
A string literal and a std::string are two completely different things. Usually when a function f expects a const char* you can pass...
Read more >jQuery Undetermined String Literal Error - SitePoint
If your trying to assign a string that covers multiple lines to a variable you might see the “Undetermined String Literal” error.
Read more >literal string with variable substitution syntax in script throws error at ...
we have this script which is generating message data into a file as part of one of our services. the message data needs...
Read more >Template literals (Template strings) - JavaScript | MDN
However, a tagged template literal may not result in a string; ... However, invalid escape sequences will cause a syntax error, ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
https://codesandbox.io/s/epic-butterfly-ou8ww?file=/src/index.js @MartijnHols here you have, updated the codesandbox to v3.x.x and looks fixed 👍🏻
I just ran into this bug. It also occurs when defining a var inside a switch case along the lines of;