Skip to content

Commit 7b73e8f

Browse files
committed
initial revision of extract method
1 parent f5d566e commit 7b73e8f

File tree

9 files changed

+1414
-26
lines changed

9 files changed

+1414
-26
lines changed

Jakefile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ var harnessSources = harnessCoreSources.concat([
126126
"projectErrors.ts",
127127
"matchFiles.ts",
128128
"initializeTSConfig.ts",
129+
"extractMethods.ts",
129130
"printer.ts",
130131
"textChanges.ts",
131132
"transform.ts",

src/compiler/checker.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,10 @@ namespace ts {
187187
// since we are only interested in declarations of the module itself
188188
return tryFindAmbientModule(moduleName, /*withAugmentations*/ false);
189189
},
190-
getApparentType
190+
getApparentType,
191+
resolveName(name, location, meaning) {
192+
return resolveName(location, name, meaning, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined);
193+
}
191194
};
192195

193196
const tupleTypes: GenericType[] = [];

src/compiler/factory.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -672,10 +672,11 @@ namespace ts {
672672
return node;
673673
}
674674

675-
export function updateBinary(node: BinaryExpression, left: Expression, right: Expression) {
675+
export function updateBinary(node: BinaryExpression, left: Expression, right: Expression, token?: Token<BinaryOperator>) {
676676
return node.left !== left
677677
|| node.right !== right
678-
? updateNode(createBinary(left, node.operatorToken, right), node)
678+
|| (token && token !== node.operatorToken)
679+
? updateNode(createBinary(left, token || node.operatorToken, right), node)
679680
: node;
680681
}
681682

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2517,6 +2517,7 @@ namespace ts {
25172517
/* @internal */ getIdentifierCount(): number;
25182518
/* @internal */ getSymbolCount(): number;
25192519
/* @internal */ getTypeCount(): number;
2520+
/* @internal */ resolveName(name: string, location: Node, meaning: SymbolFlags): Symbol;
25202521
}
25212522

25222523
export interface SymbolDisplayBuilder {

src/compiler/visitor.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,13 @@ namespace ts {
204204
* @param visitor The callback used to visit each child.
205205
* @param context A lexical environment context for the visitor.
206206
*/
207-
export function visitEachChild<T extends Node>(node: T | undefined, visitor: Visitor, context: TransformationContext, nodesVisitor?: typeof visitNodes): T | undefined;
207+
export function visitEachChild<T extends Node>(node: T | undefined, visitor: Visitor, context: TransformationContext, nodesVisitor?: typeof visitNodes, tokenVisitor?: Visitor): T | undefined;
208208

209-
export function visitEachChild(node: Node, visitor: Visitor, context: TransformationContext, nodesVisitor = visitNodes): Node {
209+
export function visitEachChild(node: Node, visitor: Visitor, context: TransformationContext, nodesVisitor = visitNodes, tokenVisitor?: Visitor): Node {
210210
if (node === undefined) {
211211
return undefined;
212212
}
213+
noop
213214

214215
const kind = node.kind;
215216
// No need to visit nodes with no children.
@@ -396,7 +397,8 @@ namespace ts {
396397
case SyntaxKind.BinaryExpression:
397398
return updateBinary(<BinaryExpression>node,
398399
visitNode((<BinaryExpression>node).left, visitor, isExpression),
399-
visitNode((<BinaryExpression>node).right, visitor, isExpression));
400+
visitNode((<BinaryExpression>node).right, visitor, isExpression),
401+
tokenVisitor ? visitNode((<BinaryExpression>node).operatorToken, tokenVisitor) : (<BinaryExpression>node).operatorToken);
400402

401403
case SyntaxKind.PrefixUnaryExpression:
402404
return updatePrefix(<PrefixUnaryExpression>node,
@@ -419,7 +421,7 @@ namespace ts {
419421

420422
case SyntaxKind.YieldExpression:
421423
return updateYield(<YieldExpression>node,
422-
(<YieldExpression>node).asteriskToken,
424+
tokenVisitor ? visitNode((<YieldExpression>node).asteriskToken, tokenVisitor) : (<YieldExpression>node).asteriskToken,
423425
visitNode((<YieldExpression>node).expression, visitor, isExpression));
424426

425427
case SyntaxKind.SpreadElement:
@@ -555,7 +557,7 @@ namespace ts {
555557
return updateFunctionDeclaration(<FunctionDeclaration>node,
556558
nodesVisitor((<FunctionDeclaration>node).decorators, visitor, isDecorator),
557559
nodesVisitor((<FunctionDeclaration>node).modifiers, visitor, isModifier),
558-
(<FunctionDeclaration>node).asteriskToken,
560+
visitNode((<FunctionDeclaration>node).asteriskToken, visitor),
559561
visitNode((<FunctionDeclaration>node).name, visitor, isIdentifier),
560562
nodesVisitor((<FunctionDeclaration>node).typeParameters, visitor, isTypeParameter),
561563
visitParameterList((<FunctionDeclaration>node).parameters, visitor, context, nodesVisitor),

0 commit comments

Comments
 (0)