Skip to content

Commit

Permalink
Preliminary polyfill support in the build. Re: #473
Browse files Browse the repository at this point in the history
  • Loading branch information
jtsage committed Jun 7, 2019
1 parent a16b159 commit 97d49ea
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
17 changes: 17 additions & 0 deletions build/build-datebox.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"),
Expand Down Expand Up @@ -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,
Expand All @@ -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] );
}
Expand Down Expand Up @@ -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;

Expand Down
36 changes: 36 additions & 0 deletions src/js/polyfill/obj.assign.js
Original file line number Diff line number Diff line change
@@ -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 */

0 comments on commit 97d49ea

Please sign in to comment.