Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

flow-parser

Package Overview
Dependencies
Maintainers
3
Versions
332
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

flow-parser - npm Package Compare versions

Comparing version 0.6.0 to 0.7.0

README-npm.md

5

package.json
{
"name": "flow-parser",
"version": "0.6.0",
"version": "0.7.0",
"license": "BSD-3-Clause",
"description": "JavaScript parser written in OCaml. Produces SpiderMonkey AST",

@@ -21,3 +22,3 @@ "author": {

"dependencies": {
"ast-types": "0.7.6",
"ast-types": "0.8.4",
"colors": ">=0.6.2",

@@ -24,0 +25,0 @@ "minimist": ">=0.2.0"

42

README.md

@@ -1,37 +0,33 @@

# The flow-parser package
# The Flow Parser
This package contains the Flow parser in its compiled-to-JavaScript form.
The Flow Parser is a JavaScript parser written in OCaml. It produces an AST that conforms to [SpiderMonkey's Parser API](https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/Parser_API) and that mostly matches what [esprima](http://esprima.org/) produces. The Flow Parser can be compiled to native code or can be compiled to JavaScript using [js_of_ocaml](http://ocsigen.org/js_of_ocaml/).
# What is Flow
## Building the Flow Parser
See [flowtype.org](http://flowtype.org/). The code for the Flow parser [lives on GitHub](https://github.com/facebook/flow/tree/master/src/parser).
Building the Flow Parser requires OCaml. Compiling to JavaScript requires js_of_ocaml.
# What is the Flow Parser
### Initial set up
The Flow Parser is a JavaScript parser written in OCaml. It produces an AST that conforms to the [ESTree spec](https://github.com/estree/estree) and that mostly matches what [esprima](http://esprima.org/) produces. The Flow Parser can be compiled to native code or can be compiled to JavaScript using [js_of_ocaml](http://ocsigen.org/js_of_ocaml/). This npm package contains the Flow parser compiled to JavaScript.
* [Install opam](https://opam.ocaml.org/doc/Install.html)
* `opam install js_of_ocaml`
# Usage
### Building the OCaml Flow Parser library
You can use the Flow parser in your browser or in node. To use in node you can just do
make
### Compiling the Flow Parser to JavaScript
```JavaScript
require('flow-parser').parse('1+1');
```
make js
To use in the browser, you can add
## Tests
```HTML
<script src="flow_parser.js"></script>
```
The Flow Parser's test suite tests the JavaScript version of the parser, so you will need js_of_ocaml installed. The tests and tools also have some node module dependencies, so you will need to run
which will make the `flow` object available to use like so:
### Initial set up
```JavaScript
flow.parse('1+1');
```
* Follow the steps in [Building the Flow Parser](https://github.com/facebook/flow/blob/master/src/parser/README.md#building-the-flow-parser)
* `npm install`
# bin scripts
### Running the Tests
* `flowparse` - Pass it a string to parse or a file to parse and it dumps the AST to stdout
* `flowvalidate` - Pass it one or more files and it checks if they parse
make test

@@ -8,3 +8,3 @@ /**

var util = require("util");
var ast_types = require("ast-types");
var ast_types = require("./esprima_ast_types.js");

@@ -61,3 +61,4 @@ function new_env() {

var expected_str = "";
if (typeof diff.expected !== "undefined") {
if (typeof diff.expected !== "undefined" ||
typeof diff.actual !== "undefined") {
expected_str =

@@ -91,5 +92,2 @@ ". Expected " + diff.expected + ", got " + diff.actual;

switch (esprima.type) {
case 'Literal':
delete esprima.regex;
break;
case "SwitchStatement":

@@ -191,2 +189,16 @@ // Esprima doesn't support let statements so it doesn't include the

break;
case "ClassBody":
// esprima-fb is pretty out of date here. The 4 kinds should be
// "constructor", "method", "get" and "set"
for (var i = 0; i < esprima.body.length; i++) {
var body = esprima.body[i];
if (body && body.type == "MethodDefinition") {
if (body.key.name === "constructor") {
body.kind = "constructor";
} else if (body.kind === "init" || body.kind === "") {
body.kind = "method";
}
}
}
break;
case 'ArrayPattern':

@@ -206,4 +218,7 @@ // Esprima has the wrong node type for spread elements in an array pattern

case 'ObjectTypeCallProperty':
esprima.static = esprima.static || false;
break;
case 'ClassProperty':
esprima.static = esprima.static || false;
esprima.value = null;
break;

@@ -404,13 +419,17 @@ case 'ArrowFunctionExpression':

if (flow_errors.length !== 0) {
result.passed = false;
output("****Unexpected Errors****");
env.push_path('errors');
for (var i = 0; i < flow_errors.length; i++) {
var e = flow_errors[i];
output(
"(#" + i + ")",
"(line " + e.loc.start.line + ", col " + e.loc.start.column + ") - " +
"(line " + e.loc.end.line + ", col " + e.loc.end.column + "): ",
e.message
);
env.push_path(i);
env.push_path('column');
env.diff("Wrong error column", undefined, e.loc.start.column + 1);
env.pop_path();
env.push_path('line');
env.diff("Wrong error line", undefined, e.loc.start.line);
env.pop_path();
env.push_path('message');
env.diff("Wrong error message", undefined, e.message);
env.pop_path();
}
env.pop_path();
}

@@ -417,0 +436,0 @@

var flow = require("./../flow_parser.js");
var util = require("util");
var ast_types = require("ast-types");
var ast_types = require("./esprima_ast_types.js");

@@ -5,0 +5,0 @@ function new_env() {

@@ -12,6 +12,4 @@ #!/usr/bin/env node

'Invalid Type Annotations': true,
'ES6: Numeric Literal': true,
'Array Comprehension': true,
'Harmony: Modules': true,
'Harmony: Iterators': true,
'Harmony: Invalid Class (strawman)': true,

@@ -18,0 +16,0 @@ 'ES6: Destructured Parameters': true,

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

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