diff --git a/ets2panda/CMakeLists.txt b/ets2panda/CMakeLists.txt index 73d465ae3641b94bb806b297268f3b89e79e5884..8cab1b5e22d4493555bd83afa4e00c5346f5052a 100644 --- a/ets2panda/CMakeLists.txt +++ b/ets2panda/CMakeLists.txt @@ -14,6 +14,7 @@ cmake_minimum_required (VERSION 3.5.0) include(cmake/coverage.cmake) +include(cmake/extensionOption.cmake) project (es2panda) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) diff --git a/ets2panda/cmake/extensionOption.cmake b/ets2panda/cmake/extensionOption.cmake new file mode 100644 index 0000000000000000000000000000000000000000..d81624b9029856b3dad75530f4900a35560c8524 --- /dev/null +++ b/ets2panda/cmake/extensionOption.cmake @@ -0,0 +1,19 @@ +# Copyright (c) 2025 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. + +option(ENABLE_ES2PANDA_OTHER_EXTENSION "Enable TS/AS/JS extension for es2panda" false) + +if(ENABLE_ES2PANDA_OTHER_EXTENSION) + add_definitions(-DES2PANDA_WITH_OTHER_EXTENSION=1) + message(STATUS "TS/AS/JS extension for es2panda is enabled") +endif(ENABLE_ES2PANDA_OTHER_EXTENSION) diff --git a/ets2panda/util/diagnostic/fatal.yaml b/ets2panda/util/diagnostic/fatal.yaml index be12c9338fccf4e46405cb1b75a68698ef17f4fc..0f46c39c633136a0d771daeaf38a6f6d01149677 100644 --- a/ets2panda/util/diagnostic/fatal.yaml +++ b/ets2panda/util/diagnostic/fatal.yaml @@ -108,7 +108,7 @@ fatal: - name: UNKNOWN_EXT id: 10 message: "Unknown extension of sourcefile, set the '--extension' option or change the file extension (available options: - js, ts, as, ets)" + ets)" - name: UNRESOLVED_MODULE id: 14 diff --git a/ets2panda/util/options.cpp b/ets2panda/util/options.cpp index e2818c61a220a59f42bc3959d0a0926e6f4043a3..10c47b51d817d95f09e6a229db75b76a27419dbe 100644 --- a/ets2panda/util/options.cpp +++ b/ets2panda/util/options.cpp @@ -371,6 +371,13 @@ bool Options::DetermineExtension() } return true; } +#ifndef ES2PANDA_WITH_OTHER_EXTENSION + case ScriptExtension::AS: + case ScriptExtension::TS: { + diagnosticEngine_.LogDiagnostic(diagnostic::UNKNOWN_EXT, util::DiagnosticMessageParams {}); + return false; + } +#endif default: return true; } diff --git a/ets2panda/util/options.yaml b/ets2panda/util/options.yaml index 5aef15cb8f7068291c8f4876df2fae12a57de17b..96bb96a46c113eb67b66c0cc3b84c99eacf58556 100644 --- a/ets2panda/util/options.yaml +++ b/ets2panda/util/options.yaml @@ -37,7 +37,8 @@ options: - ts - as - ets - possible_values: *ScriptExtension + possible_values: + - ets - name: module type: bool