Skip to content

Commit

Permalink
Add next-custom-transforms tests to verify source maps
Browse files Browse the repository at this point in the history
This allows us to quickly verify that the spans that are defined in the
SWC transforms yield correct source maps. The `output.js` and
`output.js.map` files can be used to visualize the source mapping, e.g.
at https://evanw.github.io/source-map-visualization/.

For now I'm adding a single fixture for `'use cache'` with this PR.
  • Loading branch information
unstubbable committed Jan 16, 2025
1 parent c6d3690 commit a1d9668
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
30 changes: 30 additions & 0 deletions crates/next-custom-transforms/tests/fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,36 @@ fn test_edge_assert(input: PathBuf) {
);
}

#[fixture("tests/fixture/source-maps/**/input.js")]
fn test_source_maps(input: PathBuf) {
let output = input.parent().unwrap().join("output.js");
test_fixture(
syntax(),
&|_tr| {
(
resolver(Mark::new(), Mark::new(), false),
server_actions(
&FileName::Real("/app/item.js".into()),
server_actions::Config {
is_react_server_layer: true,
dynamic_io_enabled: true,
hash_salt: "".into(),
cache_kinds: FxHashSet::from_iter([]),
},
_tr.comments.as_ref().clone(),
),
)
},
&input,
&output,
FixtureTestConfig {
module: Some(true),
sourcemap: true,
..Default::default()
},
);
}

fn lint_to_fold<R>(r: R) -> impl Pass
where
R: Visit,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use cache'

const foo = async () => {
'use cache'
}

export async function bar() {
return foo()
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a1d9668

Please sign in to comment.