Skip to content

Commit

Permalink
[v3.8.6] Fix inline enum with namespace. (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
dumganhar authored Dec 27, 2024
1 parent 2e7da44 commit 959a146
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,23 @@ class EnumInliner {
}
const symbol = typeChecker.getSymbolAtLocation(accessName);

// Doesn't support template string now.
if (node.parent && ts.isTemplateSpan(node.parent)) {
return node;
}

if (symbol && symbol.valueDeclaration) {
if (symbol.valueDeclaration.kind === ts.SyntaxKind.EnumMember) {
const enumText = node.expression.getText() + '.' + accessName.text;
let expressionName: string;
if (ts.isIdentifier(node.expression)) {
expressionName = node.expression.text;
} else if (ts.isPropertyAccessExpression(node.expression)) {
expressionName = node.expression.name.text;
} else {
console.warn(`Unsupported expression type: ${node.expression.getText()}`);
return node;
}
const enumText = expressionName + '.' + accessName.text;
const enumInlinedValue = this.findEnumData(enumText);
if (enumInlinedValue === undefined) {
return node;
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cocos/ccbuild",
"version": "2.3.0",
"version": "2.3.1",
"description": "The next generation of build tool for Cocos engine.",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
Expand Down
12 changes: 6 additions & 6 deletions test/build-engine/__snapshots__/engine-js.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2962,7 +2962,7 @@ exports[`engine-js inline enum 2`] = `
UUU: 1234,
EEE: 1235
});
console.log(15);
console.log('MyEnum5.RGB:' + 15);
console.log(16);
console.log(17);
console.log(18);
Expand All @@ -2977,16 +2977,16 @@ exports[`engine-js inline enum 2`] = `
console.log("MyEnum6.UNION.aaa");
console.log("MyEnum6.UNION");
console.log(" " + Format.RGBA);
console.log('' + (Format.RGBA | Format.RG));
console.log('' + (Format_2.RGBA | Format.RG));
console.log('(gfx.Format.RGBA | gfx.Format.RG):' + (16 | 14));
console.log('' + (31 | 14));
var MyNode = exports("MyNode", function MyNode(a) {
this._ccprivate$a = a;
});
MyNode.Format = Format;
MyNode.Format_2 = Format_2;
console.log(MyNode.Format.RG);
console.log(MyNode.Format_2.RG);
console.log(PixelFormat.A8);
console.log(14);
console.log(14);
console.log(1);
console.log(1);
console.log(1024);
console.log('---- const enum begin ----');
Expand Down
4 changes: 2 additions & 2 deletions test/test-engine-source/cocos/enums/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export enum MyEnum5 {
EEE,
}

console.log(MyEnum5.RGB);
console.log('MyEnum5.RGB:' + MyEnum5.RGB);
console.log(MyEnum5.RGBA);
console.log(MyEnum5.III);
console.log(MyEnum5.HHH);
Expand All @@ -69,7 +69,7 @@ console.log(`MyEnum6.UNION.aaa`);
console.log(`MyEnum6.UNION`);
console.log(` ${gfx.Format.RGBA}`);

console.log('' +(gfx.Format.RGBA | gfx.Format.RG));
console.log('(gfx.Format.RGBA | gfx.Format.RG):' +(gfx.Format.RGBA | gfx.Format.RG));
console.log('' +(gfx.Format_2.RGBA | gfx.Format.RG));

export * from './define';
Expand Down

0 comments on commit 959a146

Please sign in to comment.