comment-json
Advanced tools
+7
-6
@@ -40,9 +40,10 @@ // Original from DefinitelyTyped. Thanks a million | ||
| type: 'BlockComment' | 'LineComment' | ||
| // The content of the comment, including whitespaces and line breaks | ||
| /** The content of the comment, including whitespaces and line breaks */ | ||
| value: string | ||
| // If the start location is the same line as the previous token, | ||
| // then `inline` is `true` | ||
| /** | ||
| * If the start location is the same line as the previous token, | ||
| * then `inline` is `true` | ||
| */ | ||
| inline: boolean | ||
| // But pay attention that, | ||
| // locations will NOT be maintained when stringified | ||
| /* But pay attention that, locations will NOT be maintained when stringified */ | ||
| loc: CommentLocation | ||
@@ -52,3 +53,3 @@ } | ||
| export interface CommentLocation { | ||
| // The start location begins at the `//` or `/*` symbol | ||
| /** The start location begins at the `//` or `/*` symbol */ | ||
| start: Location | ||
@@ -55,0 +56,0 @@ // The end location of multi-line comment ends at the `*/` symbol |
+5
-6
| { | ||
| "name": "comment-json", | ||
| "version": "4.2.5", | ||
| "version": "4.3.0", | ||
| "description": "Parse and stringify JSON with comments. It will retain comments even after saved!", | ||
@@ -11,3 +11,3 @@ "main": "src/index.js", | ||
| "test:ts": "tsc -b test/ts/tsconfig.build.json && node test/ts/test-ts.js", | ||
| "test:node": "NODE_DEBUG=comment-json nyc ava --timeout=10s --verbose", | ||
| "test:node": "cross-env NODE_DEBUG=comment-json nyc ava --timeout=10s --verbose", | ||
| "test:dev": "npm run test:only && npm run report:dev", | ||
@@ -17,3 +17,3 @@ "lint": "eslint .", | ||
| "posttest": "npm run report", | ||
| "report": "nyc report --reporter=text-lcov > coverage.lcov && codecov", | ||
| "report": "nyc report --reporter=text-lcov > coverage.lcov", | ||
| "report:dev": "nyc report --reporter=html && npm run report:open", | ||
@@ -58,2 +58,3 @@ "report:open": "open coverage/index.html" | ||
| "codecov": "^3.8.2", | ||
| "cross-env": "^10.0.0", | ||
| "eslint": "^8.8.0", | ||
@@ -68,6 +69,4 @@ "eslint-plugin-import": "^2.25.4", | ||
| "core-util-is": "^1.0.3", | ||
| "esprima": "^4.0.1", | ||
| "has-own-prop": "^2.0.0", | ||
| "repeat-string": "^1.6.1" | ||
| "esprima": "^4.0.1" | ||
| } | ||
| } |
+3
-4
@@ -1,2 +0,1 @@ | ||
| const hasOwnProperty = require('has-own-prop') | ||
| const { | ||
@@ -55,3 +54,3 @@ isObject, | ||
| const source_prop = symbol(prefix, source_key) | ||
| if (!hasOwnProperty(source, source_prop)) { | ||
| if (!Object.hasOwn(source, source_prop)) { | ||
| return | ||
@@ -88,3 +87,3 @@ } | ||
| const target_prop = symbol(prefix, to) | ||
| if (!hasOwnProperty(array, target_prop)) { | ||
| if (!Object.hasOwn(array, target_prop)) { | ||
| copy_comments_by_kind(array, array, to, from, prefix, true) | ||
@@ -119,3 +118,3 @@ return | ||
| if (!hasOwnProperty(source, key)) { | ||
| if (!Object.hasOwn(source, key)) { | ||
| return | ||
@@ -122,0 +121,0 @@ } |
+21
-1
| const {parse, tokenize} = require('./parse') | ||
| const stringify = require('./stringify') | ||
| const {CommentArray} = require('./array') | ||
| const {assign} = require('./common') | ||
| const { | ||
| PREFIX_BEFORE, | ||
| PREFIX_AFTER_PROP, | ||
| PREFIX_AFTER_COLON, | ||
| PREFIX_AFTER_VALUE, | ||
| PREFIX_AFTER, | ||
| PREFIX_BEFORE_ALL, | ||
| PREFIX_AFTER_ALL, | ||
| assign | ||
| } = require('./common') | ||
| module.exports = { | ||
| PREFIX_BEFORE, | ||
| PREFIX_AFTER_PROP, | ||
| PREFIX_AFTER_COLON, | ||
| PREFIX_AFTER_VALUE, | ||
| PREFIX_AFTER, | ||
| PREFIX_BEFORE_ALL, | ||
| PREFIX_AFTER_ALL, | ||
| parse, | ||
@@ -8,0 +28,0 @@ stringify, |
+10
-1
@@ -40,2 +40,3 @@ // JSON formatting | ||
| let current_code | ||
| const previous_hosts = [] | ||
@@ -57,2 +58,3 @@ let comments_host = null | ||
| const clean = () => { | ||
| current_code = UNDEFINED | ||
| previous_props.length = | ||
@@ -76,2 +78,4 @@ previous_hosts.length = 0 | ||
| reviver = null | ||
| current_code = UNDEFINED | ||
| } | ||
@@ -90,5 +94,7 @@ | ||
| const unexpected = () => { | ||
| const error = new SyntaxError(`Unexpected token ${current.value.slice(0, 1)}`) | ||
| const error = new SyntaxError(`Unexpected token '${current.value.slice(0, 1)}', "${current_code}" is not valid JSON`) | ||
| Object.assign(error, current.loc.start) | ||
| free() | ||
| throw error | ||
@@ -107,2 +113,4 @@ } | ||
| free() | ||
| throw error | ||
@@ -407,2 +415,3 @@ } | ||
| current_code = code | ||
| tokens = tokenize(code) | ||
@@ -409,0 +418,0 @@ reviver = rev |
+2
-3
| const { | ||
| isArray, isObject, isFunction, isNumber, isString | ||
| } = require('core-util-is') | ||
| const repeat = require('repeat-string') | ||
@@ -311,3 +310,3 @@ const { | ||
| : isNumber(space) | ||
| ? repeat(SPACE, space) | ||
| ? SPACE.repeat(space) | ||
| : EMPTY | ||
@@ -363,3 +362,3 @@ | ||
| return isObject(value) | ||
| ? process_comments(value, PREFIX_BEFORE_ALL, EMPTY).trimLeft() | ||
| ? process_comments(value, PREFIX_BEFORE_ALL, EMPTY, true).trimLeft() | ||
| + str | ||
@@ -366,0 +365,0 @@ + process_comments(value, PREFIX_AFTER_ALL, EMPTY).trimRight() |
46716
0.73%3
-40%1135
1.89%9
12.5%- Removed
- Removed
- Removed
- Removed