1 | "use strict";
|
2 |
|
3 | var _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 |
|
5 | var _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 |
|
7 | var _postcss = require("postcss");
|
8 |
|
9 | var _postcss2 = _interopRequireDefault(_postcss);
|
10 |
|
11 | var _caniuseApi = require("caniuse-api");
|
12 |
|
13 | var _features = require("./features");
|
14 |
|
15 | var _features2 = _interopRequireDefault(_features);
|
16 |
|
17 | var _featuresActivationMap = require("./features-activation-map");
|
18 |
|
19 | var _featuresActivationMap2 = _interopRequireDefault(_featuresActivationMap);
|
20 |
|
21 | var _warnForDuplicates = require("./warn-for-duplicates");
|
22 |
|
23 | var _warnForDuplicates2 = _interopRequireDefault(_warnForDuplicates);
|
24 |
|
25 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
26 |
|
27 | var 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 |
|
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 |
|
49 | if (features.autoprefixer && features.autoprefixer.browsers === undefined) {
|
50 | delete features.autoprefixer.browsers;
|
51 | }
|
52 |
|
53 | var processor = (0, _postcss2.default)();
|
54 |
|
55 |
|
56 | Object.keys(_features2.default).forEach(function (key) {
|
57 |
|
58 |
|
59 | if (
|
60 |
|
61 | features[key] !== false && (
|
62 |
|
63 | features[key] === true ||
|
64 |
|
65 |
|
66 | _featuresActivationMap2.default[key] === undefined ||
|
67 |
|
68 |
|
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 |
|
86 | plugin.features = _features2.default;
|
87 |
|
88 | module.exports = plugin; |
\ | No newline at end of file |