Data processing method and device, electronic equipment and storage medium

CN122925205APending Publication Date: 2026-10-16TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510423906.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-03
Publication Date
2026-10-16

AI Technical Summary

Technical Problem

[0004]本申请实施例提供一种数据处理方法、装置、电子设备和存储介质,可以改善现有技术开发效率较低的问题

Benefits of technology

[0032] This application also provides a computer program product, including a computer program/instructions, which, when executed by a processor, implement the steps in any of the data processing methods provided in this application.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122925205A_ABST
    Figure CN122925205A_ABST
Patent Text Reader

Abstract

The application discloses a data processing method and device, electronic equipment and storage medium, comprising: obtaining the original code of the application, wherein the original code comprises function code and test code, the function code is used for realizing the function of the application, and the test code is used for verifying the function correctness of the application; obtaining the environment type in which the application currently locates; if the environment type is a production environment type, obtaining a copy of the original code, and searching the test code in the copy; removing the test code found in the copy to obtain the copy after removing the test code; and packaging the copy after removing the test code to obtain an executable file. The application can automatically obtain the current running environment, and automatically configure the code to be packaged based on the running environment, avoiding the omission problem caused by manual adjustment of configuration items, and improving the development efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computers, and more specifically to a data processing method, apparatus, electronic device, and storage medium. Background Technology

[0002] Switching between application development and production environments is a crucial part of the software development lifecycle. In the development environment, developers can experiment, debug, and test new features, which may introduce some instability. Production environments, on the other hand, require high stability; changes that haven't been fully validated should not be applied directly to production to avoid system failures.

[0003] In existing technologies, switching between application development and production environments is often achieved manually. However, manual switching may overlook some configuration items that need adjustment, causing the application code to malfunction in a certain environment, resulting in repeated debugging and reduced development efficiency. Summary of the Invention

[0004] This application provides a data processing method, apparatus, electronic device, and storage medium, which can improve the problem of low development efficiency in the prior art.

[0005] This application provides a data processing method, the method comprising: obtaining the original code of an application, wherein the original code includes functional code and test code, the functional code being used to implement the functions of the application, and the test code being used to verify the correctness of the functions of the application;

[0006] Obtain the current environment type of the application;

[0007] If the environment type is a production environment type, obtain a copy of the original code and locate the test code in the copy;

[0008] Remove the test code found in the copy to obtain a copy after removing the test code;

[0009] The copy after removing the test code is packaged to obtain an executable file.

[0010] This application provides a data processing apparatus, the apparatus comprising:

[0011] The source code acquisition unit is used to acquire the source code of the application, wherein the source code includes functional code and test code, the functional code is used to implement the functions of the application, and the test code is used to verify the correctness of the functions of the application;

[0012] An environment type acquisition unit is used to acquire the current environment type of the application.

[0013] The code search unit is used to obtain a copy of the original code and search for test code in the copy when the environment type is a production environment type.

[0014] The code removal unit is used to remove the test code found in the copy, so as to obtain a copy after removing the test code;

[0015] The packaging unit is used to package the copy after the test code has been removed to obtain an executable file.

[0016] In one implementation, the environment type acquisition unit is specifically configured to detect the application's environment variables through global environment detection attributes, wherein the environment variables reflect the current environment type of the application; or

[0017] Based on the running status of the type plugins, the current environment type of the application is determined. The type plugins include development type plugins and production type plugins. The development type plugins run in the development environment type, and the production type plugins run in the production environment type.

[0018] In one implementation, the code search unit is specifically used to retrieve the test folder containing the test code;

[0019] Correspondingly, the code removal unit is specifically used to remove the test folder from the copy.

[0020] In one implementation, the test code includes commented test code carrying test comment markers;

[0021] The code search unit is specifically used to traverse the copy based on the test comment markers to obtain the commented test code in the copy;

[0022] Correspondingly, the code removal unit is specifically used to remove the commented test code from the copy.

[0023] In one implementation, the code lookup unit is specifically used to parse the copy to obtain an abstract syntax tree, the abstract syntax tree including multiple nodes; and to find the debugger node corresponding to the debugger from the abstract syntax tree;

[0024] Correspondingly, the code removal unit is specifically used to: if the debugger node is found, obtain the environment type; if the environment type is a production environment type, remove the debugger node to obtain an abstract syntax tree after removing the debugger node; and transform the abstract syntax tree after removing the debugger node to obtain a transformation result, which is a copy after removing the test code.

[0025] In one implementation, the code lookup unit is specifically used to parse the copy to obtain an abstract syntax tree, the abstract syntax tree including multiple nodes; for each node of the abstract syntax tree, a type checking function is used to determine whether the node is a function call expression; if the node is a function call expression, the callee attribute of the node is checked for validity; if the callee attribute of the node is valid, the callee attribute is checked for a member expression type; if the callee attribute is a member expression type, the name of the called object is obtained, and it is checked whether the object name matches the expectation; if the object name matches the expectation, the node is obtained.

[0026] Correspondingly, the code removal unit is specifically used to remove the node if the processing instruction parameter corresponding to the node is true, and obtain the abstract syntax tree after removing the node; and to transform the abstract syntax tree after removing the node to obtain a transformation result, which is a copy after removing the test code.

[0027] In one embodiment, the device further includes:

[0028] The copy acquisition unit is used to acquire a copy of the original code when the environment type is a development environment type;

[0029] The copy packaging unit is used to package the copy to obtain the executable file.

[0030] This application also provides an electronic device, including a processor and a memory, wherein the memory stores a plurality of instructions; the processor loads instructions from the memory to execute steps in any of the data processing methods provided in this application.

[0031] This application also provides a computer-readable storage medium storing a plurality of instructions adapted for loading by a processor to execute steps in any of the data processing methods provided in this application.

[0032] This application also provides a computer program product, including a computer program / instructions, which, when executed by a processor, implement the steps in any of the data processing methods provided in this application.

[0033] The data processing method provided in this application embodiment can obtain the original code of an application. The original code includes both functional code for implementing the application's functions and test code for verifying the correctness of the application's functions. It also obtains the current environment type of the application. If the environment type is a production environment, it means the application is currently in a production environment. A copy of the original code is then obtained and processed: the test code is searched for in the copy. Then, the found test code is removed from the copy, resulting in a copy with the test code removed (i.e., a copy retaining the functional code). This copy is then packaged to obtain an executable file.

[0034] In this embodiment, the current runtime environment of the application can be automatically identified. If the current environment is a production environment, test code can be identified from a copy of the original code, and the test code in the copy can be removed, retaining only the functional code. Then, the copy with the test code removed (i.e., the retained functional code) is packaged to obtain an executable file. Since the executable file no longer includes test code, the loading time can be shortened when running in a production environment. This application can automatically obtain the current runtime environment and, based on the runtime environment, automatically configure and filter the code that needs to be packaged, avoiding omissions that may occur when manually adjusting configuration items, and improving development efficiency. Attached Figure Description

[0035] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0036] Figure 1a This is a schematic diagram illustrating an application scenario of the data processing method provided in this application;

[0037] Figure 1b This is a flowchart illustrating the data processing method provided in an embodiment of this application;

[0038] Figure 1c A flowchart illustrating the process of finding test code in a copy is shown in yet another implementation.

[0039] Figure 1d It shows Figure 1c The diagram shows a flowchart illustrating the process of removing the test code.

[0040] Figure 1e A flowchart illustrating the process of locating test code in a copy is shown in another embodiment;

[0041] Figure 1f It shows Figure 1e The diagram shows a flowchart illustrating the process of removing the test code.

[0042] Figure 1g A flowchart illustrating the pre-removal judgment for each node in the abstract syntax tree is shown;

[0043] Figure 2 This is a flowchart illustrating a data processing method provided in a specific embodiment of this application;

[0044] Figure 3 This is a schematic diagram of a data processing apparatus provided in one embodiment of this application;

[0045] Figure 4 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application. Detailed Implementation

[0046] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0047] This application provides a data processing method, apparatus, electronic device, and storage medium.

[0048] Specifically, the data processing device can be integrated into an electronic device, such as a terminal or server. The terminal can be a mobile phone, tablet, smart Bluetooth device, laptop, desktop computer, etc. The server can be a single server, a server cluster consisting of multiple servers, or a cloud server, etc.

[0049] In some embodiments, the data processing apparatus may also be integrated into multiple electronic devices, such as multiple servers, with the data processing method of this application being implemented by the multiple servers.

[0050] In some embodiments, the terminal can also be used as a server to implement some or all of the functions of a server.

[0051] In this application embodiment, the terms "module" or "unit" refer to a computer program or part of a computer program that has a predetermined function and works with other related parts to achieve a predetermined goal, and can be implemented wholly or partially using software, hardware (such as processing circuitry or memory), or a combination thereof. Similarly, a processor (or multiple processors or memory) can be used to implement one or more modules or units. Furthermore, each module or unit can be part of an overall module or unit that includes the functionality of that module or unit.

[0052] Please see details Figure 1a The method provided in this application embodiment may include: obtaining the original code of an application, wherein the original code includes functional code and test code, the functional code is used to implement the functions of the application, and the test code is used to verify the correctness of the functions of the application; obtaining the current environment type of the application; if the environment type is a production environment type, obtaining a copy of the original code and finding the test code in the copy; removing the found test code from the copy to obtain a copy after removing the test code; and packaging the copy after removing the test code to obtain an executable file.

[0053] The above method can automatically identify the application's current runtime environment. If the current environment is a production environment, test code can be identified from a copy of the original code, removed from the copy, and the functional code retained. Then, the copy with the test code removed (i.e., the retained functional code) is packaged to obtain an executable file. Since the executable file no longer includes test code, loading time is shortened when running in a production environment. This application can automatically obtain the current runtime environment and, based on the runtime environment, automatically configure and filter the code to be packaged, avoiding omissions that may occur when manually adjusting configuration items, thus improving development efficiency.

[0054] The data processing method provided in this application can be implemented via a plugin, specifically a plugin based on webpack and babel. The specific implementation steps of this plugin will be described in detail below through steps 110 to 150.

[0055] Webpack is a module bundler. It primarily treats various resources (such as JavaScript code, stylesheets, images, etc.) as modules and bundles them into one or more browser-loadable packages using a dependency graph. Furthermore, Webpack supports various plugins and loaders, enabling features like code minification, automatic refresh, and preprocessing, significantly improving front-end development efficiency and performance optimization. In development environments, Webpack helps developers quickly recompile and hot-swap modules; in production environments, it helps minimize file size, optimize loading times, and achieve efficient deployment.

[0056] Babel is a JavaScript compiler primarily used to convert ECMAScript 2015+ code into a backward-compatible JavaScript version for use in current and older browsers or environments. Besides transpiling new JavaScript features, Babel allows developers to use syntax extensions (such as JSX or Flow annotations) and enhance functionality through plugins. For example, if a developer uses new features from ES6 or later, such as arrow functions, let / const declarations, and asynchronous / wait mechanisms, but needs to support browsers that are not directly compatible with these features, they can use Babel to convert the code to ES5, thus ensuring compatibility.

[0057] The embodiments of this application can be applied to various use cases. For example, they can be applied to automated processes. During project iterations, as requirements change and are optimized, frequent code modifications and adjustments may be necessary. Manually handling environment switching and code optimization would be extremely tedious and time-consuming. However, using the data processing method provided in this application, intelligent environment switching and automatic code optimization can be achieved, such as automatically removing test code and testing tools from the development environment and automatically adjusting log output, simplifying the development process and improving development efficiency and project maintainability.

[0058] The embodiments of this application can also be applied to efficient development and testing. During the development and testing phase, developers need to frequently switch between development and testing environments. Manually configuring and managing these environments is not only inefficient but also prone to errors. However, the data processing method provided in this application allows for intelligent environment switching and automatic code management and adjustment, such as retaining test code in the development environment and removing it from the production environment, thereby improving development and testing efficiency and reducing errors.

[0059] This application's embodiments can also improve user experience: When developing front-end projects, developers often face various performance optimization issues, such as how to reduce page load time and how to avoid blank screens. To address this, the method provided in this application's embodiments can automatically identify the runtime environment and perform targeted code optimization and resource management, such as compressing JavaScript and removing unnecessary Cascading Style Sheets (CSS) in a production environment, thereby shortening page load time and improving user experience. CSS is a style sheet language used to describe the appearance and format of HTML or XML (including markup languages ​​such as SVG, MathML, or XHTML) documents. CSS helps developers control the visual presentation of web pages, such as text color, font size, page layout, and spacing between elements.

[0060] It is understood that in the embodiments of this application, data such as user information are involved. When the embodiments of this application are applied to specific products or technologies, user permission or consent is required, and the collection, use and processing of related data must comply with the relevant laws, regulations and standards of the relevant countries and regions.

[0061] The following sections provide detailed descriptions of each example. It should be noted that the sequence numbers of the following embodiments are not intended to limit the preferred order of the embodiments.

[0062] In this embodiment, a data processing method is provided. For example... Figure 1b As shown, the specific process of this method may include the following steps 110 to 150:

[0063] 110. Obtain the source code of the application, wherein the source code includes functional code and test code, the functional code is used to implement the functions of the application, and the test code is used to verify the correctness of the functions of the application.

[0064] The original code includes not only the functional code that implements the application's functions, but also the test code used to verify the correctness of the application's functions.

[0065] Functional code can consist of a series of program instructions that are directly related to the application's business logic and service provision. Optionally, functional code can undergo architectural design, coding practices, and multiple iterations of optimization to provide users of the application with a stable, efficient, and user-friendly service experience.

[0066] Test code includes, but is not limited to, various types such as unit tests, integration tests, and performance tests. Each type of test helps to check whether the application's behavior meets expectations from different levels. For example, unit tests focus on verifying the functional correctness of the smallest testable unit; integration tests focus on whether the interfaces between components work properly; and performance tests are used to evaluate the application's performance under high load conditions. By running these test codes, developers can quickly identify and fix potential problems.

[0067] There are several ways to obtain source code. For example, it can be obtained by directly cloning or downloading a specific version of the compressed file from a code repository using a version control system (such as Git). Alternatively, it can be obtained through physical media (such as USB drives or external hard drives) or by transferring files over a network (such as using File Transfer Protocol (FTP) / Secure File Transfer Protocol (SFTP), cloud storage services, etc.). Furthermore, for open-source projects, the source code can be downloaded directly from the official website or open-source software distribution platform. It should be understood that the specific method of obtaining the source code should not be construed as a limitation of this application.

[0068] 120. Obtain the current environment type of the application.

[0069] Optionally, in one implementation, the step of obtaining the current environment type of the application may specifically include:

[0070] The application's environment variables are detected through global attribute detection, whereby the environment variables reflect the current environment type of the application; or

[0071] Based on the running status of the type plugins, the current environment type of the application is determined. The type plugins include development type plugins and production type plugins. The development type plugins run in the development environment type, and the production type plugins run in the production environment type.

[0072] Environment variables are variables that reflect the type of environment an application is currently in. Environment variables help applications identify the type of runtime environment they are in, allowing them to adjust their behavior to adapt to different environmental requirements. Specifically, environment variables are dynamic values ​​provided by the operating system that can influence the behavior of running processes. Environment variables can be manually set by developers.

[0073] Optionally, the environment variable can be represented by NODE_ENV. NODE_ENV is used to indicate which stage of the application's lifecycle it is currently in: development or production.

[0074] Specifically, developers can set the environment variable NODE_ENV to "development" or "production" in npm scripts. Setting NODE_ENV to "development" indicates that the application is currently in a development environment. In a development environment, features that are only useful during development are usually enabled, such as more detailed error messages and hot reload, to facilitate rapid iteration and debugging of code. Setting NODE_ENV to "production" indicates that the application is currently in a production environment. In a production environment, configurations for performance optimization can be activated, such as minimizing JavaScript packages and disabling development tools, to ensure that the application runs efficiently and stably.

[0075] Optionally, the settings for environment variables may differ across platforms and operating systems. To ensure compatibility, a cross-platform solution can be used.

[0076] Setting environment variables may involve different syntaxes and methods across different operating systems (such as Windows, Linux, and macOS). For example, on Unix-like systems (including Linux and macOS), developers can directly set environment variables and execute commands using commands like `NODE_ENV=production webpack`. However, this approach is not applicable to Windows systems, which have their own set of methods for setting environment variables.

[0077] To ensure scripts work consistently across all platforms and avoid issues caused by environment differences, cross-platform solutions such as the cross-env library can be used. This library allows developers to set environment variables in a uniform way without worrying about differences in the underlying operating system. For example, using the cross-env library to set environment variables:

[0078] "build":"cross-env NODE_ENV=production webpack"

[0079] This means that regardless of whether the script is run on Windows, Linux, or macOS, cross-env will ensure that NODE_ENV is correctly set to production before executing the Webpack bundling command.

[0080] Environment detection global properties are global properties for detecting environment variables, and can be represented by `process.env.NODE_ENV`. In Node.js, the `process.env` object contains a large number of available environment variables, while `process.env.NODE_ENV` specifically refers to the value of the environment variable `NODE_ENV`. Optionally, application environment variables can be detected by reading the environment variable `NODE_ENV` through the global environment detection property `process.env.NODE_ENV`.

[0081] In addition to obtaining the environment type by detecting environment variables as mentioned above, the current environment type of the application can also be determined based on the running status of the type plugin.

[0082] Type plugins include development type plugins and production type plugins. Development type plugins are used during the development phase. When the application is in the development environment, development type plugins are activated to provide developer-friendly tools and services. For example, a Hot Module Replacement (HMR) plugin can be configured in the development environment. HMR can update modules without reloading the entire page, improving development efficiency. It allows developers to instantly see the effects of code changes without manually refreshing the browser, thus speeding up debugging and testing.

[0083] Production-grade plugins are used in production environments to optimize application performance and ensure its stability and security. In production environments, minification and code splitting plugins are typically configured. Minification plugins reduce file size by removing whitespace, comments, and shortening variable names, thus reducing network transfer time and improving loading speed. Code splitting plugins break the codebase into smaller chunks, allowing users to download only the necessary parts instead of loading all resources at once. This reduces initial loading time and improves the user experience.

[0084] By detecting whether specific types of plugins are activated, the current working environment of the application can be inferred. For example, if a hot reload plugin is found to be running, it can be confirmed that the application is currently in a development environment; conversely, if compression and code splitting plugins are detected to be running, it indicates that the application is running in a production environment. This implementation simplifies the environment management process and also helps to further enhance the efficiency of development and operations.

[0085] Optionally, in one specific embodiment, after step 120, the embodiments of this application may further include the following steps X1 to X2:

[0086] X1. If the environment type is a development environment type, obtain a copy of the original code.

[0087] If the current application environment is determined to be a development environment, the first step is to obtain a copy of the application's original code. Obtaining a copy of the application's original code is typically done through a version control system (such as Git), for example, by pulling the latest version of the code from a repository.

[0088] X2. Package the copy to obtain the executable file.

[0089] Optionally, in the development environment, the original code is not removed or modified in any way, ensuring that the complete codebase, including all functional and test code, is copied. After obtaining a copy of the original code, this copy can be packaged to generate a development executable suitable for the development environment. During the packaging process, all functional and test code is integrated into a unified build package. Because it includes complete test code, developers can easily perform immediate testing of new features or improvements to the application in their local environment.

[0090] In the above implementation, assuming the application's current runtime environment is a development environment, a copy of the original code (including functional code and test code) can be obtained and directly packaged without removal to obtain the corresponding development executable file. The test code included in the development executable file can test the correctness of the application's functionality. This implementation, assuming the application is in a development environment, completely packages copies including functional code and test code, preserving the testing functionality of the test code. This means developers can run test cases at any time to ensure newly added or modified functional modules work as expected, greatly enhancing quality control during the development phase. Compared to the existing method of manually selecting code segments to be included in the executable file, the method of automatically selecting appropriate code for packaging based on the application's environment significantly improves the efficiency and accuracy of the build process. Automated processes reduce the possibility of human error and allow for more frequent build and deployment activities, accelerating iteration speed.

[0091] 130. If the environment type is a production environment type, obtain a copy of the original code and find the test code in the copy.

[0092] Once the application environment is confirmed to be production, a copy of the application's original code can be obtained from the version control system. This copy includes functional code and test code used to verify the correctness of the functional code. However, in a production environment, the presence of test code not only increases the application's size but may also introduce unnecessary complexity and potential security risks. Therefore, after obtaining a copy of the original code, it needs to be thoroughly scanned to identify all test code within it.

[0093] 140. Remove the test code found in the copy to obtain a copy after removing the test code.

[0094] After identifying the test code in the original code copy, the test code can be removed, generating a cleaned-up new copy containing only functional code. This cleaned-up copy, with the test code removed, is a streamlined version of the application code, more suitable for deployment in a production environment.

[0095] Optionally, in one specific implementation, "finding the test code in the copy" in step 130 may specifically include: obtaining the test folder containing the test code.

[0096] Accordingly, step 140 may specifically include: removing the test folder from the copy.

[0097] The test folder containing the test code can be obtained by specifying the `exclude` option. For example, `exclude:[ / node_modules / , / __tests__ / ]` indicates that the code folders that do not need to be processed by Babel are excluded: ` / node_modules / ` and ` / __tests__ / `, where ` / node_modules / ` and ` / __tests__ / ` are both folder names. The code folders that do not need to be processed by Babel are the aforementioned test folders.

[0098] Test code can be stored in a specially named folder, such as __tests__, test, or spec; here, we'll use "__tests__" as an example. Alternatively, developers can follow naming conventions when naming test files, such as using .test.js or .spec.js as the suffix. This will help identify and exclude test files during the build and packaging process.

[0099] Furthermore, the `node_modules` folder containing dependent libraries typically doesn't need to be included in production builds, as it may contain numerous test files or other unnecessary resources. Therefore, specifying the `exclude` option allows for efficient identification and location of these unnecessary code folders. For example, this can be achieved by configuring the `exclude` option when using Babel for code transpilation.

[0100] exclude:[ / node_modules / , / __tests__ / ]

[0101] The above configuration excludes the ` / node_modules / ` and ` / __tests__ / ` folders during processing. This means that Babel will not process the contents of these two folders when performing the packaging operation, thus indirectly helping us locate the target folder where the test code is stored.

[0102] Once you have the test folder, you can remove the test folder from the copy.

[0103] After completing the identification process described above, the next task is to actually remove these unnecessary folders. This step can be achieved in several ways, depending on the specific build tool and framework. For example, in Webpack configuration, the CopyWebpackPlugin plugin can be used in conjunction with exclusion rules to avoid copying specified folders; or logic can be written directly in the build script to traverse the project directory structure and delete matching test folder paths. Alternatively, the removal process can be executed by configuring externals.

[0104] In the above implementation, test code can be stored in a specially named test folder. This approach not only helps maintain the cleanliness and readability of the project structure but also allows developers to quickly locate the test code for modification or extension. Using a consistent and clear naming convention to identify test folders makes it easier for automation tools to identify which parts do not belong to the final deployed product. This greatly simplifies logical judgments in subsequent processing and improves the efficiency of the entire build process. Furthermore, during the removal of test code, the entire test folder can be removed, which is a highly efficient method. Compared to scanning and deleting individual test files one by one, this method reduces unnecessary I / O operations and speeds up the cleanup process. In addition, it avoids potential security risks or performance issues caused by missing some test files.

[0105] Optionally, in another specific embodiment, the test code includes commented test code carrying test comment markers. Then, step 130, "finding test code in the copy," can specifically include: traversing the copy based on the test comment markers to obtain the commented test code in the copy.

[0106] Annotated test code typically carries explicit test annotation markers, such as `@remove-on-production`. Developers can manually add these markers near the code segments they want to remove from the production environment while writing their code. For example, a typical annotated test code block in JavaScript might look like this:

[0107] if(process.env.NODE_ENV===="development")

[0108] {

[0109] / / @remove-on-production

[0110] console.log("This is debug code that only runs in the development environment");

[0111] }

[0112] In this example, @remove-on-production is a test comment marker that indicates that the following line of code, console.log, contains debugging information for development use only.

[0113] You can use scripting tools (such as regular expressions, custom parsers, etc.) to traverse the entire code copy and find code segments marked with a specified test comment. For example, in a Node.js environment, you can write a script to find and list all lines of code that contain the `@remove-on-production` annotation.

[0114] Accordingly, step 140 may specifically include: removing the commented test code from the copy.

[0115] Once all commented test code has been successfully identified, the next step is to remove it from the code copy. Continuing with the example above, after finding the test comment marker `@remove-on-production`, the commented test code containing `@remove-on-production` can be removed, specifically the `if` statement code block mentioned above. This is because simply removing the line of code containing the `@remove-on-production` comment marker `console.log` would leave invalid or erroneous code structure; therefore, the entire `if` statement code block can be removed.

[0116] Optionally, in another specific embodiment, "finding the test code in the copy" in step 130 may specifically include steps A1 to A2 as follows; please refer to [link to details]. Figure 1c As shown:

[0117] A1. Parse the copy to obtain an abstract syntax tree, which includes multiple nodes.

[0118] A parser can be used to convert a copy into an Abstract Syntax Tree (AST). For example, in a JavaScript project, tools such as @babel / parser or Esprima provided by Babel can be used to perform the transformation. These tools can analyze the code in the copy and represent it in a structured way as a tree, where each node represents a different part of the code (such as variable declarations, function definitions, conditional statements, etc.).

[0119] A2. Locate the debugger node corresponding to the debugger in the abstract syntax tree.

[0120] The debugger is called `debugger;`. `debugger;` is a special JavaScript statement that, when executed, triggers a breakpoint if the browser's developer tools (such as Chrome DevTools) are enabled, causing the program to pause execution and allowing the developer to inspect the current execution environment.

[0121] The uses of a debugger can include: inserting debugger statements at specific locations in the code to simulate manually set breakpoints; once the program executes to the statement, it will enter a paused state, allowing developers to view information such as current variable values, call stack, and scope chain; starting from the breakpoint, developers can choose to execute code line by line (Step Over), enter the function (Step Into), or exit the current function to continue execution (Step Out) to examine the program's behavior in detail.

[0122] The use cases for the debugger are described in stages as follows:

[0123] During the development phase, in order to better understand code behavior or find problems, developers insert debugger; statements at key locations to actively trigger breakpoints.

[0124] During the testing phase, it can help developers verify certain assumptions or check whether the state of variables under specific conditions meets expectations.

[0125] During the production phase, it is generally not recommended to retain debugger statements in the production environment, as they may cause unnecessary pauses and affect the user experience.

[0126] Specifically, step A2 can recursively traverse each node of the tree and check if its type matches the debugger node.

[0127] In the above implementation, this abstract syntax tree-based method can more accurately locate the debugger code that needs to be removed. This approach avoids the potential false positives or false negatives that can result from relying solely on text matching. This method not only improves the accuracy of code cleanup but also better maintains code integrity and consistency, making it particularly suitable for large or complex projects.

[0128] Accordingly, step 140 may specifically include steps B1 to B3 as follows; please refer to [link / reference] for details. Figure 1d As shown:

[0129] B1. If the debugger node is found, then obtain the environment type.

[0130] The current application's environment type can be determined, and this process can be achieved by reading environment variables. For example, in a Node.js environment, `process.env.NODE_ENV` can be used to determine the application's environment type.

[0131] B2. If the environment type is a production environment type, then remove the debugger node to obtain the abstract syntax tree after removing the debugger node.

[0132] After determining that the environment type is production, the next task is to remove all debugger nodes from the AST. This can be achieved by recursively traversing the entire AST and deleting each node of type DebuggerStatement.

[0133] B3. Transform the abstract syntax tree after removing the debugger node to obtain a transformation result, which is a copy after removing the test code.

[0134] After removing the debugger node, the modified AST can be converted back into source code. This conversion process can be accomplished using appropriate code generation tools, such as Babel's @babel / generator.

[0135] Steps B1 to B3 above can be encapsulated in a method named `DebuggerStatement(path, state)`, which is invoked when a debugger node is detected. When `DebuggerStatement(path, state)` is invoked, steps B1 to B3 are executed. The `DebuggerStatement(path, state)` method is defined by the developer and is used to handle nodes of type `DebuggerStatement`. In the Abstract Syntax Tree (AST), a node of type `DebuggerStatement` represents a debugger statement in JavaScript. When JavaScript code executes a debugger statement, if the current environment supports debugging (e.g., in the browser's developer tools), the program pauses execution and hands control to the debugger, allowing the developer to inspect the current call stack, variable values, and other information. This is particularly useful for debugging complex applications.

[0136] The above implementation effectively identifies and removes debugger code from production environments, thereby optimizing application performance and security. This method not only improves the accuracy of code cleanup but also ensures code integrity and consistency, making it particularly suitable for large or complex projects. Furthermore, utilizing AST for code analysis and modification makes the automation process more reliable and reduces the possibility of human error.

[0137] Optionally, in another specific embodiment, "finding the test code in the copy" in step 130 may specifically include steps C1 to C6, for details please refer to Figure 1e As shown:

[0138] C1. Parse the copy to obtain an abstract syntax tree, which includes multiple nodes.

[0139] A parser can be used to convert a copy into an Abstract Syntax Tree (AST). For example, in a JavaScript project, tools such as @babel / parser or Esprima provided by Babel can be used to perform the transformation. These tools can analyze the code in the copy and represent it in a structured way as a tree, where each node represents a different part of the code (such as variable declarations, function definitions, conditional statements, etc.).

[0140] C2. For each node of the abstract syntax tree, use a type checking function to determine whether the node is a function call expression.

[0141] Specifically, you can use the `@babel / traverse` module provided by Babel to traverse the entire abstract syntax tree structure, and then use the type checking function `t.isCallExpression(path.node)` in `@babel / types` (usually abbreviated as `t`) to determine whether the specific type of a node is `CallExpression`. Here, `CallExpression` indicates that the current node is a function call expression. In JavaScript, when a piece of code attempts to call a function, it is resolved into a node of type `CallExpression`. For example, in the function call `example()`, `example` itself is an identifier, while the entire `example()` is treated as a `CallExpression`.

[0142] Here is a specific example of the example() function:

[0143]

[0144] In the above structure, callee represents the function being called (example in this case), while arguments are all the arguments passed to that function (an empty array in this case because there are no arguments).

[0145] The specific uses of the `arguments.callee` property include: for anonymous functions, recursive calls can be achieved using `arguments.callee` because anonymous functions have no name; in older versions of JavaScript (such as ES3), `arguments.callee` is one of the main ways to access the current function.

[0146] C3. If the node is a function call expression, determine whether the callee attribute of the node is valid.

[0147] Assuming the node's type is CallExpression, further check if the current node has a `callee` property representing the callee. It's necessary to confirm that the current node does indeed contain a `callee` property. In JavaScript, `callee` refers to the actual function or method being called. For a valid function call expression, this property must exist and have a specific type.

[0148] Specifically, you can confirm whether the current node has a callee attribute using the following example:

[0149]

[0150] If the current node has a `callee` attribute, then the validity of the `callee` attribute is further determined. Specifically, the validity of the `callee` attribute can be determined by whether it points to a valid function or method call. If the `callee` attribute points to a valid function or method call, then the `callee` attribute is considered valid; if the `callee` attribute does not point to any valid function or method call, then the `callee` attribute is considered invalid.

[0151] For example, a callee can be an identifier representing a direct reference to a function, or a member expression representing a method call on an object. If a callee is an identifier, it typically represents a reference to a defined function or variable. If a callee is a member expression, it represents a method call on an object.

[0152] Alternatively, in one implementation, if the callee is invalid, unused functions or methods can be discovered by identifying invalid callee attributes, thereby enabling code cleanup and optimization, removing redundant code, and improving application performance.

[0153] C4. If the callee attribute of the node is valid, determine whether the callee attribute is a member expression type.

[0154] If the `callee` property of the current node is valid, then it is further determined whether the `callee` property is of type `MemberExpression`, that is, whether the current node represents a method call to an object. Here, `MemberExpression` represents access to a method of an object; for example, in `console.log`, "console" is an object, and "log" is a method of that object.

[0155] Identifying the `callee` property of the `MemberExpression` type can help developers better understand and optimize their code. For example, developers can detect all API calls to a specific library or framework and refactor or replace them as needed. Furthermore, developers can use it for security checks to ensure that no unsafe objects or methods are called.

[0156] C5. If the called object's property is a member expression type, then obtain the name of the called object and determine whether the object name matches the expectation.

[0157] If the `callee` property of the callee is of type `MemberExpression`, then the name of the called object can be obtained by accessing the `object` property of the callee `callee`. Then, it can be determined whether the obtained object name matches the expected name.

[0158] The above expectation is a predefined specific name, for example, it could be console or alert.

[0159] The `console` object provides a series of methods, such as `log()`, `warn()`, and `error()`, for outputting information to the browser's developer tools console. This is extremely useful for debugging code, as it allows developers to view variable values, execution flow, and error messages. Common uses of the `console` object include: outputting log messages: `console.log('This is a log message')`; outputting warning messages: `console.warn('This is a warning')`; and outputting error messages: `console.error('This is an error')`.

[0160] The `alert()` function displays a warning box in the browser, showing the specified information, and requires the user to click the "OK" button to close it. It is typically used to display important notifications or warnings to the user. Common uses of the `alert()` function include: displaying important messages to the user: `alert('Please check your input')`.

[0161] While console and alert statements are crucial for development and debugging, retaining them in a production environment can lead to the following three problems:

[0162] 1. While a single `console.log()` call has a small performance impact, frequent use in high-frequency code segments can accumulate into significant performance overhead. `alert()` blocks JavaScript.

[0163] Executing the alert until the user closes it can lead to a poor user experience, especially if alert() is misused in automated operations or loops.

[0164] 2. Log information output via the console may contain sensitive data (such as API keys, user personal information, etc.). If this information is exposed to end users, it may pose a security risk. Although alerts themselves are not a direct security threat, misuse can damage the user experience and may be used for social engineering attacks or other forms of malicious behavior.

[0165] 3. Frequent alert dialog boxes can disrupt the user's normal workflow, resulting in a poor user experience. In a production environment, excessive console output is not only unhelpful to users but may also make it difficult for developers to distinguish noise from actual problems.

[0166] Alternatively, let's take "console" as an example. Then: if the name of the called object is "console", then the object name is considered to be as expected. Conversely, if it is not, then the object name is considered to be as expected.

[0167] C6. If the object name matches the expectation, then obtain the node.

[0168] If the object name matches the expectation, the node can be determined as the node to be removed, and the following steps D1 to D2 can be performed on the node to be removed.

[0169] Accordingly, step 140 may specifically include steps D1 to D2 as follows; please refer to [link to details]. Figure 1f As shown:

[0170] D1. If the processing instruction parameter corresponding to the node is true, then remove the node to obtain the abstract syntax tree after removing the node.

[0171] Continuing with the example above, let's take the expected `console` parameter as an example. The processing indicator parameter can be represented as `state.opts.isConsole`. If the processing indicator parameter `state.opts.isConsole` for the current node is true, then the current node can be removed.

[0172] `isConsole` is a boolean attribute in `state.opts` that indicates whether console-related function calls should be removed. Setting it to `true` means the corresponding operation should be performed; setting it to `false` skips these operations. Removing the current node can be achieved by calling the `path.remove()` method.

[0173] D2. Transform the abstract syntax tree after removing the node to obtain the transformation result, which is a copy after removing the test code.

[0174] After removing the current node, the modified AST can be converted back into source code. This conversion process can be accomplished using appropriate code generation tools, such as Babel's @babel / generator.

[0175] Optionally, steps C3 to C6 and steps D1 to D2 can all be encapsulated in a method named `ExpressionStatement(path, state)`. For each node in the abstract syntax tree, the `ExpressionStatement(path, state)` method can be called to implement steps C3 to C6 and steps D1 to D2. Optionally, after completing step D2, a `return` statement can be used to prematurely terminate the execution of the current function `ExpressionStatement(path, state)` to avoid unnecessary subsequent processing.

[0176] The `ExpressionStatement(path, state)` method is defined by the developer and is used to process nodes of type `ExpressionStatement`. `ExpressionStatement` is a JavaScript construct that executes expressions as statements, such as assignment operations and function calls.

[0177] Optionally, in one specific embodiment, steps C1 to C6 and steps D1 to D2 can be implemented through steps S1 to S9, for details please refer to [link to relevant documentation]. Figure 1g :

[0178] S1. Parse the copy to obtain an abstract syntax tree, which includes multiple nodes.

[0179] Step S1 corresponds to step C1, so it will not be described in detail here.

[0180] S2. For each node of the abstract syntax tree, use t.isCallExpression(path.node) to determine whether the type of the current node is CallExpression. If it is, then execute step S3.

[0181] The purpose of step S2 is to filter out all function call expressions. t.isCallExpression(path.node) is used to determine whether the currently traversed node is a function call expression (i.e., of type CallExpression). If the currently traversed node is not a function call expression, but a variable declaration statement or an assignment statement, then there is no need to perform subsequent judgments and operations.

[0182] S3. Determine if the current node has the callee attribute. If it does, proceed to step S4.

[0183] In JavaScript, the `callee` property of a function call expression points to the actual function or method being called. If this property exists, it indicates that it is a valid function call. Therefore, step S3 is used to confirm that the current node is a valid function call.

[0184] S4. Determine if the callee attribute is valid. If it is, proceed to step S5.

[0185] Although the `callee` attribute will exist in most cases, it is checked again here to ensure that it does indeed contain a valid value, avoiding the processing of invalid or erroneous data. Step S4 is used to further verify the validity of the `callee` attribute.

[0186] S5. Determine if the callee property is of type MemberExpression. If so, proceed to step S6.

[0187] A member expression represents how an object accesses its members. For example, in `console.log()`, `console` is the object, and `log` is its member. This step is used to find calls that access methods through the object.

[0188] S6. Obtain the name of the object being called by accessing the `object` property of `callee`.

[0189] For member expressions, the name of the object being called (such as console) can be obtained by accessing the callee's object property. This is to further confirm whether the object is the target object that the developer expects to process.

[0190] S7. Check if the name of the called object matches the expectation. If it does, proceed to step S8.

[0191] In this step, the extracted object name can be compared with the expected target object name (such as console). If they match, proceed to the next step; if they do not match, skip this node.

[0192] S8. Check if the value of state.opts.isConsole is true. If it is, proceed to step S9.

[0193] Here, `state.opts.isConsole` is an option or configuration parameter, typically passed through plugin configuration. It can be used to control whether specific code is removed in different environments (such as development or production). For example, setting `isConsole:true` in a production environment removes debugging-related code.

[0194] S9. Remove the current node.

[0195] If all the preceding conditions are met, and the configuration allows removal, then the path.remove() method is called to remove the current node from the AST.

[0196] The above-mentioned numerous judgment steps offer the following three advantages:

[0197] 1. Perform operations only on specific types of nodes (such as console.log()) to avoid accidentally deleting other important code;

[0198] 2. It can dynamically adjust its behavior based on different configurations or environment variables to adapt to different development and production needs;

[0199] 3. Verify each condition step by step to ensure that only nodes that meet the conditions are removed, thus reducing the risk of introducing errors.

[0200] While the steps described above may seem complex, each has a clear purpose: to provide a reliable way to clean and optimize JavaScript code, especially when preparing for production environments. This meticulous inspection mechanism helps ensure code quality and stability, while also effectively reducing unnecessary code size and improving application performance.

[0201] 150. Package the copy after removing the test code to obtain an executable file.

[0202] Identify and remove test code from the original codebase, retaining only the functional code. Then, package this optimized code to generate an executable suitable for production environments. This not only reduces application loading time but also improves performance and security.

[0203] Optionally, in one specific embodiment, after step 150, the embodiments of this application may further include the following steps.

[0204] 160. If the environment type is switched from production environment type to development environment type, the test code that was removed from the copy is restored based on the history of the copy, so as to obtain a copy after the test code is restored.

[0205] Optionally, environment variables can be retrieved periodically, and the environment type can be switched from production to development based on the specific values ​​of the environment variables. Specifically, different checking strategies can be selected to periodically check for changes in environment variables according to actual needs. Common methods include using scheduled tasks (such as the setInterval function in Node.js), checking file system events (if environment variables are stored in configuration files), or using services provided by the operating system to trigger specific events.

[0206] Optionally, a processing function can be defined to compare the current environment variables with the previous environment variables to determine whether a switch from a production environment to a development environment has occurred. In one specific implementation, the above process can be implemented using the following code:

[0207]

[0208] Based on the history of the copy, the test code that was removed from the copy is restored, which can be achieved in the following way:

[0209] Alternatively, a version control system or backup mechanism can be used: To accurately restore the removed test code, a version control system (such as Git) can be used, or a dedicated backup mechanism can be established. This approach allows developers to query a specific version of the code and restore the removed parts from it.

[0210] For example, code can be recovered using Git. If a developer uses Git as a version control tool, they can check out specific commits containing test code.

[0211] git checkout <commit-hash>--path / to / your / file.js

[0212] Among them, the command git checkout <commit-hash>--path / to / your / file.js is used to extract specific commits from the Git repository (by...). <commit-hash>This command restores a specified file (in this example, path / to / your / file.js) to the working directory. The following is a detailed explanation of the code snippet above:

[0213] `git checkout`: This is a Git command typically used to switch branches or restore files in the working directory. In this context, it's used to restore a specific version of a file.

[0214] <commit-hash>This is a placeholder representing the hash of the specific commit from which the developer wants to recover the files. Each commit in Git has a unique hash (usually a 40-character SHA-1 hash, but typically the first 7 characters are used), which developers can find using `git log` or other Git tools.

[0215] --: The double dashes here are used to tell Git that the first part is a commit reference (such as a branch name, tag name, or commit hash), and the second part is the path. This is used to distinguish between filenames and branch names or other Git references that might be confused with them.

[0216] `path / to / your / file.js`: This refers to the path to the specific file the developer wants to restore from a particular commit. It's crucial to ensure the path is correct relative to the repository's root directory.

[0217] Alternatively, the state of the entire branch can be restored to a specific commit point, as achieved using the following code snippet:

[0218] git reset--hard <commit-hash>

[0219] The code snippet above is used to reset the developer's working directory and staging area (index) to the specified commit. <commit-hash>The code snippet above can revert the entire project state to a specified commit point, and will lose all local changes made after that commit.

[0220] `git reset` is a basic Git command used to reset the current HEAD pointer. HEAD is a reference to the latest commit on the developer's current working branch.

[0221] --hard: This option tells Git not only to move the HEAD pointer, but also to reset the working directory and staging area to the state of the target commit. This means that any uncommitted changes will be discarded, and all new commits since the target commit will be deleted.

[0222] <commit-hash>This is a placeholder representing the hash of the specific commit the developer expects to reset to. Each commit in Git has a unique hash (usually a 40-character SHA-1 hash, but typically the first 7 characters are used), which developers can find using `git log` or other Git tools.

[0223] 170. Package the restored copy of the test code to obtain the development executable file.

[0224] The copy of the restored test code contains the same content as the copy corresponding to step X2. Therefore, the processing procedure of step 170 is the same as that of step X2, and will not be described in detail here.

[0225] Alternatively, in one implementation, when it is determined that the current environment of the application is a production environment, operations such as compressing JavaScript, extracting CSS, and deleting useless CSS can also be performed.

[0226] For compressing JavaScript:

[0227] In a production environment, enable code minification and use the terser-webpack-plugin to minify JavaScript code. The terser-webpack-plugin is a popular Webpack plugin for minifying and minimizing JavaScript code. Terser is a modern JavaScript parser and minifier that supports ES6+ syntax. To enable code minification and use the terser-webpack-plugin in your Webpack configuration file (webpack.config.js), you need to perform the following steps: Install the terser-webpack-plugin; Update the webpack.config.js file: Set `optimization.minimize` to `true` in the Webpack configuration file and add `TerserWebpackPlugin` to the `minimizer` array.

[0228] In a production environment, compressing JavaScript code offers several key benefits: by removing unnecessary characters (such as spaces, comments, etc.), file size can be significantly reduced, speeding up downloads; smaller files mean faster transfer times, thus improving page load speed and user experience; while not the primary goal of all compression tools, the compression process often makes code more difficult to read and understand, providing a degree of security enhancement.

[0229] For extracting CSS:

[0230] Use the mini-css-extract-plugin to extract CSS into a separate file. To use mini-css-extract-plugin to extract CSS in your Webpack configuration file (webpack.config.js), you need to do the following: Configure CSS processing in the module.rules of webpack.config.js, and use MiniCssExtractPlugin.loader to load the CSS. Add MiniCssExtractPlugin to the plugins array.

[0231] In a production environment, extracting CSS has several key benefits: extracting CSS into a separate file allows the browser to download CSS and JavaScript resources in parallel, rather than waiting for JavaScript to execute before dynamically inserting styles; the separate CSS file can be cached by the browser, meaning that if a user visits the website again, they don't need to download the CSS file again unless it has changed; and it allows developers to have better control over the loading order and application timing of styles, which is especially important for large projects.

[0232] Regarding deleting unused CSS:

[0233] Using the purgecss-webpack-plugin to detect and remove unused CSS is an effective way to optimize front-end resources and reduce the final bundle size. To use purgecss-webpack-plugin to remove unused CSS in your Webpack configuration file (webpack.config.js), you need to do the following: In your webpack.config.js file, add PurgeCSSWebpackPlugin to the plugins array and configure the appropriate content options to specify the files to check.

[0234] In a production environment, removing unused CSS has several key benefits: by removing unused CSS rules, the size of CSS files can be significantly reduced, thus reducing download time; smaller CSS files mean faster transmission and parsing times, which helps improve the overall page load speed; smaller CSS files can reduce the time required for the browser to render the page, improving the user experience.

[0235] The data processing method provided in this application embodiment can obtain the original code of an application. The original code includes both functional code for implementing the application's functions and test code for verifying the correctness of the application's functions. It also obtains the current environment type of the application. If the environment type is a production environment, it means the application is currently in a production environment. A copy of the original code is then obtained and processed: the test code in the copy is located. The found test code is then removed from the copy, resulting in a copy with the test code removed (i.e., a copy retaining the functional code). This copy is then packaged to obtain an executable file. In this application embodiment, the current running environment of the application can be automatically identified. If the current environment is a production environment, the test code can be identified from the copy of the original code, removed, and the functional code portion retained. The copy with the test code removed (i.e., the retained functional code) is then packaged to obtain an executable file. Since the executable file no longer includes test code, loading time can be shortened when running in a production environment. This application can automatically obtain the current runtime environment and, based on the runtime environment, automatically configure and filter the code that needs to be packaged, avoiding omissions that may occur when manually adjusting configuration items.

[0236] The embodiments of this application can improve development efficiency.

[0237] In this embodiment, the method of this application embodiment is described in detail, taking a plugin based on Webpack and Babel as the execution subject. The data processing method provided in this application embodiment can be executed by an electronic device. In this embodiment, the electronic device is described as a terminal device, such as... Figure 2 As shown, the specific process of a data processing method is as follows:

[0238] 201. The plugin obtains the original code of the application, wherein the original code includes functional code and test code, the functional code is used to implement the functions of the application, and the test code is used to verify the correctness of the functions of the application.

[0239] 202. The plugin obtains the current environment type of the application.

[0240] Optionally, in one embodiment, step 202 may specifically include the following steps:

[0241] The application's environment variables are detected through global attribute detection, whereby the environment variables reflect the current environment type of the application; or

[0242] Based on the running status of the type plugins, the current environment type of the application is determined. The type plugins include development type plugins and production type plugins. The development type plugins run in the development environment type, and the production type plugins run in the production environment type.

[0243] 203. If the environment type is a production environment type, the plugin obtains a copy of the original code.

[0244] 204. The plugin searches for test code in the aforementioned copy.

[0245] 205. The plugin removes the test code found in the copy, resulting in a copy with the test code removed.

[0246] Optionally, in one implementation, step 204 includes: obtaining a test folder containing the test code.

[0247] Accordingly, 205 may include: removing the test folder from the copy.

[0248] Alternatively, in another implementation, the test code includes commented test code carrying test comment markers. Step 204 includes: traversing the copy based on the test comment markers to obtain the commented test code in the copy.

[0249] Accordingly, 205 may include: removing the commented test code from the copy.

[0250] Optionally, in another embodiment, step 204 includes: parsing the copy to obtain an abstract syntax tree, the abstract syntax tree including multiple nodes; and searching for the debugger node corresponding to the debugger in the abstract syntax tree.

[0251] Accordingly, 205 may include: if the debugger node is found, then obtain the environment type; if the environment type is a production environment type, then remove the debugger node to obtain an abstract syntax tree after removing the debugger node; transform the abstract syntax tree after removing the debugger node to obtain a transformation result, the transformation result being a copy after removing the test code.

[0252] Optionally, in another embodiment, step 204 includes: parsing the copy to obtain an abstract syntax tree, the abstract syntax tree including multiple nodes; for each node of the abstract syntax tree, using a type checking function to determine whether the node is a function call expression; if the node is a function call expression, then determining whether the callee attribute of the node is valid; if the callee attribute of the node is valid, determining whether the callee attribute is a member expression type; if the callee attribute is a member expression type, then obtaining the name of the called object and determining whether the object name meets expectations; if the object name meets expectations, then obtaining the node.

[0253] Accordingly, 205 may include: if the processing instruction parameter corresponding to the node is true, then remove the node to obtain an abstract syntax tree after removing the node; transform the abstract syntax tree after removing the node to obtain a transformation result, the transformation result being a copy after removing the test code.

[0254] 206. The plugin packages the copy after removing the test code to obtain an executable file.

[0255] 207. If the environment type is a development environment type, the plugin obtains a copy of the original code.

[0256] 208. The plugin packages the copy to obtain the executable file.

[0257] The specific execution process of steps 201 to 208 has been explained in detail above, and will not be repeated here.

[0258] The data processing method provided in this application embodiment can obtain the original code of an application. The original code includes both functional code for implementing the application's functions and test code for verifying the correctness of the application's functions. It also obtains the current environment type of the application. If the environment type is a production environment, it means the application is currently in a production environment. A copy of the original code is then obtained and processed: the test code in the copy is located. The found test code is then removed from the copy, resulting in a copy with the test code removed (i.e., a copy retaining the functional code). This copy is then packaged to obtain an executable file. In this application embodiment, the current running environment of the application can be automatically identified. If the current environment is a production environment, the test code can be identified from the copy of the original code, removed, and the functional code portion retained. The copy with the test code removed (i.e., the retained functional code) is then packaged to obtain an executable file. Since the executable file no longer includes test code, loading time can be shortened when running in a production environment. This application can automatically obtain the current runtime environment and, based on the runtime environment, automatically configure and filter the code that needs to be packaged, avoiding omissions that may occur when manually adjusting configuration items.

[0259] The embodiments of this application can improve development efficiency.

[0260] To better implement the above methods, embodiments of this application also provide a data processing apparatus, such as... Figure 3 As shown, the device includes:

[0261] The source code acquisition unit 301 is used to acquire the source code of the application, wherein the source code includes functional code and test code, the functional code is used to implement the functions of the application, and the test code is used to verify the correctness of the functions of the application;

[0262] Environment type acquisition unit 302 is used to acquire the current environment type of the application;

[0263] The code lookup unit 303 is used to obtain a copy of the original code and look up the test code in the copy when the environment type is a production environment type.

[0264] Code removal unit 304 is used to remove the test code found in the copy to obtain a copy after removing the test code;

[0265] Packaging unit 305 is used to package the copy after removing the test code to obtain an executable file.

[0266] In one implementation, the environment type acquisition unit 302 is specifically configured to detect the application's environment variables through global environment detection attributes, wherein the environment variables reflect the current environment type of the application; or

[0267] Based on the running status of the type plugins, the current environment type of the application is determined. The type plugins include development type plugins and production type plugins. The development type plugins run in the development environment type, and the production type plugins run in the production environment type.

[0268] In one implementation, the code search unit 303 is specifically used to obtain a test folder containing test code;

[0269] Correspondingly, code removal unit 304 is specifically used to remove the test folder from the copy.

[0270] In one implementation, the test code includes commented test code carrying test comment markers;

[0271] The code search unit 303 is specifically used to traverse the copy based on the test comment marker to obtain the comment test code in the copy;

[0272] Correspondingly, the code removal unit 304 is specifically used to remove the commented test code from the copy.

[0273] In one implementation, the code lookup unit 303 is specifically used to parse the copy to obtain an abstract syntax tree, the abstract syntax tree including multiple nodes; and to find the debugger node corresponding to the debugger from the abstract syntax tree;

[0274] Correspondingly, the code removal unit 304 is specifically used to: if the debugger node is found, obtain the environment type; if the environment type is a production environment type, remove the debugger node to obtain an abstract syntax tree after removing the debugger node; and transform the abstract syntax tree after removing the debugger node to obtain a transformation result, which is a copy after removing the test code.

[0275] In one implementation, the code lookup unit 303 is specifically used to parse the copy to obtain an abstract syntax tree, the abstract syntax tree including multiple nodes; for each node of the abstract syntax tree, a type checking function is used to determine whether the node is a function call expression; if the node is a function call expression, the callee attribute of the node is determined to be valid; if the callee attribute of the node is valid, the callee attribute is determined to be a member expression type; if the callee attribute is a member expression type, the name of the called object is obtained, and it is determined whether the object name meets the expectation; if the object name meets the expectation, the node is obtained.

[0276] Correspondingly, the code removal unit 304 is specifically used to remove the node if the processing instruction parameter corresponding to the node is true, and obtain the abstract syntax tree after removing the node; and to transform the abstract syntax tree after removing the node to obtain a transformation result, which is a copy after removing the test code.

[0277] In one embodiment, the device further includes:

[0278] The copy acquisition unit is used to acquire a copy of the original code when the environment type is a development environment type;

[0279] The copy packaging unit is used to package the copy to obtain the executable file.

[0280] In practice, each of the above units can be implemented as an independent entity or can be arbitrarily combined to be implemented as the same or several entities. For the specific implementation of each of the above units, please refer to the previous method embodiments, which will not be repeated here.

[0281] The data processing method provided in this application embodiment can obtain the original code of an application. The original code includes both functional code for implementing the application's functions and test code for verifying the correctness of the application's functions. It also obtains the current environment type of the application. If the environment type is a production environment, it means the application is currently in a production environment. A copy of the original code is then obtained and processed: the test code in the copy is located. The found test code is then removed from the copy, resulting in a copy with the test code removed (i.e., a copy retaining the functional code). This copy is then packaged to obtain an executable file. In this application embodiment, the current running environment of the application can be automatically identified. If the current environment is a production environment, the test code can be identified from the copy of the original code, removed, and the functional code portion retained. The copy with the test code removed (i.e., the retained functional code) is then packaged to obtain an executable file. Since the executable file no longer includes test code, loading time can be shortened when running in a production environment. This application can automatically obtain the current runtime environment and, based on the runtime environment, automatically configure and filter the code that needs to be packaged, avoiding omissions that may occur when manually adjusting configuration items.

[0282] The embodiments of this application can improve development efficiency.

[0283] This application also provides an electronic device, which can be a terminal, a server, or other similar device. The terminal can be a mobile phone, tablet computer, smart Bluetooth device, laptop computer, personal computer, etc.; the server can be a single server or a server cluster composed of multiple servers, etc.

[0284] In some embodiments, the data processing apparatus may also be integrated into multiple electronic devices, such as multiple servers, with the data processing method of this application being implemented by the multiple servers.

[0285] In this embodiment, a server will be used as an example for detailed description. For example, ... Figure 4 As shown, it illustrates a structural schematic diagram of the electronic device involved in the embodiments of this application, specifically:

[0286] The electronic device may include components such as a processor 401 with one or more processing cores, a memory 402 with one or more computer-readable storage media, a power supply 403, an input module 404, and a communication module 405. Those skilled in the art will understand that... Figure 4 The electronic device structure shown does not constitute a limitation on the electronic device and may include more or fewer components than shown, or combine certain components, or have different component arrangements. Wherein:

[0287] The processor 401 is the control center of the electronic device, connecting various parts of the device via various interfaces and lines. It performs various functions and processes data by running or executing software programs and / or modules stored in the memory 402, and by calling data stored in the memory 402. In some embodiments, the processor 401 may include one or more processing cores; in some embodiments, the processor 401 may integrate an application processor and a modem processor, wherein the application processor mainly handles the operating system, user interface, and applications, and the modem processor mainly handles wireless communication. It is understood that the modem processor may also not be integrated into the processor 401.

[0288] The memory 402 can be used to store software programs and modules. The processor 401 executes various functional applications and data processing model training by running the software programs and modules stored in the memory 402. The memory 402 may mainly include a program storage area and a data storage area. The program storage area may store the operating system, at least one application program required for a function (such as sound playback function, image playback function, etc.), etc.; the data storage area may store data created according to the use of the electronic device, etc. In addition, the memory 402 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device. Accordingly, the memory 402 may also include a memory controller to provide the processor 401 with access to the memory 402.

[0289] The electronic device also includes a power supply 403 that supplies power to the various components. In some embodiments, the power supply 403 can be logically connected to the processor 401 through a power management system, thereby enabling functions such as charging, discharging, and power consumption management through the power management system. The power supply 403 may also include one or more DC or AC power supplies, recharging systems, power fault detection circuits, power converters or inverters, power status indicators, and other arbitrary components.

[0290] The electronic device may also include an input module 404, which can be used to receive input digital or character information and generate keyboard, mouse, joystick, optical or trackball signal inputs related to user settings and function control.

[0291] The electronic device may also include a communication module 405. In some embodiments, the communication module 405 may include a wireless module, through which the electronic device can perform short-range wireless transmission, thereby providing users with wireless broadband internet access. For example, the communication module 405 can be used to help users send and receive emails, browse web pages, and access streaming media.

[0292] Although not shown, the electronic device may also include a display unit, etc., which will not be described in detail here. Specifically, in this embodiment, the processor 401 in the electronic device loads the executable files corresponding to the processes of one or more applications into the memory 402 according to the following instructions, and the processor 401 runs the applications stored in the memory 402, thereby realizing the various functions in the various method embodiments of this application, as follows:

[0293] Obtain the application's source code, which includes functional code and test code. The functional code implements the application's functionality, and the test code verifies the application's functional correctness. Obtain the application's current environment type. If the environment type is a production environment, obtain a copy of the source code and locate the test code in the copy. Remove the found test code from the copy to obtain a copy with the test code removed. Package the copy with the test code removed to obtain an executable file.

[0294] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be performed by instructions, or by instructions controlling related hardware. These instructions can be stored in a computer-readable storage medium and loaded and executed by a processor.

[0295] Therefore, embodiments of this application provide a computer-readable storage medium storing instructions that can be loaded by a processor to perform steps in any of the data processing methods provided in embodiments of this application. For example, the instructions can perform the following steps:

[0296] Obtain the application's source code, which includes functional code and test code. The functional code implements the application's functionality, and the test code verifies the application's functional correctness. Obtain the application's current environment type. If the environment type is a production environment, obtain a copy of the source code and locate the test code in the copy. Remove the found test code from the copy to obtain a copy with the test code removed. Package the copy with the test code removed to obtain an executable file.

[0297] The storage medium may include: read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.

[0298] According to one aspect of this application, a computer program product or computer program is provided, comprising instructions stored in a computer-readable storage medium. A processor of a computer device reads the instructions from the computer-readable storage medium and executes the instructions, causing the computer device to perform the methods provided in the various optional implementations of the above embodiments.

[0299] Since the instructions stored in the storage medium can execute the steps of any of the data processing methods provided in the embodiments of this application, the beneficial effects that any of the data processing methods provided in the embodiments of this application can achieve can be realized. For details, please refer to the previous embodiments, which will not be repeated here.

[0300] In this application embodiment, the terms "module" or "unit" refer to a computer program or part of a computer program that has a predetermined function and works with other related parts to achieve a predetermined goal, and can be implemented wholly or partially using software, hardware (such as processing circuitry or memory), or a combination thereof. Similarly, a processor (or multiple processors or memory) can be used to implement one or more modules or units. Furthermore, each module or unit can be part of an overall module or unit that includes the functionality of that module or unit.

[0301] The foregoing has provided a detailed description of a data processing method, apparatus, electronic device, and computer-readable storage medium provided in the embodiments of this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the embodiments above are only for the purpose of helping to understand the method and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.

Claims

1. A data processing method, characterized in that, The method includes: Obtain the source code of the application, wherein the source code includes functional code and test code, the functional code is used to implement the functions of the application, and the test code is used to verify the correctness of the functions of the application; Obtain the current environment type of the application; If the environment type is a production environment type, obtain a copy of the original code and locate the test code in the copy; Remove the test code found in the copy to obtain a copy after removing the test code; The copy after removing the test code is packaged to obtain an executable file.

2. The method as described in claim 1, characterized in that, The step of obtaining the current environment type of the application includes: The application's environment variables are detected through global attribute detection, whereby the environment variables reflect the current environment type of the application; or Based on the running status of the type plugins, the current environment type of the application is determined. The type plugins include development type plugins and production type plugins. The development type plugins run in the development environment type, and the production type plugins run in the production environment type.

3. The method as described in claim 1, characterized in that, The process of finding the test code in the copy includes: Get the test folder containing the test code; The step of removing the test code found in the copy includes: Remove the test folder from the copy.

4. The method as described in claim 1, characterized in that, The test code includes commented test code with test comment markers; The process of finding the test code in the copy includes: Based on the test annotation markers, the copy is traversed to obtain the annotated test code in the copy; The step of removing the test code found in the copy includes: Remove the commented test code from the copy.

5. The method as described in claim 1, characterized in that, The process of finding the test code in the copy includes: The copy is parsed to obtain an abstract syntax tree, which includes multiple nodes; Locate the debugger node corresponding to the debugger in the abstract syntax tree; The step of removing the test code found in the copy includes: If the debugger node is found, the environment type is obtained; If the environment type is a production environment type, then remove the debugger node to obtain the abstract syntax tree after removing the debugger node; The abstract syntax tree after removing the debugger node is transformed to obtain a transformation result, which is a copy after removing the test code.

6. The method as described in claim 1, characterized in that, The process of finding the test code in the copy includes: The copy is parsed to obtain an abstract syntax tree, which includes multiple nodes; For each node of the abstract syntax tree, a type checking function is used to determine whether the node is a function call expression; If the node is a function call expression, then determine whether the callee attribute of the node is valid; If the callee attribute of the node is valid, determine whether the callee attribute is a member expression type; If the called object's property is a member expression type, then obtain the name of the called object and determine whether the object name matches the expectation; If the object name matches the expectation, then obtain the node; The step of removing the test code found in the copy includes: If the processing instruction parameter corresponding to the node is true, then the node is removed, and the abstract syntax tree after removing the node is obtained; The abstract syntax tree after removing the node is transformed to obtain a transformation result, which is a copy after removing the test code.

7. The method as described in claim 1, characterized in that, After obtaining the current environment type of the application, the method further includes: If the environment type is a development environment type, obtain a copy of the original code; The copy is packaged to obtain the executable file.

8. A data processing apparatus, characterized in that, The device includes: The source code acquisition unit is used to acquire the source code of the application, wherein the source code includes functional code and test code, the functional code is used to implement the functions of the application, and the test code is used to verify the correctness of the functions of the application; An environment type acquisition unit is used to acquire the current environment type of the application. The code search unit is used to obtain a copy of the original code and search for test code in the copy when the environment type is a production environment type. The code removal unit is used to remove the test code found in the copy, so as to obtain a copy after removing the test code; The packaging unit is used to package the copy after the test code has been removed to obtain an executable file.

9. An electronic device, characterized in that, It includes a processor and a memory, the memory storing instructions; the processor loads instructions from the memory to perform the steps of the data processing method as described in any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores instructions adapted for loading by a processor to perform the steps of the data processing method according to any one of claims 1 to 7.

11. A computer program product, characterized in that, It includes instructions that, when executed by a processor, implement the steps of the data processing method according to any one of claims 1 to 7.