def encode_sourcemap(filename, mappings, sources, names=[]):
    """
    Take a filename, mappings and names produced from the write function
    and sources.  As the write function currently does not handle the
    tracking of source filenames, the sources should be a list of one
    element with the original filename.

    Arguments

    filename
        The target filename that the stream was or to be written to.
        The stream being the argument that was supplied to the write
        function
    mappings
        The raw unencoded mappings produced by write, which is returned
        as its second element.
    sources
        List of original source filenames.  When used in conjunction
        with the above write function, it should be a list of one item,
        being the path to the original filename.
    names
        The list of original names generated by write, which is returned
        as its first element.

    Returns a dict which can be JSON encoded into a sourcemap file.

    Example usage:

    >>> from io import StringIO
    >>> from calmjs.parse import es5
    >>> from calmjs.parse.unparsers.es5 import pretty_printer
    >>> from calmjs.parse.sourcemap import write, encode_sourcemap
    >>> program = es5(u"var i = 'hello';")
    >>> stream = StringIO()
    >>> printer = pretty_printer()
    >>> sourcemap = encode_sourcemap(
    ...     'demo.min.js', *write(printer(program), stream))
    """

    return {
        "version": 3,
        "sources": sources,
        "names": names,
        "mappings": encode_mappings(mappings),
        "file": filename,
    }
Take a filename, mappings and names produced from the write function
    and sources.  As the write function currently does not handle the
    tracking of source filenames, the sources should be a list of one
    element with the original filename.

    Arguments

    filename
        The target filename that the stream was or to be written to.
        The stream being the argument that was supplied to the write
        function
    mappings
        The raw unencoded mappings produced by write, which is returned
        as its second element.
    sources
        List of original source filenames.  When used in conjunction
        with the above write function, it should be a list of one item,
        being the path to the original filename.
    names
        The list of original names generated by write, which is returned
        as its first element.

    Returns a dict which can be JSON encoded into a sourcemap file.

    Example usage:

    >>> from io import StringIO
    >>> from calmjs.parse import es5
    >>> from calmjs.parse.unparsers.es5 import pretty_printer
    >>> from calmjs.parse.sourcemap import write, encode_sourcemap
    >>> program = es5(u"var i = 'hello';")
    >>> stream = StringIO()
    >>> printer = pretty_printer()
    >>> sourcemap = encode_sourcemap(
    ...     'demo.min.js', *write(printer(program), stream))