Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(es/ast): Properly box variants #9158

Closed
wants to merge 121 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
121 commits
Select commit Hold shift + click to select a range
984d0e6
refactor(common): Drop `SyntaxContext` from AST nodes (#9175)
kdy1 Jul 9, 2024
5e723ec
pers(es/ast): Introduce `IdentName` (#9185)
kdy1 Jul 10, 2024
355f4f8
chore: Fix for the rebase
kdy1 Jul 10, 2024
728417c
refactor(es): Use `into` for AST construction (#9197)
kdy1 Jul 10, 2024
28b6369
refactor(es): Use `Into` and `From` for AST construction (#9201)
kdy1 Jul 11, 2024
8ea2280
Replace
kdy1 Jul 9, 2024
4e51964
Box variants of expr
kdy1 Jul 9, 2024
4e74fa5
Decl
kdy1 Jul 9, 2024
133ebd8
Box more
kdy1 Jul 9, 2024
c55ef47
Box more
kdy1 Jul 9, 2024
f2059c9
Box more
kdy1 Jul 9, 2024
1011bbf
Box more
kdy1 Jul 9, 2024
e3ff10d
Fix
kdy1 Jul 9, 2024
46fa576
box more
kdy1 Jul 9, 2024
e788e86
Fix ast
kdy1 Jul 9, 2024
c10ec76
Fix ast
kdy1 Jul 9, 2024
f163ebf
Fix ast
kdy1 Jul 9, 2024
254ead8
Fix ast
kdy1 Jul 9, 2024
26292c9
Fix ast
kdy1 Jul 9, 2024
6a92ad5
Fix ast
kdy1 Jul 9, 2024
b72020c
Fix ast
kdy1 Jul 9, 2024
c9def60
Fix ast
kdy1 Jul 9, 2024
40aaf04
bridge_decl_from
kdy1 Jul 9, 2024
8badf51
bridge_decl_from
kdy1 Jul 9, 2024
cae14c8
Fix ast
kdy1 Jul 9, 2024
d18001d
Fix ast
kdy1 Jul 9, 2024
5511200
Fix more
kdy1 Jul 9, 2024
16f6cb2
Fix more
kdy1 Jul 9, 2024
bc60bc6
Fix more
kdy1 Jul 9, 2024
9479194
Fix more
kdy1 Jul 9, 2024
ac4fea5
Fix more
kdy1 Jul 9, 2024
8ff1122
Fix more
kdy1 Jul 9, 2024
6d2902f
More from impl
kdy1 Jul 9, 2024
cba664b
More from impl
kdy1 Jul 9, 2024
075a4c5
More fix
kdy1 Jul 9, 2024
67faed0
More fix
kdy1 Jul 9, 2024
65152d6
More fix
kdy1 Jul 9, 2024
b9e900a
Box more
kdy1 Jul 9, 2024
3c87cb2
More fix
kdy1 Jul 9, 2024
242711d
More fix
kdy1 Jul 9, 2024
38f712a
More fix
kdy1 Jul 9, 2024
be85738
More fix
kdy1 Jul 9, 2024
6d6849d
More fix
kdy1 Jul 9, 2024
5be868f
More fix
kdy1 Jul 9, 2024
3ed14d6
More fix
kdy1 Jul 9, 2024
41bc569
ast-grep
kdy1 Jul 9, 2024
9065649
More from impl
kdy1 Jul 9, 2024
6e3e0c1
More fix
kdy1 Jul 9, 2024
8828da1
More fix
kdy1 Jul 9, 2024
60e09f6
ast-grep
kdy1 Jul 9, 2024
b3e4631
.into().into()
kdy1 Jul 9, 2024
cfec11d
Fix ast
kdy1 Jul 9, 2024
f275a29
More fix
kdy1 Jul 9, 2024
a4301b4
More fix
kdy1 Jul 9, 2024
444aeee
ast-grep
kdy1 Jul 9, 2024
e120d9e
into into
kdy1 Jul 9, 2024
356ee79
visitor fix
kdy1 Jul 9, 2024
d22ac7c
Fix visitor
kdy1 Jul 9, 2024
b68d261
Unbox UnaryExpr.arg
kdy1 Jul 9, 2024
14c5664
Fix visitor
kdy1 Jul 9, 2024
8cd4881
Fix more
kdy1 Jul 9, 2024
e09bcdc
More from impl
kdy1 Jul 9, 2024
829deef
More fix
kdy1 Jul 9, 2024
2e6de04
More fix
kdy1 Jul 9, 2024
4d6a162
More fix
kdy1 Jul 9, 2024
a0c5f56
Box more
kdy1 Jul 9, 2024
962b0b3
More fix
kdy1 Jul 9, 2024
a1899a9
More fix
kdy1 Jul 9, 2024
29cc14a
More fix
kdy1 Jul 9, 2024
7c1ca2a
More fix
kdy1 Jul 9, 2024
fcc4dfd
More fix
kdy1 Jul 9, 2024
67d7d0b
More fix
kdy1 Jul 9, 2024
5f4a65d
More fix
kdy1 Jul 9, 2024
6b27775
Box more
kdy1 Jul 9, 2024
f741a53
Box more
kdy1 Jul 9, 2024
438e378
Box more
kdy1 Jul 9, 2024
ff44752
More fix
kdy1 Jul 9, 2024
9c63989
More fix
kdy1 Jul 9, 2024
8704c3d
Unbox pat
kdy1 Jul 9, 2024
29ade6c
Fix ast
kdy1 Jul 9, 2024
e2602e5
Fix ast
kdy1 Jul 9, 2024
71065f3
Fix more
kdy1 Jul 9, 2024
40d1cfd
Box more
kdy1 Jul 9, 2024
5c1c180
Fix more
kdy1 Jul 9, 2024
2ca8113
Fix more
kdy1 Jul 9, 2024
197d281
Fix more
kdy1 Jul 9, 2024
6dea15d
Fix more
kdy1 Jul 9, 2024
27cd88f
Fix more
kdy1 Jul 9, 2024
12d4d1b
Fix more
kdy1 Jul 9, 2024
f931162
Unbox `Lit`
kdy1 Jul 9, 2024
ed43246
fix AST
kdy1 Jul 10, 2024
e14ce24
Revert for rebase
kdy1 Jul 10, 2024
7a3e3a7
Fix more
kdy1 Jul 10, 2024
36142ac
Fix more
kdy1 Jul 10, 2024
e456114
Fix more
kdy1 Jul 10, 2024
ed47a04
Fix boxing
kdy1 Jul 10, 2024
4bced00
Fix more
kdy1 Jul 10, 2024
401bc54
More from impl
kdy1 Jul 10, 2024
686b52b
Fix more
kdy1 Jul 10, 2024
c4815c8
Fix more
kdy1 Jul 10, 2024
bc4b423
Fix more
kdy1 Jul 10, 2024
df2eaab
Add `Stmt::Directive`
kdy1 Jul 10, 2024
3cd9d10
re-export
kdy1 Jul 10, 2024
30ecf0e
Fix codegen
kdy1 Jul 10, 2024
00a74dc
Fix visitor
kdy1 Jul 10, 2024
4d555ea
Fix more
kdy1 Jul 10, 2024
2dd10e5
Revert for rebase
kdy1 Jul 10, 2024
53f2674
Revert for rebase
kdy1 Jul 10, 2024
a63761e
box patterns
kdy1 Jul 10, 2024
83c2885
Fix more
kdy1 Jul 10, 2024
6a8873b
Revert
kdy1 Jul 10, 2024
53de448
fixup for rebase
kdy1 Jul 10, 2024
8ad20eb
into into
kdy1 Jul 10, 2024
e8394fe
Revert for rebase
kdy1 Jul 10, 2024
85b876e
fixup
kdy1 Jul 10, 2024
0ebd9a9
Fix AST
kdy1 Jul 11, 2024
b6c5710
Unbox `Box<Expr>`
kdy1 Jul 11, 2024
f95c367
More fix
kdy1 Jul 11, 2024
277206b
Fix AST
kdy1 Jul 11, 2024
6498040
Revert for rebase
kdy1 Jul 11, 2024
8ca216a
Revert for rebase
kdy1 Jul 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions bindings/binding_core_node/src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,23 +275,23 @@ impl swc_core::bundler::Hook for Hook {

Ok(vec![
KeyValueProp {
key: PropName::Ident(Ident::new("url".into(), span)),
key: PropName::Ident(Ident::new_no_ctxt("url".into(), span)),
value: Box::new(Expr::Lit(Lit::Str(Str {
span,
raw: None,
value: file_name.into(),
}))),
},
KeyValueProp {
key: PropName::Ident(Ident::new("main".into(), span)),
key: PropName::Ident(Ident::new_no_ctxt("main".into(), span)),
value: Box::new(if module_record.is_entry {
Expr::Member(MemberExpr {
span,
obj: Box::new(Expr::MetaProp(MetaPropExpr {
span,
kind: MetaPropKind::ImportMeta,
})),
prop: MemberProp::Ident(Ident::new("main".into(), span)),
prop: MemberProp::Ident(Ident::new_no_ctxt("main".into(), span)),
})
} else {
Expr::Lit(Lit::Bool(Bool { span, value: false }))
Expand Down
4 changes: 2 additions & 2 deletions bindings/binding_core_node/src/minify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ enum MinifyTarget {
impl MinifyTarget {
fn to_file(&self, cm: Lrc<SourceMap>) -> Lrc<SourceFile> {
match self {
MinifyTarget::Single(code) => cm.new_source_file(FileName::Anon, code.clone()),
MinifyTarget::Single(code) => cm.new_source_file(FileName::Anon.into(), code.clone()),
MinifyTarget::Map(codes) => {
assert_eq!(
codes.len(),
Expand All @@ -44,7 +44,7 @@ impl MinifyTarget {

let (filename, code) = codes.iter().next().unwrap();

cm.new_source_file(FileName::Real(filename.clone().into()), code.clone())
cm.new_source_file(FileName::Real(filename.clone().into()).into(), code.clone())
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions bindings/binding_core_node/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl Task for ParseTask {
let fm = self
.c
.cm
.new_source_file(self.filename.clone(), self.src.clone());
.new_source_file(self.filename.clone().into(), self.src.clone());

let comments = if options.comments {
Some(self.c.comments() as &dyn Comments)
Expand Down Expand Up @@ -178,7 +178,7 @@ pub fn parse_sync(src: String, opts: Buffer, filename: Option<String>) -> napi::

let program = try_with(c.cm.clone(), false, ErrorFormat::Normal, |handler| {
c.run(|| {
let fm = c.cm.new_source_file(filename, src);
let fm = c.cm.new_source_file(filename.into(), src);

let comments = if options.comments {
Some(c.comments() as &dyn Comments)
Expand Down
8 changes: 4 additions & 4 deletions bindings/binding_core_node/src/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ impl Task for TransformTask {
Input::Source { src } => {
let fm = self.c.cm.new_source_file(
if options.filename.is_empty() {
FileName::Anon
FileName::Anon.into()
} else {
FileName::Real(options.filename.clone().into())
FileName::Real(options.filename.clone().into()).into()
},
src.to_string(),
);
Expand Down Expand Up @@ -150,9 +150,9 @@ pub fn transform_sync(s: String, is_module: bool, opts: Buffer) -> napi::Result<
} else {
let fm = c.cm.new_source_file(
if options.filename.is_empty() {
FileName::Anon
FileName::Anon.into()
} else {
FileName::Real(options.filename.clone().into())
FileName::Real(options.filename.clone().into()).into()
},
s,
);
Expand Down
10 changes: 4 additions & 6 deletions bindings/binding_core_wasm/__tests__/simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,13 @@ describe("parse", () => {
"body": [
{
"body": [],
"ctxt": 0,
"declare": false,
"decorators": [],
"identifier": {
"ctxt": 2,
"optional": false,
"span": {
"ctxt": 2,
"end": 289,
"start": 286,
},
Expand All @@ -118,7 +119,6 @@ describe("parse", () => {
"implements": [],
"isAbstract": false,
"span": {
"ctxt": 0,
"end": 292,
"start": 280,
},
Expand All @@ -130,7 +130,6 @@ describe("parse", () => {
],
"interpreter": null,
"span": {
"ctxt": 0,
"end": 292,
"start": 280,
},
Expand All @@ -150,12 +149,13 @@ describe("parse", () => {
"body": [
{
"body": [],
"ctxt": 0,
"declare": false,
"decorators": [],
"identifier": {
"ctxt": 2,
"optional": false,
"span": {
"ctxt": 2,
"end": 302,
"start": 299,
},
Expand All @@ -165,7 +165,6 @@ describe("parse", () => {
"implements": [],
"isAbstract": false,
"span": {
"ctxt": 0,
"end": 305,
"start": 293,
},
Expand All @@ -177,7 +176,6 @@ describe("parse", () => {
],
"interpreter": null,
"span": {
"ctxt": 0,
"end": 305,
"start": 293,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,6 @@ exports[`transform in strip-only mode should throw an error when it encounters a
"
`;

exports[`transform in strip-only mode should throw an error with a descriptive message when it encounters a decorator 1`] = `
" x Decorators are not supported
,----
1 | class Foo { @decorator foo() {} }
: ^^^^^^^^^^
\`----
"
`;

exports[`transform should strip types 1`] = `
"
export const foo = 1;
Expand Down
8 changes: 0 additions & 8 deletions bindings/binding_typescript_wasm/__tests__/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,6 @@ describe("transform", () => {
).rejects.toMatchSnapshot();
});

it("should throw an error with a descriptive message when it encounters a decorator", async () => {
await expect(
swc.transform("class Foo { @decorator foo() {} }", {
mode: "strip-only",
})
).rejects.toMatchSnapshot();
});

it("should throw an error when it encounters a namespace", async () => {
await expect(
swc.transform("namespace Foo {}", {
Expand Down
8 changes: 4 additions & 4 deletions crates/binding_macros/src/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ macro_rules! build_minify_sync {
.map_err(|e| $crate::wasm::anyhow::anyhow!("failed to parse options: {}", e))?
};

let fm = c.cm.new_source_file($crate::wasm::FileName::Anon, s.into());
let fm = c.cm.new_source_file($crate::wasm::FileName::Anon.into(), s.into());
let program = $crate::wasm::anyhow::Context::context(c.minify(fm, handler, &opts), "failed to minify file")?;

program
Expand Down Expand Up @@ -167,7 +167,7 @@ macro_rules! build_parse_sync {
.map_err(|e| $crate::wasm::anyhow::anyhow!("failed to parse options: {}", e))?
};

let fm = c.cm.new_source_file($crate::wasm::FileName::Anon, s.into());
let fm = c.cm.new_source_file($crate::wasm::FileName::Anon.into(), s.into());

let cmts = c.comments().clone();
let comments = if opts.comments {
Expand Down Expand Up @@ -371,9 +371,9 @@ macro_rules! build_transform_sync {
Ok(s) => {
let fm = c.cm.new_source_file(
if opts.filename.is_empty() {
$crate::wasm::FileName::Anon
$crate::wasm::FileName::Anon.into()
} else {
$crate::wasm::FileName::Real(opts.filename.clone().into())
$crate::wasm::FileName::Real(opts.filename.clone().into()).into()
},
s.into(),
);
Expand Down
2 changes: 1 addition & 1 deletion crates/dbg-swc/src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub fn bundle(cm: Arc<SourceMap>, entry_url: &str) -> Result<ModuleRecord> {
let code =
String::from_utf8(output.stdout).context("deno bundle emitted non-utf8 output")?;

let fm = cm.new_source_file(FileName::Anon, code);
let fm = cm.new_source_file(FileName::Anon.into(), code);
parse_js(fm).context("failed to parse js filed emitted by `deno bundle`")
})
.with_context(|| format!("failed to bundle `{}`", entry_url))
Expand Down
2 changes: 1 addition & 1 deletion crates/dbg-swc/src/util/minifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub fn get_terser_output(file: &Path, compress: bool, mangle: bool) -> Result<St

// Drop comments
let cm = Arc::new(SourceMap::default());
let fm = cm.new_source_file(FileName::Anon, output);
let fm = cm.new_source_file(FileName::Anon.into(), output);
let m = parse_js(fm)?;

let code = print_js(cm, &m.module, true)?;
Expand Down
2 changes: 1 addition & 1 deletion crates/jsdoc/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ pub struct ExprWithTypeArgs {
pub span: Span,

// TODO parent: HeritageClause | JSDocAugmentsTag | JSDocImplementsTag;
pub expr: Box<Expr>,
pub expr: Expr,
}

#[ast_node]
Expand Down
4 changes: 2 additions & 2 deletions crates/jsdoc/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl<'i> Input<'i> {

#[inline(always)]
pub fn span(self) -> Span {
Span::new(self.start, self.end, Default::default())
Span::new(self.start, self.end)
}
}

Expand All @@ -57,7 +57,7 @@ impl_slice!(RangeTo);
impl<'i> From<Input<'i>> for Text {
fn from(i: Input) -> Self {
Self {
span: Span::new(i.start, i.end, Default::default()),
span: Span::new(i.start, i.end),
value: i.src.into(),
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/jsdoc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use nom::{
error::ErrorKind,
IResult, InputIter, Slice,
};
use swc_common::{Span, Spanned, SyntaxContext};
use swc_common::{Span, Spanned};

pub use self::input::Input;
use crate::ast::*;
Expand Down Expand Up @@ -32,7 +32,7 @@ pub fn parse(i: Input) -> IResult<Input, JsDoc> {
Ok((
i,
JsDoc {
span: Span::new(lo, hi, SyntaxContext::empty()),
span: Span::new(lo, hi),
tags,
description,
},
Expand Down Expand Up @@ -563,7 +563,7 @@ fn parse_name_path(mut i: Input) -> IResult<Input, NamePath> {
return Ok((
i,
NamePath {
span: Span::new(lo, i.span().hi, Default::default()),
span: Span::new(lo, i.span().hi),
components,
},
));
Expand Down
40 changes: 20 additions & 20 deletions crates/jsdoc/tests/fixtures/abstracttag.debug
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
[
JsDoc {
span: 1..1#0,
span: 1..1,
description: Text {
span: 1..1#0,
span: 1..1,
value: "",
},
tags: [
TagItem {
span: 1..12#0,
span: 1..12,
tag_name: Text {
span: 1..12#0,
span: 1..12,
value: "constructor",
},
tag: Class(
ClassTag {
span: 1..12#0,
span: 1..12,
ty: None,
name: None,
},
Expand All @@ -23,42 +23,42 @@
],
},
JsDoc {
span: 46..46#0,
span: 46..46,
description: Text {
span: 46..46#0,
span: 46..46,
value: "",
},
tags: [
TagItem {
span: 46..54#0,
span: 46..54,
tag_name: Text {
span: 46..54#0,
span: 46..54,
value: "abstract",
},
tag: Abstract(
AbstractTag {
span: 46..54#0,
span: 46..54,
},
),
},
],
},
JsDoc {
span: 100..100#0,
span: 100..100,
description: Text {
span: 100..100#0,
span: 100..100,
value: "",
},
tags: [
TagItem {
span: 100..111#0,
span: 100..111,
tag_name: Text {
span: 100..111#0,
span: 100..111,
value: "constructor",
},
tag: Class(
ClassTag {
span: 100..111#0,
span: 100..111,
ty: None,
name: None,
},
Expand All @@ -67,21 +67,21 @@
],
},
JsDoc {
span: 150..150#0,
span: 150..150,
description: Text {
span: 150..150#0,
span: 150..150,
value: "",
},
tags: [
TagItem {
span: 150..157#0,
span: 150..157,
tag_name: Text {
span: 150..157#0,
span: 150..157,
value: "virtual",
},
tag: Abstract(
AbstractTag {
span: 150..157#0,
span: 150..157,
},
),
},
Expand Down
Loading
Loading