Redundant code removal method, device, equipment and computer-readable storage medium

By identifying and deleting the redundant selection device code of the target style file and page content file in the applet, the redundant code removal efficiency in the applet is solved, and the code volume is reduced and the development efficiency is improved.

CN111459537BActive Publication Date: 2025-01-28WEBANK (CHINA)
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202010262738.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-04-03
Publication Date
2025-01-28
Estimated Expiration
2040-04-03

AI Technical Summary

Technical Problem

The existing technology is difficult to efficiently remove redundant code in mini programs, resulting in increased code volume and inefficient efficiency.

Method used

By determining the grammatical structure of the target style file and the target page content file, identify and delete the target style code corresponding to the redundant selector.

Benefits of technology

The efficient removal of mini -program redundant code has reduced the size of code and improved development efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN111459537B_ABST
    Figure CN111459537B_ABST
Patent Text Reader

Abstract

This invention discloses a method for removing redundant code, comprising: determining a target style file and a target page content file, and generating a first syntax structure corresponding to the target style file and a second syntax structure corresponding to the target page content file; determining a redundant selector for the target style file based on the first syntax structure and the second syntax structure; determining a target style corresponding to the redundant selector, and deleting the code corresponding to the target style. This invention also discloses a redundant code removal apparatus, device, and computer-readable storage medium. This invention generates modular syntax structures for the style file and page content file respectively. Through the syntax structures of both, redundant selectors are determined, thereby identifying the styles defined by the redundant selectors as useless styles that can be safely deleted, achieving efficient removal of redundant code and reducing code size.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of financial technology (Fintech), and in particular to a redundant code removal method, device, equipment and computer-readable storage medium. Background Art

[0002] In recent years, with the continuous development of Fintech, especially Internet finance, mini-program technology has been introduced into the daily services of banks and other financial institutions. In the daily service process of banks and other financial institutions, in order to meet business needs, it is often necessary to develop some applications that can be used without downloading - mini-programs. In order to adapt to business changes or user usage habits, mini-programs need to be continuously iterated and upgraded. In the process of continuous upgrading, it is easy to cause a lot of code redundancy. Therefore, it is necessary to remove the redundant code.

[0003] In traditional h5, the page content html (HyperText Markup Language) and the corresponding style file css (Cascading Style Sheets) are directly bound through hyperlinks. Therefore, all style files that apply to this page can be obtained through the hyperlinks in the page, thereby filtering out the codes corresponding to the style files that do not apply to this page, which are redundant codes.

[0004] Mini programs use framework conventions to define page content, such as the binding relationship between wxml (WeiXin Markup Language, a set of tag languages ​​designed by the framework) and style files, such as wxss (WeiXin Style Sheets, a set of style languages ​​used to describe the component styles of wxml). In addition, the style files (wxss) of mini programs are modifications and extensions of traditional h5 style files (css), and the syntax and usage are different. Therefore, the traditional h5 method of removing redundant code is not suitable for mini programs. Currently, the only way to manually filter and remove the redundant code of mini programs is extremely inefficient. Therefore, there is an urgent need for a method to efficiently remove redundant code from mini programs. Summary of the invention

[0005] The main purpose of the present invention is to propose a redundant code removal method, device, equipment and computer-readable storage medium, aiming to achieve efficient removal of redundant code in mini-programs.

[0006] To achieve the above object, the present invention provides a redundant code removal method, which comprises the following steps:

[0007] Determine a target style file and a target page content file, and generate a first grammatical structure corresponding to the target style file and a second grammatical structure corresponding to the target page content file;

[0008] Determining a redundant selector of the target style file based on the first grammatical structure and the second grammatical structure;

[0009] Determine the target style corresponding to the redundant selector, and delete the code corresponding to the target style.

[0010] Preferably, the step of determining the target style file and the target page content file comprises:

[0011] Determine the scope of the target style file;

[0012] If the scope of the target style file is global, a first temporary file corresponding to the target style file is determined, and the first temporary file is determined as the target page content file, so as to represent the page content files of all pages and components in the global context based on the first temporary file.

[0013] Preferably, after the step of determining the scope of the target style file, the redundant code removal method further comprises:

[0014] If the scope of the target style file is a page, then reading a configuration file of the target page corresponding to the target style file, and determining the role component corresponding to the target page based on the configuration file;

[0015] A second temporary file corresponding to the target style file is determined, and the second temporary file is determined as a target page content file, so as to characterize the page content file of the target page and the page content file of the effect component based on the second temporary file.

[0016] Preferably, if the scope of the target style file is a page, the step of reading a configuration file of a target page corresponding to the target style file, and determining, based on the configuration file, an active component corresponding to the target page includes:

[0017] If the scope of the target style file is a page, then reading a configuration file of the target page corresponding to the target style file, and determining the component to be filtered corresponding to the target page based on the configuration file;

[0018] An isolation configuration of the component to be screened is determined, and based on the isolation configuration, an effect component corresponding to the target page is determined from the component to be screened.

[0019] Preferably, the step of determining the redundant selector of the target style file based on the first grammatical structure and the second grammatical structure comprises:

[0020] Based on the first grammatical structure, extract a first selector of the target style file, and based on the second grammatical structure, extract a second selector of the target page content file;

[0021] Based on the first selector and the second selector, a redundant selector of the target style file is determined.

[0022] Preferably, the step of determining a target style file and a target page content file, and generating a first grammatical structure corresponding to the target style file and a second grammatical structure corresponding to the target page content file comprises:

[0023] Determine a target style file and a target page content file, and obtain a first source code of the target style file and a second source code of the target page content file;

[0024] Parsing the first source code, and generating a first grammatical structure corresponding to the target style file based on a preset template;

[0025] The second source code is parsed, and based on the preset template, a second grammatical structure corresponding to the target page content file is generated.

[0026] Preferably, in the process of determining the redundant selector of the target style file, the redundant code removal method further includes:

[0027] Determine the mini-program type corresponding to the target style file, and determine the selector list corresponding to the mini-program type;

[0028] Based on the selector list, determining whether the target style file has a selector that is not supported by the mini-program type;

[0029] If so, the selector that is not supported by the applet type is determined to be a redundant selector.

[0030] In addition, to achieve the above object, the present invention further provides a redundant code removal device, the redundant code removal device comprising:

[0031] A first determination module, used to determine a target style file and a target page content file, and generate a first grammatical structure corresponding to the target style file and a second grammatical structure corresponding to the target page content file;

[0032] A second determining module, configured to determine a redundant selector of the target style file based on the first grammatical structure and the second grammatical structure;

[0033] The deletion module is used to determine the target style corresponding to the redundant selector and delete the code corresponding to the target style.

[0034] Preferably, the first determining module is further used for:

[0035] Determine the scope of the target style file;

[0036] If the scope of the target style file is global, a first temporary file corresponding to the target style file is determined, and the first temporary file is determined as the target page content file, so as to represent the page content files of all pages and components in the global context based on the first temporary file.

[0037] Preferably, the first determining module is further used for:

[0038] If the scope of the target style file is a page, then reading a configuration file of the target page corresponding to the target style file, and determining the role component corresponding to the target page based on the configuration file;

[0039] A second temporary file corresponding to the target style file is determined, and the second temporary file is determined as a target page content file, so as to characterize the page content file of the target page and the page content file of the effect component based on the second temporary file.

[0040] Preferably, the first determining module is further used for:

[0041] If the scope of the target style file is a page, then reading a configuration file of the target page corresponding to the target style file, and determining the component to be filtered corresponding to the target page based on the configuration file;

[0042] An isolation configuration of the component to be screened is determined, and based on the isolation configuration, an effect component corresponding to the target page is determined from the component to be screened.

[0043] Preferably, the second determining module is further used for:

[0044] Based on the first grammatical structure, extract a first selector of the target style file, and based on the second grammatical structure, extract a second selector of the target page content file;

[0045] Based on the first selector and the second selector, a redundant selector of the target style file is determined.

[0046] Preferably, the first determining module is further used for:

[0047] Determine a target style file and a target page content file, and obtain a first source code of the target style file and a second source code of the target page content file;

[0048] Parsing the first source code, and generating a first grammatical structure corresponding to the target style file based on a preset template;

[0049] The second source code is parsed, and based on the preset template, a second grammatical structure corresponding to the target page content file is generated.

[0050] Preferably, the second determining module is further used for:

[0051] Determine the mini-program type corresponding to the target style file, and determine the selector list corresponding to the mini-program type;

[0052] Based on the selector list, determining whether the target style file has a selector that is not supported by the mini-program type;

[0053] If so, the selector that is not supported by the applet type is determined to be a redundant selector.

[0054] In addition, to achieve the above-mentioned purpose, the present invention also provides a redundant code removal device, which includes: a memory, a processor, and a redundant code removal program stored in the memory and executable on the processor, and the redundant code removal program implements the steps of the redundant code removal method described above when executed by the processor.

[0055] In addition, to achieve the above objectives, the present invention also provides a computer-readable storage medium, on which a redundant code removal program is stored, and when the redundant code removal program is executed by a processor, the steps of the redundant code removal method described above are implemented.

[0056] The redundant code removal method proposed in the present invention determines a target style file and a target page content file, and generates a first grammatical structure corresponding to the target style file and a second grammatical structure corresponding to the target page content file; based on the first grammatical structure and the second grammatical structure, determines a redundant selector of the target style file; determines a target style corresponding to the redundant selector, and deletes the code corresponding to the target style. The present invention generates modular grammatical structures for style files and page content files respectively, determines redundant selectors through the grammatical structures of the two, and thus determines that the styles defined by the redundant selectors are useless styles that can be safely deleted, thereby achieving efficient removal of redundant codes and reducing the code volume of mini-programs. BRIEF DESCRIPTION OF THE DRAWINGS

[0057] Figure 1It is a schematic diagram of the device structure of the hardware operating environment involved in the embodiment of the present invention;

[0058] Figure 2 It is a flowchart of the first embodiment of the redundant code removal method of the present invention;

[0059] FIG3( a ) is a schematic diagram of extracting a first selector in the first embodiment of the redundant code removal method of the present invention;

[0060] FIG. 3( b ) is a schematic diagram of extracting the second selector in the first embodiment of the redundant code removal method of the present invention.

[0061] The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION

[0062] It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention.

[0063] like Figure 1 As shown, Figure 1 It is a schematic diagram of the device structure of the hardware operating environment involved in the embodiment of the present invention.

[0064] The device in the embodiment of the present invention may be a mobile terminal or a server device.

[0065] like Figure 1 As shown, the device may include: a processor 1001, such as a CPU, a network interface 1004, a user interface 1003, a memory 1005, and a communication bus 1002. Among them, the communication bus 1002 is used to realize the connection and communication between these components. The user interface 1003 may include a display screen (Display), an input unit such as a keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface and a wireless interface. The network interface 1004 may optionally include a standard wired interface and a wireless interface (such as a WI-FI interface). The memory 1005 may be a high-speed RAM memory, or it may be a stable memory (non-volatile memory), such as a disk memory. The memory 1005 may also be a storage device independent of the aforementioned processor 1001.

[0066] Those skilled in the art will understand that Figure 1 The device structure shown in the figure does not constitute a limitation of the device, and may include more or less components than shown in the figure, or combine certain components, or arrange the components differently.

[0067] like Figure 1As shown, the memory 1005 as a computer storage medium may include an operating system, a network communication module, a user interface module, and a redundant code removal program.

[0068] Among them, the operating system is a program that manages and controls redundant code removal equipment and software resources, and supports the operation of network communication modules, user interface modules, redundant code removal programs and other programs or software; the network communication module is used to manage and control network interface 1002; the user interface module is used to manage and control user interface 1003.

[0069] exist Figure 1 In the redundant code removal device shown, the redundant code removal device calls the redundant code removal program stored in the memory 1005 through the processor 1001, and executes the operations in each embodiment of the following redundant code removal method.

[0070] Based on the above hardware structure, an embodiment of the redundant code removal method of the present invention is proposed.

[0071] Reference Figure 2 , Figure 2 This is a flow chart of a first embodiment of a redundant code removal method of the present invention, wherein the method comprises:

[0072] Step S10, determining a target style file and a target page content file, and generating a first grammatical structure corresponding to the target style file and a second grammatical structure corresponding to the target page content file;

[0073] Step S20, determining a redundant selector of the target style file based on the first grammatical structure and the second grammatical structure;

[0074] Step S30, determining the target style corresponding to the redundant selector, and deleting the code corresponding to the target style.

[0075] The redundant code removal method of this embodiment is applied to the redundant code removal device of financial institutions such as financial institutions or banking systems. The redundant code removal device can be a terminal, a robot or a PC device, etc. For the convenience of description, the redundant code removal device is referred to as the removal device. The removal device is installed with various applications, such as WeChat applications, etc., and runs small programs in the application, such as WeChat small programs, etc. In the following description, the WeChat small program is used as an example for description. It should be noted that the small program specifies the binding relationship between the page content wxml and the style file wxss in the small program through a framework agreement, wherein wxml is a set of tag languages ​​designed by the small program framework, combined with the basic components and event system, the content of the page can be constructed, and wxss is a set of style languages ​​​​used to describe the component style of wxml, that is, wxss is used to determine how the components of wxml should be displayed. Therefore, under normal circumstances, the style in the style file is the style used by the page content file.

[0076] However, in actual applications, mini programs, as interfaces that directly contact users in applications (such as WeChat), often need to be continuously iterated and upgraded to adapt to business changes or user usage habits. Code changes are very frequent. In the process of continuous iteration and upgrading, it is likely to cause a lot of code redundancy, especially wxss code. After iteration, there are many wxss that wxml does not need in the mini program, that is, after iteration, there are styles in the style file that are not used by the page content file. For example, after the mini program is iterated, the screen content displayed on the current interface is upgraded from static to dynamic, then the static display style is no longer the style required by the current screen content. At this time, the code corresponding to the static display style is redundant code. Because the relationship between wxss and wxml is not directly bound through hyperlinks like html and css, that is, it cannot be well modularized, it is difficult to identify useless code in wxss.

[0077] This embodiment first determines the target style file and the target page content file, and generates modular grammatical structures for the target style file and the target page content file respectively, so as to extract the selectors of the two files, and then uses the selectors of the two files to filter out the selectors not used by the target page content file, thereby determining that the style defined by the selector is a useless style, and finally, deletes the code corresponding to the useless style, thereby realizing efficient removal of redundant code.

[0078] The following is a detailed description of each step:

[0079] Step S10, determining a target style file and a target page content file, and generating a first grammatical structure corresponding to the target style file and a second grammatical structure corresponding to the target page content file;

[0080] In this embodiment, when determining the redundant code of the mini program, the target style file and the target page content file in the mini program are first determined, and the target style file is generated into a modular first grammatical structure, and the target page content file is also generated into a modular second grammatical structure, so as to facilitate the subsequent determination of the selectors of the target style file and the target page content file.

[0081] In one embodiment, step S10 includes:

[0082] Step a1, determining a target style file and a target page content file, and obtaining a first source code of the target style file and a second source code of the target page content file;

[0083] In one embodiment, the removal device first determines the target style file and the target page content file corresponding to the target style file, and then obtains the first source code of the target style file and the second source code of the target page content file respectively.

[0084] Step a2, parsing the first source code, and generating a first grammatical structure corresponding to the target style file based on a preset template;

[0085] Then, the first source code is parsed. Specifically, the first source code is lexically analyzed and then syntactically analyzed, and a first grammatical structure is generated according to a preset template, wherein the lexical analysis stage is to convert the code in the form of a string into a token stream, and the grammatical analysis stage is to convert each token stream into a grammatical node, so as to piece together the grammatical nodes into a complete grammatical structure according to the preset template, that is, the removal device parses a long string of connected strings into an arrangement of short strings, and then fills the short strings as nodes into the preset template, so as to obtain the first grammatical structure. In specific implementation, the preset template can be a tree template, that is, an extensible template with a parent node as a root node and child nodes as branch nodes, and each node corresponds to a grammatical node.

[0086] Step a3: parsing the second source code and generating a second grammatical structure corresponding to the target page content file based on the preset template.

[0087] Next, the second source code is parsed, and a second grammatical structure corresponding to the target page content file is generated according to a preset template. The specific generation method is similar to the method of generating the first grammatical structure, which will not be described in detail here.

[0088] It should be noted that in the process of generating the first syntax structure from the target style file and generating the second syntax structure from the target page content file, existing tools, such as compilers such as esprima or babel, can also be used to generate an abstract syntax tree, etc. In addition, the order of generating the first syntax structure and generating the second syntax structure can be interchanged, which does not affect the implementation of this embodiment.

[0089] Step S20: determining a redundant selector of the target style file based on the first grammatical structure and the second grammatical structure.

[0090] In this embodiment, after the first grammatical structure and the second grammatical structure are obtained, the first grammatical structure and the second grammatical structure may be compared to determine the redundant selector of the target pattern.

[0091] Specifically, in one embodiment, step S20 includes:

[0092] Step b1, extracting a first selector of the target style file based on the first grammatical structure, and extracting a second selector of the target page content file based on the second grammatical structure;

[0093] In one embodiment, the first selector of the target style file is first extracted through the first grammatical structure, and then the second selector of the target page content file is extracted through the second grammatical structure. It can be understood that the extraction order is interchangeable, wherein the selector refers to the component of the style. In the specific implementation process, the selector supported by the mini program is first obtained, such as the selectors supported by the WeChat mini program, which include class selectors, id selectors, and element selectors. For example, .class is a class selector, such as .intro, which means selecting all components with class="intro"; #id is an id selector, such as #firstname, which means selecting components with di="firstname"; element is an element selector, such as view, which means selecting all view components, etc.

[0094] Therefore, according to the selector name, the first selector used by the target style file can be determined in the first grammatical structure, and the second selector used by the target page content file can be determined in the second grammatical structure.

[0095] As shown in Figure 3(a), the left window is the wxss code, which is the source code of the target style file, and the right window is the generated first syntax structure. The rectangle in the right window is the first selector, which is the id selector: #index, the element selector: view, and the class selector: .title, .content. As shown in Figure 3(b), the left window is the wxml code, which is the source code of the target page content file, and the right window is the generated second syntax structure. The rectangle in the right window is the second selector, which is the element selector: view, text, the id selector: index, and the class selector: title.

[0096] Step b2: determining the redundant selector of the target style file based on the first selector and the second selector

[0097] In one embodiment, based on the first selector and the second selector, the redundant selector of the target style file is determined. Specifically, according to the formula: wxss selector - wxml selector = redundant selector, the first selector is subtracted from the second selector to obtain the selector not used by the target page content file, that is, the redundant selector is useless.

[0098] As in the above example, if we subtract the selector in Figure 3(b) from the selector in Figure 3(a), we will find that the .content style defined in wxss is not used in wxml, so it is determined that this selector is redundant.

[0099] For the convenience of explanation, the process of removing useless wxss is marked by the function unwxss. The input of the function includes wxml code and wxss code, that is, the function is: unwxss(wxml, wxss) = wxss(useful).

[0100] Step S30, determining the target style corresponding to the redundant selector, and deleting the code corresponding to the target style.

[0101] In this embodiment, after determining the redundant selectors of the target style file, it can be determined that the target style defined by the redundant selectors is redundant and can therefore be safely deleted. At this time, deleting the code corresponding to the target style will not affect the normal use of the mini program.

[0102] In this embodiment, the styles in the style file are defined by selectors. Therefore, after the redundant selectors are determined, the target styles defined by the redundant selectors can be reversely determined. The target styles are redundant styles and can be safely deleted, thereby reducing the code size.

[0103] This embodiment determines a target style file and a target page content file, and generates a first grammatical structure corresponding to the target style file and a second grammatical structure corresponding to the target page content file; based on the first grammatical structure and the second grammatical structure, determines a redundant selector of the target style file; determines a target style corresponding to the redundant selector, and deletes the code corresponding to the target style. The present invention generates modular grammatical structures for style files and page content files respectively, determines redundant selectors through the grammatical structures of the two, and thus determines that the styles defined by the redundant selectors are useless styles that can be safely deleted, thereby achieving efficient removal of redundant code and reducing code volume.

[0104] Furthermore, based on the first embodiment of the redundant code removal method of the present invention, a second embodiment of the redundant code removal method of the present invention is proposed.

[0105] The second embodiment of the redundant code removal method is different from the first embodiment of the redundant code removal method in that, in the process of determining the target style file and the target page content file, the redundant code removal method further includes:

[0106] Step c, determining the scope of the target style file;

[0107] Step d: if the scope of the target style file is global, determine the first temporary file corresponding to the target style file, and determine the first temporary file as the target page content file, so as to represent the page content files of all pages and components in the global based on the first temporary file.

[0108] In the mini-program framework of this embodiment, component modules are defined. The components in the component modules contain corresponding configuration files. The configuration files can have different configurations for the scope of the style files bound to the current component, that is, the style files have different scopes (scope, availability code range). Specifically, the modules containing wxss codes in the mini-program are: app (global), page (page) and component (component). The wxss of app (that is, app.wxss file) will affect the entire mini-program, which is the global style; the wxss of page will affect the page and the components called by it, which is the page style; the wxss of component will only affect this component, which is the component style. That is, the wxss in the mini-program affects app->page->component, that is, the global style affects the pages and components of the entire mini-program, the page style affects the page and the components called by the page, and the component style affects the component.

[0109] Therefore, in the process of determining the target style file and the target page content file, the scope of the target style file is determined first, and then the target page content file is determined, thereby further improving the accuracy of determining the target page content file.

[0110] The following is a detailed description of each step:

[0111] Step c: determine the scope of the target style file.

[0112] In this embodiment, the scope of the target style file is first determined, specifically according to the definition of the target style file. That is, style files of multiple scopes are defined in the mini-program framework, and each style file has its corresponding scope, where the scope includes global, page, and component.

[0113] Step d: if the scope of the target style file is global, determine the first temporary file corresponding to the target style file, and determine the first temporary file as the target page content file, so as to represent the page content files of all pages and components in the global based on the first temporary file.

[0114] In this embodiment, if the scope of the target style file is global, that is, the target style file is a global style file, the first temporary file corresponding to the target style file is first determined, and the first temporary file is determined as the target page content file, wherein the first temporary file refers to the page content file of all pages and components in the global scope, that is, when determining that the scope of the target style file is global, the page content files of all pages and components in the mini program are first determined, and then these page content files are packaged into a temporary file, which is the target page content file.

[0115] In the specific implementation, the mini program stipulates that the file named app.wxss in the root directory of the code package is the mini program public style file. The style defined in it will apply to all wxml files in the mini program, that is, the app.wxss file is a global style file. Therefore, to identify useless wxss in app.wxss, it is necessary to generate a temporary file containing the content of all pages of the mini program.

[0116] In the subsequent process of removing redundancy, the above function can be recorded as: unwxss (wxml of all pages and components, wxss of app), that is, unwxss (first temporary file, target style file).

[0117] Furthermore, in one embodiment, after step c, the redundant code removal method further comprises:

[0118] Step e: if the scope of the target style file is a page, read the configuration file of the target page corresponding to the target style file, and determine the role component corresponding to the target page based on the configuration file;

[0119] In one embodiment, if it is determined that the scope of the target style file is a page, that is, the target style file is a page style, then the configuration file of the target page corresponding to the target style file is read, that is, the configuration file of the target page acted upon by the target style file, and then the effective component corresponding to the target page is determined through the configuration file. This is because the page style will affect the current page and the components called by it, and therefore, it is necessary to determine the effective component affected by the target style file through the configuration file.

[0120] Further, in one embodiment, step e includes:

[0121] Step e1, if the scope of the target style file is a page, read the configuration file of the target page corresponding to the target style file, and determine the to-be-screened component corresponding to the target page based on the configuration file;

[0122] In one embodiment, if it is determined that the scope of the target style file is a page, that is, the target style file is a page style file, then the target page on which the target style file acts is determined, and the configuration file of the target page corresponding to the target style file is read, thereby determining the component to be filtered corresponding to the target page based on the configuration file, that is, determining all components related to the target page.

[0123] Step e2, determining the isolation configuration of the components to be screened, and based on the isolation configuration, determining the active components corresponding to the target page from the components to be screened.

[0124] Then, determine the isolation configuration of the components to be screened in turn. The isolation configuration includes absolute isolation, one-way isolation and no isolation. Absolute isolation means that the components have no influence on the outside, one-way isolation means that the components are affected by the page, but the page is not affected by the components, and no isolation means that the components are affected by the page, and the page is also affected by the components.

[0125] Then, according to the isolation configuration, the effect components corresponding to the target page are screened out from the components to be screened, that is, the components affected by the target page, that is, the components whose isolation configuration is one-way isolation and non-isolation.

[0126] In the specific implementation, the applet stipulates that each page can only have one style file with the same name and in the same directory. For example, if the page content file of a page is / pages / home.wxml, its corresponding style file is / pages / home.wxss. Next, read the usingComponents array field in the configuration file of the current page (such as / pages / home.json) to obtain all components used by the current page, that is, the components to be filtered. If the field content is [" / components / modal", " / components / msg"], read the styleIsolation field in the component configuration files / components / modal.json and / components / msg.json in turn to obtain the component's isolation configuration. If the value is isolated, it is determined that the target style file will not affect the component; if the value is apply-shared, it is determined that the target style file will affect the component.

[0127] Step f, determining a second temporary file corresponding to the target style file, and determining the second temporary file as the target page content file, so as to characterize the page content file of the target page and the page content file of the active component based on the second temporary file.

[0128] In one embodiment, if the scope of the target style file is a page, that is, the target style file is a page style file, the second temporary file corresponding to the target style file is first determined, and the second temporary file is determined as the target page content file, wherein the second temporary file refers to the page content file of the target page corresponding to the target style file, and the page content file of the active component corresponding to the target page, that is, when determining that the scope of the target style file is a page, the page content file of the corresponding target page and the page content file of the active component affected by the target page are first determined, and then these page content files are packaged into a temporary file, which is the target page content file.

[0129] Therefore, to identify the useless code in the wxss of the page scope, it is necessary to generate a temporary file containing the wxml of the target page and the wxml of all components called by the page with the styleIsolation configuration value of apply-shared. Then compare the wxss of the target page and the temporary file, which can be expressed as a function: unwxss (wxml of a page + component.wxml of all components affected by the first page style, wxss of a page), that is, unwxss (second temporary file, target style file).

[0130] Furthermore, if it is determined that the scope of the target style file is a component, it is only necessary to compare the corresponding wxml and wxss files, which can be expressed as a function: unwxss (wxml of a component, wxss of a component).

[0131] In this embodiment, since wxss files with multiple scopes are defined in the mini-program framework, the target style file and the target page content file need to be correctly identified during the process of removing redundant code. That is, the removal process is the same, the difference is that the compared wxml code and wxss code are different. Therefore, during the removal process, it is necessary to determine the scope of the target style, so as to determine the correct target page content file, so as to find the correct redundant code later and realize the correct removal of redundant code.

[0132] Furthermore, based on the first and second embodiments of the redundant code removal method of the present invention, a third embodiment of the redundant code removal method of the present invention is proposed.

[0133] The third embodiment of the redundant code removal method is different from the first and second embodiments of the redundant code removal method in that, in the process of determining the redundant selector of the target style file, the redundant code removal method further includes:

[0134] Step g, determining the mini-program type corresponding to the target style file, and determining a selector list corresponding to the mini-program type;

[0135] Step h, based on the selector list, determining whether the target style file has a selector that is not supported by the mini-program type;

[0136] Step i: if any, determine the selector that is not supported by the applet type as a redundant selector.

[0137] Due to the limitations of the mini-program project itself, this embodiment cannot support many selectors, that is, the mini-program can only support defined selectors. For unsupported selectors, if they are used in the target style file, they can be considered as redundant selectors.

[0138] The following is a detailed description of each step:

[0139] Step g, determining the mini-program type corresponding to the target style file, and determining the selector list corresponding to the mini-program type.

[0140] In this embodiment, the mini-program type corresponding to the target style file is first determined, and the selector list corresponding to the mini-program type is determined. That is, through the mini-program type, it is determined which selectors the mini-program can support. For example, if the mini-program type is a WeChat mini-program, it is determined that the selectors it can support include class selectors, id selectors, and element selectors, etc., that is, the selector list includes class selectors, id selectors, and element selectors, etc.

[0141] Step h: based on the selector list, determine whether the target style file contains a selector that is not supported by the mini-program type.

[0142] In this embodiment, after determining the selectors that the current applet can support, it is determined whether the target style file contains selectors that the current applet does not support, that is, the selectors in the target style file are compared with the selectors in the selector list to determine whether there are selectors in the target style file that are not in the selector list.

[0143] Step i: if any, determine the selector that is not supported by the applet type as a redundant selector.

[0144] In this embodiment, if it exists, the selector is determined to be a redundant selector. This is because the selector is not in the selector list. Even if the target style file uses it, it cannot be executed in the current applet. Therefore, it is identified as a redundant selector.

[0145] In addition, for example, WeChat applets have additional regulations for component scope wxss:

[0146] 1. Components and pages that reference components cannot use id selectors (#a), attribute selectors ([a]), and tag name selectors. That is, when the scope of the target style file is a component, it is also necessary to determine whether the components in the target style file and the pages that reference components use id selectors, attribute selectors, and tag name selectors. If they do, these selectors are considered redundant.

[0147] 2. Using descendant selectors (.ab) in components and pages that reference components may have unexpected behavior in some extreme cases. That is, when the scope of the target style file is a component, it is also necessary to determine whether the components in the target style file and the pages that reference components use descendant selectors. If so, these selectors are considered redundant.

[0148] 3. The sub-element selector (.a>.b) can only be used between the view component and its child nodes. Using it for other components may cause unexpected situations. That is, when the scope of the target style file is a component, determine whether there is a component other than the view component that uses the sub-element selector. If so, the selector used by the component is a redundant selector.

[0149] The mini program of this embodiment does not support selectors other than the selector list. Therefore, in the process of determining redundant selectors, it can be determined whether the selector is in the selector list. If not, it is a redundant selector. In addition, selectors that hit additional regulations are also determined to be redundant selectors so that redundant codes can be accurately removed later, thereby improving the accuracy of redundant code removal.

[0150] The present invention also provides a redundant code removal device. The redundant code removal device of the present invention comprises:

[0151] A first determination module, used to determine a target style file and a target page content file, and generate a first grammatical structure corresponding to the target style file and a second grammatical structure corresponding to the target page content file;

[0152] A second determining module, configured to determine a redundant selector of the target style file based on the first grammatical structure and the second grammatical structure;

[0153] The deletion module is used to determine the target style corresponding to the redundant selector and delete the code corresponding to the target style.

[0154] Preferably, the first determining module is further used for:

[0155] Determine the scope of the target style file;

[0156] If the scope of the target style file is global, a first temporary file corresponding to the target style file is determined, and the first temporary file is determined as the target page content file, so as to represent the page content files of all pages and components in the global context based on the first temporary file.

[0157] Preferably, the first determining module is further used for:

[0158] If the scope of the target style file is a page, then reading a configuration file of the target page corresponding to the target style file, and determining the role component corresponding to the target page based on the configuration file;

[0159] A second temporary file corresponding to the target style file is determined, and the second temporary file is determined as a target page content file, so as to characterize the page content file of the target page and the page content file of the effect component based on the second temporary file.

[0160] Preferably, the first determining module is further used for:

[0161] If the scope of the target style file is a page, then reading a configuration file of the target page corresponding to the target style file, and determining the component to be filtered corresponding to the target page based on the configuration file;

[0162] An isolation configuration of the component to be screened is determined, and based on the isolation configuration, an effect component corresponding to the target page is determined from the component to be screened.

[0163] Preferably, the second determining module is further used for:

[0164] Based on the first grammatical structure, extract a first selector of the target style file, and based on the second grammatical structure, extract a second selector of the target page content file;

[0165] Based on the first selector and the second selector, a redundant selector of the target style file is determined.

[0166] Preferably, the first determining module is further used for:

[0167] Determine a target style file and a target page content file, and obtain a first source code of the target style file and a second source code of the target page content file;

[0168] Parsing the first source code, and generating a first grammatical structure corresponding to the target style file based on a preset template;

[0169] The second source code is parsed, and based on the preset template, a second grammatical structure corresponding to the target page content file is generated.

[0170] Preferably, the second determining module is further used for:

[0171] Determine the mini-program type corresponding to the target style file, and determine the selector list corresponding to the mini-program type;

[0172] Based on the selector list, determining whether the target style file has a selector that is not supported by the mini-program type;

[0173] If so, the selector that is not supported by the applet type is determined to be a redundant selector.

[0174] The present invention also provides a computer-readable storage medium.

[0175] The computer-readable storage medium of the present invention stores a redundant code removal program, and when the redundant code removal program is executed by a processor, the steps of the redundant code removal method described above are implemented.

[0176] The method implemented when the redundant code removal program running on the processor is executed can refer to the various embodiments of the redundant code removal method of the present invention, which will not be described in detail here.

[0177] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or system including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or system. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or system including the element.

[0178] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.

[0179] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) as described above, and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in each embodiment of the present invention.

[0180] The above are only preferred embodiments of the present invention, and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.

Claims

1. A redundant code removal method, characterized in that: Applied to a redundant code removal device of a financial institution, the redundant code removal method comprises the following steps: Determine a target style file and a target page content file, and generate a first grammatical structure corresponding to the target style file and a second grammatical structure corresponding to the target page content file; Determining a redundant selector of the target style file based on the first grammatical structure and the second grammatical structure; The styles in the target style file are defined by selectors; Determine the target style corresponding to the redundant selector, that is, after determining the redundant selector, reversely determine the target style defined by the redundant selector, which is the redundant style, and delete the code corresponding to the target style to reduce the code volume of the mini program; The step of determining the target style file and the target page content file includes: Determine the scope of the target style file; If the scope of the target style file is global, determine the first temporary file corresponding to the target style file, and determine the first temporary file as the target page content file, so as to represent the page content files of all pages and components in the global scope based on the first temporary file. Specifically, when determining that the scope of the target style file is global, first determine the page content files of all pages and components in the mini program, and then package these page content files into a temporary file, which is the target page content file; the first temporary file includes: the page content files of all pages and components in the global scope; Wherein, after the step of determining the scope of the target style file, the redundant code removal method further includes: If the scope of the target style file is a page, then read the configuration file of the target page corresponding to the target style file, and determine the active component corresponding to the target page based on the configuration file, that is, determine the active component affected by the target style file through the configuration file; Determine a second temporary file corresponding to the target style file, and determine the second temporary file as the target page content file, so as to characterize the page content file of the target page and the page content file of the effect component based on the second temporary file, that is, when determining that the scope of the target style file is a page, first determine the corresponding page content file of the target page and the page content file of the effect component affected by the target page, and then package these page content files into a temporary file, which is the target page content file; Wherein, if the scope of the target style file is a page, the step of reading a configuration file of a target page corresponding to the target style file, and determining the role component corresponding to the target page based on the configuration file includes: If the scope of the target style file is a page, then reading a configuration file of the target page corresponding to the target style file, and determining the component to be filtered corresponding to the target page based on the configuration file; Determine the isolation configuration of the to-be-screened component, and based on the isolation configuration, determine the effect component corresponding to the target page from the to-be-screened component; the isolation configuration includes absolute isolation, unidirectional isolation and non-isolation, wherein the absolute isolation means that the component has no influence on the outside; the unidirectional isolation means that the component is affected by the page, but the page is not affected by the component; and the non-isolation means that the component is affected by the page, and the page is also affected by the component; Among them, the global style affects the pages and components of the entire mini program, the page style affects the current page and the components called by this page, and the component style affects the current component.

2. The redundant code removal method according to claim 1, characterized in that: The step of determining the redundant selector of the target style file based on the first grammatical structure and the second grammatical structure includes: Based on the first grammatical structure, extract a first selector of the target style file, and based on the second grammatical structure, extract a second selector of the target page content file; Based on the first selector and the second selector, a redundant selector of the target style file is determined.

3. The redundant code removal method according to claim 1, characterized in that: The step of determining a target style file and a target page content file, and generating a first grammatical structure corresponding to the target style file and a second grammatical structure corresponding to the target page content file comprises: Determine a target style file and a target page content file, and obtain a first source code of the target style file and a second source code of the target page content file; Parsing the first source code, and generating a first grammatical structure corresponding to the target style file based on a preset template; The second source code is parsed, and based on the preset template, a second grammatical structure corresponding to the target page content file is generated.

4. The redundant code removal method according to any one of claims 1 to 3, characterized in that: In the process of determining the redundant selector of the target style file, the redundant code removal method further includes: Determine the mini-program type corresponding to the target style file, and determine the selector list corresponding to the mini-program type; Based on the selector list, determining whether the target style file has a selector that is not supported by the mini-program type; If so, the selector that is not supported by the applet type is determined to be a redundant selector.

5. A redundant code removal device, characterized in that: The redundant code removal device is applied to a financial institution, and the redundant code removal device comprises: A first determination module, used to determine a target style file and a target page content file, and generate a first grammatical structure corresponding to the target style file and a second grammatical structure corresponding to the target page content file; A second determining module is used to determine a redundant selector of the target style file based on the first grammatical structure and the second grammatical structure; the style in the target style file is defined by a selector; A deletion module is used to determine the target style corresponding to the redundant selector, that is, after determining the redundant selector, reversely determine the target style defined by the redundant selector, which is the redundant style, and delete the code corresponding to the target style to reduce the code volume of the mini program; The step of determining the target style file and the target page content file includes: Determine the scope of the target style file; If the scope of the target style file is global, determine the first temporary file corresponding to the target style file, and determine the first temporary file as the target page content file, so as to represent the page content files of all pages and components in the global scope based on the first temporary file. Specifically, when determining that the scope of the target style file is global, first determine the page content files of all pages and components in the mini program, and then package these page content files into a temporary file, which is the target page content file; the first temporary file includes: the page content files of all pages and components in the global scope; Wherein, after the step of determining the scope of the target style file, the device is further specifically configured to: If the scope of the target style file is a page, then read the configuration file of the target page corresponding to the target style file, and determine the active component corresponding to the target page based on the configuration file, that is, determine the active component affected by the target style file through the configuration file; Determine a second temporary file corresponding to the target style file, and determine the second temporary file as the target page content file, so as to characterize the page content file of the target page and the page content file of the effect component based on the second temporary file, that is, when determining that the scope of the target style file is a page, first determine the corresponding page content file of the target page and the page content file of the effect component affected by the target page, and then package these page content files into a temporary file, which is the target page content file; Wherein, if the scope of the target style file is a page, the step of reading a configuration file of a target page corresponding to the target style file, and determining the role component corresponding to the target page based on the configuration file includes: If the scope of the target style file is a page, then reading a configuration file of the target page corresponding to the target style file, and determining the component to be filtered corresponding to the target page based on the configuration file; Determine the isolation configuration of the to-be-screened component, and based on the isolation configuration, determine the effect component corresponding to the target page from the to-be-screened component; the isolation configuration includes absolute isolation, unidirectional isolation and non-isolation, wherein the absolute isolation means that the component has no influence on the outside; the unidirectional isolation means that the component is affected by the page, but the page is not affected by the component; and the non-isolation means that the component is affected by the page, and the page is also affected by the component; Among them, the global style affects the pages and components of the entire mini program, the page style affects the current page and the components called by this page, and the component style affects the current component.

6. A redundant code removal device, characterized in that: The redundant code removal device comprises: a memory, a processor, and a redundant code removal program stored in the memory and executable on the processor, wherein the redundant code removal program implements the steps of the redundant code removal method according to any one of claims 1 to 4 when executed by the processor.

7. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a redundant code removal program, and when the redundant code removal program is executed by a processor, the steps of the redundant code removal method according to any one of claims 1 to 4 are implemented.

Citation Information

Patent Citations

  • Webpage optimization method and device

    CN110688118A