mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Add a source mapping to the closing } for functions, and wire in positions for class transfomtaion
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user