Code compiling method and device, equipment, medium and product
By automatically generating the target class names of HTML elements during the code compilation process, the class name conflict problem is resolved, improving code development efficiency and readability.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-23
- Publication Date
- 2026-03-24
AI Technical Summary
In existing technologies, conflicts can easily occur when combining HTML element class names by specifying class names by the user, resulting in low code development efficiency.
By responding to code compilation operations, the attribute information of the element node to be compiled is read, the parent element node is searched upwards and the target attribute name is obtained. Based on the inherited class name of the parent element node and the inherited class name of the element node to be compiled, the target class name is automatically generated, thus resolving the class name conflict problem.
It enables the automatic generation of unique class names, improving code development efficiency, reducing code development workload, and enhancing code readability.
Smart Images

Figure CN121722397A_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of computer technology, and more particularly to a code compilation method, apparatus, device, medium, and product. Background Technology
[0002] In web front-end development, HTML (HyperText Markup Language) elements are typically used to develop CSS (Cascading Style Sheets) code, which defines the layout of a webpage. To clearly distinguish the application of different styles within CSS, it's usually necessary to assign unique class names to HTML elements in the CSS code. These class names specify which HTML elements should apply which style rules.
[0003] In existing technologies, the common method for determining HTML element class names is to combine multiple user-specified class names when developing CSS code, thus assigning a unique class name to each element. This method of combining element class names by user specification is prone to conflicts when there are a large number of elements, and it also requires writing a large number of element class names, resulting in low code development efficiency. Summary of the Invention
[0004] This disclosure provides a code compilation method, apparatus, device, medium, and product to automatically generate unique class names for code elements, thereby improving code development efficiency.
[0005] In a first aspect, embodiments of this disclosure provide a code compilation method, the method comprising:
[0006] In response to the code compilation operation, read the first attribute information of the code to be compiled corresponding to the element node to be compiled;
[0007] In response to an event that the first attribute information includes the target attribute name, the parent element node of the element node to be compiled is searched upwards and the target attribute name of the parent element node is obtained.
[0008] In response to an event in which the parent element node includes the target attribute name, the target class name of the element node to be compiled is determined based on the inherited class name of the parent element node and the inherited class name of the element node to be compiled.
[0009] Based on the code to be compiled of the element node to be compiled and the target class name, the target compiled code of the code to be compiled is determined.
[0010] Secondly, embodiments of this disclosure also provide a code compilation apparatus, the apparatus comprising:
[0011] The information reading module is used to read the first attribute information of the code to be compiled corresponding to the element node to be compiled in response to the code compilation operation;
[0012] The uplink lookup module is used to respond to an event in which the first attribute information includes the target attribute name, to search uplink to the parent element node of the element node to be compiled and obtain the target attribute name of the parent element node;
[0013] The target class name determination module is used to respond to an event in which the parent element node includes the target attribute name, and determine the target class name of the element node to be compiled based on the inherited class name of the parent element node and the inherited class name of the element node to be compiled.
[0014] The target compiled code determination module is used to determine the target compiled code of the code to be compiled based on the code to be compiled of the element node to be compiled and the target class name.
[0015] Thirdly, embodiments of this disclosure also provide an electronic device, the electronic device comprising:
[0016] One or more processors;
[0017] Storage device for storing one or more programs.
[0018] When the one or more programs are executed by the one or more processors, the one or more processors implement the code compilation method as described in any of the embodiments of this disclosure.
[0019] Fourthly, embodiments of this disclosure also provide a storage medium containing computer-executable instructions, which, when executed by a computer processor, are used to perform the code compilation method as described in any of the embodiments of this disclosure.
[0020] Fifthly, embodiments of this disclosure also provide a computer program product, including a computer program that, when executed by a processor, implements the code compilation method as described in any of the embodiments of this disclosure.
[0021] The technical solution of this disclosure, in response to a code compilation operation, reads the first attribute information of the code to be compiled corresponding to the element node to be compiled; in response to an event that the first attribute information includes a target attribute name, searches upwards for the parent element node of the element node to be compiled and obtains the target attribute name of the parent element node; in response to an event that the parent element node includes a target attribute name, determines the target class name of the element node to be compiled based on the inheritance class name of the parent element node and the inheritance class name of the element node to be compiled; and determines the target compiled code of the code to be compiled based on the code to be compiled and the target class name of the element node to be compiled. This solves the problem of element class name conflicts and low code development efficiency caused by the method of combining element class names by user-specified class names in the prior art, and realizes that when developing code, the user only needs to develop... The class name to be inherited by the element node to be compiled does not need to carry the class name of the parent element node. That is, there is no need to develop a target class name to uniquely locate the element node to be compiled, reducing the amount of code development. When compiling the code, by determining that the first attribute information of the element node to be compiled includes the target attribute name, the parent element node of the element node to be compiled is searched upwards. When the target attribute name is included in the parent element node, the inherited class name of the parent element node is automatically used as a prefix and appended to the class name to be inherited by the element node to be compiled to obtain the target class name of the element node to be compiled. The style applied to the element node to be compiled can be located through the target class name. This realizes the automatic generation of unique class names for code elements while improving code readability, thereby improving code development efficiency. Attached Figure Description
[0022] The above and other features, advantages, and aspects of the embodiments of this disclosure will become more apparent from the accompanying drawings and the following detailed description. Throughout the drawings, the same or similar reference numerals denote the same or similar elements. It should be understood that the drawings are schematic, and the originals and elements are not necessarily drawn to scale.
[0023] Figure 1 A flowchart illustrating a code compilation method provided in an embodiment of this disclosure;
[0024] Figure 2 A flowchart illustrating a code compilation method provided in an embodiment of this disclosure;
[0025] Figure 3 A flowchart illustrating a code compilation method provided in an embodiment of this disclosure;
[0026] Figure 4 A flowchart illustrating a code compilation method provided in an embodiment of this disclosure;
[0027] Figure 5 This is a schematic diagram of the structure of a code compilation apparatus provided in an embodiment of the present disclosure;
[0028] Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this disclosure. Detailed Implementation
[0029] Embodiments of this disclosure will now be described in more detail with reference to the accompanying drawings. While some embodiments of this disclosure are shown in the drawings, it should be understood that this disclosure can be implemented in various forms and should not be construed as limited to the embodiments set forth herein. Rather, these embodiments are provided to provide a more thorough and complete understanding of this disclosure. It should be understood that the accompanying drawings and embodiments of this disclosure are for illustrative purposes only and are not intended to limit the scope of protection of this disclosure.
[0030] It should be understood that the steps described in the method embodiments of this disclosure may be performed in different orders and / or in parallel. Furthermore, the method embodiments may include additional steps and / or omit the steps shown. The scope of this disclosure is not limited in this respect.
[0031] The term "comprising" and its variations as used herein are open-ended inclusions, meaning "including but not limited to". The term "based on" means "at least partially based on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". Definitions of other terms will be given in the description below.
[0032] It should be noted that the concepts of "first" and "second" mentioned in this disclosure are used only to distinguish different devices, modules or units, and are not used to limit the order of functions performed by these devices, modules or units or their interdependencies.
[0033] It should be noted that the terms "a" and "a plurality of" used in this disclosure are illustrative rather than restrictive, and those skilled in the art should understand that, unless otherwise expressly indicated in the context, they should be understood as "one or more".
[0034] The names of messages or information exchanged between multiple devices in the embodiments of this disclosure are for illustrative purposes only and are not intended to limit the scope of such messages or information.
[0035] It is understood that before using the technical solutions disclosed in the various embodiments of this disclosure, users should be informed of the types, scope of use, and usage scenarios of the personal information involved in this disclosure in an appropriate manner in accordance with relevant laws and regulations, and user authorization should be obtained.
[0036] For example, upon receiving a user's active request, a prompt message is sent to the user to explicitly inform them that the requested operation will require the acquisition and use of the user's personal information. This allows the user to independently choose whether to provide personal information to the software or hardware, such as the electronic device, application, server, or storage medium performing the operations of this disclosed technical solution, based on the prompt message.
[0037] As an optional but non-limiting implementation, in response to a user's active request, sending a prompt message to the user can be done via a pop-up window, where the prompt message can be presented in text format. Furthermore, the pop-up window can also include a selection control allowing the user to choose "agree" or "disagree" to provide personal information to the electronic device.
[0038] It is understood that the above notification and user authorization process are merely illustrative and do not constitute a limitation on the implementation of this disclosure. Other methods that comply with relevant laws and regulations may also be applied to the implementation of this disclosure.
[0039] It is understood that the data involved in this technical solution (including but not limited to the data itself, the acquisition or use of the data) shall comply with the requirements of relevant laws, regulations and related provisions.
[0040] Before introducing the technical solutions provided by the embodiments of the present invention, an exemplary application scenario can be given first. This technical solution can be applied to any scenario that requires compiling front-end code. For example, when compiling web front-end code, it is necessary to ensure that the html elements in the CSS of the front-end code have unique class names so that the styles applied to the elements can be specified through the class names. In this case, the technical solution based on the embodiments of the present disclosure can be implemented. It should be noted that the code compilation method provided by this technical solution can be integrated into a plugin, which is the target compilation plugin. The target compilation plugin can be installed in the development platform or deployed independently. After the code is written in the development platform or during the process of writing code in the development platform, the development code can be compiled by calling the target compilation plugin, generating a unique class name for each element in the code, and converting the code into target code in any development environment.
[0041] Figure 1 This is a flowchart illustrating a code compilation method provided in an embodiment of the present disclosure. The embodiments of the present disclosure are applicable to any scenario that requires the compilation of front-end code. The method can be executed by a code compilation device, which can be implemented in the form of software and / or hardware. Optionally, it can be implemented by an electronic device, such as a mobile terminal, a PC, or a server.
[0042] like Figure 1 As shown, the method in this embodiment may specifically include:
[0043] S110. In response to the code compilation operation, read the first attribute information of the code to be compiled corresponding to the element node to be compiled.
[0044] In this context, code compilation refers to the process of converting source code into target code. Source code refers to the code to be compiled, while target code refers to the compiled code resulting from the original source code. The element node to be compiled can be a `<html>` tag element in HTML. The first attribute information includes, but is not limited to, the element node's class name (which can be used to reference elements in CSS styles or scripts), attribute values, unique identifiers, the element's width, height, color, hyperlinks, and the URL of its content.
[0045] In this embodiment, after each tag element's code is written, clicking the save control or compile control, or entering a command line, a code compilation operation is considered detected. The code corresponding to that tag element can then be read; that is, the tag element is the element node to be compiled, and the read code is the code to be compiled. Correspondingly, the first attribute information of the code to be compiled is read. Alternatively, after all the code is written, triggering the compile control or entering a command line, the first attribute information of the code to be compiled corresponding to each element node in the entire code can be read.
[0046] For example, "v" can be used to represent the element name of the element node to be compiled, and the usage of this element node will be introduced. The usage of the element node to be compiled can be as follows: <v>< / v> That is, a start tag <v> and an end tag< / v> This constitutes a code block, which is the code to be compiled corresponding to the element node to be compiled. <v>The content within can be the first attribute information. <v> and< / v> You can also nest other tag elements within this code block. If this code block contains another nested tag element... <v>< / v> So, the nested one <v>< / v> This can be referred to as the code to be compiled corresponding to another element node to be compiled. Each <v>This contains the first attribute information of the code to be compiled corresponding to the element node to be compiled. It should be noted that naming the element node to be compiled "v" is just an example. Its specific name corresponds to the tag element represented by the element node to be compiled. Optionally, the element node to be compiled can be a division element, in which case v can be replaced with div.
[0047] S120. In response to an event where the first attribute information includes the target attribute name, search upwards for the parent element node of the element node to be compiled and obtain the target attribute name of the parent element node.
[0048] The target attribute name can be an attribute name set during code development, so that the attribute value can be obtained during code compilation. In other words, if the target attribute name appears in a code element node, the compiler will read the attribute value of this target attribute name as the name of the class to be inherited or the inherited class name of this element node. The code to be compiled for the element node is nested within the code of its parent element node.
[0049] In this embodiment, when the first attribute information includes a target attribute name, the parent element node of the element node to be compiled can be searched upwards, and the attribute information in the code of the parent element node can be read. This attribute information may contain the target attribute name, so that the class name of the parent element node can be inherited if the target attribute name is included. For example, the first attribute information of the element node to be compiled can be read by a plugin to determine whether the first attribute information contains the defined target attribute name. The determination method can be to read all attributes in the first attribute information and determine whether the attribute name contains the target attribute name. If not, or if the attribute value is not found, the process ends. If it exists and the attribute value is not empty, the search for the parent element node of the element node to be compiled continues upwards.
[0050] For example, taking the target attribute name as xx, here is a code example 1 to be compiled. Example 1 can be represented as:
[0051] <v xx="aa">
[0052] <v xx="bb">
[0053] <v xx="cc">< / v>
[0054] <v xx="dd">< / v>
[0055]
[0056] ;
[0057] in<v xx="aa"> This can be represented as the code to be compiled corresponding to element node A.<v xx="bb"> This is the code to be compiled corresponding to element node B.<v xx="cc"> This is the code to be compiled corresponding to element node C.<v xx="dd"> This is the code to be compiled corresponding to element node D. If element node A is the element node to be compiled, and its attribute information includes xx (i.e., the target attribute name), then no parent element node of element node A is found upstream. If element node B is the element node to be compiled, and its attribute information includes xx, then element node A is found upstream. If element node C is the element node to be compiled, and its attribute information includes xx, then element node B is found upstream. If element node D is the element node to be compiled, and its attribute information includes xx, then element node B is found upstream.
[0058] It should be noted that naming the target attribute as xx is merely an example. The naming of the target attribute can be set by the developers according to actual needs, and there are no specific limitations on it. Optionally, the target attribute name can be inherit-class. When executing the code compilation method provided in this embodiment, xx can be replaced with inherit-class for execution. The execution method will not be described in detail here.
[0059] S130. In response to an event in the parent element node that includes the target attribute name, determine the target class name of the element node to be compiled based on the inherited class name of the parent element node and the inherited class name of the element node to be compiled.
[0060] In this context, the inherited class name can refer to the attribute value of the target attribute name in the parent element node. The class name to be inherited can refer to the attribute value of the target attribute name in the element node to be compiled. A target class name can be used to locate and reference a unique element node to be compiled, and the target class name has global uniqueness. For example, if there is a... <v>The element node is:<v id="123"> If the target class name is 123, then there is no other element in the compiled code whose target class name is 123.
[0061] Specifically, if the parent element node includes the target attribute name, it means that the element node to be compiled needs to inherit the inherited class name of its parent element node. In this case, the inherited class name of the parent element node and the class name to be inherited of the element node to be compiled can be concatenated to obtain the target class name of the element node to be compiled.
[0062] In this embodiment, the target class name of the element node to be compiled is determined based on the inherited class name of the parent element node and the inherited class name of the element node to be compiled, including: inheriting the inherited class name based on the inherited class name of the element node to be compiled to obtain the target class name of the element node to be compiled.
[0063] Specifically, the inherited class name of the parent element node can be used as a prefix of the target class name. This prefix can be appended to the inherited class name of the element node to be compiled using a preset identifier (such as "--"). This will give you the target class name of the element node to be compiled, ensuring that the target class name can uniquely locate the element node to be compiled.
[0064] For example, in the above-mentioned code example 1, the class name to be inherited by element node B is "bb", and the class name of its parent element node A is "aa". The two class names can be concatenated to get "aa-bb" as the target class name of element node B.
[0065] It should be noted that the parent element node searched upwards may contain multiple nodes. In this case, it can be determined whether each of these multiple parent element nodes contains the target attribute name, so that the element node to be compiled inherits the inheritance class name of the parent element node that has the target attribute name.
[0066] In this embodiment, the method of determining the target class name of the element node to be compiled based on the inherited class name of the parent element node and the inherited class name of the element node to be compiled can be as follows: when at least two parent element nodes include the target attribute name, the inherited class name is made to inherit the inherited class name of the corresponding parent element node in the order in which the parent element nodes are obtained from the upstream until the inherited class name of the last parent element node is inherited, thereby obtaining the target class name of the element node to be compiled.
[0067] This can be understood as follows: if at least two parent element nodes contain the target attribute name, then the inherited class names of these at least two parent element nodes can be inherited sequentially according to the order in which the parent element nodes were retrieved upstream, until the inherited class name of the last parent element node is inherited, thus obtaining the target class name of the element node to be compiled. The advantage of this setup is that the inherited class name of each parent element node can be sequentially appended as a prefix to the inherited class name of the element node to be compiled, forming a unique target class name. This ensures that the element node class name is unique, enabling precise location of the element node and improving the convenience of class name combination.
[0068] For example, you can iterate through the parent nodes of the element node to be compiled, finding the parent node with the target attribute name, until you find the top-level element node, which is the last parent node. Continuing with the example code to be compiled given above, the class name to be inherited by element node C is "cc". The first parent node found in the upward search is element node B, whose inherited class name is "bb". The second parent node found in the upward search is element node A, whose inherited class name is "aa". First, append "bb" from element node B to "cc" from element node C, resulting in "bb-cc". Then, append "aa" from element node A to "bb-cc", resulting in "aa-bb-cc". The target class name of element node C is then "aa-bb-cc".
[0069] It should be noted that the inheritance class name of each parent element node is inherited in the same way. The method can be found in the section on determining the target class name of the element node to be compiled based on the inheritance class name of the parent element node and the class name to be inherited of the element node to be compiled. It will not be elaborated here.
[0070] S140. Based on the code to be compiled and the target class name of the element node to be compiled, determine the target compiled code of the code to be compiled.
[0071] In this embodiment, the class name to be inherited in the code to be compiled of the element node can be converted into the target class name to obtain the converted code in the code to be compiled, which can then be used as the target compiled code. It should be noted that the target attribute name may be a user-defined name, which may not be recognized in other development environments (such as React, Vue, etc.). In order to enable the code to run in other development environments, the target attribute name in the code to be compiled can also be converted into a preset attribute name supported by that development environment.
[0072] The technical solution of this disclosure, in response to a code compilation operation, reads the first attribute information of the code to be compiled corresponding to the element node to be compiled; in response to an event that the first attribute information includes a target attribute name, searches upwards for the parent element node of the element node to be compiled and obtains the target attribute name of the parent element node; in response to an event that the parent element node includes a target attribute name, determines the target class name of the element node to be compiled based on the inheritance class name of the parent element node and the inheritance class name of the element node to be compiled; and determines the target compiled code of the code to be compiled based on the code to be compiled and the target class name of the element node to be compiled. This solves the problem of element class name conflicts and low code development efficiency caused by combining element class names by user-specified class names in the prior art, and realizes that during code development, the target compiled code is determined by using... Users only need to develop the class name to be inherited for the element node to be compiled. The class name to be inherited does not need to carry the class name of the parent element node. That is, there is no need to develop a target class name to uniquely locate the element node to be compiled, reducing the amount of code development. When compiling the code, by determining the first attribute information of the code to be compiled that includes the target attribute name, the parent element node of the element node to be compiled is searched upwards. When the target attribute name is included in the parent element node, the inherited class name of the parent element node is automatically used as a prefix and appended to the inherited class name of the element node to be compiled to obtain the target class name of the element node to be compiled. The style applied to the element node to be compiled can be located through the target class name, realizing the automatic generation of unique class names for code elements, thereby improving code development efficiency.
[0073] Figure 2 This is a flowchart illustrating a code compilation method provided in an embodiment of this disclosure. Based on the foregoing embodiments, and when at least two class names to be inherited are included, the method of "inheriting the class name based on the class name to be inherited of the element node to be compiled, to obtain the target class name of the element node to be compiled" is further refined. For specific implementation details, please refer to the detailed description of the embodiments of this disclosure. Technical features that are the same as or similar to those in the foregoing embodiments will not be repeated here.
[0074] like Figure 2 As shown, the method in this embodiment may specifically include:
[0075] S210. Each class name to be inherited inherits from the class name to be inherited, thus obtaining the class name to be displayed for each class name to be inherited.
[0076] In this embodiment, each class name to be inherited by the element node to be compiled can inherit the class name of its parent element node to obtain the class name to be displayed for each class name to be inherited. The class name to be displayed is the class name after a single class name to be inherited inherits the class name.
[0077] For example, here is a code example 2 to be compiled, which can be represented as:
[0078] <v xx="aa">
[0079] <v xx="bb1 bb2">< / v>
[0080] ;
[0081] Here, "bb1" and "bb2" are two class names to be inherited by the element node to be compiled. "bb1" inherits the inherited class name "aa" from the parent element node, and the generated class name to be displayed is "aa-bb1"; "bb2" inherits the inherited class name "aa" from the parent element node, and the generated class name to be displayed is "aa-bb2".
[0082] S220. Based on the two class names to be displayed, determine the target class name, wherein the display order of the class names to be displayed in the target class name is consistent with the display order of the class names to be inherited.
[0083] In this embodiment, the class names to be displayed corresponding to the class names to be inherited can be sorted and combined according to the sorting order of the class names to be inherited in the element nodes to be compiled, so as to obtain the target class name.
[0084] For example, if the class name to be inherited contains multiple space-separated values, then each value is a class name to be inherited, and the target class name is a set of all these values concatenated with the inherited class name of the parent element node. For example, the target class name formed by combining the class names to be displayed "aa-bb1" and "aa-bb2" can be "aa-bb1 aa-bb2".
[0085] In the technical solution of this disclosure embodiment, each class name to be inherited inherits from the class name to be inherited, thereby obtaining the class name to be displayed for each class name to be inherited. Then, according to the display order of the class names to be displayed, the two class names to be displayed are arranged in the target class name in order, so that the order of the class names to be displayed in the target class name is consistent with the order of the class names to be inherited in the element node to be compiled.
[0086] Figure 3 This is a flowchart illustrating a code compilation method provided in an embodiment of this disclosure. Based on the foregoing embodiments, the inherited class name includes a space character, further refining the process of "determining the target class name of the element node to be compiled based on the inherited class name of the parent element node and the class name to be inherited of the element node to be compiled." For detailed implementation methods, please refer to the detailed description of the embodiments of this disclosure. Technical features that are the same as or similar to those in the foregoing embodiments will not be repeated here.
[0087] like Figure 3 As shown, the method in this embodiment may specifically include:
[0088] S310. The string corresponding to the inherited class name is split according to the space character to obtain the class name to be applied.
[0089] The space character is used to separate different strings in the same inherited class name.
[0090] In this embodiment, if the inherited class name of the parent element node contains spaces, the strings in the inherited class name can be split by spaces, and the first string can be taken as the class name to be applied. For example, here is a code example 3 to be compiled, which can be represented as:
[0091] <v xx="aa1 aa2">
[0092] <v xx="bb">
[0093] ;
[0094] Here, "aa1" and "aa2" are two strings in the inherited class name of the parent element node, and "aa1" can be taken as the class name to be applied.
[0095] S320. Based on the class name to be inherited, inherit the class name to be applied to obtain the target class name of the element node to be compiled.
[0096] In this embodiment, the way the class name to be inherited inherits the class name to be applied is similar to the way the class name is inherited in step S130, and will not be described in detail here.
[0097] The technical solution of this disclosure embodiment determines the class name to be applied from the string by splitting the string corresponding to the inherited class name according to the space character, and then makes the class name to be inherited inherit the class name to be applied, thereby ensuring the uniqueness of the target class name of the element node to be compiled.
[0098] Figure 4 This is a flowchart illustrating a code compilation method provided in an embodiment of this disclosure. Based on the foregoing embodiments, in response to an event in which the first attribute information includes a preset attribute, the method further obtains the attribute value to be concatenated corresponding to the preset attribute; determines the updated attribute value corresponding to the preset attribute based on the attribute value to be concatenated and the target class name; and determines the target attribute value of the preset attribute in the updated code to be compiled based on the updated attribute value and the attribute value to be concatenated of the preset attribute. For detailed implementation methods, please refer to the detailed description of the embodiments of this disclosure. Technical features that are the same as or similar to those in the foregoing embodiments will not be repeated here.
[0099] like Figure 4 As shown, the method in this embodiment may specifically include:
[0100] S410. In response to an event in which the first attribute information includes a preset attribute, obtain the attribute value to be concatenated corresponding to the preset attribute.
[0101] Among them, the preset properties can be properties used to define class names in the preset development environment, so that these class names can be referenced in the preset development environment.
[0102] In this embodiment, if the first attribute information of the code to be compiled includes a preset attribute, the attribute value corresponding to the preset attribute can be read, and the attribute value is the attribute value to be concatenated.
[0103] For example, here is a code example 4 to be compiled, which can be represented as:
[0104] <v xx="aa">
[0105] <v xx="bb"nn="cl3" / >
[0106] ;
[0107] The first attribute information of the code to be compiled includes a preset attribute nn, whose attribute value to be concatenated is "cl3". It should be noted that naming the preset attribute nn is merely an example. The naming of the preset attribute corresponds to the preset development environment. For example, in a React development environment, when defining a preset attribute for an HTML element, this preset attribute can be className. When executing the code compilation method provided in this embodiment, nn can be replaced with className for execution; the execution method will not be elaborated here.
[0108] In this embodiment, the code compilation method further includes: in response to an event that the first attribute information does not include a preset attribute, creating a preset attribute, and updating the target attribute value of the preset attribute in the code to be compiled based on the target class name.
[0109] This can be understood as follows: if the first attribute information of the code to be compiled corresponding to the element node to be compiled does not contain a preset attribute, a preset attribute can be created so that the element node to be compiled includes the preset attribute, and the target class name is used as the target attribute value of the preset attribute.
[0110] For example, determine whether the element node has an existing nn (i.e., a preset attribute). If not, add a new nn to the element node.
[0111] S420. Based on the attribute value to be concatenated and the target class name, determine the updated attribute value corresponding to the preset attribute.
[0112] In this embodiment, spaces can be used to concatenate the attribute value to be concatenated and the target class name to obtain the updated attribute value corresponding to the preset attribute. For example, it can be determined whether the element node contains the original nn. If so, the attribute value of nn and the target class name can be concatenated to obtain the updated attribute value.
[0113] For example, you can continue to refer to the above code example 4 to be compiled. "aa-bb" represents the target class name based on inheritance, and "cl3" is the attribute value to be concatenated. You can concatenate "aa-bb" and "cl3" to get "aa-bb cl3", which can be used as the updated attribute value corresponding to the preset attribute.
[0114] S430. Based on the updated attribute value and the attribute value to be concatenated of the preset attribute, determine the target attribute value of the preset attribute in the updated code to be compiled.
[0115] In this embodiment, the attribute value to be concatenated and the attribute value to be updated can be set as a set, and the set can be used as the target attribute value corresponding to the preset attribute. For example, the set {"aa-bb cl3", "cl3"} of "aa-bb cl3" and "cl3" can be used as the updated attribute value corresponding to the preset attribute.
[0116] In this embodiment, the target compiled code of the code to be compiled is determined based on the code to be compiled and the target class name of the element node to be compiled. This includes determining the target compiled code of the code to be compiled based on the updated code to be compiled corresponding to the element node to be compiled, the target class name, and the fixed compiled code segment corresponding to the target compiled plugin.
[0117] In this context, the target compilation plugin can refer to a plugin used to execute code compilation methods. The fixed compilation code segment can be the framework logic code of the target compilation plugin.
[0118] In this embodiment, the fixed compilation code segment corresponding to the target compilation plugin can be executed to convert the target attribute name in the code of the element node to be compiled into a preset attribute, and convert the class name to be inherited from the target attribute name into the target class name, thus obtaining the compiled target code. It should be noted that the target compilation plugin can be deployed on the user's development platform or independently in a certain location. Users can automatically convert development code by calling the target compilation plugin during the code compilation process on the development platform, improving the convenience of code conversion.
[0119] To enable those skilled in the art to further understand the technical solutions of the embodiments of this disclosure, a specific implementation of the code compilation method is given by taking a certain element node in the code to be compiled as an example:
[0120] Specifically, the process retrieves the attribute list (i.e., the first attribute information) of the element node to be compiled and checks if the target attribute name exists in the attribute list. If the target attribute name is not found, the process ends. If the target attribute name is found and has no attribute value (i.e., the class name to be inherited), the process ends. If the target attribute name is found and has an attribute value, a class name variable is defined, and the process searches upwards for the nearest parent element node that carries the inherited class name of the target attribute name. A while function is used to execute the conditional statement. When the parent element node is null (indicating that no parent element node was found), the loop stops. If it is not null, the process checks if the parent element node contains the inherited class name of the target attribute name. If it does, the loop ends, and the class name variable is assigned a value. If the inherited class name of the parent element node is multiple class names (i.e., strings) separated by spaces, only the first space-separated class name (i.e., the class name to be applied) is taken, and concatenated with the class name to be inherited to obtain the target class name of the element node to be compiled. If the class name to be inherited of the element node to be compiled contains spaces, each class name is separated by spaces and concatenated with the inherited class name of the parent element node to obtain the target class name of the element node to be compiled, which is then stored. To determine if the element node to be compiled has a native `nn` attribute (i.e., a preset attribute), the attribute list is traversed, and each attribute is checked against the string `nn` to verify if the element node has a native `nn` attribute. If `nn` exists, its attribute value is concatenated with the target class name; otherwise, a new `nn` attribute is added to the element node to be compiled.
[0121] The technical solution of this disclosure embodiment, when the first attribute information includes a preset attribute, concatenates the attribute value to be concatenated of the preset attribute and the target class name to obtain the updated attribute value corresponding to the preset attribute. Then, by combining the updated attribute value and the attribute value to be concatenated of the preset attribute, the target attribute value of the preset attribute in the updated code to be compiled is determined, so that the representation of the target attribute value is unique and includes the attribute value information of the preset attribute.
[0122] Figure 5 This is a schematic diagram of the structure of a code compilation apparatus provided in an embodiment of the present disclosure, as shown below. Figure 5 As shown, the device includes: an information reading module 510, an uplink search module 520, a target class name determination module 530, and a target compiled code determination module 540.
[0123] The information reading module 510 is used to read the first attribute information of the code to be compiled corresponding to the element node to be compiled in response to the code compilation operation; the uplink search module 520 is used to search uplink to the parent element node of the element node to be compiled and obtain the target attribute name of the parent element node in response to the event that the first attribute information includes the target attribute name; the target class name determination module 530 is used to determine the target class name of the element node to be compiled based on the inherited class name of the parent element node and the inherited class name of the element node to be compiled in response to the event that the parent element node includes the target attribute name; and the target compiled code determination module 540 is used to determine the target compiled code of the code to be compiled based on the code to be compiled of the element node to be compiled and the target class name.
[0124] The technical solution of this disclosure, in response to a code compilation operation, reads the first attribute information of the code to be compiled corresponding to the element node to be compiled; in response to an event that the first attribute information includes a target attribute name, searches upwards for the parent element node of the element node to be compiled and obtains the target attribute name of the parent element node; in response to an event that the parent element node includes a target attribute name, determines the target class name of the element node to be compiled based on the inheritance class name of the parent element node and the inheritance class name of the element node to be compiled; and determines the target compiled code of the code to be compiled based on the code to be compiled and the target class name of the element node to be compiled. This solves the problem of element class name conflicts and low code development efficiency caused by combining element class names by user-specified class names in the prior art, and realizes that during code development, the target compiled code is determined by using... Users only need to develop the class name to be inherited for the element node to be compiled. The class name to be inherited does not need to carry the class name of the parent element node. That is, there is no need to develop a target class name to uniquely locate the element node to be compiled, reducing the amount of code development. When compiling the code, by determining the first attribute information of the code to be compiled that includes the target attribute name, the parent element node of the element node to be compiled is searched upwards. When the target attribute name is included in the parent element node, the inherited class name of the parent element node is automatically used as a prefix and appended to the inherited class name of the element node to be compiled to obtain the target class name of the element node to be compiled. The style applied to the element node to be compiled can be located through the target class name, realizing the automatic generation of unique class names for code elements, thereby improving code development efficiency.
[0125] Based on the above technical solution, the target class name determination module 530 is used to obtain the target class name of the element node to be compiled by inheriting the inherited class name based on the class name to be inherited of the element node to be compiled.
[0126] Based on the above technical solution, when there are at least two class names to be inherited, the target class name determination module 530 includes:
[0127] The class name to be displayed unit is used to determine the class name to be displayed for each class name to be inherited by the class name to be inherited.
[0128] The first unit for determining the target class name is used to determine the target class name based on the two class names to be displayed, wherein the display order of the class names to be displayed in the target class name is consistent with the display order of the class names to be inherited.
[0129] Based on the above technical solution, the inherited class name includes a space character, and the target class name determination module 530 includes:
[0130] The application class name determination unit is used to split the string corresponding to the inherited class name based on the space character to obtain the application class name;
[0131] The second unit for determining the target class name is used to inherit the class name to be applied based on the class name to be inherited, thereby obtaining the target class name of the element node to be compiled.
[0132] Based on the above technical solution, the device further includes:
[0133] The attribute value to be spliced determination unit is used to obtain the attribute value to be spliced corresponding to the preset attribute in response to an event in the first attribute information including a preset attribute;
[0134] The update attribute value determination unit is used to determine the update attribute value corresponding to the preset attribute based on the attribute value to be concatenated and the target class name;
[0135] The target attribute value determination unit is used to determine the target attribute value of the preset attribute in the updated code to be compiled based on the updated attribute value and the attribute value to be concatenated of the preset attribute.
[0136] Based on the above technical solution, the device further includes:
[0137] An attribute creation unit is configured to create the preset attribute in response to an event that the preset attribute is not included in the first attribute information, and update the target attribute value of the preset attribute in the code to be compiled based on the target class name.
[0138] Based on the above technical solution, the target compilation code determination module 540 is used to determine the target compilation code of the code to be compiled based on the updated code to be compiled corresponding to the element node to be compiled, the target class name, and the fixed compilation code segment corresponding to the target compilation plugin.
[0139] Based on the above technical solution, when the parent element node includes at least two, the target class name determination module 530 is further configured to, when the at least two parent element nodes include the target attribute name, cause the class name to be inherited to inherit the inherited class name of the corresponding parent element node in the order in which the parent element node is obtained from the upstream, until the inherited class name of the last parent element node is inherited, thereby obtaining the target class name of the element node to be compiled.
[0140] The code compilation apparatus provided in this disclosure can execute the code compilation method provided in any embodiment of this disclosure, and has the corresponding functional modules and beneficial effects of the execution method.
[0141] It is worth noting that the various units and modules included in the above-mentioned device are only divided according to functional logic, but are not limited to the above division, as long as the corresponding functions can be realized; in addition, the specific names of each functional unit are only for easy differentiation and are not used to limit the protection scope of the embodiments of this disclosure.
[0142] Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this disclosure. Reference is made below. Figure 6 It illustrates an electronic device suitable for implementing embodiments of the present disclosure (e.g., Figure 6 The diagram below shows the structure of the terminal device or server 600. The terminal device in this embodiment may include, but is not limited to, mobile terminals such as mobile phones, laptops, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), and vehicle terminals (e.g., vehicle navigation terminals), as well as fixed terminals such as digital TVs and desktop computers. Figure 6 The electronic device shown is merely an example and should not be construed as limiting the functionality and scope of the embodiments disclosed herein.
[0143] like Figure 6 As shown, electronic device 600 may include a processing unit (e.g., a central processing unit, a graphics processing unit, etc.) 601, which can perform various appropriate actions and processes according to a program stored in read-only memory (ROM) 602 or a program loaded from storage device 608 into random access memory (RAM) 603. The RAM 603 also stores various programs and data required for the operation of electronic device 600. The processing unit 601, ROM 602, and RAM 603 are interconnected via bus 604. An edit / output (I / O) interface 605 is also connected to bus 604.
[0144] Typically, the following devices can be connected to I / O interface 605: input devices 606 including, for example, touchscreens, touchpads, keyboards, mice, cameras, microphones, accelerometers, gyroscopes, etc.; output devices 607 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 608 including, for example, magnetic tapes, hard disks, etc.; and communication devices 609. Communication device 609 allows electronic device 600 to communicate wirelessly or wiredly with other devices to exchange data. Although Figure 6 An electronic device 600 with various devices is shown; however, it should be understood that it is not required to implement or possess all of the devices shown. More or fewer devices may be implemented or possessed alternatively.
[0145] In particular, according to embodiments of this disclosure, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this disclosure include a computer program product comprising a computer program carried on a non-transitory computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device 609, or installed from a storage device 608, or installed from a ROM 602. When the computer program is executed by the processing device 601, it performs the functions defined in the methods of embodiments of this disclosure.
[0146] The names of messages or information exchanged between multiple devices in the embodiments of this disclosure are for illustrative purposes only and are not intended to limit the scope of such messages or information.
[0147] The electronic device provided in this disclosure and the code compilation method provided in the above embodiments belong to the same inventive concept. Technical details not described in detail in this disclosure can be found in the above embodiments, and this embodiment has the same beneficial effects as the above embodiments.
[0148] This disclosure provides a computer storage medium storing a computer program that, when executed by a processor, implements the code compilation method provided in the above embodiments.
[0149] It should be noted that the computer-readable medium described in this disclosure can be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this disclosure, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in connection with an instruction execution system, apparatus, or device. In this disclosure, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium can be any computer-readable medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wires, optical fibers, RF (radio frequency), etc., or any suitable combination thereof.
[0150] In some implementations, clients and servers can communicate using any currently known or future-developed network protocol such as HTTP (Hypertext Transfer Protocol) and can interconnect with digital data communication (e.g., communication networks) of any form or medium. Examples of communication networks include local area networks (“LANs”), wide area networks (“WANs”), the Internet (e.g., the Internet of Things), and peer-to-peer networks (e.g., ad hoc peer-to-peer networks), as well as any currently known or future-developed networks.
[0151] The aforementioned computer-readable medium may be included in the aforementioned electronic device; or it may exist independently and not assembled into the electronic device.
[0152] The aforementioned computer-readable medium carries one or more programs. When the aforementioned one or more programs are executed by the electronic device, the electronic device causes the following: In response to a code compilation operation, it reads first attribute information of the code to be compiled corresponding to the element node to be compiled; In response to an event that the first attribute information includes a target attribute name, it searches upwards for the parent element node of the element node to be compiled and obtains the target attribute name of the parent element node; In response to an event that the parent element node includes the target attribute name, it determines the target class name of the element node to be compiled based on the inherited class name of the parent element node and the class name to be inherited of the element node to be compiled; Based on the code to be compiled of the element node to be compiled and the target class name, it determines the target compiled code of the code to be compiled.
[0153] Computer program code for performing the operations of this disclosure can be written in one or more programming languages or a combination thereof, including but not limited to object-oriented programming languages such as Java, Smalltalk, and C++, as well as conventional procedural programming languages such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0154] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this disclosure. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0155] The units described in the embodiments of this disclosure can be implemented in software or in hardware. The name of a unit does not necessarily limit the unit itself; for example, the first acquisition unit can also be described as "a unit that acquires at least two Internet Protocol addresses".
[0156] The functions described above in this document can be performed, at least in part, by one or more hardware logic components. For example, exemplary types of hardware logic components that can be used, without limitation, include: Field Programmable Gate Arrays (FPGAs), Application-Specific Integrated Circuits (ASICs), Application Standard Products (ASSPs), System-on-Chip (SoCs), Complex Programmable Logic Devices (CPLDs), and so on.
[0157] In the context of this disclosure, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0158] The above description is merely a preferred embodiment of this disclosure and an explanation of the technical principles employed. Those skilled in the art should understand that the scope of this disclosure is not limited to technical solutions formed by specific combinations of the above-described technical features, but should also cover other technical solutions formed by arbitrary combinations of the above-described technical features or their equivalents without departing from the above-described concept. For example, technical solutions formed by substituting the above features with (but not limited to) technical features disclosed in this disclosure that have similar functions.
[0159] Furthermore, while the operations are described in a specific order, this should not be construed as requiring these operations to be performed in the specific order shown or in a sequential order. In certain environments, multitasking and parallel processing may be advantageous. Similarly, while several specific implementation details are included in the above discussion, these should not be construed as limiting the scope of this disclosure. Certain features described in the context of individual embodiments may also be implemented in combination in a single embodiment. Conversely, various features described in the context of a single embodiment may also be implemented individually or in any suitable sub-combination in multiple embodiments.
[0160] Although the subject matter has been described using language specific to structural features and / or methodological logic, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. Rather, the specific features and actions described above are merely illustrative examples of implementing the claims.
Claims
1. A code compilation method, characterized in that, include: In response to the code compilation operation, read the first attribute information of the code to be compiled corresponding to the element node to be compiled; In response to an event that the first attribute information includes the target attribute name, the parent element node of the element node to be compiled is searched upwards and the target attribute name of the parent element node is obtained. In response to an event in which the parent element node includes the target attribute name, the target class name of the element node to be compiled is determined based on the inherited class name of the parent element node and the inherited class name of the element node to be compiled. Based on the code to be compiled of the element node to be compiled and the target class name, the target compiled code of the code to be compiled is determined.
2. The method according to claim 1, characterized in that, The step of determining the target class name of the element node to be compiled based on the inherited class name of the parent element node and the inherited class name of the element node to be compiled includes: The target class name of the element node to be compiled is obtained by inheriting the class name of the inherited class based on the class name to be inherited of the element node to be compiled.
3. The method according to claim 2, characterized in that, In cases involving at least two class names to be inherited, the process of inheriting the class name from the class name to be inherited of the element node to be compiled, to obtain the target class name of the element node to be compiled, includes: Each class name to be inherited inherits from the class name to be inherited, resulting in the class name to be displayed for each class name to be inherited. Based on the two class names to be displayed, the target class name is determined, wherein the display order of the class names to be displayed in the target class name is consistent with the display order of the class names to be inherited.
4. The method according to claim 1, characterized in that, The inherited class name includes a space character. Determining the target class name of the element node to be compiled based on the inherited class name of the parent element node and the class name to be inherited of the element node to be compiled includes: The string corresponding to the inherited class name is split based on the space character to obtain the class name to be applied; The target class name of the element node to be compiled is obtained by inheriting the class name to be applied based on the class name to be inherited.
5. The method according to any one of claims 1-4, characterized in that, The method further includes: In response to an event in which the first attribute information includes a preset attribute, the attribute value to be concatenated corresponding to the preset attribute is obtained; Based on the attribute value to be concatenated and the target class name, determine the updated attribute value corresponding to the preset attribute; Based on the updated attribute value and the attribute value to be concatenated of the preset attribute, the target attribute value of the preset attribute in the updated code to be compiled is determined.
6. The method according to claim 5, characterized in that, The method further includes: In response to an event that the preset attribute is not included in the first attribute information, the preset attribute is created, and the target attribute value of the preset attribute in the code to be compiled is updated based on the target class name.
7. The method according to claim 1, characterized in that, The step of determining the target compiled code of the code to be compiled based on the code to be compiled of the element node to be compiled and the target class name includes: Based on the updated code to be compiled corresponding to the element node to be compiled, the target class name, and the fixed compilation code segment corresponding to the target compilation plugin, the target compilation code is determined.
8. The method according to claim 1, characterized in that, When there are at least two parent element nodes, determining the target class name of the element node to be compiled based on the inherited class name of the parent element nodes and the class name to be inherited of the element node to be compiled includes: When at least two parent element nodes include the target attribute name, the class name to be inherited inherits the class names of the corresponding parent element nodes in the order in which the parent element nodes are obtained from the previous row, until the class name of the last parent element node is inherited, thus obtaining the target class name of the element node to be compiled.
9. A code compilation apparatus, characterized in that, include: The information reading module is used to read the first attribute information of the code to be compiled corresponding to the element node to be compiled in response to the code compilation operation; The uplink lookup module is used to respond to an event in which the first attribute information includes the target attribute name, to search uplink to the parent element node of the element node to be compiled and obtain the target attribute name of the parent element node; The target class name determination module is used to respond to an event in which the parent element node includes the target attribute name, and determine the target class name of the element node to be compiled based on the inherited class name of the parent element node and the inherited class name of the element node to be compiled. The target compiled code determination module is used to determine the target compiled code of the code to be compiled based on the code to be compiled of the element node to be compiled and the target class name.
10. An electronic device, characterized in that, The electronic device includes: One or more processors; Storage device for storing one or more programs. When the one or more programs are executed by the one or more processors, the one or more processors implement the code compilation method as described in any one of claims 1-8.
11. A storage medium containing computer-executable instructions, characterized in that, The computer-executable instructions, when executed by a computer processor, are used to perform the code compilation method as described in any one of claims 1-8.
12. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the code compilation method as described in any one of claims 1-8.