New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-flow-comments

Package Overview
Dependencies
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-flow-comments - npm Package Compare versions

Comparing version 1.0.6 to 1.0.7

test/fixtures/type-cast/actual.js

34

lib/index.js

@@ -11,4 +11,22 @@ "use strict";

function wrapInFlowComment(context, parent) {
context.addComment("trailing", generateComment(context, parent));
context.replaceWith(t.noop());
}
function generateComment(context, parent) {
var comment = context.getSource().replace(/\*-\//g, "*-ESCAPED/").replace(/\*\//g, "*-/");
if (parent && parent.optional) comment = "?" + comment;
if (comment[0] !== ":") comment = ":: " + comment;
return comment;
}
return new Plugin("flow-comments", {
visitor: {
TypeCastExpression: function TypeCastExpression(node) {
this.get("expression").addComment("trailing", generateComment(this.get("typeAnnotation")));
this.replaceWith(t.parenthesizedExpression(node.expression));
},
// support function a(b?) {}
Identifier: function Identifier(node, parent, scope, file) {

@@ -20,2 +38,4 @@ if (!node.optional || node.typeAnnotation) {

},
// support `export type a = {}` - #8 Error: You passed path.replaceWith() a falsy node
"ExportNamedDeclaration|Flow": function ExportNamedDeclarationFlow(node, parent, scope, file) {

@@ -25,7 +45,11 @@ if (t.isExportNamedDeclaration(node) && !t.isFlow(node.declaration)) {

}
var comment = this.getSource().replace("*/", "//");
if (parent.optional) comment = "?" + comment;
if (comment[0] !== ":") comment = ":: " + comment;
this.addComment("trailing", comment);
this.replaceWith(t.noop());
wrapInFlowComment(this, parent);
},
// support `import type A` and `import typeof A` #10
ImportDeclaration: function ImportDeclaration(node, parent, scope, file) {
if (t.isImportDeclaration(node) && node.importKind !== "type" && node.importKind !== "typeof") {
return;
}
wrapInFlowComment(this, parent);
}

@@ -32,0 +56,0 @@ }

2

package.json
{
"name": "babel-plugin-flow-comments",
"version": "1.0.6",
"version": "1.0.7",
"description": "Turn flow type annotations into comments",

@@ -5,0 +5,0 @@ "repository": "babel-plugins/babel-plugin-flow-comments",

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