diff --git a/es2panda/parser/parserImpl.cpp b/es2panda/parser/parserImpl.cpp index dd1b69eb3375549d650bf4843fb3a2e47c90af12..f494e9339b4523e1079be4a397c5f32b4f5e5f02 100644 --- a/es2panda/parser/parserImpl.cpp +++ b/es2panda/parser/parserImpl.cpp @@ -327,7 +327,7 @@ bool ParserImpl::IsStartOfTsTypePredicate() const lexer_->NextToken(); - bool result = lexer_->GetToken().KeywordType() == lexer::TokenType::KEYW_IS; + bool result = !lexer_->GetToken().NewLine() && (lexer_->GetToken().KeywordType() == lexer::TokenType::KEYW_IS); lexer_->Rewind(pos); return result; } diff --git a/es2panda/test/parser/ts/test-interface4-expected.txt b/es2panda/test/parser/ts/test-interface4-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..034c73421b279598c1ff48b6edf01f6025677994 --- /dev/null +++ b/es2panda/test/parser/ts/test-interface4-expected.txt @@ -0,0 +1,204 @@ +{ + "type": "Program", + "statements": [ + { + "type": "TSInterfaceDeclaration", + "body": { + "type": "TSInterfaceBody", + "body": [ + { + "type": "TSMethodSignature", + "computed": false, + "optional": false, + "key": { + "type": "Identifier", + "name": "func", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 9 + } + } + }, + "params": [ + { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "TSAnyKeyword", + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 16 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 11 + } + } + }, + { + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "TSAnyKeyword", + "loc": { + "start": { + "line": 18, + "column": 21 + }, + "end": { + "line": 18, + "column": 24 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 18 + }, + "end": { + "line": 18, + "column": 19 + } + } + } + ], + "typeAnnotation": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 18, + "column": 27 + }, + "end": { + "line": 18, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 19, + "column": 7 + } + } + }, + { + "type": "TSMethodSignature", + "computed": false, + "optional": false, + "key": { + "type": "Identifier", + "name": "is", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 7 + } + } + }, + "params": [], + "typeAnnotation": { + "type": "TSBooleanKeyword", + "loc": { + "start": { + "line": 19, + "column": 11 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 19 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 13 + }, + "end": { + "line": 20, + "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": 20, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 20, + "column": 2 + } + } +} diff --git a/es2panda/test/parser/ts/test-interface4.ts b/es2panda/test/parser/ts/test-interface4.ts new file mode 100644 index 0000000000000000000000000000000000000000..7f4ee18bb1847848a2dffb0643e6125e6111bb20 --- /dev/null +++ b/es2panda/test/parser/ts/test-interface4.ts @@ -0,0 +1,20 @@ +/* + * 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 { + func(a: any, b: any): number + is(): boolean; +} \ No newline at end of file diff --git a/es2panda/test/test_tsc_ignore_list.txt b/es2panda/test/test_tsc_ignore_list.txt index 716ca0e026f689dcceeda7c22a77f185ffb6a9b7..261dac1071e10798db5ae0f7277a2e660014565c 100644 --- a/es2panda/test/test_tsc_ignore_list.txt +++ b/es2panda/test/test_tsc_ignore_list.txt @@ -103,7 +103,6 @@ es2panda/test/TypeScript/tests/cases/conformance/expressions/elementAccess/letId 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