Skip to content

Commit c7feaba

Browse files
committed
feat(DartWriter): support string interpolation
1 parent c85ab3a commit c7feaba

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

tools/transpiler/spec/lang_spec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import {describe, it, expect} from 'test_lib/test_lib';
2+
3+
export function main() {
4+
describe('lang', function() {
5+
it('string interpolation', function() {
6+
expect(`${123}-'${456}"`).toEqual('123-\'456"');
7+
});
8+
});
9+
}

tools/transpiler/src/dart_writer.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {CONSTRUCTOR, FROM} from 'traceur/src/syntax/PredefinedName';
2-
import {EQUAL_EQUAL_EQUAL, OPEN_PAREN, CLOSE_PAREN, IMPORT, SEMI_COLON, STAR, OPEN_CURLY, CLOSE_CURLY, COMMA, AT, EQUAL} from 'traceur/src/syntax/TokenType';
2+
import {EQUAL_EQUAL_EQUAL, OPEN_PAREN, CLOSE_PAREN, IMPORT, SEMI_COLON, STAR, OPEN_CURLY, CLOSE_CURLY, COMMA, AT,
3+
EQUAL, SINGLE_QUOTE} from 'traceur/src/syntax/TokenType';
34

45
import {ParseTreeWriter as JavaScriptParseTreeWriter} from 'traceur/src/outputgeneration/ParseTreeWriter';
56

@@ -37,6 +38,17 @@ export class DartTreeWriter extends JavaScriptParseTreeWriter {
3738
}
3839
}
3940

41+
visitTemplateLiteralExpression(tree) {
42+
if (tree.operand) {
43+
this.visitAny(tree.operand);
44+
this.writeSpace_();
45+
}
46+
this.writeRaw_(SINGLE_QUOTE);
47+
this.visitList(tree.elements);
48+
this.writeRaw_(SINGLE_QUOTE);
49+
}
50+
51+
4052
// FUNCTIONS
4153
// - remove the "function" keyword
4254
// - type annotation infront

0 commit comments

Comments
 (0)