| 1 | import { transform } from "@babel/core"; |
| 2 | import taggedTemplates from "../lib/plugins/transform-tagged-template-caching"; |
| 3 | |
| 4 | const CONFIG = { |
| 5 | babelrc: false, |
| 6 | configFile: false, |
| 7 | sourceMap: false, |
| 8 | plugins: [taggedTemplates], |
| 9 | }; |
| 10 | |
| 11 | function babel(code) { |
| 12 | return transform(code, CONFIG).code; |
| 13 | } |
| 14 | |
| 15 | describe("@babel/preset-modern transform-tagged-template-caching evaluation", () => { |
| 16 | it("should pass same strings reference on repeated calls", () => { |
| 17 | const f = eval(babel("(function f(){return Object`a`;})")); |
| 18 | expect(f()).toStrictEqual(f()); |
| 19 | expect(f()).toStrictEqual(new f()); |
| 20 | expect(f()).toStrictEqual(f.call({})); |
| 21 | }); |
| 22 | |
| 23 | it("should pass different strings references for different callsites", () => { |
| 24 | const f = eval(babel("(function f(){return Object`a`===Object`b`;})")); |
| 25 | expect(f()).toEqual(false); |
| 26 | }); |
| 27 | |
| 28 | it("should pass different strings references for different callsites with same quasis", () => { |
| 29 | const f = eval(babel("(function f(){return Object`a`===Object`a`;})")); |
| 30 | expect(f()).toEqual(false); |
| 31 | }); |
| 32 | }); |