oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
71.8k stars 2.56k forks source link

Compiler issue: Cannot declare a var variable that shadows a let/const/class variable: '__importStar' #12176

Open joaoruntime opened 1 week ago

joaoruntime commented 1 week ago

What version of Bun is running?

1.1.16

What platform is your computer?

Darwin 21.6.0 x86_64 i386

What steps can reproduce the bug?

package.json

{
  "name": "zen",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "type": "commonjs",
  "scripts": {
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@whiskeysockets/baileys": "^6.7.5",
    "form-data": "4.0.0",
    "qrcode-terminal": "0.12.0"
  },
  "devDependencies": {
    "@types/node": "^20.14.8",
    "ts-node": "10.9.2",
    "typescript": "^5.5.2"
  }
}

testTS.ts

import { ConnectionState, MessageUpsertType, proto } from "@whiskeysockets/baileys";

import { default as WabotSocket, useMultiFileAuthState } from "@whiskeysockets/baileys";

(async function connect() {
  const { state, saveCreds } = await useMultiFileAuthState("auth");
  const bot = WabotSocket({
    browser: ["Chrome (Linux)", "", ""],
    auth: state,
    printQRInTerminal: true,
    defaultQueryTimeoutMs: undefined,
    syncFullHistory: false,
  });

  bot.ev.on("messages.upsert", async function (
    {
      messages,
    }: {
      messages: proto.IWebMessageInfo[];
      type: MessageUpsertType;
    }
  ) {
    const m = messages[0];
    if (!m.message) return;
    const messageType = Object.keys(m.message);
    console.log(m)
    if (!m.key.remoteJid?.endsWith("@g.us")) return;
    if (!m.key.fromMe) return;
    if (!messageType.includes("audioMessage")) return;

    await bot.sendMessage(m.key.remoteJid as string, { text: "hola mundo" }, { quoted: m });
  })

  bot.ev.on("connection.update", (c: Partial<ConnectionState>) => {
    const { connection, lastDisconnect } = c;
    if (lastDisconnect == undefined) return;
    if (connection === "close") {
      console.log(lastDisconnect);
      connect();
    }
    if (connection === "open"){
        console.log(bot?.user?.id.split(":")[0])
    }
  });
  bot.ev.on("creds.update", saveCreds)
})();

What is the expected behavior?

The script initiate the connections with the service and return a QR code after that the app finish their connection and run as expected

bun run ./src/testTS.ts  

{"level":30,"time":"2024-06-23T22:56:05.009Z","pid":57726,"hostname":"runtime","class":"baileys","browser":["Chrome (Linux)","",""],"helloMsg":{"clientHello":{"ephemeral":"oEIL2E1am4KB6jBpR393x0BECAr0AKlAP2g0eCGjpSg="}},"msg":"connected to WA"}
{"level":30,"time":"2024-06-23T22:56:05.246Z","pid":57726,"hostname":"runtime","class":"baileys","node":{"username":"573132603018","passive":true,"userAgent":{"platform":"WEB","appVersion":{"primary":2,"secondary":2413,"tertiary":1},"mcc":"000","mnc":"000","osVersion":"0.1","manufacturer":"","device":"Desktop","osBuildNumber":"0.1","releaseChannel":"RELEASE","localeLanguageIso6391":"en","localeCountryIso31661Alpha2":"US"},"webInfo":{"webSubPlatform":"WEB_BROWSER"},"connectType":"WIFI_UNKNOWN","connectReason":"USER_ACTIVATED","device":6},"msg":"logging in..."}
{"level":30,"time":"2024-06-23T22:56:06.578Z","pid":57726,"hostname":"runtime","class":"baileys","msg":"29 pre-keys found on server"}
{"level":30,"time":"2024-06-23T22:56:06.806Z","pid":57726,"hostname":"runtime","class":"baileys","msg":"opened connection to WA"}
{"level":30,"time":"2024-06-23T22:56:07.100Z","pid":57726,"hostname":"runtime","class":"baileys","msg":"handled 0 offline messages/notifications"}

What do you see instead?

SyntaxError: Cannot declare a var variable that shadows a let/const/class variable: '__importStar'.

bun run ./src/testTS.ts                                                                                                    ──(Wed,Jun26)─┘
13 | var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14 |     Object.defineProperty(o, "default", { enumerable: true, value: v });
15 | }) : function(o, v) {
16 |     o["default"] = v;
17 | });
18 | var __importStar = (this && this.__importStar) || function (mod) {
     ^
SyntaxError: Cannot declare a var variable that shadows a let/const/class variable: '__importStar'.
      at <parse> (/Users/joao/Documents/BUN/2tex/node_modules/@whiskeysockets/baileys/lib/Utils/messages-media.js:18:1)
      at anonymous (native:1:1)
      at /Users/joao/Documents/BUN/2tex/node_modules/@whiskeysockets/baileys/lib/Utils/messages.js:668:13
      at anonymous (native:1:1)
      at /Users/joao/Documents/BUN/2tex/node_modules/@whiskeysockets/baileys/lib/Utils/index.js:14:96
      at anonymous (native:1:1)
      at /Users/joao/Documents/BUN/2tex/node_modules/@whiskeysockets/baileys/lib/Signal/libsignal.js:64:13
      at anonymous (native:1:1)
      at /Users/joao/Documents/BUN/2tex/node_modules/@whiskeysockets/baileys/lib/Defaults/index.js:9:1
      at anonymous (native:1:1)
      at /Users/joao/Documents/BUN/2tex/node_modules/@whiskeysockets/baileys/lib/Socket/index.js:3:1

Additional information

No response

Jarred-Sumner commented 1 week ago

Minimum repro:

var a = function () {};
a();
function a() {}

Due to hoisting, transpiler outputs:

let a = function() {
};
var a = function() {
};
a();
paperdave commented 1 week ago

ive seen this before.

this is very similar but not the exact same to #5732, where the minimum reproduction is:


function A() {}
var A;