Skip to content

Commit cf486c1

Browse files
authored
feat: support decorators in javascript (#485)
1 parent 786c790 commit cf486c1

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/swc.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use anyhow::anyhow;
22
use anyhow::bail;
33
use anyhow::Result;
44
use deno_ast::swc::parser::error::SyntaxError;
5+
use deno_ast::swc::parser::Syntax;
56
use deno_ast::ParsedSource;
67
use deno_ast::SourceTextInfo;
78
use std::path::Path;
@@ -33,11 +34,17 @@ fn parse_inner(file_path: &Path, text_info: SourceTextInfo) -> Result<ParsedSour
3334
}
3435

3536
fn parse_inner_no_diagnostic_check(file_path: &Path, text_info: SourceTextInfo) -> Result<ParsedSource> {
37+
let media_type: deno_ast::MediaType = file_path.into();
38+
let mut syntax = deno_ast::get_syntax(media_type);
39+
if let Syntax::Es(es) = &mut syntax {
40+
// support decorators in js
41+
es.decorators = true;
42+
}
3643
deno_ast::parse_program(deno_ast::ParseParams {
3744
specifier: file_path.to_string_lossy().to_string(),
3845
capture_tokens: true,
39-
maybe_syntax: None,
40-
media_type: file_path.into(),
46+
maybe_syntax: Some(syntax),
47+
media_type,
4148
scope_analysis: false,
4249
text_info,
4350
})
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-- file: main.js --
2+
~~ lineWidth: 30 ~~
3+
== should support decorators in javascript ==
4+
@dec
5+
class T {
6+
}
7+
8+
[expect]
9+
@dec
10+
class T {
11+
}

0 commit comments

Comments
 (0)