Skip to content

Commit

Permalink
[[FIX]] Improve binding power for tagged templates
Browse files Browse the repository at this point in the history
Use a more accurate value for tagged templates' binding power in order
to ensure that the `singleGroups` option correctly permits use of the
grouping operator where it is truly necessary.
  • Loading branch information
jugglinmike committed Jan 31, 2016
1 parent 635dce9 commit 9cf2ff0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/jshint.js
Original file line number Diff line number Diff line change
Expand Up @@ -1944,7 +1944,7 @@ var JSHINT = (function() {
template: true,
};
state.syntax["(template)"] = _.extend({
lbp: 15,
lbp: 155,
type: "(template)",
nud: doTemplateLiteral,
led: doTemplateLiteral,
Expand All @@ -1966,7 +1966,7 @@ var JSHINT = (function() {
}, baseTemplateSyntax);

state.syntax["(no subst template)"] = _.extend({
lbp: 15,
lbp: 155,
type: "(template)",
nud: doTemplateLiteral,
led: doTemplateLiteral,
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -2734,6 +2734,30 @@ singleGroups.bindingPower.singleExpr = function (test) {
.addError(34, "Unnecessary grouping operator.")
.test(code, { singleGroups: true });

code = [
"var x;",
"x = (printA || printB)``;",
"x = (printA || printB)`${}`;",
"x = (new X)``;",
"x = (new X)`${}`;",
// Should warn:
"x = (x.y)``;",
"x = (x.y)`${}`;",
"x = (x[x])``;",
"x = (x[x])`${}`;",
"x = (x())``;",
"x = (x())`${}`;"
];

TestRun(test)
.addError(6, "Unnecessary grouping operator.")
.addError(7, "Unnecessary grouping operator.")
.addError(8, "Unnecessary grouping operator.")
.addError(9, "Unnecessary grouping operator.")
.addError(10, "Unnecessary grouping operator.")
.addError(11, "Unnecessary grouping operator.")
.test(code, { singleGroups: true, esversion: 6, supernew: true });

test.done();
};

Expand Down

0 comments on commit 9cf2ff0

Please sign in to comment.