refactor(oxc_napi): remove source_map - moved to its crate (#7614)

This commit is contained in:
Boshen 2024-12-03 14:42:34 +00:00
parent adee0d1876
commit b4f3812c4a
11 changed files with 16 additions and 65 deletions

7
Cargo.lock generated
View file

@ -1945,13 +1945,15 @@ dependencies = [
[[package]] [[package]]
name = "oxc_sourcemap" name = "oxc_sourcemap"
version = "1.0.0" version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05e75cb20b3bb96af20d320f71d67c9f20b5bedb253cae36881fedef51f7688f" checksum = "f15cc100c3a8070aa20420a6e1eafa612ebfc3d86db01cb92d928abf082d9696"
dependencies = [ dependencies = [
"base64-simd", "base64-simd",
"cfg-if", "cfg-if",
"cow-utils", "cow-utils",
"napi",
"napi-derive",
"rustc-hash", "rustc-hash",
"serde", "serde",
"serde_json", "serde_json",
@ -2037,6 +2039,7 @@ dependencies = [
"napi-derive", "napi-derive",
"oxc", "oxc",
"oxc_napi", "oxc_napi",
"oxc_sourcemap",
] ]
[[package]] [[package]]

View file

@ -122,7 +122,7 @@ unicode-id-start = "1"
oxc-browserslist = "1.1.0" oxc-browserslist = "1.1.0"
oxc_index = "1.0.0" oxc_index = "1.0.0"
oxc_resolver = "2.0.0" oxc_resolver = "2.0.0"
oxc_sourcemap = "1" oxc_sourcemap = "1.0.2"
aho-corasick = "1.1.3" aho-corasick = "1.1.3"
allocator-api2 = "0.2.18" allocator-api2 = "0.2.18"

View file

@ -22,7 +22,7 @@ doctest = false
[dependencies] [dependencies]
oxc_isolated_declarations = { workspace = true } oxc_isolated_declarations = { workspace = true }
oxc_sourcemap = { workspace = true } oxc_sourcemap = { workspace = true, features = ["napi"] }
oxc_span = { workspace = true } oxc_span = { workspace = true }
oxc_syntax = { workspace = true } oxc_syntax = { workspace = true }
oxc_transformer = { workspace = true } oxc_transformer = { workspace = true }

View file

@ -1,6 +1,6 @@
use napi_derive::napi; use napi_derive::napi;
use super::source_map::SourceMap; use oxc_sourcemap::napi::SourceMap;
#[napi(object)] #[napi(object)]
pub struct IsolatedDeclarationsResult { pub struct IsolatedDeclarationsResult {

View file

@ -1,7 +1,5 @@
pub mod parse; pub mod parse;
pub mod source_map;
pub mod isolated_declarations; pub mod isolated_declarations;
pub mod transform; pub mod transform;

View file

@ -1,48 +0,0 @@
use napi_derive::napi;
// Aligned with Rollup's sourcemap input.
//
// <https://github.com/rollup/rollup/blob/766dbf90d69268971feaafa1f53f88a0755e8023/src/rollup/types.d.ts#L80-L89>
//
// ```
// export interface ExistingRawSourceMap {
// file?: string;
// mappings: string;
// names: string[];
// sourceRoot?: string;
// sources: string[];
// sourcesContent?: string[];
// version: number;
// x_google_ignoreList?: number[];
// }
// ```
#[napi(object)]
pub struct SourceMap {
pub file: Option<String>,
pub mappings: String,
pub names: Vec<String>,
pub source_root: Option<String>,
pub sources: Vec<String>,
pub sources_content: Option<Vec<String>>,
pub version: u8,
#[napi(js_name = "x_google_ignoreList")]
pub x_google_ignorelist: Option<Vec<u32>>,
}
impl From<oxc_sourcemap::SourceMap> for SourceMap {
fn from(source_map: oxc_sourcemap::SourceMap) -> Self {
let json = source_map.to_json();
Self {
file: json.file,
mappings: json.mappings,
names: json.names,
source_root: json.source_root,
sources: json.sources,
sources_content: json.sources_content.map(|content| {
content.into_iter().map(Option::unwrap_or_default).collect::<Vec<_>>()
}),
version: 3,
x_google_ignorelist: None,
}
}
}

View file

@ -8,9 +8,10 @@ use napi::Either;
use napi_derive::napi; use napi_derive::napi;
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
use oxc_sourcemap::napi::SourceMap;
use oxc_transformer::{EnvOptions, JsxRuntime, RewriteExtensionsMode}; use oxc_transformer::{EnvOptions, JsxRuntime, RewriteExtensionsMode};
use super::{isolated_declarations::IsolatedDeclarationsOptions, source_map::SourceMap}; use super::isolated_declarations::IsolatedDeclarationsOptions;
#[derive(Default)] #[derive(Default)]
#[napi(object)] #[napi(object)]

View file

@ -23,6 +23,7 @@ doctest = false
[dependencies] [dependencies]
oxc = { workspace = true, features = ["full", "napi"] } oxc = { workspace = true, features = ["full", "napi"] }
oxc_napi = { workspace = true } oxc_napi = { workspace = true }
oxc_sourcemap = { workspace = true, features = ["napi"] }
napi = { workspace = true } napi = { workspace = true }
napi-derive = { workspace = true } napi-derive = { workspace = true }

View file

@ -9,10 +9,8 @@ use oxc::{
parser::Parser, parser::Parser,
span::SourceType, span::SourceType,
}; };
use oxc_napi::{ use oxc_napi::isolated_declarations::{IsolatedDeclarationsOptions, IsolatedDeclarationsResult};
isolated_declarations::{IsolatedDeclarationsOptions, IsolatedDeclarationsResult}, use oxc_sourcemap::napi::SourceMap;
source_map::SourceMap,
};
use crate::errors::wrap_diagnostics; use crate::errors::wrap_diagnostics;

View file

@ -11,10 +11,8 @@ use oxc::{
transformer::{InjectGlobalVariablesConfig, InjectImport, ReplaceGlobalDefinesConfig}, transformer::{InjectGlobalVariablesConfig, InjectImport, ReplaceGlobalDefinesConfig},
CompilerInterface, CompilerInterface,
}; };
use oxc_napi::{ use oxc_napi::transform::{TransformOptions, TransformResult};
source_map::SourceMap, use oxc_sourcemap::napi::SourceMap;
transform::{TransformOptions, TransformResult},
};
use crate::errors::wrap_diagnostics; use crate::errors::wrap_diagnostics;

View file

@ -8,7 +8,7 @@ import oxc from 'oxc-parser';
const sourceText = "let foo: Foo = 'foo';"; const sourceText = "let foo: Foo = 'foo';";
// Filename extension is used to determine which dialect to parse source as. // Filename extension is used to determine which dialect to parse source as.
const filename = "test.tsx"; const filename = 'test.tsx';
test(oxc.parseSync(filename, sourceText, options)); test(oxc.parseSync(filename, sourceText, options));
test(await oxc.parseAsync(filename, sourceText, options)); test(await oxc.parseAsync(filename, sourceText, options));