Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A small babel plugin that wraps console.logs inside a console.group with surrounding function name

NotificationsYou must be signed in to change notification settings

kgrz/babel-plugin-console-groupify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Scratching another itch with this. Sometimes when I'm developing inReact, I wish there was a way to group theconsole.log statements whenused inside the life-cycle functions, and add some kind of visualseparation betweenconsole.logs in different functions.

This plugin checks forconsole.logs inside functions, and wraps theminside aconsole.group/console.groupEnd set, with the function namepassed in as a variable forconsole.group. For example:

functionaFunctionDeclaration(){console.log('hi');}constaFunctionExpression=function(){console.log('hi')}constanArrowFunction=()=>{console.log('hi')}

ends up looking like:

▼ aFunctionDeclaration  | hi▼ aFunctionExpression  | hi▼ anArrowFunction  | hi

Combining this with thehttps://github.com/kgrz/babel-plugin-transform-console-log-variable-names,the printf-debugging becomes way better. For example, in a Reactcomponent:

classMyComponentextendsReact.Component{componentWillReceiveProps(nextProps){console.log(this.props);console.log(nextProps);}}

prints out:

▼ componentWillReceiveProps  | this.props: { prop1: "one" }  | nextProps: { prop1: "two. what the!" }

Actual screenshot from actual usage:

both-plugins-together

Note that both these plugins are at a pretty alpha quality.

Usage

Install the module with:

npm install --save babel-plugin-console-groupify

Include it in your babel configuration either via.babelrc or webpack.Here's a.babelrc example:

{"presets": [...],"plugins": ["console-groupify"]}

Known Issues

  • A spread operator inside a switch statement seems to be causing issueswhen used with thebabel-transform-object-rest-spread plugin. Forinstance:

    functionmyReducer(state={},action={}){console.log('hi');switch(action.type){case'some_action':return{ ...state,key:value}}}

About

A small babel plugin that wraps console.logs inside a console.group with surrounding function name

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp