Skip to content

Commit

Permalink
Allow 'console.warn()' in the minified js
Browse files Browse the repository at this point in the history
  • Loading branch information
jherax committed Dec 12, 2016
1 parent 8f057e7 commit c234ead
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 12 deletions.
33 changes: 26 additions & 7 deletions dist/proxy-storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,24 @@ return /******/ (function(modules) { // webpackBootstrap
}, value);
}

/**
* @private
*
* Try to parse a value
*
* @param {string} value: the value to parse
* @return {any}
*/
function tryParse(value) {
var parsed = void 0;
try {
parsed = JSON.parse(value);
} catch (e) {
parsed = value;
}
return parsed;
}

/**
* @private
*
Expand All @@ -262,12 +280,7 @@ return /******/ (function(modules) { // webpackBootstrap
*/
function copyKeys(instance, storage) {
Object.keys(storage).forEach(function (key) {
var value = storage[key];
try {
instance[key] = JSON.parse(value);
} catch (e) {
instance[key] = value;
}
instance[key] = tryParse(storage[key]);
});
}

Expand Down Expand Up @@ -377,7 +390,13 @@ return /******/ (function(modules) { // webpackBootstrap
value: function getItem(key) {
(0, _utils.checkEmpty)(key);
var value = _proxyMechanism.proxy[this.__storage__].getItem(key);
if (value === undefined) value = null;else value = JSON.parse(value);
if (value === undefined) {
delete this[key];
value = null;
} else {
value = tryParse(value);
this[key] = value;
}
var v = executeInterceptors('getItem', key, value);
if (v !== undefined) value = v;
return value;
Expand Down
2 changes: 1 addition & 1 deletion dist/proxy-storage.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/proxy-storage.min.js.map

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions src/web-storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,10 @@ class WebStorage {
getItem(key) {
checkEmpty(key);
let value = proxy[this.__storage__].getItem(key);
if (value === undefined) value = null;
else {
if (value === undefined) {
delete this[key];
value = null;
} else {
value = tryParse(value);
this[key] = value;
}
Expand Down
2 changes: 1 addition & 1 deletion webpack.uglify.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const config = {
compress: {
dead_code: true,
drop_debugger: true,
drop_console: true,
drop_console: false,
},
mangle: {
except: ['WebStorage'],
Expand Down

0 comments on commit c234ead

Please sign in to comment.