-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
JS files should parse as JS, not as JSX #45166
Comments
Closing, because I realized that it's caused by the JSX setting, which defaults to React in the playground |
Reopening for discussion, because I wasn't able to successfully compile this on the command line. Although it works with a TS source I'm looking for a way to compile JS In #44442 I found statements that explain the current behavior:
|
Note I had the prescriptive/descriptive thing backwards so I've updated that text. |
I can't think of any other good way for the scanner to decide whether the characters I searched through all the JS files that get installed with a full install of Definitely Typed -- the dependencies of over 7000 projects. I couldn't find any example of people writing Looking for closing tags in JS source turns up a small number of projects:
But they're widely used, and the number that have JSX in their JS tests implies to me that they expect their users to commonly put JSX in JS. I think at present the best thing to do is to keep parsing JS as JSX, and continue to be prescriptive rather than descriptive. |
The real-world case mentioned in my initial comment is not caused by people writing this on purpose, but by a minifier/uglifier compressing JS to this form. |
Also, keep in mind that the issue is not that the code compares something with a regex (implausible), but rather that the original code is effectively |
|
I've had a look at the code and the trick used by the optimizer is that here
In theory, there are other (maybe unlikely in the real world) ways for "number < regex", for example, |
Bug Report
🔎 Search Terms
TS1005 allowJS
🕗 Version & Regression Information
3.3.3
⏯ Playground Link
https://www.typescriptlang.org/play?jsx=0&ts=3.3.3&filetype=js#code/C4JwrgpgPABA9AHQEZwHTAgZ2ACgER4CU8cMA8gNIBQokUiK6WuBxcpAYgIICSAMlSA
💻 Code
tsc --allowJs --checkJs test.js
This is a small reproducing example.
The real-world code causing this issue is: https://unpkg.com/froala-editor@4.0.3/js/froala_editor.min.js
🙁 Actual behavior
🙂 Expected behavior
Compiles successfully, because line 1 and line 2 are semantically equal in JS.
The text was updated successfully, but these errors were encountered: