Skip to content

Fix this-binding in getTA and getUser - #320

Open
sadegh wants to merge 1 commit into
Mathieu2301:mainfrom
sadegh:fix/this-binding-destructured-imports
Open

Fix this-binding in getTA and getUser#320
sadegh wants to merge 1 commit into
Mathieu2301:mainfrom
sadegh:fix/this-binding-destructured-imports

Conversation

@sadegh

@sadegh sadegh commented Aug 15, 2026

Copy link
Copy Markdown

getTA and getUser reach sibling functions through this, which only resolves when the function is called as a method:

const [m] = await TradingView.searchMarketV3("binance:BTCUSD");
await m.getTA(); // works

With a destructured import the receiver is lost. miscRequests.js is sloppy-mode CommonJS, so this falls back to globalThis and the lookup throws:

const { searchMarketV3 } = require("./main");
const [m] = await searchMarketV3("binance:BTCUSD");
await m.getTA(); // TypeError: this.getTA is not a function

tests/search.test.ts imports exactly that way, so both "gets TA for ..." tests fail on current main. They pass with this change.

Resolving through module.exports doesn't depend on how the caller got the function. Applied the same fix to getUser's redirect recursion, which would throw the same way on any redirect.

getTA and getUser reach sibling functions through this, which is only
the module when called as a method (TradingView.searchMarketV3(...)).
With a destructured import the receiver is lost, so in this sloppy-mode
CommonJS module this becomes globalThis and it throws
'this.getTA is not a function'.

tests/search.test.ts imports that way, so the TA tests fail on main.

Resolve through module.exports, which doesn't depend on the call site.
Same fix applied to getUser's redirect recursion.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant