Skip to content

Commit

Permalink
Fix: no-unsupported-features crash if only ignores option
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea committed Nov 18, 2016
1 parent cb96b14 commit 8275cfc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
16 changes: 11 additions & 5 deletions lib/rules/no-unsupported-features.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,20 +154,25 @@ function isIgnored(key, ignores) {
* Parses the options.
*
* @param {object} options - An option object to parse.
* @param {number} defaultVersion - The default version to use if the version option was omitted.
* @returns {object} Parsed value.
*/
function parseOptions(options) {
function parseOptions(options, defaultVersion) {
var version = 0
var ignores = null

if (typeof options === "number") {
version = options
version = options || defaultVersion
ignores = []
}
else {
version = options.version
else if (typeof options === "object") {
version = options.version || defaultVersion
ignores = options.ignores || []
}
else {
version = defaultVersion
ignores = []
}

return Object.freeze({
version: version < 1 ? version.toFixed(2) : version.toFixed(0),
Expand Down Expand Up @@ -259,7 +264,8 @@ function hasUnicodeCodePointEscape(raw) {
module.exports = function(context) {
var sourceCode = context.getSourceCode()
var supportInfo = parseOptions(
context.options[0] || getDefaultVersion(context.getFilename())
context.options[0],
getDefaultVersion(context.getFilename())
)
var hasSpecialLexicalEnvironment = checkSpecialLexicalEnvironment(context)

Expand Down
6 changes: 6 additions & 0 deletions tests/lib/rules/no-unsupported-features.js
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,12 @@ ruleTester.run("no-unsupported-features", rule, [
code: "'\\\\u{0123}'",
env: {es6: true},
},
{
filename: fixture("gte-4.0.0/a.js"),
code: "var a = async () => 1",
parserOptions: {ecmaVersion: 2017},
options: [{ignores: ["asyncAwait"]}],
},
],
invalid: [
{
Expand Down

0 comments on commit 8275cfc

Please sign in to comment.