question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JS files should parse as JS, not as JSX

See original GitHub issue

Bug 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

https://www.typescriptlang.org/play?jsx=0&ts=3.3.3&filetype=js#code/C4JwrgpgPABA9AHQEZwHTAgZ2ACgER4CU8cMA8gNIBQokUiK6WuBxcpAYgIICSAMlSA

💻 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:open
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
DanielRosenwassercommented, Oct 29, 2021

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).

0reactions
dcsaszarcommented, Oct 29, 2021

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.

There’s only one number-typed property

In theory, there are other (maybe unlikely in the real world) ways for “number < regex”, for example, 4</4/g.test("5").toString().length.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found