Position index file generation method and device and source code positioning method and device

By generating a location index file, the identifier position mapping relationship between the applet executable file and the source code file is stored in the second location index file, which solves the problem that the applet executable file cannot be restored to the source code file, and realizes the applet Source code restoration of executable files and accurate positioning of exception locations.

CN119003680APending Publication Date: 2024-11-22BEIJING DIDI INFINITY TECH & DEV CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310545656.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-05-15
Publication Date
2024-11-22

AI Technical Summary

Technical Problem

The mini program executable file cannot be restored to the source file, resulting in the inability to accurately locate the cause of the error when an exception occurs during operation.

Method used

By generating a location index file, the identifier position mapping relationship between the applet executable file and the source code file is stored in the second location index file, thereby realizing the source code restoration of the applet executable file and positioning the target identifier in the source code based on this. Location in the file.

Benefits of technology

It realizes the source code restoration of the applet executable file, improves the accuracy of exception handling, and can accurately locate the error location in the applet executable file.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119003680A_ABST
    Figure CN119003680A_ABST
Patent Text Reader

Abstract

The invention provides a position index file generation method and device and a source code positioning method and device. The method comprises the steps that source code analysis is conducted on a file obtained after applet cross-end compiling through a first position index file, and identifier attribute information in a source code file is obtained; wherein the first position index file comprises an identifier position mapping relation between a file obtained after cross-end compilation of the applet and a source code file; the identifier attribute information comprises an identifier and original position information corresponding to the identifier; generating a second position index file according to the first position index file and the original position information corresponding to the identifier; the second position index file comprises an identifier position mapping relation between the applet executable file and the source code file; the applet executable file is generated by compiling a file after cross-end compilation of the applet. Due to the fact that the identifier position mapping relation between the applet executable file and the source code file is stored in the second position index file, the applet executable file is restored into the source code file.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of program development, and in particular to a method for generating a location index file, a method for locating a source code, and a device. Background Art

[0002] The mini program cross-terminal framework provides great convenience for developers in the mini program development process and improves development efficiency.

[0003] The cross-end framework uses a custom DSL syntax and compiler, with separate compiled files and source code mapping indexes (SourceMap), which are referred to as SM1 files for ease of description. In the mini-program engine, the files compiled by the cross-end framework are compiled again as input to obtain the mini-program executable file, and another SourceMap is generated to characterize the mapping relationship between the mini-program executable file and the cross-end framework compiled file, which is referred to as SM2 file for ease of description.

[0004] In the mini program engine, the mini program executable file can be restored to a cross-end framework compiled file through the SM2 file, but the source code file cannot be obtained. Summary of the invention

[0005] The purpose of the embodiments of the present application is to provide a location index file generation method, a source code positioning method and a device, so as to realize the restoration of a mini-program executable file to a source code file.

[0006] In a first aspect, an embodiment of the present application provides a method for generating a location index file, comprising:

[0007] The first position index file is used to perform source code analysis on the cross-end compiled file of the mini program to obtain the identifier attribute information in the source code file; wherein the first position index file includes the identifier position mapping relationship between the cross-end compiled file of the mini program and the source code file; the identifier attribute information includes the identifier and the original position information corresponding to the identifier;

[0008] A second location index file is generated based on the first location index file and the original location information corresponding to the identifier; the second location index file includes the identifier location mapping relationship between the mini-program executable file and the source code file; the mini-program executable file is generated by compiling the mini-program cross-end compiled file.

[0009] The embodiment of the present application uses the first location index file to restore the cross-end compiled file of the mini-program to the source code file, extracts the identifier and original location information in the source code file, and generates a second location index file based on the first location index file and the original location information of the identifier. Since the second location index file stores the identifier position mapping relationship between the mini-program executable file and the source code file, the second location index file provides the function of restoring the mini-program executable file to the source code file.

[0010] In any embodiment, the original location information includes first original row information; generating a second location index file according to the cross-end compiled file of the mini program and the original location information of the identifier includes:

[0011] Generate the first target row information of the identifier based on the starting row information of the mini-program executable file and the original construction row information of the identifier in the first position index file; the original construction row information is used to represent the row position information of the identifier in the file after the mini-program is cross-end compiled;

[0012] A second position index file is generated according to the first original row information and the first target row information corresponding to the identifier.

[0013] The embodiment of the present application generates a second location index file through the starting line information of the mini-program executable file and the first original line information of the identifier in the source code file, so that the mini-program executable file can be subsequently restored to the source code file based on the second location index file.

[0014] In any embodiment, after obtaining the second location index file, the method further includes:

[0015] The second position index file is standardized.

[0016] The embodiment of the present application performs standardization processing on the second location index file so that the standardized second location index file can be compatible with a third-party anomaly monitoring platform.

[0017] In any embodiment, the method further comprises:

[0018] Compile the cross-terminal compiled files of the mini program to obtain the mini program executable file.

[0019] The embodiment of the present application generates a second location index file during the process of compiling the cross-terminal compiled files of the mini-program, thereby providing support for restoring the mini-program executable file to the source code file.

[0020] In any embodiment, the mini-program cross-end compiled file includes multiple levels of mini-program cross-end compiled files, and each level of mini-program cross-end compiled files corresponds to one of the first position index files; the mini-program cross-end compiled files are source-parsed using the first position index file to obtain identifier attribute information in the source code file, including:

[0021] The first position index file is used in turn according to the level to parse the source code of the cross-terminal compiled files of the mini-programs of the corresponding level until the identifier attribute information in the source code file is obtained.

[0022] The embodiments of the present application can be applied to the scenario of multi-level mini-program cross-end compiled files. For this scenario, the mini-program cross-end compiled files can be restored in sequence until the source code file is obtained, and a second location index file is generated based on the identifier attribute information of the source code file. Therefore, even if the mini-program executable file is obtained by compiling multi-level mini-program cross-end compiled files, the mini-program executable file can still be restored to the source code file.

[0023] In any embodiment, the original position information further includes first original column information; the first original column information is used to represent the column information of the identifier in the source code file; generating a second position index file according to the first position index file and the first original row information corresponding to the identifier includes:

[0024] A second location index file is generated according to the first original row information, the first original column information and the mini-program cross-end compiled file corresponding to the identifier.

[0025] In an embodiment of the present application, in the process of compiling the mini-program cross-end compiled file into a mini-program executable file, the columns of the code in the mini-program cross-end compiled file may also change. Therefore, the second position index file can map both the row information and the column information, thereby improving the accuracy of the position mapping in the second position index file.

[0026] In any embodiment, the original position information further includes first original column information;

[0027] The method further includes:

[0028] Obtaining corresponding first target column information according to the first position index file;

[0029] Generating a second position index file according to the first original row information and the first target row information corresponding to the identifier includes:

[0030] A second position index file is generated according to the first original row information, the first original column information, the first target row information and the first target column information corresponding to the identifier.

[0031] In an embodiment of the present application, in the process of compiling the mini-program cross-end compiled file into a mini-program executable file, the columns of the code in the mini-program cross-end compiled file may also change. Therefore, the second position index file can map both the row information and the column information, thereby improving the accuracy of the position mapping in the second position index file.

[0032] In a second aspect, an embodiment of the present application provides a source code location method, including:

[0033] Determine target identifier attribute information of a target identifier in the applet executable file;

[0034] The position information of the target identifier in the source code file is determined based on the second position index file and the target identifier attribute information; wherein the second position index file is generated according to the method described in the first aspect.

[0035] The embodiment of the present application can improve the accuracy of determining the position of the target identifier in the mini-program executable file in the source code file by utilizing the second position index file.

[0036] In any embodiment, the target identifier attribute information includes second target row information and second target column information corresponding to the target identifier; determining the position information of the target identifier in the source code file based on the second position index file and the target identifier attribute information includes:

[0037] Determine the second original row information corresponding to the second target row information and the second original column information corresponding to the second target column information from the second position index file; wherein the second original row information and the second original column information are used to represent the position information of the target identifier in the source code file.

[0038] In an embodiment of the present application, since the second location index file stores the identifier position mapping relationship between the mini-program executable file and the source code file, the position of the target identifier in the source code file can be determined based on the second location index file, which facilitates subsequent exception handling.

[0039] In any embodiment, the method further comprises:

[0040] Gets the target identifier from the source file based on the location information.

[0041] In an embodiment of the present application, after determining the position of the target identifier in the source code file according to the second position index file, the corresponding target identifier can be obtained from the source code file based on the position information, thereby accurately obtaining the target identifier corresponding to the target identifier from the source code file.

[0042] In any embodiment, determining target identifier attribute information of a target identifier in an applet executable file includes:

[0043] The exception information of the mini-program executable file during operation is obtained, wherein the exception information includes the exception row information and the exception column information corresponding to the target identifier where the exception occurs in the mini-program executable file.

[0044] The embodiment of the present application utilizes the second location index file to obtain the specific location of the abnormal code in the mini-program executable file in the source code file, thereby solving the problem that the mini-program executable file cannot locate errors.

[0045] In a third aspect, an embodiment of the present application provides a location index file generating device, including:

[0046] A source code parsing module, used to perform source code parsing on the mini program cross-end compiled file using the first position index file to obtain identifier attribute information in the source code file; wherein the first position index file includes the identifier position mapping relationship between the mini program cross-end compiled file and the source code file; the identifier attribute information includes the identifier and the original position information corresponding to the identifier;

[0047] A generation module is used to generate a second location index file based on the first location index file and the original location information corresponding to the identifier; the second location index file includes the identifier location mapping relationship between the mini-program executable file and the source code file; the mini-program executable file is generated by compiling the mini-program cross-end compiled file.

[0048] In a fourth aspect, an embodiment of the present application provides a source code locating device, including:

[0049] An information determination module, used to determine target identifier attribute information of a target identifier in an executable file of a mini-program;

[0050] A position determination module is used to determine the position information of the target identifier in the source code file based on the second position index file and the target identifier attribute information; wherein the second position index file is generated according to the method described in the first aspect.

[0051] In a fifth aspect, an embodiment of the present application provides an electronic device, including: a processor, a memory, and a bus, wherein:

[0052] The processor and the memory communicate with each other via a bus;

[0053] The memory stores program instructions that can be executed by the processor, and the processor calls the program instructions to execute the method of the first aspect or the second aspect.

[0054] In a sixth aspect, an embodiment of the present application provides a non-transitory computer-readable storage medium, including:

[0055] The non-transitory computer-readable storage medium stores computer instructions, and the computer instructions enable a computer to execute the method of the first aspect or the second aspect. BRIEF DESCRIPTION OF THE DRAWINGS

[0056] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments of the present application will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope.

[0057] Figure 1 A mapping diagram of source code files to mini-program executable files provided for comparison solutions;

[0058] Figure 2 A schematic diagram of a method for generating a location index file provided in an embodiment of the present application;

[0059] Figure 3 A schematic diagram of an identifier mapping principle provided in an embodiment of the present application;

[0060] Figure 4 A schematic diagram of a source code location method flow provided in an embodiment of the present application;

[0061] Figure 5 A schematic diagram of the structure of a location index file generating device provided in an embodiment of the present application;

[0062] Figure 6 A schematic diagram of the structure of a source code positioning device provided in an embodiment of the present application;

[0063] Figure 7 A schematic diagram of the physical structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0064] The following embodiments of the technical solution of the present application will be described in detail in conjunction with the accompanying drawings. The following embodiments are only used to more clearly illustrate the technical solution of the present application, and are therefore only used as examples, and cannot be used to limit the scope of protection of the present application.

[0065] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by technicians in the technical field to which this application belongs; the terms used herein are only for the purpose of describing specific embodiments and are not intended to limit this application; the terms "including" and "having" in the specification and claims of this application and the above-mentioned figure descriptions and any variations thereof are intended to cover non-exclusive inclusions.

[0066] In the description of the embodiments of the present application, the technical terms "first", "second", etc. are only used to distinguish different objects, and cannot be understood as indicating or implying relative importance or implicitly indicating the number, specific order or primary and secondary relationship of the indicated technical features. In the description of the embodiments of the present application, the meaning of "multiple" is more than two, unless otherwise clearly and specifically defined.

[0067] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.

[0068] In the description of the embodiments of the present application, the term "and / or" is only a description of the association relationship of the associated objects, indicating that there may be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship.

[0069] In the description of the embodiments of the present application, the term "multiple" refers to more than two (including two). Similarly, "multiple groups" refers to more than two groups (including two groups), and "multiple pieces" refers to more than two pieces (including two pieces).

[0070] In the development of mini-programs, most development teams use a mini-program cross-end framework that supports packaging of multiple mini-program platforms to improve efficiency. The mini-program cross-end framework uses a custom DSL syntax and compiler, with separate compiled files and source map indexes, referred to as SM1 files. In the mini-program engine, the cross-end framework compiled file is used as input to compile into a mini-program executable file again, generating another SourceMap, called SM2 file.

[0071] Figure 1 The mapping relationship diagram from source code files to mini-program executable files provided for the comparison solution is as follows: Figure 1 As shown, a.js and b.js are two source code files, which generate bundle.js file and SM1 file (SM1 file is not shown in the figure) after being compiled through the mini program cross-end framework; the mini program engine compiles the bundle.js file again to generate app-service.js executable file and SM2 file (SM2 file is not shown in the figure).

[0072] Because in the compilation stage of the mini program engine, after receiving the mini program cross-end compiled file and SM1 file of the mini program cross-end framework, the mini program engine compiles the mini program cross-end compiled file again to generate the mini program executable file and SM2 file, and deletes the SM1 file at the same time. In addition, when the mini program executable file is ported to a third-party platform, only one location index file, namely the SM2 file, can be ported together, and the SM1 file does not exist in the mini program engine or the third-party platform. Therefore, the mini program executable file is restored to the cross-end framework compiled file through the SM2 file, but cannot be restored to the source code file before the cross-end framework compilation.

[0073] Furthermore, when an exception occurs in the mini-program executable file during operation, the js exceptions collected online will also be unable to determine the cause of the exception because the source code cannot be located.

[0074] Based on the above technical problems, the embodiments of the present application provide a method for generating a location index file, a method for locating a source code, and a device. In the method for generating a location index file, a second location index file is generated for storing the identifier location mapping relationship between the mini-program executable file and the source code file, so that the mini-program executable file can be restored to the source code file based on the second location index file.

[0075] To facilitate understanding of the embodiments of the present application, the following explanations are given for the related concepts involved:

[0076] Mini Program cross-terminal framework: Using the Mini Program cross-terminal development framework to achieve development once and run everywhere to improve efficiency has become a strong and urgent need for developers.

[0077] The mini-program cross-end framework can be divided into Vue syntax and React syntax / React-like syntax according to syntax. Its implementation principle can be divided into two states: compile time and runtime. The main workload of the cross-end framework during compilation is in the compilation stage. The cross-end framework agrees on a set of its own DSL. During the compilation and packaging process, the label tool is used to translate through AST to generate code that conforms to the mini-program rules. The cross-end framework actually runs the React or Vue runtime in the logic layer of the mini-program, and then implements a custom renderer through the adaptation layer.

[0078] DSL syntax: DSL (Domain Specific Language) is a computer programming language with limited expressiveness for a certain domain. It is often used to focus on a specific domain or problem, which requires DSL to have strong expressiveness and be simple to use. When talking about DSL, people will naturally think of general-purpose languages ​​(such as Java, C, etc.).

[0079] SourceMap: It stores the corresponding position information before and after code conversion, that is, the source code position before conversion corresponding to the converted and compressed code. It is a mapping between the source code and the production code. In the embodiment of this application, SourceMap is called a position index file (including a first position index file and a second position index file). Sourcemap solves the problem of difficulty in debugging during the packaging process, when the code is compressed, space-removed, and compiled by Babel, due to the large differences between the codes.

[0080] It is understandable that the location index file generation method provided in the embodiment of the present application can be applied to an electronic device, in which a small program compiler is running, and the small program compiler is used to recompile the small program cross-terminal compiled file to generate a small program executable file and a second location index file. The electronic device includes a terminal or a server; wherein the terminal can be a smart phone, a tablet computer, a computer, a personal digital assistant (PDA), etc.; the server can be an application server or a web server.

[0081] Figure 2 A flowchart of a method for generating a location index file provided in an embodiment of the present application is shown in FIG. Figure 2 As shown, the method includes:

[0082] Step 201: Use the first location index file to perform source code analysis on the mini-program cross-end compiled file to obtain identifier attribute information in the source code file; wherein the first location index file includes the identifier position mapping relationship between the mini-program cross-end compiled file and the source code file; the identifier attribute information includes the identifier and the original location information corresponding to the identifier.

[0083] Among them, the first position index file is generated in the process of compiling the source code file to generate the cross-end compiled file of the mini program, that is, the SM1 file in the above embodiment. In addition, the first position index file stores the position correspondence of each identifier in the cross-end compiled file of the mini program in the source code file. Since there may be multiple cross-end compiled files of the mini program, the electronic device can first traverse the cross-end compiled files of the mini program, and use the corresponding first position index file to perform source code analysis on each cross-end compiled file of the mini program to obtain the identifier attribute information in the source code file.

[0084] The Mini Program cross-end compiled file refers to the file obtained by compiling the source code file through the Mini Program cross-end framework.

[0085] The identifier attribute information includes the identifier and the first original line information corresponding to the identifier. The identifier refers to the variable name, function name, etc. in the source code file, such as Figure 1 myObjA, log, etc. in the source code file. The first original row information refers to the row information of the identifier in the source code file, that is, the row number of the source code file where the identifier is located. It is understandable that the identifier attribute information may also include other attributes, such as the first original column information corresponding to the identifier, that is, the character number of the identifier in this row.

[0086] Step 202: Generate a second location index file based on the first location index file and the first original line information corresponding to the identifier; the second location index file includes the identifier position mapping relationship between the mini-program executable file and the source code file; the mini-program executable file is generated by compiling the mini-program cross-end compiled file.

[0087] The mini program executable file is generated by recompiling the mini program cross-terminal compiled file through the mini program compiler of the mini program engine. The mini program engine runs in the electronic device.

[0088] Since the first position index file includes the mapping relationship between the position of the identifier of the cross-end compiled file of the mini-program and the source code file, the position of the identifier in the cross-end compiled file of the mini-program can be determined through the first position index file. After the electronic device determines the position of the identifier in the cross-end compiled file of the mini-program, it determines the position of the identifier in the executable file of the mini-program based on the position. In addition, in combination with the first original position information corresponding to each identifier in the source code file, the corresponding relationship between the position of the identifier in the source code file and the corresponding position in the executable file of the mini-program is obtained, and the identifier, the first original position information and the calculated position information in the executable file of the mini-program are written into the second position index file.

[0089] It should be noted that the second location index file can be generated during the process of the electronic device compiling the cross-end compiled file of the mini-program, that is, the electronic device compiles the cross-end compiled file of the mini-program to obtain the corresponding mini-program executable file, and also generates a second location index file. In addition, the second location index file can also be generated after the compilation is completed, and the embodiment of the present application does not specifically limit the timing of generating the second location index file.

[0090] The embodiment of the present application uses the first location index file to restore the cross-end compiled file of the mini-program to the source code file, extracts the identifier and original location information in the source code file, and generates a second location index file based on the first location index file and the original location information of the identifier. Since the second location index file stores the identifier position mapping relationship between the mini-program executable file and the source code file, the second location index file provides the function of restoring the mini-program executable file to the source code file.

[0091] On the basis of the above embodiment, the original position information includes first original row information; generating a second position index file according to the original position information corresponding to the first position index file and the identifier includes:

[0092] Generate first target row information of the identifier based on the start row information of the applet executable file and the original construction row information of the identifier in the first position index file;

[0093] A second position index file is generated according to the first original row information and the first target row information corresponding to the identifier.

[0094] In the specific implementation process, the starting line information refers to the starting line position of the cross-end compiled file of the mini program in the mini program executable file. In practical applications, the essence of recompiling the cross-end compiled file of the mini program is to generate a mini program executable file from multiple cross-end compiled files of the mini program. Therefore, different cross-end compiled files of the mini program have different starting lines in the mini program executable file.

[0095] A mini program cross-end compiled file can be obtained by compiling multiple source code files, and the mini program cross-end compiled file can include multiple lines of code. The original construction line information refers to the line position information of the identifier in the mini program cross-end compiled file.

[0096] In one implementation scenario, in the process of compiling the cross-end compiled file of the mini-program into the mini-program executable file, mainly the row where the identifier is located changes, and the column where the identifier is located may not change. Therefore, the first target row information refers to the row position information of the identifier in the mini-program executable file, and the determination method can be: first target row information = starting row information + original construction row information. The column information of the identifier in the mini-program executable file can be determined based on the column information of the identifier in the mini-program cross-end compiled file.

[0097] After obtaining the first target row information, the electronic device writes the identifier, the first original row information corresponding to the identifier, and the first target row information into the second position index file. It is understandable that the column of the identifier determined above in the mini-program executable file can also be written into the second position index file.

[0098] The embodiment of the present application generates a second location index file through the starting line information of the mini-program executable file and the first original line information of the identifier in the source code file, so that the mini-program executable file can be subsequently restored to the source code file based on the second location index file.

[0099] Based on the above embodiment, after obtaining the second position index file, the method further includes:

[0100] The second position index file is standardized.

[0101] In the specific implementation process, the data structure format of the second location index file obtained through the above-mentioned embodiments can be customized, for example, it can be in json format, etc., as long as it can characterize the correspondence between the position of the identifier in the applet executable file and the position in the source code file. However, the second location index file in json format cannot be recognized by the currently popular monitoring platforms (for example: MPX, Mas, Sentry, etc.) and cannot be verified on the monitoring platform. In order to solve this problem, the embodiment of the present application standardizes the second location index file, that is, the second location index file is standardized according to the data format of the Sourcemap standard applicable to the monitoring platform, that is, the data format of the second location index file is adjusted to the data format of the Sourcemap standard.

[0102] The embodiment of the present application performs standardization processing on the second location index file so that the standardized second location index file can be compatible with a third-party anomaly monitoring platform.

[0103] On the basis of the above embodiment, the mini program cross-end compiled file includes multiple levels of mini program cross-end compiled files, and each level of mini program cross-end compiled files corresponds to a first position index file; the mini program cross-end compiled file is source code parsed using the first position index file to obtain identifier attribute information in the source code file, including:

[0104] The first position index file is used in turn according to the level to parse the source code of the cross-terminal compiled files of the mini-programs of the corresponding level until the identifier attribute information in the source code file is obtained.

[0105] In the specific implementation process, a multi-level mini-program cross-end compiled file refers to the need to compile multiple times from the source code file to the mini-program executable file, and the file obtained by each compilation is called the mini-program cross-end compiled file of the corresponding level. For the convenience of description, taking the second-level mini-program cross-end compiled file as an example, the compilation process from the source code file to the mini-program executable file is: compile the source code file to obtain the first-level mini-program cross-end compiled file, that is, the corresponding first-level position index file; compile the first-level mini-program cross-end compiled file again to obtain the second-level mini-program cross-end compiled file and the second-level position index file; compile the second-level mini-program cross-end compiled file again to obtain the mini-program executable file and the second position index file.

[0106] When performing source code parsing, it is the reverse process of the above process, that is, using the second-level location index file to perform source code parsing on the second-level applet cross-end compiled file to obtain the first-level applet cross-end compiled file; then using the first-level location index file to perform source code parsing on the first-level applet cross-end compiled file to obtain the source code file. After obtaining the source code file, the identifier attribute information in the source code file can be obtained, and the corresponding second location index file is subsequently generated using the methods described in the above embodiments, which will not be repeated here.

[0107] The embodiments of the present application can be applied to the scenario of multi-level mini-program cross-end compiled files. For this scenario, the mini-program cross-end compiled files can be restored in sequence until the source code file is obtained, and a second location index file is generated based on the identifier attribute information of the source code file. Therefore, even if the mini-program executable file is obtained by compiling multi-level mini-program cross-end compiled files, the mini-program executable file can still be restored to the source code file.

[0108] On the basis of the above embodiment, the original position information further includes first original column information; generating a second position index file according to the first position index file and the first original row information corresponding to the identifier includes:

[0109] A second position index file is generated according to the first original row information, the first original column information and the first position index file corresponding to the identifier.

[0110] In a specific implementation process, the second position index file may also include the correspondence between the column position information of the identifier in the applet executable file and the column position information in the source code file. Therefore, the column information of the identifier in the source code file can also be obtained through the first position index file, which is referred to as the first original column information in the embodiment of the present application.

[0111] The electronic device can obtain the column information of the identifier in the file after the mini-program cross-end compilation based on the first position index file, and can obtain the column information of the identifier in the mini-program executable file based on the column information, which is referred to as the first target column information here.

[0112] The electronic device obtains the corresponding second position index file after acquiring the first original row information, the first original column information, the first target row information and the first target column information.

[0113] Figure 3 A schematic diagram of an identifier mapping principle provided in an embodiment of the present application, such as Figure 3 As shown, the left side of the arrow indicates the identifier correspondence between the compiled file of the mini program and the source code file, where: original:{line:3,column:8} indicates the position of the identifier "log" in the a.js file in the source code file, that is, line 3, column 8. generated:{line:1,column:45} indicates the position of the identifier "log" in the compiled file of the mini program, that is, line 1, column 45. The position correspondence of the identifiers in the b.js file is not repeated here. The right side of the arrow indicates the identifier correspondence between the mini program executable file and the source code file, where: original:{line:3,column:8} indicates the position of the identifier "log" in the a.js file in the source code file, that is, line 3, column 8. generated:{line:25038,column:45} indicates the position of the identifier "log" in the compiled file of the mini program, that is, line 25038, column 45. It can be understood that the meaning represented by the content in the second position index file is the same as the meaning represented by the figure on the right side of the arrow, except that the content format of the second position index file is different.

[0114] In some compilation scenarios, when the cross-end compiled file of the Mini Program is compiled into the Mini Program executable file, the contents of the cross-end compiled file of the Mini Program are copied line by line into the Mini Program executable file. Figure 3 It can be seen that the number of rows will change, but the number of columns may not change, that is, the number of columns of the identifier in the mini-program cross-end compiled file is the same as the number of columns in the mini-program executable file. Therefore, the first target column information of the identifier in the mini-program executable file can be determined based on the mini-program cross-end compiled file.

[0115] In an embodiment of the present application, in the process of compiling the mini-program cross-end compiled file into a mini-program executable file, the columns of the code in the mini-program cross-end compiled file may also change. Therefore, the second position index file can map both the row information and the column information, thereby improving the accuracy of the position mapping in the second position index file.

[0116] In some embodiments, during the process of compiling the cross-end compiled file of the mini-program into the mini-program executable file, the columns of the identifiers in the cross-end compiled file of the mini-program may also change. For the case of changes, a column transformation formula can be pre-constructed, and the columns of the identifiers in the cross-end compiled file of the mini-program are converted into the columns in the mini-program executable file based on the column transformation formula. For example: when the cross-end compiled file of the mini-program is copied to the mini-program executable file, there are 2 bytes of space at the beginning of each line. Therefore, when the code in the cross-end compiled file of the mini-program is copied to the mini-program executable file, the column of each code needs to be added by 2 based on the column information in the cross-end compiled file of the mini-program.

[0117] In an embodiment of the present application, in the process of compiling the mini-program cross-end compiled file into a mini-program executable file, the columns of the code in the mini-program cross-end compiled file may also change. Therefore, the second position index file can map both the row information and the column information, thereby improving the accuracy of the position mapping in the second position index file.

[0118] Figure 4 A schematic diagram of a source code location method flow provided in an embodiment of the present application is shown in FIG. Figure 4 As shown, it can be understood that the location index file generation method provided in the embodiment of the present application can be applied to an electronic device, which is loaded with a platform capable of running an applet executable file, and the electronic device includes a terminal or a server; wherein the terminal can specifically be a smart phone, a tablet computer, a computer, a personal digital assistant (PDA), etc.; the server can specifically be an application server or a Web server. The method includes:

[0119] Step 401: Determine the target identifier attribute information of the target identifier in the applet executable file.

[0120] In the specific implementation process, the target identifier can be an identifier in the applet executable file, which is an identifier whose position in the source code file needs to be determined. The target identifier can be specified by the user, or it can be an identifier of a call stack error that occurs during the execution of the applet executable file.

[0121] The target identifier attribute information is used to represent the location information of the target identifier in the mini-program executable file, for example: which row or column in the mini-program executable file.

[0122] Step 402: Determine the location information of the target identifier in the source code file based on the second location index file and the target identifier attribute information; wherein the second location index file is generated according to the method provided in the above embodiments, which will not be described in detail here.

[0123] In the specific implementation process, the second location index file is generated by the methods provided in the above embodiments. Since the second location index file contains the correspondence between the position of the identifier in the mini-program executable file and the position in the source code file, the position information in the source code file corresponding to the target identifier attribute information can be found in the second location index file.

[0124] The embodiment of the present application can improve the accuracy of determining the position of the target identifier in the mini-program executable file in the source code file by utilizing the second position index file.

[0125] Based on the above embodiment, the target identifier attribute information includes second target row information and second target column information corresponding to the target identifier; determining the position information of the target identifier in the source code file based on the second position index file and the target identifier attribute information includes:

[0126] Determine the second original row information corresponding to the second target row information and the second original column information corresponding to the second target column information from the second position index file; wherein the second original row information and the second original column information are used to represent the position information of the target identifier in the source code file.

[0127] In a specific implementation process, the second target row information is used to indicate the row number of the target identifier in the mini-program executable file, and the second target column information is used to indicate the column number of the target identifier in the mini-program executable file.

[0128] The second original row information is used to indicate the row number of the target identifier in the source code file, and the second original column information is used to indicate the column number of the target identifier in the source code file.

[0129] pass Figure 3 It can be seen that after determining the second target row information and the second target column information of the target identifier in the applet executable file, the second original row information corresponding to the second target row information and the second original column information corresponding to the second target column information can be determined from the second position index file. Thus, the corresponding target identifier can be located in the source code file.

[0130] In an embodiment of the present application, since the second location index file stores the identifier position mapping relationship between the mini-program executable file and the source code file, the position of the target identifier in the source code file can be determined based on the second location index file, which facilitates subsequent exception handling.

[0131] On the basis of the above embodiment, after the second original row information and the second original column information of the target identifier are determined, the target identifier may be obtained from the corresponding source code file.

[0132] Based on the above embodiment, the target identifier attribute information of the target identifier in the mini-program executable file is determined, including:

[0133] The exception information of the mini-program executable file during operation is obtained, wherein the exception information includes the exception row information and the exception column information corresponding to the target identifier where the exception occurs in the mini-program executable file.

[0134] In the specific implementation process, the mini-program executable file may report an error during operation, that is, a call stack error occurs. When a call stack error occurs, the electronic device can capture exception information, which includes exception line information and exception column information. Among them, the exception line information is used to represent the line information of the code where the error occurs in the mini-program executable file. The exception column information is used to represent the column information of the code where the error occurs in the mini-program executable file.

[0135] The exception information is as follows: TypeError: Cannot read'e' of undefined at app-service.js:25038:38; at app-service.js:25038:45. Figure 3 For example, through Figure 3 The figure on the right side of the arrow shows that the position of generated:25038:38 in the source code file is original:2:17; the position of generated:25038:45 in the source code file is original:3:8.

[0136] The embodiment of the present application utilizes the second location index file to obtain the specific location of the abnormal code in the mini-program executable file in the source code file, thereby solving the problem that the mini-program executable file cannot locate errors.

[0137] Figure 5 The present invention provides a schematic diagram of a device for generating a location index file. The device may be a module, program segment or code on an electronic device. Figure 2 The method embodiment corresponds to and can be executed Figure 2 The various steps involved in the method embodiment and the specific functions of the device can be found in the above description. To avoid repetition, the detailed description is appropriately omitted here.

[0138] The device comprises: a source code parsing module 501 and a generating module 502, wherein:

[0139] The source code parsing module 501 is used to perform source code parsing on the mini-program cross-end compiled file using the first location index file to obtain the identifier attribute information in the source code file; wherein the first location index file includes the identifier position mapping relationship between the mini-program cross-end compiled file and the source code file; the identifier attribute information includes the identifier and the original location information corresponding to the identifier;

[0140] The generation module 502 is used to generate a second location index file based on the first location index file and the original location information corresponding to the identifier; the second location index file includes the identifier position mapping relationship between the mini-program executable file and the source code file; the mini-program executable file is generated by compiling the mini-program cross-end compiled file.

[0141] Based on the above embodiment, the original position information includes first original row information; the generating module 502 is specifically used for:

[0142] Generate first target row information of the identifier based on the start row information of the applet executable file and the original construction row information of the identifier in the first position index file;

[0143] The second position index file is generated according to the first original row information and the first target row information corresponding to the identifier.

[0144] Based on the above embodiment, the device further includes a processing module, which is used to:

[0145] The second location index file is standardized.

[0146] Based on the above embodiment, the device further includes a compiling module, which is used to:

[0147] Compile the cross-terminal compiled file of the mini-program to obtain the executable file of the mini-program.

[0148] On the basis of the above embodiment, the mini program cross-end compiled file includes multiple levels of mini program cross-end compiled files, and each level of mini program cross-end compiled files corresponds to one first location index file; the generation module 502 is specifically used for:

[0149] The first position index file is used in sequence according to the level to perform source code analysis on the cross-terminal compiled files of the mini-programs of the corresponding level until the identifier attribute information in the source code file is obtained.

[0150] Based on the above embodiment, the original position information further includes first original column information; the generating module 502 is specifically used for:

[0151] The second location index file is generated according to the first original row information corresponding to the identifier, the first original column information and the cross-end compiled file of the mini program.

[0152] Based on the above embodiment, the original position information further includes first original column information; the generating module 502 is specifically used for:

[0153] Obtaining corresponding first target column information according to the cross-terminal compiled file of the mini program;

[0154] The second position index file is generated according to the first original row information, the first original column information, the first target row information and the first target column information corresponding to the identifier.

[0155] Figure 6 The schematic diagram of the structure of a source code location device provided in the embodiment of the present application is as follows. The device may be a module, program segment or code on an electronic device. It should be understood that the device is similar to the above-mentioned Figure 4 The method embodiment corresponds to and can be executed Figure 4 The various steps involved in the method embodiment and the specific functions of the device can be found in the above description. To avoid repetition, detailed description is appropriately omitted here. The device includes: an information determination module 601 and a location determination module 602, wherein:

[0156] The information determination module 601 is used to determine the target identifier attribute information of the target identifier in the mini-program executable file;

[0157] The position determination module 602 is used to determine the position information of the target identifier in the source code file based on the second position index file and the target identifier attribute information; wherein the second position index file is generated according to the method provided in the above embodiments.

[0158] On the basis of the above embodiment, the target identifier attribute information includes the second target row information and the second target column information corresponding to the target identifier; the position determination module 602 is specifically used for:

[0159] Determine the second original row information corresponding to the second target row information and the second original column information corresponding to the second target column information from the second position index file; wherein the second original row information and the second original column information are used to represent the position information of the target identifier in the source code file.

[0160] Based on the above embodiment, the device further includes an acquisition module, which is used to:

[0161] A target identifier is obtained from the source code file based on the location information.

[0162] Based on the above embodiment, the information determination module 601 is specifically used for:

[0163] Exception information of the mini-program executable file during operation is obtained, wherein the exception information includes exception row information and exception column information corresponding to the target identifier where the exception occurs in the mini-program executable file.

[0164] Figure 7 A schematic diagram of the physical structure of an electronic device provided in an embodiment of the present application, such as Figure 7 As shown, the electronic device includes: a processor (processor) 701, a memory (memory) 702 and a bus 703; wherein,

[0165] The processor 701 and the memory 702 communicate with each other via the bus 703;

[0166] The processor 701 is used to call the program instructions in the memory 702 to execute the methods provided by the above-mentioned method embodiments, for example, including: using the first position index file to perform source code analysis on the mini-program cross-end compiled file to obtain identifier attribute information in the source code file; wherein the first position index file includes the identifier position mapping relationship between the mini-program cross-end compiled file and the source code file; the identifier attribute information includes the identifier and the original position information corresponding to the identifier; a second position index file is generated according to the first position index file and the original position information corresponding to the identifier; the second position index file includes the identifier position mapping relationship between the mini-program executable file and the source code file; the mini-program executable file is generated by compiling the mini-program cross-end compiled file. Or,

[0167] Determine target identifier attribute information of a target identifier in the applet executable file;

[0168] The position information of the target identifier in the source code file is determined based on the second position index file and the target identifier attribute information; wherein the second position index file is generated according to the method provided in the above embodiment.

[0169] The processor 701 may be an integrated circuit chip with signal processing capabilities. The processor 701 may be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it may also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. It may implement or execute various methods, steps and logic block diagrams disclosed in the embodiments of the present application. A general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.

[0170] The memory 702 may include but is not limited to random access memory (RAM), read only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), etc.

[0171] The present embodiment discloses a computer program product, which includes a computer program stored on a non-transitory computer-readable storage medium, and the computer program includes program instructions. When the program instructions are executed by a computer, the computer can execute the methods provided by the above-mentioned method embodiments, for example, including: using a first location index file to perform source code analysis on a cross-end compiled file of a mini-program to obtain identifier attribute information in the source code file; wherein the first location index file includes an identifier position mapping relationship between the cross-end compiled file of the mini-program and the source code file; the identifier attribute information includes an identifier and the original location information corresponding to the identifier; a second location index file is generated according to the first location index file and the original location information corresponding to the identifier; the second location index file includes an identifier position mapping relationship between the mini-program executable file and the source code file; the mini-program executable file is generated by compiling the cross-end compiled file of the mini-program. Or,

[0172] Determine target identifier attribute information of a target identifier in the applet executable file;

[0173] The position information of the target identifier in the source code file is determined based on the second position index file and the target identifier attribute information; wherein the second position index file is generated according to the method provided in the above embodiment.

[0174] The present embodiment provides a non-transitory computer-readable storage medium, which stores computer instructions, and the computer instructions enable the computer to execute the methods provided by the above-mentioned method embodiments, for example, including: using a first location index file to perform source code analysis on the cross-end compiled file of the mini-program to obtain identifier attribute information in the source code file; wherein the first location index file includes an identifier position mapping relationship between the cross-end compiled file of the mini-program and the source code file; the identifier attribute information includes an identifier and the original location information corresponding to the identifier; a second location index file is generated according to the first location index file and the original location information corresponding to the identifier; the second location index file includes an identifier position mapping relationship between the mini-program executable file and the source code file; the mini-program executable file is generated by compiling the cross-end compiled file of the mini-program. Or,

[0175] Determine target identifier attribute information of a target identifier in the applet executable file;

[0176] The position information of the target identifier in the source code file is determined based on the second position index file and the target identifier attribute information; wherein the second position index file is generated according to the method provided in the above embodiment.

[0177] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, and the indirect coupling or communication connection of the devices or units can be electrical, mechanical or other forms.

[0178] In addition, the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0179] Furthermore, the functional modules in the various embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.

[0180] In this document, relational terms such as first and second, etc. are used merely to distinguish one entity or operation from another entity or operation, but do not necessarily require or imply any such actual relationship or order between these entities or operations.

[0181] The above description is only an embodiment of the present application and is not intended to limit the protection scope of the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.

Claims

1. A method for generating a location index file, characterized in that: include: The first location index file is used to perform source code analysis on the cross-end compiled file of the mini program to obtain the identifier attribute information in the source code file; wherein the first location index file includes the identifier position mapping relationship between the cross-end compiled file of the mini program and the source code file; the identifier attribute information includes the identifier and the first original location information corresponding to the identifier; A second location index file is generated according to the first location index file and the original location information corresponding to the identifier; the second location index file includes an identifier location mapping relationship between the mini-program executable file and the source code file; the mini-program executable file is generated by compiling the mini-program cross-end compiled file.

2. The method according to claim 1, characterized in that The original position information includes first original row information; and generating a second position index file according to the first position index file and the original position information corresponding to the identifier includes: Generate first target row information of the identifier based on the starting row information of the mini-program executable file and the original construction row information of the identifier in the first position index file; the original construction row information is used to represent the row position information of the identifier in the file after the mini-program is cross-end compiled; The second position index file is generated according to the first original row information and the first target row information corresponding to the identifier.

3. The method according to claim 2, characterized in that The original position information further includes first original column information, where the first original column information is used to represent column information of the identifier in the source code file; the method further includes: Obtaining corresponding first target column information according to the first position index file; The generating the second position index file according to the first original row information corresponding to the identifier and the first target row information includes: The second position index file is generated according to the first original row information, the first original column information, the first target row information and the first target column information corresponding to the identifier.

4. The method according to claim 1, characterized in that: After obtaining the second position index file, the method further includes: The second location index file is standardized.

5. The method according to claim 1, characterized in that The method further comprises: Compile the cross-terminal compiled file of the mini-program to obtain the executable file of the mini-program.

6. The method according to any one of claims 1 to 5, characterized in that: The mini-program cross-end compiled files include a plurality of levels of mini-program cross-end compiled files, and each level of mini-program cross-end compiled files corresponds to one of the first position index files; The method of using the first position index file to perform source code analysis on the cross-terminal compiled file of the mini program to obtain identifier attribute information in the source code file includes: The first position index file is used in sequence according to the level to perform source code analysis on the cross-terminal compiled files of the mini-programs of the corresponding level until the identifier attribute information in the source code file is obtained.

7. A source code location method, characterized in that: include: Determine target identifier attribute information of a target identifier in the applet executable file; The position information of the target identifier in the source code file is determined based on the second position index file and the target identifier attribute information; wherein the second position index file is generated according to the method according to any one of claims 1-6.

8. The method according to claim 7, characterized in that The target identifier attribute information includes second target row information and second target column information corresponding to the target identifier; The determining the position information of the target identifier in the source code file based on the second position index file and the target identifier attribute information includes: Determine the second original row information corresponding to the second target row information and the second original column information corresponding to the second target column information from the second position index file; wherein the second original row information and the second original column information are used to represent the position information of the target identifier in the source code file.

9. The method according to claim 7, characterized in that: The method further comprises: A target identifier is obtained from the source code file based on the location information.

10. The method according to any one of claims 7 to 9, characterized in that: The target identifier attribute information of the target identifier in the executable file of the mini-program is determined, including: Exception information of the mini-program executable file during operation is obtained, wherein the exception information includes exception row information and exception column information corresponding to the target identifier where the exception occurs in the mini-program executable file.

11. A device for generating a position index file, characterized in that: include: A source code parsing module, used to perform source code parsing on the mini-program cross-end compiled file using the first position index file to obtain identifier attribute information in the source code file; wherein the first position index file includes an identifier position mapping relationship between the mini-program cross-end compiled file and the source code file; the identifier attribute information includes an identifier and original position information corresponding to the identifier; A generation module is used to generate a second location index file based on the first location index file and the original location information corresponding to the identifier; the second location index file includes the identifier position mapping relationship between the mini-program executable file and the source code file; the mini-program executable file is generated by compiling the mini-program cross-end compiled file.

12. A source code locating device, characterized in that: include: An information determination module, used to determine target identifier attribute information of a target identifier in an executable file of a mini-program; A position determination module is used to determine the position information of the target identifier in the source code file based on a second position index file and the target identifier attribute information; wherein the second position index file is generated according to the method according to any one of claims 1-6.

13. An electronic device, characterized in that: include: processor, memory and bus, wherein, The processor and the memory communicate with each other via the bus; The memory stores program instructions executable by the processor, and the processor can execute the method according to any one of claims 1 to 10 by calling the program instructions.

14. A non-transitory computer-readable storage medium, characterized in that: The non-transitory computer-readable storage medium stores computer instructions, which, when executed by a computer, cause the computer to perform the method according to any one of claims 1 to 10.