mirror of
https://github.com/danbulant/oxc
synced 2026-05-21 21:29:01 +00:00
feat(napi/parser): remove experimental flexbuffer api (#2957)
This commit is contained in:
parent
071010964e
commit
b15bf2826b
10 changed files with 39 additions and 202 deletions
147
Cargo.lock
generated
147
Cargo.lock
generated
|
|
@ -58,7 +58,7 @@ checksum = "a507401cad91ec6a857ed5513a2073c82a9b9048762b885bb98655b306964681"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.58",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -69,7 +69,7 @@ checksum = "3c87f3f15e7794432337fc718554eaa4dc8f04c9677a950ffe366f20a162ae42"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.58",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -158,7 +158,7 @@ checksum = "9a8d5b11f7fa1068e5bbac8ab6c8c2c6940047f69185987446b60c995d4bf89c"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.58",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -180,12 +180,6 @@ dependencies = [
|
|||
"allocator-api2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
|
||||
|
||||
[[package]]
|
||||
name = "bytes"
|
||||
version = "1.6.0"
|
||||
|
|
@ -398,7 +392,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "ad291aa74992b9b7a7e88c38acbbf6ad7e107f1d90ee8775b7bc1fc3394f485c"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"syn 2.0.58",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -518,19 +512,6 @@ dependencies = [
|
|||
"miniz_oxide",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "flexbuffers"
|
||||
version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "15d14128f06405808ce75bfebe11e9b0f9da18719ede6d7bdb1702d6bfe0f7e8"
|
||||
dependencies = [
|
||||
"bitflags 1.3.2",
|
||||
"byteorder",
|
||||
"num_enum",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "form_urlencoded"
|
||||
version = "1.2.1"
|
||||
|
|
@ -596,7 +577,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.58",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -999,7 +980,7 @@ checksum = "dcf09caffaac8068c346b6df2a7fc27a177fd20b39421a39ce0a211bde679a6c"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.58",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -1049,17 +1030,15 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "napi"
|
||||
version = "2.16.1"
|
||||
version = "2.16.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c4ca998356d8ff9fba7a070dae4508a2298439c98c9f3bc9c07669538b999e8f"
|
||||
checksum = "70d04890ef4ec001fad791be785b8b920e2a3f5a6b1188e7a81dfa6197c0dee4"
|
||||
dependencies = [
|
||||
"bitflags 2.5.0",
|
||||
"ctor",
|
||||
"napi-derive",
|
||||
"napi-sys",
|
||||
"once_cell",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
|
|
@ -1080,7 +1059,7 @@ dependencies = [
|
|||
"napi-derive-backend",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.58",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -1095,14 +1074,14 @@ dependencies = [
|
|||
"quote",
|
||||
"regex",
|
||||
"semver",
|
||||
"syn 2.0.58",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "napi-sys"
|
||||
version = "2.3.0"
|
||||
version = "2.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2503fa6af34dc83fb74888df8b22afe933b58d37daf7d80424b1c60c68196b8b"
|
||||
checksum = "427802e8ec3a734331fec1035594a210ce1ff4dc5bc1950530920ab717964ea3"
|
||||
dependencies = [
|
||||
"libloading",
|
||||
]
|
||||
|
|
@ -1170,27 +1149,6 @@ dependencies = [
|
|||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num_enum"
|
||||
version = "0.5.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1f646caf906c20226733ed5b1374287eb97e3c2a5c227ce668c1f2ce20ae57c9"
|
||||
dependencies = [
|
||||
"num_enum_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num_enum_derive"
|
||||
version = "0.5.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dcbff9bc912032c62bf65ef1d5aea88983b420f4f839db1e9b0c281a25c9c799"
|
||||
dependencies = [
|
||||
"proc-macro-crate",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "object"
|
||||
version = "0.32.2"
|
||||
|
|
@ -1234,7 +1192,7 @@ dependencies = [
|
|||
"proc-macro2",
|
||||
"proc-macro2-diagnostics",
|
||||
"quote",
|
||||
"syn 2.0.58",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -1481,7 +1439,7 @@ dependencies = [
|
|||
"itertools",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.58",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -1552,7 +1510,6 @@ dependencies = [
|
|||
name = "oxc_parser_napi"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"flexbuffers",
|
||||
"napi",
|
||||
"napi-build",
|
||||
"napi-derive",
|
||||
|
|
@ -1562,7 +1519,6 @@ dependencies = [
|
|||
"oxc_module_lexer",
|
||||
"oxc_parser",
|
||||
"oxc_span",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tokio",
|
||||
]
|
||||
|
|
@ -1806,7 +1762,7 @@ dependencies = [
|
|||
"pest_meta",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.58",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -1860,7 +1816,7 @@ dependencies = [
|
|||
"phf_shared",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.58",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -1895,7 +1851,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.58",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -1910,16 +1866,6 @@ version = "0.1.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-crate"
|
||||
version = "1.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"toml_edit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.79"
|
||||
|
|
@ -1937,7 +1883,7 @@ checksum = "af066a9c399a26e020ada66a034357a868728e72cd426f3adcd35f80d88d88c8"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.58",
|
||||
"syn",
|
||||
"version_check",
|
||||
"yansi",
|
||||
]
|
||||
|
|
@ -2228,7 +2174,7 @@ checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.58",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -2239,7 +2185,7 @@ checksum = "e578a843d40b4189a4d66bba51d7684f57da5bd7c304c64e14bd63efbef49509"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.58",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -2262,7 +2208,7 @@ checksum = "0b2e6b945e9d3df726b65d6ee24060aff8e3533d431f677a9695db04eff9dfdb"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.58",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -2383,17 +2329,6 @@ dependencies = [
|
|||
"is_ci",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.109"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.58"
|
||||
|
|
@ -2445,7 +2380,7 @@ checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.58",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -2510,7 +2445,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.58",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -2527,23 +2462,6 @@ dependencies = [
|
|||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_datetime"
|
||||
version = "0.6.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1"
|
||||
|
||||
[[package]]
|
||||
name = "toml_edit"
|
||||
version = "0.19.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421"
|
||||
dependencies = [
|
||||
"indexmap",
|
||||
"toml_datetime",
|
||||
"winnow",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tower"
|
||||
version = "0.4.13"
|
||||
|
|
@ -2595,7 +2513,7 @@ checksum = "84fd902d4e0b9a4b27f2f440108dc034e1758628a9b702f8ec61ad66355422fa"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.58",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -2623,7 +2541,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.58",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -2687,7 +2605,7 @@ dependencies = [
|
|||
"proc-macro2",
|
||||
"quote",
|
||||
"serde_derive_internals",
|
||||
"syn 2.0.58",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
@ -2866,7 +2784,7 @@ dependencies = [
|
|||
"once_cell",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.58",
|
||||
"syn",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
|
|
@ -2888,7 +2806,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.58",
|
||||
"syn",
|
||||
"wasm-bindgen-backend",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
|
@ -3081,15 +2999,6 @@ version = "0.52.4"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8"
|
||||
|
||||
[[package]]
|
||||
name = "winnow"
|
||||
version = "0.5.40"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f593a95398737aeed53e489c785df13f3618e41dbcd6718c6addbf1395aa6876"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "yansi"
|
||||
version = "1.0.1"
|
||||
|
|
|
|||
|
|
@ -89,6 +89,7 @@ oxc_tasks_common = { path = "tasks/common" }
|
|||
|
||||
napi = "2"
|
||||
napi-derive = "2"
|
||||
napi-build = "2"
|
||||
|
||||
assert-unchecked = "0.1.2"
|
||||
allocator-api2 = "0.2.16"
|
||||
|
|
@ -147,13 +148,11 @@ console = "0.15.8"
|
|||
encoding_rs = "0.8.33"
|
||||
encoding_rs_io = "0.1.7"
|
||||
env_logger = { version = "0.11.3", default-features = false }
|
||||
flexbuffers = "2.0.0"
|
||||
globset = "0.4.14"
|
||||
humansize = "2.1.3"
|
||||
json-strip-comments = "1.0.2"
|
||||
log = "0.4.21"
|
||||
memchr = "2.7.2"
|
||||
napi-build = "2"
|
||||
once_cell = "1.19.0"
|
||||
ouroboros = "0.18.3"
|
||||
owo-colors = "4.0.0"
|
||||
|
|
@ -165,6 +164,9 @@ similar = "2.5.0"
|
|||
textwrap = "0.16.0"
|
||||
unicode-width = "0.1.11"
|
||||
|
||||
[workspace.metadata.cargo-shear]
|
||||
ignored = ["napi"]
|
||||
|
||||
[profile.dev]
|
||||
debug = 1 # "limited" debug, speed up compilation; debug info without type or variable-level information.
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ proc-macro = true
|
|||
doctest = false
|
||||
|
||||
[dependencies]
|
||||
syn = { workspace = true, features = ["derive", "parsing", "proc-macro", "printing"]}
|
||||
syn = { workspace = true, features = ["derive", "parsing", "proc-macro", "printing"] }
|
||||
quote = { workspace = true }
|
||||
proc-macro2 = { workspace = true }
|
||||
itertools = { workspace = true }
|
||||
|
|
|
|||
|
|
@ -28,13 +28,13 @@ oxc_span = { workspace = true }
|
|||
oxc_diagnostics = { workspace = true }
|
||||
oxc_module_lexer = { path = "../../crates/oxc_module_lexer" }
|
||||
|
||||
serde = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
flexbuffers = { workspace = true }
|
||||
|
||||
tokio = { workspace = true }
|
||||
napi = { workspace = true, features = ["serde-json", "async"] }
|
||||
napi = { workspace = true, features = ["async"] }
|
||||
napi-derive = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
|
||||
[package.metadata.cargo-shear]
|
||||
ignored = ["napi"]
|
||||
|
||||
[build-dependencies]
|
||||
napi-build = { workspace = true }
|
||||
|
|
|
|||
10
napi/parser/index.d.ts
vendored
10
napi/parser/index.d.ts
vendored
|
|
@ -121,16 +121,6 @@ export function parseWithoutReturn(sourceText: string, options?: ParserOptions |
|
|||
* * Serde JSON serialization
|
||||
*/
|
||||
export function parseSync(sourceText: string, options?: ParserOptions | undefined | null): ParseResult
|
||||
/**
|
||||
* Returns a binary AST in flexbuffers format.
|
||||
* This is a POC API. Error handling is not done yet.
|
||||
*
|
||||
* # Panics
|
||||
*
|
||||
* * File extension is invalid
|
||||
* * FlexbufferSerializer serialization error
|
||||
*/
|
||||
export function parseSyncBuffer(sourceText: string, options?: ParserOptions | undefined | null): Buffer
|
||||
/**
|
||||
* # Panics
|
||||
*
|
||||
|
|
|
|||
|
|
@ -295,11 +295,10 @@ if (!nativeBinding) {
|
|||
throw new Error(`Failed to load native binding`)
|
||||
}
|
||||
|
||||
const { moduleLexerSync, moduleLexerAsync, parseWithoutReturn, parseSync, parseSyncBuffer, parseAsync } = nativeBinding
|
||||
const { moduleLexerSync, moduleLexerAsync, parseWithoutReturn, parseSync, parseAsync } = nativeBinding
|
||||
|
||||
module.exports.moduleLexerSync = moduleLexerSync
|
||||
module.exports.moduleLexerAsync = moduleLexerAsync
|
||||
module.exports.parseWithoutReturn = parseWithoutReturn
|
||||
module.exports.parseSync = parseSync
|
||||
module.exports.parseSyncBuffer = parseSyncBuffer
|
||||
module.exports.parseAsync = parseAsync
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@
|
|||
"devDependencies": {
|
||||
"@napi-rs/cli": "^2.18.0",
|
||||
"es-module-lexer": "^1.4.1",
|
||||
"flatbuffers": "^23.5.26",
|
||||
"tinybench": "^2.6.0"
|
||||
},
|
||||
"engines": {
|
||||
|
|
|
|||
|
|
@ -11,9 +11,6 @@ devDependencies:
|
|||
es-module-lexer:
|
||||
specifier: ^1.4.1
|
||||
version: 1.4.1
|
||||
flatbuffers:
|
||||
specifier: ^23.5.26
|
||||
version: 23.5.26
|
||||
tinybench:
|
||||
specifier: ^2.6.0
|
||||
version: 2.6.0
|
||||
|
|
@ -30,10 +27,6 @@ packages:
|
|||
resolution: {integrity: sha512-cXLGjP0c4T3flZJKQSuziYoq7MlT+rnvfZjfp7h+I7K9BNX54kP9nyWvdbwjQ4u1iWbOL4u96fgeZLToQlZC7w==}
|
||||
dev: true
|
||||
|
||||
/flatbuffers@23.5.26:
|
||||
resolution: {integrity: sha512-vE+SI9vrJDwi1oETtTIFldC/o9GsVKRM+s6EL0nQgxXlYV1Vc4Tk30hj4xGICftInKQKj1F3up2n8UbIVobISQ==}
|
||||
dev: true
|
||||
|
||||
/tinybench@2.6.0:
|
||||
resolution: {integrity: sha512-N8hW3PG/3aOoZAN5V/NSAEDz0ZixDSSt5b/a05iqtpgfLWMSVuCo7w0k2vVvEjdrIoeGqZzweX2WlyioNIHchA==}
|
||||
dev: true
|
||||
|
|
|
|||
|
|
@ -1,13 +1,8 @@
|
|||
#![allow(clippy::trailing_empty_array)]
|
||||
|
||||
mod module_lexer;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use flexbuffers::FlexbufferSerializer;
|
||||
use napi::bindgen_prelude::Buffer;
|
||||
use napi_derive::napi;
|
||||
use serde::Serialize;
|
||||
|
||||
use oxc_allocator::Allocator;
|
||||
pub use oxc_ast::ast::Program;
|
||||
|
|
@ -130,24 +125,6 @@ pub fn parse_sync(source_text: String, options: Option<ParserOptions>) -> ParseR
|
|||
ParseResult { program, comments, errors }
|
||||
}
|
||||
|
||||
/// Returns a binary AST in flexbuffers format.
|
||||
/// This is a POC API. Error handling is not done yet.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// * File extension is invalid
|
||||
/// * FlexbufferSerializer serialization error
|
||||
#[allow(clippy::needless_pass_by_value)]
|
||||
#[napi]
|
||||
pub fn parse_sync_buffer(source_text: String, options: Option<ParserOptions>) -> Buffer {
|
||||
let options = options.unwrap_or_default();
|
||||
let allocator = Allocator::default();
|
||||
let ret = parse(&allocator, &source_text, &options);
|
||||
let mut serializer = FlexbufferSerializer::new();
|
||||
ret.program.serialize(&mut serializer).unwrap();
|
||||
serializer.take_buffer().into()
|
||||
}
|
||||
|
||||
/// # Panics
|
||||
///
|
||||
/// * Tokio crashes
|
||||
|
|
|
|||
|
|
@ -1,32 +0,0 @@
|
|||
const oxc = require('./index');
|
||||
const assert = require('assert');
|
||||
const flexbuffers = require('flatbuffers/js/flexbuffers');
|
||||
const file = require('fs').readFileSync(__dirname + '/index.js', 'utf8');
|
||||
|
||||
function testBuffer() {
|
||||
const buffer = oxc.parseSyncBuffer(file);
|
||||
const ref = flexbuffers.toReference(buffer.buffer);
|
||||
assert(ref.isMap());
|
||||
assert.equal(ref.get('type').stringValue(), 'Program');
|
||||
const body = ref.get('body');
|
||||
assert(body.isVector());
|
||||
}
|
||||
|
||||
function testJSON() {
|
||||
const ret = oxc.parseSync(file);
|
||||
const program = JSON.parse(ret.program);
|
||||
assert(typeof program === 'object');
|
||||
assert.equal(program.type, 'Program');
|
||||
assert(Array.isArray(program.body));
|
||||
}
|
||||
|
||||
function benchmark(func, time) {
|
||||
console.time(func.name);
|
||||
for (let i = 0; i < time; i++) {
|
||||
func();
|
||||
}
|
||||
console.timeEnd(func.name)
|
||||
}
|
||||
|
||||
benchmark(testJSON, 10000);
|
||||
benchmark(testBuffer, 10000);
|
||||
Loading…
Reference in a new issue