Open
Description
Champions: Ron Buckton (@rbuckton)
Spec Repo: https://github.com/rbuckton/proposal-throw-expressions
First presented at the July 2017 meeting: https://github.com/tc39/agendas/blob/master/2017/07.md
Stage 1 to Stage 2 at Sept 2017 meeting
Examples:
function save(filename = throw new TypeError("Argument required")) {}
lint(ast, {
with: () => throw new Error("avoid using 'with' statements.")
});
function getEncoder(encoding) {
const encoder = encoding === "utf8" ? new UTF8Encoder()
: encoding === "utf16le" ? new UTF16Encoder(false)
: encoding === "utf16be" ? new UTF16Encoder(true)
: throw new Error("Unsupported encoding");
}
class Product {
get id() { return this._id; }
set id(value) { this._id = value || throw new Error("Invalid value"); }
}
Implementation
- Parser
- Transform
- TS: Support for the ECMAScript 'throw' operator microsoft/TypeScript#18798
- REPL: https://babeljs.io/repl/build/master#?&browsers=&build=&code_lz=DYSwdgLgFAhgzhANAAgN7IFDOQdxBACwC5koBKZAXgD5lCAnAex2TAFMWBRep-qAIhgA3RiAAmyAK5xwAc2QByPIQXIEMCGwC2bSHAB0_MhgC-ZANwYgA&circleciRepo=&lineWrap=true&presets=stage-0&targets=&version=7.0.0-beta.2