Skip to content

Commit

Permalink
use variable value instead of name if name is digits
Browse files Browse the repository at this point in the history
  • Loading branch information
denofevil committed Jul 21, 2017
1 parent ccf127d commit cc315e6
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,18 @@ function convertSnippet(snippet, context) {

let body = snippet.body.join("\n");
body = body.replace(/\\t/, '');
let replacement = (str, name, value) => {
let replacement = (str, match, name, value) => {
const shortMatch = typeof value === "number";
name = !name.match(/\d*/) || shortMatch ? name : value;
value = shortMatch ? undefined : value;
const original = name;
name = name === "0" ? "END" : name;
name = name.replace("-", "_");
vars[name] = value || (!shortMatch ? original : "");
return "$" + name + "$";
};
body = body.replace(/\$([_a-zA-Z0-9\-]+)/g, replacement);
body = body.replace(/\${([_a-zA-Z0-9\-]+(?:\s*:\s*([_a-zA-Z][_a-zA-Z0-9]*))?)}/g, replacement);
body = body.replace(/\$(([_a-zA-Z0-9\-]+))/g, replacement);
body = body.replace(/\${(([_a-zA-Z0-9\-]+)(?:\s*:\s*([_a-zA-Z0-9\-]+))?)}/g, replacement);

let templateText = `
<template name="${xmlEscape(snippet.prefix)}" value="${xmlEscape(body)}" description="${xmlEscape(snippet.description)}" toReformat="true" toShortenFQNames="true">`;
Expand Down

0 comments on commit cc315e6

Please sign in to comment.