Web routing packet processing system and method based on abstract syntax tree AST and storage medium

By converting the routing source file into an abstract syntax tree and slicing and grouping, the efficiency of the web front-end development system during startup and compilation is solved, resource management and compilation optimization are realized, and development efficiency is significantly improved.

CN119225733APending Publication Date: 2024-12-31SHENZHEN FENGYI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411292279.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-14
Publication Date
2024-12-31

AI Technical Summary

Technical Problem

The existing web front-end development system needs to load and compile all pages when starting and compiling, resulting in too long startup and compilation time, which seriously affects development efficiency.

Method used

The web routing packet processing system based on abstract syntax tree AST is adopted. By converting the routing source file into an abstract syntax tree structure, slicing and grouping, unnecessary resource loading is reduced, and startup and compilation by grouping is realized.

Benefits of technology

Through grouping processing, the compilation time is significantly reduced, development efficiency is improved, and resource management and compilation optimization are realized.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119225733A_ABST
    Figure CN119225733A_ABST
Patent Text Reader

Abstract

The invention discloses a web routing packet processing method based on an abstract syntax tree AST, and the method comprises the following steps: S1, loading a routing file of a web project based on a routing file loader, and obtaining a routing configuration file from a project directory; s2, slicing and grouping the routing source file; and S3, performing grouping starting and compiling on the items according to a slice grouping result. According to the method, firstly, the development source code is converted into an abstract syntax tree structure, then, the route source file is sliced, finally, the sliced files are arranged and grouped according to the sequence of the slices, and after grouping is completed, starting and compiling can be conducted according to the groups, so that unnecessary resource loading is reduced, and development efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of web routing group processing, and in particular to a web routing group processing system, method and storage medium based on an abstract syntax tree (AST). Background Art

[0002] At present, with the iteration and growth of Internet companies' businesses, especially those involved in the field of web (global wide area network) front-end development, their internal software systems are becoming increasingly large. Most companies' operating systems have hundreds or even thousands of pages, but the existing development system will load all these pages every time it is started (because the routing of the web project is to connect all the pages in series, all of them will be loaded by default), which will greatly increase the startup and compilation time (generally, for a project with about 500 pages, the startup time is about 3 minutes to 6 minutes, and the compilation time is about 15 minutes), which seriously affects the development efficiency. Therefore, it needs to be improved. Summary of the invention

[0003] The purpose of the present invention is to provide a web routing grouping processing system, method and storage medium based on an abstract syntax tree AST. The present invention first converts the development source code into an abstract syntax tree structure, then slices the routing source file, and finally arranges the sliced ​​files in order of slices. After the grouping is completed, they can be started and compiled separately according to the groups to reduce unnecessary resource loading and improve development efficiency.

[0004] In order to achieve the above purpose, the following technical solutions are adopted:

[0005] A web routing grouping processing system based on abstract syntax tree AST, including

[0006] A routing file loader, which is used to load routing files of a web project;

[0007] An abstract syntax tree parser, which is used to parse the routing source file and convert the routing source file into an abstract syntax tree AST format, and then preliminarily group the routing nodes in the AST format according to the grouping identifier;

[0008] A routing slicer, which is used to slice each group of routing nodes and generate a number of slice files;

[0009] A routing grouper, which is used to specifically group the generated slice files;

[0010] A start-up compilation controller is used to control the start-up and compilation of the project according to the grouping result.

[0011] Furthermore, the routing slicer slices the routing nodes according to a predetermined slice size, wherein the slice size is set based on the type of file and the expected transmission efficiency, and when slicing, it is necessary to ensure that the boundaries of the slices do not destroy key information in the file, wherein the key information includes the integrity of the routing table entries.

[0012] Furthermore, the routing grouper groups the slice files according to a predetermined grouping rule, wherein the grouping rule is determined based on the nature of the slice files, the requirements of the target node, and the status of the transmission link; the routing grouper is also used to sort the slice files in each group according to the order of the slice files.

[0013] A web routing group processing method based on an abstract syntax tree AST is also provided, which adopts the web routing group processing system based on an abstract syntax tree AST, and comprises the following steps:

[0014] S1: Load the routing file of the web project based on the routing file loader and obtain the routing configuration file from the project directory;

[0015] S2: Slice and group the routing source files;

[0016] S3: Start and compile the projects in groups according to the slice grouping results.

[0017] Furthermore, the S2 specifically includes the following steps:

[0018] S21: Parse the routing source file based on the abstract syntax tree parser, and convert the routing source file into an abstract syntax tree AST format;

[0019] S22: Preliminarily grouping the routing nodes in the AST format according to the grouping identifier;

[0020] S23: Based on the routing slicer, slice each grouped routing node to generate several slice files;

[0021] S24: Based on the routing grouper, the generated slice files are specifically grouped.

[0022] Furthermore, in S24, the routing grouper groups the slice files according to a predetermined grouping rule, wherein the grouping rule is determined based on the properties of the slice files, the requirements of the target node, and the status of the transmission link.

[0023] Furthermore, in S24, the routing grouper will sort the slice files in each group according to the sequence of the slice files.

[0024] Furthermore, in the S3, command line tool parameters are used to control the startup and compilation of the project.

[0025] Furthermore, command line tool parameters are used to control the startup and compilation of the project, including the following steps:

[0026] Create a command line configuration object cliConfig;

[0027] Set an option so that the command-line tool does not store options as attributes of the program instance;

[0028] Add an option --name, which should be followed by one or more names ( <names>), its description is "product name" and its default value is 'customer';

[0029] Add another option --team, which needs to be followed by a team name ( <team>), its description is "Enable by group", and its default value is also 'customer'.

[0030] A computer-readable storage medium is also provided, wherein the computer-readable storage medium stores a computer program, wherein the computer program is suitable for being loaded and executed by a processor, so that a computer device having the processor executes the above method.

[0031] By adopting the above scheme, the beneficial effects of the present invention are:

[0032] The present invention utilizes the abstract syntax tree AST to perform group processing on web routes, thereby achieving the goals of resource management and compilation optimization. Meanwhile, by filtering and starting projects on demand, unnecessary compilation time is reduced, thereby greatly improving development efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0033] Figure 1 It is a flow chart of the method of the present invention. DETAILED DESCRIPTION

[0034] The present invention is described in detail below in conjunction with the accompanying drawings and specific embodiments.

[0035] Reference Figure 1 As shown, the present invention provides a web routing group processing system based on an abstract syntax tree AST, in one embodiment, including

[0036] A routing file loader, which is used to load routing files of a web project;

[0037] An abstract syntax tree parser, which is used to parse the routing source file and convert the routing source file into an abstract syntax tree AST format, and then preliminarily group the routing nodes in the AST format according to the grouping identifier;

[0038] A routing slicer, which is used to slice each group of routing nodes and generate a number of slice files;

[0039] A routing grouper, which is used to specifically group the generated slice files;

[0040] A start-up compilation controller is used to control the start-up and compilation of the project according to the grouping result.

[0041] In this embodiment, the routing file loader can load the routing configuration files of the web project. These files usually define the routing structure of the web application, including information such as paths, views and controllers. The routing file loader first needs to identify the location and format of the routing file in the web project. Once the routing file is identified, the loader will use the file system API to read the file content. After reading the file content, the loader needs to perform a preliminary analysis of the content to ensure that it conforms to the expected format and structure. At the same time, in order to improve efficiency, the loader can implement a caching mechanism to cache the loaded routing files to avoid repeated loading of the same file. In addition, the loader also has error handling capabilities and can handle abnormal situations such as file non-existence, permission issues, format errors, etc., and provide clear error messages.

[0042] As for the abstract syntax tree parser, it first reads the source code of the routing file (these files usually contain code that defines the web application routing, such as URL paths, processing functions, and middleware), and then uses predefined syntax rules to convert the source code into AST (AST is a tree data structure in which each node represents a structure in the source code, such as an expression, statement, or declaration). In the routing file, a node represents a routing definition, parameter, or processing function; after the AST is constructed, the parser preliminarily groups the routing nodes according to a preset grouping identifier. The grouping identifier can be a comment mark, a specific code structure, or metadata to indicate how to group the routing logic. For example, in this embodiment, one of the grouping identifiers is: team="sales".

[0043] For the routing slicer, the routing slicer slices the routing nodes according to a predetermined slice size, wherein the slice size is set according to the type of file and the expected transmission efficiency, and when slicing, it is necessary to ensure that the boundaries of the slices do not destroy the key information in the file, wherein the key information includes the integrity of the routing table entries.

[0044] The routing slicer will decide how to split each group of routing nodes into multiple slices based on the predetermined slice size and strategy. The slice size is set based on the file type and expected transmission efficiency to ensure optimal resource loading and application response without sacrificing performance. At the same time, during the slicing process, the routing slicer ensures that the boundaries of the slices will not destroy key information in the file, such as the integrity of the routing table items, that is, the slicing operation needs to be performed at logically coherent points to avoid splitting a logically complete routing definition into different slices. Once the boundaries and contents of the slices are determined, the routing slicer will generate each slice as an independent file (the routing slicer can use specific algorithms to determine the best slicing points, such as greedy algorithms, dynamic programming or other heuristic methods to ensure the efficiency and effectiveness of slicing). These files can be JavaScript modules, CSS files or any other format suitable for web applications.

[0045] For the routing grouper, the routing grouper will group the slice files according to predetermined grouping rules, wherein the grouping rules are determined based on the nature of the slice files, the requirements of the target nodes, and the status of the transmission link; the routing grouper is also used to sort the slice files in each group according to the order of the slice files.

[0046] The main uses of the routing grouper are as follows:

[0047] Rule definition: The routing grouper works based on a set of predetermined grouping rules, which define how to assign slice files to different groups. The rules can be based on a variety of factors, including but not limited to the nature of the file (such as functional modules, page types), the needs of the target node (such as specific user roles or device types), and the status of the transmission link (such as network bandwidth, latency);

[0048] File evaluation: The routing grouper evaluates each slice file (e.g., analyzing the file's metadata, content features, or matching with specific user requirements) to determine which grouping rules they meet;

[0049] Grouping decision: Based on the evaluation results, the routing grouper assigns each slice file to one or more groups;

[0050] Sorting process: Within each group, the routing grouper is also responsible for sorting the slice files.

[0051] In summary, the web routing grouping processing system based on the abstract syntax tree AST provided by the present invention first converts the development source code into an abstract syntax tree structure, then slices the routing source file, and finally arranges the sliced ​​files in order of slices. After the grouping is completed, they can be started and compiled separately according to the groups to reduce unnecessary resource loading and improve development efficiency.

[0052] In addition, a web routing group processing method based on an abstract syntax tree AST is also provided, which adopts the above-mentioned web routing group processing system based on an abstract syntax tree AST, and includes the following steps:

[0053] S1: Load the routing file of the web project based on the routing file loader and obtain the routing configuration file from the project directory.

[0054] S2: Slice and group the routing source files.

[0055] The S2 specifically includes the following steps:

[0056] S21: Parse the routing source file based on the abstract syntax tree parser, and convert the routing source file into an abstract syntax tree AST format;

[0057] S22: Preliminarily grouping the routing nodes in the AST format according to the grouping identifier;

[0058] S23: Based on the routing slicer, slice each grouped routing node to generate several slice files;

[0059] S24: Based on the routing grouper, the generated slice files are specifically grouped.

[0060] In S24, the routing grouper groups the slice files according to a predetermined grouping rule, wherein the grouping rule is determined based on the properties of the slice files, the requirements of the target node, and the status of the transmission link.

[0061] In S24, the routing grouper will also sort the slice files in each group according to the sequence of the slice files.

[0062] When grouping, you can define a function called filterRoutes, which receives a parameter option of type FilterRoutesOption and returns a string, which is the filtered source code. The purpose of this function is to filter out qualified routes from the routing configuration file of the web project. The specific steps are as follows:

[0063] 1) Deconstruct the filter attribute from the option parameter;

[0064] 2) Get the source code by calling the getSourceCode function and passing option as a parameter;

[0065] 3) If filter is not a function, the source code is returned directly without any processing;

[0066] 4) If the source code is empty, then return an empty string;

[0067] 5) Use the parse function to parse the source code and generate an abstract syntax tree (AST). Here, the source code type is specified as module, and the jsx and typescript plug-ins are enabled;

[0068] 6) Check if the source code contains the string const router. This check is to determine whether the main router file is being processed, usually config / router.tsx in the project directory;

[0069] 7) If a const router is found, traverse the abstract syntax tree (AST) to find a node of type ObjectProperty;

[0070] 8) For each ObjectProperty node, check whether its key name is routes and its value is an object expression (ObjectExpression);

[0071] 9) If a route configuration node is found, the filter function is used to filter the attribute list of this object. The getRouteInfo function is used to obtain the information of each route, and then the filter function is used to decide whether to keep the route;

[0072] 10) Use the generator function to convert the modified abstract syntax tree back to source code;

[0073] 11) Finally, return the newly generated source code.

[0074] In general, the function filters out qualified routes from a specific routing configuration file based on the provided filtering conditions (filter function) and returns the modified source code.

[0075] S3: Start and compile the projects in groups according to the slice grouping results.

[0076] In S3, command line tool parameters are used to control the startup and compilation of the project.

[0077] It uses command line tool parameters to control the startup and compilation of the project, including the following steps:

[0078] Create a command line configuration object cliConfig;

[0079] Set an option so that the command-line tool does not store options as attributes of the program instance;

[0080] Add an option --name, which should be followed by one or more names ( <names>), its description is "product name", and the default value is 'customer(startup project name demo)';

[0081] Add another option --team, which needs to be followed by a team name ( <team>), its description is "Enable by group", and its default value is also 'customer'.

[0082] In addition, a computer-readable storage medium is also provided, wherein the computer-readable storage medium stores a computer program, and the computer program is suitable for being loaded and executed by a processor so that a computer device having the processor performs the above method. The computer-readable storage medium may be an internal storage unit of a computer device, such as a hard disk or memory of the computer device. The computer-readable storage medium may also be an external storage device of the computer device, such as a plug-in hard disk, a smart memory card (smart media card, SMC), a secure digital (securedigital, SD) card, a flash card (flash card), etc. equipped on the computer device. Further, the computer-readable storage medium may also include both an internal storage unit of the computer device and an external storage device. The computer-readable storage medium is used to store the computer program and other programs and data required by the computer device. The computer-readable storage medium may also be used to temporarily store data that has been output or is to be output.

[0083] The above are only preferred embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the protection scope of the present invention.< / team> < / names> < / team> < / names>

Claims

1. A web routing group processing system based on an abstract syntax tree AST, characterized in that: Including a routing file loader, the routing file loader is used to load the routing file of the web project; An abstract syntax tree parser, which is used to parse the routing source file and convert the routing source file into an abstract syntax tree AST format, and then preliminarily group the routing nodes in the AST format according to the grouping identifier; A routing slicer, which is used to slice each group of routing nodes and generate a number of slice files; A routing grouper, which is used to specifically group the generated slice files; A start-up compilation controller is used to control the start-up and compilation of the project according to the grouping result.

2. According to claim 1, the web routing group processing system based on the abstract syntax tree AST is characterized in that: The routing slicer slices the routing nodes according to a predetermined slice size, wherein the slice size is set according to the type of file and the expected transmission efficiency. When slicing, it is necessary to ensure that the boundaries of the slices do not destroy the key information in the file, wherein the key information includes the integrity of the routing table entries.

3. The web routing grouping processing system based on the abstract syntax tree AST according to claim 2 is characterized in that: The routing grouper groups the slice files according to a predetermined grouping rule, wherein the grouping rule is determined based on the nature of the slice files, the requirements of the target node and the status of the transmission link; the routing grouper is also used to sort the slice files in each group according to the order of the slice files.

4. A web routing group processing method based on an abstract syntax tree AST, using the web routing group processing system based on an abstract syntax tree AST as described in any one of claims 1 to 3, characterized in that: The steps include: S1: Load the routing file of the web project based on the routing file loader and obtain the routing configuration file from the project directory; S2: Slice and group the routing source files; S3: Start and compile the projects in groups according to the slice grouping results.

5. The web routing grouping processing method based on the abstract syntax tree AST according to claim 4 is characterized in that: The S2 specifically includes the following steps: S21: Parse the routing source file based on the abstract syntax tree parser, and convert the routing source file into an abstract syntax tree AST format; S22: Preliminarily grouping the routing nodes in the AST format according to the grouping identifier; S23: Based on the routing slicer, slice each grouped routing node to generate several slice files; S24: Based on the routing grouper, the generated slice files are specifically grouped.

6. The web routing grouping processing method based on the abstract syntax tree AST according to claim 5 is characterized in that: In S24, the routing grouper groups the slice files according to a predetermined grouping rule, wherein the grouping rule is determined based on the properties of the slice files, the requirements of the target node, and the status of the transmission link.

7. The web routing grouping processing method based on the abstract syntax tree AST according to claim 6 is characterized in that: In S24, the routing grouper will also sort the slice files in each group according to the sequence of the slice files.

8. The web routing grouping processing method based on the abstract syntax tree AST according to claim 4 is characterized in that: In S3, command line tool parameters are used to control the startup and compilation of the project.

9. The web routing grouping processing method based on the abstract syntax tree AST according to claim 8 is characterized in that: Use command line tool parameters to control the startup and compilation of the project, including the following steps: Create a command line configuration object cliConfig; Set an option so that the command-line tool does not store options as attributes of the program instance; Add an option --name, which should be followed by one or more names ( <names> ), its description is "product name" and its default value is 'customer';< / names> Add another option --team, which needs to be followed by a team name ( <team> ), its description is "Enable by group", and its default value is also 'customer'.< / team> 10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and the computer program is suitable for being loaded and executed by a processor, so that a computer device having the processor executes the method according to any one of claims 4 to 9.