From 55d7f72f7abab48ef8ba78e9748fb1465dc6fbc3 Mon Sep 17 00:00:00 2001 From: xucheng46 Date: Wed, 19 Oct 2022 19:54:48 +0800 Subject: [PATCH] Fix the index signature problem in interface Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I5WN1P Test: parser tests, compiler tests, test262 Signed-off-by: xucheng46 Change-Id: I7df96938d41b4ae42bef6476167b0fde41ec211f --- es2panda/parser/parserImpl.cpp | 3 + .../parser/ts/test-interface5-expected.txt | 186 ++++++++++++++++++ es2panda/test/parser/ts/test-interface5.ts | 21 ++ es2panda/test/test_tsc_ignore_list.txt | 2 - 4 files changed, 210 insertions(+), 2 deletions(-) create mode 100644 es2panda/test/parser/ts/test-interface5-expected.txt create mode 100644 es2panda/test/parser/ts/test-interface5.ts diff --git a/es2panda/parser/parserImpl.cpp b/es2panda/parser/parserImpl.cpp index 728a446cf4..445dc85b39 100644 --- a/es2panda/parser/parserImpl.cpp +++ b/es2panda/parser/parserImpl.cpp @@ -476,6 +476,9 @@ ir::Expression *ParserImpl::ParseTsTypeAnnotationElement(ir::Expression *typeAnn } case lexer::TokenType::PUNCTUATOR_LEFT_SQUARE_BRACKET: { if (typeAnnotation) { + if (lexer_->GetToken().NewLine()) { + break; + } if (lexer_->Lookahead() == LEX_CHAR_RIGHT_SQUARE) { return ParseTsArrayType(typeAnnotation); } diff --git a/es2panda/test/parser/ts/test-interface5-expected.txt b/es2panda/test/parser/ts/test-interface5-expected.txt new file mode 100644 index 0000000000..f587b688cf --- /dev/null +++ b/es2panda/test/parser/ts/test-interface5-expected.txt @@ -0,0 +1,186 @@ +{ + "type": "Program", + "statements": [ + { + "type": "TSInterfaceDeclaration", + "body": { + "type": "TSInterfaceBody", + "body": [ + { + "type": "TSPropertySignature", + "computed": false, + "optional": false, + "readonly": false, + "key": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 6 + } + } + }, + "typeAnnotation": { + "type": "TSUnionType", + "types": [ + { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 15 + } + } + }, + { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 19, + "column": 11 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 20, + "column": 6 + } + } + }, + { + "type": "TSIndexSignature", + "parameters": { + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 20, + "column": 10 + }, + "end": { + "line": 20, + "column": 16 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 6 + }, + "end": { + "line": 20, + "column": 7 + } + } + }, + "typeAnnotation": { + "type": "TSStringKeyword", + "loc": { + "start": { + "line": 20, + "column": 20 + }, + "end": { + "line": 20, + "column": 26 + } + } + }, + "readonly": false, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 27 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 13 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "id": { + "type": "Identifier", + "name": "I", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 12 + } + } + }, + "extends": [], + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 21, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 22, + "column": 1 + } + } +} diff --git a/es2panda/test/parser/ts/test-interface5.ts b/es2panda/test/parser/ts/test-interface5.ts new file mode 100644 index 0000000000..83d31f7870 --- /dev/null +++ b/es2panda/test/parser/ts/test-interface5.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. + */ + + +interface I { + a : string | + number + [b : number] : string; +} diff --git a/es2panda/test/test_tsc_ignore_list.txt b/es2panda/test/test_tsc_ignore_list.txt index 4aff71e039..2aaabed9fc 100644 --- a/es2panda/test/test_tsc_ignore_list.txt +++ b/es2panda/test/test_tsc_ignore_list.txt @@ -56,8 +56,6 @@ es2panda/test/TypeScript/tests/cases/conformance/es6/functionDeclarations/Functi 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/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/unicodeExtendedEscapes/unicodeExtendedEscapesInRegularExpressions07_ES5.ts -- Gitee