Closed
Description
Describe the bug
I found the span of Ident inside BindingIdent is inconsistant. Here are 2 cases.
Case 1: BindingIdent doesn't Include TsTypeAnn
- Parse the following code.
const a: number
- The span of BindingIdent is as follows.
Span { lo: BytePos(7), hi: BytePos(8), ctxt: #0 }
- The AST is as follows.
BindingIdent {
id: Ident {
span: Span {
lo: BytePos(
7,
),
hi: BytePos(
8,
),
ctxt: #0,
},
sym: "a",
optional: false,
},
type_ann: Some(
TsTypeAnn {
span: Span {
lo: BytePos(
8,
),
hi: BytePos(
16,
),
ctxt: #0,
},
type_ann: TsKeywordType(
TsKeywordType {
span: Span {
lo: BytePos(
10,
),
hi: BytePos(
16,
),
ctxt: #0,
},
kind: TsNumberKeyword,
},
),
},
),
}
Case 2: BindingIdent Includes TsTypeAnn
- Parse the following code.
function b(a: number = 1) {}
- The span of BindingIdent is as follows.
Span { lo: BytePos(12), hi: BytePos(21), ctxt: #0 }
- The AST is as follows.
BindingIdent {
id: Ident {
span: Span {
lo: BytePos(
12,
),
hi: BytePos(
21,
),
ctxt: #0,
},
sym: "a",
optional: false,
},
type_ann: Some(
TsTypeAnn {
span: Span {
lo: BytePos(
13,
),
hi: BytePos(
21,
),
ctxt: #0,
},
type_ann: TsKeywordType(
TsKeywordType {
span: Span {
lo: BytePos(
15,
),
hi: BytePos(
21,
),
ctxt: #0,
},
kind: TsNumberKeyword,
},
),
},
),
}
Conclusions
- In case 1, the BindingIdent (7, 8) doesn't include the TsTypeAnn (8, 16) and the Ident (7, 8) is expected.
- In case 2, the BindingIdent (12, 21) includes the TsTypeAnn (13, 21) and the Ident (12, 21) is not expected because it includes the TsTypeAnn (13, 21) too.
Input code
function b(a: number = 1) {}
Config
{
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": false
},
"target": "es2020",
"loose": false,
"minify": {
"compress": false,
"mangle": false
}
},
"module": {
"type": "es6"
},
"minify": false,
"isModule": false
}
Playground link (or link to the minimal reproduction)
- 1.3.100
- 1.4.13
SWC Info output
No response
Expected behavior
The span of BindingIdent and Ident should be consistant.
- Either the BindingIdent includes the TsTypeAnn in both cases, or the BindingIdent doesn't include the TsTypeAnn in both cases.
- The Ident doesn't include the TsTypeAnn in both cases.
Actual behavior
No response
Version
- 1.3.100
- 1.4.13
Additional context
No response