Skip to content

Commit 40e86f3

Browse files
committed
Fix error with OFFSET range with multisheet cell reference
1 parent 42bf966 commit 40e86f3

4 files changed

Lines changed: 25 additions & 4 deletions

File tree

jest.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,11 @@ module.exports = {
5050
transform: {
5151
"^.+\\.(ts|tsx)$": "ts-jest"
5252
},
53+
54+
watchPathIgnorePatterns: [
55+
'/node_modules/',
56+
'/dist/',
57+
'/commonjs/',
58+
'/es/',
59+
]
5360
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
"test": "npm-run-all lint test:unit test:browser test:compatibility",
7979
"test:unit": "cross-env NODE_ICU_DATA=node_modules/full-icu jest",
8080
"test:watch": "cross-env NODE_ICU_DATA=node_modules/full-icu jest --watch",
81-
"test:tdd": "cross-env NODE_ICU_DATA=node_modules/full-icu jest --watch custom-functions",
81+
"test:tdd": "cross-env NODE_ICU_DATA=node_modules/full-icu jest --watch offset",
8282
"test:coverage": "npm run test:unit -- --coverage",
8383
"test:logMemory": "cross-env NODE_ICU_DATA=node_modules/full-icu jest --runInBand --logHeapUsage",
8484
"test:unit.ci": "cross-env NODE_ICU_DATA=node_modules/full-icu node --expose-gc ./node_modules/jest/bin/jest --forceExit",

src/parser/FormulaParser.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -843,8 +843,10 @@ export class FormulaParser extends EmbeddedActionsParser {
843843
topLeftCorner.col + width - 1,
844844
topLeftCorner.row + height - 1,
845845
topLeftCorner.type,
846+
topLeftCorner.sheet,
846847
)
847-
return buildCellRangeAst(topLeftCorner, bottomRightCorner, RangeSheetReferenceType.RELATIVE)
848+
const rangeSheetReferenceType = cellArg.reference.sheet == null ? RangeSheetReferenceType.RELATIVE : RangeSheetReferenceType.BOTH_ABSOLUTE
849+
return buildCellRangeAst(topLeftCorner, bottomRightCorner, rangeSheetReferenceType)
848850
}
849851
}
850852

test/unit/parser/offset-translation.spec.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,18 @@ describe('Parser - OFFSET to reference translation', () => {
6868
expect(ast.end).toEqual(CellAddress.relative(8, 13))
6969
})
7070

71+
it('OFFSET parsing into cell range in different sheet', () => {
72+
const sheetMapping = new SheetMapping(buildTranslationPackage(enUS))
73+
sheetMapping.addSheet('Sheet1')
74+
sheetMapping.addSheet('Sheet2')
75+
const parser = buildEmptyParserWithCaching(new Config(), sheetMapping)
76+
77+
const ast = parser.parse('=OFFSET(Sheet2!F16, 0, 2, 1, 3)', adr('B3', 0)).ast as CellRangeAst
78+
expect(ast.type).toBe(AstNodeType.CELL_RANGE)
79+
expect(ast.start).toEqual(CellAddress.relative(6, 13, 1))
80+
expect(ast.end).toEqual(CellAddress.relative(8, 13, 1))
81+
})
82+
7183
it('OFFSET first argument need to be reference', () => {
7284
const parser = buildEmptyParserWithCaching(new Config())
7385

@@ -186,9 +198,9 @@ describe('Parser - OFFSET to reference translation', () => {
186198
sheetMapping.addSheet('Sheet2')
187199
const parser = buildEmptyParserWithCaching(new Config(), sheetMapping)
188200

189-
const ast = parser.parse('=OFFSET(Sheet1!A1, 0, 0)', adr('A1', 1)).ast as CellReferenceAst
201+
const ast = parser.parse('=OFFSET(Sheet2!A1, 0, 0)', adr('A1', 0)).ast as CellReferenceAst
190202
expect(ast.type).toBe(AstNodeType.CELL_REFERENCE)
191-
expect(ast.reference).toEqual(CellAddress.relative(0, 0, 0))
203+
expect(ast.reference).toEqual(CellAddress.relative(0, 0, 1))
192204
})
193205

194206
it('function OFFSET can reference a different sheet', () => {

0 commit comments

Comments
 (0)