babel-plugin-flow-comments
Advanced tools
Comparing version 1.0.9 to 6.3.19
"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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
1
1
3988
2
4
60
72
1
+ Addedbabel-runtime@^5.0.0
+ Addedbabel-plugin-syntax-flow@6.18.0(transitive)
+ Addedbabel-runtime@5.8.38(transitive)
+ Addedcore-js@1.2.7(transitive)