-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
--erasableSyntaxOnly
#61011
--erasableSyntaxOnly
#61011
Conversation
Looks like you're introducing a change to the public API surface area. If this includes breaking changes, please document them on our wiki's API Breaking Changes page. Also, please make sure @DanielRosenwasser and @RyanCavanaugh are aware of the changes, just as a heads up. |
Reading #59601 (comment), do we also need to ban |
Modulo VMS restrictions, it always transforms to |
ts-blank-space and Node both say no to |
name: "erasableSyntaxOnly", | ||
type: "boolean", | ||
category: Diagnostics.Interop_Constraints, | ||
description: Diagnostics.Do_not_allow_runtime_constructs_that_are_not_part_of_ECMAScript, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JSX?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Open to suggestions 🤷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd vote no since that would curse anyone trying to use this for "purist" purposes to not being able to use JSX at all; you're already going to get an error from Node, and in other runtimes or with a loader, it might even work just fine....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, the fact that you already have to put JSX content in a .?sx
file means you can't possibly make the mistake of "not realizing enum is special" or whatever.
I thought Daniel wanted the text to say something different, which technically JSX is a non-ES runtime construct, but the phrasing would maybe get super awkward
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohh that interpretation makes a lot more sense, oops
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're already going to get an error from Node
Well you could make the same argument about all of these features right?
the fact that you already have to put JSX content in a
.?sx
file
Well we permit JSX in JS files 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall I think it is fine either way, just a slightly weird distinction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation seems right to me; cross checking with other tools, I don't believe we missed anything, but it might be a good idea to add a test that shows that namespaces need to be recursively checked.
Worth re-noting for people watching this that ts-blank-space and Node.js' Amaro currently do not handle uninstantiated (type-only) namespaces: |
Co-authored-by: Jake Bailey <[email protected]>
…rasableSyntaxOnly
Co-authored-by: Jake Bailey <[email protected]>
…/TypeScript into erasableSyntaxOnly
This disables ALL enums, but aren't string only enums 1 to 1 mappable to vanilla JavaScript? At runtime, as far as I can tell, a string enum behaves identical to an object composed of string values. Is this incorrect? And if not, would it be undesirable to allow string enums with this flag turned on? IMO string enums are far more ergonomic than const objects in that they are both a type and an iterable. Sorry if this is irrelevant and the ship has sailed. Just thought I'd ask. |
Enums are not "erasable" syntax - they need to be transformed to become valid Javascript. An enum like this: // Typescript
enum Direction {
Up = "UP",
Down = "DOWN"
} is transformed into // Javascript
var Direction;
(function (Direction) {
Direction["Up"] = "UP";
Direction["Down"] = "DOWN";
})(Direction || (Direction = {})); The flag introduced here aims at ensuring you get a type error when you write typescript syntax that is incompatible with Node's new type stripping feature (https://nodejs.org/en/learn/typescript/run-natively#running-typescript-code-with-nodejs), which enums are. (There is a new |
@alexbit-codemod We need a codemod for this so everyone can migrate away easily! |
Implements #59601