Skip to content

Commit 4d9d009

Browse files
committed
Fix: no-unsupported-features had a false negative (fixes #40)
1 parent f642dc3 commit 4d9d009

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

lib/rules/no-unsupported-features.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ var DESTRUCTURING_PARENT_TYPE = /^(?:Function(?:Declaration|Expression)|ArrowFun
2727
var BINARY_NUMBER = /^0[bB]/;
2828
var OCTAL_NUMBER = /^0[oO]/;
2929
var UNICODE_ESC = /\\u\{.+?\}/;
30+
var GET_OR_SET = /^(?:g|s)et$/;
3031
var NEW_BUILTIN_TYPES = [
3132
"Int8Array", "Uint8Array", "Uint8ClampedArray", "Int16Array", "Uint16Array",
3233
"Int32Array", "Uint32Array", "Float32Array", "Float64Array", "DataView",
@@ -522,7 +523,12 @@ module.exports = function(context) {
522523
if (node.parent.type === "ObjectExpression" &&
523524
(node.computed || node.shorthand || node.method)
524525
) {
525-
report(node, "objectLiteralExtensions");
526+
if (node.shorthand && GET_OR_SET.test(node.key.name)) {
527+
report(node, "objectPropertyShorthandOfGetSet");
528+
}
529+
else {
530+
report(node, "objectLiteralExtensions");
531+
}
526532
}
527533
},
528534

lib/util/features.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ module.exports = {
3535
name: "Object Literal Extensions",
3636
node: 4
3737
},
38+
"objectPropertyShorthandOfGetSet": {
39+
alias: ["syntax", "objectLiteralExtensions"],
40+
name: "Property Shorthand of 'get' and 'set'",
41+
node: 6
42+
},
3843
"forOf": {
3944
alias: ["syntax"],
4045
name: "'for..of' Loops",

tests/lib/rules/no-unsupported-features.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,13 @@ ruleTester.run("no-unsupported-features", rule, [
143143
errors: 5,
144144
supported: 4
145145
},
146+
{
147+
keys: ["objectPropertyShorthandOfGetSet", "objectLiteralExtensions", "syntax"],
148+
name: "Property Shorthand of 'get' and 'set'",
149+
code: "var obj = {get, set}",
150+
errors: 2,
151+
supported: 6
152+
},
146153
{
147154
keys: ["forOf", "syntax"],
148155
name: "'for..of' Loops",

0 commit comments

Comments
 (0)