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

content-tag's process incorrectly converts type imports to value imports. #35

Closed
NullVoxPopuli opened this issue Oct 5, 2023 · 3 comments · Fixed by #36
Closed

content-tag's process incorrectly converts type imports to value imports. #35

NullVoxPopuli opened this issue Oct 5, 2023 · 3 comments · Fixed by #36

Comments

@NullVoxPopuli
Copy link
Contributor

This comes out of: embroider-build/addon-blueprint#195

Repro:

import { Preprocessor } from 'content-tag';
const p = new Preprocessor();


const gjs2 = `
import Component from '@glimmer/component';
import type { WithBoundArgs } from '@glint/template';
import { hash } from '@ember/helper';

import Header from './header.gts';
import Content from './content.gts';

export interface AccordionItemSignature {
  Element: HTMLDivElement;
  Blocks: {
    default: [
      {
        Header: WithBoundArgs<
          typeof Header,
          'value' | 'isExpanded' | 'toggle' | 'disabled'
        >;
        Content: WithBoundArgs<typeof Content, 'value' | 'isExpanded'>;
      },
    ];
  };
}

export default class AccordionItem extends Component<AccordionItemSignature> {
  /* ... */
  <template>
    ...
  </template>
}
`;

console.log(p.process(gjs2));

results in:

import { template } from "@ember/template-compiler";
import Component from '@glimmer/component';
import { WithBoundArgs } from '@glint/template';
import { hash } from '@ember/helper';
import Header from './header.gts';
import Content from './content.gts';
export interface AccordionItemSignature {
    Element: HTMLDivElement;
    Blocks: {
        default: [{
                Header: WithBoundArgs<typeof Header, 'value' | 'isExpanded' | 'toggle' | 'disabled'>;
                Content: WithBoundArgs<typeof Content, 'value' | 'isExpanded'>;
            }];
    };
}
export default class AccordionItem extends Component<AccordionItemSignature> {
    /* ... */ static{
        template(`
    ...
  `, {
            component: this,
            eval () {
                return eval(arguments[0]);
            }
        });
    }
}

not that the type import on @glint/template was stripped.

during the babel phase of the v2-addon build, this causes just WithBoundArgs to be removed, leaving a side-effecting import '@glint/template' -- because it's not safe to remove the entirety of value imports (which is why we want to require type annotations on type-imports.

@ef4
Copy link
Collaborator

ef4 commented Oct 5, 2023

I would guess this is a bug in the swc printer.

@ef4
Copy link
Collaborator

ef4 commented Oct 5, 2023

swc-project/swc#8070

@ef4 ef4 mentioned this issue Oct 6, 2023
@ef4 ef4 closed this as completed in #36 Oct 6, 2023
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 a pull request may close this issue.

2 participants