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
6
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.9 to 6.3.19

60

lib/index.js
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.__esModule = true;
exports["default"] = function (_ref) {
var Plugin = _ref.Plugin;
var t = _ref.types;
function wrapInFlowComment(context, parent) {
context.addComment("trailing", generateComment(context, parent));
context.replaceWith(t.noop());
function wrapInFlowComment(path, parent) {
path.addComment("trailing", generateComment(path, parent));
path.replaceWith(t.noop());
}
function generateComment(context, parent) {
var comment = context.getSource().replace(/\*-\//g, "*-ESCAPED/").replace(/\*\//g, "*-/");
function generateComment(path, parent) {
var comment = path.getSource().replace(/\*-\//g, "*-ESCAPED/").replace(/\*\//g, "*-/");
if (parent && parent.optional) comment = "?" + comment;

@@ -23,15 +20,21 @@ if (comment[0] !== ":") comment = ":: " + comment;

return new Plugin("flow-comments", {
return {
inherits: require("babel-plugin-syntax-flow"),
visitor: {
TypeCastExpression: function TypeCastExpression(node) {
this.get("expression").addComment("trailing", generateComment(this.get("typeAnnotation")));
this.replaceWith(t.parenthesizedExpression(node.expression));
TypeCastExpression: function TypeCastExpression(path) {
var node = path.node;
path.get("expression").addComment("trailing", generateComment(path.get("typeAnnotation")));
path.replaceWith(t.parenthesizedExpression(node.expression));
},
// support function a(b?) {}
Identifier: function Identifier(node, parent, scope, file) {
Identifier: function Identifier(path) {
var node = path.node;
if (!node.optional || node.typeAnnotation) {
return;
}
this.addComment("trailing", ":: ?");
path.addComment("trailing", ":: ?");
},

@@ -41,7 +44,8 @@

Function: {
exit: function exit(node) {
for (var i = 0; i < node.params.length; i++) {
var param = node.params[i];
param.optional = false;
}
exit: function exit(_ref2) {
var node = _ref2.node;
node.params.forEach(function (param) {
return param.optional = false;
});
}

@@ -51,20 +55,26 @@ },

// support `export type a = {}` - #8 Error: You passed path.replaceWith() a falsy node
"ExportNamedDeclaration|Flow": function ExportNamedDeclarationFlow(node, parent, scope, file) {
"ExportNamedDeclaration|Flow": function ExportNamedDeclarationFlow(path) {
var node = path.node;
var parent = path.parent;
if (t.isExportNamedDeclaration(node) && !t.isFlow(node.declaration)) {
return;
}
wrapInFlowComment(this, parent);
wrapInFlowComment(path, parent);
},
// support `import type A` and `import typeof A` #10
ImportDeclaration: function ImportDeclaration(node, parent, scope, file) {
ImportDeclaration: function ImportDeclaration(path) {
var node = path.node;
var parent = path.parent;
if (t.isImportDeclaration(node) && node.importKind !== "type" && node.importKind !== "typeof") {
return;
}
wrapInFlowComment(this, parent);
wrapInFlowComment(path, parent);
}
}
});
};
};
module.exports = exports["default"];
{
"name": "babel-plugin-flow-comments",
"version": "1.0.9",
"version": "6.3.19",
"description": "Turn flow type annotations into comments",
"repository": "babel-plugins/babel-plugin-flow-comments",
"repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-flow-comments",
"license": "MIT",
"main": "lib/index.js",
"devDependencies": {
"babel": "^5.6.0",
"mocha": "^2.2.5"
},
"scripts": {
"build": "babel-plugin build",
"push": "babel-plugin publish",
"test": "babel-plugin test",
"test-mocha": "mocha --compilers js:babel/register"
},
"keywords": [
"babel-plugin"
]
],
"dependencies": {
"babel-runtime": "^5.0.0",
"babel-plugin-syntax-flow": "^6.3.13"
},
"devDependencies": {
"babel-helper-plugin-test-runner": "^6.3.13"
}
}

@@ -5,3 +5,3 @@ # babel-plugin-flow-comments

When using this plugin, you might want to also blacklist the `flow` transformer to preserve the `/* @flow */` directive.
You should be able to use this plugin instead of `babel-plugin-flow-strip-types` to preserve the `/* @flow */` directive and still use flow.

@@ -56,4 +56,3 @@ http://flowtype.org/blog/2015/02/20/Flow-Comments.html

{
"plugins": ["flow-comments"],
"blacklist": ["flow"]
"plugins": ["flow-comments"]
}

@@ -65,3 +64,3 @@ ```

```sh
$ babel --plugins flow-comments --blacklist flow script.js
$ babel --plugins flow-comments script.js
```

@@ -73,5 +72,4 @@

require("babel-core").transform("code", {
plugins: ["flow-comments"],
blacklist: ["flow"]
plugins: ["flow-comments"]
});
```

Sorry, the diff of this file is not supported yet

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