Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
joaoruntime opened this issue Jun 26, 2024 · 2 comments
Assignees
Labels
bug Something isn't working transpiler parser || printer

Comments

@joaoruntime
Copy link

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

@joaoruntime joaoruntime added bug Something isn't working needs triage labels Jun 26, 2024
@Jarred-Sumner
Copy link
Collaborator

Minimum repro:

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

Due to hoisting, transpiler outputs:

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

@paperdave
Copy link
Collaborator

ive seen this before.

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

function A() {}
var A;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working transpiler parser || printer
Projects
None yet
Development

No branches or pull requests

3 participants