rollup-pluginutils
Advanced tools
Comparing version 2.8.0 to 2.8.1
# rollup-pluginutils changelog | ||
## 2.8.1 | ||
*2019-06-04* | ||
* Support serialization of many edge cases ([#64](https://github.com/rollup/rollup-pluginutils/issues/64)) | ||
## 2.8.0 | ||
@@ -4,0 +8,0 @@ *2019-05-30* |
{ | ||
"name": "rollup-pluginutils", | ||
"description": "Functionality commonly needed by Rollup plugins", | ||
"version": "2.8.0", | ||
"version": "2.8.1", | ||
"main": "dist/pluginutils.cjs.js", | ||
@@ -18,3 +18,3 @@ "module": "dist/pluginutils.es.js", | ||
"@types/micromatch": "^3.1.0", | ||
"@types/node": "^12.0.3", | ||
"@types/node": "^12.0.4", | ||
"husky": "^2.3.0", | ||
@@ -25,9 +25,9 @@ "jest": "^24.8.0", | ||
"prettier": "^1.17.1", | ||
"rollup": "^1.12.4", | ||
"rollup": "^1.13.1", | ||
"rollup-plugin-commonjs": "^10.0.0", | ||
"rollup-plugin-node-resolve": "^5.0.0", | ||
"rollup-plugin-node-resolve": "^5.0.1", | ||
"rollup-plugin-typescript": "^1.0.1", | ||
"shx": "^0.3.2", | ||
"ts-jest": "^24.0.2", | ||
"tslint": "^5.16.0", | ||
"tslint": "^5.17.0", | ||
"typescript": "^3.5.1", | ||
@@ -34,0 +34,0 @@ "typescript-eslint-parser": "^22.0.0" |
@@ -6,2 +6,6 @@ import makeLegalIdentifier from './makeLegalIdentifier'; | ||
function stringify(obj: any): string { | ||
return (JSON.stringify(obj) || 'undefined').replace(/[\u2028\u2029]/g, char => `\\u${('000' + char.charCodeAt(0).toString(16)).slice(-4)}`); | ||
} | ||
function serializeArray<T>(arr: Array<T>, indent: Indent, baseIndent: string): string { | ||
@@ -23,3 +27,3 @@ let output = '['; | ||
const key = keys[i]; | ||
const stringKey = makeLegalIdentifier(key) === key ? key : JSON.stringify(key); | ||
const stringKey = makeLegalIdentifier(key) === key ? key : stringify(key); | ||
output += `${i > 0 ? ',' : ''}${separator}${stringKey}:${indent ? ' ' : ''}${serialize( | ||
@@ -36,9 +40,11 @@ obj[key], | ||
if (obj === Infinity) return 'Infinity'; | ||
if (obj === -Infinity) return '-Infinity'; | ||
if (obj === 0 && 1/obj === -Infinity) return '-0'; | ||
if (obj instanceof Date) return 'new Date(' + obj.getTime() + ')'; | ||
if (obj instanceof RegExp) return obj.toString(); | ||
if (typeof obj === 'number' && isNaN(obj)) return 'NaN'; | ||
if (obj !== obj) return 'NaN'; | ||
if (Array.isArray(obj)) return serializeArray(obj, indent, baseIndent); | ||
if (obj === null) return 'null'; | ||
if (typeof obj === 'object') return serializeObject(obj, indent, baseIndent); | ||
return JSON.stringify(obj); | ||
return stringify(obj); | ||
} | ||
@@ -56,5 +62,10 @@ | ||
Array.isArray(data) || | ||
data instanceof Date || | ||
data instanceof RegExp || | ||
data === null | ||
) | ||
return `export default${_}${serialize(data, options.compact ? null : t, '')};`; | ||
) { | ||
const code = serialize(data, options.compact ? null : t, ''); | ||
const __ = _ || (/^[{[\-\/]/.test(code) ? '' : ' '); | ||
return `export default${__}${code};`; | ||
} | ||
@@ -76,3 +87,3 @@ let namedExportCode = ''; | ||
defaultExportRows.push( | ||
`${JSON.stringify(key)}: ${serialize(data[key], options.compact ? null : t, '')}` | ||
`${stringify(key)}:${_}${serialize(data[key], options.compact ? null : t, '')}` | ||
); | ||
@@ -79,0 +90,0 @@ } |
@@ -18,5 +18,5 @@ import { MakeLegalIdentifier } from './pluginutils'; | ||
return str; | ||
return str || '_'; | ||
}; | ||
export { makeLegalIdentifier as default }; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
245983
6890
0