@atlaspack/transformer-js 3.1.0 → 3.1.1-canary.10
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/LICENSE +201 -0
- package/lib/JSTransformer.js +893 -0
- package/lib/esmodule-helpers.js +32 -0
- package/package.json +9 -9
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
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.
|
|
@@ -0,0 +1,893 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
function _sourceMap() {
|
|
8
|
+
const data = _interopRequireDefault(require("@parcel/source-map"));
|
|
9
|
+
_sourceMap = function () {
|
|
10
|
+
return data;
|
|
11
|
+
};
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
function _plugin() {
|
|
15
|
+
const data = require("@atlaspack/plugin");
|
|
16
|
+
_plugin = function () {
|
|
17
|
+
return data;
|
|
18
|
+
};
|
|
19
|
+
return data;
|
|
20
|
+
}
|
|
21
|
+
function _rust() {
|
|
22
|
+
const data = require("@atlaspack/rust");
|
|
23
|
+
_rust = function () {
|
|
24
|
+
return data;
|
|
25
|
+
};
|
|
26
|
+
return data;
|
|
27
|
+
}
|
|
28
|
+
function _browserslist() {
|
|
29
|
+
const data = _interopRequireDefault(require("browserslist"));
|
|
30
|
+
_browserslist = function () {
|
|
31
|
+
return data;
|
|
32
|
+
};
|
|
33
|
+
return data;
|
|
34
|
+
}
|
|
35
|
+
function _semver() {
|
|
36
|
+
const data = _interopRequireDefault(require("semver"));
|
|
37
|
+
_semver = function () {
|
|
38
|
+
return data;
|
|
39
|
+
};
|
|
40
|
+
return data;
|
|
41
|
+
}
|
|
42
|
+
function _nullthrows() {
|
|
43
|
+
const data = _interopRequireDefault(require("nullthrows"));
|
|
44
|
+
_nullthrows = function () {
|
|
45
|
+
return data;
|
|
46
|
+
};
|
|
47
|
+
return data;
|
|
48
|
+
}
|
|
49
|
+
function _diagnostic() {
|
|
50
|
+
const data = _interopRequireWildcard(require("@atlaspack/diagnostic"));
|
|
51
|
+
_diagnostic = function () {
|
|
52
|
+
return data;
|
|
53
|
+
};
|
|
54
|
+
return data;
|
|
55
|
+
}
|
|
56
|
+
function _utils() {
|
|
57
|
+
const data = require("@atlaspack/utils");
|
|
58
|
+
_utils = function () {
|
|
59
|
+
return data;
|
|
60
|
+
};
|
|
61
|
+
return data;
|
|
62
|
+
}
|
|
63
|
+
var _package = _interopRequireDefault(require("../package.json"));
|
|
64
|
+
function _featureFlags() {
|
|
65
|
+
const data = require("@atlaspack/feature-flags");
|
|
66
|
+
_featureFlags = function () {
|
|
67
|
+
return data;
|
|
68
|
+
};
|
|
69
|
+
return data;
|
|
70
|
+
}
|
|
71
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
72
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
73
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
74
|
+
const JSX_EXTENSIONS = {
|
|
75
|
+
jsx: true,
|
|
76
|
+
tsx: true
|
|
77
|
+
};
|
|
78
|
+
const JSX_PRAGMA = {
|
|
79
|
+
react: {
|
|
80
|
+
pragma: 'React.createElement',
|
|
81
|
+
pragmaFrag: 'React.Fragment',
|
|
82
|
+
automatic: '>= 17.0.0 || ^16.14.0 || >= 0.0.0-0 < 0.0.0'
|
|
83
|
+
},
|
|
84
|
+
preact: {
|
|
85
|
+
pragma: 'h',
|
|
86
|
+
pragmaFrag: 'Fragment',
|
|
87
|
+
automatic: '>= 10.5.0'
|
|
88
|
+
},
|
|
89
|
+
nervjs: {
|
|
90
|
+
pragma: 'Nerv.createElement',
|
|
91
|
+
pragmaFrag: undefined,
|
|
92
|
+
automatic: undefined
|
|
93
|
+
},
|
|
94
|
+
hyperapp: {
|
|
95
|
+
pragma: 'h',
|
|
96
|
+
pragmaFrag: undefined,
|
|
97
|
+
automatic: undefined
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
const BROWSER_MAPPING = {
|
|
101
|
+
and_chr: 'chrome',
|
|
102
|
+
and_ff: 'firefox',
|
|
103
|
+
ie_mob: 'ie',
|
|
104
|
+
ios_saf: 'ios',
|
|
105
|
+
op_mob: 'opera',
|
|
106
|
+
and_qq: null,
|
|
107
|
+
and_uc: null,
|
|
108
|
+
baidu: null,
|
|
109
|
+
bb: null,
|
|
110
|
+
kaios: null,
|
|
111
|
+
op_mini: null
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
// List of browsers to exclude when the esmodule target is specified.
|
|
115
|
+
// Based on https://caniuse.com/#feat=es6-module
|
|
116
|
+
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'];
|
|
117
|
+
const CONFIG_SCHEMA = {
|
|
118
|
+
type: 'object',
|
|
119
|
+
properties: {
|
|
120
|
+
inlineFS: {
|
|
121
|
+
type: 'boolean'
|
|
122
|
+
},
|
|
123
|
+
inlineEnvironment: {
|
|
124
|
+
oneOf: [{
|
|
125
|
+
type: 'boolean'
|
|
126
|
+
}, {
|
|
127
|
+
type: 'array',
|
|
128
|
+
items: {
|
|
129
|
+
type: 'string'
|
|
130
|
+
}
|
|
131
|
+
}]
|
|
132
|
+
},
|
|
133
|
+
magicComments: {
|
|
134
|
+
type: 'boolean'
|
|
135
|
+
},
|
|
136
|
+
unstable_inlineConstants: {
|
|
137
|
+
type: 'boolean'
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
additionalProperties: false
|
|
141
|
+
};
|
|
142
|
+
const SCRIPT_ERRORS = {
|
|
143
|
+
browser: {
|
|
144
|
+
message: 'Browser scripts cannot have imports or exports.',
|
|
145
|
+
hint: 'Add the type="module" attribute to the <script> tag.'
|
|
146
|
+
},
|
|
147
|
+
'web-worker': {
|
|
148
|
+
message: 'Web workers cannot have imports or exports without the `type: "module"` option.',
|
|
149
|
+
hint: "Add {type: 'module'} as a second argument to the Worker constructor."
|
|
150
|
+
},
|
|
151
|
+
'service-worker': {
|
|
152
|
+
message: 'Service workers cannot have imports or exports without the `type: "module"` option.',
|
|
153
|
+
hint: "Add {type: 'module'} as a second argument to the navigator.serviceWorker.register() call."
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
// NOTE: Make sure this is in sync with the TypeScript definition in the @atlaspack/macros package.
|
|
158
|
+
var _default = exports.default = new (_plugin().Transformer)({
|
|
159
|
+
async loadConfig({
|
|
160
|
+
config,
|
|
161
|
+
options
|
|
162
|
+
}) {
|
|
163
|
+
let pkg = await config.getPackage();
|
|
164
|
+
let isJSX, pragma, pragmaFrag, jsxImportSource, automaticJSXRuntime, reactRefresh, decorators, useDefineForClassFields;
|
|
165
|
+
if (config.isSource) {
|
|
166
|
+
var _pkg$dependencies2, _pkg$devDependencies2, _pkg$peerDependencies2, _tsconfig$contents;
|
|
167
|
+
let reactLib;
|
|
168
|
+
if (pkg !== null && pkg !== void 0 && pkg.alias && pkg.alias['react']) {
|
|
169
|
+
// e.g.: `{ alias: { "react": "preact/compat" } }`
|
|
170
|
+
reactLib = 'react';
|
|
171
|
+
} else {
|
|
172
|
+
// Find a dependency that we can map to a JSX pragma
|
|
173
|
+
reactLib = Object.keys(JSX_PRAGMA).find(libName => {
|
|
174
|
+
var _pkg$dependencies, _pkg$devDependencies, _pkg$peerDependencies;
|
|
175
|
+
return (pkg === null || pkg === void 0 || (_pkg$dependencies = pkg.dependencies) === null || _pkg$dependencies === void 0 ? void 0 : _pkg$dependencies[libName]) || (pkg === null || pkg === void 0 || (_pkg$devDependencies = pkg.devDependencies) === null || _pkg$devDependencies === void 0 ? void 0 : _pkg$devDependencies[libName]) || (pkg === null || pkg === void 0 || (_pkg$peerDependencies = pkg.peerDependencies) === null || _pkg$peerDependencies === void 0 ? void 0 : _pkg$peerDependencies[libName]);
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
reactRefresh = options.hmrOptions && options.mode === 'development' && Boolean((pkg === null || pkg === void 0 || (_pkg$dependencies2 = pkg.dependencies) === null || _pkg$dependencies2 === void 0 ? void 0 : _pkg$dependencies2.react) || (pkg === null || pkg === void 0 || (_pkg$devDependencies2 = pkg.devDependencies) === null || _pkg$devDependencies2 === void 0 ? void 0 : _pkg$devDependencies2.react) || (pkg === null || pkg === void 0 || (_pkg$peerDependencies2 = pkg.peerDependencies) === null || _pkg$peerDependencies2 === void 0 ? void 0 : _pkg$peerDependencies2.react));
|
|
179
|
+
let tsconfig = await config.getConfigFrom(options.projectRoot + '/index', ['tsconfig.json', 'jsconfig.json']);
|
|
180
|
+
let compilerOptions = tsconfig === null || tsconfig === void 0 || (_tsconfig$contents = tsconfig.contents) === null || _tsconfig$contents === void 0 ? void 0 : _tsconfig$contents.compilerOptions;
|
|
181
|
+
|
|
182
|
+
// Use explicitly defined JSX options in tsconfig.json over inferred values from dependencies.
|
|
183
|
+
pragma = (compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.jsxFactory) || (reactLib ? JSX_PRAGMA[reactLib].pragma : undefined);
|
|
184
|
+
pragmaFrag = (compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.jsxFragmentFactory) || (reactLib ? JSX_PRAGMA[reactLib].pragmaFrag : undefined);
|
|
185
|
+
if ((compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.jsx) === 'react-jsx' || (compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.jsx) === 'react-jsxdev' || compilerOptions !== null && compilerOptions !== void 0 && compilerOptions.jsxImportSource) {
|
|
186
|
+
jsxImportSource = compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.jsxImportSource;
|
|
187
|
+
automaticJSXRuntime = true;
|
|
188
|
+
} else if (reactLib) {
|
|
189
|
+
var _JSX_PRAGMA$effective, _pkg$dependencies3, _pkg$devDependencies3, _pkg$peerDependencies3, _semver$minVersion;
|
|
190
|
+
let effectiveReactLib = pkg !== null && pkg !== void 0 && pkg.alias && pkg.alias['react'] === 'preact/compat' ? 'preact' : reactLib;
|
|
191
|
+
let automaticVersion = (_JSX_PRAGMA$effective = JSX_PRAGMA[effectiveReactLib]) === null || _JSX_PRAGMA$effective === void 0 ? void 0 : _JSX_PRAGMA$effective.automatic;
|
|
192
|
+
let reactLibVersion = (pkg === null || pkg === void 0 || (_pkg$dependencies3 = pkg.dependencies) === null || _pkg$dependencies3 === void 0 ? void 0 : _pkg$dependencies3[effectiveReactLib]) || (pkg === null || pkg === void 0 || (_pkg$devDependencies3 = pkg.devDependencies) === null || _pkg$devDependencies3 === void 0 ? void 0 : _pkg$devDependencies3[effectiveReactLib]) || (pkg === null || pkg === void 0 || (_pkg$peerDependencies3 = pkg.peerDependencies) === null || _pkg$peerDependencies3 === void 0 ? void 0 : _pkg$peerDependencies3[effectiveReactLib]);
|
|
193
|
+
reactLibVersion = reactLibVersion ? _semver().default.validRange(reactLibVersion) : null;
|
|
194
|
+
let minReactLibVersion = reactLibVersion !== null && reactLibVersion !== '*' ? (_semver$minVersion = _semver().default.minVersion(reactLibVersion)) === null || _semver$minVersion === void 0 ? void 0 : _semver$minVersion.toString() : null;
|
|
195
|
+
automaticJSXRuntime = automaticVersion && !(compilerOptions !== null && compilerOptions !== void 0 && compilerOptions.jsxFactory) && minReactLibVersion != null && _semver().default.satisfies(minReactLibVersion, automaticVersion, {
|
|
196
|
+
includePrerelease: true
|
|
197
|
+
});
|
|
198
|
+
if (automaticJSXRuntime) {
|
|
199
|
+
jsxImportSource = reactLib;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
isJSX = Boolean((compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.jsx) || pragma);
|
|
203
|
+
decorators = compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.experimentalDecorators;
|
|
204
|
+
useDefineForClassFields = compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.useDefineForClassFields;
|
|
205
|
+
if (useDefineForClassFields === undefined && (compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions.target) != null) {
|
|
206
|
+
// Default useDefineForClassFields to true if target is ES2022 or higher (including ESNext)
|
|
207
|
+
let target = compilerOptions.target.slice(2);
|
|
208
|
+
if (target === 'next') {
|
|
209
|
+
useDefineForClassFields = true;
|
|
210
|
+
} else {
|
|
211
|
+
useDefineForClassFields = Number(target) >= 2022;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// Check if we should ignore fs calls
|
|
217
|
+
// See https://github.com/defunctzombie/node-browser-resolve#skip
|
|
218
|
+
let ignoreFS = pkg && pkg.browser && typeof pkg.browser === 'object' && pkg.browser.fs === false;
|
|
219
|
+
let conf = await config.getConfigFrom(options.projectRoot + '/index', [], {
|
|
220
|
+
packageKey: '@atlaspack/transformer-js'
|
|
221
|
+
});
|
|
222
|
+
let inlineEnvironment = config.isSource;
|
|
223
|
+
let inlineFS = !ignoreFS;
|
|
224
|
+
let inlineConstants = false;
|
|
225
|
+
let magicComments = false;
|
|
226
|
+
if (conf && conf.contents) {
|
|
227
|
+
var _conf$contents, _conf$contents2, _conf$contents3, _conf$contents4;
|
|
228
|
+
_utils().validateSchema.diagnostic(CONFIG_SCHEMA, {
|
|
229
|
+
data: conf.contents,
|
|
230
|
+
// FIXME
|
|
231
|
+
source: await options.inputFS.readFile(conf.filePath, 'utf8'),
|
|
232
|
+
filePath: conf.filePath,
|
|
233
|
+
prependKey: `/${(0, _diagnostic().encodeJSONKeyComponent)('@atlaspack/transformer-js')}`
|
|
234
|
+
},
|
|
235
|
+
// FIXME
|
|
236
|
+
'@atlaspack/transformer-js', 'Invalid config for @atlaspack/transformer-js');
|
|
237
|
+
magicComments = ((_conf$contents = conf.contents) === null || _conf$contents === void 0 ? void 0 : _conf$contents.magicComments) ?? magicComments;
|
|
238
|
+
inlineEnvironment = ((_conf$contents2 = conf.contents) === null || _conf$contents2 === void 0 ? void 0 : _conf$contents2.inlineEnvironment) ?? inlineEnvironment;
|
|
239
|
+
inlineFS = ((_conf$contents3 = conf.contents) === null || _conf$contents3 === void 0 ? void 0 : _conf$contents3.inlineFS) ?? inlineFS;
|
|
240
|
+
inlineConstants = ((_conf$contents4 = conf.contents) === null || _conf$contents4 === void 0 ? void 0 : _conf$contents4.unstable_inlineConstants) ?? inlineConstants;
|
|
241
|
+
}
|
|
242
|
+
return {
|
|
243
|
+
isJSX,
|
|
244
|
+
automaticJSXRuntime,
|
|
245
|
+
jsxImportSource,
|
|
246
|
+
pragma,
|
|
247
|
+
pragmaFrag,
|
|
248
|
+
inlineEnvironment,
|
|
249
|
+
inlineFS,
|
|
250
|
+
inlineConstants,
|
|
251
|
+
reactRefresh,
|
|
252
|
+
decorators,
|
|
253
|
+
useDefineForClassFields,
|
|
254
|
+
magicComments
|
|
255
|
+
};
|
|
256
|
+
},
|
|
257
|
+
async transform({
|
|
258
|
+
asset,
|
|
259
|
+
config,
|
|
260
|
+
options,
|
|
261
|
+
logger
|
|
262
|
+
}) {
|
|
263
|
+
let [code, originalMap] = await Promise.all([asset.getBuffer(), asset.getMap()]);
|
|
264
|
+
let targets;
|
|
265
|
+
if (asset.env.isElectron() && asset.env.engines.electron) {
|
|
266
|
+
var _semver$minVersion2;
|
|
267
|
+
targets = {
|
|
268
|
+
electron: (_semver$minVersion2 = _semver().default.minVersion(asset.env.engines.electron)) === null || _semver$minVersion2 === void 0 ? void 0 : _semver$minVersion2.toString()
|
|
269
|
+
};
|
|
270
|
+
} else if (asset.env.isBrowser() && asset.env.engines.browsers) {
|
|
271
|
+
targets = {};
|
|
272
|
+
let browsers = Array.isArray(asset.env.engines.browsers) ? asset.env.engines.browsers : [asset.env.engines.browsers];
|
|
273
|
+
|
|
274
|
+
// If the output format is esmodule, exclude browsers
|
|
275
|
+
// that support them natively so that we transpile less.
|
|
276
|
+
if (asset.env.outputFormat === 'esmodule') {
|
|
277
|
+
browsers = [...browsers, ...ESMODULE_BROWSERS];
|
|
278
|
+
}
|
|
279
|
+
browsers = (0, _browserslist().default)(browsers);
|
|
280
|
+
for (let browser of browsers) {
|
|
281
|
+
let [name, version] = browser.split(' ');
|
|
282
|
+
if (BROWSER_MAPPING.hasOwnProperty(name)) {
|
|
283
|
+
name = BROWSER_MAPPING[name];
|
|
284
|
+
if (!name) {
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
let [major, minor = '0', patch = '0'] = version.split('-')[0].split('.');
|
|
289
|
+
if (isNaN(major) || isNaN(minor) || isNaN(patch)) {
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
let semverVersion = `${major}.${minor}.${patch}`;
|
|
293
|
+
if (targets[name] == null || _semver().default.gt(targets[name], semverVersion)) {
|
|
294
|
+
targets[name] = semverVersion;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
} else if (asset.env.isNode() && asset.env.engines.node) {
|
|
298
|
+
var _semver$minVersion3;
|
|
299
|
+
targets = {
|
|
300
|
+
node: (_semver$minVersion3 = _semver().default.minVersion(asset.env.engines.node)) === null || _semver$minVersion3 === void 0 ? void 0 : _semver$minVersion3.toString()
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
let env = {};
|
|
304
|
+
if (!(config !== null && config !== void 0 && config.inlineEnvironment)) {
|
|
305
|
+
if (options.env.NODE_ENV != null) {
|
|
306
|
+
env.NODE_ENV = options.env.NODE_ENV;
|
|
307
|
+
}
|
|
308
|
+
} else if (Array.isArray(config === null || config === void 0 ? void 0 : config.inlineEnvironment)) {
|
|
309
|
+
for (let match of (0, _utils().globMatch)(Object.keys(options.env), config.inlineEnvironment)) {
|
|
310
|
+
env[match] = String(options.env[match]);
|
|
311
|
+
}
|
|
312
|
+
} else {
|
|
313
|
+
for (let key in options.env) {
|
|
314
|
+
if (!key.startsWith('npm_')) {
|
|
315
|
+
env[key] = String(options.env[key]);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
let supportsModuleWorkers = asset.env.shouldScopeHoist && asset.env.supports('worker-module', true);
|
|
320
|
+
let isJSX = Boolean(config === null || config === void 0 ? void 0 : config.isJSX);
|
|
321
|
+
if (asset.isSource) {
|
|
322
|
+
if (asset.type === 'ts') {
|
|
323
|
+
isJSX = false;
|
|
324
|
+
} else if (!isJSX) {
|
|
325
|
+
isJSX = Boolean(JSX_EXTENSIONS[asset.type]);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
let macroAssets = [];
|
|
329
|
+
let {
|
|
330
|
+
dependencies,
|
|
331
|
+
code: compiledCode,
|
|
332
|
+
map,
|
|
333
|
+
shebang,
|
|
334
|
+
hoist_result,
|
|
335
|
+
symbol_result,
|
|
336
|
+
needs_esm_helpers,
|
|
337
|
+
diagnostics,
|
|
338
|
+
used_env,
|
|
339
|
+
has_node_replacements,
|
|
340
|
+
is_constant_module,
|
|
341
|
+
conditions
|
|
342
|
+
} = await (_rust().transformAsync || _rust().transform)({
|
|
343
|
+
filename: asset.filePath,
|
|
344
|
+
code,
|
|
345
|
+
module_id: asset.id,
|
|
346
|
+
project_root: options.projectRoot,
|
|
347
|
+
replace_env: !asset.env.isNode(),
|
|
348
|
+
inline_fs: Boolean(config === null || config === void 0 ? void 0 : config.inlineFS) && !asset.env.isNode(),
|
|
349
|
+
insert_node_globals: !asset.env.isNode() && asset.env.sourceType !== 'script',
|
|
350
|
+
node_replacer: asset.env.isNode(),
|
|
351
|
+
is_browser: asset.env.isBrowser(),
|
|
352
|
+
is_worker: asset.env.isWorker(),
|
|
353
|
+
env,
|
|
354
|
+
is_type_script: asset.type === 'ts' || asset.type === 'tsx',
|
|
355
|
+
is_jsx: isJSX,
|
|
356
|
+
jsx_pragma: config === null || config === void 0 ? void 0 : config.pragma,
|
|
357
|
+
jsx_pragma_frag: config === null || config === void 0 ? void 0 : config.pragmaFrag,
|
|
358
|
+
automatic_jsx_runtime: Boolean(config === null || config === void 0 ? void 0 : config.automaticJSXRuntime),
|
|
359
|
+
jsx_import_source: config === null || config === void 0 ? void 0 : config.jsxImportSource,
|
|
360
|
+
is_development: options.mode === 'development',
|
|
361
|
+
react_refresh: asset.env.isBrowser() && !asset.env.isLibrary && !asset.env.isWorker() && !asset.env.isWorklet() && Boolean(config === null || config === void 0 ? void 0 : config.reactRefresh),
|
|
362
|
+
decorators: Boolean(config === null || config === void 0 ? void 0 : config.decorators),
|
|
363
|
+
use_define_for_class_fields: Boolean(config === null || config === void 0 ? void 0 : config.useDefineForClassFields),
|
|
364
|
+
targets,
|
|
365
|
+
source_maps: !!asset.env.sourceMap,
|
|
366
|
+
scope_hoist: asset.env.shouldScopeHoist && asset.env.sourceType !== 'script',
|
|
367
|
+
source_type: asset.env.sourceType === 'script' ? 'Script' : 'Module',
|
|
368
|
+
supports_module_workers: supportsModuleWorkers,
|
|
369
|
+
is_library: asset.env.isLibrary,
|
|
370
|
+
is_esm_output: asset.env.outputFormat === 'esmodule',
|
|
371
|
+
trace_bailouts: options.logLevel === 'verbose',
|
|
372
|
+
is_swc_helpers: /@swc[/\\]helpers/.test(asset.filePath),
|
|
373
|
+
standalone: asset.query.has('standalone'),
|
|
374
|
+
inline_constants: config.inlineConstants,
|
|
375
|
+
conditional_bundling: options.featureFlags.conditionalBundlingApi,
|
|
376
|
+
magic_comments: Boolean(config === null || config === void 0 ? void 0 : config.magicComments),
|
|
377
|
+
callMacro: asset.isSource ? async (err, src, exportName, args, loc) => {
|
|
378
|
+
let mod;
|
|
379
|
+
try {
|
|
380
|
+
mod = await options.packageManager.require(src, asset.filePath);
|
|
381
|
+
|
|
382
|
+
// Default interop for CommonJS modules.
|
|
383
|
+
if (exportName === 'default' && !mod.__esModule &&
|
|
384
|
+
// $FlowFixMe
|
|
385
|
+
Object.prototype.toString.call(config) !== '[object Module]') {
|
|
386
|
+
mod = {
|
|
387
|
+
default: mod
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
if (!Object.hasOwnProperty.call(mod, exportName)) {
|
|
391
|
+
throw new Error(`"${src}" does not export "${exportName}".`);
|
|
392
|
+
}
|
|
393
|
+
} catch (err) {
|
|
394
|
+
throw {
|
|
395
|
+
kind: 1,
|
|
396
|
+
message: err.message
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
try {
|
|
400
|
+
if (typeof mod[exportName] === 'function') {
|
|
401
|
+
return mod[exportName].apply({
|
|
402
|
+
// Allows macros to emit additional assets to add as dependencies (e.g. css).
|
|
403
|
+
addAsset(a) {
|
|
404
|
+
let k = String(macroAssets.length);
|
|
405
|
+
let map;
|
|
406
|
+
if (asset.env.sourceMap) {
|
|
407
|
+
// Generate a source map that maps each line of the asset to the original macro call.
|
|
408
|
+
map = new (_sourceMap().default)(options.projectRoot);
|
|
409
|
+
let mappings = [];
|
|
410
|
+
let line = 1;
|
|
411
|
+
for (let i = 0; i <= a.content.length; i++) {
|
|
412
|
+
if (i === a.content.length || a.content[i] === '\n') {
|
|
413
|
+
mappings.push({
|
|
414
|
+
generated: {
|
|
415
|
+
line,
|
|
416
|
+
column: 0
|
|
417
|
+
},
|
|
418
|
+
source: asset.filePath,
|
|
419
|
+
original: {
|
|
420
|
+
line: loc.line,
|
|
421
|
+
column: loc.col
|
|
422
|
+
}
|
|
423
|
+
});
|
|
424
|
+
line++;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
map.addIndexedMappings(mappings);
|
|
428
|
+
if (originalMap) {
|
|
429
|
+
map.extends(originalMap);
|
|
430
|
+
} else {
|
|
431
|
+
map.setSourceContent(asset.filePath, code.toString());
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
macroAssets.push({
|
|
435
|
+
type: a.type,
|
|
436
|
+
content: a.content,
|
|
437
|
+
map,
|
|
438
|
+
uniqueKey: k
|
|
439
|
+
});
|
|
440
|
+
asset.addDependency({
|
|
441
|
+
specifier: k,
|
|
442
|
+
specifierType: 'esm'
|
|
443
|
+
});
|
|
444
|
+
},
|
|
445
|
+
invalidateOnFileChange(filePath) {
|
|
446
|
+
asset.invalidateOnFileChange(filePath);
|
|
447
|
+
},
|
|
448
|
+
invalidateOnFileCreate(invalidation) {
|
|
449
|
+
asset.invalidateOnFileCreate(invalidation);
|
|
450
|
+
},
|
|
451
|
+
invalidateOnEnvChange(env) {
|
|
452
|
+
asset.invalidateOnEnvChange(env);
|
|
453
|
+
},
|
|
454
|
+
invalidateOnStartup() {
|
|
455
|
+
asset.invalidateOnStartup();
|
|
456
|
+
},
|
|
457
|
+
invalidateOnBuild() {
|
|
458
|
+
asset.invalidateOnBuild();
|
|
459
|
+
}
|
|
460
|
+
}, args);
|
|
461
|
+
} else {
|
|
462
|
+
throw new Error(`"${exportName}" in "${src}" is not a function.`);
|
|
463
|
+
}
|
|
464
|
+
} catch (err) {
|
|
465
|
+
// Remove atlaspack core from stack and build string so Rust can process errors more easily.
|
|
466
|
+
let stack = (err.stack || '').split('\n').slice(1);
|
|
467
|
+
let message = err.message;
|
|
468
|
+
for (let line of stack) {
|
|
469
|
+
if (line.includes(__filename)) {
|
|
470
|
+
break;
|
|
471
|
+
}
|
|
472
|
+
message += '\n' + line;
|
|
473
|
+
}
|
|
474
|
+
throw {
|
|
475
|
+
kind: 2,
|
|
476
|
+
message
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
} : null
|
|
480
|
+
});
|
|
481
|
+
if ((0, _featureFlags().getFeatureFlag)('conditionalBundlingApi')) {
|
|
482
|
+
asset.meta.conditions = conditions.map(c => ({
|
|
483
|
+
key: c.key,
|
|
484
|
+
ifTruePlaceholder: c.if_true_placeholder,
|
|
485
|
+
ifFalsePlaceholder: c.if_false_placeholder
|
|
486
|
+
}));
|
|
487
|
+
}
|
|
488
|
+
if (is_constant_module) {
|
|
489
|
+
asset.meta.isConstantModule = true;
|
|
490
|
+
}
|
|
491
|
+
let convertLoc = loc => {
|
|
492
|
+
let location = {
|
|
493
|
+
filePath: asset.filePath,
|
|
494
|
+
start: {
|
|
495
|
+
line: loc.start_line + Number(asset.meta.startLine ?? 1) - 1,
|
|
496
|
+
column: loc.start_col
|
|
497
|
+
},
|
|
498
|
+
end: {
|
|
499
|
+
line: loc.end_line + Number(asset.meta.startLine ?? 1) - 1,
|
|
500
|
+
column: loc.end_col
|
|
501
|
+
}
|
|
502
|
+
};
|
|
503
|
+
|
|
504
|
+
// If there is an original source map, use it to remap to the original source location.
|
|
505
|
+
if (originalMap) {
|
|
506
|
+
location = (0, _utils().remapSourceLocation)(location, originalMap);
|
|
507
|
+
}
|
|
508
|
+
return location;
|
|
509
|
+
};
|
|
510
|
+
if (diagnostics) {
|
|
511
|
+
let errors = diagnostics.filter(d => d.severity === 'Error' || d.severity === 'SourceError' && asset.isSource);
|
|
512
|
+
let warnings = diagnostics.filter(d => d.severity === 'Warning' || d.severity === 'SourceError' && !asset.isSource);
|
|
513
|
+
let convertDiagnostic = diagnostic => {
|
|
514
|
+
var _diagnostic$code_high;
|
|
515
|
+
let message = diagnostic.message;
|
|
516
|
+
if (message === 'SCRIPT_ERROR') {
|
|
517
|
+
let err = SCRIPT_ERRORS[asset.env.context];
|
|
518
|
+
message = (err === null || err === void 0 ? void 0 : err.message) || SCRIPT_ERRORS.browser.message;
|
|
519
|
+
}
|
|
520
|
+
let res = {
|
|
521
|
+
message,
|
|
522
|
+
codeFrames: [{
|
|
523
|
+
filePath: asset.filePath,
|
|
524
|
+
codeHighlights: (_diagnostic$code_high = diagnostic.code_highlights) === null || _diagnostic$code_high === void 0 ? void 0 : _diagnostic$code_high.map(highlight => (0, _diagnostic().convertSourceLocationToHighlight)(convertLoc(highlight.loc), highlight.message ?? undefined))
|
|
525
|
+
}],
|
|
526
|
+
hints: diagnostic.hints
|
|
527
|
+
};
|
|
528
|
+
if (diagnostic.documentation_url) {
|
|
529
|
+
res.documentationURL = diagnostic.documentation_url;
|
|
530
|
+
}
|
|
531
|
+
if (diagnostic.show_environment) {
|
|
532
|
+
if (asset.env.loc && asset.env.loc.filePath !== asset.filePath) {
|
|
533
|
+
var _res$codeFrames;
|
|
534
|
+
(_res$codeFrames = res.codeFrames) === null || _res$codeFrames === void 0 || _res$codeFrames.push({
|
|
535
|
+
filePath: asset.env.loc.filePath,
|
|
536
|
+
codeHighlights: [(0, _diagnostic().convertSourceLocationToHighlight)(asset.env.loc, 'The environment was originally created here')]
|
|
537
|
+
});
|
|
538
|
+
}
|
|
539
|
+
let err = SCRIPT_ERRORS[asset.env.context];
|
|
540
|
+
if (err) {
|
|
541
|
+
if (!res.hints) {
|
|
542
|
+
res.hints = [err.hint];
|
|
543
|
+
} else {
|
|
544
|
+
res.hints.push(err.hint);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
return res;
|
|
549
|
+
};
|
|
550
|
+
if (errors.length > 0) {
|
|
551
|
+
throw new (_diagnostic().default)({
|
|
552
|
+
diagnostic: errors.map(convertDiagnostic)
|
|
553
|
+
});
|
|
554
|
+
}
|
|
555
|
+
logger.warn(warnings.map(convertDiagnostic));
|
|
556
|
+
}
|
|
557
|
+
if (shebang) {
|
|
558
|
+
asset.meta.interpreter = shebang;
|
|
559
|
+
}
|
|
560
|
+
if (has_node_replacements) {
|
|
561
|
+
asset.meta.has_node_replacements = has_node_replacements;
|
|
562
|
+
}
|
|
563
|
+
for (let env of used_env) {
|
|
564
|
+
asset.invalidateOnEnvChange(env);
|
|
565
|
+
}
|
|
566
|
+
for (let dep of dependencies) {
|
|
567
|
+
if (dep.kind === 'WebWorker') {
|
|
568
|
+
// Use native ES module output if the worker was created with `type: 'module'` and all targets
|
|
569
|
+
// support native module workers. Only do this if parent asset output format is also esmodule so that
|
|
570
|
+
// assets can be shared between workers and the main thread in the global output format.
|
|
571
|
+
let outputFormat;
|
|
572
|
+
if (asset.env.outputFormat === 'esmodule' && dep.source_type === 'Module' && supportsModuleWorkers) {
|
|
573
|
+
outputFormat = 'esmodule';
|
|
574
|
+
} else {
|
|
575
|
+
outputFormat = asset.env.outputFormat === 'commonjs' ? 'commonjs' : 'global';
|
|
576
|
+
}
|
|
577
|
+
let loc = convertLoc(dep.loc);
|
|
578
|
+
asset.addURLDependency(dep.specifier, {
|
|
579
|
+
loc,
|
|
580
|
+
env: {
|
|
581
|
+
context: 'web-worker',
|
|
582
|
+
sourceType: dep.source_type === 'Module' ? 'module' : 'script',
|
|
583
|
+
outputFormat,
|
|
584
|
+
loc
|
|
585
|
+
},
|
|
586
|
+
meta: {
|
|
587
|
+
webworker: true,
|
|
588
|
+
placeholder: dep.placeholder
|
|
589
|
+
}
|
|
590
|
+
});
|
|
591
|
+
} else if (dep.kind === 'ServiceWorker') {
|
|
592
|
+
let loc = convertLoc(dep.loc);
|
|
593
|
+
asset.addURLDependency(dep.specifier, {
|
|
594
|
+
loc,
|
|
595
|
+
needsStableName: true,
|
|
596
|
+
env: {
|
|
597
|
+
context: 'service-worker',
|
|
598
|
+
sourceType: dep.source_type === 'Module' ? 'module' : 'script',
|
|
599
|
+
outputFormat: 'global',
|
|
600
|
+
// TODO: module service worker support
|
|
601
|
+
loc
|
|
602
|
+
},
|
|
603
|
+
meta: {
|
|
604
|
+
placeholder: dep.placeholder
|
|
605
|
+
}
|
|
606
|
+
});
|
|
607
|
+
} else if (dep.kind === 'Worklet') {
|
|
608
|
+
let loc = convertLoc(dep.loc);
|
|
609
|
+
asset.addURLDependency(dep.specifier, {
|
|
610
|
+
loc,
|
|
611
|
+
env: {
|
|
612
|
+
context: 'worklet',
|
|
613
|
+
sourceType: 'module',
|
|
614
|
+
outputFormat: 'esmodule',
|
|
615
|
+
// Worklets require ESM
|
|
616
|
+
loc
|
|
617
|
+
},
|
|
618
|
+
meta: {
|
|
619
|
+
placeholder: dep.placeholder
|
|
620
|
+
}
|
|
621
|
+
});
|
|
622
|
+
} else if (dep.kind === 'Url') {
|
|
623
|
+
asset.addURLDependency(dep.specifier, {
|
|
624
|
+
bundleBehavior: 'isolated',
|
|
625
|
+
loc: convertLoc(dep.loc),
|
|
626
|
+
meta: {
|
|
627
|
+
placeholder: dep.placeholder
|
|
628
|
+
}
|
|
629
|
+
});
|
|
630
|
+
} else if (dep.kind === 'File') {
|
|
631
|
+
asset.invalidateOnFileChange(dep.specifier);
|
|
632
|
+
} else {
|
|
633
|
+
let meta = {
|
|
634
|
+
kind: dep.kind
|
|
635
|
+
};
|
|
636
|
+
if (dep.attributes) {
|
|
637
|
+
meta.importAttributes = dep.attributes;
|
|
638
|
+
}
|
|
639
|
+
if (dep.placeholder) {
|
|
640
|
+
meta.placeholder = dep.placeholder;
|
|
641
|
+
}
|
|
642
|
+
let env;
|
|
643
|
+
if (dep.kind === 'DynamicImport') {
|
|
644
|
+
// https://html.spec.whatwg.org/multipage/webappapis.html#hostimportmoduledynamically(referencingscriptormodule,-modulerequest,-promisecapability)
|
|
645
|
+
if (asset.env.isWorklet() || asset.env.context === 'service-worker') {
|
|
646
|
+
let loc = convertLoc(dep.loc);
|
|
647
|
+
let diagnostic = {
|
|
648
|
+
message: `import() is not allowed in ${asset.env.isWorklet() ? 'worklets' : 'service workers'}.`,
|
|
649
|
+
codeFrames: [{
|
|
650
|
+
filePath: asset.filePath,
|
|
651
|
+
codeHighlights: [(0, _diagnostic().convertSourceLocationToHighlight)(loc)]
|
|
652
|
+
}],
|
|
653
|
+
hints: ['Try using a static `import`.']
|
|
654
|
+
};
|
|
655
|
+
if (asset.env.loc) {
|
|
656
|
+
diagnostic.codeFrames.push({
|
|
657
|
+
filePath: asset.env.loc.filePath,
|
|
658
|
+
codeHighlights: [(0, _diagnostic().convertSourceLocationToHighlight)(asset.env.loc, 'The environment was originally created here')]
|
|
659
|
+
});
|
|
660
|
+
}
|
|
661
|
+
throw new (_diagnostic().default)({
|
|
662
|
+
diagnostic
|
|
663
|
+
});
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
// If all of the target engines support dynamic import natively,
|
|
667
|
+
// we can output native ESM if scope hoisting is enabled.
|
|
668
|
+
// Only do this for scripts, rather than modules in the global
|
|
669
|
+
// output format so that assets can be shared between the bundles.
|
|
670
|
+
let outputFormat = asset.env.outputFormat;
|
|
671
|
+
if (asset.env.sourceType === 'script' && asset.env.shouldScopeHoist && asset.env.supports('dynamic-import', true)) {
|
|
672
|
+
outputFormat = 'esmodule';
|
|
673
|
+
}
|
|
674
|
+
env = {
|
|
675
|
+
sourceType: 'module',
|
|
676
|
+
outputFormat,
|
|
677
|
+
loc: convertLoc(dep.loc)
|
|
678
|
+
};
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
// Always bundle helpers, even with includeNodeModules: false, except if this is a library.
|
|
682
|
+
let isHelper = dep.is_helper && !(dep.specifier.endsWith('/jsx-runtime') || dep.specifier.endsWith('/jsx-dev-runtime'));
|
|
683
|
+
if (isHelper && !asset.env.isLibrary) {
|
|
684
|
+
env = {
|
|
685
|
+
...env,
|
|
686
|
+
includeNodeModules: true
|
|
687
|
+
};
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
// Add required version range for helpers.
|
|
691
|
+
let range;
|
|
692
|
+
if (isHelper) {
|
|
693
|
+
let idx = dep.specifier.indexOf('/');
|
|
694
|
+
if (dep.specifier[0] === '@') {
|
|
695
|
+
idx = dep.specifier.indexOf('/', idx + 1);
|
|
696
|
+
}
|
|
697
|
+
let module = idx >= 0 ? dep.specifier.slice(0, idx) : dep.specifier;
|
|
698
|
+
range = _package.default.dependencies[module];
|
|
699
|
+
}
|
|
700
|
+
asset.addDependency({
|
|
701
|
+
specifier: dep.specifier,
|
|
702
|
+
specifierType: dep.kind === 'Require' ? 'commonjs' : 'esm',
|
|
703
|
+
loc: convertLoc(dep.loc),
|
|
704
|
+
priority: dep.kind === 'DynamicImport' ? 'lazy' : dep.kind === 'ConditionalImport' ? 'conditional' : 'sync',
|
|
705
|
+
isOptional: dep.is_optional,
|
|
706
|
+
meta,
|
|
707
|
+
resolveFrom: isHelper ? __filename : undefined,
|
|
708
|
+
range,
|
|
709
|
+
env
|
|
710
|
+
});
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
asset.meta.id = asset.id;
|
|
714
|
+
if (hoist_result) {
|
|
715
|
+
asset.symbols.ensure();
|
|
716
|
+
for (let {
|
|
717
|
+
exported,
|
|
718
|
+
local,
|
|
719
|
+
loc,
|
|
720
|
+
is_esm
|
|
721
|
+
} of hoist_result.exported_symbols) {
|
|
722
|
+
asset.symbols.set(exported, local, convertLoc(loc), {
|
|
723
|
+
isEsm: is_esm
|
|
724
|
+
});
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
// deps is a map of dependencies that are keyed by placeholder or specifier
|
|
728
|
+
// If a placeholder is present, that is used first since placeholders are
|
|
729
|
+
// hashed with DependencyKind's.
|
|
730
|
+
// If not, the specifier is used along with its specifierType appended to
|
|
731
|
+
// it to separate dependencies with the same specifier.
|
|
732
|
+
let deps = new Map(asset.getDependencies().map(dep => [dep.meta.placeholder ?? dep.specifier, dep]));
|
|
733
|
+
for (let dep of deps.values()) {
|
|
734
|
+
dep.symbols.ensure();
|
|
735
|
+
}
|
|
736
|
+
for (let {
|
|
737
|
+
source,
|
|
738
|
+
local,
|
|
739
|
+
imported,
|
|
740
|
+
loc
|
|
741
|
+
} of hoist_result.imported_symbols) {
|
|
742
|
+
let dep = deps.get(source);
|
|
743
|
+
if (!dep) continue;
|
|
744
|
+
dep.symbols.set(imported, local, convertLoc(loc));
|
|
745
|
+
}
|
|
746
|
+
for (let {
|
|
747
|
+
source,
|
|
748
|
+
local,
|
|
749
|
+
imported,
|
|
750
|
+
loc
|
|
751
|
+
} of hoist_result.re_exports) {
|
|
752
|
+
let dep = deps.get(source);
|
|
753
|
+
if (!dep) continue;
|
|
754
|
+
if (local === '*' && imported === '*') {
|
|
755
|
+
dep.symbols.set('*', '*', convertLoc(loc), true);
|
|
756
|
+
} else {
|
|
757
|
+
var _dep$symbols$get;
|
|
758
|
+
let reExportName = ((_dep$symbols$get = dep.symbols.get(imported)) === null || _dep$symbols$get === void 0 ? void 0 : _dep$symbols$get.local) ?? `$${asset.id}$re_export$${local}`;
|
|
759
|
+
asset.symbols.set(local, reExportName);
|
|
760
|
+
dep.symbols.set(imported, reExportName, convertLoc(loc), true);
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
for (let specifier of hoist_result.wrapped_requires) {
|
|
764
|
+
let dep = deps.get(specifier);
|
|
765
|
+
if (!dep) continue;
|
|
766
|
+
dep.meta.shouldWrap = true;
|
|
767
|
+
}
|
|
768
|
+
for (let name in hoist_result.dynamic_imports) {
|
|
769
|
+
let dep = deps.get(hoist_result.dynamic_imports[name]);
|
|
770
|
+
if (!dep) continue;
|
|
771
|
+
dep.meta.promiseSymbol = name;
|
|
772
|
+
}
|
|
773
|
+
if (hoist_result.self_references.length > 0) {
|
|
774
|
+
let symbols = new Map();
|
|
775
|
+
for (let name of hoist_result.self_references) {
|
|
776
|
+
// Do not create a self-reference for the `default` symbol unless we have seen an __esModule flag.
|
|
777
|
+
if (name === 'default' && !asset.symbols.hasExportSymbol('__esModule')) {
|
|
778
|
+
continue;
|
|
779
|
+
}
|
|
780
|
+
let local = (0, _nullthrows().default)(asset.symbols.get(name)).local;
|
|
781
|
+
symbols.set(name, {
|
|
782
|
+
local,
|
|
783
|
+
isWeak: false,
|
|
784
|
+
loc: null
|
|
785
|
+
});
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
// Use the asset id as a unique key if one has not already been set.
|
|
789
|
+
// This lets us create a dependency on the asset itself by using it as a specifier.
|
|
790
|
+
// Using the unique key ensures that the dependency always resolves to the correct asset,
|
|
791
|
+
// even if it came from a transformer that produced multiple assets (e.g. css modules).
|
|
792
|
+
// Also avoids needing a resolution request.
|
|
793
|
+
asset.uniqueKey ||= asset.id;
|
|
794
|
+
asset.addDependency({
|
|
795
|
+
specifier: asset.uniqueKey,
|
|
796
|
+
specifierType: 'esm',
|
|
797
|
+
symbols
|
|
798
|
+
});
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
// Add * symbol if there are CJS exports, no imports/exports at all
|
|
802
|
+
// (and the asset has side effects), or the asset is wrapped.
|
|
803
|
+
// This allows accessing symbols that don't exist without errors in symbol propagation.
|
|
804
|
+
if (hoist_result.has_cjs_exports || !hoist_result.is_esm && asset.sideEffects && deps.size === 0 && Object.keys(hoist_result.exported_symbols).length === 0 || hoist_result.should_wrap && !asset.symbols.hasExportSymbol('*')) {
|
|
805
|
+
asset.symbols.set('*', `$${asset.id}$exports`);
|
|
806
|
+
}
|
|
807
|
+
asset.meta.hasCJSExports = hoist_result.has_cjs_exports;
|
|
808
|
+
asset.meta.staticExports = hoist_result.static_cjs_exports;
|
|
809
|
+
asset.meta.shouldWrap = hoist_result.should_wrap;
|
|
810
|
+
} else {
|
|
811
|
+
if (symbol_result) {
|
|
812
|
+
let deps = new Map(asset.getDependencies().map(dep => [dep.meta.placeholder ?? dep.specifier, dep]));
|
|
813
|
+
asset.symbols.ensure();
|
|
814
|
+
for (let {
|
|
815
|
+
exported,
|
|
816
|
+
local,
|
|
817
|
+
loc,
|
|
818
|
+
source
|
|
819
|
+
} of symbol_result.exports) {
|
|
820
|
+
let dep = source ? deps.get(source) : undefined;
|
|
821
|
+
asset.symbols.set(exported, `${(dep === null || dep === void 0 ? void 0 : dep.id) ?? ''}$${local}`, convertLoc(loc));
|
|
822
|
+
if (dep != null) {
|
|
823
|
+
dep.symbols.ensure();
|
|
824
|
+
dep.symbols.set(local, `${(dep === null || dep === void 0 ? void 0 : dep.id) ?? ''}$${local}`, convertLoc(loc), true);
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
for (let {
|
|
828
|
+
source,
|
|
829
|
+
local,
|
|
830
|
+
imported,
|
|
831
|
+
loc
|
|
832
|
+
} of symbol_result.imports) {
|
|
833
|
+
let dep = deps.get(source);
|
|
834
|
+
if (!dep) continue;
|
|
835
|
+
dep.symbols.ensure();
|
|
836
|
+
dep.symbols.set(imported, local, convertLoc(loc));
|
|
837
|
+
}
|
|
838
|
+
for (let {
|
|
839
|
+
source,
|
|
840
|
+
loc
|
|
841
|
+
} of symbol_result.exports_all) {
|
|
842
|
+
let dep = deps.get(source);
|
|
843
|
+
if (!dep) continue;
|
|
844
|
+
dep.symbols.ensure();
|
|
845
|
+
dep.symbols.set('*', '*', convertLoc(loc), true);
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
// Add * symbol if there are CJS exports, no imports/exports at all, or the asset is wrapped.
|
|
849
|
+
// This allows accessing symbols that don't exist without errors in symbol propagation.
|
|
850
|
+
if (symbol_result.has_cjs_exports || !symbol_result.is_esm && deps.size === 0 && symbol_result.exports.length === 0 || symbol_result.should_wrap && !asset.symbols.hasExportSymbol('*')) {
|
|
851
|
+
asset.symbols.ensure();
|
|
852
|
+
asset.symbols.set('*', `$${asset.id}$exports`);
|
|
853
|
+
}
|
|
854
|
+
} else {
|
|
855
|
+
// If the asset is wrapped, add * as a fallback
|
|
856
|
+
asset.symbols.ensure();
|
|
857
|
+
asset.symbols.set('*', `$${asset.id}$exports`);
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
// For all other imports and requires, mark everything as imported (this covers both dynamic
|
|
861
|
+
// imports and non-top-level requires.)
|
|
862
|
+
for (let dep of asset.getDependencies()) {
|
|
863
|
+
if (dep.symbols.isCleared) {
|
|
864
|
+
dep.symbols.ensure();
|
|
865
|
+
dep.symbols.set('*', `${dep.id}$`);
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
if (needs_esm_helpers) {
|
|
869
|
+
asset.addDependency({
|
|
870
|
+
specifier: '@atlaspack/transformer-js/src/esmodule-helpers.js',
|
|
871
|
+
specifierType: 'esm',
|
|
872
|
+
resolveFrom: __filename,
|
|
873
|
+
env: {
|
|
874
|
+
includeNodeModules: {
|
|
875
|
+
'@atlaspack/transformer-js': true
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
});
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
asset.type = 'js';
|
|
882
|
+
asset.setBuffer(compiledCode);
|
|
883
|
+
if (map) {
|
|
884
|
+
let sourceMap = new (_sourceMap().default)(options.projectRoot);
|
|
885
|
+
sourceMap.addVLQMap(JSON.parse(map));
|
|
886
|
+
if (originalMap) {
|
|
887
|
+
sourceMap.extends(originalMap);
|
|
888
|
+
}
|
|
889
|
+
asset.setMap(sourceMap);
|
|
890
|
+
}
|
|
891
|
+
return [asset, ...macroAssets];
|
|
892
|
+
}
|
|
893
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.interopDefault = function (a) {
|
|
4
|
+
return a && a.__esModule ? a : {
|
|
5
|
+
default: a
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
exports.defineInteropFlag = function (a) {
|
|
9
|
+
Object.defineProperty(a, '__esModule', {
|
|
10
|
+
value: true
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
exports.exportAll = function (source, dest) {
|
|
14
|
+
Object.keys(source).forEach(function (key) {
|
|
15
|
+
if (key === 'default' || key === '__esModule' || Object.prototype.hasOwnProperty.call(dest, key)) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
Object.defineProperty(dest, key, {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return source[key];
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
return dest;
|
|
26
|
+
};
|
|
27
|
+
exports.export = function (dest, destName, get) {
|
|
28
|
+
Object.defineProperty(dest, destName, {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get: get
|
|
31
|
+
});
|
|
32
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/transformer-js",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.1-canary.10+3b66d6b4b",
|
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
"test": "mocha"
|
|
16
16
|
},
|
|
17
17
|
"engines": {
|
|
18
|
-
"atlaspack": "^2.12.0",
|
|
19
18
|
"node": ">= 16.0.0"
|
|
20
19
|
},
|
|
21
20
|
"files": [
|
|
@@ -23,13 +22,13 @@
|
|
|
23
22
|
"src"
|
|
24
23
|
],
|
|
25
24
|
"dependencies": {
|
|
26
|
-
"@atlaspack/diagnostic": "2.14.
|
|
27
|
-
"@atlaspack/feature-flags": "2.14.
|
|
28
|
-
"@atlaspack/plugin": "2.14.
|
|
29
|
-
"@atlaspack/rust": "3.0.
|
|
25
|
+
"@atlaspack/diagnostic": "2.14.1-canary.10+3b66d6b4b",
|
|
26
|
+
"@atlaspack/feature-flags": "2.14.1-canary.10+3b66d6b4b",
|
|
27
|
+
"@atlaspack/plugin": "2.14.1-canary.10+3b66d6b4b",
|
|
28
|
+
"@atlaspack/rust": "3.0.1-canary.10+3b66d6b4b",
|
|
29
|
+
"@atlaspack/utils": "2.14.1-canary.10+3b66d6b4b",
|
|
30
|
+
"@atlaspack/workers": "2.14.1-canary.10+3b66d6b4b",
|
|
30
31
|
"@parcel/source-map": "^2.1.1",
|
|
31
|
-
"@atlaspack/utils": "2.14.0",
|
|
32
|
-
"@atlaspack/workers": "2.14.0",
|
|
33
32
|
"@swc/helpers": "^0.5.15",
|
|
34
33
|
"browserslist": "^4.6.6",
|
|
35
34
|
"nullthrows": "^1.1.1",
|
|
@@ -39,5 +38,6 @@
|
|
|
39
38
|
"peerDependencies": {
|
|
40
39
|
"@atlaspack/core": "^2.13.1"
|
|
41
40
|
},
|
|
42
|
-
"type": "commonjs"
|
|
41
|
+
"type": "commonjs",
|
|
42
|
+
"gitHead": "3b66d6b4bfd652ab3b41e86aacf3e47d39cd5a70"
|
|
43
43
|
}
|