mirror of
https://github.com/swc-project/swc.git
synced 2024-10-05 12:49:21 +03:00
fix(ecmascript/parser): Fix span of declare
decls. (#1282)
swc_ecma_parser: - Include `declare` span. (#843)
This commit is contained in:
parent
25856f230c
commit
bf69b47791
@ -6,7 +6,7 @@ edition = "2018"
|
||||
license = "Apache-2.0/MIT"
|
||||
name = "swc_ecmascript"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.15.0"
|
||||
version = "0.15.1"
|
||||
|
||||
[features]
|
||||
codegen = ["swc_ecma_codegen"]
|
||||
|
@ -7,7 +7,7 @@ include = ["Cargo.toml", "src/**/*.rs", "examples/**/*.rs"]
|
||||
license = "Apache-2.0/MIT"
|
||||
name = "swc_ecma_parser"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.43.4"
|
||||
version = "0.43.5"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
|
@ -2060,6 +2060,7 @@ impl<I: Tokens> Parser<I> {
|
||||
self.emit_err(span_of_declare, SyntaxError::TS1038);
|
||||
}
|
||||
|
||||
let declare_start = start;
|
||||
let ctx = Context {
|
||||
in_declare: true,
|
||||
..self.ctx()
|
||||
@ -2070,7 +2071,17 @@ impl<I: Tokens> Parser<I> {
|
||||
return p
|
||||
.parse_fn_decl(decorators)
|
||||
.map(|decl| match decl {
|
||||
Decl::Fn(f) => Decl::Fn(FnDecl { declare: true, ..f }),
|
||||
Decl::Fn(f) => Decl::Fn(FnDecl {
|
||||
declare: true,
|
||||
function: Function {
|
||||
span: Span {
|
||||
lo: declare_start,
|
||||
..f.function.span
|
||||
},
|
||||
..f.function
|
||||
},
|
||||
..f
|
||||
}),
|
||||
_ => decl,
|
||||
})
|
||||
.map(Some);
|
||||
@ -2080,7 +2091,17 @@ impl<I: Tokens> Parser<I> {
|
||||
return p
|
||||
.parse_class_decl(start, start, decorators)
|
||||
.map(|decl| match decl {
|
||||
Decl::Class(c) => Decl::Class(ClassDecl { declare: true, ..c }),
|
||||
Decl::Class(c) => Decl::Class(ClassDecl {
|
||||
declare: true,
|
||||
class: Class {
|
||||
span: Span {
|
||||
lo: declare_start,
|
||||
..c.class.span
|
||||
},
|
||||
..c.class
|
||||
},
|
||||
..c
|
||||
}),
|
||||
_ => decl,
|
||||
})
|
||||
.map(Some);
|
||||
@ -2095,6 +2116,10 @@ impl<I: Tokens> Parser<I> {
|
||||
.parse_ts_enum_decl(start, /* is_const */ true)
|
||||
.map(|decl| TsEnumDecl {
|
||||
declare: true,
|
||||
span: Span {
|
||||
lo: declare_start,
|
||||
..decl.span
|
||||
},
|
||||
..decl
|
||||
})
|
||||
.map(From::from)
|
||||
@ -2105,6 +2130,10 @@ impl<I: Tokens> Parser<I> {
|
||||
.parse_var_stmt(false)
|
||||
.map(|decl| VarDecl {
|
||||
declare: true,
|
||||
span: Span {
|
||||
lo: declare_start,
|
||||
..decl.span
|
||||
},
|
||||
..decl
|
||||
})
|
||||
.map(From::from)
|
||||
|
1
ecmascript/parser/tests/span/ts/declare/class.ts
Normal file
1
ecmascript/parser/tests/span/ts/declare/class.ts
Normal file
@ -0,0 +1 @@
|
||||
declare class Example { };
|
60
ecmascript/parser/tests/span/ts/declare/class.ts.spans
Normal file
60
ecmascript/parser/tests/span/ts/declare/class.ts.spans
Normal file
@ -0,0 +1,60 @@
|
||||
warning: Module
|
||||
--> $DIR/tests/span/ts/declare/class.ts:1:1
|
||||
|
|
||||
1 | declare class Example { };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
warning: ModuleItem
|
||||
--> $DIR/tests/span/ts/declare/class.ts:1:1
|
||||
|
|
||||
1 | declare class Example { };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
warning: Stmt
|
||||
--> $DIR/tests/span/ts/declare/class.ts:1:1
|
||||
|
|
||||
1 | declare class Example { };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
warning: Decl
|
||||
--> $DIR/tests/span/ts/declare/class.ts:1:1
|
||||
|
|
||||
1 | declare class Example { };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
warning: ClassDecl
|
||||
--> $DIR/tests/span/ts/declare/class.ts:1:1
|
||||
|
|
||||
1 | declare class Example { };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
warning: Ident
|
||||
--> $DIR/tests/span/ts/declare/class.ts:1:15
|
||||
|
|
||||
1 | declare class Example { };
|
||||
| ^^^^^^^
|
||||
|
||||
warning: Class
|
||||
--> $DIR/tests/span/ts/declare/class.ts:1:1
|
||||
|
|
||||
1 | declare class Example { };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
warning: ModuleItem
|
||||
--> $DIR/tests/span/ts/declare/class.ts:1:26
|
||||
|
|
||||
1 | declare class Example { };
|
||||
| ^
|
||||
|
||||
warning: Stmt
|
||||
--> $DIR/tests/span/ts/declare/class.ts:1:26
|
||||
|
|
||||
1 | declare class Example { };
|
||||
| ^
|
||||
|
||||
warning: EmptyStmt
|
||||
--> $DIR/tests/span/ts/declare/class.ts:1:26
|
||||
|
|
||||
1 | declare class Example { };
|
||||
| ^
|
||||
|
3
ecmascript/parser/tests/span/ts/declare/enum.ts
Normal file
3
ecmascript/parser/tests/span/ts/declare/enum.ts
Normal file
@ -0,0 +1,3 @@
|
||||
declare enum EnumSpan {
|
||||
A = 1
|
||||
};
|
100
ecmascript/parser/tests/span/ts/declare/enum.ts.spans
Normal file
100
ecmascript/parser/tests/span/ts/declare/enum.ts.spans
Normal file
@ -0,0 +1,100 @@
|
||||
warning: Module
|
||||
--> $DIR/tests/span/ts/declare/enum.ts:1:1
|
||||
|
|
||||
1 | / declare enum EnumSpan {
|
||||
2 | | A = 1
|
||||
3 | | };
|
||||
| |__^
|
||||
|
||||
warning: ModuleItem
|
||||
--> $DIR/tests/span/ts/declare/enum.ts:1:1
|
||||
|
|
||||
1 | / declare enum EnumSpan {
|
||||
2 | | A = 1
|
||||
3 | | };
|
||||
| |_^
|
||||
|
||||
warning: Stmt
|
||||
--> $DIR/tests/span/ts/declare/enum.ts:1:1
|
||||
|
|
||||
1 | / declare enum EnumSpan {
|
||||
2 | | A = 1
|
||||
3 | | };
|
||||
| |_^
|
||||
|
||||
warning: Decl
|
||||
--> $DIR/tests/span/ts/declare/enum.ts:1:1
|
||||
|
|
||||
1 | / declare enum EnumSpan {
|
||||
2 | | A = 1
|
||||
3 | | };
|
||||
| |_^
|
||||
|
||||
warning: TsEnumDecl
|
||||
--> $DIR/tests/span/ts/declare/enum.ts:1:1
|
||||
|
|
||||
1 | / declare enum EnumSpan {
|
||||
2 | | A = 1
|
||||
3 | | };
|
||||
| |_^
|
||||
|
||||
warning: Ident
|
||||
--> $DIR/tests/span/ts/declare/enum.ts:1:14
|
||||
|
|
||||
1 | declare enum EnumSpan {
|
||||
| ^^^^^^^^
|
||||
|
||||
warning: TsEnumMember
|
||||
--> $DIR/tests/span/ts/declare/enum.ts:2:5
|
||||
|
|
||||
2 | A = 1
|
||||
| ^^^^^
|
||||
|
||||
warning: TsEnumMemberId
|
||||
--> $DIR/tests/span/ts/declare/enum.ts:2:5
|
||||
|
|
||||
2 | A = 1
|
||||
| ^
|
||||
|
||||
warning: Ident
|
||||
--> $DIR/tests/span/ts/declare/enum.ts:2:5
|
||||
|
|
||||
2 | A = 1
|
||||
| ^
|
||||
|
||||
warning: Expr
|
||||
--> $DIR/tests/span/ts/declare/enum.ts:2:9
|
||||
|
|
||||
2 | A = 1
|
||||
| ^
|
||||
|
||||
warning: Lit
|
||||
--> $DIR/tests/span/ts/declare/enum.ts:2:9
|
||||
|
|
||||
2 | A = 1
|
||||
| ^
|
||||
|
||||
warning: Number
|
||||
--> $DIR/tests/span/ts/declare/enum.ts:2:9
|
||||
|
|
||||
2 | A = 1
|
||||
| ^
|
||||
|
||||
warning: ModuleItem
|
||||
--> $DIR/tests/span/ts/declare/enum.ts:3:2
|
||||
|
|
||||
3 | };
|
||||
| ^
|
||||
|
||||
warning: Stmt
|
||||
--> $DIR/tests/span/ts/declare/enum.ts:3:2
|
||||
|
|
||||
3 | };
|
||||
| ^
|
||||
|
||||
warning: EmptyStmt
|
||||
--> $DIR/tests/span/ts/declare/enum.ts:3:2
|
||||
|
|
||||
3 | };
|
||||
| ^
|
||||
|
1
ecmascript/parser/tests/span/ts/declare/function.ts
Normal file
1
ecmascript/parser/tests/span/ts/declare/function.ts
Normal file
@ -0,0 +1 @@
|
||||
declare function example(): undefined;
|
60
ecmascript/parser/tests/span/ts/declare/function.ts.spans
Normal file
60
ecmascript/parser/tests/span/ts/declare/function.ts.spans
Normal file
@ -0,0 +1,60 @@
|
||||
warning: Module
|
||||
--> $DIR/tests/span/ts/declare/function.ts:1:1
|
||||
|
|
||||
1 | declare function example(): undefined;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
warning: ModuleItem
|
||||
--> $DIR/tests/span/ts/declare/function.ts:1:1
|
||||
|
|
||||
1 | declare function example(): undefined;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
warning: Stmt
|
||||
--> $DIR/tests/span/ts/declare/function.ts:1:1
|
||||
|
|
||||
1 | declare function example(): undefined;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
warning: Decl
|
||||
--> $DIR/tests/span/ts/declare/function.ts:1:1
|
||||
|
|
||||
1 | declare function example(): undefined;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
warning: FnDecl
|
||||
--> $DIR/tests/span/ts/declare/function.ts:1:1
|
||||
|
|
||||
1 | declare function example(): undefined;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
warning: Ident
|
||||
--> $DIR/tests/span/ts/declare/function.ts:1:18
|
||||
|
|
||||
1 | declare function example(): undefined;
|
||||
| ^^^^^^^
|
||||
|
||||
warning: Function
|
||||
--> $DIR/tests/span/ts/declare/function.ts:1:1
|
||||
|
|
||||
1 | declare function example(): undefined;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
warning: TsTypeAnn
|
||||
--> $DIR/tests/span/ts/declare/function.ts:1:27
|
||||
|
|
||||
1 | declare function example(): undefined;
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
warning: TsType
|
||||
--> $DIR/tests/span/ts/declare/function.ts:1:29
|
||||
|
|
||||
1 | declare function example(): undefined;
|
||||
| ^^^^^^^^^
|
||||
|
||||
warning: TsKeywordType
|
||||
--> $DIR/tests/span/ts/declare/function.ts:1:29
|
||||
|
|
||||
1 | declare function example(): undefined;
|
||||
| ^^^^^^^^^
|
||||
|
3
ecmascript/parser/tests/span/ts/declare/module.ts
Normal file
3
ecmascript/parser/tests/span/ts/declare/module.ts
Normal file
@ -0,0 +1,3 @@
|
||||
declare module "name" {
|
||||
export class Foo { }
|
||||
}
|
112
ecmascript/parser/tests/span/ts/declare/module.ts.spans
Normal file
112
ecmascript/parser/tests/span/ts/declare/module.ts.spans
Normal file
@ -0,0 +1,112 @@
|
||||
warning: Module
|
||||
--> $DIR/tests/span/ts/declare/module.ts:1:1
|
||||
|
|
||||
1 | / declare module "name" {
|
||||
2 | | export class Foo { }
|
||||
3 | | }
|
||||
| |_^
|
||||
|
||||
warning: ModuleItem
|
||||
--> $DIR/tests/span/ts/declare/module.ts:1:1
|
||||
|
|
||||
1 | / declare module "name" {
|
||||
2 | | export class Foo { }
|
||||
3 | | }
|
||||
| |_^
|
||||
|
||||
warning: Stmt
|
||||
--> $DIR/tests/span/ts/declare/module.ts:1:1
|
||||
|
|
||||
1 | / declare module "name" {
|
||||
2 | | export class Foo { }
|
||||
3 | | }
|
||||
| |_^
|
||||
|
||||
warning: Decl
|
||||
--> $DIR/tests/span/ts/declare/module.ts:1:1
|
||||
|
|
||||
1 | / declare module "name" {
|
||||
2 | | export class Foo { }
|
||||
3 | | }
|
||||
| |_^
|
||||
|
||||
warning: TsModuleDecl
|
||||
--> $DIR/tests/span/ts/declare/module.ts:1:1
|
||||
|
|
||||
1 | / declare module "name" {
|
||||
2 | | export class Foo { }
|
||||
3 | | }
|
||||
| |_^
|
||||
|
||||
warning: TsModuleName
|
||||
--> $DIR/tests/span/ts/declare/module.ts:1:16
|
||||
|
|
||||
1 | declare module "name" {
|
||||
| ^^^^^^
|
||||
|
||||
warning: Str
|
||||
--> $DIR/tests/span/ts/declare/module.ts:1:16
|
||||
|
|
||||
1 | declare module "name" {
|
||||
| ^^^^^^
|
||||
|
||||
warning: TsNamespaceBody
|
||||
--> $DIR/tests/span/ts/declare/module.ts:1:23
|
||||
|
|
||||
1 | declare module "name" {
|
||||
| _______________________^
|
||||
2 | | export class Foo { }
|
||||
3 | | }
|
||||
| |_^
|
||||
|
||||
warning: TsModuleBlock
|
||||
--> $DIR/tests/span/ts/declare/module.ts:1:23
|
||||
|
|
||||
1 | declare module "name" {
|
||||
| _______________________^
|
||||
2 | | export class Foo { }
|
||||
3 | | }
|
||||
| |_^
|
||||
|
||||
warning: ModuleItem
|
||||
--> $DIR/tests/span/ts/declare/module.ts:2:5
|
||||
|
|
||||
2 | export class Foo { }
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
warning: ModuleDecl
|
||||
--> $DIR/tests/span/ts/declare/module.ts:2:5
|
||||
|
|
||||
2 | export class Foo { }
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
warning: ExportDecl
|
||||
--> $DIR/tests/span/ts/declare/module.ts:2:5
|
||||
|
|
||||
2 | export class Foo { }
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
warning: Decl
|
||||
--> $DIR/tests/span/ts/declare/module.ts:2:12
|
||||
|
|
||||
2 | export class Foo { }
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
warning: ClassDecl
|
||||
--> $DIR/tests/span/ts/declare/module.ts:2:12
|
||||
|
|
||||
2 | export class Foo { }
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
warning: Ident
|
||||
--> $DIR/tests/span/ts/declare/module.ts:2:18
|
||||
|
|
||||
2 | export class Foo { }
|
||||
| ^^^
|
||||
|
||||
warning: Class
|
||||
--> $DIR/tests/span/ts/declare/module.ts:2:12
|
||||
|
|
||||
2 | export class Foo { }
|
||||
| ^^^^^^^^^^^^^
|
||||
|
1
ecmascript/parser/tests/span/ts/declare/var.ts
Normal file
1
ecmascript/parser/tests/span/ts/declare/var.ts
Normal file
@ -0,0 +1 @@
|
||||
declare const a = 1;
|
66
ecmascript/parser/tests/span/ts/declare/var.ts.spans
Normal file
66
ecmascript/parser/tests/span/ts/declare/var.ts.spans
Normal file
@ -0,0 +1,66 @@
|
||||
warning: Module
|
||||
--> $DIR/tests/span/ts/declare/var.ts:1:1
|
||||
|
|
||||
1 | declare const a = 1;
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
warning: ModuleItem
|
||||
--> $DIR/tests/span/ts/declare/var.ts:1:1
|
||||
|
|
||||
1 | declare const a = 1;
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
warning: Stmt
|
||||
--> $DIR/tests/span/ts/declare/var.ts:1:1
|
||||
|
|
||||
1 | declare const a = 1;
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
warning: Decl
|
||||
--> $DIR/tests/span/ts/declare/var.ts:1:1
|
||||
|
|
||||
1 | declare const a = 1;
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
warning: VarDecl
|
||||
--> $DIR/tests/span/ts/declare/var.ts:1:1
|
||||
|
|
||||
1 | declare const a = 1;
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
warning: VarDeclarator
|
||||
--> $DIR/tests/span/ts/declare/var.ts:1:15
|
||||
|
|
||||
1 | declare const a = 1;
|
||||
| ^^^^^
|
||||
|
||||
warning: Pat
|
||||
--> $DIR/tests/span/ts/declare/var.ts:1:15
|
||||
|
|
||||
1 | declare const a = 1;
|
||||
| ^
|
||||
|
||||
warning: Ident
|
||||
--> $DIR/tests/span/ts/declare/var.ts:1:15
|
||||
|
|
||||
1 | declare const a = 1;
|
||||
| ^
|
||||
|
||||
warning: Expr
|
||||
--> $DIR/tests/span/ts/declare/var.ts:1:19
|
||||
|
|
||||
1 | declare const a = 1;
|
||||
| ^
|
||||
|
||||
warning: Lit
|
||||
--> $DIR/tests/span/ts/declare/var.ts:1:19
|
||||
|
|
||||
1 | declare const a = 1;
|
||||
| ^
|
||||
|
||||
warning: Number
|
||||
--> $DIR/tests/span/ts/declare/var.ts:1:19
|
||||
|
|
||||
1 | declare const a = 1;
|
||||
| ^
|
||||
|
Loading…
Reference in New Issue
Block a user