var util = require('util'),
    extendWithGettersAndSetters = require('../util/extendWithGettersAndSetters'),
    Relation = require('./Relation');

function CssSourceMappingUrl(config) {
    Relation.call(this, config);
}

util.inherits(CssSourceMappingUrl, Relation);

extendWithGettersAndSetters(CssSourceMappingUrl.prototype, {
    get href() {
        return this.node.text.match(/[@#]\s*sourceMappingURL=([^\s]*)/)[1];
    },

    set href(href) {
        this.node.text = this.node.text.replace(/([@#]\s*sourceMappingURL=)[^\s]*/, '$1' + href);
    },

    inline: function () {
        Relation.prototype.inline.call(this);
        this.href = this.to.dataUrl;
        this.from.markDirty();
        return this;
    },

    attach: function (asset, position, adjacentRelation) {
        if (position !== 'last') {
            throw new Error('CssSourceMappingUrl.attach(): Only position === \'last\' is supported');
        }
        var parseTree = asset.parseTree;
        parseTree.append({ type: 'comment', text: '# sourceMappingURL=' });
        this.node = parseTree.nodes[parseTree.nodes.length - 1];
        return Relation.prototype.attach.call(this, asset, position, adjacentRelation);
    },

    detach: function () {
        this.node.parent.removeChild(this.node);
        this.node = undefined;
        return Relation.prototype.detach.call(this);
    }
});

module.exports = CssSourceMappingUrl;

@@ -998,34 +998,11 @@
 end(
-%7B type: 'comment', text: '
+'/*
 # so
@@ -1020,11 +1020,11 @@
 URL=
-' %7D
+*/'
 );%0A 

Add the comment in a way so that postcss sets up the prev/next/parent pointers correctly (?).