Galooshi / import-js

A tool to simplify importing JS modules
MIT License
526 stars 70 forks source link

ImportJS misidentifies `import` methods to be Dynamic Import #529

Open arggh opened 5 years ago

arggh commented 5 years ago

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
}
mweber-ak commented 5 years ago

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.

mikabytes commented 7 months ago

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 commented 7 months ago

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: