Skip to content

Commit

Permalink
fix: sourcemaps in for loops
Browse files Browse the repository at this point in the history
  • Loading branch information
LuLaValva committed Jul 26, 2024
1 parent 2e0be72 commit 82b747d
Show file tree
Hide file tree
Showing 28 changed files with 78 additions and 45 deletions.
4 changes: 4 additions & 0 deletions packages/marko/src/runtime/helpers/of-fallback.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var arr = [];
module.exports = function (v) {
return v || arr;
};
1 change: 1 addition & 0 deletions packages/translator-default/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ export function getRuntimeEntryFiles(output, optimize) {
`${base}runtime/components/attach-detach.js`,
`${base}runtime/helpers/assign.js`,
`${base}runtime/helpers/class-value.js`,
`${base}runtime/helpers/of-fallback.js`,

Check warning on line 500 in packages/translator-default/src/index.js

View check run for this annotation

Codecov / codecov/patch

packages/translator-default/src/index.js#L500

Added line #L500 was not covered by tests
`${base}runtime/helpers/dynamic-tag.js`,
`${base}runtime/helpers/attr-tag.js`,
`${base}runtime/helpers/merge.js`,
Expand Down
13 changes: 8 additions & 5 deletions packages/translator-default/src/taglib/core/translate-for.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertAllowedAttributes } from "@marko/babel-utils";
import { assertAllowedAttributes, importDefault } from "@marko/babel-utils";
import { types as t } from "@marko/compiler";

export function exit(path) {
Expand Down Expand Up @@ -44,10 +44,13 @@ export function exit(path) {
block,
);
} else if (ofAttr) {
let ofAttrValue = t.logicalExpression(
"||",
ofAttr.value,
t.arrayExpression([]),
let ofAttrValue = t.callExpression(
importDefault(
path.hub.file,
"marko/src/runtime/helpers/of-fallback.js",
"of_fallback",
),
[ofAttr.value],
);
allowedAttributes.push("of");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ exports.__esModule = true;
exports.default = void 0;
var _index = require("marko/src/runtime/html/index.js");
var _attrTag = require("marko/src/runtime/helpers/attr-tag.js");
var _ofFallback = _interopRequireDefault(require("marko/src/runtime/helpers/of-fallback.js"));
var _escapeXml = require("marko/src/runtime/html/helpers/escape-xml.js");
var _index2 = _interopRequireDefault(require("./components/hello/index.marko"));
var _renderTag = _interopRequireDefault(require("marko/src/runtime/helpers/render-tag.js"));
Expand All @@ -16,7 +17,7 @@ const _marko_component = {};
_marko_template._ = (0, _renderer.default)(function (input, out, _componentDef, _component, state, $global) {
(0, _renderTag.default)(_index2.default, (0, _attrTag.i)(() => {
(0, _attrTag.a)("list", (0, _attrTag.i)(() => {
for (const color of input.colors || []) {
for (const color of (0, _ofFallback.default)(input.colors)) {
if (x) {
(0, _attrTag.r)("items", {
"style": {
Expand Down Expand Up @@ -55,9 +56,9 @@ _marko_template._ = (0, _renderer.default)(function (input, out, _componentDef,
});
}
}));
for (const col of input.table || []) {
for (const col of (0, _ofFallback.default)(input.table)) {
(0, _attrTag.r)("cols", (0, _attrTag.i)(() => {
for (const row of col || []) {
for (const row of (0, _ofFallback.default)(col)) {
(0, _attrTag.r)("rows", {
"row": row,
"renderBody": out => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const _marko_componentType = "packages/translator-default/test/fixtures/at-tags-
_marko_template = _t(_marko_componentType);
export default _marko_template;
import { r as _marko_repeated_attr_tag, a as _marko_repeatable_attr_tag, i as _marko_render_input } from "marko/src/runtime/helpers/attr-tag.js";
import _of_fallback from "marko/src/runtime/helpers/of-fallback.js";
import { x as _marko_escapeXml } from "marko/src/runtime/html/helpers/escape-xml.js";
import _hello from "./components/hello/index.marko";
import _marko_tag from "marko/src/runtime/helpers/render-tag.js";
Expand All @@ -11,7 +12,7 @@ const _marko_component = {};
_marko_template._ = _marko_renderer(function (input, out, _componentDef, _component, state, $global) {
_marko_tag(_hello, _marko_render_input(() => {
_marko_repeatable_attr_tag("list", _marko_render_input(() => {
for (const color of input.colors || []) {
for (const color of _of_fallback(input.colors)) {
if (x) {
_marko_repeated_attr_tag("items", {
"style": {
Expand Down Expand Up @@ -50,9 +51,9 @@ _marko_template._ = _marko_renderer(function (input, out, _componentDef, _compon
});
}
}));
for (const col of input.table || []) {
for (const col of _of_fallback(input.table)) {
_marko_repeated_attr_tag("cols", _marko_render_input(() => {
for (const row of col || []) {
for (const row of _of_fallback(col)) {
_marko_repeated_attr_tag("rows", {
"row": row,
"renderBody": out => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const _marko_componentType = "LOwmoBub",
_marko_template = _t(_marko_componentType);
export default _marko_template;
import { r as _marko_repeated_attr_tag, a as _marko_repeatable_attr_tag, i as _marko_render_input } from "marko/dist/runtime/helpers/attr-tag.js";
import _of_fallback from "marko/dist/runtime/helpers/of-fallback.js";
import { x as _marko_escapeXml } from "marko/dist/runtime/html/helpers/escape-xml.js";
import _hello from "./components/hello/index.marko";
import _marko_tag from "marko/dist/runtime/helpers/render-tag.js";
Expand All @@ -11,7 +12,7 @@ const _marko_component = {};
_marko_template._ = _marko_renderer(function (input, out, _componentDef, _component, state, $global) {
_marko_tag(_hello, _marko_render_input(() => {
_marko_repeatable_attr_tag("list", _marko_render_input(() => {
for (const color of input.colors || []) {
for (const color of _of_fallback(input.colors)) {
if (x) {
_marko_repeated_attr_tag("items", {
"style": {
Expand Down Expand Up @@ -50,9 +51,9 @@ _marko_template._ = _marko_renderer(function (input, out, _componentDef, _compon
});
}
}));
for (const col of input.table || []) {
for (const col of _of_fallback(input.table)) {
_marko_repeated_attr_tag("cols", _marko_render_input(() => {
for (const row of col || []) {
for (const row of _of_fallback(col)) {
_marko_repeated_attr_tag("rows", {
"row": row,
"renderBody": out => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const _marko_componentType = "packages/translator-default/test/fixtures/at-tags-
_marko_template = _t(_marko_componentType);
export default _marko_template;
import { r as _marko_repeated_attr_tag, a as _marko_repeatable_attr_tag, i as _marko_render_input } from "marko/src/runtime/helpers/attr-tag.js";
import _of_fallback from "marko/src/runtime/helpers/of-fallback.js";
import _hello from "./components/hello/index.marko";
import _marko_tag from "marko/src/runtime/helpers/render-tag.js";
import _marko_renderer from "marko/src/runtime/components/renderer.js";
Expand All @@ -12,7 +13,7 @@ const _marko_component = {};
_marko_template._ = _marko_renderer(function (input, out, _componentDef, _component, state, $global) {
_marko_tag(_hello, _marko_render_input(() => {
_marko_repeatable_attr_tag("list", _marko_render_input(() => {
for (const color of input.colors || []) {
for (const color of _of_fallback(input.colors)) {
if (x) {
_marko_repeated_attr_tag("items", {
"style": {
Expand Down Expand Up @@ -51,9 +52,9 @@ _marko_template._ = _marko_renderer(function (input, out, _componentDef, _compon
});
}
}));
for (const col of input.table || []) {
for (const col of _of_fallback(input.table)) {
_marko_repeated_attr_tag("cols", _marko_render_input(() => {
for (const row of col || []) {
for (const row of _of_fallback(col)) {
_marko_repeated_attr_tag("rows", {
"row": row,
"renderBody": out => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const _marko_componentType = "LOwmoBub",
_marko_template = _t(_marko_componentType);
export default _marko_template;
import { r as _marko_repeated_attr_tag, a as _marko_repeatable_attr_tag, i as _marko_render_input } from "marko/dist/runtime/helpers/attr-tag.js";
import _of_fallback from "marko/dist/runtime/helpers/of-fallback.js";
import _hello from "./components/hello/index.marko";
import _marko_tag from "marko/dist/runtime/helpers/render-tag.js";
import _marko_renderer from "marko/dist/runtime/components/renderer.js";
Expand All @@ -12,7 +13,7 @@ const _marko_component = {};
_marko_template._ = _marko_renderer(function (input, out, _componentDef, _component, state, $global) {
_marko_tag(_hello, _marko_render_input(() => {
_marko_repeatable_attr_tag("list", _marko_render_input(() => {
for (const color of input.colors || []) {
for (const color of _of_fallback(input.colors)) {
if (x) {
_marko_repeated_attr_tag("items", {
"style": {
Expand Down Expand Up @@ -51,9 +52,9 @@ _marko_template._ = _marko_renderer(function (input, out, _componentDef, _compon
});
}
}));
for (const col of input.table || []) {
for (const col of _of_fallback(input.table)) {
_marko_repeated_attr_tag("cols", _marko_render_input(() => {
for (const row of col || []) {
for (const row of _of_fallback(col)) {
_marko_repeated_attr_tag("rows", {
"row": row,
"renderBody": out => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ exports.__esModule = true;
exports.default = void 0;
var _index = require("marko/src/runtime/html/index.js");
var _attrTag = require("marko/src/runtime/helpers/attr-tag.js");
var _ofFallback = _interopRequireDefault(require("marko/src/runtime/helpers/of-fallback.js"));
var _escapeXml = require("marko/src/runtime/html/helpers/escape-xml.js");
var _index2 = _interopRequireDefault(require("./components/hello/index.marko"));
var _renderTag = _interopRequireDefault(require("marko/src/runtime/helpers/render-tag.js"));
Expand All @@ -16,7 +17,7 @@ const _marko_component = {};
_marko_template._ = (0, _renderer.default)(function (input, out, _componentDef, _component, state, $global) {
(0, _renderTag.default)(_index2.default, (0, _attrTag.i)(() => {
(0, _attrTag.a)("list", (0, _attrTag.i)(() => {
for (const color of input.colors || []) {
for (const color of (0, _ofFallback.default)(input.colors)) {
if (x) {
(0, _attrTag.r)("items", {
"renderBody": out => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const _marko_componentType = "packages/translator-default/test/fixtures/at-tags-
_marko_template = _t(_marko_componentType);
export default _marko_template;
import { r as _marko_repeated_attr_tag, a as _marko_repeatable_attr_tag, i as _marko_render_input } from "marko/src/runtime/helpers/attr-tag.js";
import _of_fallback from "marko/src/runtime/helpers/of-fallback.js";
import { x as _marko_escapeXml } from "marko/src/runtime/html/helpers/escape-xml.js";
import _hello from "./components/hello/index.marko";
import _marko_tag from "marko/src/runtime/helpers/render-tag.js";
Expand All @@ -11,7 +12,7 @@ const _marko_component = {};
_marko_template._ = _marko_renderer(function (input, out, _componentDef, _component, state, $global) {
_marko_tag(_hello, _marko_render_input(() => {
_marko_repeatable_attr_tag("list", _marko_render_input(() => {
for (const color of input.colors || []) {
for (const color of _of_fallback(input.colors)) {
if (x) {
_marko_repeated_attr_tag("items", {
"renderBody": out => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const _marko_componentType = "ktPbis$k",
_marko_template = _t(_marko_componentType);
export default _marko_template;
import { r as _marko_repeated_attr_tag, a as _marko_repeatable_attr_tag, i as _marko_render_input } from "marko/dist/runtime/helpers/attr-tag.js";
import _of_fallback from "marko/dist/runtime/helpers/of-fallback.js";
import { x as _marko_escapeXml } from "marko/dist/runtime/html/helpers/escape-xml.js";
import _hello from "./components/hello/index.marko";
import _marko_tag from "marko/dist/runtime/helpers/render-tag.js";
Expand All @@ -11,7 +12,7 @@ const _marko_component = {};
_marko_template._ = _marko_renderer(function (input, out, _componentDef, _component, state, $global) {
_marko_tag(_hello, _marko_render_input(() => {
_marko_repeatable_attr_tag("list", _marko_render_input(() => {
for (const color of input.colors || []) {
for (const color of _of_fallback(input.colors)) {
if (x) {
_marko_repeated_attr_tag("items", {
"renderBody": out => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const _marko_componentType = "packages/translator-default/test/fixtures/at-tags-
_marko_template = _t(_marko_componentType);
export default _marko_template;
import { r as _marko_repeated_attr_tag, a as _marko_repeatable_attr_tag, i as _marko_render_input } from "marko/src/runtime/helpers/attr-tag.js";
import _of_fallback from "marko/src/runtime/helpers/of-fallback.js";
import _hello from "./components/hello/index.marko";
import _marko_tag from "marko/src/runtime/helpers/render-tag.js";
import _marko_renderer from "marko/src/runtime/components/renderer.js";
Expand All @@ -12,7 +13,7 @@ const _marko_component = {};
_marko_template._ = _marko_renderer(function (input, out, _componentDef, _component, state, $global) {
_marko_tag(_hello, _marko_render_input(() => {
_marko_repeatable_attr_tag("list", _marko_render_input(() => {
for (const color of input.colors || []) {
for (const color of _of_fallback(input.colors)) {
if (x) {
_marko_repeated_attr_tag("items", {
"renderBody": out => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const _marko_componentType = "ktPbis$k",
_marko_template = _t(_marko_componentType);
export default _marko_template;
import { r as _marko_repeated_attr_tag, a as _marko_repeatable_attr_tag, i as _marko_render_input } from "marko/dist/runtime/helpers/attr-tag.js";
import _of_fallback from "marko/dist/runtime/helpers/of-fallback.js";
import _hello from "./components/hello/index.marko";
import _marko_tag from "marko/dist/runtime/helpers/render-tag.js";
import _marko_renderer from "marko/dist/runtime/components/renderer.js";
Expand All @@ -12,7 +13,7 @@ const _marko_component = {};
_marko_template._ = _marko_renderer(function (input, out, _componentDef, _component, state, $global) {
_marko_tag(_hello, _marko_render_input(() => {
_marko_repeatable_attr_tag("list", _marko_render_input(() => {
for (const color of input.colors || []) {
for (const color of _of_fallback(input.colors)) {
if (x) {
_marko_repeated_attr_tag("items", {
"renderBody": out => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ exports.__esModule = true;
exports.default = void 0;
var _index = require("marko/src/runtime/html/index.js");
var _escapeXml = require("marko/src/runtime/html/helpers/escape-xml.js");
var _ofFallback = _interopRequireDefault(require("marko/src/runtime/helpers/of-fallback.js"));
var _dataMarko = _interopRequireDefault(require("marko/src/runtime/html/helpers/data-marko.js"));
var _renderer = _interopRequireDefault(require("marko/src/runtime/components/renderer.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
Expand All @@ -13,7 +14,7 @@ var _default = exports.default = _marko_template;
const _marko_component = {};
_marko_template._ = (0, _renderer.default)(function (input, out, _componentDef, _component, state, $global) {
let _i = 0;
for (const val of arr || []) {
for (const val of (0, _ofFallback.default)(arr)) {
let i = _i++;
const _keyScope = `[${i}]`;
out.w("<div>");
Expand Down Expand Up @@ -45,7 +46,7 @@ _marko_template._ = (0, _renderer.default)(function (input, out, _componentDef,
out.w("<div></div>");
}
let _i2 = 0;
for (const val of arr || []) {
for (const val of (0, _ofFallback.default)(arr)) {
let i = _i2++;
const _keyValue = `@${i}`,
_keyScope4 = `[${_keyValue}]`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ const _marko_componentType = "packages/translator-default/test/fixtures/for-tag/
_marko_template = _t(_marko_componentType);
export default _marko_template;
import { x as _marko_escapeXml } from "marko/src/runtime/html/helpers/escape-xml.js";
import _of_fallback from "marko/src/runtime/helpers/of-fallback.js";
import _marko_props from "marko/src/runtime/html/helpers/data-marko.js";
import _marko_renderer from "marko/src/runtime/components/renderer.js";
const _marko_component = {};
_marko_template._ = _marko_renderer(function (input, out, _componentDef, _component, state, $global) {
let _i = 0;
for (const val of arr || []) {
for (const val of _of_fallback(arr)) {
let i = _i++;
const _keyScope = `[${i}]`;
out.w("<div>");
Expand Down Expand Up @@ -40,7 +41,7 @@ _marko_template._ = _marko_renderer(function (input, out, _componentDef, _compon
out.w("<div></div>");
}
let _i2 = 0;
for (const val of arr || []) {
for (const val of _of_fallback(arr)) {
let i = _i2++;
const _keyValue = `@${i}`,
_keyScope4 = `[${_keyValue}]`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ const _marko_componentType = "lMveozAf",
_marko_template = _t(_marko_componentType);
export default _marko_template;
import { x as _marko_escapeXml } from "marko/dist/runtime/html/helpers/escape-xml.js";
import _of_fallback from "marko/dist/runtime/helpers/of-fallback.js";
import _marko_props from "marko/dist/runtime/html/helpers/data-marko.js";
import _marko_renderer from "marko/dist/runtime/components/renderer.js";
const _marko_component = {};
_marko_template._ = _marko_renderer(function (input, out, _componentDef, _component, state, $global) {
let _i = 0;
for (const val of arr || []) {
for (const val of _of_fallback(arr)) {
let i = _i++;
const _keyScope = `[${i}]`;
out.w(`<div>${_marko_escapeXml(i)}: ${_marko_escapeXml(val)}</div><div></div><div></div>`);
Expand All @@ -24,7 +25,7 @@ _marko_template._ = _marko_renderer(function (input, out, _componentDef, _compon
out.w(`<div>${_marko_escapeXml(i)}</div><div></div><div></div>`);
}
let _i2 = 0;
for (const val of arr || []) {
for (const val of _of_fallback(arr)) {
let i = _i2++;
const _keyValue = `@${i}`,
_keyScope4 = `[${_keyValue}]`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import { t as _t } from "marko/src/runtime/vdom/index.js";
const _marko_componentType = "packages/translator-default/test/fixtures/for-tag/template.marko",
_marko_template = _t(_marko_componentType);
export default _marko_template;
import _of_fallback from "marko/src/runtime/helpers/of-fallback.js";
import _marko_renderer from "marko/src/runtime/components/renderer.js";
import { r as _marko_registerComponent } from "marko/src/runtime/components/registry.js";
_marko_registerComponent(_marko_componentType, () => _marko_template);
const _marko_component = {};
_marko_template._ = _marko_renderer(function (input, out, _componentDef, _component, state, $global) {
let _i = 0;
for (const val of arr || []) {
for (const val of _of_fallback(arr)) {
let i = _i++;
const _keyScope = `[${i}]`;
out.be("div", null, "0" + _keyScope, _component, null, 0);
Expand Down Expand Up @@ -40,7 +41,7 @@ _marko_template._ = _marko_renderer(function (input, out, _componentDef, _compon
out.e("div", null, "8" + _keyScope3, _component, 0, 0);
}
let _i2 = 0;
for (const val of arr || []) {
for (const val of _of_fallback(arr)) {
let i = _i2++;
const _keyValue = `@${i}`,
_keyScope4 = `[${_keyValue}]`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import { t as _t } from "marko/dist/runtime/vdom/index.js";
const _marko_componentType = "lMveozAf",
_marko_template = _t(_marko_componentType);
export default _marko_template;
import _of_fallback from "marko/dist/runtime/helpers/of-fallback.js";
import _marko_renderer from "marko/dist/runtime/components/renderer.js";
import { r as _marko_registerComponent } from "marko/dist/runtime/components/registry.js";
_marko_registerComponent(_marko_componentType, () => _marko_template);
const _marko_component = {};
_marko_template._ = _marko_renderer(function (input, out, _componentDef, _component, state, $global) {
let _i = 0;
for (const val of arr || []) {
for (const val of _of_fallback(arr)) {
let i = _i++;
const _keyScope = `[${i}]`;
out.be("div", null, "0" + _keyScope, _component, null, 0);
Expand Down Expand Up @@ -40,7 +41,7 @@ _marko_template._ = _marko_renderer(function (input, out, _componentDef, _compon
out.e("div", null, "8" + _keyScope3, _component, 0, 0);
}
let _i2 = 0;
for (const val of arr || []) {
for (const val of _of_fallback(arr)) {
let i = _i2++;
const _keyValue = `@${i}`,
_keyScope4 = `[${_keyValue}]`;
Expand Down
Loading

0 comments on commit 82b747d

Please sign in to comment.