CN111459537A - Redundant code removing method, device, equipment and computer readable storage medium - Google Patents

Redundant code removing method, device, equipment and computer readable storage medium Download PDF

Info

Publication number
CN111459537A
CN111459537A CN202010262738.0A CN202010262738A CN111459537A CN 111459537 A CN111459537 A CN 111459537A CN 202010262738 A CN202010262738 A CN 202010262738A CN 111459537 A CN111459537 A CN 111459537A
Authority
CN
China
Prior art keywords
file
target
determining
selector
page content
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202010262738.0A
Other languages
Chinese (zh)
Inventor
黎俊标
林挺
卢道和
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
WeBank Co Ltd
Original Assignee
WeBank Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by WeBank Co Ltd filed Critical WeBank Co Ltd
Priority to CN202010262738.0A priority Critical patent/CN111459537A/en
Publication of CN111459537A publication Critical patent/CN111459537A/en
Priority to PCT/CN2021/083624 priority patent/WO2021197273A1/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/71Version control; Configuration management
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/44Encoding
    • G06F8/443Optimisation
    • G06F8/4434Reducing the memory space required by the program code
    • G06F8/4435Detection or removal of dead or redundant code
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating
    • G06F9/44505Configuring for program initiating, e.g. using registry, configuration files
    • G06F9/4451User profiles; Roaming

Abstract

The invention discloses a method for removing redundant codes, which comprises the following steps: determining a target style file and a target page content file, and generating a first grammar structure corresponding to the target style file and a second grammar structure corresponding to the target page content file; determining a redundancy selector for the target style file based on the first syntax structure and the second syntax structure; and determining a target pattern corresponding to the redundancy selector, and deleting a code corresponding to the target pattern. The invention also discloses a redundant code removing device, equipment and a computer readable storage medium. The invention respectively generates the style file and the page content file into modular grammatical structures, and determines the redundant selector through the grammatical structures of the style file and the page content file, thereby determining that the style defined by the redundant selector is a useless style, safely deleting the style, realizing the high-efficiency removal of redundant codes and reducing the code volume.

Description

Redundant code removing method, device, equipment and computer readable storage medium
Technical Field
The present invention relates to the field of financial technology (Fintech), and in particular, to a method, an apparatus, a device, and a computer-readable storage medium for removing redundant codes.
Background
In recent years, with the development of financial technology (Fintech), particularly internet finance, small program technology has been introduced into daily services of financial institutions such as banks. In the daily service process of financial institutions such as banks, in order to meet business requirements, small programs which are applications and can be used without downloading are often required to be developed. In order to adapt to the change of the service or the use habit of the user, the small program needs to be continuously updated in an iterative manner, and a large amount of redundancy of the codes is easily caused in the continuous updating process, so that the redundant codes need to be removed.
In the conventional h5, page content html (HyperText Markup L language) and corresponding Style files css (Cascading Style Sheets) are directly bound in a hyperlink mode, so that all Style files acting on the page can be obtained through hyperlinks in the page, and codes corresponding to the Style files which do not act on the page are screened out and are redundant codes.
The applet specifies page contents, such as wxml (WeiXin Markup L schema) and a Style file, such as wxss (WeiXin Style documents, a set of Style languages for describing wxml component styles) by means of a framework convention, and the Style file (wxss) of the applet is a modification and extension of a conventional h5 Style file (css), and syntax and usage are different.
Disclosure of Invention
The invention mainly aims to provide a method, a device, equipment and a computer readable storage medium for removing redundant codes, and aims to realize efficient removal of applet redundant codes.
In order to achieve the above object, the present invention provides a method for removing a redundant code, including the steps of:
determining a target style file and a target page content file, and generating a first grammar structure corresponding to the target style file and a second grammar structure corresponding to the target page content file;
determining a redundancy selector for the target style file based on the first syntax structure and the second syntax structure;
and determining a target pattern corresponding to the redundancy selector, and deleting a code corresponding to the target pattern.
Preferably, the step of determining the target style file and the target page content file comprises:
determining a scope of the target style file;
if the scope of the target style file is global, determining a first temporary file corresponding to the target style file, and determining the first temporary file as a target page content file, so as to represent page content files of all pages and components in the whole office based on the first temporary file.
Preferably, 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, reading a configuration file of a target page corresponding to the target style file, and determining an effect component corresponding to the target page based on the configuration file;
and determining a second temporary file corresponding to the target style file, and determining the second temporary file as a target page content file, so as to represent the page content file of the target page and the page content file of the active component based on the second temporary file.
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 the scope component corresponding to the target page based on the configuration file includes:
if the scope of the target style file is a page, reading a configuration file of a target page corresponding to the target style file, and determining a component to be screened corresponding to the target page based on the configuration file;
and determining the isolation configuration of the components to be screened, and determining the action components corresponding to the target page from the components to be screened based on the isolation configuration.
Preferably, the determining a redundancy selector of the target style file based on the first syntax structure and the second syntax structure comprises:
extracting a first selector of the target style file based on the first grammar structure and a second selector of the target page content file based on the second grammar structure;
determining a redundancy selector for the target style file based on the first selector and the second selector.
Preferably, the step of 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 includes:
determining a target style file and a target page content file, and acquiring a first source code of the target style file and a second source code of the target page content file;
analyzing the first source code, and generating a first grammar structure corresponding to the target style file based on a preset template;
and analyzing the second source code, and generating a second grammar structure corresponding to the target page content file based on the preset template.
Preferably, in the determining of the redundancy selector of the target style file, the redundant code removing method further includes:
determining an applet type corresponding to the target style file, and determining a selector list corresponding to the applet type;
determining, based on the selector list, whether there are selectors of the target style file that are not supported by the applet type;
if so, determining the selector which is not supported by the applet type as a redundancy selector.
In addition, to achieve the above object, the present invention also provides a redundant code removal apparatus, including:
the first determining module is used for determining a target style file and a target page content file and generating a first grammar structure corresponding to the target style file and a second grammar structure corresponding to the target page content file;
a second determination module to determine a redundancy selector for the target style file based on the first syntax structure and the second syntax structure;
and the deleting module is used for determining the target pattern corresponding to the redundancy selector and deleting the code corresponding to the target pattern.
Preferably, the first determining module is further configured to:
determining a scope of the target style file;
if the scope of the target style file is global, determining a first temporary file corresponding to the target style file, and determining the first temporary file as a target page content file, so as to represent page content files of all pages and components in the whole office based on the first temporary file.
Preferably, the first determining module is further configured to:
if the scope of the target style file is a page, reading a configuration file of a target page corresponding to the target style file, and determining an effect component corresponding to the target page based on the configuration file;
and determining a second temporary file corresponding to the target style file, and determining the second temporary file as a target page content file, so as to represent the page content file of the target page and the page content file of the active component based on the second temporary file.
Preferably, the first determining module is further configured to:
if the scope of the target style file is a page, reading a configuration file of a target page corresponding to the target style file, and determining a component to be screened corresponding to the target page based on the configuration file;
and determining the isolation configuration of the components to be screened, and determining the action components corresponding to the target page from the components to be screened based on the isolation configuration.
Preferably, the second determining module is further configured to:
extracting a first selector of the target style file based on the first grammar structure and a second selector of the target page content file based on the second grammar structure;
determining a redundancy selector for the target style file based on the first selector and the second selector.
Preferably, the first determining module is further configured to:
determining a target style file and a target page content file, and acquiring a first source code of the target style file and a second source code of the target page content file;
analyzing the first source code, and generating a first grammar structure corresponding to the target style file based on a preset template;
and analyzing the second source code, and generating a second grammar structure corresponding to the target page content file based on the preset template.
Preferably, the second determining module is further configured to:
determining an applet type corresponding to the target style file, and determining a selector list corresponding to the applet type;
determining, based on the selector list, whether there are selectors of the target style file that are not supported by the applet type;
if so, determining the selector which is not supported by the applet type as a redundancy selector.
Further, to achieve the above object, the present invention also provides a redundant code removal apparatus including: a memory, a processor and a redundant code removal program stored on the memory and executable on the processor, the redundant code removal program when executed by the processor implementing the steps of the redundant code removal method as described above.
Further, to achieve the above object, the present invention also provides a computer-readable storage medium having stored thereon a redundant code removal program which, when executed by a processor, implements the steps of the redundant code removal method as described above.
The redundant code removing method determines a target style file and a target page content file, and generates a first grammar structure corresponding to the target style file and a second grammar structure corresponding to the target page content file; determining a redundancy selector for the target style file based on the first syntax structure and the second syntax structure; and determining a target pattern corresponding to the redundancy selector, and deleting a code corresponding to the target pattern. The invention respectively generates the style file and the page content file into modular grammatical structures, and determines the redundant selector through the grammatical structures of the style file and the page content file, thereby determining that the style defined by the redundant selector is a useless style, safely deleting the style, realizing the high-efficiency removal of redundant codes and reducing the volume of program codes.
Drawings
FIG. 1 is a schematic diagram of an apparatus architecture of a hardware operating environment according to an embodiment of the present invention;
FIG. 2 is a flowchart illustrating a redundant code removal method according to a first embodiment of the present invention;
FIG. 3(a) is a diagram illustrating a first selector in a first embodiment of the redundant code removal method according to the present invention;
fig. 3(b) is a schematic diagram of extracting a second selector in the first embodiment of the redundant code removal method of the present invention.
The implementation, functional features and advantages of the objects of the present invention will be further explained with reference to the accompanying drawings.
Detailed Description
It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
As shown in fig. 1, fig. 1 is a schematic device structure diagram of a hardware operating environment according to an embodiment of the present invention.
The device of the embodiment of the invention can be a mobile terminal or a server device.
As shown in fig. 1, the apparatus may include: a processor 1001, such as a CPU, a network interface 1004, a user interface 1003, a memory 1005, a communication bus 1002. Wherein a communication bus 1002 is used to enable connective 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, a wireless interface. The network interface 1004 may optionally include a standard wired interface, a wireless interface (e.g., WI-FI interface). The memory 1005 may be a high-speed RAM memory or a non-volatile memory (e.g., a magnetic disk memory). The memory 1005 may alternatively be a storage device separate from the processor 1001.
Those skilled in the art will appreciate that the configuration of the apparatus shown in fig. 1 is not intended to be limiting of the apparatus and may include more or fewer components than those shown, or some components may be combined, or a different arrangement of components.
As shown in fig. 1, a memory 1005, which is a kind of computer storage medium, may include therein an operating system, a network communication module, a user interface module, and a redundancy code removal program.
The operating system is a program for managing and controlling the redundant code removal equipment and software resources and supports the running of the network communication module, the user interface module, the redundant code removal program and other programs or software; the network communication module is used for managing and controlling the network interface 1002; the user interface module is used to manage and control the user interface 1003.
In the redundant code removal apparatus shown in fig. 1, the redundant code removal apparatus calls a redundant code removal program stored in a memory 1005 by a processor 1001 and performs operations in the respective embodiments of the redundant code removal method described below.
Based on the hardware structure, the embodiment of the method for removing the redundant code is provided.
Referring to fig. 2, fig. 2 is a schematic flowchart of a redundant code removal method according to a first embodiment of the present invention, where the method includes:
step S10, determining a target style file and a target page content file, and generating a first syntactic structure corresponding to the target style file and a second syntactic structure corresponding to the target page content file;
a step S20 of determining a redundancy selector of the target style file based on the first syntax structure and the second syntax structure;
step S30, determining a target pattern corresponding to the redundancy selector, and deleting a code corresponding to the target pattern.
The redundant code removing method is applied to redundant code removing equipment of financial institutions such as financial institutions or bank systems, the redundant code removing equipment can be terminals, robots or PC equipment, and the like, and for convenience of description, the redundant code removing equipment is referred to as removing equipment for short. The removal device is provided with various applications, such as WeChat applications and the like, and small programs, such as WeChat small programs and the like, are operated in the applications. In the following description, a wechat applet is described as an example. It should be noted that, the applet specifies a binding relationship between a page content wxml and a style file wxss in the applet in a framework convention manner, where wxml is a set of tag languages designed by the applet framework, and in combination with a basic component and an event system, the page content may be constructed, and wxss is a set of style languages used for describing a component style of wxml, that is, wxss is used to determine how a component of wxml should be displayed. Therefore, under normal conditions, the styles in the style file are the styles used by the page content file.
However, in practical applications, the applet is used as an interface directly contacting with a user in an application (such as a WeChat), and it is often necessary to adapt to changes of a service or a usage habit of the user and continuously perform iterative upgrade, the code changes very frequently, a large amount of redundancy of the code is likely to be caused in the process of continuously performing iterative upgrade, especially wxss codes, after the iteration, a large number of wxml unwanted wxss are likely to appear in the applet, that is, after the iteration, a pattern that is not used in a page content file exists in a pattern file, if the applet performs the iteration, a picture content displayed on a current interface is dynamically upgraded from a static state, a statically displayed pattern is no longer a pattern required by the current picture content, and at this time, a code corresponding to the statically displayed pattern is a redundant code. Because the relationship between wxss and wxml is not directly bound through hyperlinks like html and css, i.e. it cannot be well modularized, it is difficult to identify useless codes in wxss.
The embodiment firstly determines a target style file and a target page content file, respectively generates a modular grammar structure for the target style file and the target page content file, conveniently extracts selectors of the target style file and the target page content file, screens out selectors which are not used by the target page content file through the selectors of the target style file and the target page content file, accordingly determines that a style defined by the selectors is a useless style, and finally deletes codes corresponding to the useless style, namely, effectively removes redundant codes.
The respective steps will be described in detail below:
step S10, determining a target style file and a target page content file, and generating a first syntactic structure corresponding to the target style file and a second syntactic structure corresponding to the target page content file;
in this embodiment, when determining the redundant code of the applet, the target style file and the target page content file in the applet are determined first, the target style file is generated into a modular first syntax structure, and the target page content file is also generated into a modular second syntax structure, so that selectors of the target style file and the target page content file can be determined conveniently from the modular first syntax structure and the modular second syntax structure.
In one embodiment, step S10 includes:
step a1, determining a target style file and a target page content file, and acquiring a first source code of the target style file and a second source code of the target page content file;
in an embodiment, the removing device determines the target style file and the target page content file corresponding to the target style file, and then obtains a first source code of the target style file and a second source code of the target page content file respectively.
A2, analyzing the first source code, and generating a first syntactic structure corresponding to the target style file based on a preset template;
then, the first source code is analyzed, specifically, the lexical analysis is carried out on the first source code, then the grammatical analysis is carried out on the first source code, 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 character string into token (token) flow, the grammar analysis stage is to convert the token flow into grammar node, therefore, according to the preset template, all grammar nodes are pieced together into a complete grammar structure, namely, the removing equipment analyzes a long string of character strings connected in a whole line into the arrangement of short character strings, and then the short character strings are filled into the preset template as nodes, thereby obtaining a first grammar structure, in a specific implementation, the preset template may be a tree template, that is, an extensible template in which a parent node is used as a root node and a child node is used as a branch node, and each node corresponds to one syntax node.
Step a3, parsing the second source code, and generating a second syntactic structure corresponding to the target page content file based on the preset template.
And then, analyzing the second source code, and generating a second grammar structure corresponding to the target page content file according to a preset template, wherein the specific generation mode is similar to the mode of generating the first grammar structure, and the detailed description is omitted here.
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, an existing tool, such as an esprima compiler or a babel compiler, may also be used to generate an abstract syntax tree. In addition, the order of generating the first grammar structure and the second grammar structure may be interchanged without affecting the implementation of the present embodiment.
Step S20, determining a redundancy selector of the target style file based on the first syntax structure and the second syntax structure.
In this embodiment, after obtaining the first syntax structure and the second syntax structure, the first syntax structure and the second syntax structure may be compared to determine the redundancy selector of the target pattern.
Specifically, in an embodiment, step S20 includes:
step b1, extracting a first selector of the target style file based on the first syntactic structure, and extracting a second selector of the target page content file based on the second syntactic structure;
in an embodiment, the first selector of the target style file is extracted first through the first syntax structure, and then the second selector of the target page content file is extracted through the second syntax structure, it can be understood that the extraction sequence is interchangeable, where the selectors refer to style action components, and in the specific implementation process, the selectors supported by the applet are obtained first, for example, the selectors supported by the WeChat applet include a class selector, an id selector, an element selector, and the like. Class is a class selector, such as intro, meaning that all components that possess class are selected as "intro"; id is an id selector, such as # firstname, which means that a component with di ═ firstname is selected; an element is an element selector, such as view, that means all view components are selected, etc.
Thus, a first selector for the target style file may be determined in the first syntax structure and a second selector for the target page content file may be determined in the second syntax structure based on the selector names.
As shown in fig. 3(a), the left window is wxss code, that is, the source code of the target style file, the right window is the first syntax structure generated, and the rectangular frame in the right window is the first selector, which is respectively an id selector: # index, element selector: view, class selector: title,. content. As shown in fig. 3(b), the left window is wxml code, that is, the source code of the target page content file, the right window is the generated second syntax structure, and the rectangular frame in the right window is the second selector, which is respectively an element selector: view, text, id selector: index, class selector: title.
Step b2 of determining a redundancy selector of the target style file based on the first selector and the second selector
In an embodiment, based on the first selector and the second selector, a redundancy selector of the target style file is determined, specifically, according to a formula: wxss, wxml, is a redundancy selector, and the first selector is subtracted from the second selector to obtain a selector that is not used in the target page content file, i.e., the redundancy selector is useless.
As in the above example, subtracting the selector in FIG. 3(b) from the selector in FIG. 3(a) would find that the content pattern defined in wxss is not used in wxml, then it is determined that this selector is redundant.
For convenience of explanation, the process of removing useless wxss is identified by a function unwxss, and the function has wxml code and wxss code as its inputs, that is, the function is: unwxss (wxml, wxss) ═ wxss (useful).
Step S30, determining a target pattern corresponding to the redundancy selector, and deleting a code corresponding to the target pattern.
In this embodiment, after the redundancy selector of the target pattern file is determined, it may be determined that the target pattern defined by the redundancy selector is redundant, and therefore, safe deletion may be performed, and at this time, deleting the code corresponding to the target pattern may not affect normal use of the applet.
In this embodiment, the pattern in the pattern file is defined by the selector, and therefore, after the redundancy selector is determined, the target pattern defined by the redundancy selector can be determined in the reverse direction, and the target pattern is the redundancy pattern and can be safely deleted, so that the code volume is reduced.
The embodiment determines a target style file and a target page content file, and generates a first syntax structure corresponding to the target style file and a second syntax structure corresponding to the target page content file; determining a redundancy selector for the target style file based on the first syntax structure and the second syntax structure; and determining a target pattern corresponding to the redundancy selector, and deleting a code corresponding to the target pattern. The invention respectively generates the style file and the page content file into modular grammatical structures, and determines the redundant selector through the grammatical structures of the style file and the page content file, thereby determining that the style defined by the redundant selector is a useless style, safely deleting the style, realizing the high-efficiency removal of redundant codes and reducing the code volume.
Further, based on the first embodiment of the method for removing redundant codes of the present invention, a second embodiment of the method for removing redundant codes of the present invention is proposed.
The second embodiment of the redundant code removal method differs from the first embodiment of the redundant code removal method in that, in determining the target style file and the target page content file, the redundant code removal method further includes:
step c, determining the scope of the target style file;
and d, if the scope of the target style file is global, determining a first temporary file corresponding to the target style file, and determining the first temporary file as a target page content file so as to represent the page content files of all pages and components in the whole office based on the first temporary file.
In this embodiment, a component module is defined in an applet framework, a component in the component module includes a corresponding configuration file, the configuration file may have different configurations for an action range of a style file bound with a current component, that is, the style file has different action domains (scope, availability code range), and specifically, a module of the applet including a wxss code includes: app (global), page, and component, whose wxss (i.e., app. wxss file) affects the entire applet, as a global style; the wxss of the page can influence the page and the called components thereof, and the page is a page style; the wxss of a component only affects the component, which is a component style. That is, wxss in an applet affects app- > page- > component, that is, global style affects pages and components of the whole applet, page style affects pages and components called by pages, and component style affects components called by pages.
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, so that the correctness of determining the target page content file is further improved.
The respective steps will be described in detail below:
and c, determining the scope of the target style file.
In this embodiment, a scope of the target style file is determined, specifically, the scope of the target style file is determined according to the definition of the target style file, that is, style files of multiple scopes are defined in the applet framework, each style file has a scope corresponding thereto, where a scope includes global, page, and component.
And d, if the scope of the target style file is global, determining a first temporary file corresponding to the target style file, and determining the first temporary file as a target page content file so as to represent the page content files of all pages and components in the whole office based on the first temporary file.
In this embodiment, if the scope of the target style file is global, that is, the target style file is a global style file, a first temporary file corresponding to the target style file is determined first, and the first temporary file is determined as a target page content file, where the first temporary file refers to page content files of all pages and components in the whole office, that is, when the scope of the target style file is determined to be global, page content files of all pages and components in the applet are determined first, and then the page content files are packaged into a temporary file, that is, the target page content file.
In a specific implementation, the applet specifies a file named app.wxss in the root directory of the code package as an applet common style file, wherein a defined style acts on all wxml files in the applet, that is, the app.wxss file is a global style file, so that identifying useless wxss in the app.wxss requires generating a temporary file containing all page contents of the applet.
In the subsequent process of removing redundancy, the function can be recorded as: unwxss (wxml for all pages and components, wxss for app), i.e., unwxss (first temporary file, object style file).
Further, in an embodiment, after the step c, the method for removing redundant codes further includes:
step e, if the scope of the target style file is a page, reading a configuration file of a target page corresponding to the target style file, and determining an action component corresponding to the target page based on the configuration file;
in an 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, the configuration file of the target page corresponding to the target style file, that is, the configuration file of the target page acted by the target style file, is read, and then the action component corresponding to the target page is determined through the configuration file, because the page style affects the page and the components called by the page style, the action component affected by the target style file needs to be determined through the configuration file.
Further, in one embodiment, step e includes:
step e1, if the scope of the target style file is a page, reading a configuration file of a target page corresponding to the target style file, and determining a component to be screened corresponding to the target page based on the configuration file;
in an 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, the target page acted by the target style file is determined, and the configuration file of the target page corresponding to the target style file is read, so that the component to be screened corresponding to the target page is determined according to the configuration file, that is, all components related to the target page are determined.
Step e2, determining the isolation configuration of the components to be screened, and determining the action components corresponding to the target page from the components to be screened based on the isolation configuration.
Then, the isolation configuration of the components to be screened is determined in sequence, wherein the isolation configuration comprises absolute isolation, unidirectional isolation and non-isolation, the absolute isolation means that the components are not affected by the outside of the components, the unidirectional isolation means that the components are affected by the page, but the page is not affected by the components, the non-isolation means that the components are affected by the page, and the page is also affected by the components.
Then, according to the isolation configuration, screening out an action component corresponding to the target page from the components to be screened, namely, a component influenced by the target page, namely, the isolation configuration is a component isolated in a unidirectional manner and a component not isolated.
In particular, the applet specifies that each page can only have one style file with the same name and under the same directory. If the page content file of one page is/pages/home.wxml, the corresponding style file is/pages/home.wxss. Then, reading a using components array field in a configuration file (such as/pages/home. json) of the current page, and acquiring all components used by the current page, namely components to be screened, if the field content is [ "/components/mode", "/components/msg" ], then sequentially reading a style analysis field in the configuration file/components/mode. json and/components/msg. json of the components to acquire the isolated configuration of the components, and if the field content is isolated, determining that the target style file does not influence the components; if the value is application-shared, then the determination that the target style file affects the component.
And f, determining a second temporary file corresponding to the target style file, determining the second temporary file as a target page content file, and characterizing the page content file of the target page and the page content file of the action component based on the second temporary file.
In an embodiment, if the scope of the target style file is a page, that is, the target style file is a page style file, a second temporary file corresponding to the target style file is determined first, and the second temporary file is determined as a target page content file, where the second temporary file refers to a page content file of a target page corresponding to the target style file and a page content file of an action component corresponding to the target page, that is, when the scope of the target style file is determined as a page, a page content file of a corresponding target page and a page content file of an action component affected by the target page are determined first, and then the page content files are packaged into a temporary file, that is, the target page content file.
Therefore, to identify the garbage code in wxss of the page scope, a temporary file containing wxml of the target page wxml and all components called by the page having style relationships configuration values of application-shared needs to be generated. Then comparing wxss of the target page with the temporary file, and using the function to express as: wxss (wxml of a certain page + component of a component affected by all the first page styles, wxss of a certain page), that is, unwxss (second temporary file, target style file).
Further, if it is determined that the scope of the target style file is a component, only the corresponding wxml and wxss files need to be compared, and the functions are expressed as: unwxss (wxml for a component, wxss for a component).
In this embodiment, because the applet frame is defined in wxss files of multiple scopes, in the process of removing the redundant code, the target pattern file and the target page content file need to be correctly identified, that is, the removal process is the same, and the difference is that the compared wxml code is different from the wxss code, so in the removal process, the scope of the target pattern needs to be determined, so as to determine the correct target page content file, so that the correct redundant code is found in the following, and the correct removal of the redundant code is realized.
Further, a third embodiment of the redundant code removal method of the present invention is proposed based on the first and second embodiments of the redundant code removal method of the present invention.
The third embodiment of the redundant code removal method differs from the first and second embodiments of the redundant code removal method in that, in determining the redundancy selector of the target style file, the redundant code removal method further includes:
step g, determining the applet type corresponding to the target style file, and determining a selector list corresponding to the applet type;
step h, determining whether the target style file has a selector which is not supported by the applet type based on the selector list;
and step i, if the selector exists, determining the selector which is not supported by the applet type as a redundancy selector.
In this embodiment, due to the limitation of the applet item itself, many selectors cannot be supported, that is, the applet can only support well-defined selectors, and for the selectors that are not supported, if the object style file is used, the object style file can be regarded as a redundant selector.
The respective steps will be described in detail below:
and g, determining the applet type corresponding to the target style file, and determining a selector list corresponding to the applet type.
In this embodiment, the applet type corresponding to the target style file is determined first, and the selector list corresponding to the applet type is determined, that is, which selectors can be supported by the applet are determined by the applet type, and if the applet type is a wechat applet, the supportable selectors include a class selector, an id selector, an element selector, and the like are determined, that is, the selector list includes the class selector, the id selector, the element selector, and the like.
And h, determining whether the target style file has a selector which is not supported by the applet type or not based on the selector list.
In this embodiment, after determining the selectors that can be supported by the current applet, it is determined whether the target style file has selectors that are not supported by the current applet, that is, the selectors in the target style file are compared with the selectors in the selector list, and it is determined whether the selectors in the selector list do not exist in the target style file.
And step i, if the selector exists, determining the selector which is not supported by the applet type as a redundancy selector.
In this embodiment, if present, the selector is identified as a redundant selector because it is not in the selector list and cannot be executed in the current applet even if the target style file is used, and thus is identified as a redundant selector.
Furthermore, as with the WeChat applet, there are additional provisions for the component scope wxss:
1. the id selector (# a), attribute selector ([ a ]), and tag name selector cannot be used by the component and the page referencing the component. That is, when the scope of the target style file is a component, it is also necessary to determine whether the id selector, the attribute selector, and the tag name selector are used for the components and the pages referencing the components in the target style file, and if used, these selectors are considered as redundancy selectors.
2. The use of descendant selectors (. a.b) in the components and pages referencing the components can, in some extreme cases, behave unexpectedly. That is, when the scope of the target style file is a component, it is also necessary to determine whether the pages of the component and the reference component in the target style file use descendant selectors, and if so, these selectors are considered as redundant selectors.
3. The sub-element selector (. a >. b) can only be used between the view component and its child node for situations where other components may cause an unexpected situation. That is, when the scope of the object style file is a component, it is determined whether a child element selector is used for a component other than the view component, and if so, the selector used by the component is a redundancy selector.
The applet of the embodiment does not support selectors except the selector list, so that in the process of determining the redundancy selector, whether the selector is in the selector list can be judged, if not, the selector is the redundancy selector, and in addition, the selector hitting extra rules is also determined as the redundancy selector, so that the redundancy code can be accurately removed subsequently, and the removal accuracy of the redundancy code is improved.
The invention also provides a device for removing the redundant codes. The redundant code removing apparatus of the present invention includes:
the first determining module is used for determining a target style file and a target page content file and generating a first grammar structure corresponding to the target style file and a second grammar structure corresponding to the target page content file;
a second determination module to determine a redundancy selector for the target style file based on the first syntax structure and the second syntax structure;
and the deleting module is used for determining the target pattern corresponding to the redundancy selector and deleting the code corresponding to the target pattern.
Preferably, the first determining module is further configured to:
determining a scope of the target style file;
if the scope of the target style file is global, determining a first temporary file corresponding to the target style file, and determining the first temporary file as a target page content file, so as to represent page content files of all pages and components in the whole office based on the first temporary file.
Preferably, the first determining module is further configured to:
if the scope of the target style file is a page, reading a configuration file of a target page corresponding to the target style file, and determining an effect component corresponding to the target page based on the configuration file;
and determining a second temporary file corresponding to the target style file, and determining the second temporary file as a target page content file, so as to represent the page content file of the target page and the page content file of the active component based on the second temporary file.
Preferably, the first determining module is further configured to:
if the scope of the target style file is a page, reading a configuration file of a target page corresponding to the target style file, and determining a component to be screened corresponding to the target page based on the configuration file;
and determining the isolation configuration of the components to be screened, and determining the action components corresponding to the target page from the components to be screened based on the isolation configuration.
Preferably, the second determining module is further configured to:
extracting a first selector of the target style file based on the first grammar structure and a second selector of the target page content file based on the second grammar structure;
determining a redundancy selector for the target style file based on the first selector and the second selector.
Preferably, the first determining module is further configured to:
determining a target style file and a target page content file, and acquiring a first source code of the target style file and a second source code of the target page content file;
analyzing the first source code, and generating a first grammar structure corresponding to the target style file based on a preset template;
and analyzing the second source code, and generating a second grammar structure corresponding to the target page content file based on the preset template.
Preferably, the second determining module is further configured to:
determining an applet type corresponding to the target style file, and determining a selector list corresponding to the applet type;
determining, based on the selector list, whether there are selectors of the target style file that are not supported by the applet type;
if so, determining the selector which is not supported by the applet type as a redundancy selector.
The invention also provides a computer readable storage medium.
The computer-readable storage medium of the present invention stores thereon a redundant code removal program that implements the steps of the redundant code removal method as described above when executed by a processor.
The method implemented when the redundant code removal program running on the processor is executed may refer to each embodiment of the redundant code removal method of the present invention, and details are not described herein again.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or system. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or system that comprises the element.
The above-mentioned serial numbers of the embodiments of the present invention are merely for description and do not represent the merits of the embodiments.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium (e.g., ROM/RAM, magnetic disk, optical disk) as described above and includes instructions for enabling a terminal device (e.g., a mobile phone, a computer, a server, an air conditioner, or a network device) to execute the method according to the embodiments of the present invention.
The above description is only a preferred embodiment of the present invention, and not intended to limit the scope of the present invention, and all modifications of equivalent structures and equivalent processes, which are made by using the contents of the present specification and the accompanying drawings, or directly or indirectly applied to other related technical fields, are included in the scope of the present invention.

Claims (10)

1. A method for removing redundant codes, comprising the steps of:
determining a target style file and a target page content file, and generating a first grammar structure corresponding to the target style file and a second grammar structure corresponding to the target page content file;
determining a redundancy selector for the target style file based on the first syntax structure and the second syntax structure;
and determining a target pattern corresponding to the redundancy selector, and deleting a code corresponding to the target pattern.
2. The method of removing redundant code according to claim 1 wherein the step of determining a target style file and a target page content file comprises:
determining a scope of the target style file;
if the scope of the target style file is global, determining a first temporary file corresponding to the target style file, and determining the first temporary file as a target page content file, so as to represent page content files of all pages and components in the whole office based on the first temporary file.
3. The method of removing redundant code according to claim 2, wherein after the step of determining the scope of the target style file, the method of removing redundant code further comprises:
if the scope of the target style file is a page, reading a configuration file of a target page corresponding to the target style file, and determining an effect component corresponding to the target page based on the configuration file;
and determining a second temporary file corresponding to the target style file, and determining the second temporary file as a target page content file, so as to represent the page content file of the target page and the page content file of the active component based on the second temporary file.
4. The method according to claim 3, 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 scope component corresponding to the target page based on the configuration file comprises:
if the scope of the target style file is a page, reading a configuration file of a target page corresponding to the target style file, and determining a component to be screened corresponding to the target page based on the configuration file;
and determining the isolation configuration of the components to be screened, and determining the action components corresponding to the target page from the components to be screened based on the isolation configuration.
5. The method of claim 1, wherein the step of determining the redundancy selector of the target style file based on the first syntax structure and the second syntax structure comprises:
extracting a first selector of the target style file based on the first grammar structure and a second selector of the target page content file based on the second grammar structure;
determining a redundancy selector for the target style file based on the first selector and the second selector.
6. The method of claim 1, wherein the determining a target style file and a target page content file and generating a first syntactic structure corresponding to the target style file and a second syntactic structure corresponding to the target page content file comprises:
determining a target style file and a target page content file, and acquiring a first source code of the target style file and a second source code of the target page content file;
analyzing the first source code, and generating a first grammar structure corresponding to the target style file based on a preset template;
and analyzing the second source code, and generating a second grammar structure corresponding to the target page content file based on the preset template.
7. The method of any one of claims 1 to 6, wherein in determining the redundancy selector for the target style file, the method further comprises:
determining an applet type corresponding to the target style file, and determining a selector list corresponding to the applet type;
determining, based on the selector list, whether there are selectors of the target style file that are not supported by the applet type;
if so, determining the selector which is not supported by the applet type as a redundancy selector.
8. A redundant code removal apparatus, characterized in that the redundant code removal apparatus comprises:
the first determining module is used for determining a target style file and a target page content file and generating a first grammar structure corresponding to the target style file and a second grammar structure corresponding to the target page content file;
a second determination module to determine a redundancy selector for the target style file based on the first syntax structure and the second syntax structure;
and the deleting module is used for determining the target pattern corresponding to the redundancy selector and deleting the code corresponding to the target pattern.
9. A redundant code removal apparatus characterized by comprising: memory, a processor and a redundant code removal program stored on the memory and executable on the processor, the redundant code removal program when executed by the processor implementing the steps of the redundant code removal method according to any of claims 1 to 7.
10. A computer-readable storage medium, characterized in that a redundant code removal program is stored thereon, which when executed by a processor implements the steps of the redundant code removal method according to any one of claims 1 to 7.
CN202010262738.0A 2020-04-03 2020-04-03 Redundant code removing method, device, equipment and computer readable storage medium Pending CN111459537A (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN202010262738.0A CN111459537A (en) 2020-04-03 2020-04-03 Redundant code removing method, device, equipment and computer readable storage medium
PCT/CN2021/083624 WO2021197273A1 (en) 2020-04-03 2021-03-29 Redundant code removing method, apparatus and device, and computer readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010262738.0A CN111459537A (en) 2020-04-03 2020-04-03 Redundant code removing method, device, equipment and computer readable storage medium

Publications (1)

Publication Number Publication Date
CN111459537A true CN111459537A (en) 2020-07-28

Family

ID=71683629

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010262738.0A Pending CN111459537A (en) 2020-04-03 2020-04-03 Redundant code removing method, device, equipment and computer readable storage medium

Country Status (2)

Country Link
CN (1) CN111459537A (en)
WO (1) WO2021197273A1 (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2021197273A1 (en) * 2020-04-03 2021-10-07 深圳前海微众银行股份有限公司 Redundant code removing method, apparatus and device, and computer readable storage medium

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115576603B (en) * 2022-11-23 2023-03-10 云账户技术(天津)有限公司 Method and device for acquiring variable values in code segment
CN117170734B (en) * 2023-11-03 2023-12-29 成都数智创新精益科技有限公司 Method for limiting style scope

Family Cites Families (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20130159839A1 (en) * 2011-12-14 2013-06-20 Microsoft Corporation Semantic compression of cascading style sheets
CN105205080B (en) * 2014-06-26 2019-08-20 阿里巴巴集团控股有限公司 Redundant file method for cleaning, device and system
US10380009B2 (en) * 2015-02-27 2019-08-13 Walmart Apollo, Llc Code usage map
CN109976991A (en) * 2017-12-27 2019-07-05 北京奇虎科技有限公司 A kind for the treatment of method and apparatus of program code
CN110688118B (en) * 2019-10-28 2023-05-05 郑州阿帕斯科技有限公司 Webpage optimization method and device
CN111459537A (en) * 2020-04-03 2020-07-28 深圳前海微众银行股份有限公司 Redundant code removing method, device, equipment and computer readable storage medium

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2021197273A1 (en) * 2020-04-03 2021-10-07 深圳前海微众银行股份有限公司 Redundant code removing method, apparatus and device, and computer readable storage medium

Also Published As

Publication number Publication date
WO2021197273A1 (en) 2021-10-07

Similar Documents

Publication Publication Date Title
US8286132B2 (en) Comparing and merging structured documents syntactically and semantically
US7506324B2 (en) Enhanced compiled representation of transformation formats
US8082144B1 (en) Tax calculation explanation generator
US8032822B1 (en) Method and system for explaining dependencies on a document
CN107402746B (en) Method and device for automatically generating code file
CN111459537A (en) Redundant code removing method, device, equipment and computer readable storage medium
US20030110472A1 (en) Method and system for generating program source code of a computer application from an information model
CN109522018B (en) Page processing method and device and storage medium
Schiavone et al. An extensible environment for guideline-based accessibility evaluation of dynamic Web applications
US20080313619A1 (en) Method and apparatus for a configurable java server pages processing framework
CN109144567B (en) Cross-platform webpage rendering method and device, server and storage medium
CN108762743B (en) Data table operation code generation method and device
US10572278B2 (en) Smart controls for user interface design and implementation
US20020035580A1 (en) Computer readable medium containing HTML document generation program
CN111045678A (en) Method, device and equipment for executing dynamic code on page and storage medium
US7505988B2 (en) XML validation processing
US20090083300A1 (en) Document processing device and document processing method
CN108446136B (en) Element code extraction method and system
CN110688118B (en) Webpage optimization method and device
US9275023B2 (en) Methods for further adapting XSL to HTML document transformations and devices thereof
US20080005662A1 (en) Server Device and Name Space Issuing Method
US20080005085A1 (en) Server Device and Search Method
Le Zou et al. On synchronizing with web service evolution
CN114528218A (en) Test program generation method, test program generation device, storage medium, and electronic device
Ping et al. Refactoring web sites to the controller-centric architecture

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination