File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -256,14 +256,28 @@ export default class JavascriptLexer extends BaseLexer {
256256
257257 let optionsArgument = node . arguments . shift ( )
258258
259- // Second argument could be a string default value
259+ // Second argument could be a (concatenated) string default value
260260 if (
261261 optionsArgument &&
262262 ( optionsArgument . kind === ts . SyntaxKind . StringLiteral ||
263263 optionsArgument . kind === ts . SyntaxKind . NoSubstitutionTemplateLiteral )
264264 ) {
265265 entry . defaultValue = optionsArgument . text
266266 optionsArgument = node . arguments . shift ( )
267+ } else if (
268+ optionsArgument &&
269+ optionsArgument . kind === ts . SyntaxKind . BinaryExpression
270+ ) {
271+ const concatenatedString = this . concatenateString ( optionsArgument )
272+ if ( ! concatenatedString ) {
273+ this . emit (
274+ 'warning' ,
275+ `Default value is not a string literal: ${ optionsArgument . text } `
276+ )
277+ return null
278+ }
279+ entry . defaultValue = concatenatedString
280+ optionsArgument = node . arguments . shift ( )
267281 }
268282
269283 if (
Original file line number Diff line number Diff line change @@ -27,6 +27,15 @@ describe('JavascriptLexer', () => {
2727 done ( )
2828 } )
2929
30+ it ( 'extracts the second argument string concatenation as defaultValue' , ( done ) => {
31+ const Lexer = new JavascriptLexer ( )
32+ const content = 'i18n.t("first", "bla" + "bla" + "bla")'
33+ assert . deepEqual ( Lexer . extract ( content ) , [
34+ { key : 'first' , defaultValue : 'blablabla' } ,
35+ ] )
36+ done ( )
37+ } )
38+
3039 it ( 'extracts the defaultValue/context options' , ( done ) => {
3140 const Lexer = new JavascriptLexer ( )
3241 const content = 'i18n.t("first", {defaultValue: "foo", context: \'bar\'})'
You can’t perform that action at this time.
0 commit comments