rollup0.49.1 issue
ShiMeiWo opened this issue · 2 comments
ShiMeiWo commented
Hello.
I have been enjoying to use this plugin with rollup-riot. But I got wrong transpilation since rollup.js was updated from 0.48 to 0.49.1.
My rollup.config.js is:
import nodeResolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import nodent from 'rollup-plugin-nodent';
import riot from 'rollup-plugin-riot';
export default {
input: 'src/scripts/Main.js',
output:{
file: 'public/index.js',
format: 'iife',
sourcemap: true,
},
plugins: [
riot({
ext:'.tag.html',
}),
nodeResolve({ jsnext: true }),
commonjs(),
nodent({
extensions:['.js', '.tag.html'],
sourcemap:true,
promises: true,
noRuntime: true,
}),
],
}
and the source code is:
<test>
<div>
test tag
<div class="inner">
inner
</div>
</div>
<script>
async function lazy(param) {
return new Promise((resolve)=> {
setTimeout(resolve, param);
});
}
async function awaiter() {
await lazy(4500);
console.log('A!');
await lazy(1000);
console.log('B!');
}
awaiter();
</script>
</test>
rollup.js 0.48 transpiles it into:
riot$1.tag2('test', '<div> test tag <div class="inner"> inner </div> </div>', '', '', function (opts) {
function lazy(param) {
return new Promise((function ($return, $error) {
return $return(new Promise(function (resolve) {
setTimeout(resolve, param);
}));
}).bind(this));
}
function awaiter() {
return new Promise((function ($return, $error) {
return lazy(4500).then((function ($await_1) {
try {
console.log('A!');
return lazy(1000).then((function ($await_2) {
try {
console.log('B!');
return $return();
} catch ($boundEx) {
return $error($boundEx);
}
}).bind(this), $error);
} catch ($boundEx) {
return $error($boundEx);
}
}).bind(this), $error);
}).bind(this));
}
awaiter();
});
rollup.js 0.49.1 transpiles it into:
riot$1.tag2('test', '<div> test tag <div class="inner"> inner </div> </div>', '', '', function (opts) {
});
Next, I tried the source code:
<test>
<div>
test tag
<div class="inner">
inner
</div>
</div>
<script>
console.log('aaa');
</script>
</test>
Then the result was:
riot$1.tag2('test', '<div> test tag <div class="inner"> inner </div> </div>', '', '', function (opts) {
console.log('aaa');
});
The issue may not be caused by rollup-plugin-nodent, I'm glad to check it when you're available.
Thanks!
ShiMeiWo commented
This issue got resolved.
I received "not-overtreeshaked" code when I rewrote my source code to:
<test>
<div>
test tag
<div class="inner">
inner
</div>
</div>
<script>
var tag = this;
// function declarations changed into Function objects and set them as "this" properties.
tag.lazy = async function(param) {
return new Promise((resolve)=> {
setTimeout(resolve, param);
});
}
tag.awaiter = async function() {
await tag.lazy(4500);
console.log('A!');
await tag.lazy(1000);
console.log('B!');
}
tag.awaiter();
</script>
</test>
and transpiled it with rollup0.49.2. (not 0.49.1)
Sorry to trouble you.
oligot commented
No problem.
I'm glad you were able to solve the problem.