From a9f779cea36b376a2ffa9dcd52849d14cad9758a Mon Sep 17 00:00:00 2001 From: xucheng46 Date: Thu, 29 Sep 2022 22:36:57 +0800 Subject: [PATCH] Enable namespace emitting in es2abc Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I5QL63 Test: test262, parser tests, compiler tests Signed-off-by: xucheng46 Change-Id: I079917bff0e401188532d5bd4f4f6aae0bd96836 --- es2panda/BUILD.gn | 1 + es2panda/CMakeLists.txt | 1 + es2panda/binder/binder.cpp | 50 +- es2panda/binder/binder.h | 23 +- es2panda/binder/declaration.h | 18 +- es2panda/binder/scope.cpp | 18 + es2panda/binder/scope.h | 219 +++++++- es2panda/binder/variable.cpp | 2 + es2panda/binder/variable.h | 51 ++ es2panda/binder/variableFlags.h | 39 +- es2panda/compiler/base/hoisting.cpp | 3 +- es2panda/compiler/core/compileQueue.cpp | 2 +- es2panda/compiler/core/compilerImpl.cpp | 10 - es2panda/compiler/core/emitter/emitter.cpp | 5 +- es2panda/compiler/core/emitter/emitter.h | 2 +- es2panda/compiler/core/function.cpp | 4 +- es2panda/es2panda.cpp | 21 + es2panda/es2panda.h | 2 + es2panda/ir/astNode.h | 24 +- es2panda/ir/astNodeMapping.h | 1 + es2panda/ir/base/catchClause.cpp | 12 + es2panda/ir/base/catchClause.h | 1 + es2panda/ir/base/classDefinition.cpp | 36 ++ es2panda/ir/base/classDefinition.h | 1 + es2panda/ir/base/classProperty.cpp | 31 +- es2panda/ir/base/classProperty.h | 1 + es2panda/ir/base/decorator.cpp | 5 + es2panda/ir/base/decorator.h | 1 + es2panda/ir/base/metaProperty.cpp | 2 + es2panda/ir/base/metaProperty.h | 1 + es2panda/ir/base/methodDefinition.cpp | 14 + es2panda/ir/base/methodDefinition.h | 1 + es2panda/ir/base/property.cpp | 6 + es2panda/ir/base/property.h | 1 + es2panda/ir/base/scriptFunction.cpp | 28 + es2panda/ir/base/scriptFunction.h | 1 + es2panda/ir/base/spreadElement.cpp | 8 + es2panda/ir/base/spreadElement.h | 1 + es2panda/ir/base/templateElement.cpp | 2 + es2panda/ir/base/templateElement.h | 1 + es2panda/ir/expressions/arrayExpression.cpp | 7 + es2panda/ir/expressions/arrayExpression.h | 1 + .../expressions/arrowFunctionExpression.cpp | 5 + .../ir/expressions/arrowFunctionExpression.h | 1 + .../ir/expressions/assignmentExpression.cpp | 6 + .../ir/expressions/assignmentExpression.h | 1 + es2panda/ir/expressions/awaitExpression.cpp | 7 + es2panda/ir/expressions/awaitExpression.h | 1 + es2panda/ir/expressions/binaryExpression.cpp | 6 + es2panda/ir/expressions/binaryExpression.h | 1 + es2panda/ir/expressions/callExpression.cpp | 13 + es2panda/ir/expressions/callExpression.h | 1 + es2panda/ir/expressions/chainExpression.cpp | 5 + es2panda/ir/expressions/chainExpression.h | 1 + es2panda/ir/expressions/classExpression.cpp | 5 + es2panda/ir/expressions/classExpression.h | 1 + .../ir/expressions/conditionalExpression.cpp | 7 + .../ir/expressions/conditionalExpression.h | 1 + .../ir/expressions/functionExpression.cpp | 5 + es2panda/ir/expressions/functionExpression.h | 1 + es2panda/ir/expressions/identifier.cpp | 11 + es2panda/ir/expressions/identifier.h | 1 + es2panda/ir/expressions/importExpression.cpp | 5 + es2panda/ir/expressions/importExpression.h | 1 + .../ir/expressions/literals/bigIntLiteral.cpp | 2 + .../ir/expressions/literals/bigIntLiteral.h | 1 + .../expressions/literals/booleanLiteral.cpp | 2 + .../ir/expressions/literals/booleanLiteral.h | 1 + .../ir/expressions/literals/nullLiteral.cpp | 2 + .../ir/expressions/literals/nullLiteral.h | 1 + .../ir/expressions/literals/numberLiteral.cpp | 2 + .../ir/expressions/literals/numberLiteral.h | 1 + .../ir/expressions/literals/regExpLiteral.cpp | 2 + .../ir/expressions/literals/regExpLiteral.h | 1 + .../ir/expressions/literals/stringLiteral.cpp | 2 + .../ir/expressions/literals/stringLiteral.h | 1 + .../ir/expressions/literals/taggedLiteral.cpp | 3 + .../ir/expressions/literals/taggedLiteral.h | 1 + es2panda/ir/expressions/memberExpression.cpp | 6 + es2panda/ir/expressions/memberExpression.h | 1 + es2panda/ir/expressions/newExpression.cpp | 9 + es2panda/ir/expressions/newExpression.h | 1 + es2panda/ir/expressions/objectExpression.cpp | 11 + es2panda/ir/expressions/objectExpression.h | 1 + es2panda/ir/expressions/omittedExpression.cpp | 2 + es2panda/ir/expressions/omittedExpression.h | 1 + .../ir/expressions/sequenceExpression.cpp | 7 + es2panda/ir/expressions/sequenceExpression.h | 1 + es2panda/ir/expressions/superExpression.cpp | 2 + es2panda/ir/expressions/superExpression.h | 1 + .../expressions/taggedTemplateExpression.cpp | 10 + .../ir/expressions/taggedTemplateExpression.h | 1 + es2panda/ir/expressions/templateLiteral.cpp | 11 + es2panda/ir/expressions/templateLiteral.h | 1 + es2panda/ir/expressions/thisExpression.cpp | 2 + es2panda/ir/expressions/thisExpression.h | 1 + es2panda/ir/expressions/unaryExpression.cpp | 5 + es2panda/ir/expressions/unaryExpression.h | 1 + es2panda/ir/expressions/updateExpression.cpp | 5 + es2panda/ir/expressions/updateExpression.h | 1 + es2panda/ir/expressions/yieldExpression.cpp | 7 + es2panda/ir/expressions/yieldExpression.h | 1 + es2panda/ir/module/exportAllDeclaration.cpp | 9 + es2panda/ir/module/exportAllDeclaration.h | 1 + .../ir/module/exportDefaultDeclaration.cpp | 5 + es2panda/ir/module/exportDefaultDeclaration.h | 1 + es2panda/ir/module/exportNamedDeclaration.cpp | 15 + es2panda/ir/module/exportNamedDeclaration.h | 6 + es2panda/ir/module/exportSpecifier.cpp | 6 + es2panda/ir/module/exportSpecifier.h | 1 + es2panda/ir/module/importDeclaration.cpp | 9 + es2panda/ir/module/importDeclaration.h | 1 + es2panda/ir/module/importDefaultSpecifier.cpp | 5 + es2panda/ir/module/importDefaultSpecifier.h | 1 + .../ir/module/importNamespaceSpecifier.cpp | 5 + es2panda/ir/module/importNamespaceSpecifier.h | 1 + es2panda/ir/module/importSpecifier.cpp | 6 + es2panda/ir/module/importSpecifier.h | 1 + es2panda/ir/statements/blockStatement.cpp | 28 + es2panda/ir/statements/blockStatement.h | 1 + es2panda/ir/statements/breakStatement.cpp | 7 + es2panda/ir/statements/breakStatement.h | 1 + es2panda/ir/statements/classDeclaration.cpp | 9 + es2panda/ir/statements/classDeclaration.h | 1 + es2panda/ir/statements/continueStatement.cpp | 7 + es2panda/ir/statements/continueStatement.h | 1 + es2panda/ir/statements/debuggerStatement.cpp | 2 + es2panda/ir/statements/debuggerStatement.h | 1 + es2panda/ir/statements/doWhileStatement.cpp | 10 + es2panda/ir/statements/doWhileStatement.h | 1 + es2panda/ir/statements/emptyStatement.cpp | 2 + es2panda/ir/statements/emptyStatement.h | 1 + .../ir/statements/expressionStatement.cpp | 5 + es2panda/ir/statements/expressionStatement.h | 1 + es2panda/ir/statements/forInStatement.cpp | 12 + es2panda/ir/statements/forInStatement.h | 1 + es2panda/ir/statements/forOfStatement.cpp | 12 + es2panda/ir/statements/forOfStatement.h | 1 + es2panda/ir/statements/forUpdateStatement.cpp | 23 + es2panda/ir/statements/forUpdateStatement.h | 1 + .../ir/statements/functionDeclaration.cpp | 7 + es2panda/ir/statements/functionDeclaration.h | 1 + es2panda/ir/statements/ifStatement.cpp | 10 + es2panda/ir/statements/ifStatement.h | 1 + es2panda/ir/statements/labelledStatement.cpp | 6 + es2panda/ir/statements/labelledStatement.h | 1 + es2panda/ir/statements/returnStatement.cpp | 7 + es2panda/ir/statements/returnStatement.h | 1 + .../ir/statements/switchCaseStatement.cpp | 11 + es2panda/ir/statements/switchCaseStatement.h | 1 + es2panda/ir/statements/switchStatement.cpp | 12 + es2panda/ir/statements/switchStatement.h | 1 + es2panda/ir/statements/throwStatement.cpp | 5 + es2panda/ir/statements/throwStatement.h | 1 + es2panda/ir/statements/tryStatement.cpp | 13 + es2panda/ir/statements/tryStatement.h | 1 + .../ir/statements/variableDeclaration.cpp | 7 + es2panda/ir/statements/variableDeclaration.h | 1 + es2panda/ir/statements/variableDeclarator.cpp | 9 + es2panda/ir/statements/variableDeclarator.h | 1 + es2panda/ir/statements/whileStatement.cpp | 9 + es2panda/ir/statements/whileStatement.h | 1 + es2panda/ir/ts/tsAnyKeyword.cpp | 2 + es2panda/ir/ts/tsAnyKeyword.h | 1 + es2panda/ir/ts/tsArrayType.cpp | 5 + es2panda/ir/ts/tsArrayType.h | 1 + es2panda/ir/ts/tsAsExpression.cpp | 6 + es2panda/ir/ts/tsAsExpression.h | 1 + es2panda/ir/ts/tsBigintKeyword.cpp | 2 + es2panda/ir/ts/tsBigintKeyword.h | 1 + es2panda/ir/ts/tsBooleanKeyword.cpp | 2 + es2panda/ir/ts/tsBooleanKeyword.h | 1 + es2panda/ir/ts/tsClassImplements.cpp | 9 + es2panda/ir/ts/tsClassImplements.h | 3 +- es2panda/ir/ts/tsConditionalType.cpp | 8 + es2panda/ir/ts/tsConditionalType.h | 1 + es2panda/ir/ts/tsConstructorType.cpp | 16 + es2panda/ir/ts/tsConstructorType.h | 1 + es2panda/ir/ts/tsEnumDeclaration.cpp | 9 + es2panda/ir/ts/tsEnumDeclaration.h | 1 + es2panda/ir/ts/tsEnumMember.cpp | 9 + es2panda/ir/ts/tsEnumMember.h | 1 + es2panda/ir/ts/tsExternalModuleReference.cpp | 5 + es2panda/ir/ts/tsExternalModuleReference.h | 1 + es2panda/ir/ts/tsFunctionType.cpp | 16 + es2panda/ir/ts/tsFunctionType.h | 1 + es2panda/ir/ts/tsImportEqualsDeclaration.cpp | 6 + es2panda/ir/ts/tsImportEqualsDeclaration.h | 6 + es2panda/ir/ts/tsImportType.cpp | 13 + es2panda/ir/ts/tsImportType.h | 1 + es2panda/ir/ts/tsIndexSignature.cpp | 6 + es2panda/ir/ts/tsIndexSignature.h | 1 + es2panda/ir/ts/tsIndexedAccessType.cpp | 6 + es2panda/ir/ts/tsIndexedAccessType.h | 1 + es2panda/ir/ts/tsInferType.cpp | 5 + es2panda/ir/ts/tsInferType.h | 1 + es2panda/ir/ts/tsInterfaceBody.cpp | 7 + es2panda/ir/ts/tsInterfaceBody.h | 1 + es2panda/ir/ts/tsInterfaceDeclaration.cpp | 15 + es2panda/ir/ts/tsInterfaceDeclaration.h | 1 + es2panda/ir/ts/tsInterfaceHeritage.cpp | 5 + es2panda/ir/ts/tsInterfaceHeritage.h | 1 + es2panda/ir/ts/tsIntersectionType.cpp | 7 + es2panda/ir/ts/tsIntersectionType.h | 1 + es2panda/ir/ts/tsLiteralType.cpp | 5 + es2panda/ir/ts/tsLiteralType.h | 1 + es2panda/ir/ts/tsMappedType.cpp | 9 + es2panda/ir/ts/tsMappedType.h | 1 + es2panda/ir/ts/tsMethodSignature.cpp | 20 + es2panda/ir/ts/tsMethodSignature.h | 1 + es2panda/ir/ts/tsModuleBlock.cpp | 25 + es2panda/ir/ts/tsModuleBlock.h | 16 +- es2panda/ir/ts/tsModuleDeclaration.cpp | 11 + es2panda/ir/ts/tsModuleDeclaration.h | 28 +- es2panda/ir/ts/tsNamedTupleMember.cpp | 6 + es2panda/ir/ts/tsNamedTupleMember.h | 1 + es2panda/ir/ts/tsNeverKeyword.cpp | 2 + es2panda/ir/ts/tsNeverKeyword.h | 1 + es2panda/ir/ts/tsNonNullExpression.cpp | 5 + es2panda/ir/ts/tsNonNullExpression.h | 1 + es2panda/ir/ts/tsNullKeyword.cpp | 2 + es2panda/ir/ts/tsNullKeyword.h | 1 + es2panda/ir/ts/tsNumberKeyword.cpp | 2 + es2panda/ir/ts/tsNumberKeyword.h | 1 + es2panda/ir/ts/tsObjectKeyword.cpp | 2 + es2panda/ir/ts/tsObjectKeyword.h | 1 + es2panda/ir/ts/tsOptionalType.cpp | 5 + es2panda/ir/ts/tsOptionalType.h | 1 + es2panda/ir/ts/tsParameterProperty.cpp | 6 + es2panda/ir/ts/tsParameterProperty.h | 1 + es2panda/ir/ts/tsParenthesizedType.cpp | 5 + es2panda/ir/ts/tsParenthesizedType.h | 1 + es2panda/ir/ts/tsPrivateIdentifier.cpp | 13 + es2panda/ir/ts/tsPrivateIdentifier.h | 1 + es2panda/ir/ts/tsPropertySignature.cpp | 9 + es2panda/ir/ts/tsPropertySignature.h | 1 + es2panda/ir/ts/tsQualifiedName.cpp | 6 + es2panda/ir/ts/tsQualifiedName.h | 6 + es2panda/ir/ts/tsRestType.cpp | 5 + es2panda/ir/ts/tsRestType.h | 1 + es2panda/ir/ts/tsSignatureDeclaration.cpp | 20 +- es2panda/ir/ts/tsSignatureDeclaration.h | 1 + es2panda/ir/ts/tsStringKeyword.cpp | 2 + es2panda/ir/ts/tsStringKeyword.h | 1 + es2panda/ir/ts/tsSymbolKeyword.cpp | 2 + es2panda/ir/ts/tsSymbolKeyword.h | 1 + es2panda/ir/ts/tsTemplateLiteralType.cpp | 11 + es2panda/ir/ts/tsTemplateLiteralType.h | 1 + es2panda/ir/ts/tsThisType.cpp | 2 + es2panda/ir/ts/tsThisType.h | 1 + es2panda/ir/ts/tsTupleType.cpp | 7 + es2panda/ir/ts/tsTupleType.h | 1 + es2panda/ir/ts/tsTypeAliasDeclaration.cpp | 11 + es2panda/ir/ts/tsTypeAliasDeclaration.h | 1 + es2panda/ir/ts/tsTypeAssertion.cpp | 6 + es2panda/ir/ts/tsTypeAssertion.h | 1 + es2panda/ir/ts/tsTypeLiteral.cpp | 8 + es2panda/ir/ts/tsTypeLiteral.h | 1 + es2panda/ir/ts/tsTypeOperator.cpp | 5 + es2panda/ir/ts/tsTypeOperator.h | 1 + es2panda/ir/ts/tsTypeParameter.cpp | 13 + es2panda/ir/ts/tsTypeParameter.h | 1 + es2panda/ir/ts/tsTypeParameterDeclaration.cpp | 7 + es2panda/ir/ts/tsTypeParameterDeclaration.h | 1 + .../ir/ts/tsTypeParameterInstantiation.cpp | 7 + es2panda/ir/ts/tsTypeParameterInstantiation.h | 1 + es2panda/ir/ts/tsTypePredicate.cpp | 9 + es2panda/ir/ts/tsTypePredicate.h | 1 + es2panda/ir/ts/tsTypeQuery.cpp | 5 + es2panda/ir/ts/tsTypeQuery.h | 1 + es2panda/ir/ts/tsTypeReference.cpp | 9 + es2panda/ir/ts/tsTypeReference.h | 1 + es2panda/ir/ts/tsUndefinedKeyword.cpp | 2 + es2panda/ir/ts/tsUndefinedKeyword.h | 1 + es2panda/ir/ts/tsUnionType.cpp | 7 + es2panda/ir/ts/tsUnionType.h | 1 + es2panda/ir/ts/tsUnknownKeyword.cpp | 2 + es2panda/ir/ts/tsUnknownKeyword.h | 1 + es2panda/ir/ts/tsVoidKeyword.cpp | 2 + es2panda/ir/ts/tsVoidKeyword.h | 1 + es2panda/parser/parserImpl.cpp | 6 +- es2panda/parser/parserImpl.h | 18 +- es2panda/parser/program/program.cpp | 5 +- es2panda/parser/statementParser.cpp | 138 +++-- es2panda/parser/transformer/transformer.cpp | 527 ++++++++++++++++++ es2panda/parser/transformer/transformer.h | 134 +++++ .../compiler/test-ts-namespace-1-expected.txt | 1 + .../ts/cases/compiler/test-ts-namespace-1.ts | 19 + .../test-ts-namespace-10-expected.txt | 4 + .../ts/cases/compiler/test-ts-namespace-10.ts | 40 ++ .../test-ts-namespace-11-expected.txt | 4 + .../ts/cases/compiler/test-ts-namespace-11.ts | 34 ++ .../test-ts-namespace-12-expected.txt | 3 + .../ts/cases/compiler/test-ts-namespace-12.ts | 31 ++ .../test-ts-namespace-13-expected.txt | 3 + .../ts/cases/compiler/test-ts-namespace-13.ts | 33 ++ .../test-ts-namespace-14-expected.txt | 3 + .../ts/cases/compiler/test-ts-namespace-14.ts | 31 ++ .../test-ts-namespace-15-expected.txt | 2 + .../ts/cases/compiler/test-ts-namespace-15.ts | 27 + .../test-ts-namespace-16-expected.txt | 1 + .../ts/cases/compiler/test-ts-namespace-16.ts | 32 ++ .../test-ts-namespace-17-expected.txt | 3 + .../ts/cases/compiler/test-ts-namespace-17.ts | 29 + .../compiler/test-ts-namespace-2-expected.txt | 1 + .../ts/cases/compiler/test-ts-namespace-2.ts | 21 + .../compiler/test-ts-namespace-3-expected.txt | 1 + .../ts/cases/compiler/test-ts-namespace-3.ts | 21 + .../compiler/test-ts-namespace-4-expected.txt | 1 + .../ts/cases/compiler/test-ts-namespace-4.ts | 23 + .../compiler/test-ts-namespace-5-expected.txt | 3 + .../ts/cases/compiler/test-ts-namespace-5.ts | 32 ++ .../compiler/test-ts-namespace-6-expected.txt | 1 + .../ts/cases/compiler/test-ts-namespace-6.ts | 23 + .../compiler/test-ts-namespace-7-expected.txt | 3 + .../ts/cases/compiler/test-ts-namespace-7.ts | 49 ++ .../compiler/test-ts-namespace-8-expected.txt | 1 + .../ts/cases/compiler/test-ts-namespace-8.ts | 23 + .../compiler/test-ts-namespace-9-expected.txt | 2 + .../ts/cases/compiler/test-ts-namespace-9.ts | 29 + es2panda/test/test_tsc_ignore_list.txt | 277 ++++----- 321 files changed, 3069 insertions(+), 280 deletions(-) create mode 100644 es2panda/parser/transformer/transformer.cpp create mode 100644 es2panda/parser/transformer/transformer.h create mode 100644 es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-1-expected.txt create mode 100644 es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-1.ts create mode 100644 es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-10-expected.txt create mode 100644 es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-10.ts create mode 100644 es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-11-expected.txt create mode 100644 es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-11.ts create mode 100644 es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-12-expected.txt create mode 100644 es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-12.ts create mode 100644 es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-13-expected.txt create mode 100644 es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-13.ts create mode 100644 es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-14-expected.txt create mode 100644 es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-14.ts create mode 100644 es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-15-expected.txt create mode 100644 es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-15.ts create mode 100644 es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-16-expected.txt create mode 100644 es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-16.ts create mode 100644 es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-17-expected.txt create mode 100644 es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-17.ts create mode 100644 es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-2-expected.txt create mode 100644 es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-2.ts create mode 100644 es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-3-expected.txt create mode 100644 es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-3.ts create mode 100644 es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-4-expected.txt create mode 100644 es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-4.ts create mode 100644 es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-5-expected.txt create mode 100644 es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-5.ts create mode 100644 es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-6-expected.txt create mode 100644 es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-6.ts create mode 100644 es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-7-expected.txt create mode 100644 es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-7.ts create mode 100644 es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-8-expected.txt create mode 100644 es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-8.ts create mode 100644 es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-9-expected.txt create mode 100644 es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-9.ts diff --git a/es2panda/BUILD.gn b/es2panda/BUILD.gn index ed23cba114..18dc68c07c 100644 --- a/es2panda/BUILD.gn +++ b/es2panda/BUILD.gn @@ -197,6 +197,7 @@ es2panda_src = [ "parser/parserImpl.cpp", "parser/program/program.cpp", "parser/statementParser.cpp", + "parser/transformer/transformer.cpp", "typescript/checker.cpp", "typescript/core/binaryLikeExpression.cpp", "typescript/core/destructuringContext.cpp", diff --git a/es2panda/CMakeLists.txt b/es2panda/CMakeLists.txt index 80e619467f..d3ce0e9fb2 100644 --- a/es2panda/CMakeLists.txt +++ b/es2panda/CMakeLists.txt @@ -243,6 +243,7 @@ set(ES2PANDA_LIB_SRC parser/parserImpl.cpp parser/program/program.cpp parser/statementParser.cpp + parser/transformer/transformer.cpp typescript/checker.cpp typescript/core/binaryLikeExpression.cpp typescript/core/destructuringContext.cpp diff --git a/es2panda/binder/binder.cpp b/es2panda/binder/binder.cpp index a094a339ee..1a56f6cdc0 100644 --- a/es2panda/binder/binder.cpp +++ b/es2panda/binder/binder.cpp @@ -99,16 +99,21 @@ void Binder::AssignIndexToModuleVariable() program_->ModuleRecord()->AssignIndexToModuleVariable(topScope_->AsModuleScope()); } -void Binder::IdentifierAnalysis() +void Binder::IdentifierAnalysis(ResolveBindingFlags flags) { ASSERT(program_->Ast()); ASSERT(scope_ == topScope_); - BuildFunction(topScope_, MAIN_FUNC_NAME); - ResolveReferences(program_->Ast()); - AddMandatoryParams(); - if (topScope_->IsModuleScope()) { - AssignIndexToModuleVariable(); + bindingFlags_ = flags; + if (bindingFlags_ & ResolveBindingFlags::TS_BEFORE_TRANSFORM) { + ResolveReferences(program_->Ast()); + } else if (bindingFlags_ & ResolveBindingFlags::ALL) { + BuildFunction(topScope_, MAIN_FUNC_NAME); + ResolveReferences(program_->Ast()); + AddMandatoryParams(); + if (topScope_->IsModuleScope()) { + AssignIndexToModuleVariable(); + } } } @@ -229,12 +234,17 @@ void Binder::BuildFunction(FunctionScope *funcScope, util::StringView name) void Binder::BuildScriptFunction(Scope *outerScope, const ir::ScriptFunction *scriptFunc) { + if (bindingFlags_ & ResolveBindingFlags::TS_BEFORE_TRANSFORM) { + return; + } + if (scriptFunc->IsArrow()) { VariableScope *outerVarScope = outerScope->EnclosingVariableScope(); outerVarScope->AddFlag(VariableScopeFlags::INNER_ARROW); } - BuildFunction(scope_->AsFunctionScope(), util::Helpers::FunctionName(scriptFunc)); + ASSERT(scope_->IsFunctionScope() || scope_->IsTSModuleScope()); + BuildFunction(scope_->AsFunctionVariableScope(), util::Helpers::FunctionName(scriptFunc)); } void Binder::BuildVarDeclaratorId(const ir::AstNode *parent, ir::AstNode *childNode) @@ -571,11 +581,6 @@ void Binder::ResolveReference(const ir::AstNode *parent, ir::AstNode *childNode) ResolveReferences(childNode); break; } - case ir::AstNodeType::TS_MODULE_BLOCK: { - auto scopeCtx = LexicalScope::Enter(this, childNode->AsTSModuleBlock()->Scope()); - ResolveReferences(childNode); - break; - } default: { ResolveReferences(childNode); break; @@ -650,4 +655,25 @@ void Binder::AddMandatoryParams() } } } + +void Binder::AddDeclarationName(const util::StringView &name) +{ + if (extension_ != ScriptExtension::TS) { + return; + } + variableNames_.insert(name); + auto *scope = GetScope(); + while (scope != nullptr) { + if (scope->IsTSModuleScope()) { + scope->AsTSModuleScope()->AddDeclarationName(name); + } + scope = scope->Parent(); + } +} + +bool Binder::HasVariableName(const util::StringView &name) const +{ + return variableNames_.find(name) != variableNames_.end(); +} + } // namespace panda::es2panda::binder diff --git a/es2panda/binder/binder.h b/es2panda/binder/binder.h index e9213c472e..ebbbf6cb92 100644 --- a/es2panda/binder/binder.h +++ b/es2panda/binder/binder.h @@ -46,9 +46,11 @@ public: explicit Binder(parser::Program *program, ScriptExtension extension) : program_(program), functionScopes_(Allocator()->Adapter()), - functionNames_(Allocator()->Adapter()) + functionNames_(Allocator()->Adapter()), + variableNames_(Allocator()->Adapter()), + extension_(extension) { - if (extension == ScriptExtension::TS) { + if (extension_ == ScriptExtension::TS) { bindingOptions_ = ResolveBindingOptions::ALL; return; } @@ -61,7 +63,7 @@ public: ~Binder() = default; void InitTopScope(); - void IdentifierAnalysis(); + void IdentifierAnalysis(ResolveBindingFlags flags = ResolveBindingFlags::ALL); template T *AddDecl(const lexer::SourcePosition &pos, Args &&... args); @@ -110,6 +112,15 @@ public: return program_; } + void SetProgram(parser::Program *program) + { + program_ = program; + } + + void AddDeclarationName(const util::StringView &name); + + bool HasVariableName(const util::StringView &name) const; + static constexpr std::string_view FUNCTION_ARGUMENTS = "arguments"; static constexpr std::string_view MANDATORY_PARAM_FUNC = "=f"; static constexpr std::string_view MANDATORY_PARAM_NEW_TARGET = "=nt"; @@ -187,7 +198,10 @@ private: ArenaVector functionScopes_; ResolveBindingOptions bindingOptions_; ArenaSet functionNames_; + ArenaSet variableNames_; size_t functionNameIndex_ {1}; + ResolveBindingFlags bindingFlags_ {ResolveBindingFlags::ALL}; + ScriptExtension extension_; }; template @@ -238,6 +252,7 @@ T *Binder::AddTsDecl(const lexer::SourcePosition &pos, Args &&... args) T *decl = Allocator()->New(std::forward(args)...); if (scope_->AddTsDecl(Allocator(), decl, program_->Extension())) { + AddDeclarationName(decl->Name()); return decl; } @@ -250,6 +265,7 @@ T *Binder::AddDecl(const lexer::SourcePosition &pos, Args &&... args) T *decl = Allocator()->New(std::forward(args)...); if (scope_->AddDecl(Allocator(), decl, program_->Extension())) { + AddDeclarationName(decl->Name()); return decl; } @@ -263,6 +279,7 @@ T *Binder::AddDecl(const lexer::SourcePosition &pos, DeclarationFlags flag, Args decl->AddFlag(flag); if (scope_->AddDecl(Allocator(), decl, program_->Extension())) { + AddDeclarationName(decl->Name()); return decl; } diff --git a/es2panda/binder/declaration.h b/es2panda/binder/declaration.h index 84053347de..c835e99e5e 100644 --- a/es2panda/binder/declaration.h +++ b/es2panda/binder/declaration.h @@ -24,6 +24,7 @@ namespace panda::es2panda::ir { class AstNode; class ScriptFunction; class TSInterfaceDeclaration; +class TSModuleDeclaration; class ImportDeclaration; } // namespace panda::es2panda::ir @@ -235,9 +236,12 @@ public: } }; -class NameSpaceDecl : public Decl { +class NamespaceDecl : public MultiDecl { public: - explicit NameSpaceDecl(util::StringView name) : Decl(name) {} + explicit NamespaceDecl(ArenaAllocator *allocator, util::StringView name) + : MultiDecl(allocator, name) + { + } DeclType Type() const override { @@ -295,6 +299,16 @@ public: } }; +class ImportEqualsDecl : public Decl { +public: + explicit ImportEqualsDecl(util::StringView name) : Decl(name) {} + + DeclType Type() const override + { + return DeclType::IMPORT_EQUALS; + } +}; + } // namespace panda::es2panda::binder #endif diff --git a/es2panda/binder/scope.cpp b/es2panda/binder/scope.cpp index 634676482a..696521f188 100644 --- a/es2panda/binder/scope.cpp +++ b/es2panda/binder/scope.cpp @@ -305,6 +305,12 @@ bool FunctionScope::AddBinding(ArenaAllocator *allocator, Variable *currentVaria case DeclType::ENUM_LITERAL: { return AddTSBinding(allocator, currentVariable, newDecl, VariableFlags::ENUM_LITERAL); } + case DeclType::NAMESPACE: { + return AddTSBinding(allocator, newDecl, VariableFlags::NAMESPACE); + } + case DeclType::IMPORT_EQUALS: { + return AddTSBinding(allocator, newDecl, VariableFlags::IMPORT_EQUALS); + } case DeclType::INTERFACE: { return AddTSBinding(allocator, currentVariable, newDecl, VariableFlags::INTERFACE); } @@ -331,6 +337,12 @@ bool GlobalScope::AddBinding(ArenaAllocator *allocator, Variable *currentVariabl case DeclType::ENUM_LITERAL: { return AddTSBinding(allocator, currentVariable, newDecl, VariableFlags::ENUM_LITERAL); } + case DeclType::NAMESPACE: { + return AddTSBinding(allocator, newDecl, VariableFlags::NAMESPACE); + } + case DeclType::IMPORT_EQUALS: { + return AddTSBinding(allocator, newDecl, VariableFlags::IMPORT_EQUALS); + } case DeclType::INTERFACE: { return AddTSBinding(allocator, currentVariable, newDecl, VariableFlags::INTERFACE); } @@ -396,6 +408,12 @@ bool ModuleScope::AddBinding(ArenaAllocator *allocator, Variable *currentVariabl case DeclType::ENUM_LITERAL: { return AddTSBinding(allocator, currentVariable, newDecl, VariableFlags::ENUM_LITERAL); } + case DeclType::NAMESPACE: { + return AddTSBinding(allocator, newDecl, VariableFlags::NAMESPACE); + } + case DeclType::IMPORT_EQUALS: { + return AddTSBinding(allocator, newDecl, VariableFlags::IMPORT_EQUALS); + } case DeclType::INTERFACE: { return AddTSBinding(allocator, currentVariable, newDecl, VariableFlags::INTERFACE); } diff --git a/es2panda/binder/scope.h b/es2panda/binder/scope.h index 94b3791028..7375e89530 100644 --- a/es2panda/binder/scope.h +++ b/es2panda/binder/scope.h @@ -42,6 +42,101 @@ class Variable; using VariableMap = ArenaUnorderedMap; +class TSBindings { +public: + explicit TSBindings(ArenaAllocator *allocator) : allocator_(allocator) {} + + template + bool AddTSVariable(const util::StringView &name, Variable *variable) + { + static_assert(type < TSBindingType::COUNT); + size_t index = GetIndex(type); + if (tsBindings_[index] == nullptr) { + tsBindings_[index] = allocator_->New(allocator_->Adapter()); + } + return tsBindings_[index]->insert({name, variable}).second; + } + + template + Variable *FindTSVariable(const util::StringView &name) const + { + static_assert(type < TSBindingType::COUNT); + size_t index = GetIndex(type); + if (tsBindings_[index] == nullptr) { + return nullptr; + } + auto res = tsBindings_[index]->find(name); + if (res == tsBindings_[index]->end()) { + return nullptr; + } + return res->second; + } + + bool InTSBindings(const util::StringView &name) const + { + for (size_t i = 0; i < GetIndex(TSBindingType::COUNT); i++) { + if (tsBindings_[i] && tsBindings_[i]->find(name) != tsBindings_[i]->end()) { + return true; + } + } + return false; + } + +private: + size_t GetIndex(TSBindingType type) const + { + return static_cast(type); + } + + ArenaAllocator *allocator_; + std::array(TSBindingType::COUNT)> tsBindings_ {}; +}; + +class ExportBindings { +public: + explicit ExportBindings(ArenaAllocator *allocator) + : exportBindings_(allocator->Adapter()), + exportTSBindings_(allocator) + { + } + + Variable *FindExportVariable(const util::StringView &name) const + { + auto res = exportBindings_.find(name); + if (res == exportBindings_.end()) { + return nullptr; + } + return res->second; + } + + bool AddExportVariable(const util::StringView &name, Variable *var) + { + return exportBindings_.insert({name, var}).second; + } + + bool InExportBindings(const util::StringView &name) const + { + auto res = FindExportVariable(name); + return res != nullptr || exportTSBindings_.InTSBindings(name); + } + + template + Variable *FindExportTSVariable(const util::StringView &name) const + { + return exportTSBindings_.FindTSVariable(name); + } + + template + bool AddExportTSVariable(const util::StringView &name, Variable *var) + { + return exportTSBindings_.AddTSVariable(name, var); + } + +private: + VariableMap exportBindings_; + TSBindings exportTSBindings_; +}; + class ScopeFindResult { public: ScopeFindResult() = default; @@ -216,9 +311,26 @@ public: bool HasVarDecl(const util::StringView &name) const; + template + Variable *FindLocalTSVariable(const util::StringView &name) const + { + return tsBindings_.FindTSVariable(name); + } + + template + void AddLocalTSVariable(const util::StringView &name, Variable *var) + { + tsBindings_.AddTSVariable(name, var); + } + + bool InLocalTSBindings(const util::StringView &name) const + { + return tsBindings_.InTSBindings(name); + } + protected: explicit Scope(ArenaAllocator *allocator, Scope *parent) - : parent_(parent), decls_(allocator->Adapter()), bindings_(allocator->Adapter()) + : parent_(parent), decls_(allocator->Adapter()), bindings_(allocator->Adapter()), tsBindings_(allocator) { } @@ -237,9 +349,15 @@ protected: bool AddLocal(ArenaAllocator *allocator, Variable *currentVariable, Decl *newDecl, [[maybe_unused]] ScriptExtension extension); + void SetParent(Scope *parent) + { + parent_ = parent; + } + Scope *parent_ {}; ArenaVector decls_; VariableMap bindings_; + TSBindings tsBindings_; const ir::AstNode *node_ {}; const compiler::IRNode *startIns_ {}; const compiler::IRNode *endIns_ {}; @@ -307,6 +425,9 @@ protected: template bool AddTSBinding(ArenaAllocator *allocator, Variable *currentVariable, Decl *newDecl, VariableFlags flags); + template + bool AddTSBinding(ArenaAllocator *allocator, Decl *newDecl, VariableFlags flags); + template bool AddLexical(ArenaAllocator *allocator, Variable *currentVariable, Decl *newDecl); @@ -425,6 +546,12 @@ public: return paramScope_; } + void AddBindsFromParam() + { + ASSERT(paramScope_); + this->bindings_.insert(paramScope_->Bindings().begin(), paramScope_->Bindings().end()); + } + protected: T *paramScope_; }; @@ -607,6 +734,68 @@ public: [[maybe_unused]] ScriptExtension extension) override; }; +class TSModuleScope : public FunctionScope { +public: + explicit TSModuleScope(ArenaAllocator *allocator, Scope *parent, ExportBindings *exportBindings) + : FunctionScope(allocator, nullptr), exportBindings_(exportBindings), variableNames_(allocator->Adapter()) + { + paramScope_ = allocator->New(allocator, parent); + paramScope_->BindFunctionScope(this); + SetParent(paramScope_); + } + + ScopeType Type() const override + { + return ScopeType::TSMODULE; + } + + template + Variable *FindExportTSVariable(const util::StringView &name) const + { + return exportBindings_->FindExportTSVariable(name); + } + + template + bool AddExportTSVariable(const util::StringView &name, Variable *var) + { + return exportBindings_->AddExportTSVariable(name, var); + } + + Variable *FindExportVariable(const util::StringView &name) const + { + return exportBindings_->FindExportVariable(name); + } + + bool AddExportVariable(const util::StringView &name, Variable *var) + { + return exportBindings_->AddExportVariable(name, var); + } + + bool AddExportVariable(const util::StringView &name) + { + return exportBindings_->AddExportVariable(name, FindLocal(name)); + } + + bool InExportBindings(const util::StringView &name) const + { + return exportBindings_->InExportBindings(name); + } + + void AddDeclarationName(const util::StringView &name) + { + variableNames_.insert(name); + } + + bool HasVariableName(const util::StringView &name) const + { + return variableNames_.find(name) != variableNames_.end(); + } + +private: + ExportBindings *exportBindings_; + ArenaSet variableNames_; +}; + inline VariableFlags VariableScope::DeclFlagToVariableFlag(DeclarationFlags declFlag) { VariableFlags varFlag = VariableFlags::NONE; @@ -681,10 +870,38 @@ bool VariableScope::AddTSBinding(ArenaAllocator *allocator, [[maybe_unused]] Var VariableFlags flags) { ASSERT(!currentVariable); + // TODO(xucheng): move the ts variables to tsBindings_ bindings_.insert({newDecl->Name(), allocator->New(newDecl, flags)}); return true; } +template +bool VariableScope::AddTSBinding(ArenaAllocator *allocator, Decl *newDecl, VariableFlags flags) +{ + switch (flags) { + case VariableFlags::NAMESPACE: { + return tsBindings_.AddTSVariable( + newDecl->Name(), allocator->New(newDecl, flags)); + } + case VariableFlags::ENUM_LITERAL: { + return tsBindings_.AddTSVariable( + newDecl->Name(), allocator->New(newDecl, flags)); + } + case VariableFlags::INTERFACE: { + return tsBindings_.AddTSVariable( + newDecl->Name(), allocator->New(newDecl, flags)); + } + case VariableFlags::IMPORT_EQUALS: { + return tsBindings_.AddTSVariable( + newDecl->Name(), allocator->New(newDecl, flags)); + } + default: { + break; + } + } + return false; +} + template bool VariableScope::AddLexical(ArenaAllocator *allocator, Variable *currentVariable, Decl *newDecl) { diff --git a/es2panda/binder/variable.cpp b/es2panda/binder/variable.cpp index 7407d8a5c5..7c82dd583c 100644 --- a/es2panda/binder/variable.cpp +++ b/es2panda/binder/variable.cpp @@ -68,6 +68,8 @@ void LocalVariable::SetLexical(Scope *scope, util::Hotfix *hotfixHelper) void GlobalVariable::SetLexical([[maybe_unused]] Scope *scope, [[maybe_unused]] util::Hotfix *hotfixHelper) {} void ModuleVariable::SetLexical([[maybe_unused]] Scope *scope, [[maybe_unused]] util::Hotfix *hotfixHelper) {} void EnumVariable::SetLexical([[maybe_unused]] Scope *scope, [[maybe_unused]] util::Hotfix *hotfixHelper) {} +void NamespaceVariable::SetLexical([[maybe_unused]] Scope *scope, [[maybe_unused]] util::Hotfix *hotfixHelper) {} +void ImportEqualsVariable::SetLexical([[maybe_unused]] Scope *scope, [[maybe_unused]] util::Hotfix *hotfixHelper) {} void EnumVariable::ResetDecl(Decl *decl) { diff --git a/es2panda/binder/variable.h b/es2panda/binder/variable.h index a17b88885a..d9408beec3 100644 --- a/es2panda/binder/variable.h +++ b/es2panda/binder/variable.h @@ -34,6 +34,7 @@ namespace panda::es2panda::binder { class Decl; class Scope; class VariableScope; +class ExportBindings; #define DECLARE_CLASSES(type, className) class className; VARIABLE_TYPES(DECLARE_CLASSES) @@ -240,5 +241,55 @@ private: bool backReference_ {}; }; +class NamespaceVariable : public Variable { +public: + explicit NamespaceVariable(Decl *decl, VariableFlags flags) : Variable(decl, flags) {} + + VariableType Type() const override + { + return VariableType::NAMESPACE; + } + + void SetLexical([[maybe_unused]] Scope *scope, [[maybe_unused]] util::Hotfix *hotfixHelper = nullptr) override; + + ExportBindings *GetExportBindings() + { + return exportBindings_; + } + + void SetExportBindings(ExportBindings *exportBindings) + { + exportBindings_ = exportBindings; + } + +private: + ExportBindings *exportBindings_ {nullptr}; +}; + +class ImportEqualsVariable : public Variable { +public: + explicit ImportEqualsVariable(Decl *decl, VariableFlags flags) : Variable(decl, flags) {} + + VariableType Type() const override + { + return VariableType::IMPORT_EQUALS; + } + + void SetLexical([[maybe_unused]] Scope *scope, [[maybe_unused]] util::Hotfix *hotfixHelper = nullptr) override; + + Scope *GetScope() + { + return scope_; + } + + void SetScope(Scope *scope) + { + scope_ = scope; + } + +private: + Scope *scope_ {nullptr}; +}; + } // namespace panda::es2panda::binder #endif diff --git a/es2panda/binder/variableFlags.h b/es2panda/binder/variableFlags.h index 3b65900970..cc60c28879 100644 --- a/es2panda/binder/variableFlags.h +++ b/es2panda/binder/variableFlags.h @@ -16,6 +16,7 @@ #ifndef ES2PANDA_COMPILER_SCOPES_VARIABLE_FLAGS_H #define ES2PANDA_COMPILER_SCOPES_VARIABLE_FLAGS_H +#include #include namespace panda::es2panda::binder { @@ -29,13 +30,14 @@ namespace panda::es2panda::binder { _(PARAM, ParameterDecl) \ /* TS */ \ _(TYPE_ALIAS, TypeAliasDecl) \ - _(NAMESPACE, NameSpaceDecl) \ + _(NAMESPACE, NamespaceDecl) \ _(INTERFACE, InterfaceDecl) \ _(ENUM_LITERAL, EnumLiteralDecl) \ _(TYPE_PARAMETER, TypeParameterDecl) \ _(PROPERTY, PropertyDecl) \ _(METHOD, MethodDecl) \ - _(ENUM, EnumDecl) + _(ENUM, EnumDecl) \ + _(IMPORT_EQUALS, ImportEqualsDecl) enum class DeclType { NONE, @@ -55,7 +57,9 @@ enum class DeclType { _(LOOP_DECL, LoopDeclarationScope) \ _(FUNCTION, FunctionScope) \ _(GLOBAL, GlobalScope) \ - _(MODULE, ModuleScope) + _(MODULE, ModuleScope) \ + _(TSMODULE, TSModuleScope) + enum class ScopeType { #define GEN_SCOPE_TYPES(type, class_name) type, @@ -72,11 +76,20 @@ enum class ResolveBindingOptions { DEFINE_BITOPS(ResolveBindingOptions) -#define VARIABLE_TYPES(_) \ - _(LOCAL, LocalVariable) \ - _(GLOBAL, GlobalVariable) \ - _(MODULE, ModuleVariable) \ - _(ENUM, EnumVariable) +enum class ResolveBindingFlags { + ALL = 1U << 0U, + TS_BEFORE_TRANSFORM = 1U << 1U, +}; + +DEFINE_BITOPS(ResolveBindingFlags) + +#define VARIABLE_TYPES(_) \ + _(LOCAL, LocalVariable) \ + _(GLOBAL, GlobalVariable) \ + _(MODULE, ModuleVariable) \ + _(ENUM, EnumVariable) \ + _(NAMESPACE, NamespaceVariable) \ + _(IMPORT_EQUALS, ImportEqualsVariable) enum class VariableType { #define GEN_VARIABLE_TYPES(type, class_name) type, @@ -111,6 +124,8 @@ enum class VariableFlags { REST_ARG = 1 << 14, NUMERIC_NAME = 1 << 15, TYPE = 1 << 16, + NAMESPACE = 1 << 17, + IMPORT_EQUALS = 1 << 18, INDEX_LIKE = COMPUTED_INDEX | INDEX_NAME, @@ -150,6 +165,14 @@ enum class DeclarationFlags { DEFINE_BITOPS(DeclarationFlags) +enum class TSBindingType : size_t { + NAMESPACE = 0, + ENUM, + INTERFACE, + IMPORT_EQUALS, + COUNT, +}; + } // namespace panda::es2panda::binder #endif diff --git a/es2panda/compiler/base/hoisting.cpp b/es2panda/compiler/base/hoisting.cpp index 5f5b6370b6..2bf9a660b6 100644 --- a/es2panda/compiler/base/hoisting.cpp +++ b/es2panda/compiler/base/hoisting.cpp @@ -69,7 +69,8 @@ static void HoistFunction(PandaGen *pg, binder::Variable *var, const binder::Fun return; } - ASSERT(scope->IsFunctionScope() || scope->IsCatchScope() || scope->IsLocalScope() || scope->IsModuleScope()); + ASSERT(scope->IsFunctionScope() || scope->IsCatchScope() || scope->IsLocalScope() || + scope->IsModuleScope() || scope->IsTSModuleScope()); binder::ScopeFindResult result(decl->Name(), scope, 0, var); pg->DefineFunction(decl->Node(), scriptFunction, internalName); diff --git a/es2panda/compiler/core/compileQueue.cpp b/es2panda/compiler/core/compileQueue.cpp index f8709aa36d..ea11d2bd33 100644 --- a/es2panda/compiler/core/compileQueue.cpp +++ b/es2panda/compiler/core/compileQueue.cpp @@ -78,7 +78,7 @@ void CompileFunctionJob::Run() FunctionEmitter funcEmitter(&allocator, &pg); funcEmitter.Generate(context_->HotfixHelper()); - context_->GetEmitter()->AddFunction(&funcEmitter); + context_->GetEmitter()->AddFunction(&funcEmitter, context_); if (dependant_) { dependant_->Signal(); diff --git a/es2panda/compiler/core/compilerImpl.cpp b/es2panda/compiler/core/compilerImpl.cpp index 368783be96..f0e0448c2e 100644 --- a/es2panda/compiler/core/compilerImpl.cpp +++ b/es2panda/compiler/core/compilerImpl.cpp @@ -45,16 +45,6 @@ panda::pandasm::Program *CompilerImpl::Compile(parser::Program *program, const e context.AddHotfixHelper(hotfixHelper_); } - if (program->Extension() == ScriptExtension::TS && options.enableTypeCheck) { - ArenaAllocator localAllocator(SpaceType::SPACE_TYPE_COMPILER, nullptr, true); - auto checker = std::make_unique(&localAllocator, context.Binder()); - checker->StartChecker(); - } - - if (options.parseOnly) { - return nullptr; - } - queue_ = new CompileFuncQueue(threadCount_, &context); queue_->Schedule(); diff --git a/es2panda/compiler/core/emitter/emitter.cpp b/es2panda/compiler/core/emitter/emitter.cpp index a438ad9515..8d1b08456d 100644 --- a/es2panda/compiler/core/emitter/emitter.cpp +++ b/es2panda/compiler/core/emitter/emitter.cpp @@ -371,7 +371,7 @@ Emitter::~Emitter() delete prog_; } -void Emitter::AddFunction(FunctionEmitter *func) +void Emitter::AddFunction(FunctionEmitter *func, CompilerContext *context) { std::lock_guard lock(m_); @@ -381,7 +381,8 @@ void Emitter::AddFunction(FunctionEmitter *func) for (auto &[idx, buf] : func->LiteralBuffers()) { auto literalArrayInstance = panda::pandasm::LiteralArray(std::move(buf)); - prog_->literalarray_table.emplace(std::to_string(idx), std::move(literalArrayInstance)); + prog_->literalarray_table.emplace(std::string(context->RecordName()) + std::to_string(idx), + std::move(literalArrayInstance)); } auto *function = func->Function(); diff --git a/es2panda/compiler/core/emitter/emitter.h b/es2panda/compiler/core/emitter/emitter.h index 3bf135f729..f461ece869 100644 --- a/es2panda/compiler/core/emitter/emitter.h +++ b/es2panda/compiler/core/emitter/emitter.h @@ -102,7 +102,7 @@ public: NO_COPY_SEMANTIC(Emitter); NO_MOVE_SEMANTIC(Emitter); - void AddFunction(FunctionEmitter *func); + void AddFunction(FunctionEmitter *func, CompilerContext *context); void AddSourceTextModuleRecord(ModuleRecordEmitter *module, CompilerContext *context); static void DumpAsm(const panda::pandasm::Program *prog); panda::pandasm::Program *Finalize(bool dumpDebugInfo, util::Hotfix *hotfixHelper); diff --git a/es2panda/compiler/core/function.cpp b/es2panda/compiler/core/function.cpp index c2f0f7298e..b9a4bce84f 100644 --- a/es2panda/compiler/core/function.cpp +++ b/es2panda/compiler/core/function.cpp @@ -16,7 +16,6 @@ #include "function.h" #include -#include #include #include #include @@ -27,6 +26,7 @@ #include #include #include +#include namespace panda::es2panda::compiler { @@ -185,7 +185,7 @@ static void CompileFunctionOrProgram(PandaGen *pg) } else { pg->FunctionInit(nullptr); - if (topScope->IsFunctionScope()) { + if (topScope->IsFunctionScope() || topScope->IsTSModuleScope()) { CompileFunction(pg); } else { ASSERT(topScope->IsGlobalScope() || topScope->IsModuleScope()); diff --git a/es2panda/es2panda.cpp b/es2panda/es2panda.cpp index 81d07bbdb2..b5e978169b 100644 --- a/es2panda/es2panda.cpp +++ b/es2panda/es2panda.cpp @@ -20,6 +20,8 @@ #include #include #include +#include +#include #include #include @@ -38,6 +40,9 @@ Compiler::Compiler(ScriptExtension ext) : Compiler(ext, DEFAULT_THREAD_COUNT) {} Compiler::Compiler(ScriptExtension ext, size_t threadCount) : parser_(new parser::ParserImpl(ext)), compiler_(new compiler::CompilerImpl(threadCount)) { + if (parser_->Extension() == ScriptExtension::TS) { + transformer_ = std::make_unique(parser_->Allocator()); + } } Compiler::~Compiler() @@ -67,11 +72,27 @@ panda::pandasm::Program *Compiler::Compile(const SourceFile &input, const Compil try { auto ast = parser_->Parse(fname, src, rname, kind); + ast.Binder()->SetProgram(&ast); if (options.dumpAst) { std::cout << ast.Dump() << std::endl; } + if (ast.Extension() == ScriptExtension::TS && options.enableTypeCheck) { + ArenaAllocator localAllocator(SpaceType::SPACE_TYPE_COMPILER, nullptr, true); + auto checker = std::make_unique(&localAllocator, ast.Binder()); + checker->StartChecker(); + } + + if (options.parseOnly) { + return nullptr; + } + + if (ast.Extension() == ScriptExtension::TS) { + transformer_->Transform(&ast); + ast.Binder()->IdentifierAnalysis(binder::ResolveBindingFlags::ALL); + } + std::string debugInfoSourceFile = options.debugInfoSourceFile.empty() ? sourcefile : options.debugInfoSourceFile; auto *prog = compiler_->Compile(&ast, options, debugInfoSourceFile); diff --git a/es2panda/es2panda.h b/es2panda/es2panda.h index 43cca7772c..94878e743e 100644 --- a/es2panda/es2panda.h +++ b/es2panda/es2panda.h @@ -31,6 +31,7 @@ struct Program; namespace panda::es2panda { namespace parser { class ParserImpl; +class Transformer; enum class ScriptKind; } // namespace parser @@ -195,6 +196,7 @@ public: private: parser::ParserImpl *parser_; compiler::CompilerImpl *compiler_; + std::unique_ptr transformer_ {nullptr}; Error error_; }; } // namespace panda::es2panda diff --git a/es2panda/ir/astNode.h b/es2panda/ir/astNode.h index bdaf842d03..19fd7d0a72 100644 --- a/es2panda/ir/astNode.h +++ b/es2panda/ir/astNode.h @@ -16,13 +16,14 @@ #ifndef ES2PANDA_IR_ASTNODE_H #define ES2PANDA_IR_ASTNODE_H +#include +#include + +#include +#include #include #include #include -#include - -#include -#include namespace panda::es2panda::compiler { class PandaGen; @@ -39,6 +40,9 @@ class AstNode; using NodeTraverser = std::function; +using UpdateNodes = std::variant>; +using NodeUpdater = std::function; + enum class AstNodeType { #define DECLARE_NODE_TYPES(nodeType, className) nodeType, AST_NODE_MAPPING(DECLARE_NODE_TYPES) @@ -258,6 +262,16 @@ public: parent_ = parent; } + const AstNode *Original() const + { + return original_; + } + + void SetOriginal(const AstNode *original) + { + original_ = original; + } + binder::Variable *Variable() const { return variable_; @@ -272,6 +286,7 @@ public: virtual void Dump(ir::AstDumper *dumper) const = 0; virtual void Compile([[maybe_unused]] compiler::PandaGen *pg) const = 0; virtual checker::Type *Check([[maybe_unused]] checker::Checker *checker) const = 0; + virtual void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) = 0; protected: void SetType(AstNodeType type) @@ -283,6 +298,7 @@ protected: lexer::SourceRange range_ {}; AstNodeType type_; binder::Variable *variable_ {nullptr}; + const AstNode *original_ {nullptr}; }; } // namespace panda::es2panda::ir diff --git a/es2panda/ir/astNodeMapping.h b/es2panda/ir/astNodeMapping.h index aa260c1c87..0ae3acc429 100644 --- a/es2panda/ir/astNodeMapping.h +++ b/es2panda/ir/astNodeMapping.h @@ -128,6 +128,7 @@ _(TS_INDEX_SIGNATURE, TSIndexSignature) \ _(TS_TYPE_QUERY, TSTypeQuery) \ _(TS_AS_EXPRESSION, TSAsExpression) \ + _(TS_CLASS_IMPLEMENTS, TSClassImplements) \ _(TS_TYPE_ASSERTION, TSTypeAssertion) \ _(TAGGED_TEMPLATE_EXPRESSION, TaggedTemplateExpression) \ _(TAGGED_LITERAL, TaggedLiteral) \ diff --git a/es2panda/ir/base/catchClause.cpp b/es2panda/ir/base/catchClause.cpp index 8b1144f6d0..809d72eff5 100644 --- a/es2panda/ir/base/catchClause.cpp +++ b/es2panda/ir/base/catchClause.cpp @@ -15,6 +15,7 @@ #include "catchClause.h" +#include #include #include #include @@ -83,4 +84,15 @@ checker::Type *CatchClause::Check(checker::Checker *checker) const return nullptr; } +void CatchClause::UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) +{ + if (param_) { + auto paramScopeCtx = binder::LexicalScope::Enter(binder, scope_->ParamScope()); + param_ = std::get(cb(param_))->AsExpression(); + } + + auto scopeCtx = binder::LexicalScope::Enter(binder, scope_); + body_ = std::get(cb(body_))->AsBlockStatement(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/base/catchClause.h b/es2panda/ir/base/catchClause.h index 950a62e090..dac3dc4e66 100644 --- a/es2panda/ir/base/catchClause.h +++ b/es2panda/ir/base/catchClause.h @@ -72,6 +72,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) override; protected: binder::CatchScope *scope_; diff --git a/es2panda/ir/base/classDefinition.cpp b/es2panda/ir/base/classDefinition.cpp index 2b850b83e5..ed8938dd01 100644 --- a/es2panda/ir/base/classDefinition.cpp +++ b/es2panda/ir/base/classDefinition.cpp @@ -16,6 +16,7 @@ #include "classDefinition.h" #include +#include #include #include #include @@ -309,4 +310,39 @@ checker::Type *ClassDefinition::Check(checker::Checker *checker) const return checker->GlobalAnyType(); } +void ClassDefinition::UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) +{ + auto scopeCtx = binder::LexicalScope::Enter(binder, scope_); + + if (ident_) { + ident_ = std::get(cb(ident_))->AsIdentifier(); + } + + if (typeParams_) { + typeParams_ = std::get(cb(typeParams_))->AsTSTypeParameterDeclaration(); + } + + if (superClass_) { + superClass_ = std::get(cb(superClass_))->AsExpression(); + } + + if (superTypeParams_) { + superTypeParams_ = std::get(cb(superTypeParams_))->AsTSTypeParameterInstantiation(); + } + + for (auto iter = implements_.begin(); iter != implements_.end(); iter++) { + *iter = std::get(cb(*iter))->AsTSClassImplements(); + } + + ctor_ = std::get(cb(ctor_))->AsMethodDefinition(); + + for (auto iter = body_.begin(); iter != body_.end(); iter++) { + *iter = std::get(cb(*iter))->AsStatement(); + } + + for (auto iter = indexSignatures_.begin(); iter != indexSignatures_.end(); iter++) { + *iter = std::get(cb(*iter))->AsTSIndexSignature(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/base/classDefinition.h b/es2panda/ir/base/classDefinition.h index 2d58a5e1dd..a5210c2545 100644 --- a/es2panda/ir/base/classDefinition.h +++ b/es2panda/ir/base/classDefinition.h @@ -125,6 +125,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) override; private: compiler::VReg CompileHeritageClause(compiler::PandaGen *pg) const; diff --git a/es2panda/ir/base/classProperty.cpp b/es2panda/ir/base/classProperty.cpp index b39f7f2530..0c8f44b9e9 100644 --- a/es2panda/ir/base/classProperty.cpp +++ b/es2panda/ir/base/classProperty.cpp @@ -15,13 +15,16 @@ #include "classProperty.h" -#include -#include -#include - #include #include +#include "binder/binder.h" +#include "ir/astDump.h" +#include "ir/base/decorator.h" +#include "ir/base/scriptFunction.h" +#include "ir/expression.h" +#include "util/helpers.h" + namespace panda::es2panda::ir { void ClassProperty::Iterate(const NodeTraverser &cb) const @@ -65,4 +68,24 @@ checker::Type *ClassProperty::Check([[maybe_unused]] checker::Checker *checker) return nullptr; } +void ClassProperty::UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) +{ + const ir::ScriptFunction *ctor = util::Helpers::GetContainingConstructor(this); + auto scopeCtx = binder::LexicalScope::Enter(binder, ctor->Scope()); + + key_ = std::get(cb(key_))->AsExpression(); + + if (value_) { + value_ = std::get(cb(value_))->AsExpression(); + } + + if (typeAnnotation_) { + typeAnnotation_ = std::get(cb(typeAnnotation_))->AsExpression(); + } + + for (auto iter = decorators_.begin(); iter != decorators_.end(); iter++) { + *iter = std::get(cb(*iter))->AsDecorator(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/base/classProperty.h b/es2panda/ir/base/classProperty.h index e1bc499436..2380eea356 100644 --- a/es2panda/ir/base/classProperty.h +++ b/es2panda/ir/base/classProperty.h @@ -85,6 +85,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) override; private: Expression *key_; diff --git a/es2panda/ir/base/decorator.cpp b/es2panda/ir/base/decorator.cpp index 801230527b..fefba92b4c 100644 --- a/es2panda/ir/base/decorator.cpp +++ b/es2panda/ir/base/decorator.cpp @@ -37,4 +37,9 @@ checker::Type *Decorator::Check([[maybe_unused]] checker::Checker *checker) cons return nullptr; } +void Decorator::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + expr_ = std::get(cb(expr_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/base/decorator.h b/es2panda/ir/base/decorator.h index d01c7f01bf..8ea87b4b04 100644 --- a/es2panda/ir/base/decorator.h +++ b/es2panda/ir/base/decorator.h @@ -43,6 +43,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *expr_; diff --git a/es2panda/ir/base/metaProperty.cpp b/es2panda/ir/base/metaProperty.cpp index 043ba395e3..a8df61c894 100644 --- a/es2panda/ir/base/metaProperty.cpp +++ b/es2panda/ir/base/metaProperty.cpp @@ -63,4 +63,6 @@ checker::Type *MetaProperty::Check(checker::Checker *checker) const return checker->GlobalAnyType(); } +void MetaProperty::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/base/metaProperty.h b/es2panda/ir/base/metaProperty.h index 91eef27dc5..667de6e80c 100644 --- a/es2panda/ir/base/metaProperty.h +++ b/es2panda/ir/base/metaProperty.h @@ -44,6 +44,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: MetaPropertyKind kind_; diff --git a/es2panda/ir/base/methodDefinition.cpp b/es2panda/ir/base/methodDefinition.cpp index a3798ecfba..4c814e6eac 100644 --- a/es2panda/ir/base/methodDefinition.cpp +++ b/es2panda/ir/base/methodDefinition.cpp @@ -89,4 +89,18 @@ checker::Type *MethodDefinition::Check([[maybe_unused]] checker::Checker *checke return nullptr; } +void MethodDefinition::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + key_ = std::get(cb(key_))->AsExpression(); + value_ = std::get(cb(value_))->AsFunctionExpression(); + + for (auto iter = overloads_.begin(); iter != overloads_.end(); iter++) { + *iter = std::get(cb(*iter))->AsMethodDefinition(); + } + + for (auto iter = decorators_.begin(); iter != decorators_.end(); iter++) { + *iter = std::get(cb(*iter))->AsDecorator(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/base/methodDefinition.h b/es2panda/ir/base/methodDefinition.h index 1170e01693..77c5fc8c29 100644 --- a/es2panda/ir/base/methodDefinition.h +++ b/es2panda/ir/base/methodDefinition.h @@ -116,6 +116,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: MethodDefinitionKind kind_; diff --git a/es2panda/ir/base/property.cpp b/es2panda/ir/base/property.cpp index 5802e381fa..0bdc9c4d5d 100644 --- a/es2panda/ir/base/property.cpp +++ b/es2panda/ir/base/property.cpp @@ -135,4 +135,10 @@ checker::Type *Property::Check([[maybe_unused]] checker::Checker *checker) const return nullptr; } +void Property::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + key_ = std::get(cb(key_))->AsExpression(); + value_ = std::get(cb(value_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/base/property.h b/es2panda/ir/base/property.h index f47df4b114..1a9b225378 100644 --- a/es2panda/ir/base/property.h +++ b/es2panda/ir/base/property.h @@ -112,6 +112,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: PropertyKind kind_; diff --git a/es2panda/ir/base/scriptFunction.cpp b/es2panda/ir/base/scriptFunction.cpp index 3e2f39e87f..52a766ed10 100644 --- a/es2panda/ir/base/scriptFunction.cpp +++ b/es2panda/ir/base/scriptFunction.cpp @@ -15,6 +15,7 @@ #include "scriptFunction.h" +#include #include #include #include @@ -97,4 +98,31 @@ checker::Type *ScriptFunction::Check([[maybe_unused]] checker::Checker *checker) return nullptr; } +void ScriptFunction::UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) +{ + if (id_) { + id_ = std::get(cb(id_))->AsIdentifier(); + } + + auto paramScopeCtx = binder::LexicalScope::Enter(binder, scope_->ParamScope()); + + if (typeParams_) { + typeParams_ = std::get(cb(typeParams_))->AsTSTypeParameterDeclaration(); + } + + for (auto iter = params_.begin(); iter != params_.end(); iter++) { + *iter = std::get(cb(*iter))->AsExpression(); + } + + if (returnTypeAnnotation_) { + returnTypeAnnotation_ = std::get(cb(returnTypeAnnotation_))->AsExpression(); + } + + auto scopeCtx = binder::LexicalScope::Enter(binder, scope_); + + if (body_) { + body_ = std::get(cb(body_)); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/base/scriptFunction.h b/es2panda/ir/base/scriptFunction.h index 9eb543f4d0..5a0db1202e 100644 --- a/es2panda/ir/base/scriptFunction.h +++ b/es2panda/ir/base/scriptFunction.h @@ -161,6 +161,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) override; private: binder::FunctionScope *scope_; diff --git a/es2panda/ir/base/spreadElement.cpp b/es2panda/ir/base/spreadElement.cpp index fec7ceadd1..ca16f5cfd8 100644 --- a/es2panda/ir/base/spreadElement.cpp +++ b/es2panda/ir/base/spreadElement.cpp @@ -102,4 +102,12 @@ checker::Type *SpreadElement::Check([[maybe_unused]] checker::Checker *checker) return nullptr; } +void SpreadElement::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + argument_ = std::get(cb(argument_))->AsExpression(); + if (typeAnnotation_) { + typeAnnotation_ = std::get(cb(typeAnnotation_))->AsExpression(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/base/spreadElement.h b/es2panda/ir/base/spreadElement.h index 858ef0122b..ff01e3bc94 100644 --- a/es2panda/ir/base/spreadElement.h +++ b/es2panda/ir/base/spreadElement.h @@ -57,6 +57,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *argument_; diff --git a/es2panda/ir/base/templateElement.cpp b/es2panda/ir/base/templateElement.cpp index 4013a17ddf..12dea11a08 100644 --- a/es2panda/ir/base/templateElement.cpp +++ b/es2panda/ir/base/templateElement.cpp @@ -39,4 +39,6 @@ checker::Type *TemplateElement::Check([[maybe_unused]] checker::Checker *checker return nullptr; } +void TemplateElement::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/base/templateElement.h b/es2panda/ir/base/templateElement.h index b0d136262e..f717c4f4e4 100644 --- a/es2panda/ir/base/templateElement.h +++ b/es2panda/ir/base/templateElement.h @@ -53,6 +53,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; protected: util::StringView raw_ {}; diff --git a/es2panda/ir/expressions/arrayExpression.cpp b/es2panda/ir/expressions/arrayExpression.cpp index 906912f18e..9df2ecbef0 100644 --- a/es2panda/ir/expressions/arrayExpression.cpp +++ b/es2panda/ir/expressions/arrayExpression.cpp @@ -379,4 +379,11 @@ checker::Type *ArrayExpression::CheckPattern(checker::Checker *checker) const false); } +void ArrayExpression::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + for (auto iter = elements_.begin(); iter != elements_.end(); iter++) { + *iter = std::get(cb(*iter))->AsExpression(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/arrayExpression.h b/es2panda/ir/expressions/arrayExpression.h index 66ed5614cb..f9bdd7f80c 100644 --- a/es2panda/ir/expressions/arrayExpression.h +++ b/es2panda/ir/expressions/arrayExpression.h @@ -86,6 +86,7 @@ public: void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; checker::Type *CheckPattern(checker::Checker *checker) const; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: ArenaVector elements_; diff --git a/es2panda/ir/expressions/arrowFunctionExpression.cpp b/es2panda/ir/expressions/arrowFunctionExpression.cpp index 82e7ea038d..353ac9631d 100644 --- a/es2panda/ir/expressions/arrowFunctionExpression.cpp +++ b/es2panda/ir/expressions/arrowFunctionExpression.cpp @@ -70,4 +70,9 @@ checker::Type *ArrowFunctionExpression::Check(checker::Checker *checker) const return funcType; } +void ArrowFunctionExpression::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + func_ = std::get(cb(func_))->AsScriptFunction(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/arrowFunctionExpression.h b/es2panda/ir/expressions/arrowFunctionExpression.h index 8c60759936..d2d8d69182 100644 --- a/es2panda/ir/expressions/arrowFunctionExpression.h +++ b/es2panda/ir/expressions/arrowFunctionExpression.h @@ -52,6 +52,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: ScriptFunction *func_; diff --git a/es2panda/ir/expressions/assignmentExpression.cpp b/es2panda/ir/expressions/assignmentExpression.cpp index 0905c4fe2a..9e89751a4e 100644 --- a/es2panda/ir/expressions/assignmentExpression.cpp +++ b/es2panda/ir/expressions/assignmentExpression.cpp @@ -207,4 +207,10 @@ checker::Type *AssignmentExpression::Check(checker::Checker *checker) const return nullptr; } +void AssignmentExpression::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + left_ = std::get(cb(left_))->AsExpression(); + right_ = std::get(cb(right_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/assignmentExpression.h b/es2panda/ir/expressions/assignmentExpression.h index 53b240cc35..93f92c9b31 100644 --- a/es2panda/ir/expressions/assignmentExpression.h +++ b/es2panda/ir/expressions/assignmentExpression.h @@ -75,6 +75,7 @@ public: void Compile(compiler::PandaGen *pg) const override; void CompilePattern(compiler::PandaGen *pg) const; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *left_; diff --git a/es2panda/ir/expressions/awaitExpression.cpp b/es2panda/ir/expressions/awaitExpression.cpp index 32b76645d9..a4c74d986e 100644 --- a/es2panda/ir/expressions/awaitExpression.cpp +++ b/es2panda/ir/expressions/awaitExpression.cpp @@ -53,4 +53,11 @@ checker::Type *AwaitExpression::Check(checker::Checker *checker) const return checker->GlobalAnyType(); } +void AwaitExpression::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + if (argument_) { + argument_ = std::get(cb(argument_))->AsExpression(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/awaitExpression.h b/es2panda/ir/expressions/awaitExpression.h index 8759f5c053..3386735901 100644 --- a/es2panda/ir/expressions/awaitExpression.h +++ b/es2panda/ir/expressions/awaitExpression.h @@ -42,6 +42,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *argument_; diff --git a/es2panda/ir/expressions/binaryExpression.cpp b/es2panda/ir/expressions/binaryExpression.cpp index b34d315374..58fafd3d1a 100644 --- a/es2panda/ir/expressions/binaryExpression.cpp +++ b/es2panda/ir/expressions/binaryExpression.cpp @@ -157,4 +157,10 @@ checker::Type *BinaryExpression::Check(checker::Checker *checker) const return nullptr; } +void BinaryExpression::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + left_ = std::get(cb(left_))->AsExpression(); + right_ = std::get(cb(right_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/binaryExpression.h b/es2panda/ir/expressions/binaryExpression.h index f44860fd82..8ac98c5c57 100644 --- a/es2panda/ir/expressions/binaryExpression.h +++ b/es2panda/ir/expressions/binaryExpression.h @@ -79,6 +79,7 @@ public: void Compile(compiler::PandaGen *pg) const override; void CompileLogical(compiler::PandaGen *pg) const; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *left_; diff --git a/es2panda/ir/expressions/callExpression.cpp b/es2panda/ir/expressions/callExpression.cpp index 881b6f5078..3c83bbc32e 100644 --- a/es2panda/ir/expressions/callExpression.cpp +++ b/es2panda/ir/expressions/callExpression.cpp @@ -169,4 +169,17 @@ checker::Type *CallExpression::Check(checker::Checker *checker) const return nullptr; } +void CallExpression::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + callee_ = std::get(cb(callee_))->AsExpression(); + + if (typeParams_) { + typeParams_ = std::get(cb(typeParams_))->AsTSTypeParameterInstantiation(); + } + + for (auto iter = arguments_.begin(); iter != arguments_.end(); iter++) { + *iter = std::get(cb(*iter))->AsExpression(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/callExpression.h b/es2panda/ir/expressions/callExpression.h index 406496b71f..18576bd2b9 100644 --- a/es2panda/ir/expressions/callExpression.h +++ b/es2panda/ir/expressions/callExpression.h @@ -73,6 +73,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: compiler::VReg CreateSpreadArguments(compiler::PandaGen *pg) const; diff --git a/es2panda/ir/expressions/chainExpression.cpp b/es2panda/ir/expressions/chainExpression.cpp index 495cb42bea..d2656c05ac 100644 --- a/es2panda/ir/expressions/chainExpression.cpp +++ b/es2panda/ir/expressions/chainExpression.cpp @@ -50,4 +50,9 @@ checker::Type *ChainExpression::Check(checker::Checker *checker) const return expression_->Check(checker); } +void ChainExpression::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + expression_ = std::get(cb(expression_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/chainExpression.h b/es2panda/ir/expressions/chainExpression.h index faafcdef3e..3077fe8d02 100644 --- a/es2panda/ir/expressions/chainExpression.h +++ b/es2panda/ir/expressions/chainExpression.h @@ -45,6 +45,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *expression_; diff --git a/es2panda/ir/expressions/classExpression.cpp b/es2panda/ir/expressions/classExpression.cpp index 20580662a2..1b9ccbf2b7 100644 --- a/es2panda/ir/expressions/classExpression.cpp +++ b/es2panda/ir/expressions/classExpression.cpp @@ -40,4 +40,9 @@ checker::Type *ClassExpression::Check([[maybe_unused]] checker::Checker *checker return nullptr; } +void ClassExpression::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + def_ = std::get(cb(def_))->AsClassDefinition(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/classExpression.h b/es2panda/ir/expressions/classExpression.h index b478ab4229..b4f350b3ee 100644 --- a/es2panda/ir/expressions/classExpression.h +++ b/es2panda/ir/expressions/classExpression.h @@ -44,6 +44,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: ClassDefinition *def_; diff --git a/es2panda/ir/expressions/conditionalExpression.cpp b/es2panda/ir/expressions/conditionalExpression.cpp index 102342f507..e1bd59e648 100644 --- a/es2panda/ir/expressions/conditionalExpression.cpp +++ b/es2panda/ir/expressions/conditionalExpression.cpp @@ -61,4 +61,11 @@ checker::Type *ConditionalExpression::Check(checker::Checker *checker) const return checker->CreateUnionType({consequentType, alternateType}); } +void ConditionalExpression::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + test_ = std::get(cb(test_))->AsExpression(); + consequent_ = std::get(cb(consequent_))->AsExpression(); + alternate_ = std::get(cb(alternate_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/conditionalExpression.h b/es2panda/ir/expressions/conditionalExpression.h index 10fb8c4e95..ae40889e81 100644 --- a/es2panda/ir/expressions/conditionalExpression.h +++ b/es2panda/ir/expressions/conditionalExpression.h @@ -65,6 +65,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *test_; diff --git a/es2panda/ir/expressions/functionExpression.cpp b/es2panda/ir/expressions/functionExpression.cpp index a4e5d34126..4982bcd57f 100644 --- a/es2panda/ir/expressions/functionExpression.cpp +++ b/es2panda/ir/expressions/functionExpression.cpp @@ -68,4 +68,9 @@ checker::Type *FunctionExpression::Check(checker::Checker *checker) const return funcType; } +void FunctionExpression::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + func_ = std::get(cb(func_))->AsScriptFunction(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/functionExpression.h b/es2panda/ir/expressions/functionExpression.h index 23555b6416..3211855b98 100644 --- a/es2panda/ir/expressions/functionExpression.h +++ b/es2panda/ir/expressions/functionExpression.h @@ -44,6 +44,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: ScriptFunction *func_; diff --git a/es2panda/ir/expressions/identifier.cpp b/es2panda/ir/expressions/identifier.cpp index 7662a99ac0..26989d93db 100644 --- a/es2panda/ir/expressions/identifier.cpp +++ b/es2panda/ir/expressions/identifier.cpp @@ -99,4 +99,15 @@ checker::Type *Identifier::Check(checker::Checker *checker) const return checker->GetTypeOfVariable(Variable()); } +void Identifier::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + if (typeAnnotation_) { + typeAnnotation_ = std::get(cb(typeAnnotation_))->AsExpression(); + } + + for (auto iter = decorators_.begin(); iter != decorators_.end(); iter++) { + *iter = std::get(cb(*iter))->AsDecorator(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/identifier.h b/es2panda/ir/expressions/identifier.h index fce780b661..543397f6c6 100644 --- a/es2panda/ir/expressions/identifier.h +++ b/es2panda/ir/expressions/identifier.h @@ -126,6 +126,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: util::StringView name_; diff --git a/es2panda/ir/expressions/importExpression.cpp b/es2panda/ir/expressions/importExpression.cpp index ec88d45b4d..fbd4020a3b 100644 --- a/es2panda/ir/expressions/importExpression.cpp +++ b/es2panda/ir/expressions/importExpression.cpp @@ -41,4 +41,9 @@ checker::Type *ImportExpression::Check([[maybe_unused]] checker::Checker *checke return nullptr; } +void ImportExpression::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + source_ = std::get(cb(source_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/importExpression.h b/es2panda/ir/expressions/importExpression.h index efee65dcc4..d3affc819a 100644 --- a/es2panda/ir/expressions/importExpression.h +++ b/es2panda/ir/expressions/importExpression.h @@ -37,6 +37,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *source_; diff --git a/es2panda/ir/expressions/literals/bigIntLiteral.cpp b/es2panda/ir/expressions/literals/bigIntLiteral.cpp index 19290522c6..0a274fa6a2 100644 --- a/es2panda/ir/expressions/literals/bigIntLiteral.cpp +++ b/es2panda/ir/expressions/literals/bigIntLiteral.cpp @@ -46,4 +46,6 @@ checker::Type *BigIntLiteral::Check(checker::Checker *checker) const return newBigintLiteralType; } +void BigIntLiteral::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/literals/bigIntLiteral.h b/es2panda/ir/expressions/literals/bigIntLiteral.h index 2890dbab67..ef1aee885f 100644 --- a/es2panda/ir/expressions/literals/bigIntLiteral.h +++ b/es2panda/ir/expressions/literals/bigIntLiteral.h @@ -48,6 +48,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: util::StringView src_; diff --git a/es2panda/ir/expressions/literals/booleanLiteral.cpp b/es2panda/ir/expressions/literals/booleanLiteral.cpp index b0dd0f4fca..018727b429 100644 --- a/es2panda/ir/expressions/literals/booleanLiteral.cpp +++ b/es2panda/ir/expressions/literals/booleanLiteral.cpp @@ -38,4 +38,6 @@ checker::Type *BooleanLiteral::Check(checker::Checker *checker) const return boolean_ ? checker->GlobalTrueType() : checker->GlobalFalseType(); } +void BooleanLiteral::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/literals/booleanLiteral.h b/es2panda/ir/expressions/literals/booleanLiteral.h index 384a6e36e8..24bcb03114 100644 --- a/es2panda/ir/expressions/literals/booleanLiteral.h +++ b/es2panda/ir/expressions/literals/booleanLiteral.h @@ -47,6 +47,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: bool boolean_; diff --git a/es2panda/ir/expressions/literals/nullLiteral.cpp b/es2panda/ir/expressions/literals/nullLiteral.cpp index 67a65c2877..b643a18801 100644 --- a/es2panda/ir/expressions/literals/nullLiteral.cpp +++ b/es2panda/ir/expressions/literals/nullLiteral.cpp @@ -38,4 +38,6 @@ checker::Type *NullLiteral::Check(checker::Checker *checker) const return checker->GlobalNullType(); } +void NullLiteral::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/literals/nullLiteral.h b/es2panda/ir/expressions/literals/nullLiteral.h index fc5a9d1da0..2118fbf69e 100644 --- a/es2panda/ir/expressions/literals/nullLiteral.h +++ b/es2panda/ir/expressions/literals/nullLiteral.h @@ -42,6 +42,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; }; } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/literals/numberLiteral.cpp b/es2panda/ir/expressions/literals/numberLiteral.cpp index 11782233ee..347f776f4b 100644 --- a/es2panda/ir/expressions/literals/numberLiteral.cpp +++ b/es2panda/ir/expressions/literals/numberLiteral.cpp @@ -59,4 +59,6 @@ checker::Type *NumberLiteral::Check(checker::Checker *checker) const return newNumLiteralType; } +void NumberLiteral::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/literals/numberLiteral.h b/es2panda/ir/expressions/literals/numberLiteral.h index cd61076a81..1aaf97960e 100644 --- a/es2panda/ir/expressions/literals/numberLiteral.h +++ b/es2panda/ir/expressions/literals/numberLiteral.h @@ -65,6 +65,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: double number_; diff --git a/es2panda/ir/expressions/literals/regExpLiteral.cpp b/es2panda/ir/expressions/literals/regExpLiteral.cpp index f63d01aff1..b87cd4ab3d 100644 --- a/es2panda/ir/expressions/literals/regExpLiteral.cpp +++ b/es2panda/ir/expressions/literals/regExpLiteral.cpp @@ -60,4 +60,6 @@ checker::Type *RegExpLiteral::Check(checker::Checker *checker) const return checker->GlobalAnyType(); } +void RegExpLiteral::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/literals/regExpLiteral.h b/es2panda/ir/expressions/literals/regExpLiteral.h index 649143052a..2425403a50 100644 --- a/es2panda/ir/expressions/literals/regExpLiteral.h +++ b/es2panda/ir/expressions/literals/regExpLiteral.h @@ -56,6 +56,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: util::StringView pattern_; diff --git a/es2panda/ir/expressions/literals/stringLiteral.cpp b/es2panda/ir/expressions/literals/stringLiteral.cpp index d68d4ea58b..08b50558c6 100644 --- a/es2panda/ir/expressions/literals/stringLiteral.cpp +++ b/es2panda/ir/expressions/literals/stringLiteral.cpp @@ -48,4 +48,6 @@ checker::Type *StringLiteral::Check(checker::Checker *checker) const return newStrLiteralType; } +void StringLiteral::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/literals/stringLiteral.h b/es2panda/ir/expressions/literals/stringLiteral.h index 4ff338957a..0862d86a34 100644 --- a/es2panda/ir/expressions/literals/stringLiteral.h +++ b/es2panda/ir/expressions/literals/stringLiteral.h @@ -53,6 +53,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: util::StringView str_; diff --git a/es2panda/ir/expressions/literals/taggedLiteral.cpp b/es2panda/ir/expressions/literals/taggedLiteral.cpp index 5c8d455345..5421e1a034 100644 --- a/es2panda/ir/expressions/literals/taggedLiteral.cpp +++ b/es2panda/ir/expressions/literals/taggedLiteral.cpp @@ -36,4 +36,7 @@ checker::Type *TaggedLiteral::Check([[maybe_unused]] checker::Checker *checker) { UNREACHABLE(); } + +void TaggedLiteral::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/literals/taggedLiteral.h b/es2panda/ir/expressions/literals/taggedLiteral.h index c8ecd27e70..06cd7028bd 100644 --- a/es2panda/ir/expressions/literals/taggedLiteral.h +++ b/es2panda/ir/expressions/literals/taggedLiteral.h @@ -74,6 +74,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: uint16_t num_ {}; diff --git a/es2panda/ir/expressions/memberExpression.cpp b/es2panda/ir/expressions/memberExpression.cpp index 6754ecf672..c3bbed8a26 100644 --- a/es2panda/ir/expressions/memberExpression.cpp +++ b/es2panda/ir/expressions/memberExpression.cpp @@ -147,4 +147,10 @@ checker::Type *MemberExpression::Check(checker::Checker *checker) const return nullptr; } +void MemberExpression::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + object_ = std::get(cb(object_))->AsExpression(); + property_ = std::get(cb(property_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/memberExpression.h b/es2panda/ir/expressions/memberExpression.h index 8fbac5d816..a38b20dfb2 100644 --- a/es2panda/ir/expressions/memberExpression.h +++ b/es2panda/ir/expressions/memberExpression.h @@ -78,6 +78,7 @@ public: void CompileObject(compiler::PandaGen *pg, compiler::VReg dest) const; compiler::Operand CompileKey(compiler::PandaGen *pg) const; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *object_; diff --git a/es2panda/ir/expressions/newExpression.cpp b/es2panda/ir/expressions/newExpression.cpp index b7b2f25352..ed02d396ae 100644 --- a/es2panda/ir/expressions/newExpression.cpp +++ b/es2panda/ir/expressions/newExpression.cpp @@ -81,4 +81,13 @@ checker::Type *NewExpression::Check(checker::Checker *checker) const return nullptr; } +void NewExpression::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + callee_ = std::get(cb(callee_))->AsExpression(); + + for (auto iter = arguments_.begin(); iter != arguments_.end(); iter++) { + *iter = std::get(cb(*iter))->AsExpression(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/newExpression.h b/es2panda/ir/expressions/newExpression.h index d4d88bd140..380009c473 100644 --- a/es2panda/ir/expressions/newExpression.h +++ b/es2panda/ir/expressions/newExpression.h @@ -59,6 +59,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *callee_; diff --git a/es2panda/ir/expressions/objectExpression.cpp b/es2panda/ir/expressions/objectExpression.cpp index b4c365666a..2e5e0e924d 100644 --- a/es2panda/ir/expressions/objectExpression.cpp +++ b/es2panda/ir/expressions/objectExpression.cpp @@ -743,4 +743,15 @@ checker::Type *ObjectExpression::Check(checker::Checker *checker) const return returnType; } +void ObjectExpression::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + for (auto iter = properties_.begin(); iter != properties_.end(); iter++) { + *iter = std::get(cb(*iter))->AsExpression(); + } + + if (typeAnnotation_) { + typeAnnotation_ = std::get(cb(typeAnnotation_))->AsExpression(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/objectExpression.h b/es2panda/ir/expressions/objectExpression.h index 16f4974005..e4c7989d55 100644 --- a/es2panda/ir/expressions/objectExpression.h +++ b/es2panda/ir/expressions/objectExpression.h @@ -82,6 +82,7 @@ public: void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; checker::Type *CheckPattern(checker::Checker *checker) const; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: void FillInLiteralBuffer(compiler::LiteralBuffer *buf, diff --git a/es2panda/ir/expressions/omittedExpression.cpp b/es2panda/ir/expressions/omittedExpression.cpp index 05f4f3f56b..d15d28b2f5 100644 --- a/es2panda/ir/expressions/omittedExpression.cpp +++ b/es2panda/ir/expressions/omittedExpression.cpp @@ -34,4 +34,6 @@ checker::Type *OmittedExpression::Check(checker::Checker *checker) const return checker->GlobalUndefinedType(); } +void OmittedExpression::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/omittedExpression.h b/es2panda/ir/expressions/omittedExpression.h index f8e0ab4094..c61f5198ae 100644 --- a/es2panda/ir/expressions/omittedExpression.h +++ b/es2panda/ir/expressions/omittedExpression.h @@ -37,6 +37,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; }; } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/sequenceExpression.cpp b/es2panda/ir/expressions/sequenceExpression.cpp index c2f276f1f7..6e842ced3a 100644 --- a/es2panda/ir/expressions/sequenceExpression.cpp +++ b/es2panda/ir/expressions/sequenceExpression.cpp @@ -45,4 +45,11 @@ checker::Type *SequenceExpression::Check(checker::Checker *checker) const return checker->GlobalAnyType(); } +void SequenceExpression::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + for (auto iter = sequence_.begin(); iter != sequence_.end(); iter++) { + *iter = std::get(cb(*iter))->AsExpression(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/sequenceExpression.h b/es2panda/ir/expressions/sequenceExpression.h index e2d1f2c942..ff751fe1c3 100644 --- a/es2panda/ir/expressions/sequenceExpression.h +++ b/es2panda/ir/expressions/sequenceExpression.h @@ -49,6 +49,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: ArenaVector sequence_; diff --git a/es2panda/ir/expressions/superExpression.cpp b/es2panda/ir/expressions/superExpression.cpp index 8c305d231d..14673a4475 100644 --- a/es2panda/ir/expressions/superExpression.cpp +++ b/es2panda/ir/expressions/superExpression.cpp @@ -46,4 +46,6 @@ checker::Type *SuperExpression::Check(checker::Checker *checker) const return checker->GlobalAnyType(); } +void SuperExpression::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/superExpression.h b/es2panda/ir/expressions/superExpression.h index d1cabbd033..ae162fe7a3 100644 --- a/es2panda/ir/expressions/superExpression.h +++ b/es2panda/ir/expressions/superExpression.h @@ -37,6 +37,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: }; diff --git a/es2panda/ir/expressions/taggedTemplateExpression.cpp b/es2panda/ir/expressions/taggedTemplateExpression.cpp index 1564832381..12ac2cb3f0 100644 --- a/es2panda/ir/expressions/taggedTemplateExpression.cpp +++ b/es2panda/ir/expressions/taggedTemplateExpression.cpp @@ -89,4 +89,14 @@ checker::Type *TaggedTemplateExpression::Check(checker::Checker *checker) const return checker->GlobalAnyType(); } +void TaggedTemplateExpression::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + if (typeParams_) { + typeParams_ = std::get(cb(typeParams_))->AsTSTypeParameterInstantiation(); + } + + tag_ = std::get(cb(tag_))->AsExpression(); + quasi_ = std::get(cb(quasi_))->AsTemplateLiteral(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/taggedTemplateExpression.h b/es2panda/ir/expressions/taggedTemplateExpression.h index c2d48e5254..eac3dc1e14 100644 --- a/es2panda/ir/expressions/taggedTemplateExpression.h +++ b/es2panda/ir/expressions/taggedTemplateExpression.h @@ -59,6 +59,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; protected: Expression *tag_; diff --git a/es2panda/ir/expressions/templateLiteral.cpp b/es2panda/ir/expressions/templateLiteral.cpp index 6519cad1bf..1a66c3b81a 100644 --- a/es2panda/ir/expressions/templateLiteral.cpp +++ b/es2panda/ir/expressions/templateLiteral.cpp @@ -85,4 +85,15 @@ checker::Type *TemplateLiteral::Check(checker::Checker *checker) const return checker->GlobalAnyType(); } +void TemplateLiteral::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + for (auto iter = expressions_.begin(); iter != expressions_.end(); iter++) { + *iter = std::get(cb(*iter))->AsExpression(); + } + + for (auto iter = quasis_.begin(); iter != quasis_.end(); iter++) { + *iter = std::get(cb(*iter))->AsTemplateElement(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/templateLiteral.h b/es2panda/ir/expressions/templateLiteral.h index 31bf6761d1..c68adfe56d 100644 --- a/es2panda/ir/expressions/templateLiteral.h +++ b/es2panda/ir/expressions/templateLiteral.h @@ -51,6 +51,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; protected: ArenaVector quasis_; diff --git a/es2panda/ir/expressions/thisExpression.cpp b/es2panda/ir/expressions/thisExpression.cpp index 397b0bab53..2bd432c787 100644 --- a/es2panda/ir/expressions/thisExpression.cpp +++ b/es2panda/ir/expressions/thisExpression.cpp @@ -54,4 +54,6 @@ checker::Type *ThisExpression::Check(checker::Checker *checker) const return checker->GlobalAnyType(); } +void ThisExpression::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/thisExpression.h b/es2panda/ir/expressions/thisExpression.h index 6e3f0e4ea2..e3cc4b9475 100644 --- a/es2panda/ir/expressions/thisExpression.h +++ b/es2panda/ir/expressions/thisExpression.h @@ -37,6 +37,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: }; diff --git a/es2panda/ir/expressions/unaryExpression.cpp b/es2panda/ir/expressions/unaryExpression.cpp index 6eb17d0c3d..6f4620b932 100644 --- a/es2panda/ir/expressions/unaryExpression.cpp +++ b/es2panda/ir/expressions/unaryExpression.cpp @@ -209,4 +209,9 @@ checker::Type *UnaryExpression::Check(checker::Checker *checker) const return nullptr; } +void UnaryExpression::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + argument_ = std::get(cb(argument_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/unaryExpression.h b/es2panda/ir/expressions/unaryExpression.h index 4e6c5b1d89..fc3714fa2b 100644 --- a/es2panda/ir/expressions/unaryExpression.h +++ b/es2panda/ir/expressions/unaryExpression.h @@ -51,6 +51,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *argument_; diff --git a/es2panda/ir/expressions/updateExpression.cpp b/es2panda/ir/expressions/updateExpression.cpp index 588b34f52b..77d0be0a12 100644 --- a/es2panda/ir/expressions/updateExpression.cpp +++ b/es2panda/ir/expressions/updateExpression.cpp @@ -70,4 +70,9 @@ checker::Type *UpdateExpression::Check(checker::Checker *checker) const return checker->GetUnaryResultType(operandType); } +void UpdateExpression::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + argument_ = std::get(cb(argument_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/updateExpression.h b/es2panda/ir/expressions/updateExpression.h index 4344eaa28a..0641e3fe61 100644 --- a/es2panda/ir/expressions/updateExpression.h +++ b/es2panda/ir/expressions/updateExpression.h @@ -59,6 +59,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *argument_; diff --git a/es2panda/ir/expressions/yieldExpression.cpp b/es2panda/ir/expressions/yieldExpression.cpp index b479072706..5fbb5cbfe4 100644 --- a/es2panda/ir/expressions/yieldExpression.cpp +++ b/es2panda/ir/expressions/yieldExpression.cpp @@ -58,4 +58,11 @@ checker::Type *YieldExpression::Check(checker::Checker *checker) const return checker->GlobalAnyType(); } +void YieldExpression::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + if (argument_) { + argument_ = std::get(cb(argument_))->AsExpression(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/expressions/yieldExpression.h b/es2panda/ir/expressions/yieldExpression.h index af9cce60ff..5129260e39 100644 --- a/es2panda/ir/expressions/yieldExpression.h +++ b/es2panda/ir/expressions/yieldExpression.h @@ -51,6 +51,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *argument_; diff --git a/es2panda/ir/module/exportAllDeclaration.cpp b/es2panda/ir/module/exportAllDeclaration.cpp index 0913f07b36..a9562694e4 100644 --- a/es2panda/ir/module/exportAllDeclaration.cpp +++ b/es2panda/ir/module/exportAllDeclaration.cpp @@ -42,4 +42,13 @@ checker::Type *ExportAllDeclaration::Check([[maybe_unused]] checker::Checker *ch return nullptr; } +void ExportAllDeclaration::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + source_ = std::get(cb(source_))->AsStringLiteral(); + + if (exported_) { + exported_ = std::get(cb(exported_))->AsIdentifier(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/module/exportAllDeclaration.h b/es2panda/ir/module/exportAllDeclaration.h index f9c94ddff7..149dae0196 100644 --- a/es2panda/ir/module/exportAllDeclaration.h +++ b/es2panda/ir/module/exportAllDeclaration.h @@ -53,6 +53,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: StringLiteral *source_; diff --git a/es2panda/ir/module/exportDefaultDeclaration.cpp b/es2panda/ir/module/exportDefaultDeclaration.cpp index 7612a55558..1050faefd9 100644 --- a/es2panda/ir/module/exportDefaultDeclaration.cpp +++ b/es2panda/ir/module/exportDefaultDeclaration.cpp @@ -49,4 +49,9 @@ checker::Type *ExportDefaultDeclaration::Check([[maybe_unused]] checker::Checker return nullptr; } +void ExportDefaultDeclaration::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + decl_ = std::get(cb(decl_)); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/module/exportDefaultDeclaration.h b/es2panda/ir/module/exportDefaultDeclaration.h index 624555363c..6ab246e25a 100644 --- a/es2panda/ir/module/exportDefaultDeclaration.h +++ b/es2panda/ir/module/exportDefaultDeclaration.h @@ -50,6 +50,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: AstNode *decl_; diff --git a/es2panda/ir/module/exportNamedDeclaration.cpp b/es2panda/ir/module/exportNamedDeclaration.cpp index 1b5f851104..b8a0f08ce9 100644 --- a/es2panda/ir/module/exportNamedDeclaration.cpp +++ b/es2panda/ir/module/exportNamedDeclaration.cpp @@ -59,4 +59,19 @@ checker::Type *ExportNamedDeclaration::Check([[maybe_unused]] checker::Checker * return nullptr; } +void ExportNamedDeclaration::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + if (decl_) { + decl_ = std::get(cb(decl_))->AsStatement(); + } else { + if (source_) { + source_ = std::get(cb(source_))->AsStringLiteral(); + } + + for (auto iter = specifiers_.begin(); iter != specifiers_.end(); iter++) { + *iter = std::get(cb(*iter))->AsExportSpecifier(); + } + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/module/exportNamedDeclaration.h b/es2panda/ir/module/exportNamedDeclaration.h index 05c4089f71..d863428fe3 100644 --- a/es2panda/ir/module/exportNamedDeclaration.h +++ b/es2panda/ir/module/exportNamedDeclaration.h @@ -55,6 +55,11 @@ public: return decl_; } + Statement *Decl() + { + return decl_; + } + const StringLiteral *Source() const { return source_; @@ -69,6 +74,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: StringLiteral *source_; diff --git a/es2panda/ir/module/exportSpecifier.cpp b/es2panda/ir/module/exportSpecifier.cpp index 39710daf39..4458e409dd 100644 --- a/es2panda/ir/module/exportSpecifier.cpp +++ b/es2panda/ir/module/exportSpecifier.cpp @@ -38,4 +38,10 @@ checker::Type *ExportSpecifier::Check([[maybe_unused]] checker::Checker *checker return nullptr; } +void ExportSpecifier::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + local_ = std::get(cb(local_))->AsIdentifier(); + exported_ = std::get(cb(exported_))->AsIdentifier(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/module/exportSpecifier.h b/es2panda/ir/module/exportSpecifier.h index d160f70875..fc8aec505a 100644 --- a/es2panda/ir/module/exportSpecifier.h +++ b/es2panda/ir/module/exportSpecifier.h @@ -52,6 +52,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Identifier *local_; diff --git a/es2panda/ir/module/importDeclaration.cpp b/es2panda/ir/module/importDeclaration.cpp index ad120eb007..b6f1165012 100644 --- a/es2panda/ir/module/importDeclaration.cpp +++ b/es2panda/ir/module/importDeclaration.cpp @@ -41,4 +41,13 @@ checker::Type *ImportDeclaration::Check([[maybe_unused]] checker::Checker *check return nullptr; } +void ImportDeclaration::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + source_ = std::get(cb(source_))->AsStringLiteral(); + + for (auto iter = specifiers_.begin(); iter != specifiers_.end(); iter++) { + *iter = std::get(cb(*iter)); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/module/importDeclaration.h b/es2panda/ir/module/importDeclaration.h index 6407fb47e4..271f5f1c8f 100644 --- a/es2panda/ir/module/importDeclaration.h +++ b/es2panda/ir/module/importDeclaration.h @@ -53,6 +53,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: StringLiteral *source_; diff --git a/es2panda/ir/module/importDefaultSpecifier.cpp b/es2panda/ir/module/importDefaultSpecifier.cpp index cea1de1cba..f8d078c654 100644 --- a/es2panda/ir/module/importDefaultSpecifier.cpp +++ b/es2panda/ir/module/importDefaultSpecifier.cpp @@ -37,4 +37,9 @@ checker::Type *ImportDefaultSpecifier::Check([[maybe_unused]] checker::Checker * return nullptr; } +void ImportDefaultSpecifier::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + local_ = std::get(cb(local_))->AsIdentifier(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/module/importDefaultSpecifier.h b/es2panda/ir/module/importDefaultSpecifier.h index c38d4a5573..87595fca33 100644 --- a/es2panda/ir/module/importDefaultSpecifier.h +++ b/es2panda/ir/module/importDefaultSpecifier.h @@ -46,6 +46,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Identifier *local_; diff --git a/es2panda/ir/module/importNamespaceSpecifier.cpp b/es2panda/ir/module/importNamespaceSpecifier.cpp index a7ee3daa41..b13cddcac6 100644 --- a/es2panda/ir/module/importNamespaceSpecifier.cpp +++ b/es2panda/ir/module/importNamespaceSpecifier.cpp @@ -37,4 +37,9 @@ checker::Type *ImportNamespaceSpecifier::Check([[maybe_unused]] checker::Checker return nullptr; } +void ImportNamespaceSpecifier::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + local_ = std::get(cb(local_))->AsIdentifier(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/module/importNamespaceSpecifier.h b/es2panda/ir/module/importNamespaceSpecifier.h index dc753f85e2..9566436f1b 100644 --- a/es2panda/ir/module/importNamespaceSpecifier.h +++ b/es2panda/ir/module/importNamespaceSpecifier.h @@ -47,6 +47,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Identifier *local_; diff --git a/es2panda/ir/module/importSpecifier.cpp b/es2panda/ir/module/importSpecifier.cpp index 58ec2ee587..a790f644dc 100644 --- a/es2panda/ir/module/importSpecifier.cpp +++ b/es2panda/ir/module/importSpecifier.cpp @@ -38,4 +38,10 @@ checker::Type *ImportSpecifier::Check([[maybe_unused]] checker::Checker *checker return nullptr; } +void ImportSpecifier::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + local_ = std::get(cb(local_))->AsIdentifier(); + imported_ = std::get(cb(imported_))->AsIdentifier(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/module/importSpecifier.h b/es2panda/ir/module/importSpecifier.h index 6347067522..a5ba4fc139 100644 --- a/es2panda/ir/module/importSpecifier.h +++ b/es2panda/ir/module/importSpecifier.h @@ -52,6 +52,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Identifier *imported_; diff --git a/es2panda/ir/statements/blockStatement.cpp b/es2panda/ir/statements/blockStatement.cpp index f69f29f2c6..24abd03273 100644 --- a/es2panda/ir/statements/blockStatement.cpp +++ b/es2panda/ir/statements/blockStatement.cpp @@ -15,6 +15,7 @@ #include "blockStatement.h" +#include #include #include #include @@ -54,4 +55,31 @@ checker::Type *BlockStatement::Check(checker::Checker *checker) const return nullptr; } +void BlockStatement::UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) +{ + auto scopeCtx = binder::LexicalScope::Enter(binder, scope_); + + for (auto iter = statements_.begin(); iter != statements_.end();) { + auto newStatements = cb(*iter); + if (std::holds_alternative(newStatements)) { + auto statement = std::get(newStatements); + if (statement == *iter) { + iter++; + } else if (statement == nullptr) { + iter = statements_.erase(iter); + } else { + *iter = statement->AsStatement(); + iter++; + } + } else { + auto statements = std::get>(newStatements); + for (auto *it : statements) { + iter = statements_.insert(iter, it->AsStatement()); + iter++; + } + iter = statements_.erase(iter); + } + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/statements/blockStatement.h b/es2panda/ir/statements/blockStatement.h index ce567d4227..3769fd6862 100644 --- a/es2panda/ir/statements/blockStatement.h +++ b/es2panda/ir/statements/blockStatement.h @@ -54,6 +54,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) override; protected: binder::Scope *scope_; diff --git a/es2panda/ir/statements/breakStatement.cpp b/es2panda/ir/statements/breakStatement.cpp index 5ba38a1b33..dd2abc5cad 100644 --- a/es2panda/ir/statements/breakStatement.cpp +++ b/es2panda/ir/statements/breakStatement.cpp @@ -44,4 +44,11 @@ checker::Type *BreakStatement::Check([[maybe_unused]] checker::Checker *checker) return nullptr; } +void BreakStatement::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + if (ident_) { + ident_ = std::get(cb(ident_))->AsIdentifier(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/statements/breakStatement.h b/es2panda/ir/statements/breakStatement.h index 255b8944d1..27919c8235 100644 --- a/es2panda/ir/statements/breakStatement.h +++ b/es2panda/ir/statements/breakStatement.h @@ -45,6 +45,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; protected: Identifier *ident_ {}; diff --git a/es2panda/ir/statements/classDeclaration.cpp b/es2panda/ir/statements/classDeclaration.cpp index bc46317ece..b52fe2b484 100644 --- a/es2panda/ir/statements/classDeclaration.cpp +++ b/es2panda/ir/statements/classDeclaration.cpp @@ -55,4 +55,13 @@ checker::Type *ClassDeclaration::Check([[maybe_unused]] checker::Checker *checke return nullptr; } +void ClassDeclaration::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + def_ = std::get(cb(def_))->AsClassDefinition(); + + for (auto iter = decorators_.begin(); iter != decorators_.end(); iter++) { + *iter = std::get(cb(*iter))->AsDecorator(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/statements/classDeclaration.h b/es2panda/ir/statements/classDeclaration.h index d983604e69..5f2864fa1c 100644 --- a/es2panda/ir/statements/classDeclaration.h +++ b/es2panda/ir/statements/classDeclaration.h @@ -49,6 +49,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: ClassDefinition *def_; diff --git a/es2panda/ir/statements/continueStatement.cpp b/es2panda/ir/statements/continueStatement.cpp index 016cdce977..3613598605 100644 --- a/es2panda/ir/statements/continueStatement.cpp +++ b/es2panda/ir/statements/continueStatement.cpp @@ -43,4 +43,11 @@ checker::Type *ContinueStatement::Check([[maybe_unused]] checker::Checker *check return nullptr; } +void ContinueStatement::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + if (ident_) { + ident_ = std::get(cb(ident_))->AsIdentifier(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/statements/continueStatement.h b/es2panda/ir/statements/continueStatement.h index a4148db838..3b77294308 100644 --- a/es2panda/ir/statements/continueStatement.h +++ b/es2panda/ir/statements/continueStatement.h @@ -44,6 +44,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; protected: Identifier *ident_ {}; diff --git a/es2panda/ir/statements/debuggerStatement.cpp b/es2panda/ir/statements/debuggerStatement.cpp index a72d12075d..739aed9f4a 100644 --- a/es2panda/ir/statements/debuggerStatement.cpp +++ b/es2panda/ir/statements/debuggerStatement.cpp @@ -33,4 +33,6 @@ checker::Type *DebuggerStatement::Check([[maybe_unused]] checker::Checker *check return nullptr; } +void DebuggerStatement::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/statements/debuggerStatement.h b/es2panda/ir/statements/debuggerStatement.h index 07c3352e09..87c4a9d011 100644 --- a/es2panda/ir/statements/debuggerStatement.h +++ b/es2panda/ir/statements/debuggerStatement.h @@ -37,6 +37,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: }; diff --git a/es2panda/ir/statements/doWhileStatement.cpp b/es2panda/ir/statements/doWhileStatement.cpp index f10c2b0db5..83078b77ef 100644 --- a/es2panda/ir/statements/doWhileStatement.cpp +++ b/es2panda/ir/statements/doWhileStatement.cpp @@ -15,6 +15,7 @@ #include "doWhileStatement.h" +#include #include #include #include @@ -67,4 +68,13 @@ checker::Type *DoWhileStatement::Check(checker::Checker *checker) const return nullptr; } +void DoWhileStatement::UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) +{ + { + auto loopScopeCtx = binder::LexicalScope::Enter(binder, scope_); + body_ = std::get(cb(body_))->AsStatement(); + } + test_ = std::get(cb(test_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/statements/doWhileStatement.h b/es2panda/ir/statements/doWhileStatement.h index 098f66542f..73f64a78d4 100644 --- a/es2panda/ir/statements/doWhileStatement.h +++ b/es2panda/ir/statements/doWhileStatement.h @@ -66,6 +66,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) override; protected: Statement *body_; diff --git a/es2panda/ir/statements/emptyStatement.cpp b/es2panda/ir/statements/emptyStatement.cpp index ad7d07f66a..9c96300634 100644 --- a/es2panda/ir/statements/emptyStatement.cpp +++ b/es2panda/ir/statements/emptyStatement.cpp @@ -33,4 +33,6 @@ checker::Type *EmptyStatement::Check([[maybe_unused]] checker::Checker *checker) return nullptr; } +void EmptyStatement::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/statements/emptyStatement.h b/es2panda/ir/statements/emptyStatement.h index de5e9b90ee..688d6196d9 100644 --- a/es2panda/ir/statements/emptyStatement.h +++ b/es2panda/ir/statements/emptyStatement.h @@ -37,6 +37,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: }; diff --git a/es2panda/ir/statements/expressionStatement.cpp b/es2panda/ir/statements/expressionStatement.cpp index 55e6e76ded..2e69e05d9e 100644 --- a/es2panda/ir/statements/expressionStatement.cpp +++ b/es2panda/ir/statements/expressionStatement.cpp @@ -40,4 +40,9 @@ checker::Type *ExpressionStatement::Check(checker::Checker *checker) const return expression_->Check(checker); } +void ExpressionStatement::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + expression_ = std::get(cb(expression_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/statements/expressionStatement.h b/es2panda/ir/statements/expressionStatement.h index d670b015b5..36b2d2cf9d 100644 --- a/es2panda/ir/statements/expressionStatement.h +++ b/es2panda/ir/statements/expressionStatement.h @@ -44,6 +44,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *expression_; diff --git a/es2panda/ir/statements/forInStatement.cpp b/es2panda/ir/statements/forInStatement.cpp index 22ad7f7476..2ccad0cb65 100644 --- a/es2panda/ir/statements/forInStatement.cpp +++ b/es2panda/ir/statements/forInStatement.cpp @@ -15,6 +15,7 @@ #include "forInStatement.h" +#include #include #include #include @@ -78,4 +79,15 @@ checker::Type *ForInStatement::Check([[maybe_unused]] checker::Checker *checker) return nullptr; } +void ForInStatement::UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) +{ + auto *loopScope = Scope(); + auto declScopeCtx = binder::LexicalScope::Enter(binder, loopScope->DeclScope()); + left_ = std::get(cb(left_)); + right_ = std::get(cb(right_))->AsExpression(); + + auto loopCtx = binder::LexicalScope::Enter(binder, loopScope); + body_ = std::get(cb(body_))->AsStatement(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/statements/forInStatement.h b/es2panda/ir/statements/forInStatement.h index 668688a269..0605b33cb0 100644 --- a/es2panda/ir/statements/forInStatement.h +++ b/es2panda/ir/statements/forInStatement.h @@ -76,6 +76,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) override; private: AstNode *left_; diff --git a/es2panda/ir/statements/forOfStatement.cpp b/es2panda/ir/statements/forOfStatement.cpp index 2edd29bda0..f653ce3108 100644 --- a/es2panda/ir/statements/forOfStatement.cpp +++ b/es2panda/ir/statements/forOfStatement.cpp @@ -15,6 +15,7 @@ #include "forOfStatement.h" +#include #include #include #include @@ -79,4 +80,15 @@ checker::Type *ForOfStatement::Check([[maybe_unused]] checker::Checker *checker) return nullptr; } +void ForOfStatement::UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) +{ + auto *loopScope = Scope(); + auto declScopeCtx = binder::LexicalScope::Enter(binder, loopScope->DeclScope()); + left_ = std::get(cb(left_)); + right_ = std::get(cb(right_))->AsExpression(); + + auto loopCtx = binder::LexicalScope::Enter(binder, loopScope); + body_ = std::get(cb(body_))->AsStatement(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/statements/forOfStatement.h b/es2panda/ir/statements/forOfStatement.h index 4e639ef2e8..c28b54ecf2 100644 --- a/es2panda/ir/statements/forOfStatement.h +++ b/es2panda/ir/statements/forOfStatement.h @@ -85,6 +85,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) override; private: AstNode *left_; diff --git a/es2panda/ir/statements/forUpdateStatement.cpp b/es2panda/ir/statements/forUpdateStatement.cpp index 780fe7f448..d6275d9817 100644 --- a/es2panda/ir/statements/forUpdateStatement.cpp +++ b/es2panda/ir/statements/forUpdateStatement.cpp @@ -15,6 +15,7 @@ #include "forUpdateStatement.h" +#include #include #include #include @@ -109,4 +110,26 @@ checker::Type *ForUpdateStatement::Check(checker::Checker *checker) const return nullptr; } +void ForUpdateStatement::UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) +{ + auto *loopScope = Scope(); + auto declScopeCtx = binder::LexicalScope::Enter(binder, loopScope->DeclScope()); + + if (init_) { + init_ = std::get(cb(init_)); + } + + if (test_) { + test_ = std::get(cb(test_))->AsExpression(); + } + + auto loopCtx = binder::LexicalScope::Enter(binder, loopScope); + + if (update_) { + update_ = std::get(cb(update_))->AsExpression(); + } + + body_ = std::get(cb(body_))->AsStatement(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/statements/forUpdateStatement.h b/es2panda/ir/statements/forUpdateStatement.h index 923313adb6..9871daea2d 100644 --- a/es2panda/ir/statements/forUpdateStatement.h +++ b/es2panda/ir/statements/forUpdateStatement.h @@ -91,6 +91,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) override; private: AstNode *init_; diff --git a/es2panda/ir/statements/functionDeclaration.cpp b/es2panda/ir/statements/functionDeclaration.cpp index f032a28d40..62e3401db8 100644 --- a/es2panda/ir/statements/functionDeclaration.cpp +++ b/es2panda/ir/statements/functionDeclaration.cpp @@ -57,4 +57,11 @@ checker::Type *FunctionDeclaration::Check(checker::Checker *checker) const return nullptr; } +void FunctionDeclaration::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + if (func_) { + func_ = std::get(cb(func_))->AsScriptFunction(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/statements/functionDeclaration.h b/es2panda/ir/statements/functionDeclaration.h index aff9ae022e..9cf3df1130 100644 --- a/es2panda/ir/statements/functionDeclaration.h +++ b/es2panda/ir/statements/functionDeclaration.h @@ -44,6 +44,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: ScriptFunction *func_; diff --git a/es2panda/ir/statements/ifStatement.cpp b/es2panda/ir/statements/ifStatement.cpp index 8404cc16e6..7f0a35b5fb 100644 --- a/es2panda/ir/statements/ifStatement.cpp +++ b/es2panda/ir/statements/ifStatement.cpp @@ -75,4 +75,14 @@ checker::Type *IfStatement::Check(checker::Checker *checker) const return nullptr; } +void IfStatement::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + test_ = std::get(cb(test_))->AsExpression(); + consequent_ = std::get(cb(consequent_))->AsStatement(); + + if (alternate_) { + alternate_ = std::get(cb(alternate_))->AsStatement(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/statements/ifStatement.h b/es2panda/ir/statements/ifStatement.h index ac4dd2f01f..7380df429b 100644 --- a/es2panda/ir/statements/ifStatement.h +++ b/es2panda/ir/statements/ifStatement.h @@ -56,6 +56,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; protected: Expression *test_; diff --git a/es2panda/ir/statements/labelledStatement.cpp b/es2panda/ir/statements/labelledStatement.cpp index 021c3f650b..cdf60712e6 100644 --- a/es2panda/ir/statements/labelledStatement.cpp +++ b/es2panda/ir/statements/labelledStatement.cpp @@ -44,4 +44,10 @@ checker::Type *LabelledStatement::Check([[maybe_unused]] checker::Checker *check return nullptr; } +void LabelledStatement::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + ident_ = std::get(cb(ident_))->AsIdentifier(); + body_ = std::get(cb(body_))->AsStatement(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/statements/labelledStatement.h b/es2panda/ir/statements/labelledStatement.h index 2b0d4d9a32..926fdcf6bc 100644 --- a/es2panda/ir/statements/labelledStatement.h +++ b/es2panda/ir/statements/labelledStatement.h @@ -53,6 +53,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; protected: Identifier *ident_; diff --git a/es2panda/ir/statements/returnStatement.cpp b/es2panda/ir/statements/returnStatement.cpp index 5d65a90860..65d1a5cf01 100644 --- a/es2panda/ir/statements/returnStatement.cpp +++ b/es2panda/ir/statements/returnStatement.cpp @@ -93,4 +93,11 @@ checker::Type *ReturnStatement::Check(checker::Checker *checker) const return nullptr; } +void ReturnStatement::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + if (argument_) { + argument_ = std::get(cb(argument_))->AsExpression(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/statements/returnStatement.h b/es2panda/ir/statements/returnStatement.h index 827f8634c9..5262cbdd06 100644 --- a/es2panda/ir/statements/returnStatement.h +++ b/es2panda/ir/statements/returnStatement.h @@ -43,6 +43,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; protected: Expression *argument_ {}; diff --git a/es2panda/ir/statements/switchCaseStatement.cpp b/es2panda/ir/statements/switchCaseStatement.cpp index e2fd5c7866..70ed91d245 100644 --- a/es2panda/ir/statements/switchCaseStatement.cpp +++ b/es2panda/ir/statements/switchCaseStatement.cpp @@ -43,4 +43,15 @@ checker::Type *SwitchCaseStatement::Check([[maybe_unused]] checker::Checker *che return nullptr; } +void SwitchCaseStatement::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + if (test_) { + test_ = std::get(cb(test_))->AsExpression(); + } + + for (auto iter = consequent_.begin(); iter != consequent_.end(); iter++) { + *iter = std::get(cb(*iter))->AsStatement(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/statements/switchCaseStatement.h b/es2panda/ir/statements/switchCaseStatement.h index cb6a6f95f0..54971877cf 100644 --- a/es2panda/ir/statements/switchCaseStatement.h +++ b/es2panda/ir/statements/switchCaseStatement.h @@ -52,6 +52,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; protected: Expression *test_; diff --git a/es2panda/ir/statements/switchStatement.cpp b/es2panda/ir/statements/switchStatement.cpp index fb9be5f8ed..94b97de649 100644 --- a/es2panda/ir/statements/switchStatement.cpp +++ b/es2panda/ir/statements/switchStatement.cpp @@ -15,6 +15,7 @@ #include "switchStatement.h" +#include #include #include #include @@ -105,4 +106,15 @@ checker::Type *SwitchStatement::Check(checker::Checker *checker) const return nullptr; } +void SwitchStatement::UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) +{ + auto scopeCtx = binder::LexicalScope::Enter(binder, scope_); + + discriminant_ = std::get(cb(discriminant_))->AsExpression(); + + for (auto iter = cases_.begin(); iter != cases_.end(); iter++) { + *iter = std::get(cb(*iter))->AsSwitchCaseStatement(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/statements/switchStatement.h b/es2panda/ir/statements/switchStatement.h index 3389f5bd0e..3e2148fd76 100644 --- a/es2panda/ir/statements/switchStatement.h +++ b/es2panda/ir/statements/switchStatement.h @@ -63,6 +63,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) override; protected: binder::LocalScope *scope_; diff --git a/es2panda/ir/statements/throwStatement.cpp b/es2panda/ir/statements/throwStatement.cpp index a17408337e..8319c21834 100644 --- a/es2panda/ir/statements/throwStatement.cpp +++ b/es2panda/ir/statements/throwStatement.cpp @@ -42,4 +42,9 @@ checker::Type *ThrowStatement::Check([[maybe_unused]] checker::Checker *checker) return nullptr; } +void ThrowStatement::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + argument_ = std::get(cb(argument_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/statements/throwStatement.h b/es2panda/ir/statements/throwStatement.h index e657ecab91..274570561a 100644 --- a/es2panda/ir/statements/throwStatement.h +++ b/es2panda/ir/statements/throwStatement.h @@ -44,6 +44,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; protected: Expression *argument_; diff --git a/es2panda/ir/statements/tryStatement.cpp b/es2panda/ir/statements/tryStatement.cpp index 6ec2774bdb..7a1f1e5960 100644 --- a/es2panda/ir/statements/tryStatement.cpp +++ b/es2panda/ir/statements/tryStatement.cpp @@ -170,4 +170,17 @@ checker::Type *TryStatement::Check(checker::Checker *checker) const return nullptr; } +void TryStatement::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + block_ = std::get(cb(block_))->AsBlockStatement(); + + if (catchClause_) { + catchClause_ = std::get(cb(catchClause_))->AsCatchClause(); + } + + if (finalizer_) { + finalizer_ = std::get(cb(finalizer_))->AsBlockStatement(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/statements/tryStatement.h b/es2panda/ir/statements/tryStatement.h index 7cd7b3ef4a..79d2a12797 100644 --- a/es2panda/ir/statements/tryStatement.h +++ b/es2panda/ir/statements/tryStatement.h @@ -60,6 +60,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: void CompileTryCatch(compiler::PandaGen *pg) const; diff --git a/es2panda/ir/statements/variableDeclaration.cpp b/es2panda/ir/statements/variableDeclaration.cpp index aab386285a..bbca47e641 100644 --- a/es2panda/ir/statements/variableDeclaration.cpp +++ b/es2panda/ir/statements/variableDeclaration.cpp @@ -74,4 +74,11 @@ checker::Type *VariableDeclaration::Check(checker::Checker *checker) const return nullptr; } +void VariableDeclaration::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + for (auto iter = declarators_.begin(); iter != declarators_.end(); iter++) { + *iter = std::get(cb(*iter))->AsVariableDeclarator(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/statements/variableDeclaration.h b/es2panda/ir/statements/variableDeclaration.h index 42a70da3a4..eb38cb4ad0 100644 --- a/es2panda/ir/statements/variableDeclaration.h +++ b/es2panda/ir/statements/variableDeclaration.h @@ -63,6 +63,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: VariableDeclarationKind kind_; diff --git a/es2panda/ir/statements/variableDeclarator.cpp b/es2panda/ir/statements/variableDeclarator.cpp index 7018207f60..ef3fb7d5bc 100644 --- a/es2panda/ir/statements/variableDeclarator.cpp +++ b/es2panda/ir/statements/variableDeclarator.cpp @@ -143,4 +143,13 @@ checker::Type *VariableDeclarator::Check(checker::Checker *checker) const return nullptr; } +void VariableDeclarator::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + id_ = std::get(cb(id_))->AsExpression(); + + if (init_) { + init_ = std::get(cb(init_))->AsExpression(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/statements/variableDeclarator.h b/es2panda/ir/statements/variableDeclarator.h index dd73f305ea..4c695dfbf2 100644 --- a/es2panda/ir/statements/variableDeclarator.h +++ b/es2panda/ir/statements/variableDeclarator.h @@ -68,6 +68,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *id_; diff --git a/es2panda/ir/statements/whileStatement.cpp b/es2panda/ir/statements/whileStatement.cpp index 258cd447ff..0c5a09fb34 100644 --- a/es2panda/ir/statements/whileStatement.cpp +++ b/es2panda/ir/statements/whileStatement.cpp @@ -15,6 +15,7 @@ #include "whileStatement.h" +#include #include #include #include @@ -66,4 +67,12 @@ checker::Type *WhileStatement::Check(checker::Checker *checker) const return nullptr; } +void WhileStatement::UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) +{ + test_ = std::get(cb(test_))->AsExpression(); + + auto loopScopeCtx = binder::LexicalScope::Enter(binder, scope_); + body_ = std::get(cb(body_))->AsStatement(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/statements/whileStatement.h b/es2panda/ir/statements/whileStatement.h index 680389ab21..e77f97a631 100644 --- a/es2panda/ir/statements/whileStatement.h +++ b/es2panda/ir/statements/whileStatement.h @@ -66,6 +66,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) override; protected: Expression *test_; diff --git a/es2panda/ir/ts/tsAnyKeyword.cpp b/es2panda/ir/ts/tsAnyKeyword.cpp index 18572a52ac..5422a34616 100644 --- a/es2panda/ir/ts/tsAnyKeyword.cpp +++ b/es2panda/ir/ts/tsAnyKeyword.cpp @@ -39,4 +39,6 @@ checker::Type *TSAnyKeyword::GetType(checker::Checker *checker) const return checker->GlobalAnyType(); } +void TSAnyKeyword::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsAnyKeyword.h b/es2panda/ir/ts/tsAnyKeyword.h index 438466758e..8641cbc53c 100644 --- a/es2panda/ir/ts/tsAnyKeyword.h +++ b/es2panda/ir/ts/tsAnyKeyword.h @@ -38,6 +38,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; }; } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsArrayType.cpp b/es2panda/ir/ts/tsArrayType.cpp index 7e5d86c563..1040fbfde7 100644 --- a/es2panda/ir/ts/tsArrayType.cpp +++ b/es2panda/ir/ts/tsArrayType.cpp @@ -43,4 +43,9 @@ checker::Type *TSArrayType::GetType(checker::Checker *checker) const return checker->Allocator()->New(elementType_->AsTypeNode()->GetType(checker)); } +void TSArrayType::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + elementType_ = std::get(cb(elementType_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsArrayType.h b/es2panda/ir/ts/tsArrayType.h index 1c6e1337dd..be5a1d875a 100644 --- a/es2panda/ir/ts/tsArrayType.h +++ b/es2panda/ir/ts/tsArrayType.h @@ -43,6 +43,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *elementType_; diff --git a/es2panda/ir/ts/tsAsExpression.cpp b/es2panda/ir/ts/tsAsExpression.cpp index a4e6e08db6..c67d15b421 100644 --- a/es2panda/ir/ts/tsAsExpression.cpp +++ b/es2panda/ir/ts/tsAsExpression.cpp @@ -108,4 +108,10 @@ checker::Type *TSAsExpression::Check(checker::Checker *checker) const return targetType; } +void TSAsExpression::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + expression_ = std::get(cb(expression_))->AsExpression(); + typeAnnotation_ = std::get(cb(typeAnnotation_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsAsExpression.h b/es2panda/ir/ts/tsAsExpression.h index 698a431bf8..ceb6fc2fd1 100644 --- a/es2panda/ir/ts/tsAsExpression.h +++ b/es2panda/ir/ts/tsAsExpression.h @@ -59,6 +59,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *expression_; diff --git a/es2panda/ir/ts/tsBigintKeyword.cpp b/es2panda/ir/ts/tsBigintKeyword.cpp index 53c0ee4240..d5688ff2e4 100644 --- a/es2panda/ir/ts/tsBigintKeyword.cpp +++ b/es2panda/ir/ts/tsBigintKeyword.cpp @@ -39,4 +39,6 @@ checker::Type *TSBigintKeyword::GetType(checker::Checker *checker) const return checker->GlobalBigintType(); } +void TSBigintKeyword::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsBigintKeyword.h b/es2panda/ir/ts/tsBigintKeyword.h index 174253b416..0b2c2ce9ef 100644 --- a/es2panda/ir/ts/tsBigintKeyword.h +++ b/es2panda/ir/ts/tsBigintKeyword.h @@ -38,6 +38,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; }; } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsBooleanKeyword.cpp b/es2panda/ir/ts/tsBooleanKeyword.cpp index 179e4e1942..90f59758f0 100644 --- a/es2panda/ir/ts/tsBooleanKeyword.cpp +++ b/es2panda/ir/ts/tsBooleanKeyword.cpp @@ -39,4 +39,6 @@ checker::Type *TSBooleanKeyword::GetType(checker::Checker *checker) const return checker->GlobalBooleanType(); } +void TSBooleanKeyword::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsBooleanKeyword.h b/es2panda/ir/ts/tsBooleanKeyword.h index 4e6056d729..080a85aedc 100644 --- a/es2panda/ir/ts/tsBooleanKeyword.h +++ b/es2panda/ir/ts/tsBooleanKeyword.h @@ -38,6 +38,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; }; } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsClassImplements.cpp b/es2panda/ir/ts/tsClassImplements.cpp index c122178534..704156143f 100644 --- a/es2panda/ir/ts/tsClassImplements.cpp +++ b/es2panda/ir/ts/tsClassImplements.cpp @@ -44,4 +44,13 @@ checker::Type *TSClassImplements::Check([[maybe_unused]] checker::Checker *check return nullptr; } +void TSClassImplements::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + expression_ = std::get(cb(expression_))->AsExpression(); + + if (typeParameters_) { + typeParameters_ = std::get(cb(typeParameters_))->AsTSTypeParameterInstantiation(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsClassImplements.h b/es2panda/ir/ts/tsClassImplements.h index 3926e09ae8..cadd1d28c8 100644 --- a/es2panda/ir/ts/tsClassImplements.h +++ b/es2panda/ir/ts/tsClassImplements.h @@ -34,7 +34,7 @@ class TSTypeParameterInstantiation; class TSClassImplements : public Expression { public: explicit TSClassImplements(Expression *expression, TSTypeParameterInstantiation *typeParameters) - : Expression(AstNodeType::TS_AS_EXPRESSION), expression_(expression), typeParameters_(typeParameters) + : Expression(AstNodeType::TS_CLASS_IMPLEMENTS), expression_(expression), typeParameters_(typeParameters) { } @@ -52,6 +52,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *expression_; diff --git a/es2panda/ir/ts/tsConditionalType.cpp b/es2panda/ir/ts/tsConditionalType.cpp index ffe89a8fbb..63ece61adb 100644 --- a/es2panda/ir/ts/tsConditionalType.cpp +++ b/es2panda/ir/ts/tsConditionalType.cpp @@ -48,4 +48,12 @@ checker::Type *TSConditionalType::GetType([[maybe_unused]] checker::Checker *che return nullptr; } +void TSConditionalType::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + checkType_ = std::get(cb(checkType_))->AsExpression(); + extendsType_ = std::get(cb(extendsType_))->AsExpression(); + trueType_ = std::get(cb(trueType_))->AsExpression(); + falseType_ = std::get(cb(falseType_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsConditionalType.h b/es2panda/ir/ts/tsConditionalType.h index 4689e33691..2eb2eab7bc 100644 --- a/es2panda/ir/ts/tsConditionalType.h +++ b/es2panda/ir/ts/tsConditionalType.h @@ -66,6 +66,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; checker::Type *GetType([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *checkType_; diff --git a/es2panda/ir/ts/tsConstructorType.cpp b/es2panda/ir/ts/tsConstructorType.cpp index 74089d8bb1..e341776231 100644 --- a/es2panda/ir/ts/tsConstructorType.cpp +++ b/es2panda/ir/ts/tsConstructorType.cpp @@ -15,6 +15,7 @@ #include "tsConstructorType.h" +#include #include #include #include @@ -66,4 +67,19 @@ checker::Type *TSConstructorType::GetType(checker::Checker *checker) const return checker->CheckTypeCached(this); } +void TSConstructorType::UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) +{ + auto scopeCtx = binder::LexicalScope::Enter(binder, scope_); + + if (typeParams_) { + typeParams_ = std::get(cb(typeParams_))->AsTSTypeParameterDeclaration(); + } + + for (auto iter = params_.begin(); iter != params_.end(); iter++) { + *iter = std::get(cb(*iter))->AsExpression(); + } + + returnType_ = std::get(cb(returnType_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsConstructorType.h b/es2panda/ir/ts/tsConstructorType.h index 162eb08070..01686e44ee 100644 --- a/es2panda/ir/ts/tsConstructorType.h +++ b/es2panda/ir/ts/tsConstructorType.h @@ -78,6 +78,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) override; private: binder::Scope *scope_; diff --git a/es2panda/ir/ts/tsEnumDeclaration.cpp b/es2panda/ir/ts/tsEnumDeclaration.cpp index 304f4933ee..e75142f597 100644 --- a/es2panda/ir/ts/tsEnumDeclaration.cpp +++ b/es2panda/ir/ts/tsEnumDeclaration.cpp @@ -398,4 +398,13 @@ checker::Type *TSEnumDeclaration::Check(checker::Checker *checker) const return nullptr; } +void TSEnumDeclaration::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + key_ = std::get(cb(key_))->AsIdentifier(); + + for (auto iter = members_.begin(); iter != members_.end(); iter++) { + *iter = std::get(cb(*iter))->AsTSEnumMember(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsEnumDeclaration.h b/es2panda/ir/ts/tsEnumDeclaration.h index 0b04785f9d..b1920b0243 100644 --- a/es2panda/ir/ts/tsEnumDeclaration.h +++ b/es2panda/ir/ts/tsEnumDeclaration.h @@ -78,6 +78,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: binder::LocalScope *scope_; diff --git a/es2panda/ir/ts/tsEnumMember.cpp b/es2panda/ir/ts/tsEnumMember.cpp index 55a38d3cdc..1946bfb926 100644 --- a/es2panda/ir/ts/tsEnumMember.cpp +++ b/es2panda/ir/ts/tsEnumMember.cpp @@ -41,4 +41,13 @@ checker::Type *TSEnumMember::Check([[maybe_unused]] checker::Checker *checker) c return nullptr; } +void TSEnumMember::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + key_ = std::get(cb(key_))->AsExpression(); + + if (init_) { + init_ = std::get(cb(init_))->AsExpression(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsEnumMember.h b/es2panda/ir/ts/tsEnumMember.h index 8de6f9d3de..4f6d28ba5d 100644 --- a/es2panda/ir/ts/tsEnumMember.h +++ b/es2panda/ir/ts/tsEnumMember.h @@ -51,6 +51,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *key_; diff --git a/es2panda/ir/ts/tsExternalModuleReference.cpp b/es2panda/ir/ts/tsExternalModuleReference.cpp index 67f731168d..f77c3be5ba 100644 --- a/es2panda/ir/ts/tsExternalModuleReference.cpp +++ b/es2panda/ir/ts/tsExternalModuleReference.cpp @@ -36,4 +36,9 @@ checker::Type *TSExternalModuleReference::Check([[maybe_unused]] checker::Checke return nullptr; } +void TSExternalModuleReference::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + expr_ = std::get(cb(expr_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsExternalModuleReference.h b/es2panda/ir/ts/tsExternalModuleReference.h index d89233126b..0b41b4d7f5 100644 --- a/es2panda/ir/ts/tsExternalModuleReference.h +++ b/es2panda/ir/ts/tsExternalModuleReference.h @@ -45,6 +45,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *expr_; diff --git a/es2panda/ir/ts/tsFunctionType.cpp b/es2panda/ir/ts/tsFunctionType.cpp index 7715a736cb..335ea72c18 100644 --- a/es2panda/ir/ts/tsFunctionType.cpp +++ b/es2panda/ir/ts/tsFunctionType.cpp @@ -15,6 +15,7 @@ #include "tsFunctionType.h" +#include #include #include #include @@ -65,4 +66,19 @@ checker::Type *TSFunctionType::GetType(checker::Checker *checker) const return checker->CheckTypeCached(this); } +void TSFunctionType::UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) +{ + auto scopeCtx = binder::LexicalScope::Enter(binder, scope_); + + if (typeParams_) { + typeParams_ = std::get(cb(typeParams_))->AsTSTypeParameterDeclaration(); + } + + for (auto iter = params_.begin(); iter != params_.end(); iter++) { + *iter = std::get(cb(*iter))->AsExpression(); + } + + returnType_ = std::get(cb(returnType_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsFunctionType.h b/es2panda/ir/ts/tsFunctionType.h index 7cc2508df4..7ce73b35f7 100644 --- a/es2panda/ir/ts/tsFunctionType.h +++ b/es2panda/ir/ts/tsFunctionType.h @@ -72,6 +72,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) override; private: binder::Scope *scope_; diff --git a/es2panda/ir/ts/tsImportEqualsDeclaration.cpp b/es2panda/ir/ts/tsImportEqualsDeclaration.cpp index 89b612bc1d..f47fb66352 100644 --- a/es2panda/ir/ts/tsImportEqualsDeclaration.cpp +++ b/es2panda/ir/ts/tsImportEqualsDeclaration.cpp @@ -42,4 +42,10 @@ checker::Type *TSImportEqualsDeclaration::Check([[maybe_unused]] checker::Checke return nullptr; } +void TSImportEqualsDeclaration::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + id_ = std::get(cb(id_))->AsIdentifier(); + moduleReference_ = std::get(cb(moduleReference_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsImportEqualsDeclaration.h b/es2panda/ir/ts/tsImportEqualsDeclaration.h index 8bcd9e65ca..4ac96f3ba8 100644 --- a/es2panda/ir/ts/tsImportEqualsDeclaration.h +++ b/es2panda/ir/ts/tsImportEqualsDeclaration.h @@ -51,6 +51,11 @@ public: return moduleReference_; } + Expression *ModuleReference() + { + return moduleReference_; + } + bool IsExport() const { return isExport_; @@ -60,6 +65,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Identifier *id_; diff --git a/es2panda/ir/ts/tsImportType.cpp b/es2panda/ir/ts/tsImportType.cpp index 89b3e32d5c..3f99abf8cd 100644 --- a/es2panda/ir/ts/tsImportType.cpp +++ b/es2panda/ir/ts/tsImportType.cpp @@ -55,4 +55,17 @@ checker::Type *TSImportType::GetType([[maybe_unused]] checker::Checker *checker) return nullptr; } +void TSImportType::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + param_ = std::get(cb(param_))->AsExpression(); + + if (typeParams_) { + typeParams_ = std::get(cb(typeParams_))->AsTSTypeParameterInstantiation(); + } + + if (qualifier_) { + qualifier_ = std::get(cb(qualifier_))->AsExpression(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsImportType.h b/es2panda/ir/ts/tsImportType.h index df73c96aed..92d6c46bac 100644 --- a/es2panda/ir/ts/tsImportType.h +++ b/es2panda/ir/ts/tsImportType.h @@ -68,6 +68,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; checker::Type *GetType([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *param_; diff --git a/es2panda/ir/ts/tsIndexSignature.cpp b/es2panda/ir/ts/tsIndexSignature.cpp index 270a8aa209..f556086f2f 100644 --- a/es2panda/ir/ts/tsIndexSignature.cpp +++ b/es2panda/ir/ts/tsIndexSignature.cpp @@ -71,4 +71,10 @@ checker::Type *TSIndexSignature::Check(checker::Checker *checker) const return placeholder; } +void TSIndexSignature::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + param_ = std::get(cb(param_))->AsExpression(); + typeAnnotation_ = std::get(cb(typeAnnotation_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsIndexSignature.h b/es2panda/ir/ts/tsIndexSignature.h index 170a4e7bd9..07fc83ebce 100644 --- a/es2panda/ir/ts/tsIndexSignature.h +++ b/es2panda/ir/ts/tsIndexSignature.h @@ -62,6 +62,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *param_; diff --git a/es2panda/ir/ts/tsIndexedAccessType.cpp b/es2panda/ir/ts/tsIndexedAccessType.cpp index c7e479449c..ba8d8d8339 100644 --- a/es2panda/ir/ts/tsIndexedAccessType.cpp +++ b/es2panda/ir/ts/tsIndexedAccessType.cpp @@ -75,4 +75,10 @@ checker::Type *TSIndexedAccessType::GetType(checker::Checker *checker) const return resolved; } +void TSIndexedAccessType::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + objectType_ = std::get(cb(objectType_))->AsExpression(); + indexType_ = std::get(cb(indexType_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsIndexedAccessType.h b/es2panda/ir/ts/tsIndexedAccessType.h index 9d133fdb90..6e5be26c8c 100644 --- a/es2panda/ir/ts/tsIndexedAccessType.h +++ b/es2panda/ir/ts/tsIndexedAccessType.h @@ -51,6 +51,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *objectType_; diff --git a/es2panda/ir/ts/tsInferType.cpp b/es2panda/ir/ts/tsInferType.cpp index e1787d04bd..321591cddb 100644 --- a/es2panda/ir/ts/tsInferType.cpp +++ b/es2panda/ir/ts/tsInferType.cpp @@ -42,4 +42,9 @@ checker::Type *TSInferType::GetType([[maybe_unused]] checker::Checker *checker) return nullptr; } +void TSInferType::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + typeParam_ = std::get(cb(typeParam_))->AsTSTypeParameter(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsInferType.h b/es2panda/ir/ts/tsInferType.h index d401c76a58..b0f86d34ae 100644 --- a/es2panda/ir/ts/tsInferType.h +++ b/es2panda/ir/ts/tsInferType.h @@ -45,6 +45,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; checker::Type *GetType([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: TSTypeParameter *typeParam_; diff --git a/es2panda/ir/ts/tsInterfaceBody.cpp b/es2panda/ir/ts/tsInterfaceBody.cpp index 2dc2278c71..754f63f4e7 100644 --- a/es2panda/ir/ts/tsInterfaceBody.cpp +++ b/es2panda/ir/ts/tsInterfaceBody.cpp @@ -42,4 +42,11 @@ checker::Type *TSInterfaceBody::Check(checker::Checker *checker) const return nullptr; } +void TSInterfaceBody::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + for (auto iter = body_.begin(); iter != body_.end(); iter++) { + *iter = std::get(cb(*iter))->AsExpression(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsInterfaceBody.h b/es2panda/ir/ts/tsInterfaceBody.h index 62b5b52f62..5792c6340c 100644 --- a/es2panda/ir/ts/tsInterfaceBody.h +++ b/es2panda/ir/ts/tsInterfaceBody.h @@ -45,6 +45,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: ArenaVector body_; diff --git a/es2panda/ir/ts/tsInterfaceDeclaration.cpp b/es2panda/ir/ts/tsInterfaceDeclaration.cpp index a8e96c3259..ef74133aa7 100644 --- a/es2panda/ir/ts/tsInterfaceDeclaration.cpp +++ b/es2panda/ir/ts/tsInterfaceDeclaration.cpp @@ -126,4 +126,19 @@ checker::Type *TSInterfaceDeclaration::Check(checker::Checker *checker) const return nullptr; } +void TSInterfaceDeclaration::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + id_ = std::get(cb(id_))->AsIdentifier(); + + if (typeParams_) { + typeParams_ = std::get(cb(typeParams_))->AsTSTypeParameterDeclaration(); + } + + for (auto iter = extends_.begin(); iter != extends_.end(); iter++) { + *iter = std::get(cb(*iter))->AsTSInterfaceHeritage(); + } + + body_ = std::get(cb(body_))->AsTSInterfaceBody(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsInterfaceDeclaration.h b/es2panda/ir/ts/tsInterfaceDeclaration.h index a866a55d0b..723a92a278 100644 --- a/es2panda/ir/ts/tsInterfaceDeclaration.h +++ b/es2panda/ir/ts/tsInterfaceDeclaration.h @@ -82,6 +82,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; checker::Type *InferType(checker::Checker *checker, binder::Variable *bindingVar) const; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: binder::LocalScope *scope_; diff --git a/es2panda/ir/ts/tsInterfaceHeritage.cpp b/es2panda/ir/ts/tsInterfaceHeritage.cpp index e8801521f8..32797c357d 100644 --- a/es2panda/ir/ts/tsInterfaceHeritage.cpp +++ b/es2panda/ir/ts/tsInterfaceHeritage.cpp @@ -44,4 +44,9 @@ checker::Type *TSInterfaceHeritage::Check([[maybe_unused]] checker::Checker *che return nullptr; } +void TSInterfaceHeritage::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + expr_ = std::get(cb(expr_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsInterfaceHeritage.h b/es2panda/ir/ts/tsInterfaceHeritage.h index 915dcf8961..9d6d0f18a4 100644 --- a/es2panda/ir/ts/tsInterfaceHeritage.h +++ b/es2panda/ir/ts/tsInterfaceHeritage.h @@ -45,6 +45,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *expr_; diff --git a/es2panda/ir/ts/tsIntersectionType.cpp b/es2panda/ir/ts/tsIntersectionType.cpp index 707f84f034..cbffe8a516 100644 --- a/es2panda/ir/ts/tsIntersectionType.cpp +++ b/es2panda/ir/ts/tsIntersectionType.cpp @@ -43,4 +43,11 @@ checker::Type *TSIntersectionType::GetType([[maybe_unused]] checker::Checker *ch return nullptr; } +void TSIntersectionType::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + for (auto iter = types_.begin(); iter != types_.end(); iter++) { + *iter = std::get(cb(*iter))->AsExpression(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsIntersectionType.h b/es2panda/ir/ts/tsIntersectionType.h index a31aca5863..a79ec939b5 100644 --- a/es2panda/ir/ts/tsIntersectionType.h +++ b/es2panda/ir/ts/tsIntersectionType.h @@ -46,6 +46,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; checker::Type *GetType([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: ArenaVector types_; diff --git a/es2panda/ir/ts/tsLiteralType.cpp b/es2panda/ir/ts/tsLiteralType.cpp index 00ebe63bbc..721633147e 100644 --- a/es2panda/ir/ts/tsLiteralType.cpp +++ b/es2panda/ir/ts/tsLiteralType.cpp @@ -51,4 +51,9 @@ checker::Type *TSLiteralType::GetType(checker::Checker *checker) const return type; } +void TSLiteralType::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + literal_ = std::get(cb(literal_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsLiteralType.h b/es2panda/ir/ts/tsLiteralType.h index 3799d9f64f..4384d9c9ec 100644 --- a/es2panda/ir/ts/tsLiteralType.h +++ b/es2panda/ir/ts/tsLiteralType.h @@ -43,6 +43,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *literal_; diff --git a/es2panda/ir/ts/tsMappedType.cpp b/es2panda/ir/ts/tsMappedType.cpp index 37178340cf..e508ba89d1 100644 --- a/es2panda/ir/ts/tsMappedType.cpp +++ b/es2panda/ir/ts/tsMappedType.cpp @@ -55,4 +55,13 @@ checker::Type *TSMappedType::GetType([[maybe_unused]] checker::Checker *checker) return nullptr; } +void TSMappedType::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + typeParameter_ = std::get(cb(typeParameter_))->AsTSTypeParameter(); + + if (typeAnnotation_) { + typeAnnotation_ = std::get(cb(typeAnnotation_))->AsExpression(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsMappedType.h b/es2panda/ir/ts/tsMappedType.h index f7d32a4574..32b449638a 100644 --- a/es2panda/ir/ts/tsMappedType.h +++ b/es2panda/ir/ts/tsMappedType.h @@ -68,6 +68,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; checker::Type *GetType([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: TSTypeParameter *typeParameter_; diff --git a/es2panda/ir/ts/tsMethodSignature.cpp b/es2panda/ir/ts/tsMethodSignature.cpp index 95f0680868..c83c09581b 100644 --- a/es2panda/ir/ts/tsMethodSignature.cpp +++ b/es2panda/ir/ts/tsMethodSignature.cpp @@ -16,6 +16,7 @@ #include "tsMethodSignature.h" #include +#include #include #include #include @@ -80,4 +81,23 @@ checker::Type *TSMethodSignature::Check(checker::Checker *checker) const return nullptr; } +void TSMethodSignature::UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) +{ + auto scopeCtx = binder::LexicalScope::Enter(binder, scope_); + + key_ = std::get(cb(key_))->AsExpression(); + + if (typeParams_) { + typeParams_ = std::get(cb(typeParams_))->AsTSTypeParameterDeclaration(); + } + + for (auto iter = params_.begin(); iter != params_.end(); iter++) { + *iter = std::get(cb(*iter))->AsExpression(); + } + + if (returnTypeAnnotation_) { + returnTypeAnnotation_ = std::get(cb(returnTypeAnnotation_))->AsExpression(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsMethodSignature.h b/es2panda/ir/ts/tsMethodSignature.h index 79f671cc82..b104883516 100644 --- a/es2panda/ir/ts/tsMethodSignature.h +++ b/es2panda/ir/ts/tsMethodSignature.h @@ -95,6 +95,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) override; private: binder::Scope *scope_; diff --git a/es2panda/ir/ts/tsModuleBlock.cpp b/es2panda/ir/ts/tsModuleBlock.cpp index 295d18d207..8955fc3b40 100644 --- a/es2panda/ir/ts/tsModuleBlock.cpp +++ b/es2panda/ir/ts/tsModuleBlock.cpp @@ -39,4 +39,29 @@ checker::Type *TSModuleBlock::Check([[maybe_unused]] checker::Checker *checker) return nullptr; } +void TSModuleBlock::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + for (auto iter = statements_.begin(); iter != statements_.end();) { + auto newStatements = cb(*iter); + if (std::holds_alternative(newStatements)) { + auto statement = std::get(newStatements); + if (statement == *iter) { + iter++; + } else if (statement == nullptr) { + iter = statements_.erase(iter); + } else { + *iter = statement->AsStatement(); + iter++; + } + } else { + auto statements = std::get>(newStatements); + for (auto *it : statements) { + iter = statements_.insert(iter, it->AsStatement()); + iter++; + } + iter = statements_.erase(iter); + } + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsModuleBlock.h b/es2panda/ir/ts/tsModuleBlock.h index e0c74c12d2..f62792938f 100644 --- a/es2panda/ir/ts/tsModuleBlock.h +++ b/es2panda/ir/ts/tsModuleBlock.h @@ -18,10 +18,6 @@ #include -namespace panda::es2panda::binder { -class LocalScope; -} // namespace panda::es2panda::binder - namespace panda::es2panda::compiler { class PandaGen; } // namespace panda::es2panda::compiler @@ -35,17 +31,17 @@ namespace panda::es2panda::ir { class TSModuleBlock : public Statement { public: - explicit TSModuleBlock(binder::LocalScope *scope, ArenaVector &&statements) - : Statement(AstNodeType::TS_MODULE_BLOCK), scope_(scope), statements_(std::move(statements)) + explicit TSModuleBlock(ArenaVector &&statements) + : Statement(AstNodeType::TS_MODULE_BLOCK), statements_(std::move(statements)) { } - binder::LocalScope *Scope() const + const ArenaVector &Statements() const { - return scope_; + return statements_; } - const ArenaVector &Statements() const + ArenaVector &Statements() { return statements_; } @@ -54,9 +50,9 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: - binder::LocalScope *scope_; ArenaVector statements_; }; } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsModuleDeclaration.cpp b/es2panda/ir/ts/tsModuleDeclaration.cpp index 65667dd6ef..0cca37f7e0 100644 --- a/es2panda/ir/ts/tsModuleDeclaration.cpp +++ b/es2panda/ir/ts/tsModuleDeclaration.cpp @@ -15,6 +15,7 @@ #include "tsModuleDeclaration.h" +#include #include #include #include @@ -46,4 +47,14 @@ checker::Type *TSModuleDeclaration::Check([[maybe_unused]] checker::Checker *che return nullptr; } +void TSModuleDeclaration::UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) +{ + name_ = std::get(cb(name_))->AsExpression(); + + if (body_) { + auto scopeCtx = binder::LexicalScope::Enter(binder, scope_); + body_ = std::get(cb(body_))->AsStatement(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsModuleDeclaration.h b/es2panda/ir/ts/tsModuleDeclaration.h index dc991c4d26..82d7929080 100644 --- a/es2panda/ir/ts/tsModuleDeclaration.h +++ b/es2panda/ir/ts/tsModuleDeclaration.h @@ -16,12 +16,9 @@ #ifndef ES2PANDA_IR_TS_MODULE_DECLARATION_H #define ES2PANDA_IR_TS_MODULE_DECLARATION_H +#include #include -namespace panda::es2panda::binder { -class LocalScope; -} // namespace panda::es2panda::binder - namespace panda::es2panda::compiler { class PandaGen; } // namespace panda::es2panda::compiler @@ -37,18 +34,19 @@ class Expression; class TSModuleDeclaration : public Statement { public: - explicit TSModuleDeclaration(binder::LocalScope *scope, Expression *name, Statement *body, bool declare, - bool global) + explicit TSModuleDeclaration(binder::TSModuleScope *scope, Expression *name, Statement *body, bool declare, + bool global, bool isInstantiated = true) : Statement(AstNodeType::TS_MODULE_DECLARATION), scope_(scope), name_(name), body_(body), declare_(declare), - global_(global) + global_(global), + isInstantiated_(isInstantiated) { } - binder::LocalScope *Scope() const + binder::TSModuleScope *Scope() const { return scope_; } @@ -63,6 +61,11 @@ public: return body_; } + Statement *Body() + { + return body_; + } + bool Declare() const { return declare_; @@ -73,17 +76,24 @@ public: return global_; } + bool IsInstantiated() const + { + return isInstantiated_; + } + void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) override; private: - binder::LocalScope *scope_; + binder::TSModuleScope *scope_; Expression *name_; Statement *body_; bool declare_; bool global_; + bool isInstantiated_; }; } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsNamedTupleMember.cpp b/es2panda/ir/ts/tsNamedTupleMember.cpp index 5c76fbeef4..37b95b2583 100644 --- a/es2panda/ir/ts/tsNamedTupleMember.cpp +++ b/es2panda/ir/ts/tsNamedTupleMember.cpp @@ -42,4 +42,10 @@ checker::Type *TSNamedTupleMember::Check(checker::Checker *checker) const return nullptr; } +void TSNamedTupleMember::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + label_ = std::get(cb(label_))->AsExpression(); + elementType_ = std::get(cb(elementType_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsNamedTupleMember.h b/es2panda/ir/ts/tsNamedTupleMember.h index 135d4ed889..4243a75c1e 100644 --- a/es2panda/ir/ts/tsNamedTupleMember.h +++ b/es2panda/ir/ts/tsNamedTupleMember.h @@ -64,6 +64,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *label_; diff --git a/es2panda/ir/ts/tsNeverKeyword.cpp b/es2panda/ir/ts/tsNeverKeyword.cpp index 4964a4a9e0..3e2212e38a 100644 --- a/es2panda/ir/ts/tsNeverKeyword.cpp +++ b/es2panda/ir/ts/tsNeverKeyword.cpp @@ -39,4 +39,6 @@ checker::Type *TSNeverKeyword::GetType(checker::Checker *checker) const return checker->GlobalNeverType(); } +void TSNeverKeyword::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsNeverKeyword.h b/es2panda/ir/ts/tsNeverKeyword.h index 8333126ade..5692c320dd 100644 --- a/es2panda/ir/ts/tsNeverKeyword.h +++ b/es2panda/ir/ts/tsNeverKeyword.h @@ -38,6 +38,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; }; } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsNonNullExpression.cpp b/es2panda/ir/ts/tsNonNullExpression.cpp index 939c80a250..06f51f77c7 100644 --- a/es2panda/ir/ts/tsNonNullExpression.cpp +++ b/es2panda/ir/ts/tsNonNullExpression.cpp @@ -36,4 +36,9 @@ checker::Type *TSNonNullExpression::Check([[maybe_unused]] checker::Checker *che return nullptr; } +void TSNonNullExpression::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + expr_ = std::get(cb(expr_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsNonNullExpression.h b/es2panda/ir/ts/tsNonNullExpression.h index 110a3174ef..9f278f49f7 100644 --- a/es2panda/ir/ts/tsNonNullExpression.h +++ b/es2panda/ir/ts/tsNonNullExpression.h @@ -42,6 +42,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *expr_; diff --git a/es2panda/ir/ts/tsNullKeyword.cpp b/es2panda/ir/ts/tsNullKeyword.cpp index 0077cfc10d..a8e4586345 100644 --- a/es2panda/ir/ts/tsNullKeyword.cpp +++ b/es2panda/ir/ts/tsNullKeyword.cpp @@ -39,4 +39,6 @@ checker::Type *TSNullKeyword::GetType(checker::Checker *checker) const return checker->GlobalNullType(); } +void TSNullKeyword::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsNullKeyword.h b/es2panda/ir/ts/tsNullKeyword.h index b9bff0b967..79bf0cc1cf 100644 --- a/es2panda/ir/ts/tsNullKeyword.h +++ b/es2panda/ir/ts/tsNullKeyword.h @@ -38,6 +38,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; }; } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsNumberKeyword.cpp b/es2panda/ir/ts/tsNumberKeyword.cpp index 18d86cd934..68b57f4988 100644 --- a/es2panda/ir/ts/tsNumberKeyword.cpp +++ b/es2panda/ir/ts/tsNumberKeyword.cpp @@ -39,4 +39,6 @@ checker::Type *TSNumberKeyword::GetType(checker::Checker *checker) const return checker->GlobalNumberType(); } +void TSNumberKeyword::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsNumberKeyword.h b/es2panda/ir/ts/tsNumberKeyword.h index 115936dfd9..d56a49c15b 100644 --- a/es2panda/ir/ts/tsNumberKeyword.h +++ b/es2panda/ir/ts/tsNumberKeyword.h @@ -38,6 +38,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; }; } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsObjectKeyword.cpp b/es2panda/ir/ts/tsObjectKeyword.cpp index bbe29c3583..df378afe27 100644 --- a/es2panda/ir/ts/tsObjectKeyword.cpp +++ b/es2panda/ir/ts/tsObjectKeyword.cpp @@ -39,4 +39,6 @@ checker::Type *TSObjectKeyword::GetType(checker::Checker *checker) const return checker->GlobalNonPrimitiveType(); } +void TSObjectKeyword::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsObjectKeyword.h b/es2panda/ir/ts/tsObjectKeyword.h index 6e4fa48fdf..35d668e219 100644 --- a/es2panda/ir/ts/tsObjectKeyword.h +++ b/es2panda/ir/ts/tsObjectKeyword.h @@ -38,6 +38,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; }; } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsOptionalType.cpp b/es2panda/ir/ts/tsOptionalType.cpp index 297e6641ed..88dcbf1463 100644 --- a/es2panda/ir/ts/tsOptionalType.cpp +++ b/es2panda/ir/ts/tsOptionalType.cpp @@ -50,4 +50,9 @@ checker::Type *TSOptionalType::GetType(checker::Checker *checker) const return type; } +void TSOptionalType::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + type_ = std::get(cb(type_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsOptionalType.h b/es2panda/ir/ts/tsOptionalType.h index 3d9af242b0..525dca1690 100644 --- a/es2panda/ir/ts/tsOptionalType.h +++ b/es2panda/ir/ts/tsOptionalType.h @@ -31,6 +31,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *type_; diff --git a/es2panda/ir/ts/tsParameterProperty.cpp b/es2panda/ir/ts/tsParameterProperty.cpp index a1583d5a6a..2768a1e419 100644 --- a/es2panda/ir/ts/tsParameterProperty.cpp +++ b/es2panda/ir/ts/tsParameterProperty.cpp @@ -45,4 +45,10 @@ checker::Type *TSParameterProperty::Check([[maybe_unused]] checker::Checker *che { return nullptr; } + +void TSParameterProperty::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + parameter_ = std::get(cb(parameter_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsParameterProperty.h b/es2panda/ir/ts/tsParameterProperty.h index 635ec0a455..1addbb278f 100644 --- a/es2panda/ir/ts/tsParameterProperty.h +++ b/es2panda/ir/ts/tsParameterProperty.h @@ -73,6 +73,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: AccessibilityOption accessibility_; diff --git a/es2panda/ir/ts/tsParenthesizedType.cpp b/es2panda/ir/ts/tsParenthesizedType.cpp index b6dc972a03..25a4e89149 100644 --- a/es2panda/ir/ts/tsParenthesizedType.cpp +++ b/es2panda/ir/ts/tsParenthesizedType.cpp @@ -51,4 +51,9 @@ checker::Type *TSParenthesizedType::GetType(checker::Checker *checker) const return type; } +void TSParenthesizedType::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + type_ = std::get(cb(type_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsParenthesizedType.h b/es2panda/ir/ts/tsParenthesizedType.h index f40552fdf1..1d20117403 100644 --- a/es2panda/ir/ts/tsParenthesizedType.h +++ b/es2panda/ir/ts/tsParenthesizedType.h @@ -43,6 +43,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *type_; diff --git a/es2panda/ir/ts/tsPrivateIdentifier.cpp b/es2panda/ir/ts/tsPrivateIdentifier.cpp index e510353450..1ddda30c91 100644 --- a/es2panda/ir/ts/tsPrivateIdentifier.cpp +++ b/es2panda/ir/ts/tsPrivateIdentifier.cpp @@ -47,4 +47,17 @@ checker::Type *TSPrivateIdentifier::Check([[maybe_unused]] checker::Checker *che return nullptr; } +void TSPrivateIdentifier::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + key_ = std::get(cb(key_))->AsExpression(); + + if (value_) { + value_ = std::get(cb(value_))->AsExpression(); + } + + if (typeAnnotation_) { + typeAnnotation_ = std::get(cb(typeAnnotation_))->AsExpression(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsPrivateIdentifier.h b/es2panda/ir/ts/tsPrivateIdentifier.h index e4872d5a8f..594261e2de 100644 --- a/es2panda/ir/ts/tsPrivateIdentifier.h +++ b/es2panda/ir/ts/tsPrivateIdentifier.h @@ -55,6 +55,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *key_; diff --git a/es2panda/ir/ts/tsPropertySignature.cpp b/es2panda/ir/ts/tsPropertySignature.cpp index 1905714fbc..2450bd47a1 100644 --- a/es2panda/ir/ts/tsPropertySignature.cpp +++ b/es2panda/ir/ts/tsPropertySignature.cpp @@ -63,4 +63,13 @@ checker::Type *TSPropertySignature::Check(checker::Checker *checker) const return nullptr; } +void TSPropertySignature::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + key_ = std::get(cb(key_))->AsExpression(); + + if (typeAnnotation_) { + typeAnnotation_ = std::get(cb(typeAnnotation_))->AsExpression(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsPropertySignature.h b/es2panda/ir/ts/tsPropertySignature.h index 7adc8b2b1a..83ec0318ca 100644 --- a/es2panda/ir/ts/tsPropertySignature.h +++ b/es2panda/ir/ts/tsPropertySignature.h @@ -76,6 +76,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *key_; diff --git a/es2panda/ir/ts/tsQualifiedName.cpp b/es2panda/ir/ts/tsQualifiedName.cpp index c6088362bd..cb4acc6f73 100644 --- a/es2panda/ir/ts/tsQualifiedName.cpp +++ b/es2panda/ir/ts/tsQualifiedName.cpp @@ -55,4 +55,10 @@ checker::Type *TSQualifiedName::Check(checker::Checker *checker) const return nullptr; } +void TSQualifiedName::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + left_ = std::get(cb(left_))->AsExpression(); + right_ = std::get(cb(right_))->AsIdentifier(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsQualifiedName.h b/es2panda/ir/ts/tsQualifiedName.h index 94c381a0db..c4e61615a9 100644 --- a/es2panda/ir/ts/tsQualifiedName.h +++ b/es2panda/ir/ts/tsQualifiedName.h @@ -41,6 +41,11 @@ public: return left_; } + Expression *Left() + { + return left_; + } + const Identifier *Right() const { return right_; @@ -55,6 +60,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *left_; diff --git a/es2panda/ir/ts/tsRestType.cpp b/es2panda/ir/ts/tsRestType.cpp index a3ec1e049c..e219fdc2ff 100644 --- a/es2panda/ir/ts/tsRestType.cpp +++ b/es2panda/ir/ts/tsRestType.cpp @@ -50,4 +50,9 @@ checker::Type *TSRestType::GetType(checker::Checker *checker) const return type; } +void TSRestType::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + type_ = std::get(cb(type_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsRestType.h b/es2panda/ir/ts/tsRestType.h index 419333842f..f9ec4a0960 100644 --- a/es2panda/ir/ts/tsRestType.h +++ b/es2panda/ir/ts/tsRestType.h @@ -31,6 +31,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *type_; diff --git a/es2panda/ir/ts/tsSignatureDeclaration.cpp b/es2panda/ir/ts/tsSignatureDeclaration.cpp index 137bd4aa21..87c28ea929 100644 --- a/es2panda/ir/ts/tsSignatureDeclaration.cpp +++ b/es2panda/ir/ts/tsSignatureDeclaration.cpp @@ -15,12 +15,13 @@ #include "tsSignatureDeclaration.h" -#include +#include #include #include #include #include #include +#include namespace panda::es2panda::ir { @@ -94,4 +95,21 @@ checker::Type *TSSignatureDeclaration::Check(checker::Checker *checker) const return placeholderObj; } +void TSSignatureDeclaration::UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) +{ + auto scopeCtx = binder::LexicalScope::Enter(binder, scope_); + + if (typeParams_) { + typeParams_ = std::get(cb(typeParams_))->AsTSTypeParameterDeclaration(); + } + + for (auto iter = params_.begin(); iter != params_.end(); iter++) { + *iter = std::get(cb(*iter))->AsExpression(); + } + + if (returnTypeAnnotation_) { + returnTypeAnnotation_ = std::get(cb(returnTypeAnnotation_))->AsExpression(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsSignatureDeclaration.h b/es2panda/ir/ts/tsSignatureDeclaration.h index c23f0aa311..7a2ddf2f6c 100644 --- a/es2panda/ir/ts/tsSignatureDeclaration.h +++ b/es2panda/ir/ts/tsSignatureDeclaration.h @@ -79,6 +79,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) override; private: binder::Scope *scope_; diff --git a/es2panda/ir/ts/tsStringKeyword.cpp b/es2panda/ir/ts/tsStringKeyword.cpp index e58baba284..faf13883cd 100644 --- a/es2panda/ir/ts/tsStringKeyword.cpp +++ b/es2panda/ir/ts/tsStringKeyword.cpp @@ -39,4 +39,6 @@ checker::Type *TSStringKeyword::GetType(checker::Checker *checker) const return checker->GlobalStringType(); } +void TSStringKeyword::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsStringKeyword.h b/es2panda/ir/ts/tsStringKeyword.h index 8b626571a6..057ecfbf8f 100644 --- a/es2panda/ir/ts/tsStringKeyword.h +++ b/es2panda/ir/ts/tsStringKeyword.h @@ -38,6 +38,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; }; } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsSymbolKeyword.cpp b/es2panda/ir/ts/tsSymbolKeyword.cpp index 7234176e4f..28ba8a6e39 100644 --- a/es2panda/ir/ts/tsSymbolKeyword.cpp +++ b/es2panda/ir/ts/tsSymbolKeyword.cpp @@ -40,4 +40,6 @@ checker::Type *TSSymbolKeyword::GetType(checker::Checker *checker) const return checker->GlobalSymbolType(); } +void TSSymbolKeyword::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsSymbolKeyword.h b/es2panda/ir/ts/tsSymbolKeyword.h index 27e20304e8..53a046cf31 100644 --- a/es2panda/ir/ts/tsSymbolKeyword.h +++ b/es2panda/ir/ts/tsSymbolKeyword.h @@ -31,6 +31,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; }; } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsTemplateLiteralType.cpp b/es2panda/ir/ts/tsTemplateLiteralType.cpp index d9c300e254..f817c710c9 100644 --- a/es2panda/ir/ts/tsTemplateLiteralType.cpp +++ b/es2panda/ir/ts/tsTemplateLiteralType.cpp @@ -49,4 +49,15 @@ checker::Type *TSTemplateLiteralType::GetType(checker::Checker *checker) const return nullptr; } +void TSTemplateLiteralType::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + for (auto iter = references_.begin(); iter != references_.end(); iter++) { + *iter = std::get(cb(*iter))->AsExpression(); + } + + for (auto iter = quasis_.begin(); iter != quasis_.end(); iter++) { + *iter = std::get(cb(*iter))->AsTemplateElement(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsTemplateLiteralType.h b/es2panda/ir/ts/tsTemplateLiteralType.h index 6fe63b084a..518b53c404 100644 --- a/es2panda/ir/ts/tsTemplateLiteralType.h +++ b/es2panda/ir/ts/tsTemplateLiteralType.h @@ -36,6 +36,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: ArenaVector quasis_; diff --git a/es2panda/ir/ts/tsThisType.cpp b/es2panda/ir/ts/tsThisType.cpp index 23573f4c46..86a7392c01 100644 --- a/es2panda/ir/ts/tsThisType.cpp +++ b/es2panda/ir/ts/tsThisType.cpp @@ -38,4 +38,6 @@ checker::Type *TSThisType::GetType([[maybe_unused]] checker::Checker *checker) c return nullptr; } +void TSThisType::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsThisType.h b/es2panda/ir/ts/tsThisType.h index 826d37e38f..c36a53ac7e 100644 --- a/es2panda/ir/ts/tsThisType.h +++ b/es2panda/ir/ts/tsThisType.h @@ -38,6 +38,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; checker::Type *GetType([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; }; } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsTupleType.cpp b/es2panda/ir/ts/tsTupleType.cpp index 530305e70e..f3fb275c9a 100644 --- a/es2panda/ir/ts/tsTupleType.cpp +++ b/es2panda/ir/ts/tsTupleType.cpp @@ -125,4 +125,11 @@ checker::Type *TSTupleType::Check(checker::Checker *checker) const return nullptr; } +void TSTupleType::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + for (auto iter = elementTypes_.begin(); iter != elementTypes_.end(); iter++) { + *iter = std::get(cb(*iter))->AsExpression(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsTupleType.h b/es2panda/ir/ts/tsTupleType.h index e3590c8812..3fbbd08236 100644 --- a/es2panda/ir/ts/tsTupleType.h +++ b/es2panda/ir/ts/tsTupleType.h @@ -48,6 +48,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: ArenaVector elementTypes_; diff --git a/es2panda/ir/ts/tsTypeAliasDeclaration.cpp b/es2panda/ir/ts/tsTypeAliasDeclaration.cpp index d3061ac3d4..4cb8f006ee 100644 --- a/es2panda/ir/ts/tsTypeAliasDeclaration.cpp +++ b/es2panda/ir/ts/tsTypeAliasDeclaration.cpp @@ -52,4 +52,15 @@ checker::Type *TSTypeAliasDeclaration::Check(checker::Checker *checker) const return nullptr; } +void TSTypeAliasDeclaration::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + id_ = std::get(cb(id_))->AsIdentifier(); + + if (typeParams_) { + typeParams_ = std::get(cb(typeParams_))->AsTSTypeParameterDeclaration(); + } + + typeAnnotation_ = std::get(cb(typeAnnotation_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsTypeAliasDeclaration.h b/es2panda/ir/ts/tsTypeAliasDeclaration.h index ce247e3204..cab6f4beb7 100644 --- a/es2panda/ir/ts/tsTypeAliasDeclaration.h +++ b/es2panda/ir/ts/tsTypeAliasDeclaration.h @@ -72,6 +72,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Identifier *id_; diff --git a/es2panda/ir/ts/tsTypeAssertion.cpp b/es2panda/ir/ts/tsTypeAssertion.cpp index 90ed300678..cc09c20103 100644 --- a/es2panda/ir/ts/tsTypeAssertion.cpp +++ b/es2panda/ir/ts/tsTypeAssertion.cpp @@ -37,4 +37,10 @@ checker::Type *TSTypeAssertion::Check([[maybe_unused]] checker::Checker *checker return nullptr; } +void TSTypeAssertion::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + typeAnnotation_ = std::get(cb(typeAnnotation_))->AsExpression(); + expression_ = std::get(cb(expression_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsTypeAssertion.h b/es2panda/ir/ts/tsTypeAssertion.h index d23ba49630..afc8ced7fb 100644 --- a/es2panda/ir/ts/tsTypeAssertion.h +++ b/es2panda/ir/ts/tsTypeAssertion.h @@ -50,6 +50,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *typeAnnotation_; diff --git a/es2panda/ir/ts/tsTypeLiteral.cpp b/es2panda/ir/ts/tsTypeLiteral.cpp index f5f5825e32..00122d78ba 100644 --- a/es2panda/ir/ts/tsTypeLiteral.cpp +++ b/es2panda/ir/ts/tsTypeLiteral.cpp @@ -67,4 +67,12 @@ checker::Type *TSTypeLiteral::GetType(checker::Checker *checker) const return type; } + +void TSTypeLiteral::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + for (auto iter = members_.begin(); iter != members_.end(); iter++) { + *iter = std::get(cb(*iter))->AsExpression(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsTypeLiteral.h b/es2panda/ir/ts/tsTypeLiteral.h index 99066fd699..d34774fa9c 100644 --- a/es2panda/ir/ts/tsTypeLiteral.h +++ b/es2panda/ir/ts/tsTypeLiteral.h @@ -46,6 +46,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: ArenaVector members_; diff --git a/es2panda/ir/ts/tsTypeOperator.cpp b/es2panda/ir/ts/tsTypeOperator.cpp index 2d910a47e1..48ce1f914b 100644 --- a/es2panda/ir/ts/tsTypeOperator.cpp +++ b/es2panda/ir/ts/tsTypeOperator.cpp @@ -45,4 +45,9 @@ checker::Type *TSTypeOperator::GetType([[maybe_unused]] checker::Checker *checke return nullptr; } +void TSTypeOperator::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + type_ = std::get(cb(type_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsTypeOperator.h b/es2panda/ir/ts/tsTypeOperator.h index 3f1815e9df..5883f7611c 100644 --- a/es2panda/ir/ts/tsTypeOperator.h +++ b/es2panda/ir/ts/tsTypeOperator.h @@ -61,6 +61,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; checker::Type *GetType([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *type_; diff --git a/es2panda/ir/ts/tsTypeParameter.cpp b/es2panda/ir/ts/tsTypeParameter.cpp index 462c53bb2e..fc60a331fc 100644 --- a/es2panda/ir/ts/tsTypeParameter.cpp +++ b/es2panda/ir/ts/tsTypeParameter.cpp @@ -50,4 +50,17 @@ checker::Type *TSTypeParameter::Check([[maybe_unused]] checker::Checker *checker return nullptr; } +void TSTypeParameter::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + name_ = std::get(cb(name_))->AsIdentifier(); + + if (constraint_) { + constraint_ = std::get(cb(constraint_))->AsIdentifier(); + } + + if (defaultType_) { + defaultType_ = std::get(cb(defaultType_))->AsIdentifier(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsTypeParameter.h b/es2panda/ir/ts/tsTypeParameter.h index fb6d2c0331..1f6a560918 100644 --- a/es2panda/ir/ts/tsTypeParameter.h +++ b/es2panda/ir/ts/tsTypeParameter.h @@ -57,6 +57,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Identifier *name_; diff --git a/es2panda/ir/ts/tsTypeParameterDeclaration.cpp b/es2panda/ir/ts/tsTypeParameterDeclaration.cpp index 7b2e868caa..10ed66107d 100644 --- a/es2panda/ir/ts/tsTypeParameterDeclaration.cpp +++ b/es2panda/ir/ts/tsTypeParameterDeclaration.cpp @@ -40,4 +40,11 @@ checker::Type *TSTypeParameterDeclaration::Check([[maybe_unused]] checker::Check return nullptr; } +void TSTypeParameterDeclaration::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + for (auto iter = params_.begin(); iter != params_.end(); iter++) { + *iter = std::get(cb(*iter))->AsTSTypeParameter(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsTypeParameterDeclaration.h b/es2panda/ir/ts/tsTypeParameterDeclaration.h index d8b09540b6..539f2aba97 100644 --- a/es2panda/ir/ts/tsTypeParameterDeclaration.h +++ b/es2panda/ir/ts/tsTypeParameterDeclaration.h @@ -65,6 +65,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: binder::LocalScope *scope_; diff --git a/es2panda/ir/ts/tsTypeParameterInstantiation.cpp b/es2panda/ir/ts/tsTypeParameterInstantiation.cpp index 5910cfbc00..332f1ba33a 100644 --- a/es2panda/ir/ts/tsTypeParameterInstantiation.cpp +++ b/es2panda/ir/ts/tsTypeParameterInstantiation.cpp @@ -39,4 +39,11 @@ checker::Type *TSTypeParameterInstantiation::Check([[maybe_unused]] checker::Che return nullptr; } +void TSTypeParameterInstantiation::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + for (auto iter = params_.begin(); iter != params_.end(); iter++) { + *iter = std::get(cb(*iter))->AsExpression(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsTypeParameterInstantiation.h b/es2panda/ir/ts/tsTypeParameterInstantiation.h index 0bedba52ff..318fb9f2e4 100644 --- a/es2panda/ir/ts/tsTypeParameterInstantiation.h +++ b/es2panda/ir/ts/tsTypeParameterInstantiation.h @@ -45,6 +45,7 @@ public: void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: ArenaVector params_; diff --git a/es2panda/ir/ts/tsTypePredicate.cpp b/es2panda/ir/ts/tsTypePredicate.cpp index 52d00c0875..b20f29aa58 100644 --- a/es2panda/ir/ts/tsTypePredicate.cpp +++ b/es2panda/ir/ts/tsTypePredicate.cpp @@ -48,4 +48,13 @@ checker::Type *TSTypePredicate::GetType([[maybe_unused]] checker::Checker *check return nullptr; } +void TSTypePredicate::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + parameterName_ = std::get(cb(parameterName_))->AsExpression(); + + if (typeAnnotation_) { + typeAnnotation_ = std::get(cb(typeAnnotation_))->AsExpression(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsTypePredicate.h b/es2panda/ir/ts/tsTypePredicate.h index 1c59db4bb7..0a5e2edca9 100644 --- a/es2panda/ir/ts/tsTypePredicate.h +++ b/es2panda/ir/ts/tsTypePredicate.h @@ -59,6 +59,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; checker::Type *GetType([[maybe_unused]] checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *parameterName_; diff --git a/es2panda/ir/ts/tsTypeQuery.cpp b/es2panda/ir/ts/tsTypeQuery.cpp index 0a4c50bb7f..a9ee275d74 100644 --- a/es2panda/ir/ts/tsTypeQuery.cpp +++ b/es2panda/ir/ts/tsTypeQuery.cpp @@ -53,4 +53,9 @@ checker::Type *TSTypeQuery::GetType(checker::Checker *checker) const return type; } +void TSTypeQuery::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + exprName_ = std::get(cb(exprName_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsTypeQuery.h b/es2panda/ir/ts/tsTypeQuery.h index 5d282b8d3e..deab8a34c6 100644 --- a/es2panda/ir/ts/tsTypeQuery.h +++ b/es2panda/ir/ts/tsTypeQuery.h @@ -43,6 +43,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *exprName_; diff --git a/es2panda/ir/ts/tsTypeReference.cpp b/es2panda/ir/ts/tsTypeReference.cpp index 4dac7c8c79..10f5002de6 100644 --- a/es2panda/ir/ts/tsTypeReference.cpp +++ b/es2panda/ir/ts/tsTypeReference.cpp @@ -77,4 +77,13 @@ checker::Type *TSTypeReference::GetType(checker::Checker *checker) const return type; } +void TSTypeReference::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + if (typeParams_) { + typeParams_ = std::get(cb(typeParams_))->AsTSTypeParameterInstantiation(); + } + + typeName_ = std::get(cb(typeName_))->AsExpression(); +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsTypeReference.h b/es2panda/ir/ts/tsTypeReference.h index c7af1d9d2a..6f8ebe0564 100644 --- a/es2panda/ir/ts/tsTypeReference.h +++ b/es2panda/ir/ts/tsTypeReference.h @@ -58,6 +58,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: Expression *typeName_; diff --git a/es2panda/ir/ts/tsUndefinedKeyword.cpp b/es2panda/ir/ts/tsUndefinedKeyword.cpp index ca431d73cf..2b23a6fc7b 100644 --- a/es2panda/ir/ts/tsUndefinedKeyword.cpp +++ b/es2panda/ir/ts/tsUndefinedKeyword.cpp @@ -39,4 +39,6 @@ checker::Type *TSUndefinedKeyword::GetType(checker::Checker *checker) const return checker->GlobalUndefinedType(); } +void TSUndefinedKeyword::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsUndefinedKeyword.h b/es2panda/ir/ts/tsUndefinedKeyword.h index fd7860f9d1..c3b253dbe9 100644 --- a/es2panda/ir/ts/tsUndefinedKeyword.h +++ b/es2panda/ir/ts/tsUndefinedKeyword.h @@ -38,6 +38,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; }; } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsUnionType.cpp b/es2panda/ir/ts/tsUnionType.cpp index ecb98b5bba..b1f1ba68e0 100644 --- a/es2panda/ir/ts/tsUnionType.cpp +++ b/es2panda/ir/ts/tsUnionType.cpp @@ -65,4 +65,11 @@ checker::Type *TSUnionType::GetType(checker::Checker *checker) const return type; } +void TSUnionType::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + for (auto iter = types_.begin(); iter != types_.end(); iter++) { + *iter = std::get(cb(*iter))->AsExpression(); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsUnionType.h b/es2panda/ir/ts/tsUnionType.h index 8146f1c052..baf10055f8 100644 --- a/es2panda/ir/ts/tsUnionType.h +++ b/es2panda/ir/ts/tsUnionType.h @@ -46,6 +46,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check(checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: ArenaVector types_; diff --git a/es2panda/ir/ts/tsUnknownKeyword.cpp b/es2panda/ir/ts/tsUnknownKeyword.cpp index 69f2934674..d048731d69 100644 --- a/es2panda/ir/ts/tsUnknownKeyword.cpp +++ b/es2panda/ir/ts/tsUnknownKeyword.cpp @@ -39,4 +39,6 @@ checker::Type *TSUnknownKeyword::GetType(checker::Checker *checker) const return checker->GlobalUnknownType(); } +void TSUnknownKeyword::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsUnknownKeyword.h b/es2panda/ir/ts/tsUnknownKeyword.h index eacdf05ead..b76ec1f652 100644 --- a/es2panda/ir/ts/tsUnknownKeyword.h +++ b/es2panda/ir/ts/tsUnknownKeyword.h @@ -38,6 +38,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; }; } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsVoidKeyword.cpp b/es2panda/ir/ts/tsVoidKeyword.cpp index ab6febb2b2..df9998eb8b 100644 --- a/es2panda/ir/ts/tsVoidKeyword.cpp +++ b/es2panda/ir/ts/tsVoidKeyword.cpp @@ -39,4 +39,6 @@ checker::Type *TSVoidKeyword::GetType(checker::Checker *checker) const return checker->GlobalVoidType(); } +void TSVoidKeyword::UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) {} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/ts/tsVoidKeyword.h b/es2panda/ir/ts/tsVoidKeyword.h index dbd904d6a9..d898343913 100644 --- a/es2panda/ir/ts/tsVoidKeyword.h +++ b/es2panda/ir/ts/tsVoidKeyword.h @@ -38,6 +38,7 @@ public: void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::Checker *checker) const override; checker::Type *GetType(checker::Checker *checker) const override; + void UpdateSelf([[maybe_unused]] const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; }; } // namespace panda::es2panda::ir diff --git a/es2panda/parser/parserImpl.cpp b/es2panda/parser/parserImpl.cpp index 664faf665e..0b7012d10b 100644 --- a/es2panda/parser/parserImpl.cpp +++ b/es2panda/parser/parserImpl.cpp @@ -139,7 +139,11 @@ Program ParserImpl::Parse(const std::string &fileName, const std::string &source UNREACHABLE(); } } - Binder()->IdentifierAnalysis(); + binder::ResolveBindingFlags bindFlags = binder::ResolveBindingFlags::ALL; + if (Extension() == ScriptExtension::TS) { + bindFlags = binder::ResolveBindingFlags::TS_BEFORE_TRANSFORM; + } + Binder()->IdentifierAnalysis(bindFlags); return std::move(program_); } diff --git a/es2panda/parser/parserImpl.h b/es2panda/parser/parserImpl.h index ff4a6e6653..61873d0f20 100644 --- a/es2panda/parser/parserImpl.h +++ b/es2panda/parser/parserImpl.h @@ -184,6 +184,11 @@ public: void AddHotfixHelper(util::Hotfix *hotfixHelper); + ArenaAllocator *Allocator() const + { + return program_.Allocator(); + } + private: bool IsStartOfMappedType() const; bool IsStartOfTsTypePredicate() const; @@ -418,17 +423,19 @@ private: void AddExportStarEntryItem(const lexer::SourcePosition &startLoc, const ir::StringLiteral *source, const ir::Identifier *exported); void AddExportDefaultEntryItem(const ir::AstNode *declNode); - void AddExportLocalEntryItem(const ir::Statement *declNode); + void AddExportLocalEntryItem(const ir::Statement *declNode, bool isTsModule); parser::SourceTextModuleRecord *GetSourceTextModuleRecord(); bool ParseDirective(ArenaVector *statements); void ParseDirectivePrologue(ArenaVector *statements); ArenaVector ParseStatementList(StatementParsingFlags flags = StatementParsingFlags::ALLOW_LEXICAL); ir::Statement *ParseStatement(StatementParsingFlags flags = StatementParsingFlags::NONE); - ir::TSModuleDeclaration *ParseTsModuleDeclaration(bool isDeclare); + ir::TSModuleDeclaration *ParseTsModuleDeclaration(bool isDeclare, bool isExport = false); ir::TSModuleDeclaration *ParseTsAmbientExternalModuleDeclaration(const lexer::SourcePosition &startLoc, bool isDeclare); - ir::TSModuleDeclaration *ParseTsModuleOrNamespaceDelaration(const lexer::SourcePosition &startLoc, bool isDeclare); + ir::TSModuleDeclaration *ParseTsModuleOrNamespaceDelaration(const lexer::SourcePosition &startLoc, + bool isDeclare, + bool isExport); ir::TSImportEqualsDeclaration *ParseTsImportEqualsDeclaration(const lexer::SourcePosition &startLoc, bool isExport = false); @@ -497,11 +504,6 @@ private: return internalName.View(); } - ArenaAllocator *Allocator() const - { - return program_.Allocator(); - } - binder::Binder *Binder() { return program_.Binder(); diff --git a/es2panda/parser/program/program.cpp b/es2panda/parser/program/program.cpp index 891bd46e31..c184046e3a 100644 --- a/es2panda/parser/program/program.cpp +++ b/es2panda/parser/program/program.cpp @@ -35,9 +35,12 @@ Program::Program(Program &&other) ast_(other.ast_), sourceCode_(other.sourceCode_), sourceFile_(other.sourceFile_), + recordName_(other.recordName_), kind_(other.kind_), extension_(other.extension_), - lineIndex_(other.lineIndex_) + lineIndex_(other.lineIndex_), + moduleRecord_(other.moduleRecord_), + hotfixHelper_(other.hotfixHelper_) { other.binder_ = nullptr; other.ast_ = nullptr; diff --git a/es2panda/parser/statementParser.cpp b/es2panda/parser/statementParser.cpp index ffa8688480..ddb71e97f0 100644 --- a/es2panda/parser/statementParser.cpp +++ b/es2panda/parser/statementParser.cpp @@ -243,7 +243,7 @@ ir::Statement *ParserImpl::ParseStatement(StatementParsingFlags flags) return ParseExpressionStatement(flags); } -ir::TSModuleDeclaration *ParserImpl::ParseTsModuleDeclaration(bool isDeclare) +ir::TSModuleDeclaration *ParserImpl::ParseTsModuleDeclaration(bool isDeclare, bool isExport) { lexer::SourcePosition startLoc = lexer_->GetToken().Start(); context_.Status() |= ParserStatus::TS_MODULE; @@ -262,7 +262,7 @@ ir::TSModuleDeclaration *ParserImpl::ParseTsModuleDeclaration(bool isDeclare) } } - return ParseTsModuleOrNamespaceDelaration(startLoc, isDeclare); + return ParseTsModuleOrNamespaceDelaration(startLoc, isDeclare, isExport); } ir::TSModuleDeclaration *ParserImpl::ParseTsAmbientExternalModuleDeclaration(const lexer::SourcePosition &startLoc, @@ -288,7 +288,8 @@ ir::TSModuleDeclaration *ParserImpl::ParseTsAmbientExternalModuleDeclaration(con lexer_->NextToken(); - auto localCtx = binder::LexicalScope(Binder()); + binder::ExportBindings *exportBindings = Allocator()->New(Allocator()); + auto localCtx = binder::LexicalScope(Binder(), exportBindings); ir::Statement *body = nullptr; if (lexer_->GetToken().Type() == lexer::TokenType::PUNCTUATOR_LEFT_BRACE) { @@ -307,15 +308,32 @@ ir::TSModuleDeclaration *ParserImpl::ParseTsAmbientExternalModuleDeclaration(con } ir::TSModuleDeclaration *ParserImpl::ParseTsModuleOrNamespaceDelaration(const lexer::SourcePosition &startLoc, - bool isDeclare) + bool isDeclare, bool isExport) { if (lexer_->GetToken().Type() != lexer::TokenType::LITERAL_IDENT) { ThrowSyntaxError("Identifier expected"); } - auto *decl = Binder()->AddDecl(lexer_->GetToken().Start(), lexer_->GetToken().Ident()); + auto name = lexer_->GetToken().Ident(); + auto *parentScope = Binder()->GetScope(); + binder::Variable *res = parentScope->FindLocalTSVariable(name); + if (!res && isExport && parentScope->IsTSModuleScope()) { + res = parentScope->AsTSModuleScope()->FindExportTSVariable(name); + if (res != nullptr) { + parentScope->AddLocalTSVariable(name, res); + } + } + if (res == nullptr) { + Binder()->AddTsDecl(lexer_->GetToken().Start(), Allocator(), name); + res = parentScope->FindLocalTSVariable(name); + if (isExport && parentScope->IsTSModuleScope()) { + parentScope->AsTSModuleScope()->AddExportTSVariable(name, res); + } + res->AsNamespaceVariable()->SetExportBindings(Allocator()->New(Allocator())); + } + binder::ExportBindings *exportBindings = res->AsNamespaceVariable()->GetExportBindings(); - auto *identNode = AllocNode(lexer_->GetToken().Ident(), Allocator()); + auto *identNode = AllocNode(name, Allocator()); identNode->SetRange(lexer_->GetToken().Loc()); lexer_->NextToken(); @@ -327,22 +345,41 @@ ir::TSModuleDeclaration *ParserImpl::ParseTsModuleOrNamespaceDelaration(const le context_.Status() |= ParserStatus::IN_AMBIENT_CONTEXT; } - auto localCtx = binder::LexicalScope(Binder()); + auto localCtx = binder::LexicalScope(Binder(), exportBindings); + bool isInstantiated = false; if (lexer_->GetToken().Type() == lexer::TokenType::PUNCTUATOR_PERIOD) { lexer_->NextToken(); lexer::SourcePosition moduleStart = lexer_->GetToken().Start(); - body = ParseTsModuleOrNamespaceDelaration(moduleStart, false); + body = ParseTsModuleOrNamespaceDelaration(moduleStart, false, true); + isInstantiated = body->AsTSModuleDeclaration()->IsInstantiated(); } else { body = ParseTsModuleBlock(); + auto statements = body->AsTSModuleBlock()->Statements(); + for (auto *it : statements) { + auto statement = it; + if (statement->IsExportNamedDeclaration()) { + statement = statement->AsExportNamedDeclaration()->Decl(); + } + if (statement != nullptr && + !statement->IsTSInterfaceDeclaration() && !statement->IsTSTypeAliasDeclaration() && + (!statement->IsTSModuleDeclaration() || statement->AsTSModuleDeclaration()->IsInstantiated())) { + isInstantiated = true; + break; + } + } + } + if (isDeclare) { + isInstantiated = false; } context_.Status() = savedStatus; - auto *moduleDecl = AllocNode(localCtx.GetScope(), identNode, body, isDeclare, false); + auto *moduleDecl = AllocNode(localCtx.GetScope(), identNode, body, + isDeclare, false, isInstantiated); moduleDecl->SetRange({startLoc, lexer_->GetToken().End()}); localCtx.GetScope()->BindNode(moduleDecl); - decl->BindNode(moduleDecl); + res->Declaration()->AsNamespaceDecl()->Add(moduleDecl); return moduleDecl; } @@ -369,6 +406,21 @@ ir::TSImportEqualsDeclaration *ParserImpl::ParseTsImportEqualsDeclaration(const ThrowSyntaxError("identifier expected"); } + if (lexer_->GetToken().KeywordType() != lexer::TokenType::KEYW_REQUIRE || + lexer_->Lookahead() != LEX_CHAR_LEFT_PAREN) { + binder::DeclarationFlags declflag = binder::DeclarationFlags::NONE; + auto *decl = Binder()->AddDecl(id->Start(), declflag, id->Name()); + decl->BindNode(id); + auto *scope = Binder()->GetScope(); + auto name = id->Name(); + auto *var = scope->FindLocalTSVariable(name); + ASSERT(var != nullptr); + var->AsImportEqualsVariable()->SetScope(scope); + if (isExport && scope->IsTSModuleScope()) { + scope->AsTSModuleScope()->AddExportTSVariable(name, var); + } + } + auto *importEqualsDecl = AllocNode(id, ParseModuleReference(), isExport); importEqualsDecl->SetRange({startLoc, lexer_->GetToken().End()}); @@ -379,7 +431,6 @@ ir::TSImportEqualsDeclaration *ParserImpl::ParseTsImportEqualsDeclaration(const ir::TSModuleBlock *ParserImpl::ParseTsModuleBlock() { - auto localCtx = binder::LexicalScope(Binder()); if (lexer_->GetToken().Type() != lexer::TokenType::PUNCTUATOR_LEFT_BRACE) { ThrowSyntaxError("'{' expected."); } @@ -392,9 +443,8 @@ ir::TSModuleBlock *ParserImpl::ParseTsModuleBlock() ThrowSyntaxError("Expected a '}'"); } - auto *blockNode = AllocNode(localCtx.GetScope(), std::move(statements)); + auto *blockNode = AllocNode(std::move(statements)); blockNode->SetRange({startLoc, lexer_->GetToken().End()}); - localCtx.GetScope()->BindNode(blockNode); lexer_->NextToken(); return blockNode; @@ -2097,20 +2147,30 @@ void ParserImpl::AddExportDefaultEntryItem(const ir::AstNode *declNode) } } -void ParserImpl::AddExportLocalEntryItem(const ir::Statement *declNode) +void ParserImpl::AddExportLocalEntryItem(const ir::Statement *declNode, bool isTsModule) { ASSERT(declNode != nullptr); auto moduleRecord = GetSourceTextModuleRecord(); - ASSERT(moduleRecord != nullptr); + ASSERT(isTsModule || moduleRecord != nullptr); + binder::TSModuleScope *tsModuleScope = nullptr; + if (isTsModule) { + ASSERT(Binder()->GetScope()->IsTSModuleScope()); + tsModuleScope = Binder()->GetScope()->AsTSModuleScope(); + } if (declNode->IsVariableDeclaration()) { auto declarators = declNode->AsVariableDeclaration()->Declarators(); for (auto *decl : declarators) { std::vector bindings = util::Helpers::CollectBindingNames(decl->Id()); for (const auto *binding : bindings) { - auto *entry = moduleRecord->NewEntry( - binding->Name(), binding->Name()); - if (!moduleRecord->AddLocalExportEntry(entry)) { - ThrowSyntaxError("Duplicate export name of '" + binding->Name().Mutf8() + "'", binding->Start()); + if (isTsModule) { + tsModuleScope->AddExportVariable(binding->Name()); + } else { + auto *entry = moduleRecord->NewEntry( + binding->Name(), binding->Name()); + if (!moduleRecord->AddLocalExportEntry(entry)) { + ThrowSyntaxError("Duplicate export name of '" + binding->Name().Mutf8() + + "'", binding->Start()); + } } } } @@ -2123,9 +2183,14 @@ void ParserImpl::AddExportLocalEntryItem(const ir::Statement *declNode) ThrowSyntaxError("A class or function declaration without the default modifier mush have a name.", declNode->Start()); } - auto *entry = moduleRecord->NewEntry(name->Name(), name->Name()); - if (!moduleRecord->AddLocalExportEntry(entry)) { - ThrowSyntaxError("Duplicate export name of '" + name->Name().Mutf8() + "'", name->Start()); + if (isTsModule) { + tsModuleScope->AddExportVariable(name->Name()); + } else { + auto *entry = moduleRecord->NewEntry(name->Name(), + name->Name()); + if (!moduleRecord->AddLocalExportEntry(entry)) { + ThrowSyntaxError("Duplicate export name of '" + name->Name().Mutf8() + "'", name->Start()); + } } } } @@ -2279,6 +2344,7 @@ ir::ExportNamedDeclaration *ParserImpl::ParseNamedExportDeclaration(const lexer: ir::Statement *decl = nullptr; bool isDeclare = false; + bool isTsModule = context_.IsTsModule(); if (Extension() == ScriptExtension::TS && lexer_->GetToken().KeywordType() == lexer::TokenType::KEYW_DECLARE) { CheckDeclare(); @@ -2290,7 +2356,8 @@ ir::ExportNamedDeclaration *ParserImpl::ParseNamedExportDeclaration(const lexer: ThrowSyntaxError("Decorators are not valid here.", decorators.front()->Start()); } - VariableParsingFlags flag = VariableParsingFlags::EXPORTED; + VariableParsingFlags flag = isTsModule ? VariableParsingFlags::NO_OPTS : VariableParsingFlags::EXPORTED; + ParserStatus status = isTsModule ? ParserStatus::NO_OPTS : ParserStatus::EXPORT_REACHED; switch (lexer_->GetToken().Type()) { case lexer::TokenType::KEYW_VAR: { decl = ParseVariableDeclaration(flag | VariableParsingFlags::VAR, isDeclare); @@ -2305,11 +2372,11 @@ ir::ExportNamedDeclaration *ParserImpl::ParseNamedExportDeclaration(const lexer: break; } case lexer::TokenType::KEYW_FUNCTION: { - decl = ParseFunctionDeclaration(false, ParserStatus::EXPORT_REACHED, isDeclare); + decl = ParseFunctionDeclaration(false, status, isDeclare); break; } case lexer::TokenType::KEYW_CLASS: { - decl = ParseClassDeclaration(true, std::move(decorators), isDeclare, false, true); + decl = ParseClassDeclaration(true, std::move(decorators), isDeclare, false, !isTsModule); break; } case lexer::TokenType::LITERAL_IDENT: { @@ -2338,7 +2405,7 @@ ir::ExportNamedDeclaration *ParserImpl::ParseNamedExportDeclaration(const lexer: if (isDeclare) { context_.Status() |= ParserStatus::IN_AMBIENT_CONTEXT; } - decl = ParseTsModuleDeclaration(isDeclare); + decl = ParseTsModuleDeclaration(isDeclare, true); context_.Status() = savedStatus; break; } @@ -2360,7 +2427,7 @@ ir::ExportNamedDeclaration *ParserImpl::ParseNamedExportDeclaration(const lexer: } lexer_->NextToken(); // eat `async` keyword - decl = ParseFunctionDeclaration(false, ParserStatus::ASYNC_FUNCTION | ParserStatus::EXPORT_REACHED); + decl = ParseFunctionDeclaration(false, ParserStatus::ASYNC_FUNCTION | status); } } @@ -2368,9 +2435,7 @@ ir::ExportNamedDeclaration *ParserImpl::ParseNamedExportDeclaration(const lexer: ConsumeSemicolon(decl); } - if (Extension() != ScriptExtension::TS || !context_.IsTsModule()) { - AddExportLocalEntryItem(decl); - } + AddExportLocalEntryItem(decl, isTsModule); lexer::SourcePosition endLoc = decl->End(); ArenaVector specifiers(Allocator()->Adapter()); @@ -2383,7 +2448,7 @@ ir::ExportNamedDeclaration *ParserImpl::ParseNamedExportDeclaration(const lexer: ir::Statement *ParserImpl::ParseExportDeclaration(StatementParsingFlags flags, ArenaVector &&decorators) { - if (Extension() == ScriptExtension::JS) { + if (Extension() == ScriptExtension::JS || !context_.IsTsModule()) { if (!(flags & StatementParsingFlags::GLOBAL)) { ThrowSyntaxError("'import' and 'export' may only appear at the top level"); } @@ -2565,6 +2630,17 @@ ir::AstNode *ParserImpl::ParseImportDefaultSpecifier(ArenaVector if (lexer_->GetToken().Type() != lexer::TokenType::LITERAL_IDENT) { ThrowSyntaxError("identifier expected"); } + if (lexer_->GetToken().KeywordType() != lexer::TokenType::KEYW_REQUIRE || + lexer_->Lookahead() != LEX_CHAR_LEFT_PAREN) { + auto *decl = Binder()->AddDecl(local->Start(), + binder::DeclarationFlags::NONE, + local->Name()); + decl->BindNode(local); + auto *scope = Binder()->GetScope(); + auto *var = scope->FindLocalTSVariable(local->Name()); + ASSERT(var != nullptr); + var->AsImportEqualsVariable()->SetScope(scope); + } auto *importEqualsDecl = AllocNode(local, ParseModuleReference(), false); diff --git a/es2panda/parser/transformer/transformer.cpp b/es2panda/parser/transformer/transformer.cpp new file mode 100644 index 0000000000..19afc1c9fd --- /dev/null +++ b/es2panda/parser/transformer/transformer.cpp @@ -0,0 +1,527 @@ +/* + * 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. + */ + +#include "transformer.h" + +#include "ir/base/scriptFunction.h" +#include "ir/base/classDefinition.h" +#include "ir/expressions/assignmentExpression.h" +#include "ir/expressions/binaryExpression.h" +#include "ir/expressions/callExpression.h" +#include "ir/expressions/functionExpression.h" +#include "ir/expressions/identifier.h" +#include "ir/expressions/memberExpression.h" +#include "ir/expressions/objectExpression.h" +#include "ir/module/exportNamedDeclaration.h" +#include "ir/statements/blockStatement.h" +#include "ir/statements/classDeclaration.h" +#include "ir/statements/emptyStatement.h" +#include "ir/statements/expressionStatement.h" +#include "ir/statements/functionDeclaration.h" +#include "ir/statements/variableDeclaration.h" +#include "ir/statements/variableDeclarator.h" +#include "ir/ts/tsImportEqualsDeclaration.h" +#include "ir/ts/tsModuleBlock.h" +#include "ir/ts/tsModuleDeclaration.h" +#include "ir/ts/tsQualifiedName.h" +#include "util/helpers.h" + + +namespace panda::es2panda::parser { + +void Transformer::Transform(Program *program) +{ + program_ = program; + if (Extension() == ScriptExtension::TS) { + TransformFromTS(); + } +} + +void Transformer::TransformFromTS() +{ + ASSERT(Extension() == ScriptExtension::TS); + VisitTSNodes(program_->Ast()); +} + +ir::AstNode *Transformer::VisitTSNodes(ir::AstNode *parent) +{ + if (!parent) { + return nullptr; + } + parent->UpdateSelf([this](auto *childNode) { return VisitTSNode(childNode); }, Binder()); + return parent; +} + +binder::Scope *Transformer::FindExportVariableInTsModuleScope(util::StringView name) const +{ + bool isExport = false; + auto currentScope = Scope(); + while (currentScope != nullptr) { + binder::Variable *v = currentScope->FindLocal(name, binder::ResolveBindingOptions::ALL); + bool isTSModuleScope = currentScope->IsTSModuleScope(); + if (v != nullptr) { + if (!v->HasFlag(binder::VariableFlags::VAR)) { + break; + } + if (isTSModuleScope && currentScope->AsTSModuleScope()->FindExportVariable(name)) { + isExport = true; + } + break; + } + if (currentScope->InLocalTSBindings(name) && + !currentScope->FindLocalTSVariable(name)) { + break; + } + if (isTSModuleScope && currentScope->AsTSModuleScope()->InExportBindings(name)) { + isExport = true; + break; + } + currentScope = currentScope->Parent(); + } + if (!isExport) { + return nullptr; + } + return currentScope; +} + +ir::UpdateNodes Transformer::VisitTSNode(ir::AstNode *childNode) +{ + ASSERT(childNode != nullptr); + switch (childNode->Type()) { + case ir::AstNodeType::IDENTIFIER: { + auto *ident = childNode->AsIdentifier(); + if (!ident->IsReference() || !IsTsModule()) { + return VisitTSNodes(childNode); + } + + auto name = ident->Name(); + auto scope = FindExportVariableInTsModuleScope(name); + if (scope) { + auto moduleName = FindTSModuleNameByScope(scope); + auto *id = AllocNode(moduleName, Allocator()); + id->AsIdentifier()->SetReference(); + auto *res = AllocNode(id, AllocNode(name, Allocator()), + ir::MemberExpression::MemberExpressionKind::PROPERTY_ACCESS, false, false); + SetOriginalNode(res, childNode); + return res; + } + + return VisitTSNodes(childNode); + } + case ir::AstNodeType::TS_MODULE_DECLARATION: { + auto *node = childNode->AsTSModuleDeclaration(); + if (node->Declare() || !node->IsInstantiated()) { + return childNode; + } + auto res = VisitTsModuleDeclaration(node); + SetOriginalNode(res, childNode); + return res; + } + case ir::AstNodeType::EXPORT_NAMED_DECLARATION: { + auto *node = childNode->AsExportNamedDeclaration(); + auto *decl = node->Decl(); + if (!decl) { + return VisitTSNodes(childNode); + } + + if (decl->IsTSModuleDeclaration()) { + auto *tsModuleDeclaration = decl->AsTSModuleDeclaration(); + if (tsModuleDeclaration->Declare() || !tsModuleDeclaration->IsInstantiated()) { + return childNode; + } + auto res = VisitTsModuleDeclaration(tsModuleDeclaration, true); + SetOriginalNode(res, childNode); + return res; + } + + if (!IsTsModule()) { + return VisitTSNodes(childNode); + } + + auto res = VisitExportNamedVariable(decl); + SetOriginalNode(res, childNode); + return res; + } + case ir::AstNodeType::TS_IMPORT_EQUALS_DECLARATION: { + auto *node = childNode->AsTSImportEqualsDeclaration(); + auto *express = node->ModuleReference(); + if (express->IsTSExternalModuleReference()) { + return VisitTSNodes(childNode); + } + auto *res = VisitTsImportEqualsDeclaration(node); + SetOriginalNode(res, childNode); + return res; + } + default: { + return VisitTSNodes(childNode); + } + } +} + +ir::AstNode *Transformer::VisitTsImportEqualsDeclaration(ir::TSImportEqualsDeclaration *node) +{ + auto *express = node->ModuleReference(); + if (!IsInstantiatedTSModule(express)) { + return node; + } + auto name = node->Id()->Name(); + if (IsTsModule() && node->IsExport()) { + auto moduleName = GetCurrentTSModuleName(); + auto *id = AllocNode(moduleName, Allocator()); + id->AsIdentifier()->SetReference(); + auto *left = AllocNode(id, AllocNode(name, Allocator()), + ir::MemberExpression::MemberExpressionKind::PROPERTY_ACCESS, false, false); + ir::Expression *right = CreateMemberExpressionFromQualified(express); + auto *assignExpr = AllocNode(left, right, + lexer::TokenType::PUNCTUATOR_SUBSTITUTION); + auto *res = AllocNode(assignExpr); + return res; + } + + ir::Expression *init = CreateMemberExpressionFromQualified(express); + ir::Statement *res = CreateVariableDeclarationWithIdentify(name, VariableParsingFlags::VAR, node, + node->IsExport(), init); + if (node->IsExport()) { + ArenaVector specifiers(Allocator()->Adapter()); + res = AllocNode(res, std::move(specifiers)); + AddExportLocalEntryItem(name); + } + return res; +} + +bool Transformer::IsInstantiatedTSModule(const ir::Expression *node) const +{ + auto *var = FindTSModuleVariable(node, Scope()); + if (var == nullptr) { + return true; + } + auto *decl = var->Declaration(); + ASSERT(decl->IsNamespaceDecl()); + auto tsModules = decl->AsNamespaceDecl()->Decls(); + for (auto *it : tsModules) { + if (it->IsInstantiated()) { + return true; + } + } + return false; +} + +binder::Variable *Transformer::FindTSModuleVariable(const ir::Expression *node, binder::Scope *scope) const +{ + if (node == nullptr) { + return nullptr; + } + if (node->IsTSQualifiedName()) { + auto *tsQualifiedName = node->AsTSQualifiedName(); + auto *var = FindTSModuleVariable(tsQualifiedName->Left(), scope); + if (var == nullptr) { + return nullptr; + } + auto *exportTSBindings = var->AsNamespaceVariable()->GetExportBindings(); + auto name = tsQualifiedName->Right()->Name(); + auto *res = exportTSBindings->FindExportTSVariable(name); + if (res != nullptr) { + return res; + } + res = exportTSBindings->FindExportTSVariable(name); + if (res != nullptr) { + auto *node = res->Declaration()->Node(); + return FindTSModuleVariable(node->Parent()->AsTSImportEqualsDeclaration()->ModuleReference(), + res->AsImportEqualsVariable()->GetScope()); + } + return nullptr; + } + ASSERT(node->IsIdentifier()); + auto name = node->AsIdentifier()->Name(); + auto *currentScope = scope; + while (currentScope != nullptr) { + auto *res = currentScope->FindLocalTSVariable(name); + if (res == nullptr && currentScope->IsTSModuleScope()) { + res = currentScope->AsTSModuleScope()->FindExportTSVariable(name); + } + if (res != nullptr) { + return res; + } + res = currentScope->FindLocalTSVariable(name); + if (res == nullptr && currentScope->IsTSModuleScope()) { + res = currentScope->AsTSModuleScope()->FindExportTSVariable(name); + } + if (res != nullptr) { + auto *node = res->Declaration()->Node(); + return FindTSModuleVariable(node->Parent()->AsTSImportEqualsDeclaration()->ModuleReference(), + res->AsImportEqualsVariable()->GetScope()); + } + currentScope = currentScope->Parent(); + } + return nullptr; +} + +std::vector Transformer::VisitExportNamedVariable(ir::Statement *decl) +{ + std::vector res; + if (decl->IsVariableDeclaration()) { + auto declarators = decl->AsVariableDeclaration()->Declarators(); + for (auto *it : declarators) { + if (it->Init()) { + auto *left = std::get(VisitTSNode(it->Id()))->AsExpression(); + auto *right = std::get(VisitTSNode(it->Init()))->AsExpression(); + auto *assignExpr = AllocNode(left, right, + lexer::TokenType::PUNCTUATOR_SUBSTITUTION); + res.push_back(AllocNode(assignExpr)); + } + } + } else if (decl->IsFunctionDeclaration() || decl->IsClassDeclaration()) { + res.push_back(VisitTSNodes(decl)); + auto name = decl->IsFunctionDeclaration() ? + decl->AsFunctionDeclaration()->Function()->Id() : + decl->AsClassDeclaration()->Definition()->Ident(); + ASSERT(name != nullptr); + res.push_back(CreateTsModuleAssignment(name->Name())); + } + return res; +} + +ir::Expression *Transformer::CreateMemberExpressionFromQualified(ir::Expression *node) +{ + if (node->IsTSQualifiedName()) { + auto *tsQualifiedName = node->AsTSQualifiedName(); + auto *left = CreateMemberExpressionFromQualified(tsQualifiedName->Left()); + auto *right = AllocNode(tsQualifiedName->Right()->Name(), Allocator()); + return AllocNode(left, right, + ir::MemberExpression::MemberExpressionKind::PROPERTY_ACCESS, false, false); + } + ASSERT(node->IsIdentifier()); + auto *id = AllocNode(node->AsIdentifier()->Name(), Allocator()); + id->AsIdentifier()->SetReference(); + return id; +} + +void Transformer::SetOriginalNode(ir::UpdateNodes res, ir::AstNode *originalNode) const +{ + if (std::holds_alternative(res)) { + auto *node = std::get(res); + if (node == nullptr || node == originalNode) { + return; + } + node->SetOriginal(originalNode); + node->SetRange(originalNode->Range()); + } else { + auto nodes = std::get>(res); + for (auto *it : nodes) { + it->SetOriginal(originalNode); + it->SetRange(originalNode->Range()); + } + } +} + +ir::ExpressionStatement *Transformer::CreateTsModuleAssignment(util::StringView name) +{ + auto moduleName = GetCurrentTSModuleName(); + auto *id = AllocNode(moduleName, Allocator()); + id->AsIdentifier()->SetReference(); + auto *left = AllocNode(id, AllocNode(name, Allocator()), + ir::MemberExpression::MemberExpressionKind::PROPERTY_ACCESS, false, false); + auto *right = AllocNode(name, Allocator()); + right->AsIdentifier()->SetReference(); + auto *assignExpr = AllocNode(left, right, lexer::TokenType::PUNCTUATOR_SUBSTITUTION); + return AllocNode(assignExpr); +} + +util::StringView Transformer::GetNameFromModuleDeclaration(ir::TSModuleDeclaration *node) const +{ + return node->Name()->AsIdentifier()->Name(); +} + +ir::VariableDeclaration *Transformer::CreateVariableDeclarationWithIdentify(util::StringView name, + VariableParsingFlags flags, + ir::AstNode *node, + bool isExport, + ir::Expression *init) +{ + auto *ident = AllocNode(name, Allocator()); + ident->AsIdentifier()->SetReference(); + auto *declarator = AllocNode(ident, init); + ArenaVector declarators(Allocator()->Adapter()); + declarators.push_back(declarator); + + binder::Decl *decl = nullptr; + binder::DeclarationFlags declflag = isExport ? + binder::DeclarationFlags::EXPORT : + binder::DeclarationFlags::NONE; + auto varKind = ir::VariableDeclaration::VariableDeclarationKind::VAR; + if (flags & VariableParsingFlags::VAR) { + decl = Binder()->AddDecl(node->Start(), declflag, name); + } else if (flags & VariableParsingFlags::LET) { + varKind = ir::VariableDeclaration::VariableDeclarationKind::LET; + decl = Binder()->AddDecl(node->Start(), declflag, name); + } else { + varKind = ir::VariableDeclaration::VariableDeclarationKind::CONST; + decl = Binder()->AddDecl(node->Start(), declflag, name); + } + + auto *declaration = AllocNode(varKind, std::move(declarators), false); + decl->BindNode(declaration); + + return declaration; +} + +util::StringView Transformer::GetParamName(ir::TSModuleDeclaration *node, util::StringView name) const +{ + auto scope = node->Scope(); + if (!scope->HasVariableName(name)) { + return name; + } + + auto pramaName = name; + uint32_t idx = 0; + do { + std::stringstream ss; + ss << name; + idx++; + ss << "_" << std::to_string(idx); + util::UString internalName(ss.str(), Allocator()); + pramaName = internalName.View(); + } while (Binder()->HasVariableName(pramaName)); + Binder()->AddDeclarationName(pramaName); + return pramaName; +} + +ir::CallExpression *Transformer::CreateCallExpressionForTsModule(ir::TSModuleDeclaration *node, + util::StringView name, + bool isExport) +{ + ir::ScriptFunction *funcNode = nullptr; + + binder::FunctionScope *funcScope = node->Scope(); + binder::FunctionParamScope *funcParamScope = funcScope->ParamScope(); + auto paramName = GetParamName(node, name); + { + auto paramScopeCtx = binder::LexicalScope::Enter(Binder(), funcParamScope); + + ArenaVector params(Allocator()->Adapter()); + auto *parameter = AllocNode(paramName, Allocator()); + parameter->AsIdentifier()->SetReference(); + Binder()->AddParamDecl(parameter); + params.push_back(parameter); + + ir::BlockStatement *blockNode = nullptr; + { + auto scopeCtx = binder::LexicalScope::Enter(Binder(), funcScope); + tsModuleList_.push_back({paramName, funcScope}); + if (node->Body()->IsTSModuleDeclaration()) { + auto *tsModule = node->Body()->AsTSModuleDeclaration(); + auto body = std::get>(VisitTsModuleDeclaration(tsModule, true)); + ArenaVector statements(Allocator()->Adapter()); + for (auto *it : body) { + statements.push_back(static_cast(it)); + } + blockNode = AllocNode(funcScope, std::move(statements)); + } else { + auto body = VisitTSNodes(node->Body()); + blockNode = AllocNode(funcScope, + std::move(body->AsTSModuleBlock()->Statements())); + } + tsModuleList_.pop_back(); + funcScope->AddBindsFromParam(); + } + + funcNode = AllocNode(funcScope, std::move(params), nullptr, blockNode, nullptr, + ir::ScriptFunctionFlags::NONE, false); + + funcScope->BindNode(funcNode); + funcParamScope->BindNode(funcNode); + } + + auto *funcExpr = AllocNode(funcNode); + + ArenaVector arguments(Allocator()->Adapter()); + ArenaVector properties(Allocator()->Adapter()); + auto *objectExpression = AllocNode(ir::AstNodeType::OBJECT_EXPRESSION, + std::move(properties), + false); + auto assignExpr = AllocNode(CreateTsModuleParam(name, isExport), + objectExpression, + lexer::TokenType::PUNCTUATOR_SUBSTITUTION); + auto argument = AllocNode(CreateTsModuleParam(name, isExport), + assignExpr, + lexer::TokenType::PUNCTUATOR_LOGICAL_OR); + if (isExport) { + auto *id = AllocNode(name, Allocator()); + id->AsIdentifier()->SetReference(); + arguments.push_back(AllocNode(id, argument, + lexer::TokenType::PUNCTUATOR_SUBSTITUTION)); + } else { + arguments.push_back(argument); + } + + auto *callExpr = AllocNode(funcExpr, std::move(arguments), nullptr, false); + + return callExpr; +} + +ir::Expression *Transformer::CreateTsModuleParam(util::StringView paramName, bool isExport) +{ + if (isExport) { + auto moduleName = GetCurrentTSModuleName(); + auto *id = AllocNode(moduleName, Allocator()); + id->AsIdentifier()->SetReference(); + return AllocNode(id, AllocNode(paramName, Allocator()), + ir::MemberExpression::MemberExpressionKind::PROPERTY_ACCESS, false, false); + } + + auto *id = AllocNode(paramName, Allocator()); + id->AsIdentifier()->SetReference(); + return id; +} + +void Transformer::AddExportLocalEntryItem(util::StringView name) +{ + auto moduleRecord = GetSourceTextModuleRecord(); + auto *entry = moduleRecord->NewEntry(name, name); + [[maybe_unused]] bool res = moduleRecord->AddLocalExportEntry(entry); + ASSERT(res); +} + +ir::UpdateNodes Transformer::VisitTsModuleDeclaration(ir::TSModuleDeclaration *node, bool isExport) +{ + std::vector res; + + util::StringView name = GetNameFromModuleDeclaration(node); + + auto findRes = Scope()->FindLocal(name, binder::ResolveBindingOptions::ALL); + if (findRes == nullptr) { + bool doExport = isExport && !IsTsModule(); + auto flag = VariableParsingFlags::VAR; + if (IsTsModule()) { + flag = VariableParsingFlags::LET; + } + auto *var = CreateVariableDeclarationWithIdentify(name, flag, node, doExport); + if (doExport) { + ArenaVector specifiers(Allocator()->Adapter()); + res.push_back(AllocNode(var, std::move(specifiers))); + AddExportLocalEntryItem(name); + } else { + res.push_back(var); + } + } + + auto *callExpr = CreateCallExpressionForTsModule(node, name, isExport && IsTsModule()); + auto *exprStatementNode = AllocNode(callExpr); + res.push_back(exprStatementNode); + + return res; +} + +} // namespace panda::es2panda::parser diff --git a/es2panda/parser/transformer/transformer.h b/es2panda/parser/transformer/transformer.h new file mode 100644 index 0000000000..4a444d71a1 --- /dev/null +++ b/es2panda/parser/transformer/transformer.h @@ -0,0 +1,134 @@ +/* + * 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. + */ + +#ifndef ES2PANDA_PARSER_TRANSFORMER_TRANSFORMER_H +#define ES2PANDA_PARSER_TRANSFORMER_TRANSFORMER_H + +#include + +#include "binder/binder.h" +#include "binder/scope.h" +#include "ir/astNode.h" +#include "parser/module/sourceTextModuleRecord.h" +#include "parser/parserFlags.h" +#include "parser/program/program.h" + +namespace panda::es2panda::parser { + +struct TsModuleInfo { + util::StringView name; + binder::Scope *scope; +}; + +class Transformer { +public: + explicit Transformer(panda::ArenaAllocator *allocator) + : program_(nullptr), + tsModuleList_(allocator->Adapter()) + { + } + NO_COPY_SEMANTIC(Transformer); + ~Transformer() = default; + + void Transform(Program *program); + +private: + void TransformFromTS(); + ir::AstNode *VisitTSNodes(ir::AstNode *parent); + ir::UpdateNodes VisitTSNode(ir::AstNode *childNode); + ir::UpdateNodes VisitTsModuleDeclaration(ir::TSModuleDeclaration *childNode, bool isExport = false); + std::vector VisitExportNamedVariable(ir::Statement *decl); + ir::AstNode *VisitTsImportEqualsDeclaration(ir::TSImportEqualsDeclaration *node); + ir::VariableDeclaration *CreateVariableDeclarationWithIdentify(util::StringView name, + VariableParsingFlags flags, + ir::AstNode *node, + bool isExport, + ir::Expression *init = nullptr); + ir::CallExpression *CreateCallExpressionForTsModule(ir::TSModuleDeclaration *node, + util::StringView paramName, + bool isExport = false); + ir::Expression *CreateTsModuleParam(util::StringView paramName, bool isExport); + ir::ExpressionStatement *CreateTsModuleAssignment(util::StringView name); + ir::Expression *CreateMemberExpressionFromQualified(ir::Expression *node); + util::StringView GetNameFromModuleDeclaration(ir::TSModuleDeclaration *node) const; + util::StringView GetParamName(ir::TSModuleDeclaration *node, util::StringView name) const; + binder::Scope *FindExportVariableInTsModuleScope(util::StringView name) const; + binder::Variable *FindTSModuleVariable(const ir::Expression *node, binder::Scope *scope) const; + void AddExportLocalEntryItem(util::StringView name); + bool IsInstantiatedTSModule(const ir::Expression *node) const; + void SetOriginalNode(ir::UpdateNodes res, ir::AstNode *originalNode) const; + + bool IsTsModule() const + { + return (tsModuleList_.size() != 0); + } + + template + T *AllocNode(Args &&... args) + { + auto ret = program_->Allocator()->New(std::forward(args)...); + if (ret == nullptr) { + throw Error(ErrorType::GENERIC, "Unsuccessful allocation during parsing"); + } + return ret; + } + + ArenaAllocator *Allocator() const + { + return program_->Allocator(); + } + + binder::Binder *Binder() const + { + return program_->Binder(); + } + + binder::Scope *Scope() const + { + return Binder()->GetScope(); + } + + util::StringView GetCurrentTSModuleName() const + { + return tsModuleList_.back().name; + } + + util::StringView FindTSModuleNameByScope(binder::Scope *scope) const + { + for (auto it : tsModuleList_) { + if (it.scope == scope) { + return it.name; + } + } + UNREACHABLE(); + } + + ScriptExtension Extension() const + { + return program_->Extension(); + } + + SourceTextModuleRecord *GetSourceTextModuleRecord() + { + return program_->ModuleRecord(); + } + + Program *program_; + ArenaVector tsModuleList_; +}; + +} // namespace panda::es2panda::parser + +#endif diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-1-expected.txt b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-1-expected.txt new file mode 100644 index 0000000000..52ad985ced --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-1-expected.txt @@ -0,0 +1 @@ +test-ts-namespace-1 diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-1.ts b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-1.ts new file mode 100644 index 0000000000..c3e63d1c48 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-1.ts @@ -0,0 +1,19 @@ +/* + * 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. + */ + + +namespace ns { + print("test-ts-namespace-1") +} diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-10-expected.txt b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-10-expected.txt new file mode 100644 index 0000000000..fa1afaacc0 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-10-expected.txt @@ -0,0 +1,4 @@ +test-ts-namespace-9 flag1 +test-ts-namespace-9 flag2 +test-ts-namespace-9 flag3 +test-ts-namespace-9 flag4 diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-10.ts b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-10.ts new file mode 100644 index 0000000000..8dfebb53b6 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-10.ts @@ -0,0 +1,40 @@ +/* + * 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. + */ + + +namespace ns.ns2 { + export namespace ns3 { + export class C { + s : string = "test-ts-namespace-9 flag1"; + f() { + print("test-ts-namespace-9 flag2"); + } + } + } + export class C { + s : string = "test-ts-namespace-9 flag3"; + f() { + print("test-ts-namespace-9 flag4"); + } + } +} + +var c : ns.ns2.ns3.C = new ns.ns2.ns3.C(); +print(c.s); +c.f(); + +var d : ns.ns2.C = new ns.ns2.C(); +print(d.s); +d.f(); diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-11-expected.txt b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-11-expected.txt new file mode 100644 index 0000000000..47e54acf1c --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-11-expected.txt @@ -0,0 +1,4 @@ +test-ts-namespace-11 flag2 +test-ts-namespace-11 flag1 +test-ts-namespace-11 flag1 +test-ts-namespace-11 flag1 diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-11.ts b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-11.ts new file mode 100644 index 0000000000..61c0acac5b --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-11.ts @@ -0,0 +1,34 @@ +/* + * 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. + */ + + +namespace ns {} + +class ns { + s : string = "test-ts-namespace-11 flag1"; +} + +var s : string = "test-ts-namespace-11 flag2"; + +namespace ns { + print(s); + export var c = new ns(); + print(c.s) +} + +print(ns.c.s) + +var d = new ns(); +print(d.s); diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-12-expected.txt b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-12-expected.txt new file mode 100644 index 0000000000..12e1d0efdb --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-12-expected.txt @@ -0,0 +1,3 @@ +test-ts-namespace-12 flag3 +test-ts-namespace-12 flag1 +test-ts-namespace-12 flag2 diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-12.ts b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-12.ts new file mode 100644 index 0000000000..0022fd02af --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-12.ts @@ -0,0 +1,31 @@ +/* + * 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. + */ + + +namespace ns {} + +function ns() { + print("test-ts-namespace-12 flag1"); +} + +namespace ns { + export function ns() { + print("test-ts-namespace-12 flag2"); + } + print("test-ts-namespace-12 flag3"); +} + +ns(); +ns.ns(); diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-13-expected.txt b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-13-expected.txt new file mode 100644 index 0000000000..acd467e6ae --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-13-expected.txt @@ -0,0 +1,3 @@ +test-ts-namespace-13 flag1 +test-ts-namespace-13 flag2 +test-ts-namespace-13 flag3 diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-13.ts b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-13.ts new file mode 100644 index 0000000000..ed2269f762 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-13.ts @@ -0,0 +1,33 @@ +/* + * 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. + */ + + +var ns1_1 : string = "test-ts-namespace-13 flag1"; +var ns2_1 : string = "test-ts-namespace-13 flag2"; +var ns3_1 : string = "test-ts-namespace-13 flag3"; + +namespace ns1 { + export namespace ns2{ + export namespace ns3{ + export var ns1 = ns1_1; + export var ns2 = ns2_1; + export var ns3 = ns3_1; + } + } +} + +print(ns1.ns2.ns3.ns1); +print(ns1.ns2.ns3.ns2); +print(ns1.ns2.ns3.ns3); diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-14-expected.txt b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-14-expected.txt new file mode 100644 index 0000000000..e4f92c1865 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-14-expected.txt @@ -0,0 +1,3 @@ +test-ts-namespace-13 flag2 +test-ts-namespace-13 flag3 +test-ts-namespace-13 flag2 diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-14.ts b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-14.ts new file mode 100644 index 0000000000..f377a7c382 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-14.ts @@ -0,0 +1,31 @@ +/* + * 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. + */ + + +var ns2 : string = "test-ts-namespace-13 flag1"; +namespace ns { + namespace ns2 { + export var s : string = "test-ts-namespace-13 flag2"; + function f() { + var ns2 = { + s : "test-ts-namespace-13 flag3" + }; + print(s); + print(ns2.s); + } + f(); + print(ns2.s); + } +} diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-15-expected.txt b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-15-expected.txt new file mode 100644 index 0000000000..8464be06d1 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-15-expected.txt @@ -0,0 +1,2 @@ +test-ts-namespace-15 flag1 +test-ts-namespace-15 flag2 diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-15.ts b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-15.ts new file mode 100644 index 0000000000..0fc35ad791 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-15.ts @@ -0,0 +1,27 @@ +/* + * 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. + */ + + +namespace ns { + export var a : string = "test-ts-namespace-15 flag1"; +} + +print(ns.a); + +namespace ns { + export var a : string = "test-ts-namespace-15 flag2"; +} + +print(ns.a); diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-16-expected.txt b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-16-expected.txt new file mode 100644 index 0000000000..40fd190b00 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-16-expected.txt @@ -0,0 +1 @@ +test-ts-namespace-16 diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-16.ts b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-16.ts new file mode 100644 index 0000000000..9d839295c5 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-16.ts @@ -0,0 +1,32 @@ +/* + * 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 C = ns.ns3.ns4; + +namespace ns { + export namespace ns2 { + export namespace ns4 {} + } + export import ns3 = ns2; + var a = 1; +} + +class C { + a : string = "test-ts-namespace-16"; +} + +var c = new C(); +print(c.a); diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-17-expected.txt b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-17-expected.txt new file mode 100644 index 0000000000..62c9e811e2 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-17-expected.txt @@ -0,0 +1,3 @@ +test-ts-namespace-17 +test-ts-namespace-17 +test-ts-namespace-17 diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-17.ts b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-17.ts new file mode 100644 index 0000000000..5c421937c5 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-17.ts @@ -0,0 +1,29 @@ +/* + * 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. + */ + + +namespace ns { + namespace ns2 { + export var a : string = "test-ts-namespace-17"; + } + export import b = ns2.a; + print(b); +} + +namespace ns { + print(b); +} + +print(ns.b); \ No newline at end of file diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-2-expected.txt b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-2-expected.txt new file mode 100644 index 0000000000..72351bd590 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-2-expected.txt @@ -0,0 +1 @@ +test-ts-namespace-2 diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-2.ts b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-2.ts new file mode 100644 index 0000000000..fd6bdfb3f7 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-2.ts @@ -0,0 +1,21 @@ +/* + * 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. + */ + + +namespace ns.ns2 { + namespace ns3 { + print("test-ts-namespace-2") + } +} diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-3-expected.txt b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-3-expected.txt new file mode 100644 index 0000000000..16127b8180 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-3-expected.txt @@ -0,0 +1 @@ +test-ts-namespace-3 diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-3.ts b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-3.ts new file mode 100644 index 0000000000..4ef471ef67 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-3.ts @@ -0,0 +1,21 @@ +/* + * 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. + */ + + +namespace ns { + export var ns : string = "test-ts-namespace-3"; +} + +print(ns.ns) diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-4-expected.txt b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-4-expected.txt new file mode 100644 index 0000000000..e80ae4c2df --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-4-expected.txt @@ -0,0 +1 @@ +test-ts-namespace-4 diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-4.ts b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-4.ts new file mode 100644 index 0000000000..113b7235a3 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-4.ts @@ -0,0 +1,23 @@ +/* + * 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. + */ + + +namespace ns.ns2 { + export namespace ns3 { + export var ns : string = "test-ts-namespace-4"; + } +} + +print(ns.ns2.ns3.ns) diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-5-expected.txt b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-5-expected.txt new file mode 100644 index 0000000000..2a3ce4dac5 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-5-expected.txt @@ -0,0 +1,3 @@ +test-ts-namespace-5 +test-ts-namespace-5 +test-ts-namespace-5 diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-5.ts b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-5.ts new file mode 100644 index 0000000000..9a904dd796 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-5.ts @@ -0,0 +1,32 @@ +/* + * 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. + */ + + +namespace ns { + namespace ns2 { + export var s : string = "test-ts-namespace-5"; + } + export import ns = ns2.s; +} + +namespace ns { + print(ns) +} + +import ns3 = ns; +print(ns3.ns) + +import s = ns.ns; +print(s) diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-6-expected.txt b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-6-expected.txt new file mode 100644 index 0000000000..02948d5e0c --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-6-expected.txt @@ -0,0 +1 @@ +test-ts-namespace-6 diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-6.ts b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-6.ts new file mode 100644 index 0000000000..79142da301 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-6.ts @@ -0,0 +1,23 @@ +/* + * 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. + */ + + +namespace ns { + export var ns : string = "test-ts-namespace-6"; +} + +namespace ns { + print(ns); +} diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-7-expected.txt b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-7-expected.txt new file mode 100644 index 0000000000..0bb6191a18 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-7-expected.txt @@ -0,0 +1,3 @@ +test-ts-namespace-7 flag1 +test-ts-namespace-7 flag2 +test-ts-namespace-7 flag3 diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-7.ts b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-7.ts new file mode 100644 index 0000000000..c46ef2ed3c --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-7.ts @@ -0,0 +1,49 @@ +/* + * 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. + */ + + +namespace ns.ns2 { + export namespace ns3{ + export var s : string = "test-ts-namespace-7 flag1"; + } +} + +var s : string = "test-ts-namespace-7 flag2"; +namespace ns.ns2 { + export namespace ns3{ + export namespace ns4{ + print(s); + } + } +} + +namespace ns.ns2 { + namespace ns3 { + export namespace ns4 { + print(s); + } + } +} + +namespace ns.ns2 { + namespace ns3 { + export var s : string = "test-ts-namespace-7 flag3"; + } + namespace ns3 { + export namespace ns4 { + print(s) + } + } +} diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-8-expected.txt b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-8-expected.txt new file mode 100644 index 0000000000..285fd0a25b --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-8-expected.txt @@ -0,0 +1 @@ +test-ts-namespace-8 diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-8.ts b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-8.ts new file mode 100644 index 0000000000..00a411759b --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-8.ts @@ -0,0 +1,23 @@ +/* + * 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. + */ + + +namespace ns.ns2 { + export var ns2 : string = "test-ts-namespace-8"; +} + +namespace ns.ns2.ns3 { + print(ns2); +} diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-9-expected.txt b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-9-expected.txt new file mode 100644 index 0000000000..549855f097 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-9-expected.txt @@ -0,0 +1,2 @@ +test-ts-namespace-9 flag1 +test-ts-namespace-9 flag2 diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-9.ts b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-9.ts new file mode 100644 index 0000000000..3e2eb228e1 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-namespace-9.ts @@ -0,0 +1,29 @@ +/* + * 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. + */ + + +namespace ns.ns2 { + export namespace ns3 { + export function f() { + print("test-ts-namespace-9 flag1"); + } + } + export function f() { + print("test-ts-namespace-9 flag2"); + } +} + +ns.ns2.ns3.f(); +ns.ns2.f(); diff --git a/es2panda/test/test_tsc_ignore_list.txt b/es2panda/test/test_tsc_ignore_list.txt index 4d79e018a1..716ca0e026 100644 --- a/es2panda/test/test_tsc_ignore_list.txt +++ b/es2panda/test/test_tsc_ignore_list.txt @@ -1,182 +1,125 @@ -es2panda/test/TypeScript/tests/cases/conformance/functions/functionWithUseStrictAndSimpleParameterList.ts -es2panda/test/TypeScript/tests/cases/conformance/externalModules/es6/es6modulekindWithES5Target12.ts -es2panda/test/TypeScript/tests/cases/conformance/externalModules/esnext/esnextmodulekindWithES5Target12.ts -es2panda/test/TypeScript/tests/cases/conformance/expressions/propertyAccess/propertyAccessNumericLiterals.ts -es2panda/test/TypeScript/tests/cases/conformance/expressions/typeGuards/typePredicateASI.ts -es2panda/test/TypeScript/tests/cases/conformance/expressions/typeGuards/typeGuardFunctionOfFormThis.ts -es2panda/test/TypeScript/tests/cases/conformance/expressions/nullishCoalescingOperator/nullishCoalescingOperator_es2020.ts -es2panda/test/TypeScript/tests/cases/conformance/expressions/elementAccess/letIdentifierInElementAccess01.ts -es2panda/test/TypeScript/tests/cases/conformance/internalModules/DeclarationMerging/ClassAndModuleThatMergeWithStaticVariableAndNonExportedVarThatShareAName.ts -es2panda/test/TypeScript/tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface04.ts -es2panda/test/TypeScript/tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface01.ts -es2panda/test/TypeScript/tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface03.ts +es2panda/test/TypeScript/tests/cases/compiler/ambientClassOverloadForFunction.ts +es2panda/test/TypeScript/tests/cases/compiler/arrowFunctionWithObjectLiteralBody5.ts +es2panda/test/TypeScript/tests/cases/compiler/arrowFunctionWithObjectLiteralBody6.ts +es2panda/test/TypeScript/tests/cases/compiler/assertionFunctionsCanNarrowByDiscriminant.ts +es2panda/test/TypeScript/tests/cases/compiler/bom-utf16be.ts +es2panda/test/TypeScript/tests/cases/compiler/castOfAwait.ts +es2panda/test/TypeScript/tests/cases/compiler/castTest.ts +es2panda/test/TypeScript/tests/cases/compiler/classFunctionMerging.ts +es2panda/test/TypeScript/tests/cases/compiler/collisionArgumentsInType.ts +es2panda/test/TypeScript/tests/cases/compiler/collisionArgumentsInterfaceMembers.ts +es2panda/test/TypeScript/tests/cases/compiler/computedPropertiesTransformedInOtherwiseNonTSClasses.ts +es2panda/test/TypeScript/tests/cases/compiler/constructorOverloads5.ts +es2panda/test/TypeScript/tests/cases/compiler/continueTarget3.ts +es2panda/test/TypeScript/tests/cases/compiler/controlFlowCaching.ts +es2panda/test/TypeScript/tests/cases/compiler/controlFlowManyCallExpressionStatementsPerf.ts +es2panda/test/TypeScript/tests/cases/compiler/declarationEmitDestructuringOptionalBindingParametersInOverloads.ts +es2panda/test/TypeScript/tests/cases/compiler/declareIdentifierAsBeginningOfStatementExpression01.ts +es2panda/test/TypeScript/tests/cases/compiler/discriminantsAndPrimitives.ts +es2panda/test/TypeScript/tests/cases/compiler/elidedEmbeddedStatementsReplacedWithSemicolon.ts +es2panda/test/TypeScript/tests/cases/compiler/emitBundleWithShebang1.ts +es2panda/test/TypeScript/tests/cases/compiler/emitDecoratorMetadata_restArgs.ts +es2panda/test/TypeScript/tests/cases/compiler/exportAsNamespace.d.ts +es2panda/test/TypeScript/tests/cases/compiler/exportDeclarationsInAmbientNamespaces.ts +es2panda/test/TypeScript/tests/cases/compiler/exportEqualsOfModule.ts +es2panda/test/TypeScript/tests/cases/compiler/exportRedeclarationTypeAliases.ts +es2panda/test/TypeScript/tests/cases/compiler/exportSpecifierAndExportedMemberDeclaration.ts +es2panda/test/TypeScript/tests/cases/compiler/fileWithNextLine2.ts +es2panda/test/TypeScript/tests/cases/compiler/genericRecursiveImplicitConstructorErrors2.ts +es2panda/test/TypeScript/tests/cases/compiler/getterSetterNonAccessor.ts +es2panda/test/TypeScript/tests/cases/compiler/globalIsContextualKeyword.ts +es2panda/test/TypeScript/tests/cases/compiler/implementsInClassExpression.ts +es2panda/test/TypeScript/tests/cases/compiler/inferenceErasedSignatures.ts +es2panda/test/TypeScript/tests/cases/compiler/isLiteral1.ts +es2panda/test/TypeScript/tests/cases/compiler/isLiteral2.ts +es2panda/test/TypeScript/tests/cases/compiler/letAsIdentifier2.ts +es2panda/test/TypeScript/tests/cases/compiler/letInVarDeclOfForIn_ES5.ts +es2panda/test/TypeScript/tests/cases/compiler/letInVarDeclOfForIn_ES6.ts +es2panda/test/TypeScript/tests/cases/compiler/letInVarDeclOfForOf_ES5.ts +es2panda/test/TypeScript/tests/cases/compiler/letInVarDeclOfForOf_ES6.ts +es2panda/test/TypeScript/tests/cases/compiler/mutuallyRecursiveInterfaceDeclaration.ts +es2panda/test/TypeScript/tests/cases/compiler/objectLitGetterSetter.ts +es2panda/test/TypeScript/tests/cases/compiler/overloadResolutionOverNonCTObjectLit.ts +es2panda/test/TypeScript/tests/cases/compiler/overloadedConstructorFixesInferencesAppropriately.ts +es2panda/test/TypeScript/tests/cases/compiler/parameterInitializerBeforeDestructuringEmit.ts +es2panda/test/TypeScript/tests/cases/compiler/parseArrowFunctionWithFunctionReturnType.ts +es2panda/test/TypeScript/tests/cases/compiler/parseEntityNameWithReservedWord.ts +es2panda/test/TypeScript/tests/cases/compiler/shebang.ts +es2panda/test/TypeScript/tests/cases/compiler/sigantureIsSubTypeIfTheyAreIdentical.ts +es2panda/test/TypeScript/tests/cases/compiler/sourceMap-LineBreaks.ts +es2panda/test/TypeScript/tests/cases/compiler/sourceMapValidationDecorators.ts +es2panda/test/TypeScript/tests/cases/compiler/sourceMapValidationDestructuringForArrayBindingPattern2.ts +es2panda/test/TypeScript/tests/cases/compiler/sourceMapValidationDestructuringForArrayBindingPatternDefaultValues2.ts +es2panda/test/TypeScript/tests/cases/compiler/sourceMapValidationDestructuringForObjectBindingPattern2.ts +es2panda/test/TypeScript/tests/cases/compiler/sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2.ts +es2panda/test/TypeScript/tests/cases/compiler/systemNamespaceAliasEmit.ts +es2panda/test/TypeScript/tests/cases/compiler/taggedTemplateStringWithSymbolExpression01.ts +es2panda/test/TypeScript/tests/cases/compiler/unusedLocalsAndParametersOverloadSignatures.ts +es2panda/test/TypeScript/tests/cases/compiler/withStatementInternalComments.ts +es2panda/test/TypeScript/tests/cases/conformance/async/es2017/asyncAwait_es2017.ts +es2panda/test/TypeScript/tests/cases/conformance/async/es5/asyncAwait_es5.ts +es2panda/test/TypeScript/tests/cases/conformance/async/es6/asyncAwait_es6.ts +es2panda/test/TypeScript/tests/cases/conformance/async/es6/asyncWithVarShadowing_es6.ts es2panda/test/TypeScript/tests/cases/conformance/classes/members/privateNames/privateNameComputedPropertyName1.ts -es2panda/test/TypeScript/tests/cases/conformance/internalModules/DeclarationMerging/ClassAndModuleThatMergeWithStaticFunctionAndNonExportedFunctionThatShareAName.ts -es2panda/test/TypeScript/tests/cases/conformance/internalModules/importDeclarations/importAliasIdentifiers.ts -es2panda/test/TypeScript/tests/cases/conformance/internalModules/importDeclarations/exportImportAlias.ts -es2panda/test/TypeScript/tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace04.ts -es2panda/test/TypeScript/tests/cases/conformance/internalModules/moduleDeclarations/nonInstantiatedModule.ts -es2panda/test/TypeScript/tests/cases/conformance/classes/classDeclarations/mergeClassInterfaceAndModule.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments03_ES6.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments04_ES6.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments05_ES6.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments06_ES6.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments07_ES6.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments08.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments08_ES6.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments11_ES6.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments13.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments13_ES6.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments14_ES6.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments15_ES6.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments16_ES6.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments17_ES6.ts es2panda/test/TypeScript/tests/cases/conformance/es6/destructuring/declarationInAmbientContext.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/for-ofStatements/for-of53.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/for-ofStatements/for-of56.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration11_es6.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration2_es6.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration4_es6.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/modules/defaultExportWithOverloads01.ts es2panda/test/TypeScript/tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagNamedDeclare.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTagsES6.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagNamedDeclareES6.ts es2panda/test/TypeScript/tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTags.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/templates/taggedTemplateStringsWithTypedTagsES6.ts es2panda/test/TypeScript/tests/cases/conformance/es6/templates/templateStringControlCharacterEscapes01.ts es2panda/test/TypeScript/tests/cases/conformance/es6/templates/templateStringControlCharacterEscapes01_ES6.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/templates/taggedTemplateStringsWithTagNamedDeclareES6.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration2_es6.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration4_es6.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration11_es6.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/for-ofStatements/for-of53.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/for-ofStatements/for-of56.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/unicodeExtendedEscapes/unicodeExtendedEscapesInRegularExpressions14_ES5.ts es2panda/test/TypeScript/tests/cases/conformance/es6/unicodeExtendedEscapes/unicodeExtendedEscapesInRegularExpressions07_ES5.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/unicodeExtendedEscapes/unicodeExtendedEscapesInRegularExpressions07_ES6.ts es2panda/test/TypeScript/tests/cases/conformance/es6/unicodeExtendedEscapes/unicodeExtendedEscapesInRegularExpressions12_ES5.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/unicodeExtendedEscapes/unicodeExtendedEscapesInRegularExpressions17_ES6.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/unicodeExtendedEscapes/unicodeExtendedEscapesInRegularExpressions19_ES6.ts es2panda/test/TypeScript/tests/cases/conformance/es6/unicodeExtendedEscapes/unicodeExtendedEscapesInRegularExpressions12_ES6.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/unicodeExtendedEscapes/unicodeExtendedEscapesInRegularExpressions14_ES5.ts es2panda/test/TypeScript/tests/cases/conformance/es6/unicodeExtendedEscapes/unicodeExtendedEscapesInRegularExpressions14_ES6.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/unicodeExtendedEscapes/unicodeExtendedEscapesInRegularExpressions07_ES6.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/unicodeExtendedEscapes/unicodeExtendedEscapesInRegularExpressions19_ES5.ts es2panda/test/TypeScript/tests/cases/conformance/es6/unicodeExtendedEscapes/unicodeExtendedEscapesInRegularExpressions17_ES5.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/unicodeExtendedEscapes/unicodeExtendedEscapesInRegularExpressions17_ES6.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/unicodeExtendedEscapes/unicodeExtendedEscapesInRegularExpressions19_ES5.ts +es2panda/test/TypeScript/tests/cases/conformance/es6/unicodeExtendedEscapes/unicodeExtendedEscapesInRegularExpressions19_ES6.ts es2panda/test/TypeScript/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck38.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments14_ES6.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments08.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments17_ES6.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments08_ES6.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments04_ES6.ts -es2panda/test/TypeScript/tests/cases/conformance/scanner/ecmascript3/scannerES3NumericLiteral2.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/modules/defaultExportWithOverloads01.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments13_ES6.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments03_ES6.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments16_ES6.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments05_ES6.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments13.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments11_ES6.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments06_ES6.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments07_ES6.ts -es2panda/test/TypeScript/tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments15_ES6.ts -es2panda/test/TypeScript/tests/cases/conformance/async/es6/asyncAwait_es6.ts -es2panda/test/TypeScript/tests/cases/conformance/async/es6/asyncWithVarShadowing_es6.ts -es2panda/test/TypeScript/tests/cases/conformance/async/es5/asyncAwait_es5.ts -es2panda/test/TypeScript/tests/cases/conformance/async/es2017/asyncAwait_es2017.ts -es2panda/test/TypeScript/tests/cases/conformance/types/typeParameters/typeArgumentLists/constraintSatisfactionWithEmptyObject.ts -es2panda/test/TypeScript/tests/cases/conformance/types/tuple/named/namedTupleMembers.ts -es2panda/test/TypeScript/tests/cases/conformance/types/uniqueSymbol/uniqueSymbols.ts -es2panda/test/TypeScript/tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsDeclarations.ts -es2panda/test/TypeScript/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/nullIsSubtypeOfEverythingButUndefined.ts -es2panda/test/TypeScript/tests/cases/conformance/types/typeRelationships/assignmentCompatibility/anyAssignableToEveryType2.ts -es2panda/test/TypeScript/tests/cases/conformance/types/typeRelationships/bestCommonType/heterogeneousArrayLiterals.ts -es2panda/test/TypeScript/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/undefinedIsSubtypeOfEverything.ts -es2panda/test/TypeScript/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfAny.ts -es2panda/test/TypeScript/tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints2.ts -es2panda/test/TypeScript/tests/cases/conformance/types/typeRelationships/assignmentCompatibility/anyAssignabilityInInheritance.ts -es2panda/test/TypeScript/tests/cases/conformance/types/stringLiteral/stringLiteralTypesAndParenthesizedExpressions01.ts -es2panda/test/TypeScript/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts -es2panda/test/TypeScript/tests/cases/conformance/types/import/importTypeAmbient.ts -es2panda/test/TypeScript/tests/cases/conformance/types/specifyingTypes/typeQueries/typeQueryWithReservedWords.ts -es2panda/test/TypeScript/tests/cases/conformance/types/members/objectTypeWithStringNamedNumericProperty.ts -es2panda/test/TypeScript/tests/cases/conformance/types/objectTypeLiteral/callSignatures/callSignatureWithoutReturnTypeAnnotationInference.ts -es2panda/test/TypeScript/tests/cases/conformance/types/literal/literalTypesAndDestructuring.ts -es2panda/test/TypeScript/tests/cases/conformance/parser/ecmascript5/parserUnicodeWhitespaceCharacter1.ts +es2panda/test/TypeScript/tests/cases/conformance/expressions/elementAccess/letIdentifierInElementAccess01.ts +es2panda/test/TypeScript/tests/cases/conformance/expressions/nullishCoalescingOperator/nullishCoalescingOperator_es2020.ts +es2panda/test/TypeScript/tests/cases/conformance/expressions/propertyAccess/propertyAccessNumericLiterals.ts +es2panda/test/TypeScript/tests/cases/conformance/expressions/typeGuards/typeGuardFunctionOfFormThis.ts +es2panda/test/TypeScript/tests/cases/conformance/expressions/typeGuards/typePredicateASI.ts +es2panda/test/TypeScript/tests/cases/conformance/functions/functionWithUseStrictAndSimpleParameterList.ts +es2panda/test/TypeScript/tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface01.ts +es2panda/test/TypeScript/tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface03.ts +es2panda/test/TypeScript/tests/cases/conformance/interfaces/interfaceDeclarations/asiPreventsParsingAsInterface04.ts +es2panda/test/TypeScript/tests/cases/conformance/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace04.ts es2panda/test/TypeScript/tests/cases/conformance/parser/ecmascript5/ArrowFunctionExpressions/parserArrowFunctionExpression6.ts es2panda/test/TypeScript/tests/cases/conformance/parser/ecmascript5/RegressionTests/parser579071.ts es2panda/test/TypeScript/tests/cases/conformance/parser/ecmascript5/Statements/ContinueStatements/parser_continueTarget3.ts -es2panda/test/TypeScript/tests/cases/compiler/multiModuleClodule1.ts -es2panda/test/TypeScript/tests/cases/compiler/discriminantsAndPrimitives.ts -es2panda/test/TypeScript/tests/cases/compiler/circularTypeofWithFunctionModule.ts -es2panda/test/TypeScript/tests/cases/compiler/collisionArgumentsInType.ts -es2panda/test/TypeScript/tests/cases/compiler/sourceMapValidationDestructuringForArrayBindingPattern2.ts -es2panda/test/TypeScript/tests/cases/compiler/ambientClassOverloadForFunction.ts -es2panda/test/TypeScript/tests/cases/compiler/doubleUnderscoreEnumEmit.ts -es2panda/test/TypeScript/tests/cases/compiler/parseArrowFunctionWithFunctionReturnType.ts -es2panda/test/TypeScript/tests/cases/compiler/augmentedTypesModules3b.ts -es2panda/test/TypeScript/tests/cases/compiler/computedPropertiesTransformedInOtherwiseNonTSClasses.ts -es2panda/test/TypeScript/tests/cases/compiler/castTest.ts -es2panda/test/TypeScript/tests/cases/compiler/constructorOverloads5.ts -es2panda/test/TypeScript/tests/cases/compiler/parameterInitializerBeforeDestructuringEmit.ts -es2panda/test/TypeScript/tests/cases/compiler/classDeclarationMergedInModuleWithContinuation.ts -es2panda/test/TypeScript/tests/cases/compiler/exportEqualsOfModule.ts -es2panda/test/TypeScript/tests/cases/compiler/arrowFunctionWithObjectLiteralBody6.ts -es2panda/test/TypeScript/tests/cases/compiler/getterSetterNonAccessor.ts -es2panda/test/TypeScript/tests/cases/compiler/systemNamespaceAliasEmit.ts -es2panda/test/TypeScript/tests/cases/compiler/sourceMapValidationDestructuringForObjectBindingPattern2.ts -es2panda/test/TypeScript/tests/cases/compiler/resolveModuleNameWithSameLetDeclarationName1.ts -es2panda/test/TypeScript/tests/cases/compiler/partiallyAmbientFundule.ts -es2panda/test/TypeScript/tests/cases/compiler/internalImportInstantiatedModuleMergedWithClassNotReferencingInstanceNoConflict.ts -es2panda/test/TypeScript/tests/cases/compiler/collisionArgumentsInterfaceMembers.ts -es2panda/test/TypeScript/tests/cases/compiler/sourceMapValidationDestructuringForObjectBindingPatternDefaultValues2.ts -es2panda/test/TypeScript/tests/cases/compiler/es5ExportEqualsDts.ts -es2panda/test/TypeScript/tests/cases/compiler/parseEntityNameWithReservedWord.ts -es2panda/test/TypeScript/tests/cases/compiler/exportDeclarationsInAmbientNamespaces.ts -es2panda/test/TypeScript/tests/cases/compiler/castOfAwait.ts -es2panda/test/TypeScript/tests/cases/compiler/objectLitGetterSetter.ts -es2panda/test/TypeScript/tests/cases/compiler/continueTarget3.ts -es2panda/test/TypeScript/tests/cases/compiler/letInVarDeclOfForIn_ES6.ts -es2panda/test/TypeScript/tests/cases/compiler/functionMergedWithModule.ts -es2panda/test/TypeScript/tests/cases/compiler/internalImportUnInstantiatedModuleMergedWithClassNotReferencingInstanceNoConflict.ts -es2panda/test/TypeScript/tests/cases/compiler/controlFlowManyCallExpressionStatementsPerf.ts -es2panda/test/TypeScript/tests/cases/compiler/declareIdentifierAsBeginningOfStatementExpression01.ts -es2panda/test/TypeScript/tests/cases/compiler/declarationEmitLocalClassHasRequiredDeclare.ts -es2panda/test/TypeScript/tests/cases/compiler/isLiteral2.ts -es2panda/test/TypeScript/tests/cases/compiler/exportImportAndClodule.ts -es2panda/test/TypeScript/tests/cases/compiler/genericCloduleInModule.ts -es2panda/test/TypeScript/tests/cases/compiler/shebang.ts -es2panda/test/TypeScript/tests/cases/compiler/arrowFunctionWithObjectLiteralBody5.ts -es2panda/test/TypeScript/tests/cases/compiler/partiallyAmbientClodule.ts -es2panda/test/TypeScript/tests/cases/compiler/overloadResolutionOverNonCTObjectLit.ts -es2panda/test/TypeScript/tests/cases/compiler/controlFlowCaching.ts -es2panda/test/TypeScript/tests/cases/compiler/overloadedConstructorFixesInferencesAppropriately.ts -es2panda/test/TypeScript/tests/cases/compiler/multiModuleFundule1.ts -es2panda/test/TypeScript/tests/cases/compiler/systemModuleDeclarationMerging.ts -es2panda/test/TypeScript/tests/cases/compiler/bom-utf16be.ts -es2panda/test/TypeScript/tests/cases/compiler/isLiteral1.ts -es2panda/test/TypeScript/tests/cases/compiler/sourceMapValidationDecorators.ts -es2panda/test/TypeScript/tests/cases/compiler/cloduleGenericOnSelfMember.ts -es2panda/test/TypeScript/tests/cases/compiler/unusedLocalsAndParametersOverloadSignatures.ts -es2panda/test/TypeScript/tests/cases/compiler/noCircularDefinitionOnExportOfPrivateInMergedNamespace.ts -es2panda/test/TypeScript/tests/cases/compiler/inferenceErasedSignatures.ts -es2panda/test/TypeScript/tests/cases/compiler/exportSpecifierAndExportedMemberDeclaration.ts -es2panda/test/TypeScript/tests/cases/compiler/elidedEmbeddedStatementsReplacedWithSemicolon.ts -es2panda/test/TypeScript/tests/cases/compiler/letInVarDeclOfForOf_ES5.ts -es2panda/test/TypeScript/tests/cases/compiler/declarationEmitDestructuringOptionalBindingParametersInOverloads.ts -es2panda/test/TypeScript/tests/cases/compiler/moduleRedifinitionErrors.ts -es2panda/test/TypeScript/tests/cases/compiler/globalIsContextualKeyword.ts -es2panda/test/TypeScript/tests/cases/compiler/exportRedeclarationTypeAliases.ts -es2panda/test/TypeScript/tests/cases/compiler/letAsIdentifier2.ts -es2panda/test/TypeScript/tests/cases/compiler/fileWithNextLine2.ts -es2panda/test/TypeScript/tests/cases/compiler/mutuallyRecursiveInterfaceDeclaration.ts -es2panda/test/TypeScript/tests/cases/compiler/funduleOfFunctionWithoutReturnTypeAnnotation.ts -es2panda/test/TypeScript/tests/cases/compiler/implementsInClassExpression.ts -es2panda/test/TypeScript/tests/cases/compiler/funduleExportedClassIsUsedBeforeDeclaration.ts -es2panda/test/TypeScript/tests/cases/compiler/genericOfACloduleType2.ts -es2panda/test/TypeScript/tests/cases/compiler/genericOfACloduleType1.ts -es2panda/test/TypeScript/tests/cases/compiler/mixingFunctionAndAmbientModule1.ts -es2panda/test/TypeScript/tests/cases/compiler/cloduleWithPriorUninstantiatedModule.ts -es2panda/test/TypeScript/tests/cases/compiler/emitDecoratorMetadata_restArgs.ts -es2panda/test/TypeScript/tests/cases/compiler/sourceMapValidationDestructuringForArrayBindingPatternDefaultValues2.ts -es2panda/test/TypeScript/tests/cases/compiler/augmentedTypesClass3.ts -es2panda/test/TypeScript/tests/cases/compiler/cloduleTest1.ts -es2panda/test/TypeScript/tests/cases/compiler/taggedTemplateStringWithSymbolExpression01.ts -es2panda/test/TypeScript/tests/cases/compiler/cloduleAndTypeParameters.ts -es2panda/test/TypeScript/tests/cases/compiler/privacyCheckExportAssignmentOnExportedGenericInterface2.ts -es2panda/test/TypeScript/tests/cases/compiler/exportAsNamespace.d.ts -es2panda/test/TypeScript/tests/cases/compiler/letInVarDeclOfForOf_ES6.ts -es2panda/test/TypeScript/tests/cases/compiler/emitBundleWithShebang1.ts -es2panda/test/TypeScript/tests/cases/compiler/recursiveCloduleReference.ts -es2panda/test/TypeScript/tests/cases/compiler/letInVarDeclOfForIn_ES5.ts -es2panda/test/TypeScript/tests/cases/compiler/mergedDeclarations1.ts -es2panda/test/TypeScript/tests/cases/compiler/augmentedTypesExternalModule1.ts -es2panda/test/TypeScript/tests/cases/compiler/sigantureIsSubTypeIfTheyAreIdentical.ts -es2panda/test/TypeScript/tests/cases/compiler/assertionFunctionsCanNarrowByDiscriminant.ts -es2panda/test/TypeScript/tests/cases/compiler/withStatementInternalComments.ts -es2panda/test/TypeScript/tests/cases/compiler/genericRecursiveImplicitConstructorErrors2.ts -es2panda/test/TypeScript/tests/cases/compiler/cloduleWithRecursiveReference.ts -es2panda/test/TypeScript/tests/cases/compiler/sourceMap-LineBreaks.ts -es2panda/test/TypeScript/tests/cases/compiler/declareExternalModuleWithExportAssignedFundule.ts -es2panda/test/TypeScript/tests/cases/compiler/classFunctionMerging.ts -es2panda/test/TypeScript/tests/cases/compiler/es5ExportDefaultFunctionDeclaration4.ts -es2panda/test/TypeScript/tests/cases/compiler/typeAliasExport.ts -es2panda/test/TypeScript/tests/cases/compiler/es5ExportDefaultClassDeclaration4.ts -es2panda/test/TypeScript/tests/cases/compiler/exportDefaultVariable.ts -es2panda/test/TypeScript/tests/cases/compiler/declarationEmitModuleWithScopeMarker.ts \ No newline at end of file +es2panda/test/TypeScript/tests/cases/conformance/parser/ecmascript5/parserUnicodeWhitespaceCharacter1.ts +es2panda/test/TypeScript/tests/cases/conformance/scanner/ecmascript3/scannerES3NumericLiteral2.ts +es2panda/test/TypeScript/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts +es2panda/test/TypeScript/tests/cases/conformance/types/literal/literalTypesAndDestructuring.ts +es2panda/test/TypeScript/tests/cases/conformance/types/members/objectTypeWithStringNamedNumericProperty.ts +es2panda/test/TypeScript/tests/cases/conformance/types/specifyingTypes/typeQueries/typeQueryWithReservedWords.ts +es2panda/test/TypeScript/tests/cases/conformance/types/stringLiteral/stringLiteralTypesAndParenthesizedExpressions01.ts +es2panda/test/TypeScript/tests/cases/conformance/types/tuple/named/namedTupleMembers.ts +es2panda/test/TypeScript/tests/cases/conformance/types/typeParameters/typeArgumentLists/constraintSatisfactionWithEmptyObject.ts +es2panda/test/TypeScript/tests/cases/conformance/types/uniqueSymbol/uniqueSymbols.ts +es2panda/test/TypeScript/tests/cases/conformance/types/uniqueSymbol/uniqueSymbolsDeclarations.ts \ No newline at end of file -- Gitee