Skip to content

Instantly share code, notes, and snippets.

@tuchida
Created February 23, 2014 03:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuchida/9166234 to your computer and use it in GitHub Desktop.
Save tuchida/9166234 to your computer and use it in GitHub Desktop.
heredoc macro
macro <<EOS {
case { $_ } => {
var comments = #{$_}[0].token.leadingComments;
var text = '';
if (comments) {
text = comments.map(function(c) {
return c.type === 'Block' ? c.value.replace(/^(\r\n|\n|\r)/, '').replace(/(\r\n|\n|\r)$/, '') : c.value;
}).join('\r\n');
}
return [makeValue(text, #{here})];
}
}
console.log(/*
abcdefg
hijklmn
あいうえお
*/<<EOS);
console.log(<<EOS);
console.log(
//abcdefg
//hijklmn
//あいうえお
<<EOS);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment