Skip to content
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(es/codegen): Introduce SpanWriter and adjust_span #10261

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

kdy1
Copy link
Member

@kdy1 kdy1 commented Mar 24, 2025

Description:

We can expand

#[node_impl]
impl MacroNode for Program {
    fn emit(&mut self, emitter: &mut Macro) {
        match self {
            Program::Module(m) => emit!(m),
            Program::Script(s) => emit!(s),
        }
    }
}

to

impl crate::Node for Macro {
    fn emit_with<W, S>(&self, e: &mut crate::Emitter<'_, W, S>) -> Result
    where
        W: crate::text_writer::WriteJs,
        S: swc_common::SourceMapper + swc_ecma_ast::SourceMapperExt,
    {
        {
            match self {
                Program::Module(m) => Node::emit_with(&m, emitter),
                Program::Script(s) => Node::emit_with(&s, emitter),
            }
        }
    }

    fn adjust_span<W, S>(&mut self, wr: &mut crate::SpanWriter<'_, W, S>) -> Result
    where
        W: crate::text_writer::SpannedWriteJs,
        S: swc_common::SourceMapper + swc_ecma_ast::SourceMapperExt,
    {
        {
            match self {
                Program::Module(m) => Node::adjust_span(&mut m, emitter),
                Program::Script(s) => Node::adjust_span(&mut s, emitter),
            }
        }
    }
}

Related issue:

@kdy1 kdy1 added this to the Planned milestone Mar 24, 2025
@kdy1 kdy1 self-assigned this Mar 24, 2025
Copy link

changeset-bot bot commented Mar 24, 2025

⚠️ No Changeset found

Latest commit: 82e2286

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

codspeed-hq bot commented Mar 24, 2025

CodSpeed Performance Report

Merging #10261 will not alter performance

Comparing kdy1/rspack-codegen (82e2286) with main (c480604)

Summary

✅ 2 untouched benchmarks
⁉️ 150 dropped benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Change
⁉️ css/visitor/compare/clone 5.1 ms N/A N/A
⁉️ css/visitor/compare/fold_span 6 ms N/A N/A
⁉️ css/visitor/compare/fold_span_panic 6 ms N/A N/A
⁉️ css/visitor/compare/visit_mut_span 5.4 ms N/A N/A
⁉️ css/visitor/compare/visit_mut_span_panic 5.4 ms N/A N/A
⁉️ css/lexer/bootstrap_5_1_3 10.3 ms N/A N/A
⁉️ css/lexer/foundation_6_7_4 8.3 ms N/A N/A
⁉️ css/lexer/tailwind_3_1_1 1.6 ms N/A N/A
⁉️ css/parser/bootstrap_5_1_3 47.5 ms N/A N/A
⁉️ css/parser/foundation_6_7_4 37.6 ms N/A N/A
⁉️ css/parser/tailwind_3_1_1 7.3 ms N/A N/A
⁉️ es/codegen/colors 69.5 µs N/A N/A
⁉️ es/codegen/large 658.8 µs N/A N/A
⁉️ es/codegen/with-parser/colors 196.4 µs N/A N/A
⁉️ es/codegen/with-parser/large 1.5 ms N/A N/A
⁉️ es/fast-lexer/angular 9.2 ms N/A N/A
⁉️ es/fast-lexer/backbone 1.2 ms N/A N/A
⁉️ es/fast-lexer/jquery 6.1 ms N/A N/A
⁉️ es/fast-lexer/jquery mobile 10 ms N/A N/A
⁉️ es/fast-lexer/mootools 4.9 ms N/A N/A
... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

@kdy1 kdy1 force-pushed the kdy1/rspack-codegen branch from 885db11 to dbf1a7e Compare March 31, 2025 05:31
@kdy1 kdy1 changed the base branch from main to graphite-base/10261 March 31, 2025 07:27
@kdy1 kdy1 force-pushed the kdy1/rspack-codegen branch from dbf1a7e to 9c0c377 Compare March 31, 2025 07:27
@kdy1 kdy1 changed the base branch from graphite-base/10261 to kdy1/codegen-macro-node March 31, 2025 07:27
Copy link
Member Author

kdy1 commented Mar 31, 2025

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@kdy1 kdy1 force-pushed the kdy1/codegen-macro-node branch from 8168f76 to 7c62df5 Compare April 1, 2025 10:19
@kdy1 kdy1 force-pushed the kdy1/rspack-codegen branch from 9c0c377 to 1bbee29 Compare April 1, 2025 10:19
@kdy1 kdy1 force-pushed the kdy1/rspack-codegen branch from 1bbee29 to 85daaee Compare April 2, 2025 01:56
@kdy1 kdy1 force-pushed the kdy1/codegen-macro-node branch 2 times, most recently from 3c94998 to e7492ce Compare April 2, 2025 08:06
@kdy1 kdy1 force-pushed the kdy1/rspack-codegen branch from 85daaee to af7a437 Compare April 2, 2025 08:06
Base automatically changed from kdy1/codegen-macro-node to main April 3, 2025 06:27
@kdy1 kdy1 force-pushed the kdy1/rspack-codegen branch from af7a437 to b4da2b9 Compare April 3, 2025 07:26
@kdy1 kdy1 force-pushed the kdy1/rspack-codegen branch from b4da2b9 to a53f43c Compare April 7, 2025 03:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

rspack: ES codegen that modifies span to emulate codegen + reparse
1 participant