You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
createTempVariable() should also try to not shadowing upper lexical environment temp variables #40826
constts=require('typescript')constt=require('./ReactFreshTypeScriptTransformer.js')console.log(ts.transpileModule(`import { useDefaultWallet } from '../../plugins/Wallet/hooks/useWallet'/** * Get the address of the default wallet */export function useAccount() { const wallet = useDefaultWallet() return wallet?.address ?? ''}`,{transformers: {before: [t()]},compilerOptions: {target: ts.ScriptTarget.ES2017},}).outputText)
The buggy result using createTempVariable():
var_a;_a=$RefreshSig$();import{useDefaultWallet}from'../../plugins/Wallet/hooks/useWallet';/** * Get the address of the default wallet */exportfunctionuseAccount(){var_a;_a();constwallet=useDefaultWallet();return(_a=wallet===null||wallet===void0 ? void0 : wallet.address)!==null&&_a!==void0 ? _a : '';}_a(useAccount,"Zqcse9ORXvHAGVGDGSjWLnVdvA4=",false,()=>[useDefaultWallet]);
As you can see, downleveling ?? syntax create a new variable also called "_a" which shadows my upper variable "_a", then _a() leads to an runtime error.
The correct version using createFileLevelUniqueName():
var$c0;$c0=$RefreshSig$();import{useDefaultWallet}from'../../plugins/Wallet/hooks/useWallet';/** * Get the address of the default wallet */exportfunctionuseAccount(){var_a;$c0();constwallet=useDefaultWallet();return(_a=wallet===null||wallet===void0 ? void0 : wallet.address)!==null&&_a!==void0 ? _a : '';}$c0(useAccount,"Zqcse9ORXvHAGVGDGSjWLnVdvA4=",false,()=>[useDefaultWallet]);
Activity
Jack-Works commentedon Oct 4, 2020
If createTempVariable can accept this enum, this problem will be resolved!
Jack-Works commentedon Oct 4, 2020
Exposed: (4.1.0 beta) signature
createTempVariable(recordTempVariable: ((node: Identifier) => void) | undefined): IdentifierSignature in source code:
createTempVariable(recordTempVariable: ((node: Identifier) => void) | undefined, reservedInNestedScopes?: boolean): GeneratedIdentifierJack-Works commentedon Oct 4, 2020
Please explosure those signatures! It's very useful when transforming code
rbuckton commentedon Dec 17, 2020
In the meantime, is
factory.createUniqueNamean option?Jack-Works commentedon Dec 17, 2020
I don't know, but expose
reservedInNestedScopes?: booleanwill be very useful