peggyjs / peggy

Peggy: Parser generator for JavaScript
https://peggyjs.org/
MIT License
914 stars 65 forks source link

tsconfig targets es5, but allows es2020 functions #431

Closed markw65 closed 9 months ago

markw65 commented 1 year ago

I noticed that tsconfig has "target": "es5", but at the same time, in #430 tsc doesn't complain about string.endsWith().

That surprised me, because in other projects I have, the only way to get tsc to accept endsWith is to set target to es6 or above.

So I tried npx tsc --noEmit --listFiles, and saw (amongst lots of other output)

/Users/mwilliams/www/git/peggy/node_modules/typescript/lib/lib.d.ts
/Users/mwilliams/www/git/peggy/node_modules/typescript/lib/lib.es5.d.ts
/Users/mwilliams/www/git/peggy/node_modules/typescript/lib/lib.es2015.d.ts
/Users/mwilliams/www/git/peggy/node_modules/typescript/lib/lib.es2016.d.ts
/Users/mwilliams/www/git/peggy/node_modules/typescript/lib/lib.es2017.d.ts
/Users/mwilliams/www/git/peggy/node_modules/typescript/lib/lib.es2018.d.ts
/Users/mwilliams/www/git/peggy/node_modules/typescript/lib/lib.es2019.d.ts
/Users/mwilliams/www/git/peggy/node_modules/typescript/lib/lib.es2020.d.ts

Where I would only have expected lib.d.ts and lib.es5.d.ts.

I noticed that peggy has @types/node@20.4.9 installed, and sure enough, adding that to another ts5 project gets all those libraries pulled in too (and allows me to call endsWith without warnings).

But removing it from peggy doesn't do anything because other things that peggy depends on also depend on @types/node, and I can't find a way to get tsc to ignore it (although I'm by no means an expert on tsconfig).

So the upshot is that although tsc is targeting es5, its not going to complain about non-es5 functions (and note that it doesn't polly fill them either).

I've confirmed that the current release of peggy has a non-pollyfilled call to string.endsWith, and apparently thats fine (I think all current browsers support both endsWith, and es6 in general). So should the target be bumped to es6?