Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
12 changes: 10 additions & 2 deletions src/js_parser/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,13 @@ impl<'a, const TYPESCRIPT: bool, const SCAN_ONLY: bool> P<'a, TYPESCRIPT, SCAN_O
}
if name == b"accept" {
if !enabled {
p.method_call_must_be_replaced_with_undefined = true;
// Only ask `e_call` to drop the enclosing call when there is
// one: the flag is parser-wide and `e_call` is the only
// consumer, so setting it for a bare property read would
// leak into the next unrelated call expression.
Comment thread
robobun marked this conversation as resolved.
Outdated
if identifier_opts.is_call_target() {
p.method_call_must_be_replaced_with_undefined = true;
}
return Some(Expr {
data: js_ast::ExprData::EUndefined(E::Undefined),
loc,
Expand Down Expand Up @@ -712,7 +718,9 @@ impl<'a, const TYPESCRIPT: bool, const SCAN_ONLY: bool> P<'a, TYPESCRIPT, SCAN_O
loc,
));
} else {
p.method_call_must_be_replaced_with_undefined = true;
if identifier_opts.is_call_target() {
p.method_call_must_be_replaced_with_undefined = true;
}
return Some(Expr {
data: js_ast::ExprData::EUndefined(E::Undefined),
loc,
Expand Down
55 changes: 55 additions & 0 deletions test/bundler/bundler_minify.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,61 @@ describe("bundler", () => {
api.expectFile("/out.js").not.toContain("import.meta.hot");
},
});
// Reading an `import.meta.hot` method without calling it must not cause the
// next unrelated call expression to be dropped from the output.
itBundled("minify/ImportMetaHotReadWithoutCall", {
files: {
"/entry.ts": `
globalThis.sink = import.meta.hot.accept;
console.log("after-accept");
globalThis.sink = import.meta.hot.dispose;
console.log("after-dispose");
globalThis.sink = [
import.meta.hot.decline,
import.meta.hot.prune,
import.meta.hot.invalidate,
import.meta.hot.on,
import.meta.hot.off,
import.meta.hot.send,
];
console.log("after-array");
// Direct calls are still stripped.
import.meta.hot.accept(() => console.log("FAIL-accept-call"));
import.meta.hot.dispose(() => console.log("FAIL-dispose-call"));
console.log("after-calls");
`,
},
outfile: "/out.js",
run: {
stdout: "after-accept\nafter-dispose\nafter-array\nafter-calls",
},
onAfterBundle(api) {
const out = api.readFile("/out.js");
expect(out).toContain("after-accept");
expect(out).toContain("after-dispose");
expect(out).toContain("after-array");
expect(out).toContain("after-calls");
expect(out).not.toContain("FAIL");
expect(out).not.toContain("import.meta.hot");
},
});
itBundled("minify/ImportMetaHotReadWithoutCallNoBundle", {
files: {
"/entry.ts": `
globalThis.sink = import.meta.hot.accept;
console.log("after-accept");
globalThis.sink = import.meta.hot.dispose;
console.log("after-dispose");
`,
},
bundling: false,
outfile: "/out.js",
onAfterBundle(api) {
const out = api.readFile("/out.js");
expect(out).toContain("after-accept");
expect(out).toContain("after-dispose");
},
});
itBundled("minify/ProductionMode", {
files: {
"/entry.jsx": `
Expand Down