After a bit of playing around, it seemed messy to make it into a join, but we could replace the two array_agg sub-selects with a single one:
(SELECT pg_catalog.array_agg(ROW(attname, attstattarget) ORDER BY attnum) FROM pg_catalog.pg_attribute WHERE attrelid = i.indexrelid)
and then what we need could be pulled out of that, although I'm not sure if pg_dump has logic at hand for deconstructing an array of composite.
From what I can see, it doesn't. Moreover, the attstattarget array agg is only done in version 11 and higher, and we need to go as far back as we've got expression indexes.
Or we could leave it as two array_aggs, aggregating attname and attstattarget separately but removing the attstattarget filter.
That's what I was thinking, thanks for the confirmation.