Skip to content

Commit e5f8438

Browse files
committed
PluginSection know nodeID now
SQUASHED: AUTO-COMMIT-demos-tom-babel-plugin-tracer.js,AUTO-COMMIT-demos-tom-plugin-backup.js,AUTO-COMMIT-demos-tom-plugin-explorer-worker.js,AUTO-COMMIT-demos-tom-Sections.js,AUTO-COMMIT-demos-tom-trace.js,AUTO-COMMIT-demos-tom-TraceLogParser.js,AUTO-COMMIT-src-components-tools-lively-plugin-explorer-playground.workspace,
1 parent 9509740 commit e5f8438

File tree

7 files changed

+45
-23
lines changed

7 files changed

+45
-23
lines changed

demos/tom/Sections.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ export class TraceSection {
6464
}
6565
}
6666

67+
export class PluginSection extends TraceSection {
68+
constructor(name, nodeID, entries = []) {
69+
super(name, entries);
70+
71+
this.nodeID = nodeID;
72+
}
73+
}
74+
6775
export class FunctionSection extends TraceSection {
6876
constructor() {
6977
super(...arguments);

demos/tom/TraceLogParser.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Event, eventTypes } from 'demos/tom/Events.js';
2-
import { FunctionSection, TraceSection } from 'demos/tom/Sections.js';
2+
import { FunctionSection, PluginSection, TraceSection } from 'demos/tom/Sections.js';
33

44
class EarlyReturn {
55
constructor(type) {
@@ -128,7 +128,7 @@ export default class TraceLogParser {
128128

129129
parseTraversePlugin(section, higherSections) {
130130
const entry = this.consume();
131-
const plugin = new TraceSection('TraversePlugin:' + entry.data);
131+
const plugin = new PluginSection('TraversePlugin:' + entry.data[0], entry.data[1]);
132132
plugin.position = this.peek().position;
133133

134134
section.addEntry(plugin);
@@ -180,7 +180,7 @@ export default class TraceLogParser {
180180
}
181181

182182
parsePlugin(sections) {
183-
const plugin = new TraceSection(this.consume().data);
183+
const plugin = new PluginSection(...this.consume().data);
184184
sections.push(plugin);
185185
this.defaultParse(plugin, []);
186186
return plugin;

demos/tom/babel-plugin-tracer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ export default function({ types: t }) {
3737

3838
function modifyFunction(name, path, state) {
3939
const body = path.get('body');
40-
body.unshiftContainer('body', t.expressionStatement(callOnTrace('enterFunction', [location(path.node, state), t
41-
.stringLiteral(name)
42-
])));
40+
body.unshiftContainer('body', t.expressionStatement(callOnTrace('enterFunction', [location(path.node, state), t.stringLiteral(name)])));
4341
body.pushContainer('body', t.expressionStatement(callOnTrace('leave', [location(path.node, state)])));
4442
path.traverse(returnVisitor, state);
4543
}
@@ -101,6 +99,8 @@ export default function({ types: t }) {
10199
name = t.stringLiteral(callee.node.name || 'anonymous function');
102100
}
103101

102+
103+
104104
const loc = location(callee.node, this);
105105

106106
const aboutToEnter = callOnTrace('aboutToEnter',

demos/tom/plugin-backup.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ export default function({ types: t }) {
3737

3838
function modifyFunction(name, path, state) {
3939
const body = path.get('body');
40-
body.unshiftContainer('body', t.expressionStatement(callOnTrace('enterFunction', [location(path.node, state), t
41-
.stringLiteral(name)
42-
])));
40+
body.unshiftContainer('body', t.expressionStatement(callOnTrace('enterFunction', [location(path.node, state), t.stringLiteral(name)])));
4341
body.pushContainer('body', t.expressionStatement(callOnTrace('leave', [location(path.node, state)])));
4442
path.traverse(returnVisitor, state);
4543
}
@@ -88,7 +86,6 @@ export default function({ types: t }) {
8886
path.node.alreadyVisited = true;
8987
let callee = path.get('callee');
9088
let name;
91-
debugger
9289

9390
if (t.isMemberExpression(callee)) {
9491
if(callee.node.computed) {

demos/tom/plugin-explorer-worker.js

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,35 @@ function decorateNodePathTraverse(plugin, trace) {
7676
for (const name in visitors) {
7777
if (typeof visitors[name] === 'function') {
7878
const fn = visitors[name];
79-
newVisitors[name] = function() {
80-
trace.startTraversePlugin(name);
81-
fn(...arguments);
79+
newVisitors[name] = function(path, ...rest) {
80+
trace.startTraversePlugin(name, path.node.traceID);
81+
fn(path, ...rest);
8282
trace.endTraversePlugin(name);
8383
};
8484
} else if (typeof visitors[name] === 'object') {
85-
debugger
85+
const obj = visitors[name];
86+
87+
if(obj.enter) {
88+
obj.enter = obj.enter.map(fn => function(path, ...rest) {
89+
trace.startTraversePlugin(name, path.node.traceID);
90+
fn(path, ...rest);
91+
trace.endTraversePlugin(name);
92+
})
93+
}
94+
95+
if(obj.exit) {
96+
obj.exit = obj.exit.map(fn => function(path, ...rest) {
97+
trace.startTraversePlugin(name, path.node.traceID);
98+
fn(path, ...rest);
99+
trace.endTraversePlugin(name);
100+
})
101+
}
102+
103+
newVisitors[name] = obj;
86104
}
87105

88106
}
89107

90-
visitors = newVisitors;
91108
oldTraverse.call(this, newVisitors, ...rest);
92109

93110
}
@@ -169,9 +186,9 @@ self.onmessage = function(msg) {
169186
config.sourceMaps = true;
170187

171188
config.wrapPluginVisitorMethod = (pluginAlias, visitorType, callback) => {
172-
return (...args) => {
173-
trace.enterPlugin(pluginAlias);
174-
callback(...args);
189+
return (path, ...rest) => {
190+
trace.enterPlugin(pluginAlias, path.node.traceID);
191+
callback(path, ...rest);
175192
trace.leavePlugin(pluginAlias);
176193
}
177194
};

demos/tom/trace.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,17 +140,17 @@ export default class Trace {
140140

141141
/*MD ## Plugins MD*/
142142

143-
enterPlugin(name) {
144-
this.log(new Event('enterPlugin', name));
143+
enterPlugin(name, traceID) {
144+
this.log(new Event('enterPlugin', [name, traceID]));
145145
this.pluginRound++;
146146
}
147147

148148
leavePlugin(name) {
149149
this.log(new Event('leavePlugin', name));
150150
}
151151

152-
startTraversePlugin(name) {
153-
this.log(new Event('enterTraversePlugin', name));
152+
startTraversePlugin(name, traceID) {
153+
this.log(new Event('enterTraversePlugin', [name, traceID]));
154154
}
155155

156156
endTraversePlugin(name) {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"source":"/src/components/tools/lively-ast-explorer-example-source.js","plugin":"https://lively-kernel.org/lively4/lively4-tom/src/external/babel-plugin-locals.js","options":{"autoUpdateAST":true,"autoUpdateTransformation":true,"autoExecute":true,"systemJS":true,"autoRunTests":false,"autoSaveWorkspace":false},"pluginSelection":[{"url":"https://lively-kernel.org/lively4/lively4-tom/src/external/babel-plugin-locals.js"}]}
1+
{"source":"/src/components/tools/lively-ast-explorer-example-source.js","plugin":"https://lively-kernel.org/lively4/lively4-tom/demos/tom/plugin-backup.js","options":{"autoUpdateAST":true,"autoUpdateTransformation":true,"autoExecute":true,"systemJS":false,"autoRunTests":false,"autoSaveWorkspace":false},"pluginSelection":[{"url":"https://lively-kernel.org/lively4/lively4-tom/demos/tom/plugin-backup.js"}]}

0 commit comments

Comments
 (0)