gleam-lang/gleam

echo shows dicts using JS syntax in wasm compiler (tour, playground)

Open

#5,592 建立於 2026年4月8日

在 GitHub 查看
 (0 留言) (0 反應) (0 負責人)Rust (21,417 star) (960 fork)batch import
discussionhelp wanted

描述

import gleam/dict

pub fn main() {
  echo dict.from_list([])
}

Expected output

src/main.gleam:4
dict.from_list([])

Actual output

src/main.gleam:4
//js(Dict { "size": 0, "root": //js({ "datamap": 0, "nodemap": 0, "data": #() }) })

For echo the compiler checks if the stdlib is present and adds an import for the echo code to use if it is. In the wasm compiler the package config does not have any dependencies specified, so no import is added, and the echo code falls back to the JS syntax at runtime.

Users of the wasm compiler may not provide the stdlib, so we cannot add register the dependency as present without generating invalid code importing a module that doesn't exist. Even if the gleam/dict module is present for that user they may have it at a different location, as they're not using the Gleam build tool.

It's unclear to me what the right thing to do is here. We could possibly have users of the wasm compile configure the location of the module, but that seems like a very ugly solution to me.

Playground reproduction: https://playground.gleam.run/#N4IgbgpgTgzglgewHYgFwEYA0IDGyAuES+aIcAtgA4JT4AEA5gDYQCG5A9ACZw74A6SQZQCuAIzoAzJHXKs4SABQBKOsEF06EHAAsEdHnwB0kqAnIB9JnBj5FAbQC6ywQF9BIV0A

貢獻者指南