cocos-engine
cocos-engine copied to clipboard
Some scripts that use symbol are compiled incorrectly.
Cocos Creator version
3.8.0
System information
Mac OS
Issue description
After compiling the WeChat mini-game platform, the following error occurs in the script when running:
game.js? [sm]:64 ReferenceError: dispose is not defined
at bundle.js:252
at Object.execute (bundle.js:252)
at u (system.bundle.js:1)
at j (system.bundle.js:1)
at system.bundle.js:1
at Array.forEach (
Relevant error log output
No response
Steps to reproduce
- The script in question is an npm module, compiled into:
import { dispose } from '../../symbols/disposable.js';
/**
* 管理多个需释放资源的容器
*/
class DisposableStack {
/**
* 资源集合
*/
stack = [];
/**
* 该容器是否已被释放
*/
disposed = false;
/**
* 检查释放状态
*/
checkState() {
if (this.disposed) {
throw new ReferenceError("DisposableStack already disposed.");
}
}
/**
* 添加资源到容器中
*/
use(value) {
this.checkState();
if (value != null) {
this.stack.push(value);
}
return value;
}
/**
* 添加一个资源与一个释放回调到容器中
*/
adopt(value, callback) {
this.checkState();
if (value != null) {
this.stack.push({ [dispose]: () => callback(value) });
}
return value;
}
/**
* 添加一个释放回调到容器中
*/
defer(callback) {
this.checkState();
this.stack.push({ [dispose]: callback });
}
/**
* 将所有资源移至新的容器中,返回新容器
*/
move() {
this.checkState();
const newStack = new DisposableStack();
newStack.stack = this.stack;
this.stack = [];
this.disposed = true;
return newStack;
}
/**
* @inheritdoc
*/
[dispose]() {
if (this.disposed)
return;
this.disposed = true;
let i = this.stack.length;
while (i--) {
this.stack[i][dispose]();
}
this.stack.length = 0;
}
/**
* 释放所有资源
*/
dispose() {
this[dispose]();
}
}
export { DisposableStack };
//# sourceMappingURL=stack.js.map
- After Cocos compilation:
System.register("chunks:///_virtual/stack.js",["./rollupPluginModLoBabelHelpers.js","./disposable.js"],(function(t){var e,s,i,n;return{setters:[function(t){e=t.createClass,s=t.defineProperty,i=t.classCallCheck},function(t){n=t.dispose}],execute:function(){t("DisposableStack",function(){function t(){i(this,t),s(this,"stack",[]),s(this,"disposed",!1)}return e(t,[{key:"checkState",value:function(){if(this.disposed)throw new ReferenceError("DisposableStack already disposed.")}},{key:"use",value:function(t){return this.checkState(),null!=t&&this.stack.push(t),t}},{key:"adopt",value:function(t,e){return this.checkState(),null!=t&&this.stack.push(s({},n,(function(){return e(t)}))),t}},{key:"defer",value:function(t){this.checkState(),this.stack.push(s({},n,t))}},{key:"move",value:function(){this.checkState();var e=new t;return e.stack=this.stack,this.stack=[],this.disposed=!0,e}},{key:dispose,value:function(){if(!this.disposed){this.disposed=!0;for(var t=this.stack.length;t--;)this.stack[t][n]();this.stack.length=0}}},{key:"dispose",value:function(){this[n]()}}]),t}())}}}));
Please note that at the beginning {n=t.dispose}
, the symbol is referenced as n
, but in the following key:dispose,value:function
, the symbol is not renamed to n
or keeps the dispose
name. Can't find it.
3.The problem disappeared when the attribute of "dispose" was renamed to "dispose1". Initially, it was determined that the problem was caused by the renaming of "dispose" to the symbol dispose
.
Please fix to support usage in this case.
Minimal reproduction project
No response
There is no such problem in preview.
I tried to reproduce the issue in v3.8.2 beta, but I could not reproduce it on wechat-mini-game ( device and simulator). Could you check whether it was fixed at 3.8.2 beta ( https://forum.cocos.org/t/topic/154931/18 ) ?
I tried to reproduce the issue in v3.8.2 beta, but I could not reproduce it on wechat-mini-game ( device and simulator). Could you check whether it was fixed at 3.8.2 beta ( https://forum.cocos.org/t/topic/154931/18 ) ?
Okay, I'll try it when I get some time, and if it works, I'll close this question.
Thank you. If it still could not work, please upload a simple demo for reproducing the issue.