Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Fable.Cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [Beam] Fix generic constraint interface dispatch (by @dbrattli)
* [Beam] Fix class constructor field invokes and explicit val fields (by @dbrattli)
* [Beam] Fix mutable record field mutation (by @dbrattli)
* [JS/TS] Allows compiling `fable-library-ts` for Browser environment (by @goswinr)

## 5.0.0-rc.1 - 2026-02-26

Expand Down
4 changes: 4 additions & 0 deletions src/fable-library-ts/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Fixed

* [JS/TS] Allows compiling `fable-library-ts` for Browser environment (by @goswinr)

## 2.0.0-rc.1 - 2026-02-26

## 2.0.0-beta.7 - 2026-02-03
Expand Down
28 changes: 20 additions & 8 deletions src/fable-library-ts/Encoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,11 @@ class UTF16LE {
} else if (index != null) {
str = str.substring(index);
}
if (typeof Buffer !== "undefined") {
const bytes = Buffer.from(str, "utf16le");
// Allow to compile for Browser environment without @types/node being installed
// See https://github.com/fable-compiler/Fable/issues/4368
const g = globalThis as any;
Comment thread
goswinr marked this conversation as resolved.
if (typeof g.Buffer !== "undefined") {
const bytes = g.Buffer.from(str, "utf16le");
return new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength);
} else {
return utf16le_encode(str); // polyfill
Expand All @@ -114,10 +117,13 @@ class UTF16LE {
} else if (index != null) {
buffer = buffer.subarray(index);
}
// Allow to compile for Browser environment without @types/node being installed
// See https://github.com/fable-compiler/Fable/issues/4368
const g = globalThis as any;
if (typeof TextDecoder !== "undefined") {
return new TextDecoder("utf-16le").decode(buffer);
} else if (typeof Buffer !== "undefined") {
return Buffer.from(buffer).toString("utf16le");
} else if (typeof g.Buffer !== "undefined") {
return g.Buffer.from(buffer).toString("utf16le");
} else {
return utf16le_decode(buffer); // polyfill
}
Expand All @@ -134,10 +140,13 @@ class UTF8 {
} else if (index != null) {
str = str.substring(index);
}
// Allow to compile for Browser environment without @types/node being installed
// See https://github.com/fable-compiler/Fable/issues/4368
const g = globalThis as any;
Comment thread
goswinr marked this conversation as resolved.
if (typeof TextEncoder !== "undefined") {
return new TextEncoder().encode(str);
} else if (typeof Buffer !== "undefined") {
const bytes = Buffer.from(str, "utf8");
} else if (typeof g.Buffer !== "undefined") {
const bytes = g.Buffer.from(str, "utf8");
return new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength);
} else {
return utf8_encode(str); // polyfill
Expand All @@ -152,10 +161,13 @@ class UTF8 {
} else if (index != null) {
buffer = buffer.subarray(index);
}
// Allow to compile for Browser environment without @types/node being installed
// See https://github.com/fable-compiler/Fable/issues/4368
const g = globalThis as any;
Comment thread
goswinr marked this conversation as resolved.
if (typeof TextDecoder !== "undefined") {
return new TextDecoder().decode(buffer);
} else if (typeof Buffer !== "undefined") {
return Buffer.from(buffer).toString("utf8");
} else if (typeof g.Buffer !== "undefined") {
return g.Buffer.from(buffer).toString("utf8");
} else {
return utf8_decode(buffer); // polyfill
}
Expand Down
Loading