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

Fix: error on multiple super classes (fixes #493) #494

Merged
merged 4 commits into from
Jun 27, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 1 addition & 7 deletions lib/ast-converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,7 @@ const convert = require("./convert"),
* @returns {Object} converted error object
*/
function convertError(error) {
const loc = error.file.getLineAndCharacterOfPosition(error.start);
return {
index: error.start,
lineNumber: loc.line + 1,
column: loc.character,
message: error.message || error.messageText
};
return nodeUtils.createError(error.file, error.start, error.message || error.messageText);
}

//------------------------------------------------------------------------------
Expand Down
10 changes: 8 additions & 2 deletions lib/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -1397,8 +1397,14 @@ module.exports = function convert(config) {
const openBrace = nodeUtils.findNextToken(lastClassToken, ast);
const superClass = heritageClauses.find(clause => clause.token === SyntaxKind.ExtendsKeyword);

if (superClass && superClass.types[0] && superClass.types[0].typeArguments) {
result.superTypeParameters = convertTypeArgumentsToTypeParameters(superClass.types[0].typeArguments);
if (superClass) {
if (superClass.types.length > 1) {
throw nodeUtils.createError(ast, superClass.types[1].pos, "Classes can only extend a single class.");
}

if (superClass.types[0] && superClass.types[0].typeArguments) {
result.superTypeParameters = convertTypeArgumentsToTypeParameters(superClass.types[0].typeArguments);
}
}

const implementsClause = heritageClauses.find(clause => clause.token === SyntaxKind.ImplementsKeyword);
Expand Down
19 changes: 18 additions & 1 deletion lib/node-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ module.exports = {
isWithinTypeAnnotation,
isTypeKeyword,
isComment,
isJSDocComment
isJSDocComment,
createError
};
/* eslint-enable no-use-before-define */

Expand Down Expand Up @@ -765,3 +766,19 @@ function getNodeContainer(ast, start, end) {

return container;
}

/**
* @param {Object} ast the AST object
* @param {int} start the index at which the error starts
* @param {string} message the error message
* @returns {Object} converted error object
*/
function createError(ast, start, message) {
const loc = ast.getLineAndCharacterOfPosition(start);
return {
index: start,
lineNumber: loc.line + 1,
column: loc.character,
message
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class A extends B, C {}