mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-20 23:52:40 +08:00
284aa38d25
* consts * Bump @cocos/build-engine version * Fix * Upload @cocos/build-engine * Rm scripts/build-engine/.gitignore
24 lines
799 B
TypeScript
24 lines
799 B
TypeScript
import { DEBUG } from 'internal:constants';
|
|
|
|
/**
|
|
* 在调试模式下,将属性的 Get 访问器标记为不可变的。
|
|
* 属性必须为 Javascript 原生类型或继承自 ValueType。
|
|
* 非调试模式下,此装饰器没有任何效果。
|
|
*/
|
|
export function constget (target: Object, propertyKey: string | symbol) {
|
|
if (!DEBUG) {
|
|
return;
|
|
}
|
|
|
|
const propertyDescriptor = Object.getOwnPropertyDescriptor(target, propertyKey);
|
|
if (propertyDescriptor && propertyDescriptor.get) {
|
|
const rawGet = propertyDescriptor.get;
|
|
function constGet (this: any) {
|
|
const value = rawGet.call(this);
|
|
return value ? Object.freeze(value.clone()) : value;
|
|
}
|
|
propertyDescriptor.get = constGet;
|
|
}
|
|
return propertyDescriptor;
|
|
}
|