Rollup-based condition rendering method, system, equipment and medium
By setting conditional rendering key-value pairs in the Rollup configuration file and identifying the conditional code in the source code, the problem of lack of correlation and flexibility in the conditional rendering in the Rollup module packaging tool is solved, and more efficient development and maintenance is achieved.
Patent Information
- Application Number
- CN202411511125.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-28
- Publication Date
- 2025-02-14
AI Technical Summary
When using the Rollup module packaging tool in front-end development, the conditional rendering process lacks the correlation and flexibility between the rendering code and the source code, making it difficult to achieve automated parsing and rendering.
By setting conditional rendering key-value pairs in Rollup's configuration file, identifying the conditional code in the source code, generating the rendering value, and conditional rendering based on the value, the flexible association and automatic analysis between the rendering code and the source code are achieved.
Reduces development complexity and maintenance costs, improves the correlation between rendering code and source code, and makes conditional rendering more flexible and automated.
Smart Images

Figure CN119440608A_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of computer technology, and in particular, relates to a rollup-based conditional rendering method, system, device and medium. Background Art
[0002] In the development of front-end development, modular development is an important trend. Modular development makes the code clearer and easier to maintain, and also improves the reusability of the code. Rollup is a popular JavaScript module packaging tool that can help developers package multiple modules into a complete library or application. During the packaging process, Rollup will automatically load and use the configured plug-ins to perform code conversion, compression and other operations to generate rendering code.
[0003] In the actual software development process, it is usually necessary to decide whether to render the above rendering code according to different conditions. Specifically, the rendering of the rendering code on the source code is usually controlled by conditional compilation instructions. However, the above rendering process usually depends on the preprocessor of the compiler, and there is a lack of association between the rendering code and the source code. The rendering code and the source code are not flexible and configurable, and it is difficult to perform automatic parsing and rendering.
[0004] To sum up, there are still deficiencies in conditional rendering when using the Rollup module packaging tool in front-end development. Summary of the invention
[0005] The embodiments of the present application provide a rollup-based conditional rendering method, system, device and medium, which can solve one of the above-mentioned problems in the prior art.
[0006] In a first aspect, an embodiment of the present application provides a conditional rendering method based on rollup, including:
[0007] Setting a conditional rendering key-value pair in a Rollup configuration file, wherein the conditional rendering key-value pair is used to indicate the rendering of a rendering code in a source code, wherein the rendering code represents code content to be rendered;
[0008] identifying source code and extracting conditional code in the source code;
[0009] Based on the conditional rendering key-value pair, generating a rendering value of the conditional code;
[0010] The source code is conditionally rendered based on the rendering value.
[0011] Furthermore, the conditional rendering key-value pair is set in the Rollup configuration file, including:
[0012] Defining a call object for the conditional rendering key-value pair, wherein the call object is used to associate the rendering code with the source code;
[0013] In the source code, by calling the calling object, the key of the conditional rendering key-value pair is associated with the source code and the rendering code, and the rendering code to be rendered is determined by the value of the conditional rendering key-value pair.
[0014] Furthermore, the source code is provided with a conditional configuration module, the conditional configuration module includes a conditional comment block, a conditional option and a code block option, the conditional option is used to represent the conditional code of each rendering code, and the code block option is used to represent the rendering code;
[0015] The identifying source code and extracting the conditional code in the source code includes:
[0016] Using a predefined comment syntax to identify the start position and end position of the conditional comment block;
[0017] By determining whether each line of the source code contains the identifier of the starting position or the ending position, a conditional rendering region in the source code is obtained, wherein the conditional rendering region is used to encapsulate the conditional option and the code block option in a conditional rendering code;
[0018] The conditional code in the conditional rendering code is identified by using a regular expression matching method.
[0019] Furthermore, generating the rendering value of the conditional code based on the conditional rendering key-value pair includes:
[0020] Splitting the conditional code into at least one conditional expression according to the judgment logic;
[0021] Based on the judgment logic and the conditional expression, construct an abstract syntax tree of the conditional code;
[0022] Each node in the abstract syntax tree is traversed, and a rendering value of the conditional code is determined by comparing the conditional expression corresponding to the node with the conditional rendering key-value pair, where the rendering value includes a true value and a false value.
[0023] Furthermore, the conditional rendering of the source code based on the rendering value includes:
[0024] If the rendering value is a true value, the conditional configuration module is replaced with the rendering code in the code block option by string concatenation to generate a construction code;
[0025] If the rendering value is a false value, the conditional configuration module is deleted from the source code by string concatenation.
[0026] Furthermore, before replacing the conditional configuration module with the rendering code in the code block option and generating the construction code, the method includes:
[0027] Acquire multiple code versions generated by conditional rendering, and use the multiple code versions as target codes to be tested;
[0028] Generate a set of test cases with different condition combinations based on pre-defined test rules and boundary conditions;
[0029] Read the test case set through the test framework, and perform automated testing on the plurality of target codes in sequence;
[0030] During the test execution process, the output result of the target code is obtained, the output result is compared with the preset result, and a pre-test report is generated.
[0031] Furthermore, replacing the conditional configuration module with the rendering code in the code block option and generating the build code includes:
[0032] Associating and mapping the construction code with the pre-test report, and establishing an association model between the construction code and the test report;
[0033] Parsing the pre-test report in the association model to obtain key indicator data, the key indicator data including test coverage, number of failed cases and test pass rate;
[0034] Classifying the build code into corresponding quality levels according to the build quality score;
[0035] For the build code that meets the preset quality level, the build code is deployed in the target environment and the build code is compiled.
[0036] In a second aspect, an embodiment of the present application provides a rollup-based conditional rendering system, including:
[0037] A first processing module: used to set a conditional rendering key-value pair in a Rollup configuration file, wherein the conditional rendering key-value pair is used to indicate the rendering of a rendering code in a source code, wherein the rendering code represents code content to be rendered;
[0038] The second processing module is used to identify the source code and extract the conditional code in the source code;
[0039] A third processing module: used to generate a rendering value of the conditional code based on the conditional rendering key-value pair;
[0040] A fourth processing module is used to conditionally render the source code based on the rendering value.
[0041] In a third aspect, an embodiment of the present application provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above-mentioned rollup-based conditional rendering method when executing the computer program.
[0042] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, including a computer-readable storage medium storing a computer program, and when the computer program is executed by a processor, the above-mentioned rollup-based conditional rendering method is implemented.
[0043] Compared with the prior art, the embodiments of the present invention have the following beneficial effects:
[0044] The present application discloses a conditional rendering method based on Rollup. By setting conditional rendering key-value pairs, developers can easily manage code blocks for different environments without having to manually write complex build scripts or configurations, which reduces the complexity of development and maintenance costs. In addition, through conditional rendering key-value pairs, the calling object can receive conditional options and code block options of the source code, and conditionally render the source code according to the above options during the build process, thereby improving the association between the rendering code and the source code, allowing the rendering code and the source code to be flexibly configured, and realizing automated parsing and rendering. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0046] Figure 1 is a flowchart of a conditional rendering method based on rollup provided by an embodiment of the present invention;
[0047] Figure 2 is a structural diagram of a rollup-based conditional rendering system provided by an embodiment of the present invention;
[0048] Figure 3 It is a structural diagram of a computer device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0049] In the following description, specific details such as specific system structures, technologies, etc. are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application may also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present application.
[0050] It should be understood that when used in the present specification and the appended claims, the term "comprising" indicates the presence of described features, wholes, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or combinations thereof.
[0051] It should also be understood that the term “and / or” used in the specification and appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes these combinations.
[0052] As used in the specification and appended claims of this application, the term "if" can be interpreted as "when" or "uponce" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrase "if it is determined" or "if [described condition or event] is detected" can be interpreted as meaning "uponce it is determined" or "in response to determining" or "uponce [described condition or event] is detected" or "in response to detecting [described condition or event]", depending on the context.
[0053] In addition, in the description of the present application specification and the appended claims, the terms "first", "second", "third", etc. are only used to distinguish the descriptions and cannot be understood as indicating or implying relative importance.
[0054] References to "one embodiment" or "some embodiments" etc. described in the specification of this application mean that one or more embodiments of the present application include specific features, structures or characteristics described in conjunction with the embodiment. Therefore, the statements "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear in different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways.
[0055] See also Figure 1 As shown, the present invention is a conditional rendering method based on rollup, comprising the following steps:
[0056] S100, setting a conditional rendering key-value pair in a Rollup configuration file, wherein the conditional rendering key-value pair is used to indicate the rendering of a rendering code in a source code, wherein the rendering code represents code content to be rendered;
[0057] In the actual development process, it is usually necessary to conditionally select to include or exclude certain code parts according to different build environments or build platforms. For example, some debugging codes may need to be included in the development environment, while these codes need to be excluded in the production environment. In addition, the operation of Rollup usually starts with the configuration of its configuration file. Therefore, in this embodiment, by setting the conditional rendering key-value pair in the configuration file of Rollup, the configuration of the conditional rendering key-value pair determines which code blocks in the source code should be rendered. Specifically, the key of the conditional rendering key-value pair represents the name of the conditional option, and the value of the conditional rendering key-value pair represents the incoming string corresponding to the conditional option.
[0058] In some embodiments, the above step S100 includes:
[0059] Defining a call object for the conditional rendering key-value pair, wherein the call object is used to associate the rendering code with the source code;
[0060] In the source code, by calling the calling object, the key of the conditional rendering key-value pair is associated with the source code and the rendering code, and the rendering code to be rendered is determined by the value of the conditional rendering key-value pair.
[0061] In this embodiment, in order to associate the rendering code with the source code, a calling object is defined for the conditional rendering key-value pair. In actual applications, the source code returns the conditional options required for rendering conditions as input parameters to Rollup by calling the above-mentioned calling object, wherein the input parameters include the name of the conditional option and the rendering string of the conditional option. Rollup assigns the key of the conditional rendering key-value pair to the name of the above-mentioned conditional option based on the input parameters, and then associates the source code with the rendering code, and assigns the value of the conditional rendering key-value pair to the above-mentioned rendering string, and determines whether the rendering code needs to be rendered into the source code through the rendering string.
[0062] Specifically, in the configuration file of rollup, a calling object, such as conditionRende, can be defined. ConditionRende is used as a conditional rendering plug-in. The plug-in can be used to render the rendering code by the source code. In addition, conditionRende usually includes multiple conditional rendering key-value pairs, that is, conditionRende can define multiple conditional options for conditional rendering. In one embodiment, the calling object can be expressed as conditionRende({_PLATFORM:PLATFORM}, {_OS:OS}).
[0063] S200, identifying source code, and extracting conditional code in the source code;
[0064] In some embodiments, the source code is provided with a conditional configuration module, the conditional configuration module includes a conditional comment block, a conditional option and a code block option, the conditional option is used to represent a conditional code of each rendering code, and the code block option is used to represent the rendering code;
[0065] In this embodiment, each rendering code to be rendered is written in the source code, and the relevant rendering conditions are identified by traversing each line of code in the source code, and compared with the conditional configuration key-value pairs in the calling object, so as to determine the rendering code to be retained. Specifically, the rendering code and the rendering conditions of each rendering code are merged to generate a conditional configuration module. At the same time, in order to facilitate the identification of the conditional configuration module, a conditional comment block is introduced in the above-mentioned conditional configuration module. The conditional comment block increases the maintainability of the code. When it is necessary to modify or add new rendering conditions, the developer can directly update or add new conditional configurations in the conditional comment block, thereby avoiding direct coding in the code logic and reducing the risk of errors caused by code modifications.
[0066] The above step S200 includes:
[0067] Using a predefined comment syntax to identify the start position and end position of the conditional comment block;
[0068] By determining whether each line of the source code contains the identifier of the starting position or the ending position, a conditional rendering region in the source code is obtained, wherein the conditional rendering region is used to encapsulate the conditional option and the code block option in a conditional rendering code;
[0069] The conditional code in the conditional rendering code is identified by using a regular expression matching method.
[0070] In this embodiment, the code line between the start position and the end position of the conditional comment block is the conditional rendering code. The above conditional rendering code includes a conditional code and a rendering code. The conditional code refers to the conditional option, and the rendering code refers to the code block option. By parsing the conditional code, it is determined whether the corresponding rendering code meets the rendering condition.
[0071] In this embodiment, special strings are set for the start position and the end position of the conditional comment block respectively, and then the strings at the start position and the end position are parsed through the predefined comment syntax to determine the corresponding conditional rendering area.
[0072] In a preferred embodiment, the start mark of the start position of the conditional comment block is " / *#if", and the end mark of the end position is " / / #endif* / ", and the regular expression method is used to identify the relevant string. Specifically, when identifying the source code, a line-by-line reading method can be adopted, and the regular expression method can be used to determine whether each line contains the above-mentioned start mark or end mark. When encountering a start mark, a string matching algorithm, such as the KMP algorithm, can be used to extract the code block after the start mark until the end mark is encountered. The extracted code block can be stored in the conditional rendering code for subsequent processing.
[0073] For the above-mentioned start mark " / *#if" and the above-mentioned end mark " / / #endif* / ", during the application process, the two marks are merged to generate the comment symbol " / *....* / ". Specifically, " / *....* / " is usually used as a mark for multi-line comments in most programming languages. The above-mentioned comment method allows developers to add instructions, notes or temporarily disable certain code segments in the code without affecting the execution of the program. Therefore, in this embodiment, the above-mentioned comment symbol is used, so that the rendering code that is not determined to be rendered is ignored by the compiler and the interpreter, and is not executed as part of the program, thereby ensuring the executableness of the source code and the practicality of the conditional rendering method.
[0074] The configuration method of the conditional configuration module of the present application can be applied to applications of different channels, such as WeChat channel and Douyin channel. During development, WeChat channel and Douyin channel apply a set of codes, and where there are differences, the code wrapped by / *#if and / / #endif* / is used to handle the business differences of different channels. Finally, different parameters are provided during compilation to render the code of the specified channel. As a result, developers can easily manage code blocks for different environments without manually writing complex build scripts or configurations, which reduces development complexity and maintenance costs.
[0075] S300, generating a rendering value of the rendering condition based on the conditional rendering key-value pair;
[0076] In some embodiments, the step S300 includes:
[0077] Splitting the conditional code into at least one conditional expression according to the judgment logic;
[0078] Based on the judgment logic and the conditional expression, construct an abstract syntax tree of the conditional code;
[0079] Each node in the abstract syntax tree is traversed, and a rendering value of the conditional code is determined by comparing the conditional expression corresponding to the node with the conditional rendering key-value pair, where the rendering value includes a true value and a false value.
[0080] It is understandable that a source code usually includes multiple rendering conditions, and multiple rendering conditions can be encapsulated in one conditional code through multiple conditional expressions. Therefore, when obtaining the rendering value of the rendering condition, it is necessary to parse the conditional code to obtain multiple conditional expressions, and determine the final rendering value by judging the multiple conditional expressions in turn.
[0081] In this embodiment, a method of constructing an abstract syntax tree is adopted to convert the conditional code into judgment logic executable by the program. Specifically, the nodes of the abstract syntax tree are corresponded to each conditional expression of the conditional code, and each conditional expression is compared with the conditional rendering key-value pair. For example, in one embodiment, there is a conditional object conditionRende({_PLATFORM:DY}, {_OS:linux}), and a conditional expression of the conditional code is _PLATFORM=='DY', which means that the conditional expression matches a conditional rendering key-value pair of the calling object, and the conditional expression is assigned to 1 at this time; if there is another conditional expression in the conditional code, _OS=='linux', it means that the conditional expression matches another conditional rendering key-value pair of the calling object, and it is assigned to 1. Through the logical result of the conditional code, it is determined that the rendering value of the above embodiment is true, which means that the rendering code corresponding to the conditional code needs to be rendered into the source code.
[0082] S400: Conditionally render the source code based on the rendering value.
[0083] In some embodiments, the step S400 includes:
[0084] If the rendering value is a true value, the conditional configuration module is replaced with the rendering code in the code block option by string concatenation to generate a construction code;
[0085] If the rendering value is a false value, the conditional configuration module is deleted from the source code by string concatenation.
[0086] It can be understood that in this embodiment, according to actual development needs, the number of conditional configuration modules set in the source code can be multiple. For example, in one embodiment, the code blocks related to the conditional configuration modules in the source code are as follows:
[0087] / *#if
[0088] _PLATFORM=='WX'
[0089] Console.log('This is WeChat channel')
[0090] / / #endif* /
[0091] / *#if_PLATFORM=='DY'
[0092] Console.log('This is the Douyin channel')
[0093] / / #endif* /
[0094] In the above embodiment, _PLATFORM=='WX' and _PLATFORM=='DY' respectively represent the conditional codes of the two conditional configuration modules, and Console.log('This is the WeChat channel') and Console.log('This is the Douyin channel') respectively represent the rendering codes of the two conditional configuration modules. The corresponding rendering code can be determined by calling the incoming parameters returned by the object. If the returned incoming parameters are {_PLATFORM:DY}, it can be determined through the above step S300 that the corresponding rendering code in the conditional configuration module with the conditional code _PLATFORM=='DY' should be retained in the source code at this time. Specifically, the conditional configuration module is replaced with Console.log('This is the WeChat channel') by string concatenation, and the other conditional configuration module is deleted from the source code.
[0095] In this embodiment, the conditional configuration module usually contains a complex code structure, and a simple string replacement cannot accurately replace the conditional configuration module with the rendering code. Therefore, in other embodiments, an abstract syntax tree or regular expression method is usually used to replace the conditional configuration module with the rendering code.
[0096] In some embodiments, before replacing the conditional configuration module with the rendering code in the code block option and generating the build code, the process includes:
[0097] Acquire multiple code versions generated by conditional rendering, and use the multiple code versions as target codes to be tested;
[0098] Generate a set of test cases with different condition combinations based on pre-defined test rules and boundary conditions;
[0099] Read the test case set through the test framework, and perform automated testing on the plurality of target codes in sequence;
[0100] During the test execution process, the output result of the target code is obtained, the output result is compared with the preset result, and a pre-test report is generated.
[0101] In this embodiment, in order to ensure the smooth execution of the generated build code, before the conditional configuration module is replaced with the rendering code, the pre-generated build code is tested and a pre-test report is generated, so that syntax errors, logic errors or performance issues that may exist in the code can be discovered and resolved before the actual replacement operation, thereby avoiding difficult-to-debug errors after the final build code is generated, thereby saving time and resources.
[0102] Specifically, multiple code versions are generated according to multiple conditional configuration modules in the source code. Based on pre-defined test rules and boundary conditions, multiple test case sets are generated using test case generation tools such as JUnit or TestNG. Test frameworks such as Selenium or PyTest are used to read the generated test cases and perform automated testing on each code version. Assuming that the test case set contains 100 test cases, the test framework simulates different condition combinations to verify the target code. During the test execution process, the actual output results of the code are recorded in real time through the logging and result capture mechanism, and the actual output results are compared with the expected results. If there is any inconsistency, the test failure is recorded and a detailed pre-test report is generated.
[0103] In some embodiments, replacing the conditional configuration module with the rendering code in the code block option and generating the build code includes:
[0104] Associating and mapping the construction code with the pre-test report, and establishing an association model between the construction code and the test report;
[0105] Parsing the pre-test report in the association model to obtain key indicator data, the key indicator data including test coverage, number of failed cases and test pass rate;
[0106] Analyze and evaluate the key indicator data according to preset build quality evaluation rules to generate a build quality score;
[0107] Classifying the build code into corresponding quality levels according to the build quality score;
[0108] For the build code that meets the preset quality level, the build code is deployed in the target environment and the build code is compiled.
[0109] In this embodiment, the test results of the test cases of each code version displayed in the pre-test report are obtained to perform statistics and analysis on the test results, establish a mapping relationship table between the build code and the test results, use regular expressions to parse the test result file, and extract key quality indicators such as test coverage, number of failed cases, and test pass rate. For example, the test coverage is 80%, the number of failed cases is 5, and the test pass rate is 95%. According to the preset evaluation rules, the weighted average algorithm is used to comprehensively evaluate the key data of the above indicators to generate a build quality score of 0-100 points. The key indicator data and the scoring results are filled into the predefined report template to generate a build quality report document. The quality report document is classified using the support vector machine (SVM) algorithm to determine whether the quality level of the build code is excellent, good, general or poor. For build codes with poor quality levels, code analysis tools such as SonarQube are used to identify weak links and potential defects in the code. For example, it is found that a certain section of code has a null pointer exception under specific conditions, resulting in test failure. The analysis results are automatically generated into a defect report and directly pushed to the development team through an integrated development environment (IDE) such as Eclipse or IntelliJ IDEA. When the build code is generated, the development team can locate the problem code in time and optimize and fix it according to the defect report. For example, for null pointer exceptions, the necessary null value check logic is added, and a new round of automated testing process is carried out on the repaired code to ensure the correctness of the build code.
[0110] See also Figure 2 As shown, the present invention also provides a rollup-based conditional rendering system, the system comprising:
[0111] The first processing module 201 is used to set a conditional rendering key-value pair in a Rollup configuration file, where the conditional rendering key-value pair is used to indicate the rendering of a rendering code in a source code, where the rendering code represents code content to be rendered;
[0112] The second processing module 202 is used to identify the source code and extract the conditional code in the source code;
[0113] The third processing module 203 is used to generate a rendering value of the conditional code based on the conditional rendering key-value pair;
[0114] The fourth processing module 204 is configured to perform conditional rendering on the source code based on the rendering value.
[0115] It is understandable that if Figure 1 The contents of the rollup-based conditional rendering method embodiment shown in the figure are all applicable to the present rollup-based conditional rendering system embodiment. The functions specifically implemented by the present rollup-based conditional rendering system embodiment are similar to those in the present rollup-based conditional rendering method embodiment. Figure 1 The conditional rendering method embodiment based on rollup is the same as shown, and the beneficial effects achieved are the same as those of Figure 1 The beneficial effects achieved by the rollup-based conditional rendering method embodiment shown are also the same.
[0116] It should be noted that the information interaction, execution process and other contents between the above-mentioned systems are based on the same concept as the embodiment of the method of the present invention. Their specific functions and technical effects can be found in the method embodiment part and will not be repeated here.
[0117] Those skilled in the art can clearly understand that, for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In practical applications, the above-mentioned function allocation can be completed by different functional units and modules as needed, that is, the internal structure of the system can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.
[0118] See also Figure 3 As shown, an embodiment of the present invention further provides a computer device 3, comprising: a memory 302 and a processor 301 and a computer program 303 stored in the memory 302. When the computer program 303 is executed on the processor 301, a rollup-based conditional rendering method as described in any one of the above methods is implemented.
[0119] The computer device 3 may be a computing device such as a desktop computer, a notebook, a PDA, or a cloud server. The computer device 3 may include, but is not limited to, a processor 301 and a memory 302. Those skilled in the art will appreciate that Figure 3It is only an example of computer device 3 and does not constitute a limitation on computer device 3. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components, for example, it may also include input and output devices, network access devices, etc.
[0120] The processor 301 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.
[0121] In some embodiments, the memory 302 may be an internal storage unit of the computer device 3, such as a hard disk or memory of the computer device 3. In other embodiments, the memory 302 may also be an external storage device of the computer device 3, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped on the computer device 3. Further, the memory 302 may also include both an internal storage unit of the computer device 3 and an external storage device. The memory 302 is used to store an operating system, an application program, a boot loader (BootLoader), data, and other programs, such as the program code of the computer program, etc. The memory 302 may also be used to temporarily store data that has been output or is to be output.
[0122] An embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the rollup-based conditional rendering method described in any one of the above methods is implemented.
[0123] In this embodiment, if the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the processes in the above-mentioned embodiment method, which can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a computer-readable storage medium. When the computer program is executed by the processor, the steps of the above-mentioned various method embodiments can be implemented. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium can at least include: any entity or device that can carry the computer program code to the camera / computer device, recording medium, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electric carrier signal, telecommunication signal and software distribution medium. For example, USB flash drive, mobile hard disk, disk or optical disk. In some jurisdictions, according to legislation and patent practice, computer-readable media cannot be electric carrier signals and telecommunication signals.
[0124] The embodiments described above are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, a person skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.
Claims
1. A conditional rendering method based on rollup, characterized in that: include: Setting a conditional rendering key-value pair in a Rollup configuration file, wherein the conditional rendering key-value pair is used to indicate the rendering of a rendering code in a source code, wherein the rendering code represents code content to be rendered; identifying source code and extracting conditional code in the source code; Based on the conditional rendering key-value pair, generating a rendering value of the conditional code; The source code is conditionally rendered based on the rendering value.
2. The method according to claim 1, characterized in that The conditional rendering key-value pairs are set in the Rollup configuration file, including: Defining a call object for the conditional rendering key-value pair, wherein the call object is used to associate the rendering code with the source code; In the source code, by calling the calling object, the key of the conditional rendering key-value pair is associated with the source code and the rendering code, and the rendering code to be rendered is determined by the value of the conditional rendering key-value pair.
3. The method according to claim 1, characterized in that The source code is provided with a conditional configuration module, the conditional configuration module includes a conditional comment block, a conditional option and a code block option, the conditional option is used to represent the conditional code of each rendering code, and the code block option is used to represent the rendering code; The identifying source code and extracting the conditional code in the source code includes: Using a predefined comment syntax to identify the start position and end position of the conditional comment block; By determining whether each line of the source code contains the identifier of the starting position or the ending position, a conditional rendering region in the source code is obtained, wherein the conditional rendering region is used to encapsulate the conditional option and the code block option in a conditional rendering code; The conditional code in the conditional rendering code is identified by using a regular expression matching method.
4. The method according to claim 3, characterized in that The step of generating a rendering value of the conditional code based on the conditional rendering key-value pair includes: Splitting the conditional code into at least one conditional expression according to the judgment logic; Based on the judgment logic and the conditional expression, construct an abstract syntax tree of the conditional code; Each node in the abstract syntax tree is traversed, and a rendering value of the conditional code is determined by comparing the conditional expression corresponding to the node with the conditional rendering key-value pair, where the rendering value includes a true value and a false value.
5. The method according to claim 4, characterized in that The conditionally rendering the source code based on the rendering value includes: If the rendering value is a true value, the conditional configuration module is replaced with the rendering code in the code block option by string concatenation to generate a construction code; If the rendering value is a false value, the conditional configuration module is deleted from the source code by string concatenation.
6. The method according to claim 5, characterized in that The step of replacing the conditional configuration module with the rendering code in the code block option and generating the construction code includes: Acquire multiple code versions generated by conditional rendering, and use the multiple code versions as target codes to be tested; Generate a set of test cases with different condition combinations based on pre-defined test rules and boundary conditions; Read the test case set through the test framework, and perform automated testing on the plurality of target codes in sequence; During the test execution process, the output result of the target code is obtained, the output result is compared with the preset result, and a pre-test report is generated.
7. The method according to claim 6, characterized in that The conditional configuration module is replaced with the rendering code in the code block option, and after the build code is generated, it includes: Associating and mapping the construction code with the pre-test report, and establishing an association model between the construction code and the test report; Parsing the pre-test report in the association model to obtain key indicator data, the key indicator data including test coverage, number of failed cases and test pass rate; Classifying the build code into corresponding quality levels according to the build quality score; For the build code that meets the preset quality level, the build code is deployed in the target environment and the build code is compiled.
8. A rollup-based conditional rendering system, characterized in that: include: A first processing module: used to set a conditional rendering key-value pair in a Rollup configuration file, wherein the conditional rendering key-value pair is used to indicate the rendering of a rendering code in a source code, wherein the rendering code represents code content to be rendered; The second processing module is used to identify the source code and extract the conditional code in the source code; A third processing module: used to generate a rendering value of the conditional code based on the conditional rendering key-value pair; A fourth processing module is used to conditionally render the source code based on the rendering value.
9. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the method according to any one of claims 1 to 7 is implemented.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.