Skip to content

Commit 313ee31

Browse files
committed
Move forEachFreeIdentifier to compiler/utilities.ts
1 parent 34f6e9d commit 313ee31

File tree

3 files changed

+23
-42
lines changed

3 files changed

+23
-42
lines changed

src/compiler/transformers/es2015.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4422,25 +4422,6 @@ namespace ts {
44224422
}
44234423
}
44244424

4425-
function forEachFreeIdentifier(node: Node, cb: (id: Identifier) => void): void {
4426-
if (isIdentifier(node) && isFreeIdentifier(node)) cb(node);
4427-
forEachChild(node, child => forEachFreeIdentifier(child, cb));
4428-
}
4429-
4430-
function isFreeIdentifier(node: Identifier): boolean {
4431-
const { parent } = node;
4432-
switch (parent.kind) {
4433-
case SyntaxKind.PropertyAccessExpression:
4434-
return (parent as PropertyAccessExpression).name !== node;
4435-
case SyntaxKind.BindingElement:
4436-
return (parent as BindingElement).propertyName !== node;
4437-
case SyntaxKind.ImportSpecifier:
4438-
return (parent as ImportSpecifier).propertyName !== node;
4439-
default:
4440-
return true;
4441-
}
4442-
}
4443-
44444425
function createNonCollidingName(name: string, node: Node): string {
44454426
const identifiers = new Set<string>();
44464427
forEachFreeIdentifier(node, (identifier) => {

src/compiler/utilities.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7418,4 +7418,27 @@ namespace ts {
74187418
const declaration = symbol.valueDeclaration && getRootDeclaration(symbol.valueDeclaration);
74197419
return !!declaration && (isParameter(declaration) || isCatchClauseVariableDeclaration(declaration));
74207420
}
7421+
7422+
/**
7423+
* A free identifier is an identifier that can be accessed through name lookup as a local variable.
7424+
* In the expression `x.y`, `x` is a free identifier, but `y` is not.
7425+
*/
7426+
export function forEachFreeIdentifier(node: Node, cb: (id: Identifier) => void): void {
7427+
if (isIdentifier(node) && isFreeIdentifier(node)) cb(node);
7428+
forEachChild(node, child => forEachFreeIdentifier(child, cb));
7429+
}
7430+
7431+
export function isFreeIdentifier(node: Identifier): boolean {
7432+
const { parent } = node;
7433+
switch (parent.kind) {
7434+
case SyntaxKind.PropertyAccessExpression:
7435+
return (parent as PropertyAccessExpression).name !== node;
7436+
case SyntaxKind.BindingElement:
7437+
return (parent as BindingElement).propertyName !== node;
7438+
case SyntaxKind.ImportSpecifier:
7439+
return (parent as ImportSpecifier).propertyName !== node;
7440+
default:
7441+
return true;
7442+
}
7443+
}
74217444
}

src/services/codefixes/convertToEs6Module.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -519,29 +519,6 @@ namespace ts.codefix {
519519
return map;
520520
}
521521

522-
/**
523-
* A free identifier is an identifier that can be accessed through name lookup as a local variable.
524-
* In the expression `x.y`, `x` is a free identifier, but `y` is not.
525-
*/
526-
function forEachFreeIdentifier(node: Node, cb: (id: Identifier) => void): void {
527-
if (isIdentifier(node) && isFreeIdentifier(node)) cb(node);
528-
node.forEachChild(child => forEachFreeIdentifier(child, cb));
529-
}
530-
531-
function isFreeIdentifier(node: Identifier): boolean {
532-
const { parent } = node;
533-
switch (parent.kind) {
534-
case SyntaxKind.PropertyAccessExpression:
535-
return (parent as PropertyAccessExpression).name !== node;
536-
case SyntaxKind.BindingElement:
537-
return (parent as BindingElement).propertyName !== node;
538-
case SyntaxKind.ImportSpecifier:
539-
return (parent as ImportSpecifier).propertyName !== node;
540-
default:
541-
return true;
542-
}
543-
}
544-
545522
// Node helpers
546523

547524
function functionExpressionToDeclaration(name: string | undefined, additionalModifiers: readonly Modifier[], fn: FunctionExpression | ArrowFunction | MethodDeclaration, useSitesToUnqualify: ESMap<Node, Node> | undefined): FunctionDeclaration {

0 commit comments

Comments
 (0)