mirror of
https://gitee.com/openharmony/developtools_ace_ets2bundle
synced 2024-11-26 18:21:00 +00:00
!3931 修正状态变量传递校验报错
Merge pull request !3931 from Jiakai Shi/jiakai1112-error
This commit is contained in:
commit
886df2ad26
@ -125,7 +125,7 @@ import {
|
||||
processMemberVariableDecorators,
|
||||
UpdateResult,
|
||||
stateObjectCollection,
|
||||
curPropMap,
|
||||
PropMapManager,
|
||||
decoratorParamSet,
|
||||
isSimpleType,
|
||||
isSingleKey,
|
||||
@ -271,7 +271,8 @@ function processMembers(members: ts.NodeArray<ts.ClassElement>, parentComponentN
|
||||
partialUpdateConfig.partialUpdateMode && projectConfig.minAPIVersion > 10) {
|
||||
newMembers.push(getEntryNameFunction(componentCollection.entryComponent));
|
||||
}
|
||||
curPropMap.clear();
|
||||
log.push(...Array.from(PropMapManager.logInfoMap.values()).flat());
|
||||
PropMapManager.reset();
|
||||
return newMembers;
|
||||
}
|
||||
|
||||
|
@ -263,7 +263,40 @@ export class UpdateResult {
|
||||
}
|
||||
}
|
||||
|
||||
export const curPropMap: Map<string, string> = new Map();
|
||||
export class PropMapManager {
|
||||
static curPropMap: Map<string, string> = new Map();
|
||||
static logInfoMap: Map<string, LogInfo[]> = new Map();
|
||||
|
||||
public static register(identifierName: string, decoratorName: string) {
|
||||
PropMapManager.curPropMap.set(identifierName, decoratorName);
|
||||
|
||||
if (decoratorName !== COMPONENT_NON_DECORATOR) {
|
||||
PropMapManager.releaseLogs(identifierName, COMPONENT_NON_DECORATOR);
|
||||
}
|
||||
}
|
||||
|
||||
public static find(identifierName: string) {
|
||||
return PropMapManager.curPropMap.get(identifierName);
|
||||
}
|
||||
|
||||
public static reserveLog(identifierName: string, decoratorName: string, log: LogInfo) {
|
||||
const key: string = `${identifierName}-${decoratorName}`;
|
||||
const logInfos: LogInfo[] = PropMapManager.logInfoMap.get(key) ?? [];
|
||||
PropMapManager.logInfoMap.set(key, [...logInfos, log]);
|
||||
}
|
||||
|
||||
public static releaseLogs(identifierName: string, decoratorName: string) {
|
||||
const key: string = `${identifierName}-${decoratorName}`;
|
||||
if (PropMapManager.logInfoMap.has(key)) {
|
||||
PropMapManager.logInfoMap.delete(key);
|
||||
}
|
||||
}
|
||||
|
||||
public static reset() {
|
||||
PropMapManager.curPropMap.clear();
|
||||
PropMapManager.logInfoMap.clear();
|
||||
}
|
||||
}
|
||||
|
||||
export function processMemberVariableDecorators(parentName: ts.Identifier,
|
||||
item: ts.PropertyDeclaration, ctorNode: ts.ConstructorDeclaration, watchMap: Map<string, ts.Node>,
|
||||
@ -276,7 +309,7 @@ export function processMemberVariableDecorators(parentName: ts.Identifier,
|
||||
if (!name.escapedText) {
|
||||
return updateResult;
|
||||
}
|
||||
curPropMap.set(name.escapedText.toString(), COMPONENT_NON_DECORATOR);
|
||||
PropMapManager.register(name.escapedText.toString(), COMPONENT_NON_DECORATOR);
|
||||
updateResult.setProperity(undefined);
|
||||
updateResult.setUpdateParams(createUpdateParams(name, COMPONENT_NON_DECORATOR));
|
||||
updateResult.setCtor(updateConstructor(ctorNode, [], [
|
||||
@ -348,7 +381,7 @@ function processPropertyNodeDecorator(parentName: ts.Identifier, node: ts.Proper
|
||||
const includeWatchAndRequire: boolean =
|
||||
[COMPONENT_WATCH_DECORATOR, COMPONENT_REQUIRE_DECORATOR].includes(decoratorName);
|
||||
if (!includeWatchAndRequire) {
|
||||
curPropMap.set(name.escapedText.toString(), decoratorName);
|
||||
PropMapManager.register(name.escapedText.toString(), decoratorName);
|
||||
}
|
||||
if (BUILDIN_STYLE_NAMES.has(decoratorName.replace('@', ''))) {
|
||||
validateDuplicateDecorator(decorators[i], log);
|
||||
|
@ -79,7 +79,7 @@ import {
|
||||
componentCollection
|
||||
} from './validate_ui_syntax';
|
||||
import {
|
||||
curPropMap,
|
||||
PropMapManager,
|
||||
createViewCreate,
|
||||
createCustomComponentNewExpression,
|
||||
isLocalStorageParameter,
|
||||
@ -1055,10 +1055,7 @@ function checkFromParentToChild(node: ts.ObjectLiteralElementLike, customCompone
|
||||
if (isInitFromParent(node)) {
|
||||
parentPropertyName =
|
||||
getParentPropertyName(node as ts.PropertyAssignment, curPropertyKind, log);
|
||||
let parentPropertyKind: string = curPropMap.get(parentPropertyName);
|
||||
if (!parentPropertyKind) {
|
||||
parentPropertyKind = COMPONENT_NON_DECORATOR;
|
||||
}
|
||||
let parentPropertyKind: string = PropMapManager.find(parentPropertyName);
|
||||
if (parentPropertyKind && !isCorrectInitFormParent(parentPropertyKind, curPropertyKind)) {
|
||||
validateIllegalInitFromParent(
|
||||
node, propertyName, curPropertyKind, parentPropertyName, parentPropertyKind, log);
|
||||
@ -1131,22 +1128,22 @@ function getParentPropertyName(node: ts.PropertyAssignment, curPropertyKind: str
|
||||
return undefined;
|
||||
}
|
||||
let parentPropertyName: string = initExpression.getText();
|
||||
const symbol = globalProgram.checker?.getSymbolAtLocation(initExpression);
|
||||
if (curPropertyKind === COMPONENT_LINK_DECORATOR) {
|
||||
// @ts-ignore
|
||||
const initName: ts.Identifier = initExpression.name || initExpression;
|
||||
if (hasDollar(initExpression)) {
|
||||
if (!symbol && hasDollar(initExpression)) {
|
||||
parentPropertyName = initName.getText().replace(/^\$/, '');
|
||||
} else {
|
||||
parentPropertyName = initName.getText();
|
||||
}
|
||||
} else {
|
||||
if (hasDollar(initExpression)) {
|
||||
if (!symbol && hasDollar(initExpression)) {
|
||||
validateNonLinkWithDollar(node, log);
|
||||
} else {
|
||||
// @ts-ignore
|
||||
if (node.initializer && node.initializer.name) {
|
||||
parentPropertyName = node.initializer.name.getText();
|
||||
}
|
||||
}
|
||||
// @ts-ignore
|
||||
if (node.initializer && node.initializer.name) {
|
||||
parentPropertyName = node.initializer.name.getText();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1350,7 +1347,7 @@ function validateIllegalInitFromParent(node: ts.ObjectLiteralElementLike, proper
|
||||
parentPropertyKind) && curPropertyKind === COMPONENT_OBJECT_LINK_DECORATOR) {
|
||||
type = LogType.WARN;
|
||||
}
|
||||
log.push({
|
||||
PropMapManager.reserveLog(parentPropertyName, parentPropertyKind, {
|
||||
type: type,
|
||||
message: `The ${parentPropertyKind} property '${parentPropertyName}' cannot be assigned to ` +
|
||||
`the ${curPropertyKind} property '${propertyName}'.`,
|
||||
|
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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.
|
||||
*/
|
||||
exports.source = `
|
||||
@Entry
|
||||
@Component
|
||||
struct Parent {
|
||||
@State $arr: number[] = [1, 2, 3];
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
Child({items: this.arr});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Component
|
||||
struct Child {
|
||||
@Link items: number[];
|
||||
build() {
|
||||
}
|
||||
}
|
||||
`
|
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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.
|
||||
*/
|
||||
exports.source = `
|
||||
@Entry
|
||||
@Component
|
||||
struct Parent {
|
||||
@State $arr: number[] = [1, 2, 3];
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
Child({items: this.$arr});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Component
|
||||
struct Child {
|
||||
@Link items: number[];
|
||||
build() {
|
||||
}
|
||||
}
|
||||
`
|
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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.
|
||||
*/
|
||||
exports.source = `
|
||||
@Observed
|
||||
class Info {
|
||||
count: number;
|
||||
constructor(count: number) {
|
||||
this.count = count;
|
||||
}
|
||||
}
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct Parent {
|
||||
@State $arr: Info = new Info(1);
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
Child({items: this.$arr});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Component
|
||||
struct Child {
|
||||
@ObjectLink items: Info;
|
||||
build() {
|
||||
}
|
||||
}
|
||||
`
|
Loading…
Reference in New Issue
Block a user