Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[[FIX]] Correctly parse exported generators
Before of this patch, JSHint considered the name of expored
generators `*`, because it was the first "thing" after `function`.

Fix #2472
  • Loading branch information
nicolo-ribaudo authored and lukeapage committed Jul 9, 2015
1 parent 8a864f3 commit 0604816
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/jshint.js
Expand Up @@ -3646,7 +3646,8 @@ var JSHINT = (function() {
checkProperties(props);
}

blockstmt("function", function() {
blockstmt("function", function(context) {
var inexport = context && context.inexport;
var generator = false;
if (state.tokens.next.value === "*") {
advance("*");
Expand All @@ -3664,6 +3665,8 @@ var JSHINT = (function() {

if (i === undefined) {
warning("W025");
} else if (inexport) {
state.funct["(scope)"].setExported(i, state.tokens.prev);
}

state.funct["(scope)"].addlabel(i, {
Expand Down Expand Up @@ -4470,8 +4473,7 @@ var JSHINT = (function() {
// ExportDeclaration :: export Declaration
this.block = true;
advance("function");
state.funct["(scope)"].setExported(state.tokens.next.value, state.tokens.next);
state.syntax["function"].fud();
state.syntax["function"].fud({ inexport:true });
} else if (state.tokens.next.id === "class") {
// ExportDeclaration :: export Declaration
this.block = true;
Expand Down
6 changes: 5 additions & 1 deletion tests/unit/core.js
Expand Up @@ -777,6 +777,9 @@ exports.testES6Modules = function (test) {
.addError(59, "'import' is only available in ES6 (use esnext option).")
.addError(60, "'import' is only available in ES6 (use esnext option).")
.addError(65, "'import' is only available in ES6 (use esnext option).")
.addError(67, "'export' is only available in ES6 (use esnext option).")
.addError(67, "'function*' is only available in ES6 (use esnext option).")
.addError(67, "'yield' is available in ES6 (use esnext option) or Mozilla JS extensions (use moz).");
importConstErrors.forEach(function(error) { testRun.addError.apply(testRun, error); });
testRun.test(src, {});

Expand Down Expand Up @@ -814,7 +817,8 @@ exports.testES6ModulesNamedExportsAffectUnused = function (test) {
"export let letone = 1, lettwo = 2;",
"export var v1u, v2u;",
"export let l1u, l2u;",
"export const c1u, c2u;"
"export const c1u, c2u;",
"export function* gen() { yield 1; }"
];

TestRun(test)
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/fixtures/es6-import-export.js
Expand Up @@ -63,3 +63,5 @@ if (newImport) {
$();
}
import newImport from 'newImport';

export function* gen() { yield 1; }

0 comments on commit 0604816

Please sign in to comment.