Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve minification for --target es5 #664

Merged
merged 3 commits into from Jul 25, 2022
Merged

feat: improve minification for --target es5 #664

merged 3 commits into from Jul 25, 2022

Conversation

Nikaple
Copy link
Contributor

@Nikaple Nikaple commented Jun 28, 2022

Given command below:

tsup ./test.ts --minify --format iife --target es5 --globalName test

Before PR, result was:

function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function")}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor)}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);return Constructor}var test=function(){var s=Object.defineProperty;var t=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var g=function(l){return s(l,"__esModule",{value:!0})};var h=function(l,o){for(var a in o)s(l,a,{get:o[a],enumerable:!0})},n=function(l,o,a,c){var _iteratorNormalCompletion=true,_didIteratorError=false,_iteratorError=undefined;if(o&& typeof o=="object"|| typeof o=="function")try{var _loop=function(_iterator,_step){var e=_step.value;!f.call(l,e)&&(a||e!=="default")&&s(l,e,{get:function(){return o[e]},enumerable:!(c=t(o,e))||c.enumerable})};for(var _iterator=d(o)[Symbol.iterator](),_step;!(_iteratorNormalCompletion=(_step=_iterator.next()).done);_iteratorNormalCompletion=true)_loop(_iterator,_step)}catch(err){_didIteratorError=true;_iteratorError=err}finally{try{if(!_iteratorNormalCompletion&&_iterator.return!=null){_iterator.return()}}finally{if(_didIteratorError){throw _iteratorError}}}return l};var p=function(l){return function(o,a){return l&&l.get(o)||(a=n(g({}),o,1),l&&l.set(o,a),a)}}(typeof WeakMap!="undefined"?new WeakMap:0);var r={};h(r,{Foo:function(){return i}});var i=function(){"use strict";function _class(){_classCallCheck(this,_class)}_createClass(_class,[{key:"hi",value:function hi(){console.log(function(){return"foo"}())}}]);return _class}();return p(r)}()

After PR, result will be:

function a(a,b){if(!(a instanceof b)){throw new TypeError("Cannot call a class as a function")}}function b(a,b){for(var c=0;c<b.length;c++){var d=b[c];d.enumerable=d.enumerable||false;d.configurable=true;if("value"in d)d.writable=true;Object.defineProperty(a,d.key,d)}}function c(a,c,d){if(c)b(a.prototype,c);if(d)b(a,d);return a}var test=function(){var b=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var e=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var g=function(a){return b(a,"__esModule",{value:!0})};var h=function(a,c){for(var d in c)b(a,d,{get:c[d],enumerable:!0})},i=function(a,c,g,h){var i=true,j=false,k=undefined;if(c&& typeof c=="object"|| typeof c=="function")try{var l=function(m,n){var e=n.value;!f.call(a,e)&&(g||e!=="default")&&b(a,e,{get:function(){return c[e]},enumerable:!(h=d(c,e))||h.enumerable})};for(var m=e(c)[Symbol.iterator](),n;!(i=(n=m.next()).done);i=true)l(m,n)}catch(o){j=true;k=o}finally{try{if(!i&&m.return!=null){m.return()}}finally{if(j){throw k}}}return a};var j=function(a){return function(b,c){return a&&a.get(b)||(c=i(g({}),b,1),a&&a.set(b,c),c)}}(typeof WeakMap!="undefined"?new WeakMap:0);var k={};h(k,{Foo:function(){return l}});var l=function(){"use strict";function b(){a(this,b)}c(b,[{key:"hi",value:function a(){console.log(function(){return"foo"}())}}]);return b}();return j(k)}()

@vercel
Copy link

vercel bot commented Jun 28, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
tsup ✅ Ready (Inspect) Visit Preview Jul 25, 2022 at 2:55PM (UTC)

@@ -713,7 +713,7 @@ test('decorator metadata', async () => {
}`,
})
const contents = await getFileContent('dist/input.js')
expect(contents).toContain(`Reflect.metadata("design:type"`)
expect(contents).toContain(`metadata("design:type"`)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

After upgrading @swc/core, Reflect.metadata changes to __metadata

package.json Outdated
@@ -42,7 +42,7 @@
},
"devDependencies": {
"@rollup/plugin-json": "4.1.0",
"@swc/core": "1.2.126",
"@swc/core": "1.2.206",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@swc/core is upgraded to ensure correct typing for swc.transform

@github-actions
Copy link

🎉 This PR is included in version 6.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants