Skip to content

Commit 0bc6ccf

Browse files
committed
Allow return null/undefined for when allowReturnArray=true.
1 parent 27eb8a6 commit 0bc6ccf

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

grammar/hooks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ class FormulaParser {
283283
}
284284
// Disallow union, and other unknown data types.
285285
// e.g. `=(A1:C1, A2:E9)` -> #VALUE!
286-
if (typeof result === 'object' && !Array.isArray(result)) {
286+
if (typeof result === 'object' && !Array.isArray(result) && result != null) {
287287
return FormulaError.VALUE;
288288
}
289289

test/grammar/test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ const {DepParser} = require('../../grammar/dependency/hooks');
77

88
const parser = new FormulaParser({
99
onCell: ref => {
10+
if (ref.row === 5 && ref.col === 5)
11+
return null
1012
return 1;
1113
},
1214
onRange: ref => {
@@ -107,6 +109,11 @@ describe('Dependency parser', () => {
107109
});
108110

109111
describe('Basic parse', () => {
112+
it('should parse null', function () {
113+
let actual = parser.parse('E5', position);
114+
expect(actual).to.deep.eq(null);
115+
});
116+
110117
it('should parse whole column', function () {
111118
let actual = parser.parse('SUM(A:A)', position);
112119
expect(actual).to.deep.eq(6);
@@ -116,6 +123,7 @@ describe('Basic parse', () => {
116123
let actual = parser.parse('SUM(1:1)', position);
117124
expect(actual).to.deep.eq(1);
118125
});
126+
119127
})
120128

121129
describe('Parser allows returning array or range', () => {
@@ -141,6 +149,19 @@ describe('Parser allows returning array or range', () => {
141149
expect(actual).to.eq(1);
142150
});
143151

152+
it('should return single value', function () {
153+
let actual = parser.parse('E5', position, true);
154+
expect(actual).to.eq(null);
155+
});
156+
});
157+
158+
describe('async parse', () => {
159+
it('should return single value', async function () {
160+
let actual = await parser.parseAsync('A1', position, true);
161+
expect(actual).to.eq(1);
162+
actual = await parser.parseAsync('E5', position, true);
163+
expect(actual).to.eq(null);
164+
});
144165
});
145166

146167
describe('Custom async function', () => {

0 commit comments

Comments
 (0)