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

fix: wrap interface in ExportNamedDeclaration if necessary (fixes #269 #270

Merged
merged 1 commit into from
May 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -1703,6 +1703,7 @@ module.exports = function convert(config) {
}

const hasImplementsClause = interfaceHeritageClauses.length > 0;
const hasAbstractKeyword = nodeUtils.hasModifier(SyntaxKind.AbstractKeyword, node);
const interfaceOpenBrace = nodeUtils.findNextToken(interfaceLastClassToken, ast);

const interfaceBody = {
Expand All @@ -1713,11 +1714,16 @@ module.exports = function convert(config) {
};

Object.assign(result, {
abstract: hasAbstractKeyword,
type: AST_NODE_TYPES.TSInterfaceDeclaration,
body: interfaceBody,
id: convertChild(node.name),
heritage: hasImplementsClause ? interfaceHeritageClauses[0].types.map(convertInterfaceHeritageClause) : []
});

// check for exports
result = nodeUtils.fixExports(node, result, ast);

break;

}
Expand Down
204 changes: 204 additions & 0 deletions tests/fixtures/typescript/basics/abstract-interface.result.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
module.exports = {
"type": "Program",
"range": [
0,
31
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 1
}
},
"body": [
{
"type": "ExportNamedDeclaration",
"declaration": {
"type": "TSInterfaceDeclaration",
"range": [
16,
31
],
"loc": {
"start": {
"line": 1,
"column": 16
},
"end": {
"line": 2,
"column": 1
}
},
"abstract": true,
"body": {
"type": "TSInterfaceBody",
"body": [],
"range": [
28,
31
],
"loc": {
"start": {
"line": 1,
"column": 28
},
"end": {
"line": 2,
"column": 1
}
}
},
"id": {
"type": "Identifier",
"range": [
26,
27
],
"loc": {
"start": {
"line": 1,
"column": 26
},
"end": {
"line": 1,
"column": 27
}
},
"name": "I"
},
"heritage": []
},
"range": [
0,
31
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 2,
"column": 1
}
},
"specifiers": [],
"source": null
}
],
"sourceType": "module",
"tokens": [
{
"type": "Keyword",
"value": "export",
"range": [
0,
6
],
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 6
}
}
},
{
"type": "Identifier",
"value": "abstract",
"range": [
7,
15
],
"loc": {
"start": {
"line": 1,
"column": 7
},
"end": {
"line": 1,
"column": 15
}
}
},
{
"type": "Keyword",
"value": "interface",
"range": [
16,
25
],
"loc": {
"start": {
"line": 1,
"column": 16
},
"end": {
"line": 1,
"column": 25
}
}
},
{
"type": "Identifier",
"value": "I",
"range": [
26,
27
],
"loc": {
"start": {
"line": 1,
"column": 26
},
"end": {
"line": 1,
"column": 27
}
}
},
{
"type": "Punctuator",
"value": "{",
"range": [
28,
29
],
"loc": {
"start": {
"line": 1,
"column": 28
},
"end": {
"line": 1,
"column": 29
}
}
},
{
"type": "Punctuator",
"value": "}",
"range": [
30,
31
],
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 1
}
}
}
]
};
2 changes: 2 additions & 0 deletions tests/fixtures/typescript/basics/abstract-interface.src.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export abstract interface I {
}
82 changes: 41 additions & 41 deletions tests/fixtures/typescript/basics/class-with-mixin.result.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,59 +301,59 @@ module.exports = {
"name": "Constructor"
},
"typeParameters": {
"type": "TypeParameterInstantiation",
"range": [
32,
36
],
"loc": {
"end": {
"column": 36,
"line": 1
},
"start": {
"column": 32,
"line": 1
"line": 1,
"column": 32
},
"end": {
"line": 1,
"column": 36
}
},
"params": [
{
"id": {
"loc": {
"end": {
"column": 35,
"line": 1
},
"start": {
"column": 33,
"line": 1
}
"type": "GenericTypeAnnotation",
"range": [
33,
35
],
"loc": {
"start": {
"line": 1,
"column": 33
},
"members": [],
"end": {
"line": 1,
"column": 35
}
},
"id": {
"type": "TSTypeLiteral",
"range": [
33,
35
],
"type": "TSTypeLiteral"
},
"loc": {
"end": {
"column": 35,
"line": 1
"loc": {
"start": {
"line": 1,
"column": 33
},
"end": {
"line": 1,
"column": 35
}
},
"start": {
"column": 33,
"line": 1
}
"members": []
},
"range": [
33,
35
],
"type": "GenericTypeAnnotation",
"typeParameters": null
}
],
"range": [
32,
36
],
"type": "TypeParameterInstantiation"
]
}
}
}
Expand Down Expand Up @@ -633,6 +633,7 @@ module.exports = {
"column": 15
}
},
"abstract": false,
"body": {
"type": "TSInterfaceBody",
"body": [],
Expand Down Expand Up @@ -691,7 +692,6 @@ module.exports = {
"declarations": [
{
"type": "VariableDeclarator",
"typeParameters": null,
"id": {
"type": "Identifier",
"range": [
Expand Down Expand Up @@ -726,6 +726,7 @@ module.exports = {
"column": 47
}
},
"typeParameters": null,
"parameters": [
{
"type": "RestElement",
Expand Down Expand Up @@ -814,7 +815,6 @@ module.exports = {
}
}
],
"typeParameters": null,
"typeAnnotation": {
"type": "TypeAnnotation",
"loc": {
Expand Down Expand Up @@ -2079,4 +2079,4 @@ module.exports = {
}
}
]
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module.exports = {
"column": 1
}
},
"abstract": false,
"body": {
"type": "TSInterfaceBody",
"body": [],
Expand Down Expand Up @@ -288,4 +289,4 @@ module.exports = {
}
}
]
};
};
Loading