DanielXMoore / Civet

A TypeScript superset that favors more types and less typing
https://civet.dev
MIT License
1.33k stars 28 forks source link

Fix complex negative property access #1263

Closed edemaine closed 1 month ago

edemaine commented 1 month ago

Input:

lastChild := node.children.-1

Output without this PR:

let ref;const lastChild = (ref = node.children[ref.length-1])

Output with this PR:

let ref;const lastChild = (ref = node.children)[ref.length-1]

Context

Civet doesn't work if built with current Civet because this line is compiling incorrectly:

https://github.com/DanielXMoore/Civet/blob/41ba011b4a506af1c0a08b22a838a46e9f637fd2/source/parser/binding.civet#L140

Hopefully this will allow us to upgrade Civet and fix the CLI according to #1261.

edemaine commented 1 month ago

P.S. I wonder about adding another test mode that runs yarn test but where it uses the current code to build itself (after building itself with the current release). Essentially yarn build + yarn test using the current build instead of NPM. I wouldn't run this all the time, probably, but it would be especially good for CI testing to avoid surprises like this in the future. Civet is of course the largest example of Civet code, so it's a good real-world test.

Alternatively or in addition, an interesting idea could be to run yarn build with the current Civet dep, and then run yarn build again with the resulting build, and output a diff of the output (and ideally show that in CI, maybe as an artifact). Sometimes diffs are fine/good, but it might be good to be aware of them and make it part of code review?