Skip to content

Commit 0d2ed4e

Browse files
committed
remove hacks
1 parent 542a2b6 commit 0d2ed4e

File tree

4 files changed

+11
-14
lines changed

4 files changed

+11
-14
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13758,7 +13758,7 @@ namespace ts {
1375813758
(<PropertyAccessExpression>parent).name.escapedText === "length" || (
1375913759
parent.parent.kind === SyntaxKind.CallExpression
1376013760
&& isIdentifier((parent as PropertyAccessExpression).name)
13761-
&& isPushOrUnshiftIdentifier((parent as PropertyAccessExpression).name as Identifier)));
13761+
&& isPushOrUnshiftIdentifier((parent as PropertyAccessExpression).name)));
1376213762
const isElementAssignment = parent.kind === SyntaxKind.ElementAccessExpression &&
1376313763
(<ElementAccessExpression>parent).expression === root &&
1376413764
parent.parent.kind === SyntaxKind.BinaryExpression &&

src/compiler/utilities.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2640,8 +2640,8 @@ namespace ts {
26402640
return node.kind === SyntaxKind.Identifier && (<Identifier>node).escapedText === "Symbol";
26412641
}
26422642

2643-
export function isPushOrUnshiftIdentifier(node: Identifier) {
2644-
return node.escapedText === "push" || node.escapedText === "unshift";
2643+
export function isPushOrUnshiftIdentifier(node: Identifier | PrivateName) {
2644+
return isIdentifier(node) && node.escapedText === "push" || node.escapedText === "unshift";
26452645
}
26462646

26472647
export function isParameterDeclaration(node: VariableLikeDeclaration) {

src/services/codefixes/convertToEs6Module.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,9 @@ namespace ts.codefix {
6565
function collectExportRenames(sourceFile: SourceFile, checker: TypeChecker, identifiers: Identifiers): ExportRenames {
6666
const res = createMap<string>();
6767
forEachExportReference(sourceFile, node => {
68-
const name = node.name as Identifier;
69-
const { text, originalKeywordKind } = name;
68+
const { text, originalKeywordKind } = node.name;
7069
if (!res.has(text) && (originalKeywordKind !== undefined && isNonContextualKeyword(originalKeywordKind)
71-
|| checker.resolveName(name.text, node, SymbolFlags.Value, /*excludeGlobals*/ true))) {
70+
|| checker.resolveName(node.name.text, node, SymbolFlags.Value, /*excludeGlobals*/ true))) {
7271
// Unconditionally add an underscore in case `text` is a keyword.
7372
res.set(text, makeUniqueName(`_${text}`, identifiers));
7473
}
@@ -81,7 +80,7 @@ namespace ts.codefix {
8180
if (isAssignmentLhs) {
8281
return;
8382
}
84-
const { text } = node.name as Identifier;
83+
const { text } = node.name;
8584
changes.replaceNode(sourceFile, node, createIdentifier(exports.get(text) || text));
8685
});
8786
}
@@ -151,7 +150,7 @@ namespace ts.codefix {
151150
}
152151
else if (isPropertyAccessExpression(initializer) && isRequireCall(initializer.expression, /*checkArgumentIsStringLiteralLike*/ true)) {
153152
foundImport = true;
154-
return convertPropertyAccessImport(name, (initializer.name as Identifier).text, initializer.expression.arguments[0], identifiers, quotePreference);
153+
return convertPropertyAccessImport(name, initializer.name.text, initializer.expression.arguments[0], identifiers, quotePreference);
155154
}
156155
}
157156
// Move it out to its own variable statement. (This will not be used if `!foundImport`)
@@ -252,7 +251,7 @@ namespace ts.codefix {
252251
exports: ExportRenames,
253252
): void {
254253
// If "originalKeywordKind" was set, this is e.g. `exports.
255-
const { text } = assignment.left.name as Identifier;
254+
const { text } = assignment.left.name;
256255
const rename = exports.get(text);
257256
if (rename !== undefined) {
258257
/*
@@ -290,7 +289,7 @@ namespace ts.codefix {
290289
}
291290

292291
function convertExportsPropertyAssignment({ left, right, parent }: BinaryExpression & { left: PropertyAccessExpression }, sourceFile: SourceFile, changes: textChanges.ChangeTracker): void {
293-
const name = (left.name as Identifier).text;
292+
const name = left.name.text;
294293
if ((isFunctionExpression(right) || isArrowFunction(right) || isClassExpression(right)) && (!right.name || right.name.text === name)) {
295294
// `exports.f = function() {}` -> `export function f() {}` -- Replace `exports.f = ` with `export `, and insert the name after `function`.
296295
changes.replaceRange(sourceFile, { pos: left.getStart(sourceFile), end: right.getStart(sourceFile) }, createToken(SyntaxKind.ExportKeyword), { suffix: " " });
@@ -399,9 +398,7 @@ namespace ts.codefix {
399398

400399
const { parent } = use;
401400
if (isPropertyAccessExpression(parent)) {
402-
const { expression, name } = parent;
403-
// TODO: PrivateName fix
404-
const { text: propertyName } = name as Identifier;
401+
const { expression, name: { text: propertyName } } = parent;
405402
Debug.assert(expression === use); // Else shouldn't have been in `collectIdentifiers`
406403
let idName = namedBindingsNames.get(propertyName);
407404
if (idName === undefined) {

src/services/refactors/moveToNewFile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ namespace ts.refactor {
665665
}
666666

667667
function nameOfTopLevelDeclaration(d: TopLevelDeclaration): Identifier | undefined {
668-
return d.kind === SyntaxKind.ExpressionStatement ? d.expression.left.name as Identifier : tryCast(d.name, isIdentifier);
668+
return d.kind === SyntaxKind.ExpressionStatement ? d.expression.left.name : tryCast(d.name, isIdentifier);
669669
}
670670

671671
function getTopLevelDeclarationStatement(d: TopLevelDeclaration): TopLevelDeclarationStatement {

0 commit comments

Comments
 (0)