Make most current Node factory functions public

This commit is contained in:
Ron Buckton
2017-02-01 16:36:10 -08:00
parent bc611d9e7d
commit ff4c72de00
17 changed files with 2056 additions and 1798 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1152,13 +1152,10 @@ namespace ts {
&& (options.isolatedModules || isExternalModuleFile)
&& !file.isDeclarationFile) {
// synthesize 'import "tslib"' declaration
const externalHelpersModuleReference = <StringLiteral>createSynthesizedNode(SyntaxKind.StringLiteral);
externalHelpersModuleReference.text = externalHelpersModuleNameText;
const importDecl = createSynthesizedNode(SyntaxKind.ImportDeclaration);
importDecl.parent = file;
const externalHelpersModuleReference = createLiteral(externalHelpersModuleNameText);
const importDecl = createImportDeclaration(undefined, undefined, undefined);
externalHelpersModuleReference.parent = importDecl;
importDecl.parent = file;
imports = [externalHelpersModuleReference];
}

View File

@@ -112,7 +112,10 @@ namespace ts {
Debug.assertNode(target, createAssignmentCallback ? isIdentifier : isExpression);
const expression = createAssignmentCallback
? createAssignmentCallback(<Identifier>target, value, location)
: createAssignment(visitNode(<Expression>target, visitor, isExpression), value, location);
: setTextRange(
createAssignment(visitNode(<Expression>target, visitor, isExpression), value),
location
);
expression.original = original;
emitExpression(expression);
}
@@ -174,9 +177,10 @@ namespace ts {
const variable = createVariableDeclaration(
name,
/*type*/ undefined,
pendingExpressions ? inlineExpressions(append(pendingExpressions, value)) : value,
location);
pendingExpressions ? inlineExpressions(append(pendingExpressions, value)) : value
);
variable.original = original;
setTextRange(variable, location);
if (isIdentifier(name)) {
setEmitFlags(variable, EmitFlags.NoNestedSourceMaps);
}
@@ -416,7 +420,7 @@ namespace ts {
const temp = createTempVariable(/*recordTempVariable*/ undefined);
if (flattenContext.hoistTempVariables) {
flattenContext.context.hoistVariableDeclaration(temp);
flattenContext.emitExpression(createAssignment(temp, value, location));
flattenContext.emitExpression(setTextRange(createAssignment(temp, value), location));
}
else {
flattenContext.emitBindingOrAssignment(temp, value, location, /*original*/ undefined);
@@ -492,6 +496,15 @@ namespace ts {
}
}
}
return createCall(getHelperName("__rest"), undefined, [value, createArrayLiteral(propertyNames, location)]);
return createCall(
getHelperName("__rest"),
undefined,
[
value,
setTextRange(
createArrayLiteral(propertyNames),
location
)
]);
}
}

View File

@@ -514,7 +514,7 @@ namespace ts {
exitSubtree(ancestorFacts, HierarchyFacts.None, HierarchyFacts.None);
return updateSourceFileNode(
node,
createNodeArray(statements, node.statements)
setTextRange(createNodeArray(statements), node.statements)
);
}
@@ -671,9 +671,10 @@ namespace ts {
setOriginalNode(variable, node);
const statements: Statement[] = [];
const statement = createVariableStatement(/*modifiers*/ undefined, createVariableDeclarationList([variable]), /*location*/ node);
const statement = createVariableStatement(/*modifiers*/ undefined, createVariableDeclarationList([variable]));
setOriginalNode(statement, node);
setTextRange(statement, node);
startOnNewLine(statement);
statements.push(statement);
@@ -818,7 +819,7 @@ namespace ts {
addRange(statements, endLexicalEnvironment());
const block = createBlock(createNodeArray(statements, /*location*/ node.members), /*location*/ undefined, /*multiLine*/ true);
const block = createBlock(setTextRange(createNodeArray(statements), /*location*/ node.members), /*multiLine*/ true);
setEmitFlags(block, EmitFlags.NoComments);
return block;
}
@@ -833,8 +834,10 @@ namespace ts {
function addExtendsHelperIfNeeded(statements: Statement[], node: ClassExpression | ClassDeclaration, extendsClauseElement: ExpressionWithTypeArguments): void {
if (extendsClauseElement) {
statements.push(
createStatement(
createExtendsHelper(context, getLocalName(node)),
setTextRange(
createStatement(
createExtendsHelper(context, getLocalName(node))
),
/*location*/ extendsClauseElement
)
);
@@ -854,19 +857,18 @@ namespace ts {
const ancestorFacts = enterSubtree(HierarchyFacts.ConstructorExcludes, HierarchyFacts.ConstructorIncludes);
const constructor = getFirstConstructorWithBody(node);
const hasSynthesizedSuper = hasSynthesizedDefaultSuperCall(constructor, extendsClauseElement !== undefined);
const constructorFunction =
createFunctionDeclaration(
/*decorators*/ undefined,
/*modifiers*/ undefined,
/*asteriskToken*/ undefined,
getDeclarationName(node),
/*typeParameters*/ undefined,
transformConstructorParameters(constructor, hasSynthesizedSuper),
/*type*/ undefined,
transformConstructorBody(constructor, node, extendsClauseElement, hasSynthesizedSuper),
/*location*/ constructor || node
);
const constructorFunction = createFunctionDeclaration(
/*decorators*/ undefined,
/*modifiers*/ undefined,
/*asteriskToken*/ undefined,
getDeclarationName(node),
/*typeParameters*/ undefined,
transformConstructorParameters(constructor, hasSynthesizedSuper),
/*type*/ undefined,
transformConstructorBody(constructor, node, extendsClauseElement, hasSynthesizedSuper)
);
setTextRange(constructorFunction, constructor || node);
if (extendsClauseElement) {
setEmitFlags(constructorFunction, EmitFlags.CapturesThis);
}
@@ -962,14 +964,16 @@ namespace ts {
}
const block = createBlock(
createNodeArray(
statements,
setTextRange(
createNodeArray(
statements
),
/*location*/ constructor ? constructor.body.statements : node.members
),
/*location*/ constructor ? constructor.body : node,
/*multiLine*/ true
);
setTextRange(block, constructor ? constructor.body : node);
if (!constructor) {
setEmitFlags(block, EmitFlags.NoComments);
}
@@ -1139,14 +1143,16 @@ namespace ts {
// Binding patterns are converted into a generated name and are
// evaluated inside the function body.
return setOriginalNode(
createParameter(
/*decorators*/ undefined,
/*modifiers*/ undefined,
/*dotDotDotToken*/ undefined,
getGeneratedNameForNode(node),
/*questionToken*/ undefined,
/*type*/ undefined,
/*initializer*/ undefined,
setTextRange(
createParameter(
/*decorators*/ undefined,
/*modifiers*/ undefined,
/*dotDotDotToken*/ undefined,
getGeneratedNameForNode(node),
/*questionToken*/ undefined,
/*type*/ undefined,
/*initializer*/ undefined
),
/*location*/ node
),
/*original*/ node
@@ -1155,14 +1161,16 @@ namespace ts {
else if (node.initializer) {
// Initializers are elided
return setOriginalNode(
createParameter(
/*decorators*/ undefined,
/*modifiers*/ undefined,
/*dotDotDotToken*/ undefined,
node.name,
/*questionToken*/ undefined,
/*type*/ undefined,
/*initializer*/ undefined,
setTextRange(
createParameter(
/*decorators*/ undefined,
/*modifiers*/ undefined,
/*dotDotDotToken*/ undefined,
node.name,
/*questionToken*/ undefined,
/*type*/ undefined,
/*initializer*/ undefined
),
/*location*/ node
),
/*original*/ node
@@ -1274,21 +1282,25 @@ namespace ts {
const statement = createIf(
createTypeCheck(getSynthesizedClone(name), "undefined"),
setEmitFlags(
createBlock([
createStatement(
createAssignment(
setEmitFlags(getMutableClone(name), EmitFlags.NoSourceMap),
setEmitFlags(initializer, EmitFlags.NoSourceMap | getEmitFlags(initializer)),
/*location*/ parameter
setTextRange(
createBlock([
createStatement(
setTextRange(
createAssignment(
setEmitFlags(getMutableClone(name), EmitFlags.NoSourceMap),
setEmitFlags(initializer, EmitFlags.NoSourceMap | getEmitFlags(initializer))
),
parameter
)
)
)
], /*location*/ parameter),
]),
parameter
),
EmitFlags.SingleLine | EmitFlags.NoTrailingSourceMap | EmitFlags.NoTokenSourceMaps
),
/*elseStatement*/ undefined,
/*location*/ parameter
)
);
statement.startsOnNewLine = true;
setTextRange(statement, parameter);
setEmitFlags(statement, EmitFlags.NoTokenSourceMaps | EmitFlags.NoTrailingSourceMap | EmitFlags.CustomPrologue);
statements.push(statement);
}
@@ -1332,15 +1344,17 @@ namespace ts {
// var param = [];
statements.push(
setEmitFlags(
createVariableStatement(
/*modifiers*/ undefined,
createVariableDeclarationList([
createVariableDeclaration(
declarationName,
/*type*/ undefined,
createArrayLiteral([])
)
]),
setTextRange(
createVariableStatement(
/*modifiers*/ undefined,
createVariableDeclarationList([
createVariableDeclaration(
declarationName,
/*type*/ undefined,
createArrayLiteral([])
)
])
),
/*location*/ parameter
),
EmitFlags.CustomPrologue
@@ -1351,26 +1365,33 @@ namespace ts {
// param[_i - restIndex] = arguments[_i];
// }
const forStatement = createFor(
createVariableDeclarationList([
createVariableDeclaration(temp, /*type*/ undefined, createLiteral(restIndex))
], /*location*/ parameter),
createLessThan(
temp,
createPropertyAccess(createIdentifier("arguments"), "length"),
/*location*/ parameter
setTextRange(
createVariableDeclarationList([
createVariableDeclaration(temp, /*type*/ undefined, createLiteral(restIndex))
]),
parameter
),
createPostfixIncrement(temp, /*location*/ parameter),
setTextRange(
createLessThan(
temp,
createPropertyAccess(createIdentifier("arguments"), "length")
),
parameter
),
setTextRange(createPostfixIncrement(temp), parameter),
createBlock([
startOnNewLine(
createStatement(
createAssignment(
createElementAccess(
expressionName,
restIndex === 0
? temp
: createSubtract(temp, createLiteral(restIndex))
),
createElementAccess(createIdentifier("arguments"), temp)
setTextRange(
createStatement(
createAssignment(
createElementAccess(
expressionName,
restIndex === 0
? temp
: createSubtract(temp, createLiteral(restIndex))
),
createElementAccess(createIdentifier("arguments"), temp)
)
),
/*location*/ parameter
)
@@ -1405,11 +1426,10 @@ namespace ts {
/*type*/ undefined,
initializer
)
]),
originalStatement
])
);
setEmitFlags(captureThisStatement, EmitFlags.NoComments | EmitFlags.CustomPrologue);
setTextRange(captureThisStatement, originalStatement);
setSourceMapRange(captureThisStatement, node);
statements.push(captureThisStatement);
}
@@ -1529,7 +1549,7 @@ namespace ts {
* @param member The SemicolonClassElement node.
*/
function transformSemicolonClassElementToStatement(member: SemicolonClassElement) {
return createEmptyStatement(/*location*/ member);
return setTextRange(createEmptyStatement(), member);
}
/**
@@ -1547,8 +1567,10 @@ namespace ts {
setEmitFlags(memberFunction, EmitFlags.NoComments);
setSourceMapRange(memberFunction, sourceMapRange);
const statement = createStatement(
createAssignment(memberName, memberFunction),
const statement = setTextRange(
createStatement(
createAssignment(memberName, memberFunction)
),
/*location*/ member
);
@@ -1571,15 +1593,12 @@ namespace ts {
* @param accessors The set of related get/set accessors.
*/
function transformAccessorsToStatement(receiver: LeftHandSideExpression, accessors: AllAccessorDeclarations, container: Node): Statement {
const statement = createStatement(
transformAccessorsToExpression(receiver, accessors, container, /*startsOnNewLine*/ false),
/*location*/ getSourceMapRange(accessors.firstAccessor)
);
const statement = createStatement(transformAccessorsToExpression(receiver, accessors, container, /*startsOnNewLine*/ false));
// The location for the statement is used to emit source maps only.
// No comments should be emitted for this statement to align with the
// old emitter.
setEmitFlags(statement, EmitFlags.NoComments);
setSourceMapRange(statement, getSourceMapRange(accessors.firstAccessor));
return statement;
}
@@ -1622,8 +1641,8 @@ namespace ts {
}
properties.push(
createPropertyAssignment("enumerable", createLiteral(true)),
createPropertyAssignment("configurable", createLiteral(true))
createPropertyAssignment("enumerable", createTrue()),
createPropertyAssignment("configurable", createTrue())
);
const call = createCall(
@@ -1632,7 +1651,7 @@ namespace ts {
[
target,
propertyName,
createObjectLiteral(properties, /*location*/ undefined, /*multiLine*/ true)
createObjectLiteral(properties, /*multiLine*/ true)
]
);
if (startsOnNewLine) {
@@ -1662,9 +1681,9 @@ namespace ts {
/*typeParameters*/ undefined,
visitParameterList(node.parameters, visitor, context),
/*type*/ undefined,
transformFunctionBody(node),
node
transformFunctionBody(node)
);
setTextRange(func, node);
setOriginalNode(func, node);
setEmitFlags(func, EmitFlags.CapturesThis);
exitSubtree(ancestorFacts, HierarchyFacts.None, HierarchyFacts.None);
@@ -1758,14 +1777,16 @@ namespace ts {
exitSubtree(ancestorFacts, HierarchyFacts.PropagateNewTargetMask, HierarchyFacts.None);
convertedLoopState = savedConvertedLoopState;
return setOriginalNode(
createFunctionExpression(
/*modifiers*/ undefined,
node.asteriskToken,
name,
/*typeParameters*/ undefined,
parameters,
/*type*/ undefined,
body,
setTextRange(
createFunctionExpression(
/*modifiers*/ undefined,
node.asteriskToken,
name,
/*typeParameters*/ undefined,
parameters,
/*type*/ undefined,
body
),
location
),
/*original*/ node
@@ -1832,7 +1853,8 @@ namespace ts {
}
const expression = visitNode(body, visitor, isExpression);
const returnStatement = createReturn(expression, /*location*/ body);
const returnStatement = createReturn(expression);
setTextRange(returnStatement, body);
setEmitFlags(returnStatement, EmitFlags.NoTokenSourceMaps | EmitFlags.NoTrailingSourceMap | EmitFlags.NoTrailingComments);
statements.push(returnStatement);
@@ -1851,7 +1873,8 @@ namespace ts {
multiLine = true;
}
const block = createBlock(createNodeArray(statements, statementsLocation), node.body, multiLine);
const block = createBlock(setTextRange(createNodeArray(statements), statementsLocation), multiLine);
setTextRange(block, node.body);
if (!multiLine && singleLine) {
setEmitFlags(block, EmitFlags.SingleLine);
}
@@ -1868,8 +1891,10 @@ namespace ts {
const updated = visitFunctionBody(node.body, functionBodyVisitor, context);
return updateBlock(
updated,
createNodeArray(
prependCaptureNewTargetIfNeeded(updated.statements, node, /*copyOnWrite*/ true),
setTextRange(
createNodeArray(
prependCaptureNewTargetIfNeeded(updated.statements, node, /*copyOnWrite*/ true)
),
/*location*/ updated.statements
)
);
@@ -1969,7 +1994,7 @@ namespace ts {
}
}
if (assignments) {
updated = createStatement(reduceLeft(assignments, (acc, v) => createBinary(v, SyntaxKind.CommaToken, acc)), node);
updated = setTextRange(createStatement(reduceLeft(assignments, (acc, v) => createBinary(v, SyntaxKind.CommaToken, acc))), node);
}
else {
// none of declarations has initializer - the entire variable statement can be deleted
@@ -1999,8 +2024,9 @@ namespace ts {
? visitVariableDeclarationInLetDeclarationList
: visitVariableDeclaration));
const declarationList = createVariableDeclarationList(declarations, /*location*/ node);
const declarationList = createVariableDeclarationList(declarations);
setOriginalNode(declarationList, node);
setTextRange(declarationList, node);
setCommentRange(declarationList, node);
if (node.transformFlags & TransformFlags.ContainsBindingPattern
@@ -2248,8 +2274,9 @@ namespace ts {
elementAccess
);
const declarationList = createVariableDeclarationList(declarations, /*location*/ initializer);
const declarationList = createVariableDeclarationList(declarations);
setOriginalNode(declarationList, initializer);
setTextRange(declarationList, initializer);
// Adjust the source map range for the first declaration to align with the old
// emitter.
@@ -2268,19 +2295,24 @@ namespace ts {
// The following call does not include the initializer, so we have
// to emit it separately.
statements.push(
createVariableStatement(
/*modifiers*/ undefined,
setOriginalNode(
createVariableDeclarationList([
createVariableDeclaration(
firstOriginalDeclaration ? firstOriginalDeclaration.name : createTempVariable(/*recordTempVariable*/ undefined),
/*type*/ undefined,
createElementAccess(rhsReference, counter)
)
], /*location*/ moveRangePos(initializer, -1)),
initializer
setTextRange(
createVariableStatement(
/*modifiers*/ undefined,
setOriginalNode(
setTextRange(
createVariableDeclarationList([
createVariableDeclaration(
firstOriginalDeclaration ? firstOriginalDeclaration.name : createTempVariable(/*recordTempVariable*/ undefined),
/*type*/ undefined,
createElementAccess(rhsReference, counter)
)
]),
moveRangePos(initializer, -1)
),
initializer
)
),
/*location*/ moveRangeEnd(initializer, -1)
moveRangeEnd(initializer, -1)
)
);
}
@@ -2306,7 +2338,7 @@ namespace ts {
// Currently there is not way to check that assignment is binary expression of destructing assignment
// so we have to cast never type to binaryExpression
(<BinaryExpression>assignment).end = initializer.end;
statements.push(createStatement(assignment, /*location*/ moveRangeEnd(initializer, -1)));
statements.push(setTextRange(createStatement(assignment), moveRangeEnd(initializer, -1)));
}
}
@@ -2332,33 +2364,38 @@ namespace ts {
// The old emitter does not emit source maps for the block.
// We add the location to preserve comments.
const body = createBlock(
createNodeArray(statements, /*location*/ statementsLocation),
/*location*/ bodyLocation
);
const body = createBlock(setTextRange(createNodeArray(statements), /*location*/ statementsLocation));
setTextRange(body, bodyLocation);
setEmitFlags(body, EmitFlags.NoSourceMap | EmitFlags.NoTokenSourceMaps);
const forStatement = createFor(
setEmitFlags(
createVariableDeclarationList([
createVariableDeclaration(counter, /*type*/ undefined, createLiteral(0), /*location*/ moveRangePos(node.expression, -1)),
createVariableDeclaration(rhsReference, /*type*/ undefined, expression, /*location*/ node.expression)
], /*location*/ node.expression),
setTextRange(
createVariableDeclarationList([
setTextRange(createVariableDeclaration(counter, /*type*/ undefined, createLiteral(0)), moveRangePos(node.expression, -1)),
setTextRange(createVariableDeclaration(rhsReference, /*type*/ undefined, expression), node.expression)
]),
node.expression
),
EmitFlags.NoHoisting
),
createLessThan(
counter,
createPropertyAccess(rhsReference, "length"),
/*location*/ node.expression
setTextRange(
createLessThan(
counter,
createPropertyAccess(rhsReference, "length")
),
node.expression
),
createPostfixIncrement(counter, /*location*/ node.expression),
body,
/*location*/ node
setTextRange(
createPostfixIncrement(counter),
node.expression
),
body
);
// Disable trailing source maps for the OpenParenToken to align source map emit with the old emitter.
setEmitFlags(forStatement, EmitFlags.NoTokenTrailingSourceMaps);
setTextRange(forStatement, node);
return restoreEnclosingLabel(forStatement, outermostLabeledStatement, convertedLoopState && resetLabel);
}
@@ -2418,7 +2455,6 @@ namespace ts {
setEmitFlags(
createObjectLiteral(
visitNodes(properties, visitor, isObjectLiteralElementLike, 0, numInitialProperties),
/*location*/ undefined,
node.multiLine
),
EmitFlags.Indented
@@ -2546,14 +2582,14 @@ namespace ts {
copyOutParameters(loopOutParameters, CopyDirection.ToOutParameter, statements);
}
addRange(statements, lexicalEnvironment)
loopBody = createBlock(statements, /*location*/ undefined, /*multiline*/ true);
loopBody = createBlock(statements, /*multiline*/ true);
}
if (isBlock(loopBody)) {
loopBody.multiLine = true;
}
else {
loopBody = createBlock([loopBody], /*location*/ undefined, /*multiline*/ true);
loopBody = createBlock([loopBody], /*multiline*/ true);
}
const isAsyncBlockContainingAwait =
@@ -2687,12 +2723,7 @@ namespace ts {
// visit childnodes to transform initializer/condition/incrementor parts
clone = visitEachChild(clone, visitor, context);
// set loop statement
clone.statement = createBlock(
convertedLoopBodyStatements,
/*location*/ undefined,
/*multiline*/ true
);
clone.statement = createBlock(convertedLoopBodyStatements, /*multiline*/ true);
// reset and re-aggregate the transform flags
clone.transformFlags = 0;
aggregateTransformFlags(clone);
@@ -2903,9 +2934,9 @@ namespace ts {
receiver,
visitNode(property.name, visitor, isPropertyName)
),
visitNode(property.initializer, visitor, isExpression),
/*location*/ property
visitNode(property.initializer, visitor, isExpression)
);
setTextRange(expression, property);
if (startsOnNewLine) {
expression.startsOnNewLine = true;
}
@@ -2925,9 +2956,9 @@ namespace ts {
receiver,
visitNode(property.name, visitor, isPropertyName)
),
getSynthesizedClone(property.name),
/*location*/ property
getSynthesizedClone(property.name)
);
setTextRange(expression, property);
if (startsOnNewLine) {
expression.startsOnNewLine = true;
}
@@ -2948,9 +2979,9 @@ namespace ts {
receiver,
visitNode(method.name, visitor, isPropertyName)
),
transformFunctionLikeToExpression(method, /*location*/ method, /*name*/ undefined, container),
/*location*/ method
transformFunctionLikeToExpression(method, /*location*/ method, /*name*/ undefined, container)
);
setTextRange(expression, method);
if (startsOnNewLine) {
expression.startsOnNewLine = true;
}
@@ -2963,7 +2994,8 @@ namespace ts {
let updated: CatchClause;
if (isBindingPattern(node.variableDeclaration.name)) {
const temp = createTempVariable(undefined);
const newVariableDeclaration = createVariableDeclaration(temp, undefined, undefined, node.variableDeclaration);
const newVariableDeclaration = createVariableDeclaration(temp);
setTextRange(newVariableDeclaration, node.variableDeclaration);
const vars = flattenDestructuringBinding(
node.variableDeclaration,
visitor,
@@ -2971,8 +3003,9 @@ namespace ts {
FlattenLevel.All,
temp
);
const list = createVariableDeclarationList(vars, /*location*/node.variableDeclaration, /*flags*/node.variableDeclaration.flags);
const destructure = createVariableStatement(undefined, list);
const list = createVariableDeclarationList(vars);
setTextRange(list, node.variableDeclaration);
const destructure = createVariableStatement(/*modifiers*/ undefined, list);
updated = updateCatchClause(node, newVariableDeclaration, addStatementToStartOfBlock(node.block, destructure));
}
else {
@@ -3001,9 +3034,11 @@ namespace ts {
Debug.assert(!isComputedPropertyName(node.name));
const functionExpression = transformFunctionLikeToExpression(node, /*location*/ moveRangePos(node, -1), /*name*/ undefined, /*container*/ undefined);
setEmitFlags(functionExpression, EmitFlags.NoLeadingComments | getEmitFlags(functionExpression));
return createPropertyAssignment(
node.name,
functionExpression,
return setTextRange(
createPropertyAssignment(
node.name,
functionExpression
),
/*location*/ node
);
}
@@ -3030,9 +3065,11 @@ namespace ts {
* @param node A ShorthandPropertyAssignment node.
*/
function visitShorthandPropertyAssignment(node: ShorthandPropertyAssignment): ObjectLiteralElementLike {
return createPropertyAssignment(
node.name,
getSynthesizedClone(node.name),
return setTextRange(
createPropertyAssignment(
node.name,
getSynthesizedClone(node.name)
),
/*location*/ node
);
}
@@ -3225,8 +3262,7 @@ namespace ts {
function visitSpanOfNonSpreads(chunk: Expression[], multiLine: boolean, hasTrailingComma: boolean): VisitResult<Expression> {
return createArrayLiteral(
visitNodes(createNodeArray(chunk, /*location*/ undefined, hasTrailingComma), visitor, isExpression),
/*location*/ undefined,
visitNodes(createNodeArray(chunk, hasTrailingComma), visitor, isExpression),
multiLine
);
}
@@ -3250,7 +3286,7 @@ namespace ts {
* @param node A template literal.
*/
function visitTemplateLiteral(node: LiteralExpression): LeftHandSideExpression {
return createLiteral(node.text, /*location*/ node);
return setTextRange(createLiteral(node.text), node);
}
/**
@@ -3318,7 +3354,7 @@ namespace ts {
// ES6 Spec 11.8.6.1 - Static Semantics of TV's and TRV's
// <CR><LF> and <CR> LineTerminatorSequences are normalized to <LF> for both TV and TRV.
text = text.replace(/\r\n?/g, "\n");
return createLiteral(text, /*location*/ node);
return setTextRange(createLiteral(text), node);
}
/**
@@ -3342,7 +3378,8 @@ namespace ts {
// "abc" + (1 << 2) + ""
const expression = reduceLeft(expressions, createAdd);
if (nodeIsSynthesized(expression)) {
setTextRange(expression, node);
expression.pos = node.pos;
expression.end = node.end;
}
return expression;
@@ -3580,7 +3617,7 @@ namespace ts {
function substituteThisKeyword(node: PrimaryExpression): PrimaryExpression {
if (enabledSubstitutions & ES2015SubstitutionFlags.CapturedThis
&& hierarchyFacts & HierarchyFacts.CapturesThis) {
return createIdentifier("_this", /*location*/ node);
return setTextRange(createIdentifier("_this"), node);
}
return node;
}

View File

@@ -48,29 +48,37 @@ namespace ts {
// Transforms `a[x] **= b` into `(_a = a)[_x = x] = Math.pow(_a[_x], b)`
const expressionTemp = createTempVariable(hoistVariableDeclaration);
const argumentExpressionTemp = createTempVariable(hoistVariableDeclaration);
target = createElementAccess(
createAssignment(expressionTemp, left.expression, /*location*/ left.expression),
createAssignment(argumentExpressionTemp, left.argumentExpression, /*location*/ left.argumentExpression),
/*location*/ left
target = setTextRange(
createElementAccess(
setTextRange(createAssignment(expressionTemp, left.expression), left.expression),
setTextRange(createAssignment(argumentExpressionTemp, left.argumentExpression), left.argumentExpression)
),
left
);
value = createElementAccess(
expressionTemp,
argumentExpressionTemp,
/*location*/ left
value = setTextRange(
createElementAccess(
expressionTemp,
argumentExpressionTemp
),
left
);
}
else if (isPropertyAccessExpression(left)) {
// Transforms `a.x **= b` into `(_a = a).x = Math.pow(_a.x, b)`
const expressionTemp = createTempVariable(hoistVariableDeclaration);
target = createPropertyAccess(
createAssignment(expressionTemp, left.expression, /*location*/ left.expression),
left.name,
/*location*/ left
target = setTextRange(
createPropertyAccess(
setTextRange(createAssignment(expressionTemp, left.expression), left.expression),
left.name
),
left
);
value = createPropertyAccess(
expressionTemp,
left.name,
/*location*/ left
value = setTextRange(
createPropertyAccess(
expressionTemp,
left.name
),
left
);
}
else {
@@ -78,7 +86,13 @@ namespace ts {
target = left;
value = left;
}
return createAssignment(target, createMathPow(value, right, /*location*/ node), /*location*/ node);
return setTextRange(
createAssignment(
target,
createMathPow(value, right, /*location*/ node)
),
node
);
}
function visitExponentiationExpression(node: BinaryExpression) {

View File

@@ -104,10 +104,12 @@ namespace ts {
*/
function visitAwaitExpression(node: AwaitExpression): Expression {
return setOriginalNode(
createYield(
/*asteriskToken*/ undefined,
visitNode(node.expression, visitor, isExpression),
/*location*/ node
setTextRange(
createYield(
/*asteriskToken*/ undefined,
visitNode(node.expression, visitor, isExpression)
),
node
),
node
);
@@ -238,7 +240,8 @@ namespace ts {
addRange(statements, endLexicalEnvironment());
const block = createBlock(statements, /*location*/ node.body, /*multiLine*/ true);
const block = createBlock(statements, /*multiLine*/ true);
setTextRange(block, node.body);
// Minor optimization, emit `_super` helper to capture `super` access in an arrow.
// This step isn't needed if we eventually transform this to ES5.
@@ -266,7 +269,7 @@ namespace ts {
const declarations = endLexicalEnvironment();
if (some(declarations)) {
const block = convertToFunctionBody(expression);
return updateBlock(block, createNodeArray(concatenate(block.statements, declarations), block.statements));
return updateBlock(block, setTextRange(createNodeArray(concatenate(block.statements, declarations)), block.statements));
}
return expression;
@@ -281,7 +284,7 @@ namespace ts {
startLexicalEnvironment();
const visited = convertToFunctionBody(visitNode(body, visitor, isConciseBody));
const declarations = endLexicalEnvironment();
return updateBlock(visited, createNodeArray(concatenate(visited.statements, declarations), visited.statements));
return updateBlock(visited, setTextRange(createNodeArray(concatenate(visited.statements, declarations)), visited.statements));
}
}
@@ -431,21 +434,25 @@ namespace ts {
function createSuperAccessInAsyncMethod(argumentExpression: Expression, flags: NodeCheckFlags, location: TextRange): LeftHandSideExpression {
if (flags & NodeCheckFlags.AsyncMethodWithSuperBinding) {
return createPropertyAccess(
return setTextRange(
createPropertyAccess(
createCall(
createIdentifier("_super"),
/*typeArguments*/ undefined,
[argumentExpression]
),
"value"
),
location
);
}
else {
return setTextRange(
createCall(
createIdentifier("_super"),
/*typeArguments*/ undefined,
[argumentExpression]
),
"value",
location
);
}
else {
return createCall(
createIdentifier("_super"),
/*typeArguments*/ undefined,
[argumentExpression],
location
);
}

View File

@@ -87,7 +87,7 @@ namespace ts {
function substitutePropertyAccessExpression(node: PropertyAccessExpression): Expression {
const literalName = trySubstituteReservedName(node.name);
if (literalName) {
return createElementAccess(node.expression, literalName, /*location*/ node);
return setTextRange(createElementAccess(node.expression, literalName), node);
}
return node;
}
@@ -113,7 +113,7 @@ namespace ts {
function trySubstituteReservedName(name: Identifier) {
const token = name.originalKeywordKind || (nodeIsSynthesized(name) ? stringToToken(name.text) : undefined);
if (token >= SyntaxKind.FirstReservedWord && token <= SyntaxKind.LastReservedWord) {
return createLiteral(name, /*location*/ name);
return setTextRange(createLiteral(name), name);
}
return undefined;
}

View File

@@ -210,36 +210,40 @@ namespace ts {
const statement = createVariableStatement(
/*modifiers*/ undefined,
updateVariableDeclarationList(initializer, declarations),
/*location*/ initializer
);
setTextRange(statement, initializer);
leadingStatements = append(leadingStatements, statement);
}
}
else if (isAssignmentPattern(initializer)) {
temp = createTempVariable(/*recordTempVariable*/ undefined);
const expression = flattenDestructuringAssignment(
aggregateTransformFlags(createAssignment(initializer, temp, /*location*/ node.initializer)),
aggregateTransformFlags(
setTextRange(
createAssignment(initializer, temp),
node.initializer
)
),
visitor,
context,
FlattenLevel.ObjectRest
);
leadingStatements = append(leadingStatements, createStatement(expression, /*location*/ node.initializer));
leadingStatements = append(leadingStatements, setTextRange(createStatement(expression), node.initializer));
}
}
if (temp) {
const expression = visitNode(node.expression, visitor, isExpression);
const statement = visitNode(node.statement, visitor, isStatement);
const block = isBlock(statement)
? updateBlock(statement, createNodeArray(concatenate(leadingStatements, statement.statements), statement.statements))
: createBlock(append(leadingStatements, statement), statement, /*multiLine*/ true);
? updateBlock(statement, setTextRange(createNodeArray(concatenate(leadingStatements, statement.statements)), statement.statements))
: setTextRange(createBlock(append(leadingStatements, statement), /*multiLine*/ true), statement);
return updateForOf(
node,
createVariableDeclarationList(
[
createVariableDeclaration(temp, /*type*/ undefined, /*initializer*/ undefined, node.initializer)
],
node.initializer,
NodeFlags.Let
setTextRange(
createVariableDeclarationList([
setTextRange(createVariableDeclaration(temp), node.initializer)
], NodeFlags.Let),
node.initializer
),
expression,
block
@@ -380,7 +384,7 @@ namespace ts {
const trailingStatements = endLexicalEnvironment();
if (some(leadingStatements) || some(trailingStatements)) {
const block = convertToFunctionBody(body, /*multiLine*/ true);
return updateBlock(block, createNodeArray(concatenate(concatenate(leadingStatements, block.statements), trailingStatements), block.statements));
return updateBlock(block, setTextRange(createNodeArray(concatenate(concatenate(leadingStatements, block.statements), trailingStatements)), block.statements));
}
return body;
}

View File

@@ -450,15 +450,17 @@ namespace ts {
// Currently, we only support generators that were originally async functions.
if (node.asteriskToken && getEmitFlags(node) & EmitFlags.AsyncFunctionBody) {
node = setOriginalNode(
createFunctionDeclaration(
/*decorators*/ undefined,
node.modifiers,
/*asteriskToken*/ undefined,
node.name,
/*typeParameters*/ undefined,
visitParameterList(node.parameters, visitor, context),
/*type*/ undefined,
transformGeneratorFunctionBody(node.body),
setTextRange(
createFunctionDeclaration(
/*decorators*/ undefined,
node.modifiers,
/*asteriskToken*/ undefined,
node.name,
/*typeParameters*/ undefined,
visitParameterList(node.parameters, visitor, context),
/*type*/ undefined,
transformGeneratorFunctionBody(node.body)
),
/*location*/ node
),
node
@@ -498,14 +500,16 @@ namespace ts {
// Currently, we only support generators that were originally async functions.
if (node.asteriskToken && getEmitFlags(node) & EmitFlags.AsyncFunctionBody) {
node = setOriginalNode(
createFunctionExpression(
/*modifiers*/ undefined,
/*asteriskToken*/ undefined,
node.name,
/*typeParameters*/ undefined,
visitParameterList(node.parameters, visitor, context),
/*type*/ undefined,
transformGeneratorFunctionBody(node.body),
setTextRange(
createFunctionExpression(
/*modifiers*/ undefined,
/*asteriskToken*/ undefined,
node.name,
/*typeParameters*/ undefined,
visitParameterList(node.parameters, visitor, context),
/*type*/ undefined,
transformGeneratorFunctionBody(node.body)
),
/*location*/ node
),
node
@@ -606,7 +610,7 @@ namespace ts {
operationLocations = savedOperationLocations;
state = savedState;
return createBlock(statements, /*location*/ body, body.multiLine);
return setTextRange(createBlock(statements, body.multiLine), body);
}
/**
@@ -739,14 +743,17 @@ namespace ts {
const operator = node.operatorToken.kind;
if (isCompoundAssignment(operator)) {
return createBinary(
target,
SyntaxKind.EqualsToken,
createBinary(
cacheExpression(target),
getOperatorForCompoundAssignment(operator),
visitNode(right, visitor, isExpression),
node
return setTextRange(
createAssignment(
target,
setTextRange(
createBinary(
cacheExpression(target),
getOperatorForCompoundAssignment(operator),
visitNode(right, visitor, isExpression)
),
node
)
),
node
);
@@ -988,8 +995,11 @@ namespace ts {
const expressions = reduceLeft(elements, reduceElement, <Expression[]>[], numInitialElements);
return hasAssignedTemp
? createArrayConcat(temp, [createArrayLiteral(expressions, /*location*/ undefined, multiLine)])
: createArrayLiteral(leadingElement ? [leadingElement, ...expressions] : expressions, location, multiLine);
? createArrayConcat(temp, [createArrayLiteral(expressions, multiLine)])
: setTextRange(
createArrayLiteral(leadingElement ? [leadingElement, ...expressions] : expressions, multiLine),
location
);
function reduceElement(expressions: Expression[], element: Expression) {
if (containsYield(element) && expressions.length > 0) {
@@ -998,11 +1008,10 @@ namespace ts {
hasAssignedTemp
? createArrayConcat(
temp,
[createArrayLiteral(expressions, /*location*/ undefined, multiLine)]
[createArrayLiteral(expressions, multiLine)]
)
: createArrayLiteral(
leadingElement ? [leadingElement, ...expressions] : expressions,
/*location*/ undefined,
multiLine
)
);
@@ -1043,7 +1052,6 @@ namespace ts {
emitAssignment(temp,
createObjectLiteral(
visitNodes(properties, visitor, isObjectLiteralElementLike, 0, numInitialProperties),
/*location*/ undefined,
multiLine
)
);
@@ -1139,18 +1147,20 @@ namespace ts {
const { target, thisArg } = createCallBinding(createPropertyAccess(node.expression, "bind"), hoistVariableDeclaration);
return setOriginalNode(
createNew(
createFunctionApply(
cacheExpression(visitNode(target, visitor, isExpression)),
thisArg,
visitElements(
node.arguments,
/*leadingElement*/ createVoidZero()
)
setTextRange(
createNew(
createFunctionApply(
cacheExpression(visitNode(target, visitor, isExpression)),
thisArg,
visitElements(
node.arguments,
/*leadingElement*/ createVoidZero()
)
),
/*typeArguments*/ undefined,
[]
),
/*typeArguments*/ undefined,
[],
/*location*/ node
node
),
node
);
@@ -1423,9 +1433,11 @@ namespace ts {
}
else {
emitStatement(
createStatement(
visitNode(initializer, visitor, isExpression),
/*location*/ initializer
setTextRange(
createStatement(
visitNode(initializer, visitor, isExpression)
),
initializer
)
);
}
@@ -1441,9 +1453,11 @@ namespace ts {
markLabel(incrementLabel);
if (node.incrementor) {
emitStatement(
createStatement(
visitNode(node.incrementor, visitor, isExpression),
/*location*/ node.incrementor
setTextRange(
createStatement(
visitNode(node.incrementor, visitor, isExpression)
),
node.incrementor
)
);
}
@@ -2417,11 +2431,13 @@ namespace ts {
*/
function createInlineBreak(label: Label, location?: TextRange): ReturnStatement {
Debug.assert(label > 0, `Invalid label: ${label}`);
return createReturn(
createArrayLiteral([
createInstruction(Instruction.Break),
createLabel(label)
]),
return setTextRange(
createReturn(
createArrayLiteral([
createInstruction(Instruction.Break),
createLabel(label)
])
),
location
);
}
@@ -2433,10 +2449,12 @@ namespace ts {
* @param location An optional source map location for the statement.
*/
function createInlineReturn(expression?: Expression, location?: TextRange): ReturnStatement {
return createReturn(
createArrayLiteral(expression
? [createInstruction(Instruction.Return), expression]
: [createInstruction(Instruction.Return)]
return setTextRange(
createReturn(
createArrayLiteral(expression
? [createInstruction(Instruction.Return), expression]
: [createInstruction(Instruction.Return)]
)
),
location
);
@@ -2446,7 +2464,14 @@ namespace ts {
* Creates an expression that can be used to resume from a Yield operation.
*/
function createGeneratorResume(location?: TextRange): LeftHandSideExpression {
return createCall(createPropertyAccess(state, "sent"), /*typeArguments*/ undefined, [], location);
return setTextRange(
createCall(
createPropertyAccess(state, "sent"),
/*typeArguments*/ undefined,
[]
),
location
);
}
/**
@@ -2614,7 +2639,6 @@ namespace ts {
/*type*/ undefined,
createBlock(
buildResult,
/*location*/ undefined,
/*multiLine*/ buildResult.length > 0
)
),
@@ -2944,7 +2968,7 @@ namespace ts {
* @param operationLocation The source map location for the operation.
*/
function writeAssign(left: Expression, right: Expression, operationLocation: TextRange): void {
writeStatement(createStatement(createAssignment(left, right), operationLocation));
writeStatement(setTextRange(createStatement(createAssignment(left, right)), operationLocation));
}
/**
@@ -2956,7 +2980,7 @@ namespace ts {
function writeThrow(expression: Expression, operationLocation: TextRange): void {
lastOperationWasAbrupt = true;
lastOperationWasCompletion = true;
writeStatement(createThrow(expression, operationLocation));
writeStatement(setTextRange(createThrow(expression), operationLocation));
}
/**
@@ -2970,10 +2994,12 @@ namespace ts {
lastOperationWasCompletion = true;
writeStatement(
setEmitFlags(
createReturn(
createArrayLiteral(expression
? [createInstruction(Instruction.Return), expression]
: [createInstruction(Instruction.Return)]
setTextRange(
createReturn(
createArrayLiteral(expression
? [createInstruction(Instruction.Return), expression]
: [createInstruction(Instruction.Return)]
)
),
operationLocation
),
@@ -2992,11 +3018,13 @@ namespace ts {
lastOperationWasAbrupt = true;
writeStatement(
setEmitFlags(
createReturn(
createArrayLiteral([
createInstruction(Instruction.Break),
createLabel(label)
]),
setTextRange(
createReturn(
createArrayLiteral([
createInstruction(Instruction.Break),
createLabel(label)
])
),
operationLocation
),
EmitFlags.NoTokenSourceMaps
@@ -3017,11 +3045,13 @@ namespace ts {
createIf(
condition,
setEmitFlags(
createReturn(
createArrayLiteral([
createInstruction(Instruction.Break),
createLabel(label)
]),
setTextRange(
createReturn(
createArrayLiteral([
createInstruction(Instruction.Break),
createLabel(label)
])
),
operationLocation
),
EmitFlags.NoTokenSourceMaps
@@ -3045,11 +3075,13 @@ namespace ts {
createIf(
createLogicalNot(condition),
setEmitFlags(
createReturn(
createArrayLiteral([
createInstruction(Instruction.Break),
createLabel(label)
]),
setTextRange(
createReturn(
createArrayLiteral([
createInstruction(Instruction.Break),
createLabel(label)
])
),
operationLocation
),
EmitFlags.NoTokenSourceMaps
@@ -3070,11 +3102,13 @@ namespace ts {
lastOperationWasAbrupt = true;
writeStatement(
setEmitFlags(
createReturn(
createArrayLiteral(
expression
? [createInstruction(Instruction.Yield), expression]
: [createInstruction(Instruction.Yield)]
setTextRange(
createReturn(
createArrayLiteral(
expression
? [createInstruction(Instruction.Yield), expression]
: [createInstruction(Instruction.Yield)]
)
),
operationLocation
),
@@ -3093,11 +3127,13 @@ namespace ts {
lastOperationWasAbrupt = true;
writeStatement(
setEmitFlags(
createReturn(
createArrayLiteral([
createInstruction(Instruction.YieldStar),
expression
]),
setTextRange(
createReturn(
createArrayLiteral([
createInstruction(Instruction.YieldStar),
expression
])
),
operationLocation
),
EmitFlags.NoTokenSourceMaps

View File

@@ -143,15 +143,15 @@ namespace ts {
function transformJsxAttributeInitializer(node: StringLiteral | JsxExpression) {
if (node === undefined) {
return createLiteral(true);
return createTrue();
}
else if (node.kind === SyntaxKind.StringLiteral) {
const decoded = tryDecodeEntities((<StringLiteral>node).text);
return decoded ? createLiteral(decoded, /*location*/ node) : node;
return decoded ? setTextRange(createLiteral(decoded), node) : node;
}
else if (node.kind === SyntaxKind.JsxExpression) {
if (node.expression === undefined) {
return createLiteral(true);
return createTrue();
}
return visitJsxExpression(<JsxExpression>node);
}

View File

@@ -37,7 +37,7 @@ namespace ts {
addRange(statements, visitNodes(node.statements, visitor, isStatement, statementOffset));
return updateSourceFileNode(
node,
createNodeArray(statements, node.statements));
setTextRange(createNodeArray(statements), node.statements));
}
else {
return visitEachChild(node, visitor, context);

View File

@@ -88,7 +88,7 @@ namespace ts {
addRange(statements, endLexicalEnvironment());
addExportEqualsIfNeeded(statements, /*emitAsReturn*/ false);
const updated = updateSourceFileNode(node, createNodeArray(statements, node.statements));
const updated = updateSourceFileNode(node, setTextRange(createNodeArray(statements), node.statements));
if (currentModuleInfo.hasExportStarsToExportValues) {
addEmitHelper(updated, exportStarHelper);
}
@@ -131,47 +131,49 @@ namespace ts {
// Create an updated SourceFile:
//
// define(moduleName?, ["module1", "module2"], function ...
return updateSourceFileNode(node, createNodeArray(
[
createStatement(
createCall(
define,
/*typeArguments*/ undefined,
[
// Add the module name (if provided).
...(moduleName ? [moduleName] : []),
return updateSourceFileNode(node,
setTextRange(
createNodeArray([
createStatement(
createCall(
define,
/*typeArguments*/ undefined,
[
// Add the module name (if provided).
...(moduleName ? [moduleName] : []),
// Add the dependency array argument:
//
// ["require", "exports", module1", "module2", ...]
createArrayLiteral([
createLiteral("require"),
createLiteral("exports"),
...aliasedModuleNames,
...unaliasedModuleNames
]),
// Add the dependency array argument:
//
// ["require", "exports", module1", "module2", ...]
createArrayLiteral([
createLiteral("require"),
createLiteral("exports"),
...aliasedModuleNames,
...unaliasedModuleNames
]),
// Add the module body function argument:
//
// function (require, exports, module1, module2) ...
createFunctionExpression(
/*modifiers*/ undefined,
/*asteriskToken*/ undefined,
/*name*/ undefined,
/*typeParameters*/ undefined,
[
createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, "require"),
createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, "exports"),
...importAliasNames
],
/*type*/ undefined,
transformAsynchronousModuleBody(node)
)
]
// Add the module body function argument:
//
// function (require, exports, module1, module2) ...
createFunctionExpression(
/*modifiers*/ undefined,
/*asteriskToken*/ undefined,
/*name*/ undefined,
/*typeParameters*/ undefined,
[
createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, "require"),
createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, "exports"),
...importAliasNames
],
/*type*/ undefined,
transformAsynchronousModuleBody(node)
)
]
)
)
)
],
/*location*/ node.statements)
]),
/*location*/ node.statements
)
);
}
@@ -189,74 +191,76 @@ namespace ts {
/*typeParameters*/ undefined,
[createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, "factory")],
/*type*/ undefined,
createBlock(
[
createIf(
createLogicalAnd(
createTypeCheck(createIdentifier("module"), "object"),
createTypeCheck(createPropertyAccess(createIdentifier("module"), "exports"), "object")
),
createBlock([
createVariableStatement(
/*modifiers*/ undefined,
[
createVariableDeclaration(
"v",
/*type*/ undefined,
setTextRange(
createBlock(
[
createIf(
createLogicalAnd(
createTypeCheck(createIdentifier("module"), "object"),
createTypeCheck(createPropertyAccess(createIdentifier("module"), "exports"), "object")
),
createBlock([
createVariableStatement(
/*modifiers*/ undefined,
[
createVariableDeclaration(
"v",
/*type*/ undefined,
createCall(
createIdentifier("factory"),
/*typeArguments*/ undefined,
[
createIdentifier("require"),
createIdentifier("exports")
]
)
)
]
),
setEmitFlags(
createIf(
createStrictInequality(
createIdentifier("v"),
createIdentifier("undefined")
),
createStatement(
createAssignment(
createPropertyAccess(createIdentifier("module"), "exports"),
createIdentifier("v")
)
)
),
EmitFlags.SingleLine
)
]),
createIf(
createLogicalAnd(
createTypeCheck(createIdentifier("define"), "function"),
createPropertyAccess(createIdentifier("define"), "amd")
),
createBlock([
createStatement(
createCall(
createIdentifier("factory"),
createIdentifier("define"),
/*typeArguments*/ undefined,
[
createIdentifier("require"),
createIdentifier("exports")
createArrayLiteral([
createLiteral("require"),
createLiteral("exports"),
...aliasedModuleNames,
...unaliasedModuleNames
]),
createIdentifier("factory")
]
)
)
]
),
setEmitFlags(
createIf(
createStrictInequality(
createIdentifier("v"),
createIdentifier("undefined")
),
createStatement(
createAssignment(
createPropertyAccess(createIdentifier("module"), "exports"),
createIdentifier("v")
)
)
),
EmitFlags.SingleLine
])
)
]),
createIf(
createLogicalAnd(
createTypeCheck(createIdentifier("define"), "function"),
createPropertyAccess(createIdentifier("define"), "amd")
),
createBlock([
createStatement(
createCall(
createIdentifier("define"),
/*typeArguments*/ undefined,
[
createArrayLiteral([
createLiteral("require"),
createLiteral("exports"),
...aliasedModuleNames,
...unaliasedModuleNames
]),
createIdentifier("factory")
]
)
)
])
)
)
],
/*location*/ undefined,
/*multiLine*/ true
],
/*multiLine*/ true
),
/*location*/ undefined
)
);
@@ -274,8 +278,8 @@ namespace ts {
return updateSourceFileNode(
node,
createNodeArray(
[
setTextRange(
createNodeArray([
createStatement(
createCall(
umdHeader,
@@ -300,7 +304,7 @@ namespace ts {
]
)
)
],
]),
/*location*/ node.statements
)
);
@@ -378,7 +382,7 @@ namespace ts {
// Append the 'export =' statement if provided.
addExportEqualsIfNeeded(statements, /*emitAsReturn*/ true);
const body = createBlock(statements, /*location*/ undefined, /*multiLine*/ true);
const body = createBlock(statements, /*multiLine*/ true);
if (currentModuleInfo.hasExportStarsToExportValues) {
// If we have any `export * from ...` declarations
// we need to inform the emitter to add the __export helper.
@@ -399,11 +403,8 @@ namespace ts {
function addExportEqualsIfNeeded(statements: Statement[], emitAsReturn: boolean) {
if (currentModuleInfo.exportEquals) {
if (emitAsReturn) {
const statement = createReturn(
currentModuleInfo.exportEquals.expression,
/*location*/ currentModuleInfo.exportEquals
);
const statement = createReturn(currentModuleInfo.exportEquals.expression);
setTextRange(statement, currentModuleInfo.exportEquals);
setEmitFlags(statement, EmitFlags.NoTokenSourceMaps | EmitFlags.NoComments);
statements.push(statement);
}
@@ -415,10 +416,10 @@ namespace ts {
"exports"
),
currentModuleInfo.exportEquals.expression
),
/*location*/ currentModuleInfo.exportEquals
)
);
setTextRange(statement, currentModuleInfo.exportEquals);
setEmitFlags(statement, EmitFlags.NoComments);
statements.push(statement);
}
@@ -481,7 +482,7 @@ namespace ts {
if (moduleKind !== ModuleKind.AMD) {
if (!node.importClause) {
// import "mod";
return createStatement(createRequireCall(node), /*location*/ node);
return setTextRange(createStatement(createRequireCall(node)), node);
}
else {
const variables: VariableDeclaration[] = [];
@@ -520,12 +521,13 @@ namespace ts {
}
statements = append(statements,
createVariableStatement(
/*modifiers*/ undefined,
createVariableDeclarationList(
variables,
/*location*/ undefined,
languageVersion >= ScriptTarget.ES2015 ? NodeFlags.Const : NodeFlags.None
setTextRange(
createVariableStatement(
/*modifiers*/ undefined,
createVariableDeclarationList(
variables,
languageVersion >= ScriptTarget.ES2015 ? NodeFlags.Const : NodeFlags.None
)
),
/*location*/ node
)
@@ -539,14 +541,15 @@ namespace ts {
/*modifiers*/ undefined,
createVariableDeclarationList(
[
createVariableDeclaration(
getSynthesizedClone(namespaceDeclaration.name),
/*type*/ undefined,
getGeneratedNameForNode(node),
setTextRange(
createVariableDeclaration(
getSynthesizedClone(namespaceDeclaration.name),
/*type*/ undefined,
getGeneratedNameForNode(node)
),
/*location*/ node
)
],
/*location*/ undefined,
languageVersion >= ScriptTarget.ES2015 ? NodeFlags.Const : NodeFlags.None
)
)
@@ -592,31 +595,34 @@ namespace ts {
if (moduleKind !== ModuleKind.AMD) {
if (hasModifier(node, ModifierFlags.Export)) {
statements = append(statements,
createStatement(
createExportExpression(
node.name,
createRequireCall(node)
setTextRange(
createStatement(
createExportExpression(
node.name,
createRequireCall(node)
)
),
/*location*/ node
node
)
);
}
else {
statements = append(statements,
createVariableStatement(
/*modifiers*/ undefined,
createVariableDeclarationList(
[
createVariableDeclaration(
getSynthesizedClone(node.name),
/*type*/ undefined,
createRequireCall(node)
)
],
/*location*/ undefined,
/*flags*/ languageVersion >= ScriptTarget.ES2015 ? NodeFlags.Const : NodeFlags.None
setTextRange(
createVariableStatement(
/*modifiers*/ undefined,
createVariableDeclarationList(
[
createVariableDeclaration(
getSynthesizedClone(node.name),
/*type*/ undefined,
createRequireCall(node)
)
],
/*flags*/ languageVersion >= ScriptTarget.ES2015 ? NodeFlags.Const : NodeFlags.None
)
),
/*location*/ node
node
)
);
}
@@ -624,9 +630,11 @@ namespace ts {
else {
if (hasModifier(node, ModifierFlags.Export)) {
statements = append(statements,
createStatement(
createExportExpression(getExportName(node), getLocalName(node)),
/*location*/ node
setTextRange(
createStatement(
createExportExpression(getExportName(node), getLocalName(node))
),
node
)
);
}
@@ -662,15 +670,17 @@ namespace ts {
// export { x, y } from "mod";
if (moduleKind !== ModuleKind.AMD) {
statements.push(
createVariableStatement(
/*modifiers*/ undefined,
createVariableDeclarationList([
createVariableDeclaration(
generatedName,
/*type*/ undefined,
createRequireCall(node)
)
]),
setTextRange(
createVariableStatement(
/*modifiers*/ undefined,
createVariableDeclarationList([
createVariableDeclaration(
generatedName,
/*type*/ undefined,
createRequireCall(node)
)
])
),
/*location*/ node
)
);
@@ -681,9 +691,11 @@ namespace ts {
specifier.propertyName || specifier.name
);
statements.push(
createStatement(
createExportExpression(getExportName(specifier), exportedValue),
/*location*/ specifier
setTextRange(
createStatement(
createExportExpression(getExportName(specifier), exportedValue)
),
specifier
)
);
}
@@ -692,17 +704,19 @@ namespace ts {
}
else {
// export * from "mod";
return createStatement(
createCall(
createIdentifier("__export"),
/*typeArguments*/ undefined,
[
moduleKind !== ModuleKind.AMD
? createRequireCall(node)
: generatedName
]
return setTextRange(
createStatement(
createCall(
createIdentifier("__export"),
/*typeArguments*/ undefined,
[
moduleKind !== ModuleKind.AMD
? createRequireCall(node)
: generatedName
]
)
),
/*location*/ node
node
);
}
}
@@ -741,15 +755,17 @@ namespace ts {
if (hasModifier(node, ModifierFlags.Export)) {
statements = append(statements,
setOriginalNode(
createFunctionDeclaration(
/*decorators*/ undefined,
visitNodes(node.modifiers, modifierVisitor, isModifier),
node.asteriskToken,
getDeclarationName(node, /*allowComments*/ true, /*allowSourceMaps*/ true),
/*typeParameters*/ undefined,
node.parameters,
/*type*/ undefined,
node.body,
setTextRange(
createFunctionDeclaration(
/*decorators*/ undefined,
visitNodes(node.modifiers, modifierVisitor, isModifier),
node.asteriskToken,
getDeclarationName(node, /*allowComments*/ true, /*allowSourceMaps*/ true),
/*typeParameters*/ undefined,
node.parameters,
/*type*/ undefined,
node.body
),
/*location*/ node
),
/*original*/ node
@@ -782,16 +798,18 @@ namespace ts {
if (hasModifier(node, ModifierFlags.Export)) {
statements = append(statements,
setOriginalNode(
createClassDeclaration(
/*decorators*/ undefined,
visitNodes(node.modifiers, modifierVisitor, isModifier),
getDeclarationName(node, /*allowComments*/ true, /*allowSourceMaps*/ true),
/*typeParameters*/ undefined,
node.heritageClauses,
node.members,
/*location*/ node
setTextRange(
createClassDeclaration(
/*decorators*/ undefined,
visitNodes(node.modifiers, modifierVisitor, isModifier),
getDeclarationName(node, /*allowComments*/ true, /*allowSourceMaps*/ true),
/*typeParameters*/ undefined,
node.heritageClauses,
node.members
),
node
),
/*original*/ node
node
)
);
}
@@ -843,7 +861,7 @@ namespace ts {
}
if (expressions) {
statements = append(statements, createStatement(inlineExpressions(expressions), /*location*/ node));
statements = append(statements, setTextRange(createStatement(inlineExpressions(expressions)), node));
}
}
else {
@@ -880,9 +898,11 @@ namespace ts {
}
else {
return createAssignment(
createPropertyAccess(
createIdentifier("exports"),
node.name,
setTextRange(
createPropertyAccess(
createIdentifier("exports"),
node.name
),
/*location*/ node.name
),
node.initializer
@@ -1115,7 +1135,7 @@ namespace ts {
createStatement(
createExportExpression(
createIdentifier("__esModule"),
createLiteral(true)
createTrue()
)
)
);
@@ -1130,7 +1150,7 @@ namespace ts {
createIdentifier("exports"),
createLiteral("__esModule"),
createObjectLiteral([
createPropertyAssignment("value", createLiteral(true))
createPropertyAssignment("value", createTrue())
])
]
)
@@ -1153,7 +1173,7 @@ namespace ts {
* @param allowComments An optional value indicating whether to emit comments for the statement.
*/
function createExportStatement(name: Identifier, value: Expression, location?: TextRange, allowComments?: boolean) {
const statement = createStatement(createExportExpression(name, value), location);
const statement = setTextRange(createStatement(createExportExpression(name, value)), location);
startOnNewLine(statement);
if (!allowComments) {
setEmitFlags(statement, EmitFlags.NoComments);
@@ -1170,12 +1190,14 @@ namespace ts {
* @param location The location to use for source maps and comments for the export.
*/
function createExportExpression(name: Identifier, value: Expression, location?: TextRange) {
return createAssignment(
createPropertyAccess(
createIdentifier("exports"),
getSynthesizedClone(name)
return setTextRange(
createAssignment(
createPropertyAccess(
createIdentifier("exports"),
getSynthesizedClone(name)
),
value
),
value,
location
);
}
@@ -1268,9 +1290,9 @@ namespace ts {
// destructuring assignment
if (node.objectAssignmentInitializer) {
const initializer = createAssignment(exportedOrImportedName, node.objectAssignmentInitializer);
return createPropertyAssignment(name, initializer, /*location*/ node);
return setTextRange(createPropertyAssignment(name, initializer), node);
}
return createPropertyAssignment(name, exportedOrImportedName, /*location*/ node);
return setTextRange(createPropertyAssignment(name, exportedOrImportedName), node);
}
return node;
}
@@ -1312,9 +1334,11 @@ namespace ts {
if (!isGeneratedIdentifier(node) && !isLocalName(node)) {
const exportContainer = resolver.getReferencedExportContainer(node, isExportName(node));
if (exportContainer && exportContainer.kind === SyntaxKind.SourceFile) {
return createPropertyAccess(
createIdentifier("exports"),
getSynthesizedClone(node),
return setTextRange(
createPropertyAccess(
createIdentifier("exports"),
getSynthesizedClone(node)
),
/*location*/ node
);
}
@@ -1322,17 +1346,21 @@ namespace ts {
const importDeclaration = resolver.getReferencedImportDeclaration(node);
if (importDeclaration) {
if (isImportClause(importDeclaration)) {
return createPropertyAccess(
getGeneratedNameForNode(importDeclaration.parent),
createIdentifier("default"),
return setTextRange(
createPropertyAccess(
getGeneratedNameForNode(importDeclaration.parent),
createIdentifier("default")
),
/*location*/ node
);
}
else if (isImportSpecifier(importDeclaration)) {
const name = importDeclaration.propertyName || importDeclaration.name;
return createPropertyAccess(
getGeneratedNameForNode(importDeclaration.parent.parent.parent),
getSynthesizedClone(name),
return setTextRange(
createPropertyAccess(
getGeneratedNameForNode(importDeclaration.parent.parent.parent),
getSynthesizedClone(name)
),
/*location*/ node
);
}
@@ -1400,10 +1428,12 @@ namespace ts {
const exportedNames = getExports(node.operand);
if (exportedNames) {
let expression: Expression = node.kind === SyntaxKind.PostfixUnaryExpression
? createBinary(
node.operand,
createToken(node.operator === SyntaxKind.PlusPlusToken ? SyntaxKind.PlusEqualsToken : SyntaxKind.MinusEqualsToken),
createLiteral(1),
? setTextRange(
createBinary(
node.operand,
createToken(node.operator === SyntaxKind.PlusPlusToken ? SyntaxKind.PlusEqualsToken : SyntaxKind.MinusEqualsToken),
createLiteral(1)
),
/*location*/ node)
: node;
for (const exportName of exportedNames) {

View File

@@ -105,17 +105,20 @@ namespace ts {
const updated = setEmitFlags(
updateSourceFileNode(
node,
createNodeArray([
createStatement(
createCall(
createPropertyAccess(createIdentifier("System"), "register"),
/*typeArguments*/ undefined,
moduleName
? [moduleName, dependencies, moduleBodyFunction]
: [dependencies, moduleBodyFunction]
setTextRange(
createNodeArray([
createStatement(
createCall(
createPropertyAccess(createIdentifier("System"), "register"),
/*typeArguments*/ undefined,
moduleName
? [moduleName, dependencies, moduleBodyFunction]
: [dependencies, moduleBodyFunction]
)
)
)
], node.statements)
]),
node.statements
)
), EmitFlags.NoTrailingComments);
if (!(compilerOptions.outFile || compilerOptions.out)) {
@@ -260,35 +263,26 @@ namespace ts {
addRange(statements, endLexicalEnvironment());
const exportStarFunction = addExportStarIfNeeded(statements);
statements.push(
createReturn(
setMultiLine(
createObjectLiteral([
createPropertyAssignment("setters",
createSettersArray(exportStarFunction, dependencyGroups)
),
createPropertyAssignment("execute",
createFunctionExpression(
/*modifiers*/ undefined,
/*asteriskToken*/ undefined,
/*name*/ undefined,
/*typeParameters*/ undefined,
/*parameters*/ [],
/*type*/ undefined,
createBlock(
executeStatements,
/*location*/ undefined,
/*multiLine*/ true
)
)
)
]),
/*multiLine*/ true
const moduleObject = createObjectLiteral([
createPropertyAssignment("setters",
createSettersArray(exportStarFunction, dependencyGroups)
),
createPropertyAssignment("execute",
createFunctionExpression(
/*modifiers*/ undefined,
/*asteriskToken*/ undefined,
/*name*/ undefined,
/*typeParameters*/ undefined,
/*parameters*/ [],
/*type*/ undefined,
createBlock(executeStatements, /*multiLine*/ true)
)
)
);
]);
return createBlock(statements, /*location*/ undefined, /*multiLine*/ true);
moduleObject.multiLine = true;
statements.push(createReturn(moduleObject));
return createBlock(statements, /*multiLine*/ true);
}
/**
@@ -337,7 +331,7 @@ namespace ts {
exportedNames.push(
createPropertyAssignment(
createLiteral(exportedLocalName),
createLiteral(true)
createTrue()
)
);
}
@@ -359,7 +353,7 @@ namespace ts {
exportedNames.push(
createPropertyAssignment(
createLiteral((element.name || element.propertyName).text),
createLiteral(true)
createTrue()
)
);
}
@@ -373,7 +367,7 @@ namespace ts {
createVariableDeclaration(
exportedNamesStorageRef,
/*type*/ undefined,
createObjectLiteral(exportedNames, /*location*/ undefined, /*multiline*/ true)
createObjectLiteral(exportedNames, /*multiline*/ true)
)
])
)
@@ -456,9 +450,7 @@ namespace ts {
[exports]
)
)
],
/*location*/ undefined,
/*multiline*/ true)
], /*multiline*/ true)
);
}
@@ -525,7 +517,7 @@ namespace ts {
createCall(
exportFunction,
/*typeArguments*/ undefined,
[createObjectLiteral(properties, /*location*/ undefined, /*multiline*/ true)]
[createObjectLiteral(properties, /*multiline*/ true)]
)
)
);
@@ -558,12 +550,12 @@ namespace ts {
/*typeParameters*/ undefined,
[createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, parameterName)],
/*type*/ undefined,
createBlock(statements, /*location*/ undefined, /*multiLine*/ true)
createBlock(statements, /*multiLine*/ true)
)
);
}
return createArrayLiteral(setters, /*location*/ undefined, /*multiLine*/ true);
return createArrayLiteral(setters, /*multiLine*/ true);
}
//
@@ -713,19 +705,23 @@ namespace ts {
// Rewrite the class declaration into an assignment of a class expression.
statements = append(statements,
createStatement(
createAssignment(
name,
createClassExpression(
/*modifiers*/ undefined,
node.name,
/*typeParameters*/ undefined,
visitNodes(node.heritageClauses, destructuringVisitor, isHeritageClause),
visitNodes(node.members, destructuringVisitor, isClassElement),
/*location*/ node
setTextRange(
createStatement(
createAssignment(
name,
setTextRange(
createClassExpression(
/*modifiers*/ undefined,
node.name,
/*typeParameters*/ undefined,
visitNodes(node.heritageClauses, destructuringVisitor, isHeritageClause),
visitNodes(node.members, destructuringVisitor, isClassElement)
),
node
)
)
),
/*location*/ node
node
)
);
@@ -766,7 +762,7 @@ namespace ts {
let statements: Statement[];
if (expressions) {
statements = append(statements, createStatement(inlineExpressions(expressions), /*location*/ node));
statements = append(statements, setTextRange(createStatement(inlineExpressions(expressions)), node));
}
if (isMarkedDeclaration) {
@@ -864,8 +860,8 @@ namespace ts {
function createVariableAssignment(name: Identifier, value: Expression, location: TextRange, isExportedDeclaration: boolean) {
hoistVariableDeclaration(getSynthesizedClone(name));
return isExportedDeclaration
? createExportExpression(name, preventSubstitution(createAssignment(name, value, location)))
: preventSubstitution(createAssignment(name, value, location));
? createExportExpression(name, preventSubstitution(setTextRange(createAssignment(name, value), location)))
: preventSubstitution(setTextRange(createAssignment(name, value), location));
}
/**
@@ -1642,16 +1638,20 @@ namespace ts {
const importDeclaration = resolver.getReferencedImportDeclaration(node);
if (importDeclaration) {
if (isImportClause(importDeclaration)) {
return createPropertyAccess(
getGeneratedNameForNode(importDeclaration.parent),
createIdentifier("default"),
return setTextRange(
createPropertyAccess(
getGeneratedNameForNode(importDeclaration.parent),
createIdentifier("default")
),
/*location*/ node
);
}
else if (isImportSpecifier(importDeclaration)) {
return createPropertyAccess(
getGeneratedNameForNode(importDeclaration.parent.parent.parent),
getSynthesizedClone(importDeclaration.propertyName || importDeclaration.name),
return setTextRange(
createPropertyAccess(
getGeneratedNameForNode(importDeclaration.parent.parent.parent),
getSynthesizedClone(importDeclaration.propertyName || importDeclaration.name)
),
/*location*/ node
);
}
@@ -1718,10 +1718,13 @@ namespace ts {
const exportedNames = getExports(node.operand);
if (exportedNames) {
let expression: Expression = node.kind === SyntaxKind.PostfixUnaryExpression
? createPrefix(
node.operator,
node.operand,
/*location*/ node)
? setTextRange(
createPrefix(
node.operator,
node.operand
),
node
)
: node;
for (const exportName of exportedNames) {

View File

@@ -588,17 +588,17 @@ namespace ts {
name,
/*typeParameters*/ undefined,
visitNodes(node.heritageClauses, visitor, isHeritageClause),
transformClassMembers(node, hasExtendsClause),
node);
let emitFlags = getEmitFlags(node);
transformClassMembers(node, hasExtendsClause)
);
// To better align with the old emitter, we should not emit a trailing source map
// entry if the class has static properties.
let emitFlags = getEmitFlags(node);
if (hasStaticProperties) {
emitFlags |= EmitFlags.NoTrailingSourceMap;
}
setTextRange(classDeclaration, node);
setOriginalNode(classDeclaration, node);
setEmitFlags(classDeclaration, emitFlags);
return classDeclaration;
@@ -709,13 +709,24 @@ namespace ts {
// }
const heritageClauses = visitNodes(node.heritageClauses, visitor, isHeritageClause);
const members = transformClassMembers(node, hasExtendsClause);
const classExpression = createClassExpression(/*modifiers*/ undefined, name, /*typeParameters*/ undefined, heritageClauses, members, location);
const classExpression = createClassExpression(/*modifiers*/ undefined, name, /*typeParameters*/ undefined, heritageClauses, members);
setOriginalNode(classExpression, node);
setTextRange(classExpression, location);
// let ${name} = ${classExpression} where name is either declaredName if the class doesn't contain self-reference
// or decoratedClassAlias if the class contain self-reference.
const statement = createLetStatement(declName, classAlias ? createAssignment(classAlias, classExpression) : classExpression, location);
const statement = createVariableStatement(
/*modifiers*/ undefined,
createVariableDeclarationList([
createVariableDeclaration(
declName,
/*type*/ undefined,
classAlias ? createAssignment(classAlias, classExpression) : classExpression
)
], NodeFlags.Let)
);
setOriginalNode(statement, node);
setTextRange(statement, location);
setCommentRange(statement, node);
return statement;
}
@@ -734,18 +745,17 @@ namespace ts {
const heritageClauses = visitNodes(node.heritageClauses, visitor, isHeritageClause);
const members = transformClassMembers(node, some(heritageClauses, c => c.token === SyntaxKind.ExtendsKeyword));
const classExpression = setOriginalNode(
createClassExpression(
/*modifiers*/ undefined,
node.name,
/*typeParameters*/ undefined,
heritageClauses,
members,
/*location*/ node
),
node
const classExpression = createClassExpression(
/*modifiers*/ undefined,
node.name,
/*typeParameters*/ undefined,
heritageClauses,
members
);
setOriginalNode(classExpression, node);
setTextRange(classExpression, node);
if (staticProperties.length > 0) {
const expressions: Expression[] = [];
const temp = createTempVariable(hoistVariableDeclaration);
@@ -781,7 +791,7 @@ namespace ts {
}
addRange(members, visitNodes(node.members, classElementVisitor, isClassElement));
return createNodeArray(members, /*location*/ node.members);
return setTextRange(createNodeArray(members), /*location*/ node.members);
}
/**
@@ -812,12 +822,14 @@ namespace ts {
// }
return startOnNewLine(
setOriginalNode(
createConstructor(
/*decorators*/ undefined,
/*modifiers*/ undefined,
parameters,
body,
/*location*/ constructor || node
setTextRange(
createConstructor(
/*decorators*/ undefined,
/*modifiers*/ undefined,
parameters,
body
),
constructor || node
),
constructor
)
@@ -919,13 +931,15 @@ namespace ts {
// End the lexical environment.
addRange(statements, endLexicalEnvironment());
return createBlock(
createNodeArray(
statements,
/*location*/ constructor ? constructor.body.statements : node.members
return setTextRange(
createBlock(
setTextRange(
createNodeArray(statements),
/*location*/ constructor ? constructor.body.statements : node.members
),
/*multiLine*/ true
),
/*location*/ constructor ? constructor.body : /*location*/ undefined,
/*multiLine*/ true
/*location*/ constructor ? constructor.body : undefined
);
}
@@ -991,16 +1005,20 @@ namespace ts {
setEmitFlags(localName, EmitFlags.NoComments);
return startOnNewLine(
createStatement(
createAssignment(
createPropertyAccess(
createThis(),
propertyName,
/*location*/ node.name
),
localName
setTextRange(
createStatement(
createAssignment(
setTextRange(
createPropertyAccess(
createThis(),
propertyName
),
node.name
),
localName
)
),
/*location*/ moveRangePos(node, -1)
moveRangePos(node, -1)
)
);
}
@@ -1504,7 +1522,7 @@ namespace ts {
(properties || (properties = [])).push(createPropertyAssignment("returnType", createArrowFunction(/*modifiers*/ undefined, /*typeParameters*/ undefined, [], /*type*/ undefined, createToken(SyntaxKind.EqualsGreaterThanToken), serializeReturnTypeOfNode(node))));
}
if (properties) {
decoratorExpressions.push(createMetadataHelper(context, "design:typeinfo", createObjectLiteral(properties, /*location*/ undefined, /*multiLine*/ true)));
decoratorExpressions.push(createMetadataHelper(context, "design:typeinfo", createObjectLiteral(properties, /*multiLine*/ true)));
}
}
}
@@ -1939,10 +1957,7 @@ namespace ts {
expression = createAssignment(generatedName, expression);
}
return setOriginalNode(
createComputedPropertyName(expression, /*location*/ name),
name
);
return updateComputedPropertyName(name, expression);
}
else {
return name;
@@ -1961,9 +1976,11 @@ namespace ts {
function visitHeritageClause(node: HeritageClause): HeritageClause {
if (node.token === SyntaxKind.ExtendsKeyword) {
const types = visitNodes(node.types, visitor, isExpressionWithTypeArguments, 0, 1);
return createHeritageClause(
SyntaxKind.ExtendsKeyword,
types,
return setTextRange(
createHeritageClause(
SyntaxKind.ExtendsKeyword,
types
),
node
);
}
@@ -1980,11 +1997,10 @@ namespace ts {
* @param node The ExpressionWithTypeArguments to transform.
*/
function visitExpressionWithTypeArguments(node: ExpressionWithTypeArguments): ExpressionWithTypeArguments {
const expression = visitNode(node.expression, visitor, isLeftHandSideExpression);
return createExpressionWithTypeArguments(
return updateExpressionWithTypeArguments(
node,
/*typeArguments*/ undefined,
expression,
node
visitNode(node.expression, visitor, isLeftHandSideExpression)
);
}
@@ -2205,13 +2221,13 @@ namespace ts {
visitNode(node.name, visitor, isBindingName),
/*questionToken*/ undefined,
/*type*/ undefined,
visitNode(node.initializer, visitor, isExpression),
/*location*/ moveRangePastModifiers(node)
visitNode(node.initializer, visitor, isExpression)
);
// While we emit the source map for the node after skipping decorators and modifiers,
// we need to emit the comments for the original range.
setOriginalNode(parameter, node);
setTextRange(parameter, moveRangePastModifiers(node));
setCommentRange(parameter, node);
setSourceMapRange(parameter, moveRangePastModifiers(node));
setEmitFlags(parameter.name, EmitFlags.NoTrailingSourceMap);
@@ -2233,11 +2249,13 @@ namespace ts {
return undefined;
}
return createStatement(
inlineExpressions(
map(variables, transformInitializedVariable)
return setTextRange(
createStatement(
inlineExpressions(
map(variables, transformInitializedVariable)
)
),
/*location*/ node
node
);
}
else {
@@ -2258,9 +2276,11 @@ namespace ts {
);
}
else {
return createAssignment(
getNamespaceMemberNameWithSourceMapsAndWithoutComments(name),
visitNode(node.initializer, visitor, isExpression),
return setTextRange(
createAssignment(
getNamespaceMemberNameWithSourceMapsAndWithoutComments(name),
visitNode(node.initializer, visitor, isExpression)
),
/*location*/ node
);
}
@@ -2418,11 +2438,11 @@ namespace ts {
),
/*typeArguments*/ undefined,
[moduleArg]
),
/*location*/ node
)
);
setOriginalNode(enumStatement, node);
setTextRange(enumStatement, node);
setEmitFlags(enumStatement, emitFlags);
statements.push(enumStatement);
@@ -2448,8 +2468,7 @@ namespace ts {
currentNamespaceContainerName = savedCurrentNamespaceLocalName;
return createBlock(
createNodeArray(statements, /*location*/ node.members),
/*location*/ undefined,
setTextRange(createNodeArray(statements), /*location*/ node.members),
/*multiLine*/ true
);
}
@@ -2464,22 +2483,26 @@ namespace ts {
// we pass false as 'generateNameForComputedPropertyName' for a backward compatibility purposes
// old emitter always generate 'expression' part of the name as-is.
const name = getExpressionForPropertyName(member, /*generateNameForComputedPropertyName*/ false);
return createStatement(
createAssignment(
createElementAccess(
currentNamespaceContainerName,
return setTextRange(
createStatement(
setTextRange(
createAssignment(
createElementAccess(
currentNamespaceContainerName,
name
createAssignment(
createElementAccess(
currentNamespaceContainerName,
name
),
transformEnumMemberDeclarationValue(member)
)
),
transformEnumMemberDeclarationValue(member)
)
),
name,
/*location*/ member
name
),
member
)
),
/*location*/ member
member
);
}
@@ -2697,11 +2720,11 @@ namespace ts {
),
/*typeArguments*/ undefined,
[moduleArg]
),
/*location*/ node
)
);
setOriginalNode(moduleStatement, node);
setTextRange(moduleStatement, node);
setEmitFlags(moduleStatement, emitFlags);
statements.push(moduleStatement);
@@ -2756,13 +2779,13 @@ namespace ts {
currentScopeFirstDeclarationsOfName = savedCurrentScopeFirstDeclarationsOfName;
const block = createBlock(
createNodeArray(
statements,
setTextRange(
createNodeArray(statements),
/*location*/ statementsLocation
),
/*location*/ blockLocation,
/*multiLine*/ true
);
setTextRange(block, blockLocation);
// namespace hello.hi.world {
// function foo() {}
@@ -2962,18 +2985,20 @@ namespace ts {
// export var ${name} = ${moduleReference};
// var ${name} = ${moduleReference};
return setOriginalNode(
createVariableStatement(
visitNodes(node.modifiers, modifierVisitor, isModifier),
createVariableDeclarationList([
setOriginalNode(
createVariableDeclaration(
node.name,
/*type*/ undefined,
moduleReference
),
node
)
]),
setTextRange(
createVariableStatement(
visitNodes(node.modifiers, modifierVisitor, isModifier),
createVariableDeclarationList([
setOriginalNode(
createVariableDeclaration(
node.name,
/*type*/ undefined,
moduleReference
),
node
)
])
),
node
),
node
@@ -3034,7 +3059,7 @@ namespace ts {
* Creates a statement for the provided expression. This is used in calls to `map`.
*/
function expressionToStatement(expression: Expression) {
return createStatement(expression, /*location*/ undefined);
return createStatement(expression);
}
function addExportMemberAssignment(statements: Statement[], node: ClassDeclaration | FunctionDeclaration) {
@@ -3050,17 +3075,19 @@ namespace ts {
}
function createNamespaceExport(exportName: Identifier, exportValue: Expression, location?: TextRange) {
return createStatement(
createAssignment(
getNamespaceMemberName(currentNamespaceContainerName, exportName, /*allowComments*/ false, /*allowSourceMaps*/ true),
exportValue
return setTextRange(
createStatement(
createAssignment(
getNamespaceMemberName(currentNamespaceContainerName, exportName, /*allowComments*/ false, /*allowSourceMaps*/ true),
exportValue
)
),
location
);
}
function createNamespaceExportExpression(exportName: Identifier, exportValue: Expression, location?: TextRange) {
return createAssignment(getNamespaceMemberNameWithSourceMapsAndWithoutComments(exportName), exportValue, location);
return setTextRange(createAssignment(getNamespaceMemberNameWithSourceMapsAndWithoutComments(exportName), exportValue), location);
}
function getNamespaceMemberNameWithSourceMapsAndWithoutComments(name: Identifier) {
@@ -3201,9 +3228,9 @@ namespace ts {
// destructuring assignment
if (node.objectAssignmentInitializer) {
const initializer = createAssignment(exportedName, node.objectAssignmentInitializer);
return createPropertyAssignment(name, initializer, /*location*/ node);
return setTextRange(createPropertyAssignment(name, initializer), node);
}
return createPropertyAssignment(name, exportedName, /*location*/ node);
return setTextRange(createPropertyAssignment(name, exportedName), node);
}
}
return node;
@@ -3263,7 +3290,10 @@ namespace ts {
(applicableSubstitutions & TypeScriptSubstitutionFlags.NamespaceExports && container.kind === SyntaxKind.ModuleDeclaration) ||
(applicableSubstitutions & TypeScriptSubstitutionFlags.NonQualifiedEnumMembers && container.kind === SyntaxKind.EnumDeclaration);
if (substitute) {
return createPropertyAccess(getGeneratedNameForNode(container), node, /*location*/ node);
return setTextRange(
createPropertyAccess(getGeneratedNameForNode(container), node),
/*location*/ node
);
}
}
}
@@ -3322,13 +3352,15 @@ namespace ts {
function createParamHelper(context: TransformationContext, expression: Expression, parameterOffset: number, location?: TextRange) {
context.requestEmitHelper(paramHelper);
return createCall(
getHelperName("__param"),
/*typeArguments*/ undefined,
[
createLiteral(parameterOffset),
expression
],
return setTextRange(
createCall(
getHelperName("__param"),
/*typeArguments*/ undefined,
[
createLiteral(parameterOffset),
expression
]
),
location
);
}
@@ -3371,7 +3403,7 @@ namespace ts {
function createDecorateHelper(context: TransformationContext, decoratorExpressions: Expression[], target: Expression, memberName?: Expression, descriptor?: Expression, location?: TextRange) {
context.requestEmitHelper(decorateHelper);
const argumentsArray: Expression[] = [];
argumentsArray.push(createArrayLiteral(decoratorExpressions, /*location*/ undefined, /*multiLine*/ true));
argumentsArray.push(createArrayLiteral(decoratorExpressions, /*multiLine*/ true));
argumentsArray.push(target);
if (memberName) {
argumentsArray.push(memberName);
@@ -3380,6 +3412,13 @@ namespace ts {
}
}
return createCall(getHelperName("__decorate"), /*typeArguments*/ undefined, argumentsArray, location);
return setTextRange(
createCall(
getHelperName("__decorate"),
/*typeArguments*/ undefined,
argumentsArray
),
location
);
}
}

View File

@@ -958,8 +958,7 @@
}
// Represents an expression that is elided as part of a transformation to emit comments on a
// not-emitted node. The 'expression' property of a NotEmittedExpression should be emitted.
// @internal
// not-emitted node. The 'expression' property of a PartiallyEmittedExpression should be emitted.
export interface PartiallyEmittedExpression extends LeftHandSideExpression {
kind: SyntaxKind.PartiallyEmittedExpression;
expression: Expression;
@@ -1538,7 +1537,6 @@
// Represents a statement that is elided as part of a transformation to emit comments on a
// not-emitted node.
// @internal
export interface NotEmittedStatement extends Statement {
kind: SyntaxKind.NotEmittedStatement;
}
@@ -3730,7 +3728,6 @@
helpers?: EmitHelper[]; // Emit helpers for the node
}
/* @internal */
export const enum EmitFlags {
SingleLine = 1 << 0, // The contents of this node should be emitted on a single line.
AdviseOnEmitNode = 1 << 1, // The printer should invoke the onEmitNode callback when printing this node.
@@ -3759,7 +3756,6 @@
HasEndOfDeclarationMarker = 1 << 21, // Declaration has an associated NotEmittedStatement to mark the end of the declaration
}
/* @internal */
export interface EmitHelper {
readonly name: string; // A unique name for this helper.
readonly scoped: boolean; // Indicates whether ther helper MUST be emitted in the current scope.

View File

@@ -3331,6 +3331,14 @@ namespace ts {
}
}
export function getRangePos(range: TextRange | undefined) {
return range ? range.pos : -1;
}
export function getRangeEnd(range: TextRange | undefined) {
return range ? range.end : -1;
}
/**
* Increases (or decreases) a position by the provided amount.
*

View File

@@ -627,8 +627,7 @@ namespace ts {
// If we are not visiting all of the original nodes, we must always create a new array.
// Since this is a fragment of a node array, we do not copy over the previous location
// and will only copy over `hasTrailingComma` if we are including the last element.
updated = createNodeArray<Node>([], /*location*/ undefined,
/*hasTrailingComma*/ nodes.hasTrailingComma && start + count === length);
updated = createNodeArray<Node>([], /*hasTrailingComma*/ nodes.hasTrailingComma && start + count === length);
}
// Visit each original node.
@@ -639,7 +638,8 @@ namespace ts {
if (updated !== undefined || visited === undefined || visited !== node) {
if (updated === undefined) {
// Ensure we have a copy of `nodes`, up to the current index.
updated = createNodeArray(nodes.slice(0, i), /*location*/ nodes, nodes.hasTrailingComma);
updated = createNodeArray(nodes.slice(0, i), nodes.hasTrailingComma);
setTextRange(updated, nodes);
}
if (visited) {
if (isArray(visited)) {
@@ -675,10 +675,10 @@ namespace ts {
context.startLexicalEnvironment();
statements = visitNodes(statements, visitor, isStatement, start);
if (ensureUseStrict && !startsWithUseStrict(statements)) {
statements = createNodeArray([createStatement(createLiteral("use strict")), ...statements], statements);
statements = setTextRange(createNodeArray([createStatement(createLiteral("use strict")), ...statements]), statements);
}
const declarations = context.endLexicalEnvironment();
return createNodeArray(concatenate(statements, declarations), statements);
return setTextRange(createNodeArray(concatenate(statements, declarations)), statements);
}
/**
@@ -1228,7 +1228,7 @@ namespace ts {
return statements;
}
return isNodeArray(statements)
? createNodeArray(concatenate(statements, declarations), statements)
? setTextRange(createNodeArray(concatenate(statements, declarations)), statements)
: addRange(statements, declarations);
}
@@ -1252,13 +1252,19 @@ namespace ts {
export function mergeFunctionBodyLexicalEnvironment(body: ConciseBody, declarations: Statement[]): ConciseBody {
if (body && declarations !== undefined && declarations.length > 0) {
if (isBlock(body)) {
return updateBlock(body, createNodeArray(concatenate(body.statements, declarations), body.statements));
return updateBlock(body, setTextRange(createNodeArray(concatenate(body.statements, declarations)), body.statements));
}
else {
return createBlock(
createNodeArray([createReturn(body, /*location*/ body), ...declarations], body),
/*location*/ body,
/*multiLine*/ true);
return setTextRange(
createBlock(
setTextRange(
createNodeArray([setTextRange(createReturn(body), body), ...declarations]),
body
),
/*multiLine*/ true
),
/*location*/ body
);
}
}
return body;