Security News
NVD Backlog Tops 20,000 CVEs Awaiting Analysis as NIST Prepares System Updates
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Babylon is a JavaScript parser used in Babel.
Heavily based on acorn and acorn-jsx, thanks to the awesome work of @RReverser and @marijnh.
Significant diversions are expected to occur in the future such as streaming, EBNF definitions, sweet.js integration, interspatial parsing and more.
babylon.parse(code, [options])
allowImportExportEverywhere: By default, import
and export
declarations can only appear at a program's top level. Setting this
option to true
allows them anywhere where a statement is allowed.
allowReturnOutsideFunction: By default, a return statement at
the top level raises an error. Set this to true
to accept such
code.
allowSuperOutsideMethod TODO
sourceType: Indicate the mode the code should be parsed in. Can be
either "script"
or "module"
.
sourceFilename: Correlate output AST nodes with their source filename. Useful when generating code and source maps from the ASTs of multiple input files.
plugins: Array containing the plugins that you want to enable.
Babylon generates AST according to Babel AST format. It is based on ESTree spec with the following deviations:
directives
field with Directive and DirectiveLiteralAST for JSX code is based on Facebook JSX AST with the addition of one node type:
JSXText
Babylon follows semver in most situations. The only thing to note is that some spec-compliancy bug fixes may be released under patch versions.
For example: We push a fix to early error on something like #107 - multiple default exports per file. That would be considered a bug fix even though it would cause a build to fail.
require("babylon").parse("code", {
// parse in strict mode and allow module declarations
sourceType: "module",
plugins: [
// enable jsx and flow syntax
"jsx",
"flow"
]
});
jsx
flow
doExpressions
objectRestSpread
decorators
classProperties
exportExtensions
asyncGenerators
functionBind
functionSent
dynamicImport
6.14.0 (2016-11-16)
Throw error for reserved words enum
and await
(#195) (Kai Cataldo)
11.6.2.2 Future Reserved Words
Babylon will throw for more reserved words such as enum
or await
(in strict mode).
class enum {} // throws
class await {} // throws in strict mode (module)
Optional names for function types and object type indexers (#197) (Gabe Levi)
So where you used to have to write
type A = (x: string, y: boolean) => number;
type B = (z: string) => number;
type C = { [key: string]: number };
you can now write (with flow 0.34.0)
type A = (string, boolean) => number;
type B = string => number;
type C = { [string]: number };
Parse flow nested array type annotations like number[][]
(#219) (Bernhard Häussner)
Supports these form now of specifying array types:
var a: number[][][][];
var b: string[][];
Correctly eat semicolon at the end of DelcareModuleExports
(#223) (Daniel Tschinder)
declare module "foo" { declare module.exports: number }
declare module "foo" { declare module.exports: number; } // also allowed now
FAQs
A JavaScript parser
The npm package babylon receives a total of 6,500,116 weekly downloads. As such, babylon popularity was classified as popular.
We found that babylon demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.