diff --git a/package-lock.json b/package-lock.json index 5d058c0..ec349de 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "react-gettext-parser", - "version": "1.16.0", + "version": "1.16.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "react-gettext-parser", - "version": "1.16.0", + "version": "1.16.1", "license": "ISC", "dependencies": { "@babel/eslint-parser": "^7.22.10", diff --git a/package.json b/package.json index 89584c8..8eda8ca 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-gettext-parser", - "version": "1.16.0", + "version": "1.16.1", "description": "A gettext parser for React. Spits out .pot files!", "engines": { "node": ">=4.0.0", diff --git a/src/parse.js b/src/parse.js index 8863017..e55f082 100644 --- a/src/parse.js +++ b/src/parse.js @@ -370,9 +370,11 @@ export const getTraverser = (cb = noop, opts = {}) => { } // Extract comments for translators - if (Array.isArray(parent.leadingComments) === true) { + const leadingComments = + parent.leadingComments || parent.expression?.leadingComments + if (Array.isArray(leadingComments) === true) { const translatorCommentRegex = /Translators:.+/ - const commentNode = parent.leadingComments.find( + const commentNode = leadingComments.find( (x) => translatorCommentRegex.test(x.value) === true ) diff --git a/tests/fixtures/Comments.tsx b/tests/fixtures/Comments.tsx new file mode 100644 index 0000000..e8f218a --- /dev/null +++ b/tests/fixtures/Comments.tsx @@ -0,0 +1,20 @@ +import React from 'react' +import { GetText, gettext } from 'gettext-lib' + +// This is a unique key word in typescript, we use this to test the parser +type T = { + readonly key: string +} + +const TsxComments = () => ( +