Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 96 additions & 29 deletions packages/build/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,47 +101,112 @@ gulp.task('depcheck', function() {
* There doesn't seem to be documentation on what helpers are available, or
* which helpers are required for which transforms. The
* source is here:
* https://github.com/babel/babel/blob/6.x/packages/babel-helpers/src/helpers.js
* https://github.com/babel/babel/tree/master/packages/babel-helpers
*
* This list is an educated guess at the helpers needed for our transform set
* of ES2015 - modules. When we switch to loose mode we should update the list.
* You can usually tell what the helpers are used for by searching the babel
* source to find out which plugin packages make an `addHelper` call for it.
*
* All helpers are listed here, with some commented out, so it's clear what
* we've excluded.
*/
const babelHelperWhitelist = [
'typeof', // Symbol support, for IE11
// 'jsx', // we don't support JSX
// 'asyncIterator', // async-iterators are not in ES2015
// 'asyncGenerator', // async-iterators are not in ES2015
// 'asyncGeneratorDelegate', // async-iterators are not in ES2015
// 'asyncToGenerator', // async functions are not in ES2015

// __proto__ assignment
'defaults',
'extends',

// es2015 classes
'assertThisInitialized',
'classCallCheck',
'construct',
'createClass',
'get',
'getPrototypeOf',
'inherits',
//'inheritsLoose',
'possibleConstructorReturn',
'set',
'setPrototypeOf',
'superPropBase',
'wrapNativeSuper',

// es2015 array-spread
'slicedToArray',
//'slicedToArrayLoose',
'toArray',
'toConsumableArray',
'arrayWithoutHoles',
'arrayWithHoles',
'iterableToArray',
'iterableToArrayLimit',
//'iterableToArrayLimitLoose',
'nonIterableSpread',
'nonIterableRest',

// es2015 instanceof
'instanceof',

// es2015 arrow-functions
'newArrowCheck',

// es2015 typeof-symbol
'typeof',

// es2015 computed-properties
'defineEnumerableProperties',
'defaults', // used to make `obj.__proto__ = bar` work
'defineProperty',
'extends', // used when setting __proto__
'get', // needed for class compilation
'inherits', // used for es6 class inheritance
'instanceof',
// 'interopRequireDefault', // for modules support
// 'interopRequireWildcard', // for modules support
'newArrowCheck', // confirms that `this` is correct inside arrow function
// body

// es2015 block-scoping
'readOnlyError',
'temporalRef',
'temporalUndefined',

// es2015 destructuring
'objectDestructuringEmpty',
'objectWithoutProperties',
'possibleConstructorReturn', // can we exclude with loose?
// 'selfGlobal', // not needed. `global` is not ES2015
'set', // difficult to tell if needed
'slicedToArray',
// 'slicedToArrayLoose',

// es2015 template-literals
'taggedTemplateLiteral',
// 'taggedTemplateLiteralLoose',
'temporalRef', // not needed in loose?
'temporalUndefined',
'toArray',
'toConsumableArray',
//'taggedTemplateLiteralLoose',

// es2017 async-to-generator
'asyncToGenerator',

// es2018 proposal-async-generator-functions
'AsyncGenerator',
'AwaitValue',
'asyncGeneratorDelegate',
'asyncIterator',
'awaitAsyncGenerator',
'wrapAsyncGenerator',

// es2018 proposal-object-rest-spread
'objectSpread',
'toPropertyKey',

// proposal-function-sent
//'skipFirstGeneratorNext',

// proposal-class-properties
//'classNameTDZError',

// proposal-decorators
//'applyDecoratedDescriptor',
//'initializerDefineProperty',
//'initializerWarningHelper',

// react-inline-elements
//'jsx',
];

/**
* Babel helpers needed only for ES module transformation. We bundle these with
* the require.js AMD module loader instead so that the AMD transform does not
* depend on loading all Babel helpers.
*/
const moduleHelpers = [
'interopRequireDefault',
'interopRequireWildcard',
];

gulp.task('gen-babel-helpers', () => {
Expand All @@ -156,8 +221,10 @@ gulp.task('minify-requirejs', () => {
const requireJsPath =
path.join(path.dirname(require.resolve('requirejs')), '..', 'require.js');
const requireJsCode = fs.readFileSync(requireJsPath, 'utf-8');
const moduleBabelHelpers = babelCore.buildExternalHelpers(moduleHelpers);
const combined = requireJsCode + moduleBabelHelpers;
const minified =
babelCore.transform(requireJsCode, {presets: [babelPresetMinify]}).code;
babelCore.transform(combined, {presets: [babelPresetMinify]}).code;
fs.mkdirpSync('./lib/');
fs.writeFileSync('./lib/requirejs.min.js', minified, {encoding: 'utf-8'});
});

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
<html><head></head><body><div hidden="" by-polymer-bundler=""><script>(function(a){function b(a){return j.typeof="function"===typeof Symbol&&"symbol"===typeof Symbol.iterator?b=function(a){return typeof a}:b=function(a){return a&&"function"===typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},b(a)}function c(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}function d(a,b){for(var c in b){var d=b[c];d.configurable=d.enumerable=!0,"value"in d&&(d.writable=!0),Object.defineProperty(a,c,d)}if(Object.getOwnPropertySymbols)for(var e=Object.getOwnPropertySymbols(b),f=0;f<e.length;f++){var g=e[f],d=b[g];d.configurable=d.enumerable=!0,"value"in d&&(d.writable=!0),Object.defineProperty(a,g,d)}return a}function e(a,b,c){return b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function f(){return j.extends=f=Object.assign||function(a){for(var b,c=1;c<arguments.length;c++)for(var d in b=arguments[c],b)Object.prototype.hasOwnProperty.call(b,d)&&(a[d]=b[d]);return a},f.apply(this,arguments)}function g(a,b,c){null===a&&(a=Function.prototype);var d=Object.getOwnPropertyDescriptor(a,b);if(d===void 0){var e=Object.getPrototypeOf(a);return null===e?void 0:g(e,b,c)}if("value"in d)return d.value;var f=d.get;return void 0===f?void 0:f.call(c)}function h(a,b,c,d){var e=Object.getOwnPropertyDescriptor(a,b);if(e===void 0){var f=Object.getPrototypeOf(a);null!==f&&h(f,b,c,d)}else if("value"in e&&e.writable)e.value=c;else{var g=e.set;g!==void 0&&g.call(d,c)}return c}var j=a.babelHelpers={};j.typeof=b,j.classCallCheck=function(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")},j.createClass=function(a,b,d){return b&&c(a.prototype,b),d&&c(a,d),a},j.defineEnumerableProperties=d,j.defaults=function(a,b){for(var c=Object.getOwnPropertyNames(b),d=0;d<c.length;d++){var e=c[d],f=Object.getOwnPropertyDescriptor(b,e);f&&f.configurable&&a[e]===void 0&&Object.defineProperty(a,e,f)}return a},j.defineProperty=e,j.extends=f,j.get=g,j.inherits=function(a,b){if("function"!==typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function");a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}}),b&&(Object.setPrototypeOf?Object.setPrototypeOf(a,b):a.__proto__=b)},j.instanceof=function(a,b){return null!=b&&"undefined"!==typeof Symbol&&b[Symbol.hasInstance]?b[Symbol.hasInstance](a):a instanceof b},j.newArrowCheck=function(a,b){if(a!==b)throw new TypeError("Cannot instantiate an arrow function")},j.objectDestructuringEmpty=function(a){if(null==a)throw new TypeError("Cannot destructure undefined")},j.objectWithoutProperties=function(a,b){if(null==a)return{};var c,d,e={},f=Object.keys(a);for(d=0;d<f.length;d++)c=f[d],0<=b.indexOf(c)||(e[c]=a[c]);if(Object.getOwnPropertySymbols){var g=Object.getOwnPropertySymbols(a);for(d=0;d<g.length;d++)c=g[d],!(0<=b.indexOf(c))&&Object.prototype.propertyIsEnumerable.call(a,c)&&(e[c]=a[c])}return e},j.possibleConstructorReturn=function(a,b){return b&&("object"===typeof b||"function"===typeof b)?b:j.assertThisInitialized(a)},j.set=h,j.taggedTemplateLiteral=function(a,b){return b||(b=a.slice(0)),Object.freeze(Object.defineProperties(a,{raw:{value:Object.freeze(b)}}))},j.temporalRef=function(a,b){if(a===j.temporalUndefined)throw new ReferenceError(b+" is not defined - temporal dead zone");else return a},j.temporalUndefined={},j.slicedToArray=function(a,b){return j.arrayWithHoles(a)||j.iterableToArrayLimit(a,b)||j.nonIterableRest()},j.toArray=function(a){return j.arrayWithHoles(a)||j.iterableToArray(a)||j.nonIterableRest()},j.toConsumableArray=function(a){return j.arrayWithoutHoles(a)||j.iterableToArray(a)||j.nonIterableSpread()}})("undefined"===typeof global?self:global);</script><script>var Foo=function(a){function b(){return babelHelpers.classCallCheck(this,b),babelHelpers.possibleConstructorReturn(this,(b.__proto__||Object.getPrototypeOf(b)).apply(this,arguments))}return babelHelpers.inherits(b,a),b}(babelHelpers.wrapNativeSuper(HTMLElement));</script><script>function foo(){alert("foo")}</script><script>function bar(){alert("bar")}</script><template>I'm foo.html!</template></div><div>hello world</div><script>(function(){alert("index IIFE")})();</script></body></html>
<html><head></head><body><div hidden="" by-polymer-bundler=""><script>(function(a){function b(a){return p.typeof="function"===typeof Symbol&&"symbol"===typeof Symbol.iterator?b=function(a){return typeof a}:b=function(a){return a&&"function"===typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},b(a)}function c(a){function b(d,e){try{var f=a[d](e),g=f.value,h=g instanceof p.AwaitValue;Promise.resolve(h?g.wrapped:g).then(function(a){return h?void b("next",a):void c(f.done?"return":"normal",a)},function(a){b("throw",a)})}catch(a){c("throw",a)}}function c(a,c){switch(a){case"return":d.resolve({value:c,done:!0});break;case"throw":d.reject(c);break;default:d.resolve({value:c,done:!1});}d=d.next,d?b(d.key,d.arg):e=null}var d,e;this._invoke=function(a,c){return new Promise(function(f,g){var h={key:a,arg:c,resolve:f,reject:g,next:null};e?e=e.next=h:(d=e=h,b(a,c))})},"function"!==typeof a.return&&(this.return=void 0)}function d(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}function e(a,b){for(var c in b){var d=b[c];d.configurable=d.enumerable=!0,"value"in d&&(d.writable=!0),Object.defineProperty(a,c,d)}if(Object.getOwnPropertySymbols)for(var e=Object.getOwnPropertySymbols(b),f=0;f<e.length;f++){var g=e[f],d=b[g];d.configurable=d.enumerable=!0,"value"in d&&(d.writable=!0),Object.defineProperty(a,g,d)}return a}function f(a,b,c){return b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function g(){return p.extends=g=Object.assign||function(a){for(var b,c=1;c<arguments.length;c++)for(var d in b=arguments[c],b)Object.prototype.hasOwnProperty.call(b,d)&&(a[d]=b[d]);return a},g.apply(this,arguments)}function h(a,b,c){null===a&&(a=Function.prototype);var d=Object.getOwnPropertyDescriptor(a,b);if(d===void 0){var e=Object.getPrototypeOf(a);return null===e?void 0:h(e,b,c)}if("value"in d)return d.value;var f=d.get;return void 0===f?void 0:f.call(c)}function i(a){return i=Object.getPrototypeOf||function(a){return a.__proto__},i(a)}function j(a,b){return j=Object.setPrototypeOf||function(a,b){return a.__proto__=b,a},j(a,b)}function k(a,b,c){return k="object"===typeof Reflect&&Reflect.construct||function(b,c,d){var e,f=[null];return f.push.apply(f,c),e=b.bind.apply(b,f),j(new e,d.prototype)},k(a,b,c)}function l(a){var b="function"===typeof Map?new Map:void 0;return p.wrapNativeSuper=l=function(a){function c(){}if("function"!==typeof a)throw new TypeError("Super expression must either be null or a function");if("undefined"!==typeof b){if(b.has(a))return b.get(a);b.set(a,c)}return c.prototype=Object.create(a.prototype,{constructor:{value:c,enumerable:!1,writable:!0,configurable:!0}}),j(c,j(function(){return k(a,arguments,i(this).constructor)},a))},l(a)}function m(a,b,c,d){var e=Object.getOwnPropertyDescriptor(a,b);if(e===void 0){var f=Object.getPrototypeOf(a);null!==f&&m(f,b,c,d)}else if("value"in e&&e.writable)e.value=c;else{var g=e.set;g!==void 0&&g.call(d,c)}return c}function n(a){if(Array.isArray(a)){for(var b=0,c=Array(a.length);b<a.length;b++)c[b]=a[b];return c}}function n(a){if(Array.isArray(a))return a}function o(a){if(Symbol.iterator in Object(a)||"[object Arguments]"===Object.prototype.toString.call(a))return Array.from(a)}var p=a.babelHelpers={};p.typeof=b,p.asyncIterator=function(a){if("function"===typeof Symbol){if(Symbol.asyncIterator){var b=a[Symbol.asyncIterator];if(null!=b)return b.call(a)}if(Symbol.iterator)return a[Symbol.iterator]()}throw new TypeError("Object is not async iterable")},p.AwaitValue=function(a){this.wrapped=a},"function"===typeof Symbol&&Symbol.asyncIterator&&(c.prototype[Symbol.asyncIterator]=function(){return this}),c.prototype.next=function(a){return this._invoke("next",a)},c.prototype.throw=function(a){return this._invoke("throw",a)},c.prototype.return=function(a){return this._invoke("return",a)},p.AsyncGenerator=c,p.wrapAsyncGenerator=function(a){return function(){return new p.AsyncGenerator(a.apply(this,arguments))}},p.awaitAsyncGenerator=function(a){return new p.AwaitValue(a)},p.asyncGeneratorDelegate=function(a,b){function c(c,d){return e=!0,d=new Promise(function(b){b(a[c](d))}),{done:!1,value:b(d)}}var d={},e=!1;return"function"===typeof Symbol&&Symbol.iterator&&(d[Symbol.iterator]=function(){return this}),d.next=function(a){return e?(e=!1,a):c("next",a)},"function"===typeof a.throw&&(d.throw=function(a){if(e)throw e=!1,a;return c("throw",a)}),"function"===typeof a.return&&(d.return=function(a){return c("return",a)}),d},p.asyncToGenerator=function(a){return function(){var b=this,c=arguments;return new Promise(function(d,e){function f(a,b){try{var c=i[a](b),f=c.value}catch(a){return void e(a)}c.done?d(f):Promise.resolve(f).then(g,h)}function g(a){f("next",a)}function h(a){f("throw",a)}var i=a.apply(b,c);g()})}},p.classCallCheck=function(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")},p.createClass=function(a,b,c){return b&&d(a.prototype,b),c&&d(a,c),a},p.defineEnumerableProperties=e,p.defaults=function(a,b){for(var c=Object.getOwnPropertyNames(b),d=0;d<c.length;d++){var e=c[d],f=Object.getOwnPropertyDescriptor(b,e);f&&f.configurable&&a[e]===void 0&&Object.defineProperty(a,e,f)}return a},p.defineProperty=f,p.extends=g,p.objectSpread=function(a){for(var b=1;b<arguments.length;b++){var c=null==arguments[b]?{}:arguments[b],d=Object.keys(c);"function"===typeof Object.getOwnPropertySymbols&&(d=d.concat(Object.getOwnPropertySymbols(c).filter(function(a){return Object.getOwnPropertyDescriptor(c,a).enumerable}))),d.forEach(function(b){p.defineProperty(a,b,c[b])})}return a},p.get=h,p.inherits=function(a,b){if("function"!==typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function");a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}}),b&&(Object.setPrototypeOf?Object.setPrototypeOf(a,b):a.__proto__=b)},p.wrapNativeSuper=l,p.instanceof=function(a,b){return null!=b&&"undefined"!==typeof Symbol&&b[Symbol.hasInstance]?b[Symbol.hasInstance](a):a instanceof b},p.newArrowCheck=function(a,b){if(a!==b)throw new TypeError("Cannot instantiate an arrow function")},p.objectDestructuringEmpty=function(a){if(null==a)throw new TypeError("Cannot destructure undefined")},p.objectWithoutProperties=function(a,b){if(null==a)return{};var c,d,e={},f=Object.keys(a);for(d=0;d<f.length;d++)c=f[d],0<=b.indexOf(c)||(e[c]=a[c]);if(Object.getOwnPropertySymbols){var g=Object.getOwnPropertySymbols(a);for(d=0;d<g.length;d++)c=g[d],!(0<=b.indexOf(c))&&Object.prototype.propertyIsEnumerable.call(a,c)&&(e[c]=a[c])}return e},p.assertThisInitialized=function(a){if(void 0===a)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return a},p.possibleConstructorReturn=function(a,b){return b&&("object"===typeof b||"function"===typeof b)?b:p.assertThisInitialized(a)},p.set=m,p.taggedTemplateLiteral=function(a,b){return b||(b=a.slice(0)),Object.freeze(Object.defineProperties(a,{raw:{value:Object.freeze(b)}}))},p.temporalRef=function(a,b){if(a===p.temporalUndefined)throw new ReferenceError(b+" is not defined - temporal dead zone");else return a},p.readOnlyError=function(a){throw new Error("\""+a+"\" is read-only")},p.temporalUndefined={},p.slicedToArray=function(a,b){return p.arrayWithHoles(a)||p.iterableToArrayLimit(a,b)||p.nonIterableRest()},p.toArray=function(a){return p.arrayWithHoles(a)||p.iterableToArray(a)||p.nonIterableRest()},p.toConsumableArray=function(a){return p.arrayWithoutHoles(a)||p.iterableToArray(a)||p.nonIterableSpread()},p.arrayWithoutHoles=n,p.arrayWithHoles=n,p.iterableToArray=o,p.iterableToArrayLimit=function(a,b){var c=[],d=!0,e=!1,f=void 0;try{for(var g,h=a[Symbol.iterator]();!(d=(g=h.next()).done)&&(c.push(g.value),!(b&&c.length===b));d=!0);}catch(a){e=!0,f=a}finally{try{d||null==h["return"]||h["return"]()}finally{if(e)throw f}}return c},p.nonIterableSpread=function(){throw new TypeError("Invalid attempt to spread non-iterable instance")},p.nonIterableRest=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")},p.toPropertyKey=function(a){return"symbol"===typeof a?a:a+""}})("undefined"===typeof global?self:global);</script><script>var Foo=function(a){function b(){return babelHelpers.classCallCheck(this,b),babelHelpers.possibleConstructorReturn(this,(b.__proto__||Object.getPrototypeOf(b)).apply(this,arguments))}return babelHelpers.inherits(b,a),b}(babelHelpers.wrapNativeSuper(HTMLElement));</script><script>function foo(){alert("foo")}</script><script>function bar(){alert("bar")}</script><template>I'm foo.html!</template></div><div>hello world</div><script>(function(){alert("index IIFE")})();</script></body></html>
Loading