mirror of
https://github.com/swc-project/swc.git
synced 2024-11-23 09:38:16 +03:00
chore(es/typescript): Improve decorator handling of fast strip (#9178)
**Description:** Given that decorators will be a part of JavaScript, as specified in the [proposal](https://github.com/tc39/proposal-decorators), we retain them in the output rather than reporting an error.
This commit is contained in:
parent
67915bfe56
commit
962170fb70
@ -9,13 +9,12 @@ use swc_common::{
|
||||
BytePos, FileName, SourceMap, Span, Spanned,
|
||||
};
|
||||
use swc_ecma_ast::{
|
||||
ArrowExpr, BindingIdent, Class, ClassDecl, ClassMethod, ClassProp, Decorator, EsVersion,
|
||||
ExportAll, ExportDecl, ExportSpecifier, FnDecl, Ident, ImportDecl, ImportSpecifier,
|
||||
NamedExport, Param, Pat, Program, TsAsExpr, TsConstAssertion, TsEnumDecl, TsExportAssignment,
|
||||
TsImportEqualsDecl, TsIndexSignature, TsInstantiation, TsInterfaceDecl, TsModuleDecl,
|
||||
TsModuleName, TsNamespaceDecl, TsNonNullExpr, TsParamPropParam, TsSatisfiesExpr,
|
||||
TsTypeAliasDecl, TsTypeAnn, TsTypeAssertion, TsTypeParamDecl, TsTypeParamInstantiation,
|
||||
VarDecl,
|
||||
ArrowExpr, BindingIdent, Class, ClassDecl, ClassMethod, ClassProp, EsVersion, ExportAll,
|
||||
ExportDecl, ExportSpecifier, FnDecl, Ident, ImportDecl, ImportSpecifier, NamedExport, Param,
|
||||
Pat, Program, TsAsExpr, TsConstAssertion, TsEnumDecl, TsExportAssignment, TsImportEqualsDecl,
|
||||
TsIndexSignature, TsInstantiation, TsInterfaceDecl, TsModuleDecl, TsModuleName,
|
||||
TsNamespaceDecl, TsNonNullExpr, TsParamPropParam, TsSatisfiesExpr, TsTypeAliasDecl, TsTypeAnn,
|
||||
TsTypeAssertion, TsTypeParamDecl, TsTypeParamInstantiation, VarDecl,
|
||||
};
|
||||
use swc_ecma_parser::{
|
||||
lexer::Lexer,
|
||||
@ -364,12 +363,6 @@ impl Visit for TsStrip {
|
||||
self.add_replacement(n.span);
|
||||
}
|
||||
|
||||
fn visit_decorator(&mut self, n: &Decorator) {
|
||||
HANDLER.with(|handler| {
|
||||
handler.span_err(n.span, "Decorators are not supported");
|
||||
});
|
||||
}
|
||||
|
||||
fn visit_export_all(&mut self, n: &ExportAll) {
|
||||
if n.type_only {
|
||||
self.add_replacement(n.span);
|
||||
@ -419,6 +412,8 @@ impl Visit for TsStrip {
|
||||
let comma = self.get_next_token(import.span_hi());
|
||||
if comma.token == Token::Comma {
|
||||
span = span.with_hi(comma.span.hi);
|
||||
} else {
|
||||
debug_assert_eq!(comma.token, Token::RBrace);
|
||||
}
|
||||
self.add_replacement(span);
|
||||
}
|
||||
@ -439,6 +434,8 @@ impl Visit for TsStrip {
|
||||
let comma = self.get_next_token(e.span_hi());
|
||||
if comma.token == Token::Comma {
|
||||
span = span.with_hi(comma.span.hi);
|
||||
} else {
|
||||
debug_assert_eq!(comma.token, Token::RBrace);
|
||||
}
|
||||
self.add_replacement(span);
|
||||
}
|
||||
@ -484,6 +481,8 @@ impl Visit for TsStrip {
|
||||
let comma = self.get_next_token(span.hi);
|
||||
if comma.token == Token::Comma {
|
||||
span = span.with_hi(comma.span.hi);
|
||||
} else {
|
||||
debug_assert_eq!(comma.token, Token::RParen);
|
||||
}
|
||||
self.add_replacement(span);
|
||||
|
||||
|
@ -1,5 +0,0 @@
|
||||
x Decorators are not supported
|
||||
,----
|
||||
1 | class Foo { @decorator foo() { } }
|
||||
: ^^^^^^^^^^
|
||||
`----
|
@ -1 +0,0 @@
|
||||
class Foo { @decorator foo() { } }
|
Loading…
Reference in New Issue
Block a user