Add a source mapping to the closing } for functions, and wire in positions for class transfomtaion

This commit is contained in:
Mohamed Hegazy
2016-04-07 16:17:58 -07:00
parent 2901425d41
commit 68170dfbdb
2 changed files with 16 additions and 14 deletions
+6 -8
View File
@@ -1095,7 +1095,7 @@ const _super = (function (geti, seti) {
}
function emitPrefixUnaryExpression(node: PrefixUnaryExpression) {
writeToken(node.operator);
writeTokenText(node.operator);
if (shouldEmitWhitespaceBeforeOperand(node)) {
write(" ");
}
@@ -1123,7 +1123,7 @@ const _super = (function (geti, seti) {
function emitPostfixUnaryExpression(node: PostfixUnaryExpression) {
emitExpression(node.operand);
writeToken(node.operator);
writeTokenText(node.operator);
}
function emitBinaryExpression(node: BinaryExpression) {
@@ -1419,8 +1419,7 @@ const _super = (function (geti, seti) {
emitSignatureHead(node);
write(" {");
emitBlockFunctionBody(node, body);
write("}");
writeToken(SyntaxKind.CloseBraceToken, node.end)
if (indentedFlag) {
decreaseIndent();
}
@@ -1826,7 +1825,7 @@ const _super = (function (geti, seti) {
function emitHeritageClause(node: HeritageClause) {
write(" ");
writeToken(node.token);
writeTokenText(node.token);
write(" ");
emitList(node, node.types, ListFormat.HeritageClauseTypes);
}
@@ -2275,10 +2274,9 @@ const _super = (function (geti, seti) {
}
}
function writeToken(token: SyntaxKind, pos?: number) {
const tokenStartPos = skipTrivia(currentText, pos);
function writeToken(token: SyntaxKind, tokenStartPos: number) {
emitPos(tokenStartPos);
const tokenEndPos = writeTokenText(token, pos);
const tokenEndPos = writeTokenText(token, tokenStartPos);
emitPos(tokenEndPos);
return tokenEndPos;
}
+10 -6
View File
@@ -609,12 +609,14 @@ namespace ts {
if (node.name) {
enableSubstitutionsForBlockScopedBindings();
}
const closingBraceLocation = { pos: node.end - 1, end: node.end };
const baseTypeNode = getClassExtendsHeritageClauseElement(node);
const classFunction = createFunctionExpression(
/*asteriskToken*/ undefined,
/*name*/ undefined,
baseTypeNode ? [createParameter("_super")] : [],
transformClassBody(node, baseTypeNode !== undefined)
transformClassBody(node, baseTypeNode !== undefined, closingBraceLocation),
closingBraceLocation
);
// To preserve the behavior of the old emitter, we explicitly indent
@@ -629,8 +631,10 @@ namespace ts {
classFunction,
baseTypeNode
? [visitNode(baseTypeNode.expression, visitor, isExpression)]
: []
)
: [],
closingBraceLocation
),
closingBraceLocation
);
}
@@ -640,13 +644,13 @@ namespace ts {
* @param node A ClassExpression or ClassDeclaration node.
* @param hasExtendsClause A value indicating whether the class has an `extends` clause.
*/
function transformClassBody(node: ClassExpression | ClassDeclaration, hasExtendsClause: boolean): Block {
function transformClassBody(node: ClassExpression | ClassDeclaration, hasExtendsClause: boolean, closingBraceLocation: TextRange): Block {
const statements: Statement[] = [];
startLexicalEnvironment();
addExtendsHelperIfNeeded(statements, node, hasExtendsClause);
addConstructor(statements, node, hasExtendsClause);
addClassMembers(statements, node);
statements.push(createReturn(getDeclarationName(node)));
statements.push(createReturn(getDeclarationName(node), /*location*/ closingBraceLocation));
addRange(statements, endLexicalEnvironment());
return createBlock(statements, /*location*/ undefined, /*multiLine*/ true);
}
@@ -685,7 +689,7 @@ namespace ts {
getDeclarationName(node),
transformConstructorParameters(constructor, hasSynthesizedSuper),
transformConstructorBody(constructor, hasExtendsClause, hasSynthesizedSuper),
/*location*/ constructor
/*location*/ constructor || node
)
);
}