EcmaScript/TypeScript parser for the rust programming language.
Features
Heavily tested
Passes almost all tests from tc39/test262.
Error reporting
|
|
Error recovery
The parser can recover from some parsing errors. For example, parser returns
Ok(Module)
for the code below, while emitting error to handler.
const CONST = 9000 % 2;
const enum D {
// Comma is required, but parser can recover because of the newline.
d = 10
g = CONST
}
Example (lexer)
See lexer.rs
in examples directory.
Example (parser)
extern crate swc_common;
extern crate swc_ecma_parser;
use Lrc;
use ;
use ;
Cargo features
typescript
Enables typescript parser.
verify
Verify more errors, using swc_ecma_visit
.
Known issues
Null character after \
Because [String] of rust should only contain valid utf-8 characters while javascript allows non-utf8 characters, the parser stores invalid utf8 characters in escaped form.
As a result, swc needs a way to distinguish invalid-utf8 code points and
input specified by the user. The parser stores a null character right after
\\
for non-utf8 code points. Note that other parts of swc is aware of this
fact.
Note that this can be changed at anytime with a breaking change.