Skip to content

Commit

Permalink
Support trailing commas in import and export statements. Fixes babel#21
Browse files Browse the repository at this point in the history
  • Loading branch information
LegNeato committed Oct 21, 2015
1 parent 1197501 commit d0c65cf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
12 changes: 12 additions & 0 deletions rules/object-curly-spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ module.exports = function(context) {
penultimate = context.getLastToken(lastSpecifier),
last = context.getTokenAfter(lastSpecifier);

// support trailing commas
if (last.value === ",") {
penultimate = last;
last = context.getTokenAfter(last);
}

validateBraceSpacing(node, first, second, penultimate, last);
}

Expand All @@ -195,6 +201,12 @@ module.exports = function(context) {
return;
}

// support trailing commas
if (last.value === ",") {
penultimate = last;
last = context.getTokenAfter(last);
}

validateBraceSpacing(node, first, second, penultimate, last);

},
Expand Down
2 changes: 2 additions & 0 deletions tests/object-curly-spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ ruleTester.run('babel/object-curly-spacing', rule, {
{ code: "import {\ndoor } from 'room'", options: ["always"], ecmaFeatures: { modules: true } },
{ code: "export { door } from 'room'", options: ["always"], ecmaFeatures: { modules: true } },
{ code: "import { house, mouse } from 'caravan'", options: ["always"], ecmaFeatures: { modules: true } },
{ code: "import {\nhouse,\nmouse,\n} from 'caravan'", options: ["always"], ecmaFeatures: { modules: true } },
{ code: "export { door }", options: ["always"], ecmaFeatures: { modules: true } },
{ code: "export {\ndoor,\nhouse,\n}", options: ["always"], ecmaFeatures: { modules: true } },
{ code: "import 'room'", options: ["always"], ecmaFeatures: { modules: true } },

// always - empty object
Expand Down

0 comments on commit d0c65cf

Please sign in to comment.