Skip to content

Commit

Permalink
fix: loosen babel parse errors
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey committed Mar 21, 2023
1 parent c4be8ba commit cceab7d
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .changeset/small-donuts-sip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
"@marko/translator-default": patch
"@marko/compiler": patch
"marko": patch
---

Reduce script parsing restrictions added by Babel.
This was causing Babel to error when parsing partion scripts.

```marko
static const x = 1;
export { x };
```

Before this change in the above code Babel would error when parsing `export { x }` saying `x` was not previously defined. This is because Marko parses these statements in isolation.
8 changes: 8 additions & 0 deletions packages/compiler/src/babel-plugin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ export default (api, markoOpts) => {
return {
name: "marko",
manipulateOptions(opts) {
// We need to allow these for now since we are not parsing the entire file
// These types of syntax errors will be picked up by the bundler / runtime anyways.
opts.parserOpts.allowAwaitOutsideFunction =
opts.parserOpts.allowImportExportEverywhere =
opts.parserOpts.allowReturnOutsideFunction =
opts.parserOpts.allowSuperOutsideMethod =
opts.parserOpts.allowUndeclaredExports =
true;
curOpts = opts;
},
parserOverride(code) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"use strict";

exports.__esModule = true;
exports.y = exports.x = exports.default = void 0;
exports.z = z;
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/exports/template.marko",
_marko_template = (0, _index.t)(_marko_componentType);
var _default = _marko_template;
exports.default = _default;
const x = 1;
exports.x = x;
const y = 2;
exports.y = y;
function z() {}
const _marko_component = {};
_marko_template._ = (0, _renderer.default)(function (input, out, _componentDef, _component, state, $global) {}, {
t: _marko_componentType,
i: true,
d: true
}, _marko_component);
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const x = 1;
static const y = 2;
export { y };
export function z() {}
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/exports/template.marko",
_marko_template = _t(_marko_componentType);
export default _marko_template;
export const x = 1;
const y = 2;
export { y };
export function z() {}
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);
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 = "NPJMtzPP",
_marko_template = _t(_marko_componentType);
export default _marko_template;
export const x = 1;
const y = 2;
export { y };
export function z() {}
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);
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { t as _t } from "marko/src/runtime/vdom/index.js";
const _marko_componentType = "packages/translator-default/test/fixtures/exports/template.marko",
_marko_template = _t(_marko_componentType);
export default _marko_template;
export const x = 1;
const y = 2;
export { y };
export function z() {}
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, $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._);
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { t as _t } from "marko/dist/runtime/vdom/index.js";
const _marko_componentType = "NPJMtzPP",
_marko_template = _t(_marko_componentType);
export default _marko_template;
export const x = 1;
const y = 2;
export { y };
export function z() {}
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, $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._);
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const x = 1;

static const y = 2;
export { y };

export function z() {
}

0 comments on commit cceab7d

Please sign in to comment.