JS files should parse as JS, not as JSX
See original GitHub issueBug Report
🔎 Search Terms
TS1005 allowJS
🕗 Version & Regression Information
3.3.3
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about allowJS and TS1005
- I was unable to test this on prior versions because playground
⏯ Playground Link
💻 Code
tsc --allowJs --checkJs test.js
true< /\b/.test("") // OK
true</\b/.test("") // FAIL
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
:2:2 - error TS1005: ';' expected.
:2:7 - error TS1127: Invalid character.
:2:10 - error TS1109: Expression expected.
🙂 Expected behavior
Compiles successfully, because line 1 and line 2 are semantically equal in JS.
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Are there any differences in .Jsx and .js saving extensions?
.jsx is just a convention, it indicates that the file contains not just JavaScript, but JSX, which is an extension to JavaScript allowing ......
Read more >Demystifying JSX: building your own JSX parser from scratch
Yes! That's why you need to import React even though you're not directly using it, once parsed, the resulting JavaScript will be using...
Read more >Introducing JSX - React
It is called JSX, and it is a syntax extension to JavaScript. We recommend using it with React to describe what the UI...
Read more >Content Types - ESBuild
This loader is enabled by default for .jsx and .tsx files. Note that JSX syntax is not enabled in .js files by default....
Read more >Why is the jsx extension so rarely used for React components?
If if it's pure JavaScript file, then you should use the .js extension. This broad rule makes total sense to me so I'm...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
-1 < /someRegex/.text(someStuff)
(plausible).I’ve had a look at the code and the trick used by the optimizer is that here
-1 <
makes the following&&
expression execute unconditionally:-1</x/g.test("y")&&console.log("OK")
In other words, it disposes the return value of/someRegex/.test(someStuff)
to make the code shorter.In theory, there are other (maybe unlikely in the real world) ways for “number < regex”, for example,
4</4/g.test("5").toString().length
.