Skip to content

Commit 41d32fb

Browse files
authored
Merge pull request #261 from msgpack/polyfill-dispose
implement a tiny polyfill to Symbol.dispose
2 parents 130ea87 + 9ab0b52 commit 41d32fb

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

src/Decoder.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import "./utils/symbol.dispose";
12
import { prettyByte } from "./utils/prettyByte";
23
import { ExtensionCodec, ExtensionCodecType } from "./ExtensionCodec";
34
import { getInt64, getUint64, UINT32_MAX } from "./utils/int";

src/Encoder.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import "./utils/symbol.dispose";
12
import { utf8Count, utf8Encode } from "./utils/utf8";
23
import { ExtensionCodec, ExtensionCodecType } from "./ExtensionCodec";
34
import { setInt64, setUint64 } from "./utils/int";

src/utils/symbol.dispose.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Polyfill to Symbol.dispose
2+
3+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
4+
if (!Symbol.dispose) {
5+
Object.defineProperty(Symbol, "dispose", {
6+
value: Symbol("dispose"),
7+
writable: false,
8+
enumerable: false,
9+
configurable: false,
10+
});
11+
}

tools/esmify.ts

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ for (const file of files) {
1111
// .js => .mjs
1212
const content = fs.readFileSync(file).toString("utf-8");
1313
const newContent = content.replace(/\bfrom "(\.\.?\/[^"]+)";/g, 'from "$1.mjs";')
14+
.replace(/\bimport "(\.\.?\/[^"]+)";/g, 'import "$1.mjs";')
1415
.replace(/\/\/# sourceMappingURL=(.+)\.js\.map$/,
1516
"//# sourceMappingURL=$1.mjs.map");
1617
fs.writeFileSync(fileMjs, newContent);

0 commit comments

Comments
 (0)