Skip to content

Commit 36ffe1a

Browse files
committed
Pull methods out of definitions
1 parent 03e8f08 commit 36ffe1a

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/editor/extended_python_generator.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ import * as commonStorage from '../storage/common_storage';
3131
export class ExtendedPythonGenerator extends PythonGenerator {
3232
private currentModule: commonStorage.Module | null = null;
3333
private mapWorkspaceIdToExportedBlocks: { [key: string]: Block[] } = Object.create(null);
34+
protected methods_: {[key: string]: string} = Object.create(null);
35+
3436

3537
constructor() {
3638
super('Python');
@@ -159,7 +161,7 @@ export class ExtendedPythonGenerator extends PythonGenerator {
159161
this.definitions_['import_' + importModule] = 'import ' + importModule;
160162
}
161163
addMethod(methodName: string, code : string): void {
162-
this.definitions_['%' + methodName] = code;
164+
this.methods_[methodName] = code;
163165
}
164166

165167
classParentFromModuleType(moduleType : string) : string{
@@ -189,19 +191,24 @@ export class ExtendedPythonGenerator extends PythonGenerator {
189191
// Convert the definitions dictionary into a list.
190192
const imports = [];
191193
const definitions = [];
192-
const methods = [];
194+
193195
for (let name in this.definitions_) {
194196
const def = this.definitions_[name];
195197
if (def.match(/^(from\s+\S+\s+)?import\s+\S+/)) {
196198
imports.push(def);
197-
} else if (name.match(/^%.*/)){
198-
methods.push(def);
199199
} else{
200200
definitions.push(def);
201201
}
202202
}
203+
const methods = [];
204+
for (let name in this.methods_){
205+
methods.push(this.methods_[name])
206+
}
207+
203208
this.definitions_ = Object.create(null);
204209
this.functionNames_ = Object.create(null);
210+
this.methods_ = Object.create(null);
211+
205212
this.isInitialized = false;
206213

207214
let class_def = "class " + className + "(" + classParent + "):\n";

0 commit comments

Comments
 (0)