refactor: improve comment only statement parsing

This commit is contained in:
dpiercey 2025-08-08 14:33:14 -07:00 committed by Dylan Piercey
parent cc069bcbd1
commit cd25fbbeab
9 changed files with 84 additions and 1 deletions

View File

@ -139,7 +139,9 @@ function tryParse(
} else {
const { program } = babelParser.parse(code, parserOpts);
if (program.innerComments) {
return babelParser.parse(`;${code}`, parserOpts).program.body;
const lastNode = t.emptyStatement();
lastNode.trailingComments = program.innerComments;
program.body.push(lastNode);
}
return program.body;
}

View File

@ -0,0 +1,18 @@
"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(e) { return e && e.__esModule ? e : { default: e }; }
const _marko_componentType = "__tests__/template.marko",
_marko_template = (0, _index.t)(_marko_componentType);
var _default = exports.default = _marko_template;
;
/* only a comment */
const _marko_component = {};
_marko_template._ = (0, _renderer.default)(function (input, out, _componentDef, _component, state, $global) {}, {
t: _marko_componentType,
i: true,
d: true
}, _marko_component);

View File

@ -0,0 +1,4 @@
static {
;
/* only a comment */
}

View File

@ -0,0 +1,13 @@
import { t as _t } from "marko/src/runtime/html/index.js";
const _marko_componentType = "__tests__/template.marko",
_marko_template = _t(_marko_componentType);
export default _marko_template;
;
/* only a comment */
import _marko_renderer from "marko/src/runtime/components/renderer.js";
const _marko_component = {};
_marko_template._ = _marko_renderer(function (input, out, _componentDef, _component, state, $global) {}, {
t: _marko_componentType,
i: true,
d: true
}, _marko_component);

View File

@ -0,0 +1,12 @@
import { t as _t } from "marko/dist/runtime/html/index.js";
const _marko_componentType = "daEYByF",
_marko_template = _t(_marko_componentType);
export default _marko_template;
;
/* only a comment */
import _marko_renderer from "marko/dist/runtime/components/renderer.js";
const _marko_component = {};
_marko_template._ = _marko_renderer(function (input, out, _componentDef, _component, state, $global) {}, {
t: _marko_componentType,
i: true
}, _marko_component);

View File

@ -0,0 +1,17 @@
import { t as _t } from "marko/src/runtime/vdom/index.js";
const _marko_componentType = "__tests__/template.marko",
_marko_template = _t(_marko_componentType);
export default _marko_template;
;
/* only a comment */
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) {}, {
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._);

View File

@ -0,0 +1,16 @@
import { t as _t } from "marko/dist/runtime/vdom/index.js";
const _marko_componentType = "daEYByF",
_marko_template = _t(_marko_componentType);
export default _marko_template;
;
/* only a comment */
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) {}, {
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._);

View File

@ -0,0 +1 @@
static /* only a comment */