TypeScript Version: 3.9.3
Search Terms:
Code
I'm using createTempVariable but I found it is buggy.
The buggy version: Jack-Works/react@792a7f7#diff-6624517c3255932b3079f651161b7df0
Fixed version:
Jack-Works/react@4ae646b#diff-6624517c3255932b3079f651161b7df0
Reproduction:
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]);
TypeScript Version: 3.9.3
Search Terms:
Code
I'm using createTempVariable but I found it is buggy.
The buggy version: Jack-Works/react@792a7f7#diff-6624517c3255932b3079f651161b7df0
Fixed version:
Jack-Works/react@4ae646b#diff-6624517c3255932b3079f651161b7df0
Reproduction:
The buggy result using
createTempVariable():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():