Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-transform-comment-to-assert

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-transform-comment-to-assert

Replace commented expressions with assert statements

  • 1.0.9
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
38
increased by65.22%
Maintainers
1
Weekly downloads
 
Created
Source

babel-plugin-transform-comment-to-assert

npm Build Status

replace commented expressions with assert statements

Install

$ npm install --save babel-plugin-transform-comment-to-assert

Usage

import visitor from 'babel-plugin-transform-comment-to-assert'
import traverse from 'babel-traverse'
import generate from 'babel-generator'
import { transform } from 'babel-core'

function replace (code) {
  const { ast } = transform(code)
  traverse(ast, visitor().visitor)
  return generate(ast, {}, code).code.trim()
}

replace('1 //=> 1')
//=> 'assert.deepEqual(1, 1);'

Objects:


replace('a = { a: 1 }; a //=> {a: 1}')
//=> 'a = { a: 1 };assert.deepEqual(a, { a: 1 });'

Results of function calls:

replace("(() => 'foo')() //=> 'bar'")
//=> "assert.deepEqual((() => 'foo')(), 'bar');"

It also supports console.log:

replace("console.log('foo') //=> 'bar'")
//=> "console.log('foo');assert.deepEqual('foo', 'bar');"

License

MIT © Sigurd Fosseng

FAQs

Package last updated on 23 Apr 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc