Integrated jsonlint

This commit is contained in:
jos 2016-09-30 16:42:04 +02:00
parent 5fc5e302dc
commit adb3c6bdd9
5 changed files with 296 additions and 289 deletions

View File

@ -11,6 +11,7 @@ var NAME_MINIMALIST = 'jsoneditor-minimalist';
var ENTRY = './src/index.js';
var HEADER = './src/header.js';
var DIST = './dist';
var EMPTY = __dirname + '/src/utils/empty.js'
// generate banner with today's date and correct version
function createBanner() {
@ -69,9 +70,9 @@ var compilerMinimalist = webpack({
},
plugins: [
bannerPlugin,
new webpack.IgnorePlugin(new RegExp('^brace$')),
new webpack.IgnorePlugin(new RegExp('^ajv')),
new webpack.IgnorePlugin(new RegExp('jsonlint$')),
new webpack.NormalModuleReplacementPlugin(new RegExp('^brace$'), EMPTY),
new webpack.NormalModuleReplacementPlugin(new RegExp('^ajv'), EMPTY),
new webpack.NormalModuleReplacementPlugin(new RegExp('jsonlint$'), EMPTY),
new webpack.optimize.UglifyJsPlugin() // TODO: don't minify when watching
],
module: {

View File

@ -23,18 +23,18 @@
"test": "ava test/*.test.js test/**/*.test.js --verbose"
},
"dependencies": {
"ajv": "4.7.0",
"ajv": "4.7.5",
"brace": "0.8.0",
"javascript-natural-sort": "0.7.1",
"lodash": "4.15.0",
"preact": "6.0.2"
"lodash": "4.16.2",
"preact": "6.1.0"
},
"devDependencies": {
"ava": "0.16.0",
"babel-core": "6.14.0",
"babel-core": "6.16.0",
"babel-loader": "6.2.5",
"babel-preset-stage-2": "6.13.0",
"babel-preset-stage-3": "6.11.0",
"babel-preset-stage-2": "6.16.0",
"babel-preset-stage-3": "6.16.0",
"css-loader": "0.25.0",
"gulp": "3.9.1",
"gulp-shell": "0.5.2",

View File

@ -1,5 +1,8 @@
/* Jison generated parser */
var jsonlint = (function(){
/*
* Jison generated parser
* Refactored into an ES6 module
**/
export var parser = (function(){
var parser = {trace: function trace() { },
yy: {},
symbols_: {"error":2,"JSONString":3,"STRING":4,"JSONNumber":5,"NUMBER":6,"JSONNullLiteral":7,"NULL":8,"JSONBooleanLiteral":9,"TRUE":10,"FALSE":11,"JSONText":12,"JSONValue":13,"EOF":14,"JSONObject":15,"JSONArray":16,"{":17,"}":18,"JSONMemberList":19,"JSONMember":20,":":21,",":22,"[":23,"]":24,"JSONElementList":25,"$accept":0,"$end":1},
@ -407,12 +410,11 @@ lexer.rules = [/^(?:\s+)/,/^(?:(-?([0-9]|[1-9][0-9]+))(\.[0-9]+)?([eE][-+]?[0-9]
lexer.conditions = {"INITIAL":{"rules":[0,1,2,3,4,5,6,7,8,9,10,11,12,13],"inclusive":true}};
;
return lexer;})()
return lexer;
})()
parser.lexer = lexer;
return parser;
})();
if (typeof require !== 'undefined' && typeof exports !== 'undefined') {
exports.parser = jsonlint;
exports.parse = jsonlint.parse.bind(jsonlint);
}
export var parse = parser.parse.bind(parser);

1
src/utils/empty.js Normal file
View File

@ -0,0 +1 @@
// This file is used to replace excluded dependencies with an empty placeholder

View File

@ -1,7 +1,4 @@
// TODO: import jsonlint globally
//import '../assets/jsonlint/jsonlint'
let jsonlint = require('../assets/jsonlint/jsonlint')
/**
* Parse JSON using the parser built-in in the browser.
@ -31,10 +28,16 @@ export function parseJSON(jsonString) {
* @throws Error
*/
export function validate(jsonString) {
if (typeof(window.jsonlint) !== 'undefined') {
if (jsonlint && jsonlint.parse) {
// use embedded jsonlint
jsonlint.parse(jsonString)
}
else if (window.jsonlint && window.jsonlint.parse) {
// use global jsonlint
window.jsonlint.parse(jsonString)
}
else {
// don't use jsonlint
JSON.parse(jsonString)
}
}