support raw property on tagged template literals - closes #164
This commit is contained in:
parent
85c2de57e4
commit
9fb8a80f60
@ -18,7 +18,8 @@ function File(opts) {
|
||||
this.ast = {};
|
||||
}
|
||||
|
||||
File.declarations = ["extends", "class-props", "slice", "apply-constructor"];
|
||||
File.declarations = ["extends", "class-props", "slice", "apply-constructor",
|
||||
"tagged-template-literal"];
|
||||
|
||||
File.normaliseOptions = function (opts) {
|
||||
opts = _.cloneDeep(opts || {});
|
||||
|
||||
4
lib/6to5/templates/tagged-template-literal.js
Normal file
4
lib/6to5/templates/tagged-template-literal.js
Normal file
@ -0,0 +1,4 @@
|
||||
(function (strings, raw) {
|
||||
return Object.defineProperties(strings, { raw: { value: raw } });
|
||||
});
|
||||
|
||||
@ -1,18 +1,27 @@
|
||||
var t = require("../../types");
|
||||
var _ = require("lodash");
|
||||
var util = require("../../util");
|
||||
var t = require("../../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
var buildBinaryExpression = function (left, right) {
|
||||
return t.binaryExpression("+", left, right);
|
||||
};
|
||||
|
||||
exports.TaggedTemplateExpression = function (node) {
|
||||
exports.TaggedTemplateExpression = function (node, parent, file) {
|
||||
var args = [];
|
||||
var quasi = node.quasi;
|
||||
|
||||
var strings = quasi.quasis.map(function (elem) {
|
||||
return t.literal(elem.value.raw);
|
||||
var strings = [];
|
||||
var raw = [];
|
||||
|
||||
_.each(quasi.quasis, function (elem) {
|
||||
strings.push(t.literal(elem.value.cooked));
|
||||
raw.push(t.literal(elem.value.raw));
|
||||
});
|
||||
args.push(t.arrayExpression(strings));
|
||||
|
||||
args.push(t.callExpression(file.addDeclaration("tagged-template-literal"), [
|
||||
t.arrayExpression(strings),
|
||||
t.arrayExpression(raw)
|
||||
]));
|
||||
|
||||
_.each(quasi.expressions, function (expr) {
|
||||
args.push(expr);
|
||||
|
||||
@ -1 +1 @@
|
||||
var foo = bar`a${ 42 }b ${_.foobar()}`;
|
||||
var foo = bar`wow\na${ 42 }b ${_.foobar()}`;
|
||||
|
||||
@ -1,3 +1,11 @@
|
||||
"use strict";
|
||||
|
||||
var foo = bar(["a", "b ", ""], 42, _.foobar());
|
||||
var _taggedTemplateLiteral = function (strings, raw) {
|
||||
return Object.defineProperties(strings, {
|
||||
raw: {
|
||||
value: raw
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var foo = bar(_taggedTemplateLiteral(["wow\na", "b ", ""], ["wow\\na", "b ", ""]), 42, _.foobar());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user