Skip to content

Commit

Permalink
Merge pull request #909 from joshkel/jsx-spread
Browse files Browse the repository at this point in the history
Handle attribute spreads
  • Loading branch information
karellm authored Sep 13, 2023
2 parents 4644d1a + f6a6eab commit 2dc467d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/lexers/jsx-lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
11 changes: 11 additions & 0 deletions test/lexers/jsx-lexer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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>'
Expand Down

0 comments on commit 2dc467d

Please sign in to comment.