Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions src/js_parser/visit/visit_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,9 @@ impl<'a, const TYPESCRIPT: bool, const SCAN_ONLY: bool> P<'a, TYPESCRIPT, SCAN_O
if is_call_target {
p.call_target = dot.data;
}
if is_template_tag {
p.template_tag = dot.data;
}
if is_delete_target {
p.delete_target = dot.data;
}
Expand Down
62 changes: 62 additions & 0 deletions test/bundler/bundler_cjs2esm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1410,6 +1410,43 @@ describe("bundler", () => {
stdout: "helped:x helped:y helped:z true",
},
});
// `--minify-syntax` rewrites `X["name"]` to `X.name`. The new node is still the
// call target or the template tag, so the call still passes `X` as `this`.
itBundled("cjs2esm/DefaultImportComputedMemberKeepsThisMinifySyntax", {
files: {
"/entry.js": /* js */ `
import st from "./lib.cjs";
console.log(st["parse"]("y"), st["tag"]\`z\`);
`,
...thisReadingLib,
},
cjs2esm: true,
minifySyntax: true,
onAfterBundle(api) {
expect(api.readFile("/out.js")).toContain('console.log(exports_lib.parse("y"), exports_lib.tag`z`);');
},
run: {
stdout: "helped:y helped:z",
},
});
itBundled("cjs2esm/StarImportComputedMemberKeepsThisMinifySyntax", {
files: {
"/entry.js": /* js */ `
import * as ns from "./lib.cjs";
console.log(ns["parse"]("y"), ns["tag"]\`z\`);
`,
...thisReadingLib,
},
cjs2esm: true,
minifySyntax: true,
onAfterBundle(api) {
// Each access keeps a receiver. The printed name of `ns` is not part of this test.
expect(api.readFile("/out.js")).toMatch(/console\.log\(\w+\.parse\("y"\), \w+\.tag`z`\);/);
},
run: {
stdout: "helped:y helped:z",
},
});
itBundled("cjs2esm/StarImportMethodCallThroughExportStarKeepsThis", {
files: {
"/entry.js": /* js */ `
Expand Down Expand Up @@ -1532,6 +1569,31 @@ describe("bundler", () => {
stdout: "helped:in helped:module helped:tag",
},
});
itBundled("cjs2esm/SelfComputedMemberKeepsThisMinifySyntax", {
files: {
"/entry.js": /* js */ `
import { internal, viaTag } from "./lib.cjs";
console.log(internal(), viaTag());
`,
"/lib.cjs": /* js */ `
exports.parse = function (s) { return this._helper(s); };
exports._helper = function (s) { return "helped:" + s; };
exports.tag = function (strings) { return this._helper(strings[0]); };
exports.internal = function () { return exports["parse"]("in"); };
exports.viaTag = function () { return exports["tag"]\`tag\`; };
`,
},
cjs2esm: true,
minifySyntax: true,
onAfterBundle(api) {
const out = api.readFile("/out.js");
expect(out).toContain('return exports_lib.parse("in");');
expect(out).toContain("return exports_lib.tag`tag`;");
},
run: {
stdout: "helped:in helped:tag",
},
});
itBundled("cjs2esm/SelfMethodCallWithoutThisBindsDirectly", {
files: {
"/entry.js": /* js */ `
Expand Down
Loading