From 97d49eaa1e4cbb05851803575f196d2ed84bf406 Mon Sep 17 00:00:00 2001 From: "J.T.Sage" Date: Fri, 7 Jun 2019 09:51:18 -0400 Subject: [PATCH] Preliminary polyfill support in the build. Re: #473 --- build/build-datebox.js | 17 +++++++++++++++++ src/js/polyfill/obj.assign.js | 36 +++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 src/js/polyfill/obj.assign.js diff --git a/build/build-datebox.js b/build/build-datebox.js index da643e41..e32b1ad9 100755 --- a/build/build-datebox.js +++ b/build/build-datebox.js @@ -21,11 +21,13 @@ const config = require( "../package.json" ), glob = require( "glob" ), rimraf = require( "rimraf" ), + polyFill = [ "jqm" ], dontBundle = [ "jqm" ]; var frameName, inCode, outCodeFull, outCodeMin, outCodeObj, today = new Date(), externalLibsJS = "", + polyFillLibsJS = "", dbModeLibsJS = "", buildFiles = [], buildMode = ( typeof process.argv[2] !== "undefined" ) ? process.argv[2] : "latest", @@ -35,6 +37,7 @@ var frameName, inCode, outCodeFull, outCodeMin, outCodeObj, baseObjectJS = fs.readFileSync("src/js/baseObject.js"), externalLibs = glob.sync("src/js/external/*.js"), + polyFillLibs = glob.sync("src/js/polyfill/*.js"), frameWorks = glob.sync("src/js/framework/*.js"), modes = glob.sync("src/js/modes/*.js"), internalLibs = glob.sync("src/js/lib/*.js"), @@ -82,6 +85,10 @@ for ( var i = 0, len = externalLibs.length; i < len; i++ ) { externalLibsJS += fs.readFileSync( externalLibs[i] ); } +for ( var j = 0, lan = polyFillLibs.length; j < lan; j++ ) { + polyFillLibsJS += fs.readFileSync( polyFillLibs[j] ); +} + externalLibsJS = UglifyJS.minify( externalLibsJS, { mangle : false, compress : false, @@ -91,6 +98,15 @@ externalLibsJS = UglifyJS.minify( externalLibsJS, { } } ); +polyFillLibsJS = UglifyJS.minify( polyFillLibsJS, { + mangle : false, + compress : false, + output : { + code : true, + beautify : true + } +} ); + for ( i = 0, len = internalLibs.length; i < len; i++ ) { dbModeLibsJS += fs.readFileSync( internalLibs[i] ); } @@ -139,6 +155,7 @@ buildFiles.forEach( function( fileObj ) { preamble.long( fileObj.name ) + "\n\n" + ( ( dontBundle.includes( fileObj.name ) ) ? "" : externalLibsJS.code ) + + ( ( polyFill.includes( fileObj.name ) ) ? polyFillLibsJS.code : "" ) + "\n\n" + outCodeObj.code; diff --git a/src/js/polyfill/obj.assign.js b/src/js/polyfill/obj.assign.js new file mode 100644 index 00000000..066a8fad --- /dev/null +++ b/src/js/polyfill/obj.assign.js @@ -0,0 +1,36 @@ +/*! This contains a polyfill for Object.assign. Currently only used for jQM builds. */ + +/* eslint-disable one-var, no-unused-vars */ + +if ( typeof Object.assign != "function" ) { + // Must be writable: true, enumerable: false, configurable: true + Object.defineProperty( Object, "assign", { + value : function assign( target, varArgs ) { // .length of function is 2 + "use strict"; + if ( target == null ) { // TypeError if undefined or null + throw new TypeError( "Cannot convert undefined or null to object" ); + } + + var to = Object(target); + + for ( var index = 1; index < arguments.length; index++ ) { + var nextSource = arguments[index]; + + if ( nextSource != null ) { // Skip over if undefined or null + for ( var nextKey in nextSource ) { + // Avoid bugs when hasOwnProperty is shadowed + if ( Object.prototype.hasOwnProperty.call( nextSource, nextKey ) ) { + to[nextKey] = nextSource[nextKey]; + } + } + } + } + + return to; + }, + writable : true, + configurable : true + }); +} + +/* eslint-enable one-var, no-unused-vars */ \ No newline at end of file