Skip to content

Commit

Permalink
do not minify constructor class names
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Oct 1, 2021
1 parent a87297a commit fe8d685
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 0 deletions.
10 changes: 10 additions & 0 deletions scripts/minify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ function minifyOptions(debug: boolean): MinifyOptions {
global_defs: {
'globalThis.partytownDebug': true,
},
keep_classnames: true,
inline: false,
join_vars: false,
loops: false,
Expand All @@ -37,6 +38,7 @@ function minifyOptions(debug: boolean): MinifyOptions {
global_defs: {
'globalThis.partytownDebug': false,
},
keep_classnames: keepConstructorNames(),
ecma: 2018,
passes: 2,
unsafe_symbols: true,
Expand All @@ -45,9 +47,17 @@ function minifyOptions(debug: boolean): MinifyOptions {
comments: false,
ecma: 2018,
},
keep_classnames: keepConstructorNames(),
mangle: {
keep_classnames: keepConstructorNames(),
},
};
}

function keepConstructorNames() {
return /HTMLAnchorElement|HTMLIFrameElement|HTMLScriptElement|HTMLDocument|HTMLElement|Node|Window/;
}

function managlePropsPlugin(): Plugin {
const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$'.split('');
const mangleProps: { [key: string]: string } = {
Expand Down
3 changes: 3 additions & 0 deletions tests/platform/document-prod/document-prod.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,7 @@ test('document-prod', async ({ page }) => {
await expect(testCurrentScriptSrcLocation).toHaveText(
'/platform/document-prod/current-script-src.js'
);

const testDocCstrName = page.locator('#testDocCstrName');
await expect(testDocCstrName).toHaveText('HTMLDocument');
});
11 changes: 11 additions & 0 deletions tests/platform/document-prod/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,17 @@ <h1 class="title">Document Prod</h1>
</script>
</li>

<li>
<strong>document.constructor.name</strong>
<code id="testDocCstrName"></code>
<script type="text/partytown">
(function () {
const elm = document.getElementById('testDocCstrName');
elm.textContent = document.constructor.name;
})();
</script>
</li>

<script type="text/partytown">
(function () {
document.body.classList.add('completed');
Expand Down
3 changes: 3 additions & 0 deletions tests/platform/document/document.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,7 @@ test('document', async ({ page }) => {

const testDocType = page.locator('#testDocType');
await expect(testDocType).toHaveText('10 html html false');

const testDocCstrName = page.locator('#testDocCstrName');
await expect(testDocCstrName).toHaveText('HTMLDocument');
});
11 changes: 11 additions & 0 deletions tests/platform/document/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,17 @@ <h1 class="title">Document</h1>
</script>
</li>

<li>
<strong>document.constructor.name</strong>
<code id="testDocCstrName"></code>
<script type="text/partytown">
(function () {
const elm = document.getElementById('testDocCstrName');
elm.textContent = document.constructor.name;
})();
</script>
</li>

<script type="text/partytown">
(function () {
document.body.classList.add('completed');
Expand Down

1 comment on commit fe8d685

@vercel
Copy link

@vercel vercel bot commented on fe8d685 Oct 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failed to assign a domain to your deployment due to the following error:

Aliasing the Deployment Timed Out

Please sign in to comment.