This is the latest docs version
Quick Links
  • -Overview
  • -Language Features
  • -JS Interop
  • -Build System
Documentation
Language Manual
Reference for all language features
ReScript & React
First class bindings for ReactJS
GenType
Seamless TypeScript integration
Reanalyze
Dead Code & Termination analysis
Exploration
Packages
Explore third party libraries and bindings
Syntax Lookup
Discover all syntax constructs
APIPlaygroundBlogCommunity
  • Playground
  • Blog
  • Twitter
  • GitHub
  • Forum
Old DocsBS@8.2.0
Interop
  • Overview
  • Better Data Structures Printing (Debug Mode)
    • Usage
    • Tips & Tricks
  • Miscellaneous
  • Decorators
Advanced
  • Conditional Compilation
  • Extended Compiler Options
  • Compiler Architecture & Principles
  • Comparison to Js_of_ocaml
Docs / Old Docs / BetterDataStructuresPrintingDebugMode
IMPORTANT!
This section is still about ReasonML & BuckleScript. It will be rewritten to ReScript very soon.

Better Data Structures Printing Debug Mode

You might have seen that using Js.log to print records, variants and others don't print out record field names and variant tags. Record, for example, is compiled into an array (the field names are removed). This is partially for performance, and partially because of [insert excuse here].

To remediate this, we introduce a flag for bsc (the BuckleScript compiler), -bs-g, that retains record fields names, variant tags, exception names, module names, etc.

BeforeAfter
debugger beforedebugger after

Note: this is for debugging only. Please don't forget to undo this for production.

Usage

  • Add "bsc-flags": ["-bs-g"] to your bsconfig.json.

  • In the BuckleScript/Reason file you'd like to debug, add [%%debugger.chrome] at the top *.

  • If you're on Node.js, run: node --inspect-brk MyCompiledFile.js and open this URL in Chrome: chrome://inspect.

  • Make sure you've got Chrome custom formatter enabled.

  • Click on inspect, then step through code as you would usually:

debugger inspector

This custom formatter is still experimental; feel free to contribute to it here!

Note: you need to restart node every time your files changes.

Note: don't forget to remove -bs-g from your bsconfig.json for production!

Tips & Tricks

Here are other ways to debug using node/Chrome.

* The extension [%%debugger.chrome] conditionally turns on the debugger support. Feel free to keep it on at all time; it will not generate any extra garbage code unless you have -bs-g flag turned on above.

OverviewMiscellaneous

© 2024 The ReScript Project

Software and assets distribution powered by KeyCDN.

About
  • Community
  • ReScript Association
Find us on