AST-based component configuration method, device, equipment and medium

By converting the source code files of the Vue project into AST and automatically filtering components, the problem of low component configuration efficiency and omissions in the Vue project is solved, and automated component configuration and improved test regression efficiency are achieved.

CN114201236BActive Publication Date: 2024-08-27PINGAN YIQIANBAO E COMMERCE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111525738.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-14
Publication Date
2024-08-27
Estimated Expiration
2041-12-14

AI Technical Summary

Technical Problem

In the Vue project, the existing technology requires manual screening and the introduction of components on demand, resulting in missing components and high labor costs. In addition, intuitive data statistics cannot be formed, affecting later test regressions.

Method used

By converting the source code files of the Vue project into an abstract syntax tree (AST), the required components are automatically filtered and converted based on component configuration parameters, and injected into the entry file to achieve automated component configuration.

Benefits of technology

It improves the efficiency and accuracy of component configuration, reduces the problem of missing components, records changes more intuitively by generating log information, and reduces the cost of post-test regression.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114201236B
    Figure CN114201236B
Patent Text Reader

Abstract

The embodiments of the present application provide a method, device, equipment and medium for component configuration based on AST, which belongs to the field of computer technology. The method converts all source code files corresponding to the project into AST, and then obtains the components required to be introduced into the project based on the component configuration parameters. After that, these components that need to be introduced are converted into an AST structure consistent with the entry file, and the converted components are injected into the array object of the entry file AST, thereby realizing automatic configuration of components in the entry file on demand in the Vue project. The method realizes the automated processing of introducing components on demand. For developers, the entire component configuration work can be completed through only one command line, which not only improves efficiency, but also effectively saves manpower. In addition, because AST is highly standardized, the accuracy of automatic processing is high, thereby reducing the problem of component omissions.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a method, apparatus, device and medium for component configuration based on AST. Background Art

[0002] When using a component library in a Vue project, generally only some of the components in the component library are used. However, in the current use process, all components in the component library are usually mounted on the Vue prototype chain in the Vue project entry file, and the entire component is packaged into the production line package during packaging, which easily leads to a larger volume of the production line package, resulting in a poor user experience when the user first enters the page.

[0003] To address the above issues, it is usually necessary to remove the undependent components from the production line package based on the components that the Vue project actually depends on, that is, to introduce the components in the component library on demand. Since global mounting is required, when introducing on demand, it is generally necessary to introduce the components used by the project separately and put them into the project entry file for binding. Currently, this process mainly relies on manual operation. However, manual screening of the components used by each project will not only increase the manpower investment cost as the project complexity increases, but also easily cause component omissions and poor component configuration effects. Summary of the invention

[0004] The present application provides a component configuration method based on AST, which automatically configures Vue components for Vue projects by screening the Vue components that need to be introduced from the AST of the Vue project source code file based on component configuration parameters, and then converts these Vue components into an AST structure consistent with the entry file and injects them into the entry file, thereby avoiding the high error rate caused by the manual introduction of Vue components.

[0005] In a first aspect, a method for component configuration based on AST is provided, wherein the method comprises:

[0006] Get component configuration parameters, where the component configuration parameters are used to indicate the type of Vue component to be configured;

[0007] Get all source code files corresponding to the Vue project, and convert the source code files into an abstract syntax tree AST;

[0008] According to the component configuration parameters, filter the target Vue component from the AST corresponding to the source code file;

[0009] The target Vue component is converted according to the AST structure corresponding to the entry file to obtain the Vue component to be injected, and the structure of the Vue component to be injected is consistent with the AST structure corresponding to the file;

[0010] Inject the Vue component to be injected into the AST corresponding to the entry file, and obtain the target entry file, where the target entry file is configured with the Vue component required by the Vue project.

[0011] According to the AST-based component configuration method provided by this implementation, all source code files corresponding to the project are converted into AST, and then the components required to be introduced into the project are obtained based on the component configuration parameters. After that, these components that need to be introduced are converted into an AST structure consistent with the entry file, and the converted components are injected into the array object of the entry file AST, thereby realizing automatic configuration of components in the entry file on demand in the Vue project. This method realizes the automated processing of introducing components on demand. For developers, the entire component configuration work can be completed through only one command line, which not only improves efficiency, but also effectively saves manpower. In addition, because AST is highly standardized, the accuracy of automatic processing is high, thereby reducing the problem of component omissions.

[0012] In combination with the first aspect, in some implementations of the first aspect, the converting the source code file into an AST specifically includes:

[0013] Performing lexical analysis on the source code file to obtain a lexical token stream corresponding to the source code file;

[0014] Perform grammatical analysis on the lexical token stream to obtain the AST corresponding to the source code file.

[0015] In combination with the first aspect, in some implementations of the first aspect, the method further includes:

[0016] Obtain log information corresponding to the target entry file, wherein the log information includes the file name and file path of the target entry file, the number of Vue components that need to be processed in the process of generating the target entry file, and the names corresponding to the Vue components.

[0017] According to the AST-based component configuration method provided by this implementation, by generating a log to record relevant information during the automatic introduction of components in the entry file, the changed data can be recorded more accurately, and the changed points of each page design can be counted more intuitively, thereby reducing the cost for later test regression.

[0018] In combination with the first aspect, in some implementations of the first aspect, the acquiring component configuration parameters specifically includes:

[0019] receiving a component configuration process trigger instruction input by a user through a command identifier, wherein the component configuration process trigger instruction is used to instruct to start a component configuration process, and the component configuration process trigger instruction includes the component configuration parameter;

[0020] The component configuration parameters are acquired according to the component configuration process trigger instruction.

[0021] In combination with the first aspect, in some implementations of the first aspect, the component configuration parameters include:

[0022] The type of the component to be configured, the name of the component library corresponding to the component to be configured, and the component identifier corresponding to the component to be configured.

[0023] In combination with the first aspect, in some implementations of the first aspect, the component configuration process triggering instruction further includes a path corresponding to the source code file,

[0024] The acquisition of all source code files corresponding to the Vue project specifically includes:

[0025] Acquire the path corresponding to the source code file according to the component configuration process trigger instruction;

[0026] Through the command identifier, all source code files corresponding to the Vue project are obtained according to the path.

[0027] In combination with the first aspect, in some implementations of the first aspect, the step of filtering the target Vue component from the AST corresponding to the source code file according to the component configuration parameter specifically includes:

[0028] According to the component configuration parameters, a custom Vue component whose type satisfies the type indicated by the component configuration parameters is filtered out from the AST corresponding to the source code file as the target component.

[0029] In a second aspect, a device for component configuration based on AST is provided, which includes:

[0030] A receiving module is used to obtain component configuration parameters, where the component configuration parameters are used to indicate the type of Vue component to be configured; and obtain all source code files corresponding to the Vue project;

[0031] A conversion module, used to convert the source code file into an abstract syntax tree AST;

[0032] A processing module is used to filter the target Vue component from the AST corresponding to the source code file according to the component configuration parameters; convert the target Vue component according to the AST structure corresponding to the entry file to obtain the Vue component to be injected, and the structure of the Vue to be injected is consistent with the AST structure corresponding to the file; inject the Vue component to be injected into the AST corresponding to the entry file to obtain the target entry file, and the target entry file is configured with the Vue component required by the Vue project.

[0033] In combination with the second aspect, in some implementations of the second aspect, the conversion module is specifically used to perform lexical analysis on the source code file to obtain a lexical token stream corresponding to the source code file;

[0034] Perform grammatical analysis on the lexical token stream to obtain the AST corresponding to the source code file.

[0035] In combination with the second aspect, in certain implementations of the second aspect, the processing module is also used to obtain log information corresponding to the target entry file, and the log information includes the file name and file path of the target entry file, the number of Vue components that need to be processed in the process of generating the target entry file, and their corresponding names.

[0036] In conjunction with the second aspect, in some implementations of the second aspect, the receiving module is further configured to receive a component configuration process trigger instruction input by a user through a command identifier, wherein the component configuration process trigger instruction is used to instruct to start a component configuration process, and the component configuration process trigger instruction includes the component configuration parameter;

[0037] The processing module is further configured to acquire the component configuration parameters according to the component configuration process trigger instruction.

[0038] In combination with the second aspect, in some implementations of the second aspect, the processing module is further configured to obtain a path corresponding to the source code file according to the component configuration process trigger instruction;

[0039] Through the command identifier, all source code files corresponding to the Vue project are obtained according to the path.

[0040] In combination with the second aspect, in certain implementations of the second aspect, the processing module is also used to filter out a custom Vue component whose type satisfies the type indicated by the component configuration parameters from the AST corresponding to the source code file as the target component according to the component configuration parameters.

[0041] In a third aspect, a device for component configuration based on AST is provided, including:

[0042] at least one processor;

[0043] at least one memory;

[0044] The memory stores computer-readable program instructions. When the processor executes the computer-readable program instructions, the device performs the following steps:

[0045] Get component configuration parameters, where the component configuration parameters are used to indicate the type of Vue component to be configured;

[0046] Get all source code files corresponding to the Vue project, and convert the source code files into an abstract syntax tree AST;

[0047] According to the component configuration parameters, filter the target Vue component from the AST corresponding to the source code file;

[0048] The target Vue component is converted according to the AST structure corresponding to the entry file to obtain the Vue component to be injected, and the structure of the Vue component to be injected is consistent with the AST structure corresponding to the file;

[0049] Inject the Vue component to be injected into the AST corresponding to the entry file, and obtain the target entry file, where the target entry file is configured with the Vue component required by the Vue project.

[0050] In combination with the third aspect, in some implementations of the third aspect, when the processor runs the computer-readable program instructions, the device performs the following steps:

[0051] Performing lexical analysis on the source code file to obtain a lexical token stream corresponding to the source code file;

[0052] Perform grammatical analysis on the lexical token stream to obtain the AST corresponding to the source code file.

[0053] In combination with the third aspect, in some implementations of the third aspect, when the processor runs the computer-readable program instructions, the device performs the following steps:

[0054] Get the log information corresponding to the target entry file, where the log information includes the file name and file path of the target entry file, the number of Vue components that need to be processed in the process of generating the target entry file, and their corresponding names.

[0055] In combination with the third aspect, in some implementations of the third aspect, when the processor runs the computer-readable program instructions, the device performs the following steps:

[0056] receiving a component configuration process trigger instruction input by a user through a command identifier, wherein the component configuration process trigger instruction is used to instruct to start a component configuration process, and the component configuration process trigger instruction includes the component configuration parameter;

[0057] The component configuration parameters are acquired according to the component configuration process trigger instruction.

[0058] In combination with the third aspect, in some implementations of the third aspect, when the processor runs the computer-readable program instructions, the device performs the following steps:

[0059] The type of the component to be configured, the name of the component library corresponding to the component to be configured, and the component identifier corresponding to the component to be configured.

[0060] In combination with the third aspect, in some implementations of the third aspect, when the processor runs the computer-readable program instructions, the device performs the following steps:

[0061] Acquire the path corresponding to the source code file according to the component configuration process trigger instruction;

[0062] Through the command identifier, all source code files corresponding to the Vue project are obtained according to the path.

[0063] In combination with the third aspect, in some implementations of the third aspect, when the processor runs the computer-readable program instructions, the device performs the following steps:

[0064] According to the component configuration parameters, a custom Vue component whose type satisfies the type indicated by the component configuration parameters is filtered out from the AST corresponding to the source code file as the target component.

[0065] In a fourth aspect, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer-readable program instructions. When the computer-readable program instructions are executed on a computer, the computer executes the AST-based component configuration method as described in any implementation of the first aspect above. BRIEF DESCRIPTION OF THE DRAWINGS

[0066] Figure 1 It is a schematic flowchart of a method for component configuration based on AST provided in an embodiment of the present application.

[0067] Figure 2 It is a code structure schematic flow chart based on AST conversion provided in an embodiment of the present application.

[0068] Figure 3 It is a schematic flowchart of converting the source code file corresponding to the Vue project into AST provided by an embodiment of the present application.

[0069] Figure 4 It is another code structure schematic flowchart based on AST conversion provided in an embodiment of the present application.

[0070] Figure 5 It is a structural diagram of a device for component configuration based on AST provided in an embodiment of the present application.

[0071] Figure 6It is a structural diagram of a device with AST-based component configuration provided in an embodiment of the present application. DETAILED DESCRIPTION

[0072] It should be noted that the terms used in the implementation methods of the embodiments of the present application are only used to explain the specific embodiments of the present application, and are not intended to limit the present application. In the description of the embodiments of the present application, unless otherwise specified, " / " means or, for example, A / B can mean A or B; "and / or" in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships, for example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, in the description of the embodiments of the present application, unless otherwise specified, "multiple" means two or more than two, "at least one" and "one or more" mean one, two or more than two.

[0073] In the following, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, it is defined that the "first" and "second" features may explicitly or implicitly include one or more of the features.

[0074] References to "one embodiment" or "some embodiments" etc. described in this specification 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 one implementation", "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.

[0075] In order to better understand the AST-based component configuration method provided in the embodiment of the present application, some terms or concepts that may be involved in the embodiment of the present application are introduced below.

[0076] 1. Abstract syntax code (AST)

[0077] In computer science, an abstract syntax tree is an abstract identifier of the syntax structure of source code. It represents the syntax structure of a language in a tree-like form, and each node in the tree represents a structure in the source code. During the analysis and migration of source code, the syntax analyzer will create an AST to facilitate code analysis based on the AST.

[0078] 2. Componentization

[0079] To put it simply, componentization can be splitting a fully functional application (application, App) or module into multiple sub-modules. Each sub-module can be compiled and run independently, or combined into another new App or module. Each module is not dependent on each other but can interact with each other.

[0080] The reason for componentization is that the current projects are getting bigger and bigger with the increase in demand. The increase in scale brings a lot of troubles. Various businesses are intricately intertwined. There is no constraint between the codes of each business module, which leads to the fuzziness of code boundaries and frequent code conflicts. For example, sometimes in order to change a small problem, some new problems may arise, and one hair may affect the whole body; for example, sometimes in order to add a new requirement, you need to be familiar with a large number of codes written by predecessors before you start, which will lead to a continuous increase in code compilation time and a very low development efficiency. The emergence of componentization is proposed for this situation, which is used to solve the troubles listed above for R&D personnel.

[0081] 3. Vue Components

[0082] Vue is a front-end development framework. In a Vue project created with vue-cli, each illegal construction ending with .vue represents a Vue component. Vue component is an important concept in the Vue framework, which can expand hypertext markup language (HTML) elements and encapsulate reusable code. In short, Vue component is a reusable Vue example. In the development process, frequently repeated functions, such as "count button" and "drop-down box" in web pages, are developed as Vue components to achieve the purpose of convenient development. In the Vue framework, the Vue.component() function is usually used to create and create a Vue component. The Vue components created by the Vue.component() function are all globally registered, that is, after the Vue component is registered, a Vue example is created by new Vue, and then the Vue component can be used in the Vue example. Vue also provides a local registration mechanism. By declaring a components property in the Vue() function, the Vue component can be locally registered internally.

[0083] In other words, when developing large applications, pages can be divided into many parts. Often different pages will have the same parts, for example, they may have the same header navigation. If each page is developed independently, it will undoubtedly increase the development cost. Therefore, different parts of the page can be split into independent Vue components, and then different pages can share these Vue components to avoid repeated development.

[0084] Combined with the introduction of background technology, the current manual screening of Vue components used in projects is not only prone to high labor costs and the problem of missing components, but also accompanied by the following two problems: (1) It is impossible to form intuitive data statistics to show which components are involved in the entry files of different Vue projects, resulting in inconvenience in later regression testing; (2) When different Vue projects and different Vue component libraries are involved, there is serious duplication of work, and the degree of intelligence in configuring components for the project is low.

[0085] In response to the above problems, an embodiment of the present application provides a component configuration method based on AST. By highly abstracting the existing Vue component library, introducing general implementation logic on demand, and combining the general programming of the abstract syntax tree AST, a transformation solution compatible with multiple component libraries is provided to automatically introduce Vue project entry files on demand. This solution can automatically configure Vue components for different Vue projects and improve the efficiency and accuracy of Vue component configuration.

[0086] It should be understood that the AST-based component configuration method provided in the embodiment of the present application can be applied to various types of page development scenarios. Exemplarily, the AST-based component configuration method provided in the embodiment of the present application can be executed by a component configuration device, which can be various types of electronic devices, such as a personal computer (PC), a user terminal, etc. The embodiment of the present application does not limit the specific type of the component configuration device.

[0087] For example, Figure 1 As shown, it is a schematic flow chart of a method for component configuration based on AST provided in an embodiment of the present application. The method can be executed by a component configuration device as the main body. Exemplarily, the process corresponding to the method can include the following steps:

[0088] S101, obtaining component configuration parameters, where the component configuration parameters are used to indicate the type of Vue component to be configured.

[0089] In some embodiments, the component configuration device can receive instructions input by the user to start the component configuration process. Exemplarily, the process may include, for example: the component configuration device may receive a component configuration process trigger command input by the user through a command line, and respond to the component configuration trigger command to start the component configuration process. Among them, the component configuration process trigger command may include component parameters corresponding to the Vue component required to be introduced by the Vue project, and may also include an entry file identifier corresponding to the Vue project. For example, the component configuration process trigger command may be, for example: codemod src—pkgNameelement—prefix el—entry src / main.js.

[0090] In some embodiments, the component configuration device may acquire component configuration parameters according to the component configuration process trigger command, and the component configuration parameters may be used to indicate the type of Vue component to be configured. Among them, the type of Vue component to be configured may refer to the type corresponding to the Vue component required by the current project. Exemplarily, the component configuration parameters may include, for example, the name of the component to be configured, a tag, and the like. For example, the component configuration parameters may specifically include a unique package name of the component library (such as a pkgName element), and the unique package name of the component library may be used as a basis for subsequent queries of the Vue component.

[0091] In some embodiments, the component configuration device may also trigger a command according to the component configuration process to obtain an entry file corresponding to the Vue project (eg, entry src / main.js), which may be used to globally mount the component to the Vue prototype chain.

[0092] S102, obtaining all source code files corresponding to the Vue project, and converting the source code files into an abstract syntax tree AST.

[0093] In some embodiments, the component configuration device can obtain all files corresponding to the Vue project in response to the component configuration process trigger command. The files corresponding to the Vue project can be stored locally on the component configuration device, for example, the user downloads the source code files corresponding to the project to any directory locally on the component configuration device.

[0094] In some embodiments, the component configuration device can obtain all source code files corresponding to the Vue project according to the component configuration process trigger command. Exemplarily, the component configuration device can obtain the storage path of all source code files corresponding to the Vue project according to the component configuration process trigger command, and then obtain all source code files corresponding to the Vue project according to the storage path. For example, when the component configuration process trigger command includes the storage path corresponding to the Vue project, the component configuration device can obtain the storage path of all source code files corresponding to the Vue project according to the component configuration process trigger command, and then obtain all source code files corresponding to the Vue project according to the storage path; for another example, when the component configuration process trigger command can include the identification of the Vue project (such as the name of the Vue project, etc.), and the component configuration device can query the corresponding relationship between the identification of the Vue project and the storage path of all source code files corresponding to the Vue project, the component configuration device can query the storage path of all source code files corresponding to the Vue project according to the identification of the Vue project, and then obtain all source code files corresponding to the Vue project according to the storage path.

[0095] In one possible implementation, the process of the component configuration device obtaining all source code files corresponding to the Vue project may include: the component configuration device enters the corresponding directory through the command prompt cmd according to the storage path of the source code file, and reads all source code files under the directory through the file system provided by the node environment.

[0096] In some embodiments, after obtaining all source code files corresponding to the Vue project, the component configuration device can convert the source code file into an abstract syntax tree AST. Exemplarily, the process of the component configuration device converting the source code file into an AST may include: performing lexical analysis on the source code file of the file, reading each character in the source code file through a lexical analyzer, and converting it into a lexical token stream; then, performing grammatical analysis, converting the lexical token stream parsed by the lexical analyzer into an AST.

[0097] In order to better understand how to convert a source code file into an AST in the method provided in the embodiment of the present application, the conversion process is specifically introduced below with reference to a specific example.

[0098] For example, if the source code file to be converted is the expression const value = 'JS To AST', the AST conversion process may include: lexical analysis recognizes the entire code character by character from left to right, and then recognizes words according to word formation rules and converts them into a token stream. The token stream is as follows:

[0099] [{type:'keyword',value:'const',...},

[0100] {type:'identifier',value:'a',...},

[0101] {type:'value',value:'JS To AST'}]

[0102] After that, the above token stream is converted into AST through syntax analysis as follows:

[0103]

[0104]

[0105] It should be understood that by converting the source code files corresponding to the Vue project into AST, underlying data support can be provided for subsequent retrieval operations of the Vue components required for the Vue project.

[0106] It should also be understood that the lexical analysis involved in the process of converting the source code file corresponding to the Vue project into AST can be regarded as reading the source code file from left to right, character by character, and identifying "word" symbols one by one, that is, scanning the character stream constituting the source code file and then identifying words (also called word symbols or symbols) according to the word formation rules. The grammatical analysis involved in the process of converting the source code file corresponding to the Vue project into AST combines word sequences into various grammatical phrases on the basis of lexical analysis. The specific implementation process of lexical analysis and grammatical analysis in this conversion process can refer to any feasible existing process, which will not be repeated here.

[0107] S103, according to the component configuration parameters, filter the target Vue component from the AST corresponding to the source code file.

[0108] It should be noted that Vue components can include Vue components that use tags provided by HTML natively, such as Vue components that use tags such as p, div, and h2; Vue components can also include custom Vue components developed based on native secondary encapsulation, such as Vue components that use tags such as el-form. Custom Vue components can be distinguished from native tags by custom naming.

[0109] It should also be noted that, in the embodiment of the present application, the component configuration device automatically introduces the component of the Vue project as a custom Vue component instead of the existing manual method. Therefore, the AST-based component introduction method provided in the embodiment of the present application may not process the Vue component corresponding to the native tag, but only operate on the custom Vue component.

[0110] The target Vue component here refers to the custom Vue component that needs to be introduced into the Vue project.

[0111] In some embodiments, the Vue component type indicated by the component configuration parameter can be used as a screening basis for the target Vue component. Exemplarily, the component configuration parameter can be used to indicate that the tag value of the Vue component complies with the Vue component library rules, and the Vue component is a component of a custom Vue component. Taking the type corresponding to the custom Vue component equal to 1 as an example, the component configuration parameter can also be described as a Vue component whose tag value in the custom component with type equal to 1 complies with the naming rules of the Vue component library.

[0112] In some embodiments, after obtaining the AST corresponding to the project source code file, the component configuration device can use the component configuration parameters as the screening basis, and recursively traverse the AST to screen out the target Vue components that meet the configuration parameters. For example, when the component configuration parameter is that the Vue component name conforms to the Vue component library naming rules and type is equal to 1 (corresponding to a custom Vue component), the component configuration device can query the node whose type is equal to 1 and tag conforms to the Vue component library naming rules. The custom Vue component corresponding to the node is the target Vue component that needs to be obtained, that is, the Vue component that actually needs to be introduced according to the project requirements. For another example, taking the screening basis indicated by the component configuration parameter as el- and a- as an example, the target Vue components screened out by the component configuration device are, for example, the element component el-form and the ant design Vue component a-form.

[0113] S104, converting the target Vue component according to the AST structure corresponding to the entry file to obtain the Vue component to be injected, wherein the structure of the Vue component to be injected is consistent with the AST structure corresponding to the entry file.

[0114] The Vue component to be injected refers to the component that needs to be inserted into the AST structure of the entry file. For example, the corresponding Vue component code to be imported in the source code file can be shown in lines 4 to 7 in the following code example:

[0115]

[0116] In some embodiments, after the component configuration device obtains the target Vue component that needs to be introduced on demand, it can transform the target Vue component into an AST structure that matches the AST structure corresponding to the entry file by analyzing the AST structure corresponding to the entry file; then, the transformed Vue component to be injected is injected into the entry file AST.

[0117] For example, taking the source code file shown above as an example, after AST conversion, the AST structure of the component to be imported can be as follows: Figure 2 The structure shown in bold in the code example is as follows:

[0118] Among them, after the source code file is converted to AST, there are differences between js code and HTML in AST, but both are a nested array object structure. In the converted AST example: ①type is the type, MemberExpression is the member variable class, ExpressionStatement is the expression class, CallExpression is the function call class, and Identifier is the variable class; ②callee is the instance of the function call; ③expression is the instance of the expression; ④arguments is the parameter entity; for example Figure 4 The AST in the red box represents the code snippet of "Vue.use(Form)", that is, there is an expression that is a function, whose body is the use attribute on the root object Vue, and its parameter is the Form field.

[0119] S105, injecting the Vue component to be injected into the AST corresponding to the entry file, obtaining a target entry file, wherein the target entry file is configured with the Vue component required by the Vue project.

[0120] In some embodiments, the process of injecting the Vue component to be injected into the AST structure corresponding to the entry file may include: inserting the Vue component to be injected whose AST structure is consistent with the AST structure corresponding to the entry file into the corresponding AST array object.

[0121] In some embodiments, after the Vue components required by the project are introduced into the AST of the entry file, the component configuration device can output a target entry file including the Vue components automatically configured on demand.

[0122] In some embodiments, the component configuration device can also obtain log information corresponding to the target entry file, which may include, for example, the file name and file path of the target entry file, the number of Vue components that need to be processed during the transformation of the entry file and their corresponding names, etc.

[0123] In some embodiments, the component configuration device can output the corresponding log to the cmd control panel according to the target entry file name, or the Vue project name, so that the user can view the changes involved in the development process of the Vue project after the program runs or ends.

[0124] It should be understood that by generating a log to record relevant information during the process of automatically introducing components into the entry file, the changed data can be recorded more accurately, and the changed points of each page design can be counted more intuitively, thereby reducing the cost for later test regression.

[0125] According to the AST-based component configuration method provided in the embodiment of the present application, all source code files corresponding to the project are converted into AST, and then the components required to be introduced into the project are obtained based on the component configuration parameters. After that, these components that need to be introduced are converted into an AST structure consistent with the entry file, and the converted components are injected into the array object of the entry file AST, thereby realizing automatic configuration of components in the entry file on demand in the Vue project. This method realizes the automated processing of introducing components on demand. For developers, the entire component configuration work can be completed through only one command line, which not only improves efficiency, but also effectively saves manpower. In addition, because AST is highly standardized, the accuracy of automatic processing is high, thereby reducing the problem of component omissions.

[0126] In addition, the AST-based component configuration method provided in the embodiment of the present application provides a general solution for introducing Vue components with strong compatibility. For different component libraries and different Vue projects, it is only necessary to slightly modify the component configuration parameters of the command line.

[0127] In order to better understand the AST-based component configuration method provided in the embodiment of the present application, the implementation process of converting the source code file into AST is introduced below with reference to specific examples.

[0128] For example, Figure 3 As shown, it is a schematic flowchart of converting a source code file into AST provided in an embodiment of the present application.

[0129] S301, obtain all source code files corresponding to the Vue project.

[0130] The process of obtaining all source code files corresponding to the project can be referred to in step S102 above, which will not be repeated here.

[0131] S302, performing lexical analysis on the source code file to obtain a lexical token stream corresponding to the source code file.

[0132] S303, perform grammatical analysis on the lexical token stream to obtain the AST corresponding to the source code file.

[0133] In some embodiments, it is assumed that the vue code snippet in the source code file before conversion is as follows:

[0134] <div id="app”class="default”>

[0135] AST Example

[0136] <router-view>< / router-view>

[0137]

[0138] The AST corresponding to the converted Vue code snippet can be as follows Figure 4 As shown. :

[0139] It can be seen that after the conversion, the vue source code snippet is converted to AST, and its structure is a data structure nested by the children attribute. In the above AST, type is type 1 (bold font), which means that the component corresponds to the string text in the source code file, such as "AST example"; the tag in AST is the tag name, which can include native div, custom router-view or el-form, etc.; the attrsMap in AST is the component attribute, such as id=app, class=default, etc.; the children in AST represents the code nesting structure, which can correspond to the outer div nesting memory div and router-view in the source code file, and the inner div nesting "AST example".

[0140] It should be noted that the process of converting the source code file into AST involved in the AST-based component configuration method provided in the embodiment of the present application can refer to the existing AST conversion process, and the embodiment of the present application will not elaborate on this.

[0141] According to the AST-based component configuration method provided in the embodiment of the present application, all source code files corresponding to the project are converted into AST, and then the components required to be introduced into the project are obtained based on the component configuration parameters. After that, these components that need to be introduced are converted into an AST structure consistent with the entry file, and the converted components are injected into the array object of the entry file AST, thereby realizing automatic configuration of components in the entry file on demand in the Vue project. This method realizes the automated processing of introducing components on demand. For developers, the entire component configuration work can be completed through only one command line, which not only improves efficiency, but also effectively saves manpower. In addition, because AST is highly standardized, the accuracy of automatic processing is high, thereby reducing the problem of component omissions.

[0142] For example, Figure 5 , which is a schematic diagram of a structure of a device for component configuration based on AST provided in an embodiment of the present application. The device 500 may include a receiving module 501 , a conversion module 502 and a processing module 503 .

[0143] In some embodiments, the receiving module 501 may be used to obtain component configuration parameters, where the component configuration parameters are used to indicate the type of Vue component to be configured; obtain all source code files corresponding to the Vue project;

[0144] A conversion module 502 may be used to convert the source code file into an abstract syntax tree AST;

[0145] Processing module 503 can be used to filter the target Vue component from the AST corresponding to the source code file according to the component configuration parameters; convert the target Vue component according to the AST structure corresponding to the entry file to obtain the Vue component to be injected, and the structure of the Vue to be injected is consistent with the AST structure corresponding to the file; inject the Vue component to be injected into the AST corresponding to the entry file to obtain the target entry file, and the target entry file is configured with the Vue component required by the Vue project.

[0146] In some embodiments, the conversion module 502 may also be specifically used to perform lexical analysis on the source code file to obtain a lexical token stream corresponding to the source code file;

[0147] Perform grammatical analysis on the lexical token stream to obtain the AST corresponding to the source code file.

[0148] In some embodiments, the processing module 503 can also be used to obtain log information corresponding to the target entry file, wherein the log information includes the file name and file path of the target entry file, the number of Vue components that need to be processed in the process of generating the target entry file, and their corresponding names.

[0149] In some embodiments, the receiving module 501 may also be used to receive a component configuration process trigger instruction input by a user through a command identifier, wherein the component configuration process trigger instruction is used to instruct to start a component configuration process, and the component configuration process trigger instruction includes the component configuration parameter;

[0150] The processing module 303 may also be used to acquire the component configuration parameters according to the component configuration process trigger instruction.

[0151] In some embodiments, the processing module 503 may also be used to obtain the path corresponding to the source code file according to the component configuration process trigger instruction;

[0152] Through the command identifier, all source code files corresponding to the Vue project are obtained according to the path.

[0153] In some embodiments, the processing module 503 can also be used to filter out a custom Vue component whose type satisfies the type indicated by the component configuration parameter from the AST corresponding to the source code file as the target component according to the component configuration parameter.

[0154] For example, Figure 6As shown, it is a structural diagram of a device based on AST component configuration provided by an embodiment of the present application. The device 600 may include at least one processor 601 and at least one memory 602, wherein the memory stores computer-readable program instructions. At least one processor 601 and at least one memory 602 may be communicatively connected via a universal serial bus 603.

[0155] In some embodiments, when the processor 601 executes the computer-readable program instructions, the device 600 performs the following steps:

[0156] Get component configuration parameters, where the component configuration parameters are used to indicate the type of Vue component to be configured;

[0157] Get all source code files corresponding to the Vue project, and convert the source code files into an abstract syntax tree AST;

[0158] According to the component configuration parameters, filter the target Vue component from the AST corresponding to the source code file;

[0159] The target Vue component is converted according to the AST structure corresponding to the entry file to obtain the Vue component to be injected, and the structure of the Vue component to be injected is consistent with the AST structure corresponding to the file;

[0160] Inject the Vue component to be injected into the AST corresponding to the entry file, and obtain the target entry file, where the target entry file is configured with the Vue component required by the Vue project.

[0161] In some embodiments, when the processor 601 executes the computer-readable program instructions, the device 600 performs the following steps:

[0162] Performing lexical analysis on the source code file to obtain a lexical token stream corresponding to the source code file;

[0163] Perform grammatical analysis on the lexical token stream to obtain the AST corresponding to the source code file.

[0164] In some embodiments, when the processor 601 executes the computer-readable program instructions, the device 600 performs the following steps:

[0165] Get the log information corresponding to the target entry file, where the log information includes the file name and file path of the target entry file, the number of Vue components that need to be processed in the process of generating the target entry file, and their corresponding names.

[0166] In some embodiments, when the processor 601 executes the computer-readable program instructions, the device 600 performs the following steps:

[0167] receiving a component configuration process trigger instruction input by a user through a command identifier, wherein the component configuration process trigger instruction is used to instruct to start a component configuration process, and the component configuration process trigger instruction includes the component configuration parameter;

[0168] The component configuration parameters are acquired according to the component configuration process trigger instruction.

[0169] In some embodiments, when the processor 601 executes the computer-readable program instructions, the device 600 performs the following steps:

[0170] The type of the component to be configured, the name of the component library corresponding to the component to be configured, and the component identifier corresponding to the component to be configured.

[0171] In some embodiments, when the processor 601 executes the computer-readable program instructions, the device 600 performs the following steps:

[0172] Acquire the path corresponding to the source code file according to the component configuration process trigger instruction;

[0173] Through the command identifier, all source code files corresponding to the Vue project are obtained according to the path.

[0174] In some embodiments, when the processor 601 executes the computer-readable program instructions, the device 600 performs the following steps:

[0175] According to the component configuration parameters, a custom Vue component whose type satisfies the type indicated by the component configuration parameters is filtered out from the AST corresponding to the source code file as the target component.

[0176] Based on the same technical concept, an embodiment of the present application also provides a computer-readable storage medium, which stores a computer-executable program. When the computer-executable program is called by a computer, the computer implements the method provided by the embodiment of the present application.

[0177] Based on the same technical concept, an embodiment of the present application also provides a chip system, which includes: a communication interface for inputting and / or outputting information; a memory for storing a computer executable program; and a processor for executing the computer executable program, so that a device equipped with the chip system can implement the method provided in the embodiment of the present application.

[0178] Based on the same technical concept, an embodiment of the present application also provides a computer program product, which includes computer program instructions. When the computer program instructions are run on a computer, the computer or processor executes one or more steps in any of the above methods, so that the method provided by the embodiment of the present application can be implemented.

[0179] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium or transmitted through the computer-readable storage medium. The computer instructions may be transmitted from a website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium may be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium may be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid state drive (SSD)), etc.

[0180] Those skilled in the art can understand that to implement all or part of the processes in the above-mentioned embodiments, the processes can be completed by computer programs to instruct related hardware, and the programs can be stored in computer-readable storage media. When the programs are executed, they can include the processes of the above-mentioned method embodiments. The aforementioned storage media include: ROM or random access memory RAM, magnetic disk or optical disk and other media that can store program codes.

[0181] The above is only a specific implementation of the embodiment of the present application, but the protection scope of the embodiment of the present application is not limited thereto, and any changes or replacements within the technical scope disclosed in the embodiment of the present application should be included in the protection scope of the embodiment of the present application. Therefore, the protection scope of the embodiment of the present application should be based on the protection scope of the claims.

Claims

1. A component configuration method based on AST, characterized in that: The method comprises: Receive a component configuration process trigger command input by a user through a command line, and start the component configuration process in response to the component configuration process trigger command; wherein the component configuration process trigger command includes component configuration parameters corresponding to the Vue component required to be introduced into the Vue project and an entry file identifier corresponding to the Vue project; Get the component configuration parameters, which are used to indicate that the tag value of the Vue component complies with the Vue component library rules and the Vue component is a parameter of a custom Vue component, get the entry file corresponding to the Vue project, which is used to globally mount the component to the Vue prototype chain, and the component configuration parameters are used to indicate the type of Vue component to be configured; Obtain all source code files corresponding to the Vue project, and convert the source code files into an abstract syntax tree AST, wherein the process of converting the source code files into AST includes: reading the source code files character by character from left to right, and identifying word symbols therefrom; composing the word symbols into various grammatical phrases; According to the component configuration parameters, the target Vue component is filtered from the AST corresponding to the source code file, wherein the process of filtering the target Vue component from the AST corresponding to the source code file includes: recursively traversing and filtering in the AST, querying nodes with type=1 and tag names that conform to the naming rules of the Vue component library, and obtaining the custom Vue component corresponding to the node as the required target Vue component; Analyze and obtain the abstract syntax tree AST of the entry file, convert the target Vue component according to the AST structure corresponding to the entry file, and obtain the Vue component to be injected, the structure of the Vue component to be injected is consistent with the AST structure corresponding to the entry file; Inject the Vue component to be injected into the AST corresponding to the entry file, and obtain the target entry file, where the target entry file is configured with the Vue component required by the Vue project.

2. The method according to claim 1, characterized in that The converting the source code file into AST specifically includes: Performing lexical analysis on the source code file to obtain a lexical token stream corresponding to the source code file; Perform grammatical analysis on the lexical token stream to obtain the AST corresponding to the source code file.

3. The method according to claim 1 or 2, characterized in that: The method further comprises: Obtain log information corresponding to the target entry file, wherein the log information includes the file name and file path of the target entry file, the number of Vue components that need to be processed in the process of generating the target entry file, and the names corresponding to the Vue components.

4. The method according to claim 1 or 2, characterized in that: The obtaining of the component configuration parameters specifically includes: receiving a component configuration process trigger instruction input by a user through a command identifier, wherein the component configuration process trigger instruction is used to instruct to start a component configuration process, and the component configuration process trigger instruction includes the component configuration parameter; The component configuration parameters are acquired according to the component configuration process trigger instruction.

5. The method according to claim 4, characterized in that The component configuration parameters include: The type of the component to be configured, the name of the component library corresponding to the component to be configured, and the component identifier corresponding to the component to be configured.

6. The method according to claim 5, characterized in that The component configuration process trigger instruction also includes the path corresponding to the source code file, The acquisition of all source code files corresponding to the Vue project specifically includes: Acquire the path corresponding to the source code file according to the component configuration process trigger instruction; Through the command identifier, all source code files corresponding to the Vue project are obtained according to the path.

7. The method according to claim 1 or 2, characterized in that: The step of filtering the target Vue component from the AST corresponding to the source code file according to the component configuration parameters specifically includes: According to the component configuration parameters, a custom Vue component whose type satisfies the type indicated by the component configuration parameters is filtered out from the AST corresponding to the source code file as the target Vue component.

8. A device for component configuration based on AST, characterized in that: The device is used to implement the method for component configuration based on AST of claims 1-7, comprising: A receiving module is used to obtain component configuration parameters, where the component configuration parameters are used to indicate the type of Vue component to be configured; and obtain all source code files corresponding to the Vue project; A conversion module, used to convert the source code file into an abstract syntax tree AST; A processing module is used to filter the target Vue component from the AST corresponding to the source code file according to the component configuration parameters; convert the target Vue component according to the AST structure corresponding to the entry file to obtain the Vue component to be injected, and the structure of the Vue component to be injected is consistent with the AST structure corresponding to the entry file; inject the Vue component to be injected into the AST corresponding to the entry file to obtain the target entry file, and the target entry file is configured with the Vue component required by the Vue project.

9. A device for component configuration based on AST, characterized in that: include: at least one communication interface; at least one processor; at least one memory; The communication interface is used to communicate with other communication devices, and the memory stores computer-readable program instructions. When the processor runs the computer-readable program instructions, the device executes the method according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-readable program instructions, and when the computer-readable program instructions are executed on a computer, the computer is caused to execute the method according to any one of claims 1 to 7.