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

jsonc-parser

Package Overview
Dependencies
Maintainers
11
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsonc-parser - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

5

CHANGELOG.md
1.0.2 2018-03-05
==================
- added the *visit.onComment* API, reported when comments are allowed.
- added the *ParseErrorCode.InvalidCommentToken* enum value, reported when comments are disallowed.
1.0.1

@@ -3,0 +8,0 @@ ==================

2

lib/format.js

@@ -49,3 +49,3 @@ (function (factory) {

if (options.insertSpaces) {
indentValue = repeat(' ', options.tabSize);
indentValue = repeat(' ', options.tabSize || 4);
}

@@ -52,0 +52,0 @@ else {

@@ -92,2 +92,9 @@ export declare enum ScanError {

EndOfFileExpected = 8,
InvalidCommentToken = 9,
UnexpectedEndOfComment = 10,
UnexpectedEndOfString = 11,
UnexpectedEndOfNumber = 12,
InvalidUnicode = 13,
InvalidEscapeCharacter = 14,
InvalidCharacter = 15,
}

@@ -184,4 +191,8 @@ export declare type NodeType = 'object' | 'array' | 'property' | 'string' | 'number' | 'boolean' | 'null';

*/
onSeparator?: (charcter: string, offset: number, length: number) => void;
onSeparator?: (character: string, offset: number, length: number) => void;
/**
* When comments are allowed, invoked when a line or block comment is encountered. The offset and length represent the location of the comment.
*/
onComment?: (offset: number, length: number) => void;
/**
* Invoked on an error.

@@ -225,11 +236,11 @@ */

*/
tabSize: number;
tabSize?: number;
/**
* Is indentation based on spaces?
*/
insertSpaces: boolean;
insertSpaces?: boolean;
/**
* The default 'end of line' character
* The default 'end of line' character. If not set, '\n' is used as default.
*/
eol: string;
eol?: string;
}

@@ -248,3 +259,3 @@ /**

*/
export declare function format(documentText: string, range: Range, options: FormattingOptions): Edit[];
export declare function format(documentText: string, range: Range | undefined, options: FormattingOptions): Edit[];
/**

@@ -251,0 +262,0 @@ * Options used when computing the modification edits

@@ -279,7 +279,6 @@ (function (factory) {

pos += 2;
var safeLength = len - 1; // For lookahead.
var commentClosed = false;
while (pos < safeLength) {
while (pos < len) {
var ch = text.charCodeAt(pos);
if (ch === 42 /* asterisk */ && text.charCodeAt(pos + 1) === 47 /* slash */) {
if (ch === 42 /* asterisk */ && (pos + 1 < len) && text.charCodeAt(pos + 1) === 47 /* slash */) {
pos += 2;

@@ -431,2 +430,9 @@ commentClosed = true;

ParseErrorCode[ParseErrorCode["EndOfFileExpected"] = 8] = "EndOfFileExpected";
ParseErrorCode[ParseErrorCode["InvalidCommentToken"] = 9] = "InvalidCommentToken";
ParseErrorCode[ParseErrorCode["UnexpectedEndOfComment"] = 10] = "UnexpectedEndOfComment";
ParseErrorCode[ParseErrorCode["UnexpectedEndOfString"] = 11] = "UnexpectedEndOfString";
ParseErrorCode[ParseErrorCode["UnexpectedEndOfNumber"] = 12] = "UnexpectedEndOfNumber";
ParseErrorCode[ParseErrorCode["InvalidUnicode"] = 13] = "InvalidUnicode";
ParseErrorCode[ParseErrorCode["InvalidEscapeCharacter"] = 14] = "InvalidEscapeCharacter";
ParseErrorCode[ParseErrorCode["InvalidCharacter"] = 15] = "InvalidCharacter";
})(ParseErrorCode = exports.ParseErrorCode || (exports.ParseErrorCode = {}));

@@ -740,3 +746,3 @@ function getLiteralNodeType(value) {

}
var onObjectBegin = toNoArgVisit(visitor.onObjectBegin), onObjectProperty = toOneArgVisit(visitor.onObjectProperty), onObjectEnd = toNoArgVisit(visitor.onObjectEnd), onArrayBegin = toNoArgVisit(visitor.onArrayBegin), onArrayEnd = toNoArgVisit(visitor.onArrayEnd), onLiteralValue = toOneArgVisit(visitor.onLiteralValue), onSeparator = toOneArgVisit(visitor.onSeparator), onError = toOneArgVisit(visitor.onError);
var onObjectBegin = toNoArgVisit(visitor.onObjectBegin), onObjectProperty = toOneArgVisit(visitor.onObjectProperty), onObjectEnd = toNoArgVisit(visitor.onObjectEnd), onArrayBegin = toNoArgVisit(visitor.onArrayBegin), onArrayEnd = toNoArgVisit(visitor.onArrayEnd), onLiteralValue = toOneArgVisit(visitor.onLiteralValue), onSeparator = toOneArgVisit(visitor.onSeparator), onComment = toNoArgVisit(visitor.onComment), onError = toOneArgVisit(visitor.onError);
var disallowComments = options && options.disallowComments;

@@ -747,2 +753,24 @@ var allowTrailingComma = options && options.allowTrailingComma;

var token = _scanner.scan();
switch (_scanner.getTokenError()) {
case ScanError.InvalidUnicode:
handleError(ParseErrorCode.InvalidUnicode);
break;
case ScanError.InvalidEscapeCharacter:
handleError(ParseErrorCode.InvalidEscapeCharacter);
break;
case ScanError.UnexpectedEndOfNumber:
handleError(ParseErrorCode.UnexpectedEndOfNumber);
break;
case ScanError.UnexpectedEndOfComment:
if (!disallowComments) {
handleError(ParseErrorCode.UnexpectedEndOfComment);
}
break;
case ScanError.UnexpectedEndOfString:
handleError(ParseErrorCode.UnexpectedEndOfString);
break;
case ScanError.InvalidCharacter:
handleError(ParseErrorCode.InvalidCharacter);
break;
}
switch (token) {

@@ -752,4 +780,7 @@ case SyntaxKind.LineCommentTrivia:

if (disallowComments) {
handleError(ParseErrorCode.InvalidSymbol);
handleError(ParseErrorCode.InvalidCommentToken);
}
else {
onComment();
}
break;

@@ -888,2 +919,5 @@ case SyntaxKind.Unknown:

scanNext(); // consume comma
if (_scanner.getToken() === SyntaxKind.CloseBracketToken && allowTrailingComma) {
break;
}
}

@@ -890,0 +924,0 @@ else if (needsComma) {

{
"name": "jsonc-parser",
"version": "1.0.1",
"version": "1.0.2",
"description": "Scanner and parser for JSON with comments.",

@@ -18,3 +18,3 @@ "main": "./lib/main.js",

"mocha": "^2.4.5",
"typescript": "^2.7.1",
"typescript": "^2.7.2",
"@types/node": "^7.0.43",

@@ -28,4 +28,6 @@ "@types/mocha": "^2.2.32",

"watch": "tsc -w -p ./src",
"test": "tsc -p ./src && mocha"
"test": "tsc -p ./src && mocha",
"preversion": "npm test",
"postversion": "git push && git push --tags"
}
}

@@ -124,2 +124,6 @@ # jsonc-parser

onSeparator?: (charcter: string, offset: number, length: number) => void;
/**
* When comments are allowed, invoked when a line or block comment is encountered. The offset and length represent the location of the comment.
*/
onComment?: (offset: number, length: number) => void;
/**

@@ -126,0 +130,0 @@ * Invoked on an error.

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