flow-remove-types
Advanced tools
Comparing version 1.0.0 to 1.0.1
44
index.js
@@ -73,2 +73,5 @@ var babylon = require('babylon'); | ||
ClassDeclaration: removeImplementedInterfaces, | ||
ClassExpression: removeImplementedInterfaces, | ||
Identifier(removedNodes, node, ast) { | ||
@@ -85,22 +88,2 @@ if (node.optional) { | ||
ClassDeclaration(removedNodes, node, ast) { | ||
// Remove implemented interfaces. | ||
if (node.implements && node.implements.length > 0) { | ||
var first = node.implements[0]; | ||
var last = node.implements[node.implements.length - 1]; | ||
var idx = findTokenIndex(ast.tokens, first.start); | ||
do { | ||
idx--; | ||
} while (ast.tokens[idx].value !== 'implements'); | ||
var lastIdx = findTokenIndex(ast.tokens, last.start); | ||
do { | ||
if (ast.tokens[idx].type !== 'CommentBlock' && | ||
ast.tokens[idx].type !== 'CommentLine') { | ||
removeNode(removedNodes, ast.tokens[idx]); | ||
} | ||
} while (idx++ !== lastIdx); | ||
} | ||
}, | ||
ClassProperty(removedNodes, node) { | ||
@@ -125,2 +108,23 @@ if (!node.value) { | ||
// If this class declaration or expression implements interfaces, remove | ||
// the associated tokens. | ||
function removeImplementedInterfaces(removedNodes, node, ast) { | ||
if (node.implements && node.implements.length > 0) { | ||
var first = node.implements[0]; | ||
var last = node.implements[node.implements.length - 1]; | ||
var idx = findTokenIndex(ast.tokens, first.start); | ||
do { | ||
idx--; | ||
} while (ast.tokens[idx].value !== 'implements'); | ||
var lastIdx = findTokenIndex(ast.tokens, last.start); | ||
do { | ||
if (ast.tokens[idx].type !== 'CommentBlock' && | ||
ast.tokens[idx].type !== 'CommentLine') { | ||
removeNode(removedNodes, ast.tokens[idx]); | ||
} | ||
} while (idx++ !== lastIdx); | ||
} | ||
} | ||
// Append node to the list of removed nodes, ensuring the order of the nodes | ||
@@ -127,0 +131,0 @@ // in the list. |
{ | ||
"name": "flow-remove-types", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Removes Flow type annotations from JavaScript files with speed and simplicity.", | ||
@@ -8,2 +8,3 @@ "author": "Lee Byron <lee@leebyron.com> (http://leebyron.com/)", | ||
"main": "index.js", | ||
"bin": "flow-remove-types", | ||
"homepage": "https://github.com/leebyron/flow-remove-types", | ||
@@ -17,7 +18,5 @@ "bugs": { | ||
}, | ||
"main": "index.js", | ||
"bin": "flow-remove-types", | ||
"scripts": { | ||
"test": "node test/test.js", | ||
"test-update": "node test/test.js --update" | ||
"test": "DIFF=$(./flow-remove-types test/source.js | diff test/expected.js -); if [ -n \"$DIFF\" ]; then echo \"$DIFF\"; exit 1; fi;", | ||
"test-update": "./flow-remove-types test/source.js > test/expected.js" | ||
}, | ||
@@ -24,0 +23,0 @@ "keywords": [ |
flow-remove-types | ||
----------------- | ||
================= | ||
@@ -17,6 +17,6 @@ Turn your JavaScript with [Flow](https://flowtype.org/) type annotations into | ||
`flow-remove-types` is a faster, simpler, zero-configuration, alternative with | ||
`flow-remove-types` is a faster, simpler, zero-configuration alternative with | ||
minimal dependencies for super-fast `npm install` time. | ||
### Get Started! | ||
## Get Started! | ||
@@ -49,16 +49,16 @@ Use the command line: | ||
### Dead-Simple Transforms | ||
## Dead-Simple Transforms | ||
When `flow-remove-types` removes Flow types, it replaces them with whitespace. | ||
This ensures that the transformed output has exactly the same number of lines | ||
and characters, and all character offset remain the same. This removes the need | ||
for sourcemaps, maintains legible output, and ensures its super easy to include | ||
`flow-remove-types` at any point in your build. | ||
and characters and that all character offsets remain the same. This removes the | ||
need for sourcemaps, maintains legible output, and ensures that it is super easy | ||
to include `flow-remove-types` at any point in your existing build tools. | ||
Built atop the excellent [`babylon`](https://github.com/babel/babylon) parser, | ||
`flow-remove-types` shares the same parse rules as the source of truth | ||
Babel plugins. It also passes through other common non-standard syntax such as | ||
[JSX](https://facebook.github.io/jsx/) and experimental proposals. | ||
`flow-remove-types` shares the same parse rules as the source of truth as | ||
Flow Babel plugins. It also passes through other common non-standard syntax such | ||
as [JSX](https://facebook.github.io/jsx/) and experimental ECMAScript proposals. | ||
*Before:* | ||
**Before:** | ||
@@ -85,3 +85,3 @@ ```js | ||
*After:* | ||
**After:** | ||
@@ -106,1 +106,5 @@ ```js | ||
``` | ||
## Use in Build Systems: | ||
**Rollup**: [`rollup-plugin-flow`](https://github.com/leebyron/rollup-plugin-flow) |
@@ -45,2 +45,11 @@ /* */ | ||
// Class expression implements interface | ||
var SomeClass = class Baz { | ||
method() { | ||
return; | ||
} | ||
}; | ||
// Parametric class | ||
@@ -47,0 +56,0 @@ class Wrapper { |
@@ -45,2 +45,11 @@ /* @flow */ | ||
// Class expression implements interface | ||
var SomeClass = class Baz implements Foo { | ||
prop: any; | ||
method(): mixed { | ||
return; | ||
} | ||
}; | ||
// Parametric class | ||
@@ -47,0 +56,0 @@ class Wrapper<T> { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
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
18523
355
107
0
7