mirror of
https://github.com/swc-project/swc.git
synced 2024-11-23 17:54:15 +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,
|
BytePos, FileName, SourceMap, Span, Spanned,
|
||||||
};
|
};
|
||||||
use swc_ecma_ast::{
|
use swc_ecma_ast::{
|
||||||
ArrowExpr, BindingIdent, Class, ClassDecl, ClassMethod, ClassProp, Decorator, EsVersion,
|
ArrowExpr, BindingIdent, Class, ClassDecl, ClassMethod, ClassProp, EsVersion, ExportAll,
|
||||||
ExportAll, ExportDecl, ExportSpecifier, FnDecl, Ident, ImportDecl, ImportSpecifier,
|
ExportDecl, ExportSpecifier, FnDecl, Ident, ImportDecl, ImportSpecifier, NamedExport, Param,
|
||||||
NamedExport, Param, Pat, Program, TsAsExpr, TsConstAssertion, TsEnumDecl, TsExportAssignment,
|
Pat, Program, TsAsExpr, TsConstAssertion, TsEnumDecl, TsExportAssignment, TsImportEqualsDecl,
|
||||||
TsImportEqualsDecl, TsIndexSignature, TsInstantiation, TsInterfaceDecl, TsModuleDecl,
|
TsIndexSignature, TsInstantiation, TsInterfaceDecl, TsModuleDecl, TsModuleName,
|
||||||
TsModuleName, TsNamespaceDecl, TsNonNullExpr, TsParamPropParam, TsSatisfiesExpr,
|
TsNamespaceDecl, TsNonNullExpr, TsParamPropParam, TsSatisfiesExpr, TsTypeAliasDecl, TsTypeAnn,
|
||||||
TsTypeAliasDecl, TsTypeAnn, TsTypeAssertion, TsTypeParamDecl, TsTypeParamInstantiation,
|
TsTypeAssertion, TsTypeParamDecl, TsTypeParamInstantiation, VarDecl,
|
||||||
VarDecl,
|
|
||||||
};
|
};
|
||||||
use swc_ecma_parser::{
|
use swc_ecma_parser::{
|
||||||
lexer::Lexer,
|
lexer::Lexer,
|
||||||
@ -364,12 +363,6 @@ impl Visit for TsStrip {
|
|||||||
self.add_replacement(n.span);
|
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) {
|
fn visit_export_all(&mut self, n: &ExportAll) {
|
||||||
if n.type_only {
|
if n.type_only {
|
||||||
self.add_replacement(n.span);
|
self.add_replacement(n.span);
|
||||||
@ -419,6 +412,8 @@ impl Visit for TsStrip {
|
|||||||
let comma = self.get_next_token(import.span_hi());
|
let comma = self.get_next_token(import.span_hi());
|
||||||
if comma.token == Token::Comma {
|
if comma.token == Token::Comma {
|
||||||
span = span.with_hi(comma.span.hi);
|
span = span.with_hi(comma.span.hi);
|
||||||
|
} else {
|
||||||
|
debug_assert_eq!(comma.token, Token::RBrace);
|
||||||
}
|
}
|
||||||
self.add_replacement(span);
|
self.add_replacement(span);
|
||||||
}
|
}
|
||||||
@ -439,6 +434,8 @@ impl Visit for TsStrip {
|
|||||||
let comma = self.get_next_token(e.span_hi());
|
let comma = self.get_next_token(e.span_hi());
|
||||||
if comma.token == Token::Comma {
|
if comma.token == Token::Comma {
|
||||||
span = span.with_hi(comma.span.hi);
|
span = span.with_hi(comma.span.hi);
|
||||||
|
} else {
|
||||||
|
debug_assert_eq!(comma.token, Token::RBrace);
|
||||||
}
|
}
|
||||||
self.add_replacement(span);
|
self.add_replacement(span);
|
||||||
}
|
}
|
||||||
@ -484,6 +481,8 @@ impl Visit for TsStrip {
|
|||||||
let comma = self.get_next_token(span.hi);
|
let comma = self.get_next_token(span.hi);
|
||||||
if comma.token == Token::Comma {
|
if comma.token == Token::Comma {
|
||||||
span = span.with_hi(comma.span.hi);
|
span = span.with_hi(comma.span.hi);
|
||||||
|
} else {
|
||||||
|
debug_assert_eq!(comma.token, Token::RParen);
|
||||||
}
|
}
|
||||||
self.add_replacement(span);
|
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