AST syntax analysis-based applet construction optimization method and device, medium and equipment

By adopting AST syntax analysis technology in the construction of mini-programs, the problems of slow compilation speed and long debugging in the existing technology are solved, and a more efficient business module integration and compilation packaging process is achieved.

CN119645408APending Publication Date: 2025-03-18ZHAOLIAN CONSUMER FINANCE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411476994.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-22
Publication Date
2025-03-18

AI Technical Summary

Technical Problem

During the integration and packaging of business modules, existing applets adopt regular matching replacement methods to slow compilation speed, long debugging, and inability to effectively analyze the context of the code.

Method used

AST syntax analysis technology is used to replace regular matching replacement, and the source code of the applet is processed to realize the integration and compilation and packaging of business modules. The specific steps include reading the configuration file, downloading the source code of the business module, processing the source code through AST analysis, injecting it into the shell project for integration, and performing alias conversion, routing configuration and asynchronous subcontracting processing.

Benefits of technology

It improves the efficiency of analyzing and processing files, reduces the time-consuming process of debugging and production construction of mini programs, and achieves a faster integration and compilation process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119645408A_ABST
    Figure CN119645408A_ABST
Patent Text Reader

Abstract

The invention discloses an AST syntax analysis-based applet construction optimization method and device, a medium and equipment, and the method comprises the steps: reading a configuration file under a source code root directory, obtaining the configuration information of a plurality of service modules required by a target applet, the configuration information at least comprising the names and version numbers corresponding to the plurality of service modules; according to the obtained configuration information, downloading a plurality of source codes of the service modules from an npm server; and performing AST grammar analysis processing on the source codes of the plurality of npm packets, injecting the processed source codes into a shell project of a target applet to integrate the plurality of service modules, and compiling and packaging to obtain the target applet. According to the method, in the process of integrating the business modules of the applet, the AST grammar analysis is adopted to replace an existing regular matching replacement mode, so that the file analysis and processing efficiency is improved, and the time consumption for debugging, producing and constructing the applet is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of Internet technology, and in particular to a small program construction optimization method, device, medium and equipment based on AST syntax analysis. Background Art

[0002] With the saturation of the APP market, most users have already developed usage habits, and it is difficult for new APPs to survive in the market. Mini programs are applications that can be used without downloading and installing. They have the advantages of small size, fast response speed and low development cost.

[0003] Existing mini-programs use regular matching and replacement to integrate and package various business modules. Shell projects integrate multiple sub-packaged project codes through source code, which has slow compilation speed and long modification and debugging stages. AST (Abstract Syntax Tree) syntax analysis (parse) ignores the code style and parses the code into the purest syntax tree. Therefore, the conversion based on AST is more accurate and rigorous. Using regular expressions to analyze and convert code cannot effectively analyze the context of a piece of code. Even matching simple rules requires considering too many boundary conditions and being compatible with various code styles. In addition, regular expressions are inefficient in processing long strings.

[0004] Therefore, how to apply AST syntax analysis in the construction of mini-programs is a technical problem that needs to be solved urgently. Summary of the invention

[0005] In view of the above problems, the present invention is proposed to provide a small program construction optimization method, device, medium and equipment based on AST syntax analysis that overcome the above problems or at least partially solve the above problems.

[0006] Other features and advantages of the present invention will become apparent from the following detailed description, or may be learned in part by practice of the present invention.

[0007] According to a first aspect of an embodiment of the present invention, a method for optimizing the construction of a small program based on AST syntax analysis is provided, and the method for optimizing the construction of a small program based on AST syntax analysis includes:

[0008] Read the configuration file in the source code root directory to obtain the configuration information of multiple business modules required by the target applet, wherein the configuration information at least includes the names and version numbers corresponding to the multiple business modules;

[0009] According to the acquired configuration information, the source codes of the multiple business modules are downloaded from the npm server, and each of the business modules is independently published as an npm package;

[0010] By performing AST syntax analysis on the source codes of the multiple npm packages, the processed source codes are injected into the shell project of the target applet to integrate the multiple business modules, and the target applet is obtained after compilation and packaging.

[0011] In some embodiments of the present invention, performing AST syntax analysis on the source codes of the multiple npm packages and injecting the processed source codes into the shell project of the target applet to integrate the multiple business modules includes:

[0012] By performing AST syntax analysis on the source code, each of the npm packages is subjected to alias conversion processing, and the aliases after conversion between the npm packages are different;

[0013] Register the configuration information of each of the npm packages after the alias conversion process and the routing information in the source code into the routing configuration of the shell project, so that the shell project can access each of the npm packages after the alias conversion process through the routing information;

[0014] Perform asynchronous sub-packaging on npm packages that need to be cross-packed, so that the cross-packaging content in the npm packages after asynchronous sub-packaging can be used asynchronously after waiting for download;

[0015] The processed source code is injected into the shell project of the target applet to integrate the multiple business modules.

[0016] In some embodiments of the present invention, performing alias conversion processing on each of the npm packages includes:

[0017] When writing the source code of each npm package into the src source code directory of the shell project, the source code of each npm package is subjected to AST syntax analysis, and a business module encoding prefix is ​​added to the alias configuration in the source code and written into the webpack packaging configuration in the shell project, and a business module encoding prefix is ​​added to the reference to the alias configuration in the source code to obtain the npm package after alias conversion, and the aliases after conversion are different between the npm packages.

[0018] In some embodiments of the present invention, the step of registering the configuration information of each of the npm packages and the routing information in the source code after the alias conversion process into the routing configuration of the shell project further includes:

[0019] Read the configuration information of each of the npm packages after the alias conversion process and the routing information in the source code;

[0020] According to the way each of the npm packages is integrated, the route access path registered in the route configuration of the shell project is confirmed through AST syntax analysis.

[0021] In some embodiments of the present invention, confirming the routing access path registered in the routing configuration of the shell project according to the way each of the npm packages is integrated includes:

[0022] When the npm package integration method is to perform subpackage integration, the npm package as a subpackage is written into the subPackages object;

[0023] The npm package integration method is to write the npm package as the main package into the top-level pages object when performing main package integration.

[0024] In some embodiments of the present invention, the asynchronous sub-packaging of the npm package that needs to be cross-packed includes:

[0025] Confirm the npm packages that need to be cross-packaged;

[0026] Through AST syntax analysis, the npm package that needs to cross sub-packages is changed from the original import path of importing UI components from the main package or its own sub-package to importing from the asynchronous sub-package, and placeholder configurations are automatically added for the pages and corresponding components that use the components in the asynchronous sub-package.

[0027] In some embodiments of the present invention, after integrating the plurality of business modules, the method further includes:

[0028] Confirm the pending service module that needs to be debugged, and pass the package name of the pending service module as a command line parameter;

[0029] Perform AST semantic analysis on the entry file in the shell project of the target applet according to the command line parameters to confirm the necessary subpackaging of the business module to be processed;

[0030] The business module to be processed is trimmed, and after trimming and removing the remaining business subpackages in the business module to be processed except the necessary subpackages, the entry file in the shell project is regenerated.

[0031] According to a second aspect of an embodiment of the present invention, a small program construction optimization device based on AST syntax analysis is provided, and the small program construction optimization device based on AST syntax analysis includes:

[0032] A configuration acquisition module, used to read the configuration file in the source code root directory to obtain the configuration information of multiple business modules required by the target applet, wherein the configuration information at least includes the names and version numbers corresponding to the multiple business modules;

[0033] A source code download module, used to download the source code of multiple business modules from the npm server according to the acquired configuration information, and each business module is independently published as an npm package;

[0034] The integration processing module is used to perform AST syntax analysis on the source codes of multiple npm packages, inject the processed source codes into the shell project of the target applet to integrate the multiple business modules, and obtain the target applet after compiling and packaging.

[0035] According to a third aspect of an embodiment of the present invention, a computer-readable storage medium is provided, in which computer program instructions are stored. The computer program instructions are loaded and executed by a processor to implement the operations performed by any of the methods described above.

[0036] According to a fourth aspect of an embodiment of the present invention, there is provided an electronic device, comprising a processor and a memory, wherein the memory stores computer program instructions that can be executed by the processor, and when the processor executes the computer program instructions, it implements instructions of any of the methods described above.

[0037] The technical solution provided in the embodiments of the present invention has at least the following technical effects or advantages:

[0038] The embodiments of the present invention provide a method, device, medium and equipment for mini-program construction optimization based on AST syntax analysis. The method for mini-program construction optimization based on AST syntax analysis described in the embodiments of the present invention uses AST syntax analysis to replace the existing regular matching replacement method during the integration of various business modules of the mini-program, thereby improving the efficiency of analyzing and processing files and reducing the time consumption of mini-program debugging and production construction.

[0039] The above description is only an overview of the technical solution of the present invention. In order to more clearly understand the technical means of the present invention, it can be implemented according to the contents of the specification. In order to make the above and other purposes, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are listed below. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0041] Figure 1 A flowchart of a method for optimizing the construction of a small program based on AST syntax analysis provided by an embodiment of the present invention;

[0042] Figure 2 A schematic diagram of the principle structure of a small program construction optimization device based on AST syntax analysis provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0043] Exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings.

[0044] Various structural schematic diagrams according to embodiments of the present disclosure are shown in the accompanying drawings. These figures are not drawn to scale, and some details are magnified and some details may be omitted for the purpose of clear expression. The shapes of various regions and layers shown in the figures and the relative sizes and positional relationships therebetween are only exemplary, and may deviate in practice due to manufacturing tolerances or technical limitations, and those skilled in the art may further design regions / layers with different shapes, sizes, and relative positions according to actual needs.

[0045] In the context of the present disclosure, when a layer / element is referred to as being "on" another layer / element, the layer / element may be directly on the other layer / element, or there may be an intervening layer / element therebetween. Additionally, if a layer / element is "on" another layer / element in one orientation, the layer / element may be "below" the other layer / element when the orientation is reversed. In the context of the present disclosure, similar or identical components may be denoted by the same or similar reference numerals.

[0046] In order to better understand the above-mentioned technical scheme, the above-mentioned technical scheme will be described in detail below in combination with specific implementation methods. It should be understood that the embodiments of the present disclosure and the specific features in the embodiments are detailed descriptions of the technical scheme of the present invention, rather than limitations on the technical scheme of the present invention. In the absence of conflict, the embodiments of the present invention and the technical features in the embodiments can be combined with each other.

[0047] Figure 1 : is a flowchart of a small program construction optimization method based on AST syntax analysis provided by an embodiment of the present invention, such as Figure 1 As shown, the small program construction optimization method based on AST syntax analysis includes the following steps:

[0048] S1. Read the configuration file in the source code root directory to obtain the configuration information of multiple business modules required by the target applet, wherein the configuration information at least includes the names and version numbers corresponding to the multiple business modules;

[0049] In an embodiment of the present invention, the configuration file under the source code root directory is read through the terminal of the source code root directory to obtain the configuration information of multiple business modules required by the target applet, wherein the source code root directory (Source CodeRoot Directory) refers to the top-level directory containing all source code files of the project. This directory is the starting point of the project structure, and usually contains the configuration files, source code files, resource files (such as images, audio, etc.), documents and possible other subdirectories of the project, which further organize codes and resources. The terminal (Terminal) of the source code root directory can also be a command line interface (Command Line Interface, CLI), and the terminal of the source code root directory is a text interface that allows users to interact with the computer system by inputting commands. In the terminal, users can perform various operations, such as file operations (create, delete, move files, etc.), program compilation, running scripts, managing user accounts, code management, etc. Specifically in an embodiment of the present invention, the configuration file under the source code root directory is read through the terminal of the source code root directory.

[0050] For example, in an embodiment of the present invention, the command madp compose is entered in the terminal of the source code root directory to perform code integration of the target applet. The madp compose command reads the configuration file in config.json in the source code root directory to obtain the version number corresponding to each business module, and then downloads the source code of each business module from the npm server to inject it into the shell project of the target applet to complete the required business module integration.

[0051] It should be noted that the integration of the business modules in the embodiment of the present invention is used to integrate each business module into the shell project accordingly to obtain the target applet.

[0052] Among them, the shell project is used to integrate all business modules and provide the unique implementation of the application, the dependency management tool gradle, the application's homepage configuration and the application's homepage source code, and integrate the above codes and tools into a complete application (that is, the target applet in the embodiment of the present invention).

[0053] The business modules are used to perform different business functions, including but not limited to borrowing, repayment, login, etc. The corresponding business modules are borrowing module, repayment module, login module, etc. Each business module is independent of each other and has no dependency relationship with each other. The source codes of each business module are independent of each other. After the development is completed, the relevant packaging commands are executed, and the source code is sent to the npm server in the form of an npm package to wait for integration and assembly in the shell project of the target applet. For example, the source code of each business module can be managed using a separate gitlab repository. The source code of each business module is developed and managed separately and does not overlap with each other, so that each business module can perform functional iteration or repair separately to improve work efficiency.

[0054] Of course, in other embodiments of the present invention, the shell project of the target applet may also include a basic module, and the basic module is used to implement basic capabilities, such as but not limited to image loading function, network request function, log function, UI function, etc. The basic module can serve as the basis for supporting the business module, and the basic components can be used to provide the basic functions required by the business module.

[0055] The configuration information includes at least the names and version numbers corresponding to the multiple business modules. In other embodiments of the present invention, the configuration information may also include attribute information, description information or other related information of each business module. The attribute information includes, for example, the communication interface configuration information of the configuration platform, plug-in configuration information, whether the business module is a main package or a sub-package, etc. The description information is used to record the text description corresponding to each business module.

[0056] S2. According to the acquired configuration information, the source codes of the multiple business modules are downloaded from the npm server, and each business module is independently published as an npm package;

[0057] In an embodiment of the present invention, the source codes corresponding to all business modules are stored in the npm server. Based on the acquired configuration information, the various business modules required by the target mini-program and the version numbers corresponding to each business module can be determined, thereby downloading the source codes corresponding to multiple business modules from the npm server based on the names and version numbers of the business modules.

[0058] In an embodiment of the present invention, each of the business modules is independently published as an npm package, rather than directly integrating multiple subpackaged business modules through source code, which facilitates subsequent functional iteration or repair of each business module to improve work efficiency.

[0059] S3. Perform AST syntax analysis on the source codes of the multiple npm packages, inject the processed source codes into the shell project of the target applet to integrate the multiple business modules, and obtain the target applet after compiling and packaging.

[0060] The embodiment of the present invention uses AST syntax analysis to replace the regular matching replacement method to achieve the integration of the business modules, improve the efficiency of analyzing and processing files, and reduce the time consumption of debugging and production building of small programs. Specifically, the embodiment of the present invention performs AST syntax analysis on the source code of multiple npm packages, and injects the processed source code into the shell project of the target small program to integrate multiple business modules, including: performing AST syntax analysis on the source code, performing alias conversion processing on each of the npm packages, and the aliases after conversion between each of the npm packages are different; registering the configuration information of each of the npm packages after the alias conversion processing and the routing information in the source code into the routing configuration of the shell project, so that the shell project can access each of the npm packages after the alias conversion processing through the routing information; injecting the processed source code into the shell project of the target small program to integrate multiple business modules.

[0061] Among them, the embodiment of the present invention performs alias conversion processing on each of the npm packages separately, including: when writing the source code of each npm package into the src source code directory of the shell project, by performing AST syntax analysis processing on the source code of each of the npm packages, adding a business module coding prefix to the alias configuration in the source code and writing it into the webpack packaging configuration in the shell project, and adding a business module coding prefix to the reference of the alias configuration in the source code to obtain the npm package after alias conversion, and the aliases after conversion between the npm packages are different.

[0062] Since the absolute path of the source code of each business module changes during the integration process, the problem of alias not being able to point correctly when referencing file resources will occur. Therefore, the embodiment of the present invention performs alias conversion processing during the source code integration process, adds a namespace, and simplifies the module reference path by configuring an alias for the module. Specifically, after downloading the source code of each business module from the npm server through the configuration file, the embodiment of the present invention writes the source code of each business module into the src source code directory of the shell project through the file operation API provided by node.js; in the process of writing the source code, through AST syntax analysis, the business module encoding prefix is ​​added to the alias configuration in the source code of the business module and written into the webpack configuration in the shell project; at the same time, the reference to the alias configuration in the business module source code also adds the business module encoding prefix; in the embodiment of the present invention, the business module accepts an alias object and a string encoding prefix, and then adds this encoding prefix to the value of each alias, so that a prefix can be added to all business module references at one time, while maintaining consistency in the project, it also makes the business module reference more concise and clear.

[0063] For example, the namespace published by the business module corresponding to the subpackage is distinguished from the namespace published by the current npm package, and the name of the subpackage package.json can be named, for example, @mumod / xx, where xx is the name of the current business module.

[0064] When performing alias conversion processing, the embodiment of the present invention replaces the existing regular matching replacement method with AST syntax analysis, thereby improving the efficiency of analyzing and processing files.

[0065] Optionally, the embodiment of the present invention registers the configuration information of each of the npm packages after alias conversion and the routing information in the source code into the routing configuration of the shell project, and also includes: reading the configuration information of each of the npm packages after alias conversion and the routing information in the source code; according to the integration method of each of the npm packages, confirming the routing access path registered in the routing configuration of the shell project through AST syntax analysis.

[0066] When performing routing configuration processing, the embodiment of the present invention reads the pages routing configuration of the app.jsx of the business module, uniformly registers the routing URL information in the routing configuration of the app.jsx of the shell project, and replaces the existing regular matching replacement method with AST syntax analysis, thereby improving the efficiency of analyzing and processing files.

[0067] The integration methods of each of the npm packages include sub-package integration and main package integration. In this embodiment of the present invention, according to the integration methods of each of the npm packages, confirming that the routing access path registered in the routing configuration of the shell project includes:

[0068] When the npm package integration method is to perform subpackage integration, the npm package as a subpackage is written into the subPackages object. For example, when performing subpackage integration, the access rule of the route may be: [root]+[pages], that is, apply / pages / index / index.

[0069] The npm package integration method is to write the npm package as the main package into the top-level pages object when the main package is integrated. Then, when it is integrated as the main package (only one main package is allowed), the access rules of the route remain unchanged.

[0070] In the target applet, the sub-packages of different business modules correspond to different download units in the npm server, that is, the download resources corresponding to each business module are obtained through a corresponding download unit, and the sub-packages of different business modules cannot use custom components or perform dependency requirements on each other. Due to the size limit of the applet sub-package (for example, the WeChat sub-package is 2M), the npm packages generated by the packaging of each business module may have the risk of over-packaging. Therefore, after the embodiment of the present invention performs alias configuration processing and route configuration processing on the npm packages respectively, the embodiment of the present invention performs asynchronous sub-packaging processing on the npm packages that need to cross sub-packages, so that the cross-sub-package content in the npm packages after asynchronous sub-packaging processing can be used asynchronously after waiting for download, including: confirming the npm packages that need to cross sub-packages; through AST syntax analysis, changing the npm packages that need to cross sub-packages from the original import path of importing UI components from the main package or its own sub-package to importing from asynchronous sub-packages, and automatically adding placeholder configurations for pages and corresponding components that use components in asynchronous sub-packages.

[0071] Specifically, the embodiment of the present invention changes the import path of UI components from the main package or its own sub-package to import from the asynchronous sub-package, for example:

[0072] The original import path import{TestComponent}from'@ / @npm / testBag / component is changed to import{TestComponent}from'@ / npm / asyncbag / component, where asyncbag is the name of the asynchronous subpackage.

[0073] At the same time, placeholder configurations are automatically added to the pages and other corresponding components that use the components in the asynchronous sub-package. The placeholders are used to be replaced with corresponding cross-sub-package components later.

[0074] When performing asynchronous packet processing, the embodiment of the present invention replaces the existing regular matching replacement method with AST syntax analysis, thereby improving the efficiency of analyzing and processing files.

[0075] After injecting the processed source code into the shell project of the target applet to integrate the multiple business modules, the embodiment of the present invention compiles and packages to obtain the target applet. In the embodiment of the present invention, the shell project specifies the version of each business module in the config.json configuration file, and integrates the source code of each business module through the cli command madp compose. If the business module requires functional iteration or repair, the corresponding npm version is released for iteration, and the shell project is notified to repackage and release the entire package of the applet. There is no need to republish for the H5 end, because the business modules are accessed by providing links.

[0076] After integrating multiple business modules to obtain the target mini-program, in order to narrow the scope of development and debugging packaging, an embodiment of the present invention also includes: confirming the business module to be processed that needs to be debugged, and passing the package name of the business module to be processed as a command line parameter; performing AST semantic analysis on the entry file in the shell project of the target mini-program according to the command line parameter, and confirming the necessary subpackages of the business module to be processed; trimming the business module to be processed, trimming and eliminating the remaining business subpackages in the business module to be processed except the necessary subpackages, and regenerating the entry file in the shell project.

[0077] The embodiment of the present invention is based on AST syntax analysis technology to confirm the necessary subpackages contained in the minimum running content of the pending business module that needs to be debugged. By providing the ability to tailor business subpackages, developers can achieve the minimum compilation content of the mini-program, greatly reducing the compilation time in the development phase. By locally debugging a single business subpackage, the mini-program compilation time is reduced from more than 20 minutes to less than five minutes, greatly improving the compilation efficiency.

[0078] Specifically, the embodiment of the present invention uses the terminal input clipping command madp clip in the source code root directory, and the subpackage name that needs to be debugged is passed in. The entry file of the target applet is analyzed and replaced through AST syntax analysis, and the business module subpackage that the developer needs to debug is added to the minimum running content. The entry file is the unified entry of the front-end SPA project. The aforementioned business module integration process will add the page routing of each business module to the entry file; for example, the shell project of the target applet integrates the three business modules of loan, repayment, and apply through the madp compose command described above. After the construction and packaging are tested, it is found that only the loan module has a bug and needs to be debugged again. Then, the package name loan that needs to be debugged can be passed as a command line parameter by using the madp clip command. Madp clip will perform AST analysis on the entry file app.jsx in the shell project according to the passed parameters, retain the necessary subpackages that need to be debugged and the login subpackages required for debugging, and at the same time eliminate all other irrelevant business subpackages, and regenerate the entry file of the shell project of the applet, which greatly reduces the files required to be compiled during debugging and improves the compilation and construction speed of the applet.

[0079] Compared with the prior art, the mini-program construction optimization method based on AST syntax analysis described in the embodiment of the present invention uses AST syntax analysis to replace the existing regular matching replacement method for alias configuration processing, routing configuration processing and asynchronous subpackaging processing during the integration of various business modules of the mini-program, thereby improving the efficiency of file analysis and processing, reducing the time consumption of mini-program debugging and production construction, and conveniently traversing and modifying (transform) code files, and performing semantic analysis, optimization and code generation (generate) on the grammatical structure. The efficiency is far higher than regular matching, and the mini-program integration business module stage time can be reduced from 20 minutes to less than 10 minutes; at the same time, in the mini-program debugging stage, AST syntax analysis can also be used to narrow the development and debugging packaging scope, confirm the necessary subpackaging for optimization and debugging, and provide the ability to tailor business subpackaging. Developers can achieve the minimum compilation content of the mini-program, greatly reducing the compilation time in the development stage, optimizing the development experience, and improving development efficiency. By locally debugging a single business subpackaging, the mini-program compilation time can be reduced from more than 20 minutes to less than five minutes.

[0080] Based on the above embodiment, as the above Figure 1 The present invention provides an embodiment of a small program construction optimization device based on AST syntax analysis, and the device embodiment is similar to Figure 1 Corresponding to the method embodiment shown, the device can be specifically applied to various electronic devices, see Figure 2As shown, the mini-program construction optimization device based on AST syntax analysis includes:

[0081] The configuration acquisition module 100 is used to read the configuration file in the source code root directory to obtain the configuration information of multiple business modules required by the target applet, wherein the configuration information at least includes the names and version numbers corresponding to the multiple business modules;

[0082] A source code downloading module 200 is used to download the source code of the plurality of business modules from the npm server according to the acquired configuration information, and each of the business modules is independently published as an npm package;

[0083] The integration processing module 300 is used to perform AST syntax analysis on the source codes of multiple npm packages, inject the processed source codes into the shell project of the target applet to integrate the multiple business modules, and obtain the target applet after compiling and packaging.

[0084] The mini-program construction optimization device based on AST syntax analysis described in the embodiment of the present invention can execute the mini-program construction optimization method based on AST syntax analysis provided in the above embodiment. The mini-program construction optimization device based on AST syntax analysis has the corresponding functional steps and beneficial effects of the mini-program construction optimization method based on AST syntax analysis described in the above embodiment. Please refer to the above embodiment of the mini-program construction optimization method based on AST syntax analysis for details. The embodiment of the present invention will not be repeated here.

[0085] The embodiment of the present invention also provides an electronic device, which may include a processor and a memory, wherein the processor and the memory may be connected via a bus or other means. The processor may be a central processing unit (CPU). The processor may also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components and other chips, or a combination of the above-mentioned various types of chips. The memory, as a non-transient computer-readable storage medium, can be used to store non-transient software programs, non-transient computer executable programs and modules, such as the program instructions / modules corresponding to the mini-program construction optimization method based on AST syntax analysis in the embodiment of the present invention. The processor executes various functional applications and data processing of the processor by running the non-transient software programs, instructions and modules stored in the memory, that is, the mini-program construction optimization method based on AST syntax analysis in the above method embodiment is realized.

[0086] The memory may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required by at least one function; the data storage area may store data created by the processor, etc. In addition, the memory may include a high-speed random access memory, and may also include a non-transitory memory, such as at least one disk storage device, a flash memory device, or other non-transitory solid-state storage device. The one or more modules are stored in the memory, and when executed by the processor, the small program construction optimization method based on AST syntax analysis in the above method embodiment is executed. The specific details of the above electronic device can be understood by corresponding to the corresponding descriptions and effects in the above method embodiment, and will not be repeated here. Those skilled in the art can understand that all or part of the processes in the above embodiment method can be completed by instructing the relevant hardware through a computer program, and the program can be stored in a computer-readable storage medium, and the program, when executed, may include the processes of the embodiments of the above methods. Among them, the storage medium can be a read-only memory (ROM), a random access memory (RAM), a flash memory (Flash Memory), a hard disk drive (HDD) or a solid-state drive (SSD), etc.; the storage medium can also include a combination of the above types of memory.

[0087] In the description provided herein, a large number of specific details are described. However, it is understood that embodiments of the present invention can be practiced without these specific details. In some instances, well-known methods, structures and techniques are not shown in detail so as not to obscure the understanding of this description.

[0088] Similarly, it should be understood that in order to streamline the present disclosure and aid in understanding one or more of the various inventive aspects, in the above description of exemplary embodiments of the present invention, various features of the present invention are sometimes grouped together into a single embodiment, figure, or description thereof. However, this disclosed method should not be interpreted as reflecting the intention that the claimed invention requires more features than those expressly recited in each claim. Rather, as reflected in the claims, inventive aspects lie in less than all of the features of the individual embodiments previously disclosed. Therefore, the claims that follow the detailed description are hereby expressly incorporated into the detailed description, with each claim itself serving as a separate embodiment of the present invention.

[0089] It should be noted that the above-mentioned embodiments illustrate rather than limit the invention and that those skilled in the art will be able to design alternative embodiments without departing from the scope of the appended claims.

Claims

1. A small program construction optimization method based on AST syntax analysis, characterized in that: The mini-program construction optimization method based on AST syntax analysis includes: Read the configuration file in the source code root directory to obtain the configuration information of multiple business modules required by the target applet, wherein the configuration information at least includes the names and version numbers corresponding to the multiple business modules; According to the acquired configuration information, the source codes of the multiple business modules are downloaded from the npm server, and each of the business modules is independently published as an npm package; By performing AST syntax analysis on the source codes of the multiple npm packages, the processed source codes are injected into the shell project of the target applet to integrate the multiple business modules, and the target applet is obtained after compilation and packaging.

2. The mini-program construction optimization method based on AST syntax analysis according to claim 1 is characterized in that: The step of performing AST syntax analysis on the source codes of the multiple npm packages and injecting the processed source codes into the shell project of the target applet to integrate the multiple business modules includes: By performing AST syntax analysis on the source code, each of the npm packages is subjected to alias conversion processing, and the aliases after conversion between the npm packages are different; Register the configuration information of each of the npm packages after the alias conversion process and the routing information in the source code into the routing configuration of the shell project, so that the shell project can access each of the npm packages after the alias conversion process through the routing information; Perform asynchronous sub-packaging on npm packages that need to be cross-packed, so that the cross-packaging content in the npm packages after asynchronous sub-packaging can be used asynchronously after waiting for download; The processed source code is injected into the shell project of the target applet to integrate the multiple business modules.

3. The mini-program construction optimization method based on AST syntax analysis according to claim 2 is characterized in that: The alias conversion process for each of the npm packages comprises: When writing the source code of each npm package into the src source code directory of the shell project, the source code of each npm package is subjected to AST syntax analysis, and a business module encoding prefix is ​​added to the alias configuration in the source code and written into the webpack packaging configuration in the shell project, and a business module encoding prefix is ​​added to the reference to the alias configuration in the source code to obtain the npm package after alias conversion, and the aliases after conversion are different between the npm packages.

4. The mini-program construction optimization method based on AST syntax analysis according to claim 2 is characterized in that: The configuration information of each of the npm packages after the alias conversion and the routing information in the source code are registered in the routing configuration of the shell project, and further includes: Read the configuration information of each of the npm packages after the alias conversion process and the routing information in the source code; According to the way each of the npm packages is integrated, the route access path registered in the route configuration of the shell project is confirmed through AST syntax analysis.

5. The mini-program construction optimization method based on AST syntax analysis according to claim 4 is characterized in that: According to the way of integrating each of the npm packages, confirming the route access path registered in the route configuration of the shell project includes: When the npm package integration method is to perform subpackage integration, the npm package as a subpackage is written into the subPackages object; The npm package integration method is to write the npm package as the main package into the top-level pages object when performing main package integration.

6. The mini-program construction optimization method based on AST syntax analysis according to claim 2 is characterized in that: The asynchronous sub-packaging process of the npm package that needs to be cross-packed includes: Confirm the npm packages that need to be cross-packaged; Through AST syntax analysis, the npm package that needs to cross sub-packages is changed from the original import path of importing UI components from the main package or its own sub-package to importing from the asynchronous sub-package, and placeholder configurations are automatically added for the pages and corresponding components that use the components in the asynchronous sub-package.

7. The mini-program construction optimization method based on AST syntax analysis according to claim 1 is characterized in that: After integrating the plurality of business modules, the method further includes: Confirm the pending service module that needs to be debugged, and pass the package name of the pending service module as a command line parameter; Perform AST semantic analysis on the entry file in the shell project of the target applet according to the command line parameters to confirm the necessary subpackaging of the business module to be processed; The business module to be processed is trimmed, and after trimming and removing the remaining business subpackages in the business module to be processed except the necessary subpackages, the entry file in the shell project is regenerated.

8. A small program construction optimization device based on AST syntax analysis, applied to the method described in any one of claims 1 to 7, characterized in that: The mini-program construction optimization device based on AST syntax analysis includes: A configuration acquisition module, used to read the configuration file in the source code root directory to obtain the configuration information of multiple business modules required by the target applet, wherein the configuration information at least includes the names and version numbers corresponding to the multiple business modules; A source code download module, used to download the source code of multiple business modules from the npm server according to the acquired configuration information, and each business module is independently published as an npm package; The integration processing module is used to perform AST syntax analysis on the source codes of multiple npm packages, inject the processed source codes into the shell project of the target applet to integrate the multiple business modules, and obtain the target applet after compiling and packaging.

9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer program instructions, which are loaded and executed by a processor to implement the operations performed by the method according to any one of claims 1 to 7.

10. An electronic device comprising a processor and a memory, characterized in that: The memory stores computer program instructions that can be executed by the processor, and when the processor executes the computer program instructions, the processor implements instructions of any one of the methods described in claims 1-7.