mirror of
https://github.com/swc-project/swc.git
synced 2024-09-11 16:55:27 +03:00
fix(es/transforms/base): Fix hygiene
(#2282)
swc_ecma_transforms_base: - `hygiene`: Handle decl-ref conflict. (#2211)
This commit is contained in:
parent
e5f46a6800
commit
2156364121
4
Cargo.lock
generated
4
Cargo.lock
generated
@ -2738,7 +2738,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "swc_ecma_transforms_base"
|
||||
version = "0.31.2"
|
||||
version = "0.31.3"
|
||||
dependencies = [
|
||||
"fxhash",
|
||||
"once_cell",
|
||||
@ -3401,7 +3401,7 @@ checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
|
||||
|
||||
[[package]]
|
||||
name = "wasm"
|
||||
version = "1.2.89"
|
||||
version = "1.2.90"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"console_error_panic_hook",
|
||||
|
@ -1,10 +1,10 @@
|
||||
var foo = {
|
||||
var foo1 = {
|
||||
"\x00\x01": "foo",
|
||||
get "\x00\x01" () {
|
||||
return "bar";
|
||||
},
|
||||
set "\x00\x01" (foo1){
|
||||
save(foo1);
|
||||
set "\x00\x01" (foo){
|
||||
save(foo);
|
||||
},
|
||||
*"\x00\x01" () {
|
||||
return "foobar";
|
||||
|
@ -1,10 +1,10 @@
|
||||
var foo = {
|
||||
var foo1 = {
|
||||
"\x00\x01": "foo",
|
||||
get "\x00\x01" () {
|
||||
return "bar";
|
||||
},
|
||||
set "\x00\x01" (foo1){
|
||||
save(foo1);
|
||||
set "\x00\x01" (foo){
|
||||
save(foo);
|
||||
},
|
||||
*"\x00\x01" () {
|
||||
return "foobar";
|
||||
|
@ -6,7 +6,7 @@ edition = "2018"
|
||||
license = "Apache-2.0/MIT"
|
||||
name = "swc_ecma_transforms_base"
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "0.31.2"
|
||||
version = "0.31.3"
|
||||
|
||||
[dependencies]
|
||||
fxhash = "0.2.1"
|
||||
|
@ -900,14 +900,14 @@ impl<'a> VisitMut for Hygiene<'a> {
|
||||
}
|
||||
|
||||
fn visit_mut_var_declarator(&mut self, decl: &mut VarDeclarator) {
|
||||
let old = self.ident_type;
|
||||
self.ident_type = IdentType::Binding;
|
||||
decl.name.visit_mut_with(self);
|
||||
self.ident_type = old;
|
||||
|
||||
let old = self.var_kind;
|
||||
self.var_kind = None;
|
||||
decl.init.visit_mut_with(self);
|
||||
self.var_kind = old;
|
||||
|
||||
let old = self.ident_type;
|
||||
self.ident_type = IdentType::Binding;
|
||||
decl.name.visit_mut_with(self);
|
||||
self.ident_type = old;
|
||||
}
|
||||
}
|
||||
|
@ -1504,7 +1504,7 @@ fn opt_6() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn issue_2211() {
|
||||
fn issue_2211_1() {
|
||||
test(
|
||||
|tester| {
|
||||
let mark1 = Mark::fresh(Mark::root());
|
||||
@ -1531,14 +1531,54 @@ fn issue_2211() {
|
||||
Ok(stmts)
|
||||
},
|
||||
"
|
||||
var _bar1 = require('./bar');
|
||||
var _bar = require('./bar');
|
||||
const makeX = ()=>{
|
||||
const _bar = ()=>(0, _bar1).bar()
|
||||
const _bar1 = ()=>(0, _bar).bar()
|
||||
;
|
||||
return {
|
||||
_bar
|
||||
_bar: _bar1
|
||||
};
|
||||
};
|
||||
",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn issue_2211_2() {
|
||||
test(
|
||||
|tester| {
|
||||
let mark1 = Mark::fresh(Mark::root());
|
||||
let mark2 = Mark::fresh(Mark::root());
|
||||
|
||||
let stmts = tester
|
||||
.parse_stmts(
|
||||
"actual1.js",
|
||||
"
|
||||
var _bar = require('./bar');
|
||||
const makeX = ()=>{
|
||||
const _bar = () => _bar();
|
||||
|
||||
const alfa = () => _bar();
|
||||
|
||||
return { alfa };
|
||||
};
|
||||
",
|
||||
)?
|
||||
.fold_with(&mut OnceMarker::new(&[(
|
||||
"_bar",
|
||||
&[mark1, mark2, mark1, mark2],
|
||||
)]));
|
||||
Ok(stmts)
|
||||
},
|
||||
"
|
||||
var _bar = require('./bar');
|
||||
const makeX = ()=>{
|
||||
const _bar1 = () => _bar();
|
||||
|
||||
const alfa = () => _bar1();
|
||||
|
||||
return { alfa };
|
||||
};
|
||||
",
|
||||
);
|
||||
}
|
||||
|
@ -386,20 +386,20 @@ class Class {
|
||||
return _this;
|
||||
});
|
||||
(function() {
|
||||
var _this = _this1;
|
||||
var _this2 = _this1;
|
||||
_this1;
|
||||
(function() {
|
||||
return _this;
|
||||
return _this2;
|
||||
});
|
||||
function x() {
|
||||
var _this = this, _this2 = this;
|
||||
var _this = this, _this3 = this;
|
||||
this;
|
||||
(function() {
|
||||
_this;
|
||||
});
|
||||
(function() {
|
||||
var _ref = _asyncToGenerator(function*() {
|
||||
_this2;
|
||||
_this3;
|
||||
});
|
||||
return function() {
|
||||
return _ref.apply(this, arguments);
|
||||
|
@ -0,0 +1,10 @@
|
||||
"use strict";
|
||||
var _bar = require("./bar");
|
||||
const makeX = ()=>{
|
||||
const _bar1 = ()=>(0, _bar).bar()
|
||||
;
|
||||
return {
|
||||
_bar: _bar1
|
||||
};
|
||||
};
|
||||
makeX()._bar();
|
@ -0,0 +1,9 @@
|
||||
import { bar } from "./bar";
|
||||
|
||||
const makeX = () => {
|
||||
const _bar = () => bar();
|
||||
|
||||
const alfa = () => _bar();
|
||||
|
||||
return { alfa };
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
"use strict";
|
||||
var _bar = require("./bar");
|
||||
const makeX = ()=>{
|
||||
const _bar1 = ()=>(0, _bar).bar()
|
||||
;
|
||||
const alfa = ()=>_bar1()
|
||||
;
|
||||
return {
|
||||
alfa
|
||||
};
|
||||
};
|
@ -1,10 +0,0 @@
|
||||
"use strict";
|
||||
var _bar1 = require("./bar");
|
||||
const makeX = ()=>{
|
||||
const _bar = ()=>(0, _bar1).bar()
|
||||
;
|
||||
return {
|
||||
_bar
|
||||
};
|
||||
};
|
||||
makeX()._bar();
|
@ -3171,13 +3171,13 @@ export default class {
|
||||
"#,
|
||||
r#"
|
||||
var _class;
|
||||
let _class1 = ((_class = class _class2 {
|
||||
let _class2 = ((_class = class _class1 {
|
||||
bar() {
|
||||
}
|
||||
}) || _class, _applyDecoratedDescriptor(_class.prototype, "bar", [
|
||||
foo
|
||||
], Object.getOwnPropertyDescriptor(_class.prototype, "bar"), _class.prototype), _class);
|
||||
export { _class1 as default };
|
||||
export { _class2 as default };
|
||||
"#
|
||||
);
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@swc/core",
|
||||
"version": "1.2.89",
|
||||
"version": "1.2.90",
|
||||
"description": "Super-fast alternative for babel",
|
||||
"homepage": "https://swc.rs",
|
||||
"main": "./index.js",
|
||||
|
@ -39,7 +39,7 @@ var MyEnum;
|
||||
MyEnum["y"] = "yyy";
|
||||
})(MyEnum || (MyEnum = {
|
||||
}));
|
||||
let Xpto = ((_class = class Xpto1 {
|
||||
let Xpto1 = ((_class = class Xpto {
|
||||
constructor(){
|
||||
_initializerDefineProperty(this, "value", _descriptor, this);
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ function MyDecorator(klass) {
|
||||
console.log(klass);
|
||||
};
|
||||
}
|
||||
let MyClass = ((_class = class MyClass1 {
|
||||
let MyClass1 = ((_class = class MyClass {
|
||||
constructor(){
|
||||
_initializerDefineProperty(this, "prop", _descriptor, this);
|
||||
}
|
||||
@ -52,4 +52,4 @@ let MyClass = ((_class = class MyClass1 {
|
||||
writable: true,
|
||||
initializer: void 0
|
||||
}), _class);
|
||||
console.log(new MyClass());
|
||||
console.log(new MyClass1());
|
||||
|
@ -34,7 +34,7 @@ var _class, _dec, _dec1, _dec2, _dec3, _dec4, _dec5, _dec6;
|
||||
var _dec7 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:paramtypes", [
|
||||
typeof _appService.AppService === "undefined" ? Object : _appService.AppService
|
||||
]), _dec8 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", Function), _dec9 = (0, _common).Controller();
|
||||
let AppController = _class = _dec9(_class = _dec8(_class = _dec7(((_class = class AppController1 {
|
||||
let AppController1 = _class = _dec9(_class = _dec8(_class = _dec7(((_class = class AppController {
|
||||
async getHello() {
|
||||
const result = await this.appService.getHello();
|
||||
return result;
|
||||
@ -60,4 +60,4 @@ let AppController = _class = _dec9(_class = _dec8(_class = _dec7(((_class = clas
|
||||
_dec5,
|
||||
_dec6
|
||||
], Object.getOwnPropertyDescriptor(_class.prototype, "create"), _class.prototype), _class)) || _class) || _class) || _class;
|
||||
exports.AppController = AppController;
|
||||
exports.AppController = AppController1;
|
||||
|
@ -5,8 +5,8 @@ var _dec = typeof Reflect !== "undefined" && typeof Reflect.metadata === "functi
|
||||
]), _dec1 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", Function), _dec2 = function(target, key) {
|
||||
return Inject()(target, undefined, 0);
|
||||
};
|
||||
let MyClass1 = _class = _dec2(_class = _dec1(_class = _dec((_class = // not work
|
||||
class MyClass11 {
|
||||
let MyClass11 = _class = _dec2(_class = _dec1(_class = _dec((_class = // not work
|
||||
class MyClass1 {
|
||||
constructor(param1){
|
||||
this.param1 = param1;
|
||||
}
|
||||
@ -16,7 +16,7 @@ var _dec3 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "funct
|
||||
]), _dec4 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", Function), _dec5 = function(target, key) {
|
||||
return Inject()(target, undefined, 0);
|
||||
};
|
||||
let MyClass2 = _class1 = _dec5(_class1 = _dec4(_class1 = _dec3((_class1 = class MyClass21 {
|
||||
let MyClass21 = _class1 = _dec5(_class1 = _dec4(_class1 = _dec3((_class1 = class MyClass2 {
|
||||
constructor(param1){
|
||||
this.param1 = param1;
|
||||
}
|
||||
@ -26,7 +26,7 @@ var _dec6 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "funct
|
||||
]), _dec7 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", Function), _dec8 = function(target, key) {
|
||||
return Inject()(target, undefined, 0);
|
||||
};
|
||||
let MyClass3 = _class2 = _dec8(_class2 = _dec7(_class2 = _dec6((_class2 = class MyClass31 {
|
||||
let MyClass31 = _class2 = _dec8(_class2 = _dec7(_class2 = _dec6((_class2 = class MyClass3 {
|
||||
constructor(param1){
|
||||
this.param1 = param1;
|
||||
}
|
||||
@ -36,7 +36,7 @@ var _dec9 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "funct
|
||||
]), _dec10 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", Function), _dec11 = function(target, key) {
|
||||
return Inject()(target, undefined, 0);
|
||||
};
|
||||
let MyClass4 = _class3 = _dec11(_class3 = _dec10(_class3 = _dec9((_class3 = class MyClass41 {
|
||||
let MyClass41 = _class3 = _dec11(_class3 = _dec10(_class3 = _dec9((_class3 = class MyClass4 {
|
||||
constructor(param1){
|
||||
this.param1 = param1;
|
||||
}
|
||||
@ -46,7 +46,7 @@ var _dec12 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "func
|
||||
]), _dec13 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", Function), _dec14 = function(target, key) {
|
||||
return Inject()(target, undefined, 0);
|
||||
};
|
||||
let MyClass5 = _class4 = _dec14(_class4 = _dec13(_class4 = _dec12((_class4 = class MyClass51 {
|
||||
let MyClass51 = _class4 = _dec14(_class4 = _dec13(_class4 = _dec12((_class4 = class MyClass5 {
|
||||
constructor(param1){
|
||||
this.param1 = param1;
|
||||
}
|
||||
@ -59,7 +59,7 @@ var _dec15 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "func
|
||||
}, _dec18 = function(target, key) {
|
||||
return Inject()(target, undefined, 0);
|
||||
};
|
||||
let MyClass6 = _class5 = _dec18(_class5 = _dec17(_class5 = _dec16(_class5 = _dec15((_class5 = class MyClass61 {
|
||||
let MyClass61 = _class5 = _dec18(_class5 = _dec17(_class5 = _dec16(_class5 = _dec15((_class5 = class MyClass6 {
|
||||
constructor(param1, param2){
|
||||
this.param1 = param1;
|
||||
this.param2 = param2;
|
||||
|
@ -5,8 +5,8 @@ var _dec = typeof Reflect !== "undefined" && typeof Reflect.metadata === "functi
|
||||
]), _dec1 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "function" && Reflect.metadata("design:type", Function), _dec2 = function(target, key) {
|
||||
return Inject()(target, undefined, 0);
|
||||
};
|
||||
let MyClass1 = _class = _dec2(_class = _dec1(_class = _dec((_class = // work
|
||||
class MyClass11 {
|
||||
let MyClass11 = _class = _dec2(_class = _dec1(_class = _dec((_class = // work
|
||||
class MyClass1 {
|
||||
constructor(param1){
|
||||
}
|
||||
}) || _class) || _class) || _class) || _class;
|
||||
@ -18,7 +18,7 @@ var _dec3 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "funct
|
||||
}, _dec6 = function(target, key) {
|
||||
return Inject()(target, undefined, 0);
|
||||
};
|
||||
let MyClass2 = _class1 = _dec6(_class1 = _dec5(_class1 = _dec4(_class1 = _dec3((_class1 = class MyClass21 {
|
||||
let MyClass21 = _class1 = _dec6(_class1 = _dec5(_class1 = _dec4(_class1 = _dec3((_class1 = class MyClass2 {
|
||||
constructor(param1, param2){
|
||||
this.param1 = param1;
|
||||
}
|
||||
@ -31,7 +31,7 @@ var _dec7 = typeof Reflect !== "undefined" && typeof Reflect.metadata === "funct
|
||||
}, _dec10 = function(target, key) {
|
||||
return Inject()(target, undefined, 0);
|
||||
};
|
||||
let MyClass3 = _class2 = _dec10(_class2 = _dec9(_class2 = _dec8(_class2 = _dec7((_class2 = class MyClass31 {
|
||||
let MyClass31 = _class2 = _dec10(_class2 = _dec9(_class2 = _dec8(_class2 = _dec7((_class2 = class MyClass3 {
|
||||
constructor(param1, param2){
|
||||
this.param2 = param2;
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { Entity, BaseEntity } from 'typeorm';
|
||||
var _class;
|
||||
var _dec = Entity();
|
||||
export let Location = _class = _dec((_class = class Location extends BaseEntity {
|
||||
let Location1 = _class = _dec((_class = class Location extends BaseEntity {
|
||||
}) || _class) || _class;
|
||||
export { Location1 as Location };
|
||||
|
@ -6,7 +6,7 @@ license = "Apache-2.0 AND MIT"
|
||||
name = "wasm"
|
||||
publish = false
|
||||
repository = "https://github.com/swc-project/swc.git"
|
||||
version = "1.2.89"
|
||||
version = "1.2.90"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
|
Loading…
Reference in New Issue
Block a user