Front-end framework component automatic conversion method, system, electronic device and storage medium
By automatically parsing and converting the cascading style sheets, hypertext markup language templates and TypeScript codes of Angular framework components, we generate code that conforms to the Vue framework specifications, solving the problem of automatic conversion from Angular to Vue and improving the efficiency of code migration. .
Patent Information
- Application Number
- CN202410317323.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-20
- Publication Date
- 2024-09-17
- Estimated Expiration
- 2044-03-20
AI Technical Summary
Existing technology cannot automatically convert Angular framework components into Vue framework components, resulting in a long code migration time and developers need to spend a lot of time and energy on manual conversion.
An automatic front-end code conversion method is proposed. By obtaining the cascading style sheet, hypertext markup language template and TypeScript code of the Angular framework component, it performs syntax and semantic analysis and conversion, generates code that conforms to the Vue framework syntax specification, and converts it Write to Vue file.
It realizes the automatic conversion of Angular framework components into Vue framework components, significantly improves the code migration speed and reduces the duplication of work for developers.
Smart Images

Figure CN118245050B
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer network technology, and in particular to a method, system, electronic device and storage medium for automatic conversion of front-end framework components. Background Art
[0002] The Angul ar framework is an early front-end development framework. Currently, most historical projects are based on the Angul ar framework, and it has been updated and iterated for several years. It will continue to be put into use in the future. With the rapid development of front-end technology in recent years, Vue has become the main battlefield of front-end frameworks in China. Projects based on different frameworks cannot share code, so it is necessary to convert the Angul ar framework to the Vue framework. However, the two frameworks of Angul ar and Vue are quite different. The syntax, code best practices, and usage in some specific scenarios are quite different. Currently, the conversion can only be done through manual code migration, which takes up a lot of time and energy of developers. Summary of the invention
[0003] The main purpose of the embodiments of the present application is to propose a front-end code automatic conversion method, system, electronic device and storage medium, aiming to automatically convert the Angul ar framework components in the project into Vue framework components, improve the speed of code migration, and reduce the repetitive work of developers.
[0004] To achieve the above purpose, an embodiment of the present application provides a method for automatically converting a front-end framework component, the method comprising:
[0005] Obtaining a first cascading style sheet, a hypertext markup language template and a first TypeScript code of an Anglar framework component file;
[0006] Parsing and converting the first cascading style sheet to obtain a second cascading style sheet;
[0007] Performing syntax and semantic analysis and conversion on the hypertext markup language template to obtain a first document object model tree structure object of the hypertext markup language template;
[0008] Collecting data from the first document object model tree structure object, and synchronizing the collected data to the first TypeScript code;
[0009] Respectively perform syntax and semantic analysis and conversion on the first variable, the first method body and the first import statement in the first TypeScript code to obtain a second variable, a second method body and a second import statement accordingly;
[0010] Converting the first document object model tree structure object into a hypertext markup language template string;
[0011] Splicing a plurality of the second method bodies, the second variables and the second import statements to obtain a second TypeScript code that complies with the syntax specification of the Vue framework;
[0012] A Vue file is created, and the second cascading style sheet, the hypertext markup language template string and the second TypeScript code are written into corresponding tags in the Vue file according to preset rules to obtain a Vue framework component file.
[0013] In some embodiments, the obtaining of the first cascading style sheet, the hypertext markup language template and the first TypeScript code of the Anglar framework component file comprises the following steps:
[0014] Obtaining a first cascading style sheet reference path, a hypertext markup language template reference path and a first TypeScript code;
[0015] Reading a first cascading style sheet according to the first cascading style sheet reference path;
[0016] The hypertext markup language template is read according to the hypertext markup language template reference path.
[0017] In some embodiments, parsing and converting the first cascading style sheet to obtain a second cascading style sheet includes the following steps:
[0018] Parsing the first cascading style sheet to obtain a target modified portion that needs to be replaced in the first cascading style sheet;
[0019] The target modification part is converted by a regular expression to obtain a second cascading style sheet.
[0020] In some embodiments, the step of performing syntax and semantic parsing and conversion on the hypertext markup language template to obtain a first document object model tree structure object of the hypertext markup language template includes the following steps:
[0021] Parsing the character string of the hypertext markup language template by a parser to obtain a second document object model tree structure object, wherein the second document object model tree structure object includes a plurality of element nodes, and the element nodes are used to represent instructions or attributes;
[0022] Recursively traverse the element nodes in the second document object model tree structure object, delete useless element nodes in the second document object model tree structure object, and record the parent nodes of the traversed element nodes and the traversed special element nodes into the data collector;
[0023] Performing grammatical semantic parsing and conversion on the element nodes corresponding to the instructions in the second document object model tree structure object, and updating to obtain element nodes that conform to the Vue framework instruction grammar specification;
[0024] Performing grammatical semantic parsing and conversion on the element nodes of the corresponding attributes in the tree structure object of the second document object model, and updating to obtain element nodes that conform to the grammatical attribute specifications of the Vue framework;
[0025] According to all updated element nodes, a first document object model tree structure object is obtained.
[0026] In some embodiments, collecting data from the first document object model tree structure object and synchronizing the collected data to the first TypeScript code includes the following steps:
[0027] Traversing all element nodes in the first document object model tree structure object, and extracting variables and methods in the element node attributes;
[0028] The extracted variables and methods are synchronized to the first TypeScript code.
[0029] In some embodiments, the performing grammatical and semantic parsing and conversion on the first variable, the first method body and the first import statement in the first TypeScript code respectively to obtain the second variable, the second method body and the second import statement comprises the following steps:
[0030] According to the Vue variable definition rule, a type is defined for the first variable in the first TypeScript code, and the first variable is parsed using a corresponding parsing logic according to the type of the first variable to obtain a second variable, where the second variable is a Vue variable that complies with the Vue framework syntax specification;
[0031] Creating a corresponding abstract syntax tree structure object according to each of the first method bodies; traversing each node in the abstract syntax tree structure object to obtain a code fragment to be replaced; replacing the code fragment to be replaced by using a regular expression to obtain a second method body;
[0032] According to preset import statement rules, the first import statement is referenced to obtain a second import statement, wherein the reference processing includes one of reference deletion, reference replacement, common reference conversion or reference retention.
[0033] In some embodiments, the step of concatenating the plurality of second method bodies, the second variables, and the second import statements to obtain a second TypeScript code that complies with the syntax specification of the Vue framework comprises the following steps:
[0034] Write the second method body of the life cycle function type into the hook function corresponding to the Vue environment to obtain the second method body of the hook function type;
[0035] After assembling the second method bodies of all the hook function types, assemble the second method bodies of the common function types to obtain a first assembly code;
[0036] According to the concatenation order of different types of second variables, sequentially assemble different types of the second variables on the first assembly code to obtain a second assembly code;
[0037] The second import statement is assembled on the second assembly code to obtain a second TypeScript code that complies with the Vue framework syntax specification.
[0038] To achieve the above purpose, another aspect of the embodiment of the present application provides a front-end framework component automatic conversion system, the system comprising:
[0039] The first module is used to obtain a first cascading style sheet, a hypertext markup language template and a first TypeScript code of an Anglar framework component file;
[0040] A second module is used to parse and convert the first cascading style sheet to obtain a second cascading style sheet;
[0041] The third module is used to perform syntax and semantic analysis and conversion on the hypertext markup language template to obtain a first document object model tree structure object of the hypertext markup language template;
[0042] A fourth module, configured to collect data from the first document object model tree structure object, and synchronize the collected data to the first TypeScript code;
[0043] A fifth module is used to perform grammatical semantic analysis and conversion on the first variable, the first method body and the first import statement in the first TypeScript code respectively, and obtain a second variable, a second method body and a second import statement accordingly;
[0044] A sixth module, configured to convert the first document object model tree structure object into a hypertext markup language template string;
[0045] A seventh module is used to splice a plurality of the second method bodies, the second variables and the second import statements to obtain a second TypeScript code that complies with the syntax specification of the Vue framework;
[0046] The eighth module is used to create a Vue file, write the second cascading style sheet, the hypertext markup language template string and the second TypeScript code into corresponding tags in the Vue file according to preset rules, and obtain a Vue framework component file.
[0047] To achieve the above objective, another aspect of an embodiment of the present application provides an electronic device, the electronic device comprising a memory and a processor, the memory storing a computer program, and the processor implementing the above method when executing the computer program.
[0048] To achieve the above objective, another aspect of an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and the computer program implements the above method when executed by a processor.
[0049] The embodiments of the present application include at least the following beneficial effects: The present application provides a method, system, electronic device and storage medium for automatic conversion of front-end framework components. The solution divides the component information under the Angul ar framework into three parts: cascading style sheets, hypertext markup language templates and TypeScript codes, parses and converts the three parts of content in syntax and semantics respectively, and then writes the converted three parts into corresponding tags in the Vue component according to preset rules. This can automatically convert the Angul ar framework components in the project into Vue framework components, thereby improving the speed of code migration and reducing the repetitive work of developers. BRIEF DESCRIPTION OF THE DRAWINGS
[0050] Figure 1 It is a flow chart of the method for automatic conversion of front-end framework components provided in an embodiment of the present application;
[0051] Figure 2 It is a schematic diagram of the TypeScript code components provided in the embodiment of the present application;
[0052] Figure 3 It is a program interface diagram for writing the Angul ar framework component code into the Vue framework component provided by an embodiment of the present application;
[0053] Figure 4 It is a schematic diagram of the process of parsing a hypertext markup language template provided in an embodiment of the present application;
[0054] Figure 5It is a structural diagram of a document object model tree structure object provided in an embodiment of the present application;
[0055] Figure 6 is a schematic diagram of an element node provided in an embodiment of the present application;
[0056] Figure 7 is a schematic diagram of a variable structure in an Angul ar framework environment provided in an embodiment of the present application;
[0057] Figure 8 It is a schematic diagram of variable types in the Vue framework environment provided by an embodiment of the present application;
[0058] Fig. 9 It is a flowchart for parsing a single method body provided by an embodiment of the present application;
[0059] Fig.10 It is a schematic diagram of the structure of the import statement provided in the embodiment of the present application;
[0060] Fig.11 It is a flowchart of assembling TypeScript code provided in an embodiment of the present application;
[0061] Fig.12 is a flow chart of a method for automatic conversion of front-end framework components provided by another embodiment of the present application;
[0062] FIG. 13( a ) is a diagram of a program interface in an Ang lar framework component provided in an embodiment of the present application;
[0063] Figure 13(b) is a diagram of the program interface in the Vue framework component provided in an embodiment of the present application. DETAILED DESCRIPTION
[0064] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application is further described in detail below in conjunction with the accompanying drawings and examples. It should be understood that the specific embodiments described herein are only used to explain the present application and are not intended to limit the present application. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the embodiments of the present application. They are only examples of devices and methods consistent with some aspects of the embodiments of the present application as detailed in the attached claims.
[0065] It is understood that the terms "first", "second", etc. used in this application can be used to describe various concepts in this article, but unless otherwise specified, these concepts are not limited by these terms. These terms are only used to distinguish one concept from another concept. For example, without departing from the scope of the embodiment of the present application, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the words "if" and "if" as used herein can be interpreted as "at the time of" or "when" or "in response to determination".
[0066] The terms "at least one", "multiple", "each", "any", etc. used in this application, at least one includes one, two or more, multiple includes two or more, each refers to each of the corresponding multiple, and any refers to any one of the multiple.
[0067] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.
[0068] Before describing the embodiments of the present application in detail, some nouns and terms involved in the embodiments of the present application are first described. The nouns and terms involved in the embodiments of the present application are subject to the following explanations.
[0069] (1) HTML (Hypertext Markup Language) is a markup language. It uses tags to mark the various parts of a web page to be displayed. The web page file itself is a text file. By adding tags to the text file, you can tell the browser how to display the content.
[0070] (2) CSS (Cascading Style Sheets) is used to describe the appearance and style of a web page. It has a simple and easy-to-use syntax and can embed style rules directly in HTML documents.
[0071] (3) ts in this article refers to the code about the TypeScript code part in a component.
[0072] (4) ess is a CSS preprocessor that extends the functionality of CSS and provides functions such as variables, nested rules, and mixing, making CSS writing more convenient and flexible.
[0073] (5) Sass is also a CSS preprocessor, similar to less, but with more functions and flexibility. Sass uses indented syntax, which can more clearly express nested rules and hierarchical relationships.
[0074] Since the Angular and Vue frameworks are quite different, including syntax, code best practices, and some specific scenarios, there is currently no way to automatically convert the existing Angular code in the project into Vue code. The only compromise is to allow the code based on different frameworks to exist in the same system. This solution is the micro front-end. Micro front-ends are multiple independent small projects in the same system. They share a set of login authorization data. Micro applications can transfer and monitor data and export their own components for other micro applications to reference. For users, this difference is not perceptible, and the experience is the same as using a single application platform. However, the micro front-end solution is only a temporary solution. If the previously implemented function points are no longer changed, and the version iteration only adds new function points, the micro front-end solution is still applicable. However, when facing the need for frequent changes and adjustments or extracting a large number of public components from the project, micro applications based on different frameworks cannot achieve code sharing, that is, the extracted public component code cannot be shared, and there are some redundant codes in the packaged and deployed files. Therefore, components that can be shared under the same framework need to be developed or converted based on different frameworks.
[0075] In view of this, an embodiment of the present application provides a method, system, electronic device and storage medium for automatic conversion of front-end framework components to solve the above-mentioned problems.
[0076] The front-end framework component automatic conversion method provided in the embodiment of the present application relates to the field of computer network technology. The front-end framework component automatic conversion method provided in the embodiment of the present application can be applied to a terminal, can also be applied to a server, and can also be software running in a terminal or a server. In some embodiments, the terminal can be a smart phone, a tablet computer, a laptop computer, a desktop computer, etc., but is not limited to this; the server side can be configured as an independent physical server, or it can be configured as a server cluster or a distributed system composed of multiple physical servers, and can also be configured to provide cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and cloud servers for basic cloud computing services such as big data and artificial intelligence platforms. The server can also be a node server in a blockchain network; the software can be an application that implements the front-end framework component automatic conversion method, etc., but is not limited to the above forms.
[0077] The present application can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, programmable consumer electronic devices, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc. The present application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present application can also be practiced in distributed computing environments, in which tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.
[0078] Figure 1 is an optional flow chart of the method for automatic conversion of front-end framework components provided in an embodiment of the present application. Figure 1 The method may include but is not limited to steps S101 to S108:
[0079] Step S101, obtaining a first cascading style sheet, a hypertext markup language template and a first TypeScript code of an Anglar framework component file;
[0080] Step S102, parsing and converting the first cascading style sheet to obtain a second cascading style sheet;
[0081] Step S103, performing syntax and semantic analysis and conversion on the hypertext markup language template to obtain a first document object model tree structure object of the hypertext markup language template;
[0082] Step S104, collecting data from the first document object model tree structure object, and synchronizing the collected data to the first TypeScript code;
[0083] Step S105, respectively performing syntax and semantic analysis and conversion on the first variable, the first method body and the first import statement in the first TypeScript code, and correspondingly obtaining the second variable, the second method body and the second import statement;
[0084] Step S106, converting the first document object model tree structure object into a hypertext markup language template string;
[0085] Step S107, concatenating the plurality of second method bodies, second variables and second import statements to obtain a second TypeScript code that complies with the syntax specification of the Vue framework;
[0086] Step S108, creating a Vue file, writing the second cascading style sheet, the hypertext markup language template string and the second TypeScript code into corresponding tags in the Vue file according to preset rules, and obtaining a Vue framework component file.
[0087] In step S101 of some embodiments, a project developed based on Angular may include many modules, a module includes many components, and a component mainly includes three parts, namely, a first cascading style sheet, a hypertext markup language template, and a first TypeScript code. The first cascading style sheet, the hypertext markup language template, and the first TypeScript code are obtained by reading the file content according to the Angular component file path.
[0088] In step S102 of some embodiments, the first cascading style sheet is stored in the component in the form of a string, and the second cascading style sheet obtained after parsing and converting the first cascading style sheet is still in the form of a string.
[0089] In step S103 of some embodiments, the first Document Object Model (DOM) tree structure object can reflect the structure and content of the HTML template, and the HTML template can be more conveniently processed and converted through the first Document Object Model tree structure object.
[0090] In step S104 of some embodiments, after parsing the hypertext markup language template and before parsing the TypeScript code, variable or method body data may be collected from the first document object model tree structure object, and the collected data may be synchronized to the first TypeScript code.
[0091] In step S105 of some embodiments, refer to Figure 2 The first TypeScript code includes a first variable, a first method body, and a first import statement. With the help of a tool library, the first TypeScript code can be processed to obtain an Abstract Syntax Tree (AST) structure object, and the TypeScript code is subjected to syntax analysis and judgment, and the abstract syntax tree structure object is disassembled to obtain the first variable, the first method body, and the first import statement. The first variable, the first method body, and the first import statement in the first TypeScript code are respectively subjected to syntax and semantic analysis and conversion, and the second variable, the second method body, and the second import statement are obtained accordingly.
[0092] In step S106 of some embodiments, the converted first document object model tree structure object can be converted into a hypertext markup language template string with the help of a tool library, for example, by calling the stringy method in the third-party tool library "himalaya" to convert the data in the first document object model tree structure object into a string form.
[0093] In step S107 of some embodiments, because there is no existing interface provided for the generation of TypeScript code, the second method body, the second variable and the second import statement obtained by parsing are spliced in a bottom-up manner to obtain the second TypeScript code that conforms to the syntax specification of the Vue framework.
[0094] In step S108 of some embodiments, refer to Figure 3 After parsing the code in the Angul ar framework component file, create a Vue file, write the second cascading style sheet into the style tags specified in the Vue file, write the hypertext markup language template string into the specified template tags, and write the second TypeScript code into the specified script tags to obtain the Vue framework component file.
[0095] The embodiment of the present application divides the component information under the Angul ar framework into three parts: cascading style sheets, hypertext markup language templates, and TypeScript codes, parses and converts the three parts in terms of syntax and semantics respectively, and then writes the converted three parts into corresponding tags in the Vue component according to preset rules. This can automatically convert the Angul ar framework components in the project into Vue framework components, thereby improving the speed of code migration and reducing the repetitive work of developers.
[0096] In some embodiments, step S101 may include but is not limited to steps S201 to S203:
[0097] Step S201, obtaining a first cascading style sheet reference path, a hypertext markup language template reference path and a first TypeScript code;
[0098] Step S202, reading the first cascading style sheet according to the first cascading style sheet reference path;
[0099] Step S203, reading the hypertext markup language template according to the hypertext markup language template reference path.
[0100] In step S201 of some embodiments, the Angular framework component file content can be analyzed with the help of a third-party tool library "typescript-parser" to obtain the first Typescript code and generate a File object. The "typescript-parser" tool library is general and not for Angular components, so the data information in the component decorator @Component will be lost. Therefore, it is necessary to modify this third-party tool library to add parsing of the parameters in the component decorator @Component, convert them into decorator attributes in the File object after parsing, and obtain the reference path stylesUr l corresponding to the first cascading style sheet content corresponding to the Angular component and the reference path templateUr l corresponding to the hypertext markup language template content from the decorator attribute.
[0101] In step S202 of some embodiments, the cascading style sheet is usually suffixed with ".less" and stored in the current component directory of the project (in the same directory as the .ts file). The Angel framework component file content can be analyzed with the help of a third-party tool library "typescript-parser", and the first cascading style sheet is read in the Angel component project according to the obtained first cascading style sheet reference path styleUr l.
[0102] In step S203 of some embodiments, the hypertext markup language template is usually suffixed with ".html" and stored in the current component directory of the project (in the same directory as the .ts file). The Angel framework component file content can be analyzed with the help of a third-party tool library "typescript-parser", and the hypertext markup language template is read in the Angel component project according to the reference path tmpelateUr l corresponding to the obtained hypertext markup language template content, and the read hypertext markup language template content is converted into a string form for subsequent processing.
[0103] The embodiment of the present application parses the Angul ar framework component file to obtain Typescript code, reference path of cascading style sheets and reference path of hypertext markup language template, reads cascading style sheets and hypertext markup language template according to the reference path, and can automatically read cascading style sheets and hypertext markup language template, thereby reducing the developer's operations and improving the speed of code migration.
[0104] In some embodiments, step S102 may include but is not limited to steps S301 to S302:
[0105] Step S301, parsing the first cascading style sheet to obtain a target modification portion that needs to be replaced in the first cascading style sheet;
[0106] Step S302: convert the target modification part through a regular expression to obtain a second cascading style sheet.
[0107] In step S301 of some embodiments, since the cascading style representation is framework-independent and universal in any front-end framework, when migrating from the Angul ar framework to the Vue framework environment, only the style syntax form in the third-party UI library (Ant component library) is reset differently. The first cascading style sheet is parsed to obtain the UI library part in the first cascading style sheet, and the style syntax differences of the UI library in the Angul ar framework and the Vue framework are compared to determine the target modification part that needs to be replaced. Exemplarily, resetting the internal style of the third-party component in the Angul ar environment is achieved by ":host:ng-deep.className", while in the Vue environment it is achieved by writing ":deep(.className)".
[0108] In step S302 of some embodiments, the target modification part obtained by comparison is modified by using a regular expression to convert into a second cascading style sheet that conforms to the syntax form of resetting the internal style of the third-party component in the Vue environment.
[0109] The embodiment of the present application parses the first cascading style sheet, compares and obtains target modification parts with different style syntax forms in the UI library, and converts the target modification parts. This can automatically obtain a cascading style sheet that conforms to the style syntax form of the UI library in the Vue environment, reduce the impact of style changes caused by framework switching, and improve the efficiency of front-end framework component conversion.
[0110] In some embodiments, step S103 may include but is not limited to steps S401 to S405:
[0111] Step S401, parsing the character string of the hypertext markup language template by a parser to obtain a second document object model tree structure object, the second document object model tree structure object includes a plurality of element nodes, and the element nodes are used to represent instructions or attributes;
[0112] Step S402, recursively traverse the element nodes in the second document object model tree structure object, delete useless element nodes in the second document object model tree structure object, and record the parent nodes of the traversed element nodes and the traversed special element nodes into the data collector;
[0113] Step S403, performing syntax and semantic analysis and conversion on the element nodes corresponding to the instruction in the second document object model tree structure object, and updating to obtain element nodes that conform to the Vue framework instruction syntax specification;
[0114] Step S404, performing syntax and semantic analysis and conversion on the element nodes of the corresponding attributes in the tree structure object of the second document object model, and updating to obtain element nodes that conform to the syntax attribute specification of the Vue framework;
[0115] Step S405: obtaining a first document object model tree structure object according to all updated element nodes.
[0116] See also Figure 4 In some embodiments, the parse method in the third-party tool library "hima l aya" can be called to process the acquired hypertext markup language template string and parse to obtain the second document object model tree structure object.
[0117] Initialize the data collector context. The data collector is used to record some key information when recursively traversing all nodes, such as the node currently being traversed, the parent node, and some special nodes, which are needed when parsing ts content later. When some nodes are converted, such as the form element input / checkbox, the generated v-model attribute needs to be combined with the v-model attribute value of the parent node form element to obtain.
[0118] See also Figure 4 and Figure 5 , the second document object model tree structure object consists of three types of nodes, namely text nodes, comment nodes and element nodes. Element nodes are nodes of type element, which contain attributes, tag name tagName and children; text nodes are nodes of type text, which contain text content; comment nodes are nodes of type comment, which contain text content. Among these nodes, text nodes do not need any processing, and comment nodes will be deleted before migration to the Vue framework environment. The focus is on the processing of element nodes.
[0119] During the process of recursively traversing and processing element nodes, lexical, syntactic, and semantic analysis and transformation of element node attributes, as well as mapping of tag names, are performed. Since there are many directives in the UI library (ng-zorro-antd) on which the Angular framework project depends, but they are components in the UI library (ant-design-vue) corresponding to the Vue framework environment. For example, tooltips, dropdown menus, etc. Therefore, directives and attributes need to be processed separately. So during the recursive process, useless ng-template element nodes are first filtered and deleted, then directives are processed, then attributes are processed, and finally tag names are mapped.
[0120] See Figure 6 , both directives and attributes will correspond to ordinary node elements and special node elements. In the code directory structure, cells can be understood as cells. Default is the processing of attributes and directives on ordinary node elements, and the others are the processing of attributes and directives on special element nodes, such as form-related element nodes like form / nz-form-item / se / select, and table-related st element nodes. Below, taking the frequently used form component as an example, it shows how element nodes perform attribute conversion.
[0121] Exemplarily, taking the conversion of the nz-form-item element node to the a-form-item element node as an example to illustrate the attribute processing process. The写法 of the attributes of the nz-form-item element node in the Angular framework component is:
[0122] <nz-form-item>
[0123] <nz-form-label nz-col nzSpan="6" nzRequired>Original Password
[0124] <nz-form-control nz-col nzSpan="17" nzErrorTip="The original password cannot be empty!">
[0125] <input type="password" nz-input placeholder="Please enter the original password" formControlName="ioldPassword" name="oldPassword"
[0126] minlength="1" autocomplete="off" / >
[0127]
[0128] .
[0129] The写法 of the attributes of the a-form-item element node in the Vue framework component is:
[0130] <a-form-item required:label-col="{'span':6}"label="Original Password":wrapper-col="{'span':17}"name="ioldPassword"
[0131] :rules="[{'required':true,'message':'The original password cannot be empty!','whitespace':true}]">
[0132] <a-input type="password" placeholder="Please enter the original password" v-model:value="loginForm.ioldPassword" name="oldPassword" minlength="1" autocomplete="off">
[0133] 。
[0134] When traversing the element nodes, when encountering an element node (Node A) with the tag name nz-form-item, execute the method in nzFormItemAttrs in the form-item file under cells:
[0135] (1) Process the attributes on Node A using the default general attribute processing method;
[0136] (2) Obtain the child node nz-form-label under Node A, and put the attributes such as label, label-col, required, html-for, help, etc. into the attribute array of Node A;
[0137] (3) Obtain the child node nz-form-control under Node A, and put the attributes such as wrapper-col, rules, validate-status, etc. into the attribute array of Node A. In this process, the acquisition of the attribute rules is analyzed from nzErrorTip. nzErrorTip is the string corresponding to the message information of the attribute required. There are the following two situations: one is an ordinary string. When the attribute required in step (2) is true, a verification rule rule can be obtained. The other situation is that the attribute required is a variable, and the verification rule needs to be completed after the TypeScript code content is parsed;
[0138] (4) Obtain the form controls such as input, select, switch, checkbox, etc. under nz-form-control, and obtain the attribute values of the formControlName and [(ngModel)] attributes of this form control as the name attribute value of Node A, and directly assign the child nodes under nz-form-control to Node A as the direct child nodes of Node A.
[0139] The processing principle of instructions is similar to that of attributes, except that instruction processing may require the addition of new nodes. If the node where the instruction is located is a component, a new element node needs to be extracted from the parent level as the carrier of this instruction.
[0140] For example, the instruction processing process is explained by taking the conversion of the nz-popover element node to the a-popover element node as an example. The instruction writing method of the nz-popover element node in the Angular framework component is as follows:
[0141]
[0142] [nzPopoverTitle]="title"[nzPopoverContent]="contentTemp"[nzPopoverVisible]="visible">
[0143] <ng-template#contentTemp>
[0144] <ul class="cell-reply-list">
[0145] <li*ngFor="let text of desc">{{text}}
[0146]
[0147] .
[0148] The instructions for the a-popover element node in the Vue framework component are written as follows:
[0149] <a-popover:title="title":visible="visible">
[0150] <a style="position:absolute;":style="{left:x+'px',top:y+'px'}"type="prim ary">
[0151] <template#content>
[0152] <ul class="cell-reply-list">
[0153] <li v-for="text in desc"> {{text}}
[0154]
[0155]
[0156] .
[0157] When traversing element nodes and encountering an element node with the tag name nz-popover, execute the following method:
[0158] (1) Create a new node with the label a-popover, delete the nzPopoverTitle, nzPopoverContent, and nzPopoverVisible related attributes from the original node and set them to the newly created node;
[0159] (2) The original node is the direct child of the new node a-popover;
[0160] (3) Replace nzPopoverTitle, nzPopoverContent, and nzPopoverVisible in the new node a-popover with title, content, and visible respectively, and move the template corresponding to content to the new node a-popover.
[0161] According to all updated element nodes, spaces caused by node deletion are deleted to obtain a first document object model tree structure object, which is stored in the data format of a JSON variable for subsequent processing.
[0162] The embodiment of the present application performs lexical, grammatical, and semantic analysis and conversion on a hypertext markup language template, and further divides the parsing of the hypertext markup language template into parsing of instructions and parsing of attributes, thereby reducing redundant operations in the conversion process and realizing automatic conversion of a hypertext markup language template under an Anug l ar framework into a hypertext markup language template under a Vue framework.
[0163] In some embodiments, step S104 may also include but is not limited to steps S501 to S502:
[0164] Step S501, traversing all element nodes in the first document object model tree structure object, extracting variables and methods in the element node attributes;
[0165] Step S502: synchronize the extracted variables and methods into the first TypeScript code.
[0166] In step S501 of some embodiments, it is necessary to first traverse all element nodes in the first document object model tree structure object and collect variables and methods from the node attributes. For example, v-if, v-for and v-model in the node attributes may correspond to variables or expressions, the node attribute :prop corresponds to an object or variable value, and the node attribute @emitName corresponds to a method.
[0167] In step S502 of some embodiments, the collected variable and method data are synchronized to the first TypeScript code so as to be processed during the first TypeScript code parsing process. For example, when the node contains an icon, the corresponding icon class needs to be imported when parsing the TypeScript code.
[0168] The embodiment of the present application collects variables and methods in a hypertext markup language template and synchronizes them to the TypeScript code, so that the variables and methods from the hypertext markup language template can be parsed in the subsequent parsing of the TypeScript code, which helps to improve the accuracy of the parsing.
[0169] In some embodiments, step S105 includes but is not limited to steps S601 to S603:
[0170] Step S601, according to the Vue variable definition rule, define the type of the first variable in the first TypeScript code, and parse the first variable using the corresponding parsing logic according to the type of the first variable to obtain a second variable, where the second variable is a Vue variable that complies with the Vue framework syntax specification;
[0171] Step S602, creating a corresponding abstract syntax tree structure object according to each first method body; traversing each node in the abstract syntax tree structure object to obtain a code fragment to be replaced; replacing the code fragment to be replaced by using a regular expression to obtain a second method body;
[0172] Step S603, according to the preset import statement rule, reference processing is performed on the first import statement to obtain a second import statement, wherein the reference processing includes one of reference deletion, reference replacement, common reference conversion or reference retention.
[0173] In step S601 of some embodiments, a variable in the Angul ar framework environment includes key information such as variable name name, variable initial value value, variable type type, template reference variable viewChild, template reference variable array viewChildren, isInput (indicating whether it is an @Input variable), and isOutput (indicating whether it is an @Output variable).
[0174] See also Figure 7 , Figure 7Provides a common variable in the Angular framework environment, indicating a variable type of string type, variable name "unusualTipWithoutPhone", and variable initial value "The system detects that you are logging in from an untrusted IP address, please go to a trusted IP address to log in!"
[0175] See also Figure 8 In the Vue framework environment, there are six types of variables, namely common variables, ref responsive variables, reactive responsive variables, emits event variables, model variables (variables representing two-way binding) and props variables (variables passed from the parent). According to the key information of variables in the Angular framework environment, the first variable in the first TypeScript code is defined as a type, and the first variable is parsed using the corresponding parsing logic according to the type of the first variable to obtain a Vue variable. The parsing conversion logic is as follows:
[0176] When isInput is true in the variable in the Angular framework environment and the variable value has not been modified in the component, the variable is converted to a props variable;
[0177] When isOutput is true in the variable in the Angular framework environment, the variable is converted into an emits event variable;
[0178] When variables in the Angular framework environment are collected from HTML templates, the variables are converted into ref responsive variables;
[0179] When isInput is true in the variable in the Angular framework environment and the variable value is modified in the component, the variable is converted to a model variable;
[0180] When the variable in the Angular framework environment is collected from the HTML template and the variable type is an object instead of an array, the variable is converted to a reactive variable.
[0181] When the variable in the Angular framework environment is a variable used in the method body, the variable is converted to a common variable.
[0182] Among them, the variable parsing in the Angular framework environment will definitely be converted into props variables, emits event variables, and ref responsive variables. Therefore, these three variables can be processed first. Other variables used in the method body can be parsed when they are encountered when parsing the method body. If there are variables that are not used after conversion, they will be deleted later.
[0183] In step S602 of some embodiments, the method body parsing applied in the hypertext markup language template is first started. If the method body calls other method bodies, recursive parsing is performed, and then the methods in the life cycle function are parsed.
[0184] See also Fig. 9 , Fig. 9 A flowchart for parsing a single method body is provided. Specifically, a section of the first method body can be intercepted from the first TypeScript code according to the start and end positions of the method body; an abstract syntax tree structure object is created through the createSourceTree method provided by the Compiler API; each node in the abstract syntax tree structure object is traversed, and during the traversal process, the variables used in the first method body are collected and the variables are parsed. In addition, if a section of code needs to be replaced, the original string before the code replacement and the string after the code replacement are collected into the same array for storage. If it is found that the method body calls other method bodies during the traversal of the first method body, for example, when parsing the method body A, it is found that the method body B is called, the parsing of the method body A is performed after the parsing of the method body B.
[0185] Since replacing the string of the first method body will cause the abstract syntax tree structure to change during the process of traversing the nodes to collect information, the recursive traversal of each node to collect information and the replacement of the method body should be divided into two steps. After traversing and collecting all the data of a single method body, the method body is replaced by a regular expression in the order of the collected code snippets, variables, constructor Service, and string this, and finally the second method body is obtained.
[0186] When processing variables, since the value of the variable may be a complex object with many attributes, some of which correspond to methods, the analysis of the variable value is also processed according to the logic of the method body. The value of the variable may also be an arrow. In this case, after conversion, the variable exists as a function in the Vue framework environment.
[0187] In step S603 of some embodiments, the first import statement is encountered in the process of parsing the first method body or the first variable. Therefore, the first import statement needs to be parsed while parsing the first method body and the first variable. Fig.10 , Fig.10 Provides a structure corresponding to an import statement. When parsing import statements, for Angular-related reference statements, for example, when LibraryName starts with @angular or ng-zorro-antd, the import statement is deleted from the source code, and the variable of type LibraryName is replaced with type any (type any is a special type provided by TypeScript, which does not perform type checking and can avoid compilation errors caused by type mismatch). Public reference conversion includes when LibraryName starts with @icc / common-lib and the specifier ends with Component, LibraryName is replaced with @icc / components; if the specifier ends with Service, LibraryName is replaced with @icc / hooks; other public methods are replaced with @icc / utils. When LibraryName is a reference to other external third-party libraries, such as date or rxjs, the import statement is retained. When splicing the TypeScript hook function body, for example, when encountering onMounted, an import statement with LibraryName as Vue and specifier as onMounted is added; when splicing ref or reactive variables, an import statement with LibraryName as Vue and specifier as ref or reactive is added.
[0188] The embodiment of the present application further divides the analysis of TypeScript code into the analysis of variables, method bodies and import statements by performing lexical, grammatical, and semantic analysis and conversion on TypeScript code. According to the Vue variable definition rule, the variables under the Vue environment are obtained according to the type of the first variable, the code fragments that need to be replaced in the first method body are replaced by regular expressions, and according to the preset import statement rules, the first import statement is referenced so that the converted component can run normally. In addition, the processing under the general scenario of TypeScript code and the processing under the special scenario are also considered, which can be applied in all Anguar projects, and the automatic conversion of the front-end framework can be realized only by expanding the special scenarios in the Anguar project.
[0189] In some embodiments, step S107 may include but is not limited to steps S701 to S704:
[0190] Step S701, write the second method body of the lifecycle function type into the hook function corresponding to the Vue environment to obtain the second method body of the hook function type;
[0191] Step S702, after assembling the second method bodies of all hook function types, assemble the second method bodies of common function types to obtain a first assembly code;
[0192] Step S703, assembling different types of second variables in sequence on the first assembly code according to the concatenation order of different types of second variables to obtain a second assembly code;
[0193] Step S704, assembling a second import statement on the second assembly code to obtain a second TypeScript code that complies with the Vue framework syntax specification.
[0194] See also Fig.11 In some embodiments, TypeScript codes of the second method body, the second variable, and the second import statement are generated and linked in a bottom-up manner.
[0195] First, assemble the second method body. The method body is divided into life cycle functions and ordinary functions. Except for the ngOninit life cycle function, which can be called directly in the Vue environment, other life cycle functions in the Angular environment can be called in the Vue environment by finding the corresponding hook function. For example, the ngOnChanges method body can be written into the watchEffect hook function, the ngAfterViewInit method body can be written into the onMounted hook function, the ngOnDestroy method body can be written into the onUnmounted hook function, and the ngAfterViewChecked method body can be written into the onUpdated hook function. After splicing the life cycle functions, splice other ordinary functions to obtain the first assembly code corresponding to multiple second method bodies.
[0196] Then, the second variable is spliced on the first assembly code. There are six types of variables in the Vue environment. According to the Vue specification, the second variable is spliced and assembled in order according to the type, and the second assembly code that assembles the second method body and the second variable is obtained. The splicing order of the second variable is: props variable, emits event variable, common variable, ref responsive variable, reactive responsive variable and model variable.
[0197] Finally, assemble the second import statement on the second assembly code. The top part is the import statement, followed by the useHooks statement, and then connect it to the variable. If there are other statements between the component class and the import statement in the Angular framework component, these statements are spliced on the variable, and finally a complete TypeScript code (the second TypeScript code) is output.
[0198] The embodiment of the present application splices the method body, variables, and import statements in the TypeScript code separately, and assembles the three parts into a complete TypeScript code in a bottom-up order, so as to reduce the occurrence of front-end framework component conversion errors caused by syntax or specification mismatch, follow the syntax specifications of the Vue framework, and improve the quality of the TypeScript code.
[0199] Below, in conjunction with specific application examples, the scheme of the embodiment of the present application is described in detail and explained:
[0200] Angu l ar components cover many application scenarios. For example, a component can be a form page, a modal pop-up window, or a part of a page with complex interactive logic. It is difficult to find a general rule that can cover all application scenarios, so special processing is required for multiple application scenarios. Now, taking the page scenario as the application scenario and the component as the unit, an Anuglar component is automatically converted into a Vue component by implementing the code automatic conversion tool ng2vue of the embodiment of the present application.
[0201] In order to implement this automatic code conversion tool, the three parts of the component are processed separately.
[0202] The style part is not framework-specific and is universal in any framework. From Angular to Vue, only the style syntax in the UI library is different, and everything else is universal, so the conversion and migration cost of less is very small. However, the html template part and ts part are quite different in the two frameworks. This difference comes from the underlying syntax differences of the frameworks on the one hand, and the differences in the dependent UI library components on the other hand. For example, the Service in the Angular environment also has a form of obtaining the parent component, which has no corresponding usage in the Vue environment, but can be replaced by other methods to achieve the same effect.
[0203] The parsing and transformation of the HTML template part can be done with the help of the third-party tool library "himalaya", which generates a tree structure, performs grammatical and semantic analysis on the attributes, tag name, and text content of each node, and then makes a transformation, and then regenerates the tree into an HTML template string.
[0204] The parsing and conversion of the ts part can be done with the help of the third-party tool library "typescript-parser". The Compiler Api provided by the Typescript language itself generates an abstract syntax tree structure object, extracts the key information in it to get the File object, and also needs to go through grammatical and semantic analysis, perform code conversion, and then regenerate a ts code snippet.
[0205] See also Fig.12 In the embodiment of the present application, the solution can be regarded as three processes:
[0206] (1) Create a ComponentNg2Vue instance object. In the constructor of the ComponentNg2Vue instance object, create an Htm l Parser parsing object for parsing and generating HTML templates, a Collect collector object for parsing expressions in HTML templates and collecting variables and methods used in HTML templates, and a TsParser parsing object for parsing and generating ts code.
[0207] (2) Call the parse method in the ComponentNg2Vue instance object to pass in the file path of the Angular framework component, read the file content according to the path, and generate a File object. The File object contains all the information of the component, and can obtain the content of the three parts of this component: obtain the ess style content from styleURLs / styles and convert it through regular expressions; obtain the html template content from the template / templateURL field, parse and convert it through the parse method of the HtmlParser object, and collect data from the html, such as variables and methods, and put them into the collection data collection object; parse the ts content and convert it through the parse method of the TsParser object combined with the data in the collector. Among them, the ts content is much more complicated to process than the html template content. The analysis of the ts content can be done through the Compiler API provided by the Typescript language, calling the createSourceFile method to obtain an AST tree structure, analyze and judge the code syntax, and then disassemble, convert, and reorganize. The content that needs to be processed is divided into three parts: processing the attribute variables contained in the component class, processing the methods of the component class, and processing the import statements. There are also some code snippets that need special processing, such as the Service in the constructor, which has no corresponding application method in the Vue environment and can be replaced by hooks. Therefore, the Service reference in the constructor is parsed first, converted to a reference to hooks, and then the variables are parsed first, then the methods are parsed, and finally the import statements are parsed.
[0208] (3) Call the toTempa lte method to pass in the storage location of the Vue file. Regenerate the code and write it into the Vue file after parsing and converting the content in the previous step.
[0209] See also Figure 13(a) to Figure 13(b) By implementing the method of the embodiment of the present application, the three parts of code in the Angul ar framework component can be converted into the Vue framework component, thereby realizing automatic conversion of the front-end framework component.
[0210] The embodiment of the present application also provides a front-end framework component automatic conversion system, which can implement the above-mentioned front-end framework component automatic conversion method, and the system includes:
[0211] The first module is used to obtain a first cascading style sheet, a hypertext markup language template and a first TypeScript code of an Anglar framework component file;
[0212] The second module is used to parse and convert the first cascading style sheet to obtain a second cascading style sheet;
[0213] The third module is used to perform syntax and semantic analysis and conversion on the hypertext markup language template to obtain a first document object model tree structure object of the hypertext markup language template;
[0214] The fourth module is used to collect data from the first document object model tree structure object and synchronize the collected data to the first TypeScript code;
[0215] A fifth module is used to perform grammatical semantic analysis and conversion on the first variable, the first method body and the first import statement in the first TypeScript code respectively, and obtain the second variable, the second method body and the second import statement accordingly;
[0216] A sixth module, used for converting the first document object model tree structure object into a hypertext markup language template string;
[0217] The seventh module is used to splice multiple second method bodies, second variables and second import statements to obtain a second TypeScript code that conforms to the syntax specification of the Vue framework;
[0218] The eighth module is used to create a Vue file, write the second cascading style sheet, the hypertext markup language template string and the second TypeScript code into the corresponding tags in the Vue file according to preset rules, and obtain the Vue framework component file.
[0219] It can be understood that the contents of the above method embodiments are all applicable to the present system embodiments, the functions specifically implemented by the present system embodiments are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above method embodiments.
[0220] The embodiment of the present application also provides an electronic device, the electronic device includes a memory and a processor, the memory stores a computer program, and the processor implements the above-mentioned front-end framework component automatic conversion method when executing the computer program. The electronic device can be any intelligent terminal including a tablet computer, a car computer, etc.
[0221] It can be understood that the contents of the above method embodiments are all applicable to the present device embodiments, the functions specifically implemented by the present device embodiments are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above method embodiments.
[0222] An embodiment of the present application also provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the above-mentioned front-end framework component automatic conversion method is implemented.
[0223] It can be understood that the contents of the above method embodiments are all applicable to the present storage medium embodiments, the functions specifically implemented by the present storage medium embodiments are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above method embodiments.
[0224] The memory, as a non-transient computer-readable storage medium, can be used to store non-transient software programs and non-transient computer executable programs. In addition, the memory may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory may optionally include a memory remotely disposed relative to the processor, and these remote memories may be connected to the processor via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0225] The embodiments described in the embodiments of the present application are intended to more clearly illustrate the technical solutions of the embodiments of the present application and do not constitute a limitation on the technical solutions provided in the embodiments of the present application. Those skilled in the art will appreciate that with the evolution of technology and the emergence of new application scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.
[0226] Those skilled in the art will appreciate that the technical solutions shown in the figures do not constitute a limitation on the embodiments of the present application, and may include more or fewer steps than shown in the figures, or combine certain steps.
[0227] The system embodiments described above are merely illustrative, and the units described as separate components may or may not be physically separated, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the present embodiment.
[0228] Those skilled in the art will appreciate that all or some of the steps in the methods disclosed above, and the functional modules / units in the systems and devices may be implemented as software, firmware, hardware, or a suitable combination thereof.
[0229] The preferred embodiments of the present invention are described above with reference to the accompanying drawings, but the scope of the rights of the present invention is not limited thereto. Any modification, equivalent substitution and improvement made by a person skilled in the art without departing from the scope and essence of the present invention should be within the scope of the rights of the present invention.
Claims
1. A method for automatic conversion of front-end framework components, characterized in that: The method comprises the following steps: Get the first cascading style sheet, the HTML template and the first TypeScript code of the Angular framework component file; Parsing and converting the first cascading style sheet to obtain a second cascading style sheet; Performing syntax and semantic analysis and conversion on the hypertext markup language template to obtain a first document object model tree structure object of the hypertext markup language template; Collecting data from the first document object model tree structure object, and synchronizing the collected data to the first TypeScript code; Performing grammatical and semantic parsing and conversion on the first variable, the first method body, and the first import statement in the first TypeScript code respectively, and obtaining a second variable, a second method body, and a second import statement accordingly; Converting the first document object model tree structure object into a hypertext markup language template string; Concatenate multiple second method bodies, second variables, and second import statements to obtain a second TypeScript code that complies with the syntax specification of the Vue framework; A Vue file is created, and the second cascading style sheet, the hypertext markup language template string and the second TypeScript code are written into corresponding tags in the Vue file according to preset rules to obtain a Vue framework component file.
2. The method according to claim 1, characterized in that: The method of obtaining a first cascading style sheet, a hypertext markup language template, and a first TypeScript code of an Angular framework component file comprises the following steps: Obtain a first cascading style sheet reference path, a hypertext markup language template reference path and a first TypeScript code; Reading a first cascading style sheet according to the first cascading style sheet reference path; The hypertext markup language template is read according to the hypertext markup language template reference path.
3. The method according to claim 1, characterized in that The parsing and converting the first cascading style sheet to obtain a second cascading style sheet comprises the following steps: Parsing the first cascading style sheet to obtain a target modified portion that needs to be replaced in the first cascading style sheet; The target modification part is converted by a regular expression to obtain a second cascading style sheet.
4. The method according to claim 1, characterized in that: The step of parsing and converting the hypertext markup language template to obtain a first document object model tree structure object of the hypertext markup language template includes the following steps: Parsing the character string of the hypertext markup language template by a parser to obtain a second document object model tree structure object, wherein the second document object model tree structure object includes a plurality of element nodes, and the element nodes are used to represent instructions or attributes; Recursively traverse the element nodes in the second document object model tree structure object, delete useless element nodes in the second document object model tree structure object, and record the parent nodes of the traversed element nodes and the traversed special element nodes into the data collector; Performing grammatical semantic parsing and conversion on the element nodes corresponding to the instructions in the second document object model tree structure object, and updating to obtain element nodes that conform to the Vue framework instruction grammar specification; Performing grammatical semantic parsing and conversion on the element nodes of the corresponding attributes in the tree structure object of the second document object model, and updating to obtain element nodes that conform to the grammatical attribute specifications of the Vue framework; According to all updated element nodes, a first document object model tree structure object is obtained.
5. The method according to claim 4, characterized in that The step of collecting data from the first document object model tree structure object and synchronizing the collected data to the first TypeScript code includes the following steps: Traversing all element nodes in the first document object model tree structure object, and extracting variables and methods in the element node attributes; The extracted variables and methods are synchronized to the first TypeScript code.
6. The method according to claim 1, characterized in that The step of respectively performing grammatical and semantic parsing and conversion on the first variable, the first method body and the first import statement in the first TypeScript code to obtain the second variable, the second method body and the second import statement comprises the following steps: According to the Vue variable definition rule, a type is defined for the first variable in the first TypeScript code, and the first variable is parsed using a corresponding parsing logic according to the type of the first variable to obtain a second variable, where the second variable is a Vue variable that complies with the Vue framework syntax specification; Creating a corresponding abstract syntax tree structure object according to each of the first method bodies; traversing each node in the abstract syntax tree structure object to obtain a code fragment to be replaced; replacing the code fragment to be replaced by using a regular expression to obtain a second method body; According to preset import statement rules, the first import statement is referenced to obtain a second import statement, wherein the reference processing includes one of reference deletion, reference replacement, common reference conversion or reference retention.
7. The method according to claim 6, characterized in that The step of splicing the plurality of second method bodies, the second variables and the second import statements to obtain a second TypeScript code that complies with the syntax specification of the Vue framework includes the following steps: Write the second method body of the life cycle function type into the hook function corresponding to the Vue environment to obtain the second method body of the hook function type; After assembling the second method bodies of all the hook function types, assemble the second method bodies of the common function types to obtain a first assembly code; According to the concatenation order of different types of second variables, sequentially assemble different types of the second variables on the first assembly code to obtain a second assembly code; The second import statement is assembled on the second assembly code to obtain a second TypeScript code that complies with the syntax specification of the Vue framework.
8. A front-end frame component automatic conversion system, characterized in that: The system comprises: The first module is used to obtain a first cascading style sheet, a hypertext markup language template and a first TypeScript code of an Angular framework component file; A second module is used to parse and convert the first cascading style sheet to obtain a second cascading style sheet; The third module is used to perform syntax and semantic analysis and conversion on the hypertext markup language template to obtain a first document object model tree structure object of the hypertext markup language template; A fourth module is used to collect data from the first document object model tree structure object and synchronize the collected data to the first TypeScript code; A fifth module is used to perform grammatical and semantic analysis and conversion on the first variable, the first method body and the first import statement in the first TypeScript code respectively, and obtain a second variable, a second method body and a second import statement accordingly; A sixth module, configured to convert the first document object model tree structure object into a hypertext markup language template string; A seventh module is used to concatenate multiple second method bodies, second variables and second import statements to obtain a second TypeScript code that complies with the syntax specification of the Vue framework; The eighth module is used to create a Vue file, write the second cascading style sheet, the hypertext markup language template string and the second TypeScript code into corresponding tags in the Vue file according to preset rules, and obtain a Vue framework component file.
9. An electronic device, characterized in that: The electronic device comprises a memory and a processor, the memory stores a computer program, and the processor implements the method according to any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
