diff --git a/src/loader.ts b/src/loader.ts index 4e4bd06..4bc2307 100644 --- a/src/loader.ts +++ b/src/loader.ts @@ -110,6 +110,8 @@ export const parse = (content: string) => { } const parseItem = (expr) => { + if(!expr) return; + if (expr.kind === 'string') { return expr.value } @@ -155,7 +157,7 @@ const convertToDotsSyntax = (list) => { const flatten = (items, context = '') => { const data = {} - if (items === null) { + if (items === null || items === undefined) { return data } diff --git a/test/fixtures/lang/en/ignore.php b/test/fixtures/lang/en/ignore.php index 5eb6b8c..493009a 100644 --- a/test/fixtures/lang/en/ignore.php +++ b/test/fixtures/lang/en/ignore.php @@ -3,4 +3,5 @@ return [ 'empty_array' => [], 'null' => null, + 'undefined' => undefined, ]; diff --git a/test/loader.test.ts b/test/loader.test.ts index 38cf1fe..7a3e9d0 100644 --- a/test/loader.test.ts +++ b/test/loader.test.ts @@ -141,11 +141,12 @@ it('transforms class names and consts to .json', () => { expect(lang['name']).toBe('Name'); }); -it('ignores empty `array` or `null` translations', () => { +it('ignores empty `array`, `null`, or `undefined` translations', () => { const lang = parse(fs.readFileSync(isolatedFixtures + '/lang/en/ignore.php').toString()); expect(lang['empty_array']).toBe(undefined); expect(lang['null']).toBe(undefined); + expect(lang['undefined']).toBe(undefined); }); it('checks if there is .php translations', () => {