Skip to content

Instantly share code, notes, and snippets.

@rbuckton
Forked from fitzgen/gist:35d7e3905a915238aa14
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rbuckton/02048395a8dd1330b29a to your computer and use it in GitHub Desktop.
Save rbuckton/02048395a8dd1330b29a to your computer and use it in GitHub Desktop.
Proposal for addition of MediaTypes to the Source Map spec.

Proposed Format

/* 1.*/  {
/* 2.*/    "version": 3,
/* 3.*/    "file": "out.js",
/* 4.*/    "sourceRoot": "",
/* 5.*/    "sources": ["foo.js", "bar.ts"],
/* 6.*/    "sourcesContent": [null, null],
/* 7.*/    "names": ["src", "maps", "are", "fun"],
/* 8.*/    "mappings": "A,AAAB;;ABCDE;",
/* 9.*/    "mediaTypes": ["application/javascript", "application/x.typescript;version=1.0.1.0"],
/*10.*/    "sourcesMediaTypes": [0, 1]
/*11.*/  }

Line 9: An optional array containing the set of each media type M such that there is a source whose associated media media type is M in the "sources" property. Media types must conform to https://www.rfc-editor.org/rfc/rfc6838.txt.

Line 10: An optional array whose elements correspond to a value in the "sources" property with the same ordinal index, and whose values are integers greater than or equal to 0 and represent an index of a media type in the "mediaTypes" property. The number of integers in the array must not exceed the length of the "sources" property. If there are fewer elements in the "sourceMediaTypes" property than the number of elements in the "sources" property, the last media type index should be used for the remaining sources. If all sources share the same media type, this property may be elided and the default value 0 should be used for all remaining sources.

To find a source S's associated media type:

  1. If the "mediaTypes" property does not exist, or is null or undefined,
    1. Return undefined.
  2. Let mediaTypeIndex be 0.
  3. If the "sourcesMediaTypes" property exists and is an array,
    1. Let sourceMediaTypeIndex be the index of S in the "sources" property.
    2. Let sourcesMediaTypesLength be the length of the "sourcesMediaTypes" property.
    3. If sourceMediaTypeIndex >= sourcesMediaTypesLength,
      1. Let sourceMediaTypeIndex be sourcesMediaTypesLength - 1.
    4. Let mediaTypeIndex be the integer at sourceMediaTypeIndex of the "sourcesMediaTypes" property.
  4. Let mediaTypesLength be the length of the "mediaTypes" property.
  5. If mediaTypeIndex >= mediaTypesLength,
    1. Let mediaTypeIndex = mediaTypesLength - 1.
  6. Return the media type at mediaTypeIndex of the "mediaTypes" property.

Note that in the above algorithm, lists of size N are indexed from 0 to N-1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment