Skip to content

Commit

Permalink
fix: comments or whitespace between else/else-if tags (#1827)
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey committed Jul 25, 2022
1 parent 5add6c0 commit ae0c003
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/four-dogs-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@marko/translator-default": patch
---

Fix issue where there was whitespace or a comment between else/else-if tags.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ export function buildIfStatement(path, args) {

let nextPath = path.getNextSibling();

while (
nextPath.isMarkoComment() ||
(nextPath.isMarkoText() && /^\s*$/.test(nextPath.node.value))
) {
const ignorePath = nextPath;
nextPath = nextPath.getNextSibling();
ignorePath.remove();
}

// Provide the if statement to the next part of the if chain.
if (nextPath.isMarkoTag()) {
const nextTagName = nextPath.get("name");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"use strict";

exports.__esModule = true;
exports.default = void 0;

var _index = require("marko/src/runtime/html/index.js");

var _renderer = _interopRequireDefault(require("marko/src/runtime/components/renderer.js"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

const _marko_componentType = "packages/translator-default/test/fixtures/else-tag-with-whitespace-and-comments/template.marko",
_marko_template = (0, _index.t)(_marko_componentType);

var _default = _marko_template;
exports.default = _default;
const _marko_component = {};
_marko_template._ = (0, _renderer.default)(function (input, out, _componentDef, _component, state) {
if (x) {} else if (y) {} else {}
}, {
t: _marko_componentType,
i: true,
d: true
}, _marko_component);
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<if(x)/>
<else-if(y)/>
<!-- Comments are okay also! -->
<!-- Comments are okay also!-->
<else/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { t as _t } from "marko/src/runtime/html/index.js";

const _marko_componentType = "packages/translator-default/test/fixtures/else-tag-with-whitespace-and-comments/template.marko",
_marko_template = _t(_marko_componentType);

export default _marko_template;
import _marko_renderer from "marko/src/runtime/components/renderer.js";
const _marko_component = {};
_marko_template._ = _marko_renderer(function (input, out, _componentDef, _component, state) {
if (x) {} else if (y) {} else {}
}, {
t: _marko_componentType,
i: true,
d: true
}, _marko_component);
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { t as _t } from "marko/dist/runtime/html/index.js";

const _marko_componentType = "GzjO/FF7",
_marko_template = _t(_marko_componentType);

export default _marko_template;
import _marko_renderer from "marko/dist/runtime/components/renderer.js";
const _marko_component = {};
_marko_template._ = _marko_renderer(function (input, out, _componentDef, _component, state) {
if (x) {} else if (y) {} else {}
}, {
t: _marko_componentType,
i: true
}, _marko_component);
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { t as _t } from "marko/src/runtime/vdom/index.js";

const _marko_componentType = "packages/translator-default/test/fixtures/else-tag-with-whitespace-and-comments/template.marko",
_marko_template = _t(_marko_componentType);

export default _marko_template;
import _marko_renderer from "marko/src/runtime/components/renderer.js";
import { r as _marko_registerComponent } from "marko/src/runtime/components/registry";

_marko_registerComponent(_marko_componentType, () => _marko_template);

const _marko_component = {};
_marko_template._ = _marko_renderer(function (input, out, _componentDef, _component, state) {
if (x) {} else if (y) {} else {}
}, {
t: _marko_componentType,
i: true,
d: true
}, _marko_component);
import _marko_defineComponent from "marko/src/runtime/components/defineComponent.js";
_marko_template.Component = _marko_defineComponent(_marko_component, _marko_template._);
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { t as _t } from "marko/dist/runtime/vdom/index.js";

const _marko_componentType = "GzjO/FF7",
_marko_template = _t(_marko_componentType);

export default _marko_template;
import _marko_renderer from "marko/dist/runtime/components/renderer.js";
import { r as _marko_registerComponent } from "marko/dist/runtime/components/registry";

_marko_registerComponent(_marko_componentType, () => _marko_template);

const _marko_component = {};
_marko_template._ = _marko_renderer(function (input, out, _componentDef, _component, state) {
if (x) {} else if (y) {} else {}
}, {
t: _marko_componentType,
i: true
}, _marko_component);
import _marko_defineComponent from "marko/dist/runtime/components/defineComponent.js";
_marko_template.Component = _marko_defineComponent(_marko_component, _marko_template._);
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<if(x)>
</if>

<else-if(y)>
</else-if>
<!-- Comments are okay also! -->
// Comments are okay also!
<else>
</else>

0 comments on commit ae0c003

Please sign in to comment.