fix(build): Escape dollar signs in dart-transpiled string literals
Escape dollar signs in string literals - dart should not interpolate them. Closes #509
This commit is contained in:
parent
9f6b6cc50c
commit
93c18f5396
@ -99,9 +99,15 @@ export class DartParseTreeWriter extends JavaScriptParseTreeWriter {
|
||||
}
|
||||
|
||||
visitTemplateLiteralPortion(tree) {
|
||||
this.writeRaw_(tree.value.toString().replace(/('|")/g, "\\$&"));
|
||||
this.writeRaw_(tree.value.toString()
|
||||
.replace(/('|")/g, "\\$&")
|
||||
.replace(/([^\\])\$/g, "$1\\\$")
|
||||
.replace(/^\$/, '\\\$'));
|
||||
}
|
||||
|
||||
visitLiteralExpression(tree) {
|
||||
this.write_(('' + tree.literalToken).replace(/([^\\])\$/g, "$1\\\$"));
|
||||
}
|
||||
|
||||
// FUNCTIONS
|
||||
// - remove the "function" keyword
|
||||
|
@ -13,15 +13,38 @@ var OPTIONS = {
|
||||
describe('transpile to dart', function(){
|
||||
|
||||
// https://github.com/angular/angular/issues/509
|
||||
it('should not interpolate inside old quotes', function(){
|
||||
var result = compiler.compile(OPTIONS, "test.js",
|
||||
"var a = 1;" +
|
||||
"var s1 = '${a}';" +
|
||||
"var s2 = `${a}`;");
|
||||
expect(result.js).toBe("library test;\n" +
|
||||
"var a = 1;\n" +
|
||||
// FIXME: this should escape the interpolation with backslash to fix the issue
|
||||
"var s1 = '${a}';\n" +
|
||||
"var s2 = '''${a}''';\n");
|
||||
})
|
||||
describe('string interpolation', function() {
|
||||
it('should not interpolate inside old quotes', function(){
|
||||
var result = compiler.compile(OPTIONS, "test.js",
|
||||
"var a:number = 1;" +
|
||||
"var s1:string = \"${a}\";" +
|
||||
"var s2:string = '\\${a}';" +
|
||||
"var s3:string = '$a';");
|
||||
expect(result.js).toBe("library test;\n" +
|
||||
"num a = 1;\n" +
|
||||
"String s1 = \"\\${a}\";\n" +
|
||||
"String s2 = '\\${a}';\n" +
|
||||
"String s3 = '\\$a';\n");
|
||||
});
|
||||
|
||||
it('should not interpolate without curly braces', function() {
|
||||
var result = compiler.compile(OPTIONS, "test.js",
|
||||
"var a:number = 1;" +
|
||||
"var s1:string = `$a`;" +
|
||||
"var s2:string = `\\$a`;");
|
||||
expect(result.js).toBe("library test;\n" +
|
||||
"num a = 1;\n" +
|
||||
"String s1 = '''\\$a''';\n" +
|
||||
"String s2 = '''\\$a''';\n");
|
||||
});
|
||||
|
||||
it('should interpolate inside template quotes', function() {
|
||||
var result = compiler.compile(OPTIONS, "test.js",
|
||||
"var a:number = 1;" +
|
||||
"var s1:string = `${a}`;");
|
||||
expect(result.js).toBe("library test;\n" +
|
||||
"num a = 1;\n" +
|
||||
"String s1 = '''${a}''';\n");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user