Skip to content

Commit b2491e5

Browse files
committed
refactor(common): Drop SyntaxContext from AST nodes (swc-project#9175)
1 parent 2aef14d commit b2491e5

File tree

8,338 files changed

+834522
-1196851
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

8,338 files changed

+834522
-1196851
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindings/binding_core_node/src/bundle.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -275,23 +275,23 @@ impl swc_core::bundler::Hook for Hook {
275275

276276
Ok(vec![
277277
KeyValueProp {
278-
key: PropName::Ident(Ident::new("url".into(), span)),
278+
key: PropName::Ident(Ident::new_no_ctxt("url".into(), span)),
279279
value: Box::new(Expr::Lit(Lit::Str(Str {
280280
span,
281281
raw: None,
282282
value: file_name.into(),
283283
}))),
284284
},
285285
KeyValueProp {
286-
key: PropName::Ident(Ident::new("main".into(), span)),
286+
key: PropName::Ident(Ident::new_no_ctxt("main".into(), span)),
287287
value: Box::new(if module_record.is_entry {
288288
Expr::Member(MemberExpr {
289289
span,
290290
obj: Box::new(Expr::MetaProp(MetaPropExpr {
291291
span,
292292
kind: MetaPropKind::ImportMeta,
293293
})),
294-
prop: MemberProp::Ident(Ident::new("main".into(), span)),
294+
prop: MemberProp::Ident(Ident::new_no_ctxt("main".into(), span)),
295295
})
296296
} else {
297297
Expr::Lit(Lit::Bool(Bool { span, value: false }))

bindings/binding_core_node/src/minify.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ enum MinifyTarget {
3434
impl MinifyTarget {
3535
fn to_file(&self, cm: Lrc<SourceMap>) -> Lrc<SourceFile> {
3636
match self {
37-
MinifyTarget::Single(code) => cm.new_source_file(FileName::Anon, code.clone()),
37+
MinifyTarget::Single(code) => cm.new_source_file(FileName::Anon.into(), code.clone()),
3838
MinifyTarget::Map(codes) => {
3939
assert_eq!(
4040
codes.len(),
@@ -44,7 +44,7 @@ impl MinifyTarget {
4444

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

47-
cm.new_source_file(FileName::Real(filename.clone().into()), code.clone())
47+
cm.new_source_file(FileName::Real(filename.clone().into()).into(), code.clone())
4848
}
4949
}
5050
}

bindings/binding_core_node/src/parse.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl Task for ParseTask {
4545
let fm = self
4646
.c
4747
.cm
48-
.new_source_file(self.filename.clone(), self.src.clone());
48+
.new_source_file(self.filename.clone().into(), self.src.clone());
4949

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

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

183183
let comments = if options.comments {
184184
Some(c.comments() as &dyn Comments)

bindings/binding_core_node/src/transform.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ impl Task for TransformTask {
7171
Input::Source { src } => {
7272
let fm = self.c.cm.new_source_file(
7373
if options.filename.is_empty() {
74-
FileName::Anon
74+
FileName::Anon.into()
7575
} else {
76-
FileName::Real(options.filename.clone().into())
76+
FileName::Real(options.filename.clone().into()).into()
7777
},
7878
src.to_string(),
7979
);
@@ -150,9 +150,9 @@ pub fn transform_sync(s: String, is_module: bool, opts: Buffer) -> napi::Result<
150150
} else {
151151
let fm = c.cm.new_source_file(
152152
if options.filename.is_empty() {
153-
FileName::Anon
153+
FileName::Anon.into()
154154
} else {
155-
FileName::Real(options.filename.clone().into())
155+
FileName::Real(options.filename.clone().into()).into()
156156
},
157157
s,
158158
);

bindings/binding_core_wasm/__tests__/simple.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,13 @@ describe("parse", () => {
103103
"body": [
104104
{
105105
"body": [],
106+
"ctxt": 0,
106107
"declare": false,
107108
"decorators": [],
108109
"identifier": {
110+
"ctxt": 2,
109111
"optional": false,
110112
"span": {
111-
"ctxt": 2,
112113
"end": 289,
113114
"start": 286,
114115
},
@@ -118,7 +119,6 @@ describe("parse", () => {
118119
"implements": [],
119120
"isAbstract": false,
120121
"span": {
121-
"ctxt": 0,
122122
"end": 292,
123123
"start": 280,
124124
},
@@ -130,7 +130,6 @@ describe("parse", () => {
130130
],
131131
"interpreter": null,
132132
"span": {
133-
"ctxt": 0,
134133
"end": 292,
135134
"start": 280,
136135
},
@@ -150,12 +149,13 @@ describe("parse", () => {
150149
"body": [
151150
{
152151
"body": [],
152+
"ctxt": 0,
153153
"declare": false,
154154
"decorators": [],
155155
"identifier": {
156+
"ctxt": 2,
156157
"optional": false,
157158
"span": {
158-
"ctxt": 2,
159159
"end": 302,
160160
"start": 299,
161161
},
@@ -165,7 +165,6 @@ describe("parse", () => {
165165
"implements": [],
166166
"isAbstract": false,
167167
"span": {
168-
"ctxt": 0,
169168
"end": 305,
170169
"start": 293,
171170
},
@@ -177,7 +176,6 @@ describe("parse", () => {
177176
],
178177
"interpreter": null,
179178
"span": {
180-
"ctxt": 0,
181179
"end": 305,
182180
"start": 293,
183181
},

bindings/binding_typescript_wasm/__tests__/__snapshots__/transform.js.snap

-9
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,6 @@ exports[`transform in strip-only mode should throw an error when it encounters a
7777
"
7878
`;
7979

80-
exports[`transform in strip-only mode should throw an error with a descriptive message when it encounters a decorator 1`] = `
81-
" x Decorators are not supported
82-
,----
83-
1 | class Foo { @decorator foo() {} }
84-
: ^^^^^^^^^^
85-
\`----
86-
"
87-
`;
88-
8980
exports[`transform should strip types 1`] = `
9081
"
9182
export const foo = 1;

bindings/binding_typescript_wasm/__tests__/transform.js

-8
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,6 @@ describe("transform", () => {
115115
).rejects.toMatchSnapshot();
116116
});
117117

118-
it("should throw an error with a descriptive message when it encounters a decorator", async () => {
119-
await expect(
120-
swc.transform("class Foo { @decorator foo() {} }", {
121-
mode: "strip-only",
122-
})
123-
).rejects.toMatchSnapshot();
124-
});
125-
126118
it("should throw an error when it encounters a namespace", async () => {
127119
await expect(
128120
swc.transform("namespace Foo {}", {

crates/binding_macros/src/wasm.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ macro_rules! build_minify_sync {
111111
.map_err(|e| $crate::wasm::anyhow::anyhow!("failed to parse options: {}", e))?
112112
};
113113

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

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

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

172172
let cmts = c.comments().clone();
173173
let comments = if opts.comments {
@@ -371,9 +371,9 @@ macro_rules! build_transform_sync {
371371
Ok(s) => {
372372
let fm = c.cm.new_source_file(
373373
if opts.filename.is_empty() {
374-
$crate::wasm::FileName::Anon
374+
$crate::wasm::FileName::Anon.into()
375375
} else {
376-
$crate::wasm::FileName::Real(opts.filename.clone().into())
376+
$crate::wasm::FileName::Real(opts.filename.clone().into()).into()
377377
},
378378
s.into(),
379379
);

crates/dbg-swc/src/bundle.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub fn bundle(cm: Arc<SourceMap>, entry_url: &str) -> Result<ModuleRecord> {
2828
let code =
2929
String::from_utf8(output.stdout).context("deno bundle emitted non-utf8 output")?;
3030

31-
let fm = cm.new_source_file(FileName::Anon, code);
31+
let fm = cm.new_source_file(FileName::Anon.into(), code);
3232
parse_js(fm).context("failed to parse js filed emitted by `deno bundle`")
3333
})
3434
.with_context(|| format!("failed to bundle `{}`", entry_url))

crates/dbg-swc/src/util/minifier.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ pub fn get_terser_output(file: &Path, compress: bool, mangle: bool) -> Result<St
9696

9797
// Drop comments
9898
let cm = Arc::new(SourceMap::default());
99-
let fm = cm.new_source_file(FileName::Anon, output);
99+
let fm = cm.new_source_file(FileName::Anon.into(), output);
100100
let m = parse_js(fm)?;
101101

102102
let code = print_js(cm, &m.module, true)?;

crates/jsdoc/src/input.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl<'i> Input<'i> {
3434

3535
#[inline(always)]
3636
pub fn span(self) -> Span {
37-
Span::new(self.start, self.end, Default::default())
37+
Span::new(self.start, self.end)
3838
}
3939
}
4040

@@ -57,7 +57,7 @@ impl_slice!(RangeTo);
5757
impl<'i> From<Input<'i>> for Text {
5858
fn from(i: Input) -> Self {
5959
Self {
60-
span: Span::new(i.start, i.end, Default::default()),
60+
span: Span::new(i.start, i.end),
6161
value: i.src.into(),
6262
}
6363
}

crates/jsdoc/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use nom::{
33
error::ErrorKind,
44
IResult, InputIter, Slice,
55
};
6-
use swc_common::{Span, Spanned, SyntaxContext};
6+
use swc_common::{Span, Spanned};
77

88
pub use self::input::Input;
99
use crate::ast::*;
@@ -32,7 +32,7 @@ pub fn parse(i: Input) -> IResult<Input, JsDoc> {
3232
Ok((
3333
i,
3434
JsDoc {
35-
span: Span::new(lo, hi, SyntaxContext::empty()),
35+
span: Span::new(lo, hi),
3636
tags,
3737
description,
3838
},
@@ -563,7 +563,7 @@ fn parse_name_path(mut i: Input) -> IResult<Input, NamePath> {
563563
return Ok((
564564
i,
565565
NamePath {
566-
span: Span::new(lo, i.span().hi, Default::default()),
566+
span: Span::new(lo, i.span().hi),
567567
components,
568568
},
569569
));

crates/jsdoc/tests/fixtures/abstracttag.debug

+20-20
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
[
22
JsDoc {
3-
span: 1..1#0,
3+
span: 1..1,
44
description: Text {
5-
span: 1..1#0,
5+
span: 1..1,
66
value: "",
77
},
88
tags: [
99
TagItem {
10-
span: 1..12#0,
10+
span: 1..12,
1111
tag_name: Text {
12-
span: 1..12#0,
12+
span: 1..12,
1313
value: "constructor",
1414
},
1515
tag: Class(
1616
ClassTag {
17-
span: 1..12#0,
17+
span: 1..12,
1818
ty: None,
1919
name: None,
2020
},
@@ -23,42 +23,42 @@
2323
],
2424
},
2525
JsDoc {
26-
span: 46..46#0,
26+
span: 46..46,
2727
description: Text {
28-
span: 46..46#0,
28+
span: 46..46,
2929
value: "",
3030
},
3131
tags: [
3232
TagItem {
33-
span: 46..54#0,
33+
span: 46..54,
3434
tag_name: Text {
35-
span: 46..54#0,
35+
span: 46..54,
3636
value: "abstract",
3737
},
3838
tag: Abstract(
3939
AbstractTag {
40-
span: 46..54#0,
40+
span: 46..54,
4141
},
4242
),
4343
},
4444
],
4545
},
4646
JsDoc {
47-
span: 100..100#0,
47+
span: 100..100,
4848
description: Text {
49-
span: 100..100#0,
49+
span: 100..100,
5050
value: "",
5151
},
5252
tags: [
5353
TagItem {
54-
span: 100..111#0,
54+
span: 100..111,
5555
tag_name: Text {
56-
span: 100..111#0,
56+
span: 100..111,
5757
value: "constructor",
5858
},
5959
tag: Class(
6060
ClassTag {
61-
span: 100..111#0,
61+
span: 100..111,
6262
ty: None,
6363
name: None,
6464
},
@@ -67,21 +67,21 @@
6767
],
6868
},
6969
JsDoc {
70-
span: 150..150#0,
70+
span: 150..150,
7171
description: Text {
72-
span: 150..150#0,
72+
span: 150..150,
7373
value: "",
7474
},
7575
tags: [
7676
TagItem {
77-
span: 150..157#0,
77+
span: 150..157,
7878
tag_name: Text {
79-
span: 150..157#0,
79+
span: 150..157,
8080
value: "virtual",
8181
},
8282
tag: Abstract(
8383
AbstractTag {
84-
span: 150..157#0,
84+
span: 150..157,
8585
},
8686
),
8787
},

0 commit comments

Comments
 (0)