mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-06 10:46:53 +08:00
Fix exclusions.ts: discriminated union type, correct const method handling
This commit is contained in:
parent
4fd23d3abe
commit
0a33247f44
@ -1,6 +1,29 @@
|
|||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import { Exclusion } from './types';
|
import { Exclusion } from './types';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads exclusions from a text file.
|
||||||
|
*
|
||||||
|
* File format:
|
||||||
|
* - Lines starting with # are comments
|
||||||
|
* - Empty lines are ignored
|
||||||
|
* - Type exclusions: "type: TypeName"
|
||||||
|
* - Method exclusions: "method: TypeName::methodName [const]"
|
||||||
|
*
|
||||||
|
* Examples:
|
||||||
|
* ```
|
||||||
|
* # Exclude entire types
|
||||||
|
* type: SkeletonClipping
|
||||||
|
* type: Triangulator
|
||||||
|
*
|
||||||
|
* # Exclude specific methods
|
||||||
|
* method: AnimationState::setListener
|
||||||
|
* method: AnimationState::addListener
|
||||||
|
*
|
||||||
|
* # Exclude only const version of a method
|
||||||
|
* method: BoneData::getSetupPose const
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
export function loadExclusions(filePath: string): Exclusion[] {
|
export function loadExclusions(filePath: string): Exclusion[] {
|
||||||
const content = fs.readFileSync(filePath, 'utf8');
|
const content = fs.readFileSync(filePath, 'utf8');
|
||||||
const lines = content.split('\n');
|
const lines = content.split('\n');
|
||||||
@ -33,12 +56,9 @@ export function loadExclusions(filePath: string): Exclusion[] {
|
|||||||
kind: 'method',
|
kind: 'method',
|
||||||
typeName: methodMatch[1].trim(),
|
typeName: methodMatch[1].trim(),
|
||||||
methodName: methodName,
|
methodName: methodName,
|
||||||
isConst: isConst
|
isConst: isConst || undefined
|
||||||
});
|
});
|
||||||
|
|
||||||
if (isConst) {
|
|
||||||
console.log(`Parsed const exclusion: ${methodMatch[1].trim()}::${methodName} const`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,9 +69,8 @@ export function isTypeExcluded(typeName: string, exclusions: Exclusion[]): boole
|
|||||||
return exclusions.some(ex => ex.kind === 'type' && ex.typeName === typeName);
|
return exclusions.some(ex => ex.kind === 'type' && ex.typeName === typeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isMethodExcluded(typeName: string, methodName: string, exclusions: Exclusion[], returnType?: string): boolean {
|
export function isMethodExcluded(typeName: string, methodName: string, exclusions: Exclusion[], method?: { isConst?: boolean }): boolean {
|
||||||
// Determine if method is const by looking at return type
|
const isConstMethod = method?.isConst || false;
|
||||||
const isConstMethod = returnType ? returnType.includes('const ') && returnType.includes('&') : false;
|
|
||||||
|
|
||||||
const result = exclusions.some(ex => {
|
const result = exclusions.some(ex => {
|
||||||
if (ex.kind === 'method' &&
|
if (ex.kind === 'method' &&
|
||||||
|
|||||||
@ -14,7 +14,7 @@ export class MethodGenerator {
|
|||||||
const methods = type.members.filter(m =>
|
const methods = type.members.filter(m =>
|
||||||
m.kind === 'method' &&
|
m.kind === 'method' &&
|
||||||
!m.isStatic &&
|
!m.isStatic &&
|
||||||
!isMethodExcluded(type.name, m.name, this.exclusions, m.returnType)
|
!isMethodExcluded(type.name, m.name, this.exclusions, m)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Check for const/non-const method pairs
|
// Check for const/non-const method pairs
|
||||||
|
|||||||
@ -40,10 +40,9 @@ function checkConstNonConstConflicts(classes: Type[], exclusions: Exclusion[]):
|
|||||||
const methodGroups = new Map<string, Member[]>();
|
const methodGroups = new Map<string, Member[]>();
|
||||||
for (const method of allMethods) {
|
for (const method of allMethods) {
|
||||||
// Skip if this specific const/non-const version is excluded
|
// Skip if this specific const/non-const version is excluded
|
||||||
if (isMethodExcluded(type.name, method.name, exclusions, method.returnType)) {
|
if (isMethodExcluded(type.name, method.name, exclusions, method)) {
|
||||||
if (method.name === 'getSetupPose') {
|
if (method.name === 'getSetupPose') {
|
||||||
const isConstMethod = method.returnType && method.returnType.includes('const ') && method.returnType.includes('&');
|
console.log(`Skipping excluded method: ${type.name}::${method.name}${method.isConst ? ' const' : ''}`);
|
||||||
console.log(`Skipping excluded method: ${type.name}::${method.name}${isConstMethod ? ' const' : ''}`);
|
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,12 +41,17 @@ export interface SpineTypes {
|
|||||||
[header: string]: Type[];
|
[header: string]: Type[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Exclusion {
|
export type Exclusion =
|
||||||
kind: 'type' | 'method';
|
| {
|
||||||
typeName: string;
|
kind: 'type';
|
||||||
methodName?: string;
|
typeName: string;
|
||||||
isConst?: boolean; // For excluding specifically const or non-const versions
|
}
|
||||||
}
|
| {
|
||||||
|
kind: 'method';
|
||||||
|
typeName: string;
|
||||||
|
methodName: string;
|
||||||
|
isConst?: boolean; // Whether the method is const (e.g., void foo() const), NOT whether return type is const
|
||||||
|
};
|
||||||
|
|
||||||
export function toSnakeCase(name: string): string {
|
export function toSnakeCase(name: string): string {
|
||||||
// Handle acronyms and consecutive capitals
|
// Handle acronyms and consecutive capitals
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user