From cc9d71d6a21c65f401525d17fd74ab1cbd22da04 Mon Sep 17 00:00:00 2001 From: naruaway Date: Fri, 27 Dec 2019 18:30:01 +0900 Subject: [PATCH] Support Nullish coalescing operator ("??") (#67) It's Stage 3 and already supported in TypeScript 3.7 --- src/defaults.js | 1 + tests/fixtures/NullishCoalescing.js | 10 ++++++++++ tests/tests.js | 9 +++++++++ 3 files changed, 20 insertions(+) create mode 100644 tests/fixtures/NullishCoalescing.js 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') + }) + }) })