afterwind-io / preprocessor-loader

Bring the awesome "Conditional Compilation" to the Webpack, and more.
MIT License
40 stars 12 forks source link

Failed when having export default from imported #4

Closed cowardcalf closed 4 years ago

cowardcalf commented 4 years ago

Hi, @afterwind-io

I've found this loader does not work in the case when having export default from another imported default module.

For example,

// File ./components/a.js
const someFunc = () => { // do something };
export default someFunc;
// File ./components/index.js
import someFunc from "./a"
export default someFunc;
// File app.js
import someFunc from "./components"

someFunc();

It will throw errors when compling

WARNING in app.js "export 'default' (imported as 'someFunc') was not found in 'app.js'

It would be glad to see any response from you. Thanks.

cowardcalf commented 4 years ago

Actually, I've found that was caused by missing the empty line at the end of the .js file. The issue will be gone when adding an empty line to each of the source file.

Interesting.

afterwind-io commented 4 years ago

@cowardcalf Sorry for the delay. I'll look into it soon.

afterwind-io commented 4 years ago

@cowardcalf Surprisingly this bug lasts so long. If there is no new line at the end of the code, the last line will be skipped, because an inner state flag collects a single line never gets a chance to end itself.

Anyway thanks for the issue. v1.1.1 has solved the problem. Try it out! https://www.npmjs.com/package/webpack-preprocessor-loader/v/1.1.1

cowardcalf commented 4 years ago

@afterwind-io Thanks for the quick response and the immediate fixing. I'll try the new fresh v1.1.1 release.

Are you going to close this issue?

afterwind-io commented 4 years ago

@cowardcalf Seems the actual flaw is a little more tricky than I have thought. The problem here is what on the last line(single/multiple characters in this case, which I was missing), rather than file format.

I have bumped another update to cover more cases. It should be working now. https://www.npmjs.com/package/webpack-preprocessor-loader/v/1.1.2

cowardcalf commented 4 years ago

That's a quick fixing. Yes, I guess it was file format irrelevant. I'll try the new release soon. Thanks again.

cowardcalf commented 4 years ago

@afterwind-io I've tested new release. So far so good. Thank you for your efforts.