Comparing version 3.3.3 to 3.3.4
import { Decorators, NodeDefinition } from "./interfaces"; | ||
import Tree from "./tree"; | ||
export default class Highlight<R extends string | Text | Element> { | ||
export default class Highlight<R extends string | Text | Element | any> { | ||
private static findNodeDefinition; | ||
@@ -5,0 +5,0 @@ private mode; |
@@ -13,7 +13,4 @@ "use strict"; | ||
static findNodeDefinition(node, definitions) { | ||
const matches = definitions.filter(definition => { | ||
const definitionRange = [ | ||
definition.startPosition, | ||
definition.endPosition | ||
]; | ||
const matches = definitions.filter((definition) => { | ||
const definitionRange = [definition.startPosition, definition.endPosition]; | ||
const nodeRange = [node.startPosition, node.endPosition]; | ||
@@ -48,9 +45,7 @@ return (astNodePoint_1.default.areEqualRanges(nodeRange, definitionRange) || | ||
const point = new astNodePoint_1.default({ row, column: columnAtLine }); | ||
if (currentToken < nodes.length && | ||
astNodePoint_1.default.isInRange([startPosition, endPosition], point)) { | ||
if (currentToken < nodes.length && astNodePoint_1.default.isInRange([startPosition, endPosition], point)) { | ||
inRange = true; | ||
wordInRange += char; | ||
// if there's a token that spans till the end of the string | ||
if (column === source.length - 1 || | ||
columnAtLine === nodes[currentToken].endPosition.column - 1) { | ||
if (column === source.length - 1 || columnAtLine === nodes[currentToken].endPosition.column - 1) { | ||
decoratedStrings.push(...this.decorateNode(wordInRange, nodes[currentToken], definitions)); | ||
@@ -100,14 +95,10 @@ wordInRange = ""; | ||
column: columnInNode, | ||
row: startPosition.row | ||
row: startPosition.row, | ||
}); | ||
if (currentToken < matches.length && | ||
astNodePoint_1.default.isInRange([ | ||
matches[currentToken].startPosition, | ||
matches[currentToken].endPosition | ||
], point)) { | ||
astNodePoint_1.default.isInRange([matches[currentToken].startPosition, matches[currentToken].endPosition], point)) { | ||
inRange = true; | ||
wordInRange += char; | ||
// if there's a token that spans till the end of the string | ||
if (column === text.length - 1 || | ||
columnInNode === matches[currentToken].endPosition.column - 1) { | ||
if (column === text.length - 1 || columnInNode === matches[currentToken].endPosition.column - 1) { | ||
decoratedStrings.push(this.decorateText(wordInRange, matches[currentToken].type, node, matches[currentToken])); | ||
@@ -154,2 +145,4 @@ wordInRange = ""; | ||
return this.decorators.braces(text); | ||
case "[[": | ||
case "]]": | ||
case "[": | ||
@@ -156,0 +149,0 @@ case "]": |
@@ -24,3 +24,3 @@ import { ArgumentSchema, OptionSchema, ProgramSchema, SubcommandSchema } from "kmdr-parser"; | ||
} | ||
export interface Decorators<T extends Element | Text | string> { | ||
export interface Decorators<T extends Element | Text | string | any> { | ||
argument(text: string, node?: Node, definition?: NodeDefinition): T; | ||
@@ -27,0 +27,0 @@ arithmeticOperator(text: string, node?: Node, definition?: NodeDefinition): T; |
{ | ||
"name": "kmdr-ast", | ||
"version": "3.3.3", | ||
"version": "3.3.4", | ||
"description": "Traverse the AST of an explanation by kmdr", | ||
@@ -10,2 +10,3 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@types/react": "^16.9.34", | ||
"kmdr-parser": "^2.3.0" | ||
@@ -12,0 +13,0 @@ }, |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
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
57869
59
0
2
698
+ Added@types/react@^16.9.34
+ Added@types/prop-types@15.7.13(transitive)
+ Added@types/react@16.14.62(transitive)
+ Added@types/scheduler@0.16.8(transitive)
+ Addedcsstype@3.1.3(transitive)