From 7acff31a3a0eb120f3047f6a916e2baf899d3cae Mon Sep 17 00:00:00 2001 From: xingshunxiang Date: Wed, 6 Aug 2025 09:55:51 +0800 Subject: [PATCH] Fix comments of capi in PR8211 Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICREVL?from=project-issue Description: Fix comments of capi in PR8211, GetLicenseStringFromStart will not check the existence of the license, it will only stop and return at the first {*/} Reason: Fix comments of capi in PR8211, GetLicenseStringFromStart will not check the existence of the license, it will only stop and return at the first {*/} Tests: ninja tests passed tests/tests-u-runner/runner.sh --ets-cts --show-progress --build-dir x64.release --processes=all passed tests/tests-u-runner/runner.sh --ets-func-tests --show-progress --build-dir x64.release --processes=all passed tests/tests-u-runner/runner.sh --astchecker --show-progress --build-dir x64.release --processes=all passed tests/tests-u-runner/runner.sh --ets-runtime --show-progress --build-dir x64.release --processes=all passed tests/tests-u-runner/runner.sh --parser --no-js --show-progress --build-dir x64.release --processes=all passed Signed-off-by: xingshunxiang --- ets2panda/parser/JsdocHelper.cpp | 21 +++---------------- ..._proceed_to_state_check_jsdoc-expected.txt | 1 + 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/ets2panda/parser/JsdocHelper.cpp b/ets2panda/parser/JsdocHelper.cpp index 1823498a41..8b3b05f569 100644 --- a/ets2panda/parser/JsdocHelper.cpp +++ b/ets2panda/parser/JsdocHelper.cpp @@ -21,10 +21,7 @@ namespace ark::es2panda::parser { static constexpr std::string_view JSDOC_END = "*/"; -static constexpr std::string_view JSDOC_START = "/**"; -static constexpr std::string_view LICENSES_START = "/*"; static constexpr std::string_view EMPTY_JSDOC = "Empty Jsdoc"; -static constexpr std::string_view EMPTY_LICENSE = "Empty License"; static constexpr size_t START_POS = 0; static constexpr size_t COLLECT_CURRENT_POS = 1; @@ -167,22 +164,10 @@ util::StringView JsdocHelper::GetJsdocBackward() return SourceView(backwardPos, jsdocEndPos); } +// Note: This API will not check the existence of the license, it will only stop and return at the first '*/' util::StringView JsdocHelper::GetLicenseStringFromStart() { - size_t startPos = START_POS; - auto sv = SourceView(startPos, sourceCode_.Length()); - static constexpr std::string_view MANDATORY_PREFIX = "\'use static\'\n"; - static constexpr std::string_view MANDATORY_PREFIX_DOUBLE_QUOTE = "\"use static\"\n"; - if (sv.StartsWith(MANDATORY_PREFIX) || sv.StartsWith(MANDATORY_PREFIX_DOUBLE_QUOTE)) { - startPos += MANDATORY_PREFIX.length(); - sv = SourceView(startPos, sourceCode_.Length()); - } - - if (!sv.StartsWith(LICENSES_START) && !sv.StartsWith(JSDOC_START)) { - return EMPTY_LICENSE; - } - Forward(LICENSES_START.length()); - + Iterator().Reset(START_POS); do { const char32_t cp = Iterator().Peek(); switch (cp) { @@ -205,6 +190,6 @@ util::StringView JsdocHelper::GetLicenseStringFromStart() break; } while (true); - return SourceView(startPos, Iterator().Index()); + return SourceView(START_POS, Iterator().Index()); } } // namespace ark::es2panda::parser diff --git a/ets2panda/test/unit/plugin/plugin_proceed_to_state_check_jsdoc-expected.txt b/ets2panda/test/unit/plugin/plugin_proceed_to_state_check_jsdoc-expected.txt index 79eda4c7fc..19c7aeec5c 100644 --- a/ets2panda/test/unit/plugin/plugin_proceed_to_state_check_jsdoc-expected.txt +++ b/ets2panda/test/unit/plugin/plugin_proceed_to_state_check_jsdoc-expected.txt @@ -1,3 +1,4 @@ +'use static' /* * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); -- Gitee