Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit df0495f

Browse files
committed
fix(compiler): fix source type
1 parent c1a7053 commit df0495f

File tree

3 files changed

+19
-29
lines changed

3 files changed

+19
-29
lines changed

compiler/mod.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@ import { checksum } from './dist/wasm-checksum.js'
77
import init, { parseExportNamesSync, transformSync } from './dist/wasm-pack.js'
88

99
export enum SourceType {
10-
JS = 0,
11-
JSX = 1,
12-
TS = 2,
13-
TSX = 3,
14-
JSON = 4,
15-
WASM = 5,
16-
Unknown = 9,
10+
JS = 'js',
11+
JSX = 'jsx',
12+
TS = 'ts',
13+
TSX = 'tsx',
14+
Unknown = '??',
1715
}
1816

1917
export type ImportMap = {

compiler/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use swc::{EmitOptions, SWC};
2121
use swc_ecmascript::parser::JscTarget;
2222
use wasm_bindgen::prelude::{wasm_bindgen, JsValue};
2323

24-
#[derive(Clone, Debug, Default, Deserialize)]
24+
#[derive(Deserialize)]
2525
#[serde(deny_unknown_fields, rename_all = "camelCase")]
2626
pub struct Options {
2727
#[serde(default)]
@@ -52,7 +52,7 @@ pub struct Options {
5252
pub bundle_external: Vec<String>,
5353
}
5454

55-
#[derive(Clone, Debug, Deserialize)]
55+
#[derive(Deserialize)]
5656
#[serde(deny_unknown_fields, rename_all = "camelCase")]
5757
pub struct SWCOptions {
5858
#[serde(default)]
@@ -91,7 +91,7 @@ fn default_pragma_frag() -> String {
9191
"React.Fragment".into()
9292
}
9393

94-
#[derive(Debug, Serialize)]
94+
#[derive(Serialize)]
9595
#[serde(rename_all = "camelCase")]
9696
pub struct TransformOutput {
9797
pub code: String,

compiler/src/source_type.rs

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
use serde::Deserialize;
22
use std::path::{Path, PathBuf};
33

4-
#[repr(i32)]
5-
#[derive(Clone, Copy, Eq, PartialEq, Debug, Deserialize)]
4+
#[derive(Clone, Debug, Deserialize, Eq, PartialEq)]
65
pub enum SourceType {
7-
JS = 0,
8-
JSX = 1,
9-
TS = 2,
10-
TSX = 3,
11-
JSON = 4,
12-
WASM = 5,
13-
Unknown = 9,
6+
#[serde(rename = "js")]
7+
JS,
8+
#[serde(rename = "jsx")]
9+
JSX,
10+
#[serde(rename = "ts")]
11+
TS,
12+
#[serde(rename = "tsx")]
13+
TSX,
14+
#[serde(rename = "??")]
15+
Unknown,
1416
}
1517

1618
impl<'a> From<&'a Path> for SourceType {
@@ -47,8 +49,6 @@ impl SourceType {
4749
Some("mjs") => SourceType::JS,
4850
Some("js") => SourceType::JS,
4951
Some("jsx") => SourceType::JSX,
50-
Some("json") => SourceType::JSON,
51-
Some("wasm") => SourceType::WASM,
5252
_ => SourceType::Unknown,
5353
},
5454
}
@@ -66,14 +66,6 @@ mod tests {
6666
assert_eq!(SourceType::from(Path::new("/foo/bar.js")), SourceType::JS);
6767
assert_eq!(SourceType::from(Path::new("/foo/bar.mjs")), SourceType::JS);
6868
assert_eq!(SourceType::from(Path::new("/foo/bar.jsx")), SourceType::JSX);
69-
assert_eq!(
70-
SourceType::from(Path::new("/foo/bar.json")),
71-
SourceType::JSON
72-
);
73-
assert_eq!(
74-
SourceType::from(Path::new("/foo/bar.wasm")),
75-
SourceType::WASM
76-
);
7769
assert_eq!(
7870
SourceType::from(Path::new("/foo/bar.txt")),
7971
SourceType::Unknown

0 commit comments

Comments
 (0)