diff --git a/compiler/src/gen_abc.ts b/compiler/src/gen_abc.ts index dd923af2fd8ff91738d964f1a363da1209b32eec..8bcd6ff330b4787b5e954760c3ffc6da21b3871e 100644 --- a/compiler/src/gen_abc.ts +++ b/compiler/src/gen_abc.ts @@ -13,9 +13,9 @@ const reset: string = '\u001b[39m'; function js2abcByWorkers(inputPaths: File[], cmd: string): Promise { for (let i = 0; i < inputPaths.length; ++i) { - let input = inputPaths[i].path; - let singleCmd = `${cmd} "${input}"`; - logger.debug("gen abc cmd is: ", singleCmd); + const input = inputPaths[i].path; + const singleCmd = `${cmd} "${input}"`; + logger.debug('gen abc cmd is: ', singleCmd); try { process.execSync(singleCmd); } catch (e) { @@ -37,8 +37,8 @@ function js2abcByWorkers(inputPaths: File[], cmd: string): Promise { } } -logger.debug("worker data is: ", JSON.stringify(workerData)); +logger.debug('worker data is: ', JSON.stringify(workerData)); if (JSON.stringify(workerData) !== 'null') { - logger.debug("==>worker #", threadId, "started!"); + logger.debug('==>worker #', threadId, 'started!'); js2abcByWorkers(workerData.input, workerData.cmd); } diff --git a/compiler/src/gen_abc_plugin.ts b/compiler/src/gen_abc_plugin.ts index 1565e11c327430fea1b8fe9034d4ef3b578f8a03..3de104e3e54970c157ca4c736b4f04d1324badb4 100644 --- a/compiler/src/gen_abc_plugin.ts +++ b/compiler/src/gen_abc_plugin.ts @@ -32,7 +32,7 @@ interface File { path: string, size: number } -let intermediateJsBundle: Array = []; +const intermediateJsBundle: Array = []; const red: string = '\u001b[31m'; const reset: string = '\u001b[39m'; @@ -78,20 +78,20 @@ export class GenAbcPlugin { if (isMainThread) { let js2abc: string = path.join(arkDir, 'build', 'src', 'index.js'); if (isWin) { - js2abc = path.join(arkDir, 'build-win', 'src', 'index.js'); + js2abc = path.join(arkDir, 'build-win', 'src', 'index.js'); } else if (isMac) { js2abc = path.join(arkDir, 'build-mac', 'src', 'index.js'); } - let maxWorkerNumber = 3; - let splitedBundles = splitJsBundlesBySize(intermediateJsBundle, maxWorkerNumber); - let workerNumber = maxWorkerNumber < splitedBundles.length ? maxWorkerNumber : splitedBundles.length; - let cmdPrefix: string = `${nodeJs} --expose-gc "${js2abc}" ${param} `; - let workers = []; + const maxWorkerNumber = 3; + const splitedBundles = splitJsBundlesBySize(intermediateJsBundle, maxWorkerNumber); + const workerNumber = maxWorkerNumber < splitedBundles.length ? maxWorkerNumber : splitedBundles.length; + const cmdPrefix: string = `${nodeJs} --expose-gc "${js2abc}" ${param} `; + const workers = []; for (let i = 0; i < workerNumber; ++i) { workers.push(new Worker(path.resolve(__dirname, genAbcScript), - {workerData: {input: splitedBundles[i], cmd: cmdPrefix} })); + {workerData: {input: splitedBundles[i], cmd: cmdPrefix} })); workers[i].on('exit', () => { - logger.debug("worker ", i, "finished!"); + logger.debug('worker ', i, 'finished!'); }); } } @@ -106,7 +106,7 @@ function writeFileSync(inputString: string, output: string, jsBundleFile: string } fs.writeFileSync(output, inputString); if (fs.existsSync(output)) { - let fileSize = fs.statSync(output).size; + const fileSize = fs.statSync(output).size; intermediateJsBundle.push({path: output, size: fileSize}); } else { logger.error(red, `ETS:ERROR Failed to convert file ${jsBundleFile} to bin. ${output} is lost`, reset); @@ -122,15 +122,15 @@ function mkDir(path_: string): void { } function getSmallestSizeGroup(groupSize: Map) { - let groupSizeArray = Array.from(groupSize); + const groupSizeArray = Array.from(groupSize); groupSizeArray.sort(function(g1, g2) { return g1[1] - g2[1]; // sort by value }); return groupSizeArray[0][0]; // return key } -function splitJsBundlesBySize(bundleArray: Array, groupNumber: number){ - let result = []; +function splitJsBundlesBySize(bundleArray: Array, groupNumber: number) { + const result = []; if (bundleArray.length < groupNumber) { result.push(bundleArray); return result; @@ -139,17 +139,17 @@ function splitJsBundlesBySize(bundleArray: Array, groupNumber: number){ bundleArray.sort(function(f1: File, f2: File) { return f2.size - f1.size; }); - let groupFileSize = new Map(); + const groupFileSize = new Map(); for (let i = 0; i < groupNumber; ++i) { result.push([]); groupFileSize.set(i, 0); } let index = 0; - while(index < bundleArray.length) { - let smallestGroup = getSmallestSizeGroup(groupFileSize); + while (index < bundleArray.length) { + const smallestGroup = getSmallestSizeGroup(groupFileSize); result[smallestGroup].push(bundleArray[index]); - let sizeUpdate = groupFileSize.get(smallestGroup) + bundleArray[index].size; + const sizeUpdate = groupFileSize.get(smallestGroup) + bundleArray[index].size; groupFileSize.set(smallestGroup, sizeUpdate); index++; } diff --git a/compiler/src/process_component_build.ts b/compiler/src/process_component_build.ts index 278968a943b950938379771dbb5a4b248c9246cc..6831aa253953b0967c320d99ea649032805cf538 100644 --- a/compiler/src/process_component_build.ts +++ b/compiler/src/process_component_build.ts @@ -894,33 +894,35 @@ function addComponentAttr(temp: any, node: ts.Identifier, lastStatement: any, validateStateStyleSyntax(temp, log); } } - temp = loopEtsComponent(temp, isStylesAttr, isGlobalStyles); + temp = loopEtscomponent(temp, isStylesAttr, isGlobalStyles); statements.push(ts.factory.createExpressionStatement( createFunction(identifierNode, node, temp.arguments))); lastStatement.kind = true; } } -function loopEtsComponent(temp: any, isStylesAttr: boolean, isGlobalStyles: boolean): ts.Node { - temp.arguments.forEach((item: ts.Node, index: number) => { +function loopEtscomponent(node: any, isStylesAttr: boolean, isGlobalStyles: boolean): ts.Node { + node.arguments.forEach((item: ts.Node, index: number) => { if (isStylesAttr && isGlobalStyles) { - temp.arguments[index] = traverseStylesAttr(item); + node.arguments[index] = traverseStylesAttr(item); } - if (ts.isNewExpression(item) && item.expression && ts.isEtsComponentExpression( - item.expression)) { - temp.arguments[index] = ts.factory.updateNewExpression(item, item.expression.expression, - undefined, item.expression.arguments); - } else if (ts.isEtsComponentExpression(item)) { - temp.arguments[index] = ts.factory.createCallExpression(item.expression, - undefined, item.arguments); - } else if ((ts.isCallExpression(item) || ts.isNewExpression(item)) && item.expression && - ts.isPropertyAccessExpression(item.expression) && item.expression.expression && - ts.isEtsComponentExpression(item.expression.expression)) { - temp.arguments[index].expression.expression = ts.factory.createCallExpression( - item.expression.expression.expression, undefined, item.expression.expression.arguments); + if (ts.isEtsComponentExpression(item)) { + node.arguments[index] = ts.factory.createCallExpression( + item.expression, undefined, item.arguments); + } else if (ts.isCallExpression(item) || ts.isNewExpression(item)) { + node.arguments[index] = ts.visitEachChild(item, + changeEtsComponentKind, contextGlobal); } }); - return temp; + return node; +} + +function changeEtsComponentKind(node: ts.Node): ts.Node { + if (ts.isEtsComponentExpression(node)) { + node.kind = 204; + return node; + } + return ts.visitEachChild(node, changeEtsComponentKind, contextGlobal); } function classifyArgumentsNum(args: any, argumentsArr: ts.Expression[], propName: string, diff --git a/compiler/tsconfig.json b/compiler/tsconfig.json index b53c39d76c05e42c53b5cbb757738344f306cc7c..4204e142ac5fdf29631994da7ff97713993d7c14 100644 --- a/compiler/tsconfig.json +++ b/compiler/tsconfig.json @@ -30,7 +30,6 @@ "Ellipse", "Flex", "FormComponent", - "FrictionMotion", "Gauge", "GeometryView", "Grid", @@ -68,7 +67,6 @@ "RichText", "Scroll", "ScrollBar", - "ScrollMotion", "Search", "Section", "Select", @@ -212,11 +210,6 @@ "type": "FormComponentAttribute", "instance": "FormComponentInstance" }, - { - "name": "FrictionMotion", - "type": "FrictionMotionAttribute", - "instance": "FrictionMotionInstance" - }, { "name": "Gauge", "type": "GaugeAttribute", @@ -402,11 +395,6 @@ "type": "ScrollBarAttribute", "instance": "ScrollBarInstance" }, - { - "name": "ScrollMotion", - "type": "ScrollMotionAttribute", - "instance": "ScrollMotionInstance" - }, { "name": "Search", "type": "SearchAttribute",