mirror of
https://github.com/swc-project/swc.git
synced 2024-10-05 04:39:06 +03:00
Implement more methods for codegen (#902)
swc_ecma_codegen: - implement emit_private_property (Closes #903)
This commit is contained in:
parent
ea885df521
commit
ecd7b4decc
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "swc_ecma_codegen"
|
||||
version = "0.28.0"
|
||||
version = "0.28.1"
|
||||
authors = ["강동윤 <kdy1997.dev@gmail.com>"]
|
||||
license = "Apache-2.0/MIT"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
|
@ -894,7 +894,28 @@ impl<'a> Emitter<'a> {
|
||||
fn emit_private_prop(&mut self, n: &PrivateProp) -> Result {
|
||||
self.emit_leading_comments_of_pos(n.span().lo())?;
|
||||
|
||||
unimplemented!("emit_private_prop")
|
||||
self.emit_list(n.span, Some(&n.decorators), ListFormat::Decorators);
|
||||
|
||||
self.emit_accesibility(n.accessibility)?;
|
||||
|
||||
if n.readonly {
|
||||
keyword!("readonly");
|
||||
space!();
|
||||
}
|
||||
|
||||
emit!(n.key);
|
||||
if let Some(type_ann) = &n.type_ann {
|
||||
punct!(":");
|
||||
space!();
|
||||
emit!(type_ann);
|
||||
}
|
||||
|
||||
if let Some(value) = &n.value {
|
||||
punct!("=");
|
||||
emit!(value);
|
||||
}
|
||||
|
||||
semi!();
|
||||
}
|
||||
|
||||
#[emitter]
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"devDependencies": {
|
||||
"regenerator-runtime": "^0.11.0",
|
||||
"jest": "^23.6.0"
|
||||
"jest": "^23.6.0",
|
||||
"regenerator-runtime": "^0.11.0"
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
#![feature(test)]
|
||||
use swc_common::{chain, Mark};
|
||||
use swc_ecma_parser::{Syntax, TsConfig};
|
||||
use swc_ecma_transforms::{
|
||||
compat,
|
||||
compat::es2020::class_properties,
|
||||
@ -20,9 +21,14 @@ use swc_ecma_visit::Fold;
|
||||
#[macro_use]
|
||||
mod common;
|
||||
|
||||
fn syntax() -> ::swc_ecma_parser::Syntax {
|
||||
fn syntax() -> Syntax {
|
||||
Default::default()
|
||||
}
|
||||
fn ts_syntax() -> Syntax {
|
||||
Syntax::Typescript(TsConfig {
|
||||
..Default::default()
|
||||
})
|
||||
}
|
||||
|
||||
fn tr(config: Config) -> impl Fold {
|
||||
let mark = Mark::fresh(Mark::root());
|
||||
@ -4153,3 +4159,29 @@ const resources = [
|
||||
}
|
||||
];"
|
||||
);
|
||||
|
||||
test!(
|
||||
ts_syntax(),
|
||||
|_| tr(Config {
|
||||
..Default::default()
|
||||
}),
|
||||
issue_895,
|
||||
"import { queryString } from './url'
|
||||
|
||||
export function setup(url: string, obj: any) {
|
||||
const _queryString = queryString(obj)
|
||||
const _url = url + '?' + _queryString
|
||||
return _url
|
||||
}",
|
||||
"'use strict';
|
||||
Object.defineProperty(exports, '__esModule', {
|
||||
value: true
|
||||
});
|
||||
exports.setup = setup;
|
||||
var _url = require('./url');
|
||||
function setup(url: string, obj: any) {
|
||||
const _queryString = _url.queryString(obj);
|
||||
const _url1 = url + '?' + _queryString;
|
||||
return _url1;
|
||||
}"
|
||||
);
|
||||
|
File diff suppressed because it is too large
Load Diff
8
spack/tests/pass/swcrc/jsx/issue-884/input/.swcrc
Normal file
8
spack/tests/pass/swcrc/jsx/issue-884/input/.swcrc
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"jsc": {
|
||||
"parser": {
|
||||
"syntax": "ecmascript",
|
||||
"jsx": true
|
||||
}
|
||||
}
|
||||
}
|
4
spack/tests/pass/swcrc/jsx/issue-884/input/entry.jsx
Normal file
4
spack/tests/pass/swcrc/jsx/issue-884/input/entry.jsx
Normal file
@ -0,0 +1,4 @@
|
||||
/**
|
||||
* Don't ask why it is named as divider.
|
||||
*/
|
||||
export const Divider = <div/>
|
4
spack/tests/pass/swcrc/jsx/issue-884/output/entry.jsx
Normal file
4
spack/tests/pass/swcrc/jsx/issue-884/output/entry.jsx
Normal file
@ -0,0 +1,4 @@
|
||||
/**
|
||||
* Don't ask why it is named as divider.
|
||||
*/
|
||||
export var Divider = React.createElement('div', null);
|
@ -547,3 +547,16 @@ fn issue_879() {
|
||||
"swc should not emit `function X` twice"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn issue_895() {
|
||||
let f = file("tests/projects/issue-895/input.ts").unwrap();
|
||||
println!("{}", f);
|
||||
|
||||
assert!(f.contains("_url ="));
|
||||
assert!(f.contains("_url.queryString"));
|
||||
let s = f.replace("_url =", "").replace("_url.queryString", "");
|
||||
|
||||
assert!(!s.contains("_url."));
|
||||
assert!(!s.contains("_url,"));
|
||||
}
|
||||
|
10
tests/projects/issue-895/.swcrc
Normal file
10
tests/projects/issue-895/.swcrc
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"jsc": {
|
||||
"parser": {
|
||||
"syntax": "typescript"
|
||||
}
|
||||
},
|
||||
"module": {
|
||||
"type": "commonjs"
|
||||
}
|
||||
}
|
7
tests/projects/issue-895/input.ts
Normal file
7
tests/projects/issue-895/input.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import { queryString } from './url'
|
||||
|
||||
export function setup(url: string, obj: any) {
|
||||
const _queryString = queryString(obj)
|
||||
const _url = url + '?' + _queryString
|
||||
return _url
|
||||
}
|
Loading…
Reference in New Issue
Block a user