Skip to content

Commit 163fd0d

Browse files
Merge pull request #234 from salesforcecli/main
back merge
2 parents 48998fa + 7b7db89 commit 163fd0d

File tree

2 files changed

+33
-26
lines changed

2 files changed

+33
-26
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@salesforce/plugin-omnistudio-migration-tool",
33
"description": "This SFDX plugin migrates FlexCard, OmniScript, DataRaptor, and Integration Procedure custom objects to standard objects.",
4-
"version": "1.5.0",
4+
"version": "1.4.0",
55
"author": "Salesforce",
66
"bugs": "https://github.com/forcedotcom/cli/issues",
77
"dependencies": {

src/utils/lwcparser/jsParser/JavaScriptParser.ts

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,48 @@
1+
/* eslint-disable @typescript-eslint/no-unsafe-call */
2+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
13
/* eslint-disable no-console */
24
/* eslint-disable @typescript-eslint/explicit-member-accessibility */
3-
import * as fs from 'fs';
4-
import * as parser from '@babel/parser';
5-
import traverse, { NodePath } from '@babel/traverse';
6-
import * as t from '@babel/types'; // Import all types from @babel/types
5+
// import * as fs from 'fs';
6+
// import { parse, type ParseResult } from '@babel/parser'; // Import all types from @babel/types
77

88
class JavaScriptParser {
9-
private fileContent: string;
10-
private ast: parser.ParseResult<t.File> | null; // Specify the generic type argument
9+
// private fileContent: string;
10+
private ast: File | null = null; // Specify the generic type argument
1111

1212
constructor(filePath: string) {
13-
this.fileContent = fs.readFileSync(filePath, 'utf-8');
13+
// this.fileContent = fs.readFileSync(filePath, 'utf-8');
1414
this.ast = null;
1515
}
1616

17-
public parseFile(): void {
18-
this.ast = parser.parse(this.fileContent, {
19-
sourceType: 'module',
20-
plugins: ['decorators'],
21-
});
22-
}
17+
// public parseCode(): void {
18+
// const parseResult: File = parse(this.fileContent, {
19+
// sourceType: 'module', // Use 'script' if you're parsing non-module code
20+
// plugins: ['jsx', 'typescript'], // Add plugins as needed
21+
// });
22+
23+
// if (parseResult.type === 'File') {
24+
// this.ast = parseResult;
25+
// } else {
26+
// throw new Error("Parsing did not return a 'File' node as expected.");
27+
// }
28+
// }
2329

24-
public traverseAST(): string[] {
25-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
26-
const labels: string[] = [];
30+
// Method to get the AST as a string
31+
getAST(): string | null {
2732
if (!this.ast) {
28-
throw new Error('AST has not been generated. Call parseFile() first.');
33+
console.error('AST is not available. Please parse the code first.');
34+
return null;
2935
}
36+
return JSON.stringify(this.ast, null, 2);
37+
}
3038

31-
traverse(this.ast, {
32-
ImportDeclaration(path: NodePath<t.ImportDeclaration>) {
33-
console.log('Import found:', path.node.source.value);
34-
labels.push(path.node.source.value);
35-
},
36-
});
37-
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
38-
return labels;
39+
// Main method to process the file
40+
processFile(): void {
41+
// this.parseCode(); // Parse the JavaScript code
42+
const astString = this.getAST(); // Get the AST as a string
43+
if (astString) {
44+
console.log(astString); // Output the AST
45+
}
3946
}
4047
}
4148

0 commit comments

Comments
 (0)