Skip to content

Commit

Permalink
Merge pull request babel#144 from babel/issue142
Browse files Browse the repository at this point in the history
Fix bug with semi rule with class properties and omitLastInOneLineBlock option
  • Loading branch information
existentialism authored Apr 20, 2018
2 parents 01c6e31 + 8e83dc5 commit 41913b9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
4 changes: 2 additions & 2 deletions rules/semi.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ const semiRuleWithClassProperty = ruleComposer.joinReports([
}
} else {
if (!isSemicolon(lastToken)) {
if (!exceptOneLine || !isOneLinerBlock(node)) {
if (!exceptOneLine || !isOneLinerBlock(context, node)) {
report(context, node);
}
} else {
if (exceptOneLine && isOneLinerBlock(node)) {
if (exceptOneLine && isOneLinerBlock(context, node)) {
report(context, node, true);
}
}
Expand Down
16 changes: 14 additions & 2 deletions tests/rules/semi.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,12 @@ ruleTester.run("semi", rule, {
"class Foo { bar = 'example'; }",
"class Foo { static bar = 'example'; }",
{ code: "async function foo() { for await (let thing of {}) { console.log(thing); } }", parserOptions: { ecmaVersion: 6 } },
{ code: "class Foo { bar = () => {}; }", options: ["always", { omitLastInOneLineBlock: true }] },

// babel, "never"
{ code: "class Foo { bar = 'example' }", options: ["never"] },
{ code: "class Foo { static bar = 'example' }", options: ["never"] }
{ code: "class Foo { static bar = 'example' }", options: ["never"] },
{ code: "class Foo { bar = () => {} }", options: ["never"] },
],
invalid: [
{ code: "import * as utils from './utils'", output: "import * as utils from './utils';", parserOptions: { sourceType: "module" }, errors: [{ message: "Missing semicolon.", type: "ImportDeclaration", column: 33 }] },
Expand Down Expand Up @@ -184,9 +186,19 @@ ruleTester.run("semi", rule, {
// babel
{ code: "class Foo { bar = 'example' }", errors: [{ message: "Missing semicolon." }] },
{ code: "class Foo { static bar = 'example' }", errors: [{ message: "Missing semicolon." }] },
{
code: "class Foo { bar = () => {} }",
options: ["always", { omitLastInOneLineBlock: true }],
errors: [{ message: "Missing semicolon." }]
},

// babel, "never"
{ code: "class Foo { bar = 'example'; }", options: ["never"], errors: [{ message: "Extra semicolon." }] },
{ code: "class Foo { static bar = 'example'; }", options: ["never"], errors: [{ message: "Extra semicolon." }] }
{ code: "class Foo { static bar = 'example'; }", options: ["never"], errors: [{ message: "Extra semicolon." }] },
{
code: "class Foo { bar = () => {}; }",
options: ["never"],
errors: [{ message: "Extra semicolon." }]
},
]
});

0 comments on commit 41913b9

Please sign in to comment.