@swc/core 1.2.213 → 1.2.219

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 CHANGED
@@ -1,5 +1,245 @@
1
1
  # Changelog
2
- ## [unreleased]
2
+ ## [1.2.219] - 2022-07-27
3
+
4
+ ### Bug Fixes
5
+
6
+
7
+
8
+ - **(css)** Fix parsing of `layer` (#5290) ([83651c2](https://github.com/swc-project/swc/commit/83651c297d4e6b03809b96a87ce1c59f158e28ff))
9
+
10
+
11
+ - **(css/prefixer)** Generate at-rules based on preset-env (#5294) ([94b4e0a](https://github.com/swc-project/swc/commit/94b4e0a3213e7cd0982eebe2d1b65ac5f10af2f2))
12
+
13
+
14
+ - **(es/codegen)** Add `;` for a generator function (#5292) ([daac26b](https://github.com/swc-project/swc/commit/daac26bcfbc48a732d4b1b831a0f54518401f63b))
15
+
16
+
17
+ - **(es/codegen)** Fix sourcemap of multiline comments (#5299) ([3100bf8](https://github.com/swc-project/swc/commit/3100bf8c6220640006c3238e69f0f5fbd8fce738))
18
+
19
+
20
+ - **(es/compat)** Preserve orders of `import`s and `export`s (#5249) ([2010409](https://github.com/swc-project/swc/commit/2010409bac0f73c5f4d04f6735db6142f621701a))
21
+
22
+
23
+ - **(es/compat)** Fix capturing of block scoping pass (#5279) ([b423d6f](https://github.com/swc-project/swc/commit/b423d6f936eb1bdc66b2223fe9189a7dcc8ae1d8))
24
+
25
+
26
+ - **(es/decorators)** Use decorated consturctors (#5263) ([d9877e3](https://github.com/swc-project/swc/commit/d9877e305a3989e88b696135cb7cf16fc63e940f))
27
+
28
+
29
+ - **(es/fixer)** Wrap `await` and `yield` in callee (#5314) ([b3269fd](https://github.com/swc-project/swc/commit/b3269fda8e8614cc7faaebae0edc2bbb05b7fb0e))
30
+
31
+
32
+ - **(es/minifier)** Preserve order of side-effects in sequences pass (#5283) ([ee84842](https://github.com/swc-project/swc/commit/ee84842d226df4905fd7edae41bfa8f7d4b48bfb))
33
+
34
+
35
+ - **(es/modules)** Use a private context for `export from` (#5262) ([c0ace4c](https://github.com/swc-project/swc/commit/c0ace4cb2c63b81dc08e35d6a59f9a9bcd961985))
36
+
37
+
38
+ - **(es/preset-env)** Realign with `babel-polyfills` (#5293) ([dd0a152](https://github.com/swc-project/swc/commit/dd0a152f49da3acab06dece8eb7982c56e4c23b0))
39
+
40
+
41
+ - **(es/preset-env)** Don't add instance properties when there's a static property (#5305) ([06677c2](https://github.com/swc-project/swc/commit/06677c26eed5a2320541522b3587e0b81e7ef0e9))
42
+
43
+
44
+ - **(es/visit)** Disable `serde` by default (#5273) ([a0007e1](https://github.com/swc-project/swc/commit/a0007e11c393dd72bd5a056e7261422a96adc106))
45
+
46
+
47
+ - **(html/minifier)** Don't break unknown attributes (#5256) ([4f55459](https://github.com/swc-project/swc/commit/4f55459b013eeee8374ee9587e7d7c71d16262ec))
48
+
49
+
50
+ - **(html/parser)** Fix span (#5312) ([c80b9e1](https://github.com/swc-project/swc/commit/c80b9e106a432a858e40817069862b9a8f235ad3))
51
+
52
+ ### Documentation
53
+
54
+
55
+
56
+ - **(ast_node)** Remove an unnecessary comment (#5304) ([8896dd9](https://github.com/swc-project/swc/commit/8896dd9a66686ddb84a444480f395dcd75a92cba))
57
+
58
+ ### Features
59
+
60
+
61
+
62
+ - **(css/minifier)** Remove duplicate selectors (#5257) ([ce34746](https://github.com/swc-project/swc/commit/ce347461ee4cb14ef0f099abb6a8831c929f958a))
63
+
64
+
65
+ - **(css/prefixer)** Implement `preset-env` (#5247) ([e78d23d](https://github.com/swc-project/swc/commit/e78d23d193585bb088f71602a33340d0a1ed1601))
66
+
67
+
68
+ - **(es/codegen)** Optimize number and bigint literal (#5223) ([3f0856d](https://github.com/swc-project/swc/commit/3f0856db2ef7dde001cd482088a094f49de7ddac))
69
+
70
+
71
+ - **(es/codegen)** Remove extra space before a private method (#5295) ([0f254d5](https://github.com/swc-project/swc/commit/0f254d5ce5c23fa3ec06c074aa1b8acc5d1dbddf))
72
+
73
+
74
+ - **(es/minifier)** Calculate correct size (#5253) ([6573324](https://github.com/swc-project/swc/commit/6573324d9c59000c81ae35ad615b0b7428bc75f9))
75
+
76
+
77
+ - **(es/plugin)** Add experimental metadata field (#5254) ([bd1c2cc](https://github.com/swc-project/swc/commit/bd1c2cc7e6dcc04c3d8b59f34b4b88be29ec1ccb))
78
+
79
+
80
+ - **(es/plugin)** Pass experimental metadata from host (#5261) ([43eeeb3](https://github.com/swc-project/swc/commit/43eeeb35a5ec2a368c3cd215abaff1e1f7fa5a1d))
81
+
82
+
83
+ - **(node)** Coerce fallback bindings (#5250) ([7e6ffff](https://github.com/swc-project/swc/commit/7e6ffffbd3834f220e940d447bf1632f70f3b9a7))
84
+
85
+
86
+ - **(plugin)** Make metadata api lazy (#5310) ([5a164bd](https://github.com/swc-project/swc/commit/5a164bd13741d3871170cefe4778b615640d169d))
87
+
88
+
89
+ - **(testing/macros)** Generalize test names with regex (#5242) ([ecbf9d6](https://github.com/swc-project/swc/commit/ecbf9d6c36b4f86945a66deb8a7d90d7ae01dc3d))
90
+
91
+ ### Miscellaneous Tasks
92
+
93
+
94
+
95
+ - **(ci)** Update macos runner (#5284) ([e8473eb](https://github.com/swc-project/swc/commit/e8473eb8a8d3bebea157d0e06a56d95b2350872c))
96
+
97
+
98
+ - **(deps)** Update `bytecheck` (#5296) ([35b1e78](https://github.com/swc-project/swc/commit/35b1e7817974b0e1d7a5af1f9314444fe4070585))- **general**: Fix CI (#5251) ([d229917](https://github.com/swc-project/swc/commit/d229917588a7bfda8bf4023c42c4190552a3b0c6))- **general**: Fix CI ([3421064](https://github.com/swc-project/swc/commit/34210648b06c4e4e4bd7d368a1b9d203535bbc30))
99
+
100
+ ### Performance
101
+
102
+
103
+
104
+ - **(es/ast)** Use `Atom` in some places (#5271) ([037a53d](https://github.com/swc-project/swc/commit/037a53d5d1ff19514e6f5941fef1ed4b7fe57c31))
105
+
106
+ ### Testing
107
+
108
+
109
+
110
+ - **(es/plugin)** Test plugins with different schema versions (#5255) ([b7c7e3a](https://github.com/swc-project/swc/commit/b7c7e3afb069da6804aafc67f5207da11ad36c17))
111
+
112
+ ### Build
113
+
114
+
115
+
116
+ - **(cargo)** Align dependency versions (#5248) ([0d91741](https://github.com/swc-project/swc/commit/0d91741eb9dc9e2d3ae23f555e3b35c9c448cfc6))
117
+
118
+ ## [1.2.218] - 2022-07-18
119
+
120
+ ### Bug Fixes
121
+
122
+
123
+
124
+ - **(cli)** Emit sourcemap with file inputs (#5213) ([3e3be80](https://github.com/swc-project/swc/commit/3e3be80efda09ae494f8962947562b4411874061))
125
+
126
+
127
+ - **(es)** Check the syntax context of `arguments` (#5174) ([375774d](https://github.com/swc-project/swc/commit/375774d31e690142faeb8422fed4cc996bf1de16))
128
+
129
+
130
+ - **(es)** Fix resolving of symlinks (#5222) ([27cc45d](https://github.com/swc-project/swc/commit/27cc45d50fa035fbb7bbab307752ec55c8d5ed0c))
131
+
132
+
133
+ - **(es/codegen)** Mark bigint as an item starting with number (#5207) ([387d5e4](https://github.com/swc-project/swc/commit/387d5e41db260893297b65d0fd9084f60c71443a))
134
+
135
+
136
+ - **(es/fixer)** Handle invalid numeric literals (#5201) ([436f620](https://github.com/swc-project/swc/commit/436f6200bc05d1d88c9b3fb991f793ed308f607b))
137
+
138
+
139
+ - **(es/lints)** Disallow duplicate export functions (#5234) ([c68d484](https://github.com/swc-project/swc/commit/c68d484305d3dfac3e14e45682c9d5ec10b49a45))
140
+
141
+
142
+ - **(es/minifier)** Fix size calculation of numbers (#5232) ([2e9c9be](https://github.com/swc-project/swc/commit/2e9c9bea1ad5c95a1e4867eba2f9bbe53c466fc7))
143
+
144
+
145
+ - **(es/modules)** Preserve order for ts import equals (#5215) ([6b1ce09](https://github.com/swc-project/swc/commit/6b1ce09b6f59e53a750a71e447a148aedcef8468))
146
+
147
+
148
+ - **(es/parser)** Fix parsing of export specifiers (#5190) ([ec93783](https://github.com/swc-project/swc/commit/ec9378370dd870c304143219afed04624075141f))
149
+
150
+
151
+ - **(html/parser)** Fix span (#5209) ([b4daa30](https://github.com/swc-project/swc/commit/b4daa3005803be23676bec666bb8f8791f2472b3))
152
+
153
+
154
+ - **(html/parser)** Improve span (#5230) ([0f7646c](https://github.com/swc-project/swc/commit/0f7646cc4763f2d79d0b3cb4529a0c7ec7df94e8))
155
+
156
+
157
+ - **(testing)** Allow space in file names (#5237) ([de76868](https://github.com/swc-project/swc/commit/de76868cad88b9afe103a60331c1456a3f02e37e))- **general**: Fix(es/lints: Handle ts export import equals (#5225)
158
+
159
+ ([04de455](https://github.com/swc-project/swc/commit/04de455a9a34dbcbb193bffc9ab504c0e30e8706))
160
+
161
+ ### Features
162
+
163
+
164
+
165
+ - **(css/ast)** Make `raw` optional (#5211) ([b65a16c](https://github.com/swc-project/swc/commit/b65a16c7aa58bca57ad861ca015867f89fb80a79))
166
+
167
+
168
+ - **(es)** Add quote to `swc_ecmascript` (#5199) ([fbfa59b](https://github.com/swc-project/swc/commit/fbfa59b5b78ed76350be246eecba86f8fe8b4234))
169
+
170
+
171
+ - **(es/lints)** Support `ignoreReadBeforeAssign` for `prefer-const` (#4933) ([d035648](https://github.com/swc-project/swc/commit/d0356489cb1dfae8e6ced8dd239643bf6f5b029d))
172
+
173
+
174
+ - **(es/plugin)** Print filename on failure (#5200) ([f69dee7](https://github.com/swc-project/swc/commit/f69dee75f208a6385b64fa79147eef57bd24944e))
175
+
176
+
177
+ - **(html/ast)** Add `raw` to attributes (#5208) ([64237fa](https://github.com/swc-project/swc/commit/64237fa7fb9c95030f92892143f476c2573bed75))
178
+
179
+
180
+ - **(html/ast)** Add `raw` to doctype (#5198) ([945510a](https://github.com/swc-project/swc/commit/945510a6954db87f78dcffa888f49b630f4eb74d))
181
+
182
+
183
+ - **(html/minifier)** Compress more default attributes (#5182) ([625fc18](https://github.com/swc-project/swc/commit/625fc18da01643d81af535eefd4c636e5a632af0))
184
+
185
+
186
+ - **(html/minifier)** Improve minifier (#5227) ([1da6016](https://github.com/swc-project/swc/commit/1da6016da7db783a4207cfff480b057ea911006c))
187
+
188
+
189
+ - **(html/parser)** Add `raw` to comments (#5196) ([dead719](https://github.com/swc-project/swc/commit/dead719550b1ac3024e07f77905ce7b064f102c4))
190
+
191
+
192
+ - **(node)** Use wasm as a fallback (#5233) ([1cebf62](https://github.com/swc-project/swc/commit/1cebf626e66b52f0fe325f679443d8243ab9eba3))
193
+
194
+
195
+ - **(plugin)** Pass `unresolved_mark` to plugins (#5212) ([92c0153](https://github.com/swc-project/swc/commit/92c0153cb56a6b3b7d6503216a14d5ed78df71dc))
196
+
197
+
198
+ - **(quote)** Support different types for variables (#5194) ([c91abb2](https://github.com/swc-project/swc/commit/c91abb2ca75ff98e8fad7a4740b6feccec62cd54))
199
+
200
+ ### Miscellaneous Tasks
201
+
202
+
203
+
204
+ - **(ci)** Skip plugin e2e tests for unsupported targets (#5203) ([6b6b582](https://github.com/swc-project/swc/commit/6b6b5825438bf05ac959e932a798db72dab79c69))
205
+
206
+
207
+ - **(ci)** Disable plugin tests while publishing ([31bbf2d](https://github.com/swc-project/swc/commit/31bbf2ddbbd2babd5f2431ed39a6bcb464dbb7c4))
208
+
209
+
210
+ - **(ci)** Disable some tests ([ff949b0](https://github.com/swc-project/swc/commit/ff949b0bc7df790a6d1df11f2129d589b0dd46b8))
211
+
212
+
213
+ - **(ci)** Fix publish script (#5241) ([66550d6](https://github.com/swc-project/swc/commit/66550d6e87582bb3cb34d18c0dffd8f33814d81d))
214
+
215
+
216
+ - **(visit)** Specify version of `swc_macros_common` (#5231) ([1aa0223](https://github.com/swc-project/swc/commit/1aa022361e7918f4077eacae6e51899eac007be5))- **general**: Typo (#5239) ([17f1cee](https://github.com/swc-project/swc/commit/17f1cee0a8132c79712c742f645e098df9309999))- **general**: Typo (#5238) ([df426d7](https://github.com/swc-project/swc/commit/df426d7b1d2ca74505051bfe78aa78a2a315e0ab))
217
+
218
+ ### Testing
219
+
220
+
221
+
222
+ - **(css/codegen)** Add tests (#5195) ([fa4c2de](https://github.com/swc-project/swc/commit/fa4c2de7064a213eb70cc7712b50d4a41d2bfdfe))
223
+
224
+
225
+ - **(css/parser)** Add a test (#5228) ([8e5efb6](https://github.com/swc-project/swc/commit/8e5efb65d55706883663a25a0e281a4ef013001b))
226
+
227
+
228
+ - **(es/plugin)** Build plugins for e2e testing (#5210) ([cd94f0a](https://github.com/swc-project/swc/commit/cd94f0a2e9a7331073d20638031ae86d3308760e))
229
+
230
+
231
+ - **(plugin)** Setup e2e fixture testing for plugins (#5192) ([2fa51ec](https://github.com/swc-project/swc/commit/2fa51ecd7819b460837467d2a9093730671dd3fc))
232
+
233
+
234
+ - **(plugin)** Fix e2e tests on windows (#5216) ([f1ba332](https://github.com/swc-project/swc/commit/f1ba3327cfcc37534484362293cfac19587110da))
235
+
236
+ ### Build
237
+
238
+
239
+
240
+ - **(node)** Use explicit list for package files (#5229) ([b01b6cf](https://github.com/swc-project/swc/commit/b01b6cf57ee2dcd33886ba9196f364bcb9273afe))
241
+
242
+ ## [1.2.213] - 2022-07-13
3
243
 
4
244
  ### Bug Fixes
5
245
 
package/index.d.ts CHANGED
@@ -7,6 +7,7 @@ import { BundleInput } from "./spack";
7
7
  export declare const version: any;
8
8
  export declare function plugins(ps: Plugin[]): Plugin;
9
9
  export declare class Compiler {
10
+ private fallbackBindingsPluginWarningDisplayed;
10
11
  minify(src: string, opts?: JsMinifyOptions): Promise<Output>;
11
12
  minifySync(src: string, opts?: JsMinifyOptions): Output;
12
13
  parse(src: string, options: ParseOptions & {
package/index.js CHANGED
@@ -1,14 +1,30 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
8
12
  }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
9
18
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
19
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
20
  };
21
+ var __importStar = (this && this.__importStar) || function (mod) {
22
+ if (mod && mod.__esModule) return mod;
23
+ var result = {};
24
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25
+ __setModuleDefault(result, mod);
26
+ return result;
27
+ };
12
28
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
29
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
30
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -34,9 +50,27 @@ exports.DEFAULT_EXTENSIONS = exports.getBinaryMetadata = exports.__experimental_
34
50
  const path_1 = require("path");
35
51
  __exportStar(require("./types"), exports);
36
52
  const spack_1 = require("./spack");
53
+ const assert = __importStar(require("assert"));
37
54
  // Allow overrides to the location of the .node binding file
38
55
  const bindingsOverride = process.env["SWC_BINARY_PATH"];
39
- const bindings = !!bindingsOverride ? require((0, path_1.resolve)(bindingsOverride)) : require('./binding');
56
+ let fallbackBindings;
57
+ const bindings = (() => {
58
+ let binding;
59
+ try {
60
+ binding = !!bindingsOverride ? require((0, path_1.resolve)(bindingsOverride)) : require('./binding');
61
+ // If native binding loaded successfully, it should return proper target triple constant.
62
+ const triple = binding.getTargetTriple();
63
+ assert.ok(triple, 'Failed to read target triple from native binary.');
64
+ return binding;
65
+ }
66
+ catch (_) {
67
+ // postinstall supposed to install `@swc/wasm` already
68
+ fallbackBindings = require('@swc/wasm');
69
+ }
70
+ finally {
71
+ return binding;
72
+ }
73
+ })();
40
74
  /**
41
75
  * Version of the swc binding.
42
76
  */
@@ -52,31 +86,71 @@ function plugins(ps) {
52
86
  }
53
87
  exports.plugins = plugins;
54
88
  class Compiler {
89
+ constructor() {
90
+ this.fallbackBindingsPluginWarningDisplayed = false;
91
+ }
55
92
  minify(src, opts) {
56
93
  return __awaiter(this, void 0, void 0, function* () {
57
- return bindings.minify(toBuffer(src), toBuffer(opts !== null && opts !== void 0 ? opts : {}));
94
+ if (bindings) {
95
+ return bindings.minify(toBuffer(src), toBuffer(opts !== null && opts !== void 0 ? opts : {}));
96
+ }
97
+ else if (fallbackBindings) {
98
+ return Promise.resolve(fallbackBindings.minifySync(src, opts));
99
+ }
100
+ throw new Error('Bindings not found.');
58
101
  });
59
102
  }
60
103
  minifySync(src, opts) {
61
- return bindings.minifySync(toBuffer(src), toBuffer(opts !== null && opts !== void 0 ? opts : {}));
104
+ if (bindings) {
105
+ return bindings.minifySync(toBuffer(src), toBuffer(opts !== null && opts !== void 0 ? opts : {}));
106
+ }
107
+ else if (fallbackBindings) {
108
+ return fallbackBindings.minifySync(src, opts);
109
+ }
110
+ throw new Error('Bindings not found.');
62
111
  }
63
112
  parse(src, options, filename) {
64
113
  return __awaiter(this, void 0, void 0, function* () {
65
114
  options = options || { syntax: "ecmascript" };
66
115
  options.syntax = options.syntax || "ecmascript";
67
- const res = yield bindings.parse(src, toBuffer(options), filename);
68
- return JSON.parse(res);
116
+ if (!bindings && !!fallbackBindings) {
117
+ throw new Error('Fallback bindings does not support this interface yet.');
118
+ }
119
+ else if (!bindings) {
120
+ throw new Error('Bindings not found.');
121
+ }
122
+ if (bindings) {
123
+ const res = yield bindings.parse(src, toBuffer(options), filename);
124
+ return JSON.parse(res);
125
+ }
126
+ else if (fallbackBindings) {
127
+ const res = fallbackBindings.parseSync(src, toBuffer(options), filename);
128
+ return Promise.resolve(JSON.parse(res));
129
+ }
130
+ throw new Error('Bindings not found.');
69
131
  });
70
132
  }
71
133
  parseSync(src, options, filename) {
72
134
  options = options || { syntax: "ecmascript" };
73
135
  options.syntax = options.syntax || "ecmascript";
74
- return JSON.parse(bindings.parseSync(src, toBuffer(options), filename));
136
+ if (bindings) {
137
+ return JSON.parse(bindings.parseSync(src, toBuffer(options), filename));
138
+ }
139
+ else if (fallbackBindings) {
140
+ return JSON.parse(fallbackBindings.parseSync(src, options));
141
+ }
142
+ throw new Error('Bindings not found.');
75
143
  }
76
144
  parseFile(path, options) {
77
145
  return __awaiter(this, void 0, void 0, function* () {
78
146
  options = options || { syntax: "ecmascript" };
79
147
  options.syntax = options.syntax || "ecmascript";
148
+ if (!bindings && !!fallbackBindings) {
149
+ throw new Error('Fallback bindings does not support filesystem access.');
150
+ }
151
+ else if (!bindings) {
152
+ throw new Error('Bindings not found.');
153
+ }
80
154
  const res = yield bindings.parseFile(path, toBuffer(options));
81
155
  return JSON.parse(res);
82
156
  });
@@ -84,6 +158,12 @@ class Compiler {
84
158
  parseFileSync(path, options) {
85
159
  options = options || { syntax: "ecmascript" };
86
160
  options.syntax = options.syntax || "ecmascript";
161
+ if (!bindings && !!fallbackBindings) {
162
+ throw new Error('Fallback bindings does not support filesystem access');
163
+ }
164
+ else if (!bindings) {
165
+ throw new Error('Bindings not found.');
166
+ }
87
167
  return JSON.parse(bindings.parseFileSync(path, toBuffer(options)));
88
168
  }
89
169
  /**
@@ -93,7 +173,13 @@ class Compiler {
93
173
  print(m, options) {
94
174
  return __awaiter(this, void 0, void 0, function* () {
95
175
  options = options || {};
96
- return bindings.print(JSON.stringify(m), toBuffer(options));
176
+ if (bindings) {
177
+ return bindings.print(JSON.stringify(m), toBuffer(options));
178
+ }
179
+ else if (fallbackBindings) {
180
+ return Promise.resolve(fallbackBindings.printSync(JSON.stringify(m), options));
181
+ }
182
+ throw new Error('Bindings not found.');
97
183
  });
98
184
  }
99
185
  /**
@@ -102,7 +188,13 @@ class Compiler {
102
188
  */
103
189
  printSync(m, options) {
104
190
  options = options || {};
105
- return bindings.printSync(JSON.stringify(m), toBuffer(options));
191
+ if (bindings) {
192
+ return bindings.printSync(JSON.stringify(m), toBuffer(options));
193
+ }
194
+ else if (fallbackBindings) {
195
+ return fallbackBindings.printSync(JSON.stringify(m), options);
196
+ }
197
+ throw new Error('Bindings not found.');
106
198
  }
107
199
  transform(src, options) {
108
200
  var _a, _b, _c;
@@ -113,13 +205,23 @@ class Compiler {
113
205
  options.jsc.parser.syntax = (_b = options.jsc.parser.syntax) !== null && _b !== void 0 ? _b : 'ecmascript';
114
206
  }
115
207
  const { plugin } = options, newOptions = __rest(options, ["plugin"]);
116
- if (plugin) {
117
- const m = typeof src === "string"
118
- ? yield this.parse(src, (_c = options === null || options === void 0 ? void 0 : options.jsc) === null || _c === void 0 ? void 0 : _c.parser, options.filename)
119
- : src;
120
- return this.transform(plugin(m), newOptions);
208
+ if (bindings) {
209
+ if (plugin) {
210
+ const m = typeof src === "string"
211
+ ? yield this.parse(src, (_c = options === null || options === void 0 ? void 0 : options.jsc) === null || _c === void 0 ? void 0 : _c.parser, options.filename)
212
+ : src;
213
+ return this.transform(plugin(m), newOptions);
214
+ }
215
+ return bindings.transform(isModule ? JSON.stringify(src) : src, isModule, toBuffer(newOptions));
121
216
  }
122
- return bindings.transform(isModule ? JSON.stringify(src) : src, isModule, toBuffer(newOptions));
217
+ else if (fallbackBindings) {
218
+ if (plugin && !this.fallbackBindingsPluginWarningDisplayed) {
219
+ console.warn(`Fallback bindings does not support legacy plugins, it'll be ignored.`);
220
+ this.fallbackBindingsPluginWarningDisplayed = true;
221
+ }
222
+ return Promise.resolve(fallbackBindings.transformSync(src, options));
223
+ }
224
+ throw new Error('Bindings not found.');
123
225
  });
124
226
  }
125
227
  transformSync(src, options) {
@@ -130,15 +232,31 @@ class Compiler {
130
232
  options.jsc.parser.syntax = (_b = options.jsc.parser.syntax) !== null && _b !== void 0 ? _b : 'ecmascript';
131
233
  }
132
234
  const { plugin } = options, newOptions = __rest(options, ["plugin"]);
133
- if (plugin) {
134
- const m = typeof src === "string" ? this.parseSync(src, (_c = options === null || options === void 0 ? void 0 : options.jsc) === null || _c === void 0 ? void 0 : _c.parser, options.filename) : src;
135
- return this.transformSync(plugin(m), newOptions);
235
+ if (bindings) {
236
+ if (plugin) {
237
+ const m = typeof src === "string" ? this.parseSync(src, (_c = options === null || options === void 0 ? void 0 : options.jsc) === null || _c === void 0 ? void 0 : _c.parser, options.filename) : src;
238
+ return this.transformSync(plugin(m), newOptions);
239
+ }
240
+ return bindings.transformSync(isModule ? JSON.stringify(src) : src, isModule, toBuffer(newOptions));
241
+ }
242
+ else if (fallbackBindings) {
243
+ if (plugin && !this.fallbackBindingsPluginWarningDisplayed) {
244
+ console.warn(`Fallback bindings does not support legacy plugins, it'll be ignored.`);
245
+ this.fallbackBindingsPluginWarningDisplayed = true;
246
+ }
247
+ return fallbackBindings.transformSync(src, options);
136
248
  }
137
- return bindings.transformSync(isModule ? JSON.stringify(src) : src, isModule, toBuffer(newOptions));
249
+ throw new Error("Bindings not found");
138
250
  }
139
251
  transformFile(path, options) {
140
252
  var _a, _b, _c;
141
253
  return __awaiter(this, void 0, void 0, function* () {
254
+ if (!bindings && !!fallbackBindings) {
255
+ throw new Error('Fallback bindings does not support filesystem access.');
256
+ }
257
+ else if (!bindings) {
258
+ throw new Error('Bindings not found.');
259
+ }
142
260
  options = options || {};
143
261
  if ((_a = options === null || options === void 0 ? void 0 : options.jsc) === null || _a === void 0 ? void 0 : _a.parser) {
144
262
  options.jsc.parser.syntax = (_b = options.jsc.parser.syntax) !== null && _b !== void 0 ? _b : 'ecmascript';
@@ -154,6 +272,12 @@ class Compiler {
154
272
  }
155
273
  transformFileSync(path, options) {
156
274
  var _a, _b, _c;
275
+ if (!bindings && !!fallbackBindings) {
276
+ throw new Error('Fallback bindings does not support filesystem access.');
277
+ }
278
+ else if (!bindings) {
279
+ throw new Error('Bindings not found.');
280
+ }
157
281
  options = options || {};
158
282
  if ((_a = options === null || options === void 0 ? void 0 : options.jsc) === null || _a === void 0 ? void 0 : _a.parser) {
159
283
  options.jsc.parser.syntax = (_b = options.jsc.parser.syntax) !== null && _b !== void 0 ? _b : 'ecmascript';
@@ -168,6 +292,12 @@ class Compiler {
168
292
  }
169
293
  bundle(options) {
170
294
  return __awaiter(this, void 0, void 0, function* () {
295
+ if (!bindings && !!fallbackBindings) {
296
+ throw new Error('Fallback bindings does not support this interface yet.');
297
+ }
298
+ else if (!bindings) {
299
+ throw new Error('Bindings not found.');
300
+ }
171
301
  const opts = yield (0, spack_1.compileBundleOptions)(options);
172
302
  if (Array.isArray(opts)) {
173
303
  const all = yield Promise.all(opts.map((opt) => __awaiter(this, void 0, void 0, function* () {
@@ -258,8 +388,12 @@ exports.minifySync = minifySync;
258
388
  * or bug report at https://github.com/swc-project/swc/discussions.
259
389
  */
260
390
  function __experimental_registerGlobalTraceConfig(traceConfig) {
261
- if (traceConfig.type === 'traceEvent') {
262
- bindings.initCustomTraceSubscriber(traceConfig.fileName);
391
+ // Do not raise error if binding doesn't exists - fallback binding will not support
392
+ // this ever.
393
+ if (bindings) {
394
+ if (traceConfig.type === 'traceEvent') {
395
+ bindings.initCustomTraceSubscriber(traceConfig.fileName);
396
+ }
263
397
  }
264
398
  }
265
399
  exports.__experimental_registerGlobalTraceConfig = __experimental_registerGlobalTraceConfig;
@@ -273,7 +407,7 @@ exports.__experimental_registerGlobalTraceConfig = __experimental_registerGlobal
273
407
  */
274
408
  function getBinaryMetadata() {
275
409
  return {
276
- target: bindings.getTargetTriple()
410
+ target: bindings ? bindings === null || bindings === void 0 ? void 0 : bindings.getTargetTriple() : undefined
277
411
  };
278
412
  }
279
413
  exports.getBinaryMetadata = getBinaryMetadata;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swc/core",
3
- "version": "1.2.213",
3
+ "version": "1.2.219",
4
4
  "description": "Super-fast alternative for babel",
5
5
  "homepage": "https://swc.rs",
6
6
  "main": "./index.js",
@@ -54,6 +54,7 @@
54
54
  "scripts": {
55
55
  "changelog": "git cliff --output CHANGELOG.md",
56
56
  "prepare": "husky install && git config feature.manyFiles true && node ./crates/swc_ecma_preset_env/scripts/copy-data.js",
57
+ "postinstall": "node postinstall.js",
57
58
  "artifacts": "napi artifacts --dist scripts/npm",
58
59
  "prepublishOnly": "tsc -d && napi prepublish -p scripts/npm --tagstyle npm",
59
60
  "pack": "wasm-pack",
@@ -61,7 +62,7 @@
61
62
  "build:wasm": "npm-run-all \"pack -- build ./crates/wasm --scope swc {1} -t {2} --features plugin\" --",
62
63
  "build": "tsc -d && napi build --platform --cargo-name binding_core_node --js ./node-swc/src/binding.js --dts ./node-swc/src/binding.d.ts -p binding_core_node --release",
63
64
  "build:dev": "tsc -d && napi build --platform --cargo-name binding_core_node --js ./node-swc/src/binding.js --dts ./node-swc/src/binding.d.ts -p binding_core_node",
64
- "test": "cross-env NODE_OPTIONS='--experimental-vm-modules' jest node-swc/__tests__",
65
+ "test": "cross-env NODE_OPTIONS='--experimental-vm-modules' jest --config ./node-swc/jest.config.js",
65
66
  "version": "napi version -p scripts/npm"
66
67
  },
67
68
  "lint-staged": {
@@ -95,9 +96,10 @@
95
96
  "@babel/preset-typescript": "^7.13.0",
96
97
  "@babel/types": "^7.14.0",
97
98
  "@napi-rs/cli": "^2.10.0",
99
+ "@swc/core": "^1.2.218",
98
100
  "@swc/helpers": "^0.4.2",
99
101
  "@taplo/cli": "^0.3.2",
100
- "@types/jest": "^26.0.23",
102
+ "@types/jest": "^28.1.4",
101
103
  "@types/node": "^14.14.41",
102
104
  "acorn": "^8.6.0",
103
105
  "acorn-jsx": "^5.3.2",
@@ -110,8 +112,9 @@
110
112
  "cross-env": "^7.0.3",
111
113
  "cspell": "^5.12.3",
112
114
  "expect": "^27.4.2",
115
+ "glob": "^8.0.3",
113
116
  "husky": "^7.0.2",
114
- "jest": "^27.0.1",
117
+ "jest": "^28.1.2",
115
118
  "js-beautify": "^1.14.3",
116
119
  "lint-staged": "^12.3.6",
117
120
  "lodash": "^4.17.21",
@@ -135,18 +138,38 @@
135
138
  "url": "https://opencollective.com/swc"
136
139
  },
137
140
  "optionalDependencies": {
138
- "@swc/core-win32-x64-msvc": "1.2.213",
139
- "@swc/core-darwin-x64": "1.2.213",
140
- "@swc/core-linux-x64-gnu": "1.2.213",
141
- "@swc/core-linux-x64-musl": "1.2.213",
142
- "@swc/core-freebsd-x64": "1.2.213",
143
- "@swc/core-win32-ia32-msvc": "1.2.213",
144
- "@swc/core-linux-arm64-gnu": "1.2.213",
145
- "@swc/core-linux-arm-gnueabihf": "1.2.213",
146
- "@swc/core-darwin-arm64": "1.2.213",
147
- "@swc/core-android-arm64": "1.2.213",
148
- "@swc/core-linux-arm64-musl": "1.2.213",
149
- "@swc/core-win32-arm64-msvc": "1.2.213",
150
- "@swc/core-android-arm-eabi": "1.2.213"
151
- }
141
+ "@swc/core-win32-x64-msvc": "1.2.219",
142
+ "@swc/core-darwin-x64": "1.2.219",
143
+ "@swc/core-linux-x64-gnu": "1.2.219",
144
+ "@swc/core-linux-x64-musl": "1.2.219",
145
+ "@swc/core-freebsd-x64": "1.2.219",
146
+ "@swc/core-win32-ia32-msvc": "1.2.219",
147
+ "@swc/core-linux-arm64-gnu": "1.2.219",
148
+ "@swc/core-linux-arm-gnueabihf": "1.2.219",
149
+ "@swc/core-darwin-arm64": "1.2.219",
150
+ "@swc/core-android-arm64": "1.2.219",
151
+ "@swc/core-linux-arm64-musl": "1.2.219",
152
+ "@swc/core-win32-arm64-msvc": "1.2.219",
153
+ "@swc/core-android-arm-eabi": "1.2.219"
154
+ },
155
+ "files": [
156
+ "CHANGELOG.md",
157
+ "Visitor.d.ts",
158
+ "index.d.ts",
159
+ "spack.js",
160
+ "util.d.ts",
161
+ "LICENSE",
162
+ "Visitor.js",
163
+ "binding.d.ts",
164
+ "index.js",
165
+ "run_swcx.js",
166
+ "types.d.ts",
167
+ "util.js",
168
+ "README.md",
169
+ "binding.js",
170
+ "package.json",
171
+ "spack.d.ts",
172
+ "types.js",
173
+ "postinstall.js"
174
+ ]
152
175
  }
package/postinstall.js ADDED
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ /**
36
+ * A postinstall script runs after `@swc/core` is installed.
37
+ *
38
+ * It checks if corresponding optional dependencies for native binary is installed and can be loaded properly.
39
+ * If it fails, it'll internally try to install `@swc/wasm` as fallback.
40
+ */
41
+ const fs_1 = require("fs");
42
+ const assert = __importStar(require("assert"));
43
+ const path = __importStar(require("path"));
44
+ const child_process = __importStar(require("child_process"));
45
+ const fs = __importStar(require("fs"));
46
+ function removeRecursive(dir) {
47
+ for (const entry of fs.readdirSync(dir)) {
48
+ const entryPath = path.join(dir, entry);
49
+ let stats;
50
+ try {
51
+ stats = fs.lstatSync(entryPath);
52
+ }
53
+ catch (_a) {
54
+ continue; // Guard against https://github.com/nodejs/node/issues/4760
55
+ }
56
+ if (stats.isDirectory())
57
+ removeRecursive(entryPath);
58
+ else
59
+ fs.unlinkSync(entryPath);
60
+ }
61
+ fs.rmdirSync(dir);
62
+ }
63
+ /**
64
+ * Trying to validate @swc/core's native binary installation, then installs if it is not supported.
65
+ */
66
+ const validateBinary = () => __awaiter(void 0, void 0, void 0, function* () {
67
+ var _a;
68
+ try {
69
+ const { name } = require(path.resolve(process.env.INIT_CWD, 'package.json'));
70
+ if (name === '@swc/core') {
71
+ return;
72
+ }
73
+ }
74
+ catch (_) {
75
+ return;
76
+ }
77
+ // TODO: We do not take care of the case if user try to install with `--no-optional`.
78
+ // For now, it is considered as deliberate decision.
79
+ let binding;
80
+ try {
81
+ binding = require('./binding');
82
+ // Check if binding binary actually works.
83
+ // For the latest version, checks target triple. If it's old version doesn't have target triple, use parseSync instead.
84
+ const triple = binding.getTargetTriple ? binding.getTargetTriple() : binding.parseSync('console.log()', Buffer.from(JSON.stringify({ syntax: "ecmascript" })));
85
+ assert.ok(triple, 'Failed to read target triple from native binary.');
86
+ }
87
+ catch (error) {
88
+ // if error is unsupported architecture, ignore to display.
89
+ if (!((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes('Unsupported architecture'))) {
90
+ console.warn(error);
91
+ }
92
+ console.warn(`@swc/core was not able to resolve native bindings installation. It'll try to use @swc/wasm as fallback instead.`);
93
+ }
94
+ if (!!binding) {
95
+ return;
96
+ }
97
+ // User choose to override the binary installation. Skip remanining validation.
98
+ if (!!process.env["SWC_BINARY_PATH"]) {
99
+ console.warn(`@swc/core could not resolve native bindings installation, but found manual override config SWC_BINARY_PATH specified. Skipping remaning validation.`);
100
+ return;
101
+ }
102
+ // Check if top-level package.json installs @swc/wasm separately already
103
+ let wasmBinding;
104
+ try {
105
+ wasmBinding = require.resolve(`@swc/wasm`);
106
+ }
107
+ catch (_) {
108
+ }
109
+ if (!!wasmBinding && (0, fs_1.existsSync)(wasmBinding)) {
110
+ return;
111
+ }
112
+ const env = Object.assign(Object.assign({}, process.env), { npm_config_global: undefined });
113
+ const { version } = require(path.join(path.dirname(require.resolve('@swc/core')), 'package.json'));
114
+ // We want to place @swc/wasm next to the @swc/core as if normal installation was done,
115
+ // but can't directly set cwd to INIT_CWD as npm seems to acquire lock to the working dir.
116
+ // Instead, create a temporary inner and move it out.
117
+ const coreDir = path.dirname(require.resolve('@swc/core'));
118
+ const installDir = path.join(coreDir, 'npm-install');
119
+ try {
120
+ fs.mkdirSync(installDir);
121
+ fs.writeFileSync(path.join(installDir, 'package.json'), '{}');
122
+ // Instead of carrying over own dependencies to download & resolve package which increases installation sizes of `@swc/core`,
123
+ // assume & relies on system's npm installation.
124
+ child_process.execSync(`npm install --no-save --loglevel=error --prefer-offline --no-audit --progress=false @swc/wasm@${version}`, { cwd: installDir, stdio: 'pipe', env });
125
+ const installedBinPath = path.join(installDir, 'node_modules', `@swc/wasm`);
126
+ // INIT_CWD is injected via npm. If it doesn't exists, can't proceed.
127
+ fs.renameSync(installedBinPath, path.resolve(process.env.INIT_CWD, 'node_modules', `@swc/wasm`));
128
+ }
129
+ catch (error) {
130
+ console.error(error);
131
+ console.error(`Failed to install fallback @swc/wasm@${version}. @swc/core will not properly.
132
+ Please install @swc/wasm manually, or retry whole installation.
133
+ If there are unexpected errors, please report at https://github.com/swc-project/swc/issues`);
134
+ }
135
+ finally {
136
+ try {
137
+ removeRecursive(installDir);
138
+ }
139
+ catch (_) {
140
+ // Gracefully ignore any failures. This'll make few leftover files but it shouldn't block installation.
141
+ }
142
+ }
143
+ });
144
+ validateBinary().catch((error) => {
145
+ // for now just throw the error as-is.
146
+ throw error;
147
+ });
package/spack.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
package/.prettierignore DELETED
@@ -1,63 +0,0 @@
1
- # Bundler cache files
2
- .cache/
3
-
4
- # Generated
5
- CHANGELOG.md
6
- target/
7
- node_modules/
8
-
9
- # Space sensitive
10
- crates/jsdoc/tests/
11
- crates/swc/tests/errors/
12
- crates/swc/tests/projects/
13
- crates/swc/tests/serde/
14
- crates/swc_css_codegen/tests/
15
- crates/swc_css_lints/tests/
16
- crates/swc_css_minifier/tests/
17
- crates/swc_css_parser/tests/
18
- crates/swc_css_prefixer/tests/
19
- crates/swc_ecma_codegen/tests/
20
- crates/swc_ecma_lints/tests/
21
- crates/swc_ecma_parser/tests/
22
- crates/swc_estree_compat/tests/
23
- crates/swc_html_codegen/tests/
24
- crates/swc_html_minifier/tests/
25
- crates/swc_html_parser/tests/
26
- crates/swc_webpack_ast/tests/
27
-
28
- # Generated by testing system
29
- output/
30
- output.js
31
- output.*.js
32
- output.full.js
33
- output.mjs
34
- index.g.js
35
- output.json
36
- output.ts
37
- output.css
38
- output.min.css
39
- output.html
40
- output.min.html
41
-
42
- # Generated
43
- crates/swc_ecma_preset_env/data
44
- crates/swc_ecma_preset_env/**/*.json
45
- crates/swc/tests/tsc-references
46
- scripts/npm
47
-
48
- # Downloaded
49
- benches/
50
-
51
- # TODO: Enable formatting
52
- helpers/
53
- packages/swc-helpers
54
- node-swc/__tests__
55
- node-swc/src
56
- node-swc/tests
57
- crates/swc/tests/srcmap/
58
- crates/swc/tests/stacktrace/
59
-
60
-
61
- # git submodules
62
- crates/swc_ecma_parser/tests/test262-parser
63
- crates/swc_html_parser/tests/html5lib-tests
package/.prettierrc.json DELETED
@@ -1 +0,0 @@
1
- {}
package/babel.d.ts DELETED
@@ -1,14 +0,0 @@
1
- import { Options, ParseOptions } from './types';
2
- export declare type BabelifyOptions = {
3
- /**
4
- * If it's not specified, transforms will not be applied.
5
- *
6
- * The parser config should be provided via this property when transformations are enabled.
7
- */
8
- transforms: Options;
9
- } | {
10
- /**
11
- * Option for the parser.
12
- */
13
- parser: ParseOptions;
14
- };
package/babel.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
package/run_swcx.d.ts DELETED
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};