Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the issue with the getClassName error under ES6 #17660

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions cocos/core/utils/js-typed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
* @zh 如果不是空对象或者不是一个对象,返回 `true`;否则返回 `false`。
*/
export function isEmptyObject (obj: any): boolean {
for (const key in obj) {

Check failure on line 88 in cocos/core/utils/js-typed.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Invalid loop. Its body allows only one iteration
return false;
}
return true;
Expand All @@ -102,7 +102,7 @@
* @param writable @en If the property is writable. @zh 属性是否可写。
* @param enumerable @en If the property is enumerable. @zh 属性是否可枚举。
*/
export const value = ((): (object: Record<string | number, any>, propertyName: string, value_: any, writable?: boolean, enumerable?: boolean) => void => {

Check warning on line 105 in cocos/core/utils/js-typed.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

This line has a length of 154. Maximum allowed is 150
const descriptor: PropertyDescriptor = {
value: undefined,
enumerable: false,
Expand All @@ -128,15 +128,15 @@
* @param enumerable @en If the property is enumerable. @zh 属性是否可列举。
* @param configurable @en If the property is configurable. @zh 属性是否可配置。
*/
export const getset = ((): (object: Record<string | number, any>, propertyName: string, getter: Getter, setter?: Setter | boolean, enumerable?: boolean, configurable?: boolean) => void => {

Check warning on line 131 in cocos/core/utils/js-typed.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

This line has a length of 189. Maximum allowed is 150
const descriptor: PropertyDescriptor = {
get: undefined,
set: undefined,
enumerable: false,
};
return (object: Record<string | number, any>, propertyName: string, getter: Getter, setter?: Setter | boolean, enumerable = false, configurable = false): void => {

Check warning on line 137 in cocos/core/utils/js-typed.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

This line has a length of 167. Maximum allowed is 150
if (typeof setter === 'boolean') {
console.log('Set `setter` to boolean is deprecated. Please don not use like this again.');

Check failure on line 139 in cocos/core/utils/js-typed.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected console statement
enumerable = setter;
setter = undefined;
}
Expand All @@ -160,7 +160,7 @@
* @param enumerable @en If the property is enumerable. @zh 属性是否可列举。
* @param configurable @en If the property is configurable. @zh 属性是否可配置。
*/
export const get = ((): (object: Record<string | number, any>, propertyName: string, getter: Getter, enumerable?: boolean, configurable?: boolean) => void => {

Check warning on line 163 in cocos/core/utils/js-typed.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

This line has a length of 159. Maximum allowed is 150
const descriptor: PropertyDescriptor = {
get: undefined,
enumerable: false,
Expand All @@ -184,7 +184,7 @@
* @param enumerable @en If the property is enumerable. @zh 属性是否可列举。
* @param configurable @en If the property is configurable. @zh 属性是否可配置。
*/
export const set = ((): (object: Record<string | number, any>, propertyName: string, setter: Setter, enumerable?: boolean, configurable?: boolean) => void => {

Check warning on line 187 in cocos/core/utils/js-typed.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

This line has a length of 159. Maximum allowed is 150
const descriptor: PropertyDescriptor = {
set: undefined,
enumerable: false,
Expand Down Expand Up @@ -250,18 +250,17 @@
// for browsers which have name property in the constructor of the object, such as chrome
if (objOrCtor.name) {
ret = objOrCtor.name;
}
if (objOrCtor.toString) {
} else if (objOrCtor.toString) {
let arr;
const str = objOrCtor.toString();
if (str.charAt(0) === '[') {
// str is "[object objectClass]"
// eslint-disable-next-line @typescript-eslint/prefer-regexp-exec
arr = /\[\w+\s*(\w+)\]/.exec(str);

Check failure on line 259 in cocos/core/utils/js-typed.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `string`
} else {
// str is function objectClass () {} for IE Firefox
// eslint-disable-next-line @typescript-eslint/prefer-regexp-exec
arr = /function\s*(\w+)/.exec(str);
arr = /^function\s*(\w+)/.exec(str);

Check failure on line 263 in cocos/core/utils/js-typed.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `string`
}
if (arr && arr.length === 2) {
ret = arr[1];
Expand Down Expand Up @@ -304,9 +303,9 @@
}

if (writable) {
getset(object, oldProp, getter, setter);

Check failure on line 306 in cocos/core/utils/js-typed.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `Record<string | number, any>`
} else {
get(object, oldProp, getter);

Check failure on line 308 in cocos/core/utils/js-typed.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `Record<string | number, any>`
}
}

Expand All @@ -324,7 +323,7 @@
export function obsoletes (obj, objName, props, writable): void {
for (const obsoleted in props) {
const newName = props[obsoleted];
obsolete(obj, `${objName}.${obsoleted}`, newName, writable);

Check failure on line 326 in cocos/core/utils/js-typed.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `string`

Check failure on line 326 in cocos/core/utils/js-typed.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `boolean | undefined`
}
}

Expand Down Expand Up @@ -367,7 +366,7 @@
return '';
}
if (subst.length === 0) {
return `${msg}`;

Check warning on line 369 in cocos/core/utils/js-typed.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Invalid type "unknown" of template literal expression
}

const hasSubstitution = typeof msg === 'string' && REGEXP_NUM_OR_STR.test(msg);
Expand All @@ -375,15 +374,15 @@
for (const arg of subst) {
const regExpToTest = typeof arg === 'number' ? REGEXP_NUM_OR_STR : REGEXP_STR;
if (regExpToTest.test(msg as string)) {
const notReplaceFunction = `${arg}`;

Check warning on line 377 in cocos/core/utils/js-typed.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Invalid type "unknown" of template literal expression
msg = (msg as string).replace(regExpToTest, notReplaceFunction);
} else {
msg += ` ${arg}`;

Check failure on line 380 in cocos/core/utils/js-typed.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Invalid operand for a '+' operation. Operands must each be a number or string, allowing a string + any of: `any`, `boolean`, `null`, `RegExp`, `undefined`. Got `unknown`

Check warning on line 380 in cocos/core/utils/js-typed.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Invalid type "unknown" of template literal expression
}
}
} else {
for (const arg of subst) {
msg += ` ${arg}`;

Check failure on line 385 in cocos/core/utils/js-typed.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Invalid operand for a '+' operation. Operands must each be a number or string, allowing a string + any of: `any`, `boolean`, `null`, `RegExp`, `undefined`. Got `unknown`

Check warning on line 385 in cocos/core/utils/js-typed.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Invalid type "unknown" of template literal expression
}
}
return msg as string;
Expand Down Expand Up @@ -619,7 +618,7 @@
export const _nameToClass: Record<string, Constructor> = createMap(true);

function setup (tag: string, table: Record<string | number, any>, allowExist: boolean): (id: string, constructor: Constructor) => void {
return function (id: string, constructor: Constructor): void {

Check warning on line 621 in cocos/core/utils/js-typed.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected unnamed function
// deregister old
// eslint-disable-next-line no-prototype-builtins
if (constructor.prototype.hasOwnProperty(tag)) {
Expand Down
Loading