CN111240684B - Cutting method and device of JS codes, medium and electronic equipment - Google Patents

Cutting method and device of JS codes, medium and electronic equipment Download PDF

Info

Publication number
CN111240684B
CN111240684B CN202010006693.0A CN202010006693A CN111240684B CN 111240684 B CN111240684 B CN 111240684B CN 202010006693 A CN202010006693 A CN 202010006693A CN 111240684 B CN111240684 B CN 111240684B
Authority
CN
China
Prior art keywords
cutting
code
target
conversion function
syntax tree
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.)
Active
Application number
CN202010006693.0A
Other languages
Chinese (zh)
Other versions
CN111240684A (en
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.)
Beijing ByteDance Network Technology Co Ltd
Original Assignee
Beijing ByteDance Network Technology 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 Beijing ByteDance Network Technology Co Ltd filed Critical Beijing ByteDance Network Technology Co Ltd
Priority to CN202010006693.0A priority Critical patent/CN111240684B/en
Publication of CN111240684A publication Critical patent/CN111240684A/en
Application granted granted Critical
Publication of CN111240684B publication Critical patent/CN111240684B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • 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/44521Dynamic linking or loading; Link editing at or after load time, e.g. Java class loading
    • G06F9/44526Plug-ins; Add-ons
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)

Abstract

The invention provides a cutting method and device of JS codes, a medium and electronic equipment, wherein the cutting method of the JS codes comprises the following steps: calling a custom conversion function in a loader of a packer; analyzing an abstract syntax tree of the file in a custom conversion function to obtain cutting dependency information for cutting the JS code, and calling the customized conversion function; and converting the abstract syntax tree of the JS code according to the cutting dependency information and the first cutting target in a customized conversion function to obtain a first cut JS code which accords with the first cutting target. According to the JS code customized cutting method and the JS code customized cutting system, the abstract syntax tree of the JS code is converted according to the cutting dependency information and the cutting target in the customized conversion function, the cut JS code is obtained, and the cut JS code can meet the cutting requirement of a current user, so that the JS code customized cutting is achieved.

Description

Cutting method and device of JS code, medium and electronic equipment
Technical Field
The invention relates to the technical field of computers, in particular to a cutting method, a cutting device, a cutting medium and electronic equipment for JS codes.
Background
JavaScript is an interpreted footstep language that is used primarily for web application programming. Code for implementing a web application is generally composed of three parts, HTML (Hyper Text Mark-up Language), CSS (Cascading Style Sheets), and JS. HTML codes realize the structure of the webpage, CSS codes realize the style of the webpage, and JS codes realize the interaction of the webpage. When a user accesses a webpage, the browser requests a corresponding resource, such as a JS code, and then parses and presents the resource to the user. If the request resource is larger, the request time is longer, the time for the user to see the white screen is longer, and the user experience is poorer. Therefore, in the development of JS, developers need to adopt various techniques to reduce the volume of JS codes, such as code obfuscation, code compression, code clipping, and the like.
In modern JS development, webpack is generally adopted to package codes. Webpack provides a tree shaking function to remove the JS code that is not referenced, i.e., dead code. However, this function has a precondition that the ES2015 module syntax must be used, and codes using other module syntaxes, such as Commonjs, cannot use the treeing function.
In a standard development process, developed code needs to run in a development environment, a test environment and a production environment in sequence. The different execution environments have different requirements for the code. In the development environment, some interface simulation or type detection code is included for ease of development. In a test environment, some debugging and detailed log printing code is included to facilitate locating problems. In a production environment, in order to reduce the code volume as much as possible, only the service function code should be included, and other auxiliary code, such as debugging code, should be removed.
In order to meet different requirements of different operating environments on codes, a corresponding set of codes can be written for each operating environment, but the processing method is low in writing efficiency, wastes a large amount of manpower and material resources, and improves development cost.
Therefore, in long-term research and development, the inventor has conducted a great deal of research on existing JS code processing methods under different operating environments, and proposes a JS code clipping method to solve one of the above technical problems.
Disclosure of Invention
The invention aims to provide a cutting method, a cutting device, a cutting medium and electronic equipment of JS codes, which can solve at least one technical problem mentioned above. The specific scheme is as follows:
according to the specific implementation manner of the invention, in a first aspect, the invention provides a cutting method of a JS code, which comprises the following steps:
calling a custom conversion function in a loader of a packer;
analyzing an abstract syntax tree of the file in the custom conversion function to obtain cutting dependency information for cutting the JS code, and calling a customized conversion function;
and converting the abstract syntax tree of the JS codes in the customized conversion function according to the cutting dependency information and the first cutting target to obtain a first cut JS code conforming to the first cutting target.
According to a second aspect of the present invention, there is provided a JS code cutting device including:
the user-defined conversion function calling unit is used for calling a user-defined conversion function in a loader of the packer;
the analysis unit is used for analyzing the abstract syntax tree of the file in the custom conversion function called by the custom conversion function calling unit to obtain cutting dependency information for cutting the JS codes;
the customized conversion function calling unit is used for calling the customized conversion function;
and the conversion unit is used for calling the customized conversion function calling unit according to the customized conversion function analyzed by the analysis unit, the cutting dependency information and the first cutting target are right for the abstract syntax tree of the JS codes, and the first cut-back JS codes conforming to the first cutting target are obtained.
According to a third aspect thereof, the present invention provides a computer-readable storage medium having stored thereon a computer program which, when executed by a processor, implements the method for clipping JS code as described in any one of the above.
According to a fourth aspect of the present invention, there is provided an electronic apparatus including: one or more processors; storage means for storing one or more programs that, when executed by the one or more processors, cause the one or more processors to implement the method for clipping JS code as described in any of the above.
Compared with the prior art, the scheme of the embodiment of the invention at least has the following beneficial effects: the JS code after cutting can meet the cutting requirement of a current user, and accordingly customized cutting of the JS code is achieved.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and together with the description, serve to explain the principles of the invention. It is obvious that the drawings in the following description are only some embodiments of the invention, and that for a person skilled in the art, other drawings can be derived from them without inventive effort. In the drawings:
FIG. 1 is a flow chart of a method for cutting JS codes, according to an embodiment of the invention;
FIG. 2 is a schematic diagram showing a clipping device structure of JS codes according to an embodiment of the invention;
fig. 3 shows a schematic diagram of an electronic device connection structure according to an embodiment of the invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention clearer, the present invention will be described in further detail with reference to the accompanying drawings, and it is apparent that the described embodiments are only a part of the embodiments of the present invention, not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The terminology used in the embodiments of the invention is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention. As used in the description of the invention and the appended claims, the singular forms "a", "an", and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise, and "the plural" typically includes at least two.
It should be understood that the term "and/or" as used herein is merely a relationship that describes an associated object, meaning that three relationships may exist, e.g., a and/or B, may represent: a exists alone, A and B exist simultaneously, and B exists alone. In addition, the character "/" herein generally indicates that the former and latter related objects are in an "or" relationship.
It should be understood that while the terms first, second, third, etc. may be used in embodiments of the present invention to describe … …, these … … should not be limited to these terms. These terms are used only to distinguish … …. For example, a first … … may also be referred to as a second … …, and similarly, a second … … may also be referred to as a first … …, without departing from the scope of embodiments of the present invention.
The words "if", as used herein, may be interpreted as "at … …" or "at … …" or "in response to a determination" or "in response to a detection", depending on the context. Similarly, the phrases "if determined" or "if detected (a stated condition or event)" may be interpreted as "when determined" or "in response to a determination" or "when detected (a stated condition or event)" or "in response to a detection (a stated condition or event)", depending on the context.
It is also noted that the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that an article or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such article or apparatus. Without further limitation, an element defined by the phrase "comprising a … …" does not exclude the presence of another like element in a commodity or device comprising the element.
Alternative embodiments of the present invention are described in detail below with reference to the accompanying drawings.
Example 1
As shown in fig. 1, according to a specific implementation manner of an embodiment of the present disclosure, in a first aspect, an embodiment of the present disclosure provides a method for clipping a JS code, which specifically includes the following method steps:
s102: the custom conversion function is called in the loader of the wrapper.
In practical applications, the loader may be a ts-loader. TS-load is a loader to process TS (TypeScript) files. Since TS is a superset of JS, TS-loader can also be used to load JS files. the ts-loader has a get Custom transforms option to set the Custom transfer function. The code file is converted by the custom conversion function before being processed by the ts-loader.
In addition, in addition to the setting of the corresponding loader for the JS module and the setting of the corresponding loader for the TS module, corresponding loaders may be set for other modules, and the types of modules that can be loaded by the loaders are not particularly limited herein.
Optionally, before executing S102, invoking the custom conversion function in the loader of the wrapper, the method further includes the following steps:
and configuring a cutting plug-in and setting a loader in the cutting plug-in.
In practical application, configuring the cutting plug-in includes the following steps:
writing a class containing an application method, wherein a constructor corresponding to the class of the application method comprises at least one preset parameter, and a value corresponding to the preset parameter is a customized conversion function for cutting the JS code.
In practical applications, the module packager may use a Webpack module packager. Webpack is a static module wrapper for modern JS applications. When Webpack processes an application, it recursively builds a dependency graph for each module that the application needs, and then packages the modules into one or more packages. The entry file indicates from which file Webpack starts building the module dependency graph. Actually, webpack can only understand JS files and JSON files. When processing other files, such as TS files and CSS files, a loader needs to be used. The loader can convert all types of files into effective modules that can be processed by Webpack, so that the files can also be packaged. The plug-in is an important component of the Webpack ecosystem, and provides a way for community users to directly touch the compiling process of the Webpack. The plug-in can hook in all critical events that are triggered in each compilation process. At each step of compilation, the plug-in has full access to the compiled object and, if appropriate, the current compiled object.
Because modern JS application programs basically use Webpack for packaging processing, a Webpack plug-in is adopted to realize the code cutting function. A Webpack plugin is a JS object with application methods. The application method can be called by the Webpack compiler, and the application method can access the life cycle of the whole compiling process.
Under different application scenarios, other module packagers besides the Webpack module packager can also be used, which are not described herein again.
In practical application, the configuration process of the cutting plug-in further comprises the following steps:
acquiring an entry file in the cutting plug-in; and marking the entry file as an analysis initial position, and analyzing the code file to be analyzed to obtain class name information and/or function name information meeting preset conditions.
When cutting JS code, it is necessary to know which classes or functions have been used, and thus cut out those functions or classes that have not been used. These JS code clipping-related code clipping information can be obtained by analyzing AST (abstract syntax tree) of the code: for example, used class information, used function information, unused class information, unused function information.
In practical application, the entry file information is firstly obtained from the compiled object, then the entry file and the file dependent on the entry file are analyzed to obtain the abstract syntax tree of the code file, and finally the abstract syntax tree is analyzed to obtain the used class and function information.
Since the code and cropping requirements for each project are different, the specific cropping logic is exposed to the user for completion. In order to reduce the workload of the user, the general part logic of the custom conversion function is automatically completed. The special part of the custom conversion function is logically abstracted into the custom conversion function and is completed by a user.
In practical application, the step of setting the loader in the cutting plug-in comprises the following steps:
setting a corresponding loader for the JS module in the cutting plug-in; and/or the presence of a gas in the gas,
and setting a corresponding loader for the TS module of the superset of the JS in the cutting plug-in.
Since all files need to be processed by the loader before being packaged by Webpack, clipping logic can be injected by the loader.
In practical applications, the loader may be a ts-loader. TS-load is a loader to process TS (TypeScript) files. Since TS is a superset of JS, TS-loader can also be used to load JS files. the ts-loader has a get Custom transforms option to set the Custom transfer function. The code file is converted by the custom conversion function before being processed by the ts-loader.
In addition, in addition to the setting of the corresponding loader for the JS module and the setting of the corresponding loader for the TS module, corresponding loaders may be set for other modules, and the types of modules that can be loaded by the loaders are not particularly limited herein.
In practical application, a processing function is registered in a normal modular loader hook, and the loader configuration of a module is checked and reset in the processing function. If the loader configuration of the module does not have ts-loader, adding the ts-loader into the configuration, and setting the get Custom transformations option as a Custom conversion function; if ts-loader exists in the loader configuration of the module, the get Custom transforms option is set as the Custom transform function.
S104: and analyzing the abstract syntax tree of the file in the custom conversion function to obtain cutting dependency information for cutting the JS code, and calling the customized conversion function.
In this step, the clipping dependent information may be used class name information or used function name information.
Optionally, after executing S104 to obtain clipping dependency information for clipping the JS code, the method further includes the following steps:
reading cutting dependency information; wherein, the first and the second end of the pipe are connected with each other,
the clipping dependency information includes at least one of:
used class name information, used function name information.
In practical applications, the process of calling the customized transformation function is as follows:
firstly, a custom conversion function is compiled, the signature of the function is (ctx: ts. Transformational context) = > ts. Transformator < ts. Sourcefile >, then, the custom conversion function is called in the custom conversion function, and the obtained used class information and function information are transmitted.
The customized transfer function is implemented by the user himself.
The function signature is (ctx: ts. Transformation Context, info: usedInfo) = > ts. Transformer < ts. Sourcefile >, wherein UsedInfo is an interface type and contains used class names and function names. Optionally, after the step of entering the class name information and/or function name information meeting the preset condition is performed, the method further includes the following steps:
and traversing the abstract syntax tree nodes of the JS source codes in the customized conversion function according to the class name information and/or function name information meeting the preset conditions, and generating new abstract syntax tree nodes with redundant codes removed.
In practical applications, the redundancy code may be: unused classes or functions, code of a special format. Besides removing redundant codes, the codes in special formats can be rewritten to obtain the codes conforming to the current operating environment.
In practical application, firstly, a customized conversion function is written, and then the abstract syntax tree nodes of the code are traversed in the customized conversion function through a TS (transport stream) native interface, such as a ts.visit Node; and finally, calling a native interface of the TS during traversal, such as TS. When regenerating abstract syntax tree nodes, unused classes or functions are removed, special codes are removed, or special codes are rewritten as required.
In practical application, a user needs to use corresponding clipping plug-ins in Webpack configurations under different operating environments as required.
In practical application, the JS code after cutting is obtained by converting the abstract syntax tree of the JS code according to the cutting dependency information and the cutting target in the customized conversion function, and the JS code after cutting can meet the cutting requirement of the current user, so that the JS code can be cut in a customized manner.
S106: and converting the abstract syntax tree of the JS code according to the cutting dependency information and the first cutting target in a customized conversion function to obtain a first cut JS code which accords with the first cutting target.
Optionally, before the abstract syntax tree of the JS code is converted according to the clipping dependency information and the first clipping target in the customized conversion function to obtain the first post-clipping JS code conforming to the first clipping target, the method further includes the following steps:
a first crop target is read, wherein the first crop target is matched with the first post-crop JS code.
It should be noted that the first cropping target is set according to the cropping requirement of the specific user, and is used for realizing the specific cropping effect of the JS code.
In practical applications, the cropping target matches with the cropping requirements, and the cropping requirements vary from item to item, and belong to the customization part, and the user generally completes the configuration process of the cropping requirements and the cropping target.
In practical applications, the cropping requirements and the cropping targets are often different. Different cutting targets can be configured according to different cutting requirements of different users to achieve different code cutting effects, which is not described in detail herein.
Optionally, before reading the first cropping target, the method further includes the following steps:
and configuring the cutting target by rewriting the first abstract syntax tree corresponding to the source code to obtain a first cutting target.
In practical application, the cutting target is configured by rewriting the first abstract syntax tree corresponding to the source code, so that the first cutting target meeting the cutting requirement of a user is obtained, and the first cutting target can realize the expected code cutting effect of the user.
Optionally, after the abstract syntax tree of the JS code is converted according to the clipping dependency information and the first clipping object in the customized conversion function, and the first clipped JS code that meets the first clipping object is obtained, the method further includes the following steps:
and configuring the cutting target by rewriting a second abstract syntax tree corresponding to the source code to obtain a second cutting target, and converting the abstract syntax tree of the JS code according to the cutting dependency information and the second cutting target in a customized conversion function to obtain a second cut JS code conforming to the second cutting target, wherein the second cutting target is matched with the second cut JS code.
In practical application, the cutting target is configured by rewriting the second abstract syntax tree corresponding to the source code, so that the second cutting target meeting the cutting requirement of the user is obtained, and the second cutting target can realize the expected code cutting effect of the user.
It should be noted that, in the JS code clipping method provided in the embodiment of the present invention, the first clipping target and the second clipping target are different, and a code clipping effect that can be achieved by the first clipping target and a code clipping effect that can be achieved by the second clipping target are also different, which is not described herein again. In this way, the JS code after cutting is obtained by converting the abstract syntax tree of the JS code according to the cutting dependency information and the cutting target in the customized conversion function, and the JS code after cutting can meet the cutting requirement of the current user, so that the JS code is cut in a customized manner.
Under a specific application scene, the JS code clipping method provided by the embodiment of the invention specifically includes the following steps:
firstly, a cutting plug-in is introduced into a configuration file, and if the customized conversion function is in other files, the corresponding customized conversion function also needs to be introduced. The clipping plug-in is then instantiated and passed into the customized transfer function. And finally, packaging by using Webpack, wherein the generated code after packaging is the cut JS code.
Through the JS code cutting method provided by the embodiment of the disclosure, customized cutting can be achieved, and the cutting is finished: removing unused classes or functions and removing special codes, thereby being capable of: the special code is rewritten.
In addition, the JS code cutting method provided by the embodiment of the disclosure at least supports two languages of JS and TS, is not restricted by module grammar, and can well meet different format requirements on the same code under different operation environments.
According to the cutting method of the JS codes, the abstract syntax tree of the JS codes is converted according to the cutting dependency information and the cutting target in the customized conversion function, so that the cut JS codes are obtained, and the cut JS codes can meet the cutting requirements of a current user, and accordingly the customized cutting of the JS codes is achieved.
Example 2
The embodiment is similar to embodiment 1 in the explanation of the method steps for implementing the method steps as described in embodiment 1 based on the same names and meanings, and has the same technical effects as embodiment 1, and thus the description thereof is omitted. Referring to fig. 2, according to a specific embodiment of the present disclosure, in a second aspect, an embodiment of the present disclosure provides a cutting device for JS codes, which includes a custom conversion function calling unit 202, an analyzing unit 204, a customized conversion function calling unit 206, and a converting unit 208, specifically as follows:
a custom conversion function calling unit 202, configured to call a custom conversion function in a loader of the wrapper;
an analyzing unit 204, configured to analyze the abstract syntax tree of the file in the custom conversion function called by the custom conversion function calling unit 202, to obtain cutting dependency information for cutting the JS code;
a customized conversion function calling unit 206 for calling a customized conversion function;
a converting unit 208, configured to convert, in the customized conversion function called by the customized conversion function calling unit 206, the abstract syntax tree of the JS code according to the cutting dependency information and the first cutting target analyzed by the analyzing unit 204, so as to obtain a first cut JS code that meets the first cutting target.
Optionally, the apparatus further comprises:
a reading unit (not shown in fig. 2) configured to read the clipping dependent information after the parsing unit 204 obtains the clipping dependent information used for clipping the JS code; the cutting dependency information read by the reading unit at least includes one of the following items:
used class name information, used function name information.
Optionally, the apparatus further comprises:
a configuration unit (not shown in fig. 2) for configuring the clipping plug-in and setting the loader in the clipping plug-in before the custom conversion function calling unit 202 calls the custom conversion function in the loader of the wrapper.
Optionally, the configuration unit is specifically configured to:
setting a corresponding loader for the JS module in the cutting plug-in; and/or the presence of a gas in the gas,
and setting a corresponding loader for the TS module of the superset of the JS in the cutting plug-in.
Optionally, the reading unit is further configured to:
the conversion unit 208 converts the abstract syntax tree of the JS code according to the clipping dependency information and the first clipping target parsed by the parsing unit 204 in the customized conversion function called by the customized conversion function calling unit 206, and reads the first clipping target before obtaining the first post-clipping JS code conforming to the first clipping target, where the first clipping target read by the reading unit is matched with the first post-clipping JS code.
Optionally, the configuration unit is further configured to:
before the reading unit reads the first cutting target, the cutting target is configured by rewriting the first abstract syntax tree corresponding to the source code, and the first cutting target is obtained.
Optionally, the configuration unit is further configured to:
after the conversion unit 208 converts the abstract syntax tree of the JS code according to the cutting dependency information and the first cutting target analyzed by the analysis unit 204 in the customized conversion function called by the customized conversion function calling unit 206 to obtain the first cut JS code conforming to the first cutting target, the conversion unit configures the cutting target by rewriting the second abstract syntax tree corresponding to the source code to obtain a second cutting target, wherein the second cutting target is matched with the second cut JS code;
the conversion unit 208 is further configured to:
and converting the abstract syntax tree of the JS code according to the cutting dependency information and the second cutting target analyzed by the analyzing unit 204 in the customized conversion function called by the customized conversion function calling unit 206 to obtain a second cut JS code conforming to the second cutting target, wherein the second cutting target is matched with the second cut JS code.
According to the JS code cutting device provided by the embodiment of the disclosure, the conversion unit converts the abstract syntax tree of the JS code according to the cutting dependency information and the cutting target in the customized conversion function to obtain the cut JS code, and the cut JS code can meet the cutting requirement of the current user, so that the customized cutting of the JS code is realized.
Example 3
As shown in fig. 3, the present embodiment provides an electronic device, which is used in a JS code cutting method, where the electronic device includes: at least one processor; and a memory communicatively coupled to the at least one processor; wherein the content of the first and second substances,
the memory stores instructions executable by the one processor to cause the at least one processor to: the abstract syntax tree of the JS codes is converted according to the cutting dependence information and the cutting target in the customized conversion function, so that the cut JS codes are obtained, and the cut JS codes can meet the cutting requirement of a current user, and accordingly customized cutting of the JS codes is achieved.
Example 4
The embodiment of the disclosure provides a non-volatile computer storage medium, where a computer-executable instruction is stored, and the computer-executable instruction can execute the cutting method of the JS code in any of the above method embodiments.
Example 5
Referring now to FIG. 3, shown is a schematic diagram of an electronic device suitable for use in implementing embodiments of the present disclosure. The terminal device in the embodiments of the present disclosure may include, but is not limited to, a mobile terminal such as a mobile phone, a notebook computer, a digital broadcast receiver, a PDA (personal digital assistant), a PAD (tablet computer), a PMP (portable multimedia player), a vehicle terminal (e.g., a car navigation terminal), and the like, and a fixed terminal such as a digital TV, a desktop computer, and the like. The electronic device shown in fig. 3 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present disclosure.
As shown in fig. 3, the electronic device may include a processing device (e.g., a central processing unit, a graphics processor, etc.) 301 that may perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM) 302 or a program loaded from a storage device 308 into a Random Access Memory (RAM) 303. In the RAM 303, various programs and data necessary for the operation of the electronic apparatus are also stored. The processing device 301, the ROM 302, and the RAM 303 are connected to each other via a bus 304. An input/output (I/O) interface 305 is also connected to bus 304.
Generally, the following devices may be connected to the I/O interface 305: input devices 306 including, for example, a touch screen, touch pad, keyboard, mouse, camera, microphone, accelerometer, gyroscope, etc.; an output device 307 including, for example, a Liquid Crystal Display (LCD), a speaker, a vibrator, and the like; storage devices 308 including, for example, magnetic tape, hard disk, etc.; and a communication device 309. The communication means 309 may allow the electronic device to communicate wirelessly or by wire with other devices to exchange data. While fig. 3 illustrates an electronic device having various means, it is to be understood that not all illustrated means are required to be implemented or provided. More or fewer devices may be alternatively implemented or provided.
In particular, according to an embodiment of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication means 309, or installed from the storage means 308, or installed from the ROM 302. The computer program, when executed by the processing device 301, performs the above-described functions defined in the methods of embodiments of the present disclosure.
It should be noted that the computer readable medium in the present disclosure can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present disclosure, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In contrast, in the present disclosure, a computer readable signal medium may comprise a propagated data signal with computer readable program code embodied therein, either in baseband or as part of a carrier wave. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: electrical wires, optical cables, RF (radio frequency), etc., or any suitable combination of the foregoing.
The computer readable medium may be embodied in the electronic device; or may exist separately without being assembled into the electronic device.
The computer readable medium carries one or more programs which, when executed by the electronic device, cause the electronic device to: the JS code after cutting is obtained by converting the abstract syntax tree of the JS code according to the cutting dependency information and the cutting target in the customized conversion function, and the JS code after cutting can meet the cutting requirement of the current user, so that customized cutting of the JS code is realized.
Alternatively, the computer readable medium carries one or more programs which, when executed by the electronic device, cause the electronic device to: the JS code after cutting is obtained by converting the abstract syntax tree of the JS code according to the cutting dependency information and the cutting target in the customized conversion function, and the JS code after cutting can meet the cutting requirement of the current user, so that customized cutting of the JS code is realized.
Computer program code for carrying out operations for aspects of the present disclosure may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, smalltalk, C + +, and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units described in the embodiments of the present disclosure may be implemented by software or hardware. Where the name of an element does not in some cases constitute a limitation on the element itself.

Claims (9)

1. A cutting method of JS codes is characterized by comprising the following steps:
calling a custom conversion function in a loader of a packer;
analyzing an abstract syntax tree of the file in the custom conversion function to obtain cutting dependency information for cutting the JS code, and calling a customized conversion function;
converting the abstract syntax tree of the JS codes according to the cutting dependency information and a first cutting target in the customized conversion function to obtain a first cut JS code conforming to the first cutting target;
wherein, according to tailor dependence information and first tailor the target right in the customization transfer function abstract syntax tree of JS code is converted, obtain accord with after the first tailor JS code of first tailor target, still include:
through rewriting the second abstract syntax tree that the source code corresponds, the target is cut out to the configuration, obtains the second target of cutting out follow among the customization transfer function cut out dependency information and second and cut out the target right the abstract syntax tree of JS code is converted, obtains to accord with the second of second target of cutting out JS code after the JS code is cut out, wherein, the second target of cutting out with the second is cut out JS code matching after the JS code.
2. The method of claim 1, wherein after obtaining the clipping dependency information for clipping the JS code, the method further comprises:
reading the clipping dependent information; wherein, the first and the second end of the pipe are connected with each other,
the clipping dependent information includes at least one of:
used class name information, used function name information.
3. The method of claim 1, wherein prior to said invoking a custom transfer function in a loader of a wrapper, the method further comprises:
and configuring a cutting plug-in and setting the loader in the cutting plug-in.
4. The method of claim 3, wherein the setting the loader in the clipping plug-in comprises:
setting a corresponding loader for the JS module in the cutting plug-in; and/or the presence of a gas in the gas,
and setting a corresponding loader for the super set TS module of the JS in the cutting plug-in unit.
5. The method of claim 1, wherein before said translating, in said customized translation function, said abstract syntax tree of said JS code according to said clipping dependency information and a first clipping target, resulting in a first post-clipping JS code that conforms to said first clipping target, said method further comprises:
reading the first cropping target, wherein the first cropping target is matched with the first post-cropping JS code.
6. The method of claim 5, wherein prior to said reading said first crop target, said method further comprises:
and configuring the cutting target by rewriting the first abstract syntax tree corresponding to the source code to obtain the first cutting target.
7. A cutting device for JS codes is characterized by comprising:
the user-defined conversion function calling unit is used for calling a user-defined conversion function in a loader of the packer;
the analysis unit is used for analyzing the abstract syntax tree of the file in the custom conversion function called by the custom conversion function calling unit to obtain cutting dependency information for cutting the JS codes;
the customized conversion function calling unit is used for calling the customized conversion function;
the conversion unit is used for converting the abstract syntax tree of the JS codes according to the cutting dependency information and the first cutting target analyzed by the analysis unit in the customized conversion function called by the customized conversion function calling unit so as to obtain a first cut JS code conforming to the first cutting target;
wherein the apparatus further comprises: the configuration unit is used for converting the abstract syntax tree of the JS codes according to the cutting dependency information and the first cutting target analyzed by the analysis unit in the customized conversion function called by the customized conversion function calling unit by the conversion unit to obtain a first cut JS code conforming to the first cutting target, and then configuring the cutting target by rewriting a second abstract syntax tree corresponding to the source code to obtain a second cutting target;
wherein, the converting unit is still used for the customization transfer function call unit is called among the customization transfer function according to the parsing unit is analytic the cutting dependency information and the second cutting target are right the abstract syntax tree of JS code is converted, obtain conforming to the second cuts the back JS code of second cutting of target, wherein, the second cutting target with the second is cut the back JS code and is matchd.
8. A computer-readable storage medium, on which a computer program is stored, which program, when being executed by a processor, carries out the method according to any one of claims 1 to 6.
9. An electronic device, comprising:
one or more processors;
storage means for storing one or more programs which, when executed by the one or more processors, cause the one or more processors to carry out the method of any one of claims 1 to 6.
CN202010006693.0A 2020-01-03 2020-01-03 Cutting method and device of JS codes, medium and electronic equipment Active CN111240684B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010006693.0A CN111240684B (en) 2020-01-03 2020-01-03 Cutting method and device of JS codes, medium and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010006693.0A CN111240684B (en) 2020-01-03 2020-01-03 Cutting method and device of JS codes, medium and electronic equipment

Publications (2)

Publication Number Publication Date
CN111240684A CN111240684A (en) 2020-06-05
CN111240684B true CN111240684B (en) 2023-04-11

Family

ID=70879728

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010006693.0A Active CN111240684B (en) 2020-01-03 2020-01-03 Cutting method and device of JS codes, medium and electronic equipment

Country Status (1)

Country Link
CN (1) CN111240684B (en)

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112363706A (en) * 2020-11-20 2021-02-12 上海悦易网络信息技术有限公司 Nested combination preprocessing method and equipment
CN112988260B (en) * 2021-01-25 2023-07-04 杭州衣科云科技有限公司 Application cold start optimization method and device, computer equipment and storage medium
CN112860267B (en) * 2021-04-23 2021-07-30 武汉深之度科技有限公司 Kernel cutting method and computing device
CN113741946B (en) * 2021-08-25 2023-06-09 烽火通信科技股份有限公司 Clipping method, device and equipment of public interface function library and readable storage medium
CN114035805A (en) * 2021-11-16 2022-02-11 北京字节跳动网络技术有限公司 Code conversion method, apparatus, medium, and device for pre-compiler

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
GB201507342D0 (en) * 2015-04-29 2015-06-10 Worldpay Uk Ltd Method and system for identification and removal of redundant code
CN106980497A (en) * 2017-02-10 2017-07-25 九次方大数据信息集团有限公司 Webpage and website performance optimization method and device
CN109542460A (en) * 2018-10-15 2019-03-29 深圳点猫科技有限公司 A kind of method and electronic equipment based on access typescript in the vue for educating operating system
CN110109671A (en) * 2019-02-28 2019-08-09 深圳点猫科技有限公司 A kind of webpack label sizes pattern conversion method and device
CN110286917A (en) * 2019-05-21 2019-09-27 深圳壹账通智能科技有限公司 File packing method, device, equipment and storage medium
CN110362312A (en) * 2019-06-27 2019-10-22 绿漫科技有限公司 A kind of syntax conversion compiling system and method suitable for a variety of frames

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9405555B2 (en) * 2008-05-23 2016-08-02 Microsoft Technology Licensing, Llc Automated code splitting and pre-fetching for improving responsiveness of browser-based applications
US9043764B2 (en) * 2011-03-09 2015-05-26 International Business Machines Corporation Cross-platform compiler for data transforms
JP2017151903A (en) * 2016-02-26 2017-08-31 富士通株式会社 Compilation device, compilation method and compilation program
US11120021B2 (en) * 2017-01-11 2021-09-14 Facebook, Inc. Systems and methods for optimizing queries
US11036522B2 (en) * 2017-12-19 2021-06-15 Citrix Systems, Inc. Remote component loader

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
GB201507342D0 (en) * 2015-04-29 2015-06-10 Worldpay Uk Ltd Method and system for identification and removal of redundant code
CN106980497A (en) * 2017-02-10 2017-07-25 九次方大数据信息集团有限公司 Webpage and website performance optimization method and device
CN109542460A (en) * 2018-10-15 2019-03-29 深圳点猫科技有限公司 A kind of method and electronic equipment based on access typescript in the vue for educating operating system
CN110109671A (en) * 2019-02-28 2019-08-09 深圳点猫科技有限公司 A kind of webpack label sizes pattern conversion method and device
CN110286917A (en) * 2019-05-21 2019-09-27 深圳壹账通智能科技有限公司 File packing method, device, equipment and storage medium
CN110362312A (en) * 2019-06-27 2019-10-22 绿漫科技有限公司 A kind of syntax conversion compiling system and method suitable for a variety of frames

Non-Patent Citations (4)

* Cited by examiner, † Cited by third party
Title
Daniel Wolf.Webpack plugin: How to dynamically add a loader to a module?.《https://stackoverflow.com/questions/48992319/webpack-plugin-how-to-dynamically-add-a-loader-to-a-module》.2018,1. *
newraina.手把手教写 TypeScript Transformer Plugin.《https://zhuanlan.zhihu.com/p/30360931/》.2017,1-2. *
详解Webpack的loader和plugin编写.《https://cloud.tencent.com/developer/article/1558870》.2019,1-3. *
赵济华,陈树清,张兆庆,刘宽名.面向流水线机的表达式优化.计算机学报.1981,(03),全文. *

Also Published As

Publication number Publication date
CN111240684A (en) 2020-06-05

Similar Documents

Publication Publication Date Title
CN111240684B (en) Cutting method and device of JS codes, medium and electronic equipment
CN111680253B (en) Page application data packet generation method and device, computer equipment and storage medium
CN105718289B (en) Component relation establishing method and equipment
KR20180122019A (en) Tools and methods for real-time data flow programming languages
CN111740948B (en) Data packet issuing method, dynamic updating method, device, equipment and medium
CN113126990B (en) Page development method, device, equipment and storage medium
CN112631590B (en) Component library generation method, device, electronic equipment and computer readable medium
CN112559026B (en) API (application program interface) -based native capability development method, device and storage medium
CN110895471A (en) Installation package generation method, device, medium and electronic equipment
CN114077430A (en) Interface generation method and device, electronic equipment and storage medium
CN112527386B (en) Application program issuing method and device
CN110489162B (en) Method, device, medium and equipment for simplifying installation package SO (storage and retrieval) file
CN110389899B (en) Method and device for detecting API data type of JS program, medium and equipment
KR101117165B1 (en) Web platform unit for mobile terminal connectioned web-application program in heterogeneous operating system
CN114217789A (en) Function component expansion method, device, equipment, storage medium and program product
CN113094138A (en) Interface display method and device, electronic equipment and storage medium
CN110489180B (en) Buried point reporting method, device, medium and electronic equipment
CN110442419B (en) Interface layout method and device for Android application
CN111913741A (en) Object interception method, device, medium and electronic equipment
CN116991434A (en) Packet reorganization method, system and storage medium for android APP
CN115982491A (en) Page updating method and device, electronic equipment and computer readable storage medium
CN113568678B (en) Method and device for dynamically loading resources and electronic equipment
CN109614104B (en) Method and device for adding new semantic structure based on template preprocessing and electronic equipment
CN113778451A (en) File loading method and device, computer system and computer readable storage medium
CN111240693A (en) Real-time data processing method, device, equipment and storage medium

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
GR01 Patent grant
GR01 Patent grant