From 2a5dfe61ea4fa9ba8c2d7d9a39604175ee55eefa Mon Sep 17 00:00:00 2001 From: Chengzhong Wu Date: Thu, 19 Dec 2024 11:32:38 +0000 Subject: [PATCH] test: add a test case for unusual charsets --- test/snapshots/transform.test.js.snapshot | 8 ++++++++ test/transform.test.js | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/test/snapshots/transform.test.js.snapshot b/test/snapshots/transform.test.js.snapshot index cb98f3d70..7a181965f 100644 --- a/test/snapshots/transform.test.js.snapshot +++ b/test/snapshots/transform.test.js.snapshot @@ -34,6 +34,14 @@ exports[`should perform transformation with source maps no filename 2`] = ` "{\\"version\\":3,\\"sources\\":[\\"\\"],\\"sourcesContent\\":[\\"\\\\n enum Foo {\\\\n Bar = 7,\\\\n Baz = 2,\\\\n }\\\\n output = Foo.Bar\\"],\\"names\\":[],\\"mappings\\":\\"AACI,IAAA,AAAK,6BAAA;;;WAAA;EAAA;AAIL\\"}" `; +exports[`should perform transformation with source maps with uncommon chars 1`] = ` +"var Foo = /*#__PURE__*/ function(Foo) {\\n Foo[Foo[\\"Bar\\"] = 7] = \\"Bar\\";\\n Foo[Foo[\\"Baz\\"] = 2] = \\"Baz\\";\\n return Foo;\\n}(Foo || {});\\noutput = 7;\\n" +`; + +exports[`should perform transformation with source maps with uncommon chars 2`] = ` +"{\\"version\\":3,\\"sources\\":[\\"dir%20with $unusual\\\\\\"chars?'åß∂ƒ©∆¬…\`.cts\\"],\\"names\\":[],\\"mappings\\":\\"AACI,IAAA,AAAK,6BAAA;;;WAAA;EAAA;AAKL\\"}" +`; + exports[`should perform transformation without source maps 1`] = ` "var Foo = /*#__PURE__*/ function(Foo) {\\n Foo[Foo[\\"Bar\\"] = 7] = \\"Bar\\";\\n Foo[Foo[\\"Baz\\"] = 2] = \\"Baz\\";\\n return Foo;\\n}(Foo || {});\\noutput = 7;\\n" `; diff --git a/test/transform.test.js b/test/transform.test.js index d451d0ba7..30972125f 100644 --- a/test/transform.test.js +++ b/test/transform.test.js @@ -70,6 +70,26 @@ test("should perform transformation with source maps", (t) => { assert.strictEqual(result, 7); }); +test("should perform transformation with source maps with uncommon chars", (t) => { + const tsCode = ` + enum Foo { + Bar = 7, + Baz = 2, + } + + output = Foo.Bar`; + const { code, map } = transformSync(tsCode, { + mode: "transform", + sourceMap: true, + filename: "dir%20with $unusual\"chars?'åß∂ƒ©∆¬…`.cts", + }); + + t.assert.snapshot(code); + t.assert.snapshot(map); + const result = vm.runInContext(code, vm.createContext()); + assert.strictEqual(result, 7); +}); + test("should perform transformation with source maps no filename", (t) => { const tsCode = ` enum Foo {