Skip to content

Commit

Permalink
adjust jsbi depending on which languageOut
Browse files Browse the repository at this point in the history
  • Loading branch information
s-cork committed Sep 20, 2020
1 parent 779e36a commit f7a7fcf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
17 changes: 11 additions & 6 deletions support/polyfills/JSBI.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@
* but use BigInt as the primitive type
*
*/
if (Sk.global.BigInt === undefined) {
Sk.global.JSBI = require("jsbi");
const { default: __JSBI } = require("jsbi");
// use jsbi which is es5 compliant - change to ES6 in the compilation version
var globalThis = Sk.global;

globalThis.JSBI = globalThis.BigInt !== undefined ? Object.create(null) : __JSBI;
const JSBI = globalThis.JSBI;

if (globalThis.BigInt === undefined) {
// __isBigInt is not part of the public api so include it if this is ever removed
Sk.global.JSBI.__isBigInt = Sk.global.JSBI.__isBigInt || ((x) => x instanceof JSBI);
JSBI.__isBigInt = JSBI.__isBigInt || ((x) => x instanceof JSBI);
} else {
Sk.global.JSBI = Object.assign(Object.create(null), {
BigInt: Sk.global.BigInt,
Object.assign(JSBI, {
BigInt: globalThis.BigInt,
toNumber: (x) => Number(x),
toString: (x) => x.toString(),
__isBigInt: (x) => typeof x === "bigint",
Expand All @@ -40,7 +46,6 @@ if (Sk.global.BigInt === undefined) {
notEqual: (x, y) => x != y,
});
}
const JSBI = Sk.global.JSBI;
JSBI.__ZERO = JSBI.BigInt(0);
JSBI.__MAX_SAFE = JSBI.BigInt(Number.MAX_SAFE_INTEGER);
JSBI.__MIN_SAFE = JSBI.BigInt(-Number.MAX_SAFE_INTEGER);
Expand Down
16 changes: 14 additions & 2 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ module.exports = (env, argv) => {
};
var outfile = 'skulpt.js';
var assertfile = './assert-dev.js';
var jsbifile = 'jsbi/dist/jsbi.mjs';
var mod = {};
var languageOut = (env && env.languageOut) || '';

if (argv.mode === 'production') {
opt = {
Expand All @@ -42,14 +44,23 @@ module.exports = (env, argv) => {
'nonStandardJsDocs', 'strictModuleDepCheck', 'undefinedVars',
'unknownDefines', 'visibility'],
jscomp_off: ['fileoverviewTags', 'deprecated', 'uselessCode', 'suspiciousCode', 'checkTypes',],
languageOut: (env && env.languageOut) ? env.languageOut : 'ECMASCRIPT_2015',
languageOut: languageOut || 'ECMASCRIPT_2015',
externs: 'support/externs/sk.js',
rewritePolyfills: true,
// compiler flags here
//
// for debugging help, try these:
//
// warningLevel: "QUIET",
// formatting: 'PRETTY_PRINT',
// debug: true,
// renaming: false
})
]
};
outfile = 'skulpt.min.js';
assertfile = './assert-prod.js';
jsbifile = languageOut === "ECMASCRIPT5" || languageOut === "ECMASCRIPT3" ? "jsbi" : "jsbi/dist/jsbi.mjs";
mod = {
rules: [
{
Expand Down Expand Up @@ -88,7 +99,8 @@ module.exports = (env, argv) => {
optimization: opt,
resolve: {
alias: {
'assert': assertfile
'assert': assertfile,
'jsbi' : jsbifile,
}
},

Expand Down

0 comments on commit f7a7fcf

Please sign in to comment.