From a70d154ca4e4b218a88c79eaf234e2103dcf9d10 Mon Sep 17 00:00:00 2001 From: David Michon Date: Tue, 18 Jul 2023 13:27:20 -0700 Subject: [PATCH] [webpack5-module-minifier] Fix position units --- ...-module-minifier-length_2023-07-18-20-30.json | 10 ++++++++++ .../src/RehydrateAsset.ts | 2 +- .../src/test/AmdExternals.test.ts | 2 +- .../test/__snapshots__/AmdExternals.test.ts.snap | 16 ++++++++-------- 4 files changed, 20 insertions(+), 10 deletions(-) create mode 100644 common/changes/@rushstack/webpack5-module-minifier-plugin/fix-module-minifier-length_2023-07-18-20-30.json diff --git a/common/changes/@rushstack/webpack5-module-minifier-plugin/fix-module-minifier-length_2023-07-18-20-30.json b/common/changes/@rushstack/webpack5-module-minifier-plugin/fix-module-minifier-length_2023-07-18-20-30.json new file mode 100644 index 00000000000..540135fedd7 --- /dev/null +++ b/common/changes/@rushstack/webpack5-module-minifier-plugin/fix-module-minifier-length_2023-07-18-20-30.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@rushstack/webpack5-module-minifier-plugin", + "comment": "Fix calculation of rendered module positions to properly reflect character codes, not raw bytes.", + "type": "patch" + } + ], + "packageName": "@rushstack/webpack5-module-minifier-plugin" +} \ No newline at end of file diff --git a/webpack/webpack5-module-minifier-plugin/src/RehydrateAsset.ts b/webpack/webpack5-module-minifier-plugin/src/RehydrateAsset.ts index a06efc8b3b5..31a8140e275 100644 --- a/webpack/webpack5-module-minifier-plugin/src/RehydrateAsset.ts +++ b/webpack/webpack5-module-minifier-plugin/src/RehydrateAsset.ts @@ -67,7 +67,7 @@ export function rehydrateAsset( lastStart = CHUNK_MODULE_REGEX.lastIndex; if (moduleSource) { - const charLength: number = moduleSource.source.size(); + const charLength: number = moduleSource.source.source().length; if (emitRenderInfo) { asset.renderInfo.set(moduleSource.id, { diff --git a/webpack/webpack5-module-minifier-plugin/src/test/AmdExternals.test.ts b/webpack/webpack5-module-minifier-plugin/src/test/AmdExternals.test.ts index 91bbe25ef87..f84fa56dae9 100644 --- a/webpack/webpack5-module-minifier-plugin/src/test/AmdExternals.test.ts +++ b/webpack/webpack5-module-minifier-plugin/src/test/AmdExternals.test.ts @@ -18,7 +18,7 @@ async function amdExternalsTest(minifier: IModuleMinifier): Promise { { '/package.json': '{}', '/entry.js': `// A comment\nconsole.log("Do stuff");import(/* webpackChunkName: 'async' */ './async.js').then(mod => mod.foo());`, - '/async.js': `// @license MIT\nimport bar from 'bar';\nimport baz from 'baz';\nexport function foo() { bar.a(); baz.b(); }` + '/async.js': `// @license MIT\nimport bar from 'bar';\nimport baz from 'baz';\nexport function foo() { bar.a(); baz.b(); }console.log("Test character lengths: \ufeff\uffef")` }, '/src' ); diff --git a/webpack/webpack5-module-minifier-plugin/src/test/__snapshots__/AmdExternals.test.ts.snap b/webpack/webpack5-module-minifier-plugin/src/test/__snapshots__/AmdExternals.test.ts.snap index 0580a630bd7..6fa59e4970b 100644 --- a/webpack/webpack5-module-minifier-plugin/src/test/__snapshots__/AmdExternals.test.ts.snap +++ b/webpack/webpack5-module-minifier-plugin/src/test/__snapshots__/AmdExternals.test.ts.snap @@ -3,13 +3,13 @@ exports[`ModuleMinifierPlugin Handles AMD externals (mock): Content 1`] = ` Object { "/release/async.js": "/*! For license information please see async.js.LICENSE.txt */ -// Begin Asset Hash=1ae78808fac7117a5df587de32cb0a5dee132b58e7e47a7b63a98988b705dd2d +// Begin Asset Hash=9cea223c5b52c3d2d453434504be210b33d1d8257f6a701509abfe7888323dcb \\"use strict\\"; (self[\\"webpackChunk\\"] = self[\\"webpackChunk\\"] || []).push([[931],{ /***/ 417: -// Begin Module Hash=28dcea527403bc33391ab136fc2a6cb6b86954eee7151ce9026985cfd93e297a +// Begin Module Hash=094ab5223af3c15d458c0cef66f228ac5ef757e87c865e83b0c812f6e36777ae /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { @@ -24,7 +24,7 @@ __webpack_require__.r(__webpack_exports__); // @license MIT -function foo() { bar__WEBPACK_IMPORTED_MODULE_0___default().a(); baz__WEBPACK_IMPORTED_MODULE_1___default().b(); } +function foo() { bar__WEBPACK_IMPORTED_MODULE_0___default().a(); baz__WEBPACK_IMPORTED_MODULE_1___default().b(); }console.log(\\"Test character lengths: ￯\\") /***/ }) @@ -344,7 +344,7 @@ Object { "async.js" => Object { "positionByModuleId": Map { 417 => Object { - "charLength": 965, + "charLength": 1006, "charOffset": 240, }, }, @@ -352,7 +352,7 @@ Object { }, "byModule": Map { 417 => Map { - 931 => 965, + 931 => 1010, }, }, } @@ -363,7 +363,7 @@ exports[`ModuleMinifierPlugin Handles AMD externals (mock): Warnings 1`] = `Arra exports[`ModuleMinifierPlugin Handles AMD externals (terser): Content 1`] = ` Object { "/release/async.js": "/*! For license information please see async.js.LICENSE.txt */ -\\"use strict\\";(self.webpackChunk=self.webpackChunk||[]).push([[931],{417:((e,t,n)=>{n.r(t),n.d(t,{foo:()=>s});var a=n(791),i=n.n(a),r=n(506),o=n.n(r);function s(){i().a(),o().b()}}) +\\"use strict\\";(self.webpackChunk=self.webpackChunk||[]).push([[931],{417:((e,t,n)=>{n.r(t),n.d(t,{foo:()=>s});var a=n(791),i=n.n(a),r=n(506),o=n.n(r);function s(){i().a(),o().b()}console.log(\\"Test character lengths: \\\\ufeff￯\\")}) }]);", "/release/async.js.LICENSE.txt": "// @license MIT ", @@ -382,7 +382,7 @@ Object { "async.js" => Object { "positionByModuleId": Map { 417 => Object { - "charLength": 108, + "charLength": 154, "charOffset": 135, }, }, @@ -390,7 +390,7 @@ Object { }, "byModule": Map { 417 => Map { - 931 => 108, + 931 => 156, }, }, }