refactor(js2dart): refactor dart library statement

fixes #12
closes #16
This commit is contained in:
Victor Berchet 2014-09-26 09:23:11 +02:00 committed by Tobias Bosch
parent 87dd88ff0c
commit 2cc1a4c354
3 changed files with 17 additions and 7 deletions

View File

@ -0,0 +1,3 @@
function main() {
assert(true);
}

View File

@ -25,14 +25,9 @@ export class Compiler extends TraceurCompiler {
return transformer.transformAny(tree);
}
writeDart(tree, filename) {
var writer = new DartTreeWriter();
var writer = new DartTreeWriter(this.resolveModuleName(filename));
writer.visitAny(tree);
// TODO: Do this in the writer...
var library = this.resolveModuleName(filename)
.replace(/\//g, '.')
.replace('.lib.', '.')
.replace(/\.dart$/, '');
return 'library ' + library + ';\n' + writer.toString();
return writer.toString();
}
// Copy of the original method to use our custom Parser
parse(content, sourceName) {

View File

@ -4,6 +4,14 @@ import {EQUAL_EQUAL_EQUAL, OPEN_PAREN, CLOSE_PAREN, IMPORT, SEMI_COLON, STAR, OP
import {ParseTreeWriter as JavaScriptParseTreeWriter} from 'traceur/src/outputgeneration/ParseTreeWriter';
export class DartTreeWriter extends JavaScriptParseTreeWriter {
constructor(moduleName) {
super();
this.libName = moduleName
.replace(/\//g, '.')
.replace(/[^\w.]/, '_')
.replace('.lib.', '.')
.replace(/\.dart$/, '');
}
// VARIABLES - types
// ```
@ -237,5 +245,9 @@ export class DartTreeWriter extends JavaScriptParseTreeWriter {
this.writeSpace_()
}
toString() {
return "library " + this.libName + ";\n" + super.toString();
}
}