All Projects → mattphillips → Babel Plugin Console

mattphillips / Babel Plugin Console

Licence: mit
Babel Plugin that adds useful build time console functions 🎮

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Babel Plugin Console

Babel Blade
(under new management!) ⛸️Solve the Double Declaration problem with inline GraphQL. Babel plugin/macro that works with any GraphQL client!
Stars: ✭ 266 (-4.32%)
Mutual labels:  babel, babel-plugin
babel-plugin-proposal-pattern-matching
the minimal grammar, high performance JavaScript pattern matching implementation
Stars: ✭ 34 (-87.77%)
Mutual labels:  babel, babel-plugin
Eslint Import Resolver Babel Module
Custom eslint resolve for babel-plugin-module-resolver
Stars: ✭ 236 (-15.11%)
Mutual labels:  babel, babel-plugin
Param.macro
Partial application syntax and lambda parameters for JavaScript, inspired by Scala's `_` & Kotlin's `it`
Stars: ✭ 170 (-38.85%)
Mutual labels:  babel, babel-plugin
babel-plugin-transform-html-import-to-string
Turn HTML imports (and export from) into constant strings
Stars: ✭ 22 (-92.09%)
Mutual labels:  babel, babel-plugin
Babel Plugin Macros
🎣 Allows you to build simple compile-time libraries
Stars: ✭ 2,366 (+751.08%)
Mutual labels:  babel, babel-plugin
S2s
Coding time Compile. A tool to write code fastest.
Stars: ✭ 254 (-8.63%)
Mutual labels:  babel, babel-plugin
Babel Plugin Runtyper
⚡️ Runtime type-checker for JavaScript
Stars: ✭ 117 (-57.91%)
Mutual labels:  babel, babel-plugin
babel-plugin-transform-replace-expressions
A Babel plugin for replacing expressions with other expressions
Stars: ✭ 23 (-91.73%)
Mutual labels:  babel, babel-plugin
babel-plugin-source-map-support
A Babel plugin which automatically makes stack traces source-map aware
Stars: ✭ 41 (-85.25%)
Mutual labels:  babel, babel-plugin
Babel Plugin React Html Attrs
Babel plugin which transforms HTML and SVG attributes on JSX host elements into React-compatible attributes
Stars: ✭ 170 (-38.85%)
Mutual labels:  babel, babel-plugin
babel-plugin-syntax-pipeline
Allow parsing of pipeline operator |>
Stars: ✭ 23 (-91.73%)
Mutual labels:  babel, babel-plugin
Babel Plugin Transform Typescript Metadata
Babel plugin to emit decorator metadata like typescript compiler
Stars: ✭ 142 (-48.92%)
Mutual labels:  babel, babel-plugin
Babel Plugin React Intl Auto
i18n for the component age. Auto management react-intl ID.
Stars: ✭ 203 (-26.98%)
Mutual labels:  babel, babel-plugin
Babel Plugin Polished
Compile polished helper functions at build time
Stars: ✭ 133 (-52.16%)
Mutual labels:  babel, babel-plugin
Xwind
Tailwind CSS as a templating language in JS and CSS-in-JS
Stars: ✭ 249 (-10.43%)
Mutual labels:  babel, babel-plugin
Js Proposal Algebraic Effects
📐Let there be algebraic effects in JS
Stars: ✭ 110 (-60.43%)
Mutual labels:  babel, babel-plugin
Babel Plugin Prismjs
A babel plugin to use PrismJS with standard bundlers.
Stars: ✭ 114 (-58.99%)
Mutual labels:  babel, babel-plugin
core-web
like core-js but for Web APIs (based on polyfill.io)
Stars: ✭ 34 (-87.77%)
Mutual labels:  babel, babel-plugin
babel-plugin-remove-test-ids
🐠 Babel plugin to strip `data-test-id` HTML attributes
Stars: ✭ 40 (-85.61%)
Mutual labels:  babel, babel-plugin

babel-plugin-console

🎮

Adds useful build time console functions


Build Status Code Coverage version downloads MIT License PRs Welcome Roadmap Examples Babel Macro

Problem

Ever find yourself using console.log to work out what the heck is going on within your functions? And then put too many variables into the log and lose context of which value is which variable?

Solution

These problems can be solved by a computer at build time. This plugin allows you to inspect a functions parameters, variables, return value and parent scope by adding meaningful logs around the scope of the function - removing the hassle of manual console.log statements or debugging.

Installation

With npm:

npm install --save-dev babel-plugin-console

With yarn:

yarn add -D babel-plugin-console

Setup

.babelrc

{
  "plugins": ["console"]
}

CLI

babel --plugins console script.js

Node

require('babel-core').transform('code', {
  plugins: ['console'],
})

APIs

console.scope()

Outputs a collection of messages for a functions entire scope

Note: this API is the same as the standard console.log

Syntax

console.scope(obj1 [, obj2, ..., objN]);
console.scope(msg [, subst1, ..., substN]);

Parameters

  • obj1 ... objN A list of JavaScript objects to output. The string representations of each of these objects are appended together in the order listed and output.

  • msg A JavaScript string containing zero or more substitution strings.

  • subst1 ... substN JavaScript objects with which to replace substitution strings within msg. This gives you additional control over the format of the output.

Usage

Plugin

const add100 = (a) => {
  const oneHundred = 100;
  console.scope('Add 100 to another number');
  return add(a, oneHundred);
};

const add = (a, b) => {
  return a + b;
};

           

Browser:

Browser console scoping add100

Node:

Node console scoping add100

Macros

babel-plugin-console also ships with babel-macros supported 🎉

To use a macro you will need to install and setup babel-macros.

Once you have enabled babel-macros import/require the scope macro with:

import scope from 'babel-plugin-console/scope.macro';
// OR
const scope = require('babel-plugin-console/scope.macro');

Example

Note: this is the same as the above usage and will generate the same logs - only difference is it uses the scope macro 😎

           
import scope from 'babel-plugin-console/scope.macro';

const add100 = (a) => {
  const oneHundred = 100;
  scope('Add 100 to another number');
  return add(a, oneHundred);
};

const add = (a, b) => {
  return a + b;
};

NOTE: There's also a separate package available called scope.macro which you can install and use instead if you prefer to type less.

Inspiration

This tweet led to me watching @kentcdodds's live presentation on ASTs. This plugin is an extension on the captains-log demoed - Thanks Kent!

Other Solutions

You could use a debugger with breakpoints to pause the execution of a function and inspect the values of each variable.

The above add100 function would look like the following if you used a debugger with a breakpoint:

Debugging add100

Contributors


Matt Phillips

💻 📖 🚇 ⚠️

Stephen Bluck

📖

LICENSE

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].