mirror of
https://github.com/swc-project/swc.git
synced 2024-10-04 20:28:43 +03:00
fix(es/modules): Handle top level this (#5159)
This commit is contained in:
parent
8b62d47eb1
commit
451f346af0
@ -112,6 +112,18 @@ impl VisitMut for ModuleRefRewriter {
|
||||
self.visit_mut_with_non_global_this(&mut n.value);
|
||||
}
|
||||
|
||||
fn visit_mut_private_prop(&mut self, n: &mut PrivateProp) {
|
||||
self.visit_mut_with_non_global_this(n);
|
||||
}
|
||||
|
||||
fn visit_mut_getter_prop(&mut self, n: &mut GetterProp) {
|
||||
self.visit_mut_with_non_global_this(n);
|
||||
}
|
||||
|
||||
fn visit_mut_setter_prop(&mut self, n: &mut SetterProp) {
|
||||
self.visit_mut_with_non_global_this(n);
|
||||
}
|
||||
|
||||
fn visit_mut_static_block(&mut self, n: &mut StaticBlock) {
|
||||
self.visit_mut_with_non_global_this(n);
|
||||
}
|
||||
|
@ -0,0 +1,36 @@
|
||||
import {
|
||||
test1,
|
||||
test2,
|
||||
test3,
|
||||
test4,
|
||||
test5,
|
||||
test6,
|
||||
test7,
|
||||
test8,
|
||||
test9,
|
||||
} from "anywhere";
|
||||
|
||||
class Example {
|
||||
#test1 = test1;
|
||||
test2 = test2;
|
||||
#test3() {
|
||||
return test3;
|
||||
}
|
||||
test4() {
|
||||
return test4;
|
||||
}
|
||||
get #test5() {
|
||||
return test5;
|
||||
}
|
||||
get test6() {
|
||||
return test6;
|
||||
}
|
||||
|
||||
#test7 = this.#test1;
|
||||
#test8() {
|
||||
return this.#test3();
|
||||
}
|
||||
get #test9() {
|
||||
return this.#test5();
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
define([
|
||||
"require",
|
||||
"exports",
|
||||
"anywhere"
|
||||
], function(require, exports, _anywhere) {
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
class Example {
|
||||
#test1 = _anywhere.test1;
|
||||
test2 = _anywhere.test2;
|
||||
#test3() {
|
||||
return _anywhere.test3;
|
||||
}
|
||||
test4() {
|
||||
return _anywhere.test4;
|
||||
}
|
||||
get #test5() {
|
||||
return _anywhere.test5;
|
||||
}
|
||||
get test6() {
|
||||
return _anywhere.test6;
|
||||
}
|
||||
#test7 = this.#test1;
|
||||
#test8() {
|
||||
return this.#test3();
|
||||
}
|
||||
get #test9() {
|
||||
return this.#test5();
|
||||
}
|
||||
}
|
||||
});
|
@ -0,0 +1,28 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
const _anywhere = require("anywhere");
|
||||
class Example {
|
||||
#test1 = _anywhere.test1;
|
||||
test2 = _anywhere.test2;
|
||||
#test3() {
|
||||
return _anywhere.test3;
|
||||
}
|
||||
test4() {
|
||||
return _anywhere.test4;
|
||||
}
|
||||
get #test5() {
|
||||
return _anywhere.test5;
|
||||
}
|
||||
get test6() {
|
||||
return _anywhere.test6;
|
||||
}
|
||||
#test7 = this.#test1;
|
||||
#test8() {
|
||||
return this.#test3();
|
||||
}
|
||||
get #test9() {
|
||||
return this.#test5();
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
(function(global, factory) {
|
||||
if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("anywhere"));
|
||||
else if (typeof define === "function" && define.amd) define([
|
||||
"exports",
|
||||
"anywhere"
|
||||
], factory);
|
||||
else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {}, global.anywhere);
|
||||
})(this, function(exports, _anywhere) {
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
class Example {
|
||||
#test1 = _anywhere.test1;
|
||||
test2 = _anywhere.test2;
|
||||
#test3() {
|
||||
return _anywhere.test3;
|
||||
}
|
||||
test4() {
|
||||
return _anywhere.test4;
|
||||
}
|
||||
get #test5() {
|
||||
return _anywhere.test5;
|
||||
}
|
||||
get test6() {
|
||||
return _anywhere.test6;
|
||||
}
|
||||
#test7 = this.#test1;
|
||||
#test8() {
|
||||
return this.#test3();
|
||||
}
|
||||
get #test9() {
|
||||
return this.#test5();
|
||||
}
|
||||
}
|
||||
});
|
@ -0,0 +1,5 @@
|
||||
class Example {
|
||||
#method() {
|
||||
console.log(this);
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
define([
|
||||
"require"
|
||||
], function(require) {
|
||||
"use strict";
|
||||
class Example {
|
||||
#method() {
|
||||
console.log(this);
|
||||
}
|
||||
}
|
||||
});
|
@ -0,0 +1,6 @@
|
||||
"use strict";
|
||||
class Example {
|
||||
#method() {
|
||||
console.log(this);
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
(function(global, factory) {
|
||||
if (typeof module === "object" && typeof module.exports === "object") factory();
|
||||
else if (typeof define === "function" && define.amd) define([], factory);
|
||||
else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory();
|
||||
})(this, function() {
|
||||
"use strict";
|
||||
class Example {
|
||||
#method() {
|
||||
console.log(this);
|
||||
}
|
||||
}
|
||||
});
|
@ -0,0 +1,3 @@
|
||||
class Example {
|
||||
#property = this;
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
define([
|
||||
"require"
|
||||
], function(require) {
|
||||
"use strict";
|
||||
class Example {
|
||||
#property = this;
|
||||
}
|
||||
});
|
@ -0,0 +1,4 @@
|
||||
"use strict";
|
||||
class Example {
|
||||
#property = this;
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
(function(global, factory) {
|
||||
if (typeof module === "object" && typeof module.exports === "object") factory();
|
||||
else if (typeof define === "function" && define.amd) define([], factory);
|
||||
else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory();
|
||||
})(this, function() {
|
||||
"use strict";
|
||||
class Example {
|
||||
#property = this;
|
||||
}
|
||||
});
|
@ -0,0 +1,3 @@
|
||||
class Example {
|
||||
property = this;
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
define([
|
||||
"require"
|
||||
], function(require) {
|
||||
"use strict";
|
||||
class Example {
|
||||
property = this;
|
||||
}
|
||||
});
|
@ -0,0 +1,4 @@
|
||||
"use strict";
|
||||
class Example {
|
||||
property = this;
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
(function(global, factory) {
|
||||
if (typeof module === "object" && typeof module.exports === "object") factory();
|
||||
else if (typeof define === "function" && define.amd) define([], factory);
|
||||
else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory();
|
||||
})(this, function() {
|
||||
"use strict";
|
||||
class Example {
|
||||
property = this;
|
||||
}
|
||||
});
|
@ -0,0 +1,14 @@
|
||||
export const foo = {
|
||||
get prop1() {
|
||||
return 1;
|
||||
},
|
||||
get prop2() {
|
||||
return this.prop1 + 1;
|
||||
},
|
||||
set prop3(v) {
|
||||
this.x = v;
|
||||
},
|
||||
method() {
|
||||
return this.prop1;
|
||||
},
|
||||
};
|
@ -0,0 +1,27 @@
|
||||
define([
|
||||
"require",
|
||||
"exports"
|
||||
], function(require, exports) {
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "foo", {
|
||||
enumerable: true,
|
||||
get: ()=>foo
|
||||
});
|
||||
const foo = {
|
||||
get prop1 () {
|
||||
return 1;
|
||||
},
|
||||
get prop2 () {
|
||||
return this.prop1 + 1;
|
||||
},
|
||||
set prop3 (v){
|
||||
this.x = v;
|
||||
},
|
||||
method () {
|
||||
return this.prop1;
|
||||
}
|
||||
};
|
||||
});
|
@ -0,0 +1,22 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "foo", {
|
||||
enumerable: true,
|
||||
get: ()=>foo
|
||||
});
|
||||
const foo = {
|
||||
get prop1 () {
|
||||
return 1;
|
||||
},
|
||||
get prop2 () {
|
||||
return this.prop1 + 1;
|
||||
},
|
||||
set prop3 (v){
|
||||
this.x = v;
|
||||
},
|
||||
method () {
|
||||
return this.prop1;
|
||||
}
|
||||
};
|
@ -0,0 +1,30 @@
|
||||
(function(global, factory) {
|
||||
if (typeof module === "object" && typeof module.exports === "object") factory(exports);
|
||||
else if (typeof define === "function" && define.amd) define([
|
||||
"exports"
|
||||
], factory);
|
||||
else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {});
|
||||
})(this, function(exports) {
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "foo", {
|
||||
enumerable: true,
|
||||
get: ()=>foo
|
||||
});
|
||||
const foo = {
|
||||
get prop1 () {
|
||||
return 1;
|
||||
},
|
||||
get prop2 () {
|
||||
return this.prop1 + 1;
|
||||
},
|
||||
set prop3 (v){
|
||||
this.x = v;
|
||||
},
|
||||
method () {
|
||||
return this.prop1;
|
||||
}
|
||||
};
|
||||
});
|
@ -0,0 +1,5 @@
|
||||
class foo {
|
||||
static {
|
||||
this; // should not be replaced by undefined
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
define([
|
||||
"require"
|
||||
], function(require) {
|
||||
"use strict";
|
||||
class foo {
|
||||
static{
|
||||
this; // should not be replaced by undefined
|
||||
}
|
||||
}
|
||||
});
|
@ -0,0 +1,6 @@
|
||||
"use strict";
|
||||
class foo {
|
||||
static{
|
||||
this; // should not be replaced by undefined
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
(function(global, factory) {
|
||||
if (typeof module === "object" && typeof module.exports === "object") factory();
|
||||
else if (typeof define === "function" && define.amd) define([], factory);
|
||||
else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory();
|
||||
})(this, function() {
|
||||
"use strict";
|
||||
class foo {
|
||||
static{
|
||||
this; // should not be replaced by undefined
|
||||
}
|
||||
}
|
||||
});
|
@ -0,0 +1 @@
|
||||
export class C { [this.name]() {} }
|
@ -0,0 +1,16 @@
|
||||
define([
|
||||
"require",
|
||||
"exports"
|
||||
], function(require, exports) {
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "C", {
|
||||
enumerable: true,
|
||||
get: ()=>C
|
||||
});
|
||||
class C {
|
||||
[(void 0).name]() {}
|
||||
}
|
||||
});
|
@ -0,0 +1,11 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "C", {
|
||||
enumerable: true,
|
||||
get: ()=>C
|
||||
});
|
||||
class C {
|
||||
[(void 0).name]() {}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
(function(global, factory) {
|
||||
if (typeof module === "object" && typeof module.exports === "object") factory(exports);
|
||||
else if (typeof define === "function" && define.amd) define([
|
||||
"exports"
|
||||
], factory);
|
||||
else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {});
|
||||
})(this, function(exports) {
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "C", {
|
||||
enumerable: true,
|
||||
get: ()=>C
|
||||
});
|
||||
class C {
|
||||
[(void 0).name]() {}
|
||||
}
|
||||
});
|
@ -0,0 +1,3 @@
|
||||
class A {
|
||||
[() => this.name]() {}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
define([
|
||||
"require"
|
||||
], function(require) {
|
||||
"use strict";
|
||||
class A {
|
||||
[()=>(void 0).name]() {}
|
||||
}
|
||||
});
|
@ -0,0 +1,4 @@
|
||||
"use strict";
|
||||
class A {
|
||||
[()=>(void 0).name]() {}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
(function(global, factory) {
|
||||
if (typeof module === "object" && typeof module.exports === "object") factory();
|
||||
else if (typeof define === "function" && define.amd) define([], factory);
|
||||
else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory();
|
||||
})(this, function() {
|
||||
"use strict";
|
||||
class A {
|
||||
[()=>(void 0).name]() {}
|
||||
}
|
||||
});
|
@ -0,0 +1,3 @@
|
||||
class A {
|
||||
[function () { this.name; }]() {}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
define([
|
||||
"require"
|
||||
], function(require) {
|
||||
"use strict";
|
||||
class A {
|
||||
[function() {
|
||||
this.name;
|
||||
}]() {}
|
||||
}
|
||||
});
|
@ -0,0 +1,6 @@
|
||||
"use strict";
|
||||
class A {
|
||||
[function() {
|
||||
this.name;
|
||||
}]() {}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
(function(global, factory) {
|
||||
if (typeof module === "object" && typeof module.exports === "object") factory();
|
||||
else if (typeof define === "function" && define.amd) define([], factory);
|
||||
else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory();
|
||||
})(this, function() {
|
||||
"use strict";
|
||||
class A {
|
||||
[function() {
|
||||
this.name;
|
||||
}]() {}
|
||||
}
|
||||
});
|
@ -0,0 +1 @@
|
||||
export class C { [this.name] = 42 }
|
@ -0,0 +1,16 @@
|
||||
define([
|
||||
"require",
|
||||
"exports"
|
||||
], function(require, exports) {
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "C", {
|
||||
enumerable: true,
|
||||
get: ()=>C
|
||||
});
|
||||
class C {
|
||||
[(void 0).name] = 42;
|
||||
}
|
||||
});
|
@ -0,0 +1,11 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "C", {
|
||||
enumerable: true,
|
||||
get: ()=>C
|
||||
});
|
||||
class C {
|
||||
[(void 0).name] = 42;
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
(function(global, factory) {
|
||||
if (typeof module === "object" && typeof module.exports === "object") factory(exports);
|
||||
else if (typeof define === "function" && define.amd) define([
|
||||
"exports"
|
||||
], factory);
|
||||
else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.input = {});
|
||||
})(this, function(exports) {
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "C", {
|
||||
enumerable: true,
|
||||
get: ()=>C
|
||||
});
|
||||
class C {
|
||||
[(void 0).name] = 42;
|
||||
}
|
||||
});
|
Loading…
Reference in New Issue
Block a user