Skip to content

Commit

Permalink
[webpack5-module-minifier] Fix position units
Browse files Browse the repository at this point in the history
  • Loading branch information
dmichon-msft committed Jul 18, 2023
1 parent 287e9d3 commit a70d154
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async function amdExternalsTest(minifier: IModuleMinifier): Promise<void> {
{
'/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'
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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__) => {
Expand All @@ -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: ￯\\")
/***/ })
Expand Down Expand Up @@ -344,15 +344,15 @@ Object {
"async.js" => Object {
"positionByModuleId": Map {
417 => Object {
"charLength": 965,
"charLength": 1006,
"charOffset": 240,
},
},
},
},
"byModule": Map {
417 => Map {
931 => 965,
931 => 1010,
},
},
}
Expand All @@ -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
",
Expand All @@ -382,15 +382,15 @@ Object {
"async.js" => Object {
"positionByModuleId": Map {
417 => Object {
"charLength": 108,
"charLength": 154,
"charOffset": 135,
},
},
},
},
"byModule": Map {
417 => Map {
931 => 108,
931 => 156,
},
},
}
Expand Down

0 comments on commit a70d154

Please sign in to comment.