UNPKG

3.11 kBJavaScriptView Raw
1"use strict";
2
3var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
4
5var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
6
7var _postcss = require("postcss");
8
9var _postcss2 = _interopRequireDefault(_postcss);
10
11var _caniuseApi = require("caniuse-api");
12
13var _features = require("./features");
14
15var _features2 = _interopRequireDefault(_features);
16
17var _featuresActivationMap = require("./features-activation-map");
18
19var _featuresActivationMap2 = _interopRequireDefault(_featuresActivationMap);
20
21var _warnForDuplicates = require("./warn-for-duplicates");
22
23var _warnForDuplicates2 = _interopRequireDefault(_warnForDuplicates);
24
25function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
26
27var plugin = _postcss2.default.plugin("postcss-cssnext", function (options) {
28 options = _extends({
29 console: console,
30 warnForDuplicates: true,
31 features: {}
32 }, options);
33
34 var features = options.features;
35
36 // propagate browsers option to plugins that supports it
37 var pluginsToPropagateBrowserOption = ["autoprefixer", "rem"];
38 pluginsToPropagateBrowserOption.forEach(function (name) {
39 var feature = features[name];
40
41 if (feature !== false) {
42 features[name] = _extends({
43 browsers: feature && feature.browsers ? feature.browsers : options.browsers
44 }, feature || {});
45 }
46 });
47
48 // autoprefixer doesn't like an "undefined" value. Related to coffee ?
49 if (features.autoprefixer && features.autoprefixer.browsers === undefined) {
50 delete features.autoprefixer.browsers;
51 }
52
53 var processor = (0, _postcss2.default)();
54
55 // features
56 Object.keys(_features2.default).forEach(function (key) {
57 // feature is auto enabled if: not disable && (enabled || no data yet ||
58 // !supported yet)
59 if (
60 // feature is not disabled
61 features[key] !== false && (
62 // feature is enabled
63 features[key] === true ||
64
65 // feature don't have any browsers data (yet)
66 _featuresActivationMap2.default[key] === undefined ||
67
68 // feature is not yet supported by the browsers scope
69 _featuresActivationMap2.default[key] && _featuresActivationMap2.default[key][0] && !(0, _caniuseApi.isSupported)(_featuresActivationMap2.default[key][0], options.browsers))) {
70 var _plugin = _features2.default[key](_typeof(features[key]) === "object" ? _extends({}, features[key]) : undefined);
71 processor.use(_plugin);
72 }
73 });
74
75 if (options.warnForDuplicates) {
76 processor.use((0, _warnForDuplicates2.default)({
77 keys: Object.keys(_features2.default),
78 console: options.console
79 }));
80 }
81
82 return processor;
83});
84
85// es5/6 support
86plugin.features = _features2.default;
87
88module.exports = plugin;
\No newline at end of file