mirror of
https://github.com/openharmony/developtools_ace-ets2bundle.git
synced 2026-07-19 16:43:34 -04:00
!605 fix call extend attr in extend attr
Merge pull request !605 from houhaoyu/master3
This commit is contained in:
@@ -20,7 +20,8 @@ import * as ts from 'typescript';
|
||||
import { projectConfig } from '../main';
|
||||
import {
|
||||
processSystemApi,
|
||||
preprocessExtend
|
||||
preprocessExtend,
|
||||
preprocessNewExtend
|
||||
} from './validate_ui_syntax';
|
||||
import {
|
||||
INNER_COMPONENT_MEMBER_DECORATORS,
|
||||
@@ -283,23 +284,23 @@ function loopNodeFindDoubleDollar(node: ts.Node, parentComponentName: string): v
|
||||
while (node) {
|
||||
if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression)) {
|
||||
const argument: ts.NodeArray<ts.Node> = node.arguments;
|
||||
const propertyName: ts.Identifier | ts.PrivateIdentifier= node.expression.name;
|
||||
const propertyName: ts.Identifier | ts.PrivateIdentifier = node.expression.name;
|
||||
if (isCanAddDoubleDollar(propertyName.getText(), parentComponentName)) {
|
||||
argument.forEach((item: ts.Node)=> {
|
||||
argument.forEach((item: ts.Node) => {
|
||||
doubleDollarCollection(item);
|
||||
});
|
||||
}
|
||||
}
|
||||
} else if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && node.arguments
|
||||
&& node.arguments.length) {
|
||||
node.arguments.forEach((item: ts.Node) => {
|
||||
if (ts.isObjectLiteralExpression(item) && item.properties && item.properties.length) {
|
||||
item.properties.forEach((param: ts.Node)=>{
|
||||
item.properties.forEach((param: ts.Node) => {
|
||||
if (isObjectPram(param, parentComponentName)) {
|
||||
doubleDollarCollection(param.initializer);
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
node = node.expression;
|
||||
}
|
||||
@@ -316,12 +317,12 @@ function doubleDollarCollection(item: ts.Node): void {
|
||||
|
||||
function isObjectPram(param: ts.Node, parentComponentName:string): boolean {
|
||||
return ts.isPropertyAssignment(param) && param.name && ts.isIdentifier(param.name) &&
|
||||
param.initializer && PROPERTIES_ADD_DOUBLE_DOLLAR.has(parentComponentName) &&
|
||||
param.initializer && PROPERTIES_ADD_DOUBLE_DOLLAR.has(parentComponentName) &&
|
||||
PROPERTIES_ADD_DOUBLE_DOLLAR.get(parentComponentName).has(param.name.getText());
|
||||
}
|
||||
|
||||
function isCanAddDoubleDollar(propertyName: string, parentComponentName: string): boolean {
|
||||
return PROPERTIES_ADD_DOUBLE_DOLLAR.has(parentComponentName) &&
|
||||
return PROPERTIES_ADD_DOUBLE_DOLLAR.has(parentComponentName) &&
|
||||
PROPERTIES_ADD_DOUBLE_DOLLAR.get(parentComponentName).has(propertyName) ||
|
||||
propertyName === BIND_POPUP;
|
||||
}
|
||||
@@ -344,6 +345,7 @@ function processDraw(source: string): string {
|
||||
function processContent(source: string): string {
|
||||
source = processSystemApi(source);
|
||||
source = preprocessExtend(source, extendCollection);
|
||||
source = preprocessNewExtend(source, extendCollection);
|
||||
source = processDraw(source);
|
||||
return source;
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ import {
|
||||
linkCollection,
|
||||
componentCollection,
|
||||
preprocessExtend,
|
||||
preprocessNewExtend,
|
||||
processSystemApi,
|
||||
propCollection,
|
||||
isObservedClass,
|
||||
@@ -86,11 +87,11 @@ export default function processImport(node: ts.ImportDeclaration | ts.ImportEqua
|
||||
fileResolvePath = getFileResolvePath(fileResolvePath, pagesDir, filePath, projectConfig.projectPath);
|
||||
}
|
||||
if (fs.existsSync(fileResolvePath) && fs.statSync(fileResolvePath).isFile()) {
|
||||
const content: string = preprocessExtend(processSystemApi(
|
||||
const content: string = preprocessNewExtend(preprocessExtend(processSystemApi(
|
||||
fs.readFileSync(fileResolvePath, { encoding: 'utf-8' }).replace(
|
||||
new RegExp('\\b' + STRUCT + '\\b.+\\{', 'g'), item => {
|
||||
return item.replace(new RegExp('\\b' + STRUCT + '\\b', 'g'), `${CLASS} `);
|
||||
})));
|
||||
}))));
|
||||
const sourceFile: ts.SourceFile = ts.createSourceFile(filePath, content,
|
||||
ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
|
||||
visitAllNode(sourceFile, defaultName, asName, path.dirname(fileResolvePath), log, new Set(), new Set());
|
||||
|
||||
@@ -371,7 +371,7 @@ function hasChild(node: ts.ExpressionStatement): boolean {
|
||||
function getNextNode(node: ts.EtsComponentExpression): ts.Block {
|
||||
if (node.body && ts.isBlock(node.body)) {
|
||||
const statementsArray: ts.Block = node.body;
|
||||
return statementsArray
|
||||
return statementsArray;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -731,9 +731,9 @@ function collectionStates(node: ts.Decorator, decorator: string, name: string,
|
||||
case COMPONENT_LOCAL_STORAGE_PROP_DECORATOR:
|
||||
collectionlocalStorageParam(node, name, localStorageProp);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function collectionlocalStorageParam(node: ts.Decorator, name: string,
|
||||
localStorage: Map<string, Set<string>>): void {
|
||||
const localStorageParam: Set<string> = new Set();
|
||||
@@ -753,6 +753,7 @@ export function sourceReplace(source: string, sourcePath: string): ReplaceResult
|
||||
let content: string = source;
|
||||
const log: LogInfo[] = [];
|
||||
content = preprocessExtend(content);
|
||||
content = preprocessNewExtend(content);
|
||||
// process @system.
|
||||
content = processSystemApi(content, false, sourcePath);
|
||||
|
||||
@@ -774,6 +775,16 @@ export function preprocessExtend(content: string, extendCollection?: Set<string>
|
||||
});
|
||||
}
|
||||
|
||||
export function preprocessNewExtend(content: string, extendCollection?: Set<string>): string {
|
||||
const REG_EXTEND: RegExp = /@Extend\s*\([^\)]+\)\s*function\s+([^\(\s]+)\s*\(/gm;
|
||||
return content.replace(REG_EXTEND, (item, item1) => {
|
||||
if (extendCollection) {
|
||||
extendCollection.add(item1);
|
||||
}
|
||||
return item;
|
||||
});
|
||||
}
|
||||
|
||||
export function processSystemApi(content: string, isProcessAllowList: boolean = false,
|
||||
sourcePath: string = null, isSystemModule: boolean = false): string {
|
||||
let REG_SYSTEM: RegExp;
|
||||
|
||||
Reference in New Issue
Block a user