Skip to content

Commit de578c7

Browse files
swc version bump
1 parent 54cb7e4 commit de578c7

File tree

2 files changed

+29
-22
lines changed

2 files changed

+29
-22
lines changed

Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,26 @@
22
name = "typescript_utils"
33
version = "0.1.0"
44
authors = ["HiRoFa <info@hirofa.com>"]
5-
edition = "2018"
5+
edition = "2021"
66
description = "Typescript transpiler for GreenCopper"
77
license = "MIT"
88

99
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1010

1111
[dependencies]
12-
swc = "0.186.0"
12+
swc = "0.226"
1313
#swc = {path="../swc"}
1414
#swc = {git="https://github.com/HiRoFa/swc"}
1515
#swc = {git="https://github.com/swc-project/swc"}
1616
#swc_ecma_parser = {version = "0.57.1"}
1717
#swc_ecma_parser = {path="../swc/ecmascript/parser"}
18-
swc_ecma_parser = "0.105.0"
18+
swc_ecma_parser = "0.119"
1919
#swc_ecma_parser = {git="https://github.com/swc-project/swc"}
2020
#swc_common = {version="0.10.20", features=["tty-emitter"]}
2121
#swc_common = {path="../swc/common", features=["tty-emitter"]}
2222
#swc_common = {git="https://github.com/swc-project/swc", features=["tty-emitter"]}
23-
swc_common = {version = "0.18.8", features = ["tty-emitter"]}
24-
swc_ecma_minifier = "0.118.0"
23+
swc_common = {version = "0.28", features = ["tty-emitter"]}
24+
swc_ecma_minifier = "0.154"
2525
#hirofa_utils = {git = "https://github.com/HiRoFa/utils"}
2626
hirofa_utils = "0.5"
2727
#hirofa_utils = {path = "../utils"}

src/lib.rs

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use hirofa_utils::js_utils::{JsError, Script, ScriptPreProcessor};
22
use std::sync::Arc;
33
use swc::{Compiler};
44

5-
use swc::config::{ IsModule};
65
use swc_common::errors::{ColorConfig, Handler};
76
use swc_common::{FileName, SourceMap};
87

@@ -64,19 +63,19 @@ impl TypeScriptPreProcessor {
6463
.new_source_file(FileName::Custom(file_name.into()), code.into());
6564

6665
let minify_options = if self.minify {
67-
r#"
68-
"minify": {
69-
"compress": {
70-
"unused": true
71-
},
66+
format!(r#"
67+
"minify": {{
68+
"compress": {{
69+
"unused": {}
70+
}},
7271
"mangle": true
73-
},
74-
"#
72+
}},
73+
"#, is_module)
7574
} else {
76-
""
75+
"".to_string()
7776
};
7877

79-
let module = r#"
78+
let module = if is_module { r#"
8079
"module": {
8180
"type": "es6",
8281
"strict": true,
@@ -85,7 +84,10 @@ impl TypeScriptPreProcessor {
8584
"noInterop": false,
8685
"ignoreDynamic": true
8786
},
88-
"#;
87+
"#
88+
} else {
89+
""
90+
};
8991

9092
let cfg_json = format!(r#"
9193
@@ -105,7 +107,7 @@ impl TypeScriptPreProcessor {
105107
"legacyDecorator": true,
106108
"decoratorMetadata": true,
107109
"react": {{
108-
"runtime": "automatic",
110+
"runtime": "classic",
109111
"useBuiltins": true,
110112
"refresh": true
111113
}}
@@ -124,7 +126,6 @@ impl TypeScriptPreProcessor {
124126

125127
let ops = swc::config::Options {
126128
config: cfg,
127-
is_module: IsModule::Bool(is_module),
128129
..Default::default()
129130
};
130131

@@ -194,7 +195,7 @@ pub mod tests {
194195
.js_script_pre_processor(TypeScriptPreProcessor::new(
195196
TargetVersion::Es2020,
196197
false,
197-
false,
198+
true,
198199
))
199200
.build();
200201

@@ -215,19 +216,22 @@ pub mod tests {
215216

216217
#[test]
217218
fn test_mts() {
218-
let pp = TypeScriptPreProcessor::new(TargetVersion::Es2020, true, false);
219+
220+
log_to_stderr(LevelFilter::Trace);
221+
222+
let pp = TypeScriptPreProcessor::new(TargetVersion::Es2020, true, true);
219223
let inputs = vec![
220224
Script::new(
221225
"export_class_test.ts",
222226
"function functWithLongName(abc) {return abc + 1;};export class /* hi */ MyClass {name: string; sum: number; constructor(name) {this.name = name; this.sum = functWithLongName(1);} getIt() {return (this.name + ' is gotten');}}",
223227
),
224228
Script::new(
225229
"import_test.ts",
226-
"import {MyClass} from 'export_class_test.ts'; \n{let b: Number = MyClass.quibus;}\n export function q(val: Number) {let mc = new MyClass(); return mc.sum;};",
230+
"import {MyClass} from 'export_class_test.ts'; \n{let b: Number = MyClass.quibus;}\n export function q(val: Number) {let mc = new MyClass(); return mc.sum + mc.getIt();};",
227231
),
228232
Script::new(
229233
"not_a_module.ts",
230-
"async function test() {let m = await import('texport_class_test.ts'); let mc = new m.MyClass(); console.log(m.getIt());}",
234+
"async function test() {let m = await import('export_class_test.ts'); let mc = new m.MyClass(); console.log(m.getIt());}",
231235
),
232236

233237
Script::new(
@@ -240,6 +244,9 @@ pub mod tests {
240244
render(): void {
241245
return <Button color="red" />;
242246
}
247+
render2(): void {
248+
return <div />;
249+
}
243250
}
244251
245252
export default DangerButton;

0 commit comments

Comments
 (0)