2018-11-21 12:59:17 +03:00
|
|
|
use super::*;
|
|
|
|
|
2019-02-18 16:31:50 +03:00
|
|
|
test_exec!(
|
|
|
|
::swc_ecma_parser::Syntax::default(),
|
2019-06-03 15:54:09 +03:00
|
|
|
|_| TemplateLiteral::default(),
|
2019-02-18 16:31:50 +03:00
|
|
|
issue_231,
|
|
|
|
"const truthy = 'a=b';
|
|
|
|
const foo = `http://example.com/foo/bar${truthy && '?'}${truthy}`;
|
2019-02-18 16:34:32 +03:00
|
|
|
expect(foo).toBe('http://example.com/foo/bar?a=b');"
|
2019-02-18 16:31:50 +03:00
|
|
|
);
|
|
|
|
|
2019-06-03 15:54:09 +03:00
|
|
|
test_exec!(
|
|
|
|
::swc_ecma_parser::Syntax::default(),
|
|
|
|
|_| TemplateLiteral::default(),
|
|
|
|
issue_388,
|
|
|
|
"
|
|
|
|
'use strict';
|
|
|
|
const write = (text) => {
|
|
|
|
console.log(text)
|
|
|
|
}
|
|
|
|
write(1)
|
|
|
|
write('2')
|
|
|
|
write`3`"
|
|
|
|
);
|
|
|
|
|
2018-11-21 12:59:17 +03:00
|
|
|
test!(
|
2019-01-08 10:34:35 +03:00
|
|
|
::swc_ecma_parser::Syntax::default(),
|
2019-06-03 15:54:09 +03:00
|
|
|
|_| TemplateLiteral::default(),
|
2018-11-28 06:24:08 +03:00
|
|
|
escape_quotes,
|
|
|
|
r#"var t = `'${foo}' "${bar}"`;"#,
|
|
|
|
r#"var t = "'" + foo + '\' "' + bar + '"';"#,
|
|
|
|
ok_if_code_eq
|
2018-11-21 12:59:17 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
test!(
|
2019-01-08 10:34:35 +03:00
|
|
|
::swc_ecma_parser::Syntax::default(),
|
2019-06-03 15:54:09 +03:00
|
|
|
|_| TemplateLiteral::default(),
|
2018-11-28 06:24:08 +03:00
|
|
|
expr_first,
|
|
|
|
r#"var foo = 5;
|
2018-11-21 12:59:17 +03:00
|
|
|
var bar = 10;
|
|
|
|
var baz = 15;
|
|
|
|
|
|
|
|
var example = `${"a"}`;
|
|
|
|
var example2 = `${1}`;
|
|
|
|
var example3 = 1 + `${foo}${bar}${baz}`;
|
|
|
|
var example4 = 1 + `${foo}bar${baz}`;
|
|
|
|
var example5 = `${""}`;"#,
|
2018-11-28 06:24:08 +03:00
|
|
|
r#"var foo = 5;
|
2018-11-21 12:59:17 +03:00
|
|
|
var bar = 10;
|
|
|
|
var baz = 15;
|
|
|
|
var example = '' + 'a';
|
|
|
|
var example2 = '' + 1;
|
|
|
|
var example3 = 1 + '' + foo + bar + baz;
|
|
|
|
var example4 = 1 + '' + foo + 'bar' + baz;
|
|
|
|
var example5 = '' + '';"#,
|
2018-11-28 06:24:08 +03:00
|
|
|
ok_if_code_eq
|
2018-11-21 12:59:17 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
test!(
|
2019-01-08 10:34:35 +03:00
|
|
|
::swc_ecma_parser::Syntax::default(),
|
2019-06-03 15:54:09 +03:00
|
|
|
|_| TemplateLiteral::default(),
|
2018-11-28 06:24:08 +03:00
|
|
|
functions,
|
|
|
|
r#"var foo = `test ${_.test(foo)} ${bar}`;"#,
|
|
|
|
r#"var foo = 'test ' + _.test(foo) + ' ' + bar;"#
|
2018-11-21 12:59:17 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
test!(
|
2019-01-08 10:34:35 +03:00
|
|
|
::swc_ecma_parser::Syntax::default(),
|
2019-06-03 15:54:09 +03:00
|
|
|
|_| TemplateLiteral::default(),
|
2018-11-28 06:24:08 +03:00
|
|
|
literals,
|
|
|
|
r#"var foo = `${1}${f}oo${true}${b}ar${0}${baz}`;"#,
|
|
|
|
r#"var foo = '' + 1 + f + 'oo' + true + b + 'ar' + 0 + baz;"#
|
2018-11-21 12:59:17 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
test!(
|
2019-01-08 10:34:35 +03:00
|
|
|
::swc_ecma_parser::Syntax::default(),
|
2019-06-03 15:54:09 +03:00
|
|
|
|_| TemplateLiteral::default(),
|
2018-11-28 06:24:08 +03:00
|
|
|
multiline,
|
|
|
|
r#"var o = `wow
|
2018-11-21 12:59:17 +03:00
|
|
|
this is
|
|
|
|
actually multiline!`;"#,
|
2018-11-28 06:24:08 +03:00
|
|
|
r#"var o = "wow\nthis is\nactually multiline!";"#,
|
|
|
|
ok_if_code_eq
|
2018-11-21 12:59:17 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
test!(
|
2019-01-08 10:34:35 +03:00
|
|
|
::swc_ecma_parser::Syntax::default(),
|
2019-06-03 15:54:09 +03:00
|
|
|
|_| TemplateLiteral::default(),
|
2018-11-28 06:24:08 +03:00
|
|
|
multiple,
|
|
|
|
r#"var foo = `test ${foo} ${bar}`;"#,
|
|
|
|
r#"var foo = 'test ' + foo + ' ' + bar;"#
|
2018-11-21 12:59:17 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
test!(
|
2019-01-08 10:34:35 +03:00
|
|
|
::swc_ecma_parser::Syntax::default(),
|
2019-06-03 15:54:09 +03:00
|
|
|
|_| TemplateLiteral::default(),
|
2018-11-28 06:24:08 +03:00
|
|
|
none,
|
|
|
|
r#"var foo = `test`;"#,
|
|
|
|
r#"var foo = "test";"#
|
2018-11-21 12:59:17 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
test!(
|
2019-01-08 10:34:35 +03:00
|
|
|
::swc_ecma_parser::Syntax::default(),
|
2019-06-03 15:54:09 +03:00
|
|
|
|_| TemplateLiteral::default(),
|
2018-11-28 06:24:08 +03:00
|
|
|
only,
|
|
|
|
r#"var foo = `${test}`;"#,
|
|
|
|
r#"var foo = '' + test"#
|
2018-11-21 12:59:17 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
test_exec!(
|
2019-01-08 10:34:35 +03:00
|
|
|
::swc_ecma_parser::Syntax::default(),
|
2019-06-03 15:54:09 +03:00
|
|
|
|_| TemplateLiteral::default(),
|
2018-11-28 06:24:08 +03:00
|
|
|
order,
|
|
|
|
r#"
|
2018-11-21 12:59:17 +03:00
|
|
|
const calls = [];
|
|
|
|
|
|
|
|
`
|
|
|
|
${
|
|
|
|
(calls.push(1), {
|
|
|
|
[Symbol.toPrimitive](){
|
|
|
|
calls.push(2);
|
|
|
|
return 'foo';
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
${
|
|
|
|
(calls.push(3), {
|
|
|
|
[Symbol.toPrimitive](){
|
|
|
|
calls.push(4);
|
|
|
|
return 'bar';
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
expect(calls).toEqual([1, 2, 3, 4]);"#
|
|
|
|
);
|
|
|
|
|
|
|
|
test_exec!(
|
2019-01-08 10:34:35 +03:00
|
|
|
::swc_ecma_parser::Syntax::default(),
|
2019-06-03 15:54:09 +03:00
|
|
|
|_| TemplateLiteral::default(),
|
2018-11-28 06:24:08 +03:00
|
|
|
order2,
|
|
|
|
r#"const calls = [];
|
2018-11-21 12:59:17 +03:00
|
|
|
|
|
|
|
`
|
|
|
|
${{
|
|
|
|
[Symbol.toPrimitive]() {
|
|
|
|
calls.push(1);
|
|
|
|
return "foo";
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
${1 +
|
|
|
|
{
|
|
|
|
valueOf() {
|
|
|
|
calls.push(2);
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
`;
|
|
|
|
|
|
|
|
expect(calls).toEqual([1, 2]);"#
|
|
|
|
);
|
|
|
|
|
|
|
|
test!(
|
2019-01-08 10:34:35 +03:00
|
|
|
::swc_ecma_parser::Syntax::default(),
|
2019-06-03 15:54:09 +03:00
|
|
|
|_| TemplateLiteral::default(),
|
2018-11-28 06:24:08 +03:00
|
|
|
simple_tag,
|
|
|
|
r#"var foo = tag`wow`;
|
2018-11-21 12:59:17 +03:00
|
|
|
var bar = tag`first${1}second`;"#,
|
2019-06-03 15:54:09 +03:00
|
|
|
r#"
|
|
|
|
function _templateObject() {
|
2018-11-25 05:31:48 +03:00
|
|
|
const data = _taggedTemplateLiteral(['wow']);
|
|
|
|
_templateObject = function() {
|
|
|
|
return data;
|
|
|
|
};
|
2018-11-21 12:59:17 +03:00
|
|
|
return data;
|
2019-06-03 15:54:09 +03:00
|
|
|
}
|
|
|
|
var foo = tag(_templateObject());
|
|
|
|
function _templateObject1() {
|
2018-11-25 05:31:48 +03:00
|
|
|
const data = _taggedTemplateLiteral(['first', 'second']);
|
|
|
|
_templateObject1 = function() {
|
|
|
|
return data;
|
|
|
|
};
|
2018-11-21 12:59:17 +03:00
|
|
|
return data;
|
2019-06-03 15:54:09 +03:00
|
|
|
}
|
|
|
|
var bar = tag(_templateObject1(), 1);
|
2018-11-25 05:31:48 +03:00
|
|
|
"#
|
2018-11-21 12:59:17 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
test!(
|
2019-01-08 10:34:35 +03:00
|
|
|
::swc_ecma_parser::Syntax::default(),
|
2019-06-03 15:54:09 +03:00
|
|
|
|_| TemplateLiteral::default(),
|
2018-11-28 06:24:08 +03:00
|
|
|
single,
|
|
|
|
r#"var foo = `test ${foo}`;"#,
|
|
|
|
r#"var foo = 'test ' + foo;"#
|
2018-11-21 12:59:17 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
test!(
|
2019-01-08 10:34:35 +03:00
|
|
|
::swc_ecma_parser::Syntax::default(),
|
2019-06-03 15:54:09 +03:00
|
|
|
|_| TemplateLiteral::default(),
|
2018-11-28 06:24:08 +03:00
|
|
|
statement,
|
|
|
|
r#"var foo = `test ${foo + bar}`;"#,
|
|
|
|
r#"var foo = 'test ' + foo + bar;"#,
|
|
|
|
ok_if_code_eq
|
2018-11-21 12:59:17 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
test_exec!(
|
2019-01-08 10:34:35 +03:00
|
|
|
::swc_ecma_parser::Syntax::default(),
|
2019-06-03 15:54:09 +03:00
|
|
|
|_| TemplateLiteral::default(),
|
2018-11-28 06:24:08 +03:00
|
|
|
symbol,
|
|
|
|
r#"const fn = () => `${Symbol()}`;
|
2018-11-21 12:59:17 +03:00
|
|
|
|
|
|
|
expect(fn).toThrow(TypeError);"#
|
|
|
|
);
|
|
|
|
|
|
|
|
test!(
|
2019-01-08 10:34:35 +03:00
|
|
|
::swc_ecma_parser::Syntax::default(),
|
2019-06-03 15:54:09 +03:00
|
|
|
|_| TemplateLiteral::default(),
|
2018-11-28 06:24:08 +03:00
|
|
|
tag,
|
|
|
|
r#"
|
2018-11-21 12:59:17 +03:00
|
|
|
var foo = bar`wow\na${ 42 }b ${_.foobar()}`;
|
|
|
|
var bar = bar`wow\nab${ 42 } ${_.foobar()}`;
|
|
|
|
var bar = bar`wow\naB${ 42 } ${_.baz()}`;
|
|
|
|
"#,
|
2019-06-03 15:54:09 +03:00
|
|
|
r#"
|
|
|
|
function _templateObject() {
|
2018-11-25 05:31:48 +03:00
|
|
|
const data = _taggedTemplateLiteral(['wow\na', 'b ', ''], ['wow\\na', 'b ', '']);
|
|
|
|
_templateObject = function() {
|
|
|
|
return data;
|
|
|
|
};
|
2018-11-21 12:59:17 +03:00
|
|
|
return data;
|
2019-06-03 15:54:09 +03:00
|
|
|
}
|
|
|
|
var foo = bar(_templateObject(), 42, _.foobar());
|
|
|
|
function _templateObject1() {
|
2018-11-25 05:31:48 +03:00
|
|
|
const data = _taggedTemplateLiteral(['wow\nab', ' ', ''], ['wow\\nab', ' ', '']);
|
|
|
|
_templateObject1 = function() {
|
|
|
|
return data;
|
|
|
|
};
|
2018-11-21 12:59:17 +03:00
|
|
|
return data;
|
2019-06-03 15:54:09 +03:00
|
|
|
}
|
|
|
|
var bar = bar(_templateObject1(), 42, _.foobar());
|
|
|
|
function _templateObject2() {
|
2018-11-25 05:31:48 +03:00
|
|
|
const data = _taggedTemplateLiteral(['wow\naB', ' ', ''], ['wow\\naB', ' ', '']);
|
|
|
|
_templateObject2 = function() {
|
|
|
|
return data;
|
|
|
|
};
|
2018-11-21 12:59:17 +03:00
|
|
|
return data;
|
2019-06-03 15:54:09 +03:00
|
|
|
}
|
|
|
|
var bar = bar(_templateObject2(), 42, _.baz());
|
|
|
|
"#,
|
2018-11-28 06:24:08 +03:00
|
|
|
ok_if_code_eq
|
2018-11-21 12:59:17 +03:00
|
|
|
);
|
|
|
|
|
2018-11-25 05:31:48 +03:00
|
|
|
// TODO: Fix parser
|
2018-11-21 12:59:17 +03:00
|
|
|
test!(
|
2018-11-28 06:24:08 +03:00
|
|
|
ignore,
|
2019-01-08 10:34:35 +03:00
|
|
|
::swc_ecma_parser::Syntax::default(),
|
2019-06-03 15:54:09 +03:00
|
|
|
|_| TemplateLiteral::default(),
|
2018-11-28 06:24:08 +03:00
|
|
|
template_revision,
|
|
|
|
r#"tag`\unicode and \u{55}`;
|
2018-11-21 12:59:17 +03:00
|
|
|
tag`\01`;
|
|
|
|
tag`\xg${0}right`;
|
|
|
|
tag`left${0}\xg`;
|
|
|
|
tag`left${0}\xg${1}right`;
|
|
|
|
tag`left${0}\u000g${1}right`;
|
|
|
|
tag`left${0}\u{-0}${1}right`;
|
|
|
|
function a() {
|
|
|
|
var undefined = 4;
|
|
|
|
tag`\01`;
|
|
|
|
}"#,
|
2018-11-28 06:24:08 +03:00
|
|
|
r#"
|
2018-11-21 12:59:17 +03:00
|
|
|
function _templateObject8() {
|
|
|
|
const data = _taggedTemplateLiteral([void 0], ["\\01"]);
|
|
|
|
|
|
|
|
_templateObject8 = function () {
|
|
|
|
return data;
|
|
|
|
};
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
function _templateObject7() {
|
|
|
|
const data = _taggedTemplateLiteral(["left", void 0, "right"], ["left", "\\u{-0}", "right"]);
|
|
|
|
|
|
|
|
_templateObject7 = function () {
|
|
|
|
return data;
|
|
|
|
};
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
function _templateObject6() {
|
|
|
|
const data = _taggedTemplateLiteral(["left", void 0, "right"], ["left", "\\u000g", "right"]);
|
|
|
|
|
|
|
|
_templateObject6 = function () {
|
|
|
|
return data;
|
|
|
|
};
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
function _templateObject5() {
|
|
|
|
const data = _taggedTemplateLiteral(["left", void 0, "right"], ["left", "\\xg", "right"]);
|
|
|
|
|
|
|
|
_templateObject5 = function () {
|
|
|
|
return data;
|
|
|
|
};
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
function _templateObject4() {
|
|
|
|
const data = _taggedTemplateLiteral(["left", void 0], ["left", "\\xg"]);
|
|
|
|
|
|
|
|
_templateObject4 = function () {
|
|
|
|
return data;
|
|
|
|
};
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
function _templateObject3() {
|
|
|
|
const data = _taggedTemplateLiteral([void 0, "right"], ["\\xg", "right"]);
|
|
|
|
|
|
|
|
_templateObject3 = function () {
|
|
|
|
return data;
|
|
|
|
};
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
function _templateObject2() {
|
|
|
|
const data = _taggedTemplateLiteral([void 0], ["\\01"]);
|
|
|
|
|
|
|
|
_templateObject2 = function () {
|
|
|
|
return data;
|
|
|
|
};
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
function _templateObject() {
|
|
|
|
const data = _taggedTemplateLiteral([void 0], ["\\unicode and \\u{55}"]);
|
|
|
|
|
|
|
|
_templateObject = function () {
|
|
|
|
return data;
|
|
|
|
};
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
tag(_templateObject());
|
|
|
|
tag(_templateObject2());
|
|
|
|
tag(_templateObject3(), 0);
|
|
|
|
tag(_templateObject4(), 0);
|
|
|
|
tag(_templateObject5(), 0, 1);
|
|
|
|
tag(_templateObject6(), 0, 1);
|
|
|
|
tag(_templateObject7(), 0, 1);
|
|
|
|
|
|
|
|
function a() {
|
|
|
|
var undefined = 4;
|
|
|
|
tag(_templateObject8());
|
|
|
|
}"#
|
|
|
|
);
|