Unverified Commit 43d09ce2 authored by Maia Teegarden's avatar Maia Teegarden Committed by GitHub

Update swc_core to `v0.75.23` (#48098)

Depends on https://github.com/vercel/turbo/pull/4470

---

 - Closes https://github.com/vercel/next.js/issues/46989
 - Fixes WEB-879
 - Fixes WEB-813

---------
Co-authored-by: 's avatarOJ Kwon <1210596+kwonoj@users.noreply.github.com>
Co-authored-by: 's avatarDonny/강동윤 <kdy1997.dev@gmail.com>
Co-authored-by: 's avatarShu Ding <g@shud.in>
parent 9c910101
......@@ -77,8 +77,8 @@
"@opentelemetry/api": "1.4.1",
"@svgr/webpack": "5.5.0",
"@swc/cli": "0.1.55",
"@swc/core": "1.2.203",
"@swc/helpers": "0.4.14",
"@swc/core": "1.3.51",
"@swc/helpers": "0.5.0",
"@testing-library/react": "13.0.0",
"@types/cheerio": "0.22.16",
"@types/fs-extra": "8.1.0",
......
This diff is collapsed.
......@@ -37,21 +37,16 @@ next-transform-strip-page-exports = { path = "crates/next-transform-strip-page-e
# SWC crates
# Keep consistent with preset_env_base through swc_core
browserslist-rs = { version = "0.12.2" }
mdxjs = { version = "0.1.8" }
modularize_imports = { version = "0.26.10" }
styled_components = { version = "0.53.10" }
styled_jsx = { version = "0.30.10" }
swc_core = { version = "0.69.6" }
swc_emotion = { version = "0.29.10" }
testing = { version = "0.31.31" }
swc_core = { version = "0.75.15" }
swc_relay = { version = "0.2.5" }
testing = { version = "0.33.3" }
# Turbo crates
turbo-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230417.2" }
turbo-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230418.1" }
# [TODO]: need to refactor embed_directory! macro usages, as well as resolving turbo_tasks::function, macros..
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230417.2" }
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230418.1" }
# [TODO]: need to refactor embed_directory! macro usage in next-core
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230417.2" }
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230418.1" }
# General Deps
......
......@@ -14,7 +14,7 @@ either = "1"
fxhash = "0.2.1"
hex = "0.4.3"
once_cell = { workspace = true }
next-transform-font = {"workspace" = true}
next-transform-font = {workspace = true}
pathdiff = "0.2.0"
regex = "1.5"
serde = "1"
......@@ -31,7 +31,7 @@ turbo-binding = { workspace = true, features = [
"__swc_transform_modularize_imports",
"__swc_transform_relay",
] }
swc_relay = "0.1.0"
swc_relay = { workspace = true }
[dev-dependencies]
turbo-binding = { workspace = true, features = [
......
......@@ -249,6 +249,7 @@ where
turbo_binding::swc::custom_transform::emotion::EmotionTransformer::new(
config.clone(),
path,
file.src_hash as u32,
cm,
comments.clone(),
),
......
......@@ -62,17 +62,20 @@ impl<C: Comments> VisitMut for ReactServerComponents<C> {
fn visit_mut_module(&mut self, module: &mut Module) {
let (is_client_entry, imports) = self.collect_top_level_directives_and_imports(module);
let is_cjs = contains_cjs(module);
if self.is_server {
if !is_client_entry {
self.assert_server_graph(&imports, module);
} else {
let is_cjs = contains_cjs(module);
self.to_module_ref(module, is_cjs);
return;
}
} else {
self.assert_client_graph(&imports, module);
if is_client_entry {
self.prepend_comment_node(module, is_cjs);
}
}
module.visit_mut_children_with(self)
}
......@@ -289,21 +292,7 @@ impl<C: Comments> ReactServerComponents<C> {
.into_iter(),
);
// Prepend a special comment to the top of the file that contains
// module export names and the detected module type.
self.comments.add_leading(
module.span.lo,
Comment {
span: DUMMY_SP,
kind: CommentKind::Block,
text: format!(
" __next_internal_client_entry_do_not_use__ {} {} ",
self.export_names.join(","),
if is_cjs { "cjs" } else { "auto" }
)
.into(),
},
);
self.prepend_comment_node(module, is_cjs);
}
fn assert_server_graph(&self, imports: &[ModuleImports], module: &Module) {
......@@ -509,6 +498,24 @@ impl<C: Comments> ReactServerComponents<C> {
}
}
}
fn prepend_comment_node(&self, module: &Module, is_cjs: bool) {
// Prepend a special comment to the top of the file that contains
// module export names and the detected module type.
self.comments.add_leading(
module.span.lo,
Comment {
span: DUMMY_SP,
kind: CommentKind::Block,
text: format!(
" __next_internal_client_entry_do_not_use__ {} {} ",
self.export_names.join(","),
if is_cjs { "cjs" } else { "auto" }
)
.into(),
},
);
}
}
pub fn server_components<C: Comments>(
......
......@@ -106,6 +106,7 @@ fn next_ssg_fixture(input: PathBuf) {
syntax(),
&|tr| {
let top_level_mark = Mark::fresh(Mark::root());
let unresolved_mark = Mark::fresh(Mark::root());
let jsx = jsx::<SingleThreadedComments>(
tr.cm.clone(),
None,
......@@ -121,8 +122,13 @@ fn next_ssg_fixture(input: PathBuf) {
..Default::default()
},
top_level_mark,
unresolved_mark,
);
chain!(next_ssg(Default::default()), jsx)
chain!(
resolver(unresolved_mark, top_level_mark, true),
next_ssg(Default::default()),
jsx
)
},
&input,
&output,
......
import dynamic from 'next/dynamic'
export const NextDynamicNoSSRServerComponent = dynamic(
() => import('../text-dynamic-no-ssr-server'),
{
ssr: false,
}
)
import dynamic from 'next/dynamic';
export const NextDynamicNoSSRServerComponent = dynamic(()=>import('../text-dynamic-no-ssr-server'), {
loadableGenerated: {
modules: [
"some-file.js -> " + "../text-dynamic-no-ssr-server"
]
},
ssr: false
});
import dynamic from 'next/dynamic';
export const NextDynamicNoSSRServerComponent = dynamic(()=>import('../text-dynamic-no-ssr-server'), {
loadableGenerated: {
webpack: ()=>[
require.resolveWeak("../text-dynamic-no-ssr-server")
]
},
ssr: false
});
import dynamic from 'next/dynamic';
export const NextDynamicNoSSRServerComponent = dynamic(null, {
loadableGenerated: {
modules: [
"some-file.js -> " + "../text-dynamic-no-ssr-server"
]
},
ssr: false
});
// This is a comment.
"use strict";
/* __next_internal_client_entry_do_not_use__ default auto */ "use strict";
// This is a comment.
"foo";
import "fs";
......
function _arrayLikeToArray(arr, len) {
function _array_like_to_array(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
return arr2;
}
function _arrayWithHoles(arr) {
function _array_with_holes(arr) {
if (Array.isArray(arr)) return arr;
}
function _classCallCheck(instance, Constructor) {
function _class_call_check(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
function _iterableToArrayLimit(arr, i) {
function _iterable_to_array_limit(arr, i) {
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
if (_i == null) return;
var _arr = [];
......@@ -35,25 +35,25 @@ function _iterableToArrayLimit(arr, i) {
}
return _arr;
}
function _nonIterableRest() {
function _non_iterable_rest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _slicedToArray(arr, i) {
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
function _sliced_to_array(arr, i) {
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
}
function _unsupportedIterableToArray(o, minLen) {
function _unsupported_iterable_to_array(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
if (typeof o === "string") return _array_like_to_array(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(n);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
}
import other from "other";
var _other = _slicedToArray(other, 1), foo = _other[0];
var _other = _sliced_to_array(other, 1), foo = _other[0];
var Foo = function Foo() {
"use strict";
_classCallCheck(this, Foo);
_class_call_check(this, Foo);
};
export var __N_SSG = true;
export default function Home() {
......
function _classCallCheck(instance, Constructor) {
function _class_call_check(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
......@@ -17,7 +17,7 @@ export default function Home() {
}
var MyClass = function MyClass() {
"use strict";
_classCallCheck(this, MyClass);
_class_call_check(this, MyClass);
selectAll(".group").each(function() {
select(this).selectAll("path");
});
......
function _taggedTemplateLiteral(strings, raw) {
function _tagged_template_literal(strings, raw) {
if (!raw) {
raw = strings.slice(0);
}
......@@ -9,7 +9,7 @@ function _taggedTemplateLiteral(strings, raw) {
}));
}
function _templateObject() {
var data = _taggedTemplateLiteral([
var data = _tagged_template_literal([
"\n color: red;\n"
]);
_templateObject = function _templateObject() {
......
......@@ -10,8 +10,8 @@
"check": "tsc --noEmit"
},
"dependencies": {
"@vercel/turbopack-dev": "https://gitpkg.vercel.app/vercel/turbo/crates/turbopack-dev/js?turbopack-230417.2",
"@vercel/turbopack-node": "https://gitpkg.vercel.app/vercel/turbo/crates/turbopack-node/js?turbopack-230417.2",
"@vercel/turbopack-dev": "https://gitpkg.vercel.app/vercel/turbo/crates/turbopack-dev/js?turbopack-230418.1",
"@vercel/turbopack-node": "https://gitpkg.vercel.app/vercel/turbo/crates/turbopack-node/js?turbopack-230418.1",
"anser": "^2.1.1",
"css.escape": "^1.5.1",
"next": "*",
......
......@@ -25,6 +25,7 @@ fn run_test(input: &Path, output: &Path, mode: ExportFilter) {
syntax(),
&|tr| {
let top_level_mark = Mark::fresh(Mark::root());
let unresolved_mark = Mark::fresh(Mark::root());
let jsx = jsx::<SingleThreadedComments>(
tr.cm.clone(),
None,
......@@ -39,8 +40,10 @@ fn run_test(input: &Path, output: &Path, mode: ExportFilter) {
..Default::default()
},
top_level_mark,
unresolved_mark,
);
chain!(
swc_core::ecma::transforms::base::resolver(unresolved_mark, top_level_mark, true),
next_transform_strip_page_exports(mode, Default::default()),
jsx
)
......
......@@ -35,6 +35,7 @@ turbo-binding = { workspace = true, features = [
"__swc_core_binding_wasm",
"__feature_mdx_rs",
] }
swc_core = { workspace = true, features = ["ecma_ast_serde", "common"] }
# Workaround a bug
......
......@@ -83,7 +83,7 @@
},
"dependencies": {
"@next/env": "13.3.1-canary.11",
"@swc/helpers": "0.4.14",
"@swc/helpers": "0.5.0",
"busboy": "1.6.0",
"caniuse-lite": "^1.0.30001406",
"postcss": "8.4.14",
......
......@@ -52,20 +52,22 @@ export function getRSCModuleInformation(
isServerLayer = true
): RSCMeta {
const actions = source.match(ACTION_MODULE_LABEL)?.[1]?.split(',')
const clientInfoMatch = source.match(CLIENT_MODULE_LABEL)
const isClientRef = !!clientInfoMatch
if (!isServerLayer) {
return {
type: RSC_MODULE_TYPES.client,
actions,
isClientRef,
}
}
const clientInfoMatch = source.match(CLIENT_MODULE_LABEL)
const clientRefs = clientInfoMatch?.[1]?.split(',')
const clientEntryType = clientInfoMatch?.[2] as 'cjs' | 'auto'
const type = clientRefs ? RSC_MODULE_TYPES.client : RSC_MODULE_TYPES.server
return { type, actions, clientRefs, clientEntryType }
return { type, actions, clientRefs, clientEntryType, isClientRef }
}
/**
......
......@@ -1715,7 +1715,7 @@ export default async function getBaseWebpackConfig(
'next-flight-loader',
'next-flight-client-entry-loader',
'next-flight-action-entry-loader',
'next-flight-client-action-loader',
'next-flight-client-module-loader',
'noop-loader',
'next-middleware-loader',
'next-edge-function-loader',
......@@ -1939,7 +1939,9 @@ export default async function getBaseWebpackConfig(
]
: []),
{
loader: 'next-flight-client-action-loader',
// This loader handles actions and client entries
// in the client layer.
loader: 'next-flight-client-module-loader',
},
...swcLoaderForClientLayer,
],
......
......@@ -29,6 +29,7 @@ export interface RSCMeta {
actions?: string[]
clientRefs?: string[]
clientEntryType?: 'cjs' | 'auto'
isClientRef?: boolean
requests?: string[] // client requests in flight client entry
}
......
import { getRSCModuleInformation } from './../../analysis/get-page-static-info'
import { getRSCModuleInformation } from '../../analysis/get-page-static-info'
import { getModuleBuildInfo } from './get-module-build-info'
export default async function transformSource(
......@@ -17,6 +17,25 @@ export default async function transformSource(
const buildInfo = getModuleBuildInfo(this._module)
buildInfo.rsc = getRSCModuleInformation(source, false)
if (buildInfo.rsc.isClientRef) {
// In case the client entry is a CJS module, we need to parse all the exports
// to make sure that the flight manifest plugin can correctly generate the
// manifest.
// TODO: Currently SWC wraps CJS exports with `_export(exports, { ... })`,
// which is tricky to statically analyze. But since the shape is known, we
// use a regex to extract the exports as a workaround. See:
// https://github.com/swc-project/swc/blob/5629e6b5291b416c8316587b67b5e83d011a8c22/crates/swc_ecma_transforms_module/src/util.rs#L295
const matchExportObject = source.match(/\n_export\(exports, {([.\s\S]+)}/m)
if (matchExportObject) {
const matches: string[] = []
const matchExports = matchExportObject[1].matchAll(/([^\s]+):/g)
for (const match of matchExports) {
matches.push(match[1])
}
buildInfo.rsc.clientRefs = matches
}
}
// This is a server action entry module in the client layer. We need to attach
// noop exports of `callServer` wrappers for each action.
if (buildInfo.rsc?.actions) {
......
......@@ -242,7 +242,10 @@ export class ClientReferenceManifestPlugin {
}
return null
}),
].flat()
...(mod.buildInfo.rsc?.clientRefs || []),
]
.filter(Boolean)
.flat()
),
]
......
......@@ -287,7 +287,7 @@ export async function startServer({
handlersReady()
} else {
// when not using a worker start next in main process
const { default: next } = require('../next') as typeof import('../next')
const next = require('../next') as typeof import('../next').default
const addr = server.address()
const app = next({
dir,
......
......@@ -249,7 +249,7 @@ function createServer(options: NextServerOptions): NextServer {
// Support commonjs `require('next')`
module.exports = createServer
exports = module.exports
// exports = module.exports
// Support `import next from 'next'`
export default createServer
......@@ -199,7 +199,7 @@ async function postProcessHTML(
: null,
process.env.NEXT_RUNTIME !== 'edge' && renderOpts.optimizeFonts
? async (html: string) => {
const getFontDefinition = (url: string): string => {
const getFontDefinition = (url: string) => {
if (renderOpts.fontManifest) {
const { getFontDefinitionFromManifest } =
require('./font-utils') as typeof import('./font-utils')
......
This diff is collapsed.
......@@ -9,12 +9,12 @@ describe('handle-non-hoisted-swc-helpers', () => {
next = await createNext({
files: {
'pages/index.js': `
export default function Page() {
export default function Page() {
return <p>hello world</p>
}
}
export function getServerSideProps() {
const helper = require('@swc/helpers/lib/_object_spread.js')
const helper = require('@swc/helpers/_/_object_spread')
console.log(helper)
return {
props: {
......
import { createNext } from 'e2e-utils'
import { NextConfig } from 'packages/next'
import { NextInstance } from 'test/lib/next-modes/base'
describe('ES Check .next output', () => {
......@@ -23,29 +22,4 @@ describe('ES Check .next output', () => {
'info: ES-Check: there were no ES version matching errors! 🎉'
)
})
it('should emit ES5 with legacyBrowsers: true', async () => {
const nextConfig: NextConfig = {
experimental: {
legacyBrowsers: true,
},
}
next = await createNext({
files: {
'pages/index.js': 'export default function Page() { return "hi" }',
'next.config.js': `module.exports = ${JSON.stringify(nextConfig)}`,
},
dependencies: { 'es-check': '7.0.1' },
packageJson: {
scripts: {
build: 'next build && es-check es5 .next/static/**/*.js',
},
},
buildCommand: 'yarn build',
})
expect(next.cliOutput).toContain(
'info: ES-Check: there were no ES version matching errors! 🎉'
)
})
})
......@@ -19,15 +19,15 @@ describe('next/swc', () => {
)
expect(output).toMatchInlineSnapshot(`
"function _arrayLikeToArray(arr, len) {
"function _array_like_to_array(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
return arr2;
}
function _arrayWithHoles(arr) {
function _array_with_holes(arr) {
if (Array.isArray(arr)) return arr;
}
function _iterableToArrayLimit(arr, i) {
function _iterable_to_array_limit(arr, i) {
var _i = arr == null ? null : typeof Symbol !== \\"undefined\\" && arr[Symbol.iterator] || arr[\\"@@iterator\\"];
if (_i == null) return;
var _arr = [];
......@@ -51,22 +51,22 @@ describe('next/swc', () => {
}
return _arr;
}
function _nonIterableRest() {
function _non_iterable_rest() {
throw new TypeError(\\"Invalid attempt to destructure non-iterable instance.\\\\\\\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\\");
}
function _slicedToArray(arr, i) {
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
function _sliced_to_array(arr, i) {
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
}
function _unsupportedIterableToArray(o, minLen) {
function _unsupported_iterable_to_array(o, minLen) {
if (!o) return;
if (typeof o === \\"string\\") return _arrayLikeToArray(o, minLen);
if (typeof o === \\"string\\") return _array_like_to_array(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === \\"Object\\" && o.constructor) n = o.constructor.name;
if (n === \\"Map\\" || n === \\"Set\\") return Array.from(n);
if (n === \\"Arguments\\" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
if (n === \\"Arguments\\" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
}
import { useState } from \\"react\\";
var _useState = _slicedToArray(useState(0), 2), count = _useState[0], setCount = _useState[1];
var _useState = _sliced_to_array(useState(0), 2), count = _useState[0], setCount = _useState[1];
"
`)
})
......@@ -80,33 +80,33 @@ describe('next/swc', () => {
)
expect(output).toMatchInlineSnapshot(`
"function _arrayLikeToArray(arr, len) {
"function _array_like_to_array(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
return arr2;
}
function _arrayWithHoles(arr) {
function _array_with_holes(arr) {
if (Array.isArray(arr)) return arr;
}
function _iterableToArray(iter) {
function _iterable_to_array(iter) {
if (typeof Symbol !== \\"undefined\\" && iter[Symbol.iterator] != null || iter[\\"@@iterator\\"] != null) return Array.from(iter);
}
function _nonIterableRest() {
function _non_iterable_rest() {
throw new TypeError(\\"Invalid attempt to destructure non-iterable instance.\\\\\\\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\\");
}
function _toArray(arr) {
return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest();
function _to_array(arr) {
return _array_with_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_rest();
}
function _unsupportedIterableToArray(o, minLen) {
function _unsupported_iterable_to_array(o, minLen) {
if (!o) return;
if (typeof o === \\"string\\") return _arrayLikeToArray(o, minLen);
if (typeof o === \\"string\\") return _array_like_to_array(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === \\"Object\\" && o.constructor) n = o.constructor.name;
if (n === \\"Map\\" || n === \\"Set\\") return Array.from(n);
if (n === \\"Arguments\\" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
if (n === \\"Arguments\\" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
}
import { useState } from \\"react\\";
var _useState = _toArray(useState(0)), copy = _useState.slice(0);
var _useState = _to_array(useState(0)), copy = _useState.slice(0);
"
`)
})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment