diff --git a/src/defaults.js b/src/defaults.js index cf4da23..a572967 100644 --- a/src/defaults.js +++ b/src/defaults.js @@ -43,5 +43,6 @@ export const BABEL_PARSING_OPTS = { 'functionSent', 'dynamicImport', 'optionalChaining', + 'nullishCoalescingOperator', ], } diff --git a/tests/fixtures/NullishCoalescing.js b/tests/fixtures/NullishCoalescing.js new file mode 100644 index 0000000..26ea776 --- /dev/null +++ b/tests/fixtures/NullishCoalescing.js @@ -0,0 +1,10 @@ +import { gettext } from 'gettext-lib' + +const someObject = {} + +const OptionalChaining = () => { + const expressionUsingOptionalChaining = someObject.something ?? 'defaultValue' + gettext('Nullish coalescing works') +} + +export default OptionalChaining diff --git a/tests/tests.js b/tests/tests.js index 05c1d22..5658e92 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -527,4 +527,13 @@ describe('react-gettext-parser', () => { expect(messages[0].msgid).to.equal('Optional chaining works') }) }) + + describe('nullish coalescing support', () => { + it('should parse javascript that contains nullish coalescing operator', () => { + const code = getSource('NullishCoalescing.js') + const messages = extractMessages(code) + expect(messages).to.have.length(1) + expect(messages[0].msgid).to.equal('Nullish coalescing works') + }) + }) })