Compiling method and device, electronic equipment and readable storage medium

By performing static analysis and code generation of page source files, page updates are triggered only when necessary, and the problem of waste of resources and inefficiency of large front-end frameworks in micro applications is solved, achieving more efficient development and performance optimization.

CN119045829APending Publication Date: 2024-11-29NETEASE (HANGZHOU) NETWORK CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411143790.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-19
Publication Date
2024-11-29

AI Technical Summary

Technical Problem

Existing large front-end frameworks are wasted resources and inefficient in development when building micro front-end applications, resulting in poor page loading speed and user experience.

Method used

By reading the page source file, parsing it into an abstract syntax tree, and performing static analysis to determine the variables that can cause view updates, generating executable code, and triggering page re-rendering only when these variable values ​​change, reducing unnecessary calculations and DOM operations .

Benefits of technology

Improves the development efficiency of micro front-end applications, reduces performance burden and resource waste, eliminates the need for huge volume and complex feature sets, and ensures that the page is only updated when necessary.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119045829A_ABST
    Figure CN119045829A_ABST
Patent Text Reader

Abstract

The invention discloses a compiling method and device, electronic equipment and a readable storage medium, and relates to the technical field of computers. The method comprises the following steps: reading a page source file; analyzing the page source file to obtain an abstract syntax tree; performing static analysis on the abstract syntax tree, and determining variables capable of causing page view updating in the static analysis process; according to the abstract syntax tree and the analysis result of the static analysis, executable codes are generated, and the executable codes comprise codes used for triggering the page view to be rerendered when the value of the variable capable of causing view updating changes. According to the method, unnecessary calculation and DOM operation can be reduced for the micro front-end application, the performance burden and resource waste of the micro front-end application are reduced, in addition, a huge size and a complex function set are not needed, and therefore the development efficiency of the micro front-end application is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computer technology, and in particular to a compilation method, a compilation device, an electronic device, and a computer-readable storage medium. Background Art

[0002] With the rapid development of Internet technology, the market demand for micro front-end applications with fast iteration and deployment is growing. Such applications usually have the characteristics of small code volume, few iterations, simple data management status, single function and limited number of pages. For example, promotion pages, special landing pages, etc., they often only need to display simple information and interactive functions, but need to respond quickly to market changes and user needs.

[0003] Currently, front-end developers mainly use the following two technical solutions to build front-end applications:

[0004] Use large front-end frameworks: such as Angular, React, Vue, etc. These frameworks excel in building large and complex applications with their rich features and powerful ecosystem. They support advanced features such as component-based development, state management, virtual DOM, etc., which can bring efficient development experience and good performance.

[0005] Traditional web development technology: a combination of HTML, CSS, and JavaScript, is simple and direct, suitable for small projects and rapid prototyping. However, it lacks the advantages of structured development and state management provided by modern front-end frameworks, making the development process inefficient and difficult to maintain.

[0006] However, the current mainstream front-end frameworks, such as Angular, React, and Vue, although they perform well in building large and complex applications, are not tailor-made for micro front-end applications. Using these large frameworks to develop micro applications often leads to waste of resources and reduced development efficiency. The large size and complex feature sets of these frameworks not only increase the burden of the project for micro applications, but also make the final packaged file size too large, affecting the page loading speed and user experience.

[0007] In current Web development practices, although there are a variety of mature front-end frameworks, they are often aimed at the development of large and complex applications. For micro Web applications, these frameworks will have unnecessary calculations and DOM operations, which will bring unnecessary performance burden and resource waste. Summary of the invention

[0008] The present disclosure provides a compilation method, a compilation device, an electronic device, and a computer-readable storage medium to solve or at least partially solve the above problems, as follows.

[0009] In a first aspect, the present disclosure provides a data processing method, the method comprising:

[0010] Read the page source file;

[0011] Parsing the page source file to obtain an abstract syntax tree;

[0012] Performing static analysis on the abstract syntax tree, and determining variables that may cause a page view update during the static analysis;

[0013] An executable code is generated according to the analysis results of the abstract syntax tree and the static analysis, wherein the executable code includes code for triggering the page view to be re-rendered when the value of the variable that can cause the view to be updated changes.

[0014] In a second aspect, the present disclosure further provides a compiling device, the device comprising:

[0015] File reading module, used to read page source files;

[0016] A file parsing module, used to parse the page source file to obtain an abstract syntax tree;

[0017] A static analysis module, used for performing static analysis on the abstract syntax tree and determining variables that may cause a page view update during the static analysis;

[0018] A code generation module is used to generate executable code based on the abstract syntax tree and the analysis results of the static analysis, wherein the executable code includes code for triggering the page view to be re-rendered when the value of the variable that can cause the view to be updated changes.

[0019] In a third aspect, the present disclosure further provides an electronic device, comprising: a processor, a memory, and computer program instructions stored in the memory and executable on the processor;

[0020] When the processor executes the computer program instructions, the compiling method described in the first aspect above is implemented.

[0021] In a fourth aspect, the present disclosure further provides a computer-readable storage medium, in which computer program instructions are stored. When the computer program instructions are executed by a processor, they are used to implement the compilation method described in the first aspect above.

[0022] The exemplary embodiments of the present disclosure have the following beneficial effects:

[0023] The compilation method provided by the present invention first reads the page source file, then parses the page source file to obtain an abstract syntax tree, then performs static analysis on the abstract syntax tree, and determines the variables that can cause the page view to be updated during the static analysis, and then generates executable code based on the abstract syntax tree and the analysis results of the static analysis, wherein the executable code includes code for triggering the page view to be re-rendered when the value of the variable that can cause the view to be updated changes, so as to ensure that the re-rendering of the page view is triggered only when the value of the variable that can cause the view to be updated changes, so that the page view is updated. In this way, unnecessary calculations and DOM operations can be reduced for micro front-end applications, reducing the performance burden and resource waste of micro front-end applications. In addition, the present invention does not require a large volume and a complex function set, thereby improving the development efficiency of micro front-end applications. BRIEF DESCRIPTION OF THE DRAWINGS

[0024] Figure 1 is a flowchart of a compilation method provided by one of the embodiments of the present disclosure;

[0025] Figure 2 is a block diagram of a compiling device provided by one of the embodiments of the present disclosure;

[0026] Figure 3 It is a logical structure diagram of an electronic device for implementing compilation provided by one of the embodiments of the present disclosure. DETAILED DESCRIPTION

[0027] In order to make the purpose, technical scheme and advantages of the embodiments of the present disclosure clearer, the technical scheme in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are only part of the embodiments of the present disclosure, rather than all of the embodiments. The components of the embodiments of the present disclosure generally described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present disclosure provided in the drawings is not intended to limit the scope of the present disclosure for protection, but merely represents the selected embodiments of the present disclosure. Based on the embodiments of the present disclosure, each other embodiment obtained by those skilled in the art without making creative work belongs to the scope of protection of the present disclosure.

[0028] The terms "a", "an", "the" and "said" are used in this specification to indicate the presence of one or more elements / components / etc.; the terms "including" and "having" are used to express an open-ended inclusion and mean that additional elements / components / etc. may exist in addition to the listed elements / components / etc.; the terms "first" and "second" etc. are used only as labels and are not intended to limit the quantity of their objects.

[0029] It should be understood that in the embodiments of the present disclosure, "at least one" means one or more, and "more than one" means two or more. "And / or" is merely a way to describe the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the previous and subsequent associated objects are in an "or" relationship. "Including A, B and / or C" means including any one, any two, or any three of A, B, and C.

[0030] It should be understood that in the embodiments of the present disclosure, "B corresponding to A", "B corresponding to A", "A corresponds to B", or "B corresponds to A" means that B is associated with A, and B can be determined according to A. Determining B according to A does not mean that B is determined only according to A, and B can also be determined according to A and / or other information.

[0031] The execution subject of the compilation method in one embodiment of the present disclosure may be a terminal device or a server, and the terminal device may be a desktop computer, a laptop computer, a tablet computer, a mobile phone, etc., or other electronic devices, which are not specifically limited in the present disclosure. The server is used to provide background services for the client of the application in the terminal device. For example, the server may be the background server of the above-mentioned application. The server may be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDN), and big data and artificial intelligence platforms, which are not specifically limited in the present disclosure.

[0032] Before describing the embodiments of the present disclosure in detail, the related art is firstly further introduced.

[0033] In software development, especially web development and mobile application development, view and component are two core concepts. There are both connections and differences between them, which will be explained in detail below.

[0034] View

[0035] The view is a part of the user interface that is responsible for displaying data to the user and allowing the user to interact with it. In the MVC (Model-View-Controller) architecture, the view is a visual representation of the model data. It usually does not contain business logic, but focuses on the display of data and the response to user interactions.

[0036] Component

[0037] Components are reusable units for building user interfaces. A component can contain its own template, logic, and style. It encapsulates part of the interface's functionality, allowing developers to build complex user interfaces like building blocks. Components can be simple buttons, input boxes, or complex dialog boxes, lists, and so on.

[0038] The relationship between views and components

[0039] Inclusion relationship: In some cases, a view can be considered as composed of multiple components. A complex view interface may be composed of multiple small, reusable components. These components are responsible for the display and logic processing of a part of the interface, and work together to complete the function of the entire view.

[0040] Functional division: Views usually focus on the layout of the entire interface and the display of data, while components focus more on implementing specific functions. By splitting the interface into multiple components, the code can be made more modular, easier to maintain and reuse.

[0041] Interaction: There may be interactions between views and components. For example, a component in a view may trigger an event, which needs to be captured and processed by the view or other components. This interaction enables the interface to respond to user operations and give corresponding feedback.

[0042] Data flow: In data-driven applications, data flow is also involved between views and components. The view may obtain data from the model and pass the data to the component for display. At the same time, the component may also modify the data and feed the modified data back to the model or view.

[0043] In summary, views and components play different roles in page development, but they are closely related. By using views and components properly, you can build a user interface that is both beautiful and efficient.

[0044] Common components in HTML include:

[0045] Text: The most basic component, directly written text.

[0046] Image: Use Tags to insert images.

[0047] Link: Use tag creates a hyperlink.

[0048] List: Use (unordered list) or (Ordered list) Create a list using Represents a list item.

[0049] Table: Use Define the table, Define the line, Defines the cell.

[0050] Form: Use <form>Define the form, form elements such as <input> , <select>,< / select> <textarea> wait.< / textarea>

[0051] Script: Use <script>标签引入JavaScript脚本。

[0052] 样式:使用<style>标签定义CSS样式。

[0053] 图1示出了本公开其中一个实施例提供的一种编译方法,如图1所示,该方法包括以下步骤S101~步骤S104。

[0054] 步骤S101:读取页面源文件。

[0055] 页面源文件就是存放网页代码的文件,开发人员通常就是在源文件中采用汇编语言或高级语言编写得到网页的源代码,页面源文件中的代码是机器无法识别的,因此需要转换为机器可识别的可执行代码。

[0056] 可选的,在本公开的其中一个实施例中,本步骤可以通过以下方式实现:异步读取页面源文件。

[0057] 可选的,可以采用Node.js的fs.promises.readFile方法来实现异步读取页面源文件,为了提高性能和非阻塞特性,可以采用异步版本。使用异步特性的读取过程,体现了对前端开发效率的考量,通过异步读取页面源文件,可以在不牺牲性能的前提下,有效地处理文件I / O操作。

[0058] 可选的,在本公开的其中一个实施例中,该编译方法还包括以下步骤:对页面源文件进行预处理。

[0059] 在本实施例中,可以对读取到的页面源文件进行一定的预处理,从而减少后续处理的复杂性和时间,从而提高整体编译效率。

[0060] 可选的,对页面源文件进行预处理,可以包括:删除页面源文件中位于文件内容首尾的空格字符。

[0061] 在本实施例中,可以去除页面源文件中位于文件内容首尾的空格字符,从而去除页面源文件中不必要的部分,提高后续处理的效率。

[0062] 步骤S102:对页面源文件进行解析,得到抽象语法树。

[0063] 在将页面源文件转换为机器可识别的可执行代码的过程中,首先需要对页面源文件进行解析,在一种实施方式中,可以将页面源文件中的内容进行语法分析,从而将其抽象为树结构进行表示,即表示为抽象语法树。

[0064] 可选的,在本公开的其中一个实施例中,本步骤可以包括以下步骤S1021~步骤S1022。

[0065] 步骤S1021:识别页面源文件中的代码内容。

[0066] 页面源文件中可以包括代码内容和模板内容。其中,页面源文件中的模板内容用于定义页面的结构布局,模板内容中通常包括样式定义、元素定义、元素属性、文本、注释等内容;页面源文件中的代码内容用于定义页面的动态交互,代码内容中通常包括页面组件的管理逻辑、与用户的交互逻辑等内容。页面源文件中的模板内容定义了页面的基础框架和布局,而页面源文件中的代码内容则负责使页面中的内容"活”起来,增加动态性和交互性。页面源文件中的模板内容是页面的骨架,而页面源文件中的代码内容则是让这个骨架"动起来”的肌肉和神经。

[0067] 可选的,本步骤具体可以通过以下方式实现:识别页面源文件中位于脚本标签中的代码内容。

[0068] 其中,页面源文件中的代码内容通常使用脚本标签定义,在页面源文件中,任何标签总是成对出现,即一对标签包括开始标签和结束标签,在本公开中,脚本标签的开始标签为<script>,脚本标签的开始标签为< / script> In this embodiment, it is possible to identify tags located in pairs in the page source file. <script>和标签< / script> , thereby obtaining the script block in the page source file.

[0069] Step S1022: Parse the code content in the page source file to obtain the code content parsing result, wherein the abstract syntax tree includes the code content parsing result.

[0070] Optionally, in this step, the code content in the page source file may be subjected to lexical analysis and grammatical analysis, and the code content analysis result obtained by the analysis may characterize the code content in the page source file.

[0071] In the process of parsing the code content in the page source file, the code content in the page source file can be converted into a symbol stream (also called a token stream) through lexical analysis, and whether the symbol stream conforms to the relevant grammar can be identified through syntax analysis. Syntax errors will be found during syntax analysis (i.e., whether the syntax structure of the code conforms to the language specification). If errors are found, they can be reported so that developers can correct the code in the source file. The process of lexical analysis is like analyzing each word in an English article, while syntax analysis is like analyzing whether each word conforms to the English grammar.

[0072] Exemplarily, parsing of the code content in the page source file may be achieved through an acorn parser.

[0073] Optionally, in one of the embodiments of the present disclosure, this step may also include the following steps S1023 to S1024.

[0074] Step S1023: Parse the template content in the page source file to obtain nodes.

[0075] As mentioned above, in addition to code content, the page source file also includes template content, which is usually written in <template>Tags (including the start tag <template> and the end tag< / template> ) is defined, and the content defined in the template content is usually hidden when the page is loaded and will not be displayed.

[0076] In this step, the template content in the page source file can be structured, so that the template content in the page source file is abstracted into nodes of an abstract node tree. A node can represent an expression, a statement, a function declaration, a variable declaration, etc.

[0077] Step S1024: Arrange the nodes according to the order of appearance in the page source file to obtain a node array, wherein the abstract syntax tree includes the node array.

[0078] In this step, the abstracted nodes can be arranged in the order of appearance in the page source file and recorded in the form of an array, thereby obtaining a node array, which can represent the template content in the page source file in the form of tree structure nodes.

[0079] In summary, the abstract syntax tree obtained by parsing the page source file may include the above nodes and the above code content parsing results. Optionally, the above nodes may be represented as node arrays, and the above code content parsing results may be represented as attribute values ​​of the script attribute.

[0080] The nodes of the abstract syntax tree can have multiple node types, some of which are described below.

[0081] 1. Element node: An element in HTML is an element class tag and the content it contains.

[0082] HTML page files are actually executable files composed of many different HTML elements, and any web browser can run HTML files directly. HTML elements are the basic objects that make up HTML page files. HTML elements can be defined by using HTML tags (including start tags and end tags that appear in pairs). Therefore, HTML elements can be identified by element class tags. Element nodes include image elements, list elements, hyperlink elements, and form elements.

[0083] 2. Attribute node: attribute content in html tag.

[0084] HTML attributes are additional information attached to HTML elements to provide additional details about the element or control the behavior of the element. The relationship between elements and attributes can be understood as follows: elements are the basic building blocks of HTML, while attributes provide these elements with additional functions and style information. Without attributes, elements can still exist, but their functions may be limited. Attributes are usually defined in the start tag in the form of "name: value" pairs. The attribute content can be identified in the start tag of an HTML element. For example, CSS styles can be defined in the style attribute.

[0085] 3. Text node: text content in HTML.

[0086] Text nodes can be identified by text class tags, such as paragraph tags. , Title tag <h1> arrive< / h1> <h6>.

[0087] 4. Comment node: comment content in HTML.

[0088] Comment nodes can be identified by comment tags. The syntax of HTML comments is to start with <! -- and end with -->. Anything between these two tags is considered a comment.

[0089] The above nodes may include but are not limited to the following attributes:

[0090] type attribute: used to store the node type (such as 'Element', 'Text').

[0091] name attribute: For element nodes, the tag name is stored in this attribute.

[0092] value attribute: For text nodes, the text content is stored in this attribute.

[0093] attributes property: an object or array used to store the attributes of the element.

[0094] children attribute: child node array. If the node contains child elements, the node contains child nodes, which are stored in this attribute.

[0095] In the node array, each node and the attributes of each node may be recorded in the order in which the node appears in the page source file.

[0096] Step S103: statically analyzing the abstract syntax tree, and determining variables that may cause the page view to be updated during the static analysis process.

[0097] In this step, static analysis may be performed on the abstract syntax tree obtained by parsing the page source file. During the static analysis, it is necessary to determine the variables in the page source file that may cause the page view to be updated.

[0098] Optionally, in one of the embodiments provided in the present disclosure, the step of determining the variables that may cause the page view to be updated during the static analysis process may be implemented by the following step S1031.

[0099] Step S1031: determining expression-related nodes from the nodes of the abstract syntax tree, and determining variables that may cause the page view to be updated from the expression-related nodes.

[0100] Optionally, in one of the embodiments provided in the present disclosure, the above step S1031 may include the following steps S1031 - 1 to S1031 - 2.

[0101] Step S1031-1: Determine an update operation expression node from the nodes of the abstract syntax tree;

[0102] Step S1031 - 2 : Record and update the first variable contained in the operation expression node, wherein the variables that may cause the page view to be updated include the first variable.

[0103] Exemplarily, the abstract syntax tree may include the following nodes:

[0104] 1. Literal

[0105] 2. VariableDeclarator

[0106] 3. Property

[0107] 4. Declaration:

[0108] VariableDeclaration

[0109] FunctionDeclaration

[0110] 5.Statement

[0111] BlockStatement

[0112] ExpressionStatement

[0113] IFStatement

[0114] WhileStatement - While Loop Statement

[0115] ForStatement - For loop statement

[0116] ReturnStatement-Return Statement

[0117] 6. Expression

[0118] AssignmentExpression

[0119] FunctionExpression

[0120] BinaryExpression

[0121] MemberExpression

[0122] CallExpression - call expression

[0123] ObjectExpression

[0124] ArrayExpression

[0125] UpdateExpression - Update operation expression

[0126] SequenceExpression

[0127] During the static analysis process, the nodes of the abstract syntax tree can be traversed, and update operation expression (UpdateExpression) nodes can be found from the nodes of the abstract syntax tree. The update operation expression is used to represent the increase or decrease operation of the numerical value, such as ++ (increment) and -- (decrement). Then, the variables contained in the update operation expression node are recorded, that is, the first variable, which is a variable that can cause the page view to be updated. During the static analysis process, the name of the first variable can be added to the first set (such as the willChange set), indicating that the first variable is a variable in the update operation expression node that can cause the page view to be updated.

[0128] For example, in the statement let count=0;count++;, count++ will be parsed as an UpdateExpression node, where the variable to be changed is count and the operation is ++ (increment). During the static analysis process, the name of the variable count will be added to a willChange collection, indicating that count is a variable that can cause the page view to be updated, and its change may affect the state of the page component and needs to be considered when the page component is updated.

[0129] Optionally, in one of the embodiments provided in the present disclosure, the above step S1031 may also include the following steps S1031 - 3 to S1031 - 4 .

[0130] Step S1031-3: Determine an expression statement node from the nodes of the abstract syntax tree;

[0131] Step S1031 - 4 : If the variable included in the expression statement node exists in the portion of the template content corresponding to the page source file in the abstract syntax tree, then the second variable included in the expression statement node is recorded, wherein the variable that can cause the page view to be updated includes the second variable.

[0132] During the static analysis process, the nodes of the abstract syntax tree can be traversed, and expression statement (ExpressionStatement) nodes can be found from the nodes of the abstract syntax tree. An expression statement is usually a statement containing any expression, such as an assignment expression, a function call, or any other type of expression. If the variable contained in an expression statement node exists in the part of the template content corresponding to the page source file in the abstract syntax tree, that is, the expression statement in the expression statement node exists in the template content part of the page source file, then the variable contained in the expression statement node can be recorded, that is, the second variable, and the second variable is also a variable that can cause the page view to be updated. During the static analysis process, the name of the second variable can be added to the second set (such as the willUseInTemplate set), indicating that the second variable is a variable in the expression statement node that can cause the page view to be updated.

[0133] Optionally, in one of the embodiments provided in the present disclosure, performing static analysis on the abstract syntax tree may further include the following step S1032.

[0134] Step S1032: Determine the dependency relationship between the variables that may cause the page view to be updated and the page components.

[0135] The dependency relationship between the variables that can cause the page view to update and the page components determines which page components can be changed when these variables are changed, and which parts of the page components can be changed.

[0136] Optionally, step S1032 may be implemented by following steps S1032-1 to S1032-2.

[0137] Step S1032-1: Determine the source position of the expression containing the variable that can cause the page view to be updated in the part representing the code content of the page source file in the abstract syntax tree;

[0138] Step S1032-2: Based on the source location, construct a dependency relationship between the variable that can cause the page view to update and the page component.

[0139] In this embodiment, after recursively traversing the abstract syntax tree and identifying all variables (including the first variable and the second variable) that may affect the output of the page component, the part of the abstract syntax tree that represents the code content of the page source file can be analyzed to locate the source position of the part of the abstract syntax tree that represents the code content of the page source file to determine how these variables are assigned and modified, including whether they depend on other variables. In this way, a complete dependency graph can be constructed, which not only includes direct dependencies, but also captures indirect dependencies and transitive dependencies.

[0140] In this embodiment, a list can be created for each variable that may cause a page view update to record all nodes that depend on the variable. For each variable that may cause a page view update, all expressions and function calls that may affect its value are recursively analyzed to ensure that even indirect dependencies can be captured.

[0141] Optionally, in one of the embodiments provided in the present disclosure, performing static analysis on the abstract syntax tree may further include the following step S1033.

[0142] Step S1033: Determine the variables declared in the web page source file.

[0143] In this embodiment, the variable declaration node may be determined from the nodes of the abstract syntax tree, and the variables included in the variable declaration node may be recorded.

[0144] Among them, the variable declaration node can be determined by traversing the abstract syntax tree.

[0145] In this embodiment, the names of the variables contained in the variable declaration node may be added to a third set (eg, a variables set) to facilitate subsequent scope analysis of the variables declared in the web page source file.

[0146] Optionally, in one of the embodiments provided in the present disclosure, performing static analysis on the abstract syntax tree may further include the following steps S1034 to S1036.

[0147] Step S1034: Determine the declaration position of the declared variable;

[0148] Step S1035: Determine the declaration position of the function where the declared variable is located;

[0149] Step S1036: Determine the scope of the declared variable according to the declaration position of the declared variable and the declaration position of the function where the declared variable is located.

[0150] In this embodiment, the variable scope and page component life cycle analysis can be performed by identifying the definition location of variables and functions and how they are used in page components. This involves analyzing variable declarations (such as let, const) and their scopes (such as global, module, function, etc.). For example, variables declared by let are block-level variables with block-level scope, which means that variables declared by let are only valid within the code block in which they are declared; for example, variables declared by var have function scope or global scope; for another example, the scope of variables declared by const can be global scope or local scope, depending on where it is declared. If a const variable is declared in the global scope, then it is a global variable and can be accessed anywhere in the program. If it is declared inside a function or in any other block-level scope, then it is a local variable and can only be accessed within that specific scope.

[0151] In addition, by analyzing the life cycle hooks of page components (such as onMount and onDestroy defined in advance in the template content), the timing of resource creation and cleanup can be determined, thereby ensuring that during the execution phase of the executable code, all relevant resources are properly processed or released when the page components are in states such as loading, unloading, and updating.

[0152] Step S104: Generate executable code according to the analysis results of the abstract syntax tree and static analysis, wherein the executable code includes code for triggering the page view to be re-rendered when the value of the variable that can cause the view to be updated changes.

[0153] In this step, the abstract syntax tree may be traversed to generate executable codes for DOM operations on nodes of each node type, such as element, text, etc., in the abstract syntax tree.

[0154] Optionally, in one embodiment of the present disclosure, step S104 further includes the following steps: generating executable code for managing page components according to the analysis results of the static analysis.

[0155] The management of page components includes the entire life cycle of creation, update and destruction of page components.

[0156] Optionally, the analysis results of the static analysis include the scope of the variables declared in the webpage source file, and the dependency relationship between the variables and the page components that may cause the page view to be updated. Accordingly, according to the analysis results of the static analysis, the step of generating the executable code for managing the page components may be specifically implemented in the following manners, including:

[0157] Generate executable code for creating page components based on the scope of variables declared in the web page source file;

[0158] Generate executable code for updating the page component according to the dependency relationship between the variable that can cause the page view to be updated and the page component;

[0159] Generate executable code for destroying page components according to the scope of variables declared in the web page source file.

[0160] Variables that can cause the page view to update will affect the update of the page view. In generating the executable code, it is ensured that only the state changes that really affect the rendering result will trigger the re-rendering of the page view, avoiding unnecessary calculations and DOM operations. In the present disclosure, the executable code for updating the page component is used to trigger the page view to re-render when the value of the variable that can cause the view to update changes. In addition, the binding of the event listener is also in the process of generating the executable code for updating the page component.

[0161] The scope of variables declared in the page source file enables the generated executable code to correctly manage closures, reducing runtime memory usage and potential memory leaks.

[0162] Optionally, the compilation method provided by the present disclosure may further include the following steps: persisting the executable code in a file system.

[0163] Persisting code to the file system means saving program data from computer memory or other temporary storage to a long-term storage medium such as a hard disk, SSD, USB flash drive, or cloud storage. This means converting data from a short-lived memory state to a long-term state to ensure that data is not lost when the program ends, so that the previous state or data can be restored after the program is restarted. In programming and program development, persistence allows developers to save data while the program is running so that they can reuse the data later when needed, such as user information, application status, or any data that needs to be maintained between different running instances of the program.

[0164] The exemplary embodiments of the present disclosure may have the following advantages:

[0165] 1. Customized grammar rules: The parser disclosed in the present invention can adopt a highly flexible and extensible design. Through a modular and plug-in architecture, it allows developers to easily add support for new grammars, use a recursive descent parsing algorithm to deeply understand the nested structure of templates, and combine context-sensitive parsing strategies to make accurate grammatical analysis. For a specific template language, it can more accurately parse and understand the grammatical structure and template grammar characteristics of the language.

[0166] 2. Allows for extended and customized parsing: The parser disclosed in the present invention can adopt an open plug-in architecture and a configuration-driven design, so that developers can add new grammar rules or adjust existing rules through a simple interface. In addition, the parser provides a rich API and hook mechanism, allowing custom logic to be inserted into the parsing process, further enhancing its ability to adapt to different template structures and custom grammars. The solution itself provides an overall construction framework with direction, which can encapsulate the parse function (parsing function) according to custom requirements. These are not fixed, and the templates are all variable. The main thing is to determine the template and then encapsulate the parser according to the structure of the template.

[0167] 3. Focus on performance optimization: The static analysis of the present disclosure focuses specifically on identifying and optimizing performance bottlenecks, such as avoiding unnecessary calculations and DOM operations by accurately identifying which variables and expressions actually affect view updates.

[0168] 4. Componentization and Responsiveness Analysis: The static analysis in this disclosure not only analyzes the code structure, but also focuses on the componentized architecture and responsiveness, identifying dependencies and data flows between components to ensure that the generated code can efficiently handle changes in component status.

[0169] 5. Scope and Lifecycle Analysis: The static analysis in this disclosure deeply understands the scope of components and the lifecycle of variables, so that more optimized code can be generated, reducing runtime memory usage and potential memory leaks.

[0170] 6. Analysis of separation of template and logic: The static analysis disclosed in the present invention can handle the situation where template and logic are separated, identify the expressions in the template part and the variables in the logic part of the web page source file, and ensure that the generated executable code can correctly bind the expressions to the corresponding logical context instead of relying on runtime parsing. This greatly improves the execution efficiency of the code and reduces the computational burden of the page runtime.

[0171] 7. Generate optimized code structure: Compared with traditional static analysis, the analysis results disclosed in the present invention are used to generate more optimized and structured codes, which are not only highly readable but also easy to maintain and expand.

[0172] 8. Strong adaptability: The static analysis method disclosed in the present invention is designed to be highly adaptable and can be easily integrated into different development environments and workflows, supporting a variety of code styles and development modes.

[0173] The exemplary embodiments provided by the present disclosure can be optimized for the development requirements of micro Web applications, and provide the advantages of lightweight, rapid development, and simplified architecture.

[0174] The compilation method provided by the present invention first reads the page source file, then parses the page source file to obtain an abstract syntax tree, then performs static analysis on the abstract syntax tree, and determines the variables that can cause the page view to be updated during the static analysis, and then generates executable code based on the abstract syntax tree and the analysis results of the static analysis, wherein the executable code includes code for triggering the page view to be re-rendered when the value of the variable that can cause the view to be updated changes, so as to ensure that the re-rendering of the page view is triggered only when the value of the variable that can cause the view to be updated changes, so that the page view is updated. In this way, unnecessary calculations and DOM operations can be reduced for micro front-end applications, reducing the performance burden and resource waste of micro front-end applications. In addition, the present invention does not require a large volume and a complex function set, thereby improving the development efficiency of micro front-end applications.

[0175] Corresponding to the compilation method provided in the embodiment of the present disclosure, the embodiment of the present disclosure also provides a compilation device. Figure 3 As shown, the device 700 includes:

[0176] The file reading module 701 is used to read the page source file;

[0177] A file parsing module 702, used to parse the page source file to obtain an abstract syntax tree;

[0178] A static analysis module 703, configured to perform static analysis on the abstract syntax tree and determine variables that may cause a page view to be updated during the static analysis;

[0179] The code generation module 704 is used to generate executable code based on the abstract syntax tree and the analysis results of the static analysis, wherein the executable code includes code for triggering the page view to be re-rendered when the value of the variable that can cause the view update changes.

[0180] Optionally, determining the variable that may cause the page view to be updated during the static analysis process includes:

[0181] An expression-related node is determined from the nodes of the abstract syntax tree, and a variable that can cause a page view update is determined from the expression-related node.

[0182] Optionally, determining expression-related nodes from the nodes of the abstract syntax tree, and determining variables that may cause page view update from the expression-related nodes, includes:

[0183] Determine an update operation expression node from the nodes of the abstract syntax tree;

[0184] The first variable included in the update operation expression node is recorded, wherein the variable that can cause the page view to update includes the first variable.

[0185] Optionally, the determining of expression-related nodes from the nodes of the abstract syntax tree, and determining of variables that may cause page view update from the expression-related nodes, further includes:

[0186] Determine an expression statement node from the nodes of the abstract syntax tree;

[0187] If the variable included in the expression statement node exists in the part of the abstract syntax tree corresponding to the template content of the page source file, then the second variable included in the expression statement node is recorded, wherein the variable that can cause the page view to be updated includes the second variable.

[0188] Optionally, the static analysis of the abstract syntax tree further includes:

[0189] Determine the dependency relationship between the variable that can cause the page view to update and the page component.

[0190] Optionally, determining the dependency relationship between the variable that may cause the page view to update and the page component includes:

[0191] Determine the source position of the expression where the variable that can cause the page view update is located in the part of the abstract syntax tree that represents the code content of the page source file;

[0192] According to the source location, a dependency relationship between the variable that can cause the page view to update and the page component is constructed.

[0193] Optionally, the page source file is parsed to obtain an abstract syntax tree, including:

[0194] Identify the code content in the page source file;

[0195] The code content in the page source file is parsed to obtain a code content parsing result, wherein the abstract syntax tree includes the code content parsing result.

[0196] Optionally, the identifying the code content in the page source file includes:

[0197] Identify the code content located in the script tag in the page source file.

[0198] Optionally, parsing the code content in the page source file includes:

[0199] Perform lexical analysis and grammatical analysis on the code content in the page source file.

[0200] Optionally, the parsing the page source file to obtain an abstract syntax tree further includes:

[0201] Parsing the template content in the page source file to obtain a node;

[0202] The nodes are arranged in the order of appearance in the page source file to obtain a node array, wherein the abstract syntax tree includes the node array.

[0203] Optionally, parsing the template content in the page source file includes:

[0204] The template content in the page source file is represented in a structured manner.

[0205] Optionally, generating executable code according to the abstract syntax tree and the analysis result of the static analysis includes:

[0206] Traversing the abstract syntax tree;

[0207] Generate executable code for DOM operations on nodes of each node type in the abstract syntax tree.

[0208] Optionally, the generating executable code according to the abstract syntax tree and the analysis result of the static analysis further includes:

[0209] According to the analysis result of the static analysis, an executable code for managing page components is generated.

[0210] Optionally, the analysis result of the static analysis includes the scope of the variables declared in the webpage source file, and the dependency relationship between the variables that may cause the page view to be updated and the page components, and the generating of the executable code for managing the page components according to the analysis result of the static analysis includes:

[0211] Generate executable code for creating page components according to the scope of the variables declared in the webpage source file;

[0212] Generate executable code for updating the page component according to the dependency relationship between the variable that can cause the page view to be updated and the page component;

[0213] According to the scope of the variable declared in the webpage source file, an executable code for destroying the page component is generated.

[0214] Optionally, the device is also used for:

[0215] The executable code is persisted in a file system.

[0216] Optionally, the reading of the page source file includes:

[0217] Asynchronously reads the page source file.

[0218] Optionally, the device is also used for:

[0219] The page source file is preprocessed.

[0220] Optionally, the preprocessing of the page source file includes:

[0221] Delete the space characters at the beginning and end of the file content in the page source file.

[0222] The compilation device provided by the present invention first reads the page source file, then parses the page source file to obtain an abstract syntax tree, then performs static analysis on the abstract syntax tree, and determines the variables that can cause the page view to be updated during the static analysis, and then generates executable code based on the abstract syntax tree and the analysis results of the static analysis, wherein the executable code includes code for triggering the page view to be re-rendered when the value of the variable that can cause the view to be updated changes, so as to ensure that the re-rendering of the page view is triggered only when the value of the variable that can cause the view to be updated changes, so that the page view is updated. In this way, unnecessary calculations and DOM operations can be reduced for micro front-end applications, reducing the performance burden and resource waste of micro front-end applications. In addition, the present invention does not require a large volume and a complex function set, thereby improving the development efficiency of micro front-end applications.

[0223] Next, an electronic device provided by an embodiment of the present disclosure is introduced. Figure 3 , Figure 3 A schematic diagram of the structure of an electronic device provided in an embodiment of the present disclosure. The electronic device 800 may be deployed with the compilation device described in the embodiment of the present disclosure to implement the functions in the embodiment of the present disclosure. Specifically, the electronic device 800 includes: a receiver 801, a transmitter 802, a processor 803 and a memory 804 (the number of processors 803 in the electronic device 800 may be one or more, Figure 3 In the example of FIG. 801 , the processor 803 may include an application processor 8031 ​​and a communication processor 8032. In some embodiments of the present disclosure, the receiver 801, the transmitter 802, the processor 803 and the memory 804 may be connected via a bus or other means.

[0224] The memory 804 may include a read-only memory and a random access memory, and provides instructions and data to the processor 803. A portion of the memory 804 may also include a non-volatile random access memory (NVRAM). The memory 804 stores processor and operation instructions, executable modules or data structures, or subsets thereof, or extended sets thereof, wherein the operation instructions may include various operation instructions for implementing various operations.

[0225] The processor 803 controls the operation of the execution device. In a specific application, the various components of the execution device are coupled together through a bus system, wherein the bus system includes not only a data bus but also a power bus, a control bus, and a status signal bus, etc. However, for the sake of clarity, various buses are referred to as bus systems in the figure.

[0226] The method disclosed in the above embodiment of the present disclosure can be applied to the processor 803, or implemented by the processor 803. The processor 803 can be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit or software instructions in the processor 803. The above processor 803 can be a general processor, a digital signal processor (digital signal processing, DSP), a microprocessor or a microcontroller, and can further include an application specific integrated circuit (application specific integrated circuit, ASIC), a field programmable gate array (field-programmable gate array, FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The processor 803 can implement or execute the methods, steps and logic block diagrams disclosed in the embodiment of the present disclosure. The general processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in conjunction with the embodiment of the present disclosure can be directly embodied as a hardware decoding processor to be executed, or a combination of hardware and software modules in the decoding processor can be executed. The software module may be located in a storage medium mature in the art, such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 804, and the processor 803 reads the information in the memory 804 and completes the steps of the above method in combination with its hardware.

[0227] The receiver 801 can be used to receive input digital or character information and generate signal input related to the relevant settings and function control of the execution device. The transmitter 802 can be used to output digital or character information through the first interface; the transmitter 802 can also be used to send instructions to the disk group through the first interface to modify the data in the disk group; the transmitter 802 can also include a display device such as a display screen.

[0228] In the embodiment of the present disclosure, the application processor 8031 ​​in the processor 803 is used to execute the compilation method in the embodiment of the present disclosure. It should be noted that the specific manner in which the application processor 8031 ​​executes each step is based on the same concept as the various method embodiments in the present disclosure, and the technical effects brought by it are the same as the various method embodiments in the present disclosure. For specific contents, please refer to the description in the method embodiments shown in the foregoing of the present disclosure, and no further description will be given here.

[0229] The disclosed embodiment also provides a chip for executing instructions, which is used to execute the technical solution of the compilation method in the above embodiment.

[0230] The embodiment of the present disclosure further provides a computer-readable storage medium, in which computer instructions are stored. When the computer instructions are executed on a processor, the processor executes the technical solution of the compilation method in the above embodiment.

[0231] The embodiments of the present disclosure further provide a computer program product, including a computer program, which is used to execute the technical solution of the compiling method in the above embodiments when executed by a processor.

[0232] The computer readable storage medium mentioned above can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk. The readable storage medium can be any available medium that can be accessed by a general or dedicated server.

[0233] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.

[0234] Although the present disclosure is disclosed as above in the form of a preferred embodiment, it is not intended to limit the present disclosure. Any person skilled in the art may make possible changes and modifications without departing from the spirit and scope of the present disclosure. Therefore, the scope of protection of the present disclosure shall be based on the scope defined by the claims of the present disclosure.< / h6> < / template> < / form>

Claims

1. A compilation method, It is characterized in that The method comprises: Read the page source file; Parsing the page source file to obtain an abstract syntax tree; Performing static analysis on the abstract syntax tree, and determining variables that may cause a page view update during the static analysis; An executable code is generated according to the analysis results of the abstract syntax tree and the static analysis, wherein the executable code includes code for triggering the page view to be re-rendered when the value of the variable that can cause the view to be updated changes.

2. The method according to claim 1, It is characterized in that Determining the variables that may cause the page view to be updated during the static analysis process includes: An expression-related node is determined from the nodes of the abstract syntax tree, and a variable that can cause a page view update is determined from the expression-related node.

3. The method according to claim 2, It is characterized in that The step of determining expression-related nodes from the nodes of the abstract syntax tree, and determining variables that may cause page view updates from the expression-related nodes, includes: Determine an update operation expression node from the nodes of the abstract syntax tree; The first variable included in the update operation expression node is recorded, wherein the variable that can cause the page view to update includes the first variable.

4. The method according to claim 3, It is characterized in that The step of determining expression-related nodes from the nodes of the abstract syntax tree, and determining variables that may cause a page view update from the expression-related nodes, further includes: Determine an expression statement node from the nodes of the abstract syntax tree; If the variable included in the expression statement node exists in the part of the abstract syntax tree corresponding to the template content of the page source file, then the second variable included in the expression statement node is recorded, wherein the variable that can cause the page view to be updated includes the second variable.

5. The method according to claim 1, It is characterized in that The static analysis of the abstract syntax tree further includes: Determine the dependency relationship between the variable that can cause the page view to update and the page component.

6. The method according to claim 5, It is characterized in that The determining of the dependency relationship between the variable that may cause the page view to be updated and the page component includes: Determine the source position of the expression where the variable that can cause the page view update is located in the part of the abstract syntax tree that represents the code content of the page source file; According to the source location, a dependency relationship between the variable that can cause the page view to update and the page component is constructed.

7. The method according to claim 1, It is characterized in that The static analysis of the abstract syntax tree further includes: Variables declared in the web page source file are determined.

8. The method according to claim 7, It is characterized in that The determining of the variables declared in the webpage source file comprises: Determine a variable declaration node from the nodes of the abstract syntax tree; Record the variables contained in the variable declaration node.

9. The method according to claim 7, It is characterized in that The static analysis of the abstract syntax tree further includes: Determining the declaration position of the declared variable; Determine the declaration position of the function where the declared variable is located; The scope of the declared variable is determined according to the declaration position of the declared variable and the declaration position of the function where the declared variable is located.

10. The method according to claim 1, It is characterized in that The page source file is parsed to obtain an abstract syntax tree, including: Identify the code content in the page source file; The code content in the page source file is parsed to obtain a code content parsing result, wherein the abstract syntax tree includes the code content parsing result.

11. The method according to claim 10, It is characterized in that The identifying of the code content in the page source file includes: Identify the code content located in the script tag in the page source file.

12. The method according to claim 10, It is characterized in that The parsing of the code content in the page source file includes: Perform lexical analysis and grammatical analysis on the code content in the page source file.

13. The method according to claim 10, It is characterized in that The parsing of the page source file to obtain an abstract syntax tree also includes: Parsing the template content in the page source file to obtain a node; The nodes are arranged in the order of appearance in the page source file to obtain a node array, wherein the abstract syntax tree includes the node array.

14. The method according to claim 13, It is characterized in that The parsing of the template content in the page source file includes: The template content in the page source file is represented in a structured manner.

15. The method according to claim 1, It is characterized in that The step of generating executable code according to the abstract syntax tree and the analysis result of the static analysis includes: Traversing the abstract syntax tree; Generate executable code for DOM operations on nodes of each node type in the abstract syntax tree.

16. The method according to claim 15, It is characterized in that The step of generating executable code according to the abstract syntax tree and the analysis result of the static analysis further includes: According to the analysis result of the static analysis, an executable code for managing page components is generated.

17. The method according to claim 16, It is characterized in that The analysis result of the static analysis includes the scope of the variables declared in the webpage source file and the dependency relationship between the variables that may cause the page view to be updated and the page components. The generating of the executable code for managing the page components according to the analysis result of the static analysis includes: Generate executable code for creating page components according to the scope of the variables declared in the webpage source file; Generate executable code for updating the page component according to the dependency relationship between the variable that can cause the page view to be updated and the page component; According to the scope of the variable declared in the webpage source file, an executable code for destroying the page component is generated.

18. The method according to claim 1, It is characterized in that The method further comprises: The executable code is persisted in a file system.

19. The method according to claim 1, It is characterized in that The reading of the page source file includes: Asynchronously reads the page source file.

20. The method according to claim 1, It is characterized in that The method further comprises: The page source file is preprocessed.

21. The method according to claim 20, It is characterized in that The preprocessing of the page source file includes: Delete the space characters at the beginning and end of the file content in the page source file.

22. A compiling device, It is characterized in that The device comprises: File reading module, used to read page source files; A file parsing module, used to parse the page source file to obtain an abstract syntax tree; A static analysis module, used for performing static analysis on the abstract syntax tree and determining variables that may cause a page view update during the static analysis; A code generation module is used to generate executable code based on the abstract syntax tree and the analysis results of the static analysis, wherein the executable code includes code for triggering the page view to be re-rendered when the value of the variable that can cause the view to be updated changes.

23. An electronic device, It is characterized in that include: A processor, a memory, and computer program instructions stored on the memory and executable on the processor; When the processor executes the computer program instructions, the compilation method as described in any one of claims 1 to 21 is implemented.

24. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores computer program instructions, and when the computer program instructions are executed by a processor, they are used to implement the compilation method as described in any one of claims 1 to 21 above.

Citation Information

Cited By

  • Low-code platform loop component rendering performance optimization method and system

    CN119597371A