Skip to content

Commit

Permalink
fix #6 trailing space removed
Browse files Browse the repository at this point in the history
  • Loading branch information
kawanet committed Aug 29, 2023
1 parent 35e92cf commit a236dd1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/parser/tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,15 @@ export class Tag implements NSP.Transpiler {

// transpile attributes to array function if they include variables
const hasVars = /\(.+?\)|\$\{.+?}/s.test(attrRaw);
const attrJS = hasVars ? `${vName} => (${attrRaw})` : attrRaw;
const attrArg = hasVars ? `, ${vName} => (${attrRaw})` : `, ${attrRaw}`;

const nameJS = JSON.stringify(tagName);
const hasAttr = /:/.test(attrRaw);
const restJS = def.body ? (`, ${attrJS}, ${def.body}`) : (hasAttr ? `, ${attrJS}` : "");

let bodyArg = def.body;
if (bodyArg) bodyArg = ((/^\n/.test(bodyArg)) ? "," : ", ") + bodyArg;

const restJS = bodyArg ? (attrArg + bodyArg) : (hasAttr ? attrArg : "");

return `${nspName}.tag(${nameJS}${restJS})`;
}
Expand Down
6 changes: 6 additions & 0 deletions test/620.indent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ describe(TITLE, () => {
it(optD, async () => {
result0 = nspD.parse(doc).toJS();
assert.equal(nspD.parse(doc).toFn()(ctx), expected);

// trailing spaces
assert.doesNotMatch(result0, / +\n/);
});

it(opt0, async () => {
Expand All @@ -38,6 +41,9 @@ describe(TITLE, () => {
it(opt4, async () => {
result4 = nsp4.parse(doc).toJS();
assert.equal(nsp4.parse(doc).toFn()(ctx), expected);

// trailing spaces
assert.doesNotMatch(result4, / +\n/);
});

it(optE, async () => {
Expand Down

0 comments on commit a236dd1

Please sign in to comment.