New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

clarity-pattern-parser

Package Overview
Dependencies
Maintainers
1
Versions
190
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clarity-pattern-parser - npm Package Compare versions

Comparing version 2.0.2 to 2.0.3

55

lib/patterns/composite/CompositePattern.js

@@ -36,4 +36,2 @@ "use strict";

function CompositePattern(type, name) {
var _this;
var children = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];

@@ -43,17 +41,8 @@

_this = _possibleConstructorReturn(this, _getPrototypeOf(CompositePattern).call(this, type, name));
_this._children = children;
_this._assertArguments();
_this._cloneChildren();
_this._assignAsParent();
return _this;
return _possibleConstructorReturn(this, _getPrototypeOf(CompositePattern).call(this, type, name, children));
}
_createClass(CompositePattern, [{
key: "_assertArguments",
value: function _assertArguments() {
key: "_assertChildren",
value: function _assertChildren() {
if (!Array.isArray(this._children)) {

@@ -69,38 +58,10 @@ throw new Error("Invalid Arguments: The patterns argument need to be an array of Patterns.");

throw new Error("Invalid Argument: All patterns need to be an instance of Pattern.");
}
} // if (this._children.length < 2) {
// throw new Error(
// "Invalid Argument: Composite Patterns need to have more than one value pattern."
// );
// }
if (this._children.length < 2) {
throw new Error("Invalid Argument: Composite Patterns needs to have more than one value pattern.");
}
if (typeof this.name !== "string") {
throw new Error("Invalid Argument: Composite Patterns needs to have a name that's a string.");
}
}
}, {
key: "_cloneChildren",
value: function _cloneChildren() {
var _this2 = this;
// We need to clone the patterns so nested patterns can be parsed.
this._children = this._children.map(function (pattern) {
if (!(pattern instanceof _Pattern2.default)) {
throw new Error("The ".concat(_this2.name, " pattern has an invalid child pattern."));
}
return pattern.clone();
}); // We need to freeze the childen so they aren't modified.
Object.freeze(this._children);
}
}, {
key: "_assignAsParent",
value: function _assignAsParent() {
var _this3 = this;
this._children.forEach(function (child) {
return child.parent = _this3;
});
}
}, {
key: "clone",

@@ -107,0 +68,0 @@ value: function clone() {

42

lib/patterns/Pattern.js

@@ -24,2 +24,3 @@ "use strict";

var name = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
var children = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];

@@ -31,5 +32,6 @@ _classCallCheck(this, Pattern);

this._parent = null;
this._children = [];
this._assertName();
this.children = children;
}

@@ -68,18 +70,19 @@

key: "_assertChildren",
value: function _assertChildren() {
if (!Array.isArray(this._children)) {
throw new Error("Invalid Arguments: The patterns argument need to be an array of Patterns.");
}
value: function _assertChildren() {// Empty, meant to be overridden by subclasses.
}
}, {
key: "_cloneChildren",
value: function _cloneChildren() {
var _this = this;
var areAllPatterns = this._children.every(function (pattern) {
return pattern instanceof Pattern;
});
// We need to clone the patterns so nested patterns can be parsed.
this._children = this._children.map(function (pattern) {
if (!(pattern instanceof Pattern)) {
throw new Error("The ".concat(_this.name, " pattern has an invalid child pattern."));
}
if (!areAllPatterns) {
throw new Error("Invalid Argument: All patterns need to be an instance of Pattern.");
}
return pattern.clone();
}); // We need to freeze the childen so they aren't modified.
if (this._children.length < 2) {
throw new Error("Invalid Argument: Composite Patterns needs to have more than one value pattern.");
}
Object.freeze(this._children);
}

@@ -89,6 +92,6 @@ }, {

value: function _assignAsParent() {
var _this = this;
var _this2 = this;
this._children.forEach(function (child) {
return child.parent = _this;
return child.parent = _this2;
});

@@ -134,10 +137,7 @@ }

this._cloneChildren();
this._assertChildren();
this._assignAsParent();
this._children = value.map(function (pattern) {
return pattern.clone();
});
Object.freeze(this._children);
}

@@ -144,0 +144,0 @@ }]);

@@ -8,3 +8,3 @@ "use strict";

var _ValuePattern2 = _interopRequireDefault(require("./ValuePattern.js"));
var _ValuePattern = _interopRequireDefault(require("./ValuePattern.js"));

@@ -15,3 +15,3 @@ var _ValueNode = _interopRequireDefault(require("../../ast/ValueNode.js"));

var _Pattern = _interopRequireDefault(require("../Pattern.js"));
var _Pattern2 = _interopRequireDefault(require("../Pattern.js"));

@@ -40,21 +40,15 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

/*#__PURE__*/
function (_ValuePattern) {
_inherits(NotValue, _ValuePattern);
function (_Pattern) {
_inherits(NotValue, _Pattern);
function NotValue(name, pattern) {
var _this;
_classCallCheck(this, NotValue);
_this = _possibleConstructorReturn(this, _getPrototypeOf(NotValue).call(this, "not-value", name, [pattern]));
_this._assertArguments();
return _this;
return _possibleConstructorReturn(this, _getPrototypeOf(NotValue).call(this, "not-value", name, [pattern]));
}
_createClass(NotValue, [{
key: "_assertArguments",
value: function _assertArguments() {
if (!(this.children[0] instanceof _Pattern.default)) {
key: "_assertChildren",
value: function _assertChildren() {
if (!(this.children[0] instanceof _Pattern2.default)) {
throw new Error("Invalid Arguments: Expected the pattern to be a ValuePattern.");

@@ -138,5 +132,5 @@ }

return NotValue;
}(_ValuePattern2.default);
}(_Pattern2.default);
exports.default = NotValue;
//# sourceMappingURL=NotValue.js.map

@@ -36,4 +36,2 @@ "use strict";

function ValuePattern(type, name) {
var _this;
var children = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];

@@ -43,17 +41,8 @@

_this = _possibleConstructorReturn(this, _getPrototypeOf(ValuePattern).call(this, type, name));
_this._children = children;
_this._assertPatternArguments();
_this._cloneChildren();
_this._assignAsParent();
return _this;
return _possibleConstructorReturn(this, _getPrototypeOf(ValuePattern).call(this, type, name, children));
}
_createClass(ValuePattern, [{
key: "_assertPatternArguments",
value: function _assertPatternArguments() {
key: "_assertChildren",
value: function _assertChildren() {
if (!Array.isArray(this._children)) {

@@ -64,3 +53,3 @@ throw new Error("Invalid Arguments: The patterns argument need to be an array of ValuePattern.");

var areAllPatterns = this._children.every(function (pattern) {
return pattern instanceof ValuePattern;
return pattern instanceof ValuePattern || pattern instanceof _Pattern2.default;
});

@@ -81,27 +70,2 @@

}, {
key: "_cloneChildren",
value: function _cloneChildren() {
var _this2 = this;
// We need to clone the patterns so nested patterns can be parsed.
this._children = this._children.map(function (pattern) {
if (!(pattern instanceof _Pattern2.default)) {
throw new Error("The ".concat(_this2.name, " pattern has an invalid child pattern."));
}
return pattern.clone();
}); // We need to freeze the childen so they aren't modified.
Object.freeze(this._children);
}
}, {
key: "_assignAsParent",
value: function _assignAsParent() {
var _this3 = this;
this._children.forEach(function (child) {
return child.parent = _this3;
});
}
}, {
key: "clone",

@@ -108,0 +72,0 @@ value: function clone() {

{
"name": "clarity-pattern-parser",
"type": "module",
"version": "2.0.2",
"version": "2.0.3",
"description": "",

@@ -6,0 +6,0 @@ "main": "./lib/index.js",

@@ -5,11 +5,6 @@ import Pattern from "../Pattern.js";

constructor(type, name, children = []) {
super(type, name);
this._children = children;
this._assertArguments();
this._cloneChildren();
this._assignAsParent();
super(type, name, children);
}
_assertArguments() {
_assertChildren() {
if (!Array.isArray(this._children)) {

@@ -31,32 +26,10 @@ throw new Error(

if (this._children.length < 2) {
throw new Error(
"Invalid Argument: Composite Patterns needs to have more than one value pattern."
);
}
// if (this._children.length < 2) {
// throw new Error(
// "Invalid Argument: Composite Patterns need to have more than one value pattern."
// );
// }
if (typeof this.name !== "string") {
throw new Error(
"Invalid Argument: Composite Patterns needs to have a name that's a string."
);
}
}
_cloneChildren() {
// We need to clone the patterns so nested patterns can be parsed.
this._children = this._children.map(pattern => {
if (!(pattern instanceof Pattern)) {
throw new Error(`The ${this.name} pattern has an invalid child pattern.`);
}
return pattern.clone();
});
// We need to freeze the childen so they aren't modified.
Object.freeze(this._children);
}
_assignAsParent() {
this._children.forEach(child => (child.parent = this));
}
clone() {

@@ -63,0 +36,0 @@ throw new Error("Not Yet Implemented");

import Cursor from "../Cursor.js";
export default class Pattern {
constructor(type = null, name = null) {
constructor(type = null, name = null, children = []) {
this._type = type;
this._name = name;
this._parent = null;
this._children = [];
this._assertName();
this.children = children;
}

@@ -64,31 +64,24 @@

this._children = value;
this._cloneChildren();
this._assertChildren();
this._assignAsParent();
this._children = value.map(pattern => pattern.clone());
Object.freeze(this._children);
}
_assertChildren() {
if (!Array.isArray(this._children)) {
throw new Error(
"Invalid Arguments: The patterns argument need to be an array of Patterns."
);
}
// Empty, meant to be overridden by subclasses.
}
const areAllPatterns = this._children.every(
pattern => pattern instanceof Pattern
);
_cloneChildren() {
// We need to clone the patterns so nested patterns can be parsed.
this._children = this._children.map(pattern => {
if (!(pattern instanceof Pattern)) {
throw new Error(
`The ${this.name} pattern has an invalid child pattern.`
);
}
return pattern.clone();
});
if (!areAllPatterns) {
throw new Error(
"Invalid Argument: All patterns need to be an instance of Pattern."
);
}
if (this._children.length < 2) {
throw new Error(
"Invalid Argument: Composite Patterns needs to have more than one value pattern."
);
}
// We need to freeze the childen so they aren't modified.
Object.freeze(this._children);
}

@@ -95,0 +88,0 @@

@@ -6,9 +6,8 @@ import ValuePattern from "./ValuePattern.js";

export default class NotValue extends ValuePattern {
export default class NotValue extends Pattern {
constructor(name, pattern) {
super("not-value", name, [pattern]);
this._assertArguments();
}
_assertArguments() {
_assertChildren() {
if (!(this.children[0] instanceof Pattern)) {

@@ -15,0 +14,0 @@ throw new Error(

@@ -5,10 +5,6 @@ import Pattern from "../Pattern.js";

constructor(type, name, children = []) {
super(type, name);
this._children = children;
this._assertPatternArguments();
this._cloneChildren();
this._assignAsParent();
super(type, name, children);
}
_assertPatternArguments() {
_assertChildren() {
if (!Array.isArray(this._children)) {

@@ -21,3 +17,3 @@ throw new Error(

const areAllPatterns = this._children.every(
pattern => pattern instanceof ValuePattern
pattern => pattern instanceof ValuePattern || pattern instanceof Pattern
);

@@ -44,19 +40,2 @@

_cloneChildren() {
// We need to clone the patterns so nested patterns can be parsed.
this._children = this._children.map(pattern => {
if (!(pattern instanceof Pattern)) {
throw new Error(`The ${this.name} pattern has an invalid child pattern.`);
}
return pattern.clone();
});
// We need to freeze the childen so they aren't modified.
Object.freeze(this._children);
}
_assignAsParent() {
this._children.forEach(child => (child.parent = this));
}
clone() {

@@ -66,5 +45,5 @@ throw new Error("Not Yet Implemented");

getCurrentMark(){
getCurrentMark() {
throw new Error("Not Yet Implemented");
}
}

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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