Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(esm): use file extension and directory index #1752

Closed
wants to merge 1 commit into from
Closed

fix(esm): use file extension and directory index #1752

wants to merge 1 commit into from

Conversation

snyamathi
Copy link
Contributor

@snyamathi snyamathi commented Nov 5, 2021

This PR is tangential to #1727 and attempts to allow ESM to be used by fixing issues with mandatory-file-extensions.

For ES Modules, we need to specify /index.js when requiring a directory and .js when requiring a file without the use of one of the experimental flags.

The following template was compiled with the meta option disabled ( which uses __filename; also not supported by ESM ).

$ const foo = 'bar';
<h1 data-foo=foo>Hello World</h1>
  // Compiled using marko@5.17.3 - DO NOT EDIT
- import { t as _t } from "marko/src/runtime/html/index.js";
+ import { t as _t } from "marko/src/runtime/html/index.js";
  
  const _marko_componentType = "components/hello-world.marko",
        _marko_template = _t(_marko_componentType);
  
  export default _marko_template;
- import _marko_attr from "marko/src/runtime/html/helpers/attr";
+ import _marko_attr from "marko/src/runtime/html/helpers/attr.js";
- import _marko_renderer from "marko/src/runtime/components/renderer";
+ import _marko_renderer from "marko/src/runtime/components/renderer.js";
  const _marko_component = {};
  _marko_template._ = _marko_renderer(function (input, out, _componentDef, _component, state) {
    out.w(`<h1${_marko_attr("data-foo", input.bar)}>`);
    out.w("Hello World");
    out.w("</h1>");
  }, {
    t: _marko_componentType,
    i: true,
    d: true
  }, _marko_component);

This is only one portion of what would be required to support ES Modules, but it's a start 😄

@snyamathi
Copy link
Contributor Author

Duplicate of: #1728

@snyamathi snyamathi closed this Nov 6, 2021
@snyamathi snyamathi deleted the esm branch November 6, 2021 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant