Galooshi / import-js

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

Add support for adding custom elements #551

Closed mikabytes closed 8 months ago

mikabytes commented 4 years ago

Based on #550, this PR indeed adds support for importing files that define custom elements. It has a few quirks though.

Quirks

One idea

Maybe we could add support for "that which has a name but is not named in JS spec" as a comment? Maybe something like:

import './my-custom-element.js' // <my-custom-element>

OR

import /* <my-custom-element> from */ './my-custom-element.js'

Separating multiple named exports with comma. Or something. I'm happy to hear your ideas.

other

Not too bad for 3 hours work on a foreign codebase.... :)

trotzig commented 4 years ago

Apologies for the delay here! I hope to have a look at this later today.

trotzig commented 4 years ago

Excellent work!

I want it to be treated as a named export, but JavaScript doesn't allow me to specify such metadata. The consequence is that imports can be added, but not matched or removed.

You're right that ImportJS doesn't have support for that, but you're wrong about your solution being horrible. :)

I'm not too happy about the way I'm checking the type-of-export based on the adding <> characters to the name. I AM happy about using <> to have ImportJS give me distinct messages about importing a custom element though.

I think this is fine.

import /* <my-custom-element> from */ './my-custom-element.js'

I like this idea. If you can make this work, go for it. If not, I think it's fine if removing the imports is a manual process.

mikabytes commented 4 years ago

but you're wrong about your solution being horrible

Haha, agree to disagree ;-)

import /* <my-custom-element> from */ './my-custom-element.js'

I'll have something ready once I have some time to do it. Might not be this week, we'll see!