@borgar/fx 4.3.1 → 4.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/fx.d.ts +653 -0
- package/dist/fx.js +1 -1
- package/docs/API.md +363 -280
- package/lib/a1.js +18 -9
- package/lib/constants.js +2 -2
- package/lib/lexer-srefs.spec.js +5 -0
- package/lib/lexerParts.js +24 -12
- package/lib/parseRef.spec.js +22 -11
- package/lib/parser.js +1 -1
- package/lib/parser.spec.js +90 -39
- package/lib/rc.js +4 -2
- package/lib/sr.spec.js +7 -0
- package/lib/translate-toA1.spec.js +5 -1
- package/lib/translate-toRC.spec.js +4 -1
- package/lib/translate.js +8 -5
- package/lib/translate.spec.js +21 -0
- package/package.json +14 -10
- package/tsd.json +12 -0
- package/.jsdoc/config.json +0 -17
- package/.jsdoc/publish.js +0 -217
package/lib/a1.js
CHANGED
|
@@ -5,6 +5,7 @@ import { stringifyPrefix, stringifyPrefixAlt } from './stringifyPrefix.js';
|
|
|
5
5
|
const clamp = (min, val, max) => Math.min(Math.max(val, min), max);
|
|
6
6
|
const toColStr = (c, a) => (a ? '$' : '') + toCol(c);
|
|
7
7
|
const toRowStr = (r, a) => (a ? '$' : '') + toRow(r);
|
|
8
|
+
const charFrom = String.fromCharCode;
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Convert a column string representation to a 0 based
|
|
@@ -51,9 +52,13 @@ export function fromCol (columnString) {
|
|
|
51
52
|
*/
|
|
52
53
|
export function toCol (columnIndex) {
|
|
53
54
|
return (
|
|
54
|
-
(columnIndex >= 702
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
(columnIndex >= 702
|
|
56
|
+
? charFrom(((((columnIndex - 702) / 676) - 0) % 26) + 65)
|
|
57
|
+
: '') +
|
|
58
|
+
(columnIndex >= 26
|
|
59
|
+
? charFrom(((((columnIndex / 26) - 1) % 26) + 65))
|
|
60
|
+
: '') +
|
|
61
|
+
charFrom((columnIndex % 26) + 65)
|
|
57
62
|
);
|
|
58
63
|
}
|
|
59
64
|
|
|
@@ -102,27 +107,31 @@ export function toA1 (range) {
|
|
|
102
107
|
right = clamp(0, right | 0, MAX_COLS);
|
|
103
108
|
}
|
|
104
109
|
// A:A
|
|
105
|
-
|
|
110
|
+
const allRows = top === 0 && bottom >= MAX_ROWS;
|
|
111
|
+
const haveAbsCol = ($left && !noLeft) || ($right && !noRight);
|
|
112
|
+
if ((allRows && !noLeft && !noRight && (!haveAbsCol || left === right)) || (noTop && noBottom)) {
|
|
106
113
|
return toColStr(left, $left) + ':' + toColStr(right, $right);
|
|
107
114
|
}
|
|
108
115
|
// 1:1
|
|
109
|
-
|
|
116
|
+
const allCols = left === 0 && right >= MAX_COLS;
|
|
117
|
+
const haveAbsRow = ($top && !noTop) || ($bottom && !noBottom);
|
|
118
|
+
if ((allCols && !noTop && !noBottom && (!haveAbsRow || top === bottom)) || (noLeft && noRight)) {
|
|
110
119
|
return toRowStr(top, $top) + ':' + toRowStr(bottom, $bottom);
|
|
111
120
|
}
|
|
112
121
|
// A1:1
|
|
113
|
-
|
|
122
|
+
if (!noLeft && !noTop && !noRight && noBottom) {
|
|
114
123
|
return toColStr(left, $left) + toRowStr(top, $top) + ':' + toColStr(right, $right);
|
|
115
124
|
}
|
|
116
125
|
// A:A1 => A1:1
|
|
117
|
-
|
|
126
|
+
if (!noLeft && noTop && !noRight && !noBottom) {
|
|
118
127
|
return toColStr(left, $left) + toRowStr(bottom, $bottom) + ':' + toColStr(right, $right);
|
|
119
128
|
}
|
|
120
129
|
// A1:A
|
|
121
|
-
|
|
130
|
+
if (!noLeft && !noTop && noRight && !noBottom) {
|
|
122
131
|
return toColStr(left, $left) + toRowStr(top, $top) + ':' + toRowStr(bottom, $bottom);
|
|
123
132
|
}
|
|
124
133
|
// A:A1 => A1:A
|
|
125
|
-
|
|
134
|
+
if (noLeft && !noTop && !noRight && !noBottom) {
|
|
126
135
|
return toColStr(right, $right) + toRowStr(top, $top) + ':' + toRowStr(bottom, $bottom);
|
|
127
136
|
}
|
|
128
137
|
// A1:A1
|
package/lib/constants.js
CHANGED
|
@@ -25,5 +25,5 @@ export const CALL = 'CallExpression';
|
|
|
25
25
|
export const ARRAY = 'ArrayExpression';
|
|
26
26
|
export const IDENTIFIER = 'Identifier';
|
|
27
27
|
|
|
28
|
-
export const MAX_COLS = 2 ** 14 - 1; // 16383
|
|
29
|
-
export const MAX_ROWS = 2 ** 20 - 1; // 1048575
|
|
28
|
+
export const MAX_COLS = (2 ** 14) - 1; // 16383
|
|
29
|
+
export const MAX_ROWS = (2 ** 20) - 1; // 1048575
|
package/lib/lexer-srefs.spec.js
CHANGED
|
@@ -315,5 +315,10 @@ test('tokenize structured references (merges on)', t => {
|
|
|
315
315
|
{ type: FX_PREFIX, value: '=' },
|
|
316
316
|
{ type: REF_STRUCT, value: '\'Sales - May2020.xlsx\'!Table1[ [#Data], [#Totals], [Surf]:[Rod] ]' }
|
|
317
317
|
]);
|
|
318
|
+
|
|
319
|
+
t.isTokens('=[myworkbook.xlsx]Sheet1!TMP8w0habhr[#All]', [
|
|
320
|
+
{ type: FX_PREFIX, value: '=' },
|
|
321
|
+
{ type: REF_STRUCT, value: '[myworkbook.xlsx]Sheet1!TMP8w0habhr[#All]' }
|
|
322
|
+
]);
|
|
318
323
|
t.end();
|
|
319
324
|
});
|
package/lib/lexerParts.js
CHANGED
|
@@ -34,16 +34,17 @@ const re_CONTEXT_QUOTE = /^'(?:''|[^'])*('|$)(?=!)/;
|
|
|
34
34
|
const rngPart = '\\$?[A-Z]{1,3}\\$?[1-9][0-9]{0,6}';
|
|
35
35
|
const colPart = '\\$?[A-Z]{1,3}';
|
|
36
36
|
const rowPart = '\\$?[1-9][0-9]{0,6}';
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
const
|
|
37
|
+
const nextNotChar = '(?![a-z0-9_\\u00a1-\\uffff])';
|
|
38
|
+
const re_A1COL = new RegExp(`^${colPart}:${colPart}${nextNotChar}`, 'i');
|
|
39
|
+
const re_A1ROW = new RegExp(`^${rowPart}:${rowPart}${nextNotChar}`, 'i');
|
|
40
|
+
const re_A1RANGE = new RegExp(`^${rngPart}${nextNotChar}`, 'i');
|
|
40
41
|
const re_A1PARTIAL = new RegExp(`^((${colPart}|${rowPart}):${rngPart}|${rngPart}:(${colPart}|${rowPart}))(?![\\w($.])`, 'i');
|
|
41
42
|
const rPart = '(?:R(?:\\[[+-]?\\d+\\]|[1-9][0-9]{0,6})?)';
|
|
42
43
|
const cPart = '(?:C(?:\\[[+-]?\\d+\\]|[1-9][0-9]{0,4})?)';
|
|
43
|
-
const re_RCCOL = new RegExp(`^${cPart}(:${cPart})
|
|
44
|
-
const re_RCROW = new RegExp(`^${rPart}(:${rPart})
|
|
45
|
-
const re_RCRANGE = new RegExp(`^(?:(?=[RC])${rPart}${cPart})`, 'i');
|
|
46
|
-
const re_RCPARTIAL = new RegExp(`^(${rPart}${cPart}(:${cPart}|:${rPart})(?![[\\d])|(${rPart}|${cPart})(:${rPart}${cPart}))
|
|
44
|
+
const re_RCCOL = new RegExp(`^${cPart}(:${cPart})?${nextNotChar}`, 'i');
|
|
45
|
+
const re_RCROW = new RegExp(`^${rPart}(:${rPart})?${nextNotChar}`, 'i');
|
|
46
|
+
const re_RCRANGE = new RegExp(`^(?:(?=[RC])${rPart}${cPart})${nextNotChar}`, 'i');
|
|
47
|
+
const re_RCPARTIAL = new RegExp(`^(${rPart}${cPart}(:${cPart}|:${rPart})(?![[\\d])|(${rPart}|${cPart})(:${rPart}${cPart}))${nextNotChar}`, 'i');
|
|
47
48
|
|
|
48
49
|
// The advertized named ranges rules are a bit off from what Excel seems to do:
|
|
49
50
|
// in the "extended range" of chars, it looks like it allows most things above
|
|
@@ -51,7 +52,7 @@ const re_RCPARTIAL = new RegExp(`^(${rPart}${cPart}(:${cPart}|:${rPart})(?![[\\d
|
|
|
51
52
|
// eslint-disable-next-line
|
|
52
53
|
// const re_NAMED = /^[a-zA-Z\\_¡¤§¨ª\u00ad¯\u00b0-\uffff][a-zA-Z0-9\\_.?¡¤§¨ª\u00ad¯\u00b0-\uffff]{0,254}/i;
|
|
53
54
|
// I've simplified to allowing everything above U+00A1:
|
|
54
|
-
const re_NAMED = /^
|
|
55
|
+
const re_NAMED = /^[a-zA-Z\\_\u00a1-\uffff][a-zA-Z0-9\\_.?\u00a1-\uffff]{0,254}/i;
|
|
55
56
|
|
|
56
57
|
function makeHandler (type, re) {
|
|
57
58
|
return str => {
|
|
@@ -62,6 +63,17 @@ function makeHandler (type, re) {
|
|
|
62
63
|
};
|
|
63
64
|
}
|
|
64
65
|
|
|
66
|
+
function lexNamed (str) {
|
|
67
|
+
const m = re_NAMED.exec(str);
|
|
68
|
+
if (m) {
|
|
69
|
+
const lc = m[0].toLowerCase();
|
|
70
|
+
if (lc === 'r' || lc === 'c') {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
return { type: REF_NAMED, value: m[0] };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
65
77
|
const re_QUOTED_VALUE = /^'(?:[^[\]]+?)?(?:\[(.+?)\])?(?:[^[\]]+?)'$/;
|
|
66
78
|
const re_QUOTED_VALUE_XLSX = /^'\[(.+?)\]'$/;
|
|
67
79
|
function lexContext (str, options) {
|
|
@@ -130,9 +142,9 @@ function lexRange (str, options) {
|
|
|
130
142
|
if (t) {
|
|
131
143
|
reRCNums.lastIndex = 0;
|
|
132
144
|
while ((m = reRCNums.exec(t.value)) !== null) {
|
|
133
|
-
const x = (m[1] === 'R' ? MAX_ROWS : MAX_COLS) + (m[2] ?
|
|
145
|
+
const x = (m[1] === 'R' ? MAX_ROWS : MAX_COLS) + (m[2] ? 0 : 1);
|
|
134
146
|
const val = parseInt(m[3], 10);
|
|
135
|
-
if (val
|
|
147
|
+
if (val > x || val < -x) {
|
|
136
148
|
return null;
|
|
137
149
|
}
|
|
138
150
|
}
|
|
@@ -192,7 +204,7 @@ export const lexers = [
|
|
|
192
204
|
lexRange,
|
|
193
205
|
lexStructured,
|
|
194
206
|
makeHandler(NUMBER, re_NUMBER),
|
|
195
|
-
|
|
207
|
+
lexNamed
|
|
196
208
|
];
|
|
197
209
|
|
|
198
210
|
export const lexersRefs = [
|
|
@@ -200,5 +212,5 @@ export const lexersRefs = [
|
|
|
200
212
|
lexContext,
|
|
201
213
|
lexRange,
|
|
202
214
|
lexStructured,
|
|
203
|
-
|
|
215
|
+
lexNamed
|
|
204
216
|
];
|
package/lib/parseRef.spec.js
CHANGED
|
@@ -21,40 +21,51 @@ test('splitPrefix', t => {
|
|
|
21
21
|
testStr('[foo][bar][baz]', false, [
|
|
22
22
|
{ value: 'foo', braced: true },
|
|
23
23
|
{ value: 'bar', braced: true },
|
|
24
|
-
{ value: 'baz', braced: true }
|
|
24
|
+
{ value: 'baz', braced: true }
|
|
25
|
+
]);
|
|
25
26
|
testStr('foo[bar][baz]', false, [
|
|
26
27
|
{ value: 'foo', braced: false },
|
|
27
28
|
{ value: 'bar', braced: true },
|
|
28
|
-
{ value: 'baz', braced: true }
|
|
29
|
+
{ value: 'baz', braced: true }
|
|
30
|
+
]);
|
|
29
31
|
testStr('[foo]bar[baz]', false, [
|
|
30
32
|
{ value: 'foo', braced: true },
|
|
31
33
|
{ value: 'bar', braced: false },
|
|
32
|
-
{ value: 'baz', braced: true }
|
|
34
|
+
{ value: 'baz', braced: true }
|
|
35
|
+
]);
|
|
33
36
|
testStr('[foo][bar]baz', false, [
|
|
34
37
|
{ value: 'foo', braced: true },
|
|
35
38
|
{ value: 'bar', braced: true },
|
|
36
|
-
{ value: 'baz', braced: false }
|
|
39
|
+
{ value: 'baz', braced: false }
|
|
40
|
+
]);
|
|
37
41
|
testStr('foo[bar]baz', false, [
|
|
38
42
|
{ value: 'foo', braced: false },
|
|
39
43
|
{ value: 'bar', braced: true },
|
|
40
|
-
{ value: 'baz', braced: false }
|
|
44
|
+
{ value: 'baz', braced: false }
|
|
45
|
+
]);
|
|
41
46
|
testStr('[foo]bar[baz]', false, [
|
|
42
47
|
{ value: 'foo', braced: true },
|
|
43
48
|
{ value: 'bar', braced: false },
|
|
44
|
-
{ value: 'baz', braced: true }
|
|
49
|
+
{ value: 'baz', braced: true }
|
|
50
|
+
]);
|
|
45
51
|
testStr('[foo]bar', false, [
|
|
46
52
|
{ value: 'foo', braced: true },
|
|
47
|
-
{ value: 'bar', braced: false }
|
|
53
|
+
{ value: 'bar', braced: false }
|
|
54
|
+
]);
|
|
48
55
|
testStr('foo[bar]', false, [
|
|
49
56
|
{ value: 'foo', braced: false },
|
|
50
|
-
{ value: 'bar', braced: true }
|
|
57
|
+
{ value: 'bar', braced: true }
|
|
58
|
+
]);
|
|
51
59
|
testStr('[foo][bar]', false, [
|
|
52
60
|
{ value: 'foo', braced: true },
|
|
53
|
-
{ value: 'bar', braced: true }
|
|
61
|
+
{ value: 'bar', braced: true }
|
|
62
|
+
]);
|
|
54
63
|
testStr('[foo]', false, [
|
|
55
|
-
{ value: 'foo', braced: true }
|
|
64
|
+
{ value: 'foo', braced: true }
|
|
65
|
+
]);
|
|
56
66
|
testStr('foo', false, [
|
|
57
|
-
{ value: 'foo', braced: false }
|
|
67
|
+
{ value: 'foo', braced: false }
|
|
68
|
+
]);
|
|
58
69
|
|
|
59
70
|
t.end();
|
|
60
71
|
});
|
package/lib/parser.js
CHANGED
package/lib/parser.spec.js
CHANGED
|
@@ -227,7 +227,8 @@ test('parse array literals', t => {
|
|
|
227
227
|
[ { type: 'Literal', value: 1234, raw: '1234' } ],
|
|
228
228
|
[ { type: 'CallExpression', callee: { type: 'Identifier', name: 'UNIQUE' }, arguments: [
|
|
229
229
|
{ type: 'ReferenceIdentifier', value: 'A:A' }
|
|
230
|
-
] } ]
|
|
230
|
+
] } ]
|
|
231
|
+
] },
|
|
231
232
|
{ permitArrayCalls: true });
|
|
232
233
|
// permitArrayCalls can be nested
|
|
233
234
|
t.isParsed('={SUM({1,2}),3}',
|
|
@@ -235,9 +236,11 @@ test('parse array literals', t => {
|
|
|
235
236
|
[ { type: 'CallExpression', callee: { type: 'Identifier', name: 'SUM' }, arguments: [
|
|
236
237
|
{ type: 'ArrayExpression', elements: [ [
|
|
237
238
|
{ type: 'Literal', value: 1, raw: '1' },
|
|
238
|
-
{ type: 'Literal', value: 2, raw: '2' }
|
|
239
|
+
{ type: 'Literal', value: 2, raw: '2' }
|
|
240
|
+
] ] }
|
|
239
241
|
] },
|
|
240
|
-
{ type: 'Literal', value: 3, raw: '3' } ]
|
|
242
|
+
{ type: 'Literal', value: 3, raw: '3' } ]
|
|
243
|
+
] },
|
|
241
244
|
{ permitArrayCalls: true });
|
|
242
245
|
t.end();
|
|
243
246
|
});
|
|
@@ -259,7 +262,8 @@ test('parse function calls', t => {
|
|
|
259
262
|
type: 'CallExpression', callee: { type: 'Identifier', name: 'FOO' },
|
|
260
263
|
arguments: [
|
|
261
264
|
{ type: 'Literal', value: 1, raw: '1' },
|
|
262
|
-
{ type: 'Literal', value: 2, raw: '2' }
|
|
265
|
+
{ type: 'Literal', value: 2, raw: '2' }
|
|
266
|
+
]
|
|
263
267
|
});
|
|
264
268
|
const args = Array(300).fill('1');
|
|
265
269
|
t.isParsed(`=FOO(${args.join(',')})`, {
|
|
@@ -270,20 +274,24 @@ test('parse function calls', t => {
|
|
|
270
274
|
type: 'CallExpression', callee: { type: 'Identifier', name: 'FOO' },
|
|
271
275
|
arguments: [
|
|
272
276
|
{ type: 'ReferenceIdentifier', value: 'A1' },
|
|
273
|
-
{ type: 'ReferenceIdentifier', value: 'B2' }
|
|
277
|
+
{ type: 'ReferenceIdentifier', value: 'B2' }
|
|
278
|
+
]
|
|
274
279
|
});
|
|
275
280
|
t.isParsed('=FOO((A1,B2))', {
|
|
276
281
|
type: 'CallExpression', callee: { type: 'Identifier', name: 'FOO' },
|
|
277
282
|
arguments: [
|
|
278
283
|
{ type: 'BinaryExpression', operator: ',', arguments: [
|
|
279
284
|
{ type: 'ReferenceIdentifier', value: 'A1' },
|
|
280
|
-
{ type: 'ReferenceIdentifier', value: 'B2' }
|
|
285
|
+
{ type: 'ReferenceIdentifier', value: 'B2' }
|
|
286
|
+
] }
|
|
287
|
+
]
|
|
281
288
|
});
|
|
282
289
|
t.isParsed('=FOO(BAR())', {
|
|
283
290
|
type: 'CallExpression', callee: { type: 'Identifier', name: 'FOO' },
|
|
284
291
|
arguments: [
|
|
285
292
|
{ type: 'CallExpression', callee: { type: 'Identifier', name: 'BAR' },
|
|
286
|
-
arguments: [] }
|
|
293
|
+
arguments: [] }
|
|
294
|
+
]
|
|
287
295
|
});
|
|
288
296
|
t.isParsed('=FOO(,)', {
|
|
289
297
|
type: 'CallExpression', callee: { type: 'Identifier', name: 'FOO' },
|
|
@@ -479,8 +487,18 @@ test('parse unary operator @', t => {
|
|
|
479
487
|
// parse binary operators
|
|
480
488
|
// FIXME: add precedence & associativity tests (2+3*4)
|
|
481
489
|
[
|
|
482
|
-
'+',
|
|
483
|
-
'
|
|
490
|
+
'+',
|
|
491
|
+
'-',
|
|
492
|
+
'^',
|
|
493
|
+
'*',
|
|
494
|
+
'/',
|
|
495
|
+
'&',
|
|
496
|
+
'=',
|
|
497
|
+
'<',
|
|
498
|
+
'>',
|
|
499
|
+
'<=',
|
|
500
|
+
'>=',
|
|
501
|
+
'<>'
|
|
484
502
|
].forEach(op => {
|
|
485
503
|
test('parse binary operator ' + op, t => {
|
|
486
504
|
t.isParsed(`1${op}2`, {
|
|
@@ -496,8 +514,10 @@ test('parse unary operator @', t => {
|
|
|
496
514
|
{ type: 'BinaryExpression', operator: op,
|
|
497
515
|
arguments: [
|
|
498
516
|
{ type: 'Literal', value: 1, raw: '1' },
|
|
499
|
-
{ type: 'Literal', value: 2, raw: '2' }
|
|
500
|
-
|
|
517
|
+
{ type: 'Literal', value: 2, raw: '2' }
|
|
518
|
+
] },
|
|
519
|
+
{ type: 'Literal', value: 3, raw: '3' }
|
|
520
|
+
]
|
|
501
521
|
});
|
|
502
522
|
t.isParsed(`"foo"${op}"bar"`, {
|
|
503
523
|
type: 'BinaryExpression', operator: op,
|
|
@@ -518,10 +538,12 @@ test('parse unary operator @', t => {
|
|
|
518
538
|
arguments: [
|
|
519
539
|
{ type: 'ArrayExpression', elements: [ [
|
|
520
540
|
{ type: 'Literal', value: 1, raw: '1' },
|
|
521
|
-
{ type: 'Literal', value: 2, raw: '2' }
|
|
541
|
+
{ type: 'Literal', value: 2, raw: '2' }
|
|
542
|
+
] ] },
|
|
522
543
|
{ type: 'ArrayExpression', elements: [ [
|
|
523
544
|
{ type: 'Literal', value: 3, raw: '3' },
|
|
524
|
-
{ type: 'Literal', value: 4, raw: '4' }
|
|
545
|
+
{ type: 'Literal', value: 4, raw: '4' }
|
|
546
|
+
] ] }
|
|
525
547
|
]
|
|
526
548
|
});
|
|
527
549
|
t.isParsed(`FOO()${op}BAR()`, {
|
|
@@ -552,22 +574,26 @@ test('parse unary operator @', t => {
|
|
|
552
574
|
type: 'BinaryExpression', operator: op,
|
|
553
575
|
arguments: [
|
|
554
576
|
{ type: 'ReferenceIdentifier', value: 'named1' },
|
|
555
|
-
{ type: 'ReferenceIdentifier', value: 'named2' }
|
|
577
|
+
{ type: 'ReferenceIdentifier', value: 'named2' }
|
|
578
|
+
] });
|
|
556
579
|
t.isParsed(`A1${op}named2`, {
|
|
557
580
|
type: 'BinaryExpression', operator: op,
|
|
558
581
|
arguments: [
|
|
559
582
|
{ type: 'ReferenceIdentifier', value: 'A1' },
|
|
560
|
-
{ type: 'ReferenceIdentifier', value: 'named2' }
|
|
583
|
+
{ type: 'ReferenceIdentifier', value: 'named2' }
|
|
584
|
+
] });
|
|
561
585
|
t.isParsed(`named1${op}B2`, {
|
|
562
586
|
type: 'BinaryExpression', operator: op,
|
|
563
587
|
arguments: [
|
|
564
588
|
{ type: 'ReferenceIdentifier', value: 'named1' },
|
|
565
|
-
{ type: 'ReferenceIdentifier', value: 'B2' }
|
|
589
|
+
{ type: 'ReferenceIdentifier', value: 'B2' }
|
|
590
|
+
] });
|
|
566
591
|
t.isParsed(`(A1)${op}(B2)`, {
|
|
567
592
|
type: 'BinaryExpression', operator: op,
|
|
568
593
|
arguments: [
|
|
569
594
|
{ type: 'ReferenceIdentifier', value: 'A1' },
|
|
570
|
-
{ type: 'ReferenceIdentifier', value: 'B2' }
|
|
595
|
+
{ type: 'ReferenceIdentifier', value: 'B2' }
|
|
596
|
+
] });
|
|
571
597
|
t.isInvalidExpr(`A1${op}0`);
|
|
572
598
|
t.isInvalidExpr(`0${op}A1`);
|
|
573
599
|
t.isInvalidExpr(`0${op}0`);
|
|
@@ -578,12 +604,14 @@ test('parse unary operator @', t => {
|
|
|
578
604
|
type: 'BinaryExpression', operator: op,
|
|
579
605
|
arguments: [
|
|
580
606
|
{ type: 'ReferenceIdentifier', value: 'A1' },
|
|
581
|
-
{ type: 'ErrorLiteral', value: '#REF!', raw: '#REF!' }
|
|
607
|
+
{ type: 'ErrorLiteral', value: '#REF!', raw: '#REF!' }
|
|
608
|
+
] });
|
|
582
609
|
t.isParsed(`#REF!${op}B2`, {
|
|
583
610
|
type: 'BinaryExpression', operator: op,
|
|
584
611
|
arguments: [
|
|
585
612
|
{ type: 'ErrorLiteral', value: '#REF!', raw: '#REF!' },
|
|
586
|
-
{ type: 'ReferenceIdentifier', value: 'B2' }
|
|
613
|
+
{ type: 'ReferenceIdentifier', value: 'B2' }
|
|
614
|
+
] });
|
|
587
615
|
t.isInvalidExpr(`A1${op}#NAME?`);
|
|
588
616
|
t.isInvalidExpr(`A1${op}#VALUE!`);
|
|
589
617
|
t.isInvalidExpr(`#NULL!${op}A1`);
|
|
@@ -595,8 +623,10 @@ test('parse unary operator @', t => {
|
|
|
595
623
|
{ type: 'BinaryExpression', operator: ',',
|
|
596
624
|
arguments: [
|
|
597
625
|
{ type: 'ReferenceIdentifier', value: 'A1' },
|
|
598
|
-
{ type: 'ReferenceIdentifier', value: 'B2' }
|
|
599
|
-
|
|
626
|
+
{ type: 'ReferenceIdentifier', value: 'B2' }
|
|
627
|
+
] },
|
|
628
|
+
{ type: 'ReferenceIdentifier', value: 'C3' }
|
|
629
|
+
] });
|
|
600
630
|
t.isParsed(`C3${op}(A1,B2)`, {
|
|
601
631
|
type: 'BinaryExpression', operator: op,
|
|
602
632
|
arguments: [
|
|
@@ -604,7 +634,8 @@ test('parse unary operator @', t => {
|
|
|
604
634
|
{ type: 'BinaryExpression', operator: ',',
|
|
605
635
|
arguments: [
|
|
606
636
|
{ type: 'ReferenceIdentifier', value: 'A1' },
|
|
607
|
-
{ type: 'ReferenceIdentifier', value: 'B2' }
|
|
637
|
+
{ type: 'ReferenceIdentifier', value: 'B2' }
|
|
638
|
+
] }
|
|
608
639
|
] });
|
|
609
640
|
// intersection ops
|
|
610
641
|
t.isParsed(`(A1 B2)${op}C3`, {
|
|
@@ -613,8 +644,10 @@ test('parse unary operator @', t => {
|
|
|
613
644
|
{ type: 'BinaryExpression', operator: ' ',
|
|
614
645
|
arguments: [
|
|
615
646
|
{ type: 'ReferenceIdentifier', value: 'A1' },
|
|
616
|
-
{ type: 'ReferenceIdentifier', value: 'B2' }
|
|
617
|
-
|
|
647
|
+
{ type: 'ReferenceIdentifier', value: 'B2' }
|
|
648
|
+
] },
|
|
649
|
+
{ type: 'ReferenceIdentifier', value: 'C3' }
|
|
650
|
+
] });
|
|
618
651
|
t.isParsed(`C3${op}(A1 B2)`, {
|
|
619
652
|
type: 'BinaryExpression', operator: op,
|
|
620
653
|
arguments: [
|
|
@@ -622,7 +655,8 @@ test('parse unary operator @', t => {
|
|
|
622
655
|
{ type: 'BinaryExpression', operator: ' ',
|
|
623
656
|
arguments: [
|
|
624
657
|
{ type: 'ReferenceIdentifier', value: 'A1' },
|
|
625
|
-
{ type: 'ReferenceIdentifier', value: 'B2' }
|
|
658
|
+
{ type: 'ReferenceIdentifier', value: 'B2' }
|
|
659
|
+
] }
|
|
626
660
|
] });
|
|
627
661
|
// join ops
|
|
628
662
|
t.isParsed(`(A1:(B2))${op}C3`, {
|
|
@@ -631,8 +665,10 @@ test('parse unary operator @', t => {
|
|
|
631
665
|
{ type: 'BinaryExpression', operator: ':',
|
|
632
666
|
arguments: [
|
|
633
667
|
{ type: 'ReferenceIdentifier', value: 'A1' },
|
|
634
|
-
{ type: 'ReferenceIdentifier', value: 'B2' }
|
|
635
|
-
|
|
668
|
+
{ type: 'ReferenceIdentifier', value: 'B2' }
|
|
669
|
+
] },
|
|
670
|
+
{ type: 'ReferenceIdentifier', value: 'C3' }
|
|
671
|
+
] });
|
|
636
672
|
t.isParsed(`C3${op}(A1:(B2))`, {
|
|
637
673
|
type: 'BinaryExpression', operator: op,
|
|
638
674
|
arguments: [
|
|
@@ -640,7 +676,8 @@ test('parse unary operator @', t => {
|
|
|
640
676
|
{ type: 'BinaryExpression', operator: ':',
|
|
641
677
|
arguments: [
|
|
642
678
|
{ type: 'ReferenceIdentifier', value: 'A1' },
|
|
643
|
-
{ type: 'ReferenceIdentifier', value: 'B2' }
|
|
679
|
+
{ type: 'ReferenceIdentifier', value: 'B2' }
|
|
680
|
+
] }
|
|
644
681
|
] });
|
|
645
682
|
// ref calls
|
|
646
683
|
([
|
|
@@ -743,33 +780,38 @@ test('position information is correct', t => {
|
|
|
743
780
|
t.isParsed(
|
|
744
781
|
'=-A1',
|
|
745
782
|
{ type: 'UnaryExpression', loc: [ 1, 4 ], operator: '-', arguments: [
|
|
746
|
-
{ type: 'ReferenceIdentifier', value: 'A1', loc: [ 2, 4 ] }
|
|
783
|
+
{ type: 'ReferenceIdentifier', value: 'A1', loc: [ 2, 4 ] }
|
|
784
|
+
] },
|
|
747
785
|
{ withLocation: true }
|
|
748
786
|
);
|
|
749
787
|
t.isParsed(
|
|
750
788
|
'=10%',
|
|
751
789
|
{ type: 'UnaryExpression', loc: [ 1, 4 ], operator: '%', arguments: [
|
|
752
|
-
{ type: 'Literal', value: 10, loc: [ 1, 3 ], raw: '10' }
|
|
790
|
+
{ type: 'Literal', value: 10, loc: [ 1, 3 ], raw: '10' }
|
|
791
|
+
] },
|
|
753
792
|
{ withLocation: true }
|
|
754
793
|
);
|
|
755
794
|
t.isParsed(
|
|
756
795
|
'=-(123)',
|
|
757
796
|
{ type: 'UnaryExpression', loc: [ 1, 6 ], operator: '-', arguments: [
|
|
758
|
-
{ type: 'Literal', value: 123, loc: [ 3, 6 ], raw: '123' }
|
|
797
|
+
{ type: 'Literal', value: 123, loc: [ 3, 6 ], raw: '123' }
|
|
798
|
+
] },
|
|
759
799
|
{ withLocation: true }
|
|
760
800
|
);
|
|
761
801
|
t.isParsed(
|
|
762
802
|
'(123+(234))',
|
|
763
803
|
{ type: 'BinaryExpression', loc: [ 1, 9 ], operator: '+', arguments: [
|
|
764
804
|
{ type: 'Literal', value: 123, loc: [ 1, 4 ], raw: '123' },
|
|
765
|
-
{ type: 'Literal', value: 234, loc: [ 6, 9 ], raw: '234' }
|
|
805
|
+
{ type: 'Literal', value: 234, loc: [ 6, 9 ], raw: '234' }
|
|
806
|
+
] },
|
|
766
807
|
{ withLocation: true }
|
|
767
808
|
);
|
|
768
809
|
t.isParsed(
|
|
769
810
|
'=(A1 B2)',
|
|
770
811
|
{ type: 'BinaryExpression', loc: [ 2, 7 ], operator: ' ', arguments: [
|
|
771
812
|
{ type: 'ReferenceIdentifier', value: 'A1', loc: [ 2, 4 ] },
|
|
772
|
-
{ type: 'ReferenceIdentifier', value: 'B2', loc: [ 5, 7 ] }
|
|
813
|
+
{ type: 'ReferenceIdentifier', value: 'B2', loc: [ 5, 7 ] }
|
|
814
|
+
] },
|
|
773
815
|
{ withLocation: true }
|
|
774
816
|
);
|
|
775
817
|
t.isParsed(
|
|
@@ -789,7 +831,8 @@ test('position information is correct', t => {
|
|
|
789
831
|
[ { type: 'Literal', value: 1, loc: [ 3, 4 ], raw: '1' },
|
|
790
832
|
{ type: 'Literal', value: 2, loc: [ 6, 7 ], raw: '2' } ],
|
|
791
833
|
[ { type: 'Literal', value: 3, loc: [ 9, 10 ], raw: '3' },
|
|
792
|
-
{ type: 'Literal', value: 4, loc: [ 12, 13 ], raw: '4' } ]
|
|
834
|
+
{ type: 'Literal', value: 4, loc: [ 12, 13 ], raw: '4' } ]
|
|
835
|
+
] },
|
|
793
836
|
{ withLocation: true }
|
|
794
837
|
);
|
|
795
838
|
t.end();
|
|
@@ -802,7 +845,9 @@ test('does not tolerate unterminated tokens', t => {
|
|
|
802
845
|
arguments: [
|
|
803
846
|
{ type: 'ArrayExpression', elements: [
|
|
804
847
|
[ { type: 'ReferenceIdentifier', value: 'A:A' },
|
|
805
|
-
{ type: 'ReferenceIdentifier', value: 'B:B' } ]
|
|
848
|
+
{ type: 'ReferenceIdentifier', value: 'B:B' } ]
|
|
849
|
+
] }
|
|
850
|
+
] },
|
|
806
851
|
{ permitArrayRanges: true });
|
|
807
852
|
// whitespace in arguments
|
|
808
853
|
t.isParsed('=A2:A5=XLOOKUP(B1,C:C, D:D)',
|
|
@@ -812,19 +857,23 @@ test('does not tolerate unterminated tokens', t => {
|
|
|
812
857
|
arguments: [
|
|
813
858
|
{ type: 'ReferenceIdentifier', value: 'B1' },
|
|
814
859
|
{ type: 'ReferenceIdentifier', value: 'C:C' },
|
|
815
|
-
{ type: 'ReferenceIdentifier', value: 'D:D' }
|
|
860
|
+
{ type: 'ReferenceIdentifier', value: 'D:D' }
|
|
861
|
+
] }
|
|
862
|
+
] },
|
|
816
863
|
{ permitArrayRanges: true });
|
|
817
864
|
// whitespace surrounding comma
|
|
818
865
|
t.isParsed('=SUM(12 , B:B)',
|
|
819
866
|
{ type: 'CallExpression', callee: { type: 'Identifier', name: 'SUM' }, arguments: [
|
|
820
867
|
{ type: 'Literal', value: 12, raw: '12' },
|
|
821
|
-
{ type: 'ReferenceIdentifier', value: 'B:B' }
|
|
868
|
+
{ type: 'ReferenceIdentifier', value: 'B:B' }
|
|
869
|
+
] },
|
|
822
870
|
{ permitArrayCalls: true });
|
|
823
871
|
// whitespace tailing operator
|
|
824
872
|
t.isParsed('=A:A= C1',
|
|
825
873
|
{ type: 'BinaryExpression', operator: '=', arguments: [
|
|
826
874
|
{ type: 'ReferenceIdentifier', value: 'A:A' },
|
|
827
|
-
{ type: 'ReferenceIdentifier', value: 'C1' }
|
|
875
|
+
{ type: 'ReferenceIdentifier', value: 'C1' }
|
|
876
|
+
] },
|
|
828
877
|
{ permitArrayCalls: true });
|
|
829
878
|
t.end();
|
|
830
879
|
});
|
|
@@ -835,7 +884,9 @@ test('parser can permit xlsx mode references', t => {
|
|
|
835
884
|
{ type: 'CallExpression', callee: { type: 'Identifier', name: 'SUM' }, arguments: [
|
|
836
885
|
{ type: 'BinaryExpression', operator: '+', arguments: [
|
|
837
886
|
{ type: 'ReferenceIdentifier', value: '[Workbook.xlsx]!A1' },
|
|
838
|
-
{ type: 'ReferenceIdentifier', value: '[Workbook.xlsx]!Table1[#Data]' }
|
|
887
|
+
{ type: 'ReferenceIdentifier', value: '[Workbook.xlsx]!Table1[#Data]' }
|
|
888
|
+
] }
|
|
889
|
+
] },
|
|
839
890
|
{ xlsx: true });
|
|
840
891
|
t.end();
|
|
841
892
|
});
|
package/lib/rc.js
CHANGED
|
@@ -47,13 +47,15 @@ export function toR1C1 (range) {
|
|
|
47
47
|
c1 = clamp($c1 ? 0 : -MAX_COLS, c1 | 0, MAX_COLS);
|
|
48
48
|
}
|
|
49
49
|
// C:C
|
|
50
|
-
|
|
50
|
+
const allRows = r0 === 0 && r1 >= MAX_ROWS;
|
|
51
|
+
if ((allRows && !nullC0 && !nullC1) || (nullR0 && nullR1)) {
|
|
51
52
|
const a = toCoord(c0, $c0);
|
|
52
53
|
const b = toCoord(c1, $c1);
|
|
53
54
|
return 'C' + (a === b ? a : a + ':C' + b);
|
|
54
55
|
}
|
|
55
56
|
// R:R
|
|
56
|
-
|
|
57
|
+
const allCols = c0 === 0 && c1 >= MAX_COLS;
|
|
58
|
+
if ((allCols && !nullR0 && !nullR1) || (nullC0 && nullC1)) {
|
|
57
59
|
const a = toCoord(r0, $r0);
|
|
58
60
|
const b = toCoord(r1, $r1);
|
|
59
61
|
return 'R' + (a === b ? a : a + ':R' + b);
|
package/lib/sr.spec.js
CHANGED
|
@@ -88,6 +88,13 @@ test('parse structured references', t => {
|
|
|
88
88
|
context: [ 'Sheet1' ]
|
|
89
89
|
});
|
|
90
90
|
|
|
91
|
+
t.isSREqual('[myworkbook.xlsx]Sheet1!TMP8w0habhr[#All]', {
|
|
92
|
+
columns: [],
|
|
93
|
+
table: 'TMP8w0habhr',
|
|
94
|
+
context: [ 'myworkbook.xlsx', 'Sheet1' ],
|
|
95
|
+
sections: [ 'all' ]
|
|
96
|
+
});
|
|
97
|
+
|
|
91
98
|
t.end();
|
|
92
99
|
});
|
|
93
100
|
|
|
@@ -100,7 +100,7 @@ test('translate partials from RC to A1', t => {
|
|
|
100
100
|
t.end();
|
|
101
101
|
});
|
|
102
102
|
|
|
103
|
-
test('translate
|
|
103
|
+
test('translate bounds coords from RC to A1', t => {
|
|
104
104
|
t.isR2A('=C[-1]', 'A1', '=XFD:XFD');
|
|
105
105
|
t.isR2A('=C[-2]', 'A1', '=XFC:XFC');
|
|
106
106
|
t.isR2A('=RC[16383]', 'B1', '=A1');
|
|
@@ -110,6 +110,10 @@ test('translate out of bounds coords from RC to A1', t => {
|
|
|
110
110
|
t.isR2A('=R[1048575]C', 'A2', '=A1');
|
|
111
111
|
t.isR2A('=R[1048575]C', 'A3', '=A2');
|
|
112
112
|
|
|
113
|
+
t.isR2A('=R1:R1048576', 'A1', '=$1:$1048576');
|
|
114
|
+
t.isR2A('=C1:C16384', 'A1', '=$A:$XFD');
|
|
115
|
+
t.isR2A('=R1C1:R1048576C16384', 'A1', '=$A$1:$XFD$1048576');
|
|
116
|
+
|
|
113
117
|
const f1 = '=R[-1]C[-1]';
|
|
114
118
|
t.is(translateToA1(f1, 'A1', { wrapEdges: false }), '=#REF!', f1);
|
|
115
119
|
|
|
@@ -95,11 +95,14 @@ test('translate partials from A1 to RC', t => {
|
|
|
95
95
|
t.end();
|
|
96
96
|
});
|
|
97
97
|
|
|
98
|
-
test('translate
|
|
98
|
+
test('translate boundary coords from A1 to RC', t => {
|
|
99
99
|
t.isA2R('=XFD:XFD', 'A1', '=C[16383]');
|
|
100
100
|
t.isA2R('=A1', 'B1', '=RC[-1]');
|
|
101
101
|
t.isA2R('=B1', 'C1', '=RC[-1]');
|
|
102
102
|
t.isA2R('=1048576:1048576', 'A1', '=R[1048575]');
|
|
103
|
+
t.isA2R('=$1:$1048576', 'A1', '=R1:R1048576');
|
|
104
|
+
t.isA2R('=$A:$XFD', 'A1', '=C1:C16384');
|
|
105
|
+
t.isA2R('=$A$1:$XFD$1048576', 'A1', '=R1C1:R1048576C16384');
|
|
103
106
|
t.isA2R('=A1', 'A2', '=R[-1]C');
|
|
104
107
|
t.isA2R('=A2', 'A3', '=R[-1]C');
|
|
105
108
|
t.end();
|