Skip to content

Commit

Permalink
fix: super keyword unexpected here
Browse files Browse the repository at this point in the history
  • Loading branch information
zermelo-wisen authored and dividedmind committed Nov 17, 2023
1 parent c5dd799 commit 2fa388c
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/hooks/__tests__/instrument.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe(instrument.transform, () => {
}];
function testFun(arg) {
return global.AppMapRecordHook.call(this, function testFun(arg) {
return global.AppMapRecordHook.call(this, arg => {
return arg + 1;
}, arguments, __appmapFunctionRegistry[0]);
}
Expand Down Expand Up @@ -75,7 +75,7 @@ describe(instrument.transform, () => {
class TestClass {
foo(value) {
return global.AppMapRecordHook.call(this, function (value) {
return global.AppMapRecordHook.call(this, value => {
return value + 1;
}, arguments, __appmapFunctionRegistry[0]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/__tests__/jest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe(jestHook.patchRuntime, () => {
transformFile() {
return global.AppMap[0].call(
this,
function () {
() => {
if (false) return 4;
return 5;
},
Expand Down
8 changes: 7 additions & 1 deletion src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ export function wrap<This, Args extends unknown[], Return, Data extends LiteralV
call_(
member(expressionFor(hook), identifier("call")),
this_,
inner,
{
type: "ArrowFunctionExpression",
params: inner.params,
async: inner.async,
body: inner.body ?? { type: "BlockStatement", body: [] },
expression: false,
},
args_,
...args.map(literal),
),
Expand Down
8 changes: 7 additions & 1 deletion src/hooks/instrument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,13 @@ function wrapWithRecord(
call_(
member(...["global", "AppMapRecordHook", "call"].map(identifier)),
this_,
{ ...fd, type: "FunctionExpression" },
{
type: "ArrowFunctionExpression",
params: fd.params,
async: fd.async,
body: fd.body ?? { type: "BlockStatement", body: [] },
expression: false,
},
args_,
member(
__appmapFunctionRegistryIdentifier,
Expand Down
102 changes: 102 additions & 0 deletions test/__snapshots__/simple.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,105 @@ exports[`mapping an mjs script 1`] = `
"version": "1.12",
}
`;

exports[`mapping js class methods containing super keyword 1`] = `
{
"classMap": [
{
"children": [
{
"children": [
{
"location": "./class.js:12",
"name": "m1",
"static": false,
"type": "function",
},
],
"name": "B",
"type": "class",
},
{
"children": [
{
"location": "./class.js:2",
"name": "m1",
"static": false,
"type": "function",
},
],
"name": "A",
"type": "class",
},
],
"name": "class",
"type": "package",
},
],
"events": [
{
"defined_class": "B",
"event": "call",
"id": 1,
"lineno": 12,
"method_id": "m1",
"parameters": [],
"path": "./class.js",
"receiver": {
"class": "B",
"value": "B {}",
},
"static": false,
"thread_id": 0,
},
{
"defined_class": "A",
"event": "call",
"id": 2,
"lineno": 2,
"method_id": "m1",
"parameters": [],
"path": "./class.js",
"receiver": {
"class": "B",
"value": "B {}",
},
"static": false,
"thread_id": 0,
},
{
"elapsed": 31.337,
"event": "return",
"id": 3,
"parent_id": 2,
"thread_id": 0,
},
{
"elapsed": 31.337,
"event": "return",
"id": 4,
"parent_id": 1,
"thread_id": 0,
},
],
"metadata": {
"app": "appmap-node",
"client": {
"name": "appmap-node",
"url": "https://github.com/getappmap/appmap-node",
"version": "test node-appmap version",
},
"language": {
"engine": "Node.js",
"name": "javascript",
"version": "test node version",
},
"name": "test process recording",
"recorder": {
"name": "process",
"type": "process",
},
},
"version": "1.12",
}
`;
5 changes: 5 additions & 0 deletions test/simple.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ integrationTest("mapping an mjs script", () => {
expect(runAppmapNode("index.mjs").status).toBe(0);
expect(readAppmap()).toMatchSnapshot();
});

integrationTest("mapping js class methods containing super keyword", () => {
expect(runAppmapNode("class.js").status).toBe(0);
expect(readAppmap()).toMatchSnapshot();
});
18 changes: 18 additions & 0 deletions test/simple/class.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class A {
m1() {
console.log("A.m1()");
}
m2() {
console.log("A.m2()");
return "return m2";
}
}

class B extends A {
m1() {
super.m1();
console.log("B.m1()");
}
}

new B().m1();

0 comments on commit 2fa388c

Please sign in to comment.