Repository: i18next/i18next-parser (js)

Issue:
Trans defaults cause variable names to be treated as keys
<!--
Before you submit an issue we recommend you visit [docs](https://www.i18next.com/) or [docs](https://react.i18next.com/) or [StackOverflow](https://stackoverflow.com/) or similar and ask any questions you have or mention any problems you've had getting started with i18next.

**Please read this entire template before posting any issue. If you ignore these instructions and post an issue here that does not follow the instructions, your issue might be closed, locked.**
-->

## 🐛 Bug Report

The Trans component can be used to interpolate a line with i18next-react templates ("...<1>..."), but not to translate keys (what the `t()` function does). Although I am aware that the Trans component can also perform key translation, there are cases where this is not desired.

In this case, parsing mistakenly extracts a key when nothing should be extracted.
This is a regression that I discovered when upgrading from 3.0.1 to 3.3.0.

## To Reproduce

```js
const line = 'some generated template with <1>bold</1> text';

function Repro() {
  return (
    <Trans
      defaults={line}
      components={[<bold>text</bold>]}
    />
  );
}
```

Parsing should generate an empty file, but produces the following file:
```
{ "line": "line" }
```

## Your Environment

- *runtime version*: i.e. node v13
- *i18next-parser*: 3.3.0
- *i18next*: 19.8.3
- *react-i18next*: 11.7.3
- *os*: Linux


Pull request description:
Fix extracting Trans component without key, but with default value
Hi again! Just wanted to thank you for maintaining this project, and for responding so quick to my other PRs.

### Why am I submitting this PR
This PR fixes a bug that causes us to extract the keys of Trans components with default values incorrectly.

Take the following example:
```ts
<Trans>
  {{ name }}
</Trans>
```

The above results in the key `{{name}}`, which is correct. However, if we add a default value, it causes us to extract the key incorrectly:
```ts
<Trans defaults="Steve">
  {{ name }}
</Trans>
```

The above results in a key of `Steve`, which isn't correct. The key shouldn't change when we provide a default value.

### Does it fix an existing ticket?
Possibly fixes #249, but I'm if this is the same issue that the user was describing.

### Checklist

- [x] only relevant code is changed (make a diff before you submit the PR)
- [x] tests are included and pass: `yarn test` (see [details here](https://github.com/i18next/i18next-parser/blob/master/docs/development.md#tests))
- [ ] documentation is changed or added


Patch:
diff --git a/src/lexers/jsx-lexer.js b/src/lexers/jsx-lexer.js
index 6938281..fc6f5df 100644
--- a/src/lexers/jsx-lexer.js
+++ b/src/lexers/jsx-lexer.js
@@ -135,10 +135,9 @@ export default class JsxLexer extends JavascriptLexer {
         } else entry[property.name.text] = true
       })
 
+      const nodeAsString = this.nodeToString.call(this, node, sourceText)
       const defaultsProp = getPropValue(tagNode, 'defaults')
-      let defaultValue =
-        defaultsProp || this.nodeToString.call(this, node, sourceText)
-
+      let defaultValue = defaultsProp || nodeAsString
       if (entry.shouldUnescape === true) {
         defaultValue = unescape(defaultValue)
       }
@@ -147,7 +146,7 @@ export default class JsxLexer extends JavascriptLexer {
         entry.defaultValue = defaultValue
 
         if (!entry.key) {
-          entry.key = entry.defaultValue
+          entry.key = nodeAsString
         }
       }
 


Test patch:
diff --git a/test/lexers/jsx-lexer.test.js b/test/lexers/jsx-lexer.test.js
index bc5786b..5918044 100644
--- a/test/lexers/jsx-lexer.test.js
+++ b/test/lexers/jsx-lexer.test.js
@@ -123,6 +123,15 @@ describe('JsxLexer', () => {
       done()
     })
 
+    it('extracts keys from Trans elements without an i18nKey, but with a defaults prop', (done) => {
+      const Lexer = new JsxLexer()
+      const content = '<Trans defaults="Steve">{{ name }}</Trans>'
+      assert.deepEqual(Lexer.extract(content), [
+        { key: '{{name}}', defaultValue: 'Steve' },
+      ])
+      done()
+    })
+
     it('extracts keys from Trans elements and ignores values of expressions and spaces', (done) => {
       const Lexer = new JsxLexer()
       const content = '<Trans count={count}>{{ key: property }}</Trans>'