Skip to content

Commit

Permalink
fix(strip): Expand class expressions as sequences
Browse files Browse the repository at this point in the history
swc_ecma_transforms_typescript:
 - `strip`: Expand class expressions as sequences.

Co-authored-by: 강동윤 <kdy1997.dev@gmail.com>
  • Loading branch information
nayeemrmn and kdy1 authored Mar 30, 2021
1 parent 393808a commit 8b1f8dd
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 121 deletions.
6 changes: 3 additions & 3 deletions bundler/tests/fixture/deno-9591/output/entry.inlined.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2256,10 +2256,10 @@ class ConsoleHandler extends BaseHandler {
}
}
class WriterHandler extends BaseHandler {
#encoder=new TextEncoder();
#encoder = new TextEncoder();
}
class FileHandler extends WriterHandler {
#unloadCallback=()=>this.destroy()
#unloadCallback = ()=>this.destroy()
;
constructor(levelName3, options3){
super(levelName3, options3);
Expand Down Expand Up @@ -2305,7 +2305,7 @@ class FileHandler extends WriterHandler {
class RotatingFileHandler extends FileHandler {
#maxBytes;
#maxBackupCount;
#currentFileSize=0;
#currentFileSize = 0;
constructor(levelName4, options4){
super(levelName4, options4);
this.#maxBytes = options4.maxBytes;
Expand Down
6 changes: 3 additions & 3 deletions bundler/tests/fixture/deno-9591/output/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2267,10 +2267,10 @@ class ConsoleHandler extends BaseHandler {
}
}
class WriterHandler extends BaseHandler {
#encoder=new TextEncoder();
#encoder = new TextEncoder();
}
class FileHandler extends WriterHandler {
#unloadCallback=()=>this.destroy()
#unloadCallback = ()=>this.destroy()
;
constructor(levelName3, options3){
super(levelName3, options3);
Expand Down Expand Up @@ -2316,7 +2316,7 @@ class FileHandler extends WriterHandler {
class RotatingFileHandler extends FileHandler {
#maxBytes;
#maxBackupCount;
#currentFileSize=0;
#currentFileSize = 0;
constructor(levelName4, options4){
super(levelName4, options4);
this.#maxBytes = options4.maxBytes;
Expand Down
19 changes: 17 additions & 2 deletions ecmascript/codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -986,8 +986,17 @@ impl<'a> Emitter<'a> {
}

if let Some(value) = &n.value {
formatting_space!();
punct!("=");
emit!(value);
formatting_space!();

if value.is_seq() {
punct!("(");
emit!(value);
punct!(")");
} else {
emit!(value);
}
}

formatting_semi!();
Expand Down Expand Up @@ -1030,7 +1039,13 @@ impl<'a> Emitter<'a> {
punct!("=");
formatting_space!();

emit!(v);
if v.is_seq() {
punct!("(");
emit!(v);
punct!(")");
} else {
emit!(v);
}
}

formatting_semi!();
Expand Down
75 changes: 33 additions & 42 deletions ecmascript/transforms/tests/decorators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4291,20 +4291,17 @@ class Person {
const p = new Person();
p.save();",
"var _class, _dec;
"var _class;
var _class1, _dec;
import { Debounce } from 'lodash-decorators';
let Person = ((_class = function() {
class Person {
save() {
console.log('Hello World!');
}
let Person = ((_class1 = (_class = class Person {
save() {
console.log('Hello World!');
}
Person.debounceTime = 500;
return Person;
}()) || _class, _dec = Debounce(_class.debounceTime), _applyDecoratedDescriptor(_class.prototype, \
'save', [
}, _class.debounceTime = 500, _class)) || _class1, _dec = Debounce(_class1.debounceTime), \
_applyDecoratedDescriptor(_class1.prototype, 'save', [
_dec
], Object.getOwnPropertyDescriptor(_class.prototype, 'save'), _class.prototype), _class);
], Object.getOwnPropertyDescriptor(_class1.prototype, 'save'), _class1.prototype), _class1);
const p = new Person();
p.save();"
);
Expand Down Expand Up @@ -4335,20 +4332,17 @@ class Person {
const p = new Person();
p.save();",
"var _class, _dec;
"var _class;
var _class1, _dec;
import { Debounce } from 'lodash-decorators';
let Person = ((_class = function() {
class Person {
save() {
console.log('Hello World!');
}
let Person = ((_class1 = (_class = class Person {
save() {
console.log('Hello World!');
}
Person.debounceTime = 500;
return Person;
}()) || _class, _dec = Debounce(_class.debounceTime), _applyDecoratedDescriptor(_class.prototype, \
'save', [
}, _class.debounceTime = 500, _class)) || _class1, _dec = Debounce(_class1.debounceTime), \
_applyDecoratedDescriptor(_class1.prototype, 'save', [
_dec
], Object.getOwnPropertyDescriptor(_class.prototype, 'save'), _class.prototype), _class);
], Object.getOwnPropertyDescriptor(_class1.prototype, 'save'), _class1.prototype), _class1);
const p = new Person();
p.save();
"
Expand Down Expand Up @@ -4380,30 +4374,27 @@ class Person {
const p = new Person();
p.save();",
"var _class, _dec;
"var _class;
var _class1, _dec;
import { Debounce } from 'lodash-decorators';
let Person = ((_class = function() {
let Person = function() {
'use strict';
function Person() {
_classCallCheck(this, Person);
}
_createClass(Person, [
{
key: 'save',
value: function save() {
console.log('Hello World!');
}
let Person = ((_class1 = (_class = function() {
'use strict';
function Person() {
_classCallCheck(this, Person);
}
_createClass(Person, [
{
key: 'save',
value: function save() {
console.log('Hello World!');
}
]);
return Person;
}();
Person.debounceTime = 500;
}
]);
return Person;
}()) || _class, _dec = Debounce(_class.debounceTime), _applyDecoratedDescriptor(_class.prototype, \
'save', [
}(), _class.debounceTime = 500, _class)) || _class1, _dec = Debounce(_class1.debounceTime), \
_applyDecoratedDescriptor(_class1.prototype, 'save', [
_dec
], Object.getOwnPropertyDescriptor(_class.prototype, 'save'), _class.prototype), _class);
], Object.getOwnPropertyDescriptor(_class1.prototype, 'save'), _class1.prototype), _class1);
const p = new Person();
p.save();"
);
Expand Down
2 changes: 1 addition & 1 deletion ecmascript/transforms/typescript/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2018"
license = "Apache-2.0/MIT"
name = "swc_ecma_transforms_typescript"
repository = "https://github.com/swc-project/swc.git"
version = "0.11.2"
version = "0.11.3"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
Expand Down
Loading

0 comments on commit 8b1f8dd

Please sign in to comment.