From 316bb96ba9194a8ff0926d2add09add6191dc33b Mon Sep 17 00:00:00 2001 From: Andy Bunce Date: Thu, 10 Aug 2023 22:50:15 +0100 Subject: [PATCH 1/3] [fix] querybody --- lib/xqdoc/xqdoc.js | 2 +- lib/xqlint.d.ts | 1 + package.json | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/xqdoc/xqdoc.js b/lib/xqdoc/xqdoc.js index a4436ff..e5421ff 100644 --- a/lib/xqdoc/xqdoc.js +++ b/lib/xqdoc/xqdoc.js @@ -127,7 +127,7 @@ exports.XQDoc = function (ast,sctx) { doc.functions.push(fnDecl); }); if(querybody){ - doc.querybody=querybody; + doc.queryBody=querybody; } return doc; }; diff --git a/lib/xqlint.d.ts b/lib/xqlint.d.ts index fec5007..bc4b4a2 100644 --- a/lib/xqlint.d.ts +++ b/lib/xqlint.d.ts @@ -37,6 +37,7 @@ declare module '@quodatum/xqlint' { description: string; variables: [VarDecl]; functions: [FunDecl]; + queryBody?: LintRange; } export interface VarDecl { name: string; diff --git a/package.json b/package.json index bd6f119..1d4f082 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Andy Bunce (https://github.com/apb2006)", "name": "@quodatum/xqlint", "description": "XQuery Quality Checker", - "version": "0.3.0", + "version": "0.3.1", "keywords": [ "xquery", "dev", From 59d52b85124b4097e21ad8b2d13d6317862cb7cd Mon Sep 17 00:00:00 2001 From: Andy Bunce Date: Sat, 12 Aug 2023 16:06:15 +0100 Subject: [PATCH 2/3] [fix] xqdoc #38 defaultfunctionnamespace --- CHANGELOG.md | 2 ++ lib/compiler/static_context.js | 10 ++++++---- lib/xqdoc/xqdoc.js | 21 ++++++++++----------- package-lock.json | 18 +++++++++--------- package.json | 2 +- test/features/xqdoc.js | 1 + test/parser_test.js | 5 +++-- 7 files changed, 32 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 167e752..215e9f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +## [0.3.2] 2023-08-12 + ## [0.3.0] 2023-08-10 * [mod] use xq-catalogs for module library handling * [fix] xq outline diff --git a/lib/compiler/static_context.js b/lib/compiler/static_context.js index 96c7f22..fce33c6 100644 --- a/lib/compiler/static_context.js +++ b/lib/compiler/static_context.js @@ -3,7 +3,7 @@ const xqc = require('@quodatum/xq-catalogs'); // convert array to object representation function keyed(arr) { - if(!Array.isArray(arr)){return arr;} + if (!Array.isArray(arr)) { return arr; } const obj = {}; arr.forEach(f => obj[f.key] = f); return obj; @@ -239,7 +239,7 @@ exports.StaticContext = function (parent, pos, processor) { try { var mod = this.moduleResolver(uri, ats); if (mod.variables) { - TreeOps.concat(this.variables,keyed( mod.variables)); + TreeOps.concat(this.variables, keyed(mod.variables)); } if (mod.functions) { TreeOps.concat(this.functions, keyed(mod.functions)); @@ -349,7 +349,7 @@ exports.StaticContext = function (parent, pos, processor) { } }, - // find uri from prefix if required + // find uri from prefix if required note does NOT resolve defaultfunctionnamespace resolveQName: function (value, pos) { var qname = { uri: '', @@ -494,7 +494,9 @@ exports.StaticContext = function (parent, pos, processor) { ) { throw new StaticError('XQST0048', '"' + qname.prefix + ':' + qname.name + '": Qname not library namespace', pos); } - if (qname.uri === '') { qname.uri = this.defaultFunctionNamespace; } + if (qname.uri === '') { + qname.uri = this.defaultFunctionNamespace; + } var key = getFnKey(qname, arity); if (this.functions[key]) { throw new StaticError('XQST0034', '"' + qname.name + '": duplicate function declaration', pos); diff --git a/lib/xqdoc/xqdoc.js b/lib/xqdoc/xqdoc.js index e5421ff..a17d3e7 100644 --- a/lib/xqdoc/xqdoc.js +++ b/lib/xqdoc/xqdoc.js @@ -13,7 +13,7 @@ exports.XQDoc = function (ast,sctx) { const comments={}; // keyed as fn/vars const lintRanges={}; // keyed as fn/vars var prefix=null; - var querybody=null; // caputure pos if present + var querybody=null; // capture pos if present this.WS = function (node) { if (node.value.trim().substring(0, 3) === '(:~') { lastComment=parseComment(node.value); @@ -36,7 +36,7 @@ exports.XQDoc = function (ast,sctx) { comments[key]=lastComment; lastComment=null; } - lintRanges[key]=node.getParent.pos; + lintRanges[key]={type: "VarDecl", pos:node.getParent.pos}; // console.log("VarDecl: ",value,", pos: ",node.pos,", comments: ",node.getParent.comments) }; @@ -44,6 +44,9 @@ exports.XQDoc = function (ast,sctx) { var fnname = this.getFirstChild(node, 'EQName'); var value = TreeOps.flatten(fnname); var qname = sctx.resolveQName(value, fnname.pos); + if(qname.uri===""){ + qname.uri=sctx.defaultFunctionNamespace; + } var arity="0"; var params = this.getFirstChild(node, 'ParamList'); if(params){ @@ -58,7 +61,7 @@ exports.XQDoc = function (ast,sctx) { comments[key]=lastComment; lastComment=null; } - lintRanges[key]=node.getParent.pos; // save range of enclosing declaration + lintRanges[key]={type:"FunctionDecl",pos:node.getParent.pos}; // save range of enclosing declaration //console.log("FunctionDecl: ",value,", pos: ",node.pos,", comments: ",node.getParent.comments) }; @@ -75,7 +78,7 @@ exports.XQDoc = function (ast,sctx) { }; // main module,xq not xqm this.QueryBody=function(node){ - console.log("QueryBody"); + //console.log("QueryBody"); querybody=node.pos; }; @@ -89,7 +92,7 @@ exports.XQDoc = function (ast,sctx) { }; if(comments.module){doc.description=comments.module.description;} - Object.keys(sctx.variables).forEach((key) => { + Object.keys(lintRanges).filter(k=>lintRanges[k].type==='VarDecl').forEach((key)=>{ var variable = sctx.variables[key]; var varDecl = {... variable.qname}; //name,prefix,uri varDecl.key = key; @@ -103,11 +106,7 @@ exports.XQDoc = function (ast,sctx) { doc.variables.push(varDecl); }); - Object.keys(sctx.functions).forEach((key) => { - const ns=key.substring(0, key.indexOf("#")); - if (ns === 'http://www.w3.org/2001/XMLSchema') { - return; - } + Object.keys(lintRanges).filter(k=>lintRanges[k].type==='FunctionDecl').forEach((key)=>{ var fn = sctx.functions[key]; //console.log("fn-key:",key) var tokens = key.split('#'); @@ -133,7 +132,7 @@ exports.XQDoc = function (ast,sctx) { }; this.setPos = function (decl, key, pos) { decl.pos = pos; - var full = lintRanges[key]; + var full = lintRanges[key].pos; decl.posAll = full; }; this.visit = function (node) { diff --git a/package-lock.json b/package-lock.json index 04e6438..e6ec0d2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@quodatum/xqlint", - "version": "0.2.5", + "version": "0.3.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@quodatum/xqlint", - "version": "0.2.5", + "version": "0.3.2", "license": "Apache-2.0", "dependencies": { "@quodatum/xq-catalogs": "^0.0.5", @@ -2498,9 +2498,9 @@ } }, "node_modules/is-core-module": { - "version": "2.12.1", - "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.12.1.tgz", - "integrity": "sha512-Q4ZuBAe2FUsKtyQJoQHlvP8OvBERxO3jEmy1I7hcRXcJBGGHFh/aJBswbXuS9sgrDH2QUO8ilkwNPHvHMd8clg==", + "version": "2.13.0", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.13.0.tgz", + "integrity": "sha512-Z7dk6Qo8pOCp3l4tsX2C5ZVas4V+UxwQodwZhLopL91TX8UyyHEXafPcyoeeWuLrwzHcr3igO78wNLwHJHsMCQ==", "dev": true, "dependencies": { "has": "^1.0.3" @@ -3823,12 +3823,12 @@ } }, "node_modules/resolve": { - "version": "1.22.2", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.2.tgz", - "integrity": "sha512-Sb+mjNHOULsBv818T40qSPeRiuWLyaGMa5ewydRLFimneixmVy2zdivRl+AF6jaYPC8ERxGDmFSiqui6SfPd+g==", + "version": "1.22.4", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.4.tgz", + "integrity": "sha512-PXNdCiPqDqeUou+w1C2eTQbNfxKSuMxqTCuvlmmMsk1NWHL5fRrhY6Pl0qEYYc6+QqGClco1Qj8XnjPego4wfg==", "dev": true, "dependencies": { - "is-core-module": "^2.11.0", + "is-core-module": "^2.13.0", "path-parse": "^1.0.7", "supports-preserve-symlinks-flag": "^1.0.0" }, diff --git a/package.json b/package.json index 1d4f082..8c20458 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Andy Bunce (https://github.com/apb2006)", "name": "@quodatum/xqlint", "description": "XQuery Quality Checker", - "version": "0.3.1", + "version": "0.3.2", "keywords": [ "xquery", "dev", diff --git a/test/features/xqdoc.js b/test/features/xqdoc.js index dbaf67e..358bcb8 100644 --- a/test/features/xqdoc.js +++ b/test/features/xqdoc.js @@ -4,6 +4,7 @@ var fs = require('fs'); var XQLint = require('../../lib/xqlint').XQLint; //var src="test/queries/rbtree.xq/map.xq"; var src="test/queries/issues/pic-datefix.xq"; +//var src="test/queries/rbtree.xq/rbtree.xq"; //src="cases\history.xqm"; var linter = new XQLint(fs.readFileSync(src, 'utf-8')); // .hasSyntaxError() diff --git a/test/parser_test.js b/test/parser_test.js index bf73fae..f220e50 100644 --- a/test/parser_test.js +++ b/test/parser_test.js @@ -29,8 +29,9 @@ var files = getFiles('test/queries/basex'); files = files.concat(getFiles('test/queries/update')); files.forEach(function(file){ batch[file] = function(){ - //@todo processor: ? - var linter = new XQLint(fs.readFileSync(file, 'utf-8'), { styleCheck: false, fileName: file, processor: 'basex-9' }); + const src=fs.readFileSync(file, 'utf-8'); + //console.log(file); + var linter = new XQLint(src, { styleCheck: false, fileName: file, processor: 'basex-9' }); var syntaxError = linter.hasSyntaxError(); if(syntaxError) { assert.equal(syntaxError, false, linter.getMarkers()[0].message); From aabf04aff5cbeef347ad615069dea467da9f7353 Mon Sep 17 00:00:00 2001 From: Andy Bunce Date: Sat, 12 Aug 2023 16:08:45 +0100 Subject: [PATCH 3/3] [mod] changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 215e9f3..d93eabb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ ## [0.3.2] 2023-08-12 - +* [fix] defaultfunction namespace issue #38 ## [0.3.0] 2023-08-10 * [mod] use xq-catalogs for module library handling * [fix] xq outline