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.

*.tsx parser fails

See original GitHub issue

Hi. I’ve tried to use depcheck with tsx files + typescript@2, but with no luck. I reciving parsing error like:

"SyntaxError: Unexpectedtoken(5: 16)
atParser.pp$5.raise(.../depcheck/node_modules/babylon/lib/index.js: 4333: 13)
atParser.pp.unexpected(.../depcheck/node_modules/babylon/lib/index.js: 1705: 8)
atParser.pp$3.parseParenAndDistinguishExpression(.../depcheck/node_modules/babylon/lib/index.js: 3776: 10)
atParser.pp$3.parseExprAtom(.../depcheck/node_modules/babylon/lib/index.js: 3629: 19)
atParser.pp$3.parseExprSubscripts(.../depcheck/node_modules/babylon/lib/index.js: 3414: 19)
atParser.pp$3.parseMaybeUnary(.../depcheck/node_modules/babylon/lib/index.js: 3394: 19)
atParser.pp$3.parseExprOps(.../depcheck/node_modules/babylon/lib/index.js: 3324: 19)
atParser.pp$3.parseMaybeConditional(.../depcheck/node_modules/babylon/lib/index.js: 3301: 19)
atParser.pp$3.parseMaybeAssign(.../depcheck/node_modules/babylon/lib/index.js: 3264: 19)
atParser.pp$3.parseExpression(.../depcheck/node_modules/babylon/lib/index.js: 3226: 19)"

To reproduce go to test/fake_modules/typescript and change component.tsx from

import * as React from 'react';

export default class MyComponent extends React.Component<{}, {}> {
}

to

import * as React from 'react';

export default class MyComponent extends React.Component<{}, {}> {
  render() {
    return (<div>fake</div>)
  }
}

and run tests.

You will see that there are 2 failing tests. Both about typescript parser.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
lijunlecommented, Nov 29, 2017

As I can see the problem is that depcheck uses some default config for compiler options. After PR which added jsx option it might work in most cases. But I believe that instead of providing some defaults depcheck should try to read tsconfig from package first and use it.

I see. I suppose that is controlled here:

https://github.com/depcheck/depcheck/blob/153aa50925e4a02f1b418a7d1349bff8f5f925eb/src/parser/typescript.js#L11-L14

We need to change this hard coded compile option to read it from file. Not sure if TypeScript provides util to help here.

@yurii-sorokin Could you please help on this issue?

1reaction
mnkhouricommented, Aug 9, 2018

Thanks @yurii-sorokin !

Read more comments on GitHub >

github_iconTop Results From Across the Web

JSX parsing failure when mixing ts, tsx, js and jsx files #6031
Describe the bug My project is a bit of a mess. I have a mixture of ts, tsx, js and jsx files. I'm...
Read more >
When Eslint parse Tsx/Ts file 'public' token, always shows ...
When Eslint parse Tsx/Ts file 'public' token, always shows 'Parsing error: Unexpected token' · Ask Question. Asked 1 year ago.
Read more >
"ERROR: Unable to parse file" for numerous valid typescript files
When running a scan of a typescript (v4.4) project, I get a number of parser errors. The error reads: ERROR: Unable to parse...
Read more >
eslint-import-resolver-typescript - npm
This plugin adds `TypeScript` support to `eslint-plugin-import`. Latest version: 3.5.2, last published: 2 months ago.
Read more >
Documentation - JSX - TypeScript
If that fails, TS will report an error. Function Component. As the name suggests, the component is defined as a JavaScript function where...
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