From 267dd5b4574c32e73b06c5a4033d73b5c423cdc8 Mon Sep 17 00:00:00 2001 From: lijuan124 Date: Wed, 27 Jul 2022 09:21:12 +0800 Subject: [PATCH 01/17] add sideBarPosition to sideBar_container attr Signed-off-by: lijuan124 --- compiler/components/sideBar_container.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/components/sideBar_container.json b/compiler/components/sideBar_container.json index e26cdd9..bf9aa24 100644 --- a/compiler/components/sideBar_container.json +++ b/compiler/components/sideBar_container.json @@ -1,6 +1,6 @@ { "name": "SideBarContainer", "attrs": [ - "showSideBar", "controlButton", "showControlButton", "onChange", "sideBarWidth", "minSideBarWidth", "maxSideBarWidth", "autoHide" + "showSideBar", "controlButton", "showControlButton", "onChange", "sideBarWidth", "minSideBarWidth", "maxSideBarWidth", "autoHide", "sideBarPosition" ] } From 9d836f11f5d751aca78982a3ceec6cb578183887 Mon Sep 17 00:00:00 2001 From: pilipala195 Date: Mon, 1 Aug 2022 11:09:40 +0000 Subject: [PATCH 02/17] Web mediaPlayGestureAccess implementation Signed-off-by: yangguangzhao --- compiler/components/web.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/components/web.json b/compiler/components/web.json index a4dc014..c22300d 100644 --- a/compiler/components/web.json +++ b/compiler/components/web.json @@ -9,6 +9,6 @@ "domStorageAccess", "imageAccess", "mixedMode", "zoomAccess", "geolocationAccess", "javaScriptProxy", "userAgent", "onConfirm", "onConsole", "onErrorReceive", "onHttpErrorReceive", "onDownloadStart", "fileFromUrlAccess", "webDebuggingAccess", "onShowFileSelector", "initialScale", "onResourceLoad", "onScaleChange", "onHttpAuthRequest", - "onPermissionRequest", "onContextMenuShow" + "onPermissionRequest", "onContextMenuShow", "mediaPlayGestureAccess" ] } From daa8e5e29b4f6ba8e31853c1970fdb59c2f2b573 Mon Sep 17 00:00:00 2001 From: zhangrengao Date: Thu, 25 Aug 2022 22:28:48 +0800 Subject: [PATCH 03/17] Add sourcefile of module compiler Signed-off-by: zhangrengao Change-Id: Ie252dacee39b9ef1f8ed3dfeda68076593cb4ec9 --- compiler/src/gen_module_abc.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/gen_module_abc.ts b/compiler/src/gen_module_abc.ts index 3490442..1426cee 100644 --- a/compiler/src/gen_module_abc.ts +++ b/compiler/src/gen_module_abc.ts @@ -60,7 +60,7 @@ function es2abcByWorkers(jsonInput: string, cmd: string): Promise { for (let i = 0; i < inputPaths.length; ++i) { const input: string = inputPaths[i].tempFilePath; const abcFile: string = input.replace(/\.js$/, '.abc'); - const singleCmd: any = `${cmd} "${input}" --output "${abcFile}"`; + const singleCmd: any = `${cmd} "${input}" --output "${abcFile}" --source-file "${input}"`; logger.debug('gen abc cmd is: ', singleCmd); try { childProcess.execSync(singleCmd); From 9ccfd135cac956389031553214e51fe498aa2755 Mon Sep 17 00:00:00 2001 From: zhangrengao Date: Fri, 26 Aug 2022 15:28:50 +0800 Subject: [PATCH 04/17] toUnitPath of jsbundle Signed-off-by: zhangrengao Change-Id: Ic6e8e55b86b5982f7131a4f0e783cc867d35fd23 --- compiler/src/gen_abc_plugin.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/compiler/src/gen_abc_plugin.ts b/compiler/src/gen_abc_plugin.ts index a8c4a3a..1c7deb4 100644 --- a/compiler/src/gen_abc_plugin.ts +++ b/compiler/src/gen_abc_plugin.ts @@ -361,6 +361,8 @@ function writeFileSync(inputString: string, output: string, jsBundleFile: string let sufStr: string = output.replace(buildParentPath, ''); let cacheOutputPath: string = ""; if (process.env.cachePath) { + output = toUnixPath(output); + cacheOutputPath = toUnixPath(cacheOutputPath); cacheOutputPath = path.join(process.env.cachePath, TEMPORARY, sufStr); } else { cacheOutputPath = output; From 91bf2e718293636fcea696cce5493fba2557f528 Mon Sep 17 00:00:00 2001 From: zhangrengao Date: Fri, 26 Aug 2022 18:16:43 +0800 Subject: [PATCH 05/17] Fix cachePath is undefined Signed-off-by: zhangrengao Change-Id: Ib127f2f2f71b69602212a0c526bbf0e57dad1519 --- compiler/src/gen_abc_plugin.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/compiler/src/gen_abc_plugin.ts b/compiler/src/gen_abc_plugin.ts index 1c7deb4..fe1be97 100644 --- a/compiler/src/gen_abc_plugin.ts +++ b/compiler/src/gen_abc_plugin.ts @@ -142,6 +142,11 @@ export class GenAbcPlugin { return; } + removeDir(output); + if (projectConfig.compileMode === ESMODULE) { + removeDir(projectConfig.nodeModulesPath); + } + compiler.hooks.compilation.tap('GenAbcPlugin', (compilation) => { if (projectConfig.compileMode === JSBUNDLE || projectConfig.compileMode === undefined) { return; @@ -167,7 +172,6 @@ export class GenAbcPlugin { if (projectConfig.compileMode === ESMODULE) { return; } - removeDir(output); Object.keys(compilation.assets).forEach(key => { // choose *.js if (output && path.extname(key) === EXTNAME_JS) { @@ -361,8 +365,6 @@ function writeFileSync(inputString: string, output: string, jsBundleFile: string let sufStr: string = output.replace(buildParentPath, ''); let cacheOutputPath: string = ""; if (process.env.cachePath) { - output = toUnixPath(output); - cacheOutputPath = toUnixPath(cacheOutputPath); cacheOutputPath = path.join(process.env.cachePath, TEMPORARY, sufStr); } else { cacheOutputPath = output; @@ -374,6 +376,8 @@ function writeFileSync(inputString: string, output: string, jsBundleFile: string fs.writeFileSync(cacheOutputPath, inputString); if (fs.existsSync(cacheOutputPath)) { const fileSize: any = fs.statSync(cacheOutputPath).size; + output = toUnixPath(output); + cacheOutputPath = toUnixPath(cacheOutputPath); intermediateJsBundle.push({path: output, size: fileSize, cacheOutputPath: cacheOutputPath}); } else { logger.error(red, `ETS:ERROR Failed to convert file ${jsBundleFile} to bin. ${output} is lost`, reset); @@ -427,8 +431,6 @@ function splitJsBundlesBySize(bundleArray: Array, groupNumber: number): an } function invokeWorkersModuleToGenAbc(moduleInfos: Array): void { - removeDir(buildPathInfo); - removeDir(projectConfig.nodeModulesPath); invokeCluterModuleToAbc(); } @@ -843,7 +845,7 @@ function writeHashJson(): void { mkdirsSync(path.dirname(abcFile)); fs.copyFileSync(cacheAbcFilePath, abcFile); } - if (fs.existsSync(intermediateJsBundle[i].path)) { + if (process.env.cachePath === undefined && fs.existsSync(intermediateJsBundle[i].path)) { fs.unlinkSync(intermediateJsBundle[i].path); } } From 22de16e58e566d5f25f0d959effdd20a61203c41 Mon Sep 17 00:00:00 2001 From: zhangrengao Date: Fri, 26 Aug 2022 22:07:23 +0800 Subject: [PATCH 06/17] Add clean webpack plugin Signed-off-by: zhangrengao Change-Id: I53c9e91211ad113c8322b7165139522a278fb0f6 --- compiler/src/gen_abc_plugin.ts | 1 - compiler/webpack.config.js | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/compiler/src/gen_abc_plugin.ts b/compiler/src/gen_abc_plugin.ts index fe1be97..5b11e15 100644 --- a/compiler/src/gen_abc_plugin.ts +++ b/compiler/src/gen_abc_plugin.ts @@ -142,7 +142,6 @@ export class GenAbcPlugin { return; } - removeDir(output); if (projectConfig.compileMode === ESMODULE) { removeDir(projectConfig.nodeModulesPath); } diff --git a/compiler/webpack.config.js b/compiler/webpack.config.js index 69a06e7..ebb7678 100644 --- a/compiler/webpack.config.js +++ b/compiler/webpack.config.js @@ -17,6 +17,7 @@ const path = require('path'); const fs = require('fs'); const CopyPlugin = require('copy-webpack-plugin'); const Webpack = require('webpack'); +const { CleanWebpackPlugin } = require('clean-webpack-plugin'); const { GenAbcPlugin } = require('./lib/gen_abc_plugin'); const { OHMResolverPlugin } = require('./lib/resolve_ohm_url'); const buildPipeServer = require('./server/build_pipe_server'); @@ -344,6 +345,25 @@ function setGenAbcPlugin(env, config) { } } +function setCleanWebpackPlugin(workerFile, config) { + let cleanPath = []; + cleanPath.push(projectConfig.buildPath); + if (workerFile) { + let workerFilesPath = Object.keys(workerFile); + for (let workerFilePath of workerFilesPath) { + cleanPath.push(path.join(projectConfig.buildPath, workerFilePath, '..')); + } + } + + config.plugins.push( + new CleanWebpackPlugin({ + dry: false, + dangerouslyAllowCleanPatternsOutsideProject: true, + cleanOnceBeforeBuildPatterns: cleanPath + }) + ); +} + module.exports = (env, argv) => { const config = {}; setProjectConfig(env); @@ -354,6 +374,7 @@ module.exports = (env, argv) => { const workerFile = readWorkerFile(); setOptimizationConfig(config, workerFile); setCopyPluginConfig(config); + setCleanWebpackPlugin(workerFile, config); if (env.isPreview !== "true") { loadWorker(projectConfig, workerFile); From 496022215291862a1746d8ceeb33e226b9955a05 Mon Sep 17 00:00:00 2001 From: zhangrengao Date: Sat, 27 Aug 2022 12:06:19 +0800 Subject: [PATCH 07/17] Fix clean webpack of esmodule Signed-off-by: zhangrengao Change-Id: Id951b6b44c02dd87fa4c519dd87a98cb9c359d74 --- compiler/src/gen_abc_plugin.ts | 1 + compiler/webpack.config.js | 3 +++ 2 files changed, 4 insertions(+) diff --git a/compiler/src/gen_abc_plugin.ts b/compiler/src/gen_abc_plugin.ts index 5b11e15..30dc6c0 100644 --- a/compiler/src/gen_abc_plugin.ts +++ b/compiler/src/gen_abc_plugin.ts @@ -143,6 +143,7 @@ export class GenAbcPlugin { } if (projectConfig.compileMode === ESMODULE) { + removeDir(output); removeDir(projectConfig.nodeModulesPath); } diff --git a/compiler/webpack.config.js b/compiler/webpack.config.js index ebb7678..a9c2391 100644 --- a/compiler/webpack.config.js +++ b/compiler/webpack.config.js @@ -346,6 +346,9 @@ function setGenAbcPlugin(env, config) { } function setCleanWebpackPlugin(workerFile, config) { + if (projectConfig.compileMode === 'esmodule') { + return; + } let cleanPath = []; cleanPath.push(projectConfig.buildPath); if (workerFile) { From 36835b2295abaa341921d66653f0de37ec22b94e Mon Sep 17 00:00:00 2001 From: yfwang6 Date: Sat, 27 Aug 2022 10:41:32 +0800 Subject: [PATCH 08/17] wangyongfei6@huawei.com watch callback do not trigger Signed-off-by: yfwang6 Change-Id: I638e4b1cf0c4c8af9f41071a4e8f5feee4c788c0 --- compiler/src/pre_define.ts | 5 ++--- compiler/src/process_component_constructor.ts | 2 +- compiler/src/process_component_member.ts | 9 +++------ 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/compiler/src/pre_define.ts b/compiler/src/pre_define.ts index a1698ab..a1cfde8 100644 --- a/compiler/src/pre_define.ts +++ b/compiler/src/pre_define.ts @@ -68,9 +68,8 @@ export const INITIALIZE_CONSUME_FUNCTION: string = 'initializeConsume'; export const ADD_PROVIDED_VAR: string = 'addProvidedVar'; export const APP_STORAGE: string = 'AppStorage'; -export const APP_STORAGE_SET_AND_PROP: string = 'setAndProp'; -export const APP_STORAGE_SET_AND_LINK: string = 'setAndLink'; -export const APP_STORAGE_GET_OR_SET: string = 'GetOrCreate'; +export const APP_STORAGE_SET_AND_PROP: string = 'SetAndProp'; +export const APP_STORAGE_SET_AND_LINK: string = 'SetAndLink'; export const PAGE_ENTRY_FUNCTION_NAME: string = 'loadDocument'; export const STORE_PREVIEW_COMPONENTS: string = 'storePreviewComponents'; diff --git a/compiler/src/process_component_constructor.ts b/compiler/src/process_component_constructor.ts index 469c6c4..5b04845 100644 --- a/compiler/src/process_component_constructor.ts +++ b/compiler/src/process_component_constructor.ts @@ -168,5 +168,5 @@ export function addConstructor(ctorNode: any, watchMap: Map, ts.factory.createThis(), ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_UPDATE_PARAMS)), undefined, [ts.factory.createIdentifier(COMPONENT_CONSTRUCTOR_PARAMS)])); return updateConstructor(updateConstructor(ctorNode, [], [callSuperStatement], true), [], - [updateWithValueParamsStatement, ...watchStatements], false, true, parentComponentName); + [...watchStatements, updateWithValueParamsStatement], false, true, parentComponentName); } diff --git a/compiler/src/process_component_member.ts b/compiler/src/process_component_member.ts index 010712f..e1461c5 100644 --- a/compiler/src/process_component_member.ts +++ b/compiler/src/process_component_member.ts @@ -44,7 +44,6 @@ import { APP_STORAGE, APP_STORAGE_SET_AND_PROP, APP_STORAGE_SET_AND_LINK, - APP_STORAGE_GET_OR_SET, COMPONENT_CONSTRUCTOR_UNDEFINED, SET_CONTROLLER_METHOD, SET_CONTROLLER_CTR, @@ -509,11 +508,9 @@ function updateStoragePropAndLinkProperty(node: ts.PropertyDeclaration, name: ts return ts.factory.createExpressionStatement(ts.factory.createBinaryExpression( createPropertyAccessExpressionWithThis(`__${name.getText()}`), ts.factory.createToken(ts.SyntaxKind.EqualsToken), ts.factory.createCallExpression( - ts.factory.createPropertyAccessExpression(ts.factory.createCallExpression( - ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier(APP_STORAGE), - ts.factory.createIdentifier(APP_STORAGE_GET_OR_SET)), undefined, []), - ts.factory.createIdentifier(setFuncName)), undefined, [node.decorators[0].expression.arguments[0], - node.initializer, ts.factory.createThis()]))); + ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier(APP_STORAGE), + ts.factory.createIdentifier(setFuncName)), undefined, [node.decorators[0].expression.arguments[0], + node.initializer, ts.factory.createThis(), ts.factory.createStringLiteral(name.getText())]))); } else { validateAppStorageDecoractorsNonSingleKey(node, log); } From 74fcfa45734a8b70132cf3568d2f63dfd73fab51 Mon Sep 17 00:00:00 2001 From: yfwang6 Date: Mon, 29 Aug 2022 16:50:27 +0800 Subject: [PATCH 09/17] wangyongfei6@huawei.com ut for @watch do not work issue Signed-off-by: yfwang6 Change-Id: I552c9c470010c8d40d7102f6f1f216fce9261d3e --- .../application_state_management/@storageLink/@storageLink.ts | 4 ++-- .../application_state_management/@storageProp/@storageProp.ts | 4 ++-- .../application_state_management/appStorage/appStorage.ts | 4 ++-- compiler/test/ut/ui_state_management/others/@watch/@watch.ts | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/compiler/test/ut/ui_state_management/application_state_management/@storageLink/@storageLink.ts b/compiler/test/ut/ui_state_management/application_state_management/@storageLink/@storageLink.ts index ccfbbab..8671287 100644 --- a/compiler/test/ut/ui_state_management/application_state_management/@storageLink/@storageLink.ts +++ b/compiler/test/ut/ui_state_management/application_state_management/@storageLink/@storageLink.ts @@ -57,8 +57,8 @@ let envLang = AppStorage.Prop('languageCode'); class MyComponent extends View { constructor(compilerAssignedUniqueChildId, parent, params) { super(compilerAssignedUniqueChildId, parent); - this.__varA = AppStorage.GetOrCreate().setAndLink('varA', 2, this); - this.__lang = AppStorage.GetOrCreate().setAndProp('languageCode', 'en', this); + this.__varA = AppStorage.SetAndLink('varA', 2, this, "varA"); + this.__lang = AppStorage.SetAndProp('languageCode', 'en', this, "lang"); this.label = 'count'; this.updateWithValueParams(params); } diff --git a/compiler/test/ut/ui_state_management/application_state_management/@storageProp/@storageProp.ts b/compiler/test/ut/ui_state_management/application_state_management/@storageProp/@storageProp.ts index b37354d..24ac7c5 100644 --- a/compiler/test/ut/ui_state_management/application_state_management/@storageProp/@storageProp.ts +++ b/compiler/test/ut/ui_state_management/application_state_management/@storageProp/@storageProp.ts @@ -57,8 +57,8 @@ let envLang = AppStorage.Prop('languageCode'); class MyComponent extends View { constructor(compilerAssignedUniqueChildId, parent, params) { super(compilerAssignedUniqueChildId, parent); - this.__varA = AppStorage.GetOrCreate().setAndLink('varA', 2, this); - this.__lang = AppStorage.GetOrCreate().setAndProp('languageCode', 'en', this); + this.__varA = AppStorage.SetAndLink('varA', 2, this, "varA"); + this.__lang = AppStorage.SetAndProp('languageCode', 'en', this, "lang"); this.label = 'count'; this.updateWithValueParams(params); } diff --git a/compiler/test/ut/ui_state_management/application_state_management/appStorage/appStorage.ts b/compiler/test/ut/ui_state_management/application_state_management/appStorage/appStorage.ts index 39f2aa9..00804ec 100644 --- a/compiler/test/ut/ui_state_management/application_state_management/appStorage/appStorage.ts +++ b/compiler/test/ut/ui_state_management/application_state_management/appStorage/appStorage.ts @@ -57,8 +57,8 @@ let envLang = AppStorage.Prop('languageCode'); class MyComponent extends View { constructor(compilerAssignedUniqueChildId, parent, params) { super(compilerAssignedUniqueChildId, parent); - this.__varA = AppStorage.GetOrCreate().setAndLink('varA', 2, this); - this.__lang = AppStorage.GetOrCreate().setAndProp('languageCode', 'en', this); + this.__varA = AppStorage.SetAndLink('varA', 2, this, "varA"); + this.__lang = AppStorage.SetAndProp('languageCode', 'en', this, "lang"); this.label = 'count'; this.updateWithValueParams(params); } diff --git a/compiler/test/ut/ui_state_management/others/@watch/@watch.ts b/compiler/test/ut/ui_state_management/others/@watch/@watch.ts index 618a3be..c9b3ce6 100644 --- a/compiler/test/ut/ui_state_management/others/@watch/@watch.ts +++ b/compiler/test/ut/ui_state_management/others/@watch/@watch.ts @@ -76,9 +76,9 @@ class CompA extends View { this.__totalPurchase = new ObservedPropertySimple(0, this, "totalPurchase"); this.__defArray = new ObservedPropertyObject(['c', 'g', 't', 'z'], this, "defArray"); this.__resultTip = new ObservedPropertySimple('', this, "resultTip"); - this.updateWithValueParams(params); this.declareWatch("shopBasket", this.onBasketUpdated); this.declareWatch("defArray", this.onPutItem); + this.updateWithValueParams(params); } updateWithValueParams(params) { if (params.shopBasket !== undefined) { From 7ed1f988edfaf5fd3b6ca089a0acc37ae80b3247 Mon Sep 17 00:00:00 2001 From: zhangrengao Date: Mon, 29 Aug 2022 15:08:41 +0800 Subject: [PATCH 10/17] Fix process extra asst of jsbundle Signed-off-by: zhangrengao Change-Id: I4df117e9bb6ff57b6b30b54523e80d520657df2a --- compiler/src/gen_abc.ts | 8 ++-- compiler/src/gen_abc_plugin.ts | 85 ++++++++++++++++++---------------- 2 files changed, 48 insertions(+), 45 deletions(-) diff --git a/compiler/src/gen_abc.ts b/compiler/src/gen_abc.ts index 6dbb3cf..83f79f8 100644 --- a/compiler/src/gen_abc.ts +++ b/compiler/src/gen_abc.ts @@ -31,9 +31,9 @@ const reset: string = '\u001b[39m'; function js2abcByWorkers(jsonInput: string, cmd: string): Promise { const inputPaths: any = JSON.parse(jsonInput); for (let i = 0; i < inputPaths.length; ++i) { - const input: string = inputPaths[i].path; + const input: string = inputPaths[i].path.replace(/\.temp\.js$/, "_.js"); const cacheOutputPath: string = inputPaths[i].cacheOutputPath; - const cacheAbcFilePath: string = cacheOutputPath.replace(/\_.js$/, ".abc"); + const cacheAbcFilePath: string = cacheOutputPath.replace(/\.temp\.js$/, ".abc"); const singleCmd: any = `${cmd} "${cacheOutputPath}" -o "${cacheAbcFilePath}" --source-file "${input}"`; logger.debug('gen abc cmd is: ', singleCmd, ' ,file size is:', inputPaths[i].size, ' byte'); try { @@ -50,9 +50,9 @@ function js2abcByWorkers(jsonInput: string, cmd: string): Promise { function es2abcByWorkers(jsonInput: string, cmd: string): Promise { const inputPaths: any = JSON.parse(jsonInput); for (let i = 0; i < inputPaths.length; ++i) { - const input: string = inputPaths[i].path; + const input: string = inputPaths[i].path.replace(/\.temp\.js$/, "_.js"); const cacheOutputPath: string = inputPaths[i].cacheOutputPath; - const cacheAbcFilePath: string = cacheOutputPath.replace(/\_.js$/, ".abc"); + const cacheAbcFilePath: string = cacheOutputPath.replace(/\.temp\.js$/, ".abc"); const singleCmd: any = `${cmd} "${cacheOutputPath}" --output "${cacheAbcFilePath}" --source-file "${input}"`; logger.debug('gen abc cmd is: ', singleCmd, ' ,file size is:', inputPaths[i].size, ' byte'); try { diff --git a/compiler/src/gen_abc_plugin.ts b/compiler/src/gen_abc_plugin.ts index 30dc6c0..a0363d8 100644 --- a/compiler/src/gen_abc_plugin.ts +++ b/compiler/src/gen_abc_plugin.ts @@ -52,7 +52,6 @@ import { TEMPORARY } from './pre_define'; -const firstFileEXT: string = '_.js'; const genAbcScript: string = 'gen_abc.js'; const genModuleAbcScript: string = 'gen_module_abc.js'; let output: string; @@ -176,8 +175,8 @@ export class GenAbcPlugin { // choose *.js if (output && path.extname(key) === EXTNAME_JS) { const newContent: string = compilation.assets[key].source(); - const keyPath: string = key.replace(/\.js$/, firstFileEXT); - writeFileSync(newContent, path.resolve(output, keyPath), key); + const keyPath: string = key.replace(/\.js$/, ".temp.js"); + writeFileSync(newContent, output, keyPath, key); } }); }); @@ -356,16 +355,15 @@ function processEntryToGenAbc(entryInfos: Map): void { } } -function writeFileSync(inputString: string, output: string, jsBundleFile: string): void { +function writeFileSync(inputString: string, buildPath: string, keyPath: string, jsBundleFile: string): void { + let output = path.resolve(buildPath, keyPath); let parent: string = path.join(output, '..'); if (!(fs.existsSync(parent) && fs.statSync(parent).isDirectory())) { mkDir(parent); } - let buildParentPath: string = path.join(projectConfig.buildPath, '..'); - let sufStr: string = output.replace(buildParentPath, ''); let cacheOutputPath: string = ""; if (process.env.cachePath) { - cacheOutputPath = path.join(process.env.cachePath, TEMPORARY, sufStr); + cacheOutputPath = path.join(process.env.cachePath, TEMPORARY, keyPath); } else { cacheOutputPath = output; } @@ -647,9 +645,9 @@ function invokeWorkersToGenAbc(): void { } count_++; if (count_ === workerNumber) { - writeHashJson(); - clearGlobalInfo(); + // for preview of with incre compile if (projectConfig.isPreview) { + processExtraAssetForBundle(); console.info(red, 'COMPILE RESULT:SUCCESS ', reset); } } @@ -657,13 +655,14 @@ function invokeWorkersToGenAbc(): void { }); process.on('exit', (code) => { - intermediateJsBundle.forEach((item) => { - const input = item.path; - if (fs.existsSync(input)) { - fs.unlinkSync(input); - } - }); + // for build options + processExtraAssetForBundle(); }); + + // for preview of without incre compile + if (workerNumber === 0 && projectConfig.isPreview) { + processExtraAssetForBundle(); + } } } @@ -786,10 +785,8 @@ function filterIntermediateJsBundleByHashJson(buildPath: string, inputPaths: Fil jsonObject = JSON.parse(jsonFile); fileterIntermediateJsBundle = []; for (let i = 0; i < inputPaths.length; ++i) { - const input: string = inputPaths[i].path; - const abcPath: string = input.replace(/_.js$/, EXTNAME_ABC); const cacheOutputPath: string = inputPaths[i].cacheOutputPath; - const cacheAbcFilePath: string = cacheOutputPath.replace(/\_.js$/, '.abc'); + const cacheAbcFilePath: string = cacheOutputPath.replace(/\.temp\.js$/, '.abc'); if (!fs.existsSync(cacheOutputPath)) { logger.error(red, `ETS:ERROR ${cacheOutputPath} is lost`, reset); process.exitCode = FAIL; @@ -801,10 +798,6 @@ function filterIntermediateJsBundleByHashJson(buildPath: string, inputPaths: Fil if (jsonObject[cacheOutputPath] === hashInputContentData && jsonObject[cacheAbcFilePath] === hashAbcContentData) { updateJsonObject[cacheOutputPath] = hashInputContentData; updateJsonObject[cacheAbcFilePath] = hashAbcContentData; - if (!fs.existsSync(abcPath)) { - mkdirsSync(path.dirname(abcPath)); - fs.copyFileSync(cacheAbcFilePath, abcPath); - } } else { fileterIntermediateJsBundle.push(inputPaths[i]); } @@ -819,10 +812,8 @@ function filterIntermediateJsBundleByHashJson(buildPath: string, inputPaths: Fil function writeHashJson(): void { for (let i = 0; i < fileterIntermediateJsBundle.length; ++i) { - const input:string = fileterIntermediateJsBundle[i].path; - const abcPath: string = input.replace(/_.js$/, EXTNAME_ABC); const cacheOutputPath: string = fileterIntermediateJsBundle[i].cacheOutputPath; - const cacheAbcFilePath: string = cacheOutputPath.replace(/\_.js$/, '.abc'); + const cacheAbcFilePath: string = cacheOutputPath.replace(/\.temp\.js$/, '.abc'); if (!fs.existsSync(cacheOutputPath) || !fs.existsSync(cacheAbcFilePath)) { logger.error(red, `ETS:ERROR ${cacheOutputPath} is lost`, reset); process.exitCode = FAIL; @@ -833,22 +824,6 @@ function writeHashJson(): void { hashJsonObject[cacheOutputPath] = hashInputContentData; hashJsonObject[cacheAbcFilePath] = hashAbcContentData; } - for (let i = 0; i < intermediateJsBundle.length; ++i) { - const abcFile: string = intermediateJsBundle[i].path.replace(/\_.js$/, ".abc"); - const cacheAbcFilePath: string = intermediateJsBundle[i].cacheOutputPath.replace(/\_.js$/, ".abc"); - if (!fs.existsSync(cacheAbcFilePath)) { - logger.error(red, `ETS:ERROR ${cacheAbcFilePath} is lost`, reset); - process.exitCode = FAIL; - break; - } - if (!fs.existsSync(abcFile)) { - mkdirsSync(path.dirname(abcFile)); - fs.copyFileSync(cacheAbcFilePath, abcFile); - } - if (process.env.cachePath === undefined && fs.existsSync(intermediateJsBundle[i].path)) { - fs.unlinkSync(intermediateJsBundle[i].path); - } - } const hashFilePath: string = genHashJsonPath(buildPathInfo); if (hashFilePath.length === 0) { return; @@ -899,3 +874,31 @@ function checkNodeModules() { return true; } + +function copyFileCachePathToBuildPath() { + for (let i = 0; i < intermediateJsBundle.length; ++i) { + const abcFile: string = intermediateJsBundle[i].path.replace(/\.temp\.js$/, ".abc"); + const cacheOutputPath: string = intermediateJsBundle[i].cacheOutputPath; + const cacheAbcFilePath: string = intermediateJsBundle[i].cacheOutputPath.replace(/\.temp\.js$/, ".abc"); + if (!fs.existsSync(cacheAbcFilePath)) { + logger.error(red, `ETS:ERROR ${cacheAbcFilePath} is lost`, reset); + break; + } + let parent: string = path.join(abcFile, '..'); + if (!(fs.existsSync(parent) && fs.statSync(parent).isDirectory())) { + mkDir(parent); + } + if (!fs.existsSync(abcFile)) { + fs.copyFileSync(cacheAbcFilePath, abcFile); + } + if (process.env.cachePath === undefined && fs.existsSync(cacheOutputPath)) { + fs.unlinkSync(cacheOutputPath); + } + } +} + +function processExtraAssetForBundle() { + writeHashJson(); + copyFileCachePathToBuildPath(); + clearGlobalInfo(); +} \ No newline at end of file From 1be006c421af8f1bc8b3b55f806103c5f52e6b1b Mon Sep 17 00:00:00 2001 From: zhangrengao Date: Mon, 29 Aug 2022 15:13:23 +0800 Subject: [PATCH 11/17] Fix preview of fail, then modify code Signed-off-by: zhangrengao Change-Id: I5941036210ff535283fcc4bc5fd419f87b4a10ab --- compiler/src/gen_abc_plugin.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/compiler/src/gen_abc_plugin.ts b/compiler/src/gen_abc_plugin.ts index a0363d8..196d489 100644 --- a/compiler/src/gen_abc_plugin.ts +++ b/compiler/src/gen_abc_plugin.ts @@ -49,7 +49,8 @@ import { EXTNAME_JS_MAP, TS2ABC, ES2ABC, - TEMPORARY + TEMPORARY, + SUCCESS } from './pre_define'; const genAbcScript: string = 'gen_abc.js'; @@ -472,6 +473,9 @@ function initAbcEnv() : string[] { } function invokeCluterModuleToAbc(): void { + if (projectConfig.isPreview) { + process.exitCode = SUCCESS; + } filterIntermediateModuleByHashJson(buildPathInfo, moduleInfos); filterModuleInfos.forEach(moduleInfo => { if (moduleInfo.isCommonJs) { @@ -597,6 +601,9 @@ function judgeModuleWorkersToGenAbc(callback): void { } function invokeWorkersToGenAbc(): void { + if (projectConfig.isPreview) { + process.exitCode = SUCCESS; + } let cmdPrefix: string = ''; let maxWorkerNumber: number = 3; @@ -888,7 +895,8 @@ function copyFileCachePathToBuildPath() { if (!(fs.existsSync(parent) && fs.statSync(parent).isDirectory())) { mkDir(parent); } - if (!fs.existsSync(abcFile)) { + // for preview mode, cache path and old abc file both exist, should copy abc file for updating + if (process.env.cachePath !== undefined) { fs.copyFileSync(cacheAbcFilePath, abcFile); } if (process.env.cachePath === undefined && fs.existsSync(cacheOutputPath)) { From e5ee0637fc9ac292b4bfe9692bfbbb9507d9605a Mon Sep 17 00:00:00 2001 From: hufeng Date: Tue, 30 Aug 2022 22:18:11 +0800 Subject: [PATCH 12/17] Adapt to compileing as merged abc Description: 1. Fix node_modules level of sub-node_modules 2. Generate js files to cache-dir & map files to build-dir 3. 3. Excute es2abc asynchronized Issue: https://e.gitee.com/open_harmony/dashboard?issue=I5MYM9 Signed-off-by: hufeng Change-Id: I850b81c2986e394129e125a181832a5548512644 --- compiler/main.js | 1 + compiler/src/gen_abc.ts | 1 - compiler/src/gen_abc_plugin.ts | 98 +++++++++++++++++++------ compiler/src/gen_merged_abc.ts | 88 ++++++++++++++++++++++ compiler/src/pre_define.ts | 9 ++- compiler/src/process_js_ast.ts | 4 +- compiler/src/process_js_file.ts | 2 +- compiler/src/resolve_ohm_url.ts | 39 ++++++++++ compiler/src/utils.ts | 114 +++++++++++++++++++++++------ compiler/src/validate_ui_syntax.ts | 37 +--------- 10 files changed, 309 insertions(+), 84 deletions(-) create mode 100644 compiler/src/gen_merged_abc.ts diff --git a/compiler/main.js b/compiler/main.js index 5d56baa..d9de016 100644 --- a/compiler/main.js +++ b/compiler/main.js @@ -374,6 +374,7 @@ function loadModuleInfo(projectConfig, envArgs) { projectConfig.modulePathMap = buildJsonInfo.modulePathMap; projectConfig.isOhosTest = buildJsonInfo.isOhosTest; projectConfig.processTs = false; + projectConfig.processMergeabc = false; projectConfig.buildArkMode = envArgs.buildMode; if (buildJsonInfo.compileMode === 'esmodule') { projectConfig.nodeModulesPath = buildJsonInfo.nodeModulesPath; diff --git a/compiler/src/gen_abc.ts b/compiler/src/gen_abc.ts index 83f79f8..0ba2c02 100644 --- a/compiler/src/gen_abc.ts +++ b/compiler/src/gen_abc.ts @@ -15,7 +15,6 @@ import * as childProcess from 'child_process'; import * as process from 'process'; -import * as fs from 'fs'; import cluster from 'cluster'; import { logger } from './compile_info'; import { diff --git a/compiler/src/gen_abc_plugin.ts b/compiler/src/gen_abc_plugin.ts index 196d489..4090838 100644 --- a/compiler/src/gen_abc_plugin.ts +++ b/compiler/src/gen_abc_plugin.ts @@ -44,14 +44,16 @@ import { EXTNAME_MJS, EXTNAME_CJS, EXTNAME_D_TS, - EXTNAME_ABC, FAIL, EXTNAME_JS_MAP, TS2ABC, ES2ABC, TEMPORARY, - SUCCESS + SUCCESS, + MODULELIST_JSON } from './pre_define'; +import { getOhmUrlByFilepath } from './resolve_ohm_url'; +import { generateMergedAbc } from './gen_merged_abc'; const genAbcScript: string = 'gen_abc.js'; const genModuleAbcScript: string = 'gen_module_abc.js'; @@ -78,6 +80,7 @@ let entryInfos: Map = new Map(); let hashJsonObject = {}; let moduleHashJsonObject = {}; let buildPathInfo: string = ''; +let buildMapFileList: Array = []; const red: string = '\u001b[31m'; const reset: string = '\u001b[39m'; @@ -85,12 +88,13 @@ const blue = '\u001b[34m'; const hashFile: string = 'gen_hash.json'; const ARK: string = '/ark/'; -class ModuleInfo { +export class ModuleInfo { filePath: string; tempFilePath: string; buildFilePath: string; abcFilePath: string; isCommonJs: boolean; + recordName: string; constructor(filePath: string, tempFilePath: string, buildFilePath: string, abcFilePath: string, isCommonJs: boolean) { this.filePath = filePath; @@ -98,10 +102,11 @@ class ModuleInfo { this.buildFilePath = buildFilePath; this.abcFilePath = abcFilePath; this.isCommonJs = isCommonJs; + this.recordName = getOhmUrlByFilepath(filePath); } } -class EntryInfo { +export class EntryInfo { npmInfo: string; abcFileName: string; buildPath: string; @@ -142,9 +147,15 @@ export class GenAbcPlugin { return; } + // case ESMODULE + // | --- merge -- debug -- not removeDir + // | --- merge -- release -- removeDir + // | --- unmerge -- removeDir if (projectConfig.compileMode === ESMODULE) { - removeDir(output); - removeDir(projectConfig.nodeModulesPath); + if (!projectConfig.processMergeabc || projectConfig.buildArkMode !== 'debug') { + removeDir(output); + removeDir(projectConfig.nodeModulesPath); + } } compiler.hooks.compilation.tap('GenAbcPlugin', (compilation) => { @@ -254,8 +265,7 @@ function processNodeModulesFile(filePath: string, tempFilePath: string, buildFil moduleInfos.push(tempModuleInfo); nodeModulesFile.push(tempFilePath); } - - return; + buildMapFileList.push(genSourceMapFileName(buildFilePath)); } function processEtsModule(filePath: string, tempFilePath: string, buildFilePath: string, nodeModulesFile: Array, module: any): void { @@ -273,6 +283,7 @@ function processEtsModule(filePath: string, tempFilePath: string, buildFilePath: const tempModuleInfo: ModuleInfo = new ModuleInfo(filePath, tempFilePath, buildFilePath, abcFilePath, false); moduleInfos.push(tempModuleInfo); } + buildMapFileList.push(genSourceMapFileName(buildFilePath)); } function processDtsModule(filePath: string, tempFilePath: string, buildFilePath: string, nodeModulesFile: Array, module: any): void { @@ -291,6 +302,7 @@ function processTsModule(filePath: string, tempFilePath: string, buildFilePath: const tempModuleInfo: ModuleInfo = new ModuleInfo(filePath, tempFilePath, buildFilePath, abcFilePath, false); moduleInfos.push(tempModuleInfo); } + buildMapFileList.push(genSourceMapFileName(buildFilePath)); } function processJsModule(filePath: string, tempFilePath: string, buildFilePath: string, nodeModulesFile: Array, module: any): void { @@ -308,6 +320,39 @@ function processJsModule(filePath: string, tempFilePath: string, buildFilePath: const tempModuleInfo: ModuleInfo = new ModuleInfo(filePath, tempFilePath, buildFilePath, abcFilePath, false); moduleInfos.push(tempModuleInfo); } + buildMapFileList.push(genSourceMapFileName(buildFilePath)); +} + + +function getCachedModuleList(): Array { + const CACHED_MODULELIST_FILE: string = path.join(process.env.cachePath, MODULELIST_JSON); + if (!fs.existsSync(CACHED_MODULELIST_FILE)) { + return []; + } + const data: any = JSON.parse(fs.readFileSync(CACHED_MODULELIST_FILE).toString()); + const moduleList: Array = data.list; + return moduleList; +} + +function updateCachedModuleList(moduleList: Array): void { + const CACHED_MODULELIST_FILE: string = path.join(process.env.cachePath, MODULELIST_JSON); + let cachedJson: Object = {}; + cachedJson["list"] = moduleList; + fs.writeFile(CACHED_MODULELIST_FILE, JSON.stringify(cachedJson, null, 2), 'utf-8', + (err)=>{ + if (err) { + logger.error(red, `ETS:ERROR Failed to write module list.`, reset); + } + } + ); +} + +function eliminateUnusedFiles(moduleList: Array): void{ + let cachedModuleList: Array = getCachedModuleList(); + if (cachedModuleList.length !== 0) { + const eliminateFiles: Array = cachedModuleList.filter(m => !moduleList.includes(m)); + eliminateFiles.forEach((file) => {fs.unlinkSync(file);}); + } } function handleFinishModules(modules, callback): any { @@ -337,8 +382,16 @@ function handleFinishModules(modules, callback): any { } }); - judgeModuleWorkersToGenAbc(invokeWorkersModuleToGenAbc); - processEntryToGenAbc(entryInfos); + if (projectConfig.processMergeabc) { + if (projectConfig.buildArkMode === 'debug') { + eliminateUnusedFiles(buildMapFileList); + updateCachedModuleList(buildMapFileList); + } + generateMergedAbc(moduleInfos, entryInfos); + } else { + judgeModuleWorkersToGenAbc(invokeWorkersModuleToGenAbc); + processEntryToGenAbc(entryInfos); + } } function processEntryToGenAbc(entryInfos: Map): void { @@ -433,7 +486,7 @@ function invokeWorkersModuleToGenAbc(moduleInfos: Array): void { invokeCluterModuleToAbc(); } -function initAbcEnv() : string[] { +export function initAbcEnv() : string[] { let args: string[] = []; if (process.env.panda === TS2ABC) { let js2abc: string = path.join(arkDir, 'build', 'src', 'index.js'); @@ -465,6 +518,9 @@ function initAbcEnv() : string[] { if (isDebug) { args.push('--debug-info'); } + if (projectConfig.processMergeabc) { + args.push('--merge-abc'); + } } else { logger.error(red, `ETS:ERROR please set panda module`, reset); } @@ -701,18 +757,18 @@ function filterIntermediateModuleByHashJson(buildPath: string, moduleInfos: Arra filterModuleInfos = []; for (let i = 0; i < moduleInfos.length; ++i) { const input: string = moduleInfos[i].tempFilePath; - const abcPath: string = moduleInfos[i].abcFilePath; + let outputPath: string = moduleInfos[i].abcFilePath; if (!fs.existsSync(input)) { logger.error(red, `ETS:ERROR ${input} is lost`, reset); process.exitCode = FAIL; break; } - if (fs.existsSync(abcPath)) { + if (fs.existsSync(outputPath)) { const hashInputContentData: any = toHashData(input); - const hashAbcContentData: any = toHashData(abcPath); - if (jsonObject[input] === hashInputContentData && jsonObject[abcPath] === hashAbcContentData) { + const hashAbcContentData: any = toHashData(outputPath); + if (jsonObject[input] === hashInputContentData && jsonObject[outputPath] === hashAbcContentData) { updateJsonObject[input] = hashInputContentData; - updateJsonObject[abcPath] = hashAbcContentData; + updateJsonObject[outputPath] = hashAbcContentData; mkdirsSync(path.dirname(moduleInfos[i].buildFilePath)); if (projectConfig.buildArkMode === 'debug' && fs.existsSync(moduleInfos[i].tempFilePath)) { fs.copyFileSync(moduleInfos[i].tempFilePath, moduleInfos[i].buildFilePath); @@ -736,16 +792,16 @@ function filterIntermediateModuleByHashJson(buildPath: string, moduleInfos: Arra function writeModuleHashJson(): void { for (let i = 0; i < filterModuleInfos.length; ++i) { const input: string = filterModuleInfos[i].tempFilePath; - const abcPath: string = filterModuleInfos[i].abcFilePath; - if (!fs.existsSync(input) || !fs.existsSync(abcPath)) { + let outputPath: string = filterModuleInfos[i].abcFilePath; + if (!fs.existsSync(input) || !fs.existsSync(outputPath)) { logger.error(red, `ETS:ERROR ${input} is lost`, reset); process.exitCode = FAIL; break; } const hashInputContentData: any = toHashData(input); - const hashAbcContentData: any = toHashData(abcPath); + const hashAbcContentData: any = toHashData(outputPath); moduleHashJsonObject[input] = hashInputContentData; - moduleHashJsonObject[abcPath] = hashAbcContentData; + moduleHashJsonObject[outputPath] = hashAbcContentData; mkdirsSync(path.dirname(filterModuleInfos[i].buildFilePath)); if (projectConfig.buildArkMode === 'debug' && fs.existsSync(filterModuleInfos[i].tempFilePath)) { fs.copyFileSync(filterModuleInfos[i].tempFilePath, filterModuleInfos[i].buildFilePath); @@ -909,4 +965,4 @@ function processExtraAssetForBundle() { writeHashJson(); copyFileCachePathToBuildPath(); clearGlobalInfo(); -} \ No newline at end of file +} diff --git a/compiler/src/gen_merged_abc.ts b/compiler/src/gen_merged_abc.ts new file mode 100644 index 0000000..974eb3a --- /dev/null +++ b/compiler/src/gen_merged_abc.ts @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import * as fs from 'fs'; +import * as path from 'path'; +import * as os from 'os'; +import * as childProcess from 'child_process'; +import * as process from 'process'; +import { logger } from './compile_info'; +import { projectConfig } from '../main'; +import { + FAIL, + FILESINFO_TXT, + MODULES_ABC, + MODULES_CACHE, + NPMENTRIES_TXT, + NODE_MODULES +} from './pre_define'; +import { EntryInfo, ModuleInfo, initAbcEnv } from './gen_abc_plugin'; +import { mkdirsSync, toUnixPath } from './utils'; + +const red: string = '\u001b[31m'; +const reset: string = '\u001b[39m'; + +function generateCompileFilesInfo(moduleInfos: Array) { + const filesInfoPath: string = path.join(process.env.cachePath, FILESINFO_TXT); + let filesInfo: string = ''; + moduleInfos.forEach(info => { + const moduleType: string = info.isCommonJs ? 'cjs' : 'esm'; + filesInfo += `${info.tempFilePath};${info.recordName};${moduleType}\n`; + }); + fs.writeFileSync(filesInfoPath, filesInfo, 'utf-8'); +} + +function generateNpmEntriesInfo(entryInfos: Map) { + const npmEntriesInfoPath: string = path.join(process.env.cachePath, NPMENTRIES_TXT); + let entriesInfo: string = ''; + for (const value of entryInfos.values()) { + const buildPath: string = value.buildPath.replace(toUnixPath(projectConfig.nodeModulesPath), ''); + const entryFile: string = toUnixPath(path.join(buildPath, value.entry)); + const entry: string = entryFile.substring(0, entryFile.lastIndexOf('.')); + entriesInfo += + `${toUnixPath(path.join(NODE_MODULES, buildPath))}:${toUnixPath(path.join(NODE_MODULES, entry))}\n`; + } + fs.writeFileSync(npmEntriesInfoPath, entriesInfo, 'utf-8'); +} + +export function generateMergedAbc(moduleInfos: Array, entryInfos: Map) { + generateCompileFilesInfo(moduleInfos); + generateNpmEntriesInfo(entryInfos); + + const filesInfoPath: string = path.join(process.env.cachePath, FILESINFO_TXT); + const npmEntriesInfoPath: string = path.join(process.env.cachePath, NPMENTRIES_TXT); + const cacheFilePath: string = path.join(process.env.cachePath, MODULES_CACHE); + const outputABCPath: string = path.join(projectConfig.buildPath, MODULES_ABC); + const fileThreads = os.cpus().length < 16 ? os.cpus().length : 16; + mkdirsSync(projectConfig.buildPath); + const gen_abc_cmd: string = + `${initAbcEnv().join(' ')} "@${filesInfoPath}" --npm-module-entry-list "${npmEntriesInfoPath}" --cache-file "${cacheFilePath}" --output "${outputABCPath}" --file-threads "${fileThreads}"`; + logger.debug('gen abc cmd is: ', gen_abc_cmd); + try { + const child = childProcess.exec(gen_abc_cmd); + child.on('exit', (code: any) => { + if (code === 1) { + logger.error(red, "ETS:ERROR failed to execute es2abc", reset); + } + }); + + child.on('error', (err: any) => { + logger.error(red, err.toString(), reset); + }); + } catch (e) { + logger.error(red, `ETS:ERROR failed to generate abc with filesInfo ${filesInfoPath} `, reset); + process.exit(FAIL); + } +} \ No newline at end of file diff --git a/compiler/src/pre_define.ts b/compiler/src/pre_define.ts index a1698ab..39439a7 100644 --- a/compiler/src/pre_define.ts +++ b/compiler/src/pre_define.ts @@ -243,9 +243,15 @@ export const COMPONENT_TOGGLE: string = 'Toggle'; export const TTOGGLE_CHECKBOX: string = 'Checkbox'; export const TOGGLE_SWITCH: string = 'Switch'; +export const ENTRY_TXT: string = 'entry.txt'; +export const FILESINFO_TXT: string = 'filesInfo.txt'; +export const NPMENTRIES_TXT: string = 'npmEntries.txt'; +export const MODULES_CACHE: string = 'modules.cache'; +export const MODULES_ABC: string = 'modules.abc'; +export const MODULELIST_JSON: string = 'moduleList.json'; + export const ESMODULE: string = 'esmodule'; export const JSBUNDLE: string = 'jsbundle'; -export const ENTRY_TXT: string = 'entry.txt'; export const ARK: string = 'ark'; export const TEMPORARY: string = 'temporary'; export const MAIN: string = 'main'; @@ -260,6 +266,7 @@ export const EXTNAME_MJS: string = '.mjs'; export const EXTNAME_CJS: string = '.cjs'; export const EXTNAME_D_TS: string = '.d.ts'; export const EXTNAME_ABC: string = '.abc'; +export const EXTNAME_PROTO_BIN: string = '.protoBin'; export const SUCCESS: number = 0; export const FAIL: number = 1; diff --git a/compiler/src/process_js_ast.ts b/compiler/src/process_js_ast.ts index 8b94e5c..5407024 100644 --- a/compiler/src/process_js_ast.ts +++ b/compiler/src/process_js_ast.ts @@ -17,13 +17,13 @@ import ts from 'typescript'; import { BUILD_ON } from './pre_define'; -import { writeFileSyncByNode } from './utils'; +import { generateSourceFilesToTemporary } from './utils'; export function processJs(program: ts.Program, ut = false): Function { return (context: ts.TransformationContext) => { return (node: ts.SourceFile) => { if (process.env.compiler === BUILD_ON) { - writeFileSyncByNode(node, false); + generateSourceFilesToTemporary(node); return node; } else { return node; diff --git a/compiler/src/process_js_file.ts b/compiler/src/process_js_file.ts index 1eaec24..982bfd2 100644 --- a/compiler/src/process_js_file.ts +++ b/compiler/src/process_js_file.ts @@ -8,7 +8,7 @@ import { module.exports = function processjs2file(source: string): string { if (projectConfig.compileMode === ESMODULE && projectConfig.processTs === false && process.env.compilerType && process.env.compilerType === ARK) { - writeFileSyncByString(this.resourcePath, source, false); + writeFileSyncByString(this.resourcePath, source); } return source; }; diff --git a/compiler/src/resolve_ohm_url.ts b/compiler/src/resolve_ohm_url.ts index f40c7d3..463a6f2 100644 --- a/compiler/src/resolve_ohm_url.ts +++ b/compiler/src/resolve_ohm_url.ts @@ -1,6 +1,8 @@ import * as fs from 'fs'; import * as path from 'path'; import { logger } from './compile_info'; +import { NODE_MODULES, ONE, ZERO } from './pre_define'; +import { toUnixPath, getPackageInfo } from './utils'; const { projectConfig } = require('../main'); const red: string = '\u001b[31m'; @@ -86,3 +88,40 @@ export function resolveSourceFile(ohmUrl: string): string { return file; } + +export function getOhmUrlByFilepath(filePath: string): string { + let unixFilePath: string = toUnixPath(filePath); + unixFilePath = unixFilePath.substring(0, filePath.lastIndexOf('.')); // remove extension + const REG_PROJECT_SRC: RegExp = /(\S+)\/src\/(?:main|ohosTest)\/(ets|js)\/(\S+)/; + + const packageInfo: string[] = getPackageInfo(projectConfig.aceModuleJsonPath); + const bundleName: string = packageInfo[0]; + const moduleName: string = packageInfo[1]; + const moduleRootPath: string = toUnixPath(projectConfig.modulePathMap[moduleName]); + const projectRootPath: string = toUnixPath(projectConfig.projectRootPath); + // case1: /entry/src/main/ets/xxx/yyy + // case2: /node_modules/xxx/yyy + // case3: /entry/node_modules/xxx/yyy + const projectFilePath: string = unixFilePath.replace(projectRootPath, ''); + + const result: RegExpMatchArray | null = projectFilePath.match(REG_PROJECT_SRC); + if (result && result[1].indexOf(NODE_MODULES) === -1) { + return `${bundleName}/${moduleName}/${result[2]}/${result[3]}`; + } + + if (projectFilePath.indexOf(NODE_MODULES) !== -1) { + + const tryProjectNPM: string = toUnixPath(path.join(projectRootPath, NODE_MODULES)); + if (unixFilePath.indexOf(tryProjectNPM) !== -1) { + return unixFilePath.replace(tryProjectNPM, `${NODE_MODULES}/${ONE}`); + } + + const tryModuleNPM: string = toUnixPath(path.join(moduleRootPath, NODE_MODULES)); + if (unixFilePath.indexOf(tryModuleNPM) !== -1) { + return unixFilePath.replace(tryModuleNPM, `${NODE_MODULES}/${ZERO}`); + } + } + + logger.error(red, `ETS:ERROR Failed to get an resolved OhmUrl by filepath "${filePath}"`, reset); + return filePath; +} \ No newline at end of file diff --git a/compiler/src/utils.ts b/compiler/src/utils.ts index 4a1a473..271ef17 100644 --- a/compiler/src/utils.ts +++ b/compiler/src/utils.ts @@ -33,7 +33,8 @@ import { EXTNAME_ABC, EXTNAME_ETS, EXTNAME_TS_MAP, - EXTNAME_JS_MAP + EXTNAME_JS_MAP, + ESMODULE } from './pre_define'; export enum LogType { @@ -261,7 +262,7 @@ export function writeFileSync(filePath: string, content: string): void { fs.writeFileSync(filePath, content); } -export function genTemporaryPath(filePath: string, projectPath: string, buildPath: string, toTsFile: boolean = true): string { +export function genTemporaryPath(filePath: string, projectPath: string, buildPath: string): string { filePath = toUnixPath(filePath); if (filePath.endsWith(EXTNAME_MJS)) { filePath = filePath.replace(/\.mjs$/, EXTNAME_JS); @@ -270,19 +271,17 @@ export function genTemporaryPath(filePath: string, projectPath: string, buildPat filePath = filePath.replace(/\.cjs$/, EXTNAME_JS); } projectPath = toUnixPath(projectPath); - const hapPath: string = toUnixPath(projectConfig.projectRootPath); - const tempFilePath: string = filePath.replace(hapPath, ''); if (checkNodeModulesFile(filePath, projectPath)) { - const fakeNodeModulesPath: string = toUnixPath(path.resolve(projectConfig.projectRootPath, NODE_MODULES)); - const dataTmps: string[] = tempFilePath.split(NODE_MODULES); + const fakeNodeModulesPath: string = toUnixPath(path.join(projectConfig.projectRootPath, NODE_MODULES)); let output: string = ''; if (filePath.indexOf(fakeNodeModulesPath) === -1) { - const sufStr: string = dataTmps[dataTmps.length - 1]; + const hapPath: string = toUnixPath(projectConfig.projectRootPath); + const tempFilePath: string = filePath.replace(hapPath, ''); + const sufStr: string = tempFilePath.substring(tempFilePath.indexOf(NODE_MODULES) + NODE_MODULES.length + 1); output = path.join(buildPath, TEMPORARY, NODE_MODULES, MAIN, sufStr); } else { - const sufStr: string = dataTmps[dataTmps.length - 1]; - output = path.join(buildPath, TEMPORARY, NODE_MODULES, AUXILIARY, sufStr); + output = filePath.replace(fakeNodeModulesPath, path.join(buildPath, TEMPORARY, NODE_MODULES, AUXILIARY)); } return output; } @@ -296,7 +295,7 @@ export function genTemporaryPath(filePath: string, projectPath: string, buildPat return ''; } -export function genBuildPath(filePath: string, projectPath: string, buildPath: string, toTsFile: boolean = true): string { +export function genBuildPath(filePath: string, projectPath: string, buildPath: string): string { filePath = toUnixPath(filePath); if (filePath.endsWith(EXTNAME_MJS)) { filePath = filePath.replace(/\.mjs$/, EXTNAME_JS); @@ -305,20 +304,18 @@ export function genBuildPath(filePath: string, projectPath: string, buildPath: s filePath = filePath.replace(/\.cjs$/, EXTNAME_JS); } projectPath = toUnixPath(projectPath); - const hapPath: string = toUnixPath(projectConfig.projectRootPath); - const tempFilePath: string = filePath.replace(hapPath, ''); if (checkNodeModulesFile(filePath, projectPath)) { filePath = toUnixPath(filePath); - const fakeNodeModulesPath: string = toUnixPath(path.resolve(projectConfig.projectRootPath, NODE_MODULES)); - const dataTmps: string[] = tempFilePath.split(NODE_MODULES); + const fakeNodeModulesPath: string = toUnixPath(path.join(projectConfig.projectRootPath, NODE_MODULES)); let output: string = ''; if (filePath.indexOf(fakeNodeModulesPath) === -1) { - const sufStr: string = dataTmps[dataTmps.length - 1]; + const hapPath: string = toUnixPath(projectConfig.projectRootPath); + const tempFilePath: string = filePath.replace(hapPath, ''); + const sufStr: string = tempFilePath.substring(tempFilePath.indexOf(NODE_MODULES) + NODE_MODULES.length + 1); output = path.join(projectConfig.nodeModulesPath, ZERO, sufStr); } else { - const sufStr: string = dataTmps[dataTmps.length - 1]; - output = path.join(projectConfig.nodeModulesPath, ONE, sufStr); + output = filePath.replace(fakeNodeModulesPath, path.join(projectConfig.nodeModulesPath, ONE)); } return output; } @@ -367,16 +364,89 @@ export function mkdirsSync(dirname: string): boolean { return false; } -export function writeFileSyncByString(sourcePath: string, sourceCode: string, toTsFile: boolean): void { - const temporaryFile: string = genTemporaryPath(sourcePath, projectConfig.projectPath, process.env.cachePath, toTsFile); - if (temporaryFile.length === 0) { +export function writeFileSyncByString(sourcePath: string, sourceCode: string): void { + const jsFilePath: string = genTemporaryPath(sourcePath, projectConfig.projectPath, process.env.cachePath); + if (jsFilePath.length === 0) { return; } - mkdirsSync(path.dirname(temporaryFile)); - fs.writeFileSync(temporaryFile, sourceCode); + mkdirsSync(path.dirname(jsFilePath)); + fs.writeFileSync(jsFilePath, sourceCode); return; } +export const packageCollection: Map> = new Map(); + +export function getPackageInfo(configFile: string): Array { + if (packageCollection.has(configFile)) { + return packageCollection.get(configFile); + } + const data: any = JSON.parse(fs.readFileSync(configFile).toString()); + const bundleName: string = data.app.bundleName; + const moduleName: string = data.module.name; + packageCollection.set(configFile, [bundleName, moduleName]); + return [bundleName, moduleName]; +} + +function replaceRelativeDependency(item:string, moduleRequest: string, sourcePath: string): string { + if (sourcePath && projectConfig.compileMode === ESMODULE) { + const filePath: string = path.resolve(path.dirname(sourcePath), moduleRequest); + const result: RegExpMatchArray | null = filePath.match(/(\S+)(\/|\\)src(\/|\\)(?:main|ohosTest)(\/|\\)(ets|js)(\/|\\)(\S+)/); + if (result && projectConfig.aceModuleJsonPath) { + const npmModuleIdx: number = result[1].search(/(\/|\\)node_modules(\/|\\)/); + const projectRootPath: string = projectConfig.projectRootPath; + if (npmModuleIdx === -1 || npmModuleIdx === projectRootPath.search(/(\/|\\)node_modules(\/|\\)/)) { + const packageInfo: string[] = getPackageInfo(projectConfig.aceModuleJsonPath); + const bundleName: string = packageInfo[0]; + const moduleName: string = packageInfo[1]; + moduleRequest = `@bundle:${bundleName}/${moduleName}/${result[5]}/${toUnixPath(result[7])}`; + item = item.replace(/['"](\S+)['"]/, '\"' + moduleRequest + '\"'); + } + } + } + return item; +} + +function generateSourceMap(jsFilePath: string, sourceMapContent: string): void { + let buildFilePath: string = genBuildPath(jsFilePath, projectConfig.projectPath, projectConfig.buildPath); + if (buildFilePath.length === 0) { + return; + } + if (buildFilePath.endsWith(EXTNAME_ETS)) { + buildFilePath = buildFilePath.replace(/\.ets$/, EXTNAME_JS); + } else { + buildFilePath = buildFilePath.replace(/\.ts$/, EXTNAME_JS); + } + let buildSourceMapFile: string = genSourceMapFileName(buildFilePath); + mkdirsSync(path.dirname(buildSourceMapFile)); + fs.writeFileSync(buildSourceMapFile, sourceMapContent); +} + +export function generateSourceFilesToTemporary(node: ts.SourceFile): void { + const mixedInfo: {content: string, sourceMapContent: string} = genContentAndSourceMapInfo(node, false); + let jsFilePath: string = genTemporaryPath(node.fileName, projectConfig.projectPath, process.env.cachePath); + if (jsFilePath.length === 0) { + return; + } + if (jsFilePath.endsWith(EXTNAME_ETS)) { + jsFilePath = jsFilePath.replace(/\.ets$/, EXTNAME_JS); + } else { + jsFilePath = jsFilePath.replace(/\.ts$/, EXTNAME_JS); + } + let sourceMapFile: string = genSourceMapFileName(jsFilePath); + mkdirsSync(path.dirname(jsFilePath)); + if (sourceMapFile.length > 0 && projectConfig.buildArkMode === 'debug') { + mixedInfo.content += '\n' + "//# sourceMappingURL=" + path.basename(sourceMapFile); + generateSourceMap(node.fileName, mixedInfo.sourceMapContent); + } + // replace relative moduleSpecifier with ohmURl + const REG_RELATIVE_DEPENDENCY: RegExp = /(?:import|from)(?:\s*)['"]((?:\.\/|\.\.\/).*)['"]/g; + mixedInfo.content = mixedInfo.content.replace(REG_RELATIVE_DEPENDENCY, (item, moduleRequest)=>{ + return replaceRelativeDependency(item, moduleRequest, node.fileName); + }); + + fs.writeFileSync(jsFilePath, mixedInfo.content); +} + export function writeFileSyncByNode(node: ts.SourceFile, toTsFile: boolean): void { if (toTsFile) { const newStatements: ts.Node[] = []; diff --git a/compiler/src/validate_ui_syntax.ts b/compiler/src/validate_ui_syntax.ts index 9701ce4..b62c9c3 100644 --- a/compiler/src/validate_ui_syntax.ts +++ b/compiler/src/validate_ui_syntax.ts @@ -70,7 +70,7 @@ import { componentInfo, addLog, hasDecorator, - toUnixPath + getPackageInfo } from './utils'; import { projectConfig, abilityPagesFullPath } from '../main'; import { collectExtend } from './process_ui_syntax'; @@ -135,7 +135,6 @@ export const localStoragePropCollection: Map>> = export const isStaticViewCollection: Map = new Map(); -export const packageCollection: Map> = new Map(); export const useOSFiles: Set = new Set(); export const sourcemapNamesCollection: Map> = new Map(); export const originalImportNamesMap: Map = new Map(); @@ -841,17 +840,6 @@ export function preprocessNewExtend(content: string, extendCollection?: Set { - if (packageCollection.has(configFile)) { - return packageCollection.get(configFile); - } - const data: any = JSON.parse(fs.readFileSync(configFile).toString()); - const bundleName: string = data.app.bundleName; - const moduleName: string = data.module.name; - packageCollection.set(configFile, [bundleName, moduleName]); - return [bundleName, moduleName]; -} - function replaceSystemApi(item: string, systemValue: string, moduleType: string, systemKey: string): string { if (NATIVE_MODULE.has(`${moduleType}.${systemKey}`)) { item = `var ${systemValue} = globalThis.requireNativeModule('${moduleType}.${systemKey}')`; @@ -967,26 +955,6 @@ function replaceOhmUrl(isSystemModule: boolean, item: string, importValue: strin return item; } -function replaceRelativePath(item:string, moduleRequest: string, sourcePath: string): string { - // Do not replace relativePath to ohmUrl when building bundle - if (sourcePath && projectConfig.compileMode === ESMODULE) { - const filePath: string = path.resolve(path.dirname(sourcePath), moduleRequest); - const result: RegExpMatchArray | null = filePath.match(/(\S+)(\/|\\)src(\/|\\)(?:main|ohosTest)(\/|\\)(ets|js)(\/|\\)(\S+)/); - if (result && projectConfig.aceModuleJsonPath) { - const npmModuleIdx: number = result[1].search(/(\/|\\)node_modules(\/|\\)/); - const projectRootPath: string = projectConfig.projectRootPath; - if (npmModuleIdx == -1 || npmModuleIdx == projectRootPath.search(/(\/|\\)node_modules(\/|\\)/)) { - const packageInfo: string[] = getPackageInfo(projectConfig.aceModuleJsonPath); - const bundleName: string = packageInfo[0]; - const moduleName: string = packageInfo[1]; - moduleRequest = `@bundle:${bundleName}/${moduleName}/${result[5]}/${toUnixPath(result[7])}`; - item = item.replace(/['"](\S+)['"]/, '\"' + moduleRequest + '\"'); - } - } - } - return item; -} - export function processSystemApi(content: string, isProcessAllowList: boolean = false, sourcePath: string = null, isSystemModule: boolean = false): string { if (isProcessAllowList && projectConfig.compileMode === ESMODULE) { @@ -1028,14 +996,11 @@ export function processSystemApi(content: string, isProcessAllowList: boolean = const moduleType: string = result[1]; const apiName: string = result[2]; return replaceSystemApi(item, importValue, moduleType, apiName); - } else if (/^(\.|\.\.)\//.test(moduleRequest)) { // relativePath - return replaceRelativePath(item, moduleRequest, sourcePath); } else if (/^lib(\S+)\.so$/.test(moduleRequest)) { // libxxx.so const result: RegExpMatchArray = moduleRequest.match(/^lib(\S+)\.so$/); const libSoKey: string = result[1]; return replaceLibSo(importValue, libSoKey, sourcePath); } - // node_modules return item; }); return processInnerModule(processedContent, systemValueCollection); From 1d6e4a3bb09e0c430e3dafb9c23662f20f5a5ab6 Mon Sep 17 00:00:00 2001 From: laibo102 Date: Mon, 29 Aug 2022 17:36:34 +0800 Subject: [PATCH 13/17] Bugfix: fixed define array like '[1, 09]' in function body don't report errors Signed-off-by: laibo102 Change-Id: Ie7a0ea7625473292bef3da52a7acb4a941f32590 --- compiler/tsconfig.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/tsconfig.json b/compiler/tsconfig.json index 3f0b4a5..65cd87b 100644 --- a/compiler/tsconfig.json +++ b/compiler/tsconfig.json @@ -582,7 +582,8 @@ "typeRoots": [], "lib": [ "es2020" - ] + ], + "alwaysStrict": true }, "exclude": [ "node_modules" From 65f4f03152b23f8547697d253bcf231e7ca5dd3f Mon Sep 17 00:00:00 2001 From: laibo102 Date: Mon, 29 Aug 2022 17:50:34 +0800 Subject: [PATCH 14/17] Update: updated UT with strict mode Signed-off-by: laibo102 Change-Id: Iae71d9a06b6712a2fbc730d786e51943a03eae6a --- compiler/test/ut/import/importSystemApi.ts | 3 ++- .../ut/inner_commponent_transform/$$_component/$$_component.ts | 3 ++- .../custom_component/custom_component.ts | 3 ++- .../gesture_component/longPressGesture.ts | 3 ++- .../inner_commponent_transform/gesture_component/panGestrue.ts | 3 ++- .../gesture_component/pinchGesture.ts | 3 ++- .../gesture_component/rotationGesture.ts | 3 ++- .../gesture_component/swipeGesture.ts | 3 ++- .../inner_commponent_transform/gesture_component/tapGesture.ts | 3 ++- .../render_component/forEach/forEach.ts | 3 ++- .../render_component/lazyForEach/lazyForEach.ts | 3 ++- .../simple_component/button/button.ts | 3 ++- .../transition_component/animateTo/animateTo.ts | 3 ++- .../transition_component/pageTransition/pageTransition.ts | 3 ++- compiler/test/ut/render_decorator/@builder/@builder.ts | 3 ++- .../test/ut/render_decorator/@builder/@builderWithLinkData.ts | 3 ++- .../test/ut/render_decorator/@customDialog/@customDialog.ts | 3 ++- compiler/test/ut/render_decorator/@extend/@extend.ts | 3 ++- compiler/test/ut/render_decorator/@preview/@preview.ts | 3 ++- compiler/test/ut/render_decorator/@styles/@styles.ts | 3 ++- .../application_state_management/@storageLink/@storageLink.ts | 3 ++- .../application_state_management/@storageProp/@storageProp.ts | 3 ++- .../application_state_management/appStorage/appStorage.ts | 3 ++- .../application_state_management/localStorage/localStorage.ts | 3 ++- .../inner_struct_state_management/@link/@link.ts | 3 ++- .../inner_struct_state_management/@prop/@prop.ts | 3 ++- .../inner_struct_state_management/@state/@state.ts | 3 ++- .../others/@consume_@provide/@consume_@provide.ts | 3 ++- .../others/@observed_@objectLink/@observed_@objectLink.ts | 3 ++- compiler/test/ut/ui_state_management/others/@watch/@watch.ts | 3 ++- 30 files changed, 60 insertions(+), 30 deletions(-) diff --git a/compiler/test/ut/import/importSystemApi.ts b/compiler/test/ut/import/importSystemApi.ts index 620aaea..8945bca 100644 --- a/compiler/test/ut/import/importSystemApi.ts +++ b/compiler/test/ut/import/importSystemApi.ts @@ -36,7 +36,8 @@ import hello from 'libhello.so' import world = require('libworld.so')` exports.expectResult = -`let __generate__Id = 0; +`"use strict"; +let __generate__Id = 0; function generateId() { return "importSystemApi_" + ++__generate__Id; } diff --git a/compiler/test/ut/inner_commponent_transform/$$_component/$$_component.ts b/compiler/test/ut/inner_commponent_transform/$$_component/$$_component.ts index d24446d..aca5296 100644 --- a/compiler/test/ut/inner_commponent_transform/$$_component/$$_component.ts +++ b/compiler/test/ut/inner_commponent_transform/$$_component/$$_component.ts @@ -74,7 +74,8 @@ struct HomeComponent { }` exports.expectResult = -`let __generate__Id = 0; +`"use strict"; +let __generate__Id = 0; function generateId() { return "$$_component_" + ++__generate__Id; } diff --git a/compiler/test/ut/inner_commponent_transform/custom_component/custom_component.ts b/compiler/test/ut/inner_commponent_transform/custom_component/custom_component.ts index f3e4cf0..4581aed 100644 --- a/compiler/test/ut/inner_commponent_transform/custom_component/custom_component.ts +++ b/compiler/test/ut/inner_commponent_transform/custom_component/custom_component.ts @@ -46,7 +46,8 @@ struct Banner { }` exports.expectResult = -`let __generate__Id = 0; +`"use strict"; +let __generate__Id = 0; function generateId() { return "custom_component_" + ++__generate__Id; } diff --git a/compiler/test/ut/inner_commponent_transform/gesture_component/longPressGesture.ts b/compiler/test/ut/inner_commponent_transform/gesture_component/longPressGesture.ts index 17530be..ec1fc05 100644 --- a/compiler/test/ut/inner_commponent_transform/gesture_component/longPressGesture.ts +++ b/compiler/test/ut/inner_commponent_transform/gesture_component/longPressGesture.ts @@ -37,7 +37,8 @@ struct LongPressGestureExample { }` exports.expectResult = -`let __generate__Id = 0; +`"use strict"; +let __generate__Id = 0; function generateId() { return "longPressGesture_" + ++__generate__Id; } diff --git a/compiler/test/ut/inner_commponent_transform/gesture_component/panGestrue.ts b/compiler/test/ut/inner_commponent_transform/gesture_component/panGestrue.ts index e871eb0..b2cf0e2 100644 --- a/compiler/test/ut/inner_commponent_transform/gesture_component/panGestrue.ts +++ b/compiler/test/ut/inner_commponent_transform/gesture_component/panGestrue.ts @@ -45,7 +45,8 @@ struct PanGestureExample { ` exports.expectResult = -`let __generate__Id = 0; +`"use strict"; +let __generate__Id = 0; function generateId() { return "panGestrue_" + ++__generate__Id; } diff --git a/compiler/test/ut/inner_commponent_transform/gesture_component/pinchGesture.ts b/compiler/test/ut/inner_commponent_transform/gesture_component/pinchGesture.ts index aebbdd2..4d2d448 100644 --- a/compiler/test/ut/inner_commponent_transform/gesture_component/pinchGesture.ts +++ b/compiler/test/ut/inner_commponent_transform/gesture_component/pinchGesture.ts @@ -41,7 +41,8 @@ struct PinchGestureExample { }` exports.expectResult = -`let __generate__Id = 0; +`"use strict"; +let __generate__Id = 0; function generateId() { return "pinchGesture_" + ++__generate__Id; } diff --git a/compiler/test/ut/inner_commponent_transform/gesture_component/rotationGesture.ts b/compiler/test/ut/inner_commponent_transform/gesture_component/rotationGesture.ts index 407c8e6..61cc82c 100644 --- a/compiler/test/ut/inner_commponent_transform/gesture_component/rotationGesture.ts +++ b/compiler/test/ut/inner_commponent_transform/gesture_component/rotationGesture.ts @@ -41,7 +41,8 @@ struct RotationGestureExample { }` exports.expectResult = -`let __generate__Id = 0; +`"use strict"; +let __generate__Id = 0; function generateId() { return "rotationGesture_" + ++__generate__Id; } diff --git a/compiler/test/ut/inner_commponent_transform/gesture_component/swipeGesture.ts b/compiler/test/ut/inner_commponent_transform/gesture_component/swipeGesture.ts index 8d9b592..92f940e 100644 --- a/compiler/test/ut/inner_commponent_transform/gesture_component/swipeGesture.ts +++ b/compiler/test/ut/inner_commponent_transform/gesture_component/swipeGesture.ts @@ -39,7 +39,8 @@ struct SwipeGestureExample { }` exports.expectResult = -`let __generate__Id = 0; +`"use strict"; +let __generate__Id = 0; function generateId() { return "swipeGesture_" + ++__generate__Id; } diff --git a/compiler/test/ut/inner_commponent_transform/gesture_component/tapGesture.ts b/compiler/test/ut/inner_commponent_transform/gesture_component/tapGesture.ts index bd9de2b..2862434 100644 --- a/compiler/test/ut/inner_commponent_transform/gesture_component/tapGesture.ts +++ b/compiler/test/ut/inner_commponent_transform/gesture_component/tapGesture.ts @@ -35,7 +35,8 @@ struct TapGestureExample { }` exports.expectResult = -`let __generate__Id = 0; +`"use strict"; +let __generate__Id = 0; function generateId() { return "tapGesture_" + ++__generate__Id; } diff --git a/compiler/test/ut/inner_commponent_transform/render_component/forEach/forEach.ts b/compiler/test/ut/inner_commponent_transform/render_component/forEach/forEach.ts index bba87b4..57b366f 100644 --- a/compiler/test/ut/inner_commponent_transform/render_component/forEach/forEach.ts +++ b/compiler/test/ut/inner_commponent_transform/render_component/forEach/forEach.ts @@ -102,7 +102,8 @@ struct MyComponent { }` exports.expectResult = -`let __generate__Id = 0; +`"use strict"; +let __generate__Id = 0; function generateId() { return "forEach_" + ++__generate__Id; } diff --git a/compiler/test/ut/inner_commponent_transform/render_component/lazyForEach/lazyForEach.ts b/compiler/test/ut/inner_commponent_transform/render_component/lazyForEach/lazyForEach.ts index 70d694a..08b7a3a 100644 --- a/compiler/test/ut/inner_commponent_transform/render_component/lazyForEach/lazyForEach.ts +++ b/compiler/test/ut/inner_commponent_transform/render_component/lazyForEach/lazyForEach.ts @@ -107,7 +107,8 @@ struct MyComponent { }` exports.expectResult = -`let __generate__Id = 0; +`"use strict"; +let __generate__Id = 0; function generateId() { return "lazyForEach_" + ++__generate__Id; } diff --git a/compiler/test/ut/inner_commponent_transform/simple_component/button/button.ts b/compiler/test/ut/inner_commponent_transform/simple_component/button/button.ts index 1588490..885a8ae 100644 --- a/compiler/test/ut/inner_commponent_transform/simple_component/button/button.ts +++ b/compiler/test/ut/inner_commponent_transform/simple_component/button/button.ts @@ -34,7 +34,8 @@ struct ButtonExample { } ` exports.expectResult = -`let __generate__Id = 0; +`"use strict"; +let __generate__Id = 0; function generateId() { return "button_" + ++__generate__Id; } diff --git a/compiler/test/ut/inner_commponent_transform/transition_component/animateTo/animateTo.ts b/compiler/test/ut/inner_commponent_transform/transition_component/animateTo/animateTo.ts index 5b04dbf..d0cfe72 100644 --- a/compiler/test/ut/inner_commponent_transform/transition_component/animateTo/animateTo.ts +++ b/compiler/test/ut/inner_commponent_transform/transition_component/animateTo/animateTo.ts @@ -58,7 +58,8 @@ struct TransitionExample { ` exports.expectResult = -`let __generate__Id = 0; +`"use strict"; +let __generate__Id = 0; function generateId() { return "animateTo_" + ++__generate__Id; } diff --git a/compiler/test/ut/inner_commponent_transform/transition_component/pageTransition/pageTransition.ts b/compiler/test/ut/inner_commponent_transform/transition_component/pageTransition/pageTransition.ts index 8eda091..47d8c97 100644 --- a/compiler/test/ut/inner_commponent_transform/transition_component/pageTransition/pageTransition.ts +++ b/compiler/test/ut/inner_commponent_transform/transition_component/pageTransition/pageTransition.ts @@ -46,7 +46,8 @@ struct PageTransitionExample1 { ` exports.expectResult = -`let __generate__Id = 0; +`"use strict"; +let __generate__Id = 0; function generateId() { return "pageTransition_" + ++__generate__Id; } diff --git a/compiler/test/ut/render_decorator/@builder/@builder.ts b/compiler/test/ut/render_decorator/@builder/@builder.ts index 1cf6ab4..39bce30 100644 --- a/compiler/test/ut/render_decorator/@builder/@builder.ts +++ b/compiler/test/ut/render_decorator/@builder/@builder.ts @@ -142,7 +142,8 @@ struct MyComponent { } ` exports.expectResult = -`let __generate__Id = 0; +`"use strict"; +let __generate__Id = 0; function generateId() { return "@builder_" + ++__generate__Id; } diff --git a/compiler/test/ut/render_decorator/@builder/@builderWithLinkData.ts b/compiler/test/ut/render_decorator/@builder/@builderWithLinkData.ts index 34f4453..4f00664 100644 --- a/compiler/test/ut/render_decorator/@builder/@builderWithLinkData.ts +++ b/compiler/test/ut/render_decorator/@builder/@builderWithLinkData.ts @@ -38,7 +38,8 @@ struct TestPage{ } ` exports.expectResult = -`let __generate__Id = 0; +`"use strict"; +let __generate__Id = 0; function generateId() { return "@builderWithLinkData_" + ++__generate__Id; } diff --git a/compiler/test/ut/render_decorator/@customDialog/@customDialog.ts b/compiler/test/ut/render_decorator/@customDialog/@customDialog.ts index d07d0c0..b74df8d 100644 --- a/compiler/test/ut/render_decorator/@customDialog/@customDialog.ts +++ b/compiler/test/ut/render_decorator/@customDialog/@customDialog.ts @@ -99,7 +99,8 @@ struct CustomDialogUser { ` exports.expectResult = -`let __generate__Id = 0; +`"use strict"; +let __generate__Id = 0; function generateId() { return "@customDialog_" + ++__generate__Id; } diff --git a/compiler/test/ut/render_decorator/@extend/@extend.ts b/compiler/test/ut/render_decorator/@extend/@extend.ts index e874764..20815e5 100644 --- a/compiler/test/ut/render_decorator/@extend/@extend.ts +++ b/compiler/test/ut/render_decorator/@extend/@extend.ts @@ -54,7 +54,8 @@ struct FancyUse { } ` exports.expectResult = -`let __generate__Id = 0; +`"use strict"; +let __generate__Id = 0; function generateId() { return "@extend_" + ++__generate__Id; } diff --git a/compiler/test/ut/render_decorator/@preview/@preview.ts b/compiler/test/ut/render_decorator/@preview/@preview.ts index 2354bac..40147a2 100644 --- a/compiler/test/ut/render_decorator/@preview/@preview.ts +++ b/compiler/test/ut/render_decorator/@preview/@preview.ts @@ -37,7 +37,8 @@ struct HomePreviewComponent_Preview { ` exports.expectResult = -`let __generate__Id = 0; +`"use strict"; +let __generate__Id = 0; function generateId() { return "@preview_" + ++__generate__Id; } diff --git a/compiler/test/ut/render_decorator/@styles/@styles.ts b/compiler/test/ut/render_decorator/@styles/@styles.ts index fd49c87..61708a1 100644 --- a/compiler/test/ut/render_decorator/@styles/@styles.ts +++ b/compiler/test/ut/render_decorator/@styles/@styles.ts @@ -54,7 +54,8 @@ struct FancyUse { }` exports.expectResult = -`let __generate__Id = 0; +`"use strict"; +let __generate__Id = 0; function generateId() { return "@styles_" + ++__generate__Id; } diff --git a/compiler/test/ut/ui_state_management/application_state_management/@storageLink/@storageLink.ts b/compiler/test/ut/ui_state_management/application_state_management/@storageLink/@storageLink.ts index 8671287..3b3983a 100644 --- a/compiler/test/ut/ui_state_management/application_state_management/@storageLink/@storageLink.ts +++ b/compiler/test/ut/ui_state_management/application_state_management/@storageLink/@storageLink.ts @@ -48,7 +48,8 @@ struct MyComponent { } ` exports.expectResult = -`let __generate__Id = 0; +`"use strict"; +let __generate__Id = 0; function generateId() { return "@storageLink_" + ++__generate__Id; } diff --git a/compiler/test/ut/ui_state_management/application_state_management/@storageProp/@storageProp.ts b/compiler/test/ut/ui_state_management/application_state_management/@storageProp/@storageProp.ts index 24ac7c5..26b0f63 100644 --- a/compiler/test/ut/ui_state_management/application_state_management/@storageProp/@storageProp.ts +++ b/compiler/test/ut/ui_state_management/application_state_management/@storageProp/@storageProp.ts @@ -48,7 +48,8 @@ struct MyComponent { } ` exports.expectResult = -`let __generate__Id = 0; +`"use strict"; +let __generate__Id = 0; function generateId() { return "@storageProp_" + ++__generate__Id; } diff --git a/compiler/test/ut/ui_state_management/application_state_management/appStorage/appStorage.ts b/compiler/test/ut/ui_state_management/application_state_management/appStorage/appStorage.ts index 00804ec..3be55c9 100644 --- a/compiler/test/ut/ui_state_management/application_state_management/appStorage/appStorage.ts +++ b/compiler/test/ut/ui_state_management/application_state_management/appStorage/appStorage.ts @@ -48,7 +48,8 @@ struct MyComponent { } ` exports.expectResult = -`let __generate__Id = 0; +`"use strict"; +let __generate__Id = 0; function generateId() { return "appStorage_" + ++__generate__Id; } diff --git a/compiler/test/ut/ui_state_management/application_state_management/localStorage/localStorage.ts b/compiler/test/ut/ui_state_management/application_state_management/localStorage/localStorage.ts index 48f4e83..03de3b3 100644 --- a/compiler/test/ut/ui_state_management/application_state_management/localStorage/localStorage.ts +++ b/compiler/test/ut/ui_state_management/application_state_management/localStorage/localStorage.ts @@ -43,7 +43,8 @@ struct LocalStorageComponent { } ` exports.expectResult = -`let __generate__Id = 0; +`"use strict"; +let __generate__Id = 0; function generateId() { return "localStorage_" + ++__generate__Id; } diff --git a/compiler/test/ut/ui_state_management/inner_struct_state_management/@link/@link.ts b/compiler/test/ut/ui_state_management/inner_struct_state_management/@link/@link.ts index 9514598..122b8eb 100644 --- a/compiler/test/ut/ui_state_management/inner_struct_state_management/@link/@link.ts +++ b/compiler/test/ut/ui_state_management/inner_struct_state_management/@link/@link.ts @@ -68,7 +68,8 @@ struct linkPage { } ` exports.expectResult = -`let __generate__Id = 0; +`"use strict"; +let __generate__Id = 0; function generateId() { return "@link_" + ++__generate__Id; } diff --git a/compiler/test/ut/ui_state_management/inner_struct_state_management/@prop/@prop.ts b/compiler/test/ut/ui_state_management/inner_struct_state_management/@prop/@prop.ts index 1b63db1..63fa5a1 100644 --- a/compiler/test/ut/ui_state_management/inner_struct_state_management/@prop/@prop.ts +++ b/compiler/test/ut/ui_state_management/inner_struct_state_management/@prop/@prop.ts @@ -64,7 +64,8 @@ struct PageComponent { } ` exports.expectResult = -`let __generate__Id = 0; +`"use strict"; +let __generate__Id = 0; function generateId() { return "@prop_" + ++__generate__Id; } diff --git a/compiler/test/ut/ui_state_management/inner_struct_state_management/@state/@state.ts b/compiler/test/ut/ui_state_management/inner_struct_state_management/@state/@state.ts index 38565a9..af6344a 100644 --- a/compiler/test/ut/ui_state_management/inner_struct_state_management/@state/@state.ts +++ b/compiler/test/ut/ui_state_management/inner_struct_state_management/@state/@state.ts @@ -56,7 +56,8 @@ struct EntryComponent { } ` exports.expectResult = -`let __generate__Id = 0; +`"use strict"; +let __generate__Id = 0; function generateId() { return "@state_" + ++__generate__Id; } diff --git a/compiler/test/ut/ui_state_management/others/@consume_@provide/@consume_@provide.ts b/compiler/test/ut/ui_state_management/others/@consume_@provide/@consume_@provide.ts index 9f23e1a..da7a9fb 100644 --- a/compiler/test/ut/ui_state_management/others/@consume_@provide/@consume_@provide.ts +++ b/compiler/test/ut/ui_state_management/others/@consume_@provide/@consume_@provide.ts @@ -59,7 +59,8 @@ struct CompC { } ` exports.expectResult = -`let __generate__Id = 0; +`"use strict"; +let __generate__Id = 0; function generateId() { return "@consume_@provide_" + ++__generate__Id; } diff --git a/compiler/test/ut/ui_state_management/others/@observed_@objectLink/@observed_@objectLink.ts b/compiler/test/ut/ui_state_management/others/@observed_@objectLink/@observed_@objectLink.ts index cb096e3..ff9d976 100644 --- a/compiler/test/ut/ui_state_management/others/@observed_@objectLink/@observed_@objectLink.ts +++ b/compiler/test/ut/ui_state_management/others/@observed_@objectLink/@observed_@objectLink.ts @@ -57,7 +57,8 @@ struct ViewB { } ` exports.expectResult = -`var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { +`"use strict"; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; diff --git a/compiler/test/ut/ui_state_management/others/@watch/@watch.ts b/compiler/test/ut/ui_state_management/others/@watch/@watch.ts index c9b3ce6..7d246a6 100644 --- a/compiler/test/ut/ui_state_management/others/@watch/@watch.ts +++ b/compiler/test/ut/ui_state_management/others/@watch/@watch.ts @@ -65,7 +65,8 @@ struct CompA { } ` exports.expectResult = -`let __generate__Id = 0; +`"use strict"; +let __generate__Id = 0; function generateId() { return "@watch_" + ++__generate__Id; } From c3d2b6041d0b47e6385790be5f9295c800cc96d8 Mon Sep 17 00:00:00 2001 From: laibo102 Date: Wed, 31 Aug 2022 17:26:45 +0800 Subject: [PATCH 15/17] Update: update tsconfig.esm.json Signed-off-by: laibo102 Change-Id: I575f4db13cd03522d318862d5296871379368700 --- compiler/tsconfig.esm.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/tsconfig.esm.json b/compiler/tsconfig.esm.json index c39502f..0e29e51 100644 --- a/compiler/tsconfig.esm.json +++ b/compiler/tsconfig.esm.json @@ -582,7 +582,8 @@ "typeRoots": [], "lib": [ "es2020" - ] + ], + "alwaysStrict": true }, "exclude": [ "node_modules" From 1d220b274046aa5d3176d98f1e3b95c735b551ea Mon Sep 17 00:00:00 2001 From: bojiang Date: Fri, 2 Sep 2022 10:22:38 +0800 Subject: [PATCH 16/17] jiangbo91@huawei.com MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 解决ets工程引用js文件watch模式下修改js文件内容预览器无法刷新 Signed-off-by: bojiang Change-Id: I7b0f2d9636cbe054fc12dd5283954cec357c169e --- compiler/src/compile_info.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/compiler/src/compile_info.ts b/compiler/src/compile_info.ts index 681f5f6..16b2ba4 100644 --- a/compiler/src/compile_info.ts +++ b/compiler/src/compile_info.ts @@ -239,6 +239,17 @@ export class ResultStates { } this.printResult(); }); + + compiler.hooks.watchRun.tap('Listening State', (compiler: Compiler) => { + if (compiler.modifiedFiles) { + const isTsAndEtsFile: boolean = [...compiler.modifiedFiles].some((item: string) => { + return /.(ts|ets)$/.test(item); + }); + if (!isTsAndEtsFile) { + process.env.watchTs = 'end'; + } + } + }); } private printDiagnostic(diagnostic: ts.Diagnostic): void { From 024621f25fba4ac897c15eeb8317d713c0336b00 Mon Sep 17 00:00:00 2001 From: laibo102 Date: Fri, 2 Sep 2022 15:04:25 +0800 Subject: [PATCH 17/17] Bugfix: fiexd button with label parameter cannot have any child Signed-off-by: laibo102 Change-Id: Iae9c68672c09080d7098274e45876242a40610c3 --- compiler/src/process_component_build.ts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/compiler/src/process_component_build.ts b/compiler/src/process_component_build.ts index 3b59830..eea4651 100644 --- a/compiler/src/process_component_build.ts +++ b/compiler/src/process_component_build.ts @@ -60,7 +60,8 @@ import { BIND_POPUP_SET, $$, PROPERTIES_ADD_DOUBLE_DOLLAR, - ATTRIBUTE_ID + ATTRIBUTE_ID, + RESOURCE } from './pre_define'; import { INNER_COMPONENT_NAMES, @@ -413,6 +414,7 @@ function processInnerComponent(node: ts.ExpressionStatement, newStatements: ts.S } if (etsComponentResult.etsComponentNode.body && ts.isBlock(etsComponentResult.etsComponentNode.body)) { if (res.isButton) { + checkButtonParamHasLabel(etsComponentResult.etsComponentNode, log); if (projectConfig.isPreview) { newStatements.splice(-2, 1, createComponent(node, COMPONENT_CREATE_CHILD_FUNCTION).newNode); } else { @@ -1385,3 +1387,20 @@ function checkEtsComponent(node: ts.ExpressionStatement, log: LogInfo[]): void { ); } } + +function checkButtonParamHasLabel(node: ts.EtsComponentExpression, log: LogInfo[]): void { + if (node.arguments && node.arguments.length !== 0) { + for (let i = 0; i < node.arguments.length; i++) { + let argument: ts.Expression = node.arguments[i]; + if (ts.isStringLiteral(argument) || (ts.isCallExpression(argument) && ts.isIdentifier(argument.expression) && + (argument.expression.escapedText.toString() === RESOURCE))) { + log.push({ + type: LogType.ERROR, + message: "The Button component with a label parameter can not have any child.", + pos: node.getStart(), + }); + return; + } + } + } +}