mirror of
https://github.com/openharmony/developtools_ace-ets2bundle.git
synced 2026-07-18 16:04:32 -04:00
!872 [DFX] add varible names to sourcemap for dfx analyzing
Merge pull request !872 from zhangbingce/dev-dfx
This commit is contained in:
@@ -29,7 +29,8 @@ import ConcatSource from 'webpack-sources/lib/ConcatSource';
|
||||
|
||||
import { transformLog } from './process_ui_syntax';
|
||||
import {
|
||||
useOSFiles
|
||||
useOSFiles,
|
||||
sourcemapNamesCollection
|
||||
} from './validate_ui_syntax';
|
||||
import { projectConfig } from '../main';
|
||||
import {
|
||||
@@ -86,6 +87,17 @@ export class ResultStates {
|
||||
if (/\.map$/.test(key.toString()) && assets[key]._value) {
|
||||
assets[key]._value = assets[key]._value.toString().replace('.ets?entry', '.ets');
|
||||
assets[key]._value = assets[key]._value.toString().replace('.ts?entry', '.ts');
|
||||
|
||||
let absPath: string = path.resolve(projectConfig.projectPath, key.toString().replace('.js.map','.js'));
|
||||
if (sourcemapNamesCollection && absPath) {
|
||||
let map: Map<string, string> = sourcemapNamesCollection.get(absPath);
|
||||
if (map && map.size != 0) {
|
||||
let names: Array<string> = Array.from(map).flat();
|
||||
let sourcemapObj: any = JSON.parse(assets[key]._value);
|
||||
sourcemapObj.names = names;
|
||||
assets[key]._value = JSON.stringify(sourcemapObj);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -13,7 +13,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { processSystemApi } from './validate_ui_syntax';
|
||||
import {
|
||||
processSystemApi,
|
||||
CollectImportNames
|
||||
} from './validate_ui_syntax';
|
||||
import { systemModules } from '../main';
|
||||
|
||||
module.exports = function processSystemModule(source: string): string {
|
||||
@@ -31,5 +34,6 @@ module.exports = function processSystemModule(source: string): string {
|
||||
return item;
|
||||
});
|
||||
source = processSystemApi(source, false, this.resourcePath, true);
|
||||
CollectImportNames(source, this.resourcePath);
|
||||
return source;
|
||||
};
|
||||
|
||||
@@ -35,7 +35,7 @@ import { abilityConfig } from '../main';
|
||||
|
||||
module.exports = function resultProcess(source: string, map: any): void {
|
||||
process.env.compiler = BUILD_OFF;
|
||||
source = processSystemApi(source, true);
|
||||
source = processSystemApi(source, true, this.resourcePath);
|
||||
if (/\.(ets|ts)$/.test(this.resourcePath)) {
|
||||
componentInfo.id = 0;
|
||||
propertyCollection.clear();
|
||||
|
||||
@@ -137,6 +137,8 @@ export const isStaticViewCollection: Map<string, boolean> = new Map();
|
||||
|
||||
export const packageCollection: Map<string, Array<string>> = new Map();
|
||||
export const useOSFiles: Set<string> = new Set();
|
||||
export const sourcemapNamesCollection: Map<string, Map<string, string>> = new Map();
|
||||
export const originalImportNamesMap: Map<string, string> = new Map();
|
||||
|
||||
export function validateUISyntax(source: string, content: string, filePath: string,
|
||||
fileQuery: string): LogInfo[] {
|
||||
@@ -809,6 +811,7 @@ export function sourceReplace(source: string, sourcePath: string): ReplaceResult
|
||||
content = preprocessNewExtend(content);
|
||||
// process @system.
|
||||
content = processSystemApi(content, false, sourcePath);
|
||||
CollectImportNames(content, sourcePath);
|
||||
|
||||
return {
|
||||
content: content,
|
||||
@@ -1006,8 +1009,10 @@ export function processSystemApi(content: string, isProcessAllowList: boolean =
|
||||
if (isProcessAllowList) {
|
||||
systemValueCollection.add(importValue);
|
||||
if (projectConfig.compileMode !== ESMODULE) {
|
||||
collectSourcemapNames(sourcePath, importValue, item5);
|
||||
return replaceSystemApi(item, importValue, item4, item5);
|
||||
}
|
||||
collectSourcemapNames(sourcePath, importValue, item3);
|
||||
return replaceSystemApi(item, importValue, item2, item3);
|
||||
}
|
||||
|
||||
@@ -1036,6 +1041,51 @@ export function processSystemApi(content: string, isProcessAllowList: boolean =
|
||||
return processInnerModule(processedContent, systemValueCollection);
|
||||
}
|
||||
|
||||
function collectSourcemapNames(sourcePath: string, changedName: string, originalName: string): void {
|
||||
const cleanSourcePath: string = sourcePath.replace('.ets', '.js').replace('.ts', '.js');
|
||||
if (!sourcemapNamesCollection.has(cleanSourcePath)) {
|
||||
return;
|
||||
}
|
||||
|
||||
let map: Map<string, string> = sourcemapNamesCollection.get(cleanSourcePath);
|
||||
if (map.has(changedName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (let entry of originalImportNamesMap.entries()) {
|
||||
const key: string = entry[0];
|
||||
const value: string = entry[1];
|
||||
if (value === '@ohos.' + originalName || value === '@system.' + originalName) {
|
||||
map.set(changedName.trim(), key);
|
||||
sourcemapNamesCollection.set(cleanSourcePath, map);
|
||||
originalImportNamesMap.delete(key);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function CollectImportNames(content: string, sourcePath: string = null): void {
|
||||
const REG_IMPORT_DECL: RegExp =
|
||||
/(import|export)\s+(.+)\s+from\s+['"](\S+)['"]|import\s+(.+)\s*=\s*require\(\s*['"](\S+)['"]\s*\)/g;
|
||||
|
||||
const decls: string[] = content.match(REG_IMPORT_DECL);
|
||||
if (decls != undefined) {
|
||||
decls.forEach(decl => {
|
||||
const parts: string[] = decl.split(' ');
|
||||
if (parts.length === 4 && parts[0] === 'import' && parts[2] === 'from' && !parts[3].includes('.so')) {
|
||||
originalImportNamesMap.set(parts[1], parts[3].replace(/'/g, ''));
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
if (sourcePath && sourcePath != null) {
|
||||
const cleanSourcePath: string = sourcePath.replace('.ets', '.js').replace('.ts', '.js');
|
||||
if (!sourcemapNamesCollection.has(cleanSourcePath)) {
|
||||
sourcemapNamesCollection.set(cleanSourcePath, new Map());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function processInnerModule(content: string, systemValueCollection: Set<string>): string {
|
||||
systemValueCollection.forEach(element => {
|
||||
const target: string = element.trim() + '.default';
|
||||
|
||||
Reference in New Issue
Block a user