Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix default API export #254

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,8 @@ export {
tokenizer,
} from "./lib/parse.js";
export { to_ascii } from "./lib/minify.js";

// Also re-export everything as default export to keep compatibility with existing CommonJS tooling.
// See https://github.com/terser-js/terser/issues/251 for more info.
import * as terser from './main';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a good practice to import from self?

You can get away with this because this will be used in nodejs (commonjs env). commonjs allows all sorts of circular dependency.
But I suspect "import from self" is semantically incorrect in concept of EcmaScript Module.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that it is not correct, but in my opinion it's pretty good enough to use such import as "hotfix" to fix breaking changes in 3.16.0 and then redo it in right way

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Afaik this is not "incorrect" in ESM, it's well-defined in the spec.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx @sokra for the confirmation. Found in the spec. Personally I will avoid circular reference as much as possible in my code, not only for esm, but also for commonjs.

export default terser;