Skip to content

Commit

Permalink
Bump swc (#9574)
Browse files Browse the repository at this point in the history
* Bump swc, enable stacker feature

Bump swc

* Adapt for breaking swc AST change

* Support testing with Miri

* Grow stack when visiting expressions

* WIP add example

* Revert "WIP add example"

This reverts commit d4dba2c.

* Add swc update script

* Update test fixtures

* Fix windows stack overflow with larger stack red_zone (#9693)

* Bump swc

* Bump a few crates for vulnerabilites

* Bump swc

* Fix esm2js transform when export destructuring

---------

Co-authored-by: Jon de la Motte <jondlm@gmail.com>
  • Loading branch information
mischnic and jondlm committed May 15, 2024
1 parent a4a4033 commit 43d5d19
Show file tree
Hide file tree
Showing 24 changed files with 512 additions and 499 deletions.
613 changes: 310 additions & 303 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion crates/macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ napi = ["dep:napi", "dep:napi-derive", "dep:crossbeam-channel"]

[dependencies]
indexmap = "1.9.2"
swc_core = { version = "0.89.6", features = [
swc_core = { version = "0.92.4", features = [
"common",
"common_ahash",
"common_sourcemap",
"ecma_ast",
"ecma_parser",
"ecma_visit",
"stacker"
] }
serde = "1.0.123"
napi-derive = { version = "2.12.5", optional = true }
Expand Down
3 changes: 2 additions & 1 deletion crates/macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::HashMap;
use std::collections::HashSet;
use std::sync::Arc;
use swc_core::ecma::utils::stack_size::maybe_grow_default;

use indexmap::IndexMap;
use swc_core::common::util::take::Take;
Expand Down Expand Up @@ -254,7 +255,7 @@ impl<'a> Fold for Macros<'a> {
return Expr::Call(call);
}

node.fold_children_with(self)
maybe_grow_default(|| node.fold_children_with(self))
}

fn fold_var_decl(&mut self, mut node: VarDecl) -> VarDecl {
Expand Down
4 changes: 2 additions & 2 deletions crates/node-bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ use std::alloc::Layout;

mod init_sentry;

#[cfg(target_os = "macos")]
#[cfg(all(target_os = "macos", not(miri)))]
#[global_allocator]
static GLOBAL: jemallocator::Jemalloc = jemallocator::Jemalloc;

#[cfg(windows)]
#[cfg(all(windows, not(miri)))]
#[global_allocator]
static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc;

Expand Down
10 changes: 5 additions & 5 deletions packages/core/core/test/Parcel.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ describe('ParcelAPI', function () {
afterEach(() => workerFarm.end());

describe('parcel.unstable_transform()', () => {
it('should transforms simple file', async () => {
it('should transform simple file', async () => {
let parcel = createParcel({workerFarm});
let res = await parcel.unstable_transform({
filePath: path.join(__dirname, 'fixtures/parcel/index.js'),
});
let code = await res[0].getCode();
assert(code.includes('exports.default = "test"'));
assert(code.includes(`exports.default = 'test'`));
});

it('should transform with standalone mode', async () => {
Expand All @@ -103,9 +103,9 @@ describe('ParcelAPI', function () {
});
let code = await res[0].getCode();

assert(code.includes('require("./index.js")'));
assert(code.includes('new URL("index.js", "file:" + __filename);'));
assert(code.includes('import("index.js")'));
assert(code.includes(`require("./index.js")`));
assert(code.includes(`new URL("index.js", "file:" + __filename);`));
assert(code.includes(`import('index.js')`));
});
});

Expand Down
6 changes: 3 additions & 3 deletions packages/core/integration-tests/test/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -5875,17 +5875,17 @@ describe('cache', function () {
},
async update(b) {
let res = await run(b.bundleGraph);
assert(res.includes(`let a = "a"`));
assert(res.includes(`let a = 'a'`));

await overlayFS.writeFile(
path.join(inputDir, 'src/entries/a.js'),
`export let a = "b";`,
`export let a = 'b';`,
);
},
});

let res = await run(b.bundleGraph);
assert(res.includes(`let a = "b"`));
assert(res.includes(`let a = 'b'`));
});

it('should invalidate when switching to a different packager for an inline bundle', async function () {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/integration-tests/test/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -2689,7 +2689,7 @@ describe('html', function () {
await getNextBuild(b);

let html = await outputFS.readFile('/dist/index.html', 'utf8');
assert(html.includes(`console.log("test")`));
assert(html.includes(`console.log('test')`));

await overlayFS.writeFile(
path.join(__dirname, '/html-inline-js-require/test.js'),
Expand All @@ -2698,7 +2698,7 @@ describe('html', function () {
await getNextBuild(b);

html = await outputFS.readFile(path.join(distDir, '/index.html'), 'utf8');
assert(html.includes(`console.log("foo")`));
assert(html.includes(`console.log('foo')`));
});

it('should invalidate parent bundle when nested inline bundles change', async function () {
Expand Down
16 changes: 8 additions & 8 deletions packages/core/integration-tests/test/incremental-bundling.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ console.log('adding a new console');`,
result.bundleGraph.getBundles()[0].filePath,
'utf8',
);
assert(contents.includes(`console.log("adding a new console")`));
assert(contents.includes(`console.log('adding a new console')`));
} finally {
if (subscription) {
await subscription.unsubscribe();
Expand Down Expand Up @@ -132,7 +132,7 @@ console.log('adding a new console');`,
result.bundleGraph.getBundles()[0].filePath,
'utf8',
);
assert(contents.includes(`console.log("adding a new console")`));
assert(contents.includes(`console.log('adding a new console')`));
} finally {
if (subscription) {
await subscription.unsubscribe();
Expand Down Expand Up @@ -174,7 +174,7 @@ console.log('adding a new console');`,
result.bundleGraph.getBundles()[0].filePath,
'utf8',
);
assert(contents.includes(`console.log("adding a new console")`));
assert(contents.includes(`console.log('adding a new console')`));
} finally {
if (subscription) {
await subscription.unsubscribe();
Expand Down Expand Up @@ -217,7 +217,7 @@ console.log(a);
'utf8',
);
assert(
contents.includes(`console.log("index.js - updated string");`),
contents.includes(`console.log('index.js - updated string');`),
);
} finally {
if (subscription) {
Expand Down Expand Up @@ -308,7 +308,7 @@ module.exports = a;`,
'utf8',
);

assert(contents.includes(`console.log("adding a new console")`));
assert(contents.includes(`console.log('adding a new console')`));

let bundleOutput = await run(result.bundleGraph);
assert.equal(bundleOutput, 'a updated');
Expand Down Expand Up @@ -404,7 +404,7 @@ console.log(a, 'updated');`,
'utf8',
);

assert(contents.includes(`console.log((0, _a.a), "updated");`));
assert(contents.includes(`console.log((0, _a.a), 'updated');`));

let bundleCSS = result.bundleGraph.getBundles()[1];
assert.equal(bundleCSS.type, 'css');
Expand Down Expand Up @@ -504,7 +504,7 @@ console.log(a);
'utf8',
);

assert(contents.includes(`console.log("index.js", (0, _b.b));`));
assert(contents.includes(`console.log('index.js', (0, _b.b));`));
} finally {
if (subscription) {
await subscription.unsubscribe();
Expand Down Expand Up @@ -612,7 +612,7 @@ console.log(a, b);
);
assert(
dynamicContent.includes(`parcelHelpers.export(exports, "b", ()=>b);
const b = "b";`),
const b = 'b';`),
);
} finally {
if (subscription) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const {foo} = {foo: 1};
export const [bar] = [2];
24 changes: 16 additions & 8 deletions packages/core/integration-tests/test/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -1109,8 +1109,8 @@ describe('javascript', function () {
let main = await outputFS.readFile(b.getBundles()[0].filePath, 'utf8');
dedicated = await outputFS.readFile(dedicated.filePath, 'utf8');
shared = await outputFS.readFile(shared.filePath, 'utf8');
assert(/new Worker(.*?, {[\n\s]+type: "module"[\n\s]+})/.test(main));
assert(/new SharedWorker(.*?, {[\n\s]+type: "module"[\n\s]+})/.test(main));
assert(/new Worker(.*?, {[\n\s]+type: 'module'[\n\s]+})/.test(main));
assert(/new SharedWorker(.*?, {[\n\s]+type: 'module'[\n\s]+})/.test(main));
});

for (let shouldScopeHoist of [true, false]) {
Expand Down Expand Up @@ -1263,8 +1263,8 @@ describe('javascript', function () {
);

let main = await outputFS.readFile(b.getBundles()[0].filePath, 'utf8');
assert(/new Worker(.*?, {[\n\s]+name: "worker"[\n\s]+})/.test(main));
assert(/new SharedWorker(.*?, {[\n\s]+name: "shared"[\n\s]+})/.test(main));
assert(/new Worker(.*?, {[\n\s]+name: 'worker'[\n\s]+})/.test(main));
assert(/new SharedWorker(.*?, {[\n\s]+name: 'shared'[\n\s]+})/.test(main));
});

it('should error if importing in a worker without type: module', async function () {
Expand Down Expand Up @@ -1463,7 +1463,7 @@ describe('javascript', function () {
]);

let res = await outputFS.readFile(b.getBundles()[0].filePath, 'utf8');
assert(res.includes(`importScripts("imported.js")`));
assert(res.includes(`importScripts('imported.js')`));
});

it('should ignore importScripts in script workers when not passed a string literal', async function () {
Expand Down Expand Up @@ -1509,7 +1509,7 @@ describe('javascript', function () {
]);

let res = await outputFS.readFile(b.getBundles()[1].filePath, 'utf8');
assert(res.includes(`importScripts("https://unpkg.com/parcel")`));
assert(res.includes(`importScripts('https://unpkg.com/parcel')`));
});

it('should support bundling service-workers', async function () {
Expand Down Expand Up @@ -1584,7 +1584,7 @@ describe('javascript', function () {
let main = bundles.find(b => !b.env.isWorker());
let mainContents = await outputFS.readFile(main.filePath, 'utf8');
assert(
/navigator.serviceWorker.register\(.*?, {[\n\s]*scope: "foo"[\n\s]*}\)/.test(
/navigator.serviceWorker.register\(.*?, {[\n\s]*scope: 'foo'[\n\s]*}\)/.test(
mainContents,
),
);
Expand Down Expand Up @@ -4386,7 +4386,7 @@ describe('javascript', function () {
let res = await run(b);
assert.equal(
res.default,
`<p>test</p>\n<script>console.log("hi");\n\n</script>\n`,
`<p>test</p>\n<script>console.log('hi');\n\n</script>\n`,
);
});

Expand Down Expand Up @@ -5238,6 +5238,14 @@ describe('javascript', function () {
assert.deepEqual(res, {ns: {a: 4, default: 1}});
});

it('should support export declarations with destructuring', async function () {
let b = await bundle(
path.join(__dirname, 'integration/js-export-destructuring/index.js'),
);
let res = await run(b);
assert.deepEqual(res, {foo: 1, bar: 2});
});

it('should support export default declarations', async function () {
let b = await bundle(
path.join(__dirname, 'integration/js-export-default/index.js'),
Expand Down
2 changes: 1 addition & 1 deletion packages/core/integration-tests/test/output-formats.js
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,7 @@ describe('output formats', function () {
.find(bundle => bundle.name.startsWith('async'));
assert(
new RegExp(
`getBundleURL\\("[a-zA-Z0-9]+"\\) \\+ "` +
`getBundleURL\\('[a-zA-Z0-9]+'\\) \\+ "` +
path.basename(asyncBundle.filePath) +
'"',
).test(entry),
Expand Down
10 changes: 5 additions & 5 deletions packages/core/integration-tests/test/sourcemaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -1258,7 +1258,7 @@ describe('sourcemaps', function () {
source: input,
generated: raw,
str: "console.log('foo')",
generatedStr: `console.log("foo")`,
generatedStr: `console.log('foo')`,
sourcePath,
});

Expand All @@ -1267,7 +1267,7 @@ describe('sourcemaps', function () {
source: input,
generated: raw,
str: "console.log('bar')",
generatedStr: `console.log("bar")`,
generatedStr: `console.log('bar')`,
sourcePath,
});

Expand All @@ -1276,7 +1276,7 @@ describe('sourcemaps', function () {
source: input,
generated: raw,
str: "console.log('baz')",
generatedStr: `console.log("baz")`,
generatedStr: `console.log('baz')`,
sourcePath,
});

Expand All @@ -1285,7 +1285,7 @@ describe('sourcemaps', function () {
source: input,
generated: raw,
str: "console.log('idhf')",
generatedStr: `console.log("idhf")`,
generatedStr: `console.log('idhf')`,
sourcePath,
});
});
Expand Down Expand Up @@ -1425,7 +1425,7 @@ describe('sourcemaps', function () {
source: sourceContent,
generated: raw,
str: `foo = 'Lorem ipsum`,
generatedStr: `foo = "Lorem ipsum`,
generatedStr: `foo = 'Lorem ipsum`,
sourcePath,
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/core/integration-tests/test/svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ describe('svg', function () {
),
);
assert(svg.includes('<script>'));
assert(svg.includes(`console.log("script")`));
assert(svg.includes(`console.log('script')`));
assert(!svg.includes('import '));
});

Expand Down
4 changes: 3 additions & 1 deletion packages/transformers/js/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
crate-type = ["rlib"]

[dependencies]
swc_core = { version = "0.89.6", features = [
swc_core = { version = "0.92.4", features = [
"common",
"common_ahash",
"common_sourcemap",
Expand All @@ -22,7 +22,9 @@ swc_core = { version = "0.89.6", features = [
"ecma_transforms_proposal",
"ecma_transforms_react",
"ecma_transforms_typescript",
"ecma_utils",
"ecma_visit",
"stacker"
] }
indoc = "1.0.3"
serde = "1.0.123"
Expand Down

0 comments on commit 43d5d19

Please sign in to comment.