Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

immutable string #33

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ Usage: `jsonlint [options] [--] [<file, directory, pattern> ...]`
--enforce-single-quotes surrounds all strings with single quotes
--trim-trailing-commas omit trailing commas from objects and arrays
--succeed-with-no-files succeed (exit code 0) if no files were found
--immutable-string use immutable strings in parsing
-v, --version output the version number
-h, --help display help for command

Expand Down
4 changes: 4 additions & 0 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Options:
--enforce-single-quotes surrounds all strings with single quotes
--trim-trailing-commas omit trailing commas from objects and arrays
--succeed-with-no-files succeed (exit code 0) if no files were found
--immutable-string use immutable strings in parsing
-v, --version output the version number
-h, --help display help for command

Expand Down Expand Up @@ -220,6 +221,9 @@ for (let i = 2, l = argv.length; i < l; ++i) {
case 'succeed-with-no-files':
params.succeedWithNoFiles = flag
return
case 'immutable-string':
params.immutableString = flag;
return;
case 'v': case 'version':
console.log(require('../package.json').version)
process.exit(0)
Expand Down
7 changes: 6 additions & 1 deletion src/custom-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ function parseInternal (input, options) {
const rawTokens = options.rawTokens
const tokenLocations = options.tokenLocations
const tokenPaths = options.tokenPaths
const immutableString = options.immutableString

const isLineTerminator = json5 ? Uni.isLineTerminator : Uni.isLineTerminatorJSON
const isWhiteSpace = json5 ? Uni.isWhiteSpace : Uni.isWhiteSpaceJSON
Expand Down Expand Up @@ -573,10 +574,14 @@ function parseInternal (input, options) {
function parseString (endChar) {
// 7.8.4 of ES262 spec
let result = ''
const startPosition = position
while (position < inputLength) {
let char = input[position++]
if (char === endChar) {
return result
if (immutableString)
return input.substr(startPosition, position - 1)
else
return result
}if (char === '\\') {
if (position >= inputLength) {
fail()
Expand Down