diff --git a/Cargo.lock b/Cargo.lock index 83ccc170673974..4ad204d17c0d4f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2935,9 +2935,9 @@ checksum = "d08889ec5408683408db66ad89e0e1f93dff55c73a4ccc71c427d5b277ee47e6" [[package]] name = "string_wizard" -version = "0.0.25" +version = "0.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6bb58bc508ea1c7f771111be7870d0c8079410c0fe7e026454c7baa7998cf2a5" +checksum = "baa2ddbd6b187e9467902cf1c0f90266969897659ec5e7cefb3433ff5ffcf97d" dependencies = [ "oxc_index", "oxc_sourcemap", diff --git a/Cargo.toml b/Cargo.toml index 39152cbab27ae6..8c1152de4f39f9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -191,7 +191,7 @@ sha1 = "0.10.6" simdutf8 = { version = "0.1.5", features = ["aarch64_neon"] } similar = "2.6.0" similar-asserts = "1.6.0" -string_wizard = "0.0.25" +string_wizard = "0.0.26" tempfile = "3.14.0" tokio = "1.42.0" tower-lsp = "0.20.0" diff --git a/napi/parser/index.d.ts b/napi/parser/index.d.ts index 0961371b7ad4a7..3cb4ccc4e7913d 100644 --- a/napi/parser/index.d.ts +++ b/napi/parser/index.d.ts @@ -11,6 +11,7 @@ export declare class MagicString { getUtf16ByteOffset(offset: number): number length(): number toString(): string + hasChanged(): boolean append(input: string): this appendLeft(index: number, input: string): this appendRight(index: number, input: string): this diff --git a/napi/parser/src/magic_string.rs b/napi/parser/src/magic_string.rs index e727fb4669efbd..8470fc8d42569a 100644 --- a/napi/parser/src/magic_string.rs +++ b/napi/parser/src/magic_string.rs @@ -122,6 +122,11 @@ impl MagicString { self.cell.borrow_dependent().to_string() } + #[napi] + pub fn has_changed(&self) -> bool { + self.cell.borrow_dependent().has_changed() + } + #[napi] pub fn append(&mut self, input: String) -> &Self { self.cell.with_dependent_mut(|_, ms| { diff --git a/napi/parser/test/magic_string.test.ts b/napi/parser/test/magic_string.test.ts index 23a4e4a8b110b3..dd60ef31900c44 100644 --- a/napi/parser/test/magic_string.test.ts +++ b/napi/parser/test/magic_string.test.ts @@ -29,7 +29,9 @@ describe('simple', () => { expect(code.substring(ms.getUtf16ByteOffset(start), ms.getUtf16ByteOffset(end))).toEqual('测试'); // Magic string manipulation. + expect(ms.hasChanged()).toBe(false); ms.remove(start, end).append(';'); + expect(ms.hasChanged()).toBe(true); expect(ms.toString()).toEqual('const s: String = /* 🤨 */ "";'); }); @@ -43,7 +45,6 @@ describe('simple', () => { }); expect(map.toUrl()).toBeTypeOf('string'); expect(map.toString()).toBeTypeOf('string'); - console.log(map.toMap()); expect(map.toMap()).toEqual({ 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',