Skip to content

Commit

Permalink
Explicitly assign xsd:string as literal default datatype
Browse files Browse the repository at this point in the history
This has a few advantages:
* Makes rdflib.js comply with the rdfjs task force definition (http://rdf.js.org/#literal-interface)
* Makes behaviour consistent with the new `Term.literalByValue` implementation
* Downstream can use switch without additional undefined and null checking

We now only have one instance of xsd:string, so the overhead is only a
reference rather than an entire object for each literal.
  • Loading branch information
Fletcher91 committed Nov 13, 2018
1 parent 330d4f3 commit 265c189
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions src/literal.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ class Literal extends Term {
datatype = XSD.langString
}
// If not specified, a literal has the implied XSD.string default datatype
if (datatype) {
this.datatype = NamedNode.fromValue(datatype)
}
this.datatype = datatype ? NamedNode.fromValue(datatype) : XSD.string
}
copy () {
return Term.literalByValue(this.value, this.lang, this.datatype)
Expand Down

0 comments on commit 265c189

Please sign in to comment.