refactor(js2dart): use the parent functionalities as mush as possible
Closes #18
This commit is contained in:
parent
2cc1a4c354
commit
a75a3d0b31
|
@ -9,26 +9,30 @@ import {
|
||||||
} from 'traceur/src/Options';
|
} from 'traceur/src/Options';
|
||||||
|
|
||||||
export class Compiler extends TraceurCompiler {
|
export class Compiler extends TraceurCompiler {
|
||||||
|
|
||||||
constructor(options, sourceRoot) {
|
constructor(options, sourceRoot) {
|
||||||
super(options, sourceRoot);
|
super(options, sourceRoot);
|
||||||
}
|
}
|
||||||
compile(source, filename) {
|
|
||||||
var parsed = this.parse(source, filename || '<unknown_file>');
|
transform(tree, moduleName = undefined) {
|
||||||
if (this.options_.outputLanguage === 'dart') {
|
if (this.options_.outputLanguage.toLowerCase() === 'dart') {
|
||||||
return this.writeDart(this.transformDart(parsed), filename);
|
var transformer = new ClassTransformer();
|
||||||
|
return transformer.transformAny(tree);
|
||||||
} else {
|
} else {
|
||||||
return this.write(this.transform(parsed));
|
return super(tree, moduleName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
transformDart(tree) {
|
|
||||||
var transformer = new ClassTransformer();
|
write(tree, outputName = undefined, sourceRoot = undefined) {
|
||||||
return transformer.transformAny(tree);
|
if (this.options_.outputLanguage.toLowerCase() === 'dart') {
|
||||||
}
|
var writer = new DartTreeWriter(outputName);
|
||||||
writeDart(tree, filename) {
|
writer.visitAny(tree);
|
||||||
var writer = new DartTreeWriter(this.resolveModuleName(filename));
|
return writer.toString();
|
||||||
writer.visitAny(tree);
|
} else {
|
||||||
return writer.toString();
|
return super.write(tree, outputName, sourceRoot);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy of the original method to use our custom Parser
|
// Copy of the original method to use our custom Parser
|
||||||
parse(content, sourceName) {
|
parse(content, sourceName) {
|
||||||
if (!content) {
|
if (!content) {
|
||||||
|
|
|
@ -9,14 +9,10 @@ export class Parser extends TraceurParser {
|
||||||
constructor(file, errorReporter = new SyntaxErrorReporter()) {
|
constructor(file, errorReporter = new SyntaxErrorReporter()) {
|
||||||
super(file, errorReporter);
|
super(file, errorReporter);
|
||||||
}
|
}
|
||||||
|
|
||||||
parseTypeName_() {
|
parseTypeName_() {
|
||||||
// Copy of original implementation
|
// Copy of original implementation
|
||||||
var start = this.getTreeStartLocation_();
|
var typeName = super.parseTypeName_();
|
||||||
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 next = this.peekType_();
|
var next = this.peekType_();
|
||||||
// Generics support
|
// Generics support
|
||||||
if (this.eatIf_(OPEN_ANGLE)) {
|
if (this.eatIf_(OPEN_ANGLE)) {
|
||||||
|
@ -29,6 +25,7 @@ export class Parser extends TraceurParser {
|
||||||
}
|
}
|
||||||
return typeName;
|
return typeName;
|
||||||
}
|
}
|
||||||
|
|
||||||
parseImportSpecifier_() {
|
parseImportSpecifier_() {
|
||||||
// Copy of original implementation
|
// Copy of original implementation
|
||||||
var start = this.getTreeStartLocation_();
|
var start = this.getTreeStartLocation_();
|
||||||
|
@ -38,7 +35,7 @@ export class Parser extends TraceurParser {
|
||||||
var name = this.eatIdName_();
|
var name = this.eatIdName_();
|
||||||
// Support for wraps keywoard
|
// Support for wraps keywoard
|
||||||
if (this.peekToken_().value === WRAPS) {
|
if (this.peekToken_().value === WRAPS) {
|
||||||
var token = this.nextToken_();
|
token = this.nextToken_();
|
||||||
var wrappedIdentifier = this.eatId_();
|
var wrappedIdentifier = this.eatId_();
|
||||||
// TODO: Save the fact that this is a wrapper type and
|
// TODO: Save the fact that this is a wrapper type and
|
||||||
// also the wrapped type
|
// also the wrapped type
|
||||||
|
@ -53,9 +50,10 @@ export class Parser extends TraceurParser {
|
||||||
}
|
}
|
||||||
return new ImportSpecifier(this.getTreeLocation_(start), binding, name);
|
return new ImportSpecifier(this.getTreeLocation_(start), binding, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
parseObjectType_() {
|
parseObjectType_() {
|
||||||
//TODO(misko): save the type information
|
//TODO(misko): save the type information
|
||||||
this.eat_(OPEN_CURLY)
|
this.eat_(OPEN_CURLY);
|
||||||
do {
|
do {
|
||||||
var identifier = this.eatId_();
|
var identifier = this.eatId_();
|
||||||
this.eat_(COLON);
|
this.eat_(COLON);
|
||||||
|
|
Loading…
Reference in New Issue