diff --git a/cocos/core/curves/keyframe-curve.ts b/cocos/core/curves/keyframe-curve.ts index ff60d57a1cf..f7b6a88826d 100644 --- a/cocos/core/curves/keyframe-curve.ts +++ b/cocos/core/curves/keyframe-curve.ts @@ -280,9 +280,18 @@ export class KeyframeCurve implements CurveBase, Iterable>/engine-mangle-config.json`. + */ protected _times: number[] = []; - + /** + * @dontmangle + * NOTE: _values is a serializable property set by `CCClass.fastDefine`, + * so it should not be mangled while `mangleProtected` is true in `<>/engine-mangle-config.json`. + */ protected _values: TKeyframeValue[] = []; } diff --git a/cocos/core/data/object.ts b/cocos/core/data/object.ts index 986aeebd457..0b40f9ea0ba 100644 --- a/cocos/core/data/object.ts +++ b/cocos/core/data/object.ts @@ -196,6 +196,12 @@ class CCObject implements EditorExtendableObject { * @internal */ public _objFlags: number = 0; + + /** + * @dontmangle + * NOTE: _name is a serializable property set by `CCClass.fastDefine`, + * so it should not be mangled while `mangleProtected` is true in `<>/engine-mangle-config.json`. + */ protected declare _name: string; constructor (name = '') { diff --git a/cocos/core/event/eventify.ts b/cocos/core/event/eventify.ts index a77509fd397..fc5eee84f5c 100644 --- a/cocos/core/event/eventify.ts +++ b/cocos/core/event/eventify.ts @@ -151,6 +151,13 @@ export interface IEventified { */ export function Eventify (base: Constructor): Constructor { class Eventified extends (base as unknown as any) { + /** + * @dontmangle + * NOTE: Eventified mixins all properties from CallbacksInvoker.prototype in the following code. + * After invoking `Eventify` for a class, CallbacksInvoker's constructor will not be called, + * but its functions may invoke `this._callbackTable` which is declared as `public` in CallbacksInvoker. + * Marking it as dontmangle is a workaround to avoid the issue that `this._callbackTable` is not defined. + */ protected _callbackTable = createMap(true); public once void> (type: EventType, callback: Callback, target?: any): Callback { diff --git a/cocos/core/geometry/curve.ts b/cocos/core/geometry/curve.ts index 9580e510722..2031f0f940f 100644 --- a/cocos/core/geometry/curve.ts +++ b/cocos/core/geometry/curve.ts @@ -102,6 +102,11 @@ export function evalOptCurve (t: number, coefs: Float32Array | number[]): number * 描述一条曲线,其中每个相邻关键帧采用三次hermite插值计算。 */ export class AnimationCurve { + /** + * @dontmangle + * NOTE: _curve is a serializable property set by `CCClass.fastDefine`, + * so it should not be mangled while `mangleProtected` is true in `<>/engine-mangle-config.json`. + */ private _curve!: RealCurve; private static defaultKF: Keyframe[] = [{ diff --git a/cocos/scene-graph/node-dev.ts b/cocos/scene-graph/node-dev.ts index cae8b7f732f..676be30d526 100644 --- a/cocos/scene-graph/node-dev.ts +++ b/cocos/scene-graph/node-dev.ts @@ -50,9 +50,9 @@ export function nodePolyfill (Node): void { const existing = this.getComponent(ctor._disallowMultiple); if (existing) { if (existing.constructor === ctor) { - throw Error(getError(3805, js.getClassName(ctor), this._name)); + throw Error(getError(3805, js.getClassName(ctor), this._name as string)); } else { - throw Error(getError(3806, js.getClassName(ctor), this._name, js.getClassName(existing))); + throw Error(getError(3806, js.getClassName(ctor), this._name as string, js.getClassName(existing))); } } return true; @@ -65,9 +65,9 @@ export function nodePolyfill (Node): void { Node.prototype._getDependComponent = function (depended): Component[] { const dependant: Component[] = []; for (let i = 0; i < this._components.length; i++) { - const comp = this._components[i]; + const comp: Component = this._components[i]; if (comp !== depended && comp.isValid && !legacyCC.Object._willDestroy(comp)) { - const reqComps = comp.constructor._requireComponent; + const reqComps = (comp.constructor as typeof Component)._requireComponent; if (reqComps) { if (Array.isArray(reqComps)) { for (let i = 0; i < reqComps.length; i++) { @@ -89,7 +89,7 @@ export function nodePolyfill (Node): void { * @param {Component} comp * @param {Number} index */ - Node.prototype._addComponentAt = function (comp, index): void { + Node.prototype._addComponentAt = function (comp: Component, index: number): void { if (this._objFlags & Destroying) { return error('isDestroying'); } @@ -101,7 +101,7 @@ export function nodePolyfill (Node): void { } // recheck attributes because script may changed - const ctor = comp.constructor; + const ctor = comp.constructor as any; if (ctor._disallowMultiple) { if (!this._checkMultipleComp(ctor)) { return undefined; @@ -125,7 +125,7 @@ export function nodePolyfill (Node): void { comp.node = this; this._components.splice(index, 0, comp); if (EDITOR && !IS_PREVIEW && EditorExtends.Node && EditorExtends.Component) { - const node = EditorExtends.Node.getNode(this._id); + const node = EditorExtends.Node.getNode(this._id as string); if (node) { EditorExtends.Component.add(comp._id, comp); } @@ -147,32 +147,35 @@ export function nodePolyfill (Node): void { Node.prototype._registerIfAttached = function (register): void { if (!this._id) { + // eslint-disable-next-line no-console console.warn(`Node(${this && this.name}}) is invalid or its data is corrupted.`); return; } if (EditorExtends.Node && EditorExtends.Component) { if (register) { - EditorExtends.Node.add(this._id, this); + EditorExtends.Node.add(this._id as string, this); for (let i = 0; i < this._components.length; i++) { const comp = this._components[i]; if (!comp || !comp._id) { + // eslint-disable-next-line no-console console.warn(`Component attached to node:${this.name} is corrupted`); } else { - EditorExtends.Component.add(comp._id, comp); + EditorExtends.Component.add(comp._id as string, comp); } } } else { for (let i = 0; i < this._components.length; i++) { const comp = this._components[i]; if (!comp || !comp._id) { + // eslint-disable-next-line no-console console.warn(`Component attached to node:${this.name} is corrupted`); } else { - EditorExtends.Component.remove(comp._id); + EditorExtends.Component.remove(comp._id as string); } } - EditorExtends.Node.remove(this._id); + EditorExtends.Node.remove(this._id as string); } } @@ -186,7 +189,7 @@ export function nodePolyfill (Node): void { if (DEV) { // promote debug info - js.get(Node.prototype, ' INFO ', function (this: any) { + js.get(Node.prototype as Record, ' INFO ', function (this: any) { let path = ''; // eslint-disable-next-line @typescript-eslint/no-this-alias let node: any = this; diff --git a/cocos/scene-graph/node.ts b/cocos/scene-graph/node.ts index 99db8dd020f..4298d304bea 100644 --- a/cocos/scene-graph/node.ts +++ b/cocos/scene-graph/node.ts @@ -1331,6 +1331,14 @@ export class Node extends CCObject implements ISchedulable, CustomSerializable { this.emit(NodeEventType.CHILDREN_ORDER_CHANGED); } + /** + * @dontmangle + * NOTE: the protected method `_instantiate` is invoked by dynamically without type information. + * See `instantiate` in cocos/serialization/instantiate.ts. + * ```ts + * clone = original._instantiate(null, true); // original is any, so _instantiate should not be mangled. + * ``` + */ protected _instantiate (cloned?: Node | null, isSyncedNode: boolean = false): Node { if (!cloned) { cloned = cclegacy.instantiate._clone(this, this) as Node; diff --git a/cocos/scene-graph/prefab/prefab.ts b/cocos/scene-graph/prefab/prefab.ts index 04f51d1a8c1..ee3c02225d5 100644 --- a/cocos/scene-graph/prefab/prefab.ts +++ b/cocos/scene-graph/prefab/prefab.ts @@ -157,6 +157,14 @@ export class Prefab extends Asset { return this._createFunction!(rootToRedirect); // this.data._instantiate(); } + /** + * @dontmangle + * NOTE: the protected method `_instantiate` is invoked by dynamically without type information. + * See `instantiate` in cocos/serialization/instantiate.ts. + * ```ts + * clone = original._instantiate(null, true); // original is any, so _instantiate should not be mangled. + * ``` + */ protected _instantiate (): Node { let node: Node; let useJit = false;