Comments (3)
@iki Hmm, I think it's a bug in Prettier if it's inserting a trailing comma. TypeScript 2.9 had a breaking change to disallow trailing commas after rest elements ( https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#trailing-commas-not-allowed-on-rest-parameters ) and the latest playground shows an error ( https://www.typescriptlang.org/play/#src=const%20%7B%20...rest%2C%20%7D%20%3D%20%7B%7D%3B%0D%0A ). I'd prefer to stick with the latest TypeScript syntax rules unless there's a really compelling reason.
There's some more discussion here: prettier/prettier#4624 , although I think that's for a separate TS parsing bug that has since been fixed.
from sucrase.
True, it changes with TS 2.9.
However, it's not easy on all projects to switch to 2.9. It needs updating code and some typed dependencies to compile correctly, so we can't use the sucrase powered webpack-serve on most atm.
Would you consider making that an option similar to enableLegacyTypeScriptModuleInterop
?
from sucrase.
I think it should be reasonable to just allow trailing commas here always without need for a new option. Generally Sucrase's philosophy is to skip error validation and leave that to the linter, typechecker, or JS runtime. For example, Babel doesn't let you export the same name twice, but Sucrase does. As you can see from the error message, there's already an explicit check to disallow this case, so the main thing to do is to just remove that check and make sure the comma doesn't cause problems with later parsing.
I may want to have a more explicit range of supported TypeScript versions in the future and eventually release a semver-major update that drops support for this case, but for now, TS 2.9 is new enough that it makes sense to support older syntax.
from sucrase.
Related Issues (20)
- How to use sucrase/register/ts with gulpfile.ts? HOT 1
- Dynamic import not act as expected as typescript transpiled HOT 1
- jsx: preserve HOT 2
- TypeScript 5.0 support
- Question: strict mode HOT 2
- Add option to disable TS import/export elision
- Allow arbitrary Sucrase configuration in sucrase/register and the CLI HOT 1
- Transpilation bug, changes `;` to `,` HOT 2
- Constructor return type annotations produce invalid JS syntax HOT 1
- (plugin commonjs--resolver) Syntax Error when importing file with json import HOT 1
- TypeScript: `x < y >= z` is incorrectly interpreted as a type argument list HOT 1
- Incorrect elision of `import {}` with TS transform disabled HOT 1
- TypeScript type-only re-exports not always properly elided
- TypeScript automatic named export elision incorrectly happens for re-export
- Incorrect elision of named import if typings of a callback function contains a parameter with the same name HOT 1
- Sucrase SyntaxError - (7:3) HOT 2
- jest.mock hoisting breaks when using @jest/globals
- Option to just compile JSX to object literal HOT 2
- Unexpected output from an exported mergeable enum HOT 2
- glob lib dependency, depends on Inflight lib which is now introducing a security vulnerability HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sucrase.