Skip to content

Commit

Permalink
refactor(common): Drop SyntaxContext from AST nodes (#9175)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 committed Jul 12, 2024
1 parent 2aef14d commit b2491e5
Show file tree
Hide file tree
Showing 8,338 changed files with 834,522 additions and 1,196,851 deletions.
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
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

0 comments on commit b2491e5

Please sign in to comment.