Update Rollup and rollup-plugin-terser
Rollup-plugin-terser dropped Node <10 and Rollup <2 support
(https://github.com/TrySound/rollup-plugin-terser/releases/tag/v6.0.0)
and upgraded to Terser 5
(https://github.com/TrySound/rollup-plugin-terser/releases/tag/v7.0.0)
DISABLE_THIRD_PARTY_CHECK=NPM update
R=jacktfranklin@chromium.org
Change-Id: Ifa0085fe5daa052bdfea40720d1852549f4bf316
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2537956
Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
Reviewed-by: Jack Franklin <jacktfranklin@chromium.org>
diff --git a/node_modules/serialize-javascript/README.md b/node_modules/serialize-javascript/README.md
index 810fb57..1339474 100644
--- a/node_modules/serialize-javascript/README.md
+++ b/node_modules/serialize-javascript/README.md
@@ -40,19 +40,20 @@
bool : true,
nil : null,
undef: undefined,
- date: new Date("Thu, 28 Apr 2016 22:02:17 GMT"),
- map: new Map([['hello', 'world']]),
- set: new Set([123, 456]),
-
- fn: function echo(arg) { return arg; },
- re: /([^\s]+)/g
+ inf : Infinity,
+ date : new Date("Thu, 28 Apr 2016 22:02:17 GMT"),
+ map : new Map([['hello', 'world']]),
+ set : new Set([123, 456]),
+ fn : function echo(arg) { return arg; },
+ re : /([^\s]+)/g,
+ big : BigInt(10),
});
```
The above will produce the following string output:
```js
-'{"str":"string","num":0,"obj":{"foo":"foo"},"arr":[1,2,3],"bool":true,"nil":null,"undef":undefined,"date":new Date("2016-04-28T22:02:17.000Z"),"map":new Map([["hello","world"]]),"set":new Set([123,456]),"fn":function echo(arg) { return arg; },"re":/([^\s]+)/g}'
+'{"str":"string","num":0,"obj":{"foo":"foo"},"arr":[1,2,3],"bool":true,"nil":null,"undef":undefined,"inf":Infinity,"date":new Date("2016-04-28T22:02:17.000Z"),"map":new Map([["hello","world"]]),"set":new Set([123,456]),"fn":function echo(arg) { return arg; },"re":new RegExp("([^\\\\s]+)", "g"),"big":BigInt("10")}'
```
Note: to produced a beautified string, you can pass an optional second argument to `serialize()` to define the number of spaces to be used for the indentation.
diff --git a/node_modules/serialize-javascript/index.js b/node_modules/serialize-javascript/index.js
index 3594167..cf14df4 100644
--- a/node_modules/serialize-javascript/index.js
+++ b/node_modules/serialize-javascript/index.js
@@ -6,9 +6,12 @@
'use strict';
+var randomBytes = require('randombytes');
+
// Generate an internal UID to make the regexp pattern harder to guess.
-var UID = Math.floor(Math.random() * 0x10000000000).toString(16);
-var PLACE_HOLDER_REGEXP = new RegExp('"@__(F|R|D|M|S|U)-' + UID + '-(\\d+)__@"', 'g');
+var UID_LENGTH = 16;
+var UID = generateUID();
+var PLACE_HOLDER_REGEXP = new RegExp('(\\\\)?"@__(F|R|D|M|S|U|I|B)-' + UID + '-(\\d+)__@"', 'g');
var IS_NATIVE_CODE_REGEXP = /\{\s*\[native code\]\s*\}/g;
var IS_PURE_FUNCTION = /function.*?\(/;
@@ -31,6 +34,15 @@
return ESCAPED_CHARS[unsafeChar];
}
+function generateUID() {
+ var bytes = randomBytes(UID_LENGTH);
+ var result = '';
+ for(var i=0; i<UID_LENGTH; ++i) {
+ result += bytes[i].toString(16);
+ }
+ return result;
+}
+
function deleteFunctions(obj){
var functionKeys = [];
for (var key in obj) {
@@ -57,6 +69,8 @@
var maps = [];
var sets = [];
var undefs = [];
+ var infinities= [];
+ var bigInts = [];
// Returns placeholders for functions and regexps (identified by index)
// which are later replaced by their string representation.
@@ -102,6 +116,14 @@
return '@__U-' + UID + '-' + (undefs.push(origValue) - 1) + '__@';
}
+ if (type === 'number' && !isNaN(origValue) && !isFinite(origValue)) {
+ return '@__I-' + UID + '-' + (infinities.push(origValue) - 1) + '__@';
+ }
+
+ if (type === 'bigint') {
+ return '@__B-' + UID + '-' + (bigInts.push(origValue) - 1) + '__@';
+ }
+
return value;
}
@@ -175,14 +197,21 @@
str = str.replace(UNSAFE_CHARS_REGEXP, escapeUnsafeChars);
}
- if (functions.length === 0 && regexps.length === 0 && dates.length === 0 && maps.length === 0 && sets.length === 0 && undefs.length === 0) {
+ if (functions.length === 0 && regexps.length === 0 && dates.length === 0 && maps.length === 0 && sets.length === 0 && undefs.length === 0 && infinities.length === 0 && bigInts.length === 0) {
return str;
}
// Replaces all occurrences of function, regexp, date, map and set placeholders in the
// JSON string with their string representations. If the original value can
// not be found, then `undefined` is used.
- return str.replace(PLACE_HOLDER_REGEXP, function (match, type, valueIndex) {
+ return str.replace(PLACE_HOLDER_REGEXP, function (match, backSlash, type, valueIndex) {
+ // The placeholder may not be preceded by a backslash. This is to prevent
+ // replacing things like `"a\"@__R-<UID>-0__@"` and thus outputting
+ // invalid JS.
+ if (backSlash) {
+ return match;
+ }
+
if (type === 'D') {
return "new Date(\"" + dates[valueIndex].toISOString() + "\")";
}
@@ -203,6 +232,14 @@
return 'undefined'
}
+ if (type === 'I') {
+ return infinities[valueIndex];
+ }
+
+ if (type === 'B') {
+ return "BigInt(\"" + bigInts[valueIndex] + "\")";
+ }
+
var fn = functions[valueIndex];
return serializeFunc(fn);
diff --git a/node_modules/serialize-javascript/package.json b/node_modules/serialize-javascript/package.json
index ff9959f..4e002d2 100644
--- a/node_modules/serialize-javascript/package.json
+++ b/node_modules/serialize-javascript/package.json
@@ -3,12 +3,15 @@
"bugs": {
"url": "https://github.com/yahoo/serialize-javascript/issues"
},
+ "dependencies": {
+ "randombytes": "^2.1.0"
+ },
"description": "Serialize JavaScript to a superset of JSON that includes regular expressions and functions.",
"devDependencies": {
"benchmark": "^2.1.4",
"chai": "^4.1.0",
- "mocha": "^6.2.0",
- "nyc": "^14.1.1"
+ "mocha": "^7.0.0",
+ "nyc": "^15.0.0"
},
"homepage": "https://github.com/yahoo/serialize-javascript",
"keywords": [
@@ -29,5 +32,5 @@
"benchmark": "node -v && node test/benchmark/serialize.js",
"test": "nyc --reporter=lcov mocha test/unit"
},
- "version": "2.1.2"
+ "version": "4.0.0"
}