Skip to content

Commit

Permalink
Remove incorrect __esModule insertion,
Browse files Browse the repository at this point in the history
  • Loading branch information
tomalec committed Aug 7, 2019
1 parent e448c0c commit 04671e5
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 92 deletions.
6 changes: 3 additions & 3 deletions dist/fast-json-patch.js
Expand Up @@ -108,7 +108,7 @@ var __extends = (this && this.__extends) || (function () {
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var _hasOwnProperty = Object.prototype.hasOwnProperty;
function hasOwnProperty(obj, key) {
return _hasOwnProperty.call(obj, key);
Expand Down Expand Up @@ -277,7 +277,7 @@ exports.PatchError = PatchError;
/* 1 */
/***/ (function(module, exports, __webpack_require__) {

Object.defineProperty(exports, "__esModule", { value: true });
var helpers_js_1 = __webpack_require__(0);
exports.JsonPatchError = helpers_js_1.PatchError;
exports.deepClone = helpers_js_1._deepClone;
Expand Down Expand Up @@ -717,7 +717,7 @@ exports._areEquals = _areEquals;
/* 2 */
/***/ (function(module, exports, __webpack_require__) {

Object.defineProperty(exports, "__esModule", { value: true });
/*!
* https://github.com/Starcounter-Jack/JSON-Patch
* (c) 2017 Joachim Wester
Expand Down
2 changes: 1 addition & 1 deletion dist/fast-json-patch.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/core.js
@@ -1,4 +1,4 @@
Object.defineProperty(exports, "__esModule", { value: true });
var helpers_js_1 = require("./helpers.js");
exports.JsonPatchError = helpers_js_1.PatchError;
exports.deepClone = helpers_js_1._deepClone;
Expand Down
2 changes: 1 addition & 1 deletion lib/duplex.js
@@ -1,4 +1,4 @@
Object.defineProperty(exports, "__esModule", { value: true });
/*!
* https://github.com/Starcounter-Jack/JSON-Patch
* (c) 2017 Joachim Wester
Expand Down
2 changes: 1 addition & 1 deletion lib/helpers.js
Expand Up @@ -16,7 +16,7 @@ var __extends = (this && this.__extends) || (function () {
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var _hasOwnProperty = Object.prototype.hasOwnProperty;
function hasOwnProperty(obj, key) {
return _hasOwnProperty.call(obj, key);
Expand Down
58 changes: 26 additions & 32 deletions module/core.mjs
@@ -1,42 +1,42 @@
import { PatchError, _deepClone, isInteger, unescapePathComponent, hasUndefined } from './helpers.mjs';
export var JsonPatchError = PatchError;
export var deepClone = _deepClone;
export const JsonPatchError = PatchError;
export const deepClone = _deepClone;
/* We use a Javascript hash to store each
function. Each hash entry (property) uses
the operation identifiers specified in rfc6902.
In this way, we can map each patch operation
to its dedicated function in efficient way.
*/
/* The operations applicable to an object */
var objOps = {
const objOps = {
add: function (obj, key, document) {
obj[key] = this.value;
return { newDocument: document };
},
remove: function (obj, key, document) {
var removed = obj[key];
delete obj[key];
return { newDocument: document, removed: removed };
return { newDocument: document, removed };
},
replace: function (obj, key, document) {
var removed = obj[key];
obj[key] = this.value;
return { newDocument: document, removed: removed };
return { newDocument: document, removed };
},
move: function (obj, key, document) {
/* in case move target overwrites an existing value,
return the removed value, this can be taxing performance-wise,
and is potentially unneeded */
var removed = getValueByPointer(document, this.path);
let removed = getValueByPointer(document, this.path);
if (removed) {
removed = _deepClone(removed);
}
var originalValue = applyOperation(document, { op: "remove", path: this.from }).removed;
const originalValue = applyOperation(document, { op: "remove", path: this.from }).removed;
applyOperation(document, { op: "add", path: this.path, value: originalValue });
return { newDocument: document, removed: removed };
return { newDocument: document, removed };
},
copy: function (obj, key, document) {
var valueToCopy = getValueByPointer(document, this.from);
const valueToCopy = getValueByPointer(document, this.from);
// enforce copy by value so further operations don't affect source (see issue #177)
applyOperation(document, { op: "add", path: this.path, value: _deepClone(valueToCopy) });
return { newDocument: document };
Expand Down Expand Up @@ -68,7 +68,7 @@ var arrOps = {
replace: function (arr, i, document) {
var removed = arr[i];
arr[i] = this.value;
return { newDocument: document, removed: removed };
return { newDocument: document, removed };
},
move: objOps.move,
copy: objOps.copy,
Expand Down Expand Up @@ -105,11 +105,7 @@ export function getValueByPointer(document, pointer) {
* @param banPrototypeModifications Whether to ban modifications to `__proto__`, defaults to `true`.
* @return `{newDocument, result}` after the operation
*/
export function applyOperation(document, operation, validateOperation, mutateDocument, banPrototypeModifications, index) {
if (validateOperation === void 0) { validateOperation = false; }
if (mutateDocument === void 0) { mutateDocument = true; }
if (banPrototypeModifications === void 0) { banPrototypeModifications = true; }
if (index === void 0) { index = 0; }
export function applyOperation(document, operation, validateOperation = false, mutateDocument = true, banPrototypeModifications = true, index = 0) {
if (validateOperation) {
if (typeof validateOperation == 'function') {
validateOperation(operation, 0, document, operation.path);
Expand All @@ -120,7 +116,7 @@ export function applyOperation(document, operation, validateOperation, mutateDoc
}
/* ROOT OPERATIONS */
if (operation.path === "") {
var returnValue = { newDocument: document };
let returnValue = { newDocument: document };
if (operation.op === 'add') {
returnValue.newDocument = operation.value;
return returnValue;
Expand Down Expand Up @@ -167,14 +163,14 @@ export function applyOperation(document, operation, validateOperation, mutateDoc
if (!mutateDocument) {
document = _deepClone(document);
}
var path = operation.path || "";
var keys = path.split('/');
var obj = document;
var t = 1; //skip empty element - http://jsperf.com/to-shift-or-not-to-shift
var len = keys.length;
var existingPathFragment = undefined;
var key = void 0;
var validateFunction = void 0;
const path = operation.path || "";
const keys = path.split('/');
let obj = document;
let t = 1; //skip empty element - http://jsperf.com/to-shift-or-not-to-shift
let len = keys.length;
let existingPathFragment = undefined;
let key;
let validateFunction;
if (typeof validateOperation == 'function') {
validateFunction = validateOperation;
}
Expand Down Expand Up @@ -216,7 +212,7 @@ export function applyOperation(document, operation, validateOperation, mutateDoc
if (validateOperation && operation.op === "add" && key > obj.length) {
throw new JsonPatchError("The specified index MUST NOT be greater than the number of elements in the array", "OPERATION_VALUE_OUT_OF_BOUNDS", index, operation, document);
}
var returnValue = arrOps[operation.op].call(operation, obj, key, document); // Apply patch
const returnValue = arrOps[operation.op].call(operation, obj, key, document); // Apply patch
if (returnValue.test === false) {
throw new JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', index, operation, document);
}
Expand All @@ -228,7 +224,7 @@ export function applyOperation(document, operation, validateOperation, mutateDoc
key = unescapePathComponent(key);
}
if (t >= len) {
var returnValue = objOps[operation.op].call(operation, obj, key, document); // Apply patch
const returnValue = objOps[operation.op].call(operation, obj, key, document); // Apply patch
if (returnValue.test === false) {
throw new JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', index, operation, document);
}
Expand All @@ -253,9 +249,7 @@ export function applyOperation(document, operation, validateOperation, mutateDoc
* @param banPrototypeModifications Whether to ban modifications to `__proto__`, defaults to `true`.
* @return An array of `{newDocument, result}` after the patch
*/
export function applyPatch(document, patch, validateOperation, mutateDocument, banPrototypeModifications) {
if (mutateDocument === void 0) { mutateDocument = true; }
if (banPrototypeModifications === void 0) { banPrototypeModifications = true; }
export function applyPatch(document, patch, validateOperation, mutateDocument = true, banPrototypeModifications = true) {
if (validateOperation) {
if (!Array.isArray(patch)) {
throw new JsonPatchError('Patch sequence must be an array', 'SEQUENCE_NOT_AN_ARRAY');
Expand All @@ -264,8 +258,8 @@ export function applyPatch(document, patch, validateOperation, mutateDocument, b
if (!mutateDocument) {
document = _deepClone(document);
}
var results = new Array(patch.length);
for (var i = 0, length_1 = patch.length; i < length_1; i++) {
const results = new Array(patch.length);
for (let i = 0, length = patch.length; i < length; i++) {
// we don't need to pass mutateDocument argument because if it was true, we already deep cloned the object, we'll just pass `true`
results[i] = applyOperation(document, patch[i], validateOperation, true, banPrototypeModifications, i);
document = results[i].newDocument; // in case root was replaced
Expand All @@ -283,7 +277,7 @@ export function applyPatch(document, patch, validateOperation, mutateDocument, b
* @return The updated document
*/
export function applyReducer(document, operation, index) {
var operationResult = applyOperation(document, operation);
const operationResult = applyOperation(document, operation);
if (operationResult.test === false) { // failed test
throw new JsonPatchError("Test operation failed", 'TEST_OPERATION_FAILED', index, operation, document);
}
Expand Down
32 changes: 14 additions & 18 deletions module/duplex.mjs
Expand Up @@ -10,20 +10,18 @@ export { applyOperation, applyPatch, applyReducer, getValueByPointer, validate,
/* export some helpers */
export { PatchError as JsonPatchError, _deepClone as deepClone, escapePathComponent, unescapePathComponent } from './helpers.mjs';
var beforeDict = new WeakMap();
var Mirror = /** @class */ (function () {
function Mirror(obj) {
class Mirror {
constructor(obj) {
this.observers = new Map();
this.obj = obj;
}
return Mirror;
}());
var ObserverInfo = /** @class */ (function () {
function ObserverInfo(callback, observer) {
}
class ObserverInfo {
constructor(callback, observer) {
this.callback = callback;
this.observer = observer;
}
return ObserverInfo;
}());
}
function getMirror(obj) {
return beforeDict.get(obj);
}
Expand Down Expand Up @@ -51,7 +49,7 @@ export function observe(obj, callback) {
beforeDict.set(obj, mirror);
}
else {
var observerInfo = getObserverFromMirror(mirror, callback);
const observerInfo = getObserverFromMirror(mirror, callback);
observer = observerInfo && observerInfo.observer;
}
if (observer) {
Expand All @@ -62,10 +60,10 @@ export function observe(obj, callback) {
if (callback) {
observer.callback = callback;
observer.next = null;
var dirtyCheck = function () {
var dirtyCheck = () => {
generate(observer);
};
var fastCheck = function () {
var fastCheck = () => {
clearTimeout(observer.next);
observer.next = setTimeout(dirtyCheck);
};
Expand All @@ -79,7 +77,7 @@ export function observe(obj, callback) {
}
observer.patches = patches;
observer.object = obj;
observer.unobserve = function () {
observer.unobserve = () => {
generate(observer);
clearTimeout(observer.next);
removeObserverFromMirror(mirror, observer);
Expand All @@ -97,8 +95,7 @@ export function observe(obj, callback) {
/**
* Generate an array of patches from an observer
*/
export function generate(observer, invertible) {
if (invertible === void 0) { invertible = false; }
export function generate(observer, invertible = false) {
var mirror = beforeDict.get(observer.object);
_generate(mirror.value, observer.object, observer.patches, "", invertible);
if (observer.patches.length) {
Expand Down Expand Up @@ -153,9 +150,9 @@ function _generate(mirror, obj, patches, path, invertible) {
}
else {
if (invertible) {
patches.push({ op: "test", path: path, value: mirror });
patches.push({ op: "test", path, value: mirror });
}
patches.push({ op: "replace", path: path, value: obj });
patches.push({ op: "replace", path, value: obj });
changed = true;
}
}
Expand All @@ -172,8 +169,7 @@ function _generate(mirror, obj, patches, path, invertible) {
/**
* Create an array of patches from the differences in two objects
*/
export function compare(tree1, tree2, invertible) {
if (invertible === void 0) { invertible = false; }
export function compare(tree1, tree2, invertible = false) {
var patches = [];
_generate(tree1, tree2, patches, '', invertible);
return patches;
Expand Down
48 changes: 15 additions & 33 deletions module/helpers.mjs
Expand Up @@ -3,20 +3,7 @@
* (c) 2017 Joachim Wester
* MIT license
*/
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var _hasOwnProperty = Object.prototype.hasOwnProperty;
const _hasOwnProperty = Object.prototype.hasOwnProperty;
export function hasOwnProperty(obj, key) {
return _hasOwnProperty.call(obj, key);
}
Expand Down Expand Up @@ -144,28 +131,23 @@ export function hasUndefined(obj) {
return false;
}
function patchErrorMessageFormatter(message, args) {
var messageParts = [message];
for (var key in args) {
var value = typeof args[key] === 'object' ? JSON.stringify(args[key], null, 2) : args[key]; // pretty print
const messageParts = [message];
for (const key in args) {
const value = typeof args[key] === 'object' ? JSON.stringify(args[key], null, 2) : args[key]; // pretty print
if (typeof value !== 'undefined') {
messageParts.push(key + ": " + value);
messageParts.push(`${key}: ${value}`);
}
}
return messageParts.join('\n');
}
var PatchError = /** @class */ (function (_super) {
__extends(PatchError, _super);
function PatchError(message, name, index, operation, tree) {
var _newTarget = this.constructor;
var _this = _super.call(this, patchErrorMessageFormatter(message, { name: name, index: index, operation: operation, tree: tree })) || this;
_this.name = name;
_this.index = index;
_this.operation = operation;
_this.tree = tree;
Object.setPrototypeOf(_this, _newTarget.prototype); // restore prototype chain, see https://stackoverflow.com/a/48342359
_this.message = patchErrorMessageFormatter(message, { name: name, index: index, operation: operation, tree: tree });
return _this;
export class PatchError extends Error {
constructor(message, name, index, operation, tree) {
super(patchErrorMessageFormatter(message, { name, index, operation, tree }));
this.name = name;
this.index = index;
this.operation = operation;
this.tree = tree;
Object.setPrototypeOf(this, new.target.prototype); // restore prototype chain, see https://stackoverflow.com/a/48342359
this.message = patchErrorMessageFormatter(message, { name, index, operation, tree });
}
return PatchError;
}(Error));
export { PatchError };
}
5 changes: 3 additions & 2 deletions package.json
Expand Up @@ -44,9 +44,10 @@
},
"scripts": {
"tsc": "npm run tsc-common && npm run tsc-module",
"tsc-common": "tsc",
"tsc-module": "tsc --module esnext --moduleResolution node --outDir \"module/\" && npm run tsc-to-mjs",
"tsc-common": "tsc && npm run tsc-to-cjs",
"tsc-module": "tsc --target es6 --module es6 --moduleResolution node --outDir \"module/\" && npm run tsc-to-mjs",
"tsc-to-mjs": "bash tsc-to-mjs.sh",
"tsc-to-cjs": "bash tsc-to-cjs.sh",
"version": "npm run tsc && webpack && git add -A",
"build": "npm run tsc && webpack",
"serve": "http-server -p 5000 --silent",
Expand Down
3 changes: 3 additions & 0 deletions tsc-to-cjs.sh
@@ -0,0 +1,3 @@
#!/bin/bash
cd lib
sed -i 's/Object\.defineProperty(exports, "__esModule", { value: true });/ /g' core.js duplex.js helpers.js

0 comments on commit 04671e5

Please sign in to comment.