Skip to content

Commit 9b558f9

Browse files
authored
Remove _this, _super, and _newTarget name conflict errors (#22890)
* Add new generated name kind for reused transpiler variables * Remove error on _super or _newTarget conflict * Add test with super helper conflict * Remove error on _this conflict * Fix lint * Use flags instead of generated kinds, inline some things * Accept rename * Remove trailing whitespace * Move helper emit into printer, rather than emitter" * passthru module and target * New test, accept baselines * Make members private
1 parent 8543d30 commit 9b558f9

File tree

91 files changed

+768
-1323
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+768
-1323
lines changed

src/compiler/checker.ts

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -13647,9 +13647,6 @@ namespace ts {
1364713647
}
1364813648
}
1364913649

13650-
checkCollisionWithCapturedSuperVariable(node, node);
13651-
checkCollisionWithCapturedThisVariable(node, node);
13652-
checkCollisionWithCapturedNewTargetVariable(node, node);
1365313650
checkNestedBlockScopedBinding(node, symbol);
1365413651

1365513652
const type = getConstraintForLocation(getTypeOfSymbol(localOrExportSymbol), node);
@@ -18852,12 +18849,6 @@ namespace ts {
1885218849
}
1885318850
}
1885418851

18855-
if (produceDiagnostics && node.kind !== SyntaxKind.MethodDeclaration) {
18856-
checkCollisionWithCapturedSuperVariable(node, node.name);
18857-
checkCollisionWithCapturedThisVariable(node, node.name);
18858-
checkCollisionWithCapturedNewTargetVariable(node, node.name);
18859-
}
18860-
1886118852
return type;
1886218853
}
1886318854

@@ -21585,9 +21576,6 @@ namespace ts {
2158521576
if (produceDiagnostics) {
2158621577
checkFunctionOrMethodDeclaration(node);
2158721578
checkGrammarForGenerator(node);
21588-
checkCollisionWithCapturedSuperVariable(node, node.name);
21589-
checkCollisionWithCapturedThisVariable(node, node.name);
21590-
checkCollisionWithCapturedNewTargetVariable(node, node.name);
2159121579
checkCollisionWithRequireExportsInGeneratedCode(node, node.name);
2159221580
checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name);
2159321581
}
@@ -22012,18 +22000,6 @@ namespace ts {
2201222000
return true;
2201322001
}
2201422002

22015-
function checkCollisionWithCapturedThisVariable(node: Node, name: Identifier): void {
22016-
if (languageVersion <= ScriptTarget.ES5 && !compilerOptions.noEmit && needCollisionCheckForIdentifier(node, name, "_this")) {
22017-
potentialThisCollisions.push(node);
22018-
}
22019-
}
22020-
22021-
function checkCollisionWithCapturedNewTargetVariable(node: Node, name: Identifier): void {
22022-
if (languageVersion <= ScriptTarget.ES5 && !compilerOptions.noEmit && needCollisionCheckForIdentifier(node, name, "_newTarget")) {
22023-
potentialNewTargetCollisions.push(node);
22024-
}
22025-
}
22026-
2202722003
// this function will run after checking the source file so 'CaptureThis' is correct for all nodes
2202822004
function checkIfThisIsCapturedInEnclosingScope(node: Node): void {
2202922005
findAncestor(node, current => {
@@ -22055,33 +22031,6 @@ namespace ts {
2205522031
});
2205622032
}
2205722033

22058-
function checkCollisionWithCapturedSuperVariable(node: Node, name: Identifier) {
22059-
if (languageVersion >= ScriptTarget.ES2015 || compilerOptions.noEmit) {
22060-
return;
22061-
}
22062-
22063-
if (!needCollisionCheckForIdentifier(node, name, "_super")) {
22064-
return;
22065-
}
22066-
22067-
// bubble up and find containing type
22068-
const enclosingClass = getContainingClass(node);
22069-
// if containing type was not found or it is ambient - exit (no codegen)
22070-
if (!enclosingClass || enclosingClass.flags & NodeFlags.Ambient) {
22071-
return;
22072-
}
22073-
22074-
if (getClassExtendsHeritageClauseElement(enclosingClass)) {
22075-
const isDeclaration = node.kind !== SyntaxKind.Identifier;
22076-
if (isDeclaration) {
22077-
error(node, Diagnostics.Duplicate_identifier_super_Compiler_uses_super_to_capture_base_class_reference);
22078-
}
22079-
else {
22080-
error(node, Diagnostics.Expression_resolves_to_super_that_compiler_uses_to_capture_base_class_reference);
22081-
}
22082-
}
22083-
}
22084-
2208522034
function checkCollisionWithRequireExportsInGeneratedCode(node: Node, name: Identifier) {
2208622035
// No need to check for require or exports for ES6 modules and later
2208722036
if (modulekind >= ModuleKind.ES2015 || compilerOptions.noEmit) {
@@ -22378,9 +22327,6 @@ namespace ts {
2237822327
if (node.kind === SyntaxKind.VariableDeclaration || node.kind === SyntaxKind.BindingElement) {
2237922328
checkVarDeclaredNamesNotShadowed(node);
2238022329
}
22381-
checkCollisionWithCapturedSuperVariable(node, <Identifier>node.name);
22382-
checkCollisionWithCapturedThisVariable(node, <Identifier>node.name);
22383-
checkCollisionWithCapturedNewTargetVariable(node, <Identifier>node.name);
2238422330
checkCollisionWithRequireExportsInGeneratedCode(node, <Identifier>node.name);
2238522331
checkCollisionWithGlobalPromiseInGeneratedCode(node, <Identifier>node.name);
2238622332
}
@@ -23377,8 +23323,6 @@ namespace ts {
2337723323
checkDecorators(node);
2337823324
if (node.name) {
2337923325
checkTypeNameIsReserved(node.name, Diagnostics.Class_name_cannot_be_0);
23380-
checkCollisionWithCapturedThisVariable(node, node.name);
23381-
checkCollisionWithCapturedNewTargetVariable(node, node.name);
2338223326
checkCollisionWithRequireExportsInGeneratedCode(node, node.name);
2338323327
checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name);
2338423328
}
@@ -23907,8 +23851,6 @@ namespace ts {
2390723851
checkGrammarDecoratorsAndModifiers(node);
2390823852

2390923853
checkTypeNameIsReserved(node.name, Diagnostics.Enum_name_cannot_be_0);
23910-
checkCollisionWithCapturedThisVariable(node, node.name);
23911-
checkCollisionWithCapturedNewTargetVariable(node, node.name);
2391223854
checkCollisionWithRequireExportsInGeneratedCode(node, node.name);
2391323855
checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name);
2391423856
checkExportsOnMergedDeclarations(node);
@@ -24014,7 +23956,6 @@ namespace ts {
2401423956
}
2401523957

2401623958
if (isIdentifier(node.name)) {
24017-
checkCollisionWithCapturedThisVariable(node, node.name);
2401823959
checkCollisionWithRequireExportsInGeneratedCode(node, node.name);
2401923960
checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name);
2402023961
}
@@ -24222,7 +24163,6 @@ namespace ts {
2422224163
}
2422324164

2422424165
function checkImportBinding(node: ImportEqualsDeclaration | ImportClause | NamespaceImport | ImportSpecifier) {
24225-
checkCollisionWithCapturedThisVariable(node, node.name);
2422624166
checkCollisionWithRequireExportsInGeneratedCode(node, node.name);
2422724167
checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name);
2422824168
checkAliasSymbol(node);

src/compiler/core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2034,7 +2034,7 @@ namespace ts {
20342034
return compilerOptions.target || ScriptTarget.ES3;
20352035
}
20362036

2037-
export function getEmitModuleKind(compilerOptions: CompilerOptions) {
2037+
export function getEmitModuleKind(compilerOptions: {module?: CompilerOptions["module"], target?: CompilerOptions["target"]}) {
20382038
return typeof compilerOptions.module === "number" ?
20392039
compilerOptions.module :
20402040
getEmitScriptTarget(compilerOptions) >= ScriptTarget.ES2015 ? ModuleKind.ES2015 : ModuleKind.CommonJS;

0 commit comments

Comments
 (0)