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

Multiple functions creating the same binding are ignored and all printed #610

Closed
ggoodman opened this issue Dec 18, 2020 · 0 comments
Closed

Comments

@ggoodman
Copy link

ggoodman commented Dec 18, 2020

I'm working on a codegen library for generating typed validation codecs from a collection of interrelated json schemas. While experimenting with the newly released v7 of https://npm.im/ajv, I observed that its new standalone codegen mode was printing certain validation functions more than once.

Piping such code through esbuild results in the duplicated function being reprinted in duplicate. I've tried via bundling and minifying and have observed the same thing. While this is certainly not a bug--as it is allowed to redefine a named function, it seems--it was surprising to me and inconsistent with rollup's behaviour so I thought that I'd bring it to your attention.

My intuition is that it would make sense to remove all but the last instance of a collection of functions with the same name in the same scope when printing. A quick test shows that hoisting behaviour results in the last instance claiming the binding, even in strict mode:

dupes.js:

"use strict";
test();
const indirect1 = test;
function test() {
  console.log('1');
}
test();
const indirect2 = test;
function test() {
  console.log('2');
}
test();
const indirect3 = test;

indirect1();
indirect2();
indirect3();
$ node dupes.js
2
2
2
2
2
2
@evanw evanw closed this as completed in 4fa3d7a Dec 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant