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

support custom JavaScript formats #122

Open
thescientist13 opened this issue Oct 16, 2023 · 0 comments
Open

support custom JavaScript formats #122

thescientist13 opened this issue Oct 16, 2023 · 0 comments
Assignees
Labels
feature New feature or request
Milestone

Comments

@thescientist13
Copy link
Member

thescientist13 commented Oct 16, 2023

Type of Change

Feature

Summary

It would be nice to support importing things that are not just javascript, e.g.

import '../components/greeting.ts';

export default class ContactPage extends HTMLElement {
  connectedCallback() {
    this.innerHTML = `
      <h1>Welcome to our About page!</h1>
      <x-greeting name="About Page"></x-greeting>
    `;
  }
}

But also need to make sure it won't break / yell if something non JS compatible was added and sent to acorn

import '../components/greeting.ts';
import sheet from '../theme.css' with { type: 'css' }; 

export default class ContactPage extends HTMLElement {
  connectedCallback() {
    this.innerHTML = `
      <h1>Welcome to our About page!</h1>
      <x-greeting></x-greeting>
      <x-greeting name="About Page"></x-greeting>
    `;
  }
}

Details

This is because right now we limit what can be passed to WCC, otherwise acorn will fail on things that are not ultimately transformed into JavaScript, e.g.

    registerDeps {
      moduleURL: URL {
        href: 'file:///Users/owenbuckley/Workspace/project-evergreen/greenwood/packages/plugin-typescript/test/cases/exp-prerender.serve.ssr/src/components/card/card.ts',
        origin: 'null',
        protocol: 'file:',
        username: '',
        password: '',
        host: '',
        hostname: '',
        port: '',
        pathname: '/Users/owenbuckley/Workspace/project-evergreen/greenwood/packages/plugin-typescript/test/cases/exp-prerender.serve.ssr/src/components/card/card.ts',
        search: '',
        searchParams: URLSearchParams {},
        hash: ''
      }
    }
SyntaxError [Error]: Unexpected token (9:21)
    at pp$4.raise (file:///Users/owenbuckley/Workspace/project-evergreen/greenwood/node_modules/wc-compiler/node_modules/acorn/dist/acorn.mjs:3453:13)
    at pp$9.unexpected (file:///Users/owenbuckley/Workspace/project-evergreen/greenwood/node_modules/wc-compiler/node_modules/acorn/dist/acorn.mjs:754:8)
    at pp$8.parseVar (file:///Users/owenbuckley/Workspace/project-evergreen/greenwood/node_modules/wc-compiler/node_modules/acorn/dist/acorn.mjs:1299:12)
    at pp$8.parseVarStatement (file:///Users/owenbuckley/Workspace/project-evergreen/greenwood/node_modules/wc-compiler/node_modules/acorn/dist/acorn.mjs:1161:8)
    at pp$8.parseStatement (file:///Users/owenbuckley/Workspace/project-evergreen/greenwood/node_modules/wc-compiler/node_modules/acorn/dist/acorn.mjs:909:17)
    at pp$8.parseBlock (file:///Users/owenbuckley/Workspace/project-evergreen/greenwood/node_modules/wc-compiler/node_modules/acorn/dist/acorn.mjs:1230:21)
    at pp$8.parseStatement (file:///Users/owenbuckley/Workspace/project-evergreen/greenwood/node_modules/wc-compiler/node_modules/acorn/dist/acorn.mjs:912:36)
    at pp$8.parseIfStatement (file:///Users/owenbuckley/Workspace/project-evergreen/greenwood/node_modules/wc-compiler/node_modules/acorn/dist/acorn.mjs:1059:26)
    at pp$8.parseStatement (file:///Users/owenbuckley/Workspace/project-evergreen/greenwood/node_modules/wc-compiler/node_modules/acorn/dist/acorn.mjs:901:33)
    at pp$8.parseBlock (file:///Users/owenbuckley/Workspace/project-evergreen/greenwood/node_modules/wc-compiler/node_modules/acorn/dist/acorn.mjs:1230:21) {
  pos: 209,
  loc: { line: 9, column: 21 },
  raisedAt: 210
}

While the above outcome may seem expected, for frameworks like Greenwood that support custom imports, the use of fs here totally bypasses the ESM loader mechanics, which means if you have a custom loader for handling TypeScript, it will never run, thus WCC will always just be reading the unprocessed source contents.

@thescientist13 thescientist13 added the enhancement Improvement to existing functionality label Oct 16, 2023
@thescientist13 thescientist13 added this to the 1.0 milestone Oct 16, 2023
@thescientist13 thescientist13 changed the title support custom loaders through using import for walking module contents instead of fs support custom loaders through using import instead of fs for reading module contents Oct 16, 2023
@thescientist13 thescientist13 changed the title support custom loaders through using import instead of fs for reading module contents support custom JavaScript formats Oct 16, 2023
@thescientist13 thescientist13 added feature New feature or request and removed enhancement Improvement to existing functionality labels Oct 16, 2023
@thescientist13 thescientist13 self-assigned this Oct 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
Status: 📋 Backlog
Development

No branches or pull requests

1 participant