d3x0r / JSON6

JSON for Humans (ES6)
Other
236 stars 14 forks source link

Parse produces incorrect results. #9

Closed jdalton closed 6 years ago

jdalton commented 6 years ago

On version json-6@0.1.123 if you JSON6.parse this file https://github.com/standard-things/esm/blob/master/package.json it will incorrectly produce objects:

'test:prod':
   { 'prebuild:prod': 'optional-dev-dependency',
     prelint: 'npm run pretest',
     prepub: 'npm run test:prod',
     pretest: 'npm run build -- --test',
     'pretest:prod': 'npm run build:prod -- --test',
     build: 'node script/build.js',
     'build:prod': 'npm run build -- --prod',
     clean: 'node script/clean.js',
     lint: 'eslint \'**/*.{js,mjs}\' --fix --quiet',
     pub: 'node script/publish.js',
     test: 'node script/test.js',
     'test:prod': 'node script/test.js --prod' },

and

  yargs:
   { '@babel/core': '^7.0.0-beta.34',
     '@babel/plugin-proposal-class-properties': '^7.0.0-beta.34',
     '@babel/plugin-transform-block-scoping': '^7.0.0-beta.34',
     '@babel/preset-env': '^7.0.0-beta.34',
     '@babel/register': '^7.0.0-beta.34',
     acorn: '^5.2.1',
     ava: '^0.24.0',
     'babel-eslint': '^8.0.3',
     'babel-loader': '^8.0.0-beta.0',
     'babel-plugin-transform-for-of-as-array': '^1.0.4',
     download: '^6.2.5',
     eslint: '^4.12.0',
     'eslint-plugin-import': '^2.7.0',
     'eslint-plugin-node': '^5.2.0',
     execa: '^0.8.0',
     'fs-extra': '^4.0.3',
     globby: '^7.1.1',
     husky: '^0.14.3',
     jest: '^21.2.1',
     'json-6': '^0.1.120',
     minizlib: '^1.0.4',
     mocha: '^4.0.1',
     'mock-stdio': '^1.0.0',
     nop: '^1.0.0',
     nyc: '^11.3.0',
     'optimize-js-plugin': '0.0.4',
     'optional-dev-dependency': '^2.0.1',
     pify: '^3.0.0',
     pm2: '^2.8.0',
     semver: '^5.4.1',
     trash: '^4.2.1',
     typescript: '^2.6.1',
     'uglify-es': '^3.2.1',
     'uglifyjs-webpack-plugin': '^1.1.1',
     webpack: '^3.10.0',
     'webpack-bundle-analyzer': '^2.8.3',
     'webpack-common-shake': '^1.5.3',
     yargs: '^10.0.3' },

when there is no such structures in the actual JSON.

It looks like json-6 is glitching and turning the last key in the scripts and devDependencies objects into other objects. In the case of the example 'test:prod' and 'yargs'.

d3x0r commented 6 years ago

Oh that sample one sec.

jdalton commented 6 years ago

Try:

const pkgJSON = JSON6.parse(fs.readFileSync("./path/to/package.json"))
d3x0r commented 6 years ago

Ya I see now... pushed/published 0.1.124 (test)[https://github.com/d3x0r/JSON6/blob/master/tests/json6TestObject2.js]

jdalton commented 6 years ago

Thank you!

d3x0r commented 6 years ago

Was testing performance and found that 'let' can cause deoptimizations. FIxed to restore performance over json5.

jdalton commented 6 years ago

It looks like from your patch you added more lets?

d3x0r commented 6 years ago

kinda; the one that was really causing problems was like case (something): let... and putting brackets around that one solved it, but putting bracked around others didn't.. I was experimenting with adding more... and a few seemed to be benefictial (going from like 1732ms to 1670ms) so I left them in; although that's probably just jitter.