Repository: postcss/postcss (ts)

Issue:
Problem with source map detection in previous-map.es6
Hi i add autoprefixer-loader to my webpack config and get `Unsupported previous source map format` error. I traced problem to line: https://github.com/postcss/postcss/blob/master/lib/previous-map.es6#L70 and looks like it tests `mappings` when in internal sourcemap representation this prop called `_mappings`, so looks like we need to test `_mappings` too, or test mappings after `JSON.parse(JSON.stringify(...))`
Or can some1 who knows source map internal kitchen suggest some better decision?

Pull request:
Detect source-maps created by mozilla/source-map fix #583
All motivation in ticket #583

Patch:
diff --git a/.yaspellerrc b/.yaspellerrc
index dcf486f1..0b194aa6 100644
--- a/.yaspellerrc
+++ b/.yaspellerrc
@@ -120,7 +120,6 @@
     "js",
     "vs",
     "pantone",
-    "YIQ",
-    "gitter"
+    "YIQ"
   ]
 }
diff --git a/README.md b/README.md
index d1c0eb03..d32afd72 100644
--- a/README.md
+++ b/README.md
@@ -18,8 +18,6 @@ But PostCSS is modular, 3-30 times faster, and much more powerful.
 Twitter account: [@postcss](https://twitter.com/postcss).
 VK.com page:     [postcss](https://vk.com/postcss).
 
-Support / Discussion: [gitter](https://gitter.im/postcss/postcss).
-
 [appveyor-img]: https://img.shields.io/appveyor/ci/ai/postcss.svg?label=windows
 [travis-img]:   https://img.shields.io/travis/postcss/postcss.svg?label=unix
 [chat-img]:     https://img.shields.io/badge/Gitter-Join_the_PostCSS_chat-brightgreen.svg
@@ -239,7 +237,6 @@ Or enable plugins directly in CSS using [`postcss-use`]:
   to special annotation comments.
 * [`cssnano`] contains plugins that optimize CSS size for use in production.
 * [`cssnext`] contains plugins that allow you to use future CSS features today.
-* [`oldie`] contains plugins that transform your CSS for older Internet Explorer compatibility.
 * [`precss`] contains plugins that allow you to use Sass-like CSS.
 * [`rucksack`] contains plugins to speed up CSS development
   with new features and shortcuts.
@@ -250,7 +247,6 @@ Or enable plugins directly in CSS using [`postcss-use`]:
 [`rucksack`]:  http://simplaio.github.io/rucksack
 [`cssnano`]:   http://cssnano.co/
 [`cssnext`]:   http://cssnext.io/
-[`oldie`]:     https://github.com/jonathantneal/oldie
 [`precss`]:    https://github.com/jonathantneal/precss
 [`atcss`]:     https://github.com/morishitter/atcss
 
@@ -435,10 +431,6 @@ See also plugins in modular minifier [`cssnano`].
 * [`postcss-property-lookup`] allows referencing property values without
   a variable.
 * [`postcss-responsive-type`] changes `font-size` depends on screen size.
-* [`postcss-short-font-size`] extends `font-size` to define line-height as a second value.
-* [`postcss-short-position`] extends `position` to define edges as additional values.
-* [`postcss-short-spacing`] extends `margin` and `padding` to allow for omitted edges.
-* [`postcss-short-text`] adds a `text` shortcut property for several text-related properties.
 * [`postcss-size`] adds a `size` shortcut that sets width and height
   with one declaration.
 * [`postcss-transform-shortcut`] allows shorthand transform properties in CSS.
@@ -463,7 +455,6 @@ See also plugins in modular minifier [`cssnano`].
 * [`postcss-pseudo-content-insert`] adds `content: ''` to `:before` and `:after`
   if it is missing.
 * [`postcss-pxtorem`] converts pixel units to `rem`.
-* [`postcss-shorthand-expand`] expands shorthand properties.
 * [`postcss-remove-prefixes`] removes vendor prefixes.
 * [`postcss-style-guide`] generates a style guide automatically.
 * [`postcss-scopify`] adds a user input scope to each selector.
@@ -532,7 +523,6 @@ See also plugins in modular minifier [`cssnano`].
 [`postcss-quantity-queries`]:        https://github.com/pascalduez/postcss-quantity-queries
 [`postcss-browser-reporter`]:        https://github.com/postcss/postcss-browser-reporter
 [`postcss-selector-matches`]:        https://github.com/postcss/postcss-selector-matches
-[`postcss-shorthand-expand`]:        https://github.com/johnotander/postcss-shorthand-expand
 [`postcss-all-link-colors`]:         https://github.com/jedmao/postcss-all-link-colors
 [`postcss-color-hex-alpha`]:         https://github.com/postcss/postcss-color-hex-alpha
 [`postcss-define-property`]:         https://github.com/daleeidd/postcss-define-property
@@ -544,13 +534,11 @@ See also plugins in modular minifier [`cssnano`].
 [`postcss-remove-prefixes`]:         https://github.com/johnotander/postcss-remove-prefixes
 [`postcss-responsive-type`]:         https://github.com/seaneking/postcss-responsive-type
 [`postcss-round-subpixels`]:         https://github.com/himynameisdave/postcss-round-subpixels
-[`postcss-short-font-size`]:         https://github.com/jonathantneal/postcss-short-font-size
 [`postcss-color-function`]:          https://github.com/postcss/postcss-color-function
 [`postcss-conic-gradient`]:          https://github.com/jonathantneal/postcss-conic-gradient
 [`postcss-convert-values`]:          https://github.com/ben-eb/postcss-convert-values
 [`postcss-partial-import`]:          https://github.com/jonathantneal/postcss-partial-import
 [`postcss-pseudoelements`]:          https://github.com/axa-ch/postcss-pseudoelements
-[`postcss-short-position`]:          https://github.com/jonathantneal/postcss-short-position
 [`postcss-single-charset`]:          https://github.com/hail2u/postcss-single-charset
 [`postcss-flexbugs-fixes`]:          https://github.com/luisrudge/postcss-flexbugs-fixes
 [`postcss-alias-atrules`]:           https://github.com/maximkoretskiy/postcss-alias-atrules
@@ -562,7 +550,6 @@ See also plugins in modular minifier [`cssnano`].
 [`postcss-modular-scale`]:           https://github.com/kristoferjoseph/postcss-modular-scale
 [`postcss-normalize-url`]:           https://github.com/ben-eb/postcss-normalize-url
 [`postcss-reduce-idents`]:           https://github.com/ben-eb/postcss-reduce-idents
-[`postcss-short-spacing`]:           https://github.com/jonathantneal/postcss-short-spacing
 [`postcss-simple-extend`]:           https://github.com/davidtheclark/postcss-simple-extend
 [`postcss-russian-units`]:           https://github.com/Semigradsky/postcss-russian-units
 [`postcss-image-inliner`]:           https://github.com/bezoerb/postcss-image-inliner
@@ -601,7 +588,6 @@ See also plugins in modular minifier [`cssnano`].
 [`postcss-color-gray`]:              https://github.com/postcss/postcss-color-gray
 [`postcss-colorblind`]:              https://github.com/btholt/postcss-colorblind
 [`postcss-color-hexa`]:              https://github.com/nicksheffield/postcss-color-hexa
-[`postcss-short-text`]:              https://github.com/jonathantneal/postcss-short-text
 [`postcss-autoreset`]:               https://github.com/maximkoretskiy/postcss-autoreset
 [`postcss-font-pack`]:               https://github.com/jedmao/postcss-font-pack
 [`postcss-functions`]:               https://github.com/andyjansson/postcss-functions
diff --git a/lib/previous-map.es6 b/lib/previous-map.es6
index ebbdf4d8..4f9ae8cb 100644
--- a/lib/previous-map.es6
+++ b/lib/previous-map.es6
@@ -67,7 +67,7 @@ export default class PreviousMap {
                     .fromSourceMap(prev).toString();
             } else if ( prev instanceof mozilla.SourceMapGenerator ) {
                 return prev.toString();
-            } else if ( typeof prev === 'object' && prev.mappings ) {
+            } else if ( this.looksLikeMap(prev) ) {
                 return JSON.stringify(prev);
             } else {
                 throw new Error('Unsupported previous source map format: ' +
@@ -90,4 +90,14 @@ export default class PreviousMap {
         }
     }
 
+    looksLikeMap(map) {
+        if ( typeof map !== 'object' ) return false;
+
+        if (map.mappings || map._mappings) {
+            return true;
+        } else {
+            return false;
+        }
+
+    }
 }


Test patch:
diff --git a/test/previous-map.es6 b/test/previous-map.es6
index 4197c196..2ca5d85c 100644
--- a/test/previous-map.es6
+++ b/test/previous-map.es6
@@ -1,18 +1,21 @@
 import parse from '../lib/parse';
 
 import   mozilla  from 'source-map';
+import   mozilla2  from 'isparta/node_modules/source-map';
 import   fs       from 'fs-extra';
 import   path     from 'path';
 import { expect } from 'chai';
 
 let dir = path.join(__dirname, 'fixtures');
-let map = JSON.stringify({
+let mapObj = {
     version:  3,
     file:     null,
     sources:  [],
     names:    [],
     mappings: []
-});
+};
+let map = JSON.stringify(mapObj);
+let mapMoz = new mozilla2.SourceMapGenerator(mapObj);
 
 describe('PreviousMap', () => {
     afterEach( () => {
@@ -28,6 +31,11 @@ describe('PreviousMap', () => {
         expect(root.source.input.map.text).to.eql(map);
     });
 
+    it('works with source-map from different package', () => {
+        let parsing = () => parse('a{}', { map: { prev: mapMoz } });
+        expect(parsing).not.to.throw();
+    });
+
     it('returns consumer', () => {
         expect(parse('a{}', { map: { prev: map } }).source.input.map.consumer())
             .to.be.a.instanceOf(mozilla.SourceMapConsumer);