Skip to content

Commit

Permalink
Improve uniformity with ES6.
Browse files Browse the repository at this point in the history
  • Loading branch information
RubenVerborgh committed Aug 10, 2024
1 parent 19a7475 commit 94ab8a9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
5 changes: 4 additions & 1 deletion lib/SparqlGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ function mapJoin(array, sep, func, self) {
* newline: string
* }
*/
module.exports = function SparqlGenerator(options = {}) {
function _Generator(options = {}) {
return {
stringify: function (query) {
var currentOptions = Object.create(options);
Expand All @@ -457,3 +457,6 @@ module.exports = function SparqlGenerator(options = {}) {
createGenerator: function() { return new Generator(options); }
};
};
module.exports = {
Generator: _Generator,
};
28 changes: 18 additions & 10 deletions sparql.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var Parser = require('./lib/SparqlParser').Parser;
var Generator = require('./lib/SparqlGenerator');
var Wildcard = require("./lib/Wildcard").Wildcard;
var { DataFactory } = require('rdf-data-factory');
const { Parser } = require('./lib/SparqlParser');
const { Generator } = require('./lib/SparqlGenerator');
const { Wildcard } = require('./lib/Wildcard');
const { DataFactory } = require('rdf-data-factory');

/**
* Creates a SPARQL parser with the given pre-defined prefixes and base IRI
Expand All @@ -14,15 +14,23 @@ var { DataFactory } = require('rdf-data-factory');
* skipUngroupedVariableCheck?: boolean
* }
*/
var _Parser = function ({ prefixes, baseIRI, factory, sparqlStar, skipValidation, skipUngroupedVariableCheck, pathOnly } = {}) {
function _Parser({
prefixes,
baseIRI,
factory,
pathOnly,
sparqlStar,
skipValidation,
skipUngroupedVariableCheck,
} = {}) {
// Create a copy of the prefixes
var prefixesCopy = {};
for (var prefix in prefixes || {})
const prefixesCopy = {};
for (const prefix in prefixes ?? {})
prefixesCopy[prefix] = prefixes[prefix];

// Create a new parser with the given prefixes
// (Workaround for https://github.com/zaach/jison/issues/241)
var parser = new Parser();
const parser = new Parser();
parser.parse = function () {
Parser.base = baseIRI || '';
Parser.prefixes = Object.create(prefixesCopy);
Expand All @@ -39,6 +47,6 @@ var _Parser = function ({ prefixes, baseIRI, factory, sparqlStar, skipValidation

module.exports = {
Parser: _Parser,
Generator: Generator,
Wildcard: Wildcard,
Generator,
Wildcard,
};

0 comments on commit 94ab8a9

Please sign in to comment.