fix ExportsInfo

This commit is contained in:
Ivan Kopeykin 2022-04-06 15:03:53 +03:00
parent cb639b3efc
commit 216c3daa4e
5 changed files with 14 additions and 3 deletions

View File

@ -584,7 +584,7 @@ class ExportsInfo {
if (info.exportsInfo && name.length > 1) {
return info.exportsInfo.isExportProvided(name.slice(1));
}
return info.provided;
return info.provided ? name.length === 1 || undefined : info.provided;
}
const info = this.getReadOnlyExportInfo(name);
return info.provided;

View File

@ -6,6 +6,7 @@ import { b1, usedB1, usedB2, usedB3, usedB4 } from "./b.js";
import { usedE1, usedE2 } from "./e.js";
import { h } from "./h.js";
import * as m from "./m";
import {object as obj} from "./m";
import * as o from "./o";
import * as p from "./p";
import * as q from "./q";
@ -45,6 +46,8 @@ it("complex case should work correctly", () => {
it("should handle 'm in n' case", () => {
const obj = { aaa: "aaa" in m };
expect(obj.aaa).toBe(true);
expect("not_here" in m.object).toBe(false);
expect("not_here" in obj).toBe(false);
expect("aaa" in o).toBe(true);
expect("aaa" in p).toBe(false);
expect("ccc" in m).toBe(false);

View File

@ -1,5 +1,6 @@
export const aaa = 1;
export const bbb = 2;
export const object = {};
export * as ddd from "./n";
export const usedA = __webpack_exports_info__.aaa.used;
export const canMangleA = __webpack_exports_info__.ccc.canMangle;

View File

@ -3,5 +3,9 @@ import { b } from "./b";
export function a() {
return b();
}
export const obj = {};
export const aUsed = __webpack_exports_info__.a.used;
export const aProvided = __webpack_exports_info__.a.provideInfo;
export const objUsed = __webpack_exports_info__.obj.used;
export const objAProvided = __webpack_exports_info__.obj.A.provideInfo;
export const aToStringProvided = __webpack_exports_info__.a.toString.provideInfo;

View File

@ -1,9 +1,12 @@
import { a, aUsed, aCanBeMangled, aProvided } from "./reexport";
import { a, aUsed, aCanBeMangled, aProvided, aToStringProvided, obj, objUsed, objAProvided } from "./reexport";
if (a()) console.log("a");
if (a()) console.log("a", obj);
it("should not allow mangle if some exports are unknown", () => {
expect(aUsed).toBe(true);
expect(aProvided).toBe(true);
expect(aCanBeMangled).toBe(false);
expect(objUsed).toBe(true);
expect(objAProvided).toBe(undefined);
expect(aToStringProvided).toBe(undefined);
});