-
-
Notifications
You must be signed in to change notification settings - Fork 483
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
206 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
use napi_derive::napi; | ||
|
||
#[napi] | ||
pub struct MagicString; // (string_wizard::MagicString<'static>); | ||
|
||
impl MagicString { | ||
pub fn new(_s: String) -> Self { | ||
Self //(string_wizard::MagicString::new(s)) | ||
} | ||
} | ||
|
||
#[napi(object)] | ||
pub struct OverwriteOptions { | ||
pub content_only: bool, | ||
} | ||
|
||
#[napi] | ||
impl MagicString { | ||
#[napi] | ||
pub fn length(&self) -> u32 { | ||
// self.0.len() as u32 | ||
unimplemented!() | ||
} | ||
|
||
#[napi] | ||
#[allow(clippy::inherent_to_string)] | ||
pub fn to_string(&self) -> String { | ||
// self.0.to_string() | ||
unimplemented!() | ||
} | ||
|
||
#[napi] | ||
pub fn append(&mut self, _input: String) -> &Self { | ||
// self.0.append(input); | ||
// self | ||
unimplemented!() | ||
} | ||
|
||
#[napi] | ||
pub fn prepend(&mut self, _input: String) -> &Self { | ||
// self.0.prepend(input); | ||
// self | ||
unimplemented!() | ||
} | ||
|
||
#[napi] | ||
pub fn append_left(&mut self, _index: u32, _input: String) -> &Self { | ||
// self.0.append_left(index as usize, input); | ||
// self | ||
unimplemented!() | ||
} | ||
|
||
#[napi] | ||
pub fn append_right(&mut self, _index: u32, _input: String) -> &Self { | ||
// self.0.append_right(index as usize, input); | ||
// self | ||
unimplemented!() | ||
} | ||
|
||
#[napi] | ||
pub fn prepend_left(&mut self, _index: u32, _input: String) -> &Self { | ||
// self.0.prepend_left(index as usize, input); | ||
// self | ||
unimplemented!() | ||
} | ||
|
||
#[napi] | ||
pub fn prepend_right(&mut self, _index: u32, _input: String) -> &Self { | ||
// self.0.prepend_right(index as usize, input); | ||
// self | ||
unimplemented!() | ||
} | ||
|
||
// #[napi] | ||
// pub fn overwrite( | ||
// &mut self, | ||
// start: i64, | ||
// end: i64, | ||
// content: String, | ||
// options: OverwriteOptions, | ||
// ) -> &Self { | ||
// self.0.overwrite(start, end, content, options); | ||
// self | ||
// } | ||
|
||
// #[napi] | ||
// pub fn trim(&mut self, pattern: Option<String>) -> &Self { | ||
// self.0.trim(pattern.as_deref()); | ||
// self | ||
// } | ||
|
||
// #[napi] | ||
// pub fn trim_start(&mut self, pattern: Option<String>) -> &Self { | ||
// self.0.trim_start(pattern.as_deref()); | ||
// self | ||
// } | ||
|
||
// #[napi] | ||
// pub fn trim_end(&mut self, pattern: Option<String>) -> &Self { | ||
// self.0.trim_end(pattern.as_deref()); | ||
// self | ||
// } | ||
|
||
// #[napi] | ||
// pub fn trim_lines(&mut self) -> &Self { | ||
// self.0.trim_lines(); | ||
// self | ||
// } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { assert, describe, it } from 'vitest'; | ||
|
||
import type { StringLiteral, VariableDeclaration } from '../index.js'; | ||
import { parseSync } from '../index.js'; | ||
|
||
describe('simple', () => { | ||
const code = 'const s: String = "测试"'; | ||
|
||
it('calls magic string APIs', () => { | ||
// `oxc` holds a magic string instance on the Rust side. | ||
const { program, magicString } = parseSync('test.ts', code); | ||
const declaration = ast.body[0] as VariableDeclaration; | ||
const stringLiteral = declaration.declarations[0].init as StringLiteral; | ||
|
||
// These spans are in utf8 offsets. | ||
const start = stringLiteral.start + 1; | ||
const end = stringLiteral.end - 1; | ||
|
||
// Access source text by utf8 offset. | ||
assert.equal(oxc.sourceText(start, end), '测试'); | ||
|
||
// Magic string manipulation. | ||
oxc.remove(start, end); | ||
assert.equal(oxc.toString(), 'const s: String = ""'); | ||
}); | ||
}); |