-
-
Notifications
You must be signed in to change notification settings - Fork 480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(napi/parser): introduce experimental MagicString
#7529
Conversation
Your org has enabled the Graphite merge queue for merging into mainAdd the label “0-merge” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge. Or use the label “hotfix” to add to the merge queue as a hot fix. You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link. |
5589f42
to
d143ef8
Compare
CodSpeed Performance ReportMerging #7529 will not alter performanceComparing Summary
|
I like this - having this would actually allow Vue's
|
I believe the API this PR provides is: const code = 'const s: String = "测试"';
const oxc = new ParserBuilder(code);
const {program} = oxc.parseSync({ sourceFilename: 'test.ts' });
const stringLiteral = program.body[0].declarations[0].init;
// Magic string manipulation
oxc.remove(stringLiteral.start + 1, stringLiteral.end - 1);
// Get altered code
const alteredCode = oxc.toString(); How about returning the magic string from const code = 'const s: String = "测试"';
const {program, magicString} = parseSync(code, { sourceFilename: 'test.ts', magicString: true });
const stringLiteral = program.body[0].declarations[0].init;
// Magic string manipulation
magicString.remove(stringLiteral.start + 1, stringLiteral.end - 1);
// Get altered code
const alteredCode = magicString.toString(); i.e. You choose whether you want a Builder patterns are quite rusty, but personally I think this is more idiomatic for a JS API. |
I can't make your suggestion work without cloning the string #[napi]
pub struct ParserBuilder {
cell: ParserBuilderImpl,
}
self_cell!(
struct ParserBuilderImpl {
owner: String,
#[covariant]
dependent: MagicString,
}
);
|
Ah OK. I don't know the internals. If we could make my suggestion work, would you prefer it as an API? |
d143ef8
to
763aebd
Compare
5ca3be0
to
8df1102
Compare
b37a69d
to
ecf7b65
Compare
MagicString
MagicString
Merge activity
|
Hold magic string instance on the Rust side for utf8 string manipulation.
3dca097
to
4bd3d10
Compare
Hold magic string instance on the Rust side for utf8 string manipulation.