File tree Expand file tree Collapse file tree 3 files changed +17
-4
lines changed Expand file tree Collapse file tree 3 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -9,13 +9,14 @@ import isMinified from "is-minified-code";
9
9
// Import Internal Dependencies
10
10
import { SourceFile } from "./SourceFile.js" ;
11
11
import { isOneLineExpressionExport } from "./utils/index.js" ;
12
+ import { JsSourceParser } from "./JsSourceParser.js" ;
12
13
13
14
export class AstAnalyser {
14
15
/**
15
16
* @constructor
16
- * @param { SourceParser } parser
17
+ * @param { SourceParser } [ parser]
17
18
*/
18
- constructor ( parser ) {
19
+ constructor ( parser = new JsSourceParser ( ) ) {
19
20
this . parser = parser ;
20
21
}
21
22
@@ -35,7 +36,7 @@ export class AstAnalyser {
35
36
// we walk each AST Nodes, this is a purely synchronous I/O
36
37
walk ( body , {
37
38
enter ( node ) {
38
- // Skip the root of the AST.
39
+ // Skip the root of the AST.
39
40
if ( Array . isArray ( node ) ) {
40
41
return ;
41
42
}
Original file line number Diff line number Diff line change @@ -225,6 +225,18 @@ describe("AstAnalyser", (t) => {
225
225
assert . strictEqual ( preparedSource , "\nconst yo = 'foo'\n" ) ;
226
226
} ) ;
227
227
} ) ;
228
+
229
+ describe ( "constructor" , ( ) => {
230
+ it ( "should not throw an error when instantiated without a custom parser" , ( ) => {
231
+ assert . doesNotThrow ( ( ) => {
232
+ const analyser = new AstAnalyser ( ) ;
233
+ // perform basic operations
234
+ const result = analyser . analyse ( "const foo = 'bar';" ) ;
235
+ // compare array of keys to an empty array to ensure there are no dependencies in result
236
+ assert . deepEqual ( [ ...result . dependencies . keys ( ) ] , [ ] ) ;
237
+ } ) ;
238
+ } ) ;
239
+ } ) ;
228
240
} ) ;
229
241
230
242
let analyser = null ;
Original file line number Diff line number Diff line change @@ -78,7 +78,7 @@ interface SourceParser {
78
78
}
79
79
80
80
declare class AstAnalyser {
81
- constructor ( parser : SourceParser ) ;
81
+ constructor ( parser ? : SourceParser ) ;
82
82
analyse : ( str : string , options ?: Omit < RuntimeOptions , "customParser" > ) => Report ;
83
83
analyzeFile ( pathToFile : string , options ?: Omit < RuntimeFileOptions , "customParser" > ) : Promise < ReportOnFile > ;
84
84
}
You can’t perform that action at this time.
0 commit comments