Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
177e15b6
Unverified
Commit
177e15b6
authored
Nov 05, 2021
by
Tobias Koppers
Committed by
GitHub
Nov 05, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pass Buffer directly to Rust (#30975)
parent
bc19c2a5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
4 deletions
+24
-4
index.js
packages/next/build/swc/index.js
+2
-2
transform.rs
packages/next/build/swc/src/transform.rs
+19
-2
next-swc-loader.js
packages/next/build/webpack/loaders/next-swc-loader.js
+3
-0
No files found.
packages/next/build/swc/index.js
View file @
177e15b6
...
@@ -50,7 +50,7 @@ if (!bindings) {
...
@@ -50,7 +50,7 @@ if (!bindings) {
}
}
async
function
transform
(
src
,
options
)
{
async
function
transform
(
src
,
options
)
{
const
isModule
=
typeof
src
!==
'string'
const
isModule
=
typeof
src
!==
'string'
&&
!
Buffer
.
isBuffer
(
src
)
options
=
options
||
{}
options
=
options
||
{}
if
(
options
?.
jsc
?.
parser
)
{
if
(
options
?.
jsc
?.
parser
)
{
...
@@ -65,7 +65,7 @@ async function transform(src, options) {
...
@@ -65,7 +65,7 @@ async function transform(src, options) {
}
}
function
transformSync
(
src
,
options
)
{
function
transformSync
(
src
,
options
)
{
const
isModule
=
typeof
src
!==
'string'
const
isModule
=
typeof
src
!==
'string'
&&
!
Buffer
.
isBuffer
(
src
)
options
=
options
||
{}
options
=
options
||
{}
if
(
options
?.
jsc
?.
parser
)
{
if
(
options
?.
jsc
?.
parser
)
{
...
...
packages/next/build/swc/src/transform.rs
View file @
177e15b6
...
@@ -32,8 +32,9 @@ use crate::{
...
@@ -32,8 +32,9 @@ use crate::{
TransformOptions
,
TransformOptions
,
};
};
use
anyhow
::{
anyhow
,
Context
as
_
,
Error
};
use
anyhow
::{
anyhow
,
Context
as
_
,
Error
};
use
napi
::{
CallContext
,
Env
,
JsBoolean
,
Js
Object
,
JsString
,
Status
,
Task
};
use
napi
::{
CallContext
,
Env
,
JsBoolean
,
Js
Buffer
,
JsObject
,
JsString
,
JsUnknown
,
Status
,
Task
};
use
std
::{
use
std
::{
convert
::
TryFrom
,
panic
::{
catch_unwind
,
AssertUnwindSafe
},
panic
::{
catch_unwind
,
AssertUnwindSafe
},
sync
::
Arc
,
sync
::
Arc
,
};
};
...
@@ -117,7 +118,23 @@ where
...
@@ -117,7 +118,23 @@ where
{
{
let
c
=
get_compiler
(
&
cx
);
let
c
=
get_compiler
(
&
cx
);
let
src
=
cx
.get
::
<
JsString
>
(
0
)
?
.into_utf8
()
?
.as_str
()
?
.to_owned
();
let
unknown_src
=
cx
.get
::
<
JsUnknown
>
(
0
)
?
;
let
src
=
match
unknown_src
.get_type
()
?
{
napi
::
ValueType
::
String
=>
napi
::
Result
::
Ok
(
JsString
::
try_from
(
unknown_src
)
?
.into_utf8
()
?
.as_str
()
?
.to_owned
(),
),
napi
::
ValueType
::
Object
=>
napi
::
Result
::
Ok
(
String
::
from_utf8_lossy
(
JsBuffer
::
try_from
(
unknown_src
)
?
.into_value
()
?
.as_ref
())
.to_string
(),
),
_
=>
Err
(
napi
::
Error
::
new
(
Status
::
GenericFailure
,
"first argument must be a String or Buffer"
.to_string
(),
)),
}
?
;
let
is_module
=
cx
.get
::
<
JsBoolean
>
(
1
)
?
;
let
is_module
=
cx
.get
::
<
JsBoolean
>
(
1
)
?
;
let
options
=
cx
.get_buffer_as_string
(
2
)
?
;
let
options
=
cx
.get_buffer_as_string
(
2
)
?
;
...
...
packages/next/build/webpack/loaders/next-swc-loader.js
View file @
177e15b6
...
@@ -191,3 +191,6 @@ export default function swcLoader(inputSource, inputSourceMap) {
...
@@ -191,3 +191,6 @@ export default function swcLoader(inputSource, inputSourceMap) {
}
}
)
)
}
}
// accept Buffers instead of strings
export
const
raw
=
true
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment