clarity-pattern-parser
Advanced tools
Comparing version 3.0.0 to 3.0.1
{ | ||
"name": "clarity-pattern-parser", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "Parsing Library for Typescript and Javascript.", | ||
@@ -15,6 +15,6 @@ "main": "./dist/index.js", | ||
"devDependencies": { | ||
"rollup-plugin-typescript2": "^0.30.0", | ||
"@types/jest": "^26.0.20", | ||
"@types/jest": "^26.0.23", | ||
"jest": "^26.6.3", | ||
"rollup": "^2.41.2", | ||
"rollup-plugin-typescript2": "^0.30.0", | ||
"ts-jest": "^26.5.3", | ||
@@ -21,0 +21,0 @@ "tslib": "^2.1.0", |
@@ -13,3 +13,3 @@ import Node from "./Node"; | ||
this.startIndex, | ||
this.endIndex, | ||
this.endIndex | ||
); | ||
@@ -24,24 +24,2 @@ | ||
filter( | ||
shouldKeep: (node: Node, context: Node[]) => boolean, | ||
context: Node[] = [] | ||
) { | ||
const childrenContext = context.slice(); | ||
childrenContext.push(this); | ||
Object.freeze(childrenContext); | ||
const matches = this.children.reduce((acc: Node[], child) => { | ||
return acc.concat(child.filter(shouldKeep, childrenContext)); | ||
}, []); | ||
const match = shouldKeep(this, context); | ||
if (match) { | ||
matches.push(this); | ||
} | ||
return matches; | ||
} | ||
toString() { | ||
@@ -48,0 +26,0 @@ return this.children.map((child) => child.toString()).join(""); |
@@ -8,3 +8,3 @@ export default abstract class Node { | ||
public children: Node[] = []; | ||
public value: string = ""; | ||
public value: string | null = null; | ||
@@ -34,7 +34,2 @@ constructor( | ||
abstract filter( | ||
shouldKeep?: (node: Node, context: Node[]) => boolean, | ||
context?: Node[] | ||
): Node[]; | ||
abstract clone(): Node; | ||
@@ -41,0 +36,0 @@ |
import Node from "./Node"; | ||
export default class ValueNode extends Node { | ||
public value: string; | ||
constructor( | ||
@@ -21,3 +19,3 @@ type: string, | ||
this.name, | ||
this.value, | ||
this.value || "", | ||
this.startIndex, | ||
@@ -28,18 +26,5 @@ this.endIndex | ||
filter( | ||
shouldKeep: (node: Node, context: Node[]) => boolean, | ||
context: Node[] = [] | ||
) { | ||
const match = shouldKeep(this, context); | ||
if (match) { | ||
return [this]; | ||
} | ||
return []; | ||
} | ||
toString() { | ||
return this.value; | ||
return this.value || ""; | ||
} | ||
} |
@@ -0,1 +1,2 @@ | ||
/** @jest-environment node */ | ||
import AndComposite from "../patterns/composite/AndComposite"; | ||
@@ -2,0 +3,0 @@ import Literal from "../patterns/value/Literal"; |
@@ -0,1 +1,2 @@ | ||
/** @jest-environment node */ | ||
import AndValue from "../patterns/value/AndValue"; | ||
@@ -2,0 +3,0 @@ import Literal from "../patterns/value/Literal"; |
@@ -0,1 +1,2 @@ | ||
/** @jest-environment node */ | ||
import AnyOfThese from "../patterns/value/AnyOfThese"; | ||
@@ -2,0 +3,0 @@ import Cursor from "../Cursor"; |
@@ -0,1 +1,2 @@ | ||
/** @jest-environment node */ | ||
import whitespace from "./javascriptPatterns/whitespace"; | ||
@@ -2,0 +3,0 @@ import name from "./javascriptPatterns/name"; |
@@ -0,1 +1,2 @@ | ||
/** @jest-environment node */ | ||
import CompositeNode from "../ast/CompositeNode"; | ||
@@ -2,0 +3,0 @@ import { ValueNode } from "../index"; |
@@ -0,1 +1,2 @@ | ||
/** @jest-environment node */ | ||
import cssValue from "./cssPatterns/cssValue"; | ||
@@ -2,0 +3,0 @@ import { Cursor } from "../index"; |
@@ -0,1 +1,2 @@ | ||
/** @jest-environment node */ | ||
import CursorHistory from "../CursorHistory"; | ||
@@ -2,0 +3,0 @@ import { Literal, ValueNode, Cursor, ParseError } from "../index"; |
@@ -0,1 +1,2 @@ | ||
/** @jest-environment node */ | ||
import Cursor from "../Cursor"; | ||
@@ -2,0 +3,0 @@ import ValueNode from "../ast/ValueNode"; |
@@ -0,1 +1,2 @@ | ||
/** @jest-environment node */ | ||
import element, { attribute } from "./htmlPatterns/element"; | ||
@@ -2,0 +3,0 @@ import { Cursor } from "../index"; |
@@ -0,1 +1,2 @@ | ||
/** @jest-environment node */ | ||
import Literal from "../patterns/value/Literal"; | ||
@@ -2,0 +3,0 @@ import Cursor from "../Cursor"; |
@@ -0,1 +1,2 @@ | ||
/** @jest-environment node */ | ||
import NotValue from "../patterns/value/NotValue"; | ||
@@ -2,0 +3,0 @@ import Literal from "../patterns/value/Literal"; |
@@ -0,1 +1,2 @@ | ||
/** @jest-environment node */ | ||
import Literal from "../patterns/value/Literal"; | ||
@@ -2,0 +3,0 @@ import OptionalValue from "../patterns/value/OptionalValue"; |
@@ -0,1 +1,2 @@ | ||
/** @jest-environment node */ | ||
import OrComposite from "../patterns/composite/OrComposite"; | ||
@@ -2,0 +3,0 @@ import Literal from "../patterns/value/Literal"; |
@@ -0,1 +1,2 @@ | ||
/** @jest-environment node */ | ||
import OrValue from "../patterns/value/OrValue"; | ||
@@ -2,0 +3,0 @@ import AnyOfThese from "../patterns/value/AnyOfThese"; |
@@ -0,1 +1,2 @@ | ||
/** @jest-environment node */ | ||
import ValuePattern from "../patterns/value/ValuePattern"; | ||
@@ -2,0 +3,0 @@ import AndValue from "../patterns/value/AndValue"; |
@@ -0,1 +1,2 @@ | ||
/** @jest-environment node */ | ||
import Permutor from "../Permutor"; | ||
@@ -2,0 +3,0 @@ |
@@ -0,1 +1,2 @@ | ||
/** @jest-environment node */ | ||
import { | ||
@@ -113,3 +114,3 @@ Cursor, | ||
], | ||
value: "", | ||
value: null, | ||
type: "and-composite", | ||
@@ -116,0 +117,0 @@ name: "line-ending-comment", |
@@ -0,1 +1,2 @@ | ||
/** @jest-environment node */ | ||
import { RecursivePattern, Cursor } from "../index"; | ||
@@ -2,0 +3,0 @@ import literals from "./javascriptPatterns/json"; |
@@ -0,3 +1,3 @@ | ||
/** @jest-environment node */ | ||
import { RegexValue } from "../index"; | ||
import assert from "assert"; | ||
@@ -4,0 +4,0 @@ test("RegexValue: exec.", () => { |
@@ -0,1 +1,2 @@ | ||
/** @jest-environment node */ | ||
import RepeatComposite from "../patterns/composite/RepeatComposite"; | ||
@@ -5,3 +6,2 @@ import AndComposite from "../patterns/composite/AndComposite"; | ||
import Literal from "../patterns/value/Literal"; | ||
import assert from "assert"; | ||
@@ -8,0 +8,0 @@ describe("RepeatComposite", () => { |
@@ -0,5 +1,5 @@ | ||
/** @jest-environment node */ | ||
import RepeatValue from "../patterns/value/RepeatValue"; | ||
import Literal from "../patterns/value/Literal"; | ||
import OptionalValue from "../patterns/value/OptionalValue"; | ||
import assert from "assert"; | ||
import Cursor from "../Cursor"; | ||
@@ -9,29 +9,29 @@ | ||
test("Empty Constructor.", () => { | ||
assert.throws(() => { | ||
expect(() => { | ||
new (RepeatValue as any)(); | ||
}); | ||
}).toThrow(); | ||
}); | ||
test("Invalid name.", () => { | ||
assert.throws(() => { | ||
expect(() => { | ||
new (RepeatValue as any)([], new Literal("blah", "Blah")); | ||
}); | ||
}).toThrow(); | ||
}); | ||
test("No patterns", () => { | ||
assert.throws(() => { | ||
expect(() => { | ||
new (RepeatValue as any)("and-value"); | ||
}); | ||
}).toThrow(); | ||
}); | ||
test("Empty patterns", () => { | ||
assert.throws(() => { | ||
expect(() => { | ||
new (RepeatValue as any)("and-value", null); | ||
}); | ||
}).toThrow(); | ||
}); | ||
test("Invalid patterns", () => { | ||
assert.throws(() => { | ||
expect(() => { | ||
new (RepeatValue as any)("and-value", {}); | ||
}); | ||
}).toThrow(); | ||
}); | ||
@@ -93,3 +93,3 @@ | ||
assert.throws(() => { | ||
expect(() => { | ||
new RepeatValue("johns", new OptionalValue(john)); | ||
@@ -96,0 +96,0 @@ }); |
@@ -0,1 +1,2 @@ | ||
/** @jest-environment node */ | ||
import unit from "./javascriptPatterns/unit"; | ||
@@ -2,0 +3,0 @@ import Cursor from "../Cursor"; |
@@ -0,1 +1,2 @@ | ||
/** @jest-environment node */ | ||
import TextSuggester from "../TextSuggester"; | ||
@@ -2,0 +3,0 @@ import sentence from "./patterns/sentence"; |
@@ -0,1 +1,2 @@ | ||
/** @jest-environment node */ | ||
import ValueNode from "../ast/ValueNode"; | ||
@@ -2,0 +3,0 @@ import assert from "assert"; |
@@ -1,1 +0,2 @@ | ||
* Remove the getNextToken from the Patterns. Use a Visitor pattern to figure out the tokens. | ||
- Remove the getNextToken from the Patterns. Use a Visitor pattern to figure out the tokens. Patterns should just be data. | ||
- Build a visitor and remove the filter off of the node. Nodes should just be data. |
@@ -6,3 +6,3 @@ { | ||
"module": "esnext", | ||
"lib": ["esnext"], | ||
"lib": ["es2019"], | ||
"strict": true, | ||
@@ -18,2 +18,3 @@ "sourceMap": true, | ||
"typeRoots": ["node_modules/@types"], | ||
"strictNullChecks": true | ||
}, | ||
@@ -20,0 +21,0 @@ "exclude": ["node_modules"], |
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
0
163783
81
4756