@@ -9,12 +9,14 @@ class Literal extends Node {
99 super ( )
1010 this . termType = Literal . termType
1111 this . value = value
12- this . lang = language || ''
1312 if ( language ) {
13+ this . lang = language
1414 datatype = XSD . langString
1515 }
1616 // If not specified, a literal has the implied XSD.string default datatype
17- this . datatype = NamedNode . fromValue ( datatype ) || XSD . string
17+ if ( datatype ) {
18+ this . datatype = NamedNode . fromValue ( datatype )
19+ }
1820 }
1921 copy ( ) {
2022 return new Literal ( this . value , this . lang , this . datatype )
@@ -29,14 +31,6 @@ class Literal extends Node {
2931 ( ( ! this . datatype && ! other . datatype ) ||
3032 ( this . datatype && this . datatype . equals ( other . datatype ) ) )
3133 }
32- /**
33- * Returns whether or not this literal has a language explicitly set.
34- * Used by various serialization methods.
35- * @returns {Boolean }
36- */
37- hasLanguage ( ) {
38- return this . lang && this . lang !== ''
39- }
4034 get language ( ) {
4135 return this . lang
4236 }
@@ -56,11 +50,11 @@ class Literal extends Node {
5650 str = str . replace ( / \n / g, '\\n' )
5751 str = '"' + str + '"'
5852
59- if ( this . hasLanguage ( ) ) {
53+ if ( this . language ) {
6054 str += '@' + this . language
6155 } else if ( ! this . datatype . equals ( XSD . string ) ) {
6256 // Only add datatype if it's not a string
63- str += '^^' + this . datatype . toNT ( )
57+ str += '^^' + this . datatype . toCanonical ( )
6458 }
6559 return str
6660 }
@@ -147,6 +141,7 @@ class Literal extends Node {
147141Literal . termType = 'Literal'
148142Literal . prototype . classOrder = ClassOrder [ 'Literal' ]
149143Literal . prototype . datatype = XSD . string
144+ Literal . prototype . lang = ''
150145Literal . prototype . isVar = 0
151146
152147module . exports = Literal
0 commit comments