Skip to content

Commit fa84555

Browse files
fix ES5 build to run test suite in nashorn
1 parent bdafec2 commit fa84555

File tree

3 files changed

+62
-2
lines changed

3 files changed

+62
-2
lines changed

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"check-coverage": "istanbul check-coverage -statement 100 -branch 100 -function 100 -line 100",
2020
"browserify": "browserify src/jsonata.js --outfile jsonata.js --standalone jsonata",
2121
"mkdir-dist": "mkdirp ./dist",
22-
"regenerator": "regenerator src dist",
22+
"regenerator": "babel src --out-dir dist --presets=@babel/env",
2323
"browserify-es5": "regenerator --include-runtime polyfill.js > jsonata-es5.js; browserify dist/jsonata.js --standalone jsonata >> jsonata-es5.js",
2424
"prepublishOnly": "npm run browserify && npm run minify && npm run build-es5",
2525
"lint": "eslint src",
@@ -39,6 +39,9 @@
3939
"path"
4040
],
4141
"devDependencies": {
42+
"@babel/cli": "^7.2.0",
43+
"@babel/core": "^7.2.2",
44+
"@babel/preset-env": "^7.2.0",
4245
"browserify": "^16.1.0",
4346
"chai": "^4.1.2",
4447
"chai-as-promised": "^7.1.1",

polyfill.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,55 @@ if (!Array.from) {
9393
}());
9494
}
9595

96+
if (!String.fromCodePoint) (function(stringFromCharCode) {
97+
var fromCodePoint = function(_) {
98+
var codeUnits = [], codeLen = 0, result = "";
99+
for (var index=0, len = arguments.length; index !== len; ++index) {
100+
var codePoint = +arguments[index];
101+
// correctly handles all cases including `NaN`, `-Infinity`, `+Infinity`
102+
// The surrounding `!(...)` is required to correctly handle `NaN` cases
103+
// The (codePoint>>>0) === codePoint clause handles decimals and negatives
104+
if (!(codePoint < 0x10FFFF && (codePoint>>>0) === codePoint))
105+
throw RangeError("Invalid code point: " + codePoint);
106+
if (codePoint <= 0xFFFF) { // BMP code point
107+
codeLen = codeUnits.push(codePoint);
108+
} else { // Astral code point; split in surrogate halves
109+
// https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
110+
codePoint -= 0x10000;
111+
codeLen = codeUnits.push(
112+
(codePoint >> 10) + 0xD800, // highSurrogate
113+
(codePoint % 0x400) + 0xDC00 // lowSurrogate
114+
);
115+
}
116+
if (codeLen >= 0x3fff) {
117+
result += stringFromCharCode.apply(null, codeUnits);
118+
codeUnits.length = 0;
119+
}
120+
}
121+
return result + stringFromCharCode.apply(null, codeUnits);
122+
};
123+
try { // IE 8 only supports `Object.defineProperty` on DOM elements
124+
Object.defineProperty(String, "fromCodePoint", {
125+
"value": fromCodePoint, "configurable": true, "writable": true
126+
});
127+
} catch(e) {
128+
String.fromCodePoint = fromCodePoint;
129+
}
130+
}(String.fromCharCode));
131+
132+
if (!Object.is) {
133+
Object.is = function(x, y) {
134+
// SameValue algorithm
135+
if (x === y) { // Steps 1-5, 7-10
136+
// Steps 6.b-6.e: +0 != -0
137+
return x !== 0 || 1 / x === 1 / y;
138+
} else {
139+
// Step 6.a: NaN == NaN
140+
return x !== x && y !== y;
141+
}
142+
};
143+
}
144+
145+
Math.log10 = Math.log10 || function(x) {
146+
return Math.log(x) * Math.LOG10E;
147+
};

src/utils.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ const utils = (() => {
150150
return arg && arg._jsonata_lambda === true;
151151
}
152152

153+
// istanbul ignore next
154+
var $Symbol = typeof Symbol === "function" ? Symbol : {};
155+
// istanbul ignore next
156+
var iteratorSymbol = $Symbol.iterator || "@@iterator";
157+
153158
/**
154159
* @param {Object} arg - expression to test
155160
* @returns {boolean} - true if it is iterable
@@ -158,7 +163,7 @@ const utils = (() => {
158163
return (
159164
typeof arg === 'object' &&
160165
arg !== null &&
161-
Symbol.iterator in arg &&
166+
iteratorSymbol in arg &&
162167
'next' in arg &&
163168
typeof arg.next === 'function'
164169
);

0 commit comments

Comments
 (0)