Repository: i18next/i18next-parser (js)

Issue:
Error from JSX spread attributes such as `<a {...props}>`
<!--
Before you submit an issue we recommend you visit [docs](https://www.i18next.com/) or [docs](https://react.i18next.com/) or [docs](https://github.com/i18next/next-i18next) or [StackOverflow](https://stackoverflow.com/search?q=i18next) 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

Running i18next-parser on a JSX tag that spreads attributes results in the following error.

```
TypeError: Cannot read properties of undefined (reading 'escapedText')
    at file:///Users/josh/src/node_modules/i18next-parser/dist/lexers/jsx-lexer.js:228:51
    at Array.find (<anonymous>)
    at file:///Users/josh/src/node_modules/i18next-parser/dist/lexers/jsx-lexer.js:227:66
    at Array.map (<anonymous>)
    at JsxLexer.parseChildren (file:///Users/josh/src/node_modules/i18next-parser/dist/lexers/jsx-lexer.js:214:7)
    at JsxLexer.nodeToString (file:///Users/josh/src/node_modules/i18next-parser/dist/lexers/jsx-lexer.js:178:41)
    at JsxLexer.jsxExtractor (file:///Users/josh/src/node_modules/i18next-parser/dist/lexers/jsx-lexer.js:144:46)
    at parseTree (file:///Users/josh/src/node_modules/i18next-parser/dist/lexers/jsx-lexer.js:41:41)
    at visitNodes (/Users/josh/src/node_modules/typescript/lib/typescript.js:27937:24)
    at forEachChildInJsxElement (/Users/josh/src/node_modules/typescript/lib/typescript.js:28705:61)```

## To Reproduce

```js
<Trans>Please <a {...hrefProps}>click here.</a></Trans>
```

## Expected behavior

i18next-parser cleanly extracts the translation string.

## Your Environment

- *runtime version*: Node 18.16.1
- *i18next version*: i18next-parser 8.7.0
- *os*: Mac
- *any other relevant information*: This may have been introduced in #862.


Pull request:
Handle attribute spreads
### Why am I submitting this PR

Fix handling of spread attributes when evaluating JSX attributes within `<Trans>`.

### Does it fix an existing ticket?

Fixes #908

### 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 da9a380..9b5dd5c 100644
--- a/src/lexers/jsx-lexer.js
+++ b/src/lexers/jsx-lexer.js
@@ -225,7 +225,9 @@ export default class JsxLexer extends JavascriptLexer {
           const name = element.tagName.escapedText
           const isBasic = !element.attributes.properties.length
           const hasDynamicChildren = element.attributes.properties.find(
-            (prop) => prop.name.escapedText === 'i18nIsDynamicList'
+            (prop) =>
+              prop.kind === ts.SyntaxKind.JsxAttribute &&
+              prop.name.escapedText === 'i18nIsDynamicList'
           )
           return {
             type: 'tag',


Test patch:
diff --git a/test/lexers/jsx-lexer.test.js b/test/lexers/jsx-lexer.test.js
index e1745d9..e4eaa8d 100644
--- a/test/lexers/jsx-lexer.test.js
+++ b/test/lexers/jsx-lexer.test.js
@@ -275,6 +275,17 @@ describe('JsxLexer', () => {
       done()
     })
 
+    it('handles spread attributes', (done) => {
+      const Lexer = new JsxLexer()
+      const content =
+        '<Trans>My dog is named: <span {...styles}>Spot</span></Trans>'
+      assert.equal(
+        Lexer.extract(content)[0].defaultValue,
+        'My dog is named: <1>Spot</1>'
+      )
+      done()
+    })
+
     it('erases comment expressions', (done) => {
       const Lexer = new JsxLexer()
       const content = '<Trans>{/* some comment */}Some Content</Trans>'