From 583ed175da8bd9bb818d13e5bcd24944e1d87856 Mon Sep 17 00:00:00 2001 From: gavin1012_hw Date: Wed, 18 Jan 2023 15:34:22 +0800 Subject: [PATCH] fixed 26df8d6 from https://gitee.com/gavin1012_hw/ark_ts2abc/pulls/810 Fix LReference in PartiallyEmittedExpression Issue: I6B0EK Signed-off-by: gavin1012_hw Change-Id: I97636ca661e87d6308570565d71e28692cb89ee2 --- ts2panda/src/base/lreference.ts | 9 ++++++-- .../expression/partiallyEmittedExpression.ts | 23 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 ts2panda/src/expression/partiallyEmittedExpression.ts diff --git a/ts2panda/src/base/lreference.ts b/ts2panda/src/base/lreference.ts index b079b70bb89..1a89aa46626 100644 --- a/ts2panda/src/base/lreference.ts +++ b/ts2panda/src/base/lreference.ts @@ -20,6 +20,7 @@ import { compileDestructuring } from "../compilerUtils"; import { DiagnosticCode, DiagnosticError } from "../diagnostic"; import { getObjAndProp } from "../expression/memberAccessExpression"; import { findInnerExprOfParenthesis } from "../expression/parenthesizedExpression"; +import { findInnerExprOfPartiallyEmittedExpr } from "../expression/partiallyEmittedExpression"; import { VReg } from "../irnodes"; import * as jshelpers from "../jshelpers"; import { Scope } from "../scope"; @@ -131,8 +132,12 @@ export class LReference { let realNode: ts.Node = node; - if (ts.isParenthesizedExpression(node)) { - realNode = findInnerExprOfParenthesis(node); + if (ts.isPartiallyEmittedExpression(node)) { + realNode = findInnerExprOfPartiallyEmittedExpr(node); + } + + if (ts.isParenthesizedExpression(realNode)) { + realNode = findInnerExprOfParenthesis(realNode); } if (ts.isIdentifier(realNode)) { diff --git a/ts2panda/src/expression/partiallyEmittedExpression.ts b/ts2panda/src/expression/partiallyEmittedExpression.ts new file mode 100644 index 00000000000..d1521a7f512 --- /dev/null +++ b/ts2panda/src/expression/partiallyEmittedExpression.ts @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2021 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 ts from "typescript"; + +export function findInnerExprOfPartiallyEmittedExpr(expr: ts.PartiallyEmittedExpression): ts.Expression { + while (expr.expression.kind == ts.SyntaxKind.PartiallyEmittedExpression) { + expr = expr.expression; + } + return expr.expression; +} -- Gitee