Code conversion method and device, electronic equipment and storage medium
By using a large language model to perform structured parsing and dependency analysis on Vue2 components, business logic units are constructed and converted into Vue3 composable APIs. This solves the problem of long code conversion cycles and high costs during the Vue.js framework upgrade process, and achieves efficient and accurate automated code conversion.
Patent Information
- Application Number
- CN202511024927.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-24
- Publication Date
- 2025-11-11
AI Technical Summary
During the upgrade process of the Vue.js framework from 2.x to 3.x, the code conversion of enterprise-level single-page applications faces problems such as long cycle, high cost and easy introduction of errors. This is mainly due to differences in refactoring of responsive systems, adjustment of lifecycle hooks and changes in template syntax caused by architectural changes, which rely on manual modification of code line by line.
The large language model is used to perform structured parsing and AST parsing of Vue2 single-file components, identify the dependencies between component configuration items, build business logic units by aggregating sub-properties with the same business purpose, and perform code transformation according to the Vue3 composable API specification. Combined with static code analysis and event verification, the code transformation is fully automated.
It achieves fully automated code conversion from Vue2 to Vue3, improving conversion efficiency, reducing manual intervention, ensuring code quality and compatibility, and achieving an industrial-grade code upgrade standard with zero manual intervention.
Smart Images

Figure CN120929083A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present invention relate to the field of front-end application development technology, and in particular to a method, apparatus, electronic device and storage medium for code conversion. Background Technology
[0002] With the rapid development of front-end technologies, enterprise-level single-page applications (SPAs) face significant code conversion challenges during the upgrade of the Vue.js framework from 2.x to 3.x. While Vue 3 improves the development experience through its composable API (Application Programming Interface) and performance optimizations, its architectural changes result in fundamental differences from Vue 2's optional API, including refactoring of the reactive system, adjustments to lifecycle hooks, and changes to template syntax. Currently, code conversion mainly relies on developers manually modifying code line by line according to the official guidelines. This not only requires rewriting a large amount of logic encapsulation (such as converting Mixins to Composables) but also solving third-party library compatibility issues, easily leading to long conversion cycles, high costs, and the potential for introducing errors. Summary of the Invention
[0003] In view of this, in order to effectively alleviate the technical problems of long code conversion cycle, high cost and easy introduction of errors caused by manual code conversion, the present invention provides a code conversion method, apparatus, electronic device and storage medium.
[0004] In a first aspect, embodiments of the present invention provide a code conversion method, the method comprising:
[0005] Perform structured parsing on Vue2 single-file components to extract script files, template content, and component identifiers;
[0006] Perform AST parsing on the script file to generate an AST structure containing component configuration items;
[0007] The AST structure, template content, and component identifiers are input into the large language model. The large language model analyzes the dependencies between component configuration items and outputs Vue3 single-file components.
[0008] In one possible implementation, structured parsing of Vue2 single-file components includes:
[0009] Use a single-file component parser to perform structured parsing of Vue2 single-file components;
[0010] Perform AST parsing on the script file, including:
[0011] Use a JavaScript code parser to perform AST parsing on the script file.
[0012] In one possible implementation, the large language model analyzes the dependencies between component configuration items and outputs Vue 3 single-file components, including:
[0013] Analyze the AST structure, template content, and component identifiers to identify the sub-attribute items corresponding to each component configuration item;
[0014] Identify the purpose of each sub-attribute item and determine the corresponding business purpose of each sub-attribute item;
[0015] By aggregating all target sub-attribute items with the same business purpose, business logic units are constructed.
[0016] The business logic units are converted into code according to the Vue3 composition API specification, and output as Vue3 single-file components.
[0017] In one possible implementation, component configuration items include the following types: data flow configuration items, computation configuration items, method configuration items, listener configuration items, and lifecycle hook configuration items.
[0018] In one possible implementation, a business logic unit is constructed by aggregating all target sub-attribute items with the same business purpose, including:
[0019] In the method configuration items with the same business purpose, check whether the target sub-attribute item references the first sub-attribute item of the data flow configuration item with different business purpose;
[0020] If a reference to the first sub-attribute is detected, all target sub-attribute items with the same business purpose are aggregated with the first sub-attribute item to construct a business logic unit;
[0021] If no reference to the first sub-attribute is detected, a business logic unit is constructed by aggregating all target sub-attribute items with the same business purpose.
[0022] In one possible implementation, the method further includes the following before outputting the Vue 3 single-file component:
[0023] The large language model performs code event verification on Vue3 single-file components based on Vue2 single-file components, Vue3 single-file components, and business logic units.
[0024] Once the large language model completes code event verification and passes the verification, it outputs a Vue3 single-file component.
[0025] In one possible implementation, code event verification includes at least the following: functional equivalence verification, semantic consistency verification, Vue3 best practice verification, performance impact verification, and compatibility issue verification.
[0026] Secondly, embodiments of the present invention provide a code conversion apparatus, the apparatus comprising:
[0027] The first parsing module is used to perform structured parsing of Vue2 single-file components, extracting script files, template content, and component identifiers;
[0028] The second parsing module is used to perform AST parsing on the script file and generate an AST structure containing component configuration items;
[0029] The code transformation model is used to input the AST structure, template content, and component identifiers into the large language model. The large language model analyzes the dependencies between component configuration items and outputs Vue3 single-file components.
[0030] Thirdly, embodiments of the present invention provide an electronic device, comprising: a processor and a memory, wherein the processor is configured to execute a program for code conversion stored in the memory to implement the above-described code conversion method.
[0031] Fourthly, embodiments of the present invention provide a storage medium, wherein the storage medium stores one or more programs, which can be executed by one or more processors to implement the above-described code conversion method.
[0032] This invention provides a method, apparatus, electronic device, and storage medium for code conversion. The method includes: performing structured parsing on Vue2 single-file components to extract script files, template content, and component identifiers; performing AST parsing on the script files to generate an AST structure containing component configuration items; inputting the AST structure, template content, and component identifiers into a large language model, where the large language model analyzes the dependencies between component configuration items and outputs Vue3 single-file components. This technical solution innovatively integrates the intelligent semantic parsing and code generation capabilities of a large language model with the precise detection mechanism of static code analysis, achieving fully automated code conversion from Vue2 to Vue3. Compared to traditional manual conversion, this solution achieves significant breakthroughs in conversion efficiency, economy, and code quality, ultimately reaching an industrial-grade code upgrade standard with zero human intervention. Attached Figure Description
[0033] Figure 1 A flowchart illustrating an embodiment of a code conversion method provided by this invention;
[0034] Figure 2 A flowchart illustrating an embodiment of another code conversion method provided by this invention;
[0035] Figure 3 A block diagram illustrating an embodiment of a code conversion apparatus provided in this invention;
[0036] Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. Detailed Implementation
[0037] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0038] To facilitate understanding of the embodiments of the present invention, further explanations and descriptions will be provided below with reference to the accompanying drawings and specific embodiments. These embodiments do not constitute a limitation on the embodiments of the present invention.
[0039] This invention provides a method for code conversion, see [link to relevant documentation]. Figure 1 , Figure 1 This is a flowchart illustrating an embodiment of a code conversion method provided by the present invention. Figure 1 The process shown may include the following steps:
[0040] Step 101: Perform structured parsing on Vue2 single-file components to extract script files, template content, and component identifiers;
[0041] In practical applications, the single-file component parser, namely the @vue / compiler-sfc parser, can be used to perform structured parsing of Vue2 single-file components, parsing the template (template content), script (script file), and style (style) blocks in the .vue file, and extracting them into independent strings or objects.
[0042] Template content: Extracted into pure HTML (Hypertext Markup Language) strings, retaining Vue2 directives (such as v-for and v-if).
[0043] Script file: Extracts component configuration items exported by export default, including data flow configuration items (props, data), computed configuration items (computed), method configuration items (methods), listener configuration items (watch), lifecycle hook configuration items, etc.
[0044] Component Identifier: A unique identifier is generated by the file name or the component's name attribute.
[0045] It is important to note that if the script uses a non-JavaScript language (such as TypeScript), it must first be converted to standard JavaScript format.
[0046] Step 102: Perform AST parsing on the script file to generate an AST structure containing component configuration items;
[0047] Specifically, the JavaScript code parser, @babel / parser, is used to parse the script code into an Abstract Syntax Tree (AST) structure. By fully preserving key code structure information such as component configuration items, it provides high-fidelity input data for subsequent large language model processing. This structured preprocessing method effectively eliminates redundant noise in the original code, enabling large language models to make more accurate code transformation decisions based on clear syntax tree node relationships.
[0048] Step 103: Input the AST structure, template content and component identifiers into the large language model. The large language model analyzes the dependencies between component configuration items and outputs Vue3 single-file components.
[0049] In practical applications, the AST structure, template content, and component identifiers can be input into the large language model in the following form:
[0050] {
[0051] “componentAST”: “AST structure”
[0052] "templateContent": Template content
[0053] "componentName": Component identifier
[0054] }
[0055] Based on the analysis of the dependencies between various component configuration items using a large language model, the system identifies explicit dependencies (import / export, props passing) and / or implicit dependencies (state sharing, event communication) to reconstruct the logical structure. This allows the scattered component configuration items to be aggregated into Composables according to business purposes, ultimately achieving a high-fidelity fully automated code conversion and upgrade from Vue2 to Vue3.
[0056] The code conversion method provided in this invention includes: performing structured parsing on Vue2 single-file components to extract script files, template content, and component identifiers; performing AST parsing on the script files to generate an AST structure containing component configuration items; inputting the AST structure, template content, and component identifiers into a large language model, where the large language model analyzes the dependencies between component configuration items and outputs Vue3 single-file components. This technical solution innovatively integrates the intelligent semantic parsing and code generation capabilities of a large language model with the precise detection mechanism of static code analysis, achieving fully automated code conversion from Vue2 to Vue3. Compared to traditional manual conversion, this solution achieves significant breakthroughs in conversion efficiency, economy, and code quality, ultimately reaching an industrial-grade code upgrade standard with zero human intervention.
[0057] like Figure 2 As shown, as an optional implementation, the method described above, step 103, analyzing the dependencies between component configuration items using the large language model and outputting Vue3 single-file components, includes the following steps:
[0058] Step 201: Analyze the AST structure, template content, and component identifiers to identify the sub-attribute items corresponding to each component configuration item;
[0059] Sub-attribute items can be understood as the core reactive attribute configuration of component configuration items. Identifying the sub-attribute items corresponding to each component configuration item is beneficial for subsequent large language model analysis of the dependencies between component configuration items.
[0060] In practical implementation, to ensure that the large language model can accurately identify the sub-properties corresponding to each component configuration item, it is necessary to pre-define the role and tasks of the large language model. The role is defined as: a professional Vue.js code analysis expert, and the task is defined as: analyzing the overall structure of Vue2 components, specifically including 1. identifying the component props definition and type, 2. analyzing the data structure of the data property, 3. listing all computed properties, 4. identifying the method list, 5. analyzing the watch listener configuration, and 6. identifying the use of lifecycle hooks.
[0061] The large language model then fully understands the input based on the role and task settings, obtaining the sub-attribute items corresponding to each component configuration item. In practical applications, the large language model can output the identified sub-attribute items corresponding to each component configuration item in JSON structured data format, as shown below:
[0062] {
[0063] "props":{"propName":"propType"},
[0064] "dataProperties": ["prop1", "prop2"],
[0065] "computedProperties": ["comp1", "comp2"],
[0066] "methods": ["method1", "method2"],
[0067] "watchers": {"watchedProp": "handlerMethod"},
[0068] "lifecycleHooks": ["mounted", "beforeDestroy"]
[0069] The output shows that "prop1" and "prop2" are two sub-properties of the "data" component configuration item, and "method1" and "method2" are two sub-properties of the "methods" component configuration item. Further explanation is not provided here.
[0070] Step 202: Identify the purpose of each sub-attribute item and determine the business purpose corresponding to each sub-attribute item;
[0071] Perform code context analysis on each sub-attribute item to determine its business purpose (such as state management, API calls, code modification, user management, form validation, etc.).
[0072] Step 203: Construct a business logic unit by aggregating all target sub-attribute items with the same business purpose;
[0073] Identify the dependencies between sub-attribute items (e.g., if comp1 depends on prop1, merge them into the same business logic unit). For example, if the business purpose of "prop1", "comp1", "method1", "watchedProp", and "mounted" is state management, then these sub-attribute items will be aggregated as target sub-attribute items to form a business logic unit.
[0074] The specific implementation process of step 203 above can be achieved through steps A1 to A3:
[0075] Step A1: Detect whether the target sub-attribute of the method configuration items with the same business purpose references the first sub-attribute of the data flow configuration items with different business purposes.
[0076] Iterate through the target sub-attributes, checking if they reference the first sub-attribute of other business-purpose data flow configuration items. Continuing the previous example, check "method1" to see if it references sub-attributes of other business-purpose data flow configuration items besides "prop1". If a reference to the first sub-attribute is detected, for example, if "method1" also references "prop2" for form validation, then proceed to step A2; if no reference to the first sub-attribute is detected, for example, if "method1" references "prop1" for the same business purpose, then proceed to step A3.
[0077] Step A2: Aggregate all target sub-attribute items with the same business purpose with the first sub-attribute item to construct a business logic unit;
[0078] Continuing from the previous example, when "method1" also references "prop2" for form validation, it is necessary to aggregate "prop1", "comp1", "method1", "watchedProp", "mounted" and "prop2" to form a business logic unit for state management.
[0079] Step A3: Construct a business logic unit by aggregating all target sub-attribute items with the same business purpose.
[0080] Continuing from the previous example, when "method1" only references "prop1" which has the same business purpose, it is only necessary to aggregate "prop1", "comp1", "method1", "watchedProp", and "mounted" which have the same business purpose to form a business logic unit for state management.
[0081] In practical implementation, to ensure the large language model can accurately group logic, roles and tasks need to be defined in advance. The role is defined as a professional Vue.js architect, specifically responsible for code refactoring and logic organization. The task is defined as: analyzing the business logic of Vue2 components and intelligently grouping related code elements. Specific analysis requirements include: 1. Understanding the business purpose of each sub-attribute; 2. Identifying the business relationships between them (e.g., user management related, form validation related, etc.); 3. Analyzing the dependencies between variable references and method calls; 4. Considering best practices for Vue3's composable API; 5. Generating appropriate composable function names for each group.
[0082] The large language model then fully understands the sub-attribute items obtained in step 201 based on the role and task settings, identifies the dependencies between the sub-attribute items, and constructs business logic units. In practical applications, the large language model can output the business logic units, as shown below:
[0083] “groups”: [
[0084] {
[0085] "name": "useUserManagement",
[0086] “description”: “Logic related to user information management”
[0087] "dataProperties": ["userData", "userLoading"],
[0088] "computedProperties":["isUserValid"],
[0089] "methods": ["fetchUser", "updateUser"],
[0090] "watchers":["userData"],
[0091] "businessPurpose": "Handles the acquisition, verification, and updating of user information."
[0092] }
[0093] ].
[0094] Step 204: Transform the business logic units into code according to the Vue3 composition API specification, and output Vue3 single-file components.
[0095] In practical applications, business logic units need to be converted into complete Vue3 setup() function code according to the following rules: 1. data properties are converted to ref() or reactive(), 2. computed properties are converted to computed() functions, 3. methods are converted to ordinary functions, 4. watch is converted to watch() or watchEffect(), and 5. lifecycle hooks are converted to onXxx().
[0096] For ease of implementation, the conversion code corresponding to the above conversion rules is as follows:
[0097] const conversionRules = {
[0098] data:(dataProps)=>`const${dataProps.map(p=>`${p}=
[0099] ref(${getDefaultValue(p)})`).join(',')}`,
[0100] computed:(compProp)=>`const${compProp.name}=computed(()
[0101] =>{${compProp.body}})`,
[0102] methods:(method)=>`const${method.name}=${method.params}
[0103] => {${method.body}}`,
[0104] watch:(watcher)=>`watch(${watcher.source},${watcher.handler},
[0105] ${watcher.options})`,
[0106] lifecycle:(hook)=>`on${capitalize(hook.name)}`(onMounted)
[0107] }
[0108] In practical applications, to ensure the correctness of Vue3 single-file components, code verification is required before the large language model outputs the Vue3 single-file components. The specific verification process is as follows: the large language model performs code event verification on the Vue3 single-file components based on the Vue2 single-file components, the Vue3 single-file components, and the business logic units; after the large language model completes the code event verification and passes the verification, it outputs the Vue3 single-file components.
[0109] In this case, the role of the large language model is set as a senior Vue.js code review expert and quality assurance engineer, whose task is to verify the correctness of the Vue2 to Vue3 conversion result and provide correction suggestions. Among them, the code event verification that needs to be verified includes at least: 1. Functional equivalence verification: ensure that the converted code implements the same business functions, 2. Semantic consistency verification: check whether the data flow, event handling, and lifecycle are consistent, 3. Vue3 best practice verification: ensure that it conforms to the best practices of composable APIs, 4. Performance impact verification: identify possible performance issues, and 5. Compatibility issue verification: detect possible runtime errors.
[0110] When verifying code events 1 and 2, a test case can be generated for the Vue2 single-file component and a test case can be generated for the Vue3 single-file component. The two test cases are run separately. If the results of the test cases are the same, the verification is successful; otherwise, the verification fails. For code events 3, 4, and 5, the verification process may require traversing the entire code of the Vue3 single-file component for corresponding verification.
[0111] In practical applications, the large language model can output the validation results, with the specific output format shown below:
[0112]
[0113] It should be noted that the large language model only outputs the Vue3 single-file component when the validation results for each code event are all true, and the above code only has the fixSuggestions code module when the validation results for at least one code event are all false.
[0114] As described above, in the process of transforming complex code, the large language model needs to decompose the complex task into four levels: component analysis, logic decomposition, code transformation, and verification and correction. Each level focuses on different transformation dimensions to avoid information overload in a single processing session. In practical applications, each level can be executed by the same large language model, or multiple large language models can be used for each level; this is not a limitation here.
[0115] In this embodiment, based on the semantic understanding capabilities of the large language model and traditional correlation analysis, intelligent logical grouping is performed based on business semantic relevance, and appropriate composable functions are automatically generated. This deep analysis based on business logic breaks through the shallow transformation of syntax mapping and achieves an automatic method of equivalent refactoring from Vue2 to Vue3 through semantic modeling. It can effectively ensure the functional consistency and architectural rationality of the converted code, and ultimately achieve an industrial-grade code upgrade standard with zero human intervention.
[0116] See Figure 3 This is a block diagram illustrating an embodiment of a code conversion apparatus provided by an embodiment of the present invention. Figure 3 As shown, the device includes:
[0117] The first parsing module 301 is used to perform structured parsing of Vue2 single-file components, extracting script files, template content and component identifiers;
[0118] The second parsing module 302 is used to perform AST parsing on the script file and generate an AST structure containing component configuration items;
[0119] Code transformation model 303 is used to input the AST structure, template content and component identifiers into the large language model. The large language model analyzes the dependencies between component configuration items and outputs Vue3 single-file components.
[0120] This innovative technical solution integrates the intelligent semantic parsing and code generation capabilities of a large language model with the precise detection mechanism of static code analysis, achieving fully automated code conversion from Vue2 to Vue3. Compared to traditional manual conversion, this solution achieves significant breakthroughs in conversion efficiency, economy, and code quality, ultimately reaching an industrial-grade code upgrade standard with zero human intervention.
[0121] Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. Figure 4 The illustrated electronic device 1200 includes at least one processor 1201, a memory 1202, at least one network interface 1204, and other user interfaces 1203. The various components in the electronic device 1200 are coupled together via a bus system 1205. It is understood that the bus system 1205 is used to implement communication between these components. In addition to a data bus, the bus system 1205 also includes a power bus, a control bus, and a status signal bus. However, for clarity, ... Figure 4 The general labeled all buses as Bus System 1205.
[0122] The user interface 1203 may include a display, keyboard, or clicking device (e.g., mouse, trackball, touchpad, or touchscreen).
[0123] It is understood that the memory 1202 in the embodiments of the present invention can be volatile memory or non-volatile memory, or may include both volatile and non-volatile memory. The non-volatile memory can be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. The volatile memory can be random access memory (RAM), which is used as an external cache. By way of example, but not limitation, many forms of RAM are available, such as Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), Synchronous DRAM (SDRAM), Double Data Rate Synchronous DRAM (DDRSDRAM), Enhanced Synchronous DRAM (ESDRAM), Synchronous Link DRAM (SLDRAM), and Direct Rambus RAM (DRRAM). The memory 1202 described herein is intended to include, but is not limited to, these and any other suitable types of memory.
[0124] In some implementations, memory 1202 stores elements, executable units or data structures, or subsets thereof, or extended sets thereof: operating system 12021 and application program 12022.
[0125] The operating system 12021 includes various system programs, such as the framework layer, core library layer, and driver layer, used to implement various basic business functions and handle hardware-based tasks. The application program 12022 includes various applications, such as a media player and a browser, used to implement various application functions. The program implementing the method of this embodiment can be included in the application program 12022.
[0126] In this embodiment of the invention, by calling the program or instructions stored in the memory 1202, specifically the program or instructions stored in the application program 12022, the processor 1201 executes the method steps provided in each method embodiment, including, for example:
[0127] Perform structured parsing on Vue2 single-file components to extract script files, template content, and component identifiers;
[0128] Perform AST parsing on the script file to generate an AST structure containing component configuration items;
[0129] The AST structure, template content, and component identifiers are input into the large language model. The large language model analyzes the dependencies between component configuration items and outputs Vue3 single-file components.
[0130] In one possible implementation, structured parsing of Vue2 single-file components includes:
[0131] Use a single-file component parser to perform structured parsing of Vue2 single-file components;
[0132] Perform AST parsing on the script file, including:
[0133] Use a JavaScript code parser to perform AST parsing on the script file.
[0134] In one possible implementation, the large language model analyzes the dependencies between component configuration items and outputs Vue 3 single-file components, including:
[0135] Analyze the AST structure, template content, and component identifiers to identify the sub-attribute items corresponding to each component configuration item;
[0136] Identify the purpose of each sub-attribute item and determine the corresponding business purpose of each sub-attribute item;
[0137] By aggregating all target sub-attribute items with the same business purpose, business logic units are constructed.
[0138] The business logic units are converted into code according to the Vue3 composition API specification, and output as Vue3 single-file components.
[0139] In one possible implementation, component configuration items include the following types: data flow configuration items, computation configuration items, method configuration items, listener configuration items, and lifecycle hook configuration items.
[0140] In one possible implementation, a business logic unit is constructed by aggregating all target sub-attribute items with the same business purpose, including:
[0141] In the method configuration items with the same business purpose, check whether the target sub-attribute item references the first sub-attribute item of the data flow configuration item with different business purpose;
[0142] If a reference to the first sub-attribute is detected, all target sub-attribute items with the same business purpose are aggregated with the first sub-attribute item to construct a business logic unit;
[0143] If no reference to the first sub-attribute is detected, a business logic unit is constructed by aggregating all target sub-attribute items with the same business purpose.
[0144] In one possible implementation, the method further includes the following before outputting the Vue 3 single-file component:
[0145] The large language model performs code event verification on Vue3 single-file components based on Vue2 single-file components, Vue3 single-file components, and business logic units.
[0146] Once the large language model completes code event verification and passes the verification, it outputs a Vue3 single-file component.
[0147] In one possible implementation, code event verification includes at least the following: functional equivalence verification, semantic consistency verification, Vue3 best practice verification, performance impact verification, and compatibility issue verification.
[0148] The methods disclosed in the above embodiments of the present invention can be applied to processor 1201, or implemented by processor 1201. Processor 1201 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the integrated logic circuit of the hardware in processor 1201 or by instructions in the form of software. The processor 1201 may be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of the present invention. The general-purpose processor may be a microprocessor or any conventional processor. The steps of the methods disclosed in the embodiments of the present invention can be directly embodied in the execution of a hardware decoding processor, or executed by a combination of hardware and software units in the decoding processor. The software units may be located in random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, or other mature storage media in the art. The storage medium is located in memory 1202. Processor 1201 reads the information in memory 1202 and completes the steps of the above method in conjunction with its hardware.
[0149] It is understood that the embodiments described herein can be implemented in hardware, software, firmware, middleware, microcode, or a combination thereof. For hardware implementation, the processing unit can be implemented in one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field-programmable gate arrays (FPGAs), general-purpose processors, controllers, microcontrollers, microprocessors, other electronic units for performing the functions described herein, or combinations thereof.
[0150] For software implementation, the techniques described herein can be implemented by units that perform the functions described herein. The software code can be stored in memory and executed by a processor. The memory can be implemented in the processor or external to the processor.
[0151] The electronic device provided in this embodiment may be as follows: Figure 4 The electronic device shown can perform the following: Figure 1-2 All steps of the method for converting Chinese code to English, thereby achieving Figure 1-2 For details on the technical effects of the code conversion method shown, please refer to [link / reference]. Figure 1-2 The relevant descriptions are presented concisely and will not be elaborated upon here.
[0152] This invention also provides a storage medium (computer-readable storage medium). This storage medium stores one or more programs. The storage medium may include volatile memory, such as random access memory; the memory may also include non-volatile memory, such as read-only memory, flash memory, hard disk, or solid-state drive; the memory may also include combinations of the above types of memory.
[0153] When one or more programs in the storage medium can be executed by one or more processors, the above-mentioned code conversion method can be implemented.
[0154] The processor is used to execute a program for code conversion stored in memory to implement the following steps of the code conversion method:
[0155] Perform structured parsing on Vue2 single-file components to extract script files, template content, and component identifiers;
[0156] Perform AST parsing on the script file to generate an AST structure containing component configuration items;
[0157] The AST structure, template content, and component identifiers are input into the large language model. The large language model analyzes the dependencies between component configuration items and outputs Vue3 single-file components.
[0158] In one possible implementation, structured parsing of Vue2 single-file components includes:
[0159] Use a single-file component parser to perform structured parsing of Vue2 single-file components;
[0160] Perform AST parsing on the script file, including:
[0161] Use a JavaScript code parser to perform AST parsing on the script file.
[0162] In one possible implementation, the large language model analyzes the dependencies between component configuration items and outputs Vue 3 single-file components, including:
[0163] Analyze the AST structure, template content, and component identifiers to identify the sub-attribute items corresponding to each component configuration item;
[0164] Identify the purpose of each sub-attribute item and determine the corresponding business purpose of each sub-attribute item;
[0165] By aggregating all target sub-attribute items with the same business purpose, business logic units are constructed.
[0166] The business logic units are converted into code according to the Vue3 composition API specification, and output as Vue3 single-file components.
[0167] In one possible implementation, component configuration items include the following types: data flow configuration items, computation configuration items, method configuration items, listener configuration items, and lifecycle hook configuration items.
[0168] In one possible implementation, a business logic unit is constructed by aggregating all target sub-attribute items with the same business purpose, including:
[0169] In the method configuration items with the same business purpose, check whether the target sub-attribute item references the first sub-attribute item of the data flow configuration item with different business purpose;
[0170] If a reference to the first sub-attribute is detected, all target sub-attribute items with the same business purpose are aggregated with the first sub-attribute item to construct a business logic unit;
[0171] If no reference to the first sub-attribute is detected, a business logic unit is constructed by aggregating all target sub-attribute items with the same business purpose.
[0172] In one possible implementation, the method further includes the following before outputting the Vue 3 single-file component:
[0173] The large language model performs code event verification on Vue3 single-file components based on Vue2 single-file components, Vue3 single-file components, and business logic units.
[0174] Once the large language model completes code event verification and passes the verification, it outputs a Vue3 single-file component.
[0175] In one possible implementation, code event verification includes at least the following: functional equivalence verification, semantic consistency verification, Vue3 best practice verification, performance impact verification, and compatibility issue verification.
[0176] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.
[0177] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented in hardware, a software module executed by a processor, or a combination of both. The software module can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.
[0178] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above description is only a specific embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A method for code conversion, characterized in that, The method includes: Perform structured parsing on Vue2 single-file components to extract script files, template content, and component identifiers; The script file is parsed using an AST (Abstract Syntax Tree) to generate an AST structure containing component configuration items; The AST structure, the template content, and the component identifier are input into the large language model, which analyzes the dependencies between component configuration items and outputs Vue3 single-file components.
2. The method according to claim 1, characterized in that, The structured parsing of Vue2 single-file components includes: Use a single-file component parser to perform structured parsing of Vue2 single-file components; The AST parsing of the script file includes: The script file was parsed using a JavaScript code parser.
3. The method according to claim 1, characterized in that, The large language model analyzes the dependencies between component configuration items and outputs Vue3 single-file components, including: The AST structure, template content, and component identifiers are analyzed to identify the sub-attribute items corresponding to each component configuration item; The purpose of each sub-attribute item is identified to determine the business purpose corresponding to each sub-attribute item. By aggregating all target sub-attribute items with the same business purpose, business logic units are constructed. The business logic units are converted into code according to the Vue3 composition API specification, and output as Vue3 single-file components.
4. The method according to claim 3, characterized in that, The component configuration items include the following types: data flow configuration items, computation configuration items, method configuration items, listener configuration items, and lifecycle hook configuration items.
5. The method according to claim 4, characterized in that, The process of constructing business logic units by aggregating all target sub-attribute items with the same business purpose includes: Detect whether the target sub-attribute item of the method configuration item with the same business purpose references the first sub-attribute item of the data flow configuration item with different business purposes; If a reference to the first sub-attribute item is detected, all target sub-attribute items with the same business purpose are aggregated with the first sub-attribute item to construct a business logic unit; If no reference to the first sub-attribute is detected, a business logic unit is constructed by aggregating all target sub-attribute items with the same business purpose.
6. The method according to claim 3, characterized in that, Before outputting the Vue3 single-file component, the method further includes: The large language model performs code event verification on the Vue3 single-file component based on the Vue2 single-file component, the Vue3 single-file component, and the business logic unit. Once the large language model completes code event verification and passes the verification, it outputs the Vue3 single-file component.
7. The method according to claim 6, characterized in that, The code event verification includes at least the following: functional equivalence verification, semantic consistency verification, Vue3 best practice verification, performance impact verification, and compatibility issue verification.
8. A code conversion apparatus, characterized in that, The device includes: The first parsing module is used to perform structured parsing of Vue2 single-file components, extracting script files, template content, and component identifiers; The second parsing module is used to perform AST parsing on the script file and generate an AST structure containing component configuration items; The code transformation model is used to input the AST structure, the template content, and the component identifier into the large language model. The large language model analyzes the dependencies between component configuration items and outputs Vue3 single-file components.
9. An electronic device, characterized in that, include: A processor and a memory, the processor being configured to execute a program for code conversion stored in the memory to implement the code conversion method according to any one of claims 1 to 7.
10. A storage medium, characterized in that, The storage medium stores one or more programs, which can be executed by one or more processors to implement the code conversion method according to any one of claims 1 to 7.