@atlaspack/transformer-babel 2.13.2-dev.3682 → 2.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/package.json +8 -8
- package/LICENSE +0 -201
- package/lib/BabelTransformer.js +0 -128
- package/lib/babel7.js +0 -133
- package/lib/babelErrorUtils.js +0 -15
- package/lib/config.js +0 -311
- package/lib/constants.js +0 -7
- package/lib/flow.js +0 -48
- package/lib/jsx.js +0 -37
- package/lib/remapAstLocations.js +0 -55
- package/lib/types.js +0 -1
- package/lib/utils.js +0 -75
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @atlaspack/transformer-babel
|
|
2
2
|
|
|
3
|
+
## 2.14.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#339](https://github.com/atlassian-labs/atlaspack/pull/339) [`bfe81e5`](https://github.com/atlassian-labs/atlaspack/commit/bfe81e551c4e4bb2cac7fc4745222e66962c1728) Thanks [@yamadapc](https://github.com/yamadapc)! - Update cache invalidation metrics with build type
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- [#414](https://github.com/atlassian-labs/atlaspack/pull/414) [`eff9809`](https://github.com/atlassian-labs/atlaspack/commit/eff98093703b9999a511b87a19562f5aaccfcb53) Thanks [@alshdavid](https://github.com/alshdavid)! - Added type:commonjs to package.json files
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [[`bfe81e5`](https://github.com/atlassian-labs/atlaspack/commit/bfe81e551c4e4bb2cac7fc4745222e66962c1728), [`4837b69`](https://github.com/atlassian-labs/atlaspack/commit/4837b6988e56ca842a24797b796160964d3696ce), [`eff9809`](https://github.com/atlassian-labs/atlaspack/commit/eff98093703b9999a511b87a19562f5aaccfcb53)]:
|
|
14
|
+
- @atlaspack/diagnostic@2.14.0
|
|
15
|
+
- @atlaspack/plugin@2.14.0
|
|
16
|
+
- @atlaspack/utils@2.14.0
|
|
17
|
+
|
|
3
18
|
## 2.13.1
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/transformer-babel",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.14.0",
|
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -12,24 +12,24 @@
|
|
|
12
12
|
"main": "lib/BabelTransformer.js",
|
|
13
13
|
"source": "src/BabelTransformer.js",
|
|
14
14
|
"engines": {
|
|
15
|
-
"atlaspack": "^2.
|
|
15
|
+
"atlaspack": "^2.12.0",
|
|
16
16
|
"node": ">= 16.0.0"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@atlaspack/diagnostic": "2.
|
|
20
|
-
"@atlaspack/plugin": "2.
|
|
21
|
-
"@atlaspack/utils": "2.13.2-dev.3682+e6c0286ea",
|
|
19
|
+
"@atlaspack/diagnostic": "2.14.0",
|
|
20
|
+
"@atlaspack/plugin": "2.14.0",
|
|
22
21
|
"@parcel/source-map": "^2.1.1",
|
|
22
|
+
"@atlaspack/utils": "2.14.0",
|
|
23
23
|
"browserslist": "^4.6.6",
|
|
24
24
|
"json5": "^2.2.0",
|
|
25
25
|
"nullthrows": "^1.1.1",
|
|
26
26
|
"semver": "^7.5.2"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@atlaspack/types": "2.13.2-dev.3682+e6c0286ea",
|
|
30
29
|
"@babel/core": "^7.22.11",
|
|
31
30
|
"@babel/preset-env": "^7.22.14",
|
|
32
|
-
"@babel/types": "^7.22.11"
|
|
31
|
+
"@babel/types": "^7.22.11",
|
|
32
|
+
"@atlaspack/types": "2.14.0"
|
|
33
33
|
},
|
|
34
|
-
"
|
|
34
|
+
"type": "commonjs"
|
|
35
35
|
}
|
package/LICENSE
DELETED
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
Apache License
|
|
2
|
-
Version 2.0, January 2004
|
|
3
|
-
http://www.apache.org/licenses/
|
|
4
|
-
|
|
5
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
-
|
|
7
|
-
1. Definitions.
|
|
8
|
-
|
|
9
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
-
|
|
12
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
-
the copyright owner that is granting the License.
|
|
14
|
-
|
|
15
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
-
other entities that control, are controlled by, or are under common
|
|
17
|
-
control with that entity. For the purposes of this definition,
|
|
18
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
-
direction or management of such entity, whether by contract or
|
|
20
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
-
|
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
-
exercising permissions granted by this License.
|
|
25
|
-
|
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
-
including but not limited to software source code, documentation
|
|
28
|
-
source, and configuration files.
|
|
29
|
-
|
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
|
31
|
-
transformation or translation of a Source form, including but
|
|
32
|
-
not limited to compiled object code, generated documentation,
|
|
33
|
-
and conversions to other media types.
|
|
34
|
-
|
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
-
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
-
(an example is provided in the Appendix below).
|
|
39
|
-
|
|
40
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
-
form, that is based on (or derived from) the Work and for which the
|
|
42
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
-
of this License, Derivative Works shall not include works that remain
|
|
45
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
-
the Work and Derivative Works thereof.
|
|
47
|
-
|
|
48
|
-
"Contribution" shall mean any work of authorship, including
|
|
49
|
-
the original version of the Work and any modifications or additions
|
|
50
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
-
means any form of electronic, verbal, or written communication sent
|
|
55
|
-
to the Licensor or its representatives, including but not limited to
|
|
56
|
-
communication on electronic mailing lists, source code control systems,
|
|
57
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
-
excluding communication that is conspicuously marked or otherwise
|
|
60
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
-
|
|
62
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
-
subsequently incorporated within the Work.
|
|
65
|
-
|
|
66
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
-
Work and such Derivative Works in Source or Object form.
|
|
72
|
-
|
|
73
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
-
(except as stated in this section) patent license to make, have made,
|
|
77
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
-
where such license applies only to those patent claims licensable
|
|
79
|
-
by such Contributor that are necessarily infringed by their
|
|
80
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
-
institute patent litigation against any entity (including a
|
|
83
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
-
or contributory patent infringement, then any patent licenses
|
|
86
|
-
granted to You under this License for that Work shall terminate
|
|
87
|
-
as of the date such litigation is filed.
|
|
88
|
-
|
|
89
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
-
modifications, and in Source or Object form, provided that You
|
|
92
|
-
meet the following conditions:
|
|
93
|
-
|
|
94
|
-
(a) You must give any other recipients of the Work or
|
|
95
|
-
Derivative Works a copy of this License; and
|
|
96
|
-
|
|
97
|
-
(b) You must cause any modified files to carry prominent notices
|
|
98
|
-
stating that You changed the files; and
|
|
99
|
-
|
|
100
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
-
that You distribute, all copyright, patent, trademark, and
|
|
102
|
-
attribution notices from the Source form of the Work,
|
|
103
|
-
excluding those notices that do not pertain to any part of
|
|
104
|
-
the Derivative Works; and
|
|
105
|
-
|
|
106
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
-
distribution, then any Derivative Works that You distribute must
|
|
108
|
-
include a readable copy of the attribution notices contained
|
|
109
|
-
within such NOTICE file, excluding those notices that do not
|
|
110
|
-
pertain to any part of the Derivative Works, in at least one
|
|
111
|
-
of the following places: within a NOTICE text file distributed
|
|
112
|
-
as part of the Derivative Works; within the Source form or
|
|
113
|
-
documentation, if provided along with the Derivative Works; or,
|
|
114
|
-
within a display generated by the Derivative Works, if and
|
|
115
|
-
wherever such third-party notices normally appear. The contents
|
|
116
|
-
of the NOTICE file are for informational purposes only and
|
|
117
|
-
do not modify the License. You may add Your own attribution
|
|
118
|
-
notices within Derivative Works that You distribute, alongside
|
|
119
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
-
that such additional attribution notices cannot be construed
|
|
121
|
-
as modifying the License.
|
|
122
|
-
|
|
123
|
-
You may add Your own copyright statement to Your modifications and
|
|
124
|
-
may provide additional or different license terms and conditions
|
|
125
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
-
the conditions stated in this License.
|
|
129
|
-
|
|
130
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
-
this License, without any additional terms or conditions.
|
|
134
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
-
the terms of any separate license agreement you may have executed
|
|
136
|
-
with Licensor regarding such Contributions.
|
|
137
|
-
|
|
138
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
-
except as required for reasonable and customary use in describing the
|
|
141
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
-
|
|
143
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
-
implied, including, without limitation, any warranties or conditions
|
|
148
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
-
appropriateness of using or redistributing the Work and assume any
|
|
151
|
-
risks associated with Your exercise of permissions under this License.
|
|
152
|
-
|
|
153
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
-
unless required by applicable law (such as deliberate and grossly
|
|
156
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
-
liable to You for damages, including any direct, indirect, special,
|
|
158
|
-
incidental, or consequential damages of any character arising as a
|
|
159
|
-
result of this License or out of the use or inability to use the
|
|
160
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
-
other commercial damages or losses), even if such Contributor
|
|
163
|
-
has been advised of the possibility of such damages.
|
|
164
|
-
|
|
165
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
-
or other liability obligations and/or rights consistent with this
|
|
169
|
-
License. However, in accepting such obligations, You may act only
|
|
170
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
-
defend, and hold each Contributor harmless for any liability
|
|
173
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
-
of your accepting any such warranty or additional liability.
|
|
175
|
-
|
|
176
|
-
END OF TERMS AND CONDITIONS
|
|
177
|
-
|
|
178
|
-
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
-
|
|
180
|
-
To apply the Apache License to your work, attach the following
|
|
181
|
-
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
-
replaced with your own identifying information. (Don't include
|
|
183
|
-
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
-
comment syntax for the file format. We also recommend that a
|
|
185
|
-
file or class name and description of purpose be included on the
|
|
186
|
-
same "printed page" as the copyright notice for easier
|
|
187
|
-
identification within third-party archives.
|
|
188
|
-
|
|
189
|
-
Copyright (c) 2024 Atlassian US., Inc.
|
|
190
|
-
|
|
191
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
-
you may not use this file except in compliance with the License.
|
|
193
|
-
You may obtain a copy of the License at
|
|
194
|
-
|
|
195
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
-
|
|
197
|
-
Unless required by applicable law or agreed to in writing, software
|
|
198
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
-
See the License for the specific language governing permissions and
|
|
201
|
-
limitations under the License.
|
package/lib/BabelTransformer.js
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _babelErrorUtils = require("./babelErrorUtils");
|
|
8
|
-
function _plugin() {
|
|
9
|
-
const data = require("@atlaspack/plugin");
|
|
10
|
-
_plugin = function () {
|
|
11
|
-
return data;
|
|
12
|
-
};
|
|
13
|
-
return data;
|
|
14
|
-
}
|
|
15
|
-
function _utils() {
|
|
16
|
-
const data = require("@atlaspack/utils");
|
|
17
|
-
_utils = function () {
|
|
18
|
-
return data;
|
|
19
|
-
};
|
|
20
|
-
return data;
|
|
21
|
-
}
|
|
22
|
-
function _sourceMap() {
|
|
23
|
-
const data = _interopRequireDefault(require("@parcel/source-map"));
|
|
24
|
-
_sourceMap = function () {
|
|
25
|
-
return data;
|
|
26
|
-
};
|
|
27
|
-
return data;
|
|
28
|
-
}
|
|
29
|
-
function _semver() {
|
|
30
|
-
const data = _interopRequireDefault(require("semver"));
|
|
31
|
-
_semver = function () {
|
|
32
|
-
return data;
|
|
33
|
-
};
|
|
34
|
-
return data;
|
|
35
|
-
}
|
|
36
|
-
var _babel = _interopRequireDefault(require("./babel7"));
|
|
37
|
-
var _config = require("./config");
|
|
38
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
39
|
-
var _default = exports.default = new (_plugin().Transformer)({
|
|
40
|
-
loadConfig({
|
|
41
|
-
config,
|
|
42
|
-
options,
|
|
43
|
-
logger
|
|
44
|
-
}) {
|
|
45
|
-
return (0, _config.load)(config, options, logger);
|
|
46
|
-
},
|
|
47
|
-
canReuseAST({
|
|
48
|
-
ast
|
|
49
|
-
}) {
|
|
50
|
-
return ast.type === 'babel' && _semver().default.satisfies(ast.version, '^7.0.0');
|
|
51
|
-
},
|
|
52
|
-
async transform({
|
|
53
|
-
asset,
|
|
54
|
-
config,
|
|
55
|
-
logger,
|
|
56
|
-
options,
|
|
57
|
-
tracer
|
|
58
|
-
}) {
|
|
59
|
-
try {
|
|
60
|
-
if (config !== null && config !== void 0 && config.config) {
|
|
61
|
-
if (asset.meta.babelPlugins != null && Array.isArray(asset.meta.babelPlugins)) {
|
|
62
|
-
await (0, _babel.default)({
|
|
63
|
-
asset,
|
|
64
|
-
options,
|
|
65
|
-
logger,
|
|
66
|
-
babelOptions: config,
|
|
67
|
-
additionalPlugins: asset.meta.babelPlugins,
|
|
68
|
-
tracer
|
|
69
|
-
});
|
|
70
|
-
} else {
|
|
71
|
-
await (0, _babel.default)({
|
|
72
|
-
asset,
|
|
73
|
-
options,
|
|
74
|
-
logger,
|
|
75
|
-
babelOptions: config,
|
|
76
|
-
tracer
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
return [asset];
|
|
81
|
-
} catch (e) {
|
|
82
|
-
throw await (0, _babelErrorUtils.babelErrorEnhancer)(e, asset);
|
|
83
|
-
}
|
|
84
|
-
},
|
|
85
|
-
async generate({
|
|
86
|
-
asset,
|
|
87
|
-
ast,
|
|
88
|
-
options
|
|
89
|
-
}) {
|
|
90
|
-
let originalSourceMap = await asset.getMap();
|
|
91
|
-
let sourceFileName = (0, _utils().relativeUrl)(options.projectRoot, asset.filePath);
|
|
92
|
-
const babelCorePath = await options.packageManager.resolve('@babel/core', asset.filePath, {
|
|
93
|
-
range: '^7.12.0',
|
|
94
|
-
saveDev: true,
|
|
95
|
-
shouldAutoInstall: options.shouldAutoInstall
|
|
96
|
-
});
|
|
97
|
-
const {
|
|
98
|
-
default: generate
|
|
99
|
-
} = await options.packageManager.require('@babel/generator', babelCorePath.resolved);
|
|
100
|
-
let {
|
|
101
|
-
code,
|
|
102
|
-
rawMappings
|
|
103
|
-
} = generate(ast.program, {
|
|
104
|
-
sourceFileName,
|
|
105
|
-
sourceMaps: !!asset.env.sourceMap,
|
|
106
|
-
comments: true
|
|
107
|
-
});
|
|
108
|
-
let map = new (_sourceMap().default)(options.projectRoot);
|
|
109
|
-
if (rawMappings) {
|
|
110
|
-
map.addIndexedMappings(rawMappings);
|
|
111
|
-
}
|
|
112
|
-
if (originalSourceMap) {
|
|
113
|
-
// The babel AST already contains the correct mappings, but not the source contents.
|
|
114
|
-
// We need to copy over the source contents from the original map.
|
|
115
|
-
let sourcesContent = originalSourceMap.getSourcesContentMap();
|
|
116
|
-
for (let filePath in sourcesContent) {
|
|
117
|
-
let content = sourcesContent[filePath];
|
|
118
|
-
if (content != null) {
|
|
119
|
-
map.setSourceContent(filePath, content);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
return {
|
|
124
|
-
content: code,
|
|
125
|
-
map
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
});
|
package/lib/babel7.js
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = babel7;
|
|
7
|
-
function _assert() {
|
|
8
|
-
const data = _interopRequireDefault(require("assert"));
|
|
9
|
-
_assert = function () {
|
|
10
|
-
return data;
|
|
11
|
-
};
|
|
12
|
-
return data;
|
|
13
|
-
}
|
|
14
|
-
function _path() {
|
|
15
|
-
const data = _interopRequireDefault(require("path"));
|
|
16
|
-
_path = function () {
|
|
17
|
-
return data;
|
|
18
|
-
};
|
|
19
|
-
return data;
|
|
20
|
-
}
|
|
21
|
-
function _diagnostic() {
|
|
22
|
-
const data = require("@atlaspack/diagnostic");
|
|
23
|
-
_diagnostic = function () {
|
|
24
|
-
return data;
|
|
25
|
-
};
|
|
26
|
-
return data;
|
|
27
|
-
}
|
|
28
|
-
function _utils() {
|
|
29
|
-
const data = require("@atlaspack/utils");
|
|
30
|
-
_utils = function () {
|
|
31
|
-
return data;
|
|
32
|
-
};
|
|
33
|
-
return data;
|
|
34
|
-
}
|
|
35
|
-
var _remapAstLocations = require("./remapAstLocations");
|
|
36
|
-
var _package = _interopRequireDefault(require("../package.json"));
|
|
37
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
38
|
-
const transformerVersion = _package.default.version;
|
|
39
|
-
(0, _assert().default)(typeof transformerVersion === 'string');
|
|
40
|
-
async function babel7(opts) {
|
|
41
|
-
var _babelOptions$config$;
|
|
42
|
-
let {
|
|
43
|
-
asset,
|
|
44
|
-
options,
|
|
45
|
-
babelOptions,
|
|
46
|
-
additionalPlugins = [],
|
|
47
|
-
tracer
|
|
48
|
-
} = opts;
|
|
49
|
-
const babelCore = await options.packageManager.require('@babel/core', asset.filePath, {
|
|
50
|
-
range: '^7.12.0',
|
|
51
|
-
saveDev: true,
|
|
52
|
-
shouldAutoInstall: options.shouldAutoInstall
|
|
53
|
-
});
|
|
54
|
-
let config = {
|
|
55
|
-
...babelOptions.config,
|
|
56
|
-
plugins: additionalPlugins.concat(babelOptions.config.plugins),
|
|
57
|
-
code: false,
|
|
58
|
-
ast: true,
|
|
59
|
-
filename: asset.filePath,
|
|
60
|
-
babelrc: false,
|
|
61
|
-
configFile: false,
|
|
62
|
-
parserOpts: {
|
|
63
|
-
...babelOptions.config.parserOpts,
|
|
64
|
-
sourceFilename: (0, _utils().relativeUrl)(options.projectRoot, asset.filePath),
|
|
65
|
-
allowReturnOutsideFunction: true,
|
|
66
|
-
strictMode: false,
|
|
67
|
-
sourceType: 'module',
|
|
68
|
-
plugins: [...(((_babelOptions$config$ = babelOptions.config.parserOpts) === null || _babelOptions$config$ === void 0 ? void 0 : _babelOptions$config$.plugins) ?? []), ...(babelOptions.syntaxPlugins ?? []),
|
|
69
|
-
// Applied by preset-env
|
|
70
|
-
'classProperties', 'classPrivateProperties', 'classPrivateMethods', 'exportDefaultFrom'
|
|
71
|
-
// 'topLevelAwait'
|
|
72
|
-
]
|
|
73
|
-
},
|
|
74
|
-
|
|
75
|
-
caller: {
|
|
76
|
-
name: 'parcel',
|
|
77
|
-
version: transformerVersion,
|
|
78
|
-
targets: JSON.stringify(babelOptions.targets),
|
|
79
|
-
outputFormat: asset.env.outputFormat
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
if (tracer.enabled) {
|
|
83
|
-
config.wrapPluginVisitorMethod = (key, nodeType, fn) => {
|
|
84
|
-
return function () {
|
|
85
|
-
let pluginKey = key;
|
|
86
|
-
if (pluginKey.startsWith(options.projectRoot)) {
|
|
87
|
-
pluginKey = _path().default.relative(options.projectRoot, pluginKey);
|
|
88
|
-
}
|
|
89
|
-
const measurement = tracer.createMeasurement(pluginKey, nodeType, _path().default.relative(options.projectRoot, asset.filePath));
|
|
90
|
-
fn.apply(this, arguments);
|
|
91
|
-
measurement && measurement.end();
|
|
92
|
-
};
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
let ast = await asset.getAST();
|
|
96
|
-
let res;
|
|
97
|
-
if (ast) {
|
|
98
|
-
res = await babelCore.transformFromAstAsync(ast.program, asset.isASTDirty() ? undefined : await asset.getCode(), config);
|
|
99
|
-
} else {
|
|
100
|
-
res = await babelCore.transformAsync(await asset.getCode(), config);
|
|
101
|
-
if (res.ast) {
|
|
102
|
-
let map = await asset.getMap();
|
|
103
|
-
if (map) {
|
|
104
|
-
(0, _remapAstLocations.remapAstLocations)(babelCore.types, res.ast, map);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
if (res.externalDependencies) {
|
|
108
|
-
for (let f of res.externalDependencies) {
|
|
109
|
-
if (!_path().default.isAbsolute(f)) {
|
|
110
|
-
opts.logger.warn({
|
|
111
|
-
message: (0, _diagnostic().md)`Ignoring non-absolute Babel external dependency: ${f}`,
|
|
112
|
-
hints: ['Please report this to the corresponding Babel plugin and/or to Parcel.']
|
|
113
|
-
});
|
|
114
|
-
} else {
|
|
115
|
-
if (await options.inputFS.exists(f)) {
|
|
116
|
-
asset.invalidateOnFileChange(f);
|
|
117
|
-
} else {
|
|
118
|
-
asset.invalidateOnFileCreate({
|
|
119
|
-
filePath: f
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
if (res.ast) {
|
|
127
|
-
asset.setAST({
|
|
128
|
-
type: 'babel',
|
|
129
|
-
version: '7.0.0',
|
|
130
|
-
program: res.ast
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
}
|
package/lib/babelErrorUtils.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.babelErrorEnhancer = babelErrorEnhancer;
|
|
7
|
-
async function babelErrorEnhancer(error, asset) {
|
|
8
|
-
if (error.loc) {
|
|
9
|
-
let start = error.message.startsWith(asset.filePath) ? asset.filePath.length + 1 : 0;
|
|
10
|
-
error.message = error.message.slice(start).split('\n')[0].trim();
|
|
11
|
-
}
|
|
12
|
-
error.source = await asset.getCode();
|
|
13
|
-
error.filePath = asset.filePath;
|
|
14
|
-
return error;
|
|
15
|
-
}
|
package/lib/config.js
DELETED
|
@@ -1,311 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.load = load;
|
|
7
|
-
function _json() {
|
|
8
|
-
const data = _interopRequireDefault(require("json5"));
|
|
9
|
-
_json = function () {
|
|
10
|
-
return data;
|
|
11
|
-
};
|
|
12
|
-
return data;
|
|
13
|
-
}
|
|
14
|
-
function _path() {
|
|
15
|
-
const data = _interopRequireDefault(require("path"));
|
|
16
|
-
_path = function () {
|
|
17
|
-
return data;
|
|
18
|
-
};
|
|
19
|
-
return data;
|
|
20
|
-
}
|
|
21
|
-
function _utils() {
|
|
22
|
-
const data = require("@atlaspack/utils");
|
|
23
|
-
_utils = function () {
|
|
24
|
-
return data;
|
|
25
|
-
};
|
|
26
|
-
return data;
|
|
27
|
-
}
|
|
28
|
-
function _diagnostic() {
|
|
29
|
-
const data = require("@atlaspack/diagnostic");
|
|
30
|
-
_diagnostic = function () {
|
|
31
|
-
return data;
|
|
32
|
-
};
|
|
33
|
-
return data;
|
|
34
|
-
}
|
|
35
|
-
var _constants = require("./constants");
|
|
36
|
-
var _jsx = _interopRequireDefault(require("./jsx"));
|
|
37
|
-
var _flow = _interopRequireDefault(require("./flow"));
|
|
38
|
-
var _utils2 = require("./utils");
|
|
39
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
40
|
-
const TYPESCRIPT_EXTNAME_RE = /\.tsx?$/;
|
|
41
|
-
const JS_EXTNAME_RE = /^\.(js|cjs|mjs)$/;
|
|
42
|
-
const BABEL_CONFIG_FILENAMES = ['.babelrc', '.babelrc.js', '.babelrc.json', '.babelrc.cjs', '.babelrc.mjs', '.babelignore', 'babel.config.js', 'babel.config.json', 'babel.config.mjs', 'babel.config.cjs'];
|
|
43
|
-
async function load(config, options, logger) {
|
|
44
|
-
// Don't transpile inside node_modules
|
|
45
|
-
if (!config.isSource) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// Invalidate when any babel config file is added.
|
|
50
|
-
for (let fileName of BABEL_CONFIG_FILENAMES) {
|
|
51
|
-
config.invalidateOnFileCreate({
|
|
52
|
-
fileName,
|
|
53
|
-
aboveFilePath: config.searchPath
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Do nothing if we cannot resolve any babel config filenames. Checking using our own
|
|
58
|
-
// config resolution (which is cached) is much faster than relying on babel.
|
|
59
|
-
if (!(await (0, _utils().resolveConfig)(options.inputFS, config.searchPath, BABEL_CONFIG_FILENAMES, options.projectRoot))) {
|
|
60
|
-
return buildDefaultBabelConfig(options, config);
|
|
61
|
-
}
|
|
62
|
-
const babelCore = await options.packageManager.require('@babel/core', config.searchPath, {
|
|
63
|
-
range: _constants.BABEL_CORE_RANGE,
|
|
64
|
-
saveDev: true,
|
|
65
|
-
shouldAutoInstall: options.shouldAutoInstall
|
|
66
|
-
});
|
|
67
|
-
config.addDevDependency({
|
|
68
|
-
specifier: '@babel/core',
|
|
69
|
-
resolveFrom: config.searchPath,
|
|
70
|
-
range: _constants.BABEL_CORE_RANGE
|
|
71
|
-
});
|
|
72
|
-
config.invalidateOnEnvChange('BABEL_ENV');
|
|
73
|
-
config.invalidateOnEnvChange('NODE_ENV');
|
|
74
|
-
let babelOptions = {
|
|
75
|
-
filename: config.searchPath,
|
|
76
|
-
cwd: options.projectRoot,
|
|
77
|
-
envName: options.env.BABEL_ENV ?? options.env.NODE_ENV ?? (options.mode === 'production' || options.mode === 'development' ? options.mode : null) ?? 'development',
|
|
78
|
-
showIgnoredFiles: true
|
|
79
|
-
};
|
|
80
|
-
let partialConfig = await babelCore.loadPartialConfigAsync(babelOptions);
|
|
81
|
-
let addIncludedFile = file => {
|
|
82
|
-
if (JS_EXTNAME_RE.test(_path().default.extname(file))) {
|
|
83
|
-
// We need to invalidate on startup in case the config is non-static,
|
|
84
|
-
// e.g. uses unknown environment variables, reads from the filesystem, etc.
|
|
85
|
-
logger.warn({
|
|
86
|
-
message: `It looks like you're using a JavaScript Babel config file. This means the config cannot be watched for changes, and Babel transformations cannot be cached. You'll need to restart Parcel for changes to this config to take effect. Try using a ${_path().default.basename(file, _path().default.extname(file)) + '.json'} file instead.`
|
|
87
|
-
});
|
|
88
|
-
config.invalidateOnStartup();
|
|
89
|
-
|
|
90
|
-
// But also add the config as a dev dependency so we can at least attempt invalidation in watch mode.
|
|
91
|
-
config.addDevDependency({
|
|
92
|
-
specifier: (0, _utils().relativePath)(options.projectRoot, file),
|
|
93
|
-
resolveFrom: _path().default.join(options.projectRoot, 'index'),
|
|
94
|
-
// Also invalidate @babel/core when the config or a dependency updates.
|
|
95
|
-
// This ensures that the caches in @babel/core are also invalidated.
|
|
96
|
-
additionalInvalidations: [{
|
|
97
|
-
specifier: '@babel/core',
|
|
98
|
-
resolveFrom: config.searchPath,
|
|
99
|
-
range: _constants.BABEL_CORE_RANGE
|
|
100
|
-
}]
|
|
101
|
-
});
|
|
102
|
-
} else {
|
|
103
|
-
config.invalidateOnFileChange(file);
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
let warnOldVersion = () => {
|
|
107
|
-
logger.warn({
|
|
108
|
-
message: 'You are using an old version of @babel/core which does not support the necessary features for Parcel to cache and watch babel config files safely. You may need to restart Parcel for config changes to take effect. Please upgrade to @babel/core 7.12.0 or later to resolve this issue.'
|
|
109
|
-
});
|
|
110
|
-
config.invalidateOnStartup();
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
// Old versions of @babel/core return null from loadPartialConfig when the file should explicitly not be run through babel (ignore/exclude)
|
|
114
|
-
if (partialConfig == null) {
|
|
115
|
-
warnOldVersion();
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
if (partialConfig.files == null) {
|
|
119
|
-
// If the files property is missing, we're on an old version of @babel/core.
|
|
120
|
-
// We need to invalidate on startup because we can't properly track dependencies.
|
|
121
|
-
if (partialConfig.hasFilesystemConfig()) {
|
|
122
|
-
warnOldVersion();
|
|
123
|
-
if (typeof partialConfig.babelrcPath === 'string') {
|
|
124
|
-
addIncludedFile(partialConfig.babelrcPath);
|
|
125
|
-
}
|
|
126
|
-
if (typeof partialConfig.configPath === 'string') {
|
|
127
|
-
addIncludedFile(partialConfig.configPath);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
} else {
|
|
131
|
-
for (let file of partialConfig.files) {
|
|
132
|
-
addIncludedFile(file);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
if (partialConfig.fileHandling != null && partialConfig.fileHandling !== 'transpile') {} else if (partialConfig.hasFilesystemConfig()) {
|
|
136
|
-
// Determine what syntax plugins we need to enable
|
|
137
|
-
let syntaxPlugins = [];
|
|
138
|
-
if (TYPESCRIPT_EXTNAME_RE.test(config.searchPath)) {
|
|
139
|
-
syntaxPlugins.push('typescript');
|
|
140
|
-
if (config.searchPath.endsWith('.tsx')) {
|
|
141
|
-
syntaxPlugins.push('jsx');
|
|
142
|
-
}
|
|
143
|
-
} else if (await (0, _jsx.default)(options, config)) {
|
|
144
|
-
syntaxPlugins.push('jsx');
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// If the config has plugins loaded with require(), or inline plugins in the config,
|
|
148
|
-
// we can't cache the result of the compilation because we don't know where they came from.
|
|
149
|
-
if (hasRequire(partialConfig.options)) {
|
|
150
|
-
logger.warn({
|
|
151
|
-
message: 'It looks like you are using `require` to configure Babel plugins or presets. This means Babel transformations cannot be cached and will run on each build. Please use strings to configure Babel instead.'
|
|
152
|
-
});
|
|
153
|
-
config.setCacheKey(JSON.stringify(Date.now()));
|
|
154
|
-
config.invalidateOnStartup();
|
|
155
|
-
} else {
|
|
156
|
-
await warnOnRedundantPlugins(options.inputFS, partialConfig, logger);
|
|
157
|
-
definePluginDependencies(config, partialConfig.options, options);
|
|
158
|
-
config.setCacheKey((0, _utils().hashObject)(partialConfig.options));
|
|
159
|
-
}
|
|
160
|
-
return {
|
|
161
|
-
internal: false,
|
|
162
|
-
config: partialConfig.options,
|
|
163
|
-
targets: (0, _utils2.enginesToBabelTargets)(config.env),
|
|
164
|
-
syntaxPlugins
|
|
165
|
-
};
|
|
166
|
-
} else {
|
|
167
|
-
return buildDefaultBabelConfig(options, config);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
async function buildDefaultBabelConfig(options, config) {
|
|
171
|
-
// If this is a .ts or .tsx file, we don't need to enable flow.
|
|
172
|
-
if (TYPESCRIPT_EXTNAME_RE.test(config.searchPath)) {
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// Detect flow. If not enabled, babel doesn't need to run at all.
|
|
177
|
-
let babelOptions = await (0, _flow.default)(config, options);
|
|
178
|
-
if (babelOptions == null) {
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
// When flow is enabled, we may also need to enable JSX so it parses properly.
|
|
183
|
-
let syntaxPlugins = [];
|
|
184
|
-
if (await (0, _jsx.default)(options, config)) {
|
|
185
|
-
syntaxPlugins.push('jsx');
|
|
186
|
-
}
|
|
187
|
-
definePluginDependencies(config, babelOptions, options);
|
|
188
|
-
return {
|
|
189
|
-
internal: true,
|
|
190
|
-
config: babelOptions,
|
|
191
|
-
syntaxPlugins
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
function hasRequire(options) {
|
|
195
|
-
let configItems = [...options.presets, ...options.plugins];
|
|
196
|
-
return configItems.some(item => !item.file);
|
|
197
|
-
}
|
|
198
|
-
function definePluginDependencies(config, babelConfig, options) {
|
|
199
|
-
if (babelConfig == null) {
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
let configItems = [...(babelConfig.presets || []), ...(babelConfig.plugins || [])];
|
|
203
|
-
for (let configItem of configItems) {
|
|
204
|
-
// FIXME: this uses a relative path from the project root rather than resolving
|
|
205
|
-
// from the config location because configItem.file.request can be a shorthand
|
|
206
|
-
// rather than a full package name.
|
|
207
|
-
config.addDevDependency({
|
|
208
|
-
specifier: (0, _utils().relativePath)(options.projectRoot, configItem.file.resolved),
|
|
209
|
-
resolveFrom: _path().default.join(options.projectRoot, 'index'),
|
|
210
|
-
// Also invalidate @babel/core when the plugin or a dependency updates.
|
|
211
|
-
// This ensures that the caches in @babel/core are also invalidated.
|
|
212
|
-
additionalInvalidations: [{
|
|
213
|
-
specifier: '@babel/core',
|
|
214
|
-
resolveFrom: config.searchPath,
|
|
215
|
-
range: _constants.BABEL_CORE_RANGE
|
|
216
|
-
}]
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
const redundantPresets = new Set(['@babel/preset-env', '@babel/preset-react', '@babel/preset-typescript', '@atlaspack/babel-preset-env']);
|
|
221
|
-
async function warnOnRedundantPlugins(fs, babelConfig, logger) {
|
|
222
|
-
if (babelConfig == null) {
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
let configPath = babelConfig.config ?? babelConfig.babelrc;
|
|
226
|
-
if (!configPath) {
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
let presets = babelConfig.options.presets || [];
|
|
230
|
-
let plugins = babelConfig.options.plugins || [];
|
|
231
|
-
let foundRedundantPresets = new Set();
|
|
232
|
-
let filteredPresets = presets.filter(preset => {
|
|
233
|
-
if (redundantPresets.has(preset.file.request)) {
|
|
234
|
-
foundRedundantPresets.add(preset.file.request);
|
|
235
|
-
return false;
|
|
236
|
-
}
|
|
237
|
-
return true;
|
|
238
|
-
});
|
|
239
|
-
let filePath = _path().default.relative(process.cwd(), configPath);
|
|
240
|
-
let diagnostics = [];
|
|
241
|
-
if (filteredPresets.length === 0 && foundRedundantPresets.size > 0 && plugins.length === 0) {
|
|
242
|
-
diagnostics.push({
|
|
243
|
-
message: (0, _diagnostic().md)`Parcel includes transpilation by default. Babel config __${filePath}__ contains only redundant presets. Deleting it may significantly improve build performance.`,
|
|
244
|
-
codeFrames: [{
|
|
245
|
-
filePath: configPath,
|
|
246
|
-
codeHighlights: await getCodeHighlights(fs, configPath, foundRedundantPresets)
|
|
247
|
-
}],
|
|
248
|
-
hints: [(0, _diagnostic().md)`Delete __${filePath}__`],
|
|
249
|
-
documentationURL: 'https://parceljs.org/languages/javascript/#default-presets'
|
|
250
|
-
});
|
|
251
|
-
} else if (foundRedundantPresets.size > 0) {
|
|
252
|
-
diagnostics.push({
|
|
253
|
-
message: (0, _diagnostic().md)`Parcel includes transpilation by default. Babel config __${filePath}__ includes the following redundant presets: ${[...foundRedundantPresets].map(p => _diagnostic().md.underline(p))}. Removing these may improve build performance.`,
|
|
254
|
-
codeFrames: [{
|
|
255
|
-
filePath: configPath,
|
|
256
|
-
codeHighlights: await getCodeHighlights(fs, configPath, foundRedundantPresets)
|
|
257
|
-
}],
|
|
258
|
-
hints: [(0, _diagnostic().md)`Remove the above presets from __${filePath}__`],
|
|
259
|
-
documentationURL: 'https://parceljs.org/languages/javascript/#default-presets'
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
if (foundRedundantPresets.has('@babel/preset-env')) {
|
|
263
|
-
diagnostics.push({
|
|
264
|
-
message: "@babel/preset-env does not support Parcel's targets, which will likely result in unnecessary transpilation and larger bundle sizes.",
|
|
265
|
-
codeFrames: [{
|
|
266
|
-
filePath: babelConfig.config ?? babelConfig.babelrc,
|
|
267
|
-
codeHighlights: await getCodeHighlights(fs, babelConfig.config ?? babelConfig.babelrc, new Set(['@babel/preset-env']))
|
|
268
|
-
}],
|
|
269
|
-
hints: [`Either remove __@babel/preset-env__ to use Parcel's builtin transpilation, or replace with __@atlaspack/babel-preset-env__`],
|
|
270
|
-
documentationURL: 'https://parceljs.org/languages/javascript/#custom-plugins'
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
if (diagnostics.length > 0) {
|
|
274
|
-
logger.warn(diagnostics);
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
async function getCodeHighlights(fs, filePath, redundantPresets) {
|
|
278
|
-
let ext = _path().default.extname(filePath);
|
|
279
|
-
if (ext !== '.js' && ext !== '.cjs' && ext !== '.mjs') {
|
|
280
|
-
let contents = await fs.readFile(filePath, 'utf8');
|
|
281
|
-
let json = _json().default.parse(contents);
|
|
282
|
-
let presets = json.presets || [];
|
|
283
|
-
let pointers = [];
|
|
284
|
-
for (let i = 0; i < presets.length; i++) {
|
|
285
|
-
if (Array.isArray(presets[i]) && redundantPresets.has(presets[i][0])) {
|
|
286
|
-
pointers.push({
|
|
287
|
-
type: 'value',
|
|
288
|
-
key: `/presets/${i}/0`
|
|
289
|
-
});
|
|
290
|
-
} else if (redundantPresets.has(presets[i])) {
|
|
291
|
-
pointers.push({
|
|
292
|
-
type: 'value',
|
|
293
|
-
key: `/presets/${i}`
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
if (pointers.length > 0) {
|
|
298
|
-
return (0, _diagnostic().generateJSONCodeHighlights)(contents, pointers);
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
return [{
|
|
302
|
-
start: {
|
|
303
|
-
line: 1,
|
|
304
|
-
column: 1
|
|
305
|
-
},
|
|
306
|
-
end: {
|
|
307
|
-
line: 1,
|
|
308
|
-
column: 1
|
|
309
|
-
}
|
|
310
|
-
}];
|
|
311
|
-
}
|
package/lib/constants.js
DELETED
package/lib/flow.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = getFlowOptions;
|
|
7
|
-
var _constants = require("./constants");
|
|
8
|
-
function _path() {
|
|
9
|
-
const data = _interopRequireDefault(require("path"));
|
|
10
|
-
_path = function () {
|
|
11
|
-
return data;
|
|
12
|
-
};
|
|
13
|
-
return data;
|
|
14
|
-
}
|
|
15
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
-
/**
|
|
17
|
-
* Generates a babel config for stripping away Flow types.
|
|
18
|
-
*/
|
|
19
|
-
async function getFlowOptions(config, options) {
|
|
20
|
-
if (!config.isSource) {
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// Only add flow plugin if `flow-bin` is listed as a dependency in the root package.json
|
|
25
|
-
let conf = await config.getConfigFrom(options.projectRoot + '/index', ['package.json']);
|
|
26
|
-
let pkg = conf === null || conf === void 0 ? void 0 : conf.contents;
|
|
27
|
-
if (!pkg || !(pkg.dependencies && pkg.dependencies['flow-bin']) && !(pkg.devDependencies && pkg.devDependencies['flow-bin'])) {
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
const babelCore = await options.packageManager.require('@babel/core', config.searchPath, {
|
|
31
|
-
range: _constants.BABEL_CORE_RANGE,
|
|
32
|
-
saveDev: true,
|
|
33
|
-
shouldAutoInstall: options.shouldAutoInstall
|
|
34
|
-
});
|
|
35
|
-
await options.packageManager.require('@babel/plugin-transform-flow-strip-types', config.searchPath, {
|
|
36
|
-
range: '^7.0.0',
|
|
37
|
-
saveDev: true,
|
|
38
|
-
shouldAutoInstall: options.shouldAutoInstall
|
|
39
|
-
});
|
|
40
|
-
return {
|
|
41
|
-
plugins: [babelCore.createConfigItem(['@babel/plugin-transform-flow-strip-types', {
|
|
42
|
-
requireDirective: true
|
|
43
|
-
}], {
|
|
44
|
-
type: 'plugin',
|
|
45
|
-
dirname: _path().default.dirname(config.searchPath)
|
|
46
|
-
})]
|
|
47
|
-
};
|
|
48
|
-
}
|
package/lib/jsx.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = isJSX;
|
|
7
|
-
function _path() {
|
|
8
|
-
const data = _interopRequireDefault(require("path"));
|
|
9
|
-
_path = function () {
|
|
10
|
-
return data;
|
|
11
|
-
};
|
|
12
|
-
return data;
|
|
13
|
-
}
|
|
14
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
const JSX_EXTENSIONS = new Set(['.jsx', '.tsx']);
|
|
16
|
-
const JSX_LIBRARIES = ['react', 'preact', 'nervejs', 'hyperapp'];
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Returns whether an asset is likely JSX. Attempts to detect react or react-like libraries
|
|
20
|
-
* along with
|
|
21
|
-
*/
|
|
22
|
-
async function isJSX(options, config) {
|
|
23
|
-
if (!config.isSource) {
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
if (JSX_EXTENSIONS.has(_path().default.extname(config.searchPath))) {
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
|
-
let pkg = await config.getPackage();
|
|
30
|
-
if (pkg !== null && pkg !== void 0 && pkg.alias && pkg.alias['react']) {
|
|
31
|
-
// e.g.: `{ alias: { "react": "preact/compat" } }`
|
|
32
|
-
return true;
|
|
33
|
-
} else {
|
|
34
|
-
// Find a dependency that implies JSX syntax.
|
|
35
|
-
return JSX_LIBRARIES.some(libName => pkg && (pkg.dependencies && pkg.dependencies[libName] || pkg.devDependencies && pkg.devDependencies[libName] || pkg.peerDependencies && pkg.peerDependencies[libName]));
|
|
36
|
-
}
|
|
37
|
-
}
|
package/lib/remapAstLocations.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.remapAstLocations = remapAstLocations;
|
|
7
|
-
function remapAstLocations(t, ast, map) {
|
|
8
|
-
// remap ast to original mappings
|
|
9
|
-
// This improves sourcemap accuracy and fixes sourcemaps when scope-hoisting
|
|
10
|
-
traverseAll(t, ast.program, node => {
|
|
11
|
-
if (node.loc) {
|
|
12
|
-
var _node$loc;
|
|
13
|
-
if ((_node$loc = node.loc) !== null && _node$loc !== void 0 && _node$loc.start) {
|
|
14
|
-
let mapping = map.findClosestMapping(node.loc.start.line, node.loc.start.column);
|
|
15
|
-
if (mapping !== null && mapping !== void 0 && mapping.original) {
|
|
16
|
-
// $FlowFixMe
|
|
17
|
-
node.loc.start.line = mapping.original.line;
|
|
18
|
-
// $FlowFixMe
|
|
19
|
-
node.loc.start.column = mapping.original.column;
|
|
20
|
-
|
|
21
|
-
// $FlowFixMe
|
|
22
|
-
let length = node.loc.end.column - node.loc.start.column;
|
|
23
|
-
|
|
24
|
-
// $FlowFixMe
|
|
25
|
-
node.loc.end.line = mapping.original.line;
|
|
26
|
-
// $FlowFixMe
|
|
27
|
-
node.loc.end.column = mapping.original.column + length;
|
|
28
|
-
|
|
29
|
-
// $FlowFixMe
|
|
30
|
-
node.loc.filename = mapping.source;
|
|
31
|
-
} else {
|
|
32
|
-
// Maintain null mappings?
|
|
33
|
-
node.loc = null;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
function traverseAll(t, node, visitor) {
|
|
40
|
-
if (!node) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
visitor(node);
|
|
44
|
-
for (let key of t.VISITOR_KEYS[node.type] || []) {
|
|
45
|
-
// $FlowFixMe
|
|
46
|
-
let subNode = node[key];
|
|
47
|
-
if (Array.isArray(subNode)) {
|
|
48
|
-
for (let i = 0; i < subNode.length; i++) {
|
|
49
|
-
traverseAll(t, subNode[i], visitor);
|
|
50
|
-
}
|
|
51
|
-
} else {
|
|
52
|
-
traverseAll(t, subNode, visitor);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
package/lib/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
package/lib/utils.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.enginesToBabelTargets = enginesToBabelTargets;
|
|
7
|
-
function _assert() {
|
|
8
|
-
const data = _interopRequireDefault(require("assert"));
|
|
9
|
-
_assert = function () {
|
|
10
|
-
return data;
|
|
11
|
-
};
|
|
12
|
-
return data;
|
|
13
|
-
}
|
|
14
|
-
function _semver() {
|
|
15
|
-
const data = _interopRequireDefault(require("semver"));
|
|
16
|
-
_semver = function () {
|
|
17
|
-
return data;
|
|
18
|
-
};
|
|
19
|
-
return data;
|
|
20
|
-
}
|
|
21
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
22
|
-
// Copied from @babel/helper-compilation-targets/lib/options.js
|
|
23
|
-
const TargetNames = {
|
|
24
|
-
node: 'node',
|
|
25
|
-
chrome: 'chrome',
|
|
26
|
-
opera: 'opera',
|
|
27
|
-
edge: 'edge',
|
|
28
|
-
firefox: 'firefox',
|
|
29
|
-
safari: 'safari',
|
|
30
|
-
ie: 'ie',
|
|
31
|
-
ios: 'ios',
|
|
32
|
-
android: 'android',
|
|
33
|
-
electron: 'electron',
|
|
34
|
-
samsung: 'samsung',
|
|
35
|
-
rhino: 'rhino'
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
// List of browsers to exclude when the esmodule target is specified.
|
|
39
|
-
// Based on https://caniuse.com/#feat=es6-module
|
|
40
|
-
const ESMODULE_BROWSERS = ['not ie <= 11', 'not edge < 16', 'not firefox < 60', 'not chrome < 61', 'not safari < 11', 'not opera < 48', 'not ios_saf < 11', 'not op_mini all', 'not android < 76', 'not blackberry > 0', 'not op_mob > 0', 'not and_chr < 76', 'not and_ff < 68', 'not ie_mob > 0', 'not and_uc > 0', 'not samsung < 8.2', 'not and_qq > 0', 'not baidu > 0', 'not kaios > 0'];
|
|
41
|
-
function enginesToBabelTargets(env) {
|
|
42
|
-
// "Targets" is the name @babel/preset-env uses for what Parcel calls engines.
|
|
43
|
-
// This should not be confused with Parcel's own targets.
|
|
44
|
-
// Unlike Parcel's engines, @babel/preset-env expects to work with minimum
|
|
45
|
-
// versions, not semver ranges, of its targets.
|
|
46
|
-
let targets = {};
|
|
47
|
-
for (let engineName of Object.keys(env.engines)) {
|
|
48
|
-
let engineValue = env.engines[engineName];
|
|
49
|
-
|
|
50
|
-
// if the engineValue is a string, it might be a semver range. Use the minimum
|
|
51
|
-
// possible version instead.
|
|
52
|
-
if (engineName === 'browsers') {
|
|
53
|
-
targets[engineName] = engineValue;
|
|
54
|
-
} else {
|
|
55
|
-
var _semver$minVersion;
|
|
56
|
-
(0, _assert().default)(typeof engineValue === 'string');
|
|
57
|
-
if (!TargetNames.hasOwnProperty(engineName)) continue;
|
|
58
|
-
let minVersion = (_semver$minVersion = _semver().default.minVersion(engineValue)) === null || _semver$minVersion === void 0 ? void 0 : _semver$minVersion.toString();
|
|
59
|
-
targets[engineName] = minVersion ?? engineValue;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
if (env.outputFormat === 'esmodule' && env.isBrowser()) {
|
|
63
|
-
// If there is already a browsers target, add a blacklist to exclude
|
|
64
|
-
// instead of using babel's esmodules target. This allows specifying
|
|
65
|
-
// a newer set of browsers than the baseline esmodule support list.
|
|
66
|
-
// See https://github.com/babel/babel/issues/8809.
|
|
67
|
-
if (targets.browsers) {
|
|
68
|
-
let browsers = Array.isArray(targets.browsers) ? targets.browsers : [targets.browsers];
|
|
69
|
-
targets.browsers = [...browsers, ...ESMODULE_BROWSERS];
|
|
70
|
-
} else {
|
|
71
|
-
targets.esmodules = true;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return targets;
|
|
75
|
-
}
|