@odoo/o-spreadsheet 14.0.1 → 14.0.2
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/o_spreadsheet.cjs.js +17836 -0
- package/dist/o_spreadsheet.d.ts +4102 -0
- package/dist/o_spreadsheet.esm.js +17801 -0
- package/dist/o_spreadsheet.iife.js +17838 -0
- package/dist/o_spreadsheet.iife.min.js +1440 -0
- package/package.json +27 -7
- package/readme.md +10 -0
- package/.eslintrc.json +0 -20
- package/.husky/post-checkout +0 -9
- package/.husky/pre-commit +0 -39
- package/.prettierignore +0 -1
- package/astToFormula.patch +0 -0
- package/demo/data.js +0 -255
- package/demo/index.html +0 -9
- package/demo/libs/Chart.bundle.js +0 -20755
- package/demo/main.js +0 -101
- package/doc/readme.md +0 -46
- package/rollup.config.js +0 -23
- package/src/base_plugin.ts +0 -102
- package/src/components/autofill.ts +0 -146
- package/src/components/bottom_bar.ts +0 -199
- package/src/components/color_picker.ts +0 -150
- package/src/components/composer/autocomplete_dropdown.ts +0 -135
- package/src/components/composer/composer.ts +0 -487
- package/src/components/composer/content_editable_helper.ts +0 -146
- package/src/components/figures/chart.ts +0 -70
- package/src/components/figures/container.ts +0 -268
- package/src/components/figures/text_figure.ts +0 -36
- package/src/components/grid.ts +0 -635
- package/src/components/helpers/dom_helpers.ts +0 -7
- package/src/components/helpers/drag_and_drop.ts +0 -17
- package/src/components/icons.ts +0 -36
- package/src/components/index.ts +0 -1
- package/src/components/menu.ts +0 -288
- package/src/components/overlay.ts +0 -457
- package/src/components/scrollbar.ts +0 -22
- package/src/components/selection_input.ts +0 -168
- package/src/components/side_panel/cell_is_rule_editor.ts +0 -169
- package/src/components/side_panel/chart_panel.ts +0 -104
- package/src/components/side_panel/color_scale_rule_editor.ts +0 -145
- package/src/components/side_panel/conditional_formatting.ts +0 -396
- package/src/components/side_panel/side_panel.ts +0 -127
- package/src/components/side_panel/translations_terms.ts +0 -45
- package/src/components/spreadsheet.ts +0 -198
- package/src/components/top_bar.ts +0 -535
- package/src/constants.ts +0 -26
- package/src/data.ts +0 -149
- package/src/fonts.ts +0 -41
- package/src/formulas/compiler.ts +0 -258
- package/src/formulas/composer_tokenizer.ts +0 -70
- package/src/formulas/index.ts +0 -15
- package/src/formulas/normalize.ts +0 -52
- package/src/formulas/parser.ts +0 -280
- package/src/formulas/range_tokenizer.ts +0 -97
- package/src/formulas/tokenizer.ts +0 -242
- package/src/functions/arguments.ts +0 -114
- package/src/functions/dates.ts +0 -302
- package/src/functions/helpers.ts +0 -592
- package/src/functions/index.ts +0 -52
- package/src/functions/module_database.ts +0 -282
- package/src/functions/module_date.ts +0 -743
- package/src/functions/module_info.ts +0 -69
- package/src/functions/module_logical.ts +0 -208
- package/src/functions/module_lookup.ts +0 -185
- package/src/functions/module_math.ts +0 -1252
- package/src/functions/module_operators.ts +0 -291
- package/src/functions/module_statistical.ts +0 -882
- package/src/functions/module_text.ts +0 -370
- package/src/helpers/color.ts +0 -30
- package/src/helpers/coordinates.ts +0 -71
- package/src/helpers/grid_manipulation.ts +0 -68
- package/src/helpers/index.ts +0 -7
- package/src/helpers/misc.ts +0 -76
- package/src/helpers/numbers.ts +0 -117
- package/src/helpers/uuid.ts +0 -19
- package/src/helpers/zones.ts +0 -263
- package/src/history.ts +0 -186
- package/src/index.ts +0 -84
- package/src/model.ts +0 -261
- package/src/plugins/autofill.ts +0 -412
- package/src/plugins/chart.ts +0 -404
- package/src/plugins/clipboard.ts +0 -461
- package/src/plugins/conditional_format.ts +0 -445
- package/src/plugins/core.ts +0 -1502
- package/src/plugins/edition.ts +0 -157
- package/src/plugins/evaluation.ts +0 -428
- package/src/plugins/figures.ts +0 -123
- package/src/plugins/formatting.ts +0 -630
- package/src/plugins/highlight.ts +0 -187
- package/src/plugins/index.ts +0 -32
- package/src/plugins/merge.ts +0 -524
- package/src/plugins/renderer.ts +0 -571
- package/src/plugins/selection.ts +0 -562
- package/src/plugins/selection_inputs.ts +0 -326
- package/src/registries/autofill_modifiers.ts +0 -76
- package/src/registries/autofill_rules.ts +0 -98
- package/src/registries/figure_registry.ts +0 -30
- package/src/registries/index.ts +0 -7
- package/src/registries/menu_items_registry.ts +0 -110
- package/src/registries/menus/cell_menu_registry.ts +0 -79
- package/src/registries/menus/col_menu_registry.ts +0 -63
- package/src/registries/menus/index.ts +0 -6
- package/src/registries/menus/menu_items_actions.ts +0 -425
- package/src/registries/menus/row_menu_registry.ts +0 -63
- package/src/registries/menus/sheet_menu_registry.ts +0 -75
- package/src/registries/menus/topbar_menu_registry.ts +0 -204
- package/src/registries/side_panel_registry.ts +0 -26
- package/src/registries/topbar_component_registry.ts +0 -12
- package/src/registry.ts +0 -51
- package/src/translation.ts +0 -44
- package/src/types/autofill.ts +0 -48
- package/src/types/chart.ts +0 -26
- package/src/types/commands.ts +0 -716
- package/src/types/conditional_formatting.ts +0 -124
- package/src/types/env.ts +0 -13
- package/src/types/functions.ts +0 -35
- package/src/types/getters.ts +0 -103
- package/src/types/index.ts +0 -20
- package/src/types/misc.ts +0 -143
- package/src/types/rendering.ts +0 -41
- package/src/types/workbook_data.ts +0 -62
- package/tests/__mocks__/uuid.ts +0 -7
- package/tests/canvas.mock.ts +0 -34
- package/tests/components/__mocks__/content_editable_helper.ts +0 -79
- package/tests/components/__mocks__/scrollbar.ts +0 -18
- package/tests/components/__snapshots__/autocomplete_dropdown_test.ts.snap +0 -29
- package/tests/components/__snapshots__/bottom_bar_test.ts.snap +0 -75
- package/tests/components/__snapshots__/context_menu_test.ts.snap +0 -88
- package/tests/components/__snapshots__/grid_test.ts.snap +0 -60
- package/tests/components/__snapshots__/spreadsheet_test.ts.snap +0 -455
- package/tests/components/__snapshots__/top_bar_test.ts.snap +0 -705
- package/tests/components/autocomplete_dropdown_test.ts +0 -315
- package/tests/components/autofill_test.ts +0 -167
- package/tests/components/bottom_bar_test.ts +0 -262
- package/tests/components/chart_side_panel_test.ts +0 -123
- package/tests/components/composer_test.ts +0 -400
- package/tests/components/context_menu_test.ts +0 -825
- package/tests/components/grid_manipulation_test.ts +0 -163
- package/tests/components/grid_test.ts +0 -581
- package/tests/components/overlay_test.ts +0 -541
- package/tests/components/selection_input_test.ts +0 -259
- package/tests/components/side_panel_test.ts +0 -148
- package/tests/components/spreadsheet_test.ts +0 -194
- package/tests/components/top_bar_test.ts +0 -427
- package/tests/data_test.ts +0 -175
- package/tests/dom_helper.ts +0 -42
- package/tests/formulas/__snapshots__/compiler_test.ts.snap +0 -302
- package/tests/formulas/compiler_test.ts +0 -266
- package/tests/formulas/composer_tokenizer_test.ts +0 -137
- package/tests/formulas/expressions_test.ts +0 -57
- package/tests/formulas/formulas_test.ts +0 -80
- package/tests/formulas/normalize_test.ts +0 -82
- package/tests/formulas/parser_test.ts +0 -224
- package/tests/formulas/range_tokenizer_test.ts +0 -187
- package/tests/formulas/tokenizer_test.ts +0 -164
- package/tests/functions/arguments_test.ts +0 -141
- package/tests/functions/dates_test.ts +0 -1081
- package/tests/functions/functions_test.ts +0 -53
- package/tests/functions/helper_test.ts +0 -98
- package/tests/functions/module_database_test.ts +0 -311
- package/tests/functions/module_date_test.ts +0 -941
- package/tests/functions/module_info_test.ts +0 -139
- package/tests/functions/module_logical_test.ts +0 -369
- package/tests/functions/module_lookup_test.ts +0 -541
- package/tests/functions/module_math_test.ts +0 -2482
- package/tests/functions/module_operators_test.ts +0 -955
- package/tests/functions/module_statistical_test.ts +0 -2014
- package/tests/functions/module_text_test.ts +0 -667
- package/tests/helpers/coordinates_test.ts +0 -25
- package/tests/helpers/misc_test.ts +0 -95
- package/tests/helpers/numbers_test.ts +0 -196
- package/tests/helpers/zones_test.ts +0 -97
- package/tests/helpers.ts +0 -384
- package/tests/menu_items_registry_test.ts +0 -540
- package/tests/model/plugins/__snapshots__/chart_test.ts.snap +0 -90
- package/tests/model/plugins/chart_test.ts +0 -562
- package/tests/model_test.ts +0 -82
- package/tests/plugins/__snapshots__/conditional_formatting_test.ts.snap +0 -131
- package/tests/plugins/__snapshots__/renderer_test.ts.snap +0 -371
- package/tests/plugins/autofill_test.ts +0 -457
- package/tests/plugins/borders_test.ts +0 -295
- package/tests/plugins/clipboard_test.ts +0 -1180
- package/tests/plugins/conditional_formatting_test.ts +0 -1253
- package/tests/plugins/core_test.ts +0 -614
- package/tests/plugins/edition_test.ts +0 -100
- package/tests/plugins/evaluation_async_test.ts +0 -332
- package/tests/plugins/evaluation_dates_test.ts +0 -79
- package/tests/plugins/evaluation_test.ts +0 -901
- package/tests/plugins/figures_test.ts +0 -327
- package/tests/plugins/formatting_test.ts +0 -391
- package/tests/plugins/grid_manipulation_test.ts +0 -1366
- package/tests/plugins/highlight_test.ts +0 -413
- package/tests/plugins/history_test.ts +0 -142
- package/tests/plugins/import_export_test.ts +0 -276
- package/tests/plugins/merges_test.ts +0 -490
- package/tests/plugins/navigation_test.ts +0 -181
- package/tests/plugins/plugins/evaluation_test.ts +0 -111
- package/tests/plugins/renderer_test.ts +0 -598
- package/tests/plugins/resizing_test.ts +0 -152
- package/tests/plugins/selection_input_test.ts +0 -409
- package/tests/plugins/selection_test.ts +0 -442
- package/tests/plugins/sheets_test.ts +0 -643
- package/tests/plugins/style_test.ts +0 -90
- package/tsconfig.json +0 -22
|
@@ -1,302 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`compile functions with lazy arguments functions call requesting lazy parameters 1`] = `
|
|
4
|
-
"function anonymous(deps,sheetId,ref,range,ctx
|
|
5
|
-
) {
|
|
6
|
-
// =USELAZYARG(|N0|)
|
|
7
|
-
let _2 = ()=> deps[0]
|
|
8
|
-
ctx.__lastFnCalled = 'USELAZYARG'
|
|
9
|
-
let _1 = ctx['USELAZYARG'](_2)
|
|
10
|
-
return _1;
|
|
11
|
-
}"
|
|
12
|
-
`;
|
|
13
|
-
|
|
14
|
-
exports[`compile functions with lazy arguments functions call requesting lazy parameters 2`] = `
|
|
15
|
-
"function anonymous(deps,sheetId,ref,range,ctx
|
|
16
|
-
) {
|
|
17
|
-
// =USELAZYARG(|N0|/|N1|)
|
|
18
|
-
let _3 = deps[0]
|
|
19
|
-
let _4 = deps[1]
|
|
20
|
-
ctx.__lastFnCalled = 'DIVIDE'
|
|
21
|
-
let _2 = ()=> ctx['DIVIDE'](_3, _4)
|
|
22
|
-
ctx.__lastFnCalled = 'USELAZYARG'
|
|
23
|
-
let _1 = ctx['USELAZYARG'](_2)
|
|
24
|
-
return _1;
|
|
25
|
-
}"
|
|
26
|
-
`;
|
|
27
|
-
|
|
28
|
-
exports[`expression compiler async functions 1`] = `
|
|
29
|
-
"async function anonymous(deps,sheetId,ref,range,ctx
|
|
30
|
-
) {
|
|
31
|
-
// =WAIT(|N0|)
|
|
32
|
-
let _2 = deps[0]
|
|
33
|
-
ctx.__lastFnCalled = 'WAIT'
|
|
34
|
-
let _1 = await ctx['WAIT'](_2)
|
|
35
|
-
return _1;
|
|
36
|
-
}"
|
|
37
|
-
`;
|
|
38
|
-
|
|
39
|
-
exports[`expression compiler cells are converted to ranges if function require a range 1`] = `
|
|
40
|
-
"function anonymous(deps,sheetId,ref,range,ctx
|
|
41
|
-
) {
|
|
42
|
-
// =sum(|0|)
|
|
43
|
-
let _2 = range(0, deps, sheetId)
|
|
44
|
-
ctx.__lastFnCalled = 'SUM'
|
|
45
|
-
let _1 = ctx['SUM'](_2)
|
|
46
|
-
return _1;
|
|
47
|
-
}"
|
|
48
|
-
`;
|
|
49
|
-
|
|
50
|
-
exports[`expression compiler expression with $ref 1`] = `
|
|
51
|
-
"function anonymous(deps,sheetId,ref,range,ctx
|
|
52
|
-
) {
|
|
53
|
-
// =|0|+|1|+|2|
|
|
54
|
-
let _3 = ref(0, deps, sheetId,
|
|
55
|
-
\\"undefined\\", undefined)
|
|
56
|
-
let _4 = ref(1, deps, sheetId,
|
|
57
|
-
\\"undefined\\", undefined)
|
|
58
|
-
ctx.__lastFnCalled = 'ADD'
|
|
59
|
-
let _2 = ctx['ADD'](_3, _4)
|
|
60
|
-
let _5 = ref(2, deps, sheetId,
|
|
61
|
-
\\"undefined\\", undefined)
|
|
62
|
-
ctx.__lastFnCalled = 'ADD'
|
|
63
|
-
let _1 = ctx['ADD'](_2, _5)
|
|
64
|
-
return _1;
|
|
65
|
-
}"
|
|
66
|
-
`;
|
|
67
|
-
|
|
68
|
-
exports[`expression compiler expression with references with a sheet 1`] = `
|
|
69
|
-
"function anonymous(deps,sheetId,ref,range,ctx
|
|
70
|
-
) {
|
|
71
|
-
// =|0|
|
|
72
|
-
let _1 = ref(0, deps, sheetId,
|
|
73
|
-
\\"undefined\\", undefined)
|
|
74
|
-
return _1;
|
|
75
|
-
}"
|
|
76
|
-
`;
|
|
77
|
-
|
|
78
|
-
exports[`expression compiler expressions with a debugger 1`] = `
|
|
79
|
-
"function anonymous(deps,sheetId,ref,range,ctx
|
|
80
|
-
) {
|
|
81
|
-
// =? |0| / |N1|
|
|
82
|
-
debugger;
|
|
83
|
-
let _2 = ref(0, deps, sheetId,
|
|
84
|
-
\\"undefined\\", undefined)
|
|
85
|
-
let _3 = deps[1]
|
|
86
|
-
ctx.__lastFnCalled = 'DIVIDE'
|
|
87
|
-
let _1 = ctx['DIVIDE'](_2, _3)
|
|
88
|
-
return _1;
|
|
89
|
-
}"
|
|
90
|
-
`;
|
|
91
|
-
|
|
92
|
-
exports[`expression compiler function call (with lazy parameters) 1`] = `
|
|
93
|
-
"function anonymous(deps,sheetId,ref,range,ctx
|
|
94
|
-
) {
|
|
95
|
-
// =IF(TRUE, |N0|, |N1|)
|
|
96
|
-
let _2 = true
|
|
97
|
-
let _3 = ()=> deps[0]
|
|
98
|
-
let _4 = ()=> deps[1]
|
|
99
|
-
ctx.__lastFnCalled = 'IF'
|
|
100
|
-
let _1 = ctx['IF'](_2,_3,_4)
|
|
101
|
-
return _1;
|
|
102
|
-
}"
|
|
103
|
-
`;
|
|
104
|
-
|
|
105
|
-
exports[`expression compiler function call (with lazy parameters) 2`] = `
|
|
106
|
-
"function anonymous(deps,sheetId,ref,range,ctx
|
|
107
|
-
) {
|
|
108
|
-
// =IF(TRUE, |0|, |N1|/|N2|)
|
|
109
|
-
let _2 = true
|
|
110
|
-
let _3 = ()=> ref(0, deps, sheetId,
|
|
111
|
-
\\"IF\\", 2)
|
|
112
|
-
let _5 = deps[1]
|
|
113
|
-
let _6 = deps[2]
|
|
114
|
-
ctx.__lastFnCalled = 'DIVIDE'
|
|
115
|
-
let _4 = ()=> ctx['DIVIDE'](_5, _6)
|
|
116
|
-
ctx.__lastFnCalled = 'IF'
|
|
117
|
-
let _1 = ctx['IF'](_2,_3,_4)
|
|
118
|
-
return _1;
|
|
119
|
-
}"
|
|
120
|
-
`;
|
|
121
|
-
|
|
122
|
-
exports[`expression compiler function call (with lazy parameters) 3`] = `
|
|
123
|
-
"function anonymous(deps,sheetId,ref,range,ctx
|
|
124
|
-
) {
|
|
125
|
-
// =IF(TRUE, IF(TRUE, |0|, SQRT(-|N1|)), |N1|/|N2|)
|
|
126
|
-
let _2 = true
|
|
127
|
-
let _4 = true
|
|
128
|
-
let _5 = ()=> ref(0, deps, sheetId,
|
|
129
|
-
\\"IF\\", 2)
|
|
130
|
-
let _8 = deps[1]
|
|
131
|
-
ctx.__lastFnCalled = 'UMINUS'
|
|
132
|
-
let _7 = ctx['UMINUS']( _8)
|
|
133
|
-
ctx.__lastFnCalled = 'SQRT'
|
|
134
|
-
let _6 = ()=> ctx['SQRT'](_7)
|
|
135
|
-
ctx.__lastFnCalled = 'IF'
|
|
136
|
-
let _3 = ()=> ctx['IF'](_4,_5,_6)
|
|
137
|
-
let _10 = deps[1]
|
|
138
|
-
let _11 = deps[2]
|
|
139
|
-
ctx.__lastFnCalled = 'DIVIDE'
|
|
140
|
-
let _9 = ()=> ctx['DIVIDE'](_10, _11)
|
|
141
|
-
ctx.__lastFnCalled = 'IF'
|
|
142
|
-
let _1 = ctx['IF'](_2,_3,_9)
|
|
143
|
-
return _1;
|
|
144
|
-
}"
|
|
145
|
-
`;
|
|
146
|
-
|
|
147
|
-
exports[`expression compiler function call 1`] = `
|
|
148
|
-
"function anonymous(deps,sheetId,ref,range,ctx
|
|
149
|
-
) {
|
|
150
|
-
// =sum(|N0|,|N1|)
|
|
151
|
-
let _2 = deps[0]
|
|
152
|
-
let _3 = deps[1]
|
|
153
|
-
ctx.__lastFnCalled = 'SUM'
|
|
154
|
-
let _1 = ctx['SUM'](_2,_3)
|
|
155
|
-
return _1;
|
|
156
|
-
}"
|
|
157
|
-
`;
|
|
158
|
-
|
|
159
|
-
exports[`expression compiler function call 2`] = `
|
|
160
|
-
"function anonymous(deps,sheetId,ref,range,ctx
|
|
161
|
-
) {
|
|
162
|
-
// =sum(true, |S0|)
|
|
163
|
-
let _2 = true
|
|
164
|
-
let _3 = deps[0]
|
|
165
|
-
ctx.__lastFnCalled = 'SUM'
|
|
166
|
-
let _1 = ctx['SUM'](_2,_3)
|
|
167
|
-
return _1;
|
|
168
|
-
}"
|
|
169
|
-
`;
|
|
170
|
-
|
|
171
|
-
exports[`expression compiler function call 3`] = `
|
|
172
|
-
"function anonymous(deps,sheetId,ref,range,ctx
|
|
173
|
-
) {
|
|
174
|
-
// =sum(|N0|,,|N1|)
|
|
175
|
-
let _2 = deps[0]
|
|
176
|
-
let _3 = deps[1]
|
|
177
|
-
ctx.__lastFnCalled = 'SUM'
|
|
178
|
-
let _1 = ctx['SUM'](_2,null,_3)
|
|
179
|
-
return _1;
|
|
180
|
-
}"
|
|
181
|
-
`;
|
|
182
|
-
|
|
183
|
-
exports[`expression compiler read some values and functions 1`] = `
|
|
184
|
-
"function anonymous(deps,sheetId,ref,range,ctx
|
|
185
|
-
) {
|
|
186
|
-
// =|0| + sum(|1|)
|
|
187
|
-
let _2 = ref(0, deps, sheetId,
|
|
188
|
-
\\"undefined\\", undefined)
|
|
189
|
-
let _4 = range(1, deps, sheetId)
|
|
190
|
-
ctx.__lastFnCalled = 'SUM'
|
|
191
|
-
let _3 = ctx['SUM'](_4)
|
|
192
|
-
ctx.__lastFnCalled = 'ADD'
|
|
193
|
-
let _1 = ctx['ADD'](_2, _3)
|
|
194
|
-
return _1;
|
|
195
|
-
}"
|
|
196
|
-
`;
|
|
197
|
-
|
|
198
|
-
exports[`expression compiler simple values 1`] = `
|
|
199
|
-
"function anonymous(deps,sheetId,ref,range,ctx
|
|
200
|
-
) {
|
|
201
|
-
// =|N0|
|
|
202
|
-
let _1 = deps[0]
|
|
203
|
-
return _1;
|
|
204
|
-
}"
|
|
205
|
-
`;
|
|
206
|
-
|
|
207
|
-
exports[`expression compiler simple values 2`] = `
|
|
208
|
-
"function anonymous(deps,sheetId,ref,range,ctx
|
|
209
|
-
) {
|
|
210
|
-
// =true
|
|
211
|
-
let _1 = true
|
|
212
|
-
return _1;
|
|
213
|
-
}"
|
|
214
|
-
`;
|
|
215
|
-
|
|
216
|
-
exports[`expression compiler simple values 3`] = `
|
|
217
|
-
"function anonymous(deps,sheetId,ref,range,ctx
|
|
218
|
-
) {
|
|
219
|
-
// =|S0|
|
|
220
|
-
let _1 = deps[0]
|
|
221
|
-
return _1;
|
|
222
|
-
}"
|
|
223
|
-
`;
|
|
224
|
-
|
|
225
|
-
exports[`expression compiler some arithmetic expressions 1`] = `
|
|
226
|
-
"function anonymous(deps,sheetId,ref,range,ctx
|
|
227
|
-
) {
|
|
228
|
-
// =|N0| + |N1|
|
|
229
|
-
let _2 = deps[0]
|
|
230
|
-
let _3 = deps[1]
|
|
231
|
-
ctx.__lastFnCalled = 'ADD'
|
|
232
|
-
let _1 = ctx['ADD'](_2, _3)
|
|
233
|
-
return _1;
|
|
234
|
-
}"
|
|
235
|
-
`;
|
|
236
|
-
|
|
237
|
-
exports[`expression compiler some arithmetic expressions 2`] = `
|
|
238
|
-
"function anonymous(deps,sheetId,ref,range,ctx
|
|
239
|
-
) {
|
|
240
|
-
// =|N0| * |N1|
|
|
241
|
-
let _2 = deps[0]
|
|
242
|
-
let _3 = deps[1]
|
|
243
|
-
ctx.__lastFnCalled = 'MULTIPLY'
|
|
244
|
-
let _1 = ctx['MULTIPLY'](_2, _3)
|
|
245
|
-
return _1;
|
|
246
|
-
}"
|
|
247
|
-
`;
|
|
248
|
-
|
|
249
|
-
exports[`expression compiler some arithmetic expressions 3`] = `
|
|
250
|
-
"function anonymous(deps,sheetId,ref,range,ctx
|
|
251
|
-
) {
|
|
252
|
-
// =|N0| - |N1|
|
|
253
|
-
let _2 = deps[0]
|
|
254
|
-
let _3 = deps[1]
|
|
255
|
-
ctx.__lastFnCalled = 'MINUS'
|
|
256
|
-
let _1 = ctx['MINUS'](_2, _3)
|
|
257
|
-
return _1;
|
|
258
|
-
}"
|
|
259
|
-
`;
|
|
260
|
-
|
|
261
|
-
exports[`expression compiler some arithmetic expressions 4`] = `
|
|
262
|
-
"function anonymous(deps,sheetId,ref,range,ctx
|
|
263
|
-
) {
|
|
264
|
-
// =|N0| / |N1|
|
|
265
|
-
let _2 = deps[0]
|
|
266
|
-
let _3 = deps[1]
|
|
267
|
-
ctx.__lastFnCalled = 'DIVIDE'
|
|
268
|
-
let _1 = ctx['DIVIDE'](_2, _3)
|
|
269
|
-
return _1;
|
|
270
|
-
}"
|
|
271
|
-
`;
|
|
272
|
-
|
|
273
|
-
exports[`expression compiler some arithmetic expressions 5`] = `
|
|
274
|
-
"function anonymous(deps,sheetId,ref,range,ctx
|
|
275
|
-
) {
|
|
276
|
-
// =-|N0|
|
|
277
|
-
let _2 = deps[0]
|
|
278
|
-
ctx.__lastFnCalled = 'UMINUS'
|
|
279
|
-
let _1 = ctx['UMINUS']( _2)
|
|
280
|
-
return _1;
|
|
281
|
-
}"
|
|
282
|
-
`;
|
|
283
|
-
|
|
284
|
-
exports[`expression compiler some arithmetic expressions 6`] = `
|
|
285
|
-
"function anonymous(deps,sheetId,ref,range,ctx
|
|
286
|
-
) {
|
|
287
|
-
// =(|N0| + |N1|) * (-|N1| + |N2|)
|
|
288
|
-
let _3 = deps[0]
|
|
289
|
-
let _4 = deps[1]
|
|
290
|
-
ctx.__lastFnCalled = 'ADD'
|
|
291
|
-
let _2 = ctx['ADD'](_3, _4)
|
|
292
|
-
let _7 = deps[1]
|
|
293
|
-
ctx.__lastFnCalled = 'UMINUS'
|
|
294
|
-
let _6 = ctx['UMINUS']( _7)
|
|
295
|
-
let _8 = deps[2]
|
|
296
|
-
ctx.__lastFnCalled = 'ADD'
|
|
297
|
-
let _5 = ctx['ADD'](_6, _8)
|
|
298
|
-
ctx.__lastFnCalled = 'MULTIPLY'
|
|
299
|
-
let _1 = ctx['MULTIPLY'](_2, _5)
|
|
300
|
-
return _1;
|
|
301
|
-
}"
|
|
302
|
-
`;
|
|
@@ -1,266 +0,0 @@
|
|
|
1
|
-
import { Model } from "../../src";
|
|
2
|
-
import { functionCache } from "../../src/formulas/compiler";
|
|
3
|
-
import { compile, normalize } from "../../src/formulas/index";
|
|
4
|
-
import { functionRegistry } from "../../src/functions/index";
|
|
5
|
-
import { ArgType, NormalizedFormula } from "../../src/types";
|
|
6
|
-
import { evaluateCell } from "../helpers";
|
|
7
|
-
|
|
8
|
-
function compiledBaseFunction(formula: string): string {
|
|
9
|
-
for (let f in functionCache) {
|
|
10
|
-
delete functionCache[f];
|
|
11
|
-
}
|
|
12
|
-
compileFromCompleteFormula(formula);
|
|
13
|
-
return Object.values(functionCache)[0].toString();
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function compileFromCompleteFormula(formula: string) {
|
|
17
|
-
let formulaString: NormalizedFormula = normalize(formula);
|
|
18
|
-
return compile(formulaString);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
describe("expression compiler", () => {
|
|
22
|
-
test("simple values", () => {
|
|
23
|
-
expect(compiledBaseFunction("=1")).toMatchSnapshot();
|
|
24
|
-
expect(compiledBaseFunction("=true")).toMatchSnapshot();
|
|
25
|
-
expect(compiledBaseFunction(`="abc"`)).toMatchSnapshot();
|
|
26
|
-
|
|
27
|
-
expect(() => compiledBaseFunction(`='abc'`)).toThrowError();
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test("some arithmetic expressions", () => {
|
|
31
|
-
expect(compiledBaseFunction("=1 + 3")).toMatchSnapshot();
|
|
32
|
-
expect(compiledBaseFunction("=2 * 3")).toMatchSnapshot();
|
|
33
|
-
expect(compiledBaseFunction("=2 - 3")).toMatchSnapshot();
|
|
34
|
-
expect(compiledBaseFunction("=2 / 3")).toMatchSnapshot();
|
|
35
|
-
expect(compiledBaseFunction("=-3")).toMatchSnapshot();
|
|
36
|
-
expect(compiledBaseFunction("=(3 + 1) * (-1 + 4)")).toMatchSnapshot();
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
test("function call", () => {
|
|
40
|
-
expect(compiledBaseFunction("=sum(1,2)")).toMatchSnapshot();
|
|
41
|
-
expect(compiledBaseFunction('=sum(true, "")')).toMatchSnapshot();
|
|
42
|
-
expect(compiledBaseFunction("=sum(1,,2)")).toMatchSnapshot();
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
test("function call (with lazy parameters)", () => {
|
|
46
|
-
expect(compiledBaseFunction("=IF(TRUE, 42, 24)")).toMatchSnapshot();
|
|
47
|
-
expect(compiledBaseFunction("=IF(TRUE, A2, 1/0)")).toMatchSnapshot();
|
|
48
|
-
expect(compiledBaseFunction("=IF(TRUE, IF(TRUE, A2, SQRT(-1)), 1/0)")).toMatchSnapshot();
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
test("read some values and functions", () => {
|
|
52
|
-
expect(compiledBaseFunction("=A1 + sum(A2:C3)")).toMatchSnapshot();
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
test("expression with $ref", () => {
|
|
56
|
-
expect(compiledBaseFunction("=$A1+$A$2+A$3")).toMatchSnapshot();
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
test("expression with references with a sheet", () => {
|
|
60
|
-
expect(compiledBaseFunction("=Sheet34!B3")).toMatchSnapshot();
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
test("expressions with a debugger", () => {
|
|
64
|
-
expect(compiledBaseFunction("=? A1 / 2")).toMatchSnapshot();
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
test("async functions", () => {
|
|
68
|
-
expect(compiledBaseFunction("=WAIT(5)")).toMatchSnapshot();
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
test("cells are converted to ranges if function require a range", () => {
|
|
72
|
-
expect(compiledBaseFunction("=sum(A1)")).toMatchSnapshot();
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
test("cannot compile some invalid formulas", () => {
|
|
76
|
-
expect(() => compiledBaseFunction("=qsdf")).toThrow();
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
test("check at compile time for number of arguments", () => {
|
|
80
|
-
expect(() => compiledBaseFunction("=pi()")).not.toThrow();
|
|
81
|
-
expect(() => compiledBaseFunction("=pi(3)")).toThrowError("Invalid number of arguments");
|
|
82
|
-
expect(() => compiledBaseFunction("=sum()")).toThrowError("Invalid number of arguments");
|
|
83
|
-
expect(() => compiledBaseFunction("=sum(1)")).not.toThrowError();
|
|
84
|
-
expect(() => compiledBaseFunction("=sum(1,2)")).not.toThrowError();
|
|
85
|
-
expect(() => compiledBaseFunction("=sum(1,2,3)")).not.toThrowError();
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
describe("compile functions", () => {
|
|
90
|
-
describe("check number of arguments", () => {
|
|
91
|
-
test("with basic arguments", () => {
|
|
92
|
-
functionRegistry.add("ANYFUNCTION", {
|
|
93
|
-
description: "any function",
|
|
94
|
-
compute: () => {
|
|
95
|
-
return true;
|
|
96
|
-
},
|
|
97
|
-
args: [
|
|
98
|
-
{ name: "arg1", description: "", type: ["ANY"] },
|
|
99
|
-
{ name: "arg2", description: "", type: ["ANY"] },
|
|
100
|
-
],
|
|
101
|
-
returns: ["ANY"],
|
|
102
|
-
});
|
|
103
|
-
expect(() => compiledBaseFunction("=ANYFUNCTION()")).toThrow();
|
|
104
|
-
expect(() => compiledBaseFunction("=ANYFUNCTION(1)")).toThrow();
|
|
105
|
-
expect(() => compiledBaseFunction("=ANYFUNCTION(1,2)")).not.toThrow();
|
|
106
|
-
expect(() => compiledBaseFunction("=ANYFUNCTION(1,2,3)")).toThrow();
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
test("with optional argument", () => {
|
|
110
|
-
functionRegistry.add("OPTIONAL", {
|
|
111
|
-
description: "function with optional argument",
|
|
112
|
-
compute: (arg) => {
|
|
113
|
-
return true;
|
|
114
|
-
},
|
|
115
|
-
args: [
|
|
116
|
-
{ name: "arg1", description: "", type: ["ANY"] },
|
|
117
|
-
{ name: "arg2", description: "", type: ["ANY"], optional: true },
|
|
118
|
-
],
|
|
119
|
-
returns: ["ANY"],
|
|
120
|
-
});
|
|
121
|
-
expect(() => compiledBaseFunction("=OPTIONAL(1)")).not.toThrow();
|
|
122
|
-
expect(() => compiledBaseFunction("=OPTIONAL(1,2)")).not.toThrow();
|
|
123
|
-
expect(() => compiledBaseFunction("=OPTIONAL(1,2,3)")).toThrow();
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
test("with repeatable argument", () => {
|
|
127
|
-
functionRegistry.add("REPEATABLE", {
|
|
128
|
-
description: "function with repeatable argument",
|
|
129
|
-
compute: (arg) => {
|
|
130
|
-
return true;
|
|
131
|
-
},
|
|
132
|
-
args: [
|
|
133
|
-
{ name: "arg1", description: "", type: ["ANY"] },
|
|
134
|
-
{ name: "arg2", description: "", type: ["ANY"], optional: true, repeating: true },
|
|
135
|
-
],
|
|
136
|
-
returns: ["ANY"],
|
|
137
|
-
});
|
|
138
|
-
expect(() => compiledBaseFunction("=REPEATABLE(1)")).not.toThrow();
|
|
139
|
-
expect(() => compiledBaseFunction("=REPEATABLE(1,2)")).not.toThrow();
|
|
140
|
-
expect(() => compiledBaseFunction("=REPEATABLE(1,2,3,4,5,6)")).not.toThrow();
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
describe("check type of arguments", () => {
|
|
145
|
-
test("reject non-range argument when expecting only range argument", () => {
|
|
146
|
-
functionRegistry.add("RANGEEXPECTED", {
|
|
147
|
-
description: "function expect number in 1st arg",
|
|
148
|
-
compute: (arg) => {
|
|
149
|
-
return true;
|
|
150
|
-
},
|
|
151
|
-
args: [{ name: "arg1", description: "", type: ["RANGE"] }],
|
|
152
|
-
returns: ["ANY"],
|
|
153
|
-
});
|
|
154
|
-
expect(() => compiledBaseFunction("=RANGEEXPECTED(42)")).toThrowError(
|
|
155
|
-
"Function RANGEEXPECTED expects the parameter 1 to be reference to a cell or range, not a number."
|
|
156
|
-
);
|
|
157
|
-
expect(() => compiledBaseFunction('=RANGEEXPECTED("test")')).toThrowError(
|
|
158
|
-
"Function RANGEEXPECTED expects the parameter 1 to be reference to a cell or range, not a string."
|
|
159
|
-
);
|
|
160
|
-
expect(() => compiledBaseFunction("=RANGEEXPECTED(TRUE)")).toThrowError(
|
|
161
|
-
"Function RANGEEXPECTED expects the parameter 1 to be reference to a cell or range, not a boolean."
|
|
162
|
-
);
|
|
163
|
-
|
|
164
|
-
expect(() => compiledBaseFunction("=RANGEEXPECTED(A1)")).not.toThrow();
|
|
165
|
-
expect(() => compiledBaseFunction("=RANGEEXPECTED(A1:A1)")).not.toThrow();
|
|
166
|
-
expect(() => compiledBaseFunction("=RANGEEXPECTED(A1:A2)")).not.toThrow();
|
|
167
|
-
expect(() => compiledBaseFunction("=RANGEEXPECTED(A1:A$2)")).not.toThrow();
|
|
168
|
-
expect(() => compiledBaseFunction("=RANGEEXPECTED(sheet2!A1:A$2)")).not.toThrow();
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
test("reject range when expecting only non-range argument", () => {
|
|
172
|
-
for (let typeExpected of ["ANY", "BOOLEAN", "DATE", "NUMBER", "STRING"] as ArgType[]) {
|
|
173
|
-
functionRegistry.add(typeExpected + "EXPECTED", {
|
|
174
|
-
description: "function expect number in 1st arg",
|
|
175
|
-
compute: (arg) => {
|
|
176
|
-
return true;
|
|
177
|
-
},
|
|
178
|
-
args: [{ name: "arg1", description: "", type: [typeExpected] }],
|
|
179
|
-
returns: ["ANY"],
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
const m = new Model();
|
|
184
|
-
expect(() => m.getters.evaluateFormula("=ANYEXPECTED(A1:A2)")).toThrowError(
|
|
185
|
-
"Function ANYEXPECTED expects the parameter 1 to be a single value or a single cell reference, not a range."
|
|
186
|
-
);
|
|
187
|
-
expect(() => m.getters.evaluateFormula("=BOOLEANEXPECTED(A1:A2)")).toThrowError(
|
|
188
|
-
"Function BOOLEANEXPECTED expects the parameter 1 to be a single value or a single cell reference, not a range."
|
|
189
|
-
);
|
|
190
|
-
expect(() => m.getters.evaluateFormula("=DATEEXPECTED(A1:A2)")).toThrowError(
|
|
191
|
-
"Function DATEEXPECTED expects the parameter 1 to be a single value or a single cell reference, not a range."
|
|
192
|
-
);
|
|
193
|
-
expect(() => m.getters.evaluateFormula("=NUMBEREXPECTED(A1:A2)")).toThrowError(
|
|
194
|
-
"Function NUMBEREXPECTED expects the parameter 1 to be a single value or a single cell reference, not a range."
|
|
195
|
-
);
|
|
196
|
-
expect(() => m.getters.evaluateFormula("=STRINGEXPECTED(A1:A2)")).toThrowError(
|
|
197
|
-
"Function STRINGEXPECTED expects the parameter 1 to be a single value or a single cell reference, not a range."
|
|
198
|
-
);
|
|
199
|
-
|
|
200
|
-
expect(() => m.getters.evaluateFormula("=ANYEXPECTED(A1:A$2)")).toThrowError(
|
|
201
|
-
"Function ANYEXPECTED expects the parameter 1 to be a single value or a single cell reference, not a range."
|
|
202
|
-
);
|
|
203
|
-
expect(() => m.getters.evaluateFormula("=ANYEXPECTED(sheet2!A1:A$2)")).toThrowError(
|
|
204
|
-
"Function ANYEXPECTED expects the parameter 1 to be a single value or a single cell reference, not a range."
|
|
205
|
-
);
|
|
206
|
-
expect(() => m.getters.evaluateFormula("=ANYEXPECTED(A1:A1)")).not.toThrow();
|
|
207
|
-
});
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
describe("with lazy arguments", () => {
|
|
211
|
-
// this tests performs controls inside formula functions. For this reason, we
|
|
212
|
-
// don't use mocked functions. Errors would be caught during evaluation of
|
|
213
|
-
// formulas and not during the tests. So here we use a simple counter
|
|
214
|
-
|
|
215
|
-
let count = 0;
|
|
216
|
-
|
|
217
|
-
beforeAll(() => {
|
|
218
|
-
functionRegistry.add("ANYFUNCTION", {
|
|
219
|
-
description: "any function",
|
|
220
|
-
compute: () => {
|
|
221
|
-
count += 1;
|
|
222
|
-
return true;
|
|
223
|
-
},
|
|
224
|
-
args: [],
|
|
225
|
-
returns: ["ANY"],
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
functionRegistry.add("USELAZYARG", {
|
|
229
|
-
description: "function with a lazy argument",
|
|
230
|
-
compute: (arg) => {
|
|
231
|
-
count *= 42;
|
|
232
|
-
return arg();
|
|
233
|
-
},
|
|
234
|
-
args: [{ name: "lazyArg", description: "", type: ["ANY"], lazy: true }],
|
|
235
|
-
returns: ["ANY"],
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
functionRegistry.add("NOTUSELAZYARG", {
|
|
239
|
-
description: "any function",
|
|
240
|
-
compute: (arg) => {
|
|
241
|
-
count *= 42;
|
|
242
|
-
return arg;
|
|
243
|
-
},
|
|
244
|
-
args: [{ name: "any", description: "", type: ["ANY"] }],
|
|
245
|
-
returns: ["ANY"],
|
|
246
|
-
});
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
test("with function as argument --> change the order in which functions are evaluated ", () => {
|
|
250
|
-
count = 0;
|
|
251
|
-
evaluateCell("A1", { A1: "=USELAZYARG(ANYFUNCTION())" });
|
|
252
|
-
expect(count).toBe(1);
|
|
253
|
-
count = 0;
|
|
254
|
-
evaluateCell("A2", { A2: "=NOTUSELAZYARG(ANYFUNCTION())" });
|
|
255
|
-
expect(count).toBe(42);
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
test.each(["=USELAZYARG(24)", "=USELAZYARG(1/0)"])(
|
|
259
|
-
"functions call requesting lazy parameters",
|
|
260
|
-
(formula) => {
|
|
261
|
-
const compiledFormula = compiledBaseFunction(formula);
|
|
262
|
-
expect(compiledFormula.toString()).toMatchSnapshot();
|
|
263
|
-
}
|
|
264
|
-
);
|
|
265
|
-
});
|
|
266
|
-
});
|