|
5 | 5 | * This source code is licensed under the BSD-style license found in the
|
6 | 6 | * LICENSE file in the root directory of this source tree. An additional grant
|
7 | 7 | * of patent rights can be found in the PATENTS file in the same directory.
|
8 |
| - * |
9 | 8 | */
|
10 | 9 | 'use strict';
|
11 | 10 |
|
12 |
| -var resolvePlugins = require('../lib/resolvePlugins'); |
| 11 | +const resolvePlugins = require('../lib/resolvePlugins'); |
| 12 | +const resolvePlugin = resolvePlugins.resolvePlugin; |
| 13 | + |
| 14 | +const defaultPlugins = resolvePlugins([ |
| 15 | + 'syntax-class-properties', |
| 16 | + 'syntax-trailing-function-commas', |
| 17 | + 'transform-class-properties', |
| 18 | + 'transform-es2015-block-scoping', |
| 19 | + 'transform-es2015-computed-properties', |
| 20 | + 'transform-es2015-destructuring', |
| 21 | + 'transform-es2015-function-name', |
| 22 | + 'transform-es2015-literals', |
| 23 | + 'transform-es2015-parameters', |
| 24 | + 'transform-es2015-shorthand-properties', |
| 25 | + 'transform-flow-strip-types', |
| 26 | + 'transform-react-jsx', |
| 27 | + 'transform-regenerator', |
| 28 | + [ |
| 29 | + 'transform-es2015-modules-commonjs', |
| 30 | + {strict: false, allowTopLevelThis: true}, |
| 31 | + ], |
| 32 | +]); |
| 33 | + |
| 34 | +const checkES2015Constants = resolvePlugin('check-es2015-constants'); |
| 35 | +const es2015ArrowFunctions = resolvePlugin('transform-es2015-arrow-functions'); |
| 36 | +const es2015Classes = resolvePlugin('transform-es2015-classes'); |
| 37 | +const es2015ForOf = resolvePlugin(['transform-es2015-for-of', {loose: true}]); |
| 38 | +const es2015Spread = resolvePlugin('transform-es2015-spread'); |
| 39 | +const es2015TemplateLiterals = resolvePlugin( |
| 40 | + 'transform-es2015-template-literals' |
| 41 | +); |
| 42 | +const asyncFunctions = resolvePlugin('syntax-async-functions'); |
| 43 | +const exponentiationOperator = resolvePlugin( |
| 44 | + 'transform-exponentiation-operator' |
| 45 | +); |
| 46 | +const objectAssign = resolvePlugin('transform-object-assign'); |
| 47 | +const objectRestSpread = resolvePlugin('transform-object-rest-spread'); |
| 48 | +const reactDisplayName = resolvePlugin('transform-react-display-name'); |
| 49 | +const reactJsxSource = resolvePlugin('transform-react-jsx-source'); |
| 50 | +const symbolMember = [require('../transforms/transform-symbol-member')]; |
13 | 51 |
|
14 | 52 | const getPreset = (src, options) => {
|
15 |
| - const plugins = []; |
16 | 53 | const isNull = src === null || src === undefined;
|
17 | 54 | const hasClass = isNull || src.indexOf('class') !== -1;
|
18 | 55 | const hasForOf =
|
19 | 56 | isNull || (src.indexOf('for') !== -1 && src.indexOf('of') !== -1);
|
20 | 57 |
|
21 |
| - plugins.push( |
22 |
| - 'syntax-class-properties', |
23 |
| - 'syntax-trailing-function-commas', |
24 |
| - 'transform-class-properties', |
25 |
| - 'transform-es2015-block-scoping', |
26 |
| - 'transform-es2015-computed-properties', |
27 |
| - 'transform-es2015-destructuring', |
28 |
| - 'transform-es2015-function-name', |
29 |
| - 'transform-es2015-literals', |
30 |
| - 'transform-es2015-parameters', |
31 |
| - 'transform-es2015-shorthand-properties', |
32 |
| - 'transform-flow-strip-types', |
33 |
| - 'transform-react-jsx', |
34 |
| - 'transform-regenerator', |
35 |
| - [ |
36 |
| - 'transform-es2015-modules-commonjs', |
37 |
| - {strict: false, allowTopLevelThis: true}, |
38 |
| - ] |
39 |
| - ); |
| 58 | + const extraPlugins = []; |
40 | 59 |
|
41 | 60 | if (isNull || src.indexOf('async') !== -1 || src.indexOf('await') !== -1) {
|
42 |
| - plugins.push('syntax-async-functions'); |
| 61 | + extraPlugins.push(asyncFunctions); |
43 | 62 | }
|
44 | 63 | if (hasClass) {
|
45 |
| - plugins.push('transform-es2015-classes'); |
| 64 | + extraPlugins.push(es2015Classes); |
46 | 65 | }
|
47 | 66 | if (isNull || src.indexOf('=>') !== -1) {
|
48 |
| - plugins.push('transform-es2015-arrow-functions'); |
| 67 | + extraPlugins.push(es2015ArrowFunctions); |
49 | 68 | }
|
50 | 69 | if (isNull || src.indexOf('const') !== -1) {
|
51 |
| - plugins.push('check-es2015-constants'); |
| 70 | + extraPlugins.push(checkES2015Constants); |
52 | 71 | }
|
53 | 72 | if (isNull || hasClass || src.indexOf('...') !== -1) {
|
54 |
| - plugins.push('transform-es2015-spread'); |
55 |
| - plugins.push('transform-object-rest-spread'); |
| 73 | + extraPlugins.push(es2015Spread); |
| 74 | + extraPlugins.push(objectRestSpread); |
56 | 75 | }
|
57 | 76 | if (isNull || src.indexOf('`') !== -1) {
|
58 |
| - plugins.push('transform-es2015-template-literals'); |
| 77 | + extraPlugins.push(es2015TemplateLiterals); |
59 | 78 | }
|
60 | 79 | if (isNull || src.indexOf('**') !== -1) {
|
61 |
| - plugins.push('transform-exponentiation-operator'); |
| 80 | + extraPlugins.push(exponentiationOperator); |
62 | 81 | }
|
63 | 82 | if (isNull || src.indexOf('Object.assign') !== -1) {
|
64 |
| - plugins.push('transform-object-assign'); |
| 83 | + extraPlugins.push(objectAssign); |
65 | 84 | }
|
66 | 85 | if (hasForOf) {
|
67 |
| - plugins.push(['transform-es2015-for-of', {loose: true}]); |
| 86 | + extraPlugins.push(es2015ForOf); |
68 | 87 | }
|
69 | 88 | if (hasForOf || src.indexOf('Symbol') !== -1) {
|
70 |
| - plugins.push(require('../transforms/transform-symbol-member')); |
| 89 | + extraPlugins.push(symbolMember); |
71 | 90 | }
|
72 | 91 | if (
|
73 | 92 | isNull ||
|
74 | 93 | src.indexOf('React.createClass') !== -1 ||
|
75 | 94 | src.indexOf('createReactClass') !== -1
|
76 | 95 | ) {
|
77 |
| - plugins.push('transform-react-display-name'); |
| 96 | + extraPlugins.push(reactDisplayName); |
78 | 97 | }
|
79 | 98 |
|
80 | 99 | if (options && options.dev) {
|
81 |
| - plugins.push('transform-react-jsx-source'); |
| 100 | + extraPlugins.push(reactJsxSource); |
82 | 101 | }
|
83 | 102 |
|
84 | 103 | return {
|
85 | 104 | comments: false,
|
86 | 105 | compact: true,
|
87 |
| - plugins: resolvePlugins(plugins), |
| 106 | + plugins: defaultPlugins.concat(extraPlugins), |
88 | 107 | };
|
89 | 108 | };
|
90 | 109 |
|
|
0 commit comments