Incorrect assumption around host being defined in base64encode/base64decode #24638
Copy link
Copy link
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue
Milestone
Description
TypeScript Version: 2.9.1+
Code
Any code under deno with TypeScript 2.9.1 or later.
#22658 introduced a significant refactor of code. One of the areas defines the base64encode function which assumes that the argument host is always defined. In practice, this comes from ts.sys in which ts.sys is possibly undefined, but without the strict checking, this does not throw a compiler error, but at runtime in certain environments (like deno) an exception is thrown.
A simple check of host && host.base64encode there (and the following function base64decode restores functionality).
Expected behavior:
The code actually runs.
Actual behavior:
TypeError: Cannot read property 'base64encode' of undefined
at Object.base64encode (../node_modules/typescript/lib/typescript.js:12079:18)
at Object.getSourceMappingURL (../node_modules/typescript/lib/typescript.js:73929:46)
at printSourceFileOrBundle (../node_modules/typescript/lib/typescript.js:74550:48)
at emitJsFileOrBundle (../node_modules/typescript/lib/typescript.js:74499:13)
at emitSourceFileOrBundle (../node_modules/typescript/lib/typescript.js:74456:13)
at forEachEmittedFile (../node_modules/typescript/lib/typescript.js:74365:30)
at Object.emitFiles (../node_modules/typescript/lib/typescript.js:74446:9)
at emitWorker (../node_modules/typescript/lib/typescript.js:78992:33)
at ../node_modules/typescript/lib/typescript.js:78952:66
at runWithCancellationToken (../node_modules/typescript/lib/typescript.js:79043:24)
Related Issues:
Refs: ry/deno#117
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue
Activity
kitsonk commentedon Jun 3, 2018
Actually, in looking a bit deeper,
.sysis defined as always available, but the code internal to creating it logically assumes it can beundefinedand there are quite a few uses of.sysit is assumed to be there. There is this TODO which indicates this has been noticed before.I tried changing it to be
| undefinedand the whole sweater came unravelled so it clearly needs a bit more guidance to long term fix it.Treat host as possibly undefined for base64encode/base64decode
mhegazy commentedon Jun 4, 2018
thanks Kitson Kelly (@kitsonk)