Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

shift-reducer

Package Overview
Dependencies
Maintainers
4
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

shift-reducer - npm Package Compare versions

Comparing version 2.0.6 to 3.0.0

46

dist/clone-reducer.js

@@ -1,23 +0,29 @@

/**
* Copyright 2014 Shape Security, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
"use strict";
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
Object.defineProperty(exports, "__esModule", {
value: true
});
var _shiftSpec = require("shift-spec");
var _shiftSpec2 = _interopRequireDefault(_shiftSpec);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } /**
* Copyright 2014 Shape Security, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var CloneReducer = function CloneReducer() {

@@ -27,6 +33,6 @@ _classCallCheck(this, CloneReducer);

exports["default"] = CloneReducer;
exports.default = CloneReducer;
for (var typeName in _shiftSpec["default"]) {
var type = _shiftSpec["default"][typeName];
for (var typeName in _shiftSpec2.default) {
var type = _shiftSpec2.default[typeName];
Object.defineProperty(CloneReducer.prototype, "reduce" + typeName, {

@@ -33,0 +39,0 @@ value: function value(node, state) {

@@ -1,90 +0,9 @@

/**
* Copyright 2014 Shape Security, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
"use strict";
exports["default"] = reduce;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.MonoidalReducer = exports.CloneReducer = undefined;
exports.default = reduce;
var _shiftSpec = require("shift-spec");
function transformWithSpec(_x, _x2, _x3) {
var _left;
var _again = true;
_function: while (_again) {
var transformer = _x,
node = _x2,
spec = _x3;
_again = false;
switch (spec.typeName) {
case "Enum":
case "String":
case "Number":
case "Boolean":
case "SourceSpan":
return node;
case "Const":
// TODO: checked version
_x = transformer;
_x2 = node;
_x3 = spec.argument;
_again = true;
continue _function;
case "Maybe":
if (!(_left = node)) {
return _left;
}
_x = transformer;
_x2 = node;
_x3 = spec.argument;
_again = true;
continue _function;
case "List":
return node.map(function (e) {
return transformWithSpec(transformer, e, spec.argument);
});
case "Union":
// TODO: checked version
_x = transformer;
_x2 = node;
_x3 = _shiftSpec["default"][node.type];
_again = true;
continue _function;
default:
var state = {};
spec.fields.forEach(function (field) {
var v = transformWithSpec(transformer, node[field.name], field.type);
state[field.name] = v == null ? null : v;
});
if (typeof transformer["reduce" + node.type] !== "function") {
throw new Error("Encountered " + node.type + ", which the provided reducer does not handle.");
}
return transformer["reduce" + node.type](node, state);
}
}
}
function reduce(reducer, reducible) {
return transformWithSpec(reducer, reducible, _shiftSpec["default"][reducible.type]);
}
var _cloneReducer = require("./clone-reducer");

@@ -95,3 +14,3 @@

get: function get() {
return _cloneReducer["default"];
return _cloneReducer.default;
}

@@ -105,4 +24,61 @@ });

get: function get() {
return _monoidalReducer["default"];
return _monoidalReducer.default;
}
});
});
var _shiftSpec = require("shift-spec");
var _shiftSpec2 = _interopRequireDefault(_shiftSpec);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function transformWithSpec(transformer, node, spec) {
switch (spec.typeName) {
case "Enum":
case "String":
case "Number":
case "Boolean":
case "SourceSpan":
return node;
case "Const":
// TODO: checked version
return transformWithSpec(transformer, node, spec.argument);
case "Maybe":
return node && transformWithSpec(transformer, node, spec.argument);
case "List":
return node.map(function (e) {
return transformWithSpec(transformer, e, spec.argument);
});
case "Union":
// TODO: checked version
return transformWithSpec(transformer, node, _shiftSpec2.default[node.type]);
default:
var state = {};
spec.fields.forEach(function (field) {
var v = transformWithSpec(transformer, node[field.name], field.type);
state[field.name] = v == null ? null : v;
});
if (typeof transformer["reduce" + node.type] !== "function") {
throw new Error("Encountered " + node.type + ", which the provided reducer does not handle.");
}
return transformer["reduce" + node.type](node, state);
}
} /**
* Copyright 2014 Shape Security, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
function reduce(reducer, reducible) {
return transformWithSpec(reducer, reducible, _shiftSpec2.default[reducible.type]);
}

@@ -1,25 +0,33 @@

/**
* Copyright 2014 Shape Security, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
"use strict";
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; /**
* Copyright 2014 Shape Security, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", {
value: true
});
var _shiftSpec = require("shift-spec");
var _shiftSpec2 = _interopRequireDefault(_shiftSpec);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var methods = {};

@@ -31,65 +39,55 @@

function handlerForFieldOfType(_x) {
var _again = true;
function handlerForFieldOfType(type) {
switch (type.typeName) {
case "Enum":
case "String":
case "Boolean":
case "Number":
case "SourceSpan":
return null;
case "Const":
return handlerForFieldOfType(type.argument);
case "Maybe":
{
var _ret = function () {
var subHandler = handlerForFieldOfType(type.argument);
if (subHandler == null) return {
v: null
};
return {
v: function v(t) {
return t == null ? this.identity : subHandler.call(this, t);
}
};
}();
_function: while (_again) {
var type = _x;
_again = false;
switch (type.typeName) {
case "Enum":
case "String":
case "Boolean":
case "Number":
case "SourceSpan":
return null;
case "Const":
_x = type.argument;
_again = true;
continue _function;
case "Maybe":
{
var _ret = (function () {
var subHandler = handlerForFieldOfType(type.argument);
if (subHandler == null) return {
v: null
};
return {
v: function (t) {
return t == null ? this.identity : subHandler.call(this, t);
}
if ((typeof _ret === "undefined" ? "undefined" : _typeof(_ret)) === "object") return _ret.v;
}
case "List":
{
var _ret2 = function () {
var subHandler = handlerForFieldOfType(type.argument);
if (subHandler == null) return {
v: null
};
})();
return {
v: function v(t) {
var _this = this;
if (typeof _ret === "object") return _ret.v;
}
case "List":
{
var _ret2 = (function () {
var subHandler = handlerForFieldOfType(type.argument);
if (subHandler == null) return {
v: null
};
return {
v: function (t) {
var _this = this;
return this.fold(t.map(function (x) {
return subHandler.call(_this, x);
}));
}
};
}();
return this.fold(t.map(function (x) {
return subHandler.call(_this, x);
}));
}
};
})();
if (typeof _ret2 === "object") return _ret2.v;
}
default:
return id;
}
if ((typeof _ret2 === "undefined" ? "undefined" : _typeof(_ret2)) === "object") return _ret2.v;
}
default:
return id;
}
}
var _loop = function (typeName) {
var type = _shiftSpec["default"][typeName];
var _loop = function _loop(typeName) {
var type = _shiftSpec2.default[typeName];

@@ -105,6 +103,6 @@ var handlers = {};

value: function value(node, state) {
var _this2 = this;
var _this3 = this;
return this.fold(fieldNames.map(function (fieldName) {
return handlers[fieldName].call(_this2, state[fieldName]);
return handlers[fieldName].call(_this3, state[fieldName]);
}));

@@ -115,7 +113,7 @@ }

for (var typeName in _shiftSpec["default"]) {
for (var typeName in _shiftSpec2.default) {
_loop(typeName);
}
var MonoidalReducer = (function () {
var MonoidalReducer = function () {
function MonoidalReducer(monoid) {

@@ -134,6 +132,6 @@ _classCallCheck(this, MonoidalReducer);

value: function fold(list, a) {
var _this3 = this;
var _this2 = this;
return list.reduce(function (memo, x) {
return _this3.append(memo, x);
return _this2.append(memo, x);
}, a == null ? this.identity : a);

@@ -144,6 +142,6 @@ }

return MonoidalReducer;
})();
}();
exports["default"] = MonoidalReducer;
exports.default = MonoidalReducer;
Object.defineProperties(MonoidalReducer.prototype, methods);
{
"name": "shift-reducer",
"version": "2.0.6",
"version": "3.0.0",
"description": "reducer for the Shift AST format",

@@ -16,13 +16,15 @@ "author": "Shape Security Labs",

"scripts": {
"test": "mocha --compilers js:./babel-register --inline-diffs --check-leaks --ui tdd --reporter dot test",
"build": "babel --modules commonStrict --source-maps-inline --out-dir dist src",
"prepublish": "rm -rf dist && npm update && npm run build"
"test": "mocha --compilers js:babel-core/register --inline-diffs --check-leaks --ui tdd --reporter dot test",
"build": "babel --source-maps-inline --out-dir dist src",
"prepublish": "rm -rf dist && npm update && npm run build && (if ! (git rev-list -1 v$npm_package_version 2>&1 > /dev/null) || [ \"$(git rev-parse HEAD)\" != \"$(git rev-list -1 v$npm_package_version)\" ]; then printf \"\\e[31mPackage version does not have corresponding git tag at HEAD.\\e[0m\\n\"; exit 1; fi)"
},
"dependencies": {
"shift-spec": "^2015.1.3"
"shift-spec": "2015.2.0"
},
"devDependencies": {
"babel": "5.8.21",
"mocha": "^2.2.5",
"shift-parser": "^3.0.1"
"babel-cli": "6.3.13",
"babel-register": "6.3.13",
"babel-preset-es2015": "6.3.13",
"mocha": "^2.3.4",
"shift-parser": "^3.0.0"
},

@@ -29,0 +31,0 @@ "keywords": [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc