mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-26 00:36:29 -05:00
Ensure that emitter calls callbacks (#18284)
* Ensure that emitter calls calbacks * Move new parameter to end of parameters * Fix for ConditionalExpression * Make suggested changes to emitter * Fix parameter ordering * Respond to minor comments * Remove potentially expensive assertion * More emitter cleanup
This commit is contained in:
@@ -726,6 +726,7 @@ namespace ts.formatting {
|
||||
parent: Node,
|
||||
parentStartLine: number,
|
||||
parentDynamicIndentation: DynamicIndentation): void {
|
||||
Debug.assert(isNodeArray(nodes));
|
||||
|
||||
const listStartToken = getOpenTokenForList(parent, nodes);
|
||||
const listEndToken = getCloseTokenForOpenToken(listStartToken);
|
||||
|
||||
@@ -656,11 +656,13 @@ namespace ts.refactor.extractMethod {
|
||||
const typeParametersAndDeclarations = arrayFrom(typeParameterUsages.values()).map(type => ({ type, declaration: getFirstDeclaration(type) }));
|
||||
const sortedTypeParametersAndDeclarations = typeParametersAndDeclarations.sort(compareTypesByDeclarationOrder);
|
||||
|
||||
const typeParameters: ReadonlyArray<TypeParameterDeclaration> = sortedTypeParametersAndDeclarations.map(t => t.declaration as TypeParameterDeclaration);
|
||||
const typeParameters: ReadonlyArray<TypeParameterDeclaration> | undefined = sortedTypeParametersAndDeclarations.length === 0
|
||||
? undefined
|
||||
: sortedTypeParametersAndDeclarations.map(t => t.declaration as TypeParameterDeclaration);
|
||||
|
||||
// Strictly speaking, we should check whether each name actually binds to the appropriate type
|
||||
// parameter. In cases of shadowing, they may not.
|
||||
const callTypeArguments: ReadonlyArray<TypeNode> | undefined = typeParameters.length > 0
|
||||
const callTypeArguments: ReadonlyArray<TypeNode> | undefined = typeParameters !== undefined
|
||||
? typeParameters.map(decl => createTypeReferenceNode(decl.name, /*typeArguments*/ undefined))
|
||||
: undefined;
|
||||
|
||||
|
||||
@@ -5,19 +5,25 @@ namespace ts.textChanges {
|
||||
* Currently for simplicity we store recovered positions on the node itself.
|
||||
* It can be changed to side-table later if we decide that current design is too invasive.
|
||||
*/
|
||||
function getPos(n: TextRange) {
|
||||
return (<any>n)["__pos"];
|
||||
function getPos(n: TextRange): number {
|
||||
const result = (<any>n)["__pos"];
|
||||
Debug.assert(typeof result === "number");
|
||||
return result;
|
||||
}
|
||||
|
||||
function setPos(n: TextRange, pos: number) {
|
||||
function setPos(n: TextRange, pos: number): void {
|
||||
Debug.assert(typeof pos === "number");
|
||||
(<any>n)["__pos"] = pos;
|
||||
}
|
||||
|
||||
function getEnd(n: TextRange) {
|
||||
return (<any>n)["__end"];
|
||||
function getEnd(n: TextRange): number {
|
||||
const result = (<any>n)["__end"];
|
||||
Debug.assert(typeof result === "number");
|
||||
return result;
|
||||
}
|
||||
|
||||
function setEnd(n: TextRange, end: number) {
|
||||
function setEnd(n: TextRange, end: number): void {
|
||||
Debug.assert(typeof end === "number");
|
||||
(<any>n)["__end"] = end;
|
||||
}
|
||||
|
||||
@@ -582,7 +588,7 @@ namespace ts.textChanges {
|
||||
readonly node: Node;
|
||||
}
|
||||
|
||||
export function getNonformattedText(node: Node, sourceFile: SourceFile | undefined, newLine: NewLineKind): NonFormattedText {
|
||||
function getNonformattedText(node: Node, sourceFile: SourceFile | undefined, newLine: NewLineKind): NonFormattedText {
|
||||
const options = { newLine, target: sourceFile && sourceFile.languageVersion };
|
||||
const writer = new Writer(getNewLineCharacter(options));
|
||||
const printer = createPrinter(options, writer);
|
||||
@@ -590,7 +596,7 @@ namespace ts.textChanges {
|
||||
return { text: writer.getText(), node: assignPositionsToNode(node) };
|
||||
}
|
||||
|
||||
export function applyFormatting(nonFormattedText: NonFormattedText, sourceFile: SourceFile, initialIndentation: number, delta: number, rulesProvider: formatting.RulesProvider) {
|
||||
function applyFormatting(nonFormattedText: NonFormattedText, sourceFile: SourceFile, initialIndentation: number, delta: number, rulesProvider: formatting.RulesProvider) {
|
||||
const lineMap = computeLineStarts(nonFormattedText.text);
|
||||
const file: SourceFileLike = {
|
||||
text: nonFormattedText.text,
|
||||
@@ -616,14 +622,10 @@ namespace ts.textChanges {
|
||||
function assignPositionsToNode(node: Node): Node {
|
||||
const visited = visitEachChild(node, assignPositionsToNode, nullTransformationContext, assignPositionsToNodeArray, assignPositionsToNode);
|
||||
// create proxy node for non synthesized nodes
|
||||
const newNode = nodeIsSynthesized(visited)
|
||||
? visited
|
||||
: (Proxy.prototype = visited, new (<any>Proxy)());
|
||||
const newNode = nodeIsSynthesized(visited) ? visited : Object.create(visited) as Node;
|
||||
newNode.pos = getPos(node);
|
||||
newNode.end = getEnd(node);
|
||||
return newNode;
|
||||
|
||||
function Proxy() { }
|
||||
}
|
||||
|
||||
function assignPositionsToNodeArray(nodes: NodeArray<any>, visitor: Visitor, test?: (node: Node) => boolean, start?: number, count?: number) {
|
||||
|
||||
Reference in New Issue
Block a user