fix(hazard_symbol): start fixing dual-package hazard symbol #436
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix Dual Package Hazard with
Symbol.hasInstance
(Draft)Status: Draft — currently updating utils-ts
Problem
When a package is loaded as both CommonJS and ESM,
instanceof
checks can fail across boundaries because the same class is created twice (one per loader). This can makeinstanceof
returnfalse
for valid instances.Solution
Add a unique instance marker property and a static
Symbol.hasInstance
method to each class soinstanceof
works regardless of how the class was loaded.Pattern example:
Files to Update (tick as you go)
./types/account.ts:20
— MultisigAccount./types/account.ts:79
— SigningAccount (implementsAccount
)./types/app-arc56.ts:23
— Arc56Method (extendsalgosdk.ABIMethod
)./types/app-client.ts:478
— AppClient./types/app-client.ts:1794
— ApplicationClient./types/app-manager.ts:98
— AppManager./types/account-manager.ts:46
— AccountManager./types/algorand-client-transaction-sender.ts:36
— AlgorandClientTransactionSender./types/app-deployer.ts:112
— AppDeployer./types/logic-error.ts:22
— LogicError (extendsError
)./types/client-manager.ts:48
— ClientManager./types/algorand-client.ts:18
— AlgorandClient./types/async-event-emitter.ts:5
— AsyncEventEmitter./types/kmd-account-manager.ts:10
— KmdAccountManager./types/algorand-client-transaction-creator.ts:8
— AlgorandClientTransactionCreator./types/composer.ts:547
— TransactionComposer./types/algo-http-client-with-retry.ts:6
— AlgoHttpClientWithRetry (extendsURLTokenBaseHTTPClient
)./types/dispenser-client.ts:72
— TestNetDispenserApiClient./types/config.ts:28
— UpdatableConfig (implementsReadonly<Config>
)./types/amount.ts:4
— AlgoAmount./types/asset-manager.ts:138
— AssetManager./types/app-factory.ts:170
— AppFactory./testing/test-logger.ts:8
— TestLogger (implementsLogger
)./testing/transaction-logger.ts:12
— TransactionLogger./util.ts:25
— UnsafeConversionError (extendsError
)Testing
tests/11.DualPackageHazard.ts
verifies cross-moduleinstanceof
for both CJS and ESM.instanceof
returnstrue
across boundaries.