Socket
Socket
Sign inDemoInstall

graphql-syntax-highlighter-react

Package Overview
Dependencies
8
Maintainers
3
Versions
21
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.3.3 to 0.3.4

4

dist/GraphqlCodeBlock.js

@@ -73,3 +73,3 @@ 'use strict';

ParseRules: _Rules.ParseRules
}, function (stream, state, style) {
}, function (stream, state, style, rowIndex) {
var _sourceText = stream._sourceText,

@@ -79,3 +79,3 @@ _start = stream._start,

if (rowKeys[rowKeys.length - 1] !== _sourceText) {
if (rowKeys.length - 1 !== rowIndex) {
rowKeys.push(_sourceText);

@@ -82,0 +82,0 @@ highlighted.push([]);

@@ -7,4 +7,2 @@ 'use strict';

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
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; }; }();

@@ -15,8 +13,9 @@

/**
* Copyright (c) 2015, Facebook, Inc.
* Copyright (c) Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
* This source code is licensed under the license found in the
* LICENSE file in the root directory of this source tree.
*
*
*/

@@ -37,68 +36,44 @@

function CharacterStream(sourceText) {
var _this = this;
_classCallCheck(this, CharacterStream);
this._start = 0;
this._pos = 0;
this._sourceText = sourceText;
}
this.getStartOfToken = function () {
return _this._start;
};
_createClass(CharacterStream, [{
key: 'getStartOfToken',
value: function getStartOfToken() {
return this._start;
}
}, {
key: 'getCurrentPosition',
value: function getCurrentPosition() {
return this._pos;
}
}, {
key: '_testNextCharacter',
value: function _testNextCharacter(pattern) {
var character = this._sourceText.charAt(this._pos);
var isMatched = false;
if (typeof pattern === 'string') {
isMatched = character === pattern;
} else {
isMatched = pattern.test ? pattern.test(character) : pattern(character);
}
return isMatched;
}
}, {
key: 'eol',
value: function eol() {
return this._sourceText.length === this._pos;
}
}, {
key: 'sol',
value: function sol() {
return this._pos === 0;
}
}, {
key: 'peek',
value: function peek() {
return Boolean(this._sourceText.charAt(this._pos)) ? this._sourceText.charAt(this._pos) : null;
}
}, {
key: 'next',
value: function next() {
var char = this._sourceText.charAt(this._pos);
this._pos++;
this.getCurrentPosition = function () {
return _this._pos;
};
this.eol = function () {
return _this._sourceText.length === _this._pos;
};
this.sol = function () {
return _this._pos === 0;
};
this.peek = function () {
return _this._sourceText.charAt(_this._pos) ? _this._sourceText.charAt(_this._pos) : null;
};
this.next = function () {
var char = _this._sourceText.charAt(_this._pos);
_this._pos++;
return char;
}
}, {
key: 'eat',
value: function eat(pattern) {
var isMatched = this._testNextCharacter(pattern);
};
this.eat = function (pattern) {
var isMatched = _this._testNextCharacter(pattern);
if (isMatched) {
this._start = this._pos;
this._pos++;
return this._sourceText.charAt(this._pos - 1);
_this._start = _this._pos;
_this._pos++;
return _this._sourceText.charAt(_this._pos - 1);
}
return undefined;
}
}, {
key: 'eatWhile',
value: function eatWhile(match) {
var isMatched = this._testNextCharacter(match);
};
this.eatWhile = function (match) {
var isMatched = _this._testNextCharacter(match);
var didEat = false;

@@ -109,8 +84,8 @@

didEat = isMatched;
this._start = this._pos;
_this._start = _this._pos;
}
while (isMatched) {
this._pos++;
isMatched = this._testNextCharacter(match);
_this._pos++;
isMatched = _this._testNextCharacter(match);
didEat = true;

@@ -120,23 +95,19 @@ }

return didEat;
}
}, {
key: 'eatSpace',
value: function eatSpace() {
return this.eatWhile(/[\s\u00a0]/);
}
}, {
key: 'skipToEnd',
value: function skipToEnd() {
this._pos = this._sourceText.length;
}
}, {
key: 'skipTo',
value: function skipTo(position) {
this._pos = position;
}
}, {
key: 'match',
value: function match(pattern) {
};
this.eatSpace = function () {
return _this.eatWhile(/[\s\u00a0]/);
};
this.skipToEnd = function () {
_this._pos = _this._sourceText.length;
};
this.skipTo = function (position) {
_this._pos = position;
};
this.match = function (pattern) {
var consume = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
var caseFold = arguments[2];
var caseFold = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;

@@ -146,21 +117,25 @@ var token = null;

switch (typeof pattern === 'undefined' ? 'undefined' : _typeof(pattern)) {
case 'string':
var regex = new RegExp(pattern, caseFold ? 'i' : '');
match = regex.test(this._sourceText.substr(this._pos, pattern.length));
token = pattern;
break;
case 'object': // RegExp
case 'function':
match = this._sourceText.slice(this._pos).match(pattern);
token = match && match[0];
break;
if (typeof pattern === 'string') {
var regex = new RegExp(pattern, caseFold ? 'i' : 'g');
match = regex.test(_this._sourceText.substr(_this._pos, pattern.length));
token = pattern;
} else if (pattern instanceof RegExp) {
match = _this._sourceText.slice(_this._pos).match(pattern);
token = match && match[0];
}
if (match && (typeof pattern === 'string' || match.index === 0)) {
if (consume) {
this._start = this._pos;
this._pos += token.length;
if (match != null) {
if (typeof pattern === 'string' || match instanceof Array &&
// String.match returns 'index' property, which flow fails to detect
// for some reason. The below is a workaround, but an easier solution
// is just checking if `match.index === 0`
_this._sourceText.startsWith(match[0], _this._pos)) {
if (consume) {
_this._start = _this._pos;
if (token && token.length) {
_this._pos += token.length;
}
}
return match;
}
return match;
}

@@ -170,19 +145,16 @@

return false;
}
}, {
key: 'backUp',
value: function backUp(num) {
this._pos -= num;
}
}, {
key: 'column',
value: function column() {
return this._pos;
}
}, {
key: 'indentation',
value: function indentation() {
var match = this._sourceText.match(/\s*/);
};
this.backUp = function (num) {
_this._pos -= num;
};
this.column = function () {
return _this._pos;
};
this.indentation = function () {
var match = _this._sourceText.match(/\s*/);
var indent = 0;
if (match && match.index === 0) {
if (match && match.length === 0) {
var whitespaces = match[0];

@@ -201,8 +173,25 @@ var pos = 0;

return indent;
};
this.current = function () {
return _this._sourceText.slice(_this._start, _this._pos);
};
this._start = 0;
this._pos = 0;
this._sourceText = sourceText;
}
_createClass(CharacterStream, [{
key: '_testNextCharacter',
value: function _testNextCharacter(pattern) {
var character = this._sourceText.charAt(this._pos);
var isMatched = false;
if (typeof pattern === 'string') {
isMatched = character === pattern;
} else {
isMatched = pattern instanceof RegExp ? pattern.test(character) : pattern(character);
}
return isMatched;
}
}, {
key: 'current',
value: function current() {
return this._sourceText.slice(this._start, this._pos);
}
}]);

@@ -209,0 +198,0 @@

@@ -32,9 +32,9 @@ 'use strict';

lines.forEach(function (line) {
lines.forEach(function (line, i) {
var stream = new _CharacterStream2.default(line);
while (!stream.eol()) {
var style = parser.token(stream, state);
callbackFn(stream, state, style);
callbackFn(stream, state, style, i);
}
});
}
{
"name": "graphql-syntax-highlighter-react",
"version": "0.3.3",
"version": "0.3.4",
"description": "A React component for highlighting GraphQL syntax.",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -31,5 +31,5 @@ import { LexRules, ParseRules, isIgnored } from './utils/Rules.js';

ParseRules,
}, (stream, state, style) => {
}, (stream, state, style, rowIndex) => {
const { _sourceText, _start, _pos } = stream;
if (rowKeys[rowKeys.length-1] !== _sourceText) {
if (rowKeys.length-1 !== rowIndex) {
rowKeys.push(_sourceText);

@@ -36,0 +36,0 @@ highlighted.push([]);

/**
* Copyright (c) 2015, Facebook, Inc.
* Copyright (c) Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
* This source code is licensed under the license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

@@ -22,3 +23,7 @@

export default class CharacterStream {
constructor(sourceText: string): void {
_start;
_pos;
_sourceText;
constructor(sourceText) {
this._start = 0;

@@ -29,12 +34,8 @@ this._pos = 0;

getStartOfToken(): Number {
return this._start;
}
getStartOfToken = () => this._start;
getCurrentPosition(): Number {
return this._pos;
}
getCurrentPosition = () => this._pos;
_testNextCharacter(pattern: mixed) {
let character = this._sourceText.charAt(this._pos);
_testNextCharacter(pattern) {
const character = this._sourceText.charAt(this._pos);
let isMatched = false;

@@ -44,3 +45,6 @@ if (typeof pattern === 'string') {

} else {
isMatched = pattern.test ? pattern.test(character) : pattern(character);
isMatched =
pattern instanceof RegExp
? pattern.test(character)
: pattern(character);
}

@@ -50,32 +54,29 @@ return isMatched;

eol(): boolean {
return this._sourceText.length === this._pos;
}
eol = () => this._sourceText.length === this._pos;
sol(): boolean {
return this._pos === 0;
}
sol = () => this._pos === 0;
peek(): string | void {
return Boolean(this._sourceText.charAt(this._pos)) ?
this._sourceText.charAt(this._pos) : null;
}
peek = () => {
return this._sourceText.charAt(this._pos)
? this._sourceText.charAt(this._pos)
: null;
};
next(): string {
next = () => {
const char = this._sourceText.charAt(this._pos);
this._pos ++;
this._pos++;
return char;
}
};
eat(pattern: mixed): string | void {
eat = (pattern) => {
const isMatched = this._testNextCharacter(pattern);
if (isMatched) {
this._start = this._pos;
this._pos ++;
this._pos++;
return this._sourceText.charAt(this._pos - 1);
}
return undefined;
}
};
eatWhile(match: mixed): boolean {
eatWhile = (match) => {
let isMatched = this._testNextCharacter(match);

@@ -91,3 +92,3 @@ let didEat = false;

while (isMatched) {
this._pos ++;
this._pos++;
isMatched = this._testNextCharacter(match);

@@ -98,48 +99,48 @@ didEat = true;

return didEat;
}
};
eatSpace(): boolean {
return this.eatWhile(/[\s\u00a0]/);
}
eatSpace = () => this.eatWhile(/[\s\u00a0]/);
skipToEnd(): void {
skipToEnd = () => {
this._pos = this._sourceText.length;
}
};
skipTo(position): void {
skipTo = (position) => {
this._pos = position;
}
};
match(
pattern: mixed,
consume: ?boolean = true,
caseFold: boolean
): Array<string> | boolean {
match = (
pattern,
consume = true,
caseFold = false,
) => {
let token = null;
let match = null;
switch (typeof pattern) {
case 'string':
const regex = new RegExp(pattern, (caseFold ? 'i' : ''));
match = regex.test(this._sourceText.substr(this._pos, pattern.length));
token = pattern;
break;
case 'object': // RegExp
case 'function':
match = this._sourceText.slice(this._pos).match(pattern);
token = match && match[0];
break;
if (typeof pattern === 'string') {
const regex = new RegExp(pattern, caseFold ? 'i' : 'g');
match = regex.test(this._sourceText.substr(this._pos, pattern.length));
token = pattern;
} else if (pattern instanceof RegExp) {
match = this._sourceText.slice(this._pos).match(pattern);
token = match && match[0];
}
if (
match && (
if (match != null) {
if (
typeof pattern === 'string' ||
match.index === 0
)
) {
if (consume) {
this._start = this._pos;
this._pos += token.length;
(match instanceof Array &&
// String.match returns 'index' property, which flow fails to detect
// for some reason. The below is a workaround, but an easier solution
// is just checking if `match.index === 0`
this._sourceText.startsWith(match[0], this._pos))
) {
if (consume) {
this._start = this._pos;
if (token && token.length) {
this._pos += token.length;
}
}
return match;
}
return match;
}

@@ -149,16 +150,14 @@

return false;
}
};
backUp(num: number): void {
backUp = (num) => {
this._pos -= num;
}
};
column(): number {
return this._pos;
}
column = () => this._pos;
indentation(): number {
indentation = () => {
const match = this._sourceText.match(/\s*/);
let indent = 0;
if (match && match.index === 0) {
if (match && match.length === 0) {
const whitespaces = match[0];

@@ -177,7 +176,5 @@ let pos = 0;

return indent;
}
};
current(): string {
return this._sourceText.slice(this._start, this._pos);
}
}
current = () => this._sourceText.slice(this._start, this._pos);
}

@@ -18,9 +18,9 @@ /**

lines.forEach(line => {
lines.forEach((line, i) => {
const stream = new CharacterStream(line);
while (!stream.eol()) {
const style = parser.token(stream, state);
callbackFn(stream, state, style);
callbackFn(stream, state, style, i);
}
});
}
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc