Port missing collision detection checks from checkCollisionsForDeclarationName#2087
Conversation
Add potentialWeakMapSetCollisions array and collision checking functions Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
|
@copilot you didn't run tests, accept baselines, etc |
- Add nil check for node.Name() in checkWeakMapSetCollision - Accept baseline for privateNameWeakMapCollision test Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
|
@copilot there are more checks than just |
- Add checkCollisionWithGlobalPromiseInGeneratedCode for Promise collision detection - Add recordPotentialCollisionWithReflectInGeneratedCode and checkReflectCollision for Reflect collision detection - Add checkClassNameCollisionWithObject for Object class name collision detection - Update checkCollisionsForDeclarationName to match TypeScript checker structure - Add potentialReflectCollisions array to Checker struct - Process Reflect collisions in checkSourceFile - Accept updated baselines for new collision checks Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Ported all remaining collision checks in d6e3417:
All tests passing with updated baselines. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
There was a problem hiding this comment.
Pull request overview
Ports additional generated-name collision checks from TypeScript’s checkCollisionsForDeclarationName into the Go checker to close parity gaps (notably TS18027/TS2529/TS2818/TS2725).
Changes:
- Added deferred collision detection for
WeakMap/WeakSet,Promise, andReflect, plus newNodeCheckFlagsto track private-identifier scopes andsuperproperty access in static initializers. - Integrated private-identifier scope marking into property/method/accessor checking, and added tracking in
checkSuperExpressionfor Reflect-related collisions. - Updated/accepted a broad set of baseline error outputs to reflect the newly reported diagnostics.
Reviewed changes
Copilot reviewed 38 out of 38 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/checker/checker.go | Implements new collision checks and supporting scope/flag tracking in the checker. |
| internal/checker/types.go | Adds new NodeCheckFlags bits used by collision detection. |
| testdata/baselines/reference/submodule/conformance/superInStaticMembers1(target=es2021).errors.txt.diff | Baseline diff removed after accepting new Reflect collision behavior. |
| testdata/baselines/reference/submodule/conformance/superInStaticMembers1(target=es2021).errors.txt | New/updated expected errors for Reflect collisions. |
| testdata/baselines/reference/submodule/conformance/superInStaticMembers1(target=es2015).errors.txt.diff | Baseline diff removed after accepting new Reflect collision behavior. |
| testdata/baselines/reference/submodule/conformance/superInStaticMembers1(target=es2015).errors.txt | New/updated expected errors for Reflect collisions. |
| testdata/baselines/reference/submodule/conformance/nodeModulesGeneratedNameCollisions(module=nodenext).errors.txt.diff | Baseline diff removed after accepting Object-class-name collision error. |
| testdata/baselines/reference/submodule/conformance/nodeModulesGeneratedNameCollisions(module=nodenext).errors.txt | Updated expected errors to include TS2725 for class Object in NodeNext. |
| testdata/baselines/reference/submodule/conformance/nodeModulesGeneratedNameCollisions(module=node20).errors.txt.diff | Baseline diff removed after accepting Object-class-name collision error. |
| testdata/baselines/reference/submodule/conformance/nodeModulesGeneratedNameCollisions(module=node20).errors.txt | Updated expected errors to include TS2725 for class Object in Node20. |
| testdata/baselines/reference/submodule/conformance/nodeModulesGeneratedNameCollisions(module=node18).errors.txt.diff | Baseline diff removed after accepting Object-class-name collision error. |
| testdata/baselines/reference/submodule/conformance/nodeModulesGeneratedNameCollisions(module=node18).errors.txt | Updated expected errors to include TS2725 for class Object in Node18. |
| testdata/baselines/reference/submodule/conformance/nodeModulesGeneratedNameCollisions(module=node16).errors.txt.diff | Baseline diff removed after accepting Object-class-name collision error. |
| testdata/baselines/reference/submodule/conformance/nodeModulesGeneratedNameCollisions(module=node16).errors.txt | Updated expected errors to include TS2725 for class Object in Node16. |
| testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsGeneratedNameCollisions(module=nodenext).errors.txt.diff | Baseline diff removed after accepting Object-class-name collision error (AllowJs). |
| testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsGeneratedNameCollisions(module=nodenext).errors.txt | Updated expected errors to include TS2725 for class Object in JS (NodeNext). |
| testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsGeneratedNameCollisions(module=node20).errors.txt.diff | Baseline diff removed after accepting Object-class-name collision error (AllowJs). |
| testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsGeneratedNameCollisions(module=node20).errors.txt | Updated expected errors to include TS2725 for class Object in JS (Node20). |
| testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsGeneratedNameCollisions(module=node18).errors.txt.diff | Baseline diff removed after accepting Object-class-name collision error (AllowJs). |
| testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsGeneratedNameCollisions(module=node18).errors.txt | Updated expected errors to include TS2725 for class Object in JS (Node18). |
| testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsGeneratedNameCollisions(module=node16).errors.txt.diff | Baseline diff removed after accepting Object-class-name collision error (AllowJs). |
| testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsGeneratedNameCollisions(module=node16).errors.txt | Updated expected errors to include TS2725 for class Object in JS (Node16). |
| testdata/baselines/reference/submodule/conformance/exportDefaultClassNameWithObject(target=es2015).errors.txt.diff | Baseline diff removed after accepting TS2725 for default-exported class Object. |
| testdata/baselines/reference/submodule/conformance/exportDefaultClassNameWithObject(target=es2015).errors.txt | New/updated expected TS2725 for default-exported class Object. |
| testdata/baselines/reference/submodule/conformance/exportClassNameWithObjectCommonJS(target=es2015).errors.txt.diff | Baseline diff removed after accepting TS2725 for exported class Object. |
| testdata/baselines/reference/submodule/conformance/exportClassNameWithObjectCommonJS(target=es2015).errors.txt | New/updated expected TS2725 for exported class Object. |
| testdata/baselines/reference/submodule/compiler/staticInstanceResolution5.errors.txt.diff | Baseline diff added for new Promise collision diagnostic. |
| testdata/baselines/reference/submodule/compiler/staticInstanceResolution5.errors.txt | Updated expected errors to include TS2529 Promise collision. |
| testdata/baselines/reference/submodule/compiler/staticInstanceResolution3.errors.txt.diff | Baseline diff added for new Promise collision diagnostic. |
| testdata/baselines/reference/submodule/compiler/staticInstanceResolution3.errors.txt | Updated expected errors to include TS2529 Promise collision. |
| testdata/baselines/reference/submodule/compiler/privateNameWeakMapCollision.errors.txt.diff | Baseline diff removed after accepting WeakMap/WeakSet collision diagnostics. |
| testdata/baselines/reference/submodule/compiler/privateNameWeakMapCollision.errors.txt | New/updated expected TS18027 WeakMap/WeakSet collision diagnostics. |
| testdata/baselines/reference/submodule/compiler/moduleInTypePosition1.errors.txt.diff | Baseline diff added for new Promise collision diagnostic. |
| testdata/baselines/reference/submodule/compiler/moduleInTypePosition1.errors.txt | Updated expected errors to include TS2529 Promise collision. |
| testdata/baselines/reference/submodule/compiler/instanceofOperator(target=es2015).errors.txt.diff | Baseline diff removed after accepting TS2725 for class Object in namespace test. |
| testdata/baselines/reference/submodule/compiler/instanceofOperator(target=es2015).errors.txt | New/updated expected TS2725 for class Object. |
| testdata/baselines/reference/submodule/compiler/checkForObjectTooStrict(target=es2015).errors.txt.diff | Baseline diff removed after accepting TS2725 for exported class Object inside namespace. |
| testdata/baselines/reference/submodule/compiler/checkForObjectTooStrict(target=es2015).errors.txt | New/updated expected TS2725 for exported class Object. |
| enclosingBlockScope := ast.GetEnclosingBlockScopeContainer(node) | ||
| if c.nodeLinks.Get(enclosingBlockScope).flags&NodeCheckFlagsContainsClassWithPrivateIdentifiers != 0 { | ||
| name := node.Name() | ||
| if name != nil && ast.IsIdentifier(name) { | ||
| c.errorSkippedOnNoEmit(node, diagnostics.Compiler_reserves_name_0_when_emitting_private_identifier_downlevel, name.Text()) | ||
| } |
There was a problem hiding this comment.
checkWeakMapSetCollision reports the diagnostic at node even though the collision is for the identifier itself. Other collision diagnostics in this file use name as the location (e.g. require/exports and Promise), which gives a more precise span. Consider emitting the TS18027 diagnostic at name instead of the whole declaration node.
There was a problem hiding this comment.
this is a pure port, though we could do it as an improvement
| if hasCollision { | ||
| name := node.Name() | ||
| if name != nil && ast.IsIdentifier(name) { | ||
| c.errorSkippedOnNoEmit(node, diagnostics.Duplicate_identifier_0_Compiler_reserves_name_1_when_emitting_super_references_in_static_initializers, scanner.DeclarationNameToString(name), "Reflect") | ||
| } |
There was a problem hiding this comment.
checkReflectCollision reports the TS2818 diagnostic at node rather than at the identifier name. Since other collision checks report on the name node, this can produce a less precise error span (especially for declarations where node covers more than the identifier). Consider using name as the diagnostic location here as well.
There was a problem hiding this comment.
this is a pure port, though we could do it as an improvement
| // Reset flags (for incremental scenarios) | ||
| node.Flags &^= ast.NodeFlagsReachabilityCheckFlags | ast.NodeFlagsContainsThis | ||
| node.Flags &^= ast.NodeFlagsReachabilityAndEmitFlags | ast.NodeFlagsContainsThis |
There was a problem hiding this comment.
Not for this PR but this comment should get updated (or, this code deleted)

Ports all missing collision detection checks from TypeScript's
checkCollisionsForDeclarationNamefunction to the Go implementation.Changes Made
WeakMap/WeakSet collision detection: Records potential collisions when WeakMap/WeakSet identifiers are declared (for ES2021 and earlier targets), marks enclosing block scopes with ContainsClassWithPrivateIdentifiers flag when private fields are found, and reports TS18027 errors for collisions in scopes with private identifiers.
Promise collision detection: Implements
checkCollisionWithGlobalPromiseInGeneratedCodeto detect when the Promise identifier is shadowed in external/CommonJS modules for ES2016 and earlier targets.Reflect collision detection: Implements
recordPotentialCollisionWithReflectInGeneratedCodeandcheckReflectCollisionto detect when the Reflect identifier is shadowed in contexts containing super property access in static initializers (for ES2021 and earlier).Object class name collision: Implements
checkClassNameCollisionWithObjectto validate that class names are not "Object" when targeting ES5 or above with certain module formats.Infrastructure: Added
potentialWeakMapSetCollisionsandpotentialReflectCollisionsarrays to Checker struct, implementedsetNodeLinksForPrivateIdentifierScopeto mark scopes with private identifiers, and integrated all collision checks intocheckSourceFilefor deferred processing.Implementation Details
All collision checks use
errorSkippedOnNoEmitto match TypeScript's behavior, ensuring errors are only reported when actually emitting code (not with--noEmitflag). The implementation properly handles nil checks and follows the same deferred checking pattern as TypeScript for collisions that depend on information gathered during the entire source file analysis.Testing
The changes bring the Go implementation into parity with TypeScript's collision detection in
checkCollisionsForDeclarationName.Fixes #2086
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.