|
1 | 1 | 'use strict' |
2 | 2 |
|
3 | 3 | const { parseSync, Visitor } = require('oxc-parser') |
| 4 | +const code = require('fs').readFileSync('./node_modules/express/lib/request.js', 'utf8') |
4 | 5 |
|
5 | | -const code = 'const url: String = /* 🤨 */ import.meta.url;' |
| 6 | +// const code = 'const url: String = /* 🤨 */ import.meta.url;' |
6 | 7 |
|
7 | 8 | // File extension is used to determine which dialect to parse source as. |
8 | | -const filename = 'test.tsx' |
| 9 | +const filename = 'request.js' |
9 | 10 |
|
10 | 11 | const result = parseSync(filename, code) |
11 | 12 | // or `await parseAsync(filename, code)` |
12 | 13 |
|
13 | 14 | // An array of errors, if any. |
14 | 15 | console.log(result.errors) |
15 | 16 |
|
16 | | -// AST and comments. |
17 | | -console.log(result.program, result.comments) |
| 17 | +// // AST and comments. |
| 18 | +// console.log(result.program, result.comments) |
18 | 19 |
|
19 | | -// ESM information - imports, exports, `import.meta`s. |
20 | | -console.log(result.module) |
| 20 | +// // ESM information - imports, exports, `import.meta`s. |
| 21 | +// console.log(result.module) |
21 | 22 |
|
22 | 23 | // Visit the AST |
23 | | -const visitations = [] |
24 | | - |
25 | | -const visitor = new Visitor({ |
26 | | - VariableDeclaration (decl) { |
27 | | - visitations.push(`enter ${decl.kind}`) |
28 | | - }, |
29 | | - 'VariableDeclaration:exit' (decl) { |
30 | | - visitations.push(`exit ${decl.kind}`) |
31 | | - }, |
32 | | - Identifier (ident) { |
33 | | - visitations.push(ident.name) |
34 | | - }, |
35 | | -}) |
36 | | - |
37 | | -visitor.visit(result.program) |
| 24 | +// const visitations = [] |
| 25 | + |
| 26 | +// const visitor = new Visitor({ |
| 27 | +// VariableDeclaration (decl) { |
| 28 | +// visitations.push(`enter ${decl.kind}`) |
| 29 | +// }, |
| 30 | +// 'VariableDeclaration:exit' (decl) { |
| 31 | +// visitations.push(`exit ${decl.kind}`) |
| 32 | +// }, |
| 33 | +// Identifier (ident) { |
| 34 | +// visitations.push(ident.name) |
| 35 | +// }, |
| 36 | +// }) |
| 37 | + |
| 38 | +// visitor.visit(result.program) |
38 | 39 |
|
39 | 40 | // Logs: [ 'enter const', 'url', 'String', 'import', 'meta', 'url', 'exit const' ] |
40 | | -console.log(visitations) |
| 41 | +// console.log(visitations) |
0 commit comments