Skip to content

fix: a quoted prefix after a range operator loses its quotes, changing meaning - #64

Open
gthb wants to merge 4 commits into
borgar:masterfrom
gthb:range-operator-prefix-quoting
Open

fix: a quoted prefix after a range operator loses its quotes, changing meaning#64
gthb wants to merge 4 commits into
borgar:masterfrom
gthb:range-operator-prefix-quoting

Conversation

@gthb

@gthb gthb commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

fixFormulaRanges rewrites =SUM(foo:'Gamma'!A1) to =SUM(foo:Gamma!A1), which is the 3-D reference over the sheets foo to Gamma rather than the name foo joined to 'Gamma'!A1. The quote around the right endpoint is what makes the colon a range operator, so dropping it changes which sheets a formula refers to. Excel stores that position quoted whatever the name.

Quoting was derived from the sheet name alone. fixRanges now keeps the quotes a source wrote on a prefix after a range operator, where dropping them would leave a sheet range. A bracketed prefix (Jan:'[1]Nope'!A1) still loses quotes it does not need.

translateToA1 already adds those quotes to match Excel. Two fixes to that pass:

  • It only recognized a colon immediately before the prefix, so a prefix separated from the colon by whitespace, which Excel allows, was left unquoted. Both functions now use followsRangeOperator in stringifyPrefix.ts.
  • It lengthened the tokens it quoted without moving the loc of later tokens. Those now shift by the added characters.

docs/Prefixes.md says how the two functions differ.

gthb added 4 commits September 2, 2026 18:00
fixFormulaRanges rewrote =SUM(Q1:'Sales'!A1) to =SUM(Q1:Sales!A1), which is
the 3-D reference over the sheets Q1 to Sales rather than the name Q1
joined to 'Sales'!A1. Excel stores a range operation with its right prefix
quoted, so the normalization changed which sheets a formula refers to.

Quoting was derived from the sheet name alone. fixRanges now keeps the
quotes a source wrote on a prefix right of a range operator, where dropping
them would leave a sheet range; a bracketed prefix (Jan:'[1]Nope'!A1) still
loses quotes it does not need.

translateToA1 already added those quotes to match Excel, but only when the
colon was the immediate neighbour, so a prefix behind whitespace, which
Excel allows, was missed. Both now ask followsRangeOperator in
stringifyPrefix.ts. That pass also lengthened tokens without moving the loc
of later ones; it now carries the skew forward.

docs/Prefixes.md says how the two functions differ.
borgar#63 rewrites the body of the digit-leading test and appends a new block
right after it. Keeping master's title on that test, and putting this
branch's new test next to the quoted-RHS test it belongs with, lets the
two branches merge without conflict.

No change to what is asserted.
The test comment and the prefix docs both said that dropping the quotes
in `Q1:'Sales'!A1` would leave the sheet range `Q1:Sales`. It would not:
a left endpoint that reads as a cell address is that cell, and wins over
the sheet-range reading, so `Q1:Sales!A1` is the cell `Q1` joined to
`Sales!A1` and means what the quoted form means. Both examples were
picked from the one class where the rewrite is harmless.

Use `foo:'Gamma'!A1`, where the left endpoint can be no cell address and
the quotes really do decide: unquoted it is the sheet range `foo:Gamma`,
quoted it is the name joined to `'Gamma'!A1`. Added as a test case; the
cell-address cases stay, described as what they are.

No behaviour change — the fix already covered both.
@gthb gthb changed the title fix: a quoted prefix after a range operator loses its quotes fix: a quoted prefix after a range operator loses its quotes, changing meaning Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant