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.

Imports without semicolons not treated as imports

See original GitHub issue

Originally reported here: https://github.com/Galooshi/atom-import-js/issues/8

I’m moving the issue to the main project as it affects all clients.

Given this content

import AppView from './AppView'

const Test = AppView;

If you import AppView, you end up with duplicate import lines. One with semicolon (added by import-js) and one without (the original).

import AppView from './AppView';

import AppView from './AppView'

const Abc = AppView;

The original bug report is for the atom plugin, but I have confirmed this bug to exist in the vim plugin as well.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:9

github_iconTop GitHub Comments

2reactions
trotzigcommented, Dec 16, 2016

This is the main regex used to match imports: https://github.com/Galooshi/import-js/blob/ae73c764682d1ff9925575d0fb3969886cc6de9f/lib/ImportStatement.js#L23. Though there’s a pre-processing step that assumes semicolons higher up in the hierarchy: https://github.com/Galooshi/import-js/blob/ae73c764682d1ff9925575d0fb3969886cc6de9f/lib/findCurrentImports.js#L51

However, I’m about to kill both of those regexes in favor of a real parser. That work is ongoing in https://github.com/Galooshi/import-js/tree/better-parsing. I can’t promise anything, but I’m hoping to release that in a 2.0 in the coming month.

1reaction
trotzigcommented, Dec 29, 2016

Of course, sorry for leaving you in the dark here.

With 2.0, import statements without semicolons at the end are already recognized. The issue that you can solve with importStatementFormatter is that import-js will automatically add the semicolon when it constructs new import statements. You should be able to use something like

// .importjs.js
module.exports = {
  importStatementFormatter: function({ importStatement }) {
    return importStatement.replace(/;$/, '');
  },
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

ecmascript 6 - Does import statement need semicolon actually?
Javascript only requires semicolons to separate statements in the same line. Strictly, speaking, this is not true. It also requires semi-colons ...
Read more >
Allow importing of modules that don't use semicolons #1004
The problem is not only with rollup not adding semi colons at the end of functions. The same runtime TpyeError also occurs when...
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 >
Import or link to data in an Excel workbook - Microsoft Support
You can import Excel data into Access desktop databases or link to an Excel file, which results in a linked table.
Read more >
Style guide - The Apache Groovy programming language
1. No semicolons · 2. Return keyword optional · 3. Def and type · 4. Public by default · 5. Omitting parentheses ·...
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 Reddit Thread

No results found

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