mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Adjusts some source map locations. Updates baselines.
This commit is contained in:
+25
-13
@@ -1276,13 +1276,15 @@ const _super = (function (geti, seti) {
|
||||
}
|
||||
|
||||
function emitIfStatement(node: IfStatement) {
|
||||
write("if (");
|
||||
const openParenPos = writeToken(SyntaxKind.IfKeyword, node.pos);
|
||||
write(" ");
|
||||
writeToken(SyntaxKind.OpenParenToken, openParenPos);
|
||||
emitExpression(node.expression);
|
||||
write(")");
|
||||
writeToken(SyntaxKind.CloseParenToken, node.expression.end);
|
||||
emitEmbeddedStatement(node.thenStatement);
|
||||
if (node.elseStatement) {
|
||||
writeLine();
|
||||
write("else");
|
||||
writeToken(SyntaxKind.ElseKeyword, node.thenStatement.end);
|
||||
if (node.elseStatement.kind === SyntaxKind.IfStatement) {
|
||||
write(" ");
|
||||
emit(node.elseStatement);
|
||||
@@ -1329,20 +1331,24 @@ const _super = (function (geti, seti) {
|
||||
}
|
||||
|
||||
function emitForInStatement(node: ForInStatement) {
|
||||
write("for (");
|
||||
const openParenPos = writeToken(SyntaxKind.ForKeyword, node.pos);
|
||||
write(" ");
|
||||
writeToken(SyntaxKind.OpenParenToken, openParenPos);
|
||||
emitForBinding(node.initializer);
|
||||
write(" in ");
|
||||
emitExpression(node.expression);
|
||||
write(")");
|
||||
writeToken(SyntaxKind.CloseParenToken, node.expression.end);
|
||||
emitEmbeddedStatement(node.statement);
|
||||
}
|
||||
|
||||
function emitForOfStatement(node: ForOfStatement) {
|
||||
write("for (");
|
||||
const openParenPos = writeToken(SyntaxKind.ForKeyword, node.pos);
|
||||
write(" ");
|
||||
writeToken(SyntaxKind.OpenParenToken, openParenPos);
|
||||
emitForBinding(node.initializer);
|
||||
write(" of ");
|
||||
emitExpression(node.expression);
|
||||
write(")");
|
||||
writeToken(SyntaxKind.CloseParenToken, node.expression.end);
|
||||
emitEmbeddedStatement(node.statement);
|
||||
}
|
||||
|
||||
@@ -1358,13 +1364,13 @@ const _super = (function (geti, seti) {
|
||||
}
|
||||
|
||||
function emitContinueStatement(node: ContinueStatement) {
|
||||
write("continue");
|
||||
writeToken(SyntaxKind.ContinueKeyword, node.pos);
|
||||
emitWithPrefix(" ", node.label);
|
||||
write(";");
|
||||
}
|
||||
|
||||
function emitBreakStatement(node: BreakStatement) {
|
||||
write("break");
|
||||
writeToken(SyntaxKind.BreakKeyword, node.pos);
|
||||
emitWithPrefix(" ", node.label);
|
||||
write(";");
|
||||
}
|
||||
@@ -1383,9 +1389,12 @@ const _super = (function (geti, seti) {
|
||||
}
|
||||
|
||||
function emitSwitchStatement(node: SwitchStatement) {
|
||||
write("switch (");
|
||||
const openParenPos = writeToken(SyntaxKind.SwitchKeyword, node.pos);
|
||||
write(" ");
|
||||
writeToken(SyntaxKind.OpenParenToken, openParenPos);
|
||||
emitExpression(node.expression);
|
||||
write(") ");
|
||||
writeToken(SyntaxKind.CloseParenToken, node.expression.end);
|
||||
write(" ");
|
||||
emit(node.caseBlock);
|
||||
}
|
||||
|
||||
@@ -1872,9 +1881,12 @@ const _super = (function (geti, seti) {
|
||||
|
||||
function emitCatchClause(node: CatchClause) {
|
||||
writeLine();
|
||||
write("catch (");
|
||||
const openParenPos = writeToken(SyntaxKind.CatchKeyword, node.pos);
|
||||
write(" ");
|
||||
writeToken(SyntaxKind.OpenParenToken, openParenPos);
|
||||
emit(node.variableDeclaration);
|
||||
write(") ");
|
||||
writeToken(SyntaxKind.CloseParenToken, node.variableDeclaration ? node.variableDeclaration.end : openParenPos);
|
||||
write(" ");
|
||||
emit(node.block);
|
||||
}
|
||||
|
||||
|
||||
@@ -612,12 +612,12 @@ namespace ts {
|
||||
enableSubstitutionsForBlockScopedBindings();
|
||||
}
|
||||
|
||||
const baseTypeNode = getClassExtendsHeritageClauseElement(node);
|
||||
const extendsClauseElement = getClassExtendsHeritageClauseElement(node);
|
||||
const classFunction = createFunctionExpression(
|
||||
/*asteriskToken*/ undefined,
|
||||
/*name*/ undefined,
|
||||
baseTypeNode ? [createParameter("_super")] : [],
|
||||
transformClassBody(node, baseTypeNode !== undefined)
|
||||
extendsClauseElement ? [createParameter("_super")] : [],
|
||||
transformClassBody(node, extendsClauseElement)
|
||||
);
|
||||
|
||||
// To preserve the behavior of the old emitter, we explicitly indent
|
||||
@@ -640,8 +640,8 @@ namespace ts {
|
||||
return createParen(
|
||||
createCall(
|
||||
outer,
|
||||
baseTypeNode
|
||||
? [visitNode(baseTypeNode.expression, visitor, isExpression)]
|
||||
extendsClauseElement
|
||||
? [visitNode(extendsClauseElement.expression, visitor, isExpression)]
|
||||
: []
|
||||
)
|
||||
);
|
||||
@@ -651,13 +651,13 @@ namespace ts {
|
||||
* Transforms a ClassExpression or ClassDeclaration into a function body.
|
||||
*
|
||||
* @param node A ClassExpression or ClassDeclaration node.
|
||||
* @param hasExtendsClause A value indicating whether the class has an `extends` clause.
|
||||
* @param extendsClauseElement The expression for the class `extends` clause.
|
||||
*/
|
||||
function transformClassBody(node: ClassExpression | ClassDeclaration, hasExtendsClause: boolean): Block {
|
||||
function transformClassBody(node: ClassExpression | ClassDeclaration, extendsClauseElement: ExpressionWithTypeArguments): Block {
|
||||
const statements: Statement[] = [];
|
||||
startLexicalEnvironment();
|
||||
addExtendsHelperIfNeeded(statements, node, hasExtendsClause);
|
||||
addConstructor(statements, node, hasExtendsClause);
|
||||
addExtendsHelperIfNeeded(statements, node, extendsClauseElement);
|
||||
addConstructor(statements, node, extendsClauseElement);
|
||||
addClassMembers(statements, node);
|
||||
|
||||
// Create a synthetic text range for the return statement.
|
||||
@@ -687,13 +687,14 @@ namespace ts {
|
||||
*
|
||||
* @param statements The statements of the class body function.
|
||||
* @param node The ClassExpression or ClassDeclaration node.
|
||||
* @param hasExtendsClause A value indicating whether the class has an `extends` clause.
|
||||
* @param extendsClauseElement The expression for the class `extends` clause.
|
||||
*/
|
||||
function addExtendsHelperIfNeeded(statements: Statement[], node: ClassExpression | ClassDeclaration, hasExtendsClause: boolean): void {
|
||||
if (hasExtendsClause) {
|
||||
function addExtendsHelperIfNeeded(statements: Statement[], node: ClassExpression | ClassDeclaration, extendsClauseElement: ExpressionWithTypeArguments): void {
|
||||
if (extendsClauseElement) {
|
||||
statements.push(
|
||||
createStatement(
|
||||
createExtendsHelper(getDeclarationName(node))
|
||||
createExtendsHelper(getDeclarationName(node)),
|
||||
/*location*/ extendsClauseElement
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -704,18 +705,18 @@ namespace ts {
|
||||
*
|
||||
* @param statements The statements of the class body function.
|
||||
* @param node The ClassExpression or ClassDeclaration node.
|
||||
* @param hasExtendsClause A value indicating whether the class has an `extends` clause.
|
||||
* @param extendsClauseElement The expression for the class `extends` clause.
|
||||
*/
|
||||
function addConstructor(statements: Statement[], node: ClassExpression | ClassDeclaration, hasExtendsClause: boolean): void {
|
||||
function addConstructor(statements: Statement[], node: ClassExpression | ClassDeclaration, extendsClauseElement: ExpressionWithTypeArguments): void {
|
||||
const constructor = getFirstConstructorWithBody(node);
|
||||
const hasSynthesizedSuper = hasSynthesizedDefaultSuperCall(constructor, hasExtendsClause);
|
||||
const hasSynthesizedSuper = hasSynthesizedDefaultSuperCall(constructor, extendsClauseElement !== undefined);
|
||||
statements.push(
|
||||
createFunctionDeclaration(
|
||||
/*modifiers*/ undefined,
|
||||
/*asteriskToken*/ undefined,
|
||||
getDeclarationName(node),
|
||||
transformConstructorParameters(constructor, hasSynthesizedSuper),
|
||||
transformConstructorBody(constructor, node, hasExtendsClause, hasSynthesizedSuper),
|
||||
transformConstructorBody(constructor, node, extendsClauseElement, hasSynthesizedSuper),
|
||||
/*location*/ constructor || node
|
||||
)
|
||||
);
|
||||
@@ -746,11 +747,11 @@ namespace ts {
|
||||
*
|
||||
* @param constructor The constructor for the class.
|
||||
* @param node The node which contains the constructor.
|
||||
* @param hasExtendsClause A value indicating whether the class has an `extends` clause.
|
||||
* @param extendsClauseElement The expression for the class `extends` clause.
|
||||
* @param hasSynthesizedSuper A value indicating whether the constructor starts with a
|
||||
* synthesized `super` call.
|
||||
*/
|
||||
function transformConstructorBody(constructor: ConstructorDeclaration, node: ClassDeclaration | ClassExpression, hasExtendsClause: boolean, hasSynthesizedSuper: boolean) {
|
||||
function transformConstructorBody(constructor: ConstructorDeclaration, node: ClassDeclaration | ClassExpression, extendsClauseElement: ExpressionWithTypeArguments, hasSynthesizedSuper: boolean) {
|
||||
const statements: Statement[] = [];
|
||||
startLexicalEnvironment();
|
||||
if (constructor) {
|
||||
@@ -759,7 +760,7 @@ namespace ts {
|
||||
addRestParameterIfNeeded(statements, constructor, hasSynthesizedSuper);
|
||||
}
|
||||
|
||||
addDefaultSuperCallIfNeeded(statements, constructor, hasExtendsClause, hasSynthesizedSuper);
|
||||
addDefaultSuperCallIfNeeded(statements, constructor, extendsClauseElement, hasSynthesizedSuper);
|
||||
|
||||
if (constructor) {
|
||||
const body = saveStateAndInvoke(constructor, hasSynthesizedSuper ? transformConstructorBodyWithSynthesizedSuper : transformConstructorBodyWithoutSynthesizedSuper);
|
||||
@@ -796,24 +797,25 @@ namespace ts {
|
||||
*
|
||||
* @param statements The statements for the new constructor body.
|
||||
* @param constructor The constructor for the class.
|
||||
* @param hasExtendsClause A value indicating whether the class has an `extends` clause.
|
||||
* @param extendsClauseElement The expression for the class `extends` clause.
|
||||
* @param hasSynthesizedSuper A value indicating whether the constructor starts with a
|
||||
* synthesized `super` call.
|
||||
*/
|
||||
function addDefaultSuperCallIfNeeded(statements: Statement[], constructor: ConstructorDeclaration, hasExtendsClause: boolean, hasSynthesizedSuper: boolean) {
|
||||
function addDefaultSuperCallIfNeeded(statements: Statement[], constructor: ConstructorDeclaration, extendsClauseElement: ExpressionWithTypeArguments, hasSynthesizedSuper: boolean) {
|
||||
// If the TypeScript transformer needed to synthesize a constructor for property
|
||||
// initializers, it would have also added a synthetic `...args` parameter and
|
||||
// `super` call.
|
||||
// If this is the case, or if the class has an `extends` clause but no
|
||||
// constructor, we emit a synthesized call to `_super`.
|
||||
if (constructor ? hasSynthesizedSuper : hasExtendsClause) {
|
||||
if (constructor ? hasSynthesizedSuper : extendsClauseElement) {
|
||||
statements.push(
|
||||
createStatement(
|
||||
createFunctionApply(
|
||||
createIdentifier("_super"),
|
||||
createThis(),
|
||||
createIdentifier("arguments")
|
||||
)
|
||||
),
|
||||
/*location*/ extendsClauseElement
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -1669,7 +1671,7 @@ namespace ts {
|
||||
visitor
|
||||
)
|
||||
),
|
||||
/*location*/ initializer
|
||||
/*location*/ moveRangeEnd(initializer, -1)
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -1684,8 +1686,8 @@ namespace ts {
|
||||
firstDeclaration ? firstDeclaration.name : createTempVariable(/*recordTempVariable*/ undefined),
|
||||
createElementAccess(rhsReference, counter)
|
||||
)
|
||||
]),
|
||||
/*location*/ initializer
|
||||
], /*location*/ moveRangePos(initializer, -1)),
|
||||
/*location*/ moveRangeEnd(initializer, -1)
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -1709,7 +1711,8 @@ namespace ts {
|
||||
);
|
||||
}
|
||||
else {
|
||||
statements.push(createStatement(assignment, /*location*/ node.initializer));
|
||||
assignment.end = initializer.end;
|
||||
statements.push(createStatement(assignment, /*location*/ moveRangeEnd(initializer, -1)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1726,10 +1729,13 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
// The old emitter does not emit source maps for the expression
|
||||
setNodeEmitFlags(expression, NodeEmitFlags.NoSourceMap | getNodeEmitFlags(expression));
|
||||
|
||||
return createFor(
|
||||
createVariableDeclarationList(
|
||||
[
|
||||
createVariableDeclaration(counter, createLiteral(0), /*location*/ node.expression),
|
||||
createVariableDeclaration(counter, createLiteral(0), /*location*/ moveRangePos(node.expression, -1)),
|
||||
createVariableDeclaration(rhsReference, expression, /*location*/ node.expression)
|
||||
],
|
||||
/*location*/ node.expression
|
||||
@@ -1737,9 +1743,9 @@ namespace ts {
|
||||
createLessThan(
|
||||
counter,
|
||||
createPropertyAccess(rhsReference, "length"),
|
||||
/*location*/ initializer
|
||||
/*location*/ node.expression
|
||||
),
|
||||
createPostfixIncrement(counter, /*location*/ initializer),
|
||||
createPostfixIncrement(counter, /*location*/ node.expression),
|
||||
createBlock(
|
||||
statements
|
||||
),
|
||||
|
||||
@@ -2660,13 +2660,22 @@ namespace ts {
|
||||
}
|
||||
|
||||
function addExportMemberAssignment(statements: Statement[], node: DeclarationStatement) {
|
||||
statements.push(createNamespaceExport(getDeclarationName(node), getDeclarationName(node)));
|
||||
statements.push(
|
||||
createStatement(
|
||||
createAssignment(
|
||||
getExportName(node),
|
||||
getLocalName(node, /*noSourceMaps*/ true),
|
||||
/*location*/ node
|
||||
),
|
||||
/*location*/ moveRangePos(node, -1)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function createNamespaceExport(exportName: Identifier, exportValue: Expression, location?: TextRange) {
|
||||
return createStatement(
|
||||
createAssignment(
|
||||
getNamespaceMemberName(exportName),
|
||||
getNamespaceMemberName(exportName, /*allowComments*/ false, /*allowSourceMaps*/ true),
|
||||
exportValue
|
||||
),
|
||||
location
|
||||
@@ -2720,11 +2729,11 @@ namespace ts {
|
||||
* "exports.".
|
||||
*
|
||||
* @param node The declaration.
|
||||
* @param noSourceMaps A value indicating whether source maps may not be emitted for the name.
|
||||
* @param allowComments A value indicating whether comments may be emitted for the name.
|
||||
* @param allowSourceMaps A value indicating whether source maps may be emitted for the name.
|
||||
*/
|
||||
function getLocalName(node: ClassDeclaration | FunctionDeclaration | ModuleDeclaration | EnumDeclaration, allowComments?: boolean) {
|
||||
return getDeclarationName(node, allowComments, /*allowSourceMaps*/ true, NodeEmitFlags.LocalName);
|
||||
function getLocalName(node: DeclarationStatement | ClassExpression, noSourceMaps?: boolean, allowComments?: boolean) {
|
||||
return getDeclarationName(node, allowComments, !noSourceMaps, NodeEmitFlags.LocalName);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2734,15 +2743,15 @@ namespace ts {
|
||||
* like "exports." if one is required.
|
||||
*
|
||||
* @param node The declaration.
|
||||
* @param noSourceMaps A value indicating whether source maps may not be emitted for the name.
|
||||
* @param allowComments A value indicating whether comments may be emitted for the name.
|
||||
* @param allowSourceMaps A value indicating whether source maps may be emitted for the name.
|
||||
*/
|
||||
function getExportName(node: ClassDeclaration | FunctionDeclaration | ModuleDeclaration | EnumDeclaration, allowComments?: boolean) {
|
||||
function getExportName(node: DeclarationStatement | ClassExpression, noSourceMaps?: boolean, allowComments?: boolean) {
|
||||
if (isNamespaceExport(node)) {
|
||||
return getNamespaceMemberName(getDeclarationName(node), allowComments, /*allowSourceMaps*/ true);
|
||||
return getNamespaceMemberName(getDeclarationName(node), allowComments, !noSourceMaps);
|
||||
}
|
||||
|
||||
return getDeclarationName(node, allowComments, /*allowSourceMaps*/ true, NodeEmitFlags.ExportName);
|
||||
return getDeclarationName(node, allowComments, !noSourceMaps, NodeEmitFlags.ExportName);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user