Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A blazing fast 100% spec compliant, self-hosted javascript parser written in Typescript

License

NotificationsYou must be signed in to change notification settings

KFlash/seafox

Repository files navigation

A blazing fast 100% spec compliant, self-hosted javascript parser written in Typescript.


Seafox NPMGitHub licenseTotal alertsCircleLicense

Features

  • Conforms to the standard ECMAScript® 2021 (ECMA-262 11th Edition) language specification
  • Support for additional ECMAScript features for Web Browsers
  • Optionally track syntactic node locations
  • Emits an ESTree-compatible abstract syntax tree
  • Lexical analysis
  • No backtracking
  • Low memory usage
  • Insane performance both on desktop computers and handheld devices
  • Twice as fast as other Javascript parsers
  • Very well tested (~33 000 unit tests with full code coverage)
  • Lightweight - ~84 KB minified

Installation

npm install seafox --save-dev

API

Seafox generatesAST according toESTree AST format, and can be used to performsyntactic analysis (parsing) orlexical analysis (tokenization) of a JavaScript program, and withES2015 and later a JavaScript program can be eithera script or a module.

Theparse method exposed bySeafox takes an optionaloptions object which allows you to specify whether to parse inscript mode (the default) or inmodule mode.

This is the available options:

{// Allow parsing using Module as the goal symbolmodule?:boolean;// The flag to enable start and end offsets and line/column location information to each node  loc:false;// Disable web compatibility  disableWebCompat:false;// The flag to attach raw property to each literal and identifier node  raw:false;// Enabled directives  directives:false;// The flag to allow return in the global scope  globalReturn:false;// The flag to enable implied strict mode  impliedStrict:false;// Enable non-standard parenthesized expression node  preserveParens:false;// Allows token extraction. Accepts only a function  onToken:function(){}}

Example usage:

import{parseScript,parseModule,parse}from'./seafox';parseScript('({x: [y] = 0} = 1)');parseModule('({x: [y] = 0} = 1)',{directives:true,raw:true});parse('({x: [y] = 0} = 1)',{module:true});parse('({x: [y] = 0} = 1)');

Lexical analysis

Lexical analysis can only be done during parsing and accepts only a function type as the option

parseScript('foo = bar',{onToken:()=>{}});

The callback function have 4 arguments.

ArgumentsDescription
tokenThe token to be extracted
valueValue of the extracted token
startStart position of the extracted token
endEnd position of the extracted token

Theloc option needs to be enabled forstart andend. Otherwise this values will be set toundefined

Performance

Seafox is developed for performance and low memory usage, and the parser is about 2x - 4x faster than all other javascript parsers.

About

A blazing fast 100% spec compliant, self-hosted javascript parser written in Typescript

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp