Closed
Description
Hello,
swc+webpack got our compilation times for debug builds down to ~3s from ~7s, which makes hitting F5 after a change much less frustrating! Thanks!
However, it breaks our use of tagged template literals for i18n. Setting target: "es2019" avoids the broken transformation, but there's still a bug somewhere.
cat test.js
:
export function foo() {
console.log(i18n`Hello World`);
console.log(i18n`Nobody will ever see this.`);
}
npx swc --no-swcrc test.js
function _taggedTemplateLiteral(strings, raw) {
if (!raw) {
raw = strings.slice(0);
}
return Object.freeze(Object.defineProperties(strings, {
raw: {
value: Object.freeze(raw)
}
}));
}
function _templateObject() {
var data = _taggedTemplateLiteral([
'Hello World'
]);
_templateObject = function _templateObject() {
return data;
};
return data;
}
function _templateObject1() {
var data = _taggedTemplateLiteral([
'Nobody will ever see this.'
]);
_templateObject1 = function _templateObject1() {
return data;
};
return data;
}
export function foo() {
console.log(i18n(_templateObject()));
console.log(i18n(_templateObject()));
}
Note the last line, where it should use _templateObject1()
, but uses _templateObject()
again. Consequently, if we insert an implementation of i18n() and call foo(), running the transformed function says Hello World
twice.
Note that the bug only appears in export
ed functions.