pax_global_header00006660000000000000000000000064131715634050014517gustar00rootroot0000000000000052 comment=592e371443c90f7d3add0346cdb1c341ceff4f65 flow-remove-types-1.2.3/000077500000000000000000000000001317156340500151265ustar00rootroot00000000000000flow-remove-types-1.2.3/.gitignore000066400000000000000000000000601317156340500171120ustar00rootroot00000000000000.DS_Store npm-debug.log node_modules /npm-alias flow-remove-types-1.2.3/.travis.yml000066400000000000000000000002021317156340500172310ustar00rootroot00000000000000language: node_js node_js: - "7" - "6" - "4" - "0.12" - "0.10" before_install: - npm config set spin false --global flow-remove-types-1.2.3/LICENSE000066400000000000000000000027771317156340500161500ustar00rootroot00000000000000BSD License For flow-remove-types software Copyright (c) 2014-2016, Facebook, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name Facebook nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. flow-remove-types-1.2.3/PATENTS000066400000000000000000000037241317156340500161750ustar00rootroot00000000000000Additional Grant of Patent Rights Version 2 "Software" means the flow-remove-types software distributed by Facebook, Inc. Facebook, Inc. (“Facebook”) hereby grants to each recipient of the Software (“you”) a perpetual, worldwide, royalty-free, non-exclusive, irrevocable (subject to the termination provision below) license under any Necessary Claims, to make, have made, use, sell, offer to sell, import, and otherwise transfer the Software. For avoidance of doubt, no license is granted under Facebook’s rights in any patent claims that are infringed by (i) modifications to the Software made by you or any third party or (ii) the Software in combination with any software or other technology. The license granted hereunder will terminate, automatically and without notice, if you (or any of your subsidiaries, corporate affiliates or agents) initiate directly or indirectly, or take a direct financial interest in, any Patent Assertion: (i) against Facebook or any of its subsidiaries or corporate affiliates, (ii) against any party if such Patent Assertion arises in whole or in part from any software, technology, product or service of Facebook or any of its subsidiaries or corporate affiliates, or (iii) against any party relating to the Software. Notwithstanding the foregoing, if Facebook or any of its subsidiaries or corporate affiliates files a lawsuit alleging patent infringement against you in the first instance, and you respond by filing a patent infringement counterclaim in that lawsuit against that party that is unrelated to the Software, the license granted hereunder will not terminate under section (i) of this paragraph due to such counterclaim. A “Necessary Claim” is a claim of a patent owned by Facebook that is necessarily infringed by the Software standing alone. A “Patent Assertion” is any lawsuit or other action alleging direct, indirect, or contributory infringement or inducement to infringe any patent, including a cross-claim or counterclaim. flow-remove-types-1.2.3/README.md000066400000000000000000000142351317156340500164120ustar00rootroot00000000000000flow-remove-types ================= [![npm](https://img.shields.io/npm/v/flow-remove-types.svg?maxAge=86400)](https://www.npmjs.com/package/flow-remove-types) [![Build Status](https://img.shields.io/travis/flowtype/flow-remove-types.svg?style=flat&label=travis&branch=master)](https://travis-ci.org/flowtype/flow-remove-types) Turn your JavaScript with [Flow](https://flowtype.org/) type annotations into standard JavaScript in an instant with no configuration and minimal setup. [Flow](https://flowtype.org/) provides static type checking to JavaScript which can both help find and detect bugs long before code is deployed and can make code easier to read and more self-documenting. The Flow tool itself only reads and analyzes code. Running code with Flow type annotations requires first removing the annotations which are non-standard JavaScript. Typically this is done via adding a plugin to your [Babel](https://babeljs.io/) configuration, however Babel may be overkill if you're only targetting modern versions of Node.js or just not using the modern ES2015 features that may not be in every browser. `flow-remove-types` is a faster, simpler, zero-configuration alternative with minimal dependencies for super-fast `npm install` time. ## Get Started! Use the command line: ``` npm install --global flow-remove-types ``` ``` flow-remove-types --help flow-remove-types input.js > output.js ``` Or the JavaScript API: ``` npm install flow-remove-types ``` ```js var flowRemoveTypes = require('flow-remove-types'); var fs = require('fs'); var input = fs.readFileSync('input.js', 'utf8'); var output = flowRemoveTypes(input); fs.writeFileSync('output.js', output.toString()); ``` When using the `flow-remove-types` script, be sure [not to direct the output to itself](https://superuser.com/questions/597244/why-does-redirecting-the-output-of-a-file-to-itself-produce-a-blank-file)! ## Use in Build Systems: **Rollup:** [`rollup-plugin-flow`](https://github.com/leebyron/rollup-plugin-flow) **Browserify:** [`unflowify`](https://github.com/leebyron/unflowify) **Webpack:** [`remove-flow-types-loader`](https://github.com/conorhastings/remove-flow-types-loader) **Gulp:** [`gulp-flow-remove-types`](https://github.com/wain-pc/gulp-flow-remove-types) ## Use with existing development tools * ESLint: [eslint-plugin-flowtype](https://github.com/gajus/eslint-plugin-flowtype) * Mocha: `mocha -r flow-remove-types/register` ## Use `flow-node` Wherever you use `node` you can substitute `flow-node` and have a super fast flow-types aware evaluator or REPL. ``` $ flow-node > var x: number = 42 undefined > x 42 ``` > Note: This package is also available under the *alias* `flow-node` since it's > often looked for at that location due to the popularity of this script. Both > scripts are available no matter which package you install. ## Use the require hook Using the require hook allows you to automatically compile files on the fly when requiring in node, useful during development: ```js require('flow-remove-types/register') require('./some-module-with-flow-type-syntax') ``` You can also provide options to the require hook: ```js // Transforms all files, not just those with a "@flow" comment. require('flow-remove-types/register')({ all: true }) ``` Use options to define exactly which files to `includes` or `excludes` with regular expressions. All files are included by default except those found in the `node_modules` folder, which is excluded by default. ```js require('flow-remove-types/register')({ includes: /\/custom_path\// }) ``` > #### Don't use the require hook in packages distributed on NPM > As always, don't forget to use `flow-remove-types` to compile files before distributing > your code on npm, as using the require hook affects the whole runtime and not > just your module and may hurt the runtime performance of code that includes it. ## 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 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 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:** ```js import SomeClass from 'some-module' import type { SomeInterface } from 'some-module' export class MyClass extends SomeClass implements SomeInterface { value: T constructor(value: T) { this.value = value } get(): T { return this.value } } ``` **After:** ```js import SomeClass from 'some-module' export class MyClass extends SomeClass { constructor(value ) { this.value = value } get() { return this.value } } ``` ### Pretty Transform Rather not have the whitespace? Pass the `--pretty` flag to remove the whitespace. ``` flow-remove-types --pretty --sourcemaps source.js ``` Or using the JS API: ```js var flowRemoveTypes = require('flow-remove-types'); var fs = require('fs'); var input = fs.readFileSync('input.js', 'utf8'); var output = flowRemoveTypes(input, { pretty: true }); fs.writeFileSync('output.js', output.toString()); var sourceMap = output.generateMap(); fs.writeFileSync('output.js.map', JSON.stringify(sourceMap)); ``` ## Performance ### Install: Installing via `npm` from an empty project: **flow-remove-types:** ``` time npm install flow-remove-types real 0m3.193s user 0m1.643s sys 0m0.775s ``` **Babel:** ``` time npm install babel-cli babel-plugin-transform-flow-strip-types real 0m23.200s user 0m10.395s sys 0m4.238s ``` ### Transform: Transforming a directory of 20 files of 100 lines each: **flow-remove-types:** ``` time flow-remove-types src/ --out-dir dest/ real 0m0.431s user 0m0.436s sys 0m0.068s ``` **Babel:** ``` time babel src/ --out-dir dest/ real 0m1.074s user 0m1.092s sys 0m0.149s ``` flow-remove-types-1.2.3/flow-node000077500000000000000000000110621317156340500167460ustar00rootroot00000000000000#!/usr/bin/env node var fs = require('fs'); var Module = require('module'); var path = require('path'); var repl = require('repl'); var util = require('util'); var vm = require('vm'); var flowRemoveTypes = require('./index'); var usage = 'Usage: flow-node [options] [ script.js ] [arguments] \n' + '\nOptions:\n' + ' -h, --help Show this message\n' + ' -v, --version Prints the current version of flow-node\n' + ' -e, --eval script Evaluate script\n' + ' -p, --print script Evaluate script and print result\n' + ' -c, --check Syntax check script without executing\n' + ' -a, --all Interpret all files as flow-typed, not just those with a @flow comment\n'; // Collect arguments var evalScript; var printScript; var checkSource; var all; var source; var options = []; var i = 2; while (i < process.argv.length) { var arg = process.argv[i++]; if (arg === '-h' || arg === '--help') { process.stdout.write(usage); process.exit(0); } else if (arg === '-v' || arg === '--version') { process.stdout.write('v' + require('./package').version + '\n'); process.exit(0); } else if (arg === '-e' || arg === '--eval') { evalScript = process.argv[i++]; if (!evalScript) { process.stderr.write('flow-node: ' + arg + ' requires an argument'); return process.exit(1); } } else if (arg === '-p' || arg === '--print') { printScript = process.argv[i++]; if (!printScript) { process.stderr.write('flow-node: ' + arg + ' requires an argument'); return process.exit(1); } } else if (arg === '-c' || arg === '--check') { checkSource = true; } else if (arg === '-a' || arg === '--all') { all = true; } else if (arg[0] === '-' || arg === 'debug') { options.push(arg); } else { source = arg; break; } } // If node options were provided, forward to another process with the options // applied before other arguments. if (options.length > 0) { var nodePath = process.argv.shift(); var nodeArgs = options.concat(process.argv.filter(function (arg) { return options.indexOf(arg) === -1; })); const child_process = require('child_process'); const proc = child_process.spawn(nodePath, nodeArgs, { stdio: 'inherit' }); proc.on('exit', function (code, signal) { process.on('exit', function () { if (signal) { process.kill(process.pid, signal); } else { process.exit(code); } }); }); return; } require('./register')({ all: all }); // Evaluate and possibly also print a script. if (evalScript || printScript) { global.__filename = '[eval]'; global.__dirname = process.cwd(); var evalModule = new Module(global.__filename); evalModule.filename = global.__filename; evalModule.paths = Module._nodeModulePaths(global.__dirname); global.exports = evalModule.exports; global.module = evalModule; global.require = evalModule.require.bind(evalModule); var result = vm.runInThisContext( flowRemoveTypes(evalScript || printScript, { all: true }).toString(), { filename: global.__filename } ); if (printScript) { process.stdout.write((typeof result === 'string' ? result : util.inspect(result)) + '\n'); } // Or check the source for syntax errors but do not run it. } else if (source && checkSource) { var code = fs.readFileSync(source, 'utf8'); try { flowRemoveTypes(code, { all: all }); } catch (error) { var lines = code.split(/\r\n?|\n|\u2028|\u2029/); process.stdout.write(source + ':' + error.loc.line + '\n'); process.stdout.write(lines[error.loc.line - 1] + '\n'); process.stdout.write(Array(error.loc.column + 1).join(' ') + '^\n'); process.stdout.write(error.stack + '\n'); return process.exit(1); } // Or run the script. } else if (source) { var absoluteSource = path.resolve(process.cwd(), source); process.argv = [ 'node' ].concat( absoluteSource, process.argv.slice(i) ); process.execArgv.unshift(__filename); Module.runMain(); // Or begin a REPL. } else { repl.start({ prompt: '> ', input: process.stdin, output: process.stdout, useGlobal: true, eval: function (code, context, filename, callback) { var error; var result; try { var runCode = flowRemoveTypes(code, { all: true }).toString(); try { result = vm.runInThisContext(runCode, { filename: filename }); } catch (runError) { error = runError; } } catch (transformError) { error = repl.Recoverable ? new repl.Recoverable(transformError) : transformError; } callback(error, result); } }); } flow-remove-types-1.2.3/flow-remove-types000077500000000000000000000161621317156340500204660ustar00rootroot00000000000000#!/usr/bin/env node var fs = require('fs'); var path = require('path'); var flowRemoveTypes = require('./index'); var usage = 'Usage: flow-remove-types [options] [sources] \n' + '\nOptions:\n' + ' -h, --help Show this message\n' + ' -v, --version Prints the current version of flow-remove-types\n' + ' -i, --ignore Paths to ignore, Regular Expression\n' + ' -x, --extensions File extensions to transform\n' + ' -o, --out-file The file path to write transformed file to\n' + ' -d, --out-dir The directory path to write transformed files within\n' + ' -a, --all Transform all files, not just those with a @flow comment\n' + ' -p, --pretty Remove flow types without replacing with spaces, \n' + ' producing prettier output but may require using source maps\n' + ' -m, --sourcemaps Also output source map files. Optionally pass "inline"\n' + ' -q, --quiet Does not produce any output concerning successful progress.\n' + '\nExamples:\n' + '\nTransform one file:\n' + ' flow-remove-types --out-file output.js input.js\n' + '\nTransform many files:\n' + ' flow-remove-types --out-dir out/ input1.js input2.js\n' + '\nTransform files in directory:\n' + ' flow-remove-types --out-dir out/ indir/\n' + '\nTransform files with source maps:\n' + ' flow-remove-types --out-dir out/ indir/ --sourcemaps\n' + '\nTransform files with inline source maps:\n' + ' flow-remove-types --out-dir out/ indir/ --sourcemaps inline\n' + '\nTransform stdin:\n' + ' cat input.js | flow-remove-types > output.js\n'; var _memo = {}; function mkdirp(dirpath) { if (_memo[dirpath]) { return; } _memo[dirpath] = true; try { fs.mkdirSync(dirpath); } catch (err) { if (err.code === 'ENOENT') { mkdirp(path.dirname(dirpath)); fs.mkdirSync(dirpath); } else { try { stat = fs.statSync(dirpath); } catch (ignored) { throw err; } if (!stat.isDirectory()) { throw err; } } } } // Collect arguments var ignore = /node_modules/; var extensions = [ '.js', '.mjs', '.jsx', '.flow', '.es6' ]; var outDir; var outFile; var all; var pretty; var sourceMaps; var inlineSourceMaps; var quiet; var sources = []; var i = 2; while (i < process.argv.length) { var arg = process.argv[i++]; if (arg === '-h' || arg === '--help') { process.stdout.write(usage); process.exit(0); } else if (arg === '-v' || arg === '--version') { process.stdout.write('v' + require('./package').version); process.exit(0); } else if (arg === '-i' || arg === '--ignore') { ignore = new RegExp(process.argv[i++]); } else if (arg === '-x' || arg === '--extensions') { extensions = process.argv[i++].split(','); } else if (arg === '-o' || arg === '--out-file') { outFile = process.argv[i++]; } else if (arg === '-d' || arg === '--out-dir') { outDir = process.argv[i++]; } else if (arg === '-a' || arg === '--all') { all = true; } else if (arg === '-p' || arg === '--pretty') { pretty = true; } else if (arg === '-m' || arg === '--sourcemaps') { sourceMaps = true; if (process.argv[i] === 'inline') { inlineSourceMaps = true; i++; } } else if (arg === '-q' || arg === '--quiet') { quiet = true; } else { sources.push(arg); } } function info(msg) { if (!quiet) { process.stderr.write(msg); } } function error(msg) { process.stderr.write('\n\033[31m ' + msg + '\033[0m\n\n'); process.exit(1); } // Validate arguments if (outDir && outFile) { error('Only specify one of --out-dir or --out-file'); } if (outDir && sources.length === 0) { error('Must specify files when providing --out-dir'); } if (!outDir && !outFile && sourceMaps && !inlineSourceMaps) { error('Must specify either an output path or inline source maps'); } // Ensure all sources exist for (var i = 0; i < sources.length; i++) { try { var stat = fs.lstatSync(sources[i]); if (sources.length > 1 && !stat.isFile()) { error('Source "' + sources[i] + '" is not a file.'); } } catch (err) { error('Source "' + sources[i] + '" does not exist.'); } } // Process stdin if no sources were provided if (sources.length === 0) { var content = ''; process.stdin.setEncoding('utf-8'); process.stdin.resume(); process.stdin.on('data', function (str) { content += str; }); process.stdin.on('end', function () { transformAndOutput(content, outFile); }); return; } var isDirSource = sources.length === 1 && fs.statSync(sources[0]).isDirectory(); if ((sources.length > 1 || isDirSource) && !outDir) { error('Multiple files require providing --out-dir'); } // Process multiple files for (var i = 0; i < sources.length; i++) { var source = sources[i]; var stat = fs.lstatSync(source); if (stat.isDirectory()) { var files = fs.readdirSync(source); for (var j = 0; j < files.length; j++) { var subSource = path.join(source, files[j]); if (!ignore || !ignore.test(subSource)) { sources.push(subSource); } } } else if (stat.isFile() && extensions.indexOf(path.extname(source)) !== -1) { if (outDir) { outFile = path.join(outDir, isDirSource ? path.relative(sources[0], source) : source); mkdirp(path.dirname(outFile)); } var content = fs.readFileSync(source, 'utf8'); transformAndOutput(content, outFile, source); } } function transformAndOutput(content, outFile, source) { var fileName = source || ''; var result = transformSource(content, fileName); var code = result.toString(); if (sourceMaps) { var map = result.generateMap(); delete map.file; map.sources[0] = fileName; if (source) { delete map.sourcesContent; if (outFile) { map.sources[0] = path.join(path.relative(path.dirname(outFile), path.dirname(source)), path.basename(source)); } } else { map.sourcesContent[0] = content; } code += '\n//# sourceMappingURL=' + (inlineSourceMaps ? 'data:application/json;charset=utf-8;base64,' + btoa(JSON.stringify(map)) : path.basename(outFile) + '.map' ) + '\n'; } if (outFile) { fs.writeFileSync(outFile, code); info(fileName + '\n \u21B3 \033[32m' + outFile + '\033[0m\n'); if (sourceMaps && !inlineSourceMaps) { var mapOutFile = outFile + '.map'; fs.writeFileSync(mapOutFile, JSON.stringify(map) + '\n'); info('\033[2m \u21B3 \033[32m' + mapOutFile + '\033[0m\n'); } } else { process.stdout.write(code); } } function btoa(str) { return (Buffer.from ? Buffer.from(str) : new Buffer(str)).toString('base64'); } function transformSource(content, filepath) { try { return flowRemoveTypes(content, { all: all, pretty: pretty }); } catch (error) { if (error.loc) { var line = error.loc.line - 1; var col = error.loc.column; var text = content.split(/\r\n?|\n|\u2028|\u2029/)[line]; process.stderr.write( filepath + '\n' + ' \u21B3 \033[31mSyntax Error: ' + error.message + '\033[0m\n' + ' \033[90m' + line + ': \033[0m' + text.slice(0, col) + '\033[7;31m' + text[col] + '\033[0m' + text.slice(col + 1) + '\n' ); process.exit(1); } throw error; } } flow-remove-types-1.2.3/index.js000066400000000000000000000313531317156340500166000ustar00rootroot00000000000000var babylon = require('babylon'); var vlq = require('vlq'); /** * Given a string JavaScript source which contains Flow types, return a string * which has removed those types. * * Options: * * - all: (default: false) * If true, bypasses looking for an @flow pragma comment before parsing. * * - pretty: (default: false) * If true, removes types completely rather than replacing with spaces. * This may require using source maps. * * Returns an object with two methods: * * - .toString() * Returns the transformed source code. * * - .generateMap() * Returns a v3 source map. */ module.exports = function flowRemoveTypes(source, options) { // Options var all = Boolean(options && options.all); if (options && options.checkPragma) { throw new Error( 'flow-remove-types: the "checkPragma" option has been replaced by "all".' ); } // If there's no @flow or @noflow flag, then expect no annotation. var pragmaStart = source.indexOf('@' + 'flow'); var pragmaSize = 5; if (pragmaStart === -1) { pragmaStart = source.indexOf('@' + 'noflow'); pragmaSize = 7; if (pragmaStart === -1 && !all) { return resultPrinter(options, source); } } // Babylon is one of the sources of truth for Flow syntax. This parse // configuration is intended to be as permissive as possible. var ast = babylon.parse(source, { allowImportExportEverywhere: true, allowReturnOutsideFunction: true, allowSuperOutsideMethod: true, sourceType: 'module', plugins: [ '*', 'jsx', 'flow' ], }); var removedNodes = []; var context = { ast: ast, source: source, removedNodes: removedNodes, pretty: Boolean(options && options.pretty) }; // Remove the flow pragma. if (pragmaStart !== -1) { var pragmaIdx = findTokenIndex(ast.tokens, pragmaStart); var pragmaType = ast.tokens[pragmaIdx].type; if (pragmaType === 'CommentLine' || pragmaType === 'CommentBlock') { removedNodes.push(getPragmaNode(context, pragmaStart, pragmaSize)); } } // Remove all flow type definitions. visit(ast, context, removeFlowVisitor); return resultPrinter(options, source, removedNodes); } function resultPrinter(options, source, removedNodes) { // Options var pretty = Boolean(options && options.pretty); return { toString: function () { if (!removedNodes || removedNodes.length === 0) { return source; } var result = ''; var lastPos = 0; // Step through the removed nodes, building up the resulting string. for (var i = 0; i < removedNodes.length; i++) { var node = removedNodes[i]; result += source.slice(lastPos, node.start); lastPos = node.end; if (!pretty) { var toReplace = source.slice(node.start, node.end); if (!node.loc || node.loc.start.line === node.loc.end.line) { result += space(toReplace.length); } else { var toReplaceLines = toReplace.split(LINE_RX); result += space(toReplaceLines[0].length); for (var j = 1; j < toReplaceLines.length; j += 2) { result += toReplaceLines[j] + space(toReplaceLines[j + 1].length); } } } } return result += source.slice(lastPos); }, generateMap: function () { return { version: 3, sources: [ 'source.js' ], names: [], mappings: pretty ? generateSourceMappings(removedNodes) : '' }; } } } var LINE_RX = /(\r\n?|\n|\u2028|\u2029)/; // A collection of methods for each AST type names which contain Flow types to // be removed. var removeFlowVisitor = { DeclareClass: removeNode, DeclareFunction: removeNode, DeclareInterface:removeNode, DeclareModule: removeNode, DeclareTypeAlias: removeNode, DeclareVariable: removeNode, InterfaceDeclaration: removeNode, TypeAlias: removeNode, TypeAnnotation: removeNode, TypeParameterDeclaration: removeNode, TypeParameterInstantiation: removeNode, ClassDeclaration: removeImplementedInterfaces, ClassExpression: removeImplementedInterfaces, Identifier: function (context, node, ast) { if (node.optional) { // Find the optional token. var idx = findTokenIndex(ast.tokens, node.start); do { idx++; } while (ast.tokens[idx].type.label !== '?'); removeNode(context, ast.tokens[idx]); } }, ClassProperty: function (context, node) { if (!node.value) { return removeNode(context, node) } }, ExportNamedDeclaration: function (context, node) { if (node.exportKind === 'type' || node.exportKind === 'typeof') { return removeNode(context, node); } }, ImportDeclaration: function (context, node) { if (node.importKind === 'type' || node.importKind === 'typeof') { return removeNode(context, node); } }, ImportSpecifier: function(context, node) { if (node.importKind === 'type' || node.importKind === 'typeof') { removeNode(context, node); // Remove trailing comma var ast = context.ast; var idx = findTokenIndex(ast.tokens, node.end); while (isComment(ast.tokens[idx])) { idx++; } if (ast.tokens[idx].type.label === ',') { removeNode(context, ast.tokens[idx]); } return false; } } }; // If this class declaration or expression implements interfaces, remove // the associated tokens. function removeImplementedInterfaces(context, 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 (!isComment(ast.tokens[idx])) { removeNode(context, ast.tokens[idx]); } } while (idx++ !== lastIdx); } } // Append node to the list of removed nodes, ensuring the order of the nodes // in the list. function removeNode(context, node) { var removedNodes = context.removedNodes; var length = removedNodes.length; var index = length; // Check for line's leading and trailing space to be removed. var spaceNode = context.pretty ? getLeadingSpaceNode(context, node) : null; var lineNode = context.pretty ? getTrailingLineNode(context, node) : null; while (index > 0 && removedNodes[index - 1].end > node.start) { index--; } if (index === length) { if (spaceNode) { removedNodes.push(spaceNode); } removedNodes.push(node); if (lineNode) { removedNodes.push(lineNode); } } else { if (lineNode) { if (spaceNode) { removedNodes.splice(index, 0, spaceNode, node, lineNode); } else { removedNodes.splice(index, 0, node, lineNode); } } else if (spaceNode) { removedNodes.splice(index, 0, spaceNode, node); } else { removedNodes.splice(index, 0, node); } } return false; } function getPragmaNode(context, start, size) { var source = context.source; var line = 1; var column = 0; for (var position = 0; position < start; position++) { var char = source[position]; if (char === '\n') { line++; column = 0; } else if (char === '\r') { if (source[position + 1] === '\n') { position++; } line++; column = 0; } else { column++; } } return { start: start, end: start + size, loc: { start: { line: line, column: column }, end: { line: line, column: column + size }, }, }; } function getLeadingSpaceNode(context, node) { var source = context.source; var end = node.start; var start = end; while (source[start - 1] === ' ' || source[start - 1] === '\t') { start--; } if (start !== end) { return { start: start, end: end, loc: { start: node.loc.start, end: node.loc.start } }; } } function getTrailingLineNode(context, node) { var source = context.source; var start = node.end; var end = start; while (source[end] === ' ' || source[end] === '\t') { end++; } // Remove all space including the line break if this token was alone on the line. if (source[end] === '\n' || source[end] === '\r') { if (source[end] === '\r' && source[end + 1] === '\n') { end++; } end++; if (isLastNodeRemovedFromLine(context, node)) { return { start: start, end: end, loc: { start: node.loc.end, end: node.loc.end } }; } } } // Returns true if node is the last to be removed from a line. function isLastNodeRemovedFromLine(context, node) { var tokens = context.ast.tokens; var priorTokenIdx = findTokenIndex(tokens, node.start) - 1; var token = tokens[priorTokenIdx]; var line = node.loc.end.line; // Find previous token that was not removed on the same line. while (priorTokenIdx >= 0 && token.loc.end.line === line && isRemovedToken(context, token)) { token = tokens[--priorTokenIdx] } // If there's no prior token (start of file), or the prior token is on another // line, this line must be fully removed. return !token || token.loc.end.line !== line; } // Returns true if the provided token was previously marked as removed. function isRemovedToken(context, token) { var removedNodes = context.removedNodes; var nodeIdx = removedNodes.length - 1; // Find the last removed node which could possibly contain this token. while (nodeIdx >= 0 && removedNodes[nodeIdx].start > token.start) { nodeIdx--; } var node = removedNodes[nodeIdx]; // This token couldn't be removed if not contained within the removed node. if (nodeIdx === -1 || node.end < token.end) { return false; } // Iterate through the tokens contained by the removed node to find a match. var tokens = context.ast.tokens; var tokenIdx = findTokenIndex(tokens, node.start); while (tokens[tokenIdx].end <= node.end) { if (token === tokens[tokenIdx]) { return true; } tokenIdx++; } return false; } // Given the AST output of babylon parse, walk through in a depth-first order, // calling methods on the given visitor, providing context as the first argument. function visit(ast, context, visitor) { var stack; var parent; var keys = []; var index = -1; do { index++; if (stack && index === keys.length) { parent = stack.parent; keys = stack.keys; index = stack.index; stack = stack.prev; } else { var node = parent ? parent[keys[index]] : ast.program; if (node && typeof node === 'object' && (node.type || node.length)) { if (node.type) { var visitFn = visitor[node.type]; if (visitFn && visitFn(context, node, ast) === false) { continue; } } stack = { parent: parent, keys: keys, index: index, prev: stack }; parent = node; keys = Object.keys(node); index = -1; } } } while (stack); } // Given an array of sorted tokens, find the index of the token which contains // the given offset. Uses binary search for O(log N) performance. function findTokenIndex(tokens, offset) { var min = 0; var max = tokens.length - 1; while (min <= max) { var ptr = (min + max) / 2 | 0; var token = tokens[ptr]; if (token.end <= offset) { min = ptr + 1; } else if (token.start > offset) { max = ptr - 1; } else { return ptr; } } return ptr; } // True if the provided token is a comment. function isComment(token) { return token.type === 'CommentBlock' || token.type === 'CommentLine'; } // Produce a string full of space characters of a given size. function space(size) { var sp = ' ' var result = ''; for (;;) { if ((size & 1) === 1) { result += sp; } size >>>= 1; if (size === 0) { break; } sp += sp; } return result; } // Generate a source map when *removing* nodes rather than replacing them // with spaces. function generateSourceMappings(removedNodes) { var mappings = ''; if (!removedNodes || removedNodes.length === '') { return mappings; } var end = { line: 1, column: 0 }; for (var i = 0; i < removedNodes.length; i++) { var start = removedNodes[i].loc.start; var lineDiff = start.line - end.line; var columnDiff = start.column - end.column; if (lineDiff) { for (var l = 0; l !== lineDiff; l++) { mappings += ';'; } mappings += vlq.encode([ start.column, 0, lineDiff, columnDiff ]); } else if (columnDiff) { if (i) { mappings += ','; } mappings += vlq.encode([ columnDiff, 0, lineDiff, columnDiff ]); } end = removedNodes[i].loc.end; mappings += ','; mappings += vlq.encode([ 0, 0, end.line - start.line, end.column - start.column ]); } return mappings; } flow-remove-types-1.2.3/package.json000066400000000000000000000020331317156340500174120ustar00rootroot00000000000000{ "name": "flow-remove-types", "version": "1.2.3", "description": "Removes Flow type annotations from JavaScript files with speed and simplicity.", "author": "Lee Byron (http://leebyron.com/)", "license": "BSD-3-Clause", "main": "index.js", "bin": { "flow-remove-types": "./flow-remove-types", "flow-node": "./flow-node" }, "files": [ "index.js", "register.js", "flow-remove-types", "flow-node", "LICENSE", "PATENTS" ], "homepage": "https://github.com/flowtype/flow-remove-types", "bugs": { "url": "https://github.com/flowtype/flow-remove-types/issues" }, "repository": { "type": "git", "url": "http://github.com/flowtype/flow-remove-types.git" }, "scripts": { "test": "./test.sh", "test-update": "./test-update.sh", "postpublish": "./publish-npm-alias.sh" }, "keywords": [ "flow", "flowtype", "compiler", "transpiler", "transform", "es6" ], "dependencies": { "babylon": "^6.15.0", "vlq": "^0.2.1" } } flow-remove-types-1.2.3/publish-npm-alias.sh000077500000000000000000000003611317156340500210120ustar00rootroot00000000000000#!/bin/sh rm -rf npm-alias mkdir npm-alias cp * npm-alias/ 2> /dev/null node -p "p=require('./package.json');p.name='flow-node';delete p.scripts;JSON.stringify(p, null, 2)" > npm-alias/package.json cd npm-alias npm publish rm -rf npm-alias flow-remove-types-1.2.3/register.js000066400000000000000000000047731317156340500173230ustar00rootroot00000000000000var flowRemoveTypes = require('./index'); // Supported options: // // - all: Transform all files, not just those with a @flow comment. // - includes: A Regexp/String to determine which files should be transformed. // (alias: include) // - excludes: A Regexp/String to determine which files should not be // transformed, defaults to ignoring /node_modules/, provide null // to exclude nothing. (alias: exclude) var options; module.exports = function setOptions(newOptions) { options = newOptions; } // Swizzle Module#_compile on each applicable module instance. // NOTE: if using alongside Babel or another require-hook which simply // over-writes the require.extensions and does not continue execution, then // this require hook must come after it. Encourage those module authors to call // the prior loader in their require hooks. var jsLoader = require.extensions['.js']; var exts = [ '.js', '.mjs', '.jsx', '.flow', '.es6' ]; exts.forEach(function (ext) { var superLoader = require.extensions[ext] || jsLoader; require.extensions[ext] = function (module, filename) { if (shouldTransform(filename, options)) { var super_compile = module._compile; module._compile = function _compile(code, filename) { super_compile.call(this, flowRemoveTypes(code, options).toString(), filename); }; } superLoader(module, filename); }; }); function shouldTransform(filename, options) { var includes = options && regexpPattern(options.includes || options.include); var excludes = options && 'excludes' in options ? regexpPattern(options.excludes) : options && 'exclude' in options ? regexpPattern(options.exclude) : /\/node_modules\//; return (!includes || includes.test(filename)) && !(excludes && excludes.test(filename)); } // Given a null | string | RegExp | any, returns null | Regexp or throws a // more helpful error. function regexpPattern(pattern) { if (!pattern) { return pattern; } // A very simplified glob transform which allows passing legible strings like // "myPath/*.js" instead of a harder to read RegExp like /\/myPath\/.*\.js/. if (typeof pattern === 'string') { pattern = pattern.replace(/\./g, '\\.').replace(/\*/g, '.*'); if (pattern[0] !== '/') { pattern = '/' + pattern; } return new RegExp(pattern); } if (typeof pattern.test === 'function') { return pattern; } throw new Error( 'flow-remove-types: includes and excludes must be RegExp or path strings. Got: ' + pattern ); } flow-remove-types-1.2.3/test-update.sh000077500000000000000000000010041317156340500177170ustar00rootroot00000000000000#!/bin/sh # Generate expected output ./flow-remove-types test/source.js > test/expected.js; # Generate expected output with --pretty flag ./flow-remove-types --pretty test/source.js > test/expected-pretty.js; # Test expected source maps with --pretty --sourcemaps ./flow-remove-types --pretty --sourcemaps test/source.js -d test/expected-with-maps; # Test expected source maps with --pretty --sourcemaps inline ./flow-remove-types --pretty --sourcemaps inline test/source.js > test/expected-pretty-inlinemap.js; flow-remove-types-1.2.3/test.sh000077500000000000000000000043541317156340500164520ustar00rootroot00000000000000#!/bin/sh # Test expected output echo "Test: flow-remove-types test/source.js" DIFF=$(./flow-remove-types test/source.js | diff test/expected.js -); if [ -n "$DIFF" ]; then echo "$DIFF"; exit 1; fi; # Test expected output with --pretty flag echo "Test: flow-remove-types --pretty test/source.js" DIFF=$(./flow-remove-types --pretty test/source.js | diff test/expected-pretty.js -); if [ -n "$DIFF" ]; then echo "$DIFF"; exit 1; fi; # Test expected source maps with --pretty --sourcemaps echo "Test: flow-remove-types --pretty --sourcemaps test/source.js -d test/expected-with-maps" TEST_DIR=$(cd $(dirname ${BASH_SOURCE[0]}) && pwd) DIR=$(mktemp -d) cp -r test $DIR pushd $DIR > /dev/null $TEST_DIR/flow-remove-types --pretty --sourcemaps test/source.js -d test/expected-with-maps; popd > /dev/null DIFF_SOURCE=$(diff test/expected-with-maps/test/source.js $DIR/test/expected-with-maps/test/source.js); DIFF_MAP=$(diff test/expected-with-maps/test/source.js.map $DIR/test/expected-with-maps/test/source.js.map); rm -rf $DIR if [ -n "$DIFF_SOURCE" ]; then echo "$DIFF_SOURCE"; exit 1; fi; if [ -n "$DIFF_MAP" ]; then echo "$DIFF_MAP"; exit 1; fi; # Test expected source maps with --pretty --sourcemaps inline echo "Test: flow-remove-types --pretty --sourcemaps inline test/source.js" DIFF=$(./flow-remove-types --pretty --sourcemaps inline test/source.js | diff test/expected-pretty-inlinemap.js -); if [ -n "$DIFF" ]; then echo "$DIFF"; exit 1; fi; # Test expected output with @flow outside of comments echo "Test: flow-remove-types test/without-flow.js" DIFF=$(./flow-remove-types test/without-flow.js | diff test/without-flow.js -); if [ -n "$DIFF" ]; then echo "$DIFF"; exit 1; fi; # Test node require hook echo "Test: node require hook" RES=$(node -e 'require("./register");require("./test/test-node-module.js")'); if [ "$RES" != 42 ]; then echo 'Node require hook failed'; exit 1; fi; # Test flow-node echo "Test: flow-node" FLOW_NODE=$(./flow-node ./test/test-node-module.js); if [ "$FLOW_NODE" != 42 ]; then echo 'flow-node failed'; exit 1; fi; # Test flow-node with options echo "Test: flow-node with options" FLOW_NODE_OPTS=$(./flow-node --code-comments -p 'process.argv.length'); if [ "$FLOW_NODE_OPTS" != 4 ]; then echo 'flow-node with options failed'; exit 1; fi; flow-remove-types-1.2.3/test/000077500000000000000000000000001317156340500161055ustar00rootroot00000000000000flow-remove-types-1.2.3/test/expected-pretty-inlinemap.js000066400000000000000000000047171317156340500235540ustar00rootroot00000000000000/* */ // Regular import import { Something, } from 'some-module'; // Import types // Typed function async function test(x, y /*.*/ /*.*/ , z /*.*/ /*.*/ = 123) { // Typed expression return await (x); } // Interface // Exported interface // Interface extends // Implements interface class Bar extends Other /*.*/ { // Class Property with default value answer = 42; // Class Property method() { return; } } // Class expression implements interface var SomeClass = class Baz { method() { return; } }; // Parametric class class Wrapper { get() { return this.value; } map() { // do something } } // Extends Parametric class class StringWrapper extends Wrapper { // ... } // Declare class // Declare funtion // Declare interface // Declare module // Declare type alias // Declare variable // Type alias // Export type // Regular export export { Wrapper }; // Exported type alias // Object with types within var someObj = { objMethod() { // do nothing. } } // Example from README import SomeClass from 'some-module' export class MyClass extends SomeClass { constructor(value) { this.value = value } get() { return this.value } } // Test async/await functions async function asyncFunction(input) { return await t; } //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3Qvc291cmNlLmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJHQUFHLEFBQUs7Ozs7O0VBS04sQUFBQSxBQUFhLEFBQUMsQUFBQTtFQUNkLEFBQUEsQUFBcUIsQUFBQTs7OztBQUl2QixBQUE0QyxBQUFBOzs7cUJBR3ZCLEFBQU0sVUFBVSxBQUFBLEFBQUMsaUJBQWlCLEFBQUEsQUFBQyxPQUFPLEFBQUEsQUFBYyxPQUFPLEFBQVE7O2lCQUUzRSxBQUFLOzs7O0FBSXRCLEFBSUMsQUFBQTs7O0FBR0QsQUFFQyxBQUFBOzs7QUFHRCxBQUVDLEFBQUE7Ozt3QkFHdUIsQUFBQSxBQUFVLE9BQU8sQUFBQSxBQUFHLEFBQUMsQ0FBQyxBQUFBLEFBQVU7O1FBRWhELEFBQVE7OztFQUdkLEFBQUEsQUFBVSxBQUFBOztVQUVGLEFBQU87Ozs7OzswQkFNUyxBQUFBLEFBQVUsQ0FBQyxBQUFBLEFBQUc7RUFDdEMsQUFBQSxBQUFVLEFBQUE7O1VBRUYsQUFBTzs7Ozs7O2FBTUosQUFBRztPQUNULEFBQUc7Ozs7S0FJTCxBQUFHLEVBQUUsQUFBWTs7Ozs7O21DQU1hLEFBQVE7Ozs7O0FBSzNDLEFBRUMsQUFBQTs7O0FBR0QsQUFBa0MsQUFBQTs7O0FBR2xDLEFBRUMsQUFBQTs7O0FBR0QsQUFFQyxBQUFBOzs7QUFHRCxBQUdFLEFBQUE7OztBQUdGLEFBQStCLEFBQUE7OztBQUcvQixBQUFnQixBQUFBOzs7QUFHaEIsQUFBa0IsQUFBQTs7Ozs7O0FBTWxCLEFBQWtDLEFBQUE7Ozs7YUFJckIsQUFBTTs7Ozs7OztBQU9uQixBQUFnRCxBQUFBOztvQkFFNUIsQUFBRyxtQkFBbUIsQUFBQSxBQUFVLENBQUMsQUFBQSxBQUFhOztFQUVoRSxBQUFBLEFBQVEsQUFBQTs7bUJBRVMsQUFBRzs7OztPQUlmLEFBQUc7Ozs7Ozs7NEJBT2tCLEFBQUcsTUFBTSxBQUFHLENBQUMsQUFBWSJ9 flow-remove-types-1.2.3/test/expected-pretty.js000066400000000000000000000024411317156340500215720ustar00rootroot00000000000000/* */ // Regular import import { Something, } from 'some-module'; // Import types // Typed function async function test(x, y /*.*/ /*.*/ , z /*.*/ /*.*/ = 123) { // Typed expression return await (x); } // Interface // Exported interface // Interface extends // Implements interface class Bar extends Other /*.*/ { // Class Property with default value answer = 42; // Class Property method() { return; } } // Class expression implements interface var SomeClass = class Baz { method() { return; } }; // Parametric class class Wrapper { get() { return this.value; } map() { // do something } } // Extends Parametric class class StringWrapper extends Wrapper { // ... } // Declare class // Declare funtion // Declare interface // Declare module // Declare type alias // Declare variable // Type alias // Export type // Regular export export { Wrapper }; // Exported type alias // Object with types within var someObj = { objMethod() { // do nothing. } } // Example from README import SomeClass from 'some-module' export class MyClass extends SomeClass { constructor(value) { this.value = value } get() { return this.value } } // Test async/await functions async function asyncFunction(input) { return await t; } flow-remove-types-1.2.3/test/expected-with-maps/000077500000000000000000000000001317156340500216155ustar00rootroot00000000000000flow-remove-types-1.2.3/test/expected-with-maps/test/000077500000000000000000000000001317156340500225745ustar00rootroot00000000000000flow-remove-types-1.2.3/test/expected-with-maps/test/source.js000066400000000000000000000025051317156340500244340ustar00rootroot00000000000000/* */ // Regular import import { Something, } from 'some-module'; // Import types // Typed function async function test(x, y /*.*/ /*.*/ , z /*.*/ /*.*/ = 123) { // Typed expression return await (x); } // Interface // Exported interface // Interface extends // Implements interface class Bar extends Other /*.*/ { // Class Property with default value answer = 42; // Class Property method() { return; } } // Class expression implements interface var SomeClass = class Baz { method() { return; } }; // Parametric class class Wrapper { get() { return this.value; } map() { // do something } } // Extends Parametric class class StringWrapper extends Wrapper { // ... } // Declare class // Declare funtion // Declare interface // Declare module // Declare type alias // Declare variable // Type alias // Export type // Regular export export { Wrapper }; // Exported type alias // Object with types within var someObj = { objMethod() { // do nothing. } } // Example from README import SomeClass from 'some-module' export class MyClass extends SomeClass { constructor(value) { this.value = value } get() { return this.value } } // Test async/await functions async function asyncFunction(input) { return await t; } //# sourceMappingURL=source.js.map flow-remove-types-1.2.3/test/expected-with-maps/test/source.js.map000066400000000000000000000015231317156340500252070ustar00rootroot00000000000000{"version":3,"sources":["../../source.js"],"names":[],"mappings":"GAAG,AAAK;;;;;EAKN,AAAA,AAAa,AAAC,AAAA;EACd,AAAA,AAAqB,AAAA;;;;AAIvB,AAA4C,AAAA;;;qBAGvB,AAAM,UAAU,AAAA,AAAC,iBAAiB,AAAA,AAAC,OAAO,AAAA,AAAc,OAAO,AAAQ;;iBAE3E,AAAK;;;;AAItB,AAIC,AAAA;;;AAGD,AAEC,AAAA;;;AAGD,AAEC,AAAA;;;wBAGuB,AAAA,AAAU,OAAO,AAAA,AAAG,AAAC,CAAC,AAAA,AAAU;;QAEhD,AAAQ;;;EAGd,AAAA,AAAU,AAAA;;UAEF,AAAO;;;;;;0BAMS,AAAA,AAAU,CAAC,AAAA,AAAG;EACtC,AAAA,AAAU,AAAA;;UAEF,AAAO;;;;;;aAMJ,AAAG;OACT,AAAG;;;;KAIL,AAAG,EAAE,AAAY;;;;;;mCAMa,AAAQ;;;;;AAK3C,AAEC,AAAA;;;AAGD,AAAkC,AAAA;;;AAGlC,AAEC,AAAA;;;AAGD,AAEC,AAAA;;;AAGD,AAGE,AAAA;;;AAGF,AAA+B,AAAA;;;AAG/B,AAAgB,AAAA;;;AAGhB,AAAkB,AAAA;;;;;;AAMlB,AAAkC,AAAA;;;;aAIrB,AAAM;;;;;;;AAOnB,AAAgD,AAAA;;oBAE5B,AAAG,mBAAmB,AAAA,AAAU,CAAC,AAAA,AAAa;;EAEhE,AAAA,AAAQ,AAAA;;mBAES,AAAG;;;;OAIf,AAAG;;;;;;;4BAOkB,AAAG,MAAM,AAAG,CAAC,AAAY"} flow-remove-types-1.2.3/test/expected.js000066400000000000000000000042201317156340500202420ustar00rootroot00000000000000/* */ // Regular import import { Something, } from 'some-module'; // Import types // Typed function async function test(x , y /*.*/ /*.*/ , z /*.*/ /*.*/ = 123) { // Typed expression return await (x ); } // Interface // Exported interface // Interface extends // Implements interface class Bar extends Other /*.*/ { // Class Property with default value answer = 42; // Class Property method() { return; } } // Class expression implements interface var SomeClass = class Baz { method() { return; } }; // Parametric class class Wrapper { get() { return this.value; } map () { // do something } } // Extends Parametric class class StringWrapper extends Wrapper { // ... } // Declare class // Declare funtion // Declare interface // Declare module // Declare type alias // Declare variable // Type alias // Export type // Regular export export { Wrapper }; // Exported type alias // Object with types within var someObj = { objMethod() { // do nothing. } } // Example from README import SomeClass from 'some-module' export class MyClass extends SomeClass { constructor(value ) { this.value = value } get() { return this.value } } // Test async/await functions async function asyncFunction (input ) { return await t; } flow-remove-types-1.2.3/test/source.js000066400000000000000000000042201317156340500177410ustar00rootroot00000000000000/* @flow */ // Regular import import { Something, type SomeType, typeof SomeOtherThing } from 'some-module'; // Import types import type { SomeType } from 'some-module'; // Typed function async function test(x: Type, y /*.*/ ? /*.*/ , z /*.*/ ? /*.*/ : /*.*/ number = 123): string { // Typed expression return await (x: any); } // Interface interface Foo { prop: any; method(): mixed; } // Exported interface export interface IThing { exported: true; } // Interface extends interface SillyFoo extends Foo { silly: string; } // Implements interface class Bar extends Other implements /*.*/ Foo, ISomething { // Class Property with default value answer: number = 42; // Class Property prop: any; method(): mixed { return; } } // Class expression implements interface var SomeClass = class Baz implements Foo { prop: any; method(): mixed { return; } }; // Parametric class class Wrapper { get(): T { return this.value; } map(): Wrapper { // do something } } // Extends Parametric class class StringWrapper extends Wrapper { // ... } // Declare class declare class Baz { method(): mixed; } // Declare funtion declare function someFunc(): void; // Declare interface declare interface ISomething { answer: number; } // Declare module declare module 'fs' { declare function readThing(path: string): string; } // Declare type alias declare type Location = { lat: number, lon: number }; // Declare variable declare var SOME_CONST: string; // Type alias type T = string; // Export type export type { T }; // Regular export export { Wrapper }; // Exported type alias export type ONE = { one: number }; // Object with types within var someObj = { objMethod(): void { // do nothing. } } // Example from README import SomeClass from 'some-module' import type { SomeInterface } from 'some-module' export class MyClass extends SomeClass implements SomeInterface { value: T constructor(value: T) { this.value = value } get(): T { return this.value } } // Test async/await functions async function asyncFunction(input: T): Promise { return await t; } flow-remove-types-1.2.3/test/test-node-module.js000066400000000000000000000000561317156340500216310ustar00rootroot00000000000000// @flow var n: number = 42; console.log(n); flow-remove-types-1.2.3/test/without-flow.js000066400000000000000000000000741317156340500211140ustar00rootroot00000000000000function hasNoFlow(flow) { return '@flow'.test(/@flow/) }