Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
invalid syntax
  • Loading branch information
kdy1 committed Jan 6, 2025
commit 605fe6655e1badf7295479136f56a02239fb033d
83 changes: 52 additions & 31 deletions crates/swc_fast_ts_strip/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ pub fn operate(
err.into_diagnostic(handler).note("INVALID_SYNTAX").emit();

for e in errors {
e.into_diagnostic(handler).note("INVALID_SYNTAX").emit();
e.into_diagnostic(handler).note("Invalid syntax").emit();
}

return Err(anyhow::anyhow!("failed to parse"));
Expand All @@ -183,7 +183,7 @@ pub fn operate(

if !errors.is_empty() {
for e in errors {
e.into_diagnostic(handler).note("INVALID_SYNTAX").emit();
e.into_diagnostic(handler).note("Invalid syntax").emit();
}

return Err(anyhow::anyhow!("failed to parse"));
Expand Down Expand Up @@ -1028,10 +1028,13 @@ 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",
)
.note("Unsupported syntax")
.emit();
});
}

Expand All @@ -1043,10 +1046,13 @@ 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",
)
.note("Unsupported syntax")
.emit();
});
}

Expand All @@ -1062,28 +1068,37 @@ 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",
)
.note("Unsupported syntax")
.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",
)
.note("Unsupported syntax")
.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",
)
.note("Unsupported syntax")
.emit();
});
}

Expand All @@ -1095,10 +1110,13 @@ 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",
)
.note("Unsupported syntax")
.emit();
});
}

Expand Down Expand Up @@ -1133,11 +1151,14 @@ 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, `<T>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, `<T>expr`, is not supported in \
type strip mode. Instead, use the 'as' syntax: `expr as T`.",
)
.note("Unsupported syntax")
.emit();
});

n.expr.visit_children_with(self);
Expand Down