WO2023035563A1 - 小程序跨应用迁移方法、设备、终端、系统及存储介质 - Google Patents

小程序跨应用迁移方法、设备、终端、系统及存储介质 Download PDF

Info

Publication number
WO2023035563A1
WO2023035563A1 PCT/CN2022/079174 CN2022079174W WO2023035563A1 WO 2023035563 A1 WO2023035563 A1 WO 2023035563A1 CN 2022079174 W CN2022079174 W CN 2022079174W WO 2023035563 A1 WO2023035563 A1 WO 2023035563A1
Authority
WO
WIPO (PCT)
Prior art keywords
target
syntax tree
abstract syntax
application program
original
Prior art date
Application number
PCT/CN2022/079174
Other languages
English (en)
French (fr)
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 WO2023035563A1 publication Critical patent/WO2023035563A1/zh

Links

Images

Classifications

    • 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/70Software maintenance or management
    • G06F8/71Version control; Configuration management
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating
    • G06F9/44568Immediately runnable code

Definitions

  • the present application belongs to the field of data processing, and in particular relates to a small program cross-application migration method, device, equipment, terminal, system and storage medium.
  • An applet is an application that can be used without downloading and installing, and is attached to the host application. With the rapid development of small program technology, each application platform has launched its own small program framework specification.
  • the applet can be migrated among different application programs, that is, the applet running in one application program can be migrated to another application program.
  • the compatibility of applets in different applications is poor, and even in some applications, they cannot be directly run.
  • Embodiments of the present application provide a small program cross-application migration method, device, terminal, system, and storage medium, which can improve the compatibility of small programs in different application programs.
  • the embodiment of the present application provides a method for migrating applets across applications, which is applied to a compilation device.
  • the method includes: parsing the original code file of the applet of the original application, and generating the original abstract syntax tree.
  • the original abstract syntax tree is The abstract syntax tree of the original code file corresponding to the original application program; according to the original abstract syntax tree and the target conversion rules of the target application program, the target abstract syntax tree is converted, and the target abstract syntax tree is the original code file corresponding to the target application program Abstract syntax tree; based on the target abstract syntax tree, generate the object code file of the applet in the target application program; transmit the object code file to the user terminal, so that the user terminal can obtain the target configuration when the target application program runs the object code file
  • the parameter completes the application programming interface API call of the target application program to realize the function of the applet, and the target configuration parameters include configuration parameters matching the current API version of the target application program.
  • the embodiment of the present application provides a small program cross-application migration method, which is applied to a user terminal, and the user terminal is installed with a target application program.
  • the method includes: obtaining the target code file of the small program in the target application program, and the target code file
  • the target abstract syntax tree is generated by the compilation device based on the target abstract syntax tree.
  • the target abstract syntax tree is converted by the compilation device according to the original abstract syntax tree and the target conversion rules of the target application program.
  • the original abstract syntax tree is parsed by the compilation device from the original
  • the code file is generated; in the process of the target application program running the target code file, the target configuration parameters are obtained, and the target configuration parameters include configuration parameters matching the current application programming interface API version of the target application program; the target application is completed using the target configuration parameters
  • the embodiment of the present application provides a compiling device, including: a parsing module, which is used to parse the original code file of the applet of the original application program, and generate the original abstract syntax tree, which is the original abstract syntax tree corresponding to the original application program.
  • the abstract syntax tree of the original code file; the conversion module is used to convert the target abstract syntax tree according to the original abstract syntax tree and the target conversion rules of the target application program, and the target abstract syntax tree is an abstraction of the original code file corresponding to the target application program
  • the target configuration parameters are obtained to complete the application programming interface API call of the target application program to realize the functions of the applet.
  • the target configuration parameters include configuration parameters matching the current API version of the target application program.
  • the embodiment of the present application provides a user terminal, the user terminal is installed with a target application program, and the user terminal includes: a first acquisition module, configured to acquire the target code file of the applet in the target application program, and the target code file is compiled by The device is generated based on the target abstract syntax tree.
  • the target abstract syntax tree is converted by the compiling device according to the original abstract syntax tree and the target conversion rules of the target application program.
  • the original abstract syntax tree is parsed by the compiling device to the original code file of the applet of the original application program.
  • the second acquisition module in the process of the target application program running the target code file, acquires the target configuration parameters, and the target configuration parameters include configuration parameters matching the current application programming interface API version of the target application program; calling the module, using It is used to complete the API call of the target application program by using the target configuration parameters, so as to realize the functions of the applet.
  • the embodiment of the present application provides a compiling device, including: a processor and a memory storing computer program instructions; when the processor executes the computer program instructions, the method for migrating applets across applications in the first aspect is implemented.
  • an embodiment of the present application provides a user terminal, including: a processor and a memory storing computer program instructions; when the processor executes the computer program instructions, the method for migrating applets across applications in the second aspect is implemented.
  • the embodiment of the present application provides a small program cross-application migration system, including the compiling device in the fifth aspect and the user terminal in the sixth aspect.
  • the embodiments of the present application provide a computer-readable storage medium, on which computer program instructions are stored, and when the computer program instructions are executed by a processor, the method for migrating applets across applications in the first aspect or the second Two methods of cross-application migration of small programs.
  • the embodiment of the present application provides a small program cross-application migration method, device, terminal, system and storage medium.
  • the compilation device analyzes the original code file of the small program of the original application program through the abstract syntax tree technology to obtain the original abstract syntax tree. Use the target conversion rules corresponding to the target application to convert the original abstract syntax tree into a target abstract syntax tree that conforms to the target application framework, and then generate an applet that conforms to the target application framework according to the target abstract syntax tree. code files.
  • the compilation device can transmit the object code file to the user terminal.
  • the target code file compiled by the compiling device conforms to the framework of the target application program.
  • the applet can be migrated from the original application program to the target application program.
  • the configuration parameters matching the current API version complete the API call to the target application to realize the functions of the applet.
  • the applet can be adapted to the functions of different API versions, thereby improving the compatibility of the applet in different applications.
  • FIG. 1 is a schematic diagram of an example of an application scenario of a method for inter-application migration of small programs provided by an embodiment of the present application;
  • FIG. 2 is a schematic diagram of another example of the application scenario of the method for migrating applets across applications provided by the embodiment of the present application;
  • FIG. 3 is a schematic diagram of another example of an application scenario of the method for migrating applets across applications provided by the embodiment of the present application;
  • Fig. 4 is a flow chart of an embodiment of the method for migrating applets across applications provided in the first aspect of the present application
  • FIG. 5 is a schematic diagram of an example of the target abstract syntax tree corresponding to the JS file provided by the embodiment of the present application;
  • FIG. 6 is a schematic diagram of an example of a target abstract syntax tree corresponding to a page template file provided by an embodiment of the present application
  • FIG. 7 is a flow chart of another embodiment of the method for migrating applets across applications provided in the first aspect of the present application.
  • FIG. 8 is a flow chart of another embodiment of the method for migrating applets across applications provided in the first aspect of the present application.
  • FIG. 9 is a schematic diagram of an example of partial annotations of the target abstract syntax tree provided by the embodiment of the present application.
  • FIG. 10 is a flowchart of an embodiment of a method for migrating applets across applications provided by the second aspect of the present application.
  • Fig. 11 is a flow chart of another embodiment of the method for migrating applets across applications provided by the second aspect of the present application.
  • FIG. 12 is a schematic diagram of an example of the generation process of the API configuration parameter list provided by the embodiment of the present application.
  • FIG. 13 is a schematic diagram of an example of the cross-application migration process of applets provided by the embodiment of the present application.
  • FIG. 14 is a schematic structural diagram of an embodiment of a compiling device provided in the third aspect of the present application.
  • FIG. 15 is a schematic structural diagram of another embodiment of the compiling device provided by the third aspect of the present application.
  • FIG. 16 is a schematic structural diagram of an embodiment of a user terminal provided in the fourth aspect of the present application.
  • FIG. 17 is a schematic structural diagram of another embodiment of a user terminal provided in the fourth aspect of the present application.
  • FIG. 18 is a schematic structural diagram of an embodiment of a compiling device provided in the fifth aspect of the present application.
  • Fig. 19 is a schematic structural diagram of an embodiment of a user terminal provided in the sixth aspect of the present application.
  • An applet is an application that can be used without downloading and installing, and is attached to the host application.
  • each application platform has launched its own mini-program framework specification.
  • the applet architecture includes two types of standards, the custom domain-specific language (Domain-specific language, DSL) standard and the general language standard, the underlying mechanisms of the two types of standard specifications are completely different, such as the law structure, analysis and compilation processing, and data update and rendering.
  • DSL Domain-specific language
  • the applet specifications of applications on different application platforms are also different, resulting in poor compatibility between the same applet and applications other than the original application corresponding to the applet, and even in some It cannot be run directly in the application.
  • the embodiment of the present application provides a small program cross-application migration method, device, terminal, system and storage medium, which can generate an abstract syntax tree (Abstract Syntax Tree, AST) according to the code file of the small program of the original application program, and use the target
  • the conversion rule of the application program converts the abstract syntax tree generated above into the abstract syntax tree of the original code file corresponding to the target application program, and according to the abstract syntax tree of the original code file corresponding to the target application program, obtains the Program code files.
  • the applet calls the value of the configuration parameter matched by the current version of the application programming interface (Application Programming Interface, API) of the target application to realize the function of the applet, so that the applet can Migrate from the original application to the target application, and it can run normally in the target application, which improves the compatibility of the applet in different applications.
  • API Application Programming Interface
  • the applet cross-application migration method provided in the embodiment of the present application may involve a compiling device and a user terminal.
  • the compilation device can communicate directly with the user terminal.
  • other devices may also be set between the compiling device and the user terminal, that is, the compiling device does not communicate directly with the user terminal.
  • the quantity and type of other devices provided between the compiling device and the user terminal are not limited here.
  • FIG. 1 is a schematic diagram of an example of an application scenario of a method for migrating applets across applications provided by an embodiment of the present application. As shown in FIG. 1 , the compiling device 11 can communicate directly with the user terminal 12 .
  • the compiling device 11 is used to compile code files, that is, the compiling device 11 can compile and generate a code file of an applet that is provided to the user terminal 12 and can be run in the target application program.
  • the compilation device 11 may include a server or a terminal device, and the type of the compilation device 11 is not limited here.
  • the user terminal 12 is installed with a target application program.
  • the user terminal 12 can run the code file of the applet corresponding to the target application program in the target application program.
  • the user terminal 12 can also install the original application program, which is not limited here.
  • the code file of the applet corresponding to the original application program can be run on the original application program, and the applet corresponding to the target application program can be run on the target application program. code file.
  • the user terminal 12 may include terminal equipment such as a mobile phone, a computer, and a tablet computer, and is not limited here.
  • FIG. 2 is a schematic diagram of another example of an application scenario of the method for migrating applets across applications provided by the embodiment of the present application.
  • the difference between FIG. 1 and FIG. 2 is that the compiling device 11 communicates with the device 13 , and the device 13 communicates with the user terminal 12 .
  • the compilation device 11 can upload the code file of the generated applet in the target application program to the device 13, and the device 13 sends the code file to the user terminal 12.
  • the device 13 may include devices such as a server, which is not limited here.
  • FIG. 3 is a schematic diagram of another example of an application scenario of the method for migrating applets across applications provided by the embodiment of the present application.
  • the difference between FIG. 3 and FIG. 1 is that FIG. 3 may also include a configuration platform 14 .
  • the configuration platform 14 can provide the user terminal 12 with the values of the configuration parameters corresponding to the API versions of the target application program, so that the user terminal 12 can call it when the target application program runs the applet.
  • the first aspect of the present application provides a small program cross-application migration method, which can be used in a compiling device, that is, the small program cross-application migration method can be executed by the compiling device.
  • Fig. 4 is a flow chart of an embodiment of the method for migrating applets across applications provided in the first aspect of the present application. As shown in FIG. 4 , the method for migrating applets across applications may include steps S201 to S204.
  • step S201 the original code file of the applet of the original application program is analyzed to generate the original abstract syntax tree.
  • the original application is the application that the applet was attached to before migration.
  • the original code file is a code file that the applet can run in the original application program.
  • the original abstract syntax tree is the abstract syntax tree of the original code file corresponding to the original application program.
  • An abstract syntax tree corresponding to the original code file can be generated by parsing the original code file.
  • the original abstract syntax tree includes multiple nodes, and the nodes may include variables, functions, events, data states, etc. in the original code file.
  • the logic details in the original code file can be represented by the branches in the original abstract syntax tree and the nodes in the branches.
  • the child nodes of a node are also nodes in the abstract syntax tree.
  • a child node of a node may represent the content of the node, and may also be a child node representing the attribute of the node.
  • Variables can implement some dynamic content in the applet, and events can be used to respond to user operations, which are not limited here.
  • the source code file may include different files.
  • an abstract syntax tree corresponding to each file can be obtained.
  • source code files may include script files, page template files, and style files.
  • the original abstract syntax tree may include a first original abstract syntax tree corresponding to the script file, a second original abstract syntax tree corresponding to the page template file, and a third original abstract syntax tree corresponding to the style file.
  • the script file may specifically be a Java script file, ie a JS file, or a script file of other front-end languages, which is not limited here.
  • the script file of the applet of the original application program is analyzed to obtain an abstract syntax tree corresponding to the script file, that is, the first original abstract syntax tree.
  • a page template file is a specific type of template file that can be applied to a specific page or group of pages.
  • the page template file of the applet can ensure the web page of the applet.
  • the page template file of the applet of the original application program is analyzed to obtain an abstract syntax tree corresponding to the page template file, that is, the second original abstract syntax tree.
  • the page template file in the original code file may be parsed to generate a Document Object Model (Document Object Model, DOM) tree corresponding to the page template file. Extract the program logic in the document object model tree, such as if judgment, for loop, etc., according to the program logic, convert the document object model tree into the abstract syntax tree corresponding to the page template file, that is, the second original abstract syntax tree.
  • the document object model tree may specifically include an extensible markup language document object model (Extensible Markup Language Document Object Model, XML DOM) tree, which is not limited here.
  • the style file may include the definition information of the elements in the web page of the applet, such as the default font, size, color, front page appearance, text arrangement interval and other related information of the title and body text, which is not limited here.
  • the style file of the applet of the original application program is analyzed to obtain an abstract syntax tree corresponding to the style file, that is, a third original abstract syntax tree.
  • step S202 the target abstract syntax tree is converted according to the original abstract syntax tree and the target conversion rules of the target application program.
  • the target conversion rule of the target application is a general conversion rule for converting the abstract syntax tree of the applet conforming to the framework of the original application program to the abstract syntax tree of the applet conforming to the framework of the target application program.
  • Target conversion rules can be programmed in advance. Different target applications correspond to different target conversion rules.
  • the target abstract syntax tree is the abstract syntax tree of the original code file corresponding to the target application program, that is, the abstract syntax tree conforming to the framework of the target application program.
  • source code files may include script files, page template files, and style files.
  • the original abstract syntax tree may include a first original abstract syntax tree corresponding to the script file, a second original abstract syntax tree corresponding to the page template file, and a third original abstract syntax tree corresponding to the style file.
  • the target abstract syntax tree may include a first target abstract syntax tree corresponding to script files, a second target abstract syntax tree corresponding to page template files, and a third target abstract syntax tree corresponding to style files.
  • the first original abstract syntax tree can be converted into the first target abstract syntax tree.
  • the second original abstract syntax tree can be converted into the second target abstract syntax tree.
  • the third original abstract syntax tree can be converted into the third target abstract syntax tree.
  • the style file of the applet of the original application program can be parsed, and the abstract syntax tree of the intermediate stage is first obtained.
  • the abstract syntax tree of the intermediate stage is the third original abstract syntax tree, and then the abstract syntax tree of the intermediate stage is converted to An abstract syntax tree for the third object.
  • the third target abstract syntax tree may specifically include a Cascading Style Sheets Abstract Syntax Tree (CSS AST), which is not limited here.
  • FIG. 5 is a schematic diagram of an example of a target abstract syntax tree corresponding to a JS file provided in the embodiment of the present application.
  • the target abstract syntax tree JS AST corresponding to the JS file includes nodes such as data state, life cycle function, and time function.
  • the branch where the data state node is located also includes three nodes, all of which are data state nodes, representing variable a, variable b, and variable c respectively.
  • this.state.a, this.state.b, and this. state.c said.
  • the branch of the life cycle function node also includes four nodes, all of which are nodes of the life cycle function, respectively representing the onInit function, onShow function, onUpdate function and onHide function, which are respectively represented by onInit, onShow, onUpdate and onHide in Figure 5.
  • the branch where the event function node is located also includes a node, which is the node of the event function and represents the dom_func_e function.
  • FIG. 6 is a schematic diagram of an example of a target abstract syntax tree corresponding to a page template file provided in the embodiment of the present application.
  • the target abstract syntax tree corresponding to the page template file ie, the page template AST
  • the branch where the node Element1 is located also includes a variable node, which represents a variable a, which is represented by variable a in FIG. 6 .
  • the branch where the node Element2 is located also includes the node Element4.
  • the two branches below the node Element4 each include a node, one node is a node of a document object model event, and the other node is a node of a variable.
  • the node of a document object model event represents an event e, It is represented by event e in FIG. 6 ; the node of the variable represents variable c, which is represented by variable c in FIG. 6 .
  • the branch where the node Element3 is located also includes a variable node, and the variable node represents variable b, which is represented by variable b in FIG. 6 .
  • step S203 an object code file of the applet in the target application program is generated based on the target abstract syntax tree.
  • the target abstract syntax tree After the target abstract syntax tree is obtained, the target abstract syntax tree can be converted into a code file, and the converted code file is the target code file.
  • the object code file is the code file of the applet in the target application program.
  • source code files include script files, page template files, and style files.
  • the target abstract syntax tree includes a first target abstract syntax tree corresponding to the script file, a second target abstract syntax tree corresponding to the page template file, and a third target abstract syntax tree corresponding to the style file.
  • the first target abstract syntax tree and the second target abstract syntax tree can be logically integrated to obtain the target program code file.
  • the target program code file is the program code file corresponding to the applet and the target application program
  • the target style file is the style file corresponding to the applet and the target application program.
  • the target program code file and the target style file can be combined to obtain the target code file of the applet in the target application program.
  • step S204 the target code file is transmitted to the user terminal, so that the user terminal obtains the target configuration parameters and completes the API call of the target application program to realize the function of the applet during the process of running the target application program.
  • the compiling device may directly send the object code file to the user terminal when the user terminal requests to run the applet in the target application program, so that the user terminal can run the object code file in the target application program.
  • the compiling device may first send the object code file to another intermediate device, and then the intermediate device sends the object code file to the user terminal when the user terminal requests to run the applet in the target application program, Realize the process of transmitting the object code file from the compilation device to the user terminal, so that the user terminal can run the object code file in the target application program.
  • the target configuration parameters include configuration parameters that match the current API version of the target application's application programming interface.
  • the user terminal needs to obtain configuration parameters that match the current API version of the target application, and the applet can be implemented without modifying the target code file for different API versions. Compatible with functions of different API versions.
  • the compiling device analyzes the original code file of the applet of the original application program through the abstract syntax tree technology to obtain the original abstract syntax tree.
  • Use the target conversion rules corresponding to the target application to convert the original abstract syntax tree into a target abstract syntax tree that conforms to the target application framework, and then generate an applet that conforms to the target application framework according to the target abstract syntax tree.
  • the compilation device can transmit the object code file to the user terminal.
  • the target code file compiled by the compiling device conforms to the framework of the target application program.
  • the applet can be migrated from the original application program to the target application program.
  • the configuration parameters matching the current API version complete the API call to the target application to realize the functions of the applet.
  • the applet can be adapted to the functions of different API versions, thereby improving the compatibility of the applet in different applications.
  • the compiling device can automatically generate an object code file that conforms to the frame of the target application program according to the original code file of the applet of the original application program, and also avoids manual rewriting of programs caused by different levels of developers.
  • the performance and stability of the applet running in the target application program are uneven, which can ensure the consistency of the performance and stability of the applet running in the target application program, and improve the development efficiency.
  • FIG. 7 is a flow chart of another embodiment of the method for migrating applets across applications provided in the first aspect of the present application. The difference between FIG. 7 and FIG. 4 lies in that step S203 in FIG. 4 can be subdivided into steps S2031 to S2034 in FIG. 7 .
  • step S2031 bind the nodes in the first target abstract syntax tree representing the same object with the nodes in the second target abstract syntax tree.
  • the objects represented by the nodes in the bound first target abstract syntax tree and the nodes in the second target abstract syntax tree are the same object.
  • Nodes in the bound first target abstract syntax tree have a binding relationship with nodes in the second target abstract syntax tree.
  • nodes in the first target abstract syntax tree may include data states and event functions
  • nodes in the second target abstract syntax tree may include variables and document object schema events.
  • the data state in the first target abstract syntax tree representing the same object and the variable in the second target abstract syntax tree can be bound
  • the event function and the second target abstract syntax tree in the first target abstract syntax tree representing the same object can also be bound Document Object Model events in the tree.
  • the object represented by the node variable a of the data state in Figure 5 and the node variable a of the variable in Figure 6 is variable a
  • the node variable a of the data state in Figure 5 can be It is bound to the node variable a of the variable in Figure 6
  • the object represented by the node variable b of the data state in Figure 5 and the node variable b of the variable in Figure 6 is variable b
  • the node variable of the data state in Figure 5 can be b is bound to the node variable b of the variable in Figure 6
  • the object represented by the node variable c of the data state in Figure 5 and the node variable c of the variable in Figure 6 is variable c
  • the node of the data state in Figure 5 can be
  • the variable c is bound to the node variable c of the variable in Figure 6
  • the node dom_func_e(this.on_btn_e_click) of the event function in Figure 5 represents the click event
  • step S2032 the target program code file is obtained according to the binding relationship of the nodes, the functions in the first target abstract syntax tree and the second target abstract syntax tree.
  • the node representing the same object in the first target abstract syntax tree and the second target abstract syntax tree can be determined, so that according to the binding relationship of the nodes, the function in the first target abstract syntax tree and the second
  • the target abstract syntax tree implements the logical integration of the first target abstract syntax tree and the second target abstract syntax tree to obtain the target program code file.
  • variables in the second target abstract syntax tree can be replaced with bound data states
  • document object model events in the second target abstract syntax tree can be replaced with bound event functions to obtain an updated second target abstract syntax tree ;Encapsulate the updated second target abstract syntax tree to obtain the rendering function; encapsulate the function in the first target abstract syntax tree to obtain the function to be called; based on the bound data state and variables, bound event functions and document object model event, rendering function and function to be called to obtain the target program code file.
  • first target abstract syntax tree as the abstract syntax tree shown in FIG. 5
  • second target abstract syntax tree as the abstract syntax tree shown in FIG. 6
  • the variables in the abstract syntax tree of the second target can be replaced with the unified management of the data state in the abstract syntax tree of the first target, which can be realized by using the following programming language:
  • variable b this.state.b
  • the document object model event in the abstract syntax tree of the second target can be replaced with the click event function in the abstract syntax tree of the first target, which can be realized by using the following programming language:
  • Encapsulating the updated second target abstract syntax tree as a rendering function can be used for page rendering of applets.
  • the functions in the first target abstract syntax tree may include business functions and lifecycle functions, but are not limited thereto.
  • the function to be called includes a first calling function obtained by encapsulating a business function and a second calling function obtained by encapsulating a lifecycle function, but it is not limited thereto.
  • the second calling function encapsulated by the business function may exist in the form of a business logic layer, that is, the business function is encapsulated as a business logic layer.
  • the function to be called can be called during the running of the applet in the target application program. According to the bound data state and variable, the variable can be managed in the form of data state.
  • the document object mode event can be managed in the form of event function.
  • the object program code file may include variables and data states managed in the form of data states, event functions and document object mode events managed in the form of event functions, rendering functions, and functions to be called.
  • step S2033 the target style file is obtained based on the third target abstract syntax tree.
  • the target style file is a style file corresponding to the applet and the target application program.
  • step S2034 the object code file is obtained based on the object program code file and the object style file.
  • Object code files include object program code files and object style files. That is, the target program code file and the target style file can be combined to obtain the target code file of the applet in the target application program.
  • FIG. 8 is a flow chart of another embodiment of the method for migrating applets across applications provided in the first aspect of the present application. The difference between FIG. 8 and FIG. 4 lies in that step S202 in FIG. 4 can be subdivided into step S2021 and step S2022 in FIG. 8 .
  • step S2021 the original abstract syntax tree is converted into an abstract syntax tree conforming to the framework of the target application program by using the target conversion rule.
  • the framework of the target application program is different from that of the original application program.
  • the form of the abstract syntax tree corresponding to the target application program is different from the form of the abstract syntax tree corresponding to the original application program, that is, the form of the original abstract syntax tree.
  • step S2022 comments are inserted at positions indicated by the target transformation rules in the abstract syntax tree of the target application program to obtain the target abstract syntax tree.
  • Notes include the functional development guidelines of the branch where the notes are located.
  • the target conversion rule is set for the frame of the target application program, and the target conversion rule records the positions of the branches and nodes representing each function in the abstract syntax tree conforming to the frame of the target application program. According to the position of each function in the abstract syntax tree of the framework conforming to the target application program recorded by the target conversion rule, comments including function development guidelines can be inserted correspondingly.
  • the target abstract syntax tree includes inserted comments.
  • Fig. 9 is a schematic diagram of an example of partial annotation of the target abstract syntax tree provided by the embodiment of the present application. As shown in FIG. 9 , on the branch where the lifecycle function node of the target abstract syntax tree is located, comment 1 may be inserted before node statement 1 .
  • the second aspect of the present application also provides a method for migrating applets across applications, which can be applied to a user terminal, that is, the method for migrating applets across applications can be executed by the user terminal.
  • FIG. 10 is a flowchart of an embodiment of a method for migrating applets across applications provided by the second aspect of the present application. As shown in FIG. 10 , the method for migrating applets across applications may include steps S301 to S303.
  • step S301 the object code file of the applet in the target application is acquired.
  • the object code file is generated by the compilation facility based on the object abstract syntax tree.
  • the target abstract syntax tree is converted by the compiling device according to the original abstract syntax tree and the target conversion rules of the target application program.
  • the original abstract syntax tree is generated by the compilation device by parsing the original code file of the applet of the original application program.
  • step S302 the target configuration parameters are acquired during the target application program running the target code file.
  • step S303 the API call of the target application program is completed by using the target configuration parameters, so as to realize the functions of the applet.
  • Target configuration parameters include configuration parameters that match the target application's current API version.
  • the version of the API of the original application program may be the same as that of the target application program, or may be different.
  • the object code file runs in the target application program and needs to call the API under the current API version of the target application program.
  • the configuration parameters that match the current API version of the target application program, that is, the target configuration parameters may be transmitted to the local layer of the user terminal, that is, the native layer to perform function substitution.
  • the user terminal can obtain the object code file compiled by the compiling device.
  • the object code file is compiled by the compiling device through the abstract syntax tree technology and the target conversion rules corresponding to the target application.
  • the object code file conforms to the framework of the target application program, can run normally on the target application program of the user terminal, and the applet can be migrated from the original application program to the target application program.
  • the user terminal obtains and utilizes the configuration parameters matching the current API version of the target application program to complete the API call of the target application program to realize the function of the applet, which can be used at any time.
  • the API plug-in interface function of the current API version of the target application is adapted to improve the compatibility of the applet in different applications.
  • the target configuration parameters can be determined by comparing the API version of the original application program with the current API version of the target application program.
  • Fig. 11 is a flow chart of another embodiment of the method for migrating applets across applications provided by the second aspect of the present application. The difference between FIG. 11 and FIG. 10 is that step S302 in FIG. 10 can be specifically refined into step S3021 or step S3022 in FIG. 11 .
  • step S3021 if the API version of the original application program is consistent with the current API version of the target application program, the configuration parameters corresponding to the API version of the original application program are obtained as target configuration parameters.
  • the API version of the original application is consistent with the current API version of the target application, which means that the plug-in interface functions of the API of the original application and the API of the target application are consistent, that is, the configuration parameters corresponding to the API version of the original application are the same as those of the target application.
  • the configuration parameters corresponding to the current API version are the same, and the configuration parameters corresponding to the API version of the original application program can be obtained locally on the user terminal.
  • step S3022 if the API version of the original application program is inconsistent with the current API version of the target application program, the configuration parameters corresponding to the API version of the original application program are obtained, and new configurations are obtained from the preloaded API configuration parameter list parameters as target configuration parameters.
  • the newly added configuration parameters are the configuration parameters corresponding to the current API version of the target application program except the configuration parameters corresponding to the API version of the original application program.
  • the API configuration parameter list includes configuration parameters corresponding to each API version of the target application program.
  • the API version of the original application is inconsistent with the current API version of the target application, which means that the plug-in interface functions of the API of the original application and the API of the target application are inconsistent, that is, the configuration parameters corresponding to the API version of the original application are different from those of the target application.
  • the configuration parameters corresponding to the current API version are inconsistent, and all the configuration parameters corresponding to the API version of the original application cannot be obtained locally on the user terminal.
  • the API configuration parameter list can make up for the lack of local data of the user terminal, and the configuration parameters corresponding to the current API version of the target application program can be obtained from the API configuration parameter list.
  • the combination of newly added configuration parameters and the configuration parameters corresponding to the API version of the original application can meet the requirements of the current API version of the target application, so that the current API of the target application can be adapted without modifying the target code file of the applet
  • the plug-in interface function of the API version improves the compatibility of applets in different applications.
  • the function that the applet calls to obtain the geolocation API in the original application is get_location().
  • the current API version of the target application adds a whether to cache the current geolocation information for next use.
  • the configuration parameters of the applet, the function called by the applet to obtain the geolocation API in the target application becomes get_location(isCache), resulting in inconsistent API functions.
  • the code in the target program code file may not be modified, and the API configuration parameter list is loaded on the user terminal in advance.
  • the API configuration parameter list is obtained by deduplicating and merging the configuration parameters corresponding to the API version of the original application program and the configuration parameters corresponding to each API version of the target application program.
  • the list of API configuration parameters can be obtained by processing the configuration platform, and is not limited here.
  • the configuration platform can obtain the configuration parameters of the applet corresponding to the API version of the original application program from the object code file of the applet or the original code file of the applet.
  • the configuration platform may deduplicate and merge the configuration parameters corresponding to each API version of the target application program to obtain the first configuration parameter set. Merge the configuration parameters of the applet corresponding to the API version of the original application program with the first configuration parameter set to obtain the API configuration parameter list in the above embodiment.
  • Fig. 12 is a schematic diagram of an example of the generation process of the API configuration parameter list provided by the embodiment of the present application.
  • the original application program is application program A
  • the target application program is application program B
  • the API of application program B has N versions, namely API 1 to API N.
  • the configuration parameters corresponding to the API version of application A include a' and b'; the configuration parameters corresponding to API version 1 of application B include a; the configuration parameters corresponding to API version 2 of application B include a and b; ...,
  • the configuration parameters corresponding to the API N version of application B include a, b, c, ..., n; wherein, the configuration parameter a' is the same as the configuration parameter a, and the configuration parameter b' is the same as the configuration parameter b.
  • the obtained first configuration parameter set includes a, b, c, . . . , n.
  • the obtained API configuration parameter list includes a', b', c, ..., n.
  • the API configuration parameter list obtained through deduplication and merging processing can reduce useless redundant data, reduce resources occupied by the API configuration parameter list, and prevent the API configuration parameter list from occupying a large amount of resources to affect the performance of the user terminal.
  • the user terminal may load the API configuration parameter list issued by the configuration platform when the applet is initialized in the target application program. During the second, third, and subsequent runs of the applet, there is no need to repeatedly request the API configuration parameter list from the loading configuration platform.
  • FIG. 13 is a schematic diagram of an example of a process of migrating applets across applications provided by the embodiment of the present application.
  • the original application program is application program A
  • the target application program is application program B
  • the compilation device is provided with a Java script file abstract syntax tree conversion engine (abbreviated as JS AST conversion engine), a page template file conversion engine (abbreviated as Template conversion engine), style file conversion engine (referred to as style conversion engine) and logic integration engine
  • the user terminal is equipped with an API dynamic adaptation engine.
  • the original code files of the applet include JS files, page template files, and style files.
  • JS files are input to the JS AST conversion engine
  • page template files are input to the template conversion engine
  • style files are input to the style conversion engine.
  • the output of the JS AST transformation engine and the template transformation engine are fed into the input of the logic integration engine.
  • the logic integration engine outputs the target program code file
  • the style transformation engine outputs the target style file.
  • the object program code file and the object style file constitute an object code file.
  • the target code file can be transmitted to the API dynamic adaptation engine, and the API dynamic adaptation engine can obtain the configuration parameters matching the current API version of the target application program during the process of running the target code file, and use the target configuration parameters to complete the API call of the target application program , to realize the functions of the applet.
  • the third aspect of the present application may provide a compiling device.
  • FIG. 14 is a schematic structural diagram of an embodiment of a compiling device provided in the third aspect of the present application.
  • the compilation device 400 may include an analysis module 401 , a conversion module 402 , a file generation module 403 and a communication module 404 .
  • the analysis module 401 can be used to analyze the original code file of the applet of the original application program, and generate the original abstract syntax tree.
  • the original abstract syntax tree is the abstract syntax tree of the original code file corresponding to the original application program.
  • the conversion module 402 can be used to convert the original abstract syntax tree and the target application program's target conversion rules to obtain the target abstract syntax tree.
  • the target abstract syntax tree is the abstract syntax tree of the source code file corresponding to the target application program.
  • the file generation module 403 can be used to generate the object code file of the applet in the target application program based on the target abstract syntax tree.
  • the communication module 404 is used to transmit the object code file to the user terminal, so that the user terminal obtains the target configuration parameters to complete the application programming interface API call of the target application program in the process of running the target application program to realize the applet. Function.
  • Target configuration parameters include configuration parameters that match the target application's current API version.
  • source code files include script files, page template files, and style files.
  • the original abstract syntax tree includes a first original abstract syntax tree corresponding to the script file, a second original abstract syntax tree corresponding to the page template file and a third original abstract syntax tree corresponding to the style file.
  • the target abstract syntax tree includes a first target abstract syntax tree corresponding to the script file, a second target abstract syntax tree corresponding to the page template file, and a third target abstract syntax tree corresponding to the style file.
  • the compiling device analyzes the original code file of the applet of the original application program through the abstract syntax tree technology to obtain the original abstract syntax tree.
  • Use the target conversion rules corresponding to the target application to convert the original abstract syntax tree into a target abstract syntax tree that conforms to the target application framework, and then generate an applet that conforms to the target application framework according to the target abstract syntax tree.
  • the compilation device can transmit the object code file to the user terminal.
  • the target code file compiled by the compiling device conforms to the framework of the target application program.
  • the applet can be migrated from the original application program to the target application program.
  • the configuration parameters matching the current API version complete the API call to the target application to realize the functions of the applet.
  • the applet can be adapted to the functions of different API versions, thereby improving the compatibility of the applet in different applications.
  • the compiling device can automatically generate an object code file that conforms to the frame of the target application program according to the original code file of the applet of the original application program, and also avoids manual rewriting of programs caused by different levels of developers.
  • the performance and stability of the applet running in the target application program are uneven, which can ensure the consistency of the performance and stability of the applet running in the target application program, and improve the development efficiency.
  • Fig. 15 is a schematic structural diagram of another embodiment of the compiling device provided in the third aspect of the present application.
  • the difference between FIG. 15 and FIG. 14 is that the file generating module 403 shown in FIG. 15 may include a binding unit 4031 and a file generating unit 4032 .
  • the binding unit 4031 can be used to bind the nodes in the first target abstract syntax tree representing the same object and the nodes in the second target abstract syntax tree.
  • the file generation unit 4032 can be used to: obtain the target program code file according to the binding relationship of the nodes, the functions in the first target abstract syntax tree and the second target abstract syntax tree; obtain the target style file based on the third target abstract syntax tree; Based on the object program code file and the object style file, the object code file is obtained.
  • Object code files include object program code files and object style files.
  • the nodes in the first target abstract syntax tree include data states and event functions.
  • Nodes in the second target abstract syntax tree include variables and Document Object Model events.
  • the binding unit 4031 can be used to: bind the data state in the first target abstract syntax tree representing the same object and the variable in the second target abstract syntax tree; bind the event function and the second target abstract syntax tree representing the same object Document Object Model event in the target abstract syntax tree.
  • the file generation unit 4032 can be used to: replace the variables in the abstract syntax tree of the second target with the bound data state, replace the document object model event in the abstract syntax tree of the second target with the bound event function, and obtain the updated second target Abstract syntax tree; encapsulate the updated second target abstract syntax tree to obtain rendering functions; encapsulate functions in the first target abstract syntax tree to obtain functions to be called; based on bound data states and variables, bound event functions and The document object model event, the rendering function and the function to be called obtain the target program code file.
  • the functions in the first target abstract syntax tree include business functions and lifecycle functions.
  • the functions to be called include a first calling function obtained by encapsulating a business function and a second calling function obtained by encapsulating a lifecycle function.
  • the source code files include page template files.
  • the parsing module 401 can be used to parse the page template file in the original code file, and generate a document object model tree corresponding to the page template file; extract the program logic of the document object model tree, and convert the document object model tree into a page template file corresponding to the program logic according to the program logic
  • the conversion module 402 can be used to: convert the original abstract syntax tree into an abstract syntax tree conforming to the framework of the target application program by using the target conversion rules; Insert the comment to get the target abstract syntax tree, and the comment includes the function development guide of the branch where the comment is located.
  • the fourth aspect of the present application further provides a user terminal, where a target application program is installed on the user terminal.
  • Fig. 16 is a schematic structural diagram of an embodiment of a user terminal provided in the fourth aspect of the present application.
  • the user terminal 500 may include a first obtaining module 501 , a second obtaining module 502 and a calling module 503 .
  • the first acquiring module 501 can be used to acquire the object code file of the applet in the target application program.
  • the object code file is generated by the compilation facility based on the object abstract syntax tree.
  • the target abstract syntax tree is converted by the compiling device according to the original abstract syntax tree and the target conversion rules of the target application program.
  • the original abstract syntax tree is generated by the compilation device by parsing the original code file of the applet of the original application program.
  • the second acquiring module 502 can acquire target configuration parameters during the target application running the target code file.
  • the target configuration parameters include configuration parameters that match the target application's current application programming interface API version.
  • the calling module 503 can be used to complete the API calling of the target application program by using the target configuration parameters, so as to realize the functions of the applet.
  • the user terminal may obtain the object code file compiled by the compiling device.
  • the object code file is compiled by the compiling device through the abstract syntax tree technology and the target conversion rules corresponding to the target application.
  • the object code file conforms to the framework of the target application program, can run normally on the target application program of the user terminal, and the applet can be migrated from the original application program to the target application program.
  • the user terminal obtains and utilizes the configuration parameters matching the current API version of the target application program to complete the API call of the target application program to realize the function of the applet, which can be used at any time.
  • the API plug-in interface function of the current API version of the target application is adapted to improve the compatibility of the applet in different applications.
  • the above-mentioned second obtaining module 502 can be used to: obtain the configuration parameter corresponding to the API version of the original application program as the target configuration parameter when the API version of the original application program is consistent with the current API version of the target application program; When the API version of the original application is inconsistent with the current API version of the target application, obtain the configuration parameters corresponding to the API version of the original application, and obtain new configuration parameters from the preloaded API configuration parameter list as the target configuration parameters .
  • the newly added configuration parameters are the configuration parameters corresponding to the current API version of the target application program except the configuration parameters corresponding to the API version of the original application program.
  • the API configuration parameter list includes configuration parameters corresponding to each API version of the target application program.
  • the API configuration parameter list is obtained by deduplicating and merging configuration parameters corresponding to the API version of the original application program and configuration parameters corresponding to each API version of the target application program.
  • Fig. 17 is a schematic structural diagram of another embodiment of a user terminal provided in the fourth aspect of the present application. The difference between FIG. 17 and FIG. 16 is that the user terminal 500 shown in FIG. 17 may further include a loading module 504 .
  • the loading module 504 can be used to load the API configuration parameter list issued by the configuration platform when the applet is initialized in the target application program.
  • the fifth aspect of the present application also provides a compiling device.
  • Fig. 18 is a schematic structural diagram of an embodiment of the compiling device provided in the fifth aspect of the present application.
  • the compiling device 600 includes a memory 601 , a processor 602 and a computer program stored in the memory 601 and executable on the processor 602 .
  • the processor 602 may include a central processing unit (CPU), or an application specific integrated circuit (Application Specific Integrated Circuit, ASIC), or may be configured to implement one or more integrated circuits of the embodiments of the present application.
  • CPU central processing unit
  • ASIC Application Specific Integrated Circuit
  • Memory 601 may include read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), disk storage medium device, optical storage medium device, flash memory device, electrical, optical or other physical/tangible Memory storage device.
  • ROM read-only memory
  • RAM random access memory
  • disk storage medium device disk storage medium device
  • optical storage medium device disk storage medium device
  • flash memory device electrical, optical or other physical/tangible Memory storage device.
  • memory includes one or more tangible (non-transitory) computer-readable storage media (e.g., memory devices) encoded with software comprising computer-executable instructions, and when the software is executed (e.g., by one or multiple processors), it is operable to execute the operations described with reference to the method for cross-application migration of applets applied to compiling devices according to the embodiments of the present application.
  • the processor 602 runs the computer program corresponding to the executable program code by reading the executable program code stored in the memory 601, so as to realize the method for migrating applets across applications applied to the compiling device in the above embodiments.
  • the compilation device 600 may further include a communication interface 603 and a bus 604 .
  • the memory 601 , the processor 602 , and the communication interface 603 are connected through a bus 604 to complete mutual communication.
  • the communication interface 603 is mainly used to implement communication between modules, devices, units and/or devices in the embodiments of the present application. Input devices and/or output devices may also be accessed through the communication interface 603 .
  • Bus 604 includes hardware, software, or both, and couples the components of compilation device 600 to each other.
  • the bus 604 may include an Accelerated Graphics Port (AGP) or other graphics bus, an Enhanced Industry Standard Architecture (Enhanced Industry Standard Architecture, EISA) bus, a Front Side Bus (Front Side Bus, FSB), Hyper Transport (HT) interconnect, Industry Standard Architecture (ISA) bus, InfiniBand interconnect, Low pin count (Low pin count, LPC) bus, memory bus, Micro Channel architecture (Micro Channel Architecture, MCA) bus, Peripheral Component Interconnect (PCI) bus, PCI-Express (PCI-E) bus, Serial Advanced Technology Attachment (Serial Advanced Technology Attachment, SATA) bus, Video Electronics Standards Association local ( Video Electronics Standards Association Local Bus, VLB) bus or other suitable bus or a combination of two or more of these.
  • Bus 604 may comprise one or more buses, where appropriate.
  • Fig. 19 is a schematic structural diagram of an embodiment of a user terminal provided in the sixth aspect of the present application.
  • the user terminal 700 includes a memory 701 , a processor 702 and computer programs stored in the memory 701 and operable on the processor 702 .
  • processor 702 may include a central processing unit (CPU), or an application specific integrated circuit (Application Specific Integrated Circuit, ASIC), or may be configured to implement one or more integrated circuits of the embodiments of the present application.
  • CPU central processing unit
  • ASIC Application Specific Integrated Circuit
  • Memory 701 may include read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), disk storage medium device, optical storage medium device, flash memory device, electrical, optical or other physical/tangible Memory storage device.
  • ROM read-only memory
  • RAM random access memory
  • disk storage medium device disk storage medium device
  • optical storage medium device disk storage medium device
  • flash memory device electrical, optical or other physical/tangible Memory storage device.
  • memory includes one or more tangible (non-transitory) computer-readable storage media (e.g., memory devices) encoded with software comprising computer-executable instructions, and when the software is executed (e.g., by one or multiple processors), it is operable to execute the operations described with reference to the method for migrating applets across applications applied to a user terminal according to an embodiment of the present application.
  • the processor 702 runs the computer program corresponding to the executable program code by reading the executable program code stored in the memory 701, so as to implement the method for migrating applets across applications applied to the user terminal in the above embodiment.
  • the user terminal 700 may further include a communication interface 703 and a bus 704 .
  • the memory 701 , the processor 702 , and the communication interface 703 are connected through a bus 704 to complete mutual communication.
  • the communication interface 703 is mainly used to realize the communication between various modules, devices, units and/or devices in the embodiments of the present application. Input devices and/or output devices may also be accessed through the communication interface 703 .
  • the bus 704 includes hardware, software, or both, and couples the components of the user terminal 700 to each other.
  • the bus 704 may include an Accelerated Graphics Port (AGP) or other graphics bus, an Enhanced Industry Standard Architecture (Enhanced Industry Standard Architecture, EISA) bus, a Front Side Bus (FSB), Hyper Transport (HT) interconnect, Industry Standard Architecture (ISA) bus, InfiniBand interconnect, Low pin count (Low pin count, LPC) bus, memory bus, Micro Channel architecture (Micro Channel Architecture, MCA) bus, Peripheral Component Interconnect (PCI) bus, PCI-Express (PCI-E) bus, Serial Advanced Technology Attachment (Serial Advanced Technology Attachment, SATA) bus, Video Electronics Standards Association local ( Video Electronics Standards Association Local Bus, VLB) bus or other suitable bus or a combination of two or more of these.
  • Bus 704 may comprise one or more buses, where appropriate. Although the embodiments of this application describe and illustrate a particular bus, this application contemplates any suitable bus or interconnect.
  • the seventh aspect of the present application also provides a small program cross-application migration system.
  • the applet cross-application migration system may include the compiling device and the user terminal in the above embodiments.
  • the applet cross-application migration system may include the compiling device and the user terminal in the above embodiments.
  • the eighth aspect of the present application also provides a computer-readable storage medium, on which computer program instructions are stored, and when the computer program instructions are executed by a processor, the applet applied to the compiling device in the above-mentioned embodiments can be realized
  • the cross-application migration method or the cross-application migration method of a small program for a user terminal can achieve the same technical effect, and will not be repeated here to avoid repetition.
  • the above-mentioned computer-readable storage medium may include a non-transitory computer-readable storage medium, such as a read-only memory (Read-Only Memory, ROM for short), a random access memory (Random Access Memory, RAM for short), a magnetic disk or an optical disk. etc., are not limited here.
  • processors may be, but are not limited to, general purpose processors, special purpose processors, application specific processors, or field programmable logic circuits. It can also be understood that each block in the block diagrams and/or flowcharts and combinations of blocks in the block diagrams and/or flowcharts can also be realized by dedicated hardware for performing specified functions or actions, or can be implemented by dedicated hardware and Combination of computer instructions to achieve.

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Security & Cryptography (AREA)
  • Stored Programmes (AREA)

Abstract

本申请公开了一种小程序跨应用迁移方法、设备、终端、系统及存储介质,属于数据处理领域。该方法包括:解析原应用程序的小程序的原代码文件,生成原抽象语法树;根据原抽象语法树和目标应用程序的目标转换规则,转换得到目标抽象语法树;基于目标抽象语法树,生成小程序在目标应用程序的目标代码文件;将目标代码文件传输至用户终端,以使用户终端在目标应用程序运行目标代码文件的过程中,获取目标配置参数完成目标应用程序的应用程序编程接口API调用以实现小程序的功能,目标配置参数包括与目标应用程序的当前API版本匹配的配置参数。根据本申请实施例能够提高小程序在不同应用程序的兼容性。

Description

小程序跨应用迁移方法、设备、终端、系统及存储介质
相关申请的交叉引用
本申请要求享有于2021年9月10日提交的名称为“小程序跨应用迁移方法、设备、终端、系统及存储介质”的中国专利申请202111064530.9的优先权,该申请的全部内容通过引用并入本文中。
技术领域
本申请属于数据处理领域,尤其涉及一种小程序跨应用迁移方法、装置、设备、终端、系统及存储介质。
背景技术
小程序是一种不需要下载安装即可使用的应用,依附在宿主应用程序中。而随着小程序技术的快速发展,各个应用程序平台都推出了自己的小程序框架规范。
为了提高小程序的灵活应用,希望小程序能够在不同的应用程序中迁移,也就是说,使在某一应用程序运行的小程序,可迁移至另一应用程序。但由于不同应用程序的规范等不同,导致小程序在不同应用程序的兼容性较差,甚至在一些应用程序中无法直接运行。
发明内容
本申请实施例提供一种小程序跨应用迁移方法、设备、终端、系统及存储介质,能够提高小程序在不同应用程序的兼容性。
第一方面,本申请实施例提供一种小程序跨应用迁移方法,应用于编译设备,该方法包括:解析原应用程序的小程序的原代码文件,生成原抽象语法树,原抽象语法树为与原应用程序对应的原代码文件的抽象语法树;根据原抽象语法树和目标应用程序的目标转换规则,转换得到目标抽 象语法树,目标抽象语法树为与目标应用程序对应的原代码文件的抽象语法树;基于目标抽象语法树,生成小程序在目标应用程序的目标代码文件;将目标代码文件传输至用户终端,以使用户终端在目标应用程序运行目标代码文件的过程中,获取目标配置参数完成目标应用程序的应用程序编程接口API调用以实现小程序的功能,目标配置参数包括与目标应用程序的当前API版本匹配的配置参数。
第二方面,本申请实施例提供一种小程序跨应用迁移方法,应用于用户终端,用户终端安装有目标应用程序,该方法包括:获取小程序在目标应用程序的目标代码文件,目标代码文件由编译设备基于目标抽象语法树生成,目标抽象语法树由编译设备根据原抽象语法树和目标应用程序的目标转换规则转换得到的,原抽象语法树由编译设备解析原应用程序的小程序的原代码文件生成得到;在目标应用程序运行目标代码文件的过程中,获取目标配置参数,目标配置参数包括与目标应用程序的当前应用程序编程接口API版本匹配的配置参数;利用目标配置参数完成目标应用程序的API调用,以实现小程序的功能。
第三方面,本申请实施例提供一种编译设备,包括:解析模块,用于解析原应用程序的小程序的原代码文件,生成原抽象语法树,原抽象语法树为与原应用程序对应的原代码文件的抽象语法树;转换模块,用于根据原抽象语法树和目标应用程序的目标转换规则,转换得到目标抽象语法树,目标抽象语法树为与目标应用程序对应的原代码文件的抽象语法树;文件生成模块,用于基于目标抽象语法树,生成小程序在目标应用程序的目标代码文件;通信模块,用于将目标代码文件传输至用户终端,以使用户终端在目标应用程序运行目标代码文件的过程中,获取目标配置参数完成目标应用程序的应用程序编程接口API调用以实现小程序的功能,目标配置参数包括与目标应用程序的当前API版本匹配的配置参数。
第四方面,本申请实施例提供一种用户终端,用户终端安装有目标应用程序,用户终端包括:第一获取模块,用于获取小程序在目标应用程序的目标代码文件,目标代码文件由编译设备基于目标抽象语法树生成,目标抽象语法树由编译设备根据原抽象语法树和目标应用程序的目标转换规 则转换得到的,原抽象语法树由编译设备解析原应用程序的小程序的原代码文件生成得到;第二获取模块,在目标应用程序运行目标代码文件的过程中,获取目标配置参数,目标配置参数包括与目标应用程序的当前应用程序编程接口API版本匹配的配置参数;调用模块,用于利用目标配置参数完成目标应用程序的API调用,以实现小程序的功能。
第五方面,本申请实施例提供一种编译设备,包括:处理器以及存储有计算机程序指令的存储器;处理器执行计算机程序指令时实现第一方面的小程序跨应用迁移方法。
第六方面,本申请实施例提供一种用户终端,包括:处理器以及存储有计算机程序指令的存储器;处理器执行计算机程序指令时实现第二方面的小程序跨应用迁移方法。
第七方面,本申请实施例提供一种小程序跨应用迁移系统,包括第五方面的编译设备和第六方面的用户终端。
第八方面,本申请实施例提供一种计算机可读存储介质,计算机可读存储介质上存储有计算机程序指令,计算机程序指令被处理器执行时实现第一方面的小程序跨应用迁移方法或第二方面的小程序跨应用迁移方法。
本申请实施例提供一种小程序跨应用迁移方法、设备、终端、系统及存储介质,编译设备通过抽象语法树技术对原应用程序的小程序的原代码文件进行分析,得到原抽象语法树。利用与目标应用程序对应的目标转换规则,将原抽象语法树转换为符合目标应用程序框架的目标抽象语法树,再根据目标抽象语法树生成符合目标应用程序框架的小程序在目标应用程序的目标代码文件。编译设备可将目标代码文件传输至用户终端。编译设备编译得到的目标代码文件符合目标应用程序的框架,小程序可从原应用程序迁移至目标应用程序,可在用户终端的目标应用程序正常运行,且在运行过程中获取与目标应用程序的当前API版本匹配的配置参数完成对目标应用程序的API调用来实现小程序的功能,小程序可与不同API版本的功能适配,从而提高了小程序在不同应用程序的兼容性。
附图说明
为了更清楚地说明本申请实施例的技术方案,下面将对本申请实施例中所需要使用的附图作简单的介绍,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。
图1为本申请实施例提供的小程序跨应用迁移方法的应用场景的一示例的示意图;
图2为本申请实施例提供的小程序跨应用迁移方法的应用场景的另一示例的示意图;
图3为本申请实施例提供的小程序跨应用迁移方法的应用场景的又一示例的示意图;
图4为本申请第一方面提供的小程序跨应用迁移方法的一实施例的流程图;
图5为本申请实施例提供的与JS文件对应的目标抽象语法树的一示例的示意图;
图6为本申请实施例提供的与页面模版文件对应的目标抽象语法树的一示例的示意图;
图7为本申请第一方面提供的小程序跨应用迁移方法的另一实施例的流程图;
图8为本申请第一方面提供的小程序跨应用迁移方法的又一实施例的流程图;
图9为本申请实施例提供的目标抽象语法树的局部的注释的一示例的示意图;
图10为本申请第二方面提供的小程序跨应用迁移方法的一实施例的流程图;
图11为本申请第二方面提供的小程序跨应用迁移方法的另一实施例的流程图;
图12为本申请实施例提供的API配置参数列表的生成过程的一示例的示意图;
图13为本申请实施例提供的小程序跨应用迁移过程的一示例的示意图;
图14为本申请第三方面提供的编译设备的一实施例的结构示意图;
图15为本申请第三方面提供的编译设备的另一实施例的结构示意图;
图16为本申请第四方面提供的用户终端的一实施例的结构示意图;
图17为本申请第四方面提供的用户终端的另一实施例的结构示意图;
图18为本申请第五方面提供的编译设备的一实施例的结构示意图;
图19为本申请第六方面提供的用户终端的一实施例的结构示意图。
具体实施方式
下面将详细描述本申请的各个方面的特征和示例性实施例,为了使本申请的目的、技术方案及优点更加清楚明白,以下结合附图及具体实施例,对本申请进行进一步详细描述。应理解,此处所描述的具体实施例仅意在解释本申请,而不是限定本申请。对于本领域技术人员来说,本申请可以在不需要这些具体细节中的一些细节的情况下实施。下面对实施例的描述仅仅是为了通过示出本申请的示例来提供对本申请更好的理解。
随着信息技术的发展和用户的需求,小程序应运而生。小程序是一种不需要下载安装即可使用的应用,依附在宿主应用程序。随着小程序技术的快速发展,各个应用程序平台都推出了自己的小程序框架规范。为了提高小程序的灵活应用,希望小程序能够在不同应用迁移。也就是说,希望依附某一应用程序运行的小程序,可迁移至另一应用程序。但由于小程序架构包括自定义领域特定语言(Domain-specific language,DSL)标准和通用语言标准两类标准,两类标准规范的法结构、解析编译处理、数据更新渲染等底层机制完全不同,且应用程序平台众多,且不同应用程序平台的应用程序的小程序规范也有所不同,导致同一个小程序与除该小程序对应的原应用程序之外的应用程序的兼容性较差,甚至在一些应用程序中无法直接运行。
本申请实施例提供一种小程序跨应用迁移方法、设备、终端、系统及存储介质,能够根据原应用程序的小程序的代码文件,生成抽象语法树 (Abstract Syntax Tree,AST),并利用目标应用程序的转换规则,将上面生成的抽象语法树转换为与目标应用程序对应的原代码文件的抽象语法树,根据与目标应用程序对应的原代码文件的抽象语法树,得到小程序在目标应用程序的代码文件。小程序在目标应用程序的代码文件被运行的过程中,调用目标应用程序的应用程序编程接口(Application Programming Interface,API)当前版本匹配的配置参数的值以实现小程序的功能,使得小程序可从原应用程序迁移至目标应用程序,并能在目标应用程序正常运行,提高了小程序在不同应用程序的兼容性。
本申请实施例提供的小程序跨应用迁移方法可涉及编译设备和用户终端。在一些示例中,编译设备可与用户终端直接进行通信交互。在另一些示例中,编译设备与用户终端之间还可设置其他设备,即编译设备并不与用户终端直接进行通信交互。在此并不限定编译设备与用户终端之间设置的其他设备的数量和种类。
图1为本申请实施例提供的小程序跨应用迁移方法的应用场景的一示例的示意图。如图1所示,编译设备11可与用户终端12直接进行通信交互。
编译设备11用于编译代码文件,即编译设备11可编译生成提供给用户终端12的能够在目标应用程序运行的小程序的代码文件。编译设备11可包括服务器,也可包括终端设备,在此并不限定编译设备11的种类。
用户终端12安装有目标应用程序。用户终端12可在目标应用程序运行与目标应用程序对应的该小程序的代码文件。用户终端12也可安装原应用程序,在此并不限定。在用户终端12安装有目标应用程序和原应用程序的情况下,可在原应用程序运行与原应用程序对应的该小程序的代码文件,可在目标应用程序运行与目标应用程序对应的该小程序的代码文件。用户终端12可包括手机、计算机、平板电脑等终端设备,在此并不限定。
图2为本申请实施例提供的小程序跨应用迁移方法的应用场景的另一示例的示意图。图1与图2的不同之处在于,编译设备11与设备13进行通信交互,设备13与用户终端12进行通信交互。具体地,编译设备11可 将生成的小程序在目标应用程序的代码文件上传至设备13,设备13将该代码文件下发给用户终端12。设备13可包括服务器等设备,在此并不限定。
在又一些示例中,该小程序跨应用迁移方法还可涉及目标应用程序的后台服务器。图3为本申请实施例提供的小程序跨应用迁移方法的应用场景的又一示例的示意图。图3与图1的不同之处在于,图3还可包括配置平台14。配置平台14可为用户终端12提供目标应用程序的各API版本对应的配置参数的值,以供用户终端12在目标应用程序运行小程序的过程中调用。
下面依次对小程序跨应用迁移方法、编译设备、用户终端、系统及存储介质进行介绍。
本申请第一方面提供一种小程序跨应用迁移方法,可用于编译设备,即该小程序跨应用迁移方法可由编译设备执行。图4为本申请第一方面提供的小程序跨应用迁移方法的一实施例的流程图。如图4所示,该小程序跨应用迁移方法可包括步骤S201至步骤S204。
在步骤S201中,解析原应用程序的小程序的原代码文件,生成原抽象语法树。
原应用程序为小程序迁移前所依附的应用程序。原代码文件是小程序能够在原应用程序运行的代码文件。原抽象语法树为与原应用程序对应的原代码文件的抽象语法树。
通过对原代码文件进行解析可生成与原代码文件对应的抽象语法树即原抽象语法树。原抽象语法树包括多个节点,节点可包括原代码文件中的变量、函数、事件、数据状态等。原代码文件中的逻辑细节可采用原抽象语法树中的分支以及分支中的节点表示。在抽象语法树中,某节点的子节点也是该抽象语法树中的节点。某节点的子节点可表征该节点的内容,也可为表征该节点的属性的子节点。变量可实现小程序中的一些动态内容,事件可用于响应用户操作,在此并不限定。
根据功能的不同,原代码文件可包括不同的文件。对应地,根据原代码文件中的各文件,可得到与各文件分别对应的抽象语法树。
在一些示例中,原代码文件可包括脚本文件、页面模版文件和样式文件。对应地,原抽象语法树可包括与脚本文件对应的第一原抽象语法树、与页面模版文件对应的第二原抽象语法树和与样式文件对应的第三原抽象语法树。
脚本文件具体可为Java脚本文件即JS文件,也可为其他前端语言的脚本文件,在此并不限定。解析原应用程序的小程序的脚本文件,得到与该脚本文件对应的抽象语法树即第一原抽象语法树。
页面模版文件为可应用于特定页面或页面组的特定类型的模板文件。小程序的页面模版文件可保证小程序的网页页面。解析原应用程序的小程序的页面模版文件,得到与该页面模版文件对应的抽象语法树即第二原抽象语法树。在一些示例中,可解析原代码文件中的页面模版文件,生成页面模版文件对应的文档对象模型(Document Object Model,DOM)树。抽取文档对象模型树中的程序逻辑,如if判断、for循环等,根据程序逻辑,将文档对象模型树转换为页面模版文件对应的抽象语法树即第二原抽象语法树。文档对象模型树具体可包括可扩展标记语言文档对象模型(Extensible Markup Language Document Object Model,XML DOM)树,在此并不限定。
样式文件可包括小程序的网页中元素的定义信息,例如标题和正文的默认字体、大小、颜色、前页外观、文字排列间隔等相关信息,在此并不限定。解析原应用程序的小程序的样式文件,得到与该样式文件对应的抽象语法树即第三原抽象语法树。
在步骤S202中,根据原抽象语法树和目标应用程序的目标转换规则,转换得到目标抽象语法树。
目标应用程序的目标转换规则为通用的将小程序符合原应用程序框架的抽象语法树转换为小程序符合目标应用程序框架的抽象语法树的转换规则。目标转换规则可预先编写设定。不同目标应用程序对应的目标转换规则不同。目标抽象语法树为与目标应用程序对应的原代码文件的抽象语法树,即符合目标应用程序框架的抽象语法树。
在一些示例中,原代码文件可包括脚本文件、页面模版文件和样式文 件。原抽象语法树可包括与脚本文件对应的第一原抽象语法树、与页面模版文件对应的第二原抽象语法树和与样式文件对应的第三原抽象语法树。对应地,目标抽象语法树可包括与脚本文件对应的第一目标抽象语法树、与页面模版文件对应的第二目标抽象语法树和与样式文件对应的第三目标抽象语法树。具体地,按照目标转换规则,可第一原抽象语法树转换为第一目标抽象语法树。按照目标转换规则,可第二原抽象语法树转换为第二目标抽象语法树。按照目标转换规则,可第三原抽象语法树转换为第三目标抽象语法树。在一些示例中,可解析原应用程序的小程序的样式文件,先得到中间阶段的抽象语法树,中间阶段的抽象语法树即为第三原抽象语法树,再将中间阶段的抽象语法树转换为第三目标抽象语法树。第三目标抽象语法树具体可包括叠层样式表抽象语法树(Cascading Style Sheets Abstract Syntax Tree,CSS AST),在此并不限定。
例如,图5为本申请实施例提供的与JS文件对应的目标抽象语法树的一示例的示意图。如图5所示,与JS文件对应的目标抽象语法树JS AST包括数据状态、生命周期函数、时间函数等节点。数据状态节点所在的分支还包括三个节点,均为数据状态的节点,分别表征变量a、变量b和变量c,在图5中分别以this.state.a、this.state.b和this.state.c表示。生命周期函数节点所在分支还包括四个节点,均为生命周期函数的节点,分别表征onInit函数、onShow函数、onUpdate函数和onHide函数,在图5中分别以onInit、onShow、onUpdate和onHide表示。事件函数节点所在的分支还包括一个节点,为事件函数的节点,表征dom_func_e函数,图5中该事件函数为点击事件函数,表征点击事件,在图5中以dom_func_e(this.on_btn_e_click)表示。
例如,图6为本申请实施例提供的与页面模版文件对应的目标抽象语法树的一示例的示意图。如图6所示,与页面模版文件对应的目标抽象语法树即页面模版AST包括多个节点。其中,节点Element1所在的分支还包括变量的节点,该节点表征变量a,在图6中以变量a表示。节点Element2所在的分支还包括节点Element4,节点Element4下方的两个分支各包括一个节点,一个节点为文档对象模型事件的节点,另一个节点为 变量的节点,文档对象模型事件的节点表征事件e,在图6中以事件e表示;变量的节点表征变量c,在图6中以变量c表示。节点Element3所在的分支还包括变量的节点,该变量的节点表征变量b,在图6中以变量b表示。
在步骤S203中,基于目标抽象语法树,生成小程序在目标应用程序的目标代码文件。
在得到目标抽象语法树后,可将目标抽象语法树转换为代码文件,转换得到的代码文件即为目标代码文件。目标代码文件为小程序在目标应用程序的代码文件。
在一些示例中,原代码文件包括脚本文件、页面模版文件和样式文件。目标抽象语法树包括与脚本文件对应的第一目标抽象语法树、与页面模版文件对应的第二目标抽象语法树和与样式文件对应的第三目标抽象语法树。可对第一目标抽象语法树和第二目标抽象语法树进行逻辑整合,得到目标程序代码文件。根据第三目标抽象语法树,生成目标样式文件。目标程序代码文件即为小程序与目标应用程序对应的程序代码文件,目标样式文件即为小程序与目标应用程序对应的样式文件。目标程序代码文件和目标样式文件可组合得到小程序在目标应用程序的目标代码文件。
在步骤S204中,将目标代码文件传输至用户终端,以使用户终端在目标应用程序运行目标代码文件的过程中,获取目标配置参数完成目标应用程序的API调用以实现小程序的功能。
在一些示例中,编译设备可在用户终端请求在目标应用程序运行小程序的情况下,直接将目标代码文件发送给用户终端,以使用户终端能够在目标应用程序运行该目标代码文件。
在另一些示例中,编译设备可将该目标代码文件先发送至另一中间设备,再由中间设备在用户终端请求在目标应用程序运行小程序的情况下,将目标代码文件发送给用户终端,实现目标代码文件由编译设备传输至用户终端的过程,以使用户终端能够在目标应用程序运行该目标代码文件。
目标配置参数包括与目标应用程序的应用程序编程接口当前API版本匹配的配置参数。用户终端在目标应用程序运行该目标代码文件的过程 中,需要获取与目标应用程序的当前API版本匹配的配置参数,不需要针对不同的API版本再对目标代码文件进行修改,就可实现小程序与不同API版本的功能适配。
在本申请实施例中,编译设备通过抽象语法树技术对原应用程序的小程序的原代码文件进行分析,得到原抽象语法树。利用与目标应用程序对应的目标转换规则,将原抽象语法树转换为符合目标应用程序框架的目标抽象语法树,再根据目标抽象语法树生成符合目标应用程序框架的小程序在目标应用程序的目标代码文件。编译设备可将目标代码文件传输至用户终端。编译设备编译得到的目标代码文件符合目标应用程序的框架,小程序可从原应用程序迁移至目标应用程序,可在用户终端的目标应用程序正常运行,且在运行过程中获取与目标应用程序的当前API版本匹配的配置参数完成对目标应用程序的API调用来实现小程序的功能,小程序可与不同API版本的功能适配,从而提高了小程序在不同应用程序的兼容性。
而且,本申请实施例中,编译设备可根据原应用程序的小程序的原代码文件,自动生成符合目标应用程序的框架的目标代码文件,也避免了人工改写程序不同开发人员水平不同所带来的小程序在目标应用程序运行的性能与稳定性的参差不齐,能够保证小程序在目标应用程序运行的性能与稳定性的一致,并提高开发效率。
下面介绍上述实施例中基于目标抽象语法树生成小程序在目标应用程序的目标代码文件的具体内容。在本实施例中,原代码文件包括脚本文件、页面模版文件和样式文件;目标抽象语法树包括与脚本文件对应的第一目标抽象语法树、与页面模版文件对应的第二目标抽象语法树和与样式文件对应的第三目标抽象语法树。图7为本申请第一方面提供的小程序跨应用迁移方法的另一实施例的流程图。图7与图4的不同之处在于,图4中的步骤S203可具体细化为图7中的步骤S2031至步骤S2034。
在步骤S2031中,绑定表征同一对象的第一目标抽象语法树中的节点与第二目标抽象语法树的节点。
绑定的第一目标抽象语法树中的节点与第二目标抽象语法树的节点表征的对象是同一对象。绑定的第一目标抽象语法树中的节点与第二目标抽 象语法树的节点具有绑定关系。
在一些示例中,第一目标抽象语法树中的节点可包括数据状态和事件函数,第二目标抽象语法树中的节点可包括变量和文档对象模式事件。具体可绑定表征同一对象的第一目标抽象语法树中数据状态和第二目标抽象语法树中变量,还可绑定表征同一对象的第一目标抽象语法树中事件函数和第二目标抽象语法树中文档对象模型事件。
例如,如图5和图6所示,图5中的数据状态的节点变量a和图6中的变量的节点变量a表征的对象均是变量a,可将图5中数据状态的节点变量a与图6中变量的节点变量a绑定;图5中的数据状态的节点变量b和图6中的变量的节点变量b表征的对象均是变量b,可将图5中数据状态的节点变量b与图6中变量的节点变量b绑定;图5中的数据状态的节点变量c和图6中的变量的节点变量c表征的对象均是变量c,可将图5中数据状态的节点变量c与图6中变量的节点变量c绑定;图5中事件函数的节点dom_func_e(this.on_btn_e_click)表征的是点击事件,图6中文档对象模型事件的节点事件e表征的是点击事件,可将图5中的事件函数的节点dom_func_e(this.on_btn_e_click)与图6中文档对象模型事件的节点事件e绑定。
在步骤S2032中,根据节点的绑定关系、第一目标抽象语法树中的函数和第二目标抽象语法树,得到目标程序代码文件。
根据节点的绑定关系,可确定第一目标抽象语法树与第二目标抽象语法树中表征同一对象的节点,从而可根据节点的绑定关系、第一目标抽象语法树中的函数和第二目标抽象语法树,实现第一目标抽象语法树与第二目标抽象语法树的逻辑整合,以得到目标程序代码文件。
具体地,可将第二目标抽象语法树中变量替换为绑定的数据状态,第二目标抽象语法树中文档对象模型事件替换为绑定的事件函数,得到更新后的第二目标抽象语法树;封装更新后的第二目标抽象语法树,得到渲染函数;封装第一目标抽象语法树中的函数,得到待调用函数;基于绑定的数据状态和变量、绑定的事件函数和文档对象模型事件、渲染函数以及待调用函数,得到目标程序代码文件。
为了便于理解,以第一目标抽象语法树为图5所示的抽象语法树、第二目标抽象语法树为图6所示的抽象语法树为例进行说明。可将第二目标抽象语法树中的变量替换为第一目标抽象语法树中的数据状态统一管理,可采用下方程序语言实现:
变量a=>this.state.a
变量b=>this.state.b
变量c=>this.state.c
再将第一目标抽象语法树中对变量的赋值调整为this.setState()的方式,可采用下方程序语言实现:
a=1=>this.setState({a:1})
b=2=>this.setState({b:2})
c=“hello world”=>this.setState({c:“hello world”})
通过this.setState()的方式来统一管理状态变量,小程序运行过程中会在调用生命周期函数中的onUpdate函数时进行优化渲染。
可将第二目标抽象语法树中的文档对象模型事件替换为第一目标抽象语法树中的点击事件函数,可采用下方程序语言实现:
onClick=”on_btn_e_click”=>onClick={this.on_btn_e_click}
将更新后的第二目标抽象语法树封装作为渲染函数。渲染函数可用于小程序的页面渲染。
在一些示例中,第一目标抽象语法树中的函数可包括业务函数和生命周期函数,但并不限于此。对应地,待调用函数包括封装业务函数得到的第一调用函数和封装生命周期函数得到的第二调用函数,但也并不限于此。在一些示例中,业务函数封装得到的第二调用函数可以以业务逻辑层的形式存在,即将业务函数封装为业务逻辑层。待调用函数可在小程序在目标应用程序运行的过程中被调用。根据绑定的数据状态和变量,可将变量以数据状态的形式管理。根据绑定的事件函数和文档对象模式事件,可将文档对象模式事件以事件函数的形式管理。目标程序代码文件可包括以数据状态的形式管理的变量和数据状态、以事件函数的形式管理的事件函数和文档对象模式事件、渲染函数和待调用函数。
在步骤S2033中,基于第三目标抽象语法树,得到目标样式文件。
目标样式文件为小程序与目标应用程序对应的样式文件。
在步骤S2034中,基于目标程序代码文件和目标样式文件,得到目标代码文件。
目标代码文件包括目标程序代码文件和目标样式文件。即目标程序代码文件和目标样式文件可组合得到小程序在目标应用程序的目标代码文件。
在一些实施例中,开发人员可能会在目标代码文件基础上进行调整,以实现自定义的个性化的二次开发。为了便于开发人员的个性化二次开发,编译设备自动生成的目标代码文件可包括注释,以提示指引开发人员,提高二次开发的效率。图8为本申请第一方面提供的小程序跨应用迁移方法的又一实施例的流程图。图8与图4的不同之处在于,图4中的步骤S202可具体细化为图8中的步骤S2021和步骤S2022。
在步骤S2021中,利用所述目标转换规则,将所述原抽象语法树转换为符合所述目标应用程序的框架的抽象语法树。
目标应用程序的框架与原应用程序的框架不同,对应地,目标应用程序对应的抽象语法树的形式与原应用程序对应的抽象语法树即原抽象语法树的形式不同。利用目标转换规则,可对原抽象语法树进行调整,以得到内容与原抽象语法树相同,但形式与目标应用程序对应的抽象语法树的形式相同的抽象语法树。
在步骤S2022中,在符合所述目标应用程序的抽象语法树中所述目标转换规则指示的位置插入注释,得到所述目标抽象语法树。
注释包括所述注释所在分支的功能开发指引说明。目标转换规则是针对目标应用程序的框架设定的,目标转换规则中记录有符合目标应用程序的框架的抽象语法树中表征各功能的分支、节点的位置。根据目标转换规则记录的符合目标应用程序的框架的抽象语法树中表征各功能的位置,可对应插入包括功能开发指引说明的注释。目标抽象语法树包括插入的注释。
例如,图9为本申请实施例提供的目标抽象语法树的局部的注释的一 示例的示意图。如图9所示,在目标抽象语法树的生命周期函数节点所在的分支上,可在节点语句1之前插入注释1。
根据目标抽象语法树生成的目标代码文件中的功能部分对应具有上述注释。开发人员可在目标代码文件中的注释的指引下遵循目标应用程序的最佳实践进行二次开发,尽量减小不同开发人员的开发差异,提高二次开发的效率。
本申请第二方面还提供一种小程序跨应用迁移方法,可应用于用户终端,即该小程序跨应用迁移方法可由用户终端执行。图10为本申请第二方面提供的小程序跨应用迁移方法的一实施例的流程图。如图10所示,该小程序跨应用迁移方法可包括步骤S301至步骤S303。
在步骤S301中,获取小程序在目标应用程序的目标代码文件。
目标代码文件由编译设备基于目标抽象语法树生成。目标抽象语法树由编译设备根据原抽象语法树和目标应用程序的目标转换规则转换得到的。原抽象语法树由编译设备解析原应用程序的小程序的原代码文件生成得到。
上述目标应用程序、目标代码文件等的具体内容可参见上述实施例中的相关说明,在此不再赘述。
在步骤S302中,在目标应用程序运行目标代码文件的过程中,获取目标配置参数。
在步骤S303中,利用目标配置参数完成目标应用程序的API调用,以实现小程序的功能。
目标配置参数包括与目标应用程序的当前API版本匹配的配置参数。原应用程序的API与目标应用程序的API的版本可能相同,也可能不同。目标代码文件在目标应用程序运行,需要调用目标应用程序的当前API版本下的API。可将与目标应用程序的当前API版本匹配的配置参数即目标配置参数传输给用户终端的本地层即native层执行功能代用。利用与目标应用程序的当前API版本匹配的配置参数,能够在不修改小程序的目标代码文件的基础上适配目标应用程序当前API版本的API的插件接口功能。
在本申请实施例中,用户终端可获取编译设备编译得到的目标代码文 件。目标代码文件是编译设备通过抽象语法树技术和目标应用程序对应的目标转换规则编译得到的。目标代码文件符合目标应用程序的框架,能够在用户终端的目标应用程序正常运行,小程序可从原应用程序迁移至目标应用程序。在目标代码文件在用户终端的目标应用程序运行的过程中,用户终端获取并利用与目标应用程序的当前API版本匹配的配置参数完成目标应用程序的API调用,实现小程序的功能,能够在不修改小程序的目标代码文件的基础上适配目标应用程序当前API版本的API的插件接口功能,提高小程序在不同应用程序的兼容性。
在一些实施例中,可通过对比原应用程序的API版本与目标应用程序的当前API版本,来确定目标配置参数。图11为本申请第二方面提供的小程序跨应用迁移方法的另一实施例的流程图。图11与图10的不同之处在于,图10中的步骤S302可具体细化为图11中的步骤S3021或步骤S3022。
在步骤S3021中,在原应用程序的API版本与目标应用程序的当前API版本一致的情况下,获取原应用程序的API版本对应的配置参数作为目标配置参数。
原应用程序的API版本与目标应用程序的当前API版本一致,表示原应用程序的API与目标应用程序的API的插件接口功能一致,即原应用程序的API版本对应的配置参数与目标应用程序的当前API版本对应的配置参数一致,原应用程序的API版本对应的配置参数在用户终端本地可获取到。
在步骤S3022中,在原应用程序的API版本与目标应用程序的当前API版本不一致的情况下,获取原应用程序的API版本对应的配置参数,以及从预先加载的API配置参数列表中获取新增配置参数作为目标配置参数。
新增配置参数为目标应用程序的当前API版本对应的配置参数中除原应用程序的API版本对应的配置参数以外的配置参数。API配置参数列表包括目标应用程序的各API版本对应的配置参数。
原应用程序的API版本与目标应用程序的当前API版本不一致,表示 原应用程序的API与目标应用程序的API的插件接口功能不一致,即原应用程序的API版本对应的配置参数与目标应用程序的当前API版本对应的配置参数不一致,原应用程序的API版本对应的配置参数在用户终端本地不能全部获取到。API配置参数列表可弥补用户终端本地数据的不足,可从API配置参数列表中获取与目标应用程序的当前API版本对应的配置参数。新增配置参数与原应用程序的API版本对应的配置参数组合即可满足目标应用程序的当前API版本的需求,从而能够在不修改小程序的目标代码文件的基础上适配目标应用程序当前API版本的API的插件接口功能,提高小程序在不同应用程序的兼容性。
例如,小程序在原应用程序调用获取地理定位的API的函数为get_location(),目标应用程序的API版本经过迭代后,目标应用程序的当前API版本增加了一个是否缓存当前地理定位信息供下次使用的配置参数,小程序在目标应用程序调用获取地理定位的API的函数变成了get_location(isCache),导致API的函数不一致。在本申请实施例中,可不修改目标程序代码文件中的代码,预先在用户终端加载API配置参数列表,API配置参数列表中包括各API版本对应的配置参数,当然也包括当前API版本对应的配置参数[isCache=True]。用户终端可获取到该配置参数[isCache=True],即可调用原应用程序的API的get_location()函数获取配置参数[isCache=True],以实现对目标应用程序的API的调用。
在一些示例中,上述实施例中,API配置参数列表根据原应用程序的API版本对应的配置参数和目标应用程序的各API版本对应的配置参数经去重、合并得到。API配置参数列表可由配置平台处理得到,在此并不限定。
具体地,配置平台可从小程序的目标代码文件或小程序的原代码文件可获取小程序在原应用程序的API版本对应的配置参数。配置平台可先将目标应用程序的各API版本对应的配置参数进行去重合并,得到第一配置参数集合。将小程序在原应用程序的API版本对应的配置参数于第一配置参数集合进行合并,得到上述实施例中的API配置参数列表。
例如,图12为本申请实施例提供的API配置参数列表的生成过程的 一示例的示意图。如图12所示,原应用程序为应用程序A,目标应用程序为应用程序B,应用程序B的的API具有N个版本,分别为API 1至API N。应用程序A的API版本对应的配置参数包括a’和b’;应用程序B的API 1版本对应的配置参数包括a;应用程序B的API 2版本对应的配置参数包括a和b;……,应用程序B的API N版本对应的配置参数包括a、b、c、……、n;其中,配置参数a’与配置参数a相同,配置参数b’与配置参数b相同。应用程序B的各API版本的配置参数去重合并后,得到的第一配置参数集合包括a、b、c、……、n。应用程序A的API版本对应的配置参数与第一配置参数集合合并后,得到的API配置参数列表包括a’、b’、c、……、n。
通过去重、合并处理得到的API配置参数列表能够减少无用的冗余数据,减少API配置参数列表占用的资源,避免API配置参数列表占用大量资源以影响用户终端的性能。
在一些示例中,在步骤S302在之前,用户终端可在小程序在目标应用程序中初始化时,加载配置平台下发的API配置参数列表。在小程序第二次、第三次等后续次数的运行中,不需要反复向加载配置平台请求该API配置参数列表。
在本申请实施例中,编译设备和用户终端可设置各类引擎以实现小程序跨应用迁移方法。图13为本申请实施例提供的小程序跨应用迁移过程的一示例的示意图。如图13所示,原应用程序为应用程序A,目标应用程序为应用程序B;编译设备设置有Java脚本文件抽象语法树转换引擎(简称为JS AST转换引擎)、页面模版文件转换引擎(简称模版转换引擎)、样式文件转换引擎(简称样式转换引擎)和逻辑整合引擎;用户终端设置有API动态适配引擎。
小程序的原代码文件包括JS文件、页面模版文件和样式文件,JS文件输入JS AST转换引擎,页面模版文件输入模版转换引擎,样式文件输入样式转换引擎。JS AST转换引擎和模版转换引擎的输出通入逻辑整合引擎的输入。逻辑整合引擎输出目标程序代码文件,样式转换引擎输出目标样式文件。目标程序代码文件和目标样式文件组成目标代码文件。目标代 码文件可传输至API动态适配引擎,由API动态适配引擎在运行目标代码文件的过程中获取与目标应用程序的当前API版本匹配的配置参数利用目标配置参数完成目标应用程序的API调用,以实现小程序的功能。
本申请第三方面可提供一种编译设备。图14为本申请第三方面提供的编译设备的一实施例的结构示意图。如图14所示,该编译设备400可包括解析模块401、转换模块402、文件生成模块403和通信模块404。
解析模块401可用于解析原应用程序的小程序的原代码文件,生成原抽象语法树。
原抽象语法树为与原应用程序对应的原代码文件的抽象语法树。
转换模块402可用于根据原抽象语法树和目标应用程序的目标转换规则,转换得到目标抽象语法树。
目标抽象语法树为与目标应用程序对应的原代码文件的抽象语法树。
文件生成模块403可用于基于目标抽象语法树,生成小程序在目标应用程序的目标代码文件。
通信模块404用于将目标代码文件传输至用户终端,以使用户终端在目标应用程序运行目标代码文件的过程中,获取目标配置参数完成目标应用程序的应用程序编程接口API调用以实现小程序的功能。
目标配置参数包括与目标应用程序的当前API版本匹配的配置参数。
在一些示例中,原代码文件包括脚本文件、页面模版文件和样式文件。
原抽象语法树包括与脚本文件对应的第一原抽象语法树、与页面模版文件对应的第二原抽象语法树和与样式文件对应的第三原抽象语法树。
目标抽象语法树包括与脚本文件对应的第一目标抽象语法树、与页面模版文件对应的第二目标抽象语法树和与样式文件对应的第三目标抽象语法树。
在本申请实施例中,编译设备通过抽象语法树技术对原应用程序的小程序的原代码文件进行分析,得到原抽象语法树。利用与目标应用程序对应的目标转换规则,将原抽象语法树转换为符合目标应用程序框架的目标抽象语法树,再根据目标抽象语法树生成符合目标应用程序框架的小程序 在目标应用程序的目标代码文件。编译设备可将目标代码文件传输至用户终端。编译设备编译得到的目标代码文件符合目标应用程序的框架,小程序可从原应用程序迁移至目标应用程序,可在用户终端的目标应用程序正常运行,且在运行过程中获取与目标应用程序的当前API版本匹配的配置参数完成对目标应用程序的API调用来实现小程序的功能,小程序可与不同API版本的功能适配,从而提高了小程序在不同应用程序的兼容性。
而且,本申请实施例中,编译设备可根据原应用程序的小程序的原代码文件,自动生成符合目标应用程序的框架的目标代码文件,也避免了人工改写程序不同开发人员水平不同所带来的小程序在目标应用程序运行的性能与稳定性的参差不齐,能够保证小程序在目标应用程序运行的性能与稳定性的一致,并提高开发效率。
图15为本申请第三方面提供的编译设备的另一实施例的结构示意图。图15与图14的不同之处在于,图15所示的文件生成模块403可包括绑定单元4031和文件生成单元4032。
绑定单元4031可用于绑定表征同一对象的第一目标抽象语法树中的节点与第二目标抽象语法树的节点。
文件生成单元4032可用于:根据节点的绑定关系、第一目标抽象语法树中的函数和第二目标抽象语法树,得到目标程序代码文件;基于第三目标抽象语法树,得到目标样式文件;基于目标程序代码文件和目标样式文件,得到目标代码文件。
目标代码文件包括目标程序代码文件和目标样式文件。
在一些示例中,第一目标抽象语法树中的节点包括数据状态和事件函数。第二目标抽象语法树中的节点包括变量和文档对象模型事件。
绑定单元4031可用于:绑定表征同一对象的第一目标抽象语法树中数据状态和第二目标抽象语法树中变量;绑定表征同一对象的第一目标抽象语法树中事件函数和第二目标抽象语法树中文档对象模型事件。
文件生成单元4032可用于:将第二目标抽象语法树中变量替换为绑定的数据状态,第二目标抽象语法树中文档对象模型事件替换为绑定的事件函数,得到更新后的第二目标抽象语法树;封装更新后的第二目标抽象 语法树,得到渲染函数;封装第一目标抽象语法树中的函数,得到待调用函数;基于绑定的数据状态和变量、绑定的事件函数和文档对象模型事件、渲染函数以及待调用函数,得到目标程序代码文件。
在一些示例中,第一目标抽象语法树中的函数包括业务函数和生命周期函数。待调用函数包括封装业务函数得到的第一调用函数和封装生命周期函数得到的第二调用函数。
在一些实施例中,原代码文件包括页面模版文件。
解析模块401可用于解析原代码文件中的页面模版文件,生成页面模版文件对应的文档对象模型树;抽取文档对象模型树的程序逻辑,根据程序逻辑,将文档对象模型树转换为页面模版文件对应的第二原抽象语法树。
在一些示例中,转换模块402可用于:利用目标转换规则,将原抽象语法树转换为符合目标应用程序的框架的抽象语法树;在符合目标应用程序的抽象语法树中目标转换规则指示的位置插入注释,得到目标抽象语法树,注释包括注释所在分支的功能开发指引说明。
本申请第四方面还提供一种用户终端,该用户终端安装有目标应用程序。图16为本申请第四方面提供的用户终端的一实施例的结构示意图。如图16所示,该用户终端500可包括第一获取模块501、第二获取模块502和调用模块503。
第一获取模块501可用于获取小程序在目标应用程序的目标代码文件。
目标代码文件由编译设备基于目标抽象语法树生成。目标抽象语法树由编译设备根据原抽象语法树和目标应用程序的目标转换规则转换得到的。原抽象语法树由编译设备解析原应用程序的小程序的原代码文件生成得到。
第二获取模块502可在目标应用程序运行目标代码文件的过程中,获取目标配置参数。
目标配置参数包括与目标应用程序的当前应用程序编程接口API版本匹配的配置参数。
调用模块503可用于利用目标配置参数完成目标应用程序的API调用,以实现小程序的功能。
在本申请实施例中,用户终端可获取编译设备编译得到的目标代码文件。目标代码文件是编译设备通过抽象语法树技术和目标应用程序对应的目标转换规则编译得到的。目标代码文件符合目标应用程序的框架,能够在用户终端的目标应用程序正常运行,小程序可从原应用程序迁移至目标应用程序。在目标代码文件在用户终端的目标应用程序运行的过程中,用户终端获取并利用与目标应用程序的当前API版本匹配的配置参数完成目标应用程序的API调用,实现小程序的功能,能够在不修改小程序的目标代码文件的基础上适配目标应用程序当前API版本的API的插件接口功能,提高小程序在不同应用程序的兼容性。
在一些实施例中,上述第二获取模块502可用于:在原应用程序的API版本与目标应用程序的当前API版本一致的情况下,获取原应用程序的API版本对应的配置参数作为目标配置参数;在原应用程序的API版本与目标应用程序的当前API版本不一致的情况下,获取原应用程序的API版本对应的配置参数,以及从预先加载的API配置参数列表中获取新增配置参数作为目标配置参数。
新增配置参数为目标应用程序的当前API版本对应的配置参数中除原应用程序的API版本对应的配置参数以外的配置参数。API配置参数列表包括目标应用程序的各API版本对应的配置参数。
在一些示例中,API配置参数列表根据原应用程序的API版本对应的配置参数和目标应用程序的各API版本对应的配置参数经去重、合并得到。
图17为本申请第四方面提供的用户终端的另一实施例的结构示意图。图17与图16的不同之处在于,图17所示的用户终端500还可包括加载模块504。
加载模块504可用于在小程序在目标应用程序中初始化时,加载配置平台下发的API配置参数列表。
本申请第五方面还提供了一种编译设备。图18为本申请第五方面提 供的编译设备的一实施例的结构示意图。如图18所示,编译设备600包括存储器601、处理器602及存储在存储器601上并可在处理器602上运行的计算机程序。
在一个示例中,上述处理器602可以包括中央处理器(CPU),或者特定集成电路(Application Specific Integrated Circuit,ASIC),或者可以被配置成实施本申请实施例的一个或多个集成电路。
存储器601可包括只读存储器(Read-Only Memory,ROM),随机存取存储器(Random Access Memory,RAM),磁盘存储介质设备,光存储介质设备,闪存设备,电气、光学或其他物理/有形的存储器存储设备。因此,通常,存储器包括一个或多个编码有包括计算机可执行指令的软件的有形(非暂态)计算机可读存储介质(例如,存储器设备),并且当该软件被执行(例如,由一个或多个处理器)时,其可操作来执行参考根据本申请实施例中应用于编译设备的小程序跨应用迁移方法所描述的操作。
处理器602通过读取存储器601中存储的可执行程序代码来运行与可执行程序代码对应的计算机程序,以用于实现上述实施例中应用于编译设备的小程序跨应用迁移方法。
在一个示例中,编译设备600还可包括通信接口603和总线604。其中,如图18所示,存储器601、处理器602、通信接口603通过总线604连接并完成相互间的通信。
通信接口603,主要用于实现本申请实施例中各模块、装置、单元和/或设备之间的通信。也可通过通信接口603接入输入设备和/或输出设备。
总线604包括硬件、软件或两者,将编译设备600的部件彼此耦接在一起。举例来说而非限制,总线604可包括加速图形端口(Accelerated Graphics Port,AGP)或其他图形总线、增强工业标准架构(Enhanced Industry Standard Architecture,EISA)总线、前端总线(Front Side Bus,FSB)、超传输(Hyper Transport,HT)互连、工业标准架构(Industry Standard Architecture,ISA)总线、无限带宽互连、低引脚数(Low pin count,LPC)总线、存储器总线、微信道架构(Micro Channel Architecture,MCA)总线、外围组件互连(Peripheral Component  Interconnect,PCI)总线、PCI-Express(PCI-E)总线、串行高级技术附件(Serial Advanced Technology Attachment,SATA)总线、视频电子标准协会局部(Video Electronics Standards Association Local Bus,VLB)总线或其他合适的总线或者两个或更多个以上这些的组合。在合适的情况下,总线604可包括一个或多个总线。尽管本申请实施例描述和示出了特定的总线,但本申请考虑任何合适的总线或互连。
本申请第六方面还提供了一种用户终端。图19为本申请第六方面提供的用户终端的一实施例的结构示意图。如图19所示,用户终端700包括存储器701、处理器702及存储在存储器701上并可在处理器702上运行的计算机程序。
在一个示例中,上述处理器702可以包括中央处理器(CPU),或者特定集成电路(Application Specific Integrated Circuit,ASIC),或者可以被配置成实施本申请实施例的一个或多个集成电路。
存储器701可包括只读存储器(Read-Only Memory,ROM),随机存取存储器(Random Access Memory,RAM),磁盘存储介质设备,光存储介质设备,闪存设备,电气、光学或其他物理/有形的存储器存储设备。因此,通常,存储器包括一个或多个编码有包括计算机可执行指令的软件的有形(非暂态)计算机可读存储介质(例如,存储器设备),并且当该软件被执行(例如,由一个或多个处理器)时,其可操作来执行参考根据本申请实施例中应用于用户终端的小程序跨应用迁移方法所描述的操作。
处理器702通过读取存储器701中存储的可执行程序代码来运行与可执行程序代码对应的计算机程序,以用于实现上述实施例中应用于用户终端的小程序跨应用迁移方法。
在一个示例中,用户终端700还可包括通信接口703和总线704。其中,如图19所示,存储器701、处理器702、通信接口703通过总线704连接并完成相互间的通信。
通信接口703,主要用于实现本申请实施例中各模块、装置、单元和/或设备之间的通信。也可通过通信接口703接入输入设备和/或输出设备。
总线704包括硬件、软件或两者,将用户终端700的部件彼此耦接在 一起。举例来说而非限制,总线704可包括加速图形端口(Accelerated Graphics Port,AGP)或其他图形总线、增强工业标准架构(Enhanced Industry Standard Architecture,EISA)总线、前端总线(Front Side Bus,FSB)、超传输(Hyper Transport,HT)互连、工业标准架构(Industry Standard Architecture,ISA)总线、无限带宽互连、低引脚数(Low pin count,LPC)总线、存储器总线、微信道架构(Micro Channel Architecture,MCA)总线、外围组件互连(Peripheral Component Interconnect,PCI)总线、PCI-Express(PCI-E)总线、串行高级技术附件(Serial Advanced Technology Attachment,SATA)总线、视频电子标准协会局部(Video Electronics Standards Association Local Bus,VLB)总线或其他合适的总线或者两个或更多个以上这些的组合。在合适的情况下,总线704可包括一个或多个总线。尽管本申请实施例描述和示出了特定的总线,但本申请考虑任何合适的总线或互连。
本申请第七方面还提供一种小程序跨应用迁移系统。该小程序跨应用迁移系统可包括上述实施例中的编译设备和用户终端。编译设备和用户终端所执行的小程序跨应用迁移方法的具体内容以及有益效果可参见上述实施例中的相关描述,在此不再赘述。
本申请第八方面还提供一种计算机可读存储介质,该计算机可读存储介质上存储有计算机程序指令,该计算机程序指令被处理器执行时可实现上述实施例中应用于编译设备的小程序跨应用迁移方法或用于用户终端的小程序跨应用迁移方法,且能达到相同的技术效果,为避免重复,这里不再赘述。其中,上述计算机可读存储介质可包括非暂态计算机可读存储介质,如只读存储器(Read-Only Memory,简称ROM)、随机存取存储器(Random Access Memory,简称RAM)、磁碟或者光盘等,在此并不限定。
需要明确的是,本说明书中的各个实施例均采用递进的方式描述,各个实施例之间相同或相似的部分互相参见即可,每个实施例重点说明的都是与其他实施例的不同之处。对于编译设备实施例、用户终端实施例、系统实施例、计算机可读存储介质实施例而言,相关之处可以参见方法实施 例的说明部分。本申请并不局限于上文所描述并在图中示出的特定步骤和结构。本领域的技术人员可以在领会本申请的精神之后,作出各种改变、修改和添加,或者改变步骤之间的顺序。并且,为了简明起见,这里省略对已知方法技术的详细描述。
上面参考根据本申请的实施例的方法、装置(系统)和计算机程序产品的流程图和/或框图描述了本申请的各方面。应当理解,流程图和/或框图中的每个方框以及流程图和/或框图中各方框的组合可以由计算机程序指令实现。这些计算机程序指令可被提供给通用计算机、专用计算机、或其它可编程数据处理装置的处理器,以产生一种机器,使得经由计算机或其它可编程数据处理装置的处理器执行的这些指令使能对流程图和/或框图的一个或多个方框中指定的功能/动作的实现。这种处理器可以是但不限于是通用处理器、专用处理器、特殊应用处理器或者现场可编程逻辑电路。还可理解,框图和/或流程图中的每个方框以及框图和/或流程图中的方框的组合,也可以由执行指定的功能或动作的专用硬件来实现,或可由专用硬件和计算机指令的组合来实现。
本领域技术人员应能理解,上述实施例均是示例性而非限制性的。在不同实施例中出现的不同技术特征可以进行组合,以取得有益效果。本领域技术人员在研究附图、说明书及权利要求书的基础上,应能理解并实现所揭示的实施例的其他变化的实施例。在权利要求书中,术语“包括”并不排除其他装置或步骤;数量词“一个”不排除多个;术语“第一”、“第二”用于标示名称而非用于表示任何特定的顺序。权利要求中的任何附图标记均不应被理解为对保护范围的限制。权利要求中出现的多个部分的功能可以由一个单独的硬件或软件模块来实现。某些技术特征出现在不同的从属权利要求中并不意味着不能将这些技术特征进行组合以取得有益效果。

Claims (17)

  1. 一种小程序跨应用迁移方法,应用于编译设备,所述方法包括:
    解析原应用程序的小程序的原代码文件,生成原抽象语法树,所述原抽象语法树为与所述原应用程序对应的所述原代码文件的抽象语法树;
    根据所述原抽象语法树和目标应用程序的目标转换规则,转换得到目标抽象语法树,所述目标抽象语法树为与所述目标应用程序对应的所述原代码文件的抽象语法树;
    基于所述目标抽象语法树,生成所述小程序在所述目标应用程序的目标代码文件;
    将所述目标代码文件传输至用户终端,以使所述用户终端在所述目标应用程序运行所述目标代码文件的过程中,获取目标配置参数完成所述目标应用程序的应用程序编程接口API调用以实现所述小程序的功能,所述目标配置参数包括与所述目标应用程序的当前API版本匹配的配置参数。
  2. 根据权利要求1所述的方法,其中,
    所述原代码文件包括脚本文件、页面模版文件和样式文件;
    所述原抽象语法树包括与所述脚本文件对应的第一原抽象语法树、与所述页面模版文件对应的第二原抽象语法树和与所述样式文件对应的第三原抽象语法树;
    所述目标抽象语法树包括与所述脚本文件对应的第一目标抽象语法树、与所述页面模版文件对应的第二目标抽象语法树和与所述样式文件对应的第三目标抽象语法树。
  3. 根据权利要求2所述的方法,其中,所述基于所述目标抽象语法树,生成所述小程序在所述目标应用程序的目标代码文件,包括:
    绑定表征同一对象的第一目标抽象语法树中的节点与所述第二目标抽象语法树的节点;
    根据节点的绑定关系、所述第一目标抽象语法树中的函数和所述第二目标抽象语法树,得到目标程序代码文件;
    基于第三目标抽象语法树,得到目标样式文件;
    基于所述目标程序代码文件和所述目标样式文件,得到所述目标代码文件,所述目标代码文件包括所述目标程序代码文件和所述目标样式文件。
  4. 根据权利要求3所述的方法,其中,所述第一目标抽象语法树中的节点包括数据状态和事件函数,所述第二目标抽象语法树中的节点包括变量和文档对象模型事件;
    所述绑定表征同一对象的第一目标抽象语法树中的节点与所述第二目标抽象语法树的节点,包括:
    绑定表征同一对象的所述第一目标抽象语法树中所述数据状态和所述第二目标抽象语法树中所述变量;
    绑定表征同一对象的所述第一目标抽象语法树中所述事件函数和所述第二目标抽象语法树中所述文档对象模型事件;
    所述根据节点的绑定关系、所述第一目标抽象语法树中的函数和所述第二目标抽象语法树,得到目标程序代码文件,包括:
    将所述第二目标抽象语法树中所述变量替换为绑定的所述数据状态,所述第二目标抽象语法树中所述文档对象模型事件替换为绑定的所述事件函数,得到更新后的所述第二目标抽象语法树;
    封装更新后的所述第二目标抽象语法树,得到渲染函数;
    封装所述第一目标抽象语法树中的函数,得到待调用函数;
    基于绑定的所述数据状态和所述变量、绑定的所述事件函数和所述文档对象模型事件、所述渲染函数以及所述待调用函数,得到所述目标程序代码文件。
  5. 根据权利要求4所述的方法,其中,
    所述第一目标抽象语法树中的函数包括业务函数和生命周期函数;
    所述待调用函数包括封装所述业务函数得到的第一调用函数和封装所述生命周期函数得到的第二调用函数。
  6. 根据权利要求1所述的方法,其中,所述原代码文件包括页面模版文件,
    所述解析原应用程序的小程序的原代码文件,生成原抽象语法树,包 括:
    解析所述原代码文件中的所述页面模版文件,生成所述页面模版文件对应的文档对象模型树;
    抽取所述文档对象模型树的程序逻辑,根据所述程序逻辑,将所述文档对象模型树转换为所述页面模版文件对应的第二原抽象语法树。
  7. 根据权利要求1所述的方法,其中,所述根据所述原抽象语法树和目标应用程序的目标转换规则,转换得到目标抽象语法树,包括:
    利用所述目标转换规则,将所述原抽象语法树转换为符合所述目标应用程序的框架的抽象语法树;
    在符合所述目标应用程序的抽象语法树中所述目标转换规则指示的位置插入注释,得到所述目标抽象语法树,所述注释包括所述注释所在分支的功能开发指引说明。
  8. 一种小程序跨应用迁移方法,应用于用户终端,所述用户终端安装有目标应用程序,所述方法包括:
    获取小程序在所述目标应用程序的目标代码文件,所述目标代码文件由编译设备基于目标抽象语法树生成,所述目标抽象语法树由所述编译设备根据原抽象语法树和所述目标应用程序的目标转换规则转换得到的,所述原抽象语法树由所述编译设备解析原应用程序的所述小程序的原代码文件生成得到;
    在所述目标应用程序运行所述目标代码文件的过程中,获取目标配置参数,所述目标配置参数包括与所述目标应用程序的当前应用程序编程接口API版本匹配的配置参数;
    利用所述目标配置参数完成所述目标应用程序的API调用,以实现所述小程序的功能。
  9. 根据权利要求8所述的方法,其中,所述获取目标配置参数的值,包括:
    在所述原应用程序的API版本与所述目标应用程序的当前API版本一致的情况下,获取原应用程序的API版本对应的配置参数作为所述目标配置参数;
    在所述原应用程序的API版本与所述目标应用程序的当前API版本不一致的情况下,获取所述原应用程序的API版本对应的配置参数,以及从预先加载的API配置参数列表中获取新增配置参数作为所述目标配置参数,所述新增配置参数为所述目标应用程序的当前API版本对应的配置参数中除所述原应用程序的API版本对应的配置参数以外的配置参数,所述API配置参数列表包括所述目标应用程序的各API版本对应的配置参数。
  10. 根据权利要求9所述的方法,其中,所述API配置参数列表根据原应用程序的API版本对应的配置参数和所述目标应用程序的各API版本对应的配置参数经去重、合并得到。
  11. 根据权利要求9所述的方法,在所述获取目标配置参数之前,还包括:
    在所述小程序在所述目标应用程序中初始化时,加载配置平台下发的所述API配置参数列表。
  12. 一种编译设备,包括:
    解析模块,用于解析原应用程序的小程序的原代码文件,生成原抽象语法树,所述原抽象语法树为与所述原应用程序对应的所述原代码文件的抽象语法树;
    转换模块,用于根据所述原抽象语法树和目标应用程序的目标转换规则,转换得到目标抽象语法树,所述目标抽象语法树为与所述目标应用程序对应的所述原代码文件的抽象语法树;
    文件生成模块,用于基于所述目标抽象语法树,生成所述小程序在所述目标应用程序的目标代码文件;
    通信模块,用于将所述目标代码文件传输至用户终端,以使所述用户终端在所述目标应用程序运行所述目标代码文件的过程中,获取目标配置参数完成所述目标应用程序的应用程序编程接口API调用以实现所述小程序的功能,所述目标配置参数包括与所述目标应用程序的当前API版本匹配的配置参数。
  13. 一种用户终端,所述用户终端安装有目标应用程序,所述用户终端包括:
    第一获取模块,用于获取小程序在所述目标应用程序的目标代码文件,所述目标代码文件由编译设备基于目标抽象语法树生成,所述目标抽象语法树由所述编译设备根据原抽象语法树和所述目标应用程序的目标转换规则转换得到的,所述原抽象语法树由所述编译设备解析原应用程序的所述小程序的原代码文件生成得到;
    第二获取模块,在所述目标应用程序运行所述目标代码文件的过程中,获取目标配置参数,所述目标配置参数包括与所述目标应用程序的当前应用程序编程接口API版本匹配的配置参数;
    调用模块,用于利用所述目标配置参数完成所述目标应用程序的API调用,以实现所述小程序的功能。
  14. 一种编译设备,包括:处理器以及存储有计算机程序指令的存储器;
    所述处理器执行所述计算机程序指令时实现如权利要求1至7中任意一项所述的小程序跨应用迁移方法。
  15. 一种用户终端,包括:处理器以及存储有计算机程序指令的存储器;
    所述处理器执行所述计算机程序指令时实现如权利要求8至11中任意一项所述的小程序跨应用迁移方法。
  16. 一种小程序跨应用迁移系统,包括如权利要求14所述的编译设备和如权利要求15所述的用户终端。
  17. 一种计算机可读存储介质,所述计算机可读存储介质上存储有计算机程序指令,所述计算机程序指令被处理器执行时实现如权利要求1至11中任意一项所述的小程序跨应用迁移方法。
PCT/CN2022/079174 2021-09-10 2022-03-04 小程序跨应用迁移方法、设备、终端、系统及存储介质 WO2023035563A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202111064530.9 2021-09-10
CN202111064530.9A CN113805890A (zh) 2021-09-10 2021-09-10 小程序跨应用迁移方法、设备、终端、系统及存储介质

Publications (1)

Publication Number Publication Date
WO2023035563A1 true WO2023035563A1 (zh) 2023-03-16

Family

ID=78895078

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/079174 WO2023035563A1 (zh) 2021-09-10 2022-03-04 小程序跨应用迁移方法、设备、终端、系统及存储介质

Country Status (2)

Country Link
CN (1) CN113805890A (zh)
WO (1) WO2023035563A1 (zh)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113805890A (zh) * 2021-09-10 2021-12-17 中国银联股份有限公司 小程序跨应用迁移方法、设备、终端、系统及存储介质
CN114185551B (zh) * 2022-02-17 2022-06-21 浙江口碑网络技术有限公司 小程序的编译方法、小程序的运行方法及装置、存储介质
CN118069286A (zh) * 2022-11-23 2024-05-24 华为技术有限公司 应用迁移方法及电子设备

Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107273118A (zh) * 2017-05-31 2017-10-20 湖南机友科技有限公司 一种应用程序多开的实现方法及装置
US20190012153A1 (en) * 2017-07-07 2019-01-10 Beijing Xiaomi Mobile Software Co., Ltd. Method and device for supporting multi-framework syntax
CN109947433A (zh) * 2019-03-28 2019-06-28 优信拍(北京)信息科技有限公司 一种小程序的生成方法、更新方法及装置
CN110442344A (zh) * 2019-08-14 2019-11-12 中国工商银行股份有限公司 用于跨平台转换应用的方法、装置、系统及介质
CN110457065A (zh) * 2019-08-14 2019-11-15 中国工商银行股份有限公司 用于获得可兼容多版本系统的应用的方法及装置
CN110968325A (zh) * 2019-10-28 2020-04-07 苏宁云计算有限公司 一种小程序转换方法及装置
CN111610978A (zh) * 2020-05-19 2020-09-01 中国建设银行股份有限公司 一种小程序转换方法、装置、设备及存储介质
CN112416328A (zh) * 2020-12-11 2021-02-26 广州伊智信息科技有限公司 多平台小程序商城的构建方法、装置、设备及介质
CN113805890A (zh) * 2021-09-10 2021-12-17 中国银联股份有限公司 小程序跨应用迁移方法、设备、终端、系统及存储介质

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102298537A (zh) * 2011-06-10 2011-12-28 宇龙计算机通信科技(深圳)有限公司 应用程序的迁移方法及系统
CN103257878A (zh) * 2013-05-16 2013-08-21 浪潮通信信息系统有限公司 一种基于云计算的应用程序的跨平台平滑迁移方法
CN109918073A (zh) * 2019-01-29 2019-06-21 维沃移动通信有限公司 一种源码文件的生成方法、装置以及终端
CN111736840A (zh) * 2019-09-19 2020-10-02 北京沃东天骏信息技术有限公司 小程序应用的编译方法、运行方法、存储介质及电子设备

Patent Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107273118A (zh) * 2017-05-31 2017-10-20 湖南机友科技有限公司 一种应用程序多开的实现方法及装置
US20190012153A1 (en) * 2017-07-07 2019-01-10 Beijing Xiaomi Mobile Software Co., Ltd. Method and device for supporting multi-framework syntax
CN109947433A (zh) * 2019-03-28 2019-06-28 优信拍(北京)信息科技有限公司 一种小程序的生成方法、更新方法及装置
CN110442344A (zh) * 2019-08-14 2019-11-12 中国工商银行股份有限公司 用于跨平台转换应用的方法、装置、系统及介质
CN110457065A (zh) * 2019-08-14 2019-11-15 中国工商银行股份有限公司 用于获得可兼容多版本系统的应用的方法及装置
CN110968325A (zh) * 2019-10-28 2020-04-07 苏宁云计算有限公司 一种小程序转换方法及装置
CN111610978A (zh) * 2020-05-19 2020-09-01 中国建设银行股份有限公司 一种小程序转换方法、装置、设备及存储介质
CN112416328A (zh) * 2020-12-11 2021-02-26 广州伊智信息科技有限公司 多平台小程序商城的构建方法、装置、设备及介质
CN113805890A (zh) * 2021-09-10 2021-12-17 中国银联股份有限公司 小程序跨应用迁移方法、设备、终端、系统及存储介质

Also Published As

Publication number Publication date
CN113805890A (zh) 2021-12-17

Similar Documents

Publication Publication Date Title
CN110825362B (zh) 低代码应用软件开发系统及方法
WO2023035563A1 (zh) 小程序跨应用迁移方法、设备、终端、系统及存储介质
CN111708539B (zh) 一种应用程序代码转换方法、装置、电子设备和存储介质
US8997070B2 (en) Extension mechanism for scripting language compiler
US8707263B2 (en) Using a DSL for calling APIS to test software
CN107861728B (zh) 用于传统程序语言向现代程序语言转换的方法及其系统
WO2019233293A1 (zh) 一种应用程序的开发方法和装置
CN107665216B (zh) 一种数据库访问方法及中间件
CN112104709B (zh) 智能合约的处理方法、装置、介质及电子设备
US10592220B2 (en) Metadata-driven binding of converted source code to original source code
CN111078555B (zh) 一种测试文件的生成方法、系统、服务器和存储介质
CN110825430A (zh) 一种api文档生成方法、装置、设备及存储介质
WO2018233673A1 (zh) 一种控制器中模型代码配置方法和装置、存储介质
US11650901B2 (en) Automated generation of software patches
CN114153459A (zh) 接口文档生成方法及装置
CN113031932A (zh) 项目开发方法、装置、电子设备及存储介质
CN113778897B (zh) 接口的自动测试方法、装置、设备及存储介质
WO2021259290A1 (zh) 存储过程转换方法、装置、设备和存储介质
CN105867886B (zh) 一种写表格的方法及装置
CN107239265B (zh) Java函数与C函数的绑定方法及装置
WO2022099913A1 (zh) 界面配置方法、装置、设备及介质
CN113448874A (zh) 一种单元测试脚本的生成方法及装置
CN113885841A (zh) 脚本生成的方法、装置、电子设备和可读介质
CN114579141A (zh) require框架转化为VUE框架的方法及装置
CN109725932B (zh) 一种应用组件的说明文档生成方法和装置

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: 22866041

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE