WO2023087720A1 - Applet generation method and apparatus, device and storage medium - Google Patents

Applet generation method and apparatus, device and storage medium Download PDF

Info

Publication number
WO2023087720A1
WO2023087720A1 PCT/CN2022/102158 CN2022102158W WO2023087720A1 WO 2023087720 A1 WO2023087720 A1 WO 2023087720A1 CN 2022102158 W CN2022102158 W CN 2022102158W WO 2023087720 A1 WO2023087720 A1 WO 2023087720A1
Authority
WO
WIPO (PCT)
Prior art keywords
file
syntax tree
abstract syntax
applet
target
Prior art date
Application number
PCT/CN2022/102158
Other languages
French (fr)
Chinese (zh)
Inventor
朱桂锋
林挺
Original Assignee
深圳前海微众银行股份有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 深圳前海微众银行股份有限公司 filed Critical 深圳前海微众银行股份有限公司
Publication of WO2023087720A1 publication Critical patent/WO2023087720A1/en

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/37Compiler construction; Parser generation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • G06F8/427Parsing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/44Encoding
    • G06F8/447Target code generation

Definitions

  • the present application relates to the field of computer technology, and in particular to a small program generation method, device, equipment and storage medium.
  • WeChat applets are applications that can be used without downloading and installing. Users can open the application by scanning or searching, which embodies an instant usage concept and is widely used.
  • applets cannot load content such as HTML (Hyper Text Markup Language) pages, and these HTML pages need to be able to be opened during the use of the applet, so it needs to be used according to the existing HTML pages.
  • HTML Hyper Text Markup Language
  • the component generates applet components.
  • HTML pages can be formed using VUE components, and the file content of VUE components includes HTML template files, JavaScript (JS) files, and Cascading Style Sheets (Cascading Style Sheets, CSS) files.
  • JS JavaScript
  • CSS Cascading Style Sheets
  • the above two existing methods have defects.
  • the manual replacement method is inefficient, cannot guarantee the correctness of the replacement result, and requires manual inspection.
  • the position of the replaced code is difficult to record, resulting in a lack of correspondence between the codes before and after the replacement. Therefore, in the subsequent modification and maintenance stage, it is necessary to rely on manual positioning of the location of the error.
  • an error occurs at the grammatical level, there is a lack of tool assistance, resulting in repeated development of the same function.
  • the way of replacing by regular expressions is rough and general for code processing, and it takes a long time to locate the problem, and when encountering long strings, the efficiency of regular expressions is relatively low. It can be seen that there is an urgent need for a method for generating applets to overcome the above-mentioned technical defects in the existing technology of generating applet components based on VUE components.
  • the present application provides a small program generation method, device, device and storage medium, which are used to provide a small program generation method to overcome the existing technical defects of replacing VUE components by manual replacement or regular expression replacement.
  • the present application provides a method for generating a small program, including:
  • each component file in described VUE component comprises page file, JS file and cascading style sheet CSS file;
  • each of the component files includes a Wechat markup language WXML temporary file, a JS temporary file and a Wechat Cascading Style Sheet WXSS temporary file;
  • the preset conversion strategy includes traversing each abstract syntax tree Each node of each node is modified to modify the target node of each abstract syntax tree, and each abstract syntax tree is correspondingly formed for the code in each temporary file.
  • the codes in each temporary file are converted according to the preset conversion strategy to obtain corresponding applet component files, including:
  • the preset conversion policy includes the first preset conversion rule, the second preset conversion rule, and the third preset conversion rule
  • the applet component files include the WXML target file, The JS target file and the WXSS target file.
  • the code in the WXML temporary file is converted according to a first preset conversion rule to generate a WXML target file, including:
  • the modifying the first abstract syntax tree according to the first preset conversion rule to obtain the first target abstract syntax tree includes:
  • the first preset conversion rule includes the preset tag mapping table and the format modification rule.
  • the format modification rules include:
  • the event binding format in the first abstract syntax tree is modified to the applet event binding format.
  • the code in the JS temporary file is converted according to the second preset conversion rule to generate a JS target file, including:
  • modifying the second abstract syntax tree according to the second preset conversion rule to obtain a second target abstract syntax tree includes:
  • the attribute modification rules include:
  • the code in the WXSS temporary file is converted according to a third preset conversion rule to generate a WXSS target file, including:
  • the third abstract syntax tree includes a description of all content in the CSS tag
  • the traversing and modifying the third abstract syntax tree according to the third preset conversion rule to obtain a third target abstract syntax tree includes:
  • the third abstract syntax tree is traversed, and the third abstract syntax tree is modified according to the selector modification rule to obtain the third target abstract syntax tree, and the third preset conversion rule includes the selector modification rule.
  • the selector modification rule includes:
  • Logging is used to record limited selectors, the limited selectors being any selectors not supported by the applet in the third abstract syntax tree.
  • the information file is generated according to the code in the JS target file, and the information file is used to record the position information of the code of each applet component file in the code of the VUE component.
  • the preset asynchronous reading tool before using the preset asynchronous reading tool to read the VUE component, it also includes:
  • a work order is generated according to the component generation requirement, and a command line tool is executed in response to the work order, and the command line tool is used to enable the applet generation method.
  • the present application provides a small program generation device, including:
  • the acquisition module is used to read the VUE component using a preset asynchronous reading tool to obtain each component file in the VUE component, and each component file includes a page file, a JS file and a cascading style sheet CSS file;
  • the storage module is used to store the codes in each of the component files correspondingly to each temporary file respectively, and each of the temporary files includes a Wechat markup language WXML temporary file, a JS temporary file and a Wechat Cascading Style Sheet WXSS temporary file;
  • a processing module configured to convert the code in each temporary file according to a preset conversion strategy to obtain corresponding applet component files, so as to generate applets according to the applet component files, and the preset conversion strategy includes traversing Each node of each abstract syntax tree is used to modify the target node of each abstract syntax tree, and each abstract syntax tree is correspondingly formed for the code in each temporary file.
  • the present application provides an electronic device, including:
  • a memory for storing the computer program of the processor
  • the processor is configured to implement any possible applet generating method provided in the first aspect by executing the computer program.
  • the present application provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, any possible applet generation method provided in the first aspect is implemented.
  • the present application further provides a computer program product, including a computer program, and when the computer program is executed by a processor, any possible applet generation method provided in the first aspect is implemented.
  • This application provides a small program generation method, device, equipment and storage medium.
  • First use the preset asynchronous reading tool to read the VUE component to obtain each component file in the VUE component.
  • Each component file includes a page file, a JS file, and a cascaded Style sheet CSS file.
  • the codes in each component file are correspondingly stored in each temporary file, and each temporary file includes a WeChat markup language WXML temporary file, a JS temporary file and a WeChat Cascading Style Sheet WXSS temporary file.
  • the code in each temporary file is converted according to the preset conversion strategy to obtain the component files of each applet, and the conversion from the VUE component to the applet component is completed, and then the applet is generated according to the component files of each applet.
  • the preset conversion strategy includes traversing each node of each abstract syntax tree to modify the target node of each abstract syntax tree, and each abstract syntax tree is correspondingly formed by codes in each temporary file.
  • the applet components are converted based on the preset conversion strategy, which effectively improves the efficiency of obtaining applet components and generating applets, making the granularity of modifiable content smaller, ensuring the correctness of the obtained applet components, and You can know the correspondence between codes before and after modification, which is convenient for subsequent maintenance.
  • FIG. 1 is a schematic diagram of an application scenario provided by an embodiment of the present application
  • FIG. 2 is a schematic flowchart of a method for generating a small program provided by an embodiment of the present application
  • FIG. 3 is a schematic diagram of file storage provided by an embodiment of the present application.
  • FIG. 4 is a schematic flowchart of another applet generation method provided by the embodiment of the present application.
  • FIG. 5 is a schematic flowchart of another method for generating a small program provided by the embodiment of the present application.
  • FIG. 6 is a schematic flowchart of another applet generation method provided by the embodiment of the present application.
  • FIG. 7 is a schematic flowchart of another method for generating a small program provided by the embodiment of the present application.
  • FIG. 8 is a schematic structural diagram of a small program generation device provided by an embodiment of the present application.
  • FIG. 9 is a schematic structural diagram of a processing module provided in an embodiment of the present application.
  • FIG. 10 is a schematic structural diagram of an electronic device provided by the present application.
  • HTML pages can be formed using VUE components, which include HTML templates, JavaScript (JS) components, and Cascading Style Sheets (Cascading Style Sheets, CSS) components.
  • VUE components include HTML templates, JavaScript (JS) components, and Cascading Style Sheets (Cascading Style Sheets, CSS) components.
  • JS JavaScript
  • CSS Cascading Style Sheets
  • this application provides a method for generating a small program.
  • the inventive idea is to: store the codes in each component file included in the VUE component in each temporary file, and then use the preset conversion strategy to The code in each temporary file is converted to obtain corresponding applet component files, complete the conversion from VUE components to applet components, and then generate applets based on each applet component file.
  • the preset conversion strategy includes traversing each node of each abstract syntax tree to modify the target node of each abstract syntax tree, and each abstract syntax tree is formed correspondingly by the codes in each temporary file, thus in this application
  • the implementation process of converting VUE components based on the preset conversion strategy to obtain applet components makes the granularity of the modifiable content smaller, ensures the correctness of the obtained applet components, and effectively improves the process of obtaining each applet component and generating The efficiency of the applet, and the corresponding relationship between the before and after code can also be modified to facilitate subsequent code maintenance.
  • FIG. 1 is a schematic diagram of an application scenario provided by an embodiment of the present application.
  • the network is used as a medium for providing a communication link between the server 11 and the terminal device 12 .
  • a network may include various connection types such as wires, wireless communication links, or fiber optic cables, among others.
  • the server 11 and the terminal device 12 can interact through the network to receive or send messages.
  • the server 11 can be configured as a corresponding electronic device that executes the applet generation method provided by the embodiment of the present application, and the terminal device 12 can run the generated applet.
  • the applet generation method provided by the embodiment of the application is executed by the server 11 to convert the VUE components into various applet components, and then generate applets, so that the applets formed by the VUE components, such as HTML pages, can be loaded on the terminal device 12 .
  • the server 11 can also be a server cluster
  • the terminal device 12 can be a smart phone, smart glasses, smart bracelet, smart watch, tablet computer, etc. etc.
  • the terminal device 12 in FIG. 1 is illustrated by taking a smart phone as an example.
  • FIG. 2 is a schematic flowchart of a method for generating a small program provided by an embodiment of the present application.
  • the applet generation method provided by the embodiment of the present application includes:
  • S101 Read the VUE component by using a preset asynchronous reading tool to obtain each component file in the VUE component.
  • each component file includes a page file, a JS file, and a cascading style sheet CSS file.
  • the VUE component is an abstract data type of view and interaction logic, which contains HTML templates, CSS styles, and JS logic code fragments.
  • the ist-loader plugin of the webpack packaging tool can compile VUE components into runnable H5 code.
  • the VUE component is read by a preset asynchronous reading tool, and each component file is obtained according to its contained content, that is, the page file, JS file and CSS file of the cascading style sheet are obtained.
  • the page file can be understood as a file storing HTML template codes
  • the JS file can be understood as a file storing JS logic code fragments
  • the CSS file can be understood as a file storing CSS style codes. Therefore, by reading the file content of the VUE component, each component file can be obtained according to the file content contained in it.
  • Each component file is shown in the left part of Figure 3, and Figure 3 is a file storage provided by the embodiment of the present application. schematic diagram.
  • the preset asynchronous reading tool can be, for example, fs.readFileSync, which is used to asynchronously read the content of each part of the file contained in the VUE file.
  • the preset asynchronous reading tool before using the preset asynchronous reading tool to read VUE components, it also includes:
  • a work instruction is generated according to the component generation requirement, and a command line tool is run in response to the work order, wherein the command line tool is used to enable the applet generation method provided by the embodiment of the present application.
  • the component generation requirements are used to represent the current component conversion requirements, and the existing VUE components need to be converted.
  • an auxiliary tool can be set to convert the VUE components through the auxiliary tool, which is a command-line tool capable of enabling the applet generation method provided by the embodiment of the present application in response to a work order.
  • the specific working prompt corresponding to the command line tool can be set according to the actual situation, which is not limited in this embodiment of the present application.
  • each temporary file includes WeChat Markup Language (WeiXin Markup Language) WXML temporary files, JS temporary files, and WeChat Cascading Style Sheets (WeiXinStyle Sheets) WXSS temporary files.
  • the codes in each component file obtained from the VUE components in corresponding temporary files. Further, the codes in each temporary file are converted respectively. For example, based on the correspondence between the codes in each component file and the codes in each applet component file to be converted to eventually, the code in the page file can be stored in the WXML temporary file, and the code in the JS file can be stored in the The JS temporary file stores the code in the CSS file to the WXSS temporary file.
  • the right part of FIG. 3 shows the temporary files where the component files are correspondingly stored.
  • the document format in each temporary file can be set according to the actual situation, for example, it can be a notepad format, a document format, etc., which is not limited in this embodiment of the present application.
  • S103 Convert the code in each temporary file according to a preset conversion strategy to obtain corresponding applet component files, so as to generate a applet according to each applet component file.
  • the preset conversion strategy includes traversing each node of each abstract syntax tree to modify the target node of each abstract syntax tree, and each abstract syntax tree is correspondingly formed for the code in each temporary file.
  • each applet component file When converting the code in each temporary file to obtain each applet component file, a preset conversion strategy is introduced to traverse each node of each abstract syntax tree to modify the node that needs to be modified, that is, the target node Purpose, the codes in each temporary file correspond to form their respective abstract syntax trees. After converting the codes in each temporary file according to the preset conversion strategy, the converted temporary files are correspondingly determined as applet component files, so as to obtain corresponding applet component files. On the basis of obtaining each applet component file, the applet is generated by reading and loading the obtained file content in each applet component file. Wherein, the file content in each applet component file is each applet component obtained after conversion.
  • the target file with the suffix of JSON is the configuration JSON file of the applet, and the content of the file is ⁇ "component": true ⁇ .
  • FIG. 4 is a schematic flowchart of another method for generating a small program provided by an embodiment of the present application. As shown in Figure 4, the embodiment of this application includes:
  • S201 Convert the code in the WXML temporary file according to a first preset conversion rule to generate a WXML target file.
  • S203 Convert the code in the WXSS temporary file according to the third preset conversion rule to generate a WXSS target file.
  • the preset conversion strategy includes a first preset conversion rule, a second preset conversion rule, and a third preset conversion rule
  • each applet component file includes a WXML object file, a JS object file, and a WXSS object file.
  • the preset conversion strategy includes a first preset conversion rule, a second preset conversion rule and a third preset conversion rule, wherein the first preset conversion rule is a specific rule for converting the code in the WXML temporary file, and the second The preset conversion rule is a specific rule for converting codes in the JS temporary file, and the third preset conversion rule is a specific rule for converting codes in the WXSS temporary file.
  • the WXML temporary file is determined as the WXML target file, that is, the code in the WXML target file is the code converted by the first preset conversion rule .
  • the JS temporary file is determined as the JS target file, that is, the code in the JS target file is the code converted by the second preset conversion rule.
  • the CSS temporary file is determined as the CSS target file, that is, the code in the CSS target file is the code converted by the third preset conversion rule.
  • the specific contents of the first preset conversion rule, the second preset conversion rule and the third preset conversion rule are required for converting the codes in each temporary file into corresponding applet components. code, and when using the first preset conversion rule, the second preset conversion rule, and the third preset conversion rule, the abstract syntax tree corresponding to the code in each temporary file is used, so that by traversing each abstract syntax tree and modify the target node of each abstract syntax tree to realize the conversion of the code in each temporary file to the corresponding applet code, improve the conversion efficiency and make the granularity of the modifiable content smaller, thereby ensuring Revised for correctness.
  • the target node of each abstract syntax tree is the node where there is a difference between the VUE component and the applet component.
  • an information file is also generated according to the code in the JS target file, and the information file is used to record the position information of the code of each applet component file in the code of the VUE component, which is convenient for later debugging.
  • the applet generation method first uses the preset asynchronous reading tool to read the VUE component to obtain each component file in the VUE component, and each component file includes a page file, a JS file and a CSS file. Then, the codes in each component file are correspondingly stored in each temporary file, and each temporary file includes a WXML temporary file, a JS temporary file, and a WXSS temporary file. Finally, convert the code in each temporary file according to the preset conversion strategy to obtain each applet component file, complete the conversion from VUE component to applet component, and then generate the applet according to the file content in each applet component file.
  • the preset conversion strategy includes traversing each node of each abstract syntax tree to modify the target node of each abstract syntax tree, and each abstract syntax tree is correspondingly formed by codes in each temporary file.
  • the applet components are converted based on the preset conversion strategy, which effectively improves the efficiency of obtaining applet components and generating applets, making the granularity of modifiable content smaller, ensuring the correctness of the obtained applet components, and You can know the correspondence between codes before and after modification, which is convenient for subsequent maintenance.
  • FIG. 5 is a schematic flowchart of another method for generating a small program provided by the embodiment of the present application. As shown in Figure 5, the embodiment of this application includes:
  • S2011 Read the WXML temporary file by using a preset asynchronous reading tool to obtain the code in the WXML temporary file.
  • asynchronous reading tool Use the preset asynchronous reading tool to read the file content of the WXML temporary file, so as to obtain the code in the WXML temporary file, wherein the step is to use the preset asynchronous reading tool to read the file content of the WXML temporary file and read it into The process of converting the content of the file into the corresponding string.
  • Preset asynchronous read tools such as fs.readFileSync.
  • the first abstract syntax tree includes descriptions of all contents in the page file.
  • a page parser such as htmlparser2 to parse the code in the WXML temporary file, that is, parse the string obtained in the above steps, and obtain an abstract syntax tree corresponding to the code in the WXML temporary file, that is, the first abstract syntax tree.
  • the abstract syntax tree (Abstract Syntax Tree, AST) is a tree representation of the abstract syntax structure of the source code, and each node on the tree is the structured abstract data of the corresponding node in the source code. Therefore, the first abstract syntax tree defines each part in the page file in detail, that is, the first abstract syntax tree includes descriptions of all contents in the page file.
  • S2013 Modify the first abstract syntax tree according to the first preset conversion rule to obtain the first target abstract syntax tree.
  • the first abstract syntax tree is modified by using the first preset conversion rule, and the modified first abstract syntax tree is determined as the first target abstract syntax tree to obtain the first target abstract syntax tree.
  • the specific content of the first preset conversion rule is the corresponding rule followed when modifying the code in the WXML temporary file to the code required by the corresponding applet.
  • the applet for the content involved in the code in the WXML temporary file, the content in the DOCTYPE tag at the top is not needed, and only the content in the body tag is required.
  • the body tag may have only one child element div,
  • the div has two child elements, which are text (TEXT) "VUE TO MP" and a label (ELEMENT) span.
  • the label span has only one child element, which is "This is detail.” of type text (TEXT).
  • the abstract syntax tree obtained by modifying the first abstract syntax tree according to the first preset conversion rule is the first target abstract syntax tree, and step S2014 can be executed to obtain the WXML target file.
  • S2014 Generate a first object code according to the first object abstract syntax tree, and obtain a WXML object file according to the first object code.
  • the content represented by the first object abstract syntax tree is determined as the first object code, that is, the first object code is generated according to the first object abstract syntax tree, and the file to which the first object code belongs is determined as a WXML object file, that is, according to The first target code obtains the WXML target file, thereby completing the conversion of the code in the page file in the VUE component to the code in the WXML target file in the applet component file.
  • step S2013 includes:
  • the form tag is customized for describing standard HTML tags in the page file that are different from the applet component.
  • the preset label mapping table is shown in Table 1 below:
  • the target node of the first abstract syntax tree is modified according to the format modification rule, and then the first abstract syntax tree after the preset expression mapping table is replaced and the format modification rule is modified is determined as the first target abstract syntax tree.
  • the first preset conversion rule adopted for modifying the first abstract syntax tree includes the above preset expression mapping table and format modification rules.
  • the format modification rule includes specific modification content involved in modifying the target node of the first abstract syntax tree so that the format of the modified code meets the requirements of the applet component.
  • format modification rules may include the following content:
  • conditional rendering format in the first abstract syntax tree For example, modify the conditional rendering format in the first abstract syntax tree to the applet conditional rendering format.
  • conditional rendering format in the VUE component is written as follows:
  • the node to which the content representing list rendering, conditional rendering and event binding belongs in the first abstract syntax tree is the target node of the first abstract syntax tree.
  • the code in the WXML temporary file is converted according to the first preset conversion rule to obtain the WXML object file, and the code in the WXML object file is used to represent the WXML template in the applet component.
  • the target node of the first abstract syntax tree is modified by traversing the first abstract syntax tree and according to the preset tag mapping table and format modification rules included in the first preset conversion rule, so that the WXML target obtained after modification
  • the code in the file meets the running requirements of the applet, which not only improves the conversion efficiency of the code in the page file in the VUE component to the code in the WXML target file, but also makes the granularity of the modifiable content smaller, ensuring the obtained WXML target
  • the correctness of the code in the file, and the corresponding relationship between the code in the page file and the code in the WXML target file, that is, the code before and after modification, is convenient for subsequent code maintenance and error location.
  • FIG. 6 is a schematic flowchart of another applet generation method provided by the embodiment of the present application. As shown in Figure 6, the embodiment of this application includes:
  • S2021 Use a preset asynchronous reading tool to read the JS temporary file to obtain the code in the JS temporary file.
  • this step is to use the preset asynchronous reading tool to read the file content of the JS temporary file and read it into The process of converting the content of the file into the corresponding string.
  • the second abstract syntax tree includes a description of all contents in the JS file.
  • the parse method such as @babel/parser to parse the code in the JS temporary file, that is, parse the string obtained in the above steps, and obtain the corresponding abstract syntax tree corresponding to the code in the JS temporary file, that is, the second abstract syntax tree.
  • the abstract syntax tree (Abstract Syntax Tree, AST) is a tree representation of the abstract syntax structure of the source code, and each node on the tree is the structured abstract data of the corresponding node in the source code. Therefore, the second abstract syntax tree defines each part in the JS file in detail, that is, the second abstract syntax tree includes a description of all contents in the JS file.
  • S2023 Modify the second abstract syntax tree according to the second preset conversion rule to obtain a second target abstract syntax tree.
  • the second abstract syntax tree is modified by using the second preset conversion rule, and the modified second abstract syntax tree is determined as the second target abstract syntax tree to obtain the second target abstract syntax tree.
  • the specific content of the second preset conversion rule is the corresponding rule followed when modifying the code in the JS temporary file to the code required by the corresponding applet.
  • the content of the code in the JS file in the VUE component is reflected in the three attributes of data, created, and methods, so the second preset conversion rule can be represented by setting the corresponding attribute modification rules to modify the second abstract syntax tree .
  • the abstract syntax tree obtained by modifying the second abstract syntax tree according to the second preset conversion rule is the second target abstract syntax tree, and step S2024 can be executed to obtain the JS target file.
  • S2024 Generate a second object code according to the second object abstract syntax tree, and obtain a JS object file according to the second object code.
  • the content represented by the second target abstract syntax tree is determined as the second target code, that is, the second target code is generated according to the second target abstract syntax tree, and the file to which the second target code belongs is determined as the JS target file, that is, according to The second target code obtains the JS target file, thereby completing the conversion of the code in the JS file in the VUE component to the code in the JS target file in the applet component.
  • step 2023 possible implementations of step 2023 include:
  • the specific content of the second preset conversion rule is the corresponding rule followed when modifying the code in the JS temporary file to the code required by the corresponding applet, and the corresponding rule may specifically include an attribute modification rule.
  • the attribute modification rules include the following:
  • the definition of the data attribute in the VUE component is defined by the return data of the return (return) function, but since the object definition is directly used in the applet, for the data attribute, the attribute and value of the return function must first be obtained , and then directly use the attributes and values of the returned function to directly define the data attribute, that is, use the attributes and values of the returned function to replace the returned data of the returned function, modify the definition of the data attribute in the second abstract syntax tree, and the returned data of the returned function is then It is the definition of the data attribute in the corresponding second abstract syntax data in the VUE component before modification, for example, in the form of "key” and "value" as the definition of the data attribute in the applet component.
  • the attribute modification rules also include modifications to the props attribute definition, for example, modifying the props attribute definition in the second abstract syntax tree and the definition method of the corresponding default attribute value to the target attribute definition and the target definition method, wherein, the target attribute definition and the target The definition method meets the attribute definition requirements of the applet.
  • the definition of the props attribute in the VUE component is as follows:
  • ⁇ mode ⁇ type: Number, default: 0 ⁇
  • the property modification rule is to modify the above “props” to “properties”, “props” is the definition of the props attribute, “properties” is the definition of the target attribute, “default” represents the definition of the corresponding default attribute value defined by the props attribute, and the property modification rule It is to change "default” to "value”, and "value” indicates the target definition method, which meets the attribute definition requirements of the applet. Therefore, the definition of the props attribute in the above VUE component is modified through the attribute modification rules, that is, the definition of the props attribute in the second abstract syntax tree and the definition of the corresponding default attribute value are modified to obtain the property definition requirements of the applet.
  • Target property definitions and target definition are as follows:
  • ⁇ mode ⁇ type: Number, value: 0 ⁇
  • the property modification rule further includes: modifying the data reading mode of the second abstract syntax tree to a target reading mode, and the target reading mode satisfies the life cycle hook function of the applet. For example, reading data in the VUE component is directly using "this.key”, “key” represents the key value of the data, for example, "this.name” can directly get the value corresponding to the data "name” in the VUE component. However, reading data in the applet component adds a level, and the format is "this.data.key”, which is equivalent to using "this.data.name” in the VUE component to get the value referred to by "name”. When traversing the second abstract syntax tree, when encountering the "ThisExpression” expression, replace the corresponding "property".
  • the node to which the part involved in the attribute modification rule belongs in the second abstract syntax tree is the target node of the second abstract syntax tree.
  • the code in the JS temporary file is converted according to the second preset conversion rule to obtain the JS target file, and the code in the JS target file is used to represent the JS logic code in the applet component fragment.
  • the target node of the second abstract syntax tree is modified by traversing the second abstract syntax tree and according to the attribute modification rules included in the second preset conversion rules, so that the code in the modified JS target file conforms to the small
  • This not only improves the conversion efficiency of the code in the JS file in the VUE component to the code in the JS target file, but also makes the granularity of the modifiable content smaller, ensuring the correctness of the code in the obtained JS target file , and ensure the corresponding relationship between the code in the JS file and the code in the JS target file, that is, the code before and after modification, so as to facilitate subsequent code maintenance and error location.
  • FIG. 7 is a schematic flowchart of another method for generating a small program provided by the embodiment of the present application. As shown in Figure 7, the embodiment of this application includes:
  • S2031 Read the WXSS temporary file by using a preset asynchronous reading tool to obtain the code in the WXSS temporary file.
  • this step is to use the preset asynchronous reading tool to read the file content of the WXSS temporary file and read it into The process of converting the content of the file into the corresponding string.
  • the third abstract syntax tree includes a description of all content in the CSS file.
  • the abstract syntax tree (Abstract Syntax Tree, AST) is a tree representation of the abstract syntax structure of the source code, and each node on the tree is the structured abstract data of the corresponding node in the source code. Therefore, the third abstract syntax tree defines each part in the CSS file in detail, that is, the third abstract syntax tree includes a description of all contents in the CSS file.
  • S2033 Modify the third abstract syntax tree according to the third preset conversion rule to obtain a third target abstract syntax tree.
  • the third abstract syntax tree is modified by using the third preset conversion rule, and the modified third abstract syntax tree is determined as the third target abstract syntax tree to obtain the third target abstract syntax tree.
  • the specific content of the third preset conversion rule is the corresponding rule followed when modifying the code in the WXSS temporary file to the code required by the corresponding applet.
  • the abstract syntax tree obtained by modifying the third abstract syntax tree according to the third preset conversion rule is the third target abstract syntax tree, and step S2034 can be executed to obtain the WXSS target file.
  • S2034 Generate a third object code according to the third object abstract syntax tree, and obtain a WXSS object file according to the third object code.
  • the content represented by the third target abstract syntax tree is determined as the third target code, that is, the third target code is generated according to the third target abstract syntax tree, and the file to which the third target code belongs is determined as a WXSS target file, that is, according to The third target code obtains the WXSS target file, thereby completing the conversion of the code in the CSS file in the VUE component to the code in the WXSS target file in the applet component file.
  • step S2033 possible implementations of step S2033 include:
  • the specific content of the third preset conversion rule is the corresponding rule followed when modifying the code in the WXSS temporary file to the code required by the corresponding applet, and the corresponding rule may specifically include a selector modification rule.
  • selector modification rules include the following:
  • the unit of measurement declared by the target selector in the third abstract syntax tree is modified to the target unit of measurement, and the target unit of measurement satisfies the adaptive size unit of each applet.
  • the VUE component there is a rule statement.
  • the value corresponding to the CSS selector of type "ClassSelector” is "params-list-row”, and "block” corresponds to the value of the CSS selector.
  • the value is to declare the value of the bottom margin "padding-bottom" is 10, and the unit of measurement of this value is "px".
  • the applet uses "rpx" as the unit of measurement, that is, "rpx” is the target unit of measurement, which satisfies the adaptive size unit of the applet, so the third abstract syntax tree is traversed, and the target selector in the third abstract syntax tree such as The type is "Dimension” and the declared measurement unit “px” is all modified to the target measurement unit "rpx” according to 1:1.
  • the node in the third abstract syntax tree whose type is "Dimension” and whose declared measurement unit is "px" belongs to is the target node of the third abstract syntax tree.
  • selector modification rules also include logging limited selectors.
  • the selectors supported by them are limited. If you traverse the third abstract syntax tree and find that there are selectors that are not supported by applets, you need to use logs to record the selectors that these applets do not support. These applets do not support The supported selectors are limited selectors. In other words, the limited selectors can be any selectors not supported by the applet in the third abstract syntax tree.
  • the selectors currently supported by the applet include Class Selector, ID Selector, Type Selector, Pseudo-element Selector Element Selector).
  • the log record is to remind the developer that a style rule that is not currently supported is used in the applet, but it can be compiled normally, but there is no corresponding effect in the applet.
  • the code in the WXSS temporary file is converted according to the third preset conversion rule to obtain the WXSS target file, and the code in the WXSS target file is used to represent the WXSS component style in the applet component .
  • the target node of the third abstract syntax tree is modified by traversing the third abstract syntax tree and according to the selector modification rules included in the third preset transformation rules, so that the codes in the modified WXSS target file conform to Mini-program operation requirements, which not only improves the conversion efficiency of the code in the CSS file in the VUE component to the code in the WXSS target file, but also makes the granularity of the modifiable content smaller, ensuring the correctness of the code in the obtained WXSS target file , and ensure the corresponding relationship between the code in the CSS file and the code in the WXSS target file, that is, the code before and after modification, which is convenient for subsequent code maintenance and error location.
  • FIG. 8 is a schematic structural diagram of an apparatus for generating a small program provided by an embodiment of the present application.
  • the applet generation device 300 provided in the embodiment of the present application includes:
  • the obtaining module 301 is used to read the VUE component by using a preset asynchronous reading tool to obtain each component file in the VUE component, and each component file includes a page file, a JS file and a cascading style sheet CSS file.
  • the storage module 302 is used to store the codes in each component file correspondingly to each temporary file, and each temporary file includes a WeChat markup language WXML temporary file, a JS temporary file and a WeChat Cascading Style Sheet WXSS temporary file.
  • the processing module 303 is configured to convert the code in each temporary file according to a preset conversion strategy to obtain corresponding applet component files, so as to generate applets according to each applet component file.
  • the preset conversion strategy includes traversing each node of each abstract syntax tree to modify the target node of each abstract syntax tree, and each abstract syntax tree is correspondingly formed for the code in each temporary file.
  • FIG. 9 is a schematic structural diagram of a processing module provided in an embodiment of the present application.
  • the processing module 303 in the applet generating device 300 provided by the embodiment of the present application includes:
  • the first processing sub-module 3031 is configured to convert the code in the WXML temporary file according to the first preset conversion rule to generate a WXML target file;
  • the second processing sub-module 3032 is used to convert the code in the JS temporary file according to the second preset conversion rule to generate the JS target file;
  • the third processing sub-module 3033 is configured to convert the code in the WXSS temporary file according to the third preset conversion rule to generate a WXSS target file.
  • the preset conversion strategy includes a first preset conversion rule, a second preset conversion rule, and a third preset conversion rule
  • each applet component file includes a WXML object file, a JS object file, and a WXSS object file.
  • the first processing submodule 3031 is specifically used for:
  • the page parser Utilize the page parser to parse the code in the WXML temporary file to obtain a first abstract syntax tree, and the first abstract syntax tree includes a description of all contents in the page file;
  • the first object code is generated according to the first object abstract syntax tree, and the WXML object file is obtained according to the first object code.
  • the first processing submodule 3031 is also specifically used for:
  • the first preset conversion rule includes a preset tag mapping table and a format modification rule.
  • format modification rules include:
  • the second processing submodule 3032 is specifically used for:
  • a second object code is generated according to the second object abstract syntax tree, and a JS object file is obtained according to the second object code.
  • the second processing submodule 3032 is also specifically used for:
  • the second abstract syntax tree is traversed, and the target node of the second abstract syntax tree is modified according to the attribute modification rules to obtain the second target abstract syntax tree.
  • the second preset conversion rules include attribute modification rules.
  • attribute modification rules include:
  • the returned data of the returned function is the data in the second abstract syntax tree before modification property definition
  • the assignment expression in the second abstract syntax tree is modified to the way of executing the function of the applet.
  • the third processing submodule 3033 is specifically used for:
  • a third object code is generated according to the third object abstract syntax tree, and a WXSS object file is obtained according to the third object code.
  • the third processing submodule 3033 is also specifically used for:
  • the third abstract syntax tree is traversed, and the third abstract syntax tree is modified according to the selector modification rule to obtain a third target abstract syntax tree.
  • the third preset conversion rule includes the selector modification rule.
  • selectors modify rules, including:
  • a log record limited selector is used, and the limited selector is any selector not supported by the applet in the third abstract syntax tree.
  • the applet generating apparatus 300 further includes: a fourth processing submodule.
  • the fourth processing submodule is used for:
  • the information file is generated according to the code in the JS target file, and the information file is used to record the position information of the code of each applet component file in the code of the VUE component.
  • the applet generating apparatus 300 further includes: a fifth processing submodule.
  • the fifth processing submodule is used for:
  • a work order is generated based on the component generation requirements, a command line tool is run in response to the work order, the command line tool is used to enable the applet generation method.
  • modules division therein is only a logical function division, and there may be other division methods in actual implementation.
  • several modules may be combined or may be integrated into another system.
  • the mutual coupling of various modules can be realized through some interfaces, and these interfaces are usually electrical communication interfaces, but it is not excluded that they may be mechanical interfaces or other forms of interfaces.
  • modules described as separate components may or may not be physically separate, and may be located at one location or distributed to different locations on the same or different devices.
  • FIG. 10 is a schematic structural diagram of an electronic device provided by the present application.
  • the electronic device 400 may include: at least one processor 401 and a memory 402 .
  • FIG. 10 shows an electronic device using a processor as an example.
  • the memory 402 is used for storing computer programs of the processor 401 .
  • the program may include program code, and the program code includes computer operation instructions.
  • the memory 402 may include a high-speed RAM memory, and may also include a non-volatile memory (non-volatile memory), such as at least one disk storage.
  • the processor 401 is configured to execute the computer program stored in the memory 402, so as to realize each step of the applet generating method in each method embodiment above.
  • processor 401 may be a central processing unit (central processing unit, referred to as CPU), or a specific integrated circuit (application specific integrated circuit, referred to as ASIC), or one or more integrated circuits configured to implement the embodiments of the present application.
  • CPU central processing unit
  • ASIC application specific integrated circuit
  • the memory 402 can be independent or integrated with the processor 401 .
  • the electronic device 400 may further include:
  • the bus 403 is used to connect the processor 401 and the memory 402 .
  • the bus can be an industry standard architecture (industry standard architecture (ISA) bus, peripheral component interconnect (PCI) bus or extended industry standard architecture (EISA) bus, etc.
  • ISA industry standard architecture
  • PCI peripheral component interconnect
  • EISA extended industry standard architecture
  • the bus can be divided into address bus, data bus, control bus, etc., but it does not mean that there is only one bus or one type of bus.
  • the memory 402 and the processor 401 may communicate through an internal interface.
  • the present application also provides a computer-readable storage medium, which may include: U disk, mobile hard disk, read-only memory (read-only memory, ROM), random access memory (random access memory, RAM) ), a magnetic disk or an optical disk, and other media that can store program codes.
  • the computer-readable storage medium stores a computer program.
  • the electronic device executes the above-mentioned Each step of the applet generating method provided in the above implementation manner.
  • An embodiment of the present application further provides a computer program product, where the computer program product includes a computer program, and the computer program is stored in a readable storage medium.
  • At least one processor of the electronic device can read the computer program from the readable storage medium, and the at least one processor executes the computer program so that the electronic device implements each step of the applet generating method provided in the above-mentioned various embodiments.

Abstract

The present application provides an applet generation method and apparatus, a device and a storage medium. The method comprises: reading a VUE component by using a preset asynchronous reading tool to obtain component files in the VUE component, the component files each comprising a page file, a JS file and a CSS file; correspondingly storing codes in the component files in temporary files, the temporary files each comprising a WXML temporary file, a JS temporary file and a WXSS temporary file; converting codes in each temporary file according to a preset conversion policy to obtain applet component files, completing the conversion from the VUE component to an applet component, and generating an applet according to the applet component files. The applet component is obtained by performing conversion on the basis of the preset conversion policy, thus effectively improving the efficiency of obtaining applet components and generating an applet, enabling the granularity of modifiable content to be smaller, thus ensuring the correctness of the applet components, and the correspondence between codes before and after modification may be known, which facilitates subsequent maintenance.

Description

小程序生成方法、装置、设备及存储介质Small program generation method, device, equipment and storage medium
本申请要求于2021年11月16日提交中国专利局、申请号为202111358314.5、申请名称为“小程序生成方法、装置、设备及存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims the priority of a Chinese patent application with application number 202111358314.5 and application title "Machine Program Generation Method, Apparatus, Equipment, and Storage Medium" filed with the China Patent Office on November 16, 2021, the entire contents of which are incorporated by reference in this application.
技术领域technical field
本申请涉及计算机技术领域,尤其涉及一种小程序生成方法、装置、设备及存储介质。The present application relates to the field of computer technology, and in particular to a small program generation method, device, equipment and storage medium.
背景技术Background technique
微信小程序,简称小程序,是一种不需要下载安装即可使用的应用,用户可以通过扫一扫或者搜索的方式即可打开应用,体现了一种即时的使用理念而被广泛使用。目前,小程序无法加载例如HTML(超级文本标记语言,Hyper Text Markup Language)页面等内容,而在小程序的使用过程中又需要能够打开这些HTML页面,因而则需要根据已有的HTML页面所使用的组件生成小程序组件。WeChat applets, or applets for short, are applications that can be used without downloading and installing. Users can open the application by scanning or searching, which embodies an instant usage concept and is widely used. Currently, applets cannot load content such as HTML (Hyper Text Markup Language) pages, and these HTML pages need to be able to be opened during the use of the applet, so it needs to be used according to the existing HTML pages. The component generates applet components.
HTML页面可以使用VUE组件形成,VUE组件的文件内容包括HTML模板文件、JavaScript(JS)文件以及层叠样式表(Cascading Style Sheets,CSS)文件。当前根据VUE组件得到小程序组件的方式有两种。一种是采用手动替换的方式将VUE组件中的每个单文件组件替换为小程序所需的对应组件,并新建小程序JSON(JavaScript Object Notation)配置文件。另一种是通过正则表达式将VUE组件替换为小程序组件。HTML pages can be formed using VUE components, and the file content of VUE components includes HTML template files, JavaScript (JS) files, and Cascading Style Sheets (Cascading Style Sheets, CSS) files. Currently, there are two ways to obtain applet components based on VUE components. One is to manually replace each single-file component in the VUE component with the corresponding component required by the applet, and create a new applet JSON (JavaScript Object Notation) configuration file. The other is to replace VUE components with applet components through regular expressions.
然而现有的上述两种方式均存在缺陷,例如,手动替换方式效率低下,无法保证替换结果的正确性,并需要人工检测,替换后的代码位置较难记录导致替换前后的代码缺乏对应关系,从而在后续的修改维护阶段需要依赖人工定位出现错误的位置,当语法层面出现错误时则缺乏工具辅助,导致同一功能的重复开发。通过正则表达式替换的方式对于代码处理较为粗暴笼统,问题定位耗时较长,并当遇到长字符串时,正则表达式的效率比较低。可见,亟需一种小程序生成方法,以克服现有技术根据VUE组件生成小程序组件所存在的上述技术缺陷。However, the above two existing methods have defects. For example, the manual replacement method is inefficient, cannot guarantee the correctness of the replacement result, and requires manual inspection. The position of the replaced code is difficult to record, resulting in a lack of correspondence between the codes before and after the replacement. Therefore, in the subsequent modification and maintenance stage, it is necessary to rely on manual positioning of the location of the error. When an error occurs at the grammatical level, there is a lack of tool assistance, resulting in repeated development of the same function. The way of replacing by regular expressions is rough and general for code processing, and it takes a long time to locate the problem, and when encountering long strings, the efficiency of regular expressions is relatively low. It can be seen that there is an urgent need for a method for generating applets to overcome the above-mentioned technical defects in the existing technology of generating applet components based on VUE components.
技术解决方案technical solution
本申请提供一种小程序生成方法、装置、设备及存储介质,用于提供一种小程序生成方法以克服现有采用手动替换或者正则表达式替换对VUE组件进行替换所存在的技术缺陷。The present application provides a small program generation method, device, device and storage medium, which are used to provide a small program generation method to overcome the existing technical defects of replacing VUE components by manual replacement or regular expression replacement.
第一方面,本申请提供一种小程序生成方法,包括:In the first aspect, the present application provides a method for generating a small program, including:
利用预设异步读取工具读取VUE组件,得到所述VUE组件中的各组件文件,所述各组件文件包括页面文件、JS文件以及层叠样式表CSS文件;Utilize preset asynchronous reading tool to read VUE component, obtain each component file in described VUE component, described each component file comprises page file, JS file and cascading style sheet CSS file;
将所述各组件文件内的代码分别对应存储至各临时文件,所述各临时文件包括微信标记语言WXML临时文件、JS临时文件以及微信层叠样式表WXSS临时文件;The codes in each of the component files are correspondingly stored in each temporary file respectively, and each of the temporary files includes a Wechat markup language WXML temporary file, a JS temporary file and a Wechat Cascading Style Sheet WXSS temporary file;
根据预设转换策略对每个临时文件内的代码进行转换,对应得到各小程序组件文件,以根据所述各小程序组件文件生成小程序,所述预设转换策略包括遍历每个抽象语法树的每个节点以修改所述每个抽象语法树的目标节点,所述每个抽象语法树为所述每个临时文件内的代码对应形成。Convert the code in each temporary file according to a preset conversion strategy to obtain corresponding applet component files to generate applets according to the applet component files. The preset conversion strategy includes traversing each abstract syntax tree Each node of each node is modified to modify the target node of each abstract syntax tree, and each abstract syntax tree is correspondingly formed for the code in each temporary file.
在一种可能的设计中,所述根据预设转换策略对每个临时文件内的代码进行转换,对应得到各小程序组件文件,包括:In a possible design, the codes in each temporary file are converted according to the preset conversion strategy to obtain corresponding applet component files, including:
按照第一预设转换规则对所述WXML临时文件内的代码进行转换,生成WXML目标文件;converting the code in the WXML temporary file according to a first preset conversion rule to generate a WXML target file;
按照第二预设转换规则对所述JS临时文件内的代码进行转换,生成JS目标文件;converting the code in the JS temporary file according to the second preset conversion rule to generate the JS target file;
按照第三预设转换规则对所述WXSS临时文件内的代码进行转换,生成WXSS目标文件;converting the code in the WXSS temporary file according to a third preset conversion rule to generate a WXSS target file;
其中,所述预设转换策略包括所述第一预设转换规则、所述第二预设转换规则以及所述第三预设转换规则,所述各小程序组件文件包括所述WXML目标文件、所述JS目标文件以及所述WXSS目标文件。Wherein, the preset conversion policy includes the first preset conversion rule, the second preset conversion rule, and the third preset conversion rule, and the applet component files include the WXML target file, The JS target file and the WXSS target file.
在一种可能的设计中,所述按照第一预设转换规则对所述WXML临时文件内的代码进行转换,生成WXML目标文件,包括:In a possible design, the code in the WXML temporary file is converted according to a first preset conversion rule to generate a WXML target file, including:
利用所述预设异步读取工具读取所述WXML临时文件,以获得所述WXSS临时文件内的代码;Using the preset asynchronous reading tool to read the WXML temporary file to obtain the code in the WXSS temporary file;
利用页面解析器解析所述WXML临时文件内的代码,得到第一抽象语法树,所述第一抽象语法树包括对所述页面文件中所有内容的描述;Using a page parser to parse the code in the WXML temporary file to obtain a first abstract syntax tree, the first abstract syntax tree including a description of all content in the page file;
根据所述第一预设转换规则修改所述第一抽象语法树,得到第一目标抽象语法树;Modifying the first abstract syntax tree according to the first preset conversion rule to obtain a first target abstract syntax tree;
根据所述第一目标抽象语法树生成第一目标代码,并根据所述第一目标代码得到所述WXML目标文件。Generate a first object code according to the first object abstract syntax tree, and obtain the WXML object file according to the first object code.
在一种可能的设计中,所述根据所述第一预设转换规则修改所述第一抽象语法树,得到第一目标抽象语法树,包括:In a possible design, the modifying the first abstract syntax tree according to the first preset conversion rule to obtain the first target abstract syntax tree includes:
遍历所述第一抽象语法树,获得表单标签,并根据预设标签映射表替换所述表单标签中的标签内容;Traversing the first abstract syntax tree to obtain a form tag, and replacing the tag content in the form tag according to a preset tag mapping table;
根据格式修改规则修改所述第一抽象语法树的目标节点;modifying the target node of the first abstract syntax tree according to a format modification rule;
将经过所述预设标签映射表替换以及所述格式修改规则修改的第一抽象语法树确定为所述第一目标抽象语法树;determining the first abstract syntax tree that has been replaced by the preset label mapping table and modified by the format modification rule as the first target abstract syntax tree;
其中,所述第一预设转换规则包括所述预设标签映射表和所述格式修改规则。Wherein, the first preset conversion rule includes the preset tag mapping table and the format modification rule.
在一种可能的设计中,所述格式修改规则包括:In a possible design, the format modification rules include:
将所述第一抽象语法树中的列渲染格式修改为小程序列表渲染格式;modifying the column rendering format in the first abstract syntax tree to the applet list rendering format;
将所述第一抽象语法树中的条件渲染格式修改为小程序条件渲染格式;modifying the conditional rendering format in the first abstract syntax tree to the applet conditional rendering format;
将所述第一抽象语法树中的事件绑定格式修改为小程序事件绑定格式。The event binding format in the first abstract syntax tree is modified to the applet event binding format.
在一种可能的设计中,所述按照第二预设转换规则对所述JS临时文件内的代码进行转换,生成JS目标文件,包括:In a possible design, the code in the JS temporary file is converted according to the second preset conversion rule to generate a JS target file, including:
利用所述预设异步读取工具读取所述JS临时文件,以获得所述JS临时文件内的代码;Using the preset asynchronous reading tool to read the JS temporary file to obtain the code in the JS temporary file;
利用解析插件解析所述JS临时文件内的代码,得到第二抽象语法树,所述第二抽象语法树包括对所述JS文件中所有内容的描述;Parsing the code in the JS temporary file by using the parsing plug-in to obtain a second abstract syntax tree, the second abstract syntax tree including a description of all content in the JS file;
根据所述第二预设转换规则修改所述第二抽象语法树,得到第二目标抽象语法树;Modifying the second abstract syntax tree according to the second preset conversion rule to obtain a second target abstract syntax tree;
根据所述第二目标抽象语法树生成第二目标代码,并根据所述第二目标代码得到所述JS目标文件。Generate a second object code according to the second object abstract syntax tree, and obtain the JS object file according to the second object code.
在一种可能的设计中,所述根据所述第二预设转换规则修改所述第二抽象语法树,得到第二目标抽象语法树,包括:In a possible design, modifying the second abstract syntax tree according to the second preset conversion rule to obtain a second target abstract syntax tree includes:
遍历所述第二抽象语法树,根据属性修改规则修改所述第二抽象语法树的目标节点,得到所述第二目标抽象语法树,所述第二预设转换规则包括所述属性修改规则。Traversing the second abstract syntax tree, modifying target nodes of the second abstract syntax tree according to attribute modification rules to obtain the second target abstract syntax tree, wherein the second preset conversion rules include the attribute modification rules.
在一种可能的设计中,所述属性修改规则包括:In a possible design, the attribute modification rules include:
获取返回函数的属性和值,利用所述返回函数的属性和值替换所述返回函数的返回数据,以修改所述第二抽象语法树中data属性的定义,所述返回函数的返回数据为修改前所述第二抽象语法树中data属性的定义;Obtain the attributes and values of the return function, and use the attributes and values of the return function to replace the return data of the return function to modify the definition of the data attribute in the second abstract syntax tree, and the return data of the return function is modified The definition of the data attribute in the aforementioned second abstract syntax tree;
将所述第二抽象语法树中的props属性定义以及对应默认属性值的定义方式分别修改为目标属性定义和目标定义方式,所述目标属性定义和所述目标定义方式满足所述小程序的属性定义要求;modifying the definition of the props attribute in the second abstract syntax tree and the definition of the corresponding default attribute value to the definition of the target attribute and the definition of the target, the definition of the target attribute and the definition of the target meet the attributes of the applet define requirements;
将所述第二抽象语法树的数据读取方式修改为目标读取方式,所述目标读取方式满足所述小程序的生命周期钩子函数;modifying the data reading mode of the second abstract syntax tree to a target reading mode, and the target reading mode satisfies the life cycle hook function of the applet;
将所述第二抽象语法树中的赋值表达式修改为小程序执行函数方式。Modifying the assignment expression in the second abstract syntax tree to the mode of executing the function of the applet.
在一种可能的设计中,所述按照第三预设转换规则对所述WXSS临时文件内的代码进行转换,生成WXSS目标文件,包括:In a possible design, the code in the WXSS temporary file is converted according to a third preset conversion rule to generate a WXSS target file, including:
利用所述预设异步读取工具读取所述WXSS临时文件,以获得所述WXSS临时文件内的代码;Using the preset asynchronous reading tool to read the WXSS temporary file to obtain the code in the WXSS temporary file;
利用语法分析器解析所述WXSS临时文件内的代码,得到第三抽象语法树,所述第三抽象语法树包括对所述CSS标签中所有内容的描述;Using a syntax analyzer to parse the code in the WXSS temporary file to obtain a third abstract syntax tree, the third abstract syntax tree includes a description of all content in the CSS tag;
根据所述第三预设转换规则遍历并修改所述第三抽象语法树,得到第三目标抽象语法树;Traversing and modifying the third abstract syntax tree according to the third preset conversion rule to obtain a third target abstract syntax tree;
根据所述第三目标抽象语法树生成第三目标代码,并根据所述第三目标代码得到所述WXSS目标文件。Generate a third object code according to the third object abstract syntax tree, and obtain the WXSS object file according to the third object code.
在一种可能的设计中,所述根据所述第三预设转换规则遍历并修改所述第三抽象语法树,得到第三目标抽象语法树,包括:In a possible design, the traversing and modifying the third abstract syntax tree according to the third preset conversion rule to obtain a third target abstract syntax tree includes:
遍历所述第三抽象语法树,根据选择器修改规则修改所述第三抽象语法树,得到所述第三目标抽象语法树,所述第三预设转换规则包括所述选择器修改规则。The third abstract syntax tree is traversed, and the third abstract syntax tree is modified according to the selector modification rule to obtain the third target abstract syntax tree, and the third preset conversion rule includes the selector modification rule.
在一种可能的设计中,所述选择器修改规则,包括:In a possible design, the selector modification rule includes:
将所述第三抽象语法树中目标选择器所声明的计量单位修改为目标计量单位,所述目标计量单位满足所述小程序的自适应尺寸单位;modifying the unit of measure declared by the target selector in the third abstract syntax tree to a target unit of measure, the target unit of measure meeting the self-adaptive size unit of the applet;
利用日志记录有限选择器,所述有限选择器为所述第三抽象语法树中所述小程序不支持的任意选择器。Logging is used to record limited selectors, the limited selectors being any selectors not supported by the applet in the third abstract syntax tree.
在一种可能的设计中,在所述得到各小程序组件文件之后,还包括:In a possible design, after obtaining the applet component files, it further includes:
根据JS目标文件内的代码生成信息文件,所述信息文件用于记录所述各小程序组件文件的代码在所述VUE组件的代码中的位置信息。The information file is generated according to the code in the JS target file, and the information file is used to record the position information of the code of each applet component file in the code of the VUE component.
在一种可能的设计中,在所述利用预设异步读取工具读取VUE组件之前,还包括:In a possible design, before using the preset asynchronous reading tool to read the VUE component, it also includes:
根据组件生成需求生成工作指令,响应于所述工作指令运行命令行工具,所述命令行工具用于启用所述小程序生成方法。A work order is generated according to the component generation requirement, and a command line tool is executed in response to the work order, and the command line tool is used to enable the applet generation method.
第二方面,本申请提供一种小程序生成装置,包括:In a second aspect, the present application provides a small program generation device, including:
获取模块,用于利用预设异步读取工具读取VUE组件,得到所述VUE组件中的各组件文件,所述各组件文件包括页面文件、JS文件以及层叠样式表CSS文件;The acquisition module is used to read the VUE component using a preset asynchronous reading tool to obtain each component file in the VUE component, and each component file includes a page file, a JS file and a cascading style sheet CSS file;
存储模块,用于将所述各组件文件内的代码分别对应存储至各临时文件,所述各临时文件包括微信标记语言WXML临时文件、JS临时文件以及微信层叠样式表WXSS临时文件;The storage module is used to store the codes in each of the component files correspondingly to each temporary file respectively, and each of the temporary files includes a Wechat markup language WXML temporary file, a JS temporary file and a Wechat Cascading Style Sheet WXSS temporary file;
处理模块,用于根据预设转换策略对每个临时文件内的代码进行转换,对应得到各小程序组件文件,以根据所述各小程序组件文件生成小程序,所述预设转换策略包括遍历每个抽象语法树的每个节点以修改所述每个抽象语法树的目标节点,所述每个抽象语法树为所述每个临时文件内的代码对应形成。A processing module, configured to convert the code in each temporary file according to a preset conversion strategy to obtain corresponding applet component files, so as to generate applets according to the applet component files, and the preset conversion strategy includes traversing Each node of each abstract syntax tree is used to modify the target node of each abstract syntax tree, and each abstract syntax tree is correspondingly formed for the code in each temporary file.
第三方面,本申请提供一种电子设备,包括:In a third aspect, the present application provides an electronic device, including:
处理器;以及,Processor; and,
存储器,用于存储所述处理器的计算机程序;a memory for storing the computer program of the processor;
其中,所述处理器配置为经由执行所述计算机程序来实现第一方面所提供的任意一种可能的小程序生成方法。Wherein, the processor is configured to implement any possible applet generating method provided in the first aspect by executing the computer program.
第四方面,本申请提供一种计算机可读存储介质,其上存储有计算机程序,所述计算机程序被处理器执行时实现第一方面所提供的任意一种可能的小程序生成方法。In a fourth aspect, the present application provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, any possible applet generation method provided in the first aspect is implemented.
第五方面,本申请还提供一种计算机程序产品,包括计算机程序,该计算机程序被处理器执行时实现第一方面所提供的任意一种可能的小程序生成方法。In a fifth aspect, the present application further provides a computer program product, including a computer program, and when the computer program is executed by a processor, any possible applet generation method provided in the first aspect is implemented.
本申请提供一种小程序生成方法、装置、设备及存储介质,首先利用预设异步读取工具读取VUE组件,得到VUE组件中的各组件文件,各组件文件包括页面文件、JS文件以及层叠样式表CSS文件。然后将各组件文件内的代码分别对应存储至各临时文件,所述各临时文件包括微信标记语言WXML临时文件、JS临时文件以及微信层叠样式表WXSS临时文件。最后根据预设转换策略对每个临时文件内的代码进行转换,得到各小程序组件文件,完成VUE组件至小程序组件的转换,进而根据各小程序组件文件生成小程序。其中,预设转换策略包括遍历每个抽象语法树的每个节点以修改每个抽象语法树的目标节点,而每个抽象语法树由每个临时文件内的代码对应形成。基于预设转换策略进行转换得到小程序组件,有效提高了得到各小程序组件以及生成小程序的效率,使得可修改的内容颗粒度更小,保障了所得到的小程序组件的正确性,并可以获知修改前后代码之间的对应关系,便于后续维护。This application provides a small program generation method, device, equipment and storage medium. First, use the preset asynchronous reading tool to read the VUE component to obtain each component file in the VUE component. Each component file includes a page file, a JS file, and a cascaded Style sheet CSS file. Then the codes in each component file are correspondingly stored in each temporary file, and each temporary file includes a WeChat markup language WXML temporary file, a JS temporary file and a WeChat Cascading Style Sheet WXSS temporary file. Finally, the code in each temporary file is converted according to the preset conversion strategy to obtain the component files of each applet, and the conversion from the VUE component to the applet component is completed, and then the applet is generated according to the component files of each applet. Wherein, the preset conversion strategy includes traversing each node of each abstract syntax tree to modify the target node of each abstract syntax tree, and each abstract syntax tree is correspondingly formed by codes in each temporary file. The applet components are converted based on the preset conversion strategy, which effectively improves the efficiency of obtaining applet components and generating applets, making the granularity of modifiable content smaller, ensuring the correctness of the obtained applet components, and You can know the correspondence between codes before and after modification, which is convenient for subsequent maintenance.
附图说明Description of drawings
图1为本申请实施例提供的一种应用场景示意图;FIG. 1 is a schematic diagram of an application scenario provided by an embodiment of the present application;
图2为本申请实施例提供的一种小程序生成方法的流程示意图;FIG. 2 is a schematic flowchart of a method for generating a small program provided by an embodiment of the present application;
图3为本申请实施例提供的一种文件存储示意图;FIG. 3 is a schematic diagram of file storage provided by an embodiment of the present application;
图4为本申请实施例提供的另一种小程序生成方法的流程示意图;FIG. 4 is a schematic flowchart of another applet generation method provided by the embodiment of the present application;
图5为本申请实施例提供的再一种小程序生成方法的流程示意图;FIG. 5 is a schematic flowchart of another method for generating a small program provided by the embodiment of the present application;
图6为本申请实施例提供的又一种小程序生成方法的流程示意图;FIG. 6 is a schematic flowchart of another applet generation method provided by the embodiment of the present application;
图7为本申请实施例提供的又一种小程序生成方法的流程示意图;FIG. 7 is a schematic flowchart of another method for generating a small program provided by the embodiment of the present application;
图8为本申请实施例提供的一种小程序生成装置的结构示意图;FIG. 8 is a schematic structural diagram of a small program generation device provided by an embodiment of the present application;
图9为本申请实施例提供的一种处理模块的结构示意图;FIG. 9 is a schematic structural diagram of a processing module provided in an embodiment of the present application;
图10为本申请提供的一种电子设备的结构示意图。FIG. 10 is a schematic structural diagram of an electronic device provided by the present application.
本发明的实施方式Embodiments of the present invention
这里将详细地对示例性实施例进行说明,其示例表示在附图中。下面的描述涉及附图时,除非另有表示,不同附图中的相同数字表示相同或相似的要素。以下示例性实施例中所描述的实施方式并不代表与本申请相一致的所有实施方式。相反,它们仅是与如所附权利要求书中所详述的、本申请的一些方面相一致的方法和装置的例子。Reference will now be made in detail to the exemplary embodiments, examples of which are illustrated in the accompanying drawings. When the following description refers to the accompanying drawings, the same numerals in different drawings refer to the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with this application. Rather, they are merely examples of methods and apparatus consistent with aspects of the present application as recited in the appended claims.
本申请的说明书和权利要求书及上述附图中的术语“第一”、“第二”、“第三”“第四”等(如果存在)是用于区别类似的对象,而不必用于描述特定的顺序或先后次序。应该理解这样使用的数据在适当情况下可以互换,以便这里描述的本申请的实施例例如能够以除了在这里图示或描述的那些以外的顺序实施。此外,术语“包括”和“具有”以及他们的任何变形,意图在于覆盖不排他的包含,例如,包含了一系列步骤或单元的过程、方法、系统、产品或设备不必限于清楚地列出的那些步骤或单元,而是可包括没有清楚地列出的或对于这些过程、方法、产品或设备固有的其它步骤或单元。The terms "first", "second", "third", "fourth", etc. (if any) in the description and claims of this application and the above drawings are used to distinguish similar objects and not necessarily Describe a specific order or sequence. It is to be understood that the data so used are interchangeable under appropriate circumstances such that the embodiments of the application described herein, for example, can be practiced in sequences other than those illustrated or described herein. Furthermore, the terms "comprising" and "having", as well as any variations thereof, are intended to cover a non-exclusive inclusion, for example, a process, method, system, product or device comprising a sequence of steps or elements is not necessarily limited to the expressly listed instead, may include other steps or elements not explicitly listed or inherent to the process, method, product or apparatus.
由于小程序无法加载例如HTML(超级文本标记语言,Hyper Text Markup Language)页面等内容,而在小程序的使用过程中又需要能够打开这些HTML页面,因而需要根据已有的HTML页面所使用的组件生成小程序组件。HTML页面可以使用VUE组件形成,VUE组件包括HTML模板、JavaScript(JS)组件以及层叠样式表(Cascading Style Sheets,CSS)组件。当前根据VUE组件得到小程序组件的方式有两种。一种是采用手动替换的方式将VUE组件中的每个单文件组件替换为小程序所需的对应组件,并需新建小程序JSON(JavaScript Object Notation)配置文件。另一种是通过正则表达式将VUE组件替换为小程序组件。但这两种方式存在例如转换效率低下、正确性无法保障以及替换前后代码缺乏对应关系导致维护阶段难以定位等问题。Since the applet cannot load e.g. HTML (Hyper Text Markup Language, Hyper Text Markup Language) pages and other content, and these HTML pages need to be able to be opened during the use of the applet, so it is necessary to generate applet components based on the components used by the existing HTML pages. HTML pages can be formed using VUE components, which include HTML templates, JavaScript (JS) components, and Cascading Style Sheets (Cascading Style Sheets, CSS) components. Currently, there are two ways to obtain applet components based on VUE components. One is to manually replace each single-file component in the VUE component with the corresponding component required by the applet, and create a new applet JSON (JavaScript Object Notation) configuration file. The other is to replace VUE components with applet components through regular expressions. However, these two methods have problems such as low conversion efficiency, inability to guarantee correctness, and lack of correspondence between codes before and after replacement, which makes it difficult to locate in the maintenance phase.
针对现有技术存在的上述问题,本申请提供一种小程序生成方法的发明构思在于:将VUE组件所包括的各组件文件内的代码分别对应存储至各临时文件,然后利用预设转换策略对每个临时文件内的代码进行转换,对应得到各小程序组件文件,完成VUE组件至小程序组件的转换,进而根据各小程序组件文件生成小程序。其中,由于预设转换策略包括遍历每个抽象语法树的每个节点以修改每个抽象语法树的目标节点,而每个抽象语法树由每个临时文件内的代码对应形成,因而本申请中基于预设转换策略对VUE组件进行转换得到小程序组件的实现过程使得可修改的内容颗粒度更小,保障了所得到的各小程序组件的正确性,有效提高了得到各小程序组件以及生成小程序的效率,并且还可以或者修改前后代码之间的对应关系,便于后续代码维护。In view of the above-mentioned problems existing in the prior art, this application provides a method for generating a small program. The inventive idea is to: store the codes in each component file included in the VUE component in each temporary file, and then use the preset conversion strategy to The code in each temporary file is converted to obtain corresponding applet component files, complete the conversion from VUE components to applet components, and then generate applets based on each applet component file. Wherein, since the preset conversion strategy includes traversing each node of each abstract syntax tree to modify the target node of each abstract syntax tree, and each abstract syntax tree is formed correspondingly by the codes in each temporary file, thus in this application The implementation process of converting VUE components based on the preset conversion strategy to obtain applet components makes the granularity of the modifiable content smaller, ensures the correctness of the obtained applet components, and effectively improves the process of obtaining each applet component and generating The efficiency of the applet, and the corresponding relationship between the before and after code can also be modified to facilitate subsequent code maintenance.
以下,对本申请实施例的示例性应用场景进行介绍。Hereinafter, exemplary application scenarios of the embodiments of the present application are introduced.
图1为本申请实施例提供的一种应用场景示意图。如图1所示,网络用于为服务器11和终端设备12之间提供通信链路的介质。网络可以包括各种连接类型,例如有线、无线通信链路或者光纤电缆等等。服务器11和终端设备12之间可以通过网络进行交互,以接收或发送消息。其中,服务器11可以配置为执行本申请实施例提供的小程序生成方法的相应电子设备中,而终端设备12可以运行所生成的小程序。通过服务器11执行本申请实施例提供的小程序生成方法以将VUE组件转换为各小程序组件,进而生成小程序,使得VUE组件所形成的例如HTML页面可以在终端设备12运行的小程序得以加载。FIG. 1 is a schematic diagram of an application scenario provided by an embodiment of the present application. As shown in FIG. 1 , the network is used as a medium for providing a communication link between the server 11 and the terminal device 12 . A network may include various connection types such as wires, wireless communication links, or fiber optic cables, among others. The server 11 and the terminal device 12 can interact through the network to receive or send messages. Wherein, the server 11 can be configured as a corresponding electronic device that executes the applet generation method provided by the embodiment of the present application, and the terminal device 12 can run the generated applet. The applet generation method provided by the embodiment of the application is executed by the server 11 to convert the VUE components into various applet components, and then generate applets, so that the applets formed by the VUE components, such as HTML pages, can be loaded on the terminal device 12 .
本申请实施例对于上述描述中的服务器11和终端设备12的类型不作限定,例如服务器11也可以是服务器集群,终端设备12可以是智能手机、智能眼镜、智能手环、智能手表、平板电脑等等,图1中的终端设备12以智能手机为例示出。The embodiment of the present application does not limit the types of the server 11 and terminal device 12 in the above description. For example, the server 11 can also be a server cluster, and the terminal device 12 can be a smart phone, smart glasses, smart bracelet, smart watch, tablet computer, etc. etc., the terminal device 12 in FIG. 1 is illustrated by taking a smart phone as an example.
需要说明的是,上述应用场景仅仅是示意性的,本申请实施例提供的小程序生成方法、装置、设备及存储介质包括但不仅限于上述应用场景。It should be noted that the above application scenarios are only illustrative, and the applet generation method, device, device, and storage medium provided in the embodiments of the present application include but are not limited to the above application scenarios.
下面以具体地实施例对本申请的技术方案以及本申请的技术方案如何解决上述技术问题进行详细说明。下面这几个具体的实施例可以相互结合,对于相同或相似的概念或过程可能在某些实施例中不再赘述。下面将结合附图,对本申请的实施例进行描述。The technical solution of the present application and how the technical solution of the present application solves the above technical problems will be described in detail below with specific embodiments. The following specific embodiments may be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. Embodiments of the present application will be described below in conjunction with the accompanying drawings.
图2为本申请实施例提供的一种小程序生成方法的流程示意图。如图2所示,本申请实施例提供的小程序生成方法,包括:FIG. 2 is a schematic flowchart of a method for generating a small program provided by an embodiment of the present application. As shown in Figure 2, the applet generation method provided by the embodiment of the present application includes:
S101:利用预设异步读取工具读取VUE组件,得到VUE组件中的各组件文件。S101: Read the VUE component by using a preset asynchronous reading tool to obtain each component file in the VUE component.
其中,各组件文件包括页面文件、JS文件以及层叠样式表CSS文件。Wherein, each component file includes a page file, a JS file, and a cascading style sheet CSS file.
利用预设异步读取工具读取VUE组件的文件内容,得到VUE组件中的各组件文件。其中,VUE组件是一种视图与交互逻辑的抽象数据类型,其包含有HTML模板、CSS样式以及JS逻辑代码片段,使用例如webpack打包工具的vue-loader插件可以将VUE组件编译为可运行的H5代码。Use the preset asynchronous reading tool to read the file content of the VUE component, and get each component file in the VUE component. Among them, the VUE component is an abstract data type of view and interaction logic, which contains HTML templates, CSS styles, and JS logic code fragments. Using the vue-loader plugin of the webpack packaging tool, for example, can compile VUE components into runnable H5 code.
在本申请实施例中,通过预设异步读取工具读取VUE组件,根据其所包含的内容得到各组件文件,即得到页面文件、JS文件以及层叠样式表CSS文件。其中,页面文件可以理解为存储HTML模板的代码的文件,JS文件可以理解为存储JS逻辑代码片段的文件,CSS文件可以理解为存储CSS样式的代码的文件。因而,通过读取VUE组件的文件内容,可以按照其所包含的文件内容得到各组件文件,各组件文件如图3中的左边部分所示,图3为本申请实施例提供的一种文件存储示意图。预设异步读取工具可以例如fs.readFileSync,用于异步读取VUE文件中所包含的各部分文件内容。In the embodiment of this application, the VUE component is read by a preset asynchronous reading tool, and each component file is obtained according to its contained content, that is, the page file, JS file and CSS file of the cascading style sheet are obtained. Wherein, the page file can be understood as a file storing HTML template codes, the JS file can be understood as a file storing JS logic code fragments, and the CSS file can be understood as a file storing CSS style codes. Therefore, by reading the file content of the VUE component, each component file can be obtained according to the file content contained in it. Each component file is shown in the left part of Figure 3, and Figure 3 is a file storage provided by the embodiment of the present application. schematic diagram. The preset asynchronous reading tool can be, for example, fs.readFileSync, which is used to asynchronously read the content of each part of the file contained in the VUE file.
在一种可能的设计中,在利用预设异步读取工具读取VUE组件之前,还包括:In a possible design, before using the preset asynchronous reading tool to read VUE components, it also includes:
根据组件生成需求生成工作指令,响应于工作指令运行命令行工具,其中,命令行工具用于启用本申请实施例提供的小程序生成方法。可以理解的是,组件生成需求用于表征当前存在组件转换需求,需要将已有的VUE组件进行转换。进一步地,则可以设置辅助工具,通过辅助工具进行VUE组件的转换,该辅助工具即为响应工作指令能够启用本申请实施例提供的小程序生成方法的命令行工具。命令行工具具体所对应的工作提示符可以根据实际情况设置,对此本申请实施例不作限定。A work instruction is generated according to the component generation requirement, and a command line tool is run in response to the work order, wherein the command line tool is used to enable the applet generation method provided by the embodiment of the present application. It can be understood that the component generation requirements are used to represent the current component conversion requirements, and the existing VUE components need to be converted. Further, an auxiliary tool can be set to convert the VUE components through the auxiliary tool, which is a command-line tool capable of enabling the applet generation method provided by the embodiment of the present application in response to a work order. The specific working prompt corresponding to the command line tool can be set according to the actual situation, which is not limited in this embodiment of the present application.
S102:将各组件文件内的代码分别对应存储至各临时文件。S102: Correspondingly store the codes in each component file into each temporary file.
其中,各临时文件包括微信标记语言(WeiXin Markup Language)WXML临时文件、JS临时文件以及微信层叠样式表(WeiXinStyle Sheets)WXSS临时文件。Among them, each temporary file includes WeChat Markup Language (WeiXin Markup Language) WXML temporary files, JS temporary files, and WeChat Cascading Style Sheets (WeiXinStyle Sheets) WXSS temporary files.
为了使得VUE组件在转换前后的代码具有清晰的对应关系,以及确保转换后得到的各小程序组件的正确性,可以将根据VUE组件得到的各组件文件内的代码分别对应存储至各临时文件,进而分别对各临时文件内的代码进行转换。例如,基于各组件文件内的代码和最终所要转换到的各小程序组件文件内代码之间的对应关系,则可以将页面文件内的代码存储至WXML临时文件,将JS文件内的代码存储至JS临时文件,将CSS文件内的代码存储至WXSS临时文件。继续参照图3所示,图3中的右边部分则示出了将各组件文件对应存储到的各临时文件。In order to make the codes of VUE components have a clear correspondence before and after conversion, and to ensure the correctness of the converted applet components, you can store the codes in each component file obtained from the VUE components in corresponding temporary files. Further, the codes in each temporary file are converted respectively. For example, based on the correspondence between the codes in each component file and the codes in each applet component file to be converted to eventually, the code in the page file can be stored in the WXML temporary file, and the code in the JS file can be stored in the The JS temporary file stores the code in the CSS file to the WXSS temporary file. Continuing to refer to FIG. 3 , the right part of FIG. 3 shows the temporary files where the component files are correspondingly stored.
可选地,将各组件文件对应存储至各临时文件时,各临时文件内的文档格式可以根据实际情况设置,例如可以为记事本格式、文档格式等等,对此本申请实施例不作限定。Optionally, when each component file is correspondingly stored in each temporary file, the document format in each temporary file can be set according to the actual situation, for example, it can be a notepad format, a document format, etc., which is not limited in this embodiment of the present application.
S103:根据预设转换策略对每个临时文件内的代码进行转换,对应得到各小程序组件文件,以根据各小程序组件文件生成小程序。S103: Convert the code in each temporary file according to a preset conversion strategy to obtain corresponding applet component files, so as to generate a applet according to each applet component file.
其中,预设转换策略包括遍历每个抽象语法树的每个节点以修改每个抽象语法树的目标节点,每个抽象语法树为每个临时文件内的代码对应形成。Wherein, the preset conversion strategy includes traversing each node of each abstract syntax tree to modify the target node of each abstract syntax tree, and each abstract syntax tree is correspondingly formed for the code in each temporary file.
在分别对每个临时文件内的代码进行转换得到各小程序组件文件时,引入预设转换策略达到遍历每个抽象语法树的每个节点以对需要进行修改的节点也即目标节点进行修改的目的,每个临时文件内的代码对应形成各自的抽象语法树。经过对预设转换策略对每个临时文件内的代码进行转换后,相应地将经过转换后的各临时文件对应确定为小程序组件文件,从而对应得到各小程序组件文件。在得到各小程序组件文件的基础上,通过读取并加载得到的各小程序组件文件内的文件内容,生成小程序。其中,各小程序组件文件内的文件内容即为转换后得到的各小程序组件。另外需要说明的是,在生成小程序时还需新建一个后缀为JSON的目标文件,该后缀为JSON的目标文件为小程序的配置JSON文件,其中的文件内容为{ "component": true }。When converting the code in each temporary file to obtain each applet component file, a preset conversion strategy is introduced to traverse each node of each abstract syntax tree to modify the node that needs to be modified, that is, the target node Purpose, the codes in each temporary file correspond to form their respective abstract syntax trees. After converting the codes in each temporary file according to the preset conversion strategy, the converted temporary files are correspondingly determined as applet component files, so as to obtain corresponding applet component files. On the basis of obtaining each applet component file, the applet is generated by reading and loading the obtained file content in each applet component file. Wherein, the file content in each applet component file is each applet component obtained after conversion. In addition, it should be noted that when generating the applet, a target file with the suffix of JSON needs to be created. The target file with the suffix of JSON is the configuration JSON file of the applet, and the content of the file is { "component": true }.
在一种可能的设计中,本步骤S103中根据预设转换策略对每个临时文件内的代码进行转换对应得到各小程序组件文件的可能实现方式如图4所示。图4为本申请实施例提供的另一种小程序生成方法的流程示意图。如图4所示,本申请实施例包括:In a possible design, in this step S103, the code in each temporary file is converted according to the preset conversion strategy to obtain each applet component file, as shown in FIG. 4 . FIG. 4 is a schematic flowchart of another method for generating a small program provided by an embodiment of the present application. As shown in Figure 4, the embodiment of this application includes:
S201:按照第一预设转换规则对WXML临时文件内的代码进行转换,生成WXML目标文件。S201: Convert the code in the WXML temporary file according to a first preset conversion rule to generate a WXML target file.
S202:按照第二预设转换规则对JS临时文件内的代码进行转换,生成JS目标文件。S202: Convert the code in the JS temporary file according to the second preset conversion rule to generate a JS target file.
S203:按照第三预设转换规则对WXSS临时文件内的代码进行转换,生成WXSS目标文件。S203: Convert the code in the WXSS temporary file according to the third preset conversion rule to generate a WXSS target file.
其中,预设转换策略包括第一预设转换规则、第二预设转换规则以及第三预设转换规则,各小程序组件文件包括WXML目标文件、JS目标文件以及WXSS目标文件。预设转换策略包括第一预设转换规则、第二预设转换规则以及第三预设转换规则,其中,第一预设转换规则为针对WXML临时文件内的代码进行转换的具体规则,第二预设转换规则为针对JS临时文件内的代码进行转换的具体规则,第三预设转换规则为针对WXSS临时文件内的代码进行转换的具体规则。Wherein, the preset conversion strategy includes a first preset conversion rule, a second preset conversion rule, and a third preset conversion rule, and each applet component file includes a WXML object file, a JS object file, and a WXSS object file. The preset conversion strategy includes a first preset conversion rule, a second preset conversion rule and a third preset conversion rule, wherein the first preset conversion rule is a specific rule for converting the code in the WXML temporary file, and the second The preset conversion rule is a specific rule for converting codes in the JS temporary file, and the third preset conversion rule is a specific rule for converting codes in the WXSS temporary file.
相应地,WXML临时文件内的代码经过第一预设转换规则转换后,则将该WXML临时文件确定为WXML目标文件,即WXML目标文件内的代码为经过第一预设转换规则转换后的代码。JS临时文件内的代码经过第二预设转换规则转换后,则将该JS临时文件确定为JS目标文件,即JS目标文件内的代码为经过第二预设转换规则转换后的代码。CSS临时文件内的代码经过第三预设转换规则转换后,则将该CSS临时文件确定为CSS目标文件,即CSS目标文件内的代码为经过第三预设转换规则转换后的代码。Correspondingly, after the code in the WXML temporary file is converted by the first preset conversion rule, the WXML temporary file is determined as the WXML target file, that is, the code in the WXML target file is the code converted by the first preset conversion rule . After the code in the JS temporary file is converted by the second preset conversion rule, the JS temporary file is determined as the JS target file, that is, the code in the JS target file is the code converted by the second preset conversion rule. After the code in the CSS temporary file is converted by the third preset conversion rule, the CSS temporary file is determined as the CSS target file, that is, the code in the CSS target file is the code converted by the third preset conversion rule.
其中,需要说明的是,第一预设转换规则、第二预设转换规则以及第三预设转换规则各自的具体内容则为将各临时文件内的代码转换为对应的各小程序组件所需的代码,并且在采用第一预设转换规则、第二预设转换规则以及第三预设转换规则时以各临时文件内的代码所对应形成的抽象语法树进行,从而通过遍历各抽象语法树的每个节点并对每个抽象语法树的目标节点进行修改,实现对各临时文件内的代码至对应各小程序代码的转换,提高转换效率并使得可修改的内容颗粒度更小,进而保证修改正确性。每个抽象语法树的目标节点即为VUE组件和小程序组件存在差异的节点。Wherein, it should be noted that the specific contents of the first preset conversion rule, the second preset conversion rule and the third preset conversion rule are required for converting the codes in each temporary file into corresponding applet components. code, and when using the first preset conversion rule, the second preset conversion rule, and the third preset conversion rule, the abstract syntax tree corresponding to the code in each temporary file is used, so that by traversing each abstract syntax tree and modify the target node of each abstract syntax tree to realize the conversion of the code in each temporary file to the corresponding applet code, improve the conversion efficiency and make the granularity of the modifiable content smaller, thereby ensuring Revised for correctness. The target node of each abstract syntax tree is the node where there is a difference between the VUE component and the applet component.
进一步地,在得到各小程序组件文件之后,还根据JS目标文件内的代码生成信息文件,采用信息文件记录各小程序组件文件的代码在VUE组件的代码中的位置信息,便于后期调试。Further, after obtaining each applet component file, an information file is also generated according to the code in the JS target file, and the information file is used to record the position information of the code of each applet component file in the code of the VUE component, which is convenient for later debugging.
本申请实施例提供的小程序生成方法,首先利用预设异步读取工具读取VUE组件,得到VUE组件中的各组件文件,各组件文件包括页面文件、JS文件以及CSS文件。然后将各组件文件内的代码分别对应存储至各临时文件,各临时文件包括WXML临时文件、JS临时文件以及WXSS临时文件。最后根据预设转换策略对每个临时文件内的代码进行转换,得到各小程序组件文件,完成VUE组件至小程序组件的转换,进而根据各小程序组件文件内的文件内容生成小程序。其中,预设转换策略包括遍历每个抽象语法树的每个节点以修改每个抽象语法树的目标节点,而每个抽象语法树由每个临时文件内的代码对应形成。基于预设转换策略进行转换得到小程序组件,有效提高了得到各小程序组件以及生成小程序的效率,使得可修改的内容颗粒度更小,保障了所得到的小程序组件的正确性,并可以获知修改前后代码之间的对应关系,便于后续维护。The applet generation method provided by the embodiment of the present application first uses the preset asynchronous reading tool to read the VUE component to obtain each component file in the VUE component, and each component file includes a page file, a JS file and a CSS file. Then, the codes in each component file are correspondingly stored in each temporary file, and each temporary file includes a WXML temporary file, a JS temporary file, and a WXSS temporary file. Finally, convert the code in each temporary file according to the preset conversion strategy to obtain each applet component file, complete the conversion from VUE component to applet component, and then generate the applet according to the file content in each applet component file. Wherein, the preset conversion strategy includes traversing each node of each abstract syntax tree to modify the target node of each abstract syntax tree, and each abstract syntax tree is correspondingly formed by codes in each temporary file. The applet components are converted based on the preset conversion strategy, which effectively improves the efficiency of obtaining applet components and generating applets, making the granularity of modifiable content smaller, ensuring the correctness of the obtained applet components, and You can know the correspondence between codes before and after modification, which is convenient for subsequent maintenance.
在一种可能的设计中,步骤S201可能的实现方式如图5所示。图5为本申请实施例提供的再一种小程序生成方法的流程示意图。如图5所示,本申请实施例包括:In a possible design, a possible implementation manner of step S201 is shown in FIG. 5 . FIG. 5 is a schematic flowchart of another method for generating a small program provided by the embodiment of the present application. As shown in Figure 5, the embodiment of this application includes:
S2011:利用预设异步读取工具读取WXML临时文件,以获得WXML临时文件内的代码。S2011: Read the WXML temporary file by using a preset asynchronous reading tool to obtain the code in the WXML temporary file.
利用预设异步读取工具读取WXML临时文件的文件内容,从而获得WXML临时文件内的代码,其中该步骤为利用预设异步读取工具读取WXML临时文件的文件内容并将所读取到的文件内容转化为对应字符串的过程。预设异步读取工具可以例如fs.readFileSync。Use the preset asynchronous reading tool to read the file content of the WXML temporary file, so as to obtain the code in the WXML temporary file, wherein the step is to use the preset asynchronous reading tool to read the file content of the WXML temporary file and read it into The process of converting the content of the file into the corresponding string. Preset asynchronous read tools such as fs.readFileSync.
S2012:利用页面解析器解析WXML临时文件内的代码,得到第一抽象语法树。S2012: Using the page parser to parse the code in the WXML temporary file to obtain a first abstract syntax tree.
其中,第一抽象语法树包括对页面文件中所有内容的描述。采用例如htmlparser2这种页面解析器解析WXML临时文件内的代码也即解析上述步骤得到的字符串,对应得到WXML临时文件内的代码所对应的抽象语法树,即第一抽象语法树。其中,抽象语法树(Abstract Syntax Tree,AST)是源代码的抽象语法结构的树状表示,树上的每个节点是源代码中对应节点的结构化的抽象数据。因而,第一抽象语法树对页面文件中的每一个部分都进行了详细的定义,也即第一抽象语法树包括有对页面文件中所有内容的描述。Wherein, the first abstract syntax tree includes descriptions of all contents in the page file. Using a page parser such as htmlparser2 to parse the code in the WXML temporary file, that is, parse the string obtained in the above steps, and obtain an abstract syntax tree corresponding to the code in the WXML temporary file, that is, the first abstract syntax tree. Among them, the abstract syntax tree (Abstract Syntax Tree, AST) is a tree representation of the abstract syntax structure of the source code, and each node on the tree is the structured abstract data of the corresponding node in the source code. Therefore, the first abstract syntax tree defines each part in the page file in detail, that is, the first abstract syntax tree includes descriptions of all contents in the page file.
S2013:根据第一预设转换规则修改第一抽象语法树,得到第一目标抽象语法树。S2013: Modify the first abstract syntax tree according to the first preset conversion rule to obtain the first target abstract syntax tree.
采用第一预设转换规则对第一抽象语法树进行修改,将修改后的第一抽象语法树确定为第一目标抽象语法树,得到第一目标抽象语法树。The first abstract syntax tree is modified by using the first preset conversion rule, and the modified first abstract syntax tree is determined as the first target abstract syntax tree to obtain the first target abstract syntax tree.
其中,根据前述实施例的描述可知,第一预设转换规则的具体内容为将WXML临时文件内的代码修改为对应的小程序所需的代码时所遵循的对应规则。在小程序中,对于WXML临时文件内的代码所涉及到的内容,是不需要顶部的DOCTYPE标签中的内容的,只需要关注在body标签中的内容即可。换言之,在对第一抽象语法树利用第一预设转换规则进行修改时,只需关注第一抽象语法树中body标签所在的节点上的内容即可,例如body标签可以只有一个子元素div,div有两个子元素,分别是文本(TEXT)”VUE TO MP”和一个标签(ELEMENT)span,标签span只有一个子元素,是类型为文本(TEXT)的“This is detail.”。Wherein, according to the description of the foregoing embodiments, it can be seen that the specific content of the first preset conversion rule is the corresponding rule followed when modifying the code in the WXML temporary file to the code required by the corresponding applet. In the applet, for the content involved in the code in the WXML temporary file, the content in the DOCTYPE tag at the top is not needed, and only the content in the body tag is required. In other words, when modifying the first abstract syntax tree using the first preset conversion rule, you only need to pay attention to the content of the node where the body tag is located in the first abstract syntax tree. For example, the body tag may have only one child element div, The div has two child elements, which are text (TEXT) "VUE TO MP" and a label (ELEMENT) span. The label span has only one child element, which is "This is detail." of type text (TEXT).
对第一抽象语法树按照第一预设转换规则进行修改后得到的抽象语法树即为第一目标抽象语法树,进而则可执行步骤S2014得到WXML目标文件。The abstract syntax tree obtained by modifying the first abstract syntax tree according to the first preset conversion rule is the first target abstract syntax tree, and step S2014 can be executed to obtain the WXML target file.
S2014:根据第一目标抽象语法树生成第一目标代码,并根据第一目标代码得到WXML目标文件。S2014: Generate a first object code according to the first object abstract syntax tree, and obtain a WXML object file according to the first object code.
将第一目标抽象语法树所表示的内容确定为第一目标代码,即根据第一目标抽象语法树生成第一目标代码,该第一目标代码所属的文件则被确定为WXML目标文件,即根据第一目标代码得到WXML目标文件,从而完成VUE组件中页面文件内的代码至小程序组件文件中WXML目标文件内代码的转换。The content represented by the first object abstract syntax tree is determined as the first object code, that is, the first object code is generated according to the first object abstract syntax tree, and the file to which the first object code belongs is determined as a WXML object file, that is, according to The first target code obtains the WXML target file, thereby completing the conversion of the code in the page file in the VUE component to the code in the WXML target file in the applet component file.
在一种可能的设计中,步骤S2013可能的实现方式包括:In a possible design, a possible implementation of step S2013 includes:
遍历第一抽象语法树,在第一抽象语法树中获得表单标签,根据预设标签映射表替换表单标签中的标签内容。其中,表单标签是为了方面描述页面文件中与小程序组件写法不同的标准的HTML标签而自定义的。利用预设标签映射表对表单标签进行修改,以将其修改为小程序支持的标签。预设标签映射表如下表1所示:Traverse the first abstract syntax tree, obtain form tags in the first abstract syntax tree, and replace the label content in the form tags according to the preset label mapping table. Among them, the form tag is customized for describing standard HTML tags in the page file that are different from the applet component. Use the preset label mapping table to modify the form label to change it to the label supported by the applet. The preset label mapping table is shown in Table 1 below:
表1Table 1
Figure 891506dest_path_image001
Figure 891506dest_path_image001
根据格式修改规则修改第一抽象语法树的目标节点,然后将经过预设表情映射表替换以及格式修改规则修改后的第一抽象语法树确定为第一目标抽象语法树。其中,对第一抽象语法树进行修改所采用的第一预设转换规则包括上述预设表情映射表以及格式修改规则。格式修改规则包括对第一抽象语法树的目标节点进行修改以使得修改后的代码的格式符合小程序组件要求所涉及的具体修改内容。The target node of the first abstract syntax tree is modified according to the format modification rule, and then the first abstract syntax tree after the preset expression mapping table is replaced and the format modification rule is modified is determined as the first target abstract syntax tree. Wherein, the first preset conversion rule adopted for modifying the first abstract syntax tree includes the above preset expression mapping table and format modification rules. The format modification rule includes specific modification content involved in modifying the target node of the first abstract syntax tree so that the format of the modified code meets the requirements of the applet component.
在一种可能的设计中,格式修改规则可以包括如下内容:In a possible design, format modification rules may include the following content:
例如将第一抽象语法树中的列渲染格式修改为小程序列表渲染格式,具体地,在VUE组件中列表渲染格式的写法为:<tag v-for=“(item,index) in list” v-bind:key=“index”></tag>,因而需要修改为小程序列表渲染格式的写法:<tag wx:for=“{{list}}” wx:key=“index”></tag>。For example, modify the column rendering format in the first abstract syntax tree to the applet list rendering format. Specifically, the list rendering format in the VUE component is written as: <tag v-for="(item,index) in list" v -bind:key="index"></tag>, so it needs to be modified to the rendering format of the applet list: <tag wx:for="{{list}}" wx:key="index"></tag >.
例如将第一抽象语法树中的条件渲染格式修改为小程序条件渲染格式,具体地,在VUE组件中条件渲染格式的写法如下所示:For example, modify the conditional rendering format in the first abstract syntax tree to the applet conditional rendering format. Specifically, the conditional rendering format in the VUE component is written as follows:
<tag v-if=“a”></tag><tag v-if="a"></tag>
<tag v—else-if=“b”></tag><tag v—else-if="b"></tag>
<tag v—else></tag><tag v—else></tag>
因而需要修改为小程序条件渲染格式的写法,如下所示:Therefore, it is necessary to modify the writing method of the conditional rendering format of the applet, as follows:
<tag wx:if={{a}}></tag><tag wx:if={{a}}></tag>
<tag wx:elif={{b}}></tag><tag wx:elif={{b}}></tag>
<tag wx:else></tag><tag wx:else></tag>
例如将第一抽象语法树中的事件绑定格式修改为小程序事件绑定格式,VUE组件中事件绑定格式的写法为:<tag @cilck=“doSomething”></tag>,修改为小程序事件绑定格式的写法为:<tag bindtap=“doSomething”></tag>。For example, modify the event binding format in the first abstract syntax tree to the applet event binding format, and the event binding format in the VUE component is written as: <tag @cilck="doSomething"></tag>, modify it to the small program event binding format: <tag bindtap="doSomething"></tag>.
用于表征列表渲染、条件渲染以及事件绑定的内容在第一抽象语法树中所属的节点即为第一抽象语法树的目标节点。The node to which the content representing list rendering, conditional rendering and event binding belongs in the first abstract syntax tree is the target node of the first abstract syntax tree.
本申请实施例提供的小程序生成方法中,按照第一预设转换规则对WXML临时文件内的代码进行转换得到WXML目标文件,WXML目标文件内的代码则用于表征小程序组件中WXML模板。其中,通过遍历第一抽象语法树以及根据第一预设转换规则所包括的预设标签映射表和格式修改规则对第一抽象语法树的目标节点进行修改,以使得的修改后得到的WXML目标文件内的代码符合小程序的运行要求,从而不但提高VUE组件中页面文件内的代码至WXML目标文件内代码的转换效率,还使得可修改的内容颗粒度更小,保障了所得到的WXML目标文件内代码的正确性,并且保证页面文件内代码与WXML目标文件内代码也即修改前后代码之间的对应关系,便于后续的代码维护和错误定位。In the applet generating method provided by the embodiment of the present application, the code in the WXML temporary file is converted according to the first preset conversion rule to obtain the WXML object file, and the code in the WXML object file is used to represent the WXML template in the applet component. Among them, the target node of the first abstract syntax tree is modified by traversing the first abstract syntax tree and according to the preset tag mapping table and format modification rules included in the first preset conversion rule, so that the WXML target obtained after modification The code in the file meets the running requirements of the applet, which not only improves the conversion efficiency of the code in the page file in the VUE component to the code in the WXML target file, but also makes the granularity of the modifiable content smaller, ensuring the obtained WXML target The correctness of the code in the file, and the corresponding relationship between the code in the page file and the code in the WXML target file, that is, the code before and after modification, is convenient for subsequent code maintenance and error location.
在一种可能的设计中,步骤S202可能的实现方式如图6所示。图6为本申请实施例提供的又一种小程序生成方法的流程示意图。如图6所示,本申请实施例包括:In a possible design, a possible implementation manner of step S202 is shown in FIG. 6 . FIG. 6 is a schematic flowchart of another applet generation method provided by the embodiment of the present application. As shown in Figure 6, the embodiment of this application includes:
S2021:利用预设异步读取工具读取JS临时文件,以获得JS临时文件内的代码。S2021: Use a preset asynchronous reading tool to read the JS temporary file to obtain the code in the JS temporary file.
利用预设异步读取工具读取JS临时文件的文件内容,从而获得JS临时文件内的代码,其中该步骤为利用预设异步读取工具读取JS临时文件的文件内容并将所读取到的文件内容转化为对应字符串的过程。Use the preset asynchronous reading tool to read the file content of the JS temporary file, so as to obtain the code in the JS temporary file, wherein this step is to use the preset asynchronous reading tool to read the file content of the JS temporary file and read it into The process of converting the content of the file into the corresponding string.
预设异步读取工具可以例如fs.readFileSync。Preset asynchronous read tools such as fs.readFileSync.
S2022:利用解析插件解析JS临时文件内的代码,得到第二抽象语法树。S2022: Use the parsing plug-in to parse the code in the JS temporary file to obtain a second abstract syntax tree.
其中,第二抽象语法树包括对JS文件中所有内容的描述。Wherein, the second abstract syntax tree includes a description of all contents in the JS file.
采用例如@babel/parser的parse方法解析JS临时文件内的代码也即解析上述步骤得到的字符串,对应得到JS临时文件内的代码所对应的抽象语法树,即第二抽象语法树。其中,抽象语法树(Abstract Syntax Tree,AST)是源代码的抽象语法结构的树状表示,树上的每个节点是源代码中对应节点的结构化的抽象数据。因而,第二抽象语法树对JS文件中的每一个部分都进行了详细的定义,也即第二抽象语法树包括有对JS文件中所有内容的描述。Use the parse method such as @babel/parser to parse the code in the JS temporary file, that is, parse the string obtained in the above steps, and obtain the corresponding abstract syntax tree corresponding to the code in the JS temporary file, that is, the second abstract syntax tree. Among them, the abstract syntax tree (Abstract Syntax Tree, AST) is a tree representation of the abstract syntax structure of the source code, and each node on the tree is the structured abstract data of the corresponding node in the source code. Therefore, the second abstract syntax tree defines each part in the JS file in detail, that is, the second abstract syntax tree includes a description of all contents in the JS file.
S2023:根据第二预设转换规则修改第二抽象语法树,得到第二目标抽象语法树。S2023: Modify the second abstract syntax tree according to the second preset conversion rule to obtain a second target abstract syntax tree.
采用第二预设转换规则对第二抽象语法树进行修改,将修改后的第二抽象语法树确定为第二目标抽象语法树,得到第二目标抽象语法树。The second abstract syntax tree is modified by using the second preset conversion rule, and the modified second abstract syntax tree is determined as the second target abstract syntax tree to obtain the second target abstract syntax tree.
其中,根据前述实施例的描述可知,第二预设转换规则的具体内容为将JS临时文件内的代码修改为对应的小程序所需的代码时所遵循的对应规则。VUE组件中JS文件中的代码的内容体现在data、created、methods这三个属性上,因而可以通过设置相应的属性修改规则来表征第二预设转换规则,以对第二抽象语法树进行修改。Wherein, according to the description of the foregoing embodiments, it can be seen that the specific content of the second preset conversion rule is the corresponding rule followed when modifying the code in the JS temporary file to the code required by the corresponding applet. The content of the code in the JS file in the VUE component is reflected in the three attributes of data, created, and methods, so the second preset conversion rule can be represented by setting the corresponding attribute modification rules to modify the second abstract syntax tree .
对第二抽象语法树按照第二预设转换规则进行修改后得到的抽象语法树即为第二目标抽象语法树,进而则可执行步骤S2024得到JS目标文件。The abstract syntax tree obtained by modifying the second abstract syntax tree according to the second preset conversion rule is the second target abstract syntax tree, and step S2024 can be executed to obtain the JS target file.
S2024:根据第二目标抽象语法树生成第二目标代码,并根据第二目标代码得到JS目标文件。S2024: Generate a second object code according to the second object abstract syntax tree, and obtain a JS object file according to the second object code.
将第二目标抽象语法树所表示的内容确定为第二目标代码,即根据第二目标抽象语法树生成第二目标代码,该第二目标代码所属的文件则被确定为JS目标文件,即根据第二目标代码得到JS目标文件,从而完成VUE组件中JS文件内的代码至小程序组件中JS目标文件内代码的转换。The content represented by the second target abstract syntax tree is determined as the second target code, that is, the second target code is generated according to the second target abstract syntax tree, and the file to which the second target code belongs is determined as the JS target file, that is, according to The second target code obtains the JS target file, thereby completing the conversion of the code in the JS file in the VUE component to the code in the JS target file in the applet component.
在一种可能的设计中,步骤2023可能的实现方式包括:In a possible design, possible implementations of step 2023 include:
遍历第二抽象语法树,根据属性修改规则修改第二抽象语法树的目标节点,将修改后的第二抽象语法树确定为第二目标抽象语法树,从而得到第二目标抽象语法树。第二预设转换规则的具体内容为将JS临时文件内的代码修改为对应的小程序所需的代码时所遵循的对应规则,该对应规则具体可包括属性修改规则。Traverse the second abstract syntax tree, modify the target node of the second abstract syntax tree according to the attribute modification rules, and determine the modified second abstract syntax tree as the second target abstract syntax tree, thereby obtaining the second target abstract syntax tree. The specific content of the second preset conversion rule is the corresponding rule followed when modifying the code in the JS temporary file to the code required by the corresponding applet, and the corresponding rule may specifically include an attribute modification rule.
在一种可能的设计中,属性修改规则包括以下内容:In one possible design, the attribute modification rules include the following:
例如,在VUE组件中data属性的定义是以返回(return)函数的返回数据定义的,但由于小程序中直接使用对象定义,因此对于data属性而言,则首先获取到返回函数的属性和值,然后直接利用返回函数的属性和值直接定义data属性,即利用返回函数的属性和值替换返回函数的返回数据,对第二抽象语法树中data属性的定义得到修改,返回函数的返回数据则为修改前也即VUE组件中对应的第二抽象语法数据中data属性的定义,比如以“key”、“value”的形式作为小程序组件中data属性的定义。For example, the definition of the data attribute in the VUE component is defined by the return data of the return (return) function, but since the object definition is directly used in the applet, for the data attribute, the attribute and value of the return function must first be obtained , and then directly use the attributes and values of the returned function to directly define the data attribute, that is, use the attributes and values of the returned function to replace the returned data of the returned function, modify the definition of the data attribute in the second abstract syntax tree, and the returned data of the returned function is then It is the definition of the data attribute in the corresponding second abstract syntax data in the VUE component before modification, for example, in the form of "key" and "value" as the definition of the data attribute in the applet component.
属性修改规则还包括对于props属性定义的修改,例如将第二抽象语法树中的props属性定义以及对应默认属性值的定义方式分别修改为目标属性定义和目标定义方式,其中,目标属性定义和目标定义方式满足小程序的属性定义要求。具体地,VUE组件中对于props属性的定义如下:The attribute modification rules also include modifications to the props attribute definition, for example, modifying the props attribute definition in the second abstract syntax tree and the definition method of the corresponding default attribute value to the target attribute definition and the target definition method, wherein, the target attribute definition and the target The definition method meets the attribute definition requirements of the applet. Specifically, the definition of the props attribute in the VUE component is as follows:
props: {props: {
       mode: { type: Number, default: 0 }`` mode: { type: Number, default: 0 }
}。}.
属性修改规则是将上述的“props”修改为“properties”,“props”为props属性定义,“properties”为目标属性定义,“default”表示props属性定义的对应默认属性值的定义,属性修改规则是将“default”修改为“value”,“value”则表示目标定义方式,其满足小程序的属性定义要求。因而,通过属性修改规则对上述VUE组件中props属性的定义,也即对第二抽象语法树中的props属性定义以及对应默认属性值的定义方式进行修改,以得到满足小程序的属性定义要求的目标属性定义和目标定义方式如下所示:The property modification rule is to modify the above "props" to "properties", "props" is the definition of the props attribute, "properties" is the definition of the target attribute, "default" represents the definition of the corresponding default attribute value defined by the props attribute, and the property modification rule It is to change "default" to "value", and "value" indicates the target definition method, which meets the attribute definition requirements of the applet. Therefore, the definition of the props attribute in the above VUE component is modified through the attribute modification rules, that is, the definition of the props attribute in the second abstract syntax tree and the definition of the corresponding default attribute value are modified to obtain the property definition requirements of the applet. Target property definitions and target definition are as follows:
properties: {properties: {
       mode: { type: Number, value: 0 }`` mode: { type: Number, value: 0 }
}。}.
属性修改规则还包括:将第二抽象语法树的数据读取方式修改为目标读取方式,目标读取方式满足小程序的生命周期钩子函数。例如,在VUE组件中读取数据是直接使用“this.key”的方式,“key”代表数据的键值,比如“this.name”可以直接拿到VUE组件中数据“name”对应的值。而在小程序组件中读取数据增加了一个层级,格式为“this.data.key”,相当于在VUE组件中使用“this.data.name”才能取到“name”指代的值。在遍历第二抽象语法树时,当遇到 “ThisExpression”表达式时,则替换对应的“property”,比如VUE组件中的表达式“this.name”在第二抽象语法树中属于“MemberExpression”,其中的“this”代表“ThisExpression”,“name”代表类型为“Identifier”的“property”。在小程序组件中“this.data.name”在修改后的第二抽象语法树中属于“MemberExpression”,“this.data”属于子“MemberExpression”,“name”则作为跟这个子“MemberExpression”同一个层级的类型为“Identifier”的“property”,从而以将第二抽象语法树的数据读取方式进行修改,修改为满足小程序的生命周期钩子函数的目标读取方式。The property modification rule further includes: modifying the data reading mode of the second abstract syntax tree to a target reading mode, and the target reading mode satisfies the life cycle hook function of the applet. For example, reading data in the VUE component is directly using "this.key", "key" represents the key value of the data, for example, "this.name" can directly get the value corresponding to the data "name" in the VUE component. However, reading data in the applet component adds a level, and the format is "this.data.key", which is equivalent to using "this.data.name" in the VUE component to get the value referred to by "name". When traversing the second abstract syntax tree, when encountering the "ThisExpression" expression, replace the corresponding "property". For example, the expression "this.name" in the VUE component belongs to "MemberExpression" in the second abstract syntax tree , where "this" represents "ThisExpression", and "name" represents a "property" of type "Identifier". In the applet component, "this.data.name" belongs to "MemberExpression" in the modified second abstract syntax tree, "this.data" belongs to the child "MemberExpression", and "name" is the same as the child "MemberExpression". A level of "property" whose type is "Identifier" modifies the data reading method of the second abstract syntax tree to meet the target reading method of the life cycle hook function of the applet.
属性修改规则还包括将第二抽象语法树中的赋值表达式修改为小程序执行函数的方式。在VUE组件中可以直接进行赋值,例如当需要为“name”赋值时,则按照表达式“this.name = ‘值’”进行即可。但在小程序中,必须使用如下表达式才能正确赋值:The property modifying rule also includes a method of modifying the assignment expression in the second abstract syntax tree into the execution function of the applet. Assignment can be made directly in the VUE component. For example, when you need to assign a value to "name", follow the expression "this.name = 'value'". But in the applet, the following expressions must be used to assign values correctly:
this.setData({this.setData({
  name: ‘值’name: 'value'
})。}).
上述小程序中的赋值表达式即为小程序执行函数方式。其中,“setData”为小程序内置的,在对赋值表达式进行修改时需要将第二抽象语法树中赋值的表达式修改为小程序执行函数的方式。“this.name = ‘值’”整个表达式在第二抽象语法树中的定义为“ExpressionStatement”,细分定义为类型为负值表达式“AssignmentExpression”中的表达式“expression”,操作符号“operator”表示“=”,“this.name”作为整个赋值表达式的左侧部分,“‘值’”作为右侧部分。The assignment expression in the above applet is the way the applet executes the function. Among them, "setData" is built in the applet. When modifying the assignment expression, it is necessary to modify the assigned expression in the second abstract syntax tree to the way the applet executes the function. "this.name = 'value'" The whole expression is defined as "ExpressionStatement" in the second abstract syntax tree, and the subdivision is defined as the expression "expression" in the negative value expression "AssignmentExpression", and the operation symbol "operator" means " =", "this.name" as the left part of the entire assignment expression, and "'value'" as the right part.
属性修改规则所涉及到部分在第二抽象语法树中的所属的节点即为第二抽象语法树的目标节点。The node to which the part involved in the attribute modification rule belongs in the second abstract syntax tree is the target node of the second abstract syntax tree.
本申请实施例提供的小程序生成方法中,按照第二预设转换规则对JS临时文件内的代码进行转换得到JS目标文件,JS目标文件内的代码则用于表征小程序组件中JS逻辑代码片段。其中,通过遍历第二抽象语法树以及根据第二预设转换规则所包括的属性修改规则对第二抽象语法树的目标节点进行修改,以使得的修改后得到的JS目标文件内的代码符合小程序的运行要求,从而不但提高VUE组件中JS文件内的代码至JS目标文件内代码的转换效率,还使得可修改的内容颗粒度更小,保障了所得到的JS目标文件内代码的正确性,并且保证JS文件内代码与JS目标文件内代码也即修改前后代码之间的对应关系,便于后续的代码维护和错误定位。In the applet generation method provided by the embodiment of the present application, the code in the JS temporary file is converted according to the second preset conversion rule to obtain the JS target file, and the code in the JS target file is used to represent the JS logic code in the applet component fragment. Wherein, the target node of the second abstract syntax tree is modified by traversing the second abstract syntax tree and according to the attribute modification rules included in the second preset conversion rules, so that the code in the modified JS target file conforms to the small This not only improves the conversion efficiency of the code in the JS file in the VUE component to the code in the JS target file, but also makes the granularity of the modifiable content smaller, ensuring the correctness of the code in the obtained JS target file , and ensure the corresponding relationship between the code in the JS file and the code in the JS target file, that is, the code before and after modification, so as to facilitate subsequent code maintenance and error location.
在一种可能的设计中,步骤S203可能的实现方式如图7所示。图7为本申请实施例提供的又一种小程序生成方法的流程示意图。如图7所示,本申请实施例包括:In a possible design, a possible implementation manner of step S203 is shown in FIG. 7 . FIG. 7 is a schematic flowchart of another method for generating a small program provided by the embodiment of the present application. As shown in Figure 7, the embodiment of this application includes:
S2031:利用预设异步读取工具读取WXSS临时文件,以获得WXSS临时文件内的代码。S2031: Read the WXSS temporary file by using a preset asynchronous reading tool to obtain the code in the WXSS temporary file.
利用预设异步读取工具读取WXSS临时文件的文件内容,从而获得WXSS临时文件内的代码,其中该步骤为利用预设异步读取工具读取WXSS临时文件的文件内容并将所读取到的文件内容转化为对应字符串的过程。Use the preset asynchronous reading tool to read the file content of the WXSS temporary file, so as to obtain the code in the WXSS temporary file, wherein this step is to use the preset asynchronous reading tool to read the file content of the WXSS temporary file and read it into The process of converting the content of the file into the corresponding string.
预设异步读取工具可以例如fs.readFileSync。Preset asynchronous read tools such as fs.readFileSync.
S2032:利用语法分析器解析WXSS临时文件内的代码,得到第三抽象语法树。S2032: Use the syntax analyzer to parse the code in the WXSS temporary file to obtain a third abstract syntax tree.
其中,第三抽象语法树包括对CSS文件中所有内容的描述。Wherein, the third abstract syntax tree includes a description of all content in the CSS file.
采用例如层叠样式表-树(CSSTREE)的parser解析WXSS临时文件内的代码也即解析上述步骤得到的字符串,对应得到WXSS临时文件内的代码所对应的抽象语法树,即第三抽象语法树。其中,抽象语法树(Abstract Syntax Tree,AST)是源代码的抽象语法结构的树状表示,树上的每个节点是源代码中对应节点的结构化的抽象数据。因而,第三抽象语法树对CSS文件中的每一个部分都进行了详细的定义,也即第三抽象语法树包括有对CSS文件中所有内容的描述。Use a parser such as Cascading Style Sheet-Tree (CSSTREE) to parse the code in the WXSS temporary file, that is, parse the string obtained in the above steps, and obtain the corresponding abstract syntax tree corresponding to the code in the WXSS temporary file, that is, the third abstract syntax tree . Among them, the abstract syntax tree (Abstract Syntax Tree, AST) is a tree representation of the abstract syntax structure of the source code, and each node on the tree is the structured abstract data of the corresponding node in the source code. Therefore, the third abstract syntax tree defines each part in the CSS file in detail, that is, the third abstract syntax tree includes a description of all contents in the CSS file.
S2033:根据第三预设转换规则修改第三抽象语法树,得到第三目标抽象语法树。S2033: Modify the third abstract syntax tree according to the third preset conversion rule to obtain a third target abstract syntax tree.
采用第三预设转换规则对第三抽象语法树进行修改,将修改后的第三抽象语法树确定为第三目标抽象语法树,得到第三目标抽象语法树。The third abstract syntax tree is modified by using the third preset conversion rule, and the modified third abstract syntax tree is determined as the third target abstract syntax tree to obtain the third target abstract syntax tree.
其中,根据前述实施例的描述可知,第三预设转换规则的具体内容为将WXSS临时文件内的代码修改为对应的小程序所需的代码时所遵循的对应规则。Wherein, according to the description of the foregoing embodiments, it can be seen that the specific content of the third preset conversion rule is the corresponding rule followed when modifying the code in the WXSS temporary file to the code required by the corresponding applet.
对第三抽象语法树按照第三预设转换规则进行修改后得到的抽象语法树即为第三目标抽象语法树,进而则可执行步骤S2034得到WXSS目标文件。The abstract syntax tree obtained by modifying the third abstract syntax tree according to the third preset conversion rule is the third target abstract syntax tree, and step S2034 can be executed to obtain the WXSS target file.
S2034:根据第三目标抽象语法树生成第三目标代码,并根据第三目标代码得到WXSS目标文件。S2034: Generate a third object code according to the third object abstract syntax tree, and obtain a WXSS object file according to the third object code.
将第三目标抽象语法树所表示的内容确定为第三目标代码,即根据第三目标抽象语法树生成第三目标代码,该第三目标代码所属的文件则被确定为WXSS目标文件,即根据第三目标代码得到WXSS目标文件,从而完成VUE组件中CSS文件内的代码至小程序组件文件中WXSS目标文件内代码的转换。The content represented by the third target abstract syntax tree is determined as the third target code, that is, the third target code is generated according to the third target abstract syntax tree, and the file to which the third target code belongs is determined as a WXSS target file, that is, according to The third target code obtains the WXSS target file, thereby completing the conversion of the code in the CSS file in the VUE component to the code in the WXSS target file in the applet component file.
在一种可能的设计中,步骤S2033可能的实现方式包括:In a possible design, possible implementations of step S2033 include:
遍历第三抽象语法树,根据选择器修改规则修改第三抽象语法树的目标节点,将修改后的第三抽象语法树确定为第三目标抽象语法树,从而得到第三目标抽象语法树。第三预设转换规则的具体内容为将WXSS临时文件内的代码修改为对应的小程序所需的代码时所遵循的对应规则,该对应规则具体可包括选择器修改规则。Traverse the third abstract syntax tree, modify the target node of the third abstract syntax tree according to the selector modification rule, and determine the modified third abstract syntax tree as the third target abstract syntax tree, thereby obtaining the third target abstract syntax tree. The specific content of the third preset conversion rule is the corresponding rule followed when modifying the code in the WXSS temporary file to the code required by the corresponding applet, and the corresponding rule may specifically include a selector modification rule.
在一种可能的设计中,选择器修改规则包括以下内容:In one possible design, selector modification rules include the following:
例如,将第三抽象语法树中目标选择器所声明的计量单位修改为目标计量单位,目标计量单位满足各小程序的自适应尺寸单位。比如,在VUE组件中,存在一条规则语句,通过该条规则语句得知,类型为“ClassSelector”的CSS选择器对应的值为“params-list-row”,“block”对应表示CSS选择器的值,比如该值是声明底部边距“padding-bottom”的值为10,该值的计量单位为“px”。而由于小程序使用“rpx”作为计量单位,即“rpx”为目标计量单位,其满足小程序的自适应尺寸单位,因而遍历第三抽象语法树,将第三抽象语法树中目标选择器例如类型为“Dimension”并且其声明的计量单位“px”,全部按照1:1修改为目标计量单位“rpx”。其中,第三抽象语法树中类型为“Dimension”并且其声明的计量单位为“px”的内容所属的节点即为第三抽象语法树的目标节点。For example, the unit of measurement declared by the target selector in the third abstract syntax tree is modified to the target unit of measurement, and the target unit of measurement satisfies the adaptive size unit of each applet. For example, in the VUE component, there is a rule statement. Through this rule statement, it is known that the value corresponding to the CSS selector of type "ClassSelector" is "params-list-row", and "block" corresponds to the value of the CSS selector. Value, for example, the value is to declare the value of the bottom margin "padding-bottom" is 10, and the unit of measurement of this value is "px". Since the applet uses "rpx" as the unit of measurement, that is, "rpx" is the target unit of measurement, which satisfies the adaptive size unit of the applet, so the third abstract syntax tree is traversed, and the target selector in the third abstract syntax tree such as The type is "Dimension" and the declared measurement unit "px" is all modified to the target measurement unit "rpx" according to 1:1. Wherein, the node in the third abstract syntax tree whose type is "Dimension" and whose declared measurement unit is "px" belongs to is the target node of the third abstract syntax tree.
另外,选择器修改规则还包括利用日志记录有限选择器。对于小程序而言,其支持的选择器有限,如果遍历第三抽象语法树发现其包括有小程序不支持的选择器,则需要利用日志记录这些小程序不支持的选择器,这些小程序不支持的选择器即为有限选择器,换言之,有限选择器可以为第三抽象语法树中小程序不支持的任意选择器。In addition, selector modification rules also include logging limited selectors. For applets, the selectors supported by them are limited. If you traverse the third abstract syntax tree and find that there are selectors that are not supported by applets, you need to use logs to record the selectors that these applets do not support. These applets do not support The supported selectors are limited selectors. In other words, the limited selectors can be any selectors not supported by the applet in the third abstract syntax tree.
当前小程序支持的选择器有类选择器(Class Selector)、ID选择器(Id Selector)、元素选择器(Type Selector)、伪元素选择器(Pseudo Element Selector)。The selectors currently supported by the applet include Class Selector, ID Selector, Type Selector, Pseudo-element Selector Element Selector).
其中,日志记录是为了提示开发者小程序中使用了其当前不支持的样式规则,但可以正常编译,只是在小程序中没有对应效果而已。例如“input[type=textarea]”是属性选择器(AttributeSelector),其在小程序中没有效果,但仍然被正常编译,在生成WXSS目标文件中利用日志记录的方式提示开发者。Among them, the log record is to remind the developer that a style rule that is not currently supported is used in the applet, but it can be compiled normally, but there is no corresponding effect in the applet. For example, "input[type=textarea]" is an attribute selector (AttributeSelector), which has no effect in the applet, but it is still compiled normally, and the developer is prompted by logging when generating the WXSS target file.
本申请实施例提供的小程序生成方法中,按照第三预设转换规则对WXSS临时文件内的代码进行转换得到WXSS目标文件,WXSS目标文件内的代码则用于表征小程序组件中WXSS组件样式。其中,通过遍历第三抽象语法树以及根据第三预设转换规则所包括的选择器修改规则对第三抽象语法树的目标节点进行修改,以使得的修改后得到的WXSS目标文件内的代码符合小程序的运行要求,从而不但提高VUE组件中CSS文件内的代码至WXSS目标文件内代码的转换效率,还使得可修改的内容颗粒度更小,保障了所得到的WXSS目标文件内代码的正确性,并且保证CSS文件内代码与WXSS目标文件内代码也即修改前后代码之间的对应关系,便于后续的代码维护和错误定位。In the applet generation method provided by the embodiment of the present application, the code in the WXSS temporary file is converted according to the third preset conversion rule to obtain the WXSS target file, and the code in the WXSS target file is used to represent the WXSS component style in the applet component . Wherein, the target node of the third abstract syntax tree is modified by traversing the third abstract syntax tree and according to the selector modification rules included in the third preset transformation rules, so that the codes in the modified WXSS target file conform to Mini-program operation requirements, which not only improves the conversion efficiency of the code in the CSS file in the VUE component to the code in the WXSS target file, but also makes the granularity of the modifiable content smaller, ensuring the correctness of the code in the obtained WXSS target file , and ensure the corresponding relationship between the code in the CSS file and the code in the WXSS target file, that is, the code before and after modification, which is convenient for subsequent code maintenance and error location.
图8为本申请实施例提供的一种小程序生成装置的结构示意图。如图8所示,本申请实施例提供的小程序生成装置300,包括:FIG. 8 is a schematic structural diagram of an apparatus for generating a small program provided by an embodiment of the present application. As shown in FIG. 8 , the applet generation device 300 provided in the embodiment of the present application includes:
获取模块301,用于利用预设异步读取工具读取VUE组件,得到VUE组件中的各组件文件,各组件文件包括页面文件、JS文件以及层叠样式表CSS文件。The obtaining module 301 is used to read the VUE component by using a preset asynchronous reading tool to obtain each component file in the VUE component, and each component file includes a page file, a JS file and a cascading style sheet CSS file.
存储模块302,用于将各组件文件内的代码分别对应存储至各临时文件,各临时文件包括微信标记语言WXML临时文件、JS临时文件以及微信层叠样式表WXSS临时文件。The storage module 302 is used to store the codes in each component file correspondingly to each temporary file, and each temporary file includes a WeChat markup language WXML temporary file, a JS temporary file and a WeChat Cascading Style Sheet WXSS temporary file.
处理模块303,用于根据预设转换策略对每个临时文件内的代码进行转换,对应得到各小程序组件文件,以根据各小程序组件文件生成小程序。预设转换策略包括遍历每个抽象语法树的每个节点以修改每个抽象语法树的目标节点,每个抽象语法树为每个临时文件内的代码对应形成。The processing module 303 is configured to convert the code in each temporary file according to a preset conversion strategy to obtain corresponding applet component files, so as to generate applets according to each applet component file. The preset conversion strategy includes traversing each node of each abstract syntax tree to modify the target node of each abstract syntax tree, and each abstract syntax tree is correspondingly formed for the code in each temporary file.
在一种可能的设计中,图9为本申请实施例提供的一种处理模块的结构示意图。如图9所示,本申请实施例提供的小程序生成装置300中的处理模块303,包括:In a possible design, FIG. 9 is a schematic structural diagram of a processing module provided in an embodiment of the present application. As shown in FIG. 9, the processing module 303 in the applet generating device 300 provided by the embodiment of the present application includes:
第一处理子模块3031,用于按照第一预设转换规则对WXML临时文件内的代码进行转换,生成WXML目标文件;The first processing sub-module 3031 is configured to convert the code in the WXML temporary file according to the first preset conversion rule to generate a WXML target file;
第二处理子模块3032,用于按照第二预设转换规则对JS临时文件内的代码进行转换,生成JS目标文件;The second processing sub-module 3032 is used to convert the code in the JS temporary file according to the second preset conversion rule to generate the JS target file;
第三处理子模块3033,用于按照第三预设转换规则对WXSS临时文件内的代码进行转换,生成WXSS目标文件。The third processing sub-module 3033 is configured to convert the code in the WXSS temporary file according to the third preset conversion rule to generate a WXSS target file.
其中,预设转换策略包括第一预设转换规则、第二预设转换规则以及第三预设转换规则,各小程序组件文件包括WXML目标文件、JS目标文件以及WXSS目标文件。Wherein, the preset conversion strategy includes a first preset conversion rule, a second preset conversion rule, and a third preset conversion rule, and each applet component file includes a WXML object file, a JS object file, and a WXSS object file.
在一种可能的设计中,第一处理子模块3031,具体用于:In a possible design, the first processing submodule 3031 is specifically used for:
利用预设异步读取工具读取WXML临时文件,以获得WXSS临时文件内的代码;Use the preset asynchronous reading tool to read the WXML temporary file to obtain the code in the WXSS temporary file;
利用页面解析器解析WXML临时文件内的代码,得到第一抽象语法树,第一抽象语法树包括对页面文件中所有内容的描述;Utilize the page parser to parse the code in the WXML temporary file to obtain a first abstract syntax tree, and the first abstract syntax tree includes a description of all contents in the page file;
根据第一预设转换规则修改第一抽象语法树,得到第一目标抽象语法树;Modifying the first abstract syntax tree according to the first preset conversion rule to obtain the first target abstract syntax tree;
根据第一目标抽象语法树生成第一目标代码,并根据第一目标代码得到WXML目标文件。The first object code is generated according to the first object abstract syntax tree, and the WXML object file is obtained according to the first object code.
在一种可能的设计中,第一处理子模块3031,还具体用于: In a possible design, the first processing submodule 3031 is also specifically used for:
遍历第一抽象语法树,获得表单标签,并根据预设标签映射表替换表单标签中的标签内容;Traversing the first abstract syntax tree, obtaining the form label, and replacing the label content in the form label according to the preset label mapping table;
根据格式修改规则修改第一抽象语法树的目标节点;modifying the target node of the first abstract syntax tree according to the format modification rule;
将经过预设标签映射表替换以及格式修改规则修改的第一抽象语法树确定为第一目标抽象语法树;Determining the first abstract syntax tree modified by the preset label mapping table and the format modification rule as the first target abstract syntax tree;
其中,第一预设转换规则包括预设标签映射表和格式修改规则。Wherein, the first preset conversion rule includes a preset tag mapping table and a format modification rule.
在一种可能的设计中,格式修改规则包括:In one possible design, format modification rules include:
将第一抽象语法树中的列渲染格式修改为小程序列表渲染格式;Modify the column rendering format in the first abstract syntax tree to the applet list rendering format;
将第一抽象语法树中的条件渲染格式修改为小程序条件渲染格式;Modify the conditional rendering format in the first abstract syntax tree to the applet conditional rendering format;
将第一抽象语法树中的事件绑定格式修改为小程序事件绑定格式。Modify the event binding format in the first abstract syntax tree to the applet event binding format.
在一种可能的设计中,第二处理子模块3032,具体用于:In a possible design, the second processing submodule 3032 is specifically used for:
利用预设异步读取工具读取JS临时文件,以获得JS临时文件内的代码;Use the preset asynchronous reading tool to read the JS temporary file to obtain the code in the JS temporary file;
利用解析插件解析JS临时文件内的代码,得到第二抽象语法树,第二抽象语法树包括对JS文件中所有内容的描述;Parse the code in the JS temporary file by using the parsing plug-in to obtain a second abstract syntax tree, and the second abstract syntax tree includes a description of all contents in the JS file;
根据第二预设转换规则修改第二抽象语法树,得到第二目标抽象语法树;Modifying the second abstract syntax tree according to the second preset conversion rule to obtain the second target abstract syntax tree;
根据第二目标抽象语法树生成第二目标代码,并根据第二目标代码得到JS目标文件。A second object code is generated according to the second object abstract syntax tree, and a JS object file is obtained according to the second object code.
在一种可能的设计中,第二处理子模块3032,还具体用于:In a possible design, the second processing submodule 3032 is also specifically used for:
遍历第二抽象语法树,根据属性修改规则修改第二抽象语法树的目标节点,得到第二目标抽象语法树,第二预设转换规则包括属性修改规则。The second abstract syntax tree is traversed, and the target node of the second abstract syntax tree is modified according to the attribute modification rules to obtain the second target abstract syntax tree. The second preset conversion rules include attribute modification rules.
在一种可能的设计中,属性修改规则包括:In one possible design, attribute modification rules include:
获取返回函数的属性和值,利用返回函数的属性和值替换返回函数的返回数据,以修改第二抽象语法树中data属性的定义,返回函数的返回数据为修改前第二抽象语法树中data属性的定义;Obtain the attributes and values of the returned function, and use the attributes and values of the returned function to replace the returned data of the returned function to modify the definition of the data attribute in the second abstract syntax tree. The returned data of the returned function is the data in the second abstract syntax tree before modification property definition;
将第二抽象语法树中的props属性定义以及对应默认属性值的定义方式分别修改为目标属性定义和目标定义方式,目标属性定义和目标定义方式满足小程序的属性定义要求;modifying the props attribute definition in the second abstract syntax tree and the definition method of the corresponding default attribute value to the target attribute definition and the target definition method respectively, and the target attribute definition and the target definition method meet the property definition requirements of the applet;
将第二抽象语法树的数据读取方式修改为目标读取方式,目标读取方式满足小程序的生命周期钩子函数;Modify the data reading method of the second abstract syntax tree to the target reading method, and the target reading method satisfies the life cycle hook function of the applet;
将第二抽象语法树中的赋值表达式修改为小程序执行函数方式。The assignment expression in the second abstract syntax tree is modified to the way of executing the function of the applet.
在一种可能的设计中,第三处理子模块3033,具体用于:In a possible design, the third processing submodule 3033 is specifically used for:
利用预设异步读取工具读取WXSS临时文件,以获得WXSS临时文件内的代码;Use the preset asynchronous reading tool to read the WXSS temporary file to obtain the code in the WXSS temporary file;
利用语法分析器解析WXSS临时文件内的代码,得到第三抽象语法树,第三抽象语法树包括对CSS标签中所有内容的描述;Parse the code in the WXSS temporary file with a syntax analyzer to obtain a third abstract syntax tree, where the third abstract syntax tree includes a description of all content in the CSS tag;
根据第三预设转换规则遍历并修改第三抽象语法树,得到第三目标抽象语法树;Traversing and modifying the third abstract syntax tree according to the third preset conversion rule to obtain the third target abstract syntax tree;
根据第三目标抽象语法树生成第三目标代码,并根据第三目标代码得到WXSS目标文件。A third object code is generated according to the third object abstract syntax tree, and a WXSS object file is obtained according to the third object code.
在一种可能的设计中,第三处理子模块3033,还具体用于:In a possible design, the third processing submodule 3033 is also specifically used for:
遍历第三抽象语法树,根据选择器修改规则修改第三抽象语法树,得到第三目标抽象语法树,第三预设转换规则包括选择器修改规则。The third abstract syntax tree is traversed, and the third abstract syntax tree is modified according to the selector modification rule to obtain a third target abstract syntax tree. The third preset conversion rule includes the selector modification rule.
在一种可能的设计中,选择器修改规则,包括:In one possible design, selectors modify rules, including:
将第三抽象语法树中目标选择器所声明的计量单位修改为目标计量单位,目标计量单位满足小程序的自适应尺寸单位;Modify the unit of measurement declared by the target selector in the third abstract syntax tree to the target unit of measurement, and the target unit of measurement satisfies the adaptive size unit of the applet;
利用日志记录有限选择器,有限选择器为第三抽象语法树中小程序不支持的任意选择器。A log record limited selector is used, and the limited selector is any selector not supported by the applet in the third abstract syntax tree.
在一种可能的设计中,小程序生成装置300,还包括:第四处理子模块。该第四处理子模块,用于:In a possible design, the applet generating apparatus 300 further includes: a fourth processing submodule. The fourth processing submodule is used for:
根据JS目标文件内的代码生成信息文件,信息文件用于记录各小程序组件文件的代码在VUE组件的代码中的位置信息。The information file is generated according to the code in the JS target file, and the information file is used to record the position information of the code of each applet component file in the code of the VUE component.
在一种可能的设计中,小程序生成装置300,还包括:第五处理子模块。该第五处理子模块,用于: In a possible design, the applet generating apparatus 300 further includes: a fifth processing submodule. The fifth processing submodule is used for:
根据组件生成需求生成工作指令,响应于工作指令运行命令行工具,命令行工具用于启用小程序生成方法。A work order is generated based on the component generation requirements, a command line tool is run in response to the work order, the command line tool is used to enable the applet generation method.
值得说明的,上述图8和图9以及可选的实施例提供的小程序生成装置,可用于执行上述任一实施例提供的小程序生成方法的各步骤,具体实现方式和技术效果类似,这里不再赘述。It is worth noting that the above-mentioned Figures 8 and 9 and the applet generation device provided by the optional embodiment can be used to execute the steps of the applet generation method provided by any of the above-mentioned embodiments. The specific implementation method and technical effect are similar. Here No longer.
本申请所提供的上述各装置实施例仅仅是示意性的,其中的模块划分仅仅是一种逻辑功能划分,实际实现时可以有另外的划分方式。例如多个模块可以结合或者可以集成到另一个系统。各个模块相互之间的耦合可以是通过一些接口实现,这些接口通常是电性通信接口,但是也不排除可能是机械接口或其它的形式接口。因此,作为分离部件说明的模块可以是或者也可以不是物理上分开的,既可以位于一个地方,也可以分布到同一个或不同设备的不同位置上。The above-mentioned device embodiments provided in the present application are only illustrative, and the module division therein is only a logical function division, and there may be other division methods in actual implementation. For example several modules may be combined or may be integrated into another system. The mutual coupling of various modules can be realized through some interfaces, and these interfaces are usually electrical communication interfaces, but it is not excluded that they may be mechanical interfaces or other forms of interfaces. Thus, modules described as separate components may or may not be physically separate, and may be located at one location or distributed to different locations on the same or different devices.
图10为本申请提供的一种电子设备的结构示意图。如图10所示,该电子设备400可以包括:至少一个处理器401和存储器402。图10示出的是以一个处理器为例的电子设备。FIG. 10 is a schematic structural diagram of an electronic device provided by the present application. As shown in FIG. 10 , the electronic device 400 may include: at least one processor 401 and a memory 402 . FIG. 10 shows an electronic device using a processor as an example.
存储器402,用于存放处理器401的计算机程序。具体地,程序可以包括程序代码,程序代码包括计算机操作指令。存储器402可能包含高速RAM存储器,也可能还包括非易失性存储器(non-volatile memory),例如至少一个磁盘存储器。The memory 402 is used for storing computer programs of the processor 401 . Specifically, the program may include program code, and the program code includes computer operation instructions. The memory 402 may include a high-speed RAM memory, and may also include a non-volatile memory (non-volatile memory), such as at least one disk storage.
处理器401配置为用于执行存储器402存储的计算机程序,以实现以上各方法实施例中小程序生成方法的各步骤。The processor 401 is configured to execute the computer program stored in the memory 402, so as to realize each step of the applet generating method in each method embodiment above.
其中,处理器401可能是一个中央处理器(central processing unit,简称为CPU),或者是特定集成电路(application specific integrated circuit,简称为ASIC),或者是被配置成实施本申请实施例的一个或多个集成电路。Wherein, processor 401 may be a central processing unit (central processing unit, referred to as CPU), or a specific integrated circuit (application specific integrated circuit, referred to as ASIC), or one or more integrated circuits configured to implement the embodiments of the present application.
可选地,存储器402既可以是独立的,也可以跟处理器401集成在一起。当存储器402是独立于处理器401之外的器件时,电子设备400,还可以包括:Optionally, the memory 402 can be independent or integrated with the processor 401 . When the memory 402 is a device independent of the processor 401, the electronic device 400 may further include:
总线403,用于连接处理器401以及存储器402。总线可以是工业标准体系结构(industry standard architecture,简称为ISA)总线、外部设备互连(peripheral component, PCI)总线或扩展工业标准体系结构(extended industry standard architecture, EISA)总线等。总线可以分为地址总线、数据总线、控制总线等,但并不表示仅有一根总线或一种类型的总线。The bus 403 is used to connect the processor 401 and the memory 402 . The bus can be an industry standard architecture (industry standard architecture (ISA) bus, peripheral component interconnect (PCI) bus or extended industry standard architecture (EISA) bus, etc. The bus can be divided into address bus, data bus, control bus, etc., but it does not mean that there is only one bus or one type of bus.
可选的,在具体实现上,如果存储器402和处理器401集成在一块芯片上实现,则存储器402和处理器401可以通过内部接口完成通信。Optionally, in terms of specific implementation, if the memory 402 and the processor 401 are integrated and implemented on one chip, the memory 402 and the processor 401 may communicate through an internal interface.
本申请还提供了一种计算机可读存储介质,该计算机可读存储介质可以包括:U盘、移动硬盘、只读存储器(read-only memory ,ROM)、随机存取存储器(random access memory,RAM)、磁盘或者光盘等各种可以存储程序代码的介质,具体的,该计算机可读存储介质中存储有计算机程序,当电子设备的至少一个处理器执行该计算机程序时,电子设备执行上述的各种实施方式提供的小程序生成方法的各个步骤。The present application also provides a computer-readable storage medium, which may include: U disk, mobile hard disk, read-only memory (read-only memory, ROM), random access memory (random access memory, RAM) ), a magnetic disk or an optical disk, and other media that can store program codes. Specifically, the computer-readable storage medium stores a computer program. When at least one processor of the electronic device executes the computer program, the electronic device executes the above-mentioned Each step of the applet generating method provided in the above implementation manner.
本申请实施例还提供一种计算机程序产品,该计算机程序产品包括计算机程序,该计算机程序存储在可读存储介质中。电子设备的至少一个处理器可以从可读存储介质读取该计算机程序,至少一个处理器执行该计算机程序使得电子设备实施上述的各种实施方式提供的小程序生成方法的各个步骤。An embodiment of the present application further provides a computer program product, where the computer program product includes a computer program, and the computer program is stored in a readable storage medium. At least one processor of the electronic device can read the computer program from the readable storage medium, and the at least one processor executes the computer program so that the electronic device implements each step of the applet generating method provided in the above-mentioned various embodiments.
本领域技术人员在考虑说明书及实践这里公开的发明后,将容易想到本申请的其它实施方案。本申请旨在涵盖本申请的任何变型、用途或者适应性变化,这些变型、用途或者适应性变化遵循本申请的一般性原理并包括本申请未公开的本技术领域中的公知常识或惯用技术手段。说明书和实施例仅被视为示例性的,本申请的真正范围和精神由权利要求书指出。应当理解的是,本申请并不局限于上面已经描述并在附图中示出的精确结构,并且可以在不脱离其范围进行各种修改和改变。本申请的范围仅由所附的权利要求书来限制。Other embodiments of the present application will be readily apparent to those skilled in the art from consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any modification, use or adaptation of the application, these modifications, uses or adaptations follow the general principles of the application and include common knowledge or conventional technical means in the technical field not disclosed in the application . The specification and examples are to be considered exemplary only, with a true scope and spirit of the application indicated by the appended claims. It should be understood that the present application is not limited to the precise constructions which have been described above and shown in the accompanying drawings, and various modifications and changes may be made without departing from the scope thereof. The scope of the application is limited only by the appended claims.

Claims (17)

  1. 一种小程序生成方法,其特征在于,包括:A small program generation method, characterized by comprising:
    利用预设异步读取工具读取VUE组件,得到所述VUE组件中的各组件文件,所述各组件文件包括页面文件、JS文件以及层叠样式表CSS文件;Utilize preset asynchronous reading tool to read VUE component, obtain each component file in described VUE component, described each component file comprises page file, JS file and cascading style sheet CSS file;
    将所述各组件文件内的代码分别对应存储至各临时文件,所述各临时文件包括微信标记语言WXML临时文件、JS临时文件以及微信层叠样式表WXSS临时文件;The codes in each of the component files are correspondingly stored in each temporary file respectively, and each of the temporary files includes a Wechat markup language WXML temporary file, a JS temporary file and a Wechat Cascading Style Sheet WXSS temporary file;
    根据预设转换策略对每个临时文件内的代码进行转换,对应得到各小程序组件文件,以根据所述各小程序组件文件生成小程序,所述预设转换策略包括遍历每个抽象语法树的每个节点以修改所述每个抽象语法树的目标节点,所述每个抽象语法树为所述每个临时文件内的代码对应形成。Convert the code in each temporary file according to a preset conversion strategy to obtain corresponding applet component files to generate applets according to the applet component files. The preset conversion strategy includes traversing each abstract syntax tree Each node of each node is modified to modify the target node of each abstract syntax tree, and each abstract syntax tree is correspondingly formed for the code in each temporary file.
  2. 根据权利要求1所述的小程序生成方法,其特征在于,所述根据预设转换策略对每个临时文件内的代码进行转换,对应得到各小程序组件文件,包括:The applet generation method according to claim 1, characterized in that, converting the code in each temporary file according to a preset conversion strategy to obtain corresponding applet component files, including:
    按照第一预设转换规则对所述WXML临时文件内的代码进行转换,生成WXML目标文件;converting the code in the WXML temporary file according to a first preset conversion rule to generate a WXML target file;
    按照第二预设转换规则对所述JS临时文件内的代码进行转换,生成JS目标文件;converting the code in the JS temporary file according to the second preset conversion rule to generate the JS target file;
    按照第三预设转换规则对所述WXSS临时文件内的代码进行转换,生成WXSS目标文件;converting the code in the WXSS temporary file according to a third preset conversion rule to generate a WXSS target file;
    其中,所述预设转换策略包括所述第一预设转换规则、所述第二预设转换规则以及所述第三预设转换规则,所述各小程序组件文件包括所述WXML目标文件、所述JS目标文件以及所述WXSS目标文件。Wherein, the preset conversion policy includes the first preset conversion rule, the second preset conversion rule, and the third preset conversion rule, and the applet component files include the WXML target file, The JS target file and the WXSS target file.
  3. 根据权利要求2所述的小程序生成方法,其特征在于,所述按照第一预设转换规则对所述WXML临时文件内的代码进行转换,生成WXML目标文件,包括:The applet generating method according to claim 2, wherein said converting the code in said WXML temporary file according to a first preset conversion rule to generate a WXML target file includes:
    利用所述预设异步读取工具读取所述WXML临时文件,以获得所述WXSS临时文件内的代码;Using the preset asynchronous reading tool to read the WXML temporary file to obtain the code in the WXSS temporary file;
    利用页面解析器解析所述WXML临时文件内的代码,得到第一抽象语法树,所述第一抽象语法树包括对所述页面文件中所有内容的描述;Using a page parser to parse the code in the WXML temporary file to obtain a first abstract syntax tree, the first abstract syntax tree including a description of all content in the page file;
    根据所述第一预设转换规则修改所述第一抽象语法树,得到第一目标抽象语法树;Modifying the first abstract syntax tree according to the first preset conversion rule to obtain a first target abstract syntax tree;
    根据所述第一目标抽象语法树生成第一目标代码,并根据所述第一目标代码得到所述WXML目标文件。Generate a first object code according to the first object abstract syntax tree, and obtain the WXML object file according to the first object code.
  4. 根据权利要求3所述的小程序生成方法,其特征在于,所述根据所述第一预设转换规则修改所述第一抽象语法树,得到第一目标抽象语法树,包括:The applet generating method according to claim 3, wherein said modifying said first abstract syntax tree according to said first preset conversion rule to obtain a first target abstract syntax tree comprises:
    遍历所述第一抽象语法树,获得表单标签,并根据预设标签映射表替换所述表单标签中的标签内容;Traversing the first abstract syntax tree to obtain a form tag, and replacing the tag content in the form tag according to a preset tag mapping table;
    根据格式修改规则修改所述第一抽象语法树的目标节点;modifying the target node of the first abstract syntax tree according to a format modification rule;
    将经过所述预设标签映射表替换以及所述格式修改规则修改的第一抽象语法树确定为所述第一目标抽象语法树;determining the first abstract syntax tree that has been replaced by the preset label mapping table and modified by the format modification rule as the first target abstract syntax tree;
    其中,所述第一预设转换规则包括所述预设标签映射表和所述格式修改规则。Wherein, the first preset conversion rule includes the preset tag mapping table and the format modification rule.
  5. 根据权利要求4所述的小程序生成方法,其特征在于,所述格式修改规则包括:The applet generation method according to claim 4, wherein the format modification rules include:
    将所述第一抽象语法树中的列渲染格式修改为小程序列表渲染格式;modifying the column rendering format in the first abstract syntax tree to the applet list rendering format;
    将所述第一抽象语法树中的条件渲染格式修改为小程序条件渲染格式;modifying the conditional rendering format in the first abstract syntax tree to the applet conditional rendering format;
    将所述第一抽象语法树中的事件绑定格式修改为小程序事件绑定格式。The event binding format in the first abstract syntax tree is modified to the applet event binding format.
  6. 根据权利要求2-5中任一项所述的小程序生成方法,其特征在于,所述按照第二预设转换规则对所述JS临时文件内的代码进行转换,生成JS目标文件,包括:The method for generating a small program according to any one of claims 2-5, wherein the converting the code in the JS temporary file according to the second preset conversion rule to generate the JS target file includes:
    利用所述预设异步读取工具读取所述JS临时文件,以获得所述JS临时文件内的代码;Using the preset asynchronous reading tool to read the JS temporary file to obtain the code in the JS temporary file;
    利用解析插件解析所述JS临时文件内的代码,得到第二抽象语法树,所述第二抽象语法树包括对所述JS文件中所有内容的描述;Parsing the code in the JS temporary file by using the parsing plug-in to obtain a second abstract syntax tree, the second abstract syntax tree including a description of all content in the JS file;
    根据所述第二预设转换规则修改所述第二抽象语法树,得到第二目标抽象语法树;Modifying the second abstract syntax tree according to the second preset conversion rule to obtain a second target abstract syntax tree;
    根据所述第二目标抽象语法树生成第二目标代码,并根据所述第二目标代码得到所述JS目标文件。Generate a second object code according to the second object abstract syntax tree, and obtain the JS object file according to the second object code.
  7. 根据权利要求6所述的小程序生成方法,其特征在于,所述根据所述第二预设转换规则修改所述第二抽象语法树,得到第二目标抽象语法树,包括:The applet generating method according to claim 6, wherein said modifying said second abstract syntax tree according to said second preset conversion rule to obtain a second target abstract syntax tree comprises:
    遍历所述第二抽象语法树,根据属性修改规则修改所述第二抽象语法树的目标节点,得到所述第二目标抽象语法树,所述第二预设转换规则包括所述属性修改规则。Traversing the second abstract syntax tree, modifying target nodes of the second abstract syntax tree according to attribute modification rules to obtain the second target abstract syntax tree, wherein the second preset conversion rules include the attribute modification rules.
  8. 根据权利要求7所述的小程序生成方法,其特征在于,所述属性修改规则包括:The applet generating method according to claim 7, wherein the property modification rules include:
    获取返回函数的属性和值,利用所述返回函数的属性和值替换所述返回函数的返回数据,以修改所述第二抽象语法树中data属性的定义,所述返回函数的返回数据为修改前所述第二抽象语法树中data属性的定义;Obtain the attributes and values of the return function, and use the attributes and values of the return function to replace the return data of the return function to modify the definition of the data attribute in the second abstract syntax tree, and the return data of the return function is modified The definition of the data attribute in the aforementioned second abstract syntax tree;
    将所述第二抽象语法树中的props属性定义以及对应默认属性值的定义方式分别修改为目标属性定义和目标定义方式,所述目标属性定义和所述目标定义方式满足所述小程序的属性定义要求;modifying the definition of the props attribute in the second abstract syntax tree and the definition of the corresponding default attribute value to the definition of the target attribute and the definition of the target, the definition of the target attribute and the definition of the target meet the attributes of the applet define requirements;
    将所述第二抽象语法树的数据读取方式修改为目标读取方式,所述目标读取方式满足所述小程序的生命周期钩子函数;modifying the data reading mode of the second abstract syntax tree to a target reading mode, and the target reading mode satisfies the life cycle hook function of the applet;
    将所述第二抽象语法树中的赋值表达式修改为小程序执行函数方式。Modifying the assignment expression in the second abstract syntax tree to the mode of executing the function of the applet.
  9. 根据权利要求2-8中任一项所述的小程序生成方法,其特征在于,所述按照第三预设转换规则对所述WXSS临时文件内的代码进行转换,生成WXSS目标文件,包括:The method for generating a small program according to any one of claims 2-8, wherein said converting the code in said WXSS temporary file according to a third preset conversion rule to generate a WXSS target file includes:
    利用所述预设异步读取工具读取所述WXSS临时文件,以获得所述WXSS临时文件内的代码;Using the preset asynchronous reading tool to read the WXSS temporary file to obtain the code in the WXSS temporary file;
    利用语法分析器解析所述WXSS临时文件内的代码,得到第三抽象语法树,所述第三抽象语法树包括对所述CSS标签中所有内容的描述;Using a syntax analyzer to parse the code in the WXSS temporary file to obtain a third abstract syntax tree, the third abstract syntax tree includes a description of all content in the CSS tag;
    根据所述第三预设转换规则遍历并修改所述第三抽象语法树,得到第三目标抽象语法树;Traversing and modifying the third abstract syntax tree according to the third preset conversion rule to obtain a third target abstract syntax tree;
    根据所述第三目标抽象语法树生成第三目标代码,并根据所述第三目标代码得到所述WXSS目标文件。Generate a third object code according to the third object abstract syntax tree, and obtain the WXSS object file according to the third object code.
  10. 根据权利要求9所述的小程序生成方法,其特征在于,所述根据所述第三预设转换规则遍历并修改所述第三抽象语法树,得到第三目标抽象语法树,包括:The applet generating method according to claim 9, wherein the step of traversing and modifying the third abstract syntax tree according to the third preset conversion rule to obtain a third target abstract syntax tree includes:
    遍历所述第三抽象语法树,根据选择器修改规则修改所述第三抽象语法树,得到所述第三目标抽象语法树,所述第三预设转换规则包括所述选择器修改规则。The third abstract syntax tree is traversed, and the third abstract syntax tree is modified according to the selector modification rule to obtain the third target abstract syntax tree, and the third preset conversion rule includes the selector modification rule.
  11. 根据权利要求10所述的小程序生成方法,其特征在于,所述选择器修改规则,包括:The applet generation method according to claim 10, wherein the selector modification rule includes:
    将所述第三抽象语法树中目标选择器所声明的计量单位修改为目标计量单位,所述目标计量单位满足所述小程序的自适应尺寸单位;modifying the unit of measure declared by the target selector in the third abstract syntax tree to a target unit of measure, the target unit of measure meeting the self-adaptive size unit of the applet;
    利用日志记录有限选择器,所述有限选择器为所述第三抽象语法树中所述小程序不支持的任意选择器。Logging is used to record limited selectors, the limited selectors being any selectors not supported by the applet in the third abstract syntax tree.
  12. 根据权利要求2-11中任一项所述的小程序生成方法,其特征在于,在所述得到各小程序组件文件之后,还包括:The applet generating method according to any one of claims 2-11, characterized in that, after obtaining each applet component file, further comprising:
    根据JS目标文件内的代码生成信息文件,所述信息文件用于记录所述各小程序组件文件的代码在所述VUE组件的代码中的位置信息。The information file is generated according to the code in the JS target file, and the information file is used to record the position information of the code of each applet component file in the code of the VUE component.
  13. 根据权利要求1-12任一项所述的小程序生成方法,其特征在于,在所述利用预设异步读取工具读取VUE组件之前,还包括:The applet generating method according to any one of claims 1-12, characterized in that, before reading the VUE component with a preset asynchronous reading tool, it further includes:
    根据组件生成需求生成工作指令,响应于所述工作指令运行命令行工具,所述命令行工具用于启用所述小程序生成方法。A work order is generated according to the component generation requirement, and a command line tool is executed in response to the work order, and the command line tool is used to enable the applet generation method.
  14. 一种小程序生成装置,其特征在于,包括:A small program generating device is characterized in that it includes:
    获取模块,用于利用预设异步读取工具读取VUE组件,得到所述VUE组件中的各组件文件,所述各组件文件包括页面文件、JS文件以及层叠样式表CSS文件;The acquisition module is used to read the VUE component using a preset asynchronous reading tool to obtain each component file in the VUE component, and each component file includes a page file, a JS file and a cascading style sheet CSS file;
    存储模块,用于将所述各组件文件内的代码分别对应存储至各临时文件,所述各临时文件包括微信标记语言WXML临时文件、JS临时文件以及微信层叠样式表WXSS临时文件;The storage module is used to store the codes in each of the component files correspondingly to each temporary file respectively, and each of the temporary files includes a Wechat markup language WXML temporary file, a JS temporary file and a Wechat Cascading Style Sheet WXSS temporary file;
    处理模块,用于根据预设转换策略对每个临时文件内的代码进行转换,对应得到各小程序组件文件,以根据所述各小程序组件文件生成小程序,所述预设转换策略包括遍历每个抽象语法树的每个节点以修改所述每个抽象语法树的目标节点,所述每个抽象语法树为所述每个临时文件内的代码对应形成。A processing module, configured to convert the code in each temporary file according to a preset conversion strategy to obtain corresponding applet component files, so as to generate applets according to the applet component files, and the preset conversion strategy includes traversing Each node of each abstract syntax tree is used to modify the target node of each abstract syntax tree, and each abstract syntax tree is correspondingly formed for the code in each temporary file.
  15. 一种电子设备,其特征在于,包括:An electronic device, characterized in that it comprises:
    处理器;以及,Processor; and,
    存储器,用于存储所述处理器的计算机程序;a memory for storing the computer program of the processor;
    其中,所述处理器配置为经由执行所述计算机程序来实现权利要求1至13任一项所述的小程序生成方法。Wherein, the processor is configured to implement the applet generating method according to any one of claims 1 to 13 by executing the computer program.
  16. 一种计算机可读存储介质,其上存储有计算机程序,其特征在于,所述计算机程序被处理器执行时实现权利要求1至13任一项所述的小程序生成方法。A computer-readable storage medium, on which a computer program is stored, wherein, when the computer program is executed by a processor, the method for generating a small program according to any one of claims 1 to 13 is realized.
  17. 一种计算机程序产品,包括计算机程序,其特征在于,该计算机程序被处理器执行时实现权利要求1至13任一项所述的小程序生成方法。A computer program product, comprising a computer program, characterized in that, when the computer program is executed by a processor, the applet generation method described in any one of claims 1 to 13 is realized.
PCT/CN2022/102158 2021-11-16 2022-06-29 Applet generation method and apparatus, device and storage medium WO2023087720A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202111358314.5A CN114064003A (en) 2021-11-16 2021-11-16 Applet generation method, apparatus, device and storage medium
CN202111358314.5 2021-11-16

Publications (1)

Publication Number Publication Date
WO2023087720A1 true WO2023087720A1 (en) 2023-05-25

Family

ID=80272822

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/102158 WO2023087720A1 (en) 2021-11-16 2022-06-29 Applet generation method and apparatus, device and storage medium

Country Status (2)

Country Link
CN (1) CN114064003A (en)
WO (1) WO2023087720A1 (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114064003A (en) * 2021-11-16 2022-02-18 深圳前海微众银行股份有限公司 Applet generation method, apparatus, device and storage medium
CN116954571B (en) * 2023-09-21 2023-12-22 深圳凡泰极客科技有限责任公司 Development processing method and device for applet plug-in and computer readable storage medium

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140282444A1 (en) * 2013-03-15 2014-09-18 ArtinSoft Corporation Programming language transformations with abstract syntax tree extensions
CN108268262A (en) * 2017-12-27 2018-07-10 广东耐思尼克信息技术有限公司 Realize the method, apparatus and system that HTML is converted to wechat small routine
CN108664248A (en) * 2018-05-14 2018-10-16 北京汉能光伏投资有限公司 A kind of generation method and device of wechat small routine
CN110333863A (en) * 2019-06-17 2019-10-15 无线生活(杭州)信息科技有限公司 A kind of method and device for generating, showing the small routine page
CN110888645A (en) * 2019-10-12 2020-03-17 贝壳技术有限公司 Method, device and storage medium for converting into small program
CN114064003A (en) * 2021-11-16 2022-02-18 深圳前海微众银行股份有限公司 Applet generation method, apparatus, device and storage medium

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140282444A1 (en) * 2013-03-15 2014-09-18 ArtinSoft Corporation Programming language transformations with abstract syntax tree extensions
CN108268262A (en) * 2017-12-27 2018-07-10 广东耐思尼克信息技术有限公司 Realize the method, apparatus and system that HTML is converted to wechat small routine
CN108664248A (en) * 2018-05-14 2018-10-16 北京汉能光伏投资有限公司 A kind of generation method and device of wechat small routine
CN110333863A (en) * 2019-06-17 2019-10-15 无线生活(杭州)信息科技有限公司 A kind of method and device for generating, showing the small routine page
CN110888645A (en) * 2019-10-12 2020-03-17 贝壳技术有限公司 Method, device and storage medium for converting into small program
CN114064003A (en) * 2021-11-16 2022-02-18 深圳前海微众银行股份有限公司 Applet generation method, apparatus, device and storage medium

Also Published As

Publication number Publication date
CN114064003A (en) 2022-02-18

Similar Documents

Publication Publication Date Title
US7962904B2 (en) Dynamic parser
Javanbakht et al. Advanced finite element simulation with MSC Marc
WO2023087720A1 (en) Applet generation method and apparatus, device and storage medium
US8898651B2 (en) Automatic generation of instruction-set documentation
CN106412086B (en) Method and system for automatically generating communication code by using protocol description file
US10592220B2 (en) Metadata-driven binding of converted source code to original source code
JP2020522790A (en) Automatic dependency analyzer for heterogeneously programmed data processing systems
TWI536263B (en) Projecting native application programming interfaces of an operating system into other programming languages
JPS6375835A (en) Apparatus for generating intended code, program, list and design document
CN113641701B (en) Data query method, system, heterogeneous acceleration platform and storage medium
JP4638484B2 (en) Data integrity in data processing equipment
CN110554875B (en) Code conversion method and device, electronic equipment and storage medium
CN116627429B (en) Assembly code generation method and device, electronic equipment and storage medium
van Beusekom et al. Formalising the Dezyne modelling language in mCRL2
Fritzson et al. Towards Modelica 4 meta-programming and language modeling with MetaModelica 2.0
WO2023123111A1 (en) Compiling method and compiling apparatus
WO2021208867A1 (en) Cross-platform code conversion method and device
CN110737431B (en) Software development method, development platform, terminal device and storage medium
CN113961238A (en) Object conversion method and device, electronic equipment and storage medium
CN117075912B (en) Method for program language conversion, compiling method and related equipment
CN111399842A (en) Code compiling method and device
CN117234466B (en) Enterprise management software development method, system, equipment and storage medium
CN116627390B (en) ICD file substitution method and device in aviation software development
US11650802B2 (en) Idiomatic source code generation
Nguyen Thiet Compiling JSONiq Queries to Native Machine Code: Semester Project

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 22894263

Country of ref document: EP

Kind code of ref document: A1