mirror of
https://github.com/danbulant/oxc
synced 2026-05-20 12:48:38 +00:00
feat(napi/parser): add .hasChanged() to MagicString (#8586)
This commit is contained in:
parent
1bef911e59
commit
ee8ee55cda
5 changed files with 11 additions and 4 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
|
@ -2935,9 +2935,9 @@ checksum = "d08889ec5408683408db66ad89e0e1f93dff55c73a4ccc71c427d5b277ee47e6"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "string_wizard"
|
name = "string_wizard"
|
||||||
version = "0.0.25"
|
version = "0.0.26"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6bb58bc508ea1c7f771111be7870d0c8079410c0fe7e026454c7baa7998cf2a5"
|
checksum = "baa2ddbd6b187e9467902cf1c0f90266969897659ec5e7cefb3433ff5ffcf97d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"oxc_index",
|
"oxc_index",
|
||||||
"oxc_sourcemap",
|
"oxc_sourcemap",
|
||||||
|
|
|
||||||
|
|
@ -191,7 +191,7 @@ sha1 = "0.10.6"
|
||||||
simdutf8 = { version = "0.1.5", features = ["aarch64_neon"] }
|
simdutf8 = { version = "0.1.5", features = ["aarch64_neon"] }
|
||||||
similar = "2.6.0"
|
similar = "2.6.0"
|
||||||
similar-asserts = "1.6.0"
|
similar-asserts = "1.6.0"
|
||||||
string_wizard = "0.0.25"
|
string_wizard = "0.0.26"
|
||||||
tempfile = "3.14.0"
|
tempfile = "3.14.0"
|
||||||
tokio = "1.42.0"
|
tokio = "1.42.0"
|
||||||
tower-lsp = "0.20.0"
|
tower-lsp = "0.20.0"
|
||||||
|
|
|
||||||
1
napi/parser/index.d.ts
vendored
1
napi/parser/index.d.ts
vendored
|
|
@ -11,6 +11,7 @@ export declare class MagicString {
|
||||||
getUtf16ByteOffset(offset: number): number
|
getUtf16ByteOffset(offset: number): number
|
||||||
length(): number
|
length(): number
|
||||||
toString(): string
|
toString(): string
|
||||||
|
hasChanged(): boolean
|
||||||
append(input: string): this
|
append(input: string): this
|
||||||
appendLeft(index: number, input: string): this
|
appendLeft(index: number, input: string): this
|
||||||
appendRight(index: number, input: string): this
|
appendRight(index: number, input: string): this
|
||||||
|
|
|
||||||
|
|
@ -122,6 +122,11 @@ impl MagicString {
|
||||||
self.cell.borrow_dependent().to_string()
|
self.cell.borrow_dependent().to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[napi]
|
||||||
|
pub fn has_changed(&self) -> bool {
|
||||||
|
self.cell.borrow_dependent().has_changed()
|
||||||
|
}
|
||||||
|
|
||||||
#[napi]
|
#[napi]
|
||||||
pub fn append(&mut self, input: String) -> &Self {
|
pub fn append(&mut self, input: String) -> &Self {
|
||||||
self.cell.with_dependent_mut(|_, ms| {
|
self.cell.with_dependent_mut(|_, ms| {
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,9 @@ describe('simple', () => {
|
||||||
expect(code.substring(ms.getUtf16ByteOffset(start), ms.getUtf16ByteOffset(end))).toEqual('测试');
|
expect(code.substring(ms.getUtf16ByteOffset(start), ms.getUtf16ByteOffset(end))).toEqual('测试');
|
||||||
|
|
||||||
// Magic string manipulation.
|
// Magic string manipulation.
|
||||||
|
expect(ms.hasChanged()).toBe(false);
|
||||||
ms.remove(start, end).append(';');
|
ms.remove(start, end).append(';');
|
||||||
|
expect(ms.hasChanged()).toBe(true);
|
||||||
expect(ms.toString()).toEqual('const s: String = /* 🤨 */ "";');
|
expect(ms.toString()).toEqual('const s: String = /* 🤨 */ "";');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -43,7 +45,6 @@ describe('simple', () => {
|
||||||
});
|
});
|
||||||
expect(map.toUrl()).toBeTypeOf('string');
|
expect(map.toUrl()).toBeTypeOf('string');
|
||||||
expect(map.toString()).toBeTypeOf('string');
|
expect(map.toString()).toBeTypeOf('string');
|
||||||
console.log(map.toMap());
|
|
||||||
expect(map.toMap()).toEqual({
|
expect(map.toMap()).toEqual({
|
||||||
mappings:
|
mappings:
|
||||||
'CAAA,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC',
|
'CAAA,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC',
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue