@swc/core 1.2.145 → 1.2.148

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
@@ -5,6 +5,326 @@
5
5
 
6
6
 
7
7
 
8
+ - **(css/codegen)** Fix codegen of preserved tokens (#3819) ([7ba5861](https://github.com/swc-project/swc/commit/7ba5861a334657cb443b2f143222f632fcbcf752))
9
+
10
+
11
+ - **(css/codegen)** Fix the output of `SimpleBlock` (#3838) ([e3a5c14](https://github.com/swc-project/swc/commit/e3a5c142d5f6e965478bd68201714e6d0b4bc863))
12
+
13
+
14
+ - **(css/parser)** Fix parsing of `;` in values (#3821) ([30cd29b](https://github.com/swc-project/swc/commit/30cd29b0f0153bd732f0004dfcb10892635ee027))
15
+
16
+
17
+ - **(es/compat)** Fix block scoping of variables (#3826) ([406b8ea](https://github.com/swc-project/swc/commit/406b8eaeafa37d1ec68a5d5aca0f8dd337ae39ec))
18
+
19
+
20
+ - **(es/hygiene)** Fix renaming bugs (#3824) ([043fba2](https://github.com/swc-project/swc/commit/043fba274e13055dad4b2f6cee85b1bf751572ca))
21
+
22
+
23
+ - **(es/minifier)** Preserve more variables (#3805) ([89388e6](https://github.com/swc-project/swc/commit/89388e6ac3669f129d1dfc1f687ad7792373dbc9))
24
+
25
+
26
+ - **(es/minifier)** Don't reorder unnecessarily (#3817) ([8a468f7](https://github.com/swc-project/swc/commit/8a468f7544ae7e717de4d629c33e5cdffdfcc7de))
27
+
28
+
29
+ - **(es/minifier)** Support declaring multiple bindings with the same name (#3837) ([0fc819e](https://github.com/swc-project/swc/commit/0fc819e2ef04a5a809d1c15523262b2f3fbc580a))
30
+
31
+
32
+ - **(node-swc)** Correctly close trace spans after completion (#3811) ([ffb2ee8](https://github.com/swc-project/swc/commit/ffb2ee85e6e3cac7136578c2eaaff73b883f208c))
33
+
34
+
35
+ - **(node-swc)** Fix handling of `OptionalChainingExpression` in `Visitor` (#3809) ([4d123c3](https://github.com/swc-project/swc/commit/4d123c3789cd5a837de08014675e945990122c62))
36
+
37
+
38
+ - **(node-swc/types)** Add a missing field of `ExportNamedDeclaration` (#3822) ([bde7577](https://github.com/swc-project/swc/commit/bde75770988a6e1c9bb6ae4b850866cea79b0f2c))
39
+
40
+ ### Features
41
+
42
+
43
+
44
+ - **(config)** Add a dedicated cached regex (#3832) ([efc6741](https://github.com/swc-project/swc/commit/efc67417a5afd7813c2d09938300b5c372d1a978))
45
+
46
+
47
+ - **(css)** Support color functions (#3836) ([3df887c](https://github.com/swc-project/swc/commit/3df887ca3744813d8cfc6c253a7bb3decaca54db))
48
+
49
+
50
+ - **(css/lints)** Add `font-family-no-duplicate-names` rule (#3818) ([2d273d6](https://github.com/swc-project/swc/commit/2d273d60b9dec4d9f969f0e691ba21ce4b252b7d))
51
+
52
+
53
+ - **(css/lints)** Implement `color-hex-alpha` rule (#3829) ([818b408](https://github.com/swc-project/swc/commit/818b40857328ae9b855d78d774621fa1ab243da9))
54
+
55
+
56
+ - **(css/minifier)** Compress more declarations (#3840) ([0db6915](https://github.com/swc-project/swc/commit/0db6915e32d6c1de848b0f5aeacea2c4cb4522f8))
57
+
58
+
59
+ - **(css/parser)** Improve error recovery (#3810) ([f969f8c](https://github.com/swc-project/swc/commit/f969f8c5f54e3028576a74ccfcaae72b1c19eaf9))
60
+
61
+
62
+ - **(css/parser)** Improve error recovery (#3828) ([fbb98aa](https://github.com/swc-project/swc/commit/fbb98aa73cbbac186493065af8cfa0fd31407fe6))
63
+
64
+
65
+ - **(es/lints)** Implement `radix` rule (#3651) ([f6b4bbe](https://github.com/swc-project/swc/commit/f6b4bbe47beccb6052d60c8e6d7d8c8c7fec5100))
66
+
67
+
68
+ - **(es/minifier)** Drop more function parameters in strict mode (#3814) ([789eb7b](https://github.com/swc-project/swc/commit/789eb7baa9ece80e85f0ffd9a92f4d07214d9b11))
69
+
70
+
71
+ - **(es/minifier)** Improve sequential inlining (#3820) ([364532e](https://github.com/swc-project/swc/commit/364532e9a74ee55196cecb37eb3fc8256e3a23df))
72
+
73
+
74
+ - **(es/minifier)** Implement more rules (#3841) ([260c2a8](https://github.com/swc-project/swc/commit/260c2a885e16332a0e3401bccb65d1381bfab3f3))
75
+
76
+ ### Miscellaneous Tasks
77
+ - **general**: Ignore linguist detection for CSS test files (#3831) ([8755ce1](https://github.com/swc-project/swc/commit/8755ce160f9fa6f9ce75c4ac40fc02d5df236d2d))
78
+
79
+ ### Performance
80
+
81
+
82
+
83
+ - **(es)** Use `Mutex` from `parking_lot` (#3830) ([351b814](https://github.com/swc-project/swc/commit/351b814ed0f1ca36a1e8fd352674689ffe392eda))
84
+
85
+
86
+ - **(es/parser)** Remove duplicated instantiations of `Parser` to reduce binary size (#3813) ([f5103a7](https://github.com/swc-project/swc/commit/f5103a77256060e2c27ca360d0c58bbcc6b92b13))
87
+
88
+ ### Testing
89
+
90
+
91
+
92
+ - **(es/compat)** Organize tests (#3825) ([814dcc0](https://github.com/swc-project/swc/commit/814dcc09d66f9c7a968348fc3a08573cadd036f8))
93
+
94
+ ## [1.2.147] - 2022-03-02
95
+
96
+ ### Bug Fixes
97
+
98
+
99
+
100
+ - **(es/compat)** Initialize class fields as a last step (#3767) ([11bf29f](https://github.com/swc-project/swc/commit/11bf29f44b4233b2e7f60b750ef56429dbe47ce9))
101
+
102
+
103
+ - **(es/minifier)** Disable some operations for asm.js codes (#3572) ([e7f7f69](https://github.com/swc-project/swc/commit/e7f7f69db4f327b35005e863d3669bad382626c6))
104
+
105
+
106
+ - **(es/minifier)** Fix inlining logic (#3776) ([cfc0363](https://github.com/swc-project/swc/commit/cfc036381a5c174798198f4ecf7e0a62abce5a75))
107
+
108
+
109
+ - **(es/minifier)** Preserve unresolved references (#3780) ([73cab63](https://github.com/swc-project/swc/commit/73cab638a11978da9f94c886a5fafc462b1556b7))
110
+
111
+
112
+ - **(es/minifier)** Fix optimizations of terminating expressions (#3794) ([8beaa20](https://github.com/swc-project/swc/commit/8beaa202e2a8c321a0f2266378d0f0a3ecb06c03))
113
+
114
+
115
+ - **(es/react)** Catch refresh directives widely (#3791) ([5ae907f](https://github.com/swc-project/swc/commit/5ae907f6f21d31da708ac7237536bd6f838856c3))
116
+
117
+
118
+ - **(es/react)** Fix logic for extracting refresh comments (#3796) ([b485b5a](https://github.com/swc-project/swc/commit/b485b5a1d5480548de9ce2c22060be37298e6346))
119
+
120
+
121
+ - **(es/typescript)** Transform `this` in TypeScript classes (#3764) ([5f3f9ef](https://github.com/swc-project/swc/commit/5f3f9ef033797a1b13d32bd854c3acf3cbaf4495))
122
+
123
+
124
+ - **(node-swc/cli)** Correctly expose `swcx` entrypoint (#3784) ([95ecc01](https://github.com/swc-project/swc/commit/95ecc013fe9b0ab0c2f52465bd961616315938c3))
125
+
126
+ ### Documentation
127
+
128
+
129
+
130
+ - **(adr)** Add `adr-00002` for event trace profiling (#3787) ([3c1c5d0](https://github.com/swc-project/swc/commit/3c1c5d0363b231a8ac3f5bdfd15f1b2ec9224849))
131
+
132
+ ### Features
133
+
134
+
135
+
136
+ - **(css/ast)** Union `Value` and `ComponentValue` (#3804) ([3ec45a6](https://github.com/swc-project/swc/commit/3ec45a6858a24c56ee1fe143410f3763b2b5e4b4))
137
+
138
+
139
+ - **(css/lints)** Add CSS linter (#3765) ([66c6cae](https://github.com/swc-project/swc/commit/66c6cae8dc7d614aac83a620b4dff022459f54d7))
140
+
141
+
142
+ - **(css/lints)** Add `selector-max-combinators` rule (#3789) ([e389bef](https://github.com/swc-project/swc/commit/e389bef3ad0f27382d2d6c5f2be62dd28e65e757))
143
+
144
+
145
+ - **(css/minifier)** Convert more length (#3769) ([500d62c](https://github.com/swc-project/swc/commit/500d62c0850a93321baafb44fa4ac4b8a9bff3f8))
146
+
147
+
148
+ - **(es/codegen)** Optimize output of new expressions without arguments (#3800) ([e1b13eb](https://github.com/swc-project/swc/commit/e1b13eb21a6eb1ec094a64ab30852042b89748a8))
149
+
150
+
151
+ - **(es/compat)** Optimize handling of literals in computed property names (#3756) ([8ed4d2f](https://github.com/swc-project/swc/commit/8ed4d2fcaccf27733e8fbfe19da810504653ce6b))
152
+
153
+
154
+ - **(es/compat)** Add tracing support for `es2022` transforms (#3785) ([4d70482](https://github.com/swc-project/swc/commit/4d7048291fae26c081754a496d9c77ddb2215575))
155
+
156
+
157
+ - **(es/compat)** Use sequence expressions instead of iife in `classes` pass (#3773) ([5b6beca](https://github.com/swc-project/swc/commit/5b6beca1afb7e4278629840c94c775a083288cd2))
158
+
159
+
160
+ - **(es/compat)** Add tracing support for es2020 transforms (#3798) ([8f41d7a](https://github.com/swc-project/swc/commit/8f41d7a10e99c21dc12176ee7724f0e13ca702dd))
161
+
162
+
163
+ - **(es/dep-graph)** Add support for `require.resolve` (#3783) ([19b84e7](https://github.com/swc-project/swc/commit/19b84e7723c381843c98df90f64e5123acdd5808))
164
+
165
+
166
+ - **(es/minifier)** Consider `arguments` while dropping unused assignments (#3775) ([714e05e](https://github.com/swc-project/swc/commit/714e05e5535dd4f8552ce700cc5b582d134d8a08))
167
+
168
+
169
+ - **(es/module)** Workaround stack overflow bug of JavaScriptCore related to too many exports (#3763) ([ad0a853](https://github.com/swc-project/swc/commit/ad0a8539e058fda49e40cc8fab167e2602576d48))
170
+
171
+
172
+ - **(es/modules)** Support system js (#3659) ([557a520](https://github.com/swc-project/swc/commit/557a520a6d6814f79625ca0227c47fa2d42a806e))
173
+
174
+
175
+ - **(es/parser)** Raise a syntax error on an invalid shorthand assignment (#3734) ([2aa3b21](https://github.com/swc-project/swc/commit/2aa3b2123fc73bc187099b5c4a0b1f796b0a51f4))
176
+
177
+
178
+ - **(es/quote)** Implement quasi quoter partially (#3155) ([fe0ddcc](https://github.com/swc-project/swc/commit/fe0ddcc54b0f8343a3a3d227bde8b38fa47ebd80))
179
+
180
+
181
+ - **(es/quote)** Support variables (#3774) ([e3c374b](https://github.com/swc-project/swc/commit/e3c374b53bdd3fe8baef5be7a63b10d2efcd47e4))
182
+
183
+
184
+ - **(plugin)** Expose `swc_ecma_quote` (#3790) ([bc60a6e](https://github.com/swc-project/swc/commit/bc60a6e90ccc1adcb8d9eda9ef47725e20fbfa23))
185
+
186
+
187
+ - **(plugin/runner)** Update `wasmer` to `v2.2` (#3788) ([99d536e](https://github.com/swc-project/swc/commit/99d536e4869df5a9cc642ed0a155683165ee93c9))
188
+
189
+ ### Miscellaneous Tasks
190
+ - **general**: Update `rustc` (#3768) ([3798436](https://github.com/swc-project/swc/commit/3798436201a0838e55beac974792f4d560b47657))
191
+
192
+ ### Performance
193
+
194
+
195
+
196
+ - **(css/lints)** Skip disabled rules (#3803) ([0336029](https://github.com/swc-project/swc/commit/0336029c22a8751d2acb9765f11ead79c77115dc))
197
+
198
+
199
+ - **(plugin/runner)** Optimize `write_into_memory_view` (#3797) ([7fd0eee](https://github.com/swc-project/swc/commit/7fd0eeecb844a182fef39872178e3991356e3ae0))
200
+
201
+ ### Refactor
202
+
203
+
204
+
205
+ - **(css/ast)** Simplify AST types (#3753) ([815a489](https://github.com/swc-project/swc/commit/815a489dcfb72df928fc03f216dbe4a21b0e0716))
206
+
207
+
208
+ - **(css/lints)** Simplify error reporting API (#3781) ([b8211da](https://github.com/swc-project/swc/commit/b8211da1c9a8277cf09a8a3a1d7ae537b5d6e783))
209
+
210
+ ### Testing
211
+
212
+
213
+
214
+ - **(css/parser)** Add tests for selectors (#3770) ([1651bcc](https://github.com/swc-project/swc/commit/1651bccf4578ff2d44a9c37eab3845c006b5164d))
215
+
216
+
217
+ - **(css/parser)** Add css files for material design (#3777) ([189707a](https://github.com/swc-project/swc/commit/189707a1fd5ef8547b3b80ac82f7f422f295086a))
218
+
219
+
220
+ - **(es/minifier)** Prepare porting more rules from `terser` (#3779) ([86072b5](https://github.com/swc-project/swc/commit/86072b57f9e0cf59b660f88cdb2c9cee15f33720))
221
+
222
+ ### Build
223
+
224
+
225
+
226
+ - **(node-swc)** Rename entrypoint to avoid artifact collision (#3806) ([b485a2f](https://github.com/swc-project/swc/commit/b485a2fc267e0f373b9882e61c14b9fbf7a92471))
227
+
228
+ ## [1.2.146] - 2022-02-27
229
+
230
+ ### Bug Fixes
231
+
232
+
233
+
234
+ - **(css)** Fix processing of integers (#3752) ([f258ee4](https://github.com/swc-project/swc/commit/f258ee4729ccd007b43b1a08d77359d99f53ca87))
235
+
236
+
237
+ - **(es/codegen)** Fix escaping of unicodes in es5 (#3636) ([dba90ea](https://github.com/swc-project/swc/commit/dba90eae875bbaec9911c6dd72d482b75de77982))
238
+
239
+
240
+ - **(es/helpers)** Cast the result of the `instanceof` helper to boolean (#3728) ([72c9e6c](https://github.com/swc-project/swc/commit/72c9e6ca2b8186c4b297658bec1ce37912898d9f))
241
+
242
+
243
+ - **(es/parser)** Handle trailing comma and bracket after an arrow function in conditional (#3685) ([342dccc](https://github.com/swc-project/swc/commit/342dccce473aa507eabb3eed96485e2ff0674188))
244
+
245
+
246
+ - **(es/typescript)** Allow empty nested namespaces (#3754) ([f5a3647](https://github.com/swc-project/swc/commit/f5a364736420c2977a5d1211ead55ea91700fccb))
247
+
248
+
249
+ - **(plugin/macro)** Do not free guest memory twice (#3732) ([d8b0166](https://github.com/swc-project/swc/commit/d8b01660dcd0bca43993043e8fa6ed33c62894a9))- **general**: Fix(es/parser) Throw a syntax error for `const` without initializer in strict mode (#3742)
250
+
251
+ Co-authored-by: Donny/강동윤 <kdy1997.dev@gmail.com> ([abc0572](https://github.com/swc-project/swc/commit/abc05725575b0ee29319f32beadb014e70af5e06))
252
+
253
+ ### Features
254
+
255
+
256
+
257
+ - **(cli)** Add tracing options for `compile` command (#3746) ([41f92d2](https://github.com/swc-project/swc/commit/41f92d228b778193e12c51466630a42cb8953599))
258
+
259
+
260
+ - **(css/ast)** Support more selectors (#3729) ([f5c5e77](https://github.com/swc-project/swc/commit/f5c5e7761297e4413a1615e2537ade885ec12280))
261
+
262
+
263
+ - **(css/ast)** Allow more syntax for `@supports` at-rule (#3740) ([9b92eba](https://github.com/swc-project/swc/commit/9b92eba63686fee2176715fad8d072d6d6d34fe9))
264
+
265
+
266
+ - **(css/ast)** Improve type definitions for unicode ranges (#3757) ([91cf965](https://github.com/swc-project/swc/commit/91cf965e07a5382349262c6d6993477fde68aa58))
267
+
268
+
269
+ - **(css/minifier)** Compress `display` (#3706) ([8512719](https://github.com/swc-project/swc/commit/8512719e126d4041133a78e106bce6c7eca30154))
270
+
271
+
272
+ - **(es/codegen)** Add sourcemap entry for injected semicolons (#3750) ([0fd4fd2](https://github.com/swc-project/swc/commit/0fd4fd242287fde0e6a744dabf7c09430fb23d21))
273
+
274
+
275
+ - **(es/compat)** Implement loose mode for `class_properties` (#3722) ([14155eb](https://github.com/swc-project/swc/commit/14155eb0e7f6295471c92067afa4dfb84b3224ca))
276
+
277
+
278
+ - **(es/dep-graph)** Add `TsImportEqualsDecl` for `DependencyCollector` (#3758) ([7de7eca](https://github.com/swc-project/swc/commit/7de7ecaa85f21d074d8ca8a05dae2bf5b4ab3ce8))
279
+
280
+
281
+ - **(es/parser)** Provide more api for reducing binary size (#3747) ([47ccff8](https://github.com/swc-project/swc/commit/47ccff8a7ca0054fcd761ea5878a92165f7e1c6b))
282
+
283
+
284
+ - **(macros)** Add `#[swc_trace]` (#3738) ([b4830b6](https://github.com/swc-project/swc/commit/b4830b61dc7be716fd4de3703537517e6adefdba))
285
+
286
+
287
+ - **(node-swc)** Add experimental trace support in `@swc/core` (#3731) ([a454996](https://github.com/swc-project/swc/commit/a454996314f31ed9d8672e10588ef94815b16e98))
288
+
289
+
290
+ - **(plugin)** Support tracing plugin execution (#3744) ([5c29f15](https://github.com/swc-project/swc/commit/5c29f156404002d6946fbc7a71d76a6c97d7b82a))
291
+
292
+
293
+ - **(visit)** Allow using `?Sized` as visitor (#3745) ([b0b5d5d](https://github.com/swc-project/swc/commit/b0b5d5d0c2779e48d815fbbc65c01d5344590763))
294
+
295
+ ### Miscellaneous Tasks
296
+ - **general**: Skip CI for automated commits (#3760) ([6d98d14](https://github.com/swc-project/swc/commit/6d98d146a65e801677e63069bc52e66bb5315617))- **general**: Skip more actions for automated commits (#3761) ([0ff4ad3](https://github.com/swc-project/swc/commit/0ff4ad37c3783e7b141c6d879ed0a5a7e85135a3))
297
+
298
+ ### Performance
299
+
300
+
301
+
302
+ - **(es/modules)** Reduce usage of generics (#3743) ([1094018](https://github.com/swc-project/swc/commit/1094018153bc7d0373d9b7b533193191f416406d))
303
+
304
+
305
+ - **(es/parser)** Reduce usage of generics to reduce binary size (#3726) ([e21579d](https://github.com/swc-project/swc/commit/e21579d84ec287632393480e86032cc228bef0ce))
306
+
307
+ ### Refactor
308
+
309
+
310
+
311
+ - **(es)** Make compilation faster (#3749) ([3d94465](https://github.com/swc-project/swc/commit/3d944656bfa47532a79925f5b7392e2aec1a8a30))
312
+
313
+
314
+ - **(es/transforms)** Use recommended ast apis (#3735) ([fd22379](https://github.com/swc-project/swc/commit/fd223793e86f70400a3a69d7f7c8a4775b8abaad))
315
+
316
+ ### Testing
317
+
318
+
319
+
320
+ - **(css/parser)** Add malformed hex color tests (#3762) ([9f90882](https://github.com/swc-project/swc/commit/9f90882b27d345fac79f938d42e1b5fd04d4b1b5))
321
+
322
+ ## [1.2.145] - 2022-02-24
323
+
324
+ ### Bug Fixes
325
+
326
+
327
+
8
328
  - **(es/codegen)** Fix sourcemap of comments (#3723) ([b8b0c92](https://github.com/swc-project/swc/commit/b8b0c920e49c235fb65ca5585d343d2af79f9526))
9
329
 
10
330
 
package/Visitor.js CHANGED
@@ -779,7 +779,7 @@ class Visitor {
779
779
  }
780
780
  }
781
781
  visitOptionalChainingExpression(n) {
782
- n.expr = this.visitExpression(n.expr);
782
+ n.base = this.visitExpression(n.base);
783
783
  return n;
784
784
  }
785
785
  visitAssignmentExpression(n) {
package/binding.d.ts CHANGED
@@ -11,4 +11,5 @@ export const transform: any;
11
11
  export const transformSync: any;
12
12
  export const transformFile: any;
13
13
  export const transformFileSync: any;
14
+ export const initCustomTraceSubscriber: any;
14
15
  export const Compiler: any;
package/binding.js CHANGED
@@ -1,15 +1,15 @@
1
1
  "use strict";
2
- const { existsSync, readFileSync } = require("fs");
3
- const { join } = require("path");
2
+ const { existsSync, readFileSync } = require('fs');
3
+ const { join } = require('path');
4
4
  const { platform, arch } = process;
5
5
  let nativeBinding = null;
6
6
  let localFileExisted = false;
7
7
  let loadError = null;
8
8
  function isMusl() {
9
9
  // For Node 10
10
- if (!process.report || typeof process.report.getReport !== "function") {
10
+ if (!process.report || typeof process.report.getReport !== 'function') {
11
11
  try {
12
- return readFileSync("/usr/bin/ldd", "utf8").includes("musl");
12
+ return readFileSync('/usr/bin/ldd', 'utf8').includes('musl');
13
13
  }
14
14
  catch (e) {
15
15
  return true;
@@ -21,30 +21,30 @@ function isMusl() {
21
21
  }
22
22
  }
23
23
  switch (platform) {
24
- case "android":
24
+ case 'android':
25
25
  switch (arch) {
26
- case "arm64":
27
- localFileExisted = existsSync(join(__dirname, "swc.android-arm64.node"));
26
+ case 'arm64':
27
+ localFileExisted = existsSync(join(__dirname, 'swc.android-arm64.node'));
28
28
  try {
29
29
  if (localFileExisted) {
30
- nativeBinding = require("./swc.android-arm64.node");
30
+ nativeBinding = require('./swc.android-arm64.node');
31
31
  }
32
32
  else {
33
- nativeBinding = require("@swc/core-android-arm64");
33
+ nativeBinding = require('@swc/core-android-arm64');
34
34
  }
35
35
  }
36
36
  catch (e) {
37
37
  loadError = e;
38
38
  }
39
39
  break;
40
- case "arm":
41
- localFileExisted = existsSync(join(__dirname, "swc.android-arm-eabi.node"));
40
+ case 'arm':
41
+ localFileExisted = existsSync(join(__dirname, 'swc.android-arm-eabi.node'));
42
42
  try {
43
43
  if (localFileExisted) {
44
- nativeBinding = require("./swc.android-arm-eabi.node");
44
+ nativeBinding = require('./swc.android-arm-eabi.node');
45
45
  }
46
46
  else {
47
- nativeBinding = require("@swc/core-android-arm-eabi");
47
+ nativeBinding = require('@swc/core-android-arm-eabi');
48
48
  }
49
49
  }
50
50
  catch (e) {
@@ -55,44 +55,44 @@ switch (platform) {
55
55
  throw new Error(`Unsupported architecture on Android ${arch}`);
56
56
  }
57
57
  break;
58
- case "win32":
58
+ case 'win32':
59
59
  switch (arch) {
60
- case "x64":
61
- localFileExisted = existsSync(join(__dirname, "swc.win32-x64-msvc.node"));
60
+ case 'x64':
61
+ localFileExisted = existsSync(join(__dirname, 'swc.win32-x64-msvc.node'));
62
62
  try {
63
63
  if (localFileExisted) {
64
- nativeBinding = require("./swc.win32-x64-msvc.node");
64
+ nativeBinding = require('./swc.win32-x64-msvc.node');
65
65
  }
66
66
  else {
67
- nativeBinding = require("@swc/core-win32-x64-msvc");
67
+ nativeBinding = require('@swc/core-win32-x64-msvc');
68
68
  }
69
69
  }
70
70
  catch (e) {
71
71
  loadError = e;
72
72
  }
73
73
  break;
74
- case "ia32":
75
- localFileExisted = existsSync(join(__dirname, "swc.win32-ia32-msvc.node"));
74
+ case 'ia32':
75
+ localFileExisted = existsSync(join(__dirname, 'swc.win32-ia32-msvc.node'));
76
76
  try {
77
77
  if (localFileExisted) {
78
- nativeBinding = require("./swc.win32-ia32-msvc.node");
78
+ nativeBinding = require('./swc.win32-ia32-msvc.node');
79
79
  }
80
80
  else {
81
- nativeBinding = require("@swc/core-win32-ia32-msvc");
81
+ nativeBinding = require('@swc/core-win32-ia32-msvc');
82
82
  }
83
83
  }
84
84
  catch (e) {
85
85
  loadError = e;
86
86
  }
87
87
  break;
88
- case "arm64":
89
- localFileExisted = existsSync(join(__dirname, "swc.win32-arm64-msvc.node"));
88
+ case 'arm64':
89
+ localFileExisted = existsSync(join(__dirname, 'swc.win32-arm64-msvc.node'));
90
90
  try {
91
91
  if (localFileExisted) {
92
- nativeBinding = require("./swc.win32-arm64-msvc.node");
92
+ nativeBinding = require('./swc.win32-arm64-msvc.node');
93
93
  }
94
94
  else {
95
- nativeBinding = require("@swc/core-win32-arm64-msvc");
95
+ nativeBinding = require('@swc/core-win32-arm64-msvc');
96
96
  }
97
97
  }
98
98
  catch (e) {
@@ -103,30 +103,30 @@ switch (platform) {
103
103
  throw new Error(`Unsupported architecture on Windows: ${arch}`);
104
104
  }
105
105
  break;
106
- case "darwin":
106
+ case 'darwin':
107
107
  switch (arch) {
108
- case "x64":
109
- localFileExisted = existsSync(join(__dirname, "swc.darwin-x64.node"));
108
+ case 'x64':
109
+ localFileExisted = existsSync(join(__dirname, 'swc.darwin-x64.node'));
110
110
  try {
111
111
  if (localFileExisted) {
112
- nativeBinding = require("./swc.darwin-x64.node");
112
+ nativeBinding = require('./swc.darwin-x64.node');
113
113
  }
114
114
  else {
115
- nativeBinding = require("@swc/core-darwin-x64");
115
+ nativeBinding = require('@swc/core-darwin-x64');
116
116
  }
117
117
  }
118
118
  catch (e) {
119
119
  loadError = e;
120
120
  }
121
121
  break;
122
- case "arm64":
123
- localFileExisted = existsSync(join(__dirname, "swc.darwin-arm64.node"));
122
+ case 'arm64':
123
+ localFileExisted = existsSync(join(__dirname, 'swc.darwin-arm64.node'));
124
124
  try {
125
125
  if (localFileExisted) {
126
- nativeBinding = require("./swc.darwin-arm64.node");
126
+ nativeBinding = require('./swc.darwin-arm64.node');
127
127
  }
128
128
  else {
129
- nativeBinding = require("@swc/core-darwin-arm64");
129
+ nativeBinding = require('@swc/core-darwin-arm64');
130
130
  }
131
131
  }
132
132
  catch (e) {
@@ -137,34 +137,34 @@ switch (platform) {
137
137
  throw new Error(`Unsupported architecture on macOS: ${arch}`);
138
138
  }
139
139
  break;
140
- case "freebsd":
141
- if (arch !== "x64") {
140
+ case 'freebsd':
141
+ if (arch !== 'x64') {
142
142
  throw new Error(`Unsupported architecture on FreeBSD: ${arch}`);
143
143
  }
144
- localFileExisted = existsSync(join(__dirname, "swc.freebsd-x64.node"));
144
+ localFileExisted = existsSync(join(__dirname, 'swc.freebsd-x64.node'));
145
145
  try {
146
146
  if (localFileExisted) {
147
- nativeBinding = require("./swc.freebsd-x64.node");
147
+ nativeBinding = require('./swc.freebsd-x64.node');
148
148
  }
149
149
  else {
150
- nativeBinding = require("@swc/core-freebsd-x64");
150
+ nativeBinding = require('@swc/core-freebsd-x64');
151
151
  }
152
152
  }
153
153
  catch (e) {
154
154
  loadError = e;
155
155
  }
156
156
  break;
157
- case "linux":
157
+ case 'linux':
158
158
  switch (arch) {
159
- case "x64":
159
+ case 'x64':
160
160
  if (isMusl()) {
161
- localFileExisted = existsSync(join(__dirname, "swc.linux-x64-musl.node"));
161
+ localFileExisted = existsSync(join(__dirname, 'swc.linux-x64-musl.node'));
162
162
  try {
163
163
  if (localFileExisted) {
164
- nativeBinding = require("./swc.linux-x64-musl.node");
164
+ nativeBinding = require('./swc.linux-x64-musl.node');
165
165
  }
166
166
  else {
167
- nativeBinding = require("@swc/core-linux-x64-musl");
167
+ nativeBinding = require('@swc/core-linux-x64-musl');
168
168
  }
169
169
  }
170
170
  catch (e) {
@@ -172,13 +172,13 @@ switch (platform) {
172
172
  }
173
173
  }
174
174
  else {
175
- localFileExisted = existsSync(join(__dirname, "swc.linux-x64-gnu.node"));
175
+ localFileExisted = existsSync(join(__dirname, 'swc.linux-x64-gnu.node'));
176
176
  try {
177
177
  if (localFileExisted) {
178
- nativeBinding = require("./swc.linux-x64-gnu.node");
178
+ nativeBinding = require('./swc.linux-x64-gnu.node');
179
179
  }
180
180
  else {
181
- nativeBinding = require("@swc/core-linux-x64-gnu");
181
+ nativeBinding = require('@swc/core-linux-x64-gnu');
182
182
  }
183
183
  }
184
184
  catch (e) {
@@ -186,15 +186,15 @@ switch (platform) {
186
186
  }
187
187
  }
188
188
  break;
189
- case "arm64":
189
+ case 'arm64':
190
190
  if (isMusl()) {
191
- localFileExisted = existsSync(join(__dirname, "swc.linux-arm64-musl.node"));
191
+ localFileExisted = existsSync(join(__dirname, 'swc.linux-arm64-musl.node'));
192
192
  try {
193
193
  if (localFileExisted) {
194
- nativeBinding = require("./swc.linux-arm64-musl.node");
194
+ nativeBinding = require('./swc.linux-arm64-musl.node');
195
195
  }
196
196
  else {
197
- nativeBinding = require("@swc/core-linux-arm64-musl");
197
+ nativeBinding = require('@swc/core-linux-arm64-musl');
198
198
  }
199
199
  }
200
200
  catch (e) {
@@ -202,13 +202,13 @@ switch (platform) {
202
202
  }
203
203
  }
204
204
  else {
205
- localFileExisted = existsSync(join(__dirname, "swc.linux-arm64-gnu.node"));
205
+ localFileExisted = existsSync(join(__dirname, 'swc.linux-arm64-gnu.node'));
206
206
  try {
207
207
  if (localFileExisted) {
208
- nativeBinding = require("./swc.linux-arm64-gnu.node");
208
+ nativeBinding = require('./swc.linux-arm64-gnu.node');
209
209
  }
210
210
  else {
211
- nativeBinding = require("@swc/core-linux-arm64-gnu");
211
+ nativeBinding = require('@swc/core-linux-arm64-gnu');
212
212
  }
213
213
  }
214
214
  catch (e) {
@@ -216,14 +216,14 @@ switch (platform) {
216
216
  }
217
217
  }
218
218
  break;
219
- case "arm":
220
- localFileExisted = existsSync(join(__dirname, "swc.linux-arm-gnueabihf.node"));
219
+ case 'arm':
220
+ localFileExisted = existsSync(join(__dirname, 'swc.linux-arm-gnueabihf.node'));
221
221
  try {
222
222
  if (localFileExisted) {
223
- nativeBinding = require("./swc.linux-arm-gnueabihf.node");
223
+ nativeBinding = require('./swc.linux-arm-gnueabihf.node');
224
224
  }
225
225
  else {
226
- nativeBinding = require("@swc/core-linux-arm-gnueabihf");
226
+ nativeBinding = require('@swc/core-linux-arm-gnueabihf');
227
227
  }
228
228
  }
229
229
  catch (e) {
@@ -243,7 +243,7 @@ if (!nativeBinding) {
243
243
  }
244
244
  throw new Error(`Failed to load native binding`);
245
245
  }
246
- const { bundle, minify, minifySync, parse, parseSync, parseFileSync, parseFile, print, printSync, transform, transformSync, transformFile, transformFileSync, Compiler, } = nativeBinding;
246
+ const { bundle, minify, minifySync, parse, parseSync, parseFileSync, parseFile, print, printSync, transform, transformSync, transformFile, transformFileSync, initCustomTraceSubscriber, Compiler } = nativeBinding;
247
247
  module.exports.bundle = bundle;
248
248
  module.exports.minify = minify;
249
249
  module.exports.minifySync = minifySync;
@@ -257,4 +257,5 @@ module.exports.transform = transform;
257
257
  module.exports.transformSync = transformSync;
258
258
  module.exports.transformFile = transformFile;
259
259
  module.exports.transformFileSync = transformFileSync;
260
+ module.exports.initCustomTraceSubscriber = initCustomTraceSubscriber;
260
261
  module.exports.Compiler = Compiler;
package/index.d.ts CHANGED
@@ -70,4 +70,26 @@ export declare function bundle(options?: BundleInput | string): Promise<{
70
70
  }>;
71
71
  export declare function minify(src: string, opts?: JsMinifyOptions): Promise<Output>;
72
72
  export declare function minifySync(src: string, opts?: JsMinifyOptions): Output;
73
+ /**
74
+ * Configure custom trace configuration runs for a process lifecycle.
75
+ * Currently only chromium's trace event format is supported.
76
+ * (https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview)
77
+ *
78
+ * This should be called before calling any binding interfaces exported in `@swc/core`, such as
79
+ * `transform*`, or `parse*` or anything. To avoid breaking changes, each binding fn internally
80
+ * sets default trace subscriber if not set.
81
+ *
82
+ * Unlike other configuration, this does not belong to individual api surface using swcrc
83
+ * or api's parameters (`transform(..., {trace})`). This is due to current tracing subscriber
84
+ * can be configured only once for the global scope. Calling `registerGlobalTraceConfig` multiple
85
+ * time won't cause error, subsequent calls will be ignored.
86
+ *
87
+ * As name implies currently this is experimental interface may change over time without semver
88
+ * major breaking changes. Please provide feedbacks,
89
+ * or bug report at https://github.com/swc-project/swc/discussions.
90
+ */
91
+ export declare function __experimental_registerGlobalTraceConfig(traceConfig: {
92
+ type: 'traceEvent';
93
+ fileName?: string;
94
+ }): void;
73
95
  export declare const DEFAULT_EXTENSIONS: readonly string[];
package/index.js CHANGED
@@ -30,7 +30,7 @@ var __rest = (this && this.__rest) || function (s, e) {
30
30
  return t;
31
31
  };
32
32
  Object.defineProperty(exports, "__esModule", { value: true });
33
- exports.DEFAULT_EXTENSIONS = exports.minifySync = exports.minify = exports.bundle = exports.transformFileSync = exports.transformFile = exports.transformSync = exports.transform = exports.printSync = exports.print = exports.parseFileSync = exports.parseFile = exports.parseSync = exports.parse = exports.Compiler = exports.plugins = exports.version = void 0;
33
+ exports.DEFAULT_EXTENSIONS = exports.__experimental_registerGlobalTraceConfig = exports.minifySync = exports.minify = exports.bundle = exports.transformFileSync = exports.transformFile = exports.transformSync = exports.transform = exports.printSync = exports.print = exports.parseFileSync = exports.parseFile = exports.parseSync = exports.parse = exports.Compiler = exports.plugins = exports.version = void 0;
34
34
  const path_1 = require("path");
35
35
  __exportStar(require("./types"), exports);
36
36
  const spack_1 = require("./spack");
@@ -239,6 +239,30 @@ function minifySync(src, opts) {
239
239
  return compiler.minifySync(src, opts);
240
240
  }
241
241
  exports.minifySync = minifySync;
242
+ /**
243
+ * Configure custom trace configuration runs for a process lifecycle.
244
+ * Currently only chromium's trace event format is supported.
245
+ * (https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview)
246
+ *
247
+ * This should be called before calling any binding interfaces exported in `@swc/core`, such as
248
+ * `transform*`, or `parse*` or anything. To avoid breaking changes, each binding fn internally
249
+ * sets default trace subscriber if not set.
250
+ *
251
+ * Unlike other configuration, this does not belong to individual api surface using swcrc
252
+ * or api's parameters (`transform(..., {trace})`). This is due to current tracing subscriber
253
+ * can be configured only once for the global scope. Calling `registerGlobalTraceConfig` multiple
254
+ * time won't cause error, subsequent calls will be ignored.
255
+ *
256
+ * As name implies currently this is experimental interface may change over time without semver
257
+ * major breaking changes. Please provide feedbacks,
258
+ * or bug report at https://github.com/swc-project/swc/discussions.
259
+ */
260
+ function __experimental_registerGlobalTraceConfig(traceConfig) {
261
+ if (traceConfig.type === 'traceEvent') {
262
+ bindings.initCustomTraceSubscriber(traceConfig.fileName);
263
+ }
264
+ }
265
+ exports.__experimental_registerGlobalTraceConfig = __experimental_registerGlobalTraceConfig;
242
266
  exports.DEFAULT_EXTENSIONS = Object.freeze([
243
267
  ".js",
244
268
  ".jsx",
package/package.json CHANGED
@@ -1,9 +1,12 @@
1
1
  {
2
2
  "name": "@swc/core",
3
- "version": "1.2.145",
3
+ "version": "1.2.148",
4
4
  "description": "Super-fast alternative for babel",
5
5
  "homepage": "https://swc.rs",
6
6
  "main": "./index.js",
7
+ "bin": {
8
+ "swcx": "run_swcx.js"
9
+ },
7
10
  "author": "강동윤 <kdy1997.dev@gmail.com>",
8
11
  "license": "Apache-2.0",
9
12
  "keywords": [
@@ -104,18 +107,18 @@
104
107
  "url": "https://opencollective.com/swc"
105
108
  },
106
109
  "optionalDependencies": {
107
- "@swc/core-win32-x64-msvc": "1.2.145",
108
- "@swc/core-darwin-x64": "1.2.145",
109
- "@swc/core-linux-x64-gnu": "1.2.145",
110
- "@swc/core-linux-x64-musl": "1.2.145",
111
- "@swc/core-freebsd-x64": "1.2.145",
112
- "@swc/core-win32-ia32-msvc": "1.2.145",
113
- "@swc/core-linux-arm64-gnu": "1.2.145",
114
- "@swc/core-linux-arm-gnueabihf": "1.2.145",
115
- "@swc/core-darwin-arm64": "1.2.145",
116
- "@swc/core-android-arm64": "1.2.145",
117
- "@swc/core-linux-arm64-musl": "1.2.145",
118
- "@swc/core-win32-arm64-msvc": "1.2.145",
119
- "@swc/core-android-arm-eabi": "1.2.145"
110
+ "@swc/core-win32-x64-msvc": "1.2.148",
111
+ "@swc/core-darwin-x64": "1.2.148",
112
+ "@swc/core-linux-x64-gnu": "1.2.148",
113
+ "@swc/core-linux-x64-musl": "1.2.148",
114
+ "@swc/core-freebsd-x64": "1.2.148",
115
+ "@swc/core-win32-ia32-msvc": "1.2.148",
116
+ "@swc/core-linux-arm64-gnu": "1.2.148",
117
+ "@swc/core-linux-arm-gnueabihf": "1.2.148",
118
+ "@swc/core-darwin-arm64": "1.2.148",
119
+ "@swc/core-android-arm64": "1.2.148",
120
+ "@swc/core-linux-arm64-musl": "1.2.148",
121
+ "@swc/core-win32-arm64-msvc": "1.2.148",
122
+ "@swc/core-android-arm-eabi": "1.2.148"
120
123
  }
121
124
  }
package/run_swcx.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/run_swcx.js ADDED
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
+ return new (P || (P = Promise))(function (resolve, reject) {
6
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
10
+ });
11
+ };
12
+ var __importDefault = (this && this.__importDefault) || function (mod) {
13
+ return (mod && mod.__esModule) ? mod : { "default": mod };
14
+ };
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ /**
17
+ * Lightweight entrypoint to native swc cli binary.
18
+ *
19
+ * This is to locate corresponding per-platform executables correctly, as well as
20
+ * let npm links binary to `node_modules/.bin` allows npm-related ecosystem (`npx swcx`, etcs)
21
+ * works correctly. However, it means spawning native binary still requires warmup from node.js
22
+ * process.
23
+ *
24
+ * NOTE: THIS IS NOT A PERMANENT APPROACH.
25
+ * Distribution of native cli binary is not fully concluded yet. This allows easier
26
+ * opt-in while implementation is in progress to collect feedback.
27
+ */
28
+ const child_process_1 = require("child_process");
29
+ const path_1 = __importDefault(require("path"));
30
+ const fs_1 = require("fs");
31
+ const { platform, arch } = process;
32
+ const isMusl = () => (() => {
33
+ function isMusl() {
34
+ if (!process.report || typeof process.report.getReport !== "function") {
35
+ try {
36
+ return (0, fs_1.readFileSync)("/usr/bin/ldd", "utf8").includes("musl");
37
+ }
38
+ catch (e) {
39
+ return true;
40
+ }
41
+ }
42
+ else {
43
+ const { glibcVersionRuntime } = process.report.getReport().header;
44
+ return !glibcVersionRuntime;
45
+ }
46
+ }
47
+ return isMusl();
48
+ })();
49
+ const platformPackagesMap = {
50
+ "android": {
51
+ "arm64": "@swc/core-android-arm64",
52
+ "arm": "@swc/core-android-arm-eabi",
53
+ },
54
+ "win32": {
55
+ "x64": "@swc/core-win32-x64-msvc",
56
+ "ia32": "@swc/core-win32-ia32-msvc",
57
+ "arm64": "@swc/core-win32-arm64-msvc"
58
+ },
59
+ "darwin": {
60
+ "x64": "@swc/core-darwin-x64",
61
+ "arm64": "@swc/core-darwin-arm64",
62
+ },
63
+ "freebsd": {
64
+ "x64": "@swc/core-freebsd-x64",
65
+ },
66
+ "linux": {
67
+ "x64": `@swc/core-linux-x64-${isMusl() ? 'musl' : 'gnu'}`,
68
+ "arm64": `@swc/core-linux-arm64-${isMusl() ? 'musl' : 'gnu'}`,
69
+ "arm": "@swc/core-linux-arm64-gnu"
70
+ },
71
+ };
72
+ const inferBinaryName = () => {
73
+ const packageName = platformPackagesMap[platform][arch];
74
+ if (!packageName) {
75
+ throw new Error(`Unsupported platform: binary for '${platform} ${arch}' is not available`);
76
+ }
77
+ return path_1.default.join(path_1.default.dirname(require.resolve(packageName)), platform === 'win32' ? 'swc.exe' : 'swc');
78
+ };
79
+ const executeBinary = () => __awaiter(void 0, void 0, void 0, function* () {
80
+ const binary = inferBinaryName();
81
+ const [, , ...args] = process.argv;
82
+ const options = { cwd: process.cwd(), stdio: "inherit" };
83
+ return (0, child_process_1.spawn)(binary, args, options);
84
+ });
85
+ executeBinary().catch((e) => console.error(e));
package/types.d.ts CHANGED
@@ -742,7 +742,7 @@ export interface OptionalChainingExpression extends ExpressionBase {
742
742
  /**
743
743
  * Call expression or member expression.
744
744
  */
745
- expr: Expression;
745
+ base: Expression;
746
746
  }
747
747
  export interface ThisExpression extends ExpressionBase {
748
748
  type: "ThisExpression";
@@ -1020,6 +1020,7 @@ export interface ExportNamedDeclaration extends Node, HasSpan {
1020
1020
  type: "ExportNamedDeclaration";
1021
1021
  specifiers: ExportSpecifier[];
1022
1022
  source?: StringLiteral;
1023
+ typeOnly: boolean;
1023
1024
  }
1024
1025
  export interface ExportDefaultDeclaration extends Node, HasSpan {
1025
1026
  type: "ExportDefaultDeclaration";
@@ -1 +0,0 @@
1
- ### This adr attempts to describe 10,000ft view for the swc project itself. To be filled gradually.
@@ -1,94 +0,0 @@
1
- # Support transform plugin in native rust binaries
2
-
3
- - Status: accepted <!-- optional -->
4
- - Deciders: @kdy1, @kwonoj <!-- optional -->
5
- - Date: 2021-01-01 <!-- optional -->
6
-
7
- Technical Story: [Issue](https://github.com/swc-project/swc/issues/2635) <!-- optional -->
8
-
9
- ## Context and Problem Statement
10
-
11
- SWC wants to support load, run plugins in the native binary for the custom transform behavior. SWC already have priliminary support to load plugins in its node.js JS bindings but it has known limitations.
12
-
13
- ## Decision Drivers <!-- optional -->
14
-
15
- - Allow to write a plugin binary can be loaded in the SWC's native binary without involving JS binding interop.
16
- - Provide good, satisfactory performance while loading, running plugin's custom transformation.
17
- - Keep abi stability as much, plugin binary should work across different versions of SWC host binary except intended breaking changes.
18
- - Allow to write a plugin without caring much around the native platform targets binaries.
19
-
20
- ## Considered Options
21
-
22
- - [option 1] JS-based plugins, including babel plugins
23
-
24
- - [option 2] Plugins based on `abi_stable` and native dynamic libraries
25
-
26
- - [option 3] Wasm plugins based on `wasmtime`
27
-
28
- - **[option 4]** Wasm plugins based on `wasmer`
29
-
30
- ## Decision Outcome
31
-
32
- Chosen option: **[option 4] Wasm plugins based on `wasmer`**
33
-
34
- This decision is taken because
35
-
36
- - It was relatively easy plugin author to generate single binary works across most of platforms SWC's host binary supports, without concern of cross-target compilations.
37
- - It was relatively easy to achieve abi-stable between SWC host to plugin binaries.
38
- - It doesn't require to have separate, specialized AST struct (named `plugin_ast`) to pass into ffi boundary of the plugin.
39
- - Its serialization / deserialization performance is near identical or faster than `abi_stable` based ffi
40
-
41
- ## Pros and Cons of the Options <!-- optional -->
42
-
43
- ### [option 1] JS-based plugins, including babel plugins
44
-
45
- SWC allow implementing plugins using javascript, and call it from worker threads as required.
46
- This includes babel plugins, to make migration from babel more convenient.
47
-
48
- - Good, because users can use rich ecosystem of babel.
49
- - Good, because users are used to javascript.
50
- - Good, because all platforms are supported.
51
- - Bad, because passing data to and from javascript is very costly. ([SWC issue: Speed up `parse`](https://github.com/swc-project/swc/issues/2175))
52
- - Bad, because js plugins require and block the main javascript thread.
53
- - Bad, because the main javascript is singled threaded and be bottleneck.
54
- - Bad, because `napi` (renamed to `node-api`) does not provide a way to get the return value of a function called from other thread than js thread. To workaround this, we should implement a complex request-response system based using lots of mutex.
55
- - Bad, because node js worker thread is not an event loop. This means worker we cannot `yield` from a worker thread when we need to call js plugin. As a result, the when main js thread is busy because of js plugins, worker threads are also blocked without doing any task.
56
-
57
- ### [option 2] Plugins based on `abi_stable` and native dynamic libraries
58
-
59
- Plugins are written in rust, and built as native libraries for each platforms. SWC pass data to plugin using special form of AST, which has stable memory representation regardless of the version of `rustc`.
60
-
61
- - Good, because it's fast, even on the first run.
62
- - Good, because it does not require very complex request-response system.
63
- - Good, because plugin authors can use all features of rust.
64
- - Bad, because configuring CI for publishing plugins is very hard.
65
- - Bad, because plugin developer cannot publish a plugin from a single machine.
66
- - Bad, because loading of plugins is complex. Path for dynamic libraries are platform-dependant.
67
- - Bad, because we have to handle quirks of each platforms.
68
- - Bad, because `@swc/wasm` has no way to support plugins.
69
-
70
- ### [option 3] Wasm plugins based on `wasmtime`
71
-
72
- SWC embeds `wasmtime`, loads plugin built as web assembly.
73
-
74
- - Good, because it's fast except the first run.
75
- - Good, because configuring CI is simple.
76
- - Good, because plugin authors can publish a plugin without CI, even with a single machine.
77
- - Bad, because `@swc/wasm` has no way to support plugins.
78
- - Bad, because first run is slow.
79
- - Bad, because we have to manage the cache of compiled wasm files.
80
- - Bad, because `wasmtime` does not support all platforms.
81
-
82
- ### [option 4] Wasm plugins based on `wasmer`
83
-
84
- SWC embeds web assembly runtime (https://wasmer.io/), loads plugin built as web assembly.
85
-
86
- - Good, because it's fast except the first run.
87
- - Good, because configuring CI is simple.
88
- - Good, because plugin authors can publish a plugin without CI, even with a single machine.
89
- - Good, because `@swc/wasm` can support plugins in future as `wasmer` officially supports using it within a wasm file.
90
- - Bad, because first run is slow.
91
- - Bad, because we have to manage the cache of compiled wasm files.
92
- - Bad, because `wasmer` does not support all platforms.
93
-
94
- ## Links
@@ -1,13 +0,0 @@
1
- # Architectural Decision Records
2
-
3
- This directory contains a series of [Architectural Decision Records](https://adr.github.io/)
4
- or "ADRs" for the `swc` project. We're going to try to use it as a kind of collective
5
- memory of the decisions we've made and the path we've taken to get the project to its current
6
- point.
7
-
8
- Note that these are *historical references* that do not supersede (but might enhance) the living
9
- documentation of the project itself, which you can find inline in the source code.
10
-
11
- Proposing a non-trivial change to the way `swc` works? You might like to start with an ADR
12
- by copying `template.md` into a new file, filling out a first version of the proposal, and
13
- posting it as a PR on the github repo for discussion.
@@ -1,72 +0,0 @@
1
- # [short title of solved problem and solution]
2
-
3
- * Status: [proposed | rejected | accepted | deprecated | … | superseded by [ADR-0005](0005-example.md)] <!-- optional -->
4
- * Deciders: [list everyone involved in the decision] <!-- optional -->
5
- * Date: [YYYY-MM-DD when the decision was last updated] <!-- optional -->
6
-
7
- Technical Story: [description | ticket/issue URL] <!-- optional -->
8
-
9
- ## Context and Problem Statement
10
-
11
- [Describe the context and problem statement, e.g., in free form using two to three sentences. You may want to articulate the problem in form of a question.]
12
-
13
- ## Decision Drivers <!-- optional -->
14
-
15
- * [driver 1, e.g., a force, facing concern, …]
16
- * [driver 2, e.g., a force, facing concern, …]
17
- * … <!-- numbers of drivers can vary -->
18
-
19
- ## Considered Options
20
-
21
- * [option 1]
22
- * [option 2]
23
- * [option 3]
24
- * … <!-- numbers of options can vary -->
25
-
26
- ## Decision Outcome
27
-
28
- Chosen option: "[option 1]", because [justification. e.g., only option, which meets k.o. criterion decision driver | which resolves force force | … | comes out best (see below)].
29
-
30
- ### Positive Consequences <!-- optional -->
31
-
32
- * [e.g., improvement of quality attribute satisfaction, follow-up decisions required, …]
33
- * …
34
-
35
- ### Negative Consequences <!-- optional -->
36
-
37
- * [e.g., compromising quality attribute, follow-up decisions required, …]
38
- * …
39
-
40
- ## Pros and Cons of the Options <!-- optional -->
41
-
42
- ### [option 1]
43
-
44
- [example | description | pointer to more information | …] <!-- optional -->
45
-
46
- * Good, because [argument a]
47
- * Good, because [argument b]
48
- * Bad, because [argument c]
49
- * … <!-- numbers of pros and cons can vary -->
50
-
51
- ### [option 2]
52
-
53
- [example | description | pointer to more information | …] <!-- optional -->
54
-
55
- * Good, because [argument a]
56
- * Good, because [argument b]
57
- * Bad, because [argument c]
58
- * … <!-- numbers of pros and cons can vary -->
59
-
60
- ### [option 3]
61
-
62
- [example | description | pointer to more information | …] <!-- optional -->
63
-
64
- * Good, because [argument a]
65
- * Good, because [argument b]
66
- * Bad, because [argument c]
67
- * … <!-- numbers of pros and cons can vary -->
68
-
69
- ## Links <!-- optional -->
70
-
71
- * [Link type] [Link to ADR] <!-- example: Refined by [ADR-0005](0005-example.md) -->
72
- * … <!-- numbers of links can vary -->