Skip to content

Commit 8c05dca

Browse files
authored
feat: allowing decorators (#78)
* feat: allowing decorators * test: adding a decorator test
1 parent 0bc11ba commit 8c05dca

File tree

4 files changed

+55
-1
lines changed

4 files changed

+55
-1
lines changed

src/parser/mod.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use swc_common::{
1414
FileName, MultiSpan, SourceMap,
1515
};
1616
use swc_ecma_ast::{ClassMember, Decl, Key, ModuleDecl, ModuleItem, Stmt};
17+
use swc_ecma_parser::TsConfig;
1718
use swc_ecma_parser::{lexer::Lexer, Parser, Syntax};
1819
use tag::{get_sql_from_expr, get_sql_from_var_decl};
1920

@@ -243,8 +244,15 @@ pub fn parse_source(path: &PathBuf) -> Result<(HashMap<PathBuf, Vec<SQL>>, Handl
243244

244245
let file_path = path.as_os_str().to_str().unwrap().to_string();
245246
let fm = cm.new_source_file(FileName::Custom(file_path), contents);
247+
let ts_config: TsConfig = TsConfig {
248+
tsx: false,
249+
decorators: true,
250+
dts: false,
251+
no_early_errors: false,
252+
disallow_ambiguous_jsx_like: false
253+
};
246254
let lexer = Lexer::new(
247-
Syntax::Typescript(Default::default()),
255+
Syntax::Typescript(ts_config),
248256
Default::default(),
249257
StringInput::from(&*fm),
250258
None,
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
3+
export type DecoQueryParams = [];
4+
5+
6+
export interface IDecoQueryResult {
7+
id: number;
8+
};
9+
10+
11+
export interface IDecoQueryQuery {
12+
params: DecoQueryParams;
13+
result: IDecoQueryResult;
14+
};
15+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
3+
export type DecoQueryParams = [];
4+
5+
6+
export interface IDecoQueryResult {
7+
id: number;
8+
};
9+
10+
11+
export interface IDecoQueryQuery {
12+
params: DecoQueryParams;
13+
result: IDecoQueryResult;
14+
};
15+
16+

tests/demo/typescript/decorators.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { sql } from 'sqlx-ts'
2+
3+
function SomeDeco(target: typeof DecoClass, context): typeof DecoClass {
4+
console.log('target', target)
5+
console.log('context', context)
6+
return target
7+
}
8+
9+
@SomeDeco
10+
class DecoClass {
11+
constructor() {
12+
console.log('class test')
13+
const decoQuery = sql`SELECT id FROM items`
14+
}
15+
}

0 commit comments

Comments
 (0)