Skip to content

Commit 97d334c

Browse files
committed
first working implementation of NodePath traverse tracking
SQUASHED: AUTO-COMMIT-demos-tom-plugin-explorer-worker.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 a7651a0 commit 97d334c

File tree

4 files changed

+59
-25
lines changed

4 files changed

+59
-25
lines changed

demos/tom/TraceLogParser.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ export default class TraceLogParser {
9898
}
9999
} else if(this.matchPeek('beginCondition')) {
100100
this.parseCondition(section, [...higherSections, section]);
101+
} else if(this.matchPeek('enterTraversePlugin')) {
102+
this.parseTraversePlugin(section, [...higherSections, section]);
103+
} else if(this.match('leaveTraversePlugin')) {
104+
return section;
101105
} else if(this.matchPeek('astChangeEvent')) {
102106
const change = this.consumeAsEvent();
103107

@@ -122,6 +126,17 @@ export default class TraceLogParser {
122126
return section;
123127
}
124128

129+
parseTraversePlugin(section, higherSections) {
130+
const entry = this.consume();
131+
const plugin = new TraceSection('TraversePlugin:' + entry.data);
132+
133+
section.addEntry(plugin);
134+
135+
this.defaultParse(plugin, higherSections);
136+
137+
return plugin;
138+
}
139+
125140
parseCondition(section, higherSections) {
126141
const entry = this.consume();
127142
const condition = new TraceSection('Condition');

demos/tom/plugin-explorer-worker.js

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -149,44 +149,55 @@ self.onmessage = function(msg) {
149149

150150
config.plugins = config.plugins
151151
.map(plugin => decorateFunction(plugin, result => {
152-
if(result.pre) {
153-
const oldPre = result.pre;
154-
result.pre = function(path) {
155-
const oldTraverse = path.prototype.traverse;
156-
path.prototype.traverse = function() {
157-
trace.startTraversePlugin();
158-
oldTraverse(...arguments);
159-
trace.endTraversePlugin();
152+
const oldPre = result.pre;
153+
result.pre = function(state) {
154+
if(!state.preIsAlreadyDecorated) {
155+
const oldTraverse = state.path.__proto__.traverse;
156+
state.path.__proto__.traverse = function(visitors, ...rest) {
157+
const newVisitors = {};
158+
debugger
159+
for (const name in visitors) {
160+
if(typeof visitors[name] === 'function') {
161+
const fn = visitors[name];
162+
newVisitors[name] = function() {
163+
trace.startTraversePlugin(name);
164+
fn(...arguments);
165+
trace.endTraversePlugin(name);
166+
};
167+
} else {
168+
debugger
169+
}
170+
171+
}
172+
173+
visitors = newVisitors;
174+
175+
debugger
176+
oldTraverse.call(this, newVisitors, ...rest);
177+
160178
}
179+
state.preIsAlreadyDecorated = true;
180+
}
181+
182+
if(oldPre) {
161183
oldPre(...arguments);
162-
};
163-
} else {
164-
result.pre = function(path) {
165-
const oldTraverse = path.prototype.traverse;
166-
path.prototype.traverse = function() {
167-
trace.startTraversePlugin();
168-
oldTraverse(...arguments);
169-
trace.endTraversePlugin();
170-
}
171-
};
184+
}
185+
172186
}
173187
}));
174188

175189
trace.startTraversion();
176-
debugger
177190
const ast = babel.transform(msg.data.source, enumerationConfig(createTraceID)).ast;
178191
const oldASTAsString = JSON.stringify(ast);
179192

180193
wrapAST(ast, trace);
181194
let result
182-
try {
195+
//try {
183196
result = babel.transformFromAst(ast, undefined, config);
184-
} catch (e) {
197+
/*} catch (e) {
185198
result = null;
186199
trace.error(e);
187-
}
188-
189-
debugger
200+
}*/
190201

191202
const pluginsToUnload = Object.keys(System['@@registerRegistry']).filter(plugin => !
192203
preloadedPlugins.has(plugin));

demos/tom/trace.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,14 @@ export default class Trace {
148148
leavePlugin(name) {
149149
this.log(new Event('leavePlugin', name));
150150
}
151+
152+
startTraversePlugin() {
153+
this.log(new Event('enterTraversePlugin', name));
154+
}
155+
156+
endTraversePlugin() {
157+
this.log(new Event('leaveTraversePlugin', name));
158+
}
151159

152160
/* Functions */
153161

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/client/reactive/babel-plugin-active-expression-rewriting/index.js","options":{"autoUpdateAST":true,"autoUpdateTransformation":true,"autoExecute":true,"systemJS":false,"autoRunTests":false,"autoSaveWorkspace":false},"pluginSelection":[{"url":"https://lively-kernel.org/lively4/lively4-tom/src/client/reactive/babel-plugin-active-expression-rewriting/index.js"}]}
1+
{"source":"/src/components/tools/lively-ast-explorer-example-source.js","plugin":"https://lively-kernel.org/lively4/lively4-tom/demos/tom/playground.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/playground.js"}]}

0 commit comments

Comments
 (0)