Skip to content

Commit

Permalink
Merge d577c45 into 8f28bb1
Browse files Browse the repository at this point in the history
  • Loading branch information
Raynos committed May 6, 2015
2 parents 8f28bb1 + d577c45 commit 43811a2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
27 changes: 25 additions & 2 deletions compile.js
@@ -1,6 +1,6 @@
var template = require("./index")
var escape = require("js-string-escape")

var whitespaceRegex = /["'\\\n\r\u2028\u2029]/g
var nargs = /\{[0-9a-zA-Z]+\}/g

var replaceTemplate =
Expand Down Expand Up @@ -115,6 +115,29 @@ function compile(string, inline) {
}
}

function inlineConcat(token) {
function escape(string) {
string = '' + string;

return string.replace(whitespaceRegex, escapedWhitespace);
}

function escapedWhitespace(character) {
// Escape all characters not included in SingleStringCharacters and
// DoubleStringCharacters on
// http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.4
switch (character) {
case '"':
case "'":
case '\\':
return '\\' + character
// Four possible LineTerminator characters need to be escaped:
case '\n':
return '\\n'
case '\r':
return '\\r'
case '\u2028':
return '\\u2028'
case '\u2029':
return '\\u2029'
}
}
4 changes: 1 addition & 3 deletions package.json
Expand Up @@ -22,9 +22,7 @@
"url": "https://github.com/Matt-Esch/string-template/issues",
"email": "matt@mattesch.info"
},
"dependencies": {
"js-string-escape": "~1.0.0"
},
"dependencies": {},
"devDependencies": {
"tape": "~1.1.1"
},
Expand Down

0 comments on commit 43811a2

Please sign in to comment.