Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ export const parse = (content: string) => {
}

const parseItem = (expr) => {
if(!expr) return;

if (expr.kind === 'string') {
return expr.value
}
Expand Down Expand Up @@ -155,7 +157,7 @@ const convertToDotsSyntax = (list) => {
const flatten = (items, context = '') => {
const data = {}

if (items === null) {
if (items === null || items === undefined) {
return data
}

Expand Down
1 change: 1 addition & 0 deletions test/fixtures/lang/en/ignore.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
return [
'empty_array' => [],
'null' => null,
'undefined' => undefined,
];
3 changes: 2 additions & 1 deletion test/loader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down