Skip to content

Instantly share code, notes, and snippets.

@retorquere
Created July 19, 2021 19:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save retorquere/4772339a5f6f3b0d55797397e09573c4 to your computer and use it in GitHub Desktop.
Save retorquere/4772339a5f6f3b0d55797397e09573c4 to your computer and use it in GitHub Desktop.
module.exports.fix = (path) => {
path.node.value.raw = '\n';
};
module.exports.traverse = ({push}) => ({
TemplateLiteral(path) {
const [start] = path.node.quasis;
if (/^\n\s+/.test(start.value.raw))
push(path.get('quasis.0'));
}
});
export function set(extra) {
extra += `
${prefix}${casing[field] || field}
${value.raw ? "=" : ":"}
${value.value}`;
return extra;
}
const fs = require('fs')
const putout = require('putout')
async function trace(source, target) {
const estrace = await import('estrace/plugin');
const newLine = await import('./setup/loaders/putout-new-line-plugin.js');
const {code} = putout(await fs.promises.readFile(source, 'utf-8'), {
fixCount: 1,
rules: {
estrace: ['on', { url: 'inline', exclude: [ 'FunctionExpression', 'ArrowFunctionExpression' ] }]
},
plugins: [
[ 'estrace', estrace ],
[ 'new-line', newLine ],
],
})
await fs.promises.writeFile(target, code)
}
async function main() {
await trace('source.js', 'traced.js')
}
main()
export function set(extra) {
try {
__estrace.enter('set', 'inline:1', arguments);
extra += `
${prefix}${casing[field] || field}
${value.raw ? "=" : ":"}
${value.value}`;
return extra;
} finally {
__estrace.exit('set', 'inline:1');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment