diff --git a/README.md b/README.md index dcebf406..30d0433c 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,42 @@ } ``` +### New: Modern JS + +Microbundle now has a new `modern` format (`microbundle -f modern`). +Modern output still bundles and compresses your code, but it keeps useful syntax +around that actually helps compression: + +```js +// Our source, "src/make-dom.js": +export default async function makeDom(tag, props, children) { + const el = document.createElement(tag); + el.append(...(await children)); + return Object.assign(el, props); +} +``` + +Microbundle compiles the above to this: + +```js +export default async (e, t, a) => { + const n = document.createElement(e); + return n.append(...(await a)), Object.assign(n, t); +}; +``` + +This is enabled by default - all you have to do is add the field to your `package.json`. You might choose to ship modern JS using the "module" field: + +```js +{ + "main": "dist/foo.umd.js", // legacy UMD bundle (for Node & CDN's) + "module": "dist/foo.modern.mjs", // modern ES2017 bundle + "scripts": { + "build": "microbundle src/foo.js -f modern,umd" + } +} +``` + ## 📦 Usage Microbundle includes two commands - `build` (the default) and `watch`. Neither require any options, but you can tailor things to suit your needs a bit if you like. @@ -76,50 +112,51 @@ Libraries often wish to rename internal object properties or class members to sm ```json { - "mangle": { - "regex": "^_" - } + "mangle": { + "regex": "^_" + } } ``` + ### All CLI Options ``` - Usage - $ microbundle [options] - - Available Commands - build Build once and exit - watch Rebuilds on any change - - For more info, run any command with the `--help` flag - $ microbundle build --help - $ microbundle watch --help - - Options - -v, --version Displays current version - -i, --entry Entry module(s) - -o, --output Directory to place build files into - -f, --format Only build specified formats (default es,cjs,umd) - -w, --watch Rebuilds on any change (default false) - --target Specify your target environment (node or web, default web) - --external Specify external dependencies, or 'none' - --globals Specify globals dependencies, or 'none' - --define Replace constants with hard-coded values - --alias Map imports to different modules - --compress Compress output using Terser (default true) - --strict Enforce undefined global context and add "use strict" - --name Specify name exposed in UMD builds - --cwd Use an alternative working directory (default .) - --sourcemap Generate source map (default true) - --raw Show raw byte size (default false) - --jsx A custom JSX pragma like React.createElement (default: h) - -h, --help Displays this message - - Examples - $ microbundle build --globals react=React,jquery=$ - $ microbundle build --define API_KEY=1234 - $ microbundle build --alias react=preact - $ microbundle build --no-sourcemap # don't generate sourcemaps +Usage + $ microbundle [options] + +Available Commands + build Build once and exit + watch Rebuilds on any change + +For more info, run any command with the `--help` flag + $ microbundle build --help + $ microbundle watch --help + +Options + -v, --version Displays current version + -i, --entry Entry module(s) + -o, --output Directory to place build files into + -f, --format Only build specified formats (default modern,es,cjs,umd) + -w, --watch Rebuilds on any change (default false) + --target Specify your target environment (node or web) (default web) + --external Specify external dependencies, or 'none' + --globals Specify globals dependencies, or 'none' + --define Replace constants with hard-coded values + --alias Map imports to different modules + --compress Compress output using Terser + --strict Enforce undefined global context and add "use strict" + --name Specify name exposed in UMD builds + --cwd Use an alternative working directory (default .) + --sourcemap Generate source map (default true) + --raw Show raw byte size (default false) + --jsx A custom JSX pragma like React.createElement (default: h) + -h, --help Displays this message + +Examples + $ microbundle microbundle --globals react=React,jquery=$ + $ microbundle microbundle --define API_KEY=1234 + $ microbundle microbundle --alias react=preact + $ microbundle microbundle --no-sourcemap # don't generate sourcemaps ``` ## 🛣 Roadmap diff --git a/src/index.js b/src/index.js index e4cef223..764e1cdb 100644 --- a/src/index.js +++ b/src/index.js @@ -425,9 +425,15 @@ function createConfig(options, entry, format, writeMeta) { : pkg['jsnext:main'] || 'x.mjs', mainNoExtension, ); + let modernMain = replaceName( + (pkg.syntax && pkg.syntax.esmodules) || pkg.esmodule || 'x.modern.mjs', + mainNoExtension, + ); let cjsMain = replaceName(pkg['cjs:main'] || 'x.js', mainNoExtension); let umdMain = replaceName(pkg['umd:main'] || 'x.umd.js', mainNoExtension); + const modern = format === 'modern'; + // let rollupName = safeVariableName(basename(entry).replace(/\.js$/, '')); let nameCache = {}; @@ -553,6 +559,8 @@ function createConfig(options, entry, format, writeMeta) { passPerPreset: true, // @see https://babeljs.io/docs/en/options#passperpreset custom: { defines, + modern, + compress: options.compress !== false, targets: options.target === 'node' ? { node: '8' } : undefined, pragma: options.jsx || 'h', pragmaFrag: options.jsxFragment || 'Fragment', @@ -562,20 +570,19 @@ function createConfig(options, entry, format, writeMeta) { options.compress !== false && [ terser({ sourcemap: true, - output: { - comments: (node, comment) => /[@#]__PURE__/.test(comment.value), - }, compress: Object.assign( { keep_infinity: true, pure_getters: true, + // Ideally we'd just get Terser to respect existing Arrow functions... + // unsafe_arrows: true, passes: 10, }, minifyOptions.compress || {}, ), warnings: true, - ecma: 5, - toplevel: format === 'cjs' || format === 'es', + ecma: modern ? 9 : 5, + toplevel: modern || format === 'cjs' || format === 'es', mangle: Object.assign({}, minifyOptions.mangle || {}), nameCache, }), @@ -617,13 +624,15 @@ function createConfig(options, entry, format, writeMeta) { get banner() { return shebang[options.name]; }, - format, + format: modern ? 'es' : format, name: options.name, file: resolve( options.cwd, - (format === 'es' && moduleMain) || - (format === 'umd' && umdMain) || - cjsMain, + { + modern: modernMain, + es: moduleMain, + umd: umdMain, + }[format] || cjsMain, ), }, }; diff --git a/src/lib/babel-custom.js b/src/lib/babel-custom.js index 4bd58523..ce9e9477 100644 --- a/src/lib/babel-custom.js +++ b/src/lib/babel-custom.js @@ -3,6 +3,10 @@ import babelPlugin from 'rollup-plugin-babel'; import merge from 'lodash.merge'; import { isTruthy } from '../utils'; +const ESMODULES_TARGET = { + esmodules: true, +}; + const mergeConfigItems = (type, ...configItemsToMerge) => { const mergedItems = []; @@ -64,7 +68,7 @@ export default babelPlugin.custom(babelCore => { name: 'babel-plugin-transform-replace-expressions', replace: customOptions.defines, }, - { + !customOptions.modern && { name: 'babel-plugin-transform-async-to-promises', inlineHelpers: true, externalHelpers: true, @@ -73,7 +77,7 @@ export default babelPlugin.custom(babelCore => { name: '@babel/plugin-proposal-class-properties', loose: true, }, - { + !customOptions.modern && { name: '@babel/plugin-transform-regenerator', async: false, }, @@ -94,19 +98,22 @@ export default babelPlugin.custom(babelCore => { babelOptions.presets[envIdx] = createConfigItem( [ preset.file.resolved, - merge( - { - loose: true, - targets: customOptions.targets, - }, - preset.options, - { - modules: false, - exclude: merge( - ['transform-async-to-generator', 'transform-regenerator'], - preset.options.exclude || [], - ), - }, + Object.assign( + merge( + { + loose: true, + targets: customOptions.targets, + }, + preset.options, + { + modules: false, + exclude: merge( + ['transform-async-to-generator', 'transform-regenerator'], + preset.options.exclude || [], + ), + }, + ), + customOptions.modern ? { targets: ESMODULES_TARGET } : {}, ), ], { @@ -117,7 +124,9 @@ export default babelPlugin.custom(babelCore => { babelOptions.presets = createConfigItems('preset', [ { name: '@babel/preset-env', - targets: customOptions.targets, + targets: customOptions.modern + ? ESMODULES_TARGET + : customOptions.targets, modules: false, loose: true, exclude: ['transform-async-to-generator', 'transform-regenerator'], @@ -132,6 +141,12 @@ export default babelPlugin.custom(babelCore => { babelOptions.plugins || [], ); + babelOptions.generatorOpts = { + minified: customOptions.compress, + compact: customOptions.compress, + shouldPrintComment: comment => /[@#]__PURE__/.test(comment), + }; + return babelOptions; }, }; diff --git a/src/prog.js b/src/prog.js index a38298fe..0cc51fe7 100644 --- a/src/prog.js +++ b/src/prog.js @@ -4,6 +4,10 @@ let { version } = require('../package'); const toArray = val => (Array.isArray(val) ? val : val == null ? [] : [val]); export default handler => { + const ENABLE_MODERN = process.env.MICROBUNDLE_MODERN !== 'false'; + + const DEFAULT_FORMATS = ENABLE_MODERN ? 'modern,es,cjs,umd' : 'es,cjs,umd'; + const cmd = type => (str, opts) => { opts.watch = opts.watch || type === 'watch'; opts.compress = @@ -18,7 +22,7 @@ export default handler => { .version(version) .option('--entry, -i', 'Entry module(s)') .option('--output, -o', 'Directory to place build files into') - .option('--format, -f', 'Only build specified formats', 'es,cjs,umd') + .option('--format, -f', 'Only build specified formats', DEFAULT_FORMATS) .option('--watch, -w', 'Rebuilds on any change', false) .option('--target', 'Specify your target environment (node or web)', 'web') .option('--external', `Specify external dependencies, or 'none'`) diff --git a/test/__snapshots__/index.test.js.snap b/test/__snapshots__/index.test.js.snap index 6d546009..fb2fadbf 100644 --- a/test/__snapshots__/index.test.js.snap +++ b/test/__snapshots__/index.test.js.snap @@ -117,36 +117,30 @@ async-ts Build \\"asyncTs\\" to dist: -111 B: async-ts.js.gz -85 B: async-ts.js.br -120 B: async-ts.mjs.gz -105 B: async-ts.mjs.br -207 B: async-ts.umd.js.gz -161 B: async-ts.umd.js.br" +103 B: async-ts.js.gz +72 B: async-ts.js.br +112 B: async-ts.mjs.gz +91 B: async-ts.mjs.br +202 B: async-ts.umd.js.gz +159 B: async-ts.umd.js.br" `; exports[`fixtures build async-ts with microbundle 2`] = `7`; exports[`fixtures build async-ts with microbundle 3`] = ` -"exports.MyClass= -/* */ -function(){function o(){}return o.prototype.foo=function(){return Promise.resolve()},o}(); +"exports.MyClass=function(){function o(){}return o.prototype.foo=function(){return Promise.resolve()},o}(); //# sourceMappingURL=async-ts.js.map " `; exports[`fixtures build async-ts with microbundle 4`] = ` -"var o= -/* */ -function(){function o(){}return o.prototype.foo=function(){return Promise.resolve()},o}();export{o as MyClass}; +"var o=function(){function o(){}return o.prototype.foo=function(){return Promise.resolve()},o}();export{o as MyClass}; //# sourceMappingURL=async-ts.mjs.map " `; exports[`fixtures build async-ts with microbundle 5`] = ` -"!function(e,n){\\"object\\"==typeof exports&&\\"undefined\\"!=typeof module?n(exports):\\"function\\"==typeof define&&define.amd?define([\\"exports\\"],n):n((e=e||self).asyncTs={})}(this,function(e){e.MyClass= -/* */ -function(){function e(){}return e.prototype.foo=function(){return Promise.resolve()},e}()}); +"!function(e,n){\\"object\\"==typeof exports&&\\"undefined\\"!=typeof module?n(exports):\\"function\\"==typeof define&&define.amd?define([\\"exports\\"],n):n((e=e||self).asyncTs={})}(this,function(e){e.MyClass=function(){function e(){}return e.prototype.foo=function(){return Promise.resolve()},e}()}); //# sourceMappingURL=async-ts.umd.js.map " `; @@ -743,36 +737,30 @@ basic-ts Build \\"basicLibTs\\" to dist: -110 B: basic-lib-ts.js.gz -86 B: basic-lib-ts.js.br -104 B: basic-lib-ts.mjs.gz -84 B: basic-lib-ts.mjs.br -193 B: basic-lib-ts.umd.js.gz -150 B: basic-lib-ts.umd.js.br" +104 B: basic-lib-ts.js.gz +76 B: basic-lib-ts.js.br +97 B: basic-lib-ts.mjs.gz +73 B: basic-lib-ts.mjs.br +187 B: basic-lib-ts.umd.js.gz +144 B: basic-lib-ts.umd.js.br" `; exports[`fixtures build basic-ts with microbundle 2`] = `8`; exports[`fixtures build basic-ts with microbundle 3`] = ` -"var n=new( -/* */ -function(){function n(){}return n.prototype.drive=function(n){return!0},n}());module.exports=n; +"var n=new(function(){function n(){}return n.prototype.drive=function(n){return!0},n}());module.exports=n; //# sourceMappingURL=basic-lib-ts.js.map " `; exports[`fixtures build basic-ts with microbundle 4`] = ` -"export default new( -/* */ -function(){function n(){}return n.prototype.drive=function(n){return!0},n}()); +"export default new(function(){function n(){}return n.prototype.drive=function(n){return!0},n}()); //# sourceMappingURL=basic-lib-ts.mjs.map " `; exports[`fixtures build basic-ts with microbundle 5`] = ` -"!function(e,n){\\"object\\"==typeof exports&&\\"undefined\\"!=typeof module?module.exports=n():\\"function\\"==typeof define&&define.amd?define(n):(e=e||self).basicLibTs=n()}(this,function(){return new( -/* */ -function(){function e(){}return e.prototype.drive=function(e){return!0},e}())}); +"!function(e,n){\\"object\\"==typeof exports&&\\"undefined\\"!=typeof module?module.exports=n():\\"function\\"==typeof define&&define.amd?define(n):(e=e||self).basicLibTs=n()}(this,function(){return new(function(){function e(){}return e.prototype.drive=function(e){return!0},e}())}); //# sourceMappingURL=basic-lib-ts.umd.js.map " `; @@ -816,36 +804,30 @@ basic-tsx Build \\"basicLibTsx\\" to dist: -245 B: basic-lib-tsx.js.gz -230 B: basic-lib-tsx.js.br -246 B: basic-lib-tsx.mjs.gz -207 B: basic-lib-tsx.mjs.br -324 B: basic-lib-tsx.umd.js.gz -273 B: basic-lib-tsx.umd.js.br" +235 B: basic-lib-tsx.js.gz +188 B: basic-lib-tsx.js.br +239 B: basic-lib-tsx.mjs.gz +191 B: basic-lib-tsx.mjs.br +317 B: basic-lib-tsx.umd.js.gz +260 B: basic-lib-tsx.umd.js.br" `; exports[`fixtures build basic-tsx with microbundle 2`] = `7`; exports[`fixtures build basic-tsx with microbundle 3`] = ` -"var r=function(r,n){for(var e=arguments.length,o=new Array(e>2?e-2:0),t=2;t2?e-2:0),t=2;t2?e-2:0),o=2;o2?e-2:0),o=2;o2?o-2:0),r=2;r2?o-2:0),r=2;r=0;f--)(n=e[f])&&(l=(c<3?n(l):c>3?n(t,r,l):n(t,r))||l);return c>3&&l&&Object.defineProperty(t,r,l),l}([function(e){Object.seal(e),Object.seal(e.prototype)}],e))(\\"Hello World\\");module.exports=t; +"var e=function(){function e(e){this.greeting=e}return e.prototype.greet=function(){return\\"Hello, \\"+this.greeting},e}(),t=new(e=function(e,t,r,o){var n,c=arguments.length,l=c<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,r):o;if(\\"object\\"==typeof Reflect&&\\"function\\"==typeof Reflect.decorate)l=Reflect.decorate(e,t,r,o);else for(var f=e.length-1;f>=0;f--)(n=e[f])&&(l=(c<3?n(l):c>3?n(t,r,l):n(t,r))||l);return c>3&&l&&Object.defineProperty(t,r,l),l}([function(e){Object.seal(e),Object.seal(e.prototype)}],e))(\\"Hello World\\");module.exports=t; //# sourceMappingURL=class-decorators-ts.js.map " `; exports[`fixtures build class-decorators-ts with microbundle 4`] = ` -"var e= -/* */ -function(){function e(e){this.greeting=e}return e.prototype.greet=function(){return\\"Hello, \\"+this.greeting},e}();export default new(e=function(e,t,r,n){var o,c=arguments.length,l=c<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if(\\"object\\"==typeof Reflect&&\\"function\\"==typeof Reflect.decorate)l=Reflect.decorate(e,t,r,n);else for(var f=e.length-1;f>=0;f--)(o=e[f])&&(l=(c<3?o(l):c>3?o(t,r,l):o(t,r))||l);return c>3&&l&&Object.defineProperty(t,r,l),l}([function(e){Object.seal(e),Object.seal(e.prototype)}],e))(\\"Hello World\\"); +"var e=function(){function e(e){this.greeting=e}return e.prototype.greet=function(){return\\"Hello, \\"+this.greeting},e}();export default new(e=function(e,t,r,n){var o,c=arguments.length,l=c<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if(\\"object\\"==typeof Reflect&&\\"function\\"==typeof Reflect.decorate)l=Reflect.decorate(e,t,r,n);else for(var f=e.length-1;f>=0;f--)(o=e[f])&&(l=(c<3?o(l):c>3?o(t,r,l):o(t,r))||l);return c>3&&l&&Object.defineProperty(t,r,l),l}([function(e){Object.seal(e),Object.seal(e.prototype)}],e))(\\"Hello World\\"); //# sourceMappingURL=class-decorators-ts.mjs.map " `; exports[`fixtures build class-decorators-ts with microbundle 5`] = ` -"!function(e,t){\\"object\\"==typeof exports&&\\"undefined\\"!=typeof module?module.exports=t():\\"function\\"==typeof define&&define.amd?define(t):(e=e||self).classDecoratorsTs=t()}(this,function(){var e= -/* */ -function(){function e(e){this.greeting=e}return e.prototype.greet=function(){return\\"Hello, \\"+this.greeting},e}();return new(e=function(e,t,n,o){var r,f=arguments.length,c=f<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,n):o;if(\\"object\\"==typeof Reflect&&\\"function\\"==typeof Reflect.decorate)c=Reflect.decorate(e,t,n,o);else for(var i=e.length-1;i>=0;i--)(r=e[i])&&(c=(f<3?r(c):f>3?r(t,n,c):r(t,n))||c);return f>3&&c&&Object.defineProperty(t,n,c),c}([function(e){Object.seal(e),Object.seal(e.prototype)}],e))(\\"Hello World\\")}); +"!function(e,t){\\"object\\"==typeof exports&&\\"undefined\\"!=typeof module?module.exports=t():\\"function\\"==typeof define&&define.amd?define(t):(e=e||self).classDecoratorsTs=t()}(this,function(){var e=function(){function e(e){this.greeting=e}return e.prototype.greet=function(){return\\"Hello, \\"+this.greeting},e}();return new(e=function(e,t,n,o){var r,f=arguments.length,c=f<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,n):o;if(\\"object\\"==typeof Reflect&&\\"function\\"==typeof Reflect.decorate)c=Reflect.decorate(e,t,n,o);else for(var i=e.length-1;i>=0;i--)(r=e[i])&&(c=(f<3?r(c):f>3?r(t,n,c):r(t,n))||c);return f>3&&c&&Object.defineProperty(t,n,c),c}([function(e){Object.seal(e),Object.seal(e.prototype)}],e))(\\"Hello World\\")}); //# sourceMappingURL=class-decorators-ts.umd.js.map " `; @@ -1271,48 +1247,30 @@ esnext-ts Build \\"esnextTs\\" to dist: -1036 B: esnext-ts.js.gz -941 B: esnext-ts.js.br -1036 B: esnext-ts.mjs.gz -939 B: esnext-ts.mjs.br -1095 B: esnext-ts.umd.js.gz -1000 B: esnext-ts.umd.js.br" +1022 B: esnext-ts.js.gz +926 B: esnext-ts.js.br +1022 B: esnext-ts.mjs.gz +925 B: esnext-ts.mjs.br +1081 B: esnext-ts.umd.js.gz +982 B: esnext-ts.umd.js.br" `; exports[`fixtures build esnext-ts with microbundle 2`] = `7`; exports[`fixtures build esnext-ts with microbundle 3`] = ` -"var n= -/* */ -function(){function n(){}return n.prototype.then=function(r,e){var o=new n,i=this.s;if(i){var u=1&i?r:e;if(u){try{t(o,1,u(this.v))}catch(n){t(o,2,n)}return o}return this}return this.o=function(n){try{var i=n.v;1&n.s?t(o,1,r?r(i):i):e?t(o,1,e(i)):t(o,2,i)}catch(n){t(o,2,n)}},o},n}();function t(r,e,o){if(!r.s){if(o instanceof n){if(!o.s)return void(o.o=t.bind(null,r,e));1&e&&(e=o.s),o=o.v}if(o&&o.then)return void o.then(t.bind(null,r,e),t.bind(null,r,2));r.s=e,r.v=o;var i=r.o;i&&i(r)}}function r(t){return t instanceof n&&1&t.s}function e(n,t){try{var r=n()}catch(n){return t(!0,n)}return r&&r.then?r.then(t.bind(null,!1),t.bind(null,!0)):t(!1,value)} -/* */ -\\"undefined\\"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol(\\"Symbol.iterator\\"))), -/* */ -\\"undefined\\"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol(\\"Symbol.asyncIterator\\")));var o=function(){try{var o,i,u,f,h=!1,c=[],a=!0,l=!1,v=e(function(){return function(e,f){try{var h=function(){o=function(n){var t;if(\\"undefined\\"!=typeof Symbol){if(Symbol.asyncIterator&&null!=(t=n[Symbol.asyncIterator]))return t.call(n);if(Symbol.iterator&&null!=(t=n[Symbol.iterator]))return t.call(n)}throw new TypeError(\\"Object is not async iterable\\")}([1,2]);var e=function(e,o,i){for(var u;;){var f=e();if(r(f)&&(f=f.v),!f)return h;if(f.then){u=0;break}var h=i();if(h&&h.then){if(!r(h)){u=1;break}h=h.s}if(o){var c=o();if(c&&c.then&&!r(c)){u=2;break}}}var a=new n,l=t.bind(null,a,2);return(0===u?f.then(s):1===u?h.then(v):c.then(y)).then(void 0,l),a;function v(n){h=n;do{if(o&&(c=o())&&c.then&&!r(c))return void c.then(y).then(void 0,l);if(!(f=e())||r(f)&&!f.v)return void t(a,1,h);if(f.then)return void f.then(s).then(void 0,l);r(h=i())&&(h=h.v)}while(!h||!h.then);h.then(v).then(void 0,l)}function s(n){n?(h=i())&&h.then?h.then(v).then(void 0,l):v(h):t(a,1,h)}function y(){(f=e())?f.then?f.then(s).then(void 0,l):s(f):t(a,1,h)}}(function(){return!!Promise.resolve(o.next()).then(function(n){return a=i.done,i=n,Promise.resolve(i.value).then(function(n){return u=n,!a})})},function(){return!!(a=!0)},function(){c.push(u)});if(e&&e.then)return e.then(function(){})}()}catch(n){return f(n)}return h&&h.then?h.then(void 0,f):h}(0,function(n){l=!0,f=n})},function(n,t){function r(r){if(h)return r;if(n)throw t;return t}var i=e(function(){var n=function(){if(!a&&null!=o.return)return Promise.resolve(o.return()).then(function(){})}();if(n&&n.then)return n.then(function(){})},function(n,t){if(l)throw f;if(n)throw t;return t});return i&&i.then?i.then(r):r(i)});return Promise.resolve(v&&v.then?v.then(function(n){return h?n:c}):h?v:c)}catch(n){return Promise.reject(n)}};o().then(console.log),module.exports=o; +"var n=function(){function n(){}return n.prototype.then=function(r,e){var o=new n,i=this.s;if(i){var u=1&i?r:e;if(u){try{t(o,1,u(this.v))}catch(n){t(o,2,n)}return o}return this}return this.o=function(n){try{var i=n.v;1&n.s?t(o,1,r?r(i):i):e?t(o,1,e(i)):t(o,2,i)}catch(n){t(o,2,n)}},o},n}();function t(r,e,o){if(!r.s){if(o instanceof n){if(!o.s)return void(o.o=t.bind(null,r,e));1&e&&(e=o.s),o=o.v}if(o&&o.then)return void o.then(t.bind(null,r,e),t.bind(null,r,2));r.s=e,r.v=o;var i=r.o;i&&i(r)}}function r(t){return t instanceof n&&1&t.s}function e(n,t){try{var r=n()}catch(n){return t(!0,n)}return r&&r.then?r.then(t.bind(null,!1),t.bind(null,!0)):t(!1,value)}\\"undefined\\"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol(\\"Symbol.iterator\\"))),\\"undefined\\"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol(\\"Symbol.asyncIterator\\")));var o=function(){try{var o,i,u,f,h=!1,c=[],a=!0,l=!1,v=e(function(){return function(e,f){try{var h=function(){o=function(n){var t;if(\\"undefined\\"!=typeof Symbol){if(Symbol.asyncIterator&&null!=(t=n[Symbol.asyncIterator]))return t.call(n);if(Symbol.iterator&&null!=(t=n[Symbol.iterator]))return t.call(n)}throw new TypeError(\\"Object is not async iterable\\")}([1,2]);var e=function(e,o,i){for(var u;;){var f=e();if(r(f)&&(f=f.v),!f)return h;if(f.then){u=0;break}var h=i();if(h&&h.then){if(!r(h)){u=1;break}h=h.s}if(o){var c=o();if(c&&c.then&&!r(c)){u=2;break}}}var a=new n,l=t.bind(null,a,2);return(0===u?f.then(s):1===u?h.then(v):c.then(y)).then(void 0,l),a;function v(n){h=n;do{if(o&&(c=o())&&c.then&&!r(c))return void c.then(y).then(void 0,l);if(!(f=e())||r(f)&&!f.v)return void t(a,1,h);if(f.then)return void f.then(s).then(void 0,l);r(h=i())&&(h=h.v)}while(!h||!h.then);h.then(v).then(void 0,l)}function s(n){n?(h=i())&&h.then?h.then(v).then(void 0,l):v(h):t(a,1,h)}function y(){(f=e())?f.then?f.then(s).then(void 0,l):s(f):t(a,1,h)}}(function(){return!!Promise.resolve(o.next()).then(function(n){return a=i.done,i=n,Promise.resolve(i.value).then(function(n){return u=n,!a})})},function(){return!!(a=!0)},function(){c.push(u)});if(e&&e.then)return e.then(function(){})}()}catch(n){return f(n)}return h&&h.then?h.then(void 0,f):h}(0,function(n){l=!0,f=n})},function(n,t){function r(r){if(h)return r;if(n)throw t;return t}var i=e(function(){var n=function(){if(!a&&null!=o.return)return Promise.resolve(o.return()).then(function(){})}();if(n&&n.then)return n.then(function(){})},function(n,t){if(l)throw f;if(n)throw t;return t});return i&&i.then?i.then(r):r(i)});return Promise.resolve(v&&v.then?v.then(function(n){return h?n:c}):h?v:c)}catch(n){return Promise.reject(n)}};o().then(console.log),module.exports=o; //# sourceMappingURL=esnext-ts.js.map " `; exports[`fixtures build esnext-ts with microbundle 4`] = ` -"var n= -/* */ -function(){function n(){}return n.prototype.then=function(r,e){var o=new n,i=this.s;if(i){var u=1&i?r:e;if(u){try{t(o,1,u(this.v))}catch(n){t(o,2,n)}return o}return this}return this.o=function(n){try{var i=n.v;1&n.s?t(o,1,r?r(i):i):e?t(o,1,e(i)):t(o,2,i)}catch(n){t(o,2,n)}},o},n}();function t(r,e,o){if(!r.s){if(o instanceof n){if(!o.s)return void(o.o=t.bind(null,r,e));1&e&&(e=o.s),o=o.v}if(o&&o.then)return void o.then(t.bind(null,r,e),t.bind(null,r,2));r.s=e,r.v=o;var i=r.o;i&&i(r)}}function r(t){return t instanceof n&&1&t.s}function e(n,t){try{var r=n()}catch(n){return t(!0,n)}return r&&r.then?r.then(t.bind(null,!1),t.bind(null,!0)):t(!1,value)} -/* */ -\\"undefined\\"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol(\\"Symbol.iterator\\"))), -/* */ -\\"undefined\\"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol(\\"Symbol.asyncIterator\\")));var o=function(){try{var o,i,u,f,h=!1,c=[],a=!0,l=!1,v=e(function(){return function(e,f){try{var h=function(){o=function(n){var t;if(\\"undefined\\"!=typeof Symbol){if(Symbol.asyncIterator&&null!=(t=n[Symbol.asyncIterator]))return t.call(n);if(Symbol.iterator&&null!=(t=n[Symbol.iterator]))return t.call(n)}throw new TypeError(\\"Object is not async iterable\\")}([1,2]);var e=function(e,o,i){for(var u;;){var f=e();if(r(f)&&(f=f.v),!f)return h;if(f.then){u=0;break}var h=i();if(h&&h.then){if(!r(h)){u=1;break}h=h.s}if(o){var c=o();if(c&&c.then&&!r(c)){u=2;break}}}var a=new n,l=t.bind(null,a,2);return(0===u?f.then(s):1===u?h.then(v):c.then(y)).then(void 0,l),a;function v(n){h=n;do{if(o&&(c=o())&&c.then&&!r(c))return void c.then(y).then(void 0,l);if(!(f=e())||r(f)&&!f.v)return void t(a,1,h);if(f.then)return void f.then(s).then(void 0,l);r(h=i())&&(h=h.v)}while(!h||!h.then);h.then(v).then(void 0,l)}function s(n){n?(h=i())&&h.then?h.then(v).then(void 0,l):v(h):t(a,1,h)}function y(){(f=e())?f.then?f.then(s).then(void 0,l):s(f):t(a,1,h)}}(function(){return!!Promise.resolve(o.next()).then(function(n){return a=i.done,i=n,Promise.resolve(i.value).then(function(n){return u=n,!a})})},function(){return!!(a=!0)},function(){c.push(u)});if(e&&e.then)return e.then(function(){})}()}catch(n){return f(n)}return h&&h.then?h.then(void 0,f):h}(0,function(n){l=!0,f=n})},function(n,t){function r(r){if(h)return r;if(n)throw t;return t}var i=e(function(){var n=function(){if(!a&&null!=o.return)return Promise.resolve(o.return()).then(function(){})}();if(n&&n.then)return n.then(function(){})},function(n,t){if(l)throw f;if(n)throw t;return t});return i&&i.then?i.then(r):r(i)});return Promise.resolve(v&&v.then?v.then(function(n){return h?n:c}):h?v:c)}catch(n){return Promise.reject(n)}};o().then(console.log);export default o; +"var n=function(){function n(){}return n.prototype.then=function(r,e){var o=new n,i=this.s;if(i){var u=1&i?r:e;if(u){try{t(o,1,u(this.v))}catch(n){t(o,2,n)}return o}return this}return this.o=function(n){try{var i=n.v;1&n.s?t(o,1,r?r(i):i):e?t(o,1,e(i)):t(o,2,i)}catch(n){t(o,2,n)}},o},n}();function t(r,e,o){if(!r.s){if(o instanceof n){if(!o.s)return void(o.o=t.bind(null,r,e));1&e&&(e=o.s),o=o.v}if(o&&o.then)return void o.then(t.bind(null,r,e),t.bind(null,r,2));r.s=e,r.v=o;var i=r.o;i&&i(r)}}function r(t){return t instanceof n&&1&t.s}function e(n,t){try{var r=n()}catch(n){return t(!0,n)}return r&&r.then?r.then(t.bind(null,!1),t.bind(null,!0)):t(!1,value)}\\"undefined\\"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol(\\"Symbol.iterator\\"))),\\"undefined\\"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol(\\"Symbol.asyncIterator\\")));var o=function(){try{var o,i,u,f,h=!1,c=[],a=!0,l=!1,v=e(function(){return function(e,f){try{var h=function(){o=function(n){var t;if(\\"undefined\\"!=typeof Symbol){if(Symbol.asyncIterator&&null!=(t=n[Symbol.asyncIterator]))return t.call(n);if(Symbol.iterator&&null!=(t=n[Symbol.iterator]))return t.call(n)}throw new TypeError(\\"Object is not async iterable\\")}([1,2]);var e=function(e,o,i){for(var u;;){var f=e();if(r(f)&&(f=f.v),!f)return h;if(f.then){u=0;break}var h=i();if(h&&h.then){if(!r(h)){u=1;break}h=h.s}if(o){var c=o();if(c&&c.then&&!r(c)){u=2;break}}}var a=new n,l=t.bind(null,a,2);return(0===u?f.then(s):1===u?h.then(v):c.then(y)).then(void 0,l),a;function v(n){h=n;do{if(o&&(c=o())&&c.then&&!r(c))return void c.then(y).then(void 0,l);if(!(f=e())||r(f)&&!f.v)return void t(a,1,h);if(f.then)return void f.then(s).then(void 0,l);r(h=i())&&(h=h.v)}while(!h||!h.then);h.then(v).then(void 0,l)}function s(n){n?(h=i())&&h.then?h.then(v).then(void 0,l):v(h):t(a,1,h)}function y(){(f=e())?f.then?f.then(s).then(void 0,l):s(f):t(a,1,h)}}(function(){return!!Promise.resolve(o.next()).then(function(n){return a=i.done,i=n,Promise.resolve(i.value).then(function(n){return u=n,!a})})},function(){return!!(a=!0)},function(){c.push(u)});if(e&&e.then)return e.then(function(){})}()}catch(n){return f(n)}return h&&h.then?h.then(void 0,f):h}(0,function(n){l=!0,f=n})},function(n,t){function r(r){if(h)return r;if(n)throw t;return t}var i=e(function(){var n=function(){if(!a&&null!=o.return)return Promise.resolve(o.return()).then(function(){})}();if(n&&n.then)return n.then(function(){})},function(n,t){if(l)throw f;if(n)throw t;return t});return i&&i.then?i.then(r):r(i)});return Promise.resolve(v&&v.then?v.then(function(n){return h?n:c}):h?v:c)}catch(n){return Promise.reject(n)}};o().then(console.log);export default o; //# sourceMappingURL=esnext-ts.mjs.map " `; exports[`fixtures build esnext-ts with microbundle 5`] = ` -"!function(n,t){\\"object\\"==typeof exports&&\\"undefined\\"!=typeof module?module.exports=t():\\"function\\"==typeof define&&define.amd?define(t):(n=n||self).esnextTs=t()}(this,function(){var n= -/* */ -function(){function n(){}return n.prototype.then=function(e,r){var o=new n,i=this.s;if(i){var u=1&i?e:r;if(u){try{t(o,1,u(this.v))}catch(n){t(o,2,n)}return o}return this}return this.o=function(n){try{var i=n.v;1&n.s?t(o,1,e?e(i):i):r?t(o,1,r(i)):t(o,2,i)}catch(n){t(o,2,n)}},o},n}();function t(e,r,o){if(!e.s){if(o instanceof n){if(!o.s)return void(o.o=t.bind(null,e,r));1&r&&(r=o.s),o=o.v}if(o&&o.then)return void o.then(t.bind(null,e,r),t.bind(null,e,2));e.s=r,e.v=o;var i=e.o;i&&i(e)}}function e(t){return t instanceof n&&1&t.s}function r(n,t){try{var e=n()}catch(n){return t(!0,n)}return e&&e.then?e.then(t.bind(null,!1),t.bind(null,!0)):t(!1,value)} -/* */ -\\"undefined\\"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol(\\"Symbol.iterator\\"))), -/* */ -\\"undefined\\"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol(\\"Symbol.asyncIterator\\")));var o=function(){try{var o,i,u,f,c=!1,h=[],a=!0,l=!1,v=r(function(){return function(r,f){try{var c=function(){o=function(n){var t;if(\\"undefined\\"!=typeof Symbol){if(Symbol.asyncIterator&&null!=(t=n[Symbol.asyncIterator]))return t.call(n);if(Symbol.iterator&&null!=(t=n[Symbol.iterator]))return t.call(n)}throw new TypeError(\\"Object is not async iterable\\")}([1,2]);var r=function(r,o,i){for(var u;;){var f=r();if(e(f)&&(f=f.v),!f)return c;if(f.then){u=0;break}var c=i();if(c&&c.then){if(!e(c)){u=1;break}c=c.s}if(o){var h=o();if(h&&h.then&&!e(h)){u=2;break}}}var a=new n,l=t.bind(null,a,2);return(0===u?f.then(s):1===u?c.then(v):h.then(d)).then(void 0,l),a;function v(n){c=n;do{if(o&&(h=o())&&h.then&&!e(h))return void h.then(d).then(void 0,l);if(!(f=r())||e(f)&&!f.v)return void t(a,1,c);if(f.then)return void f.then(s).then(void 0,l);e(c=i())&&(c=c.v)}while(!c||!c.then);c.then(v).then(void 0,l)}function s(n){n?(c=i())&&c.then?c.then(v).then(void 0,l):v(c):t(a,1,c)}function d(){(f=r())?f.then?f.then(s).then(void 0,l):s(f):t(a,1,c)}}(function(){return!!Promise.resolve(o.next()).then(function(n){return a=i.done,i=n,Promise.resolve(i.value).then(function(n){return u=n,!a})})},function(){return!!(a=!0)},function(){h.push(u)});if(r&&r.then)return r.then(function(){})}()}catch(n){return f(n)}return c&&c.then?c.then(void 0,f):c}(0,function(n){l=!0,f=n})},function(n,t){function e(e){if(c)return e;if(n)throw t;return t}var i=r(function(){var n=function(){if(!a&&null!=o.return)return Promise.resolve(o.return()).then(function(){})}();if(n&&n.then)return n.then(function(){})},function(n,t){if(l)throw f;if(n)throw t;return t});return i&&i.then?i.then(e):e(i)});return Promise.resolve(v&&v.then?v.then(function(n){return c?n:h}):c?v:h)}catch(n){return Promise.reject(n)}};return o().then(console.log),o}); +"!function(n,t){\\"object\\"==typeof exports&&\\"undefined\\"!=typeof module?module.exports=t():\\"function\\"==typeof define&&define.amd?define(t):(n=n||self).esnextTs=t()}(this,function(){var n=function(){function n(){}return n.prototype.then=function(e,r){var o=new n,i=this.s;if(i){var u=1&i?e:r;if(u){try{t(o,1,u(this.v))}catch(n){t(o,2,n)}return o}return this}return this.o=function(n){try{var i=n.v;1&n.s?t(o,1,e?e(i):i):r?t(o,1,r(i)):t(o,2,i)}catch(n){t(o,2,n)}},o},n}();function t(e,r,o){if(!e.s){if(o instanceof n){if(!o.s)return void(o.o=t.bind(null,e,r));1&r&&(r=o.s),o=o.v}if(o&&o.then)return void o.then(t.bind(null,e,r),t.bind(null,e,2));e.s=r,e.v=o;var i=e.o;i&&i(e)}}function e(t){return t instanceof n&&1&t.s}function r(n,t){try{var e=n()}catch(n){return t(!0,n)}return e&&e.then?e.then(t.bind(null,!1),t.bind(null,!0)):t(!1,value)}\\"undefined\\"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol(\\"Symbol.iterator\\"))),\\"undefined\\"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol(\\"Symbol.asyncIterator\\")));var o=function(){try{var o,i,u,f,c=!1,h=[],a=!0,l=!1,v=r(function(){return function(r,f){try{var c=function(){o=function(n){var t;if(\\"undefined\\"!=typeof Symbol){if(Symbol.asyncIterator&&null!=(t=n[Symbol.asyncIterator]))return t.call(n);if(Symbol.iterator&&null!=(t=n[Symbol.iterator]))return t.call(n)}throw new TypeError(\\"Object is not async iterable\\")}([1,2]);var r=function(r,o,i){for(var u;;){var f=r();if(e(f)&&(f=f.v),!f)return c;if(f.then){u=0;break}var c=i();if(c&&c.then){if(!e(c)){u=1;break}c=c.s}if(o){var h=o();if(h&&h.then&&!e(h)){u=2;break}}}var a=new n,l=t.bind(null,a,2);return(0===u?f.then(s):1===u?c.then(v):h.then(d)).then(void 0,l),a;function v(n){c=n;do{if(o&&(h=o())&&h.then&&!e(h))return void h.then(d).then(void 0,l);if(!(f=r())||e(f)&&!f.v)return void t(a,1,c);if(f.then)return void f.then(s).then(void 0,l);e(c=i())&&(c=c.v)}while(!c||!c.then);c.then(v).then(void 0,l)}function s(n){n?(c=i())&&c.then?c.then(v).then(void 0,l):v(c):t(a,1,c)}function d(){(f=r())?f.then?f.then(s).then(void 0,l):s(f):t(a,1,c)}}(function(){return!!Promise.resolve(o.next()).then(function(n){return a=i.done,i=n,Promise.resolve(i.value).then(function(n){return u=n,!a})})},function(){return!!(a=!0)},function(){h.push(u)});if(r&&r.then)return r.then(function(){})}()}catch(n){return f(n)}return c&&c.then?c.then(void 0,f):c}(0,function(n){l=!0,f=n})},function(n,t){function e(e){if(c)return e;if(n)throw t;return t}var i=r(function(){var n=function(){if(!a&&null!=o.return)return Promise.resolve(o.return()).then(function(){})}();if(n&&n.then)return n.then(function(){})},function(n,t){if(l)throw f;if(n)throw t;return t});return i&&i.then?i.then(e):e(i)});return Promise.resolve(v&&v.then?v.then(function(n){return c?n:h}):c?v:h)}catch(n){return Promise.reject(n)}};return o().then(console.log),o}); //# sourceMappingURL=esnext-ts.umd.js.map " `; @@ -1340,36 +1298,30 @@ jsx Build \\"jsx\\" to dist: -268 B: jsx.js.gz -222 B: jsx.js.br -268 B: jsx.mjs.gz -223 B: jsx.mjs.br -343 B: jsx.umd.js.gz -288 B: jsx.umd.js.br" +262 B: jsx.js.gz +209 B: jsx.js.br +261 B: jsx.mjs.gz +208 B: jsx.mjs.br +335 B: jsx.umd.js.gz +278 B: jsx.umd.js.br" `; exports[`fixtures build jsx with microbundle 2`] = `6`; exports[`fixtures build jsx with microbundle 3`] = ` -"var n=function(n,r){for(var e=arguments.length,t=new Array(e>2?e-2:0),l=2;l2?e-2:0),l=2;l2?e-2:0),l=2;l2?e-2:0),l=2;l2?t-2:0),o=2;o2?t-2:0),o=2;on+r,0)}export default async function(){return[await n(...arguments),await n(...arguments)]} +//# sourceMappingURL=basic-lib.modern.mjs.map +" +`; + exports[`fixtures build name-custom-amd with microbundle 1`] = ` "Used script: microbundle @@ -1781,12 +1761,12 @@ ts-mixed-exports Build \\"tsMixedExports\\" to dist: -119 B: ts-mixed-exports.js.gz +112 B: ts-mixed-exports.js.gz 89 B: ts-mixed-exports.js.br -119 B: ts-mixed-exports.mjs.gz -110 B: ts-mixed-exports.mjs.br -218 B: ts-mixed-exports.umd.js.gz -184 B: ts-mixed-exports.umd.js.br" +113 B: ts-mixed-exports.mjs.gz +98 B: ts-mixed-exports.mjs.br +213 B: ts-mixed-exports.umd.js.gz +171 B: ts-mixed-exports.umd.js.br" `; exports[`fixtures build ts-mixed-exports with microbundle 2`] = `8`; @@ -1810,25 +1790,19 @@ export default Ferrari; `; exports[`fixtures build ts-mixed-exports with microbundle 5`] = ` -"var r= -/* */ -function(){function r(){}return r.prototype.drive=function(r){return!0},r}(),t=new r;exports.Car=r,exports.default=t; +"var r=function(){function r(){}return r.prototype.drive=function(r){return!0},r}(),t=new r;exports.Car=r,exports.default=t; //# sourceMappingURL=ts-mixed-exports.js.map " `; exports[`fixtures build ts-mixed-exports with microbundle 6`] = ` -"var t= -/* */ -function(){function t(){}return t.prototype.drive=function(t){return!0},t}();export default new t;export{t as Car}; +"var t=function(){function t(){}return t.prototype.drive=function(t){return!0},t}();export default new t;export{t as Car}; //# sourceMappingURL=ts-mixed-exports.mjs.map " `; exports[`fixtures build ts-mixed-exports with microbundle 7`] = ` -"!function(e,t){\\"object\\"==typeof exports&&\\"undefined\\"!=typeof module?t(exports):\\"function\\"==typeof define&&define.amd?define([\\"exports\\"],t):t((e=e||self).tsMixedExports={})}(this,function(e){var t= -/* */ -function(){function e(){}return e.prototype.drive=function(e){return!0},e}(),n=new t;e.Car=t,e.default=n}); +"!function(e,t){\\"object\\"==typeof exports&&\\"undefined\\"!=typeof module?t(exports):\\"function\\"==typeof define&&define.amd?define([\\"exports\\"],t):t((e=e||self).tsMixedExports={})}(this,function(e){var t=function(){function e(){}return e.prototype.drive=function(e){return!0},e}(),n=new t;e.Car=t,e.default=n}); //# sourceMappingURL=ts-mixed-exports.umd.js.map " `; diff --git a/test/fixtures/modern/package.json b/test/fixtures/modern/package.json new file mode 100644 index 00000000..36180397 --- /dev/null +++ b/test/fixtures/modern/package.json @@ -0,0 +1,6 @@ +{ + "name": "basic-lib", + "scripts": { + "build": "microbundle -f modern" + } +} diff --git a/test/fixtures/modern/src/index.js b/test/fixtures/modern/src/index.js new file mode 100644 index 00000000..a756a0a4 --- /dev/null +++ b/test/fixtures/modern/src/index.js @@ -0,0 +1,5 @@ +import { two } from './two'; + +export default async function(...args) { + return [await two(...args), await two(...args)]; +} diff --git a/test/fixtures/modern/src/two.js b/test/fixtures/modern/src/two.js new file mode 100644 index 00000000..9f1f741b --- /dev/null +++ b/test/fixtures/modern/src/two.js @@ -0,0 +1,3 @@ +export async function two(...args) { + return args.reduce((total, value) => total + value, 0); +} diff --git a/test/index.test.js b/test/index.test.js index e7ee2697..ad6baabe 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -58,6 +58,7 @@ describe('fixtures', () => { // we don't realy care about the content of a sourcemap files .filter(file => !/\.map$/.test(file)) + .sort(file => (/modern/.test(file) ? 1 : 0)) .forEach(file => { expect( fs.readFileSync(resolve(dist, file)).toString('utf8'), diff --git a/tools/build-fixture.js b/tools/build-fixture.js index 60c522eb..cf4145f0 100644 --- a/tools/build-fixture.js +++ b/tools/build-fixture.js @@ -12,13 +12,18 @@ const FIXTURES_DIR = resolve(`${__dirname}/../test/fixtures`); const DEFAULT_SCRIPT = 'microbundle'; const parseScript = (() => { - let parsed; - const prog = createProg(_parsed => (parsed = _parsed)); - return script => { + let parsed; + const prog = createProg(_parsed => (parsed = _parsed)); const argv = shellQuote.parse(`node ${script}`); + + // default to non-modern formats + let hasFormats = argv.some(arg => /^(--format|-f)$/.test(arg)); + if (!hasFormats) argv.push('-f', 'es,cjs,umd'); + // assuming {op: 'glob', pattern} for non-string args prog(argv.map(arg => (typeof arg === 'string' ? arg : arg.pattern))); + return parsed; }; })();