diff --git a/compiler/src/pre_define.ts b/compiler/src/pre_define.ts index 5a665b9..9dc8b93 100644 --- a/compiler/src/pre_define.ts +++ b/compiler/src/pre_define.ts @@ -175,7 +175,8 @@ export const RESOURCE_TYPE = { pattern: 10008, strarray: 10009, media: 20000, - rawfile: 30000 + rawfile: 30000, + graphic: 40000 }; export const WORKERS_DIR: string = 'workers'; diff --git a/compiler/src/process_ui_syntax.ts b/compiler/src/process_ui_syntax.ts index e1c7684..ebba07a 100644 --- a/compiler/src/process_ui_syntax.ts +++ b/compiler/src/process_ui_syntax.ts @@ -294,19 +294,31 @@ function processResourceData(node: ts.CallExpression): ts.Node { if (node.expression.getText() === RESOURCE_RAWFILE) { return createResourceParam(0, RESOURCE_TYPE.rawfile, [node.arguments[0]]); } else { - // @ts-ignore - const resourceData: string[] = node.arguments[0].text.trim().split('.'); - if (validateResourceData(resourceData, resources, node.arguments[0].getStart())) { - const resourceType: number = RESOURCE_TYPE[resourceData[1]]; - const resourceValue: number = resources[resourceData[0]][resourceData[1]][resourceData[2]]; - return createResourceParam(resourceValue, resourceType, - Array.from(node.arguments).slice(1)); - } + return getResourceDataNode(node); } } return node; } +function getResourceDataNode(node: ts.CallExpression): ts.Node { + const resourceData: string[] = (node.arguments[0] as ts.StringLiteral).text.trim().split('.'); + if (validateResourceData(resourceData, resources, node.arguments[0].getStart())) { + const resourceType: number = RESOURCE_TYPE[resourceData[1]]; + if (resourceType === undefined) { + transformLog.errors.push({ + type: LogType.ERROR, + message: `The resource type ${resourceData[1]} is not supported.`, + pos: node.getStart() + }); + return node; + } + const resourceValue: number = resources[resourceData[0]][resourceData[1]][resourceData[2]]; + return createResourceParam(resourceValue, resourceType, + Array.from(node.arguments).slice(1)); + } + return node; +} + function createResourceParam(resourceValue: number, resourceType: number, argsArr: ts.Expression[]): ts.ObjectLiteralExpression { const propertyArray: Array[ts.PropertyAssignment] = [