From 5709bc2205e17540d55d459cd2208a3110e073c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Fri, 10 Jan 2025 12:02:51 +0900 Subject: [PATCH] feat(ts/fast-strip): Distinguish invalid vs unsupported (#9846) **Description:** I tried adding a property to the error thrown, but `wasm_bindgen` does not support adding a property to an error nor creating different kinds of errors. So, I throw an object with `code` and `message` instead. --- .changeset/metal-penguins-travel.md | 6 + bindings/binding_minifier_node/src/minify.rs | 6 +- .../__tests__/__snapshots__/transform.js.snap | 54 ++++- .../__tests__/transform.js | 19 ++ bindings/binding_typescript_wasm/src/lib.rs | 21 +- crates/swc_fast_ts_strip/benches/assets.rs | 5 +- crates/swc_fast_ts_strip/src/lib.rs | 141 +++++++++---- .../tests/errors/export-equals.swc-stderr | 6 + .../tests/errors/export-equals.ts | 2 + .../tests/errors/import-equals.swc-stderr | 5 + .../tests/errors/import-equals.ts | 1 + .../errors/parameter-property.swc-stderr | 14 ++ .../tests/errors/parameter-property.ts | 11 + .../tests/errors/ts-module.swc-stderr | 7 + .../tests/errors/ts-module.ts | 5 + .../tests/errors/ts-namespace.swc-stderr | 7 + .../tests/errors/ts-namespace.ts | 5 + .../tests/errors/type-assertions.swc-stderr | 6 + .../tests/errors/type-assertions.ts | 3 + crates/swc_fast_ts_strip/tests/fixture.rs | 14 +- .../tests/fixture/class-properties.js | 6 - .../tests/fixture/test-case-1.js | 198 ------------------ .../tests/fixture/unicode.js | 7 - 23 files changed, 281 insertions(+), 268 deletions(-) create mode 100644 .changeset/metal-penguins-travel.md create mode 100644 crates/swc_fast_ts_strip/tests/errors/export-equals.swc-stderr create mode 100644 crates/swc_fast_ts_strip/tests/errors/export-equals.ts create mode 100644 crates/swc_fast_ts_strip/tests/errors/import-equals.swc-stderr create mode 100644 crates/swc_fast_ts_strip/tests/errors/import-equals.ts create mode 100644 crates/swc_fast_ts_strip/tests/errors/parameter-property.swc-stderr create mode 100644 crates/swc_fast_ts_strip/tests/errors/parameter-property.ts create mode 100644 crates/swc_fast_ts_strip/tests/errors/ts-module.swc-stderr create mode 100644 crates/swc_fast_ts_strip/tests/errors/ts-module.ts create mode 100644 crates/swc_fast_ts_strip/tests/errors/ts-namespace.swc-stderr create mode 100644 crates/swc_fast_ts_strip/tests/errors/ts-namespace.ts create mode 100644 crates/swc_fast_ts_strip/tests/errors/type-assertions.swc-stderr create mode 100644 crates/swc_fast_ts_strip/tests/errors/type-assertions.ts delete mode 100644 crates/swc_fast_ts_strip/tests/fixture/class-properties.js delete mode 100644 crates/swc_fast_ts_strip/tests/fixture/test-case-1.js delete mode 100644 crates/swc_fast_ts_strip/tests/fixture/unicode.js diff --git a/.changeset/metal-penguins-travel.md b/.changeset/metal-penguins-travel.md new file mode 100644 index 000000000000..00c9f45b9a6a --- /dev/null +++ b/.changeset/metal-penguins-travel.md @@ -0,0 +1,6 @@ +--- +swc_core: minor +swc_fast_ts_strip: minor +--- + +feat(ts/fast-strip): Distinguish invalid vs unsupported diff --git a/bindings/binding_minifier_node/src/minify.rs b/bindings/binding_minifier_node/src/minify.rs index 7cb2181bbdbe..4bac8d46e51f 100644 --- a/bindings/binding_minifier_node/src/minify.rs +++ b/bindings/binding_minifier_node/src/minify.rs @@ -212,7 +212,11 @@ fn do_work( .clone() .into_inner() .unwrap_or(BoolOr::Data(JsMinifyCommentOption::PreserveSomeComments)); - minify_file_comments(&comments, preserve_comments); + minify_file_comments( + &comments, + preserve_comments, + options.format.preserve_annotations, + ); swc_compiler_base::print( cm.clone(), diff --git a/bindings/binding_typescript_wasm/__tests__/__snapshots__/transform.js.snap b/bindings/binding_typescript_wasm/__tests__/__snapshots__/transform.js.snap index 23cb962051ca..e6903c8993c9 100644 --- a/bindings/binding_typescript_wasm/__tests__/__snapshots__/transform.js.snap +++ b/bindings/binding_typescript_wasm/__tests__/__snapshots__/transform.js.snap @@ -1,12 +1,15 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`transform in strip-only mode should not emit 'Caused by: failed to parse' 1`] = ` -" x await isn't allowed in non-async function +{ + "code": "InvalidSyntax", + "message": " x await isn't allowed in non-async function ,---- 1 | function foo() { await Promise.resolve(1); } : ^^^^^^^ \`---- -" +", +} `; exports[`transform in strip-only mode should remove declare enum 1`] = ` @@ -35,6 +38,32 @@ exports[`transform in strip-only mode should remove declare enum 3`] = ` } `; +exports[`transform in strip-only mode should report correct error for syntax error 1`] = ` +{ + "code": "InvalidSyntax", + "message": " x Expected ';', '}' or + ,---- + 1 | function foo() { invalid syntax } + : ^^^|^^^ ^^^^^^ + : \`-- This is the expression part of an expression statement + \`---- +", +} +`; + +exports[`transform in strip-only mode should report correct error for unsupported syntax 1`] = ` +{ + "code": "UnsupportedSyntax", + "message": " x TypeScript enum is not supported in strip-only mode + ,-[1:1] + 1 | ,-> enum Foo { + 2 | | a, b + 3 | \`-> } + \`---- +", +} +`; + exports[`transform in strip-only mode should strip complex expressions 1`] = ` { "code": "const foo = { @@ -89,30 +118,39 @@ exports[`transform in strip-only mode should strip type declarations 1`] = ` `; exports[`transform in strip-only mode should throw an error when it encounters a module 1`] = ` -" x TypeScript namespace declaration is not supported in strip-only mode +{ + "code": "UnsupportedSyntax", + "message": " x TypeScript namespace declaration is not supported in strip-only mode ,---- 1 | module foo {} : ^^^^^^^^^^^^^ \`---- -" +", +} `; exports[`transform in strip-only mode should throw an error when it encounters a namespace 1`] = ` -" x TypeScript namespace declaration is not supported in strip-only mode +{ + "code": "UnsupportedSyntax", + "message": " x TypeScript namespace declaration is not supported in strip-only mode ,---- 1 | namespace Foo {} : ^^^^^^^^^^^^^^^^ \`---- -" +", +} `; exports[`transform in strip-only mode should throw an error when it encounters an enum 1`] = ` -" x TypeScript enum is not supported in strip-only mode +{ + "code": "UnsupportedSyntax", + "message": " x TypeScript enum is not supported in strip-only mode ,---- 1 | enum Foo {} : ^^^^^^^^^^^ \`---- -" +", +} `; exports[`transform should strip types 1`] = ` diff --git a/bindings/binding_typescript_wasm/__tests__/transform.js b/bindings/binding_typescript_wasm/__tests__/transform.js index 8a1e491db566..dbaed85e381c 100644 --- a/bindings/binding_typescript_wasm/__tests__/transform.js +++ b/bindings/binding_typescript_wasm/__tests__/transform.js @@ -138,5 +138,24 @@ describe("transform", () => { }) ).rejects.toMatchSnapshot(); }); + + + it("should report correct error for syntax error", async () => { + await expect( + swc.transform("function foo() { invalid syntax }", { + mode: "strip-only", + }) + ).rejects.toMatchSnapshot(); + }); + + it("should report correct error for unsupported syntax", async () => { + await expect( + swc.transform(`enum Foo { + a, b + }`, { + mode: "strip-only", + }) + ).rejects.toMatchSnapshot(); + }); }); }); diff --git a/bindings/binding_typescript_wasm/src/lib.rs b/bindings/binding_typescript_wasm/src/lib.rs index 13c751adc6e3..3eb1be2e1033 100644 --- a/bindings/binding_typescript_wasm/src/lib.rs +++ b/bindings/binding_typescript_wasm/src/lib.rs @@ -1,7 +1,8 @@ use anyhow::Error; +use serde::Serialize; use swc_common::{errors::ColorConfig, sync::Lrc, SourceMap, GLOBALS}; use swc_error_reporters::handler::{try_with_handler, HandlerOpts}; -use swc_fast_ts_strip::{Options, TransformOutput}; +use swc_fast_ts_strip::{ErrorCode, Options, TransformOutput, TsError}; use wasm_bindgen::prelude::*; use wasm_bindgen_futures::{ future_to_promise, @@ -48,10 +49,26 @@ fn operate(input: String, options: Options) -> Result { color: ColorConfig::Never, skip_filename: true, }, - |handler| swc_fast_ts_strip::operate(&cm, handler, input, options), + |handler| { + swc_fast_ts_strip::operate(&cm, handler, input, options).map_err(anyhow::Error::new) + }, ) } +#[derive(Debug, Serialize)] +struct ErrorObject { + code: ErrorCode, + message: String, +} + pub fn convert_err(err: Error) -> wasm_bindgen::prelude::JsValue { + if let Some(ts_error) = err.downcast_ref::() { + return serde_wasm_bindgen::to_value(&ErrorObject { + code: ts_error.code, + message: err.to_string(), + }) + .unwrap(); + } + format!("{}", err).into() } diff --git a/crates/swc_fast_ts_strip/benches/assets.rs b/crates/swc_fast_ts_strip/benches/assets.rs index 789e91b0856f..45f0e1d12e9e 100644 --- a/crates/swc_fast_ts_strip/benches/assets.rs +++ b/crates/swc_fast_ts_strip/benches/assets.rs @@ -9,15 +9,14 @@ fn fast_ts(c: &mut Criterion) { fn fast_typescript(b: &mut Bencher) { b.iter(|| { ::testing::run_test(false, |cm, handler| { - black_box(operate( + let _result = black_box(operate( &cm, handler, black_box(SOURCE.to_string()), Options { ..Default::default() }, - )) - .unwrap(); + )); Ok(()) }) diff --git a/crates/swc_fast_ts_strip/src/lib.rs b/crates/swc_fast_ts_strip/src/lib.rs index 3ffe10527e61..7c2f37aa3e50 100644 --- a/crates/swc_fast_ts_strip/src/lib.rs +++ b/crates/swc_fast_ts_strip/src/lib.rs @@ -1,6 +1,6 @@ -use std::{cell::RefCell, rc::Rc}; +use std::{cell::RefCell, fmt::Display, rc::Rc}; -use anyhow::{Context, Error}; +use anyhow::Context; use serde::{Deserialize, Serialize}; use swc_allocator::maybe::vec::Vec; use swc_common::{ @@ -134,12 +134,53 @@ interface TransformOutput { } "#; +#[derive(Debug, Serialize)] +pub struct TsError { + pub message: String, + pub code: ErrorCode, +} + +impl std::fmt::Display for TsError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "[{}] {}", self.code, self.message) + } +} + +impl std::error::Error for TsError { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + None + } +} + +#[non_exhaustive] +#[derive(Debug, Clone, Copy, Serialize)] +pub enum ErrorCode { + InvalidSyntax, + UnsupportedSyntax, + Unknown, +} + +impl Display for ErrorCode { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{:?}", self) + } +} + +impl From for TsError { + fn from(err: anyhow::Error) -> Self { + TsError { + message: err.to_string(), + code: ErrorCode::Unknown, + } + } +} + pub fn operate( cm: &Lrc, handler: &Handler, input: String, options: Options, -) -> Result { +) -> Result { let filename = options .filename .map_or(FileName::Anon, |f| FileName::Real(f.into())); @@ -177,7 +218,10 @@ pub fn operate( e.into_diagnostic(handler).emit(); } - return Err(anyhow::anyhow!("failed to parse")); + return Err(TsError { + message: "Syntax error".to_string(), + code: ErrorCode::InvalidSyntax, + }); } }; @@ -186,7 +230,10 @@ pub fn operate( e.into_diagnostic(handler).emit(); } - return Err(anyhow::anyhow!("failed to parse")); + return Err(TsError { + message: "Syntax error".to_string(), + code: ErrorCode::InvalidSyntax, + }); } drop(parser); @@ -200,6 +247,12 @@ pub fn operate( // Strip typescript types let mut ts_strip = TsStrip::new(fm.src.clone(), tokens); program.visit_with(&mut ts_strip); + if handler.has_errors() { + return Err(TsError { + message: "Unsupported syntax".to_string(), + code: ErrorCode::UnsupportedSyntax, + }); + } let replacements = ts_strip.replacements; let overwrites = ts_strip.overwrites; @@ -266,8 +319,10 @@ pub fn operate( } let code = if cfg!(debug_assertions) { - String::from_utf8(code) - .map_err(|_| anyhow::anyhow!("failed to convert to utf-8"))? + String::from_utf8(code).map_err(|err| TsError { + message: format!("failed to convert to utf-8: {}", err), + code: ErrorCode::Unknown, + })? } else { // SAFETY: We've already validated that the source is valid utf-8 // and our operations are limited to character-level string replacements. @@ -1028,10 +1083,12 @@ impl Visit for TsStrip { fn visit_ts_export_assignment(&mut self, n: &TsExportAssignment) { HANDLER.with(|handler| { - handler.span_err( - n.span, - "TypeScript export assignment is not supported in strip-only mode", - ); + handler + .struct_span_err( + n.span, + "TypeScript export assignment is not supported in strip-only mode", + ) + .emit(); }); } @@ -1043,10 +1100,12 @@ impl Visit for TsStrip { } HANDLER.with(|handler| { - handler.span_err( - n.span, - "TypeScript import equals declaration is not supported in strip-only mode", - ); + handler + .struct_span_err( + n.span, + "TypeScript import equals declaration is not supported in strip-only mode", + ) + .emit(); }); } @@ -1062,28 +1121,34 @@ impl Visit for TsStrip { fn visit_ts_enum_decl(&mut self, e: &TsEnumDecl) { HANDLER.with(|handler| { - handler.span_err( - e.span, - "TypeScript enum is not supported in strip-only mode", - ); + handler + .struct_span_err( + e.span, + "TypeScript enum is not supported in strip-only mode", + ) + .emit(); }); } fn visit_ts_module_decl(&mut self, n: &TsModuleDecl) { HANDLER.with(|handler| { - handler.span_err( - n.span(), - "TypeScript namespace declaration is not supported in strip-only mode", - ); + handler + .struct_span_err( + n.span(), + "TypeScript namespace declaration is not supported in strip-only mode", + ) + .emit(); }); } fn visit_ts_namespace_decl(&mut self, n: &TsNamespaceDecl) { HANDLER.with(|handler| { - handler.span_err( - n.span(), - "TypeScript module declaration is not supported in strip-only mode", - ); + handler + .struct_span_err( + n.span(), + "TypeScript module declaration is not supported in strip-only mode", + ) + .emit(); }); } @@ -1095,10 +1160,12 @@ impl Visit for TsStrip { fn visit_ts_param_prop_param(&mut self, n: &TsParamPropParam) { HANDLER.with(|handler| { - handler.span_err( - n.span(), - "TypeScript parameter property is not supported in strip-only mode", - ); + handler + .struct_span_err( + n.span(), + "TypeScript parameter property is not supported in strip-only mode", + ) + .emit(); }); } @@ -1133,11 +1200,13 @@ impl Visit for TsStrip { /// See https://github.com/swc-project/swc/issues/9295 fn visit_ts_type_assertion(&mut self, n: &TsTypeAssertion) { HANDLER.with(|handler| { - handler.span_err( - n.span, - "The angle-bracket syntax for type assertions, `expr`, is not supported in \ - type strip mode. Instead, use the 'as' syntax: `expr as T`.", - ); + handler + .struct_span_err( + n.span, + "The angle-bracket syntax for type assertions, `expr`, is not supported in \ + type strip mode. Instead, use the 'as' syntax: `expr as T`.", + ) + .emit(); }); n.expr.visit_children_with(self); diff --git a/crates/swc_fast_ts_strip/tests/errors/export-equals.swc-stderr b/crates/swc_fast_ts_strip/tests/errors/export-equals.swc-stderr new file mode 100644 index 000000000000..4f7863b5a20d --- /dev/null +++ b/crates/swc_fast_ts_strip/tests/errors/export-equals.swc-stderr @@ -0,0 +1,6 @@ + x TypeScript export assignment is not supported in strip-only mode + ,-[2:1] + 1 | + 2 | export = 1; + : ^^^^^^^^^^^ + `---- diff --git a/crates/swc_fast_ts_strip/tests/errors/export-equals.ts b/crates/swc_fast_ts_strip/tests/errors/export-equals.ts new file mode 100644 index 000000000000..2f4528443607 --- /dev/null +++ b/crates/swc_fast_ts_strip/tests/errors/export-equals.ts @@ -0,0 +1,2 @@ + +export = 1; diff --git a/crates/swc_fast_ts_strip/tests/errors/import-equals.swc-stderr b/crates/swc_fast_ts_strip/tests/errors/import-equals.swc-stderr new file mode 100644 index 000000000000..f960b56486e5 --- /dev/null +++ b/crates/swc_fast_ts_strip/tests/errors/import-equals.swc-stderr @@ -0,0 +1,5 @@ + x TypeScript import equals declaration is not supported in strip-only mode + ,---- + 1 | import foo = require("foo"); + : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + `---- diff --git a/crates/swc_fast_ts_strip/tests/errors/import-equals.ts b/crates/swc_fast_ts_strip/tests/errors/import-equals.ts new file mode 100644 index 000000000000..11fb569cd7c2 --- /dev/null +++ b/crates/swc_fast_ts_strip/tests/errors/import-equals.ts @@ -0,0 +1 @@ +import foo = require("foo"); \ No newline at end of file diff --git a/crates/swc_fast_ts_strip/tests/errors/parameter-property.swc-stderr b/crates/swc_fast_ts_strip/tests/errors/parameter-property.swc-stderr new file mode 100644 index 000000000000..82f78c87780b --- /dev/null +++ b/crates/swc_fast_ts_strip/tests/errors/parameter-property.swc-stderr @@ -0,0 +1,14 @@ + x TypeScript parameter property is not supported in strip-only mode + ,-[5:1] + 4 | class Foo { + 5 | constructor(public id: string) { } + : ^^^^^^^^^^ + 6 | } + `---- + x TypeScript parameter property is not supported in strip-only mode + ,-[10:1] + 9 | class Bar { + 10 | constructor(private id: string) { } + : ^^^^^^^^^^ + 11 | } + `---- diff --git a/crates/swc_fast_ts_strip/tests/errors/parameter-property.ts b/crates/swc_fast_ts_strip/tests/errors/parameter-property.ts new file mode 100644 index 000000000000..1ab53dc0f75b --- /dev/null +++ b/crates/swc_fast_ts_strip/tests/errors/parameter-property.ts @@ -0,0 +1,11 @@ + + + +class Foo { + constructor(public id: string) { } +} + + +class Bar { + constructor(private id: string) { } +} \ No newline at end of file diff --git a/crates/swc_fast_ts_strip/tests/errors/ts-module.swc-stderr b/crates/swc_fast_ts_strip/tests/errors/ts-module.swc-stderr new file mode 100644 index 000000000000..a9f37bc16ae1 --- /dev/null +++ b/crates/swc_fast_ts_strip/tests/errors/ts-module.swc-stderr @@ -0,0 +1,7 @@ + x TypeScript namespace declaration is not supported in strip-only mode + ,-[3:1] + 2 | + 3 | ,-> module Foo { + 4 | | export const foo = 1; + 5 | `-> } + `---- diff --git a/crates/swc_fast_ts_strip/tests/errors/ts-module.ts b/crates/swc_fast_ts_strip/tests/errors/ts-module.ts new file mode 100644 index 000000000000..43e1c67d88e4 --- /dev/null +++ b/crates/swc_fast_ts_strip/tests/errors/ts-module.ts @@ -0,0 +1,5 @@ + + +module Foo { + export const foo = 1; +} \ No newline at end of file diff --git a/crates/swc_fast_ts_strip/tests/errors/ts-namespace.swc-stderr b/crates/swc_fast_ts_strip/tests/errors/ts-namespace.swc-stderr new file mode 100644 index 000000000000..2774b4dfa8e6 --- /dev/null +++ b/crates/swc_fast_ts_strip/tests/errors/ts-namespace.swc-stderr @@ -0,0 +1,7 @@ + x TypeScript namespace declaration is not supported in strip-only mode + ,-[3:1] + 2 | + 3 | ,-> namespace Foo { + 4 | | export const foo = 1; + 5 | `-> } + `---- diff --git a/crates/swc_fast_ts_strip/tests/errors/ts-namespace.ts b/crates/swc_fast_ts_strip/tests/errors/ts-namespace.ts new file mode 100644 index 000000000000..c55f6f9776c8 --- /dev/null +++ b/crates/swc_fast_ts_strip/tests/errors/ts-namespace.ts @@ -0,0 +1,5 @@ + + +namespace Foo { + export const foo = 1; +} \ No newline at end of file diff --git a/crates/swc_fast_ts_strip/tests/errors/type-assertions.swc-stderr b/crates/swc_fast_ts_strip/tests/errors/type-assertions.swc-stderr new file mode 100644 index 000000000000..d4b0c89a1d57 --- /dev/null +++ b/crates/swc_fast_ts_strip/tests/errors/type-assertions.swc-stderr @@ -0,0 +1,6 @@ + x The angle-bracket syntax for type assertions, `expr`, is not supported in type strip mode. Instead, use the 'as' syntax: `expr as T`. + ,-[3:1] + 2 | + 3 | const foo = 1; + : ^^^^^^^^^ + `---- diff --git a/crates/swc_fast_ts_strip/tests/errors/type-assertions.ts b/crates/swc_fast_ts_strip/tests/errors/type-assertions.ts new file mode 100644 index 000000000000..ad9af693cab6 --- /dev/null +++ b/crates/swc_fast_ts_strip/tests/errors/type-assertions.ts @@ -0,0 +1,3 @@ + + +const foo = 1; \ No newline at end of file diff --git a/crates/swc_fast_ts_strip/tests/fixture.rs b/crates/swc_fast_ts_strip/tests/fixture.rs index 9f537e35c98e..0fc384a7794d 100644 --- a/crates/swc_fast_ts_strip/tests/fixture.rs +++ b/crates/swc_fast_ts_strip/tests/fixture.rs @@ -16,13 +16,13 @@ fn test(input: PathBuf) { let transform_output_file = input.with_extension("transform.js"); let err = testing::run_test(false, |cm, handler| { - let code = operate(&cm, handler, input_code.clone(), opts(Mode::StripOnly)) - .expect("should not return Err()") - .code; + if let Ok(code) = operate(&cm, handler, input_code.clone(), opts(Mode::StripOnly)) { + let code = code.code; - NormalizedOutput::new_raw(code) - .compare_to_file(output_file) - .unwrap(); + NormalizedOutput::new_raw(code) + .compare_to_file(output_file) + .unwrap(); + } if handler.has_errors() { return Err(()); @@ -102,7 +102,7 @@ fn error(input: PathBuf) { let output_file = input.with_extension("swc-stderr"); testing::run_test(false, |cm, handler| { - operate(&cm, handler, input_code, opts(Mode::StripOnly)).expect("should not return Err()"); + operate(&cm, handler, input_code, opts(Mode::StripOnly)).expect_err("should return Err()"); Err::<(), _>(()) }) diff --git a/crates/swc_fast_ts_strip/tests/fixture/class-properties.js b/crates/swc_fast_ts_strip/tests/fixture/class-properties.js deleted file mode 100644 index 3713bda1fc69..000000000000 --- a/crates/swc_fast_ts_strip/tests/fixture/class-properties.js +++ /dev/null @@ -1,6 +0,0 @@ -class Foo { - x = console.log(1) - constructor(public y = console.log(2)) { - console.log(3) - } -} \ No newline at end of file diff --git a/crates/swc_fast_ts_strip/tests/fixture/test-case-1.js b/crates/swc_fast_ts_strip/tests/fixture/test-case-1.js deleted file mode 100644 index 62454e9ef522..000000000000 --- a/crates/swc_fast_ts_strip/tests/fixture/test-case-1.js +++ /dev/null @@ -1,198 +0,0 @@ -let x /**/ /**/ = 1 ; -// ^^^^^^^^ ^ - -[] ; -// ^^^^^^^^^^^^^^^^^^ - -("test"); -//^^^^^^^^ - -class C /**/ /*︎*/ extends Array/**/ /*︎*/ /*︎*/ { - // ^^^^^ ^^^ ^^^^^^^^^^^^^^ - field/**/ /**/ = ""; - // ^^^^^^^^ ^^^^^^^^ - static accessor f1; - f2/**/ /**/ /*︎*/; - // ^^^^^^^ ^ ^^^^^^^^ - - // ^^^^^^^^^^^^^^^^ declared property - - method/**/ /*︎*/(/*︎*/ /**/ a /*︎*/ /**/)/*︎*/ /*︎*/ { - // ^^^^^^ ^^^ ^^^^^^^^ ^ ^^^^^^^^ ^^^^^^ - } - - - // ^^^^^^^^^^^^^^^^^^^ index signature - - get g() { return 1 }; - // ^^^^^ - set g(v ) { }; - // ^^^^^ -} - -class D extends C { - // ^^^^^ - method(...args) { } - // ^^^^^^^^ ^^^^^ -} - - class A { - // ^^^^^^^^ - - // ^^^^^^^^^^^ abstract property - b; - - // ^^^^^^^^^^^^^^^^^^ abstract method -} - -{ - let m = new (Map ) ([] ); - // ^ ^^^^^^^^^^^^^^^^ ^ -} - -{ - let a = (foo ) ; - // ^ ^^^^^ -} - -{ - let a = (foo ) ([] ); - // ^ ^^^^^ ^ -} - -{ - let f = function (p ) { } - // ^^^^^ -} - -{ - - // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ overload - function overload() { } - // ^^^^^ -} - -/** @doc */ - -// ^^^^^^^^^^^ interface - -void 0; - -/** @doc */ - -// ^^^^^^^^ type alias - -/**/ -// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `import type` - -/**/ -// ^^^^^^^^^^^^^^^^^^ `export type` - -/**/ -// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `export type *` - -import { deepEqual } from "node:assert"; -// ^^^^^^^^^^^^^^^^^^^^^^^^^ - -export { - C, - - // ^^^^^^ -} - -/**/ -// ^^^^^^^^^^^^^^^^^^^ - -function foo (p = () => 1) { - // ^^^ ^^^^^ ^^^^^ ^^^^^ - return p ; - // ^^^^^^ -} - -/**/ -// ^^^^^^^^^^^^^^^^^^ `declare enum` - -void 0; - -/**/ -// ^^^^^^^^^^^^^^^^^^^^^^ `declare namespace` - -void 0; - -/**/ -// ^^^^^^^^^^^^^^^^^^^ `declare module` - -void 0; - -/**/ -// ^^^^^^^^^^^^^^ `declare let` - -void 0; - -/**/ -// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `declare class` - -void 0; - -/**/ -// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `declare function` - -void 0; - -// `=>` spanning line cases: -{ - ( - ) => - 1 -}; -{ - ( - ) => - 1 -}; -{ - ( - - ) => - 1 -}; -{ - ( - - - ) => - 1 -}; -{ - ( - - - ) => - 1 -}; -{ - (a, b, c = [] /*comment-1*/ /*comment-2*/ - ) => - 1 -}; - - - ( - )=> - 1; - -{ - (a, b, c = [] /*comment-1*/ /*comment-2*/ - )/*comment-4*/=> - 1 -}; - -      - -( -   ) => -1; - -( /*comment-1*/ -    ) /*comment-4*/=> -1; \ No newline at end of file diff --git a/crates/swc_fast_ts_strip/tests/fixture/unicode.js b/crates/swc_fast_ts_strip/tests/fixture/unicode.js deleted file mode 100644 index 62378ffc84dd..000000000000 --- a/crates/swc_fast_ts_strip/tests/fixture/unicode.js +++ /dev/null @@ -1,7 +0,0 @@ -    - -function foo() { - <任意>(void 1); throw new Error('foo'); -} - -foo(); \ No newline at end of file