UNPKG

vite-plugin-utils

Version:
360 lines (357 loc) 12.3 kB
const fs = require('fs'); const path = require('path'); const { c, walk } = require('../function'); const ast = { "type": "Program", "start": 0, "end": 313, "body": [ { "type": "FunctionDeclaration", "start": 0, "end": 312, "id": { "type": "Identifier", "start": 15, "end": 33, "name": "nestedTryCatchBlok" }, "expression": false, "generator": false, "async": true, "params": [ { "type": "Identifier", "start": 34, "end": 38, "name": "path" } ], "body": { "type": "BlockStatement", "start": 40, "end": 312, "body": [ { "type": "VariableDeclaration", "start": 44, "end": 55, "declarations": [ { "type": "VariableDeclarator", "start": 48, "end": 55, "id": { "type": "Identifier", "start": 48, "end": 50, "name": "md" }, "init": { "type": "Literal", "start": 53, "end": 55, "value": "", "raw": "''" } } ], "kind": "let" }, { "type": "VariableDeclaration", "start": 58, "end": 74, "declarations": [ { "type": "VariableDeclarator", "start": 62, "end": 74, "id": { "type": "Identifier", "start": 62, "end": 68, "name": "status" }, "init": { "type": "Literal", "start": 71, "end": 74, "value": 200, "raw": "200" } } ], "kind": "let" }, { "type": "TryStatement", "start": 77, "end": 310, "block": { "type": "BlockStatement", "start": 81, "end": 158, "body": [ { "type": "VariableDeclaration", "start": 87, "end": 136, "declarations": [ { "type": "VariableDeclarator", "start": 93, "end": 136, "id": { "type": "Identifier", "start": 93, "end": 101, "name": "markdown" }, "init": { "type": "AwaitExpression", "start": 104, "end": 136, "argument": { "type": "ImportExpression", "start": 110, "end": 136, "source": { "type": "TemplateLiteral", "start": 117, "end": 135, "expressions": [ { "type": "Identifier", "start": 126, "end": 130, "name": "path" } ], "quasis": [ { "type": "TemplateElement", "start": 118, "end": 124, "value": { "raw": "./docs", "cooked": "./docs" }, "tail": false }, { "type": "TemplateElement", "start": 131, "end": 134, "value": { "raw": ".md", "cooked": ".md" }, "tail": true } ] } } } } ], "kind": "const" }, { "type": "ExpressionStatement", "start": 141, "end": 154, "expression": { "type": "AssignmentExpression", "start": 141, "end": 154, "operator": "=", "left": { "type": "Identifier", "start": 141, "end": 143, "name": "md" }, "right": { "type": "Identifier", "start": 146, "end": 154, "name": "markdown" } } } ] }, "handler": { "type": "CatchClause", "start": 159, "end": 310, "param": { "type": "Identifier", "start": 166, "end": 167, "name": "e" }, "body": { "type": "BlockStatement", "start": 169, "end": 310, "body": [ { "type": "TryStatement", "start": 175, "end": 306, "block": { "type": "BlockStatement", "start": 179, "end": 269, "body": [ { "type": "VariableDeclaration", "start": 187, "end": 243, "declarations": [ { "type": "VariableDeclarator", "start": 193, "end": 243, "id": { "type": "Identifier", "start": 193, "end": 201, "name": "markdown" }, "init": { "type": "AwaitExpression", "start": 204, "end": 243, "argument": { "type": "ImportExpression", "start": 210, "end": 243, "source": { "type": "TemplateLiteral", "start": 217, "end": 242, "expressions": [ { "type": "Identifier", "start": 226, "end": 230, "name": "path" } ], "quasis": [ { "type": "TemplateElement", "start": 218, "end": 224, "value": { "raw": "./docs", "cooked": "./docs" }, "tail": false }, { "type": "TemplateElement", "start": 231, "end": 241, "value": { "raw": "/README.md", "cooked": "/README.md" }, "tail": true } ] } } } } ], "kind": "const" }, { "type": "ExpressionStatement", "start": 250, "end": 263, "expression": { "type": "AssignmentExpression", "start": 250, "end": 263, "operator": "=", "left": { "type": "Identifier", "start": 250, "end": 252, "name": "md" }, "right": { "type": "Identifier", "start": 255, "end": 263, "name": "markdown" } } } ] }, "handler": { "type": "CatchClause", "start": 270, "end": 306, "param": { "type": "Identifier", "start": 277, "end": 278, "name": "e" }, "body": { "type": "BlockStatement", "start": 280, "end": 306, "body": [ { "type": "ExpressionStatement", "start": 288, "end": 300, "expression": { "type": "AssignmentExpression", "start": 288, "end": 300, "operator": "=", "left": { "type": "Identifier", "start": 288, "end": 294, "name": "status" }, "right": { "type": "Literal", "start": 297, "end": 300, "value": 404, "raw": "404" } } } ] } }, "finalizer": null } ] } }, "finalizer": null } ] } } ], "sourceType": "module" }; walk(ast, { ImportExpression(node) { console.log('----', node); }, });