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
112589e2
Commit
112589e2
authored
Sep 28, 2022
by
Donny/강동윤
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix
parent
fbf1bd11
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
129 additions
and
120 deletions
+129
-120
minify.rs
packages/next-swc/crates/napi/src/minify.rs
+13
-11
parse.rs
packages/next-swc/crates/napi/src/parse.rs
+38
-33
transform.rs
packages/next-swc/crates/napi/src/transform.rs
+78
-76
No files found.
packages/next-swc/crates/napi/src/minify.rs
View file @
112589e2
...
@@ -35,7 +35,7 @@ use serde::Deserialize;
...
@@ -35,7 +35,7 @@ use serde::Deserialize;
use
std
::
sync
::
Arc
;
use
std
::
sync
::
Arc
;
use
swc_core
::{
use
swc_core
::{
base
::{
config
::
JsMinifyOptions
,
try_with_handler
,
TransformOutput
},
base
::{
config
::
JsMinifyOptions
,
try_with_handler
,
TransformOutput
},
common
::{
errors
::
ColorConfig
,
sync
::
Lrc
,
FileName
,
SourceFile
,
SourceMap
},
common
::{
errors
::
ColorConfig
,
sync
::
Lrc
,
FileName
,
SourceFile
,
SourceMap
,
GLOBALS
},
};
};
struct
MinifyTask
{
struct
MinifyTask
{
...
@@ -85,6 +85,7 @@ impl Task for MinifyTask {
...
@@ -85,6 +85,7 @@ impl Task for MinifyTask {
skip_filename
:
true
,
skip_filename
:
true
,
},
},
|
handler
|
{
|
handler
|
{
GLOBALS
.set
(
&
Default
::
default
(),
||
{
let
fm
=
self
.code
.to_file
(
self
.c.cm
.clone
());
let
fm
=
self
.code
.to_file
(
self
.c.cm
.clone
());
self
.c
.minify
(
self
.c
.minify
(
...
@@ -94,6 +95,7 @@ impl Task for MinifyTask {
...
@@ -94,6 +95,7 @@ impl Task for MinifyTask {
..
self
.opts
.clone
()
..
self
.opts
.clone
()
},
},
)
)
})
},
},
)
)
.convert_err
()
.convert_err
()
...
@@ -131,7 +133,7 @@ pub fn minify_sync(cx: CallContext) -> napi::Result<JsObject> {
...
@@ -131,7 +133,7 @@ pub fn minify_sync(cx: CallContext) -> napi::Result<JsObject> {
color
:
ColorConfig
::
Never
,
color
:
ColorConfig
::
Never
,
skip_filename
:
true
,
skip_filename
:
true
,
},
},
|
handler
|
c
.minify
(
fm
,
handler
,
&
opts
),
|
handler
|
GLOBALS
.set
(
&
Default
::
default
(),
||
c
.minify
(
fm
,
handler
,
&
opts
)
),
)
)
.convert_err
()
?
;
.convert_err
()
?
;
...
...
packages/next-swc/crates/napi/src/parse.rs
View file @
112589e2
...
@@ -4,7 +4,9 @@ use napi::{CallContext, Either, Env, JsObject, JsString, JsUndefined, Task};
...
@@ -4,7 +4,9 @@ use napi::{CallContext, Either, Env, JsObject, JsString, JsUndefined, Task};
use
std
::
sync
::
Arc
;
use
std
::
sync
::
Arc
;
use
swc_core
::{
use
swc_core
::{
base
::{
config
::
ParseOptions
,
try_with_handler
},
base
::{
config
::
ParseOptions
,
try_with_handler
},
common
::{
comments
::
Comments
,
errors
::
ColorConfig
,
FileName
,
FilePathMapping
,
SourceMap
},
common
::{
comments
::
Comments
,
errors
::
ColorConfig
,
FileName
,
FilePathMapping
,
SourceMap
,
GLOBALS
,
},
};
};
pub
struct
ParseTask
{
pub
struct
ParseTask
{
...
@@ -22,7 +24,9 @@ impl Task for ParseTask {
...
@@ -22,7 +24,9 @@ impl Task for ParseTask {
type
JsValue
=
JsString
;
type
JsValue
=
JsString
;
fn
compute
(
&
mut
self
)
->
napi
::
Result
<
Self
::
Output
>
{
fn
compute
(
&
mut
self
)
->
napi
::
Result
<
Self
::
Output
>
{
let
c
=
swc_core
::
base
::
Compiler
::
new
(
Arc
::
new
(
SourceMap
::
new
(
FilePathMapping
::
empty
())));
GLOBALS
.set
(
&
Default
::
default
(),
||
{
let
c
=
swc_core
::
base
::
Compiler
::
new
(
Arc
::
new
(
SourceMap
::
new
(
FilePathMapping
::
empty
())));
let
options
:
ParseOptions
=
deserialize_json
(
&
self
.options
)
.convert_err
()
?
;
let
options
:
ParseOptions
=
deserialize_json
(
&
self
.options
)
.convert_err
()
?
;
let
comments
=
c
.comments
()
.clone
();
let
comments
=
c
.comments
()
.clone
();
...
@@ -57,6 +61,7 @@ impl Task for ParseTask {
...
@@ -57,6 +61,7 @@ impl Task for ParseTask {
.convert_err
()
?
;
.convert_err
()
?
;
Ok
(
ast_json
)
Ok
(
ast_json
)
})
}
}
fn
resolve
(
self
,
env
:
Env
,
result
:
Self
::
Output
)
->
napi
::
Result
<
Self
::
JsValue
>
{
fn
resolve
(
self
,
env
:
Env
,
result
:
Self
::
Output
)
->
napi
::
Result
<
Self
::
JsValue
>
{
...
...
packages/next-swc/crates/napi/src/transform.rs
View file @
112589e2
...
@@ -44,7 +44,7 @@ use std::{
...
@@ -44,7 +44,7 @@ use std::{
};
};
use
swc_core
::{
use
swc_core
::{
base
::{
try_with_handler
,
Compiler
,
TransformOutput
},
base
::{
try_with_handler
,
Compiler
,
TransformOutput
},
common
::{
errors
::
ColorConfig
,
FileName
},
common
::{
errors
::
ColorConfig
,
FileName
,
GLOBALS
},
ecma
::
transforms
::
base
::
pass
::
noop
,
ecma
::
transforms
::
base
::
pass
::
noop
,
};
};
...
@@ -68,6 +68,7 @@ impl Task for TransformTask {
...
@@ -68,6 +68,7 @@ impl Task for TransformTask {
type
JsValue
=
JsObject
;
type
JsValue
=
JsObject
;
fn
compute
(
&
mut
self
)
->
napi
::
Result
<
Self
::
Output
>
{
fn
compute
(
&
mut
self
)
->
napi
::
Result
<
Self
::
Output
>
{
GLOBALS
.set
(
&
Default
::
default
(),
||
{
let
eliminated_packages
:
Rc
<
RefCell
<
fxhash
::
FxHashSet
<
String
>>>
=
Default
::
default
();
let
eliminated_packages
:
Rc
<
RefCell
<
fxhash
::
FxHashSet
<
String
>>>
=
Default
::
default
();
let
res
=
catch_unwind
(
AssertUnwindSafe
(||
{
let
res
=
catch_unwind
(
AssertUnwindSafe
(||
{
try_with_handler
(
try_with_handler
(
...
@@ -145,6 +146,7 @@ impl Task for TransformTask {
...
@@ -145,6 +146,7 @@ impl Task for TransformTask {
format!
(
"{:?}"
,
err
),
format!
(
"{:?}"
,
err
),
)),
)),
}
}
})
}
}
fn
resolve
(
fn
resolve
(
...
...
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