refactor(js2dart): refactor dart library statement
fixes #12 closes #16
This commit is contained in:
parent
87dd88ff0c
commit
2cc1a4c354
|
@ -0,0 +1,3 @@
|
|||
function main() {
|
||||
assert(true);
|
||||
}
|
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue