This library aims to provide codegen helpers and data structure for Vue language plugin API v1.x that does not depend on Volar runtime.
Why "Muggle"?
A better situation is Volar can use magic-string on the Vue plugin API, but currently can't do this easily.
This solution is just for Vue language plugin API v1.x and planned to be deprecate in v2.
Usage
The example is base-on magic-string readme.
<script>problems = 99</script>
<more-script lang="js">console.log( answer )</more-script>
import {
toString,
replace,
} from 'muggle-string';
const plugin = () => {
return {
name: 'example-vue-language-plugin',
version: 1,
resolveEmbeddedFile(fileName, sfc, embeddedFile) {
if (embeddedFile.fileName.replace(fileName, '').match(/^\.(js|ts|jsx|tsx)$/)) {
const s = embeddedFile.content;
toString(s);
replace(s, 'problems', 'answer');
toString(s);
replace(s, '99', '42');
toString(s);
s.unshift('var ');
s.push(';');
toString(s);
for (const block of sfc.customBlocks) {
if (block.type === 'more-script') {
s.push([
block.content,
block.name,
0,
{
hover: true,
references: true,
definition: true,
diagnostic: true,
rename: true,
completion: true,
semanticTokens: true,
},
]);
toString(s);
}
}
}
}
};
};
module.exports = plugin;