question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

semi reports missing semicolon on export default class

See original GitHub issue
// test.js
export default class {};
// config.json
{
    "env": {
      "es6": true
    },
    "ecmaFeatures": {
      "modules": true
    },
    "rules": {
        "semi": 2
    }
}
$ eslint --reset --no-eslintrc --config config.json test.js

test.js
  2:23  error  Missing semicolon  semi

✖ 1 problem (1 error, 0 warnings)

Looks like similar cases were addressed in #2178 and this one was missed.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
btmillscommented, Apr 1, 2015

Working on this. It’s quite the bear. In the meantime, this is my interpretation of the spec, broken down by the productions of ExportDeclaration:

export * FromClause ;

Semicolon belongs to ExportDeclaration.

export * from 'foo';

export ExportClause FromClause ;

Semicolon belongs to ExportDeclaration.

export { foo } from 'foo';

export ExportClause ;

Semicolon belongs to ExportDeclaration.

export { foo };

export VariableStatement

Semicolon belongs to VariableStatement.

export var foo;

export Declaration

Declaration : HoistableDeclaration

No semicolon.

export function foo () { }
export function* foo () { }

Declaration : ClassDeclaration

No semicolon.

export class Foo () { }

Declaration : LexicalDeclaration

Semicolon belongs to LexicalDeclaration.

export let foo;
export const foo = 42;

export default HoistableDeclaration

No semicolon.

export default function () { }
export default function* foo() { }

export default ClassDeclaration

No semicolon.

export default class { }

export default AssignmentExpression ;

Semicolon belongs to ExportDeclaration.

export default foo || bar;
export default (foo) => foo.bar();
export default foo = 42;
export default foo += 42;

tl;dr:

  • ExportAllDeclaration may have a semicolon.
  • ExportNamedDeclaration whose declaration is null may have a semicolon.
  • ExportNamedDeclaration with a child declaration does not have a semicolon, though its child may.
  • ExportDefaultDeclaration may have a semicolon only if its declaration is an expression.

(end tl;dr)

I find this interesting, from ESTree:

interface ExportNamedDeclaration <: Node {
    type: "ExportNamedDeclaration";
    declaration: Declaration | null;
    specifiers: [ ExportSpecifier ];
    source: Literal | null;
}

Note: Having declaration populated with non-empty specifiers or non-null source results in an invalid state.

If declaration and (specifiers, source) are mutually exclusive, why are they the same node?

Edit: ExportDefaultDeclaration may have a semicolon if its child is an expression.

0reactions
voithoscommented, Nov 26, 2015

@lo1tuma Ah, you’re right! That’s… unexpected. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Semicolon after default export - javascript - Stack Overflow
You don't need to add a semicolon after a export default when it's followed by a function declaration, that's what the grammar says....
Read more >
SyntaxError: missing ; before statement - JavaScript | MDN
The JavaScript exception "missing ; before statement" occurs when there is a semicolon ( ; ) missing somewhere and can't be added by...
Read more >
semi - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
Rollup and Bublé. Runtime error due to missing semicolon in ...
Evertything worked fine until I refactor it (due to a security issue reported by github) but now, it compiles OK, but crashes at...
Read more >
In csv export set delimiter to semicolon instead of comma in ...
csv), while Open Office and Libre Office do that, and changing the default delimiter in Excel requires to change the language/locale settings. So,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found