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 adef3c4
Show file tree
Hide file tree
Showing 2 changed files with 20 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
8 changes: 8 additions & 0 deletions tests/object-curly-spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ 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: "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: "export {\ndoor,\nhouse\n}", options: ["always"], ecmaFeatures: { modules: true } },
{ code: "import 'room'", options: ["always"], ecmaFeatures: { modules: true } },

// always - empty object
Expand Down Expand Up @@ -85,7 +89,11 @@ ruleTester.run('babel/object-curly-spacing', rule, {
{ code: "export {\ndoor\n} from 'room'", options: ["never"], ecmaFeatures: { modules: true } },
{ code: "import {house,mouse} from 'caravan'", options: ["never"], ecmaFeatures: { modules: true } },
{ code: "import {house, mouse} from 'caravan'", options: ["never"], ecmaFeatures: { modules: true } },
{ code: "import {\nhouse,\nmouse} from 'caravan'", options: ["never"], ecmaFeatures: { modules: true } },
{ code: "import {\nhouse,\nmouse,\n} from 'caravan'", options: ["never"], ecmaFeatures: { modules: true } },
{ code: "export {door}", options: ["never"], ecmaFeatures: { modules: true } },
{ code: "export {\ndoor,\nmouse\n}", options: ["never"], ecmaFeatures: { modules: true } },
{ code: "export {\ndoor,\nmouse,\n}", options: ["never"], ecmaFeatures: { modules: true } },
{ code: "import 'room'", options: ["never"], ecmaFeatures: { modules: true } },

// never - empty object
Expand Down

0 comments on commit adef3c4

Please sign in to comment.