import-js icon indicating copy to clipboard operation
import-js copied to clipboard

ImportJS misidentifies `import` methods to be Dynamic Import

Open arggh opened this issue 5 years ago • 3 comments

I just run ImportJS on a huge codebase and the results are mostly good, but this one seemed peculiar enough for me to report it:

importjsbug

I'm not too familiar with the lib, but in this case it broke the code by sorting two variable assignments in false order.

Used ImportJS 3.2.0 on Mac OS, via CLI:

find ./client -name "**.js*" -exec importjs fix --overwrite {} \;
//.importjs.js
module.exports = {
    declarationKeyword: 'import',
    environments: ['meteor', 'node'],
    excludes: ['.meteor/local/**', '.vscode/**'],
    mergableOptions: {
        globals: false,
    },
    useRelativePaths: true
}

arggh avatar Mar 18 '19 06:03 arggh

image What I see after hitting ctrl + shift + i

Once I click through all the options all import statements disappear. But I can ctrl + z to go back to the block pictured above.

mweber-ak avatar Aug 28 '19 23:08 mweber-ak

I couldn't reproduce this behavior. Probably it has been fixed since this issue was created (we're on v5.2 now, this issue is for 3.2).

I'll close this, but please reopen if anyone can reproduce. Thanks.

mikabytes avatar Feb 03 '24 08:02 mikabytes

Apologies, my test had a typo. I can now reproduce some of it.

On current master, empty project with no dependencies:

import Quill from "quill";

const Parchment = Quill.import("parchment");
const Block = Parchment.query("block");

const a = "some code after";

becomes

import Quill from "quill"

const Parchment = Quill.import("parchment")

const a = "some code after";

While it didn't move the line for me, it still deleted it. I'm guessing ImportJS somehow misinterprets the Quill.import method to be a dynamic import.

This is the smallest reproducible I could achieve:

let l = a.import("")

These conditions need to be present for this bug:

  • const, var, or let before the variable
  • foo.import where foo is non-zero length string (let l = import("") does not work)
  • Argument to import must be double quote or single quote. Blockquotes does not trigger the bug.

mikabytes avatar Feb 03 '24 08:02 mikabytes