refactor(js2dart): use the parent functionalities as mush as possible

Closes #18
This commit is contained in:
Victor Berchet 2014-09-26 13:26:11 +02:00 committed by Tobias Bosch
parent 2cc1a4c354
commit a75a3d0b31
2 changed files with 23 additions and 21 deletions

View File

@ -9,26 +9,30 @@ import {
} from 'traceur/src/Options';
export class Compiler extends TraceurCompiler {
constructor(options, sourceRoot) {
super(options, sourceRoot);
}
compile(source, filename) {
var parsed = this.parse(source, filename || '<unknown_file>');
if (this.options_.outputLanguage === 'dart') {
return this.writeDart(this.transformDart(parsed), filename);
} else {
return this.write(this.transform(parsed));
}
}
transformDart(tree) {
transform(tree, moduleName = undefined) {
if (this.options_.outputLanguage.toLowerCase() === 'dart') {
var transformer = new ClassTransformer();
return transformer.transformAny(tree);
} else {
return super(tree, moduleName);
}
writeDart(tree, filename) {
var writer = new DartTreeWriter(this.resolveModuleName(filename));
}
write(tree, outputName = undefined, sourceRoot = undefined) {
if (this.options_.outputLanguage.toLowerCase() === 'dart') {
var writer = new DartTreeWriter(outputName);
writer.visitAny(tree);
return writer.toString();
} else {
return super.write(tree, outputName, sourceRoot);
}
}
// Copy of the original method to use our custom Parser
parse(content, sourceName) {
if (!content) {

View File

@ -9,14 +9,10 @@ export class Parser extends TraceurParser {
constructor(file, errorReporter = new SyntaxErrorReporter()) {
super(file, errorReporter);
}
parseTypeName_() {
// Copy of original implementation
var start = this.getTreeStartLocation_();
var typeName = new TypeName(this.getTreeLocation_(start), null, this.eatId_());
while (this.eatIf_(PERIOD)) {
var memberName = this.eatIdName_();
typeName = new TypeName(this.getTreeLocation_(start), typeName, memberName);
}
var typeName = super.parseTypeName_();
var next = this.peekType_();
// Generics support
if (this.eatIf_(OPEN_ANGLE)) {
@ -29,6 +25,7 @@ export class Parser extends TraceurParser {
}
return typeName;
}
parseImportSpecifier_() {
// Copy of original implementation
var start = this.getTreeStartLocation_();
@ -38,7 +35,7 @@ export class Parser extends TraceurParser {
var name = this.eatIdName_();
// Support for wraps keywoard
if (this.peekToken_().value === WRAPS) {
var token = this.nextToken_();
token = this.nextToken_();
var wrappedIdentifier = this.eatId_();
// TODO: Save the fact that this is a wrapper type and
// also the wrapped type
@ -53,9 +50,10 @@ export class Parser extends TraceurParser {
}
return new ImportSpecifier(this.getTreeLocation_(start), binding, name);
}
parseObjectType_() {
//TODO(misko): save the type information
this.eat_(OPEN_CURLY)
this.eat_(OPEN_CURLY);
do {
var identifier = this.eatId_();
this.eat_(COLON);