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.

Tree view appears to have some trouble with JSX when using Recast

See original GitHub issue

Describe the bug First off, a HUGE thank you for making this project available. It’s been so incredibly helpful!

I appear to have broken the tree view and code when attempting to using JSX syntax in conjunction with recast.

Instead of displaying the super-helpful AST viewer, the tree view prints an error message like this: Invalid regular expression: missing /.

It seems some of the recast configuration may be misidentifying a closing JSX tag with a regular expression.

When switching to a different parser (ex: babylon7), the tree view displays as expected.

To Reproduce Steps to reproduce the behavior:

  1. Go to the example gist to replicate the bug.
  2. Examine the “Tree” tab of the AST Viewer
  3. See error message Line 4: Invalid regular expression: missing /

Expected behavior The interactive AST display rendered as it does with vanilla JavaScript.

Screenshots Here’s the state of the code editor: Screen Shot 2019-11-14 at 7 57 25 PM

Browser (please complete the following information):

  • OS: macOS 10.14.6
  • Browser: Brave (Chromium browser)
  • Version: (Brave) 0.68.138 Chromium: 77.0.3865.75 (Official Build) (64-bit)

astexplorer settings:

  • Selected parser: recast configured to use babylon7
  • Selected transformer (if applicable): jscodeshift
  • Contents of the local storage key explorerSettingsV1
{"showTransformPanel":false,"parserSettings":{},"parserPerCategory":{},"workbench":{"parser":"acorn","code":"/**\n * Paste or drop some JavaScript here and explore\n * the syntax tree created by chosen parser.\n * You can use all the cool new features from ES6\n * and even more. Enjoy!\n */\n\nlet tips = [\n  \"Click on any AST node with a '+' to expand it\",\n\n  \"Hovering over a node highlights the \\\n   corresponding part in the source code\",\n\n  \"Shift click on an AST node expands the whole substree\"\n];\n\nfunction printTips() {\n  tips.forEach((tip, i) => console.log(`Tip ${i}:` + tip));\n}\n","keyMap":"default","transform":{"code":"","transformer":null}}}

Additional context The code editor also seems to have a syntax highlighting problem with the closing tag as well, so the issue with JSX may not be entirely limited to the AST Tree viewer

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:3
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
fklingcommented, Nov 15, 2019

Mmh. My hunch is that the babylon 7 parser or its settings aren’t passed correctly to recast. I will have to investigate this locally. Thank you for reporting!

(Also thank you for the kind words, it’s always nice to hear that 😃)

0reactions
albertogasparincommented, Aug 10, 2021

Can confirm this is still an issue with Flow as parser too 😞

Read more comments on GitHub >

github_iconTop Results From Across the Web

Support TypeScript · Issue #424 · benjamn/recast - GitHub
So, typescript syntax was merged in babylon would you support it here? Im getting this error: Error: {type: TSArrayType, start: undefined, ...
Read more >
React TreeView DevExtreme not rendering data on init
I am trying to render a TreeView with departments which have some organization structure, meaning each department has a parent. The problem ......
Read more >
Converting A Project From AMD to CommonJS with Recast
I have some experience with working with a CSS AST from using Rework. I came across Ben Newman's Recast project and needed a...
Read more >
ReactCodemod: An automated approach for refactoring class ...
The AST is a tree-based data structure that contains all ... of components, hooks have solved a wide range of seemingly unrelated problems...
Read more >
Introduction to Abstract Syntax Trees - Twilio
It converts our tokens into a tree that represents the actual structure of the code. Where previously in the tokens we only had...
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