Skip to content

Commit 1f1c26a

Browse files
immutable string
1 parent 8dae9b7 commit 1f1c26a

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ Usage: `jsonlint [options] [--] [<file, directory, pattern> ...]`
163163
--enforce-single-quotes surrounds all strings with single quotes
164164
--trim-trailing-commas omit trailing commas from objects and arrays
165165
--succeed-with-no-files succeed (exit code 0) if no files were found
166+
--immutable-string use immutable strings in parsing
166167
-v, --version output the version number
167168
-h, --help display help for command
168169

lib/cli.js

+4
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ Options:
6060
--enforce-single-quotes surrounds all strings with single quotes
6161
--trim-trailing-commas omit trailing commas from objects and arrays
6262
--succeed-with-no-files succeed (exit code 0) if no files were found
63+
--immutable-string use immutable strings in parsing
6364
-v, --version output the version number
6465
-h, --help display help for command
6566
@@ -220,6 +221,9 @@ for (let i = 2, l = argv.length; i < l; ++i) {
220221
case 'succeed-with-no-files':
221222
params.succeedWithNoFiles = flag
222223
return
224+
case 'immutable-string':
225+
params.immutableString = flag;
226+
return;
223227
case 'v': case 'version':
224228
console.log(require('../package.json').version)
225229
process.exit(0)

src/custom-parser.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ function parseInternal (input, options) {
5757
const rawTokens = options.rawTokens
5858
const tokenLocations = options.tokenLocations
5959
const tokenPaths = options.tokenPaths
60+
const immutableString = options.immutableString
6061

6162
const isLineTerminator = json5 ? Uni.isLineTerminator : Uni.isLineTerminatorJSON
6263
const isWhiteSpace = json5 ? Uni.isWhiteSpace : Uni.isWhiteSpaceJSON
@@ -573,10 +574,14 @@ function parseInternal (input, options) {
573574
function parseString (endChar) {
574575
// 7.8.4 of ES262 spec
575576
let result = ''
577+
const startPosition = position
576578
while (position < inputLength) {
577579
let char = input[position++]
578580
if (char === endChar) {
579-
return result
581+
if (immutableString)
582+
return input.substr(startPosition, position - 1)
583+
else
584+
return result
580585
}if (char === '\\') {
581586
if (position >= inputLength) {
582587
fail()

0 commit comments

Comments
 (0)