Skip to content
This repository was archived by the owner on Jan 14, 2019. It is now read-only.

Commit 02d5e91

Browse files
committed
feat(ast): heritage array is now optional, not empty array
BREAKING CHANGE: This changes the AST of TSInterfaceDeclaration nodes
1 parent 868e760 commit 02d5e91

File tree

4 files changed

+9
-43
lines changed

4 files changed

+9
-43
lines changed

src/convert.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -2525,13 +2525,15 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
25252525
Object.assign(result, {
25262526
type: AST_NODE_TYPES.TSInterfaceDeclaration,
25272527
body: interfaceBody,
2528-
id: convertChild(node.name),
2529-
heritage: hasImplementsClause
2530-
? interfaceHeritageClauses[0].types.map(el =>
2531-
convertHeritageClause(AST_NODE_TYPES.TSInterfaceHeritage, el)
2532-
)
2533-
: []
2528+
id: convertChild(node.name)
25342529
});
2530+
2531+
if (hasImplementsClause) {
2532+
result.heritage = interfaceHeritageClauses[0].types.map(el =>
2533+
convertHeritageClause(AST_NODE_TYPES.TSInterfaceHeritage, el)
2534+
);
2535+
}
2536+
25352537
/**
25362538
* Semantically, decorators are not allowed on interface declarations,
25372539
* but the TypeScript compiler will parse them and produce a valid AST,

src/temp-types-based-on-js-source.ts

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export interface ESTreeNode {
3434
value?: string;
3535
expression?: ESTreeNode | null;
3636
decorators?: (ESTreeNode | null)[];
37+
heritage?: ESTreeNode[];
3738
const?: boolean;
3839
declare?: boolean;
3940
global?: boolean;

tests/ast-alignment/fixtures-to-test.ts

-6
Original file line numberDiff line numberDiff line change
@@ -385,12 +385,6 @@ tester.addFixturePatternConfig('typescript/basics', {
385385
'interface-without-type-annotation',
386386
'type-guard-in-interface',
387387
'typed-this',
388-
/**
389-
* AST difference
390-
* ts-estree: heritage = []
391-
* babel: heritage = undefined
392-
*/
393-
'interface-with-method',
394388
/**
395389
* Babel bug for parsing exported abstract interface
396390
* https://github.com/babel/babel/issues/9304

tests/lib/__snapshots__/typescript.ts.snap

-31
Original file line numberDiff line numberDiff line change
@@ -2919,7 +2919,6 @@ Object {
29192919
],
29202920
"type": "TSInterfaceBody",
29212921
},
2922-
"heritage": Array [],
29232922
"id": Object {
29242923
"loc": Object {
29252924
"end": Object {
@@ -13703,7 +13702,6 @@ Object {
1370313702
],
1370413703
"type": "TSInterfaceBody",
1370513704
},
13706-
"heritage": Array [],
1370713705
"id": Object {
1370813706
"loc": Object {
1370913707
"end": Object {
@@ -42082,7 +42080,6 @@ Object {
4208242080
],
4208342081
"type": "TSInterfaceBody",
4208442082
},
42085-
"heritage": Array [],
4208642083
"id": Object {
4208742084
"loc": Object {
4208842085
"end": Object {
@@ -43574,7 +43571,6 @@ Object {
4357443571
],
4357543572
"type": "TSInterfaceBody",
4357643573
},
43577-
"heritage": Array [],
4357843574
"id": Object {
4357943575
"loc": Object {
4358043576
"end": Object {
@@ -45761,7 +45757,6 @@ Object {
4576145757
],
4576245758
"type": "TSInterfaceBody",
4576345759
},
45764-
"heritage": Array [],
4576545760
"id": Object {
4576645761
"loc": Object {
4576745762
"end": Object {
@@ -46513,7 +46508,6 @@ Object {
4651346508
],
4651446509
"type": "TSInterfaceBody",
4651546510
},
46516-
"heritage": Array [],
4651746511
"id": Object {
4651846512
"loc": Object {
4651946513
"end": Object {
@@ -46829,7 +46823,6 @@ Object {
4682946823
],
4683046824
"type": "TSInterfaceBody",
4683146825
},
46832-
"heritage": Array [],
4683346826
"id": Object {
4683446827
"loc": Object {
4683546828
"end": Object {
@@ -47409,7 +47402,6 @@ Object {
4740947402
],
4741047403
"type": "TSInterfaceBody",
4741147404
},
47412-
"heritage": Array [],
4741347405
"id": Object {
4741447406
"loc": Object {
4741547407
"end": Object {
@@ -48176,7 +48168,6 @@ Object {
4817648168
],
4817748169
"type": "TSInterfaceBody",
4817848170
},
48179-
"heritage": Array [],
4818048171
"id": Object {
4818148172
"loc": Object {
4818248173
"end": Object {
@@ -48760,7 +48751,6 @@ Object {
4876048751
],
4876148752
"type": "TSInterfaceBody",
4876248753
},
48763-
"heritage": Array [],
4876448754
"id": Object {
4876548755
"loc": Object {
4876648756
"end": Object {
@@ -56298,7 +56288,6 @@ Object {
5629856288
],
5629956289
"type": "TSInterfaceBody",
5630056290
},
56301-
"heritage": Array [],
5630256291
"id": Object {
5630356292
"loc": Object {
5630456293
"end": Object {
@@ -62299,7 +62288,6 @@ Object {
6229962288
],
6230062289
"type": "TSInterfaceBody",
6230162290
},
62302-
"heritage": Array [],
6230362291
"id": Object {
6230462292
"loc": Object {
6230562293
"end": Object {
@@ -65746,7 +65734,6 @@ Object {
6574665734
"type": "TSInterfaceBody",
6574765735
},
6574865736
"declare": true,
65749-
"heritage": Array [],
6575065737
"id": Object {
6575165738
"loc": Object {
6575265739
"end": Object {
@@ -78610,7 +78597,6 @@ Object {
7861078597
"type": "Decorator",
7861178598
},
7861278599
],
78613-
"heritage": Array [],
7861478600
"id": Object {
7861578601
"loc": Object {
7861678602
"end": Object {
@@ -80327,7 +80313,6 @@ Object {
8032780313
],
8032880314
"type": "TSInterfaceBody",
8032980315
},
80330-
"heritage": Array [],
8033180316
"id": Object {
8033280317
"loc": Object {
8033380318
"end": Object {
@@ -80747,7 +80732,6 @@ Object {
8074780732
],
8074880733
"type": "TSInterfaceBody",
8074980734
},
80750-
"heritage": Array [],
8075180735
"id": Object {
8075280736
"loc": Object {
8075380737
"end": Object {
@@ -81167,7 +81151,6 @@ Object {
8116781151
],
8116881152
"type": "TSInterfaceBody",
8116981153
},
81170-
"heritage": Array [],
8117181154
"id": Object {
8117281155
"loc": Object {
8117381156
"end": Object {
@@ -81587,7 +81570,6 @@ Object {
8158781570
],
8158881571
"type": "TSInterfaceBody",
8158981572
},
81590-
"heritage": Array [],
8159181573
"id": Object {
8159281574
"loc": Object {
8159381575
"end": Object {
@@ -82007,7 +81989,6 @@ Object {
8200781989
],
8200881990
"type": "TSInterfaceBody",
8200981991
},
82010-
"heritage": Array [],
8201181992
"id": Object {
8201281993
"loc": Object {
8201381994
"end": Object {
@@ -82446,7 +82427,6 @@ Object {
8244682427
],
8244782428
"type": "TSInterfaceBody",
8244882429
},
82449-
"heritage": Array [],
8245082430
"id": Object {
8245182431
"loc": Object {
8245282432
"end": Object {
@@ -82903,7 +82883,6 @@ Object {
8290382883
],
8290482884
"type": "TSInterfaceBody",
8290582885
},
82906-
"heritage": Array [],
8290782886
"id": Object {
8290882887
"loc": Object {
8290982888
"end": Object {
@@ -83360,7 +83339,6 @@ Object {
8336083339
],
8336183340
"type": "TSInterfaceBody",
8336283341
},
83363-
"heritage": Array [],
8336483342
"id": Object {
8336583343
"loc": Object {
8336683344
"end": Object {
@@ -83817,7 +83795,6 @@ Object {
8381783795
],
8381883796
"type": "TSInterfaceBody",
8381983797
},
83820-
"heritage": Array [],
8382183798
"id": Object {
8382283799
"loc": Object {
8382383800
"end": Object {
@@ -84274,7 +84251,6 @@ Object {
8427484251
],
8427584252
"type": "TSInterfaceBody",
8427684253
},
84277-
"heritage": Array [],
8427884254
"id": Object {
8427984255
"loc": Object {
8428084256
"end": Object {
@@ -84677,7 +84653,6 @@ Object {
8467784653
],
8467884654
"type": "TSInterfaceBody",
8467984655
},
84680-
"heritage": Array [],
8468184656
"id": Object {
8468284657
"loc": Object {
8468384658
"end": Object {
@@ -84990,7 +84965,6 @@ Object {
8499084965
],
8499184966
"type": "TSInterfaceBody",
8499284967
},
84993-
"heritage": Array [],
8499484968
"id": Object {
8499584969
"loc": Object {
8499684970
"end": Object {
@@ -85303,7 +85277,6 @@ Object {
8530385277
],
8530485278
"type": "TSInterfaceBody",
8530585279
},
85306-
"heritage": Array [],
8530785280
"id": Object {
8530885281
"loc": Object {
8530985282
"end": Object {
@@ -85616,7 +85589,6 @@ Object {
8561685589
],
8561785590
"type": "TSInterfaceBody",
8561885591
},
85619-
"heritage": Array [],
8562085592
"id": Object {
8562185593
"loc": Object {
8562285594
"end": Object {
@@ -85929,7 +85901,6 @@ Object {
8592985901
],
8593085902
"type": "TSInterfaceBody",
8593185903
},
85932-
"heritage": Array [],
8593385904
"id": Object {
8593485905
"loc": Object {
8593585906
"end": Object {
@@ -86260,7 +86231,6 @@ Object {
8626086231
],
8626186232
"type": "TSInterfaceBody",
8626286233
},
86263-
"heritage": Array [],
8626486234
"id": Object {
8626586235
"loc": Object {
8626686236
"end": Object {
@@ -90388,7 +90358,6 @@ Object {
9038890358
],
9038990359
"type": "TSInterfaceBody",
9039090360
},
90391-
"heritage": Array [],
9039290361
"id": Object {
9039390362
"loc": Object {
9039490363
"end": Object {

0 commit comments

Comments
 (0)