Skip to content

Commit

Permalink
Merge branch 'main' into regression
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 authored Aug 9, 2024
2 parents f9a8f45 + 10d99e5 commit f748c2e
Show file tree
Hide file tree
Showing 132 changed files with 1,621 additions and 55 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@

- **(es/typescript)** Enable Injector to process JSX ([#9395](https://github.com/swc-project/swc/issues/9395)) ([e24e2ff](https://github.com/swc-project/swc/commit/e24e2ffe5971d2d1ef667c910a12b94ca41f1b52))


- **(es/typescript)** Strip declaration of exported function overloads ([#9397](https://github.com/swc-project/swc/issues/9397)) ([5c8aa52](https://github.com/swc-project/swc/commit/5c8aa522da205fc7fab156cb9d44c8acca872523))

### Features


Expand Down
16 changes: 8 additions & 8 deletions Cargo.lock

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

20 changes: 10 additions & 10 deletions bindings/Cargo.lock

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

2 changes: 1 addition & 1 deletion bindings/binding_core_wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ license = "Apache-2.0"
name = "binding_core_wasm"
publish = false
repository = "https://github.com/swc-project/swc.git"
version = "1.7.8-nightly-20240807.2"
version = "1.7.8-nightly-20240808.1"

[lib]
bench = false
Expand Down
2 changes: 1 addition & 1 deletion bindings/binding_minifier_wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ license = "Apache-2.0"
name = "binding_minifier_wasm"
publish = false
repository = "https://github.com/swc-project/swc.git"
version = "1.7.8-nightly-20240807.2"
version = "1.7.8-nightly-20240808.1"

[lib]
bench = false
Expand Down
2 changes: 1 addition & 1 deletion bindings/binding_typescript_wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ license = "Apache-2.0"
name = "binding_typescript_wasm"
publish = false
repository = "https://github.com/swc-project/swc.git"
version = "1.7.8-nightly-20240807.2"
version = "1.7.8-nightly-20240808.1"

[lib]
bench = false
Expand Down
2 changes: 1 addition & 1 deletion bindings/swc_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ include = ["Cargo.toml", "src/**/*.rs"]
license = "Apache-2.0"
name = "swc_cli"
repository = "https://github.com/swc-project/swc.git"
version = "0.91.358"
version = "0.91.359"

[[bin]]
bench = false
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"
license = "Apache-2.0"
name = "swc_core"
repository = "https://github.com/swc-project/swc.git"
version = "0.100.2"
version = "0.100.3"
[package.metadata.docs.rs]
features = [
"allocator_node",
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_fast_ts_strip/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ include = ["Cargo.toml", "src/**/*.rs"]
license = "Apache-2.0"
name = "swc_fast_ts_strip"
repository = { workspace = true }
version = "0.5.0"
version = "0.5.1"


[dependencies]
Expand Down
11 changes: 3 additions & 8 deletions crates/swc_fast_ts_strip/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,14 +655,6 @@ impl Visit for TsStrip {
n.visit_children_with(self);
}

fn visit_fn_decl(&mut self, n: &FnDecl) {
if n.function.body.is_none() {
self.add_replacement(n.function.span);
return;
}
n.visit_children_with(self);
}

fn visit_import_decl(&mut self, n: &ImportDecl) {
if n.type_only {
self.add_replacement(n.span);
Expand Down Expand Up @@ -955,6 +947,9 @@ impl IsTsDecl for Decl {
Self::Var(ref var) => var.declare,
Self::Fn(FnDecl { declare: true, .. })
| Self::Class(ClassDecl { declare: true, .. }) => true,

Self::Fn(FnDecl { function, .. }) => function.body.is_none(),

_ => false,
}
}
Expand Down
104 changes: 103 additions & 1 deletion crates/swc_fast_ts_strip/tests/fixture.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use std::path::PathBuf;

use swc_ecma_parser::TsSyntax;
use swc_common::{
comments::SingleThreadedComments, errors::Handler, sync::Lrc, FileName, SourceMap,
};
use swc_ecma_ast::EsVersion;
use swc_ecma_parser::{lexer::Lexer, Capturing, EsSyntax, Parser, StringInput, Syntax, TsSyntax};
use swc_fast_ts_strip::{operate, Mode, Options};
use testing::NormalizedOutput;

Expand Down Expand Up @@ -43,6 +47,55 @@ fn test(input: PathBuf) {
.expect("should not fail");
}

#[testing::fixture("../swc_ecma_parser/tests/tsc/**/*.ts")]
fn verify(input: PathBuf) {
let input_code = std::fs::read_to_string(&input).unwrap();

let output = PathBuf::from(
input
.to_string_lossy()
.replace("swc_ecma_parser", "swc_fast_ts_strip"),
);

let output_file = output.with_extension("strip.js");
let output_stderr = output.with_extension("strip.broken");

let err = testing::run_test(false, |cm, handler| {
let code = match operate(&cm, handler, input_code.clone(), opts(Mode::StripOnly)) {
Ok(v) => v.code,
Err(..) => {
// Skip if the input is invalid
return Ok(());
}
};

if handler.has_errors() {
// Skip if the input is invalid

return Ok(());
}

reparse(&cm, handler, &output_file, code.clone());

if handler.has_errors() {
NormalizedOutput::new_raw(code)
.compare_to_file(&output_file)
.unwrap();

return Err(());
}

Ok(())
});

if let Err(err) = err {
err.compare_to_file(output_stderr).unwrap();
} else {
let _ = std::fs::remove_file(&output_file);
let _ = std::fs::remove_file(&output_stderr);
}
}

#[testing::fixture("tests/errors/**/*.ts")]
fn error(input: PathBuf) {
let input_code = std::fs::read_to_string(&input).unwrap();
Expand Down Expand Up @@ -70,3 +123,52 @@ fn opts(mode: Mode) -> Options {
..Default::default()
}
}

fn reparse(cm: &Lrc<SourceMap>, handler: &Handler, filename: &PathBuf, input: String) {
let filename = FileName::Real(filename.into());

let fm = cm.new_source_file(filename.into(), input);

let syntax = Syntax::Es(EsSyntax {
auto_accessors: true,
decorators: true,
decorators_before_export: true,
explicit_resource_management: true,
import_attributes: true,
..Default::default()
});
let target = EsVersion::latest();

let comments = SingleThreadedComments::default();

let lexer = Capturing::new(Lexer::new(
syntax,
target,
StringInput::from(&*fm),
Some(&comments),
));

let mut parser = Parser::new_from(lexer);

let program = parser.parse_program();
let errors = parser.take_errors();

match program {
Ok(program) => program,
Err(err) => {
err.into_diagnostic(handler).emit();

for e in errors {
e.into_diagnostic(handler).emit();
}

return;
}
};

if !errors.is_empty() {
for e in errors {
e.into_diagnostic(handler).emit();
}
}
}
1 change: 1 addition & 0 deletions crates/swc_fast_ts_strip/tests/fixture/issue-9396.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { };
1 change: 1 addition & 0 deletions crates/swc_fast_ts_strip/tests/fixture/issue-9396.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function f();
7 changes: 7 additions & 0 deletions crates/swc_fast_ts_strip/tests/tsc/Protected3.strip.broken
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
x Unexpected token `constructor`. Expected * for generator, private key, identifier or async
,-[$DIR/tests/tsc/Protected3.strip.js:2:1]
1 | class C {
2 | protected constructor() { }
: ^^^^^^^^^^^
3 | }
`----
3 changes: 3 additions & 0 deletions crates/swc_fast_ts_strip/tests/tsc/Protected3.strip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class C {
protected constructor() { }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
x Unexpected token `constructor`. Expected * for generator, private key, identifier or async
,-[$DIR/tests/tsc/accessorsOverrideProperty9.strip.js:31:1]
30 | class MixedClass extends baseClass {
31 | public constructor(...args ) {
: ^^^^^^^^^^^
32 | super(...args);
`----
Loading

0 comments on commit f748c2e

Please sign in to comment.