Add support for parsing babylons throwExpressions (#4695)

master
Vojtěch Štěpančík 2018-06-15 02:35:39 +02:00 committed by Lucas Duailibe
parent 18aa527adc
commit 56af3d621d
4 changed files with 68 additions and 1 deletions

View File

@ -31,7 +31,8 @@ function parse(text, parsers, opts) {
"optionalChaining",
"classPrivateProperties",
"pipelineOperator",
"nullishCoalescingOperator"
"nullishCoalescingOperator",
"throwExpressions"
]
};

View File

@ -0,0 +1,48 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`throw_expression.js 1`] = `
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"); }
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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");
}
}
`;

View File

@ -0,0 +1 @@
run_spec(__dirname, ["babylon"]);

View File

@ -0,0 +1,17 @@
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"); }
}