diff options
-rw-r--r-- | BUILD.gn | 1 | ||||
-rw-r--r-- | js/globals.ts | 12 | ||||
-rw-r--r-- | js/text-encoding.d.ts | 6 | ||||
-rw-r--r-- | js/text_encoding.ts | 28 | ||||
-rw-r--r-- | package.json | 2 | ||||
m--------- | third_party | 0 |
6 files changed, 39 insertions, 10 deletions
@@ -287,6 +287,7 @@ run_node("bundle") { "js/os.ts", "js/plugins.d.ts", "js/runtime.ts", + "js/text_encoding.ts", "js/timers.ts", "js/types.d.ts", "js/util.ts", diff --git a/js/globals.ts b/js/globals.ts index f17d2f33a..a6f1b0927 100644 --- a/js/globals.ts +++ b/js/globals.ts @@ -3,6 +3,7 @@ import { Console } from "./console"; import { RawSourceMap } from "./types"; import * as timers from "./timers"; +import { TextEncoder, TextDecoder } from "./text_encoding"; declare global { interface Window { @@ -16,6 +17,11 @@ declare global { const console: Console; const window: Window; + + // tslint:disable:variable-name + let TextEncoder: TextEncoder; + let TextDecoder: TextDecoder; + // tslint:enable:variable-name } // If you use the eval function indirectly, by invoking it via a reference @@ -49,10 +55,8 @@ window.clearTimeout = timers.clearTimer; window.clearInterval = timers.clearTimer; window.console = new Console(libdeno.print); +window.TextEncoder = TextEncoder; +window.TextDecoder = TextDecoder; // import { fetch } from "./fetch"; // window["fetch"] = fetch; - -// import { TextEncoder, TextDecoder } from "text-encoding"; -// window["TextEncoder"] = TextEncoder; -// window["TextDecoder"] = TextDecoder; diff --git a/js/text-encoding.d.ts b/js/text-encoding.d.ts deleted file mode 100644 index 6feadad9c..000000000 --- a/js/text-encoding.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -// Remove and depend on @types/text-encoding once this PR is merged -// https://github.com/DefinitelyTyped/DefinitelyTyped/pull/26141 -declare module "text-encoding" { - export const TextEncoder: TextEncoder; - export const TextDecoder: TextDecoder; -} diff --git a/js/text_encoding.ts b/js/text_encoding.ts new file mode 100644 index 000000000..c8e262f5e --- /dev/null +++ b/js/text_encoding.ts @@ -0,0 +1,28 @@ +// Copyright 2018 the Deno authors. All rights reserved. MIT license. + +// @types/text-encoding relies on lib.dom.d.ts for some interfaces. We do not +// want to include lib.dom.d.ts (due to size) into deno's global type scope. +// Therefore this hack: add a few of the missing interfaces in +// @types/text-encoding to the global scope before importing. + +declare global { + type BufferSource = ArrayBufferView | ArrayBuffer; + + interface TextDecodeOptions { + stream?: boolean; + } + + interface TextDecoderOptions { + fatal?: boolean; + ignoreBOM?: boolean; + } + + interface TextDecoder { + readonly encoding: string; + readonly fatal: boolean; + readonly ignoreBOM: boolean; + decode(input?: BufferSource, options?: TextDecodeOptions): string; + } +} + +export { TextEncoder, TextDecoder } from "text-encoding"; diff --git a/package.json b/package.json index 829508413..62c4f6218 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "@types/base64-js": "^1.2.5", "@types/flatbuffers": "^1.9.0", "@types/source-map-support": "^0.4.1", + "@types/text-encoding": "0.0.33", "base64-js": "^1.3.0", "flatbuffers": "^1.9.0", "prettier": "^1.14.0", @@ -16,6 +17,7 @@ "rollup-plugin-typescript2": "^0.16.1", "rollup-pluginutils": "^2.3.0", "source-map-support": "^0.5.6", + "text-encoding": "0.6.4", "tslint": "^5.10.0", "tslint-eslint-rules": "^5.3.1", "tslint-no-circular-imports": "^0.5.0", diff --git a/third_party b/third_party -Subproject 785db4ec088750adde4f63211120ecb828fca14 +Subproject 221e8d5662be4d7524e31bb7b647623f46ad53c |