diff --git a/modules/build-engine/src/engine-js/ts-plugins/inline-enum/index.ts b/modules/build-engine/src/engine-js/ts-plugins/inline-enum/index.ts index 1b43f22..a3934ee 100644 --- a/modules/build-engine/src/engine-js/ts-plugins/inline-enum/index.ts +++ b/modules/build-engine/src/engine-js/ts-plugins/inline-enum/index.ts @@ -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; diff --git a/package-lock.json b/package-lock.json index abd037a..205f9a9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@cocos/ccbuild", - "version": "2.3.0", + "version": "2.3.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@cocos/ccbuild", - "version": "2.3.0", + "version": "2.3.1", "hasInstallScript": true, "license": "MIT", "workspaces": [ diff --git a/package.json b/package.json index 8a5f86e..83450c4 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/build-engine/__snapshots__/engine-js.test.ts.snap b/test/build-engine/__snapshots__/engine-js.test.ts.snap index 9c2cd94..b4b11f2 100644 --- a/test/build-engine/__snapshots__/engine-js.test.ts.snap +++ b/test/build-engine/__snapshots__/engine-js.test.ts.snap @@ -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); @@ -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 ----'); diff --git a/test/test-engine-source/cocos/enums/index.ts b/test/test-engine-source/cocos/enums/index.ts index 8649a27..d6e8419 100644 --- a/test/test-engine-source/cocos/enums/index.ts +++ b/test/test-engine-source/cocos/enums/index.ts @@ -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); @@ -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';