From aab9f16f9ce8d5ab42e80c789859c7aaf217bd22 Mon Sep 17 00:00:00 2001 From: Jared Jurkiewicz Date: Mon, 30 Jun 2014 08:38:35 -0400 Subject: [PATCH] Convert abandoned dojox/jsonPath to full AMD. fixes: #18055 --- dojox.profile.js | 1 - jsonPath.js | 6 +- jsonPath/query.js | 367 +++++++++++++++++++++++++++------------------- 3 files changed, 224 insertions(+), 150 deletions(-) diff --git a/dojox.profile.js b/dojox.profile.js index 427e26bee0..5dfacf5fee 100644 --- a/dojox.profile.js +++ b/dojox.profile.js @@ -23,7 +23,6 @@ var profile = (function(){ "help", "image/(Gallery|SlideShow|ThumbnailPicker)", "jq", - "jsonPath/query", "lang/(aspect|async|docs|observable|oo|typed|functional/(binrec|curry|linrec|listcomp|multirec|numrec|tailrec|util|zip))", "layout/(BorderContainer|dnd|ext-dijit)", "mobile/app/", diff --git a/jsonPath.js b/jsonPath.js index 8956807176..b16ecf56b9 100644 --- a/jsonPath.js +++ b/jsonPath.js @@ -1,4 +1,6 @@ -define(['./jsonPath/query'],function(){ +define(["dojo/_base/kernel", + "./jsonPath/query" +],function(kernel, query){ /*===== return { // summary: @@ -6,4 +8,6 @@ define(['./jsonPath/query'],function(){ // this module. }; =====*/ + kernel.deprecated("dojox/jsonPath: The dojox/jsonPath root module is deprecated, use dojox/jsonPath/query", "", "2.0"); + return {query: query}; }); diff --git a/jsonPath/query.js b/jsonPath/query.js index c893bf11f3..84da5daeed 100644 --- a/jsonPath/query.js +++ b/jsonPath/query.js @@ -1,164 +1,235 @@ -dojo.provide("dojox.jsonPath.query"); +define(["dojo/_base/kernel", + "dojo/_base/lang" +], function(kernel, lang){ + var query = function( /*Object*/ obj, /*String*/ expr, /*Object*/ arg){ + // summary: + // Perform jsonPath query `expr` on javascript object or json string `obj` + // obj: + // object || json string to perform query on + // expr: + // jsonPath expression (string) to be evaluated + // arg: + // {} special arguments. + // + // - resultType: "VALUE"||"BOTH"||"PATH"} (defaults to value) + // - evalType: "RESULT"||"ITEM"} (defaults to ?) -dojox.jsonPath.query = function(/*Object*/ obj, /*String*/ expr, /*Object*/ arg){ - // summary: - // Perform jsonPath query `expr` on javascript object or json string `obj` - // obj: - // object || json string to perform query on - // expr: - // jsonPath expression (string) to be evaluated - // arg: - // {} special arguments. - // - // - resultType: "VALUE"||"BOTH"||"PATH"} (defaults to value) - // - evalType: "RESULT"||"ITEM"} (defaults to ?) + if(!arg){ + arg = {}; + } - var re = dojox.jsonPath._regularExpressions; - if (!arg){arg={};} + var strs = []; - var strs = []; - function _str(i){ return strs[i];} - var _strName = _str.name; - var acc; - if (arg.resultType == "PATH" && arg.evalType == "RESULT") throw Error("RESULT based evaluation not supported with PATH based results"); - var P = { - resultType: arg.resultType || "VALUE", - normalize: function(expr){ - var subx = []; - expr = expr.replace(/'([^']|'')*'/g, function(t){return _strName + "("+(strs.push(eval(t))-1)+")";}); - var ll = -1; - while(ll!=subx.length){ - ll=subx.length;//TODO: Do expression syntax checking - expr = expr.replace(/(\??\([^\(\)]*\))/g, function($0){return "#"+(subx.push($0)-1);}); - } - expr = expr.replace(/[\['](#[0-9]+)[\]']/g,'[$1]') - .replace(/'?\.'?|\['?/g, ";") - .replace(/;;;|;;/g, ";..;") - .replace(/;$|'?\]|'$/g, ""); - ll = -1; - while(ll!=expr){ - ll=expr; - expr = expr.replace(/#([0-9]+)/g, function($0,$1){return subx[$1];}); - } - return expr.split(";"); - }, - asPaths: function(paths){ - for (var j=0;j