diff --git a/package.json b/package.json index b8b39fa..5e3bf1c 100644 --- a/package.json +++ b/package.json @@ -18,16 +18,16 @@ "license": "MIT", "dependencies": { "@types/acorn": "4.0.5", - "acorn": "7.4.0", + "acorn": "8.0.1", "reflect-metadata": "^0.1.13" }, "devDependencies": { - "@types/jest": "^26.0.9", - "@types/node": "^14.0.27", + "@types/jest": "^26.0.13", + "@types/node": "^14.6.4", "coveralls": "^3.1.0", - "jest": "^26.2.2", - "ts-jest": "^26.1.4", - "tslib": "^2.0.0", - "typescript": "^3.9.7" + "jest": "^26.4.2", + "ts-jest": "^26.3.0", + "tslib": "^2.0.1", + "typescript": "^4.0.2" } } diff --git a/src/parser.ts b/src/parser.ts index 3700cc7..aa0c26f 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -49,25 +49,25 @@ function getNamesFromAst(nodes: any[]) { return nodes.map(x => getName(x)).filter((x): x is string | { [key: string]: string[] } => !!x) } -function getCode(fn:Class|Function){ +function getCode(fn: Class | Function) { const code = fn.toString() - if(code.search(/^class(\s*)extends\s*option.parent\s*{\s*}/gm) > -1) { + if (code.search(/^class(\s*)extends\s*option.parent\s*{\s*}/gm) > -1) { return "class DynamicClass extends parent {}" } - else + else return code.replace("[native code]", "") } function getMethodParameters(fn: Class, method: string) { const body = getCode(fn) - const ast = parse(body) + const ast = parse(body, { ecmaVersion: 2020 }) const ctor = getNode(ast, x => x.type === "MethodDefinition" && x.kind === "method" && x.key.name === method) return getNamesFromAst(ctor ? (ctor as any).value.params : []) } function getConstructorParameters(fn: Class) { const body = getCode(fn) - const ast = parse(body) + const ast = parse(body, { ecmaVersion: 2020 }) const ctor = getNode(ast, x => x.type === "MethodDefinition" && x.kind === "constructor") return getNamesFromAst(ctor ? (ctor as any).value.params : []) } @@ -75,7 +75,7 @@ function getConstructorParameters(fn: Class) { function getFunctionParameters(fn: Function) { try { const body = getCode(fn) - const ast = parse(body) + const ast = parse(body, { ecmaVersion: 2020 }) return getNamesFromAst((ast as any).body[0].params) } catch { @@ -176,7 +176,7 @@ function parseConstructor(fn: Class): ConstructorReflection { function parseClass(fn: Class): ClassReflection { const proto = Object.getPrototypeOf(fn) return { - kind: "Class", name: fn.name, type: fn, decorators: [], + kind: "Class", name: fn.name, type: fn, decorators: [], methods: parseMethods(fn), properties: parseProperties(fn), ctor: parseConstructor(fn),