Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions napi/transform/test/transform.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ describe('react refresh plugin', () => {

it('matches output', () => {
const ret = oxc.transform('test.tsx', code, { jsx: { refresh: {} } });
console.log(ret.code)
console.log(ret.code);
assert.equal(
ret.code,
`import { useState } from "react";
`import { useState } from "react";
import { jsxs as _jsxs } from "react/jsx-runtime";
var _s = $RefreshSig$();
export const App = () => {
Expand All @@ -53,7 +53,7 @@ _s(App, "oDgYfYHkD9Wkv4hrAPCkI/ev3YU=");
_c = App;
var _c;
$RefreshReg$(_c, "App");
`
`,
);
});
});
Expand Down
2 changes: 1 addition & 1 deletion tasks/ast_tools/src/output/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl Output {

let (path, code) = match self {
Self::Rust { path, tokens } => {
let code = print_rust(&tokens, &generator_path);
let code = print_rust(tokens, &generator_path);
(path, code)
}
Self::Javascript { path, code } => {
Expand Down
6 changes: 3 additions & 3 deletions tasks/ast_tools/src/output/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ use std::{
use lazy_static::lazy_static;
use proc_macro2::TokenStream;
use regex::{Captures, Regex, Replacer};
use syn::parse_file;
use syn::parse2;

use super::add_header;

/// Format Rust code, and add header.
pub fn print_rust(tokens: &TokenStream, generator_path: &str) -> String {
let code = prettyplease::unparse(&parse_file(tokens.to_string().as_str()).unwrap());
pub fn print_rust(tokens: TokenStream, generator_path: &str) -> String {
let code = prettyplease::unparse(&parse2(tokens).unwrap());
let code = COMMENT_REGEX.replace_all(&code, CommentReplacer).to_string();
let code = add_header(&code, generator_path, "//");
rust_fmt(&code)
Expand Down